@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ==========================================================================
   Design Tokens — Open WebUI Premium Dark Theme
   ========================================================================== */
:root {
  --bg-primary:    #0f0f1a;
  --bg-secondary:  #1a1a2e;
  --bg-sidebar:    #111118;
  --bg-surface:    #1e1e2e;
  --bg-hover:      rgba(255, 255, 255, 0.04);
  --bg-active:     rgba(255, 255, 255, 0.06);
  --bg-input:      rgba(255, 255, 255, 0.04);
  --bg-card:       #1e1e2e;

  --border-primary:  rgba(255, 255, 255, 0.06);
  --border-hover:    rgba(255, 255, 255, 0.1);
  --border-focus:    rgba(245, 158, 11, 0.5);

  --text-primary:    #e5e5e5;
  --text-secondary:  #a1a1aa;
  --text-muted:      #71717a;
  --text-accent:     #f59e0b;
  --text-error:      #ef4444;
  --text-success:    #22c55e;

  --accent:          #f59e0b;
  --accent-hover:    #d97706;
  --accent-soft:     rgba(245, 158, 11, 0.1);

  --user-bubble:     rgba(245, 158, 11, 0.08);
  --bot-bubble:      transparent;

  --font-primary: 'Inter', system-ui, -apple-system, sans-serif;
  --sidebar-width: 260px;
  --header-height: 56px;
  --chat-max-width: 768px;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --radius-pill: 24px;
  --transition: all 0.2s ease;
}

/* Light Theme */
body.light {
  --bg-primary:    #ffffff;
  --bg-secondary:  #f9fafb;
  --bg-sidebar:    #f3f4f6;
  --bg-surface:    #ffffff;
  --bg-hover:      rgba(0, 0, 0, 0.03);
  --bg-active:     rgba(0, 0, 0, 0.05);
  --bg-input:      rgba(0, 0, 0, 0.03);
  --bg-card:       #ffffff;

  --border-primary:  rgba(0, 0, 0, 0.08);
  --border-hover:    rgba(0, 0, 0, 0.12);
  --border-focus:    rgba(245, 158, 11, 0.5);

  --text-primary:    #1f2937;
  --text-secondary:  #4b5563;
  --text-muted:      #9ca3af;
  --text-accent:     #d97706;
  --text-error:      #dc2626;
  --text-success:    #16a34a;

  --accent:          #d97706;
  --accent-hover:    #b45309;
  --accent-soft:     rgba(245, 158, 11, 0.08);

  --user-bubble:     rgba(245, 158, 11, 0.06);
  --bot-bubble:      transparent;
}

/* ==========================================================================
   Global Reset & Base
   ========================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-primary);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.3s ease, color 0.3s ease;
}

a { color: var(--text-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(128, 128, 128, 0.3); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: rgba(128, 128, 128, 0.5); }

/* ==========================================================================
   Auth Pages — Centered Card Layout
   ========================================================================== */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  overflow-y: auto;
  padding: 40px 20px;
  position: relative;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  position: relative;
  z-index: 2;
}

.auth-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 32px;
}

.auth-logo-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent-soft);
  display: grid;
  place-items: center;
  color: var(--text-accent);
}

.auth-logo-text {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.auth-heading {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 4px;
  text-align: center;
  letter-spacing: -0.02em;
}

.auth-subheading {
  font-size: 14px;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 28px;
}

/* Form Fields */
.field-group {
  margin-bottom: 16px;
}

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.field-input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-primary);
  font-size: 14px;
  outline: none;
  transition: var(--transition);
}

.field-input:focus {
  border-color: var(--border-focus);
  background: var(--bg-hover);
}

.field-input::placeholder {
  color: var(--text-muted);
}

/* Buttons */
.btn-primary {
  width: 100%;
  height: 44px;
  background: var(--bg-hover);
  border: 1px solid var(--border-primary);
  border-radius: 999px;
  color: var(--text-primary);
  font-family: var(--font-primary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.btn-primary:hover {
  background: var(--bg-active);
  border-color: var(--border-hover);
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  height: 44px;
  background: var(--bg-hover);
  border: 1px solid var(--border-primary);
  border-radius: 999px;
  color: var(--text-primary);
  font-family: var(--font-primary);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: var(--transition);
}

.btn-google:hover {
  background: var(--bg-active);
  border-color: var(--border-hover);
  text-decoration: none;
}

/* Auth divider */
.auth-divider {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 20px 0;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-primary);
}

.auth-divider span {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

/* Auth links */
.auth-footer {
  text-align: center;
  margin-top: 20px;
  font-size: 14px;
  color: var(--text-muted);
}

.auth-footer a {
  font-weight: 500;
}

/* Error / Success boxes */
.error-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--radius-sm);
  color: var(--text-error);
  font-size: 13px;
  margin-bottom: 16px;
}

.success-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: rgba(34, 197, 94, 0.08);
  border: 1px solid rgba(34, 197, 94, 0.2);
  border-radius: var(--radius-sm);
  color: var(--text-success);
  font-size: 13px;
  margin-bottom: 16px;
}

/* Auth meta info */
.auth-meta {
  margin-top: 24px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.7;
}

/* Remember me row */
.auth-options-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  font-size: 13px;
}

.auth-options-row label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--text-secondary);
}

.auth-options-row input[type="checkbox"] {
  accent-color: var(--text-accent);
}

/* OTP boxes */
.otp-group {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 20px;
}

.otp-box {
  width: 50px;
  height: 56px;
  text-align: center;
  font-size: 22px;
  font-weight: 600;
  font-family: var(--font-primary);
  background: var(--bg-input);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  outline: none;
  transition: var(--transition);
}

.otp-box:focus {
  border-color: var(--border-focus);
  background: var(--bg-hover);
}

.otp-box.filled {
  border-color: var(--text-accent);
  background: var(--accent-soft);
}

/* Password strength */
.strength-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
  margin-bottom: 16px;
}
.strength-bars {
  display: flex;
  gap: 5px;
  flex: 1;
}
.strength-bar-bg {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--border-primary);
  overflow: hidden;
}
.strength-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 2px;
  transition: width 0.3s ease, background-color 0.3s ease;
}
.strength-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  min-width: 50px;
  text-align: right;
  color: var(--text-muted);
}

.match-hint {
  font-size: 13px;
  margin-top: 6px;
  opacity: 0;
  transition: opacity 0.2s;
}
.match-hint.visible { opacity: 1; }
.match-hint.ok { color: var(--text-success); }
.match-hint.bad { color: var(--text-error); }

/* Timer (OTP page) */
.timer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  font-size: 13px;
}
.timer-display {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-secondary);
}
.timer-ring-wrap {
  position: relative;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}
.timer-ring-wrap svg { transform: rotate(-90deg); }
.timer-ring-bg { fill: none; stroke: var(--border-primary); stroke-width: 3; }
.timer-ring-fg { fill: none; stroke: var(--text-accent); stroke-width: 3; stroke-linecap: round; transition: stroke-dashoffset 1s linear; }
.timer-num {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-accent);
}
.resend-btn {
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-primary);
  color: var(--text-muted);
  cursor: not-allowed;
  transition: color 0.2s;
}
.resend-btn.active {
  color: var(--text-accent);
  cursor: pointer;
}
.resend-btn.active:hover { text-decoration: underline; }

/* Step indicators (OTP page) */
.steps-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
}
.step-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.step-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-input);
  border: 2px solid var(--border-primary);
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
}
.step-dot.active { background: var(--accent-soft); border-color: var(--text-accent); color: var(--text-accent); }
.step-dot.done { border-color: var(--text-success); color: var(--text-success); }
.step-label { font-size: 11px; font-weight: 600; text-transform: uppercase; color: var(--text-muted); }
.step-title { font-size: 14px; font-weight: 600; }
.step-desc { font-size: 13px; color: var(--text-muted); }

/* Theme toggle for auth pages */
.theme-toggle-fixed {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-hover);
  border: 1px solid var(--border-primary);
  color: var(--text-secondary);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: var(--transition);
}
.theme-toggle-fixed:hover { background: var(--bg-active); color: var(--text-primary); }

/* ==========================================================================
   Chat Page — App Shell
   ========================================================================== */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-primary);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: var(--transition);
  overflow: hidden;
}

.sidebar-header {
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent-soft);
  display: grid;
  place-items: center;
  color: var(--text-accent);
}

.sidebar-logo-text {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.sidebar-toggle-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: var(--transition);
}
.sidebar-toggle-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* New Chat button */
.new-chat-btn {
  margin: 4px 14px 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: none;
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}
.new-chat-btn:hover { background: var(--bg-hover); border-color: var(--border-hover); }
.new-chat-btn svg { flex-shrink: 0; }

/* Sidebar section label */
.sidebar-section-label {
  padding: 12px 16px 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

/* Chat history */
.chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px;
}

.history-row {
  position: relative;
}

.history-btn {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 8px 12px;
  padding-right: 32px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-primary);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.history-btn.active-history { background: var(--bg-active); color: var(--text-primary); }

.history-title-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  opacity: 0;
  transition: var(--transition);
}
.history-row:hover .menu-btn { opacity: 1; }
.menu-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.history-menu {
  display: none;
  position: absolute;
  right: 8px;
  top: 40px;
  background: var(--bg-surface);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-sm);
  z-index: 999;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}
.history-menu button {
  display: block;
  width: 130px;
  padding: 8px 14px;
  background: none;
  border: none;
  color: var(--text-error);
  font-family: var(--font-primary);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: var(--transition);
}
.history-menu button:hover { background: rgba(239, 68, 68, 0.08); }

/* Sidebar footer */
.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border-primary);
}

.memory-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  margin-bottom: 10px;
}
.memory-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
}

.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.sidebar-user-avatar-fallback {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--text-accent);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.sidebar-user-name {
  font-size: 13px;
  font-weight: 500;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-disclaimer {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.5;
  padding: 8px 4px;
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

/* ==========================================================================
   Chat Panel — Main Content
   ========================================================================== */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  background: var(--bg-primary);
}

/* Header */
.chat-header {
  height: var(--header-height);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-primary);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-model-name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.header-status {
  font-size: 12px;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Icon buttons */
.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: var(--transition);
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }

/* Voice button */
.voice-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  height: 36px;
  background: var(--bg-hover);
  border: 1px solid var(--border-primary);
  border-radius: 999px;
  color: var(--text-secondary);
  font-family: var(--font-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}
.voice-btn:hover { background: var(--bg-active); color: var(--text-primary); }
.voice-btn.voice-active {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.3);
  color: #ef4444;
}
.voice-btn.voice-connecting {
  opacity: 0.6;
  cursor: wait;
}
.voice-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
}
.voice-active .voice-dot {
  background: #ef4444;
  animation: voicePulse 1.5s ease infinite;
}
@keyframes voicePulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
.voice-mic-icon { font-size: 14px; }

/* Language dropdown */
.language-select {
  height: 36px;
  padding: 0 30px 0 12px;
  background: var(--bg-hover);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-primary);
  font-size: 13px;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg fill='%239ca3af' height='20' viewBox='0 0 24 24' width='20' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
  transition: var(--transition);
}
.language-select:hover { border-color: var(--border-hover); }
.language-select option { background: var(--bg-surface); color: var(--text-primary); }

/* User info in header */
.header-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 12px;
  margin-left: 6px;
  border-left: 1px solid var(--border-primary);
}

.header-user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
}

.header-user-avatar-fallback {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--text-accent);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
}

.btn-signout {
  padding: 0 12px;
  height: 32px;
  background: var(--bg-hover);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-primary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  display: grid;
  place-items: center;
  transition: var(--transition);
}
.btn-signout:hover { background: var(--bg-active); color: var(--text-primary); text-decoration: none; }

/* ==========================================================================
   Messages Area
   ========================================================================== */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

/* Welcome State */
.welcome-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px 0;
  max-width: var(--chat-max-width);
  margin: 0 auto;
  text-align: center;
}

.welcome-logo {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent-soft);
  display: grid;
  place-items: center;
  color: var(--text-accent);
  margin-bottom: 16px;
}

.welcome-title {
  font-size: 26px;
  font-weight: 600;
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}

.welcome-sub {
  font-size: 15px;
  color: var(--text-muted);
  margin-bottom: 32px;
  max-width: 480px;
}

/* Suggestion cards */
.suggestion-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 600px;
}

.suggestion-card {
  padding: 14px 16px;
  background: var(--bg-hover);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius);
  text-align: left;
  cursor: pointer;
  font-family: var(--font-primary);
  transition: var(--transition);
}
.suggestion-card:hover { background: var(--bg-active); border-color: var(--border-hover); }
.suggestion-card-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text-primary);
}
.suggestion-card-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Messages */
#messagesList {
  max-width: var(--chat-max-width);
  margin: 0 auto;
  padding: 24px 20px;
}

.message-wrap {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  align-items: flex-start;
}
.message-wrap.visible { opacity: 1; transform: translateY(0); }

.message-wrap.user {
  flex-direction: row-reverse;
}

.message-wrap .avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-soft);
  display: grid;
  place-items: center;
  color: var(--text-accent);
  flex-shrink: 0;
  margin-top: 2px;
}

.bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.7;
  max-width: 85%;
  word-break: break-word;
}

.message-wrap.assistant .bubble {
  background: var(--bot-bubble);
  color: var(--text-primary);
}

.message-wrap.user .bubble {
  background: var(--user-bubble);
  border: 1px solid rgba(245, 158, 11, 0.1);
  color: var(--text-primary);
}

.msg-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  flex-shrink: 0;
  align-self: flex-end;
}

/* Typing dots */
.typing-bubble { padding: 14px 18px !important; }
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  display: inline-block;
  animation: typingBounce 1.4s ease infinite;
}
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* Voice label on bubbles */
.voice-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-accent);
  margin-bottom: 4px;
  display: block;
  letter-spacing: 0.03em;
}

/* Code blocks in responses */
.bubble pre {
  background: var(--bg-surface);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-sm);
  padding: 14px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 13px;
}

.bubble code {
  font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
  font-size: 13px;
}

.bubble ul, .bubble ol { padding-left: 20px; margin: 8px 0; }
.bubble li { margin-bottom: 4px; }
.bubble p { margin-bottom: 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble strong { font-weight: 600; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 {
  font-weight: 600;
  margin: 12px 0 6px;
}

/* ==========================================================================
   Input Area
   ========================================================================== */
.input-area {
  padding: 12px 20px 16px;
  max-width: calc(var(--chat-max-width) + 40px);
  margin: 0 auto;
  width: 100%;
}

.input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 0;
  background: var(--bg-input);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-pill);
  padding: 6px 8px 6px 18px;
  transition: var(--transition);
}
.input-wrap:focus-within { border-color: var(--border-focus); }

.chat-input {
  flex: 1;
  border: none;
  outline: none;
  background: none;
  color: var(--text-primary);
  font-family: var(--font-primary);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  padding: 8px 0;
  max-height: 140px;
}
.chat-input::placeholder { color: var(--text-muted); }

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--text-accent);
  border: none;
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: var(--transition);
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.input-disclaimer {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 8px;
}

/* ==========================================================================
   Voice Toast
   ========================================================================== */
#voiceToast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-surface);
  border: 1px solid var(--border-primary);
  color: var(--text-primary);
  padding: 10px 22px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 9000;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}
#voiceToast.show { opacity: 1; }

/* ==========================================================================
   Memory Modal
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 8000;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.modal-overlay.active { opacity: 1; pointer-events: auto; }

.modal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 90%;
  max-width: 520px;
  max-height: 70vh;
  overflow-y: auto;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 6px;
}

.modal-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
  line-height: 1.6;
}

.memory-content {
  padding: 16px;
  background: var(--bg-input);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-secondary);
  margin-bottom: 20px;
  min-height: 100px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.modal-actions button {
  padding: 0 18px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-primary);
  background: var(--bg-hover);
  color: var(--text-primary);
  font-family: var(--font-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}
.modal-actions button:hover { background: var(--bg-active); }
.modal-actions button:first-child { color: var(--text-error); }

/* ==========================================================================
   Loader Screen
   ========================================================================== */
#loader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}
#loader.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

.loader-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-primary);
  border-top-color: var(--text-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loader-text {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.loader-text span { color: var(--text-accent); }

.loader-bar {
  width: 180px;
  height: 2px;
  background: var(--border-primary);
  border-radius: 2px;
  overflow: hidden;
}
.loader-bar::after {
  content: '';
  display: block;
  height: 100%;
  width: 40%;
  background: var(--text-accent);
  animation: loadSlide 1.2s ease-in-out infinite;
}
@keyframes loadSlide { 0% { transform: translateX(-100%); } 100% { transform: translateX(350%); } }

.loader-sub {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.15em;
}

/* ==========================================================================
   Responsive
   ========================================================================== */
/* ==========================================================================
   Responsive & Mobile Optimization
   ========================================================================== */
body {
  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);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  z-index: 4999;
  opacity: 0;
  transition: opacity 0.3s ease;
}

/* Responsive tables, images, pre blocks inside bubble */
.bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13px;
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.bubble th, .bubble td {
  border: 1px solid var(--border-primary);
  padding: 8px 10px;
  text-align: left;
}
.bubble th {
  background: var(--bg-hover);
  font-weight: 600;
}
.bubble img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  margin: 8px 0;
}
.bubble pre {
  max-width: 100%;
  box-sizing: border-box;
  overflow-x: auto;
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -300px;
    z-index: 5000;
    transition: left 0.3s ease;
  }
  .sidebar.open {
    left: 0;
  }
  .sidebar.open + .sidebar-overlay {
    display: block;
    opacity: 1;
  }

  .suggestion-grid {
    grid-template-columns: 1fr;
  }

  .header-actions {
    gap: 4px;
  }

  .voice-btn .voice-text { display: none; }
  .language-select { display: none; }

  .header-user .sidebar-user-name { display: none; }
}

@media (max-width: 480px) {
  .auth-page {
    padding: 24px 16px;
  }
  .auth-card {
    padding: 0 8px;
  }
  .input-area {
    padding: 8px 12px 12px;
  }
  .input-wrap {
    padding: 6px 6px 6px 12px;
  }
  .chat-input {
    font-size: 13px;
  }
  .modal-card {
    padding: 20px;
    max-height: 85vh;
  }
}

@media (max-width: 420px) {
  .otp-group {
    gap: 6px;
  }
  .otp-box {
    width: 40px;
    height: 48px;
    font-size: 18px;
  }
}

@media (max-width: 360px) {
  .chat-header {
    padding: 0 8px;
  }
  .header-left {
    gap: 6px;
  }
  .header-actions {
    gap: 2px;
  }
  .btn-icon {
    width: 32px;
    height: 32px;
  }
  .voice-btn {
    padding: 0 8px;
    height: 32px;
  }
}