/* =========================
   GLOBAL RESET
========================= */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: system-ui, Arial;
  }
  
  html, body {
    height: 100%;
    width: 100%;
  }
  
  /* =========================
     SAFE MOBILE FIX (IMPORTANT)
  ========================= */
  body {
    background: linear-gradient(135deg, rgb(185, 149, 167), rgb(77, 42, 68));
    display: flex;
    justify-content: center;
    align-items: center;
  
    min-height: 100vh;
    min-height: 100dvh; /* modern mobile fix */
  
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  
  /* =========================
     APP CONTAINER
  ========================= */
  .chat-app {
    width: 100%;
    max-width: 520px;
  
    height: 100dvh;
    max-height: 100dvh;
  
    display: flex;
    flex-direction: column;
  
    background: rgb(7, 57, 57);
  
    overflow: hidden;
  
    border-radius: 0;
  }
  
  /* Desktop polish */
  @media (min-width: 768px) {
    .chat-app {
      height: 90vh;
      border-radius: 18px;
      box-shadow: 0 20px 60px rgba(0,0,0,0.4);
    }
  }
  
  /* =========================
     TOP BAR
  ========================= */
  .top-bar {
    padding: 14px 16px;
    background: rgb(60, 121, 125);
    color: white;
  
    display: flex;
    justify-content: space-between;
    align-items: center;
  
    flex-shrink: 0;
  }
  
  .top-bar h1 {
    font-size: 16px;
  }
  
  /* =========================
     CONTROLS
  ========================= */
  .controls {
    display: flex;
    align-items: center;
    gap: 10px;
  }
  
  /* =========================
     CHAT AREA
  ========================= */
  #chatbox {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overscroll-behavior: contain;  
    -webkit-overflow-scrolling: touch;
  }
  
  /* =========================
     MESSAGES
  ========================= */
  .message {
    max-width: 85%;
    padding: 12px 14px;
  
    border-radius: 16px;
  
    font-size: 15px;
    line-height: 1.4;
  
    word-wrap: break-word;
  }
  
  .bot {
    background: #374151;
    color: white;
    align-self: flex-start;
  }
  
  /* =========================
     INPUT BAR (FIXED MOBILE UX)
  ========================= */
  .input-bar {
    flex-shrink: 0;
    min-height: 64px;
    display: flex;
    gap: 10px;
    padding: 12px;
    background: rgb(54, 73, 143);
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
  
  /* BUTTONS */
  .input-bar button {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 12px;
    background: rgb(44, 205, 202);
    color: white;
    font-weight: 600;
    min-height: 44px;
  }
  
  /* =========================
     MOBILE TUNING
  ========================= */
  @media (max-width: 480px) {
    .top-bar h1 {
      font-size: 14px;
    }
  
    .message {
      font-size: 14px;
    }
  
    .input-bar button {
      padding: 10px;
    }
  }
  
  /* =========================
     DARK MODE
  ========================= */
  body.dark {
    background: #0a0f1c;
  }
  
  body.dark .chat-app {
    background: #0b1220;
  }
  
  body.dark .top-bar,
  body.dark .input-bar {
    background: #111827;
  }
  
  body.dark .bot {
    background: #1f2937;
  }
  button {
    touch-action: manipulation;
  }

  .message {
    display: flex;
  }
  
  .bubble {
    padding: 12px 14px;
    border-radius: 18px;
    max-width: 80%;
    font-size: 15px;
    line-height: 1.4;
    word-wrap: break-word;
  }
  
  /* BOT (left like iMessage incoming) */
  .bot .bubble {
    background: #374151;
    color: white;
    border-bottom-left-radius: 4px;
  }
  
  /* USER (right side like iMessage outgoing) */
  .user {
    justify-content: flex-end;
  }
  
  .user .bubble {
    background: rgb(103, 216, 205);
    color: white;
    border-bottom-right-radius: 4px;
  }
  .typing-bubble {
    display: flex;
    gap: 4px;
    align-items: center;
  }
  
  .typing-bubble span {
    width: 6px;
    height: 6px;
    background: white;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
  }
  
  .typing-bubble span:nth-child(2) { animation-delay: 0.2s; }
  .typing-bubble span:nth-child(3) { animation-delay: 0.4s; }
  
  @keyframes bounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
    40% { transform: scale(1); opacity: 1; }
  }

  .modal {
    position: fixed;
    inset: 0;
    background: rgba(131, 101, 101, 0.276);
    display: flex;
    justify-content: center;
    align-items: center;
  }
  
  .hidden {
    display: none;
  }
  
  .modal-content {
    background: #111827;
    padding: 16px;
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    color: white;
  }
  
  #historyList {
    max-height: 300px;
    overflow-y: auto;
    margin: 10px 0;
  }