html,
body {
      width: 100vw;
      min-width: 0;
      max-width: 100vw;
      height: 100vh;
      min-height: 100vh;
      max-height: 100vh;
      overflow: hidden;
      box-sizing: border-box;
}
* {
      box-sizing: inherit;
}

body {
      background: #f7fafd;
      font-family: "Inter", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
      margin: 0;
      padding: 0;
      min-height: 100vh;
      height: 100vh;
      max-height: 100vh;
      color: #222;
      overflow: hidden;
      display: flex;
      flex-direction: column;
}

.banner {
      width: 100%;
      max-width: 100vw;
      background: #fff;
      color: #222;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
      padding: 1.1rem 1.5rem 0.7rem 1.5rem;
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: space-between;
      position: relative;
      z-index: 10;
      gap: 1rem;
}
.banner-title {
      font-size: 1.25rem;
      font-weight: 700;
      letter-spacing: 0.5px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      margin: 0;
}
.banner-actions {
      display: flex;
      align-items: center;
      gap: 0.5rem;
      margin: 0;
      height: 100%;
}

.chat-container {
      display: flex;
      flex-direction: column;
      justify-content: flex-end;
      align-items: stretch;
      flex: 1 1 0;
      min-height: 0;
      width: 100%;
      max-width: 100vw;
      background: #f7fafd;
      height: 0;
}

.chat-messages {
      flex: 1 1 0;
      overflow-y: auto;
      overflow-x: hidden;
      padding: 1.2rem 0.7rem 0.7rem 0.7rem;
      display: flex;
      flex-direction: column;
      gap: 0.6rem;
      width: 100%;
      max-width: 100vw;
      min-height: 0;
}

.message {
      display: flex;
      flex-direction: column;
      max-width: 80%;
}

.message.user {
      align-self: flex-end;
      align-items: flex-end;
}

.message.bot {
      align-self: flex-start;
      align-items: flex-start;
}

.message-content {
      padding: 0.7rem 1.1rem;
      border-radius: 1.2rem;
      font-size: 1rem;
      line-height: 1.6;
      background: #e3eafc;
      color: #222;
      box-shadow: 0 1px 4px rgba(0, 0, 0, 0.03);
      word-break: break-word;
      white-space: pre-wrap;
      border: 1px solid #e0e7ef;
}

.message.user .message-content {
      background: #b6d0fa;
      color: #174ea6;
      border-bottom-right-radius: 0.4rem;
      border: 1px solid #a3c3f5;
}

.message.bot .message-content {
      background: #f1f3f7;
      color: #222;
      border-bottom-left-radius: 0.4rem;
      border: 1px solid #e0e7ef;
}

#chat-form {
      display: flex;
      gap: 0.6rem;
      padding: 0.8rem;
      background: #f7fafd;
      border-top: 1px solid #e0e7ef;
      width: 100%;
      max-width: 100vw;
      flex-shrink: 0;
      align-items: center;
}

#user-input {
      flex: 1;
      min-width: 0;
      height: 44px;
      max-height: 300px;
      padding: 0.7rem 1rem;
      border: 1px solid #cfd8e3;
      border-radius: 1rem;
      font-size: 1rem;
      outline: none;
      background: #fff;
      transition: border 0.2s;
      box-sizing: border-box;
      resize: none;
      line-height: 1.5;
      display: block;
      overflow-y: hidden;
}
#user-input:focus {
      border: 1.5px solid #5b9bfa;
      background: #f7fafd;
}

button[type="submit"] {
      background: #5b9bfa;
      color: #fff;
      border: none;
      border-radius: 1rem;
      height: 44px;
      padding: 0 1.3rem;
      font-size: 1rem;
      font-weight: 500;
      cursor: pointer;
      transition: background 0.2s;
      min-width: 64px;
      box-shadow: 0 1px 4px rgba(0, 0, 0, 0.03);
      box-sizing: border-box;
      display: flex;
      align-items: center;
      justify-content: center;
}
button[type="submit"]:hover {
      background: #2563eb;
}

.banner-content {
      display: flex;
      flex-direction: column;
      align-items: flex-start;
      min-width: 0;
}
.banner-title {
      font-size: 1.25rem;
      font-weight: 700;
      letter-spacing: 0.5px;
      margin-bottom: 0.2rem;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      order: 1;
      margin-right: auto;
}
.banner-desc {
      font-size: 1rem;
      color: #4b5563;
      margin-bottom: 0.2rem;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
}
#theme-toggle {
      position: static;
      width: 40px;
      height: 40px;
      font-size: 1.3rem;
      cursor: pointer;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
      display: flex;
      align-items: center;
      justify-content: center;
      background: #fff;
      color: #222;
      border: 1px solid #e0e7ef;
      border-radius: 50%;
      transition: background 0.2s, color 0.2s;
}
#theme-toggle:hover {
      background: #e3eafc;
}
body.dark-mode #theme-toggle {
      background: #232a36;
      color: #e6e6e6;
      border: 1px solid #232a36;
}
body.dark-mode #theme-toggle:hover {
      background: #3b4252;
}

.banner-actions {
      display: flex;
      align-items: center;
      gap: 0.5rem;
      order: 2;
      margin-left: 0;
      margin-right: 0;
}

@media (max-width: 600px) {
      html,
      body {
            width: 100vw;
            min-width: 0;
            max-width: 100vw;
            height: 100vh;
            min-height: 100vh;
            max-height: 100vh;
            overflow: hidden;
      }
      .banner {
            padding: 0.7rem 0.7rem 0.5rem 0.7rem;
            flex-direction: row;
            align-items: center;
            justify-content: space-between;
            gap: 0.7rem;
            width: 100%;
            max-width: 100vw;
      }
      .chat-container {
            min-height: 0;
            border-radius: 0;
            box-shadow: none;
            width: 100%;
            max-width: 100vw;
            flex: 1 1 0;
            height: 0;
      }
      .chat-messages {
            padding: 1rem 0.2rem 0.7rem 0.2rem;
            gap: 0.4rem;
            width: 100%;
            max-width: 100vw;
            min-height: 0;
      }
      .message-content {
            font-size: 0.98rem;
            padding: 0.6rem 0.8rem;
      }
      #chat-form {
            padding: 0.7rem 0.2rem;
            gap: 0.4rem;
            width: 100%;
            max-width: 100vw;
            flex-shrink: 0;
            align-items: center;
      }
      #user-input {
            font-size: 0.98rem;
            height: 44px;
            max-height: 300px;
            padding: 0.7rem 0.7rem;
            overflow-y: hidden;
      }
      button[type="submit"] {
            font-size: 0.98rem;
            height: 44px;
            padding: 0 0.9rem;
            min-width: 54px;
      }
      .banner-content {
            align-items: flex-start;
      }
      .banner-title {
            font-size: 1.05rem;
            margin: 0;
      }
      .banner-desc {
            font-size: 0.92rem;
      }
      #theme-toggle {
            align-self: flex-end;
            margin: 0;
            margin-top: 0.3rem;
      }
      .banner-actions {
            margin: 0;
            align-self: center;
      }
}

/* Dark mode - حرفه‌ای و کامل */
body.dark-mode,
.dark-mode .chat-container {
      background: #18181b !important;
      color: #e5e7eb !important;
}
.dark-mode .chat-messages {
      background: #18181b !important;
}
.dark-mode .message-content {
      background: #23272f !important;
      color: #f3f4f6 !important;
      border: 1px solid #23272f !important;
      box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}
.dark-mode .message.user .message-content {
      background: #2563eb !important;
      color: #fff !important;
      border: 1px solid #2563eb !important;
}
.dark-mode .message.bot .message-content {
      background: #23272f !important;
      color: #f3f4f6 !important;
      border: 1px solid #23272f !important;
}
.dark-mode #chat-form {
      background: #18181b !important;
      border-top: 1px solid #23272f !important;
}
.dark-mode #user-input {
      background: #23272f !important;
      color: #f3f4f6 !important;
      border: 1px solid #23272f !important;
}
.dark-mode #user-input:focus {
      background: #23272f !important;
      border: 1.5px solid #2563eb !important;
}
.dark-mode button[type="submit"] {
      background: #2563eb !important;
      color: #fff !important;
      border: none !important;
}
.dark-mode button[type="submit"]:hover {
      background: #1d4ed8 !important;
}
.dark-mode #theme-toggle {
      background: #23272f !important;
      color: #e5e7eb !important;
      border: 1px solid #23272f !important;
}
.dark-mode #theme-toggle:hover {
      background: #1e293b !important;
}
.dark-mode .banner {
      background: #23272f;
      color: #e5e7eb;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}
.dark-mode .banner-desc {
      color: #a1a1aa;
}
/* ===== Bridge for legacy .msg structure ===== */
.msg {
      display: flex;
      flex-direction: column;
      width: fit-content;
      max-width: 80%;
      padding: 0;
      background: transparent;
      border: none;
}
.msg.user {
      align-self: flex-end;
      align-items: flex-end;
}
.msg.bot {
      align-self: flex-start;
      align-items: flex-start;
}

/* خودِ حباب پیام وقتی .message-content نداریم */
.msg.bot,
.msg.user {
      /* حباب */
}
.msg:not(.typing)::after {
      content: attr(data-text);
      display: block;
      padding: 0.7rem 1.1rem;
      border-radius: 1.2rem;
      font-size: 1rem;
      line-height: 1.6;
      background: #f1f3f7;
      color: #222;
      box-shadow: 0 1px 4px rgba(0, 0, 0, 0.03);
      border: 1px solid #e0e7ef;
      white-space: pre-wrap;
      word-break: break-word;
      max-width: min(80ch, 92vw);
}
.msg.user:not(.typing)::after {
      background: #b6d0fa;
      color: #174ea6;
      border: 1px solid #a3c3f5;
      border-bottom-right-radius: 0.4rem;
}
.msg.bot:not(.typing)::after {
      background: #f1f3f7;
      color: #222;
      border-bottom-left-radius: 0.4rem;
}

/* typing bubble */
.msg.typing {
      width: 46px;
      text-align: center;
      letter-spacing: 4px;
      opacity: 0.7;
      padding: 0.6rem 0.8rem;
      border-radius: 1rem;
      background: #e3eafc;
      border: 1px solid #e0e7ef;
      animation: blink 1.1s infinite alternate;
}
@keyframes blink {
      from {
            opacity: 0.35;
      }
      to {
            opacity: 1;
      }
}

/* دارک‌مود برای legacy */
.dark-mode .msg:not(.typing)::after {
      background: #23272f !important;
      color: #f3f4f6 !important;
      border: 1px solid #23272f !important;
}
.dark-mode .msg.user:not(.typing)::after {
      background: #2563eb !important;
      color: #fff !important;
      border-color: #2563eb !important;
}

/* Force pre-wrap for all message bubbles */
.message-content,
.message.user .message-content,
.message.bot .message-content {
      white-space: pre-wrap !important;
}
