/* =========================================================
   Student AI — minimal design system
   ========================================================= */

:root {
  --bg: #ffffff;
  --bg-secondary: #f7f7f8;
  --bg-tertiary: #ededed;
  --text: #1f1f23;
  --text-muted: #6b6b72;
  --border: #e5e5e7;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --radius: 8px;
  --radius-sm: 4px;
  --header-h: 56px;
  --sidebar-w: 260px;
}

[data-theme="dark"] {
  --bg: #0a0a0a;
  --bg-secondary: #141414;
  --bg-tertiary: #1f1f1f;
  --text: #e5e5e7;
  --text-muted: #9ca3af;
  --border: #262626;
  --accent: #818cf8;
  --accent-hover: #a5b4fc;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; font-size: inherit; cursor: pointer; }
code, pre { font-family: "SF Mono", Monaco, Consolas, "Liberation Mono", monospace; font-size: 13px; }

/* =========================================================
   Buttons
   ========================================================= */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: var(--radius);
  font-weight: 500;
  font-size: 14px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); color: #fff; }
.btn-ghost { border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-secondary); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; color: #fff; }
.btn-block { width: 100%; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-lg { padding: 12px 20px; font-size: 16px; }

.as-link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font: inherit;
  width: 100%;
}
.as-link:hover { color: var(--accent); }

/* =========================================================
   Landing page
   ========================================================= */

.landing-body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1000px 520px at 50% -180px, rgba(79,70,229,0.16), transparent 70%),
    radial-gradient(700px 400px at 110% 10%, rgba(129,140,248,0.12), transparent 60%),
    var(--bg);
}
[data-theme="dark"] .landing-body {
  background:
    radial-gradient(1000px 520px at 50% -180px, rgba(129,140,248,0.22), transparent 70%),
    radial-gradient(700px 400px at 110% 10%, rgba(79,70,229,0.18), transparent 60%),
    var(--bg);
}

.landing-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
}
.landing-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
  font-size: 16px;
}
.landing-brand:hover { text-decoration: none; }
.landing-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
}
.landing-nav { display: flex; gap: 18px; align-items: center; }
.landing-link {
  font-size: 14px;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
}
.landing-link:hover { color: var(--text); text-decoration: none; }

.landing-main {
  flex: 1;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 64px 24px 32px;
}

.hero {
  text-align: center;
  padding: 40px 0 48px;
}
.hero-eyebrow {
  display: inline-block;
  padding: 5px 12px;
  margin-bottom: 20px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-radius: 999px;
}
.hero h1 {
  font-size: clamp(32px, 6.5vw, 60px);
  margin: 0 0 18px;
  letter-spacing: -0.025em;
  line-height: 1.05;
  font-weight: 700;
}
.tagline {
  font-size: clamp(16px, 2.4vw, 20px);
  color: var(--text-muted);
  margin: 0 auto 32px;
  max-width: 620px;
  line-height: 1.55;
}
.hero-cta {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.hero-fineprint { font-size: 13px; color: var(--text-muted); margin: 0; }

.logo-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  justify-content: center;
  align-items: center;
  padding: 12px 0 56px;
}
.logo-strip-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-right: 4px;
}
.logo-chip {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  padding: 24px 0 40px;
}
.feature {
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg);
  transition: transform 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
}
.feature:hover {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(15,23,42,0.06);
}
[data-theme="dark"] .feature:hover { box-shadow: 0 8px 24px rgba(0,0,0,0.3); }
.feature-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  border-radius: 10px;
  margin-bottom: 14px;
}
.feature h3 { margin: 0 0 8px; font-size: 16px; font-weight: 600; }
.feature p { margin: 0; color: var(--text-muted); font-size: 14.5px; line-height: 1.55; }
.feature code {
  background: var(--bg-secondary);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12.5px;
}

.how-it-works { padding: 56px 0 32px; }
.how-it-works h2,
.pricing h2 {
  font-size: clamp(24px, 3.6vw, 32px);
  margin: 0 0 8px;
  text-align: center;
  letter-spacing: -0.015em;
}
.pricing-sub {
  text-align: center;
  color: var(--text-muted);
  margin: 0 auto 28px;
  font-size: 15px;
}
.steps {
  list-style: none;
  padding: 0;
  margin: 32px auto 0;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.steps li {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
}
.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
}
.steps h4 { margin: 0 0 4px; font-size: 15.5px; font-weight: 600; }
.steps p { margin: 0; color: var(--text-muted); font-size: 14px; line-height: 1.55; }

.pricing { padding: 48px 0 24px; }
.pricing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  max-width: 720px;
  margin: 0 auto;
}
.pricing-card {
  position: relative;
  padding: 28px 24px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
.pricing-card.is-featured {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
.pricing-badge {
  position: absolute;
  top: -10px; left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.pricing-tier { font-size: 13px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.pricing-amount { font-size: 36px; font-weight: 700; margin: 8px 0 2px; letter-spacing: -0.02em; }
.pricing-per { color: var(--text-muted); font-size: 13px; margin-bottom: 18px; }
.pricing-list { list-style: none; padding: 0; margin: 0 0 24px; flex: 1; font-size: 14px; color: var(--text); line-height: 1.6; }
.pricing-list li {
  padding: 6px 0 6px 22px;
  position: relative;
}
.pricing-list li::before {
  content: "";
  position: absolute;
  left: 0; top: 12px;
  width: 14px; height: 8px;
  border-left: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
  transform: rotate(-45deg);
}

.cta-strip {
  text-align: center;
  padding: 56px 24px;
  margin: 56px auto 0;
  max-width: 760px;
  border-radius: 18px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 14%, var(--bg)), color-mix(in srgb, var(--accent) 4%, var(--bg)));
  border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--border));
}
.cta-strip h2 { margin: 0 0 8px; font-size: clamp(22px, 3.2vw, 28px); letter-spacing: -0.01em; }
.cta-strip p { margin: 0 0 20px; color: var(--text-muted); }

.landing-footer {
  padding: 24px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin-top: 40px;
}
.landing-footer-inner {
  max-width: 1080px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.landing-foot-nav { display: flex; gap: 16px; }
.landing-foot-nav a { font-size: 13px; color: var(--text-muted); }
.landing-foot-nav a:hover { color: var(--text); text-decoration: none; }

@media (max-width: 640px) {
  .landing-header { padding: 12px 16px; }
  .landing-nav { gap: 10px; }
  .landing-link[href="#features"],
  .landing-link[href="#pricing"] { display: none; }
  .landing-main { padding: 32px 16px 16px; }
  .hero { padding: 16px 0 32px; }
  .hero-cta .btn-lg { width: 100%; }
  .logo-strip { padding: 4px 0 36px; gap: 6px 10px; }
  .steps li { flex-direction: row; padding: 14px 16px; }
  .cta-strip { padding: 40px 20px; margin-top: 40px; }
  .pricing-badge { font-size: 10px; padding: 3px 8px; }
}

/* =========================================================
   Auth pages
   ========================================================= */

.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-wrap { width: 100%; max-width: 400px; }
.auth-brand {
  display: block;
  text-align: center;
  font-weight: 700;
  font-size: 20px;
  margin-bottom: 24px;
  color: var(--text);
}
.auth-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  background: var(--bg);
}
.auth-card h1 { margin: 0 0 4px; font-size: 22px; }
.auth-sub { color: var(--text-muted); margin: 0 0 24px; font-size: 14px; }
.auth-foot { text-align: center; margin: 16px 0 0; font-size: 14px; color: var(--text-muted); }

form label {
  display: block;
  margin-bottom: 14px;
  font-size: 14px;
  font-weight: 500;
}
form label input,
form label select,
form label textarea,
form input[type="text"],
form input[type="email"],
form input[type="password"],
form input[type="tel"],
form input[type="number"],
form input[type="date"],
form input[type="search"],
form select,
form textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  transition: border-color 0.15s;
}
form label input:focus,
form label textarea:focus,
form label select:focus,
form input:focus,
form select:focus,
form textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}
.hint { color: var(--text-muted); font-size: 12px; display: block; margin-top: 4px; }
.hint.center { text-align: center; }

.checkbox { display: flex !important; align-items: center; gap: 8px; }
.checkbox input[type="checkbox"] { width: auto; margin: 0; }

.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin: 0 0 16px;
  font-size: 14px;
  border: 1px solid var(--border);
}
.alert-error { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.alert-success { background: #dcfce7; color: #14532d; border-color: #bbf7d0; }
.alert-info { background: #dbeafe; color: #1e3a8a; border-color: #bfdbfe; }
[data-theme="dark"] .alert-error { background: rgba(220, 38, 38, 0.15); color: #fca5a5; border-color: rgba(220,38,38,0.3); }
[data-theme="dark"] .alert-success { background: rgba(22, 163, 74, 0.15); color: #86efac; border-color: rgba(22,163,74,0.3); }
[data-theme="dark"] .alert-info { background: rgba(59, 130, 246, 0.15); color: #93c5fd; border-color: rgba(59,130,246,0.3); }

/* =========================================================
   Chat shell
   ========================================================= */

.app-shell {
  display: flex;
  height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
}

#sidebar-scrim { display: none; }

.sidebar-close {
  display: none;
  position: absolute;
  top: 8px; right: 8px;
  width: 36px; height: 36px;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text);
  cursor: pointer;
  z-index: 2;
  -webkit-tap-highlight-color: transparent;
}
.sidebar-close:hover { background: var(--bg-tertiary); }
.sidebar-top { position: relative; }

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  transition: transform 0.2s ease;
}
.sidebar-top { padding: 12px; }
.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-weight: 500;
  font-size: 14px;
  text-decoration: none;
}
.new-chat-btn:hover { background: var(--bg-tertiary); text-decoration: none; }

.conv-list { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.conv-group-label {
  padding: 12px 10px 4px;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}
.conv-item {
  position: relative;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
}
.conv-item:hover { background: var(--bg-tertiary); }
.conv-item.is-active { background: var(--bg-tertiary); }
.conv-link {
  flex: 1;
  padding: 8px 10px;
  color: var(--text);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-decoration: none;
}
.conv-link:hover { text-decoration: none; }
.conv-menu-btn {
  background: none;
  border: 0;
  color: var(--text-muted);
  padding: 6px 8px;
  opacity: 0;
  transition: opacity 0.15s;
  border-radius: var(--radius-sm);
}
.conv-item:hover .conv-menu-btn { opacity: 1; }
.conv-menu-btn:hover { background: var(--bg); color: var(--text); }
.conv-menu {
  position: absolute;
  right: 4px;
  top: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px;
  min-width: 140px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  font-size: 13px;
}
.conv-menu button, .conv-menu a {
  background: none;
  border: 0;
  padding: 7px 10px;
  text-align: left;
  color: var(--text);
  border-radius: var(--radius-sm);
  text-decoration: none;
  font: inherit;
}
.conv-menu button:hover, .conv-menu a:hover { background: var(--bg-secondary); text-decoration: none; }
.conv-menu .danger { color: var(--danger); }

.conv-empty { padding: 20px 10px; color: var(--text-muted); font-size: 13px; text-align: center; }

.sidebar-bottom { padding: 10px 10px 14px; border-top: 1px solid var(--border); }
.upgrade-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  margin-bottom: 8px;
  text-decoration: none;
}
.upgrade-pill:hover { background: var(--bg-tertiary); text-decoration: none; }

.user-menu-wrap { position: relative; }
.user-menu-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text);
  text-align: left;
}
.user-menu-btn:hover { background: var(--bg-tertiary); }
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 13px;
  text-transform: uppercase;
  flex-shrink: 0;
}
.user-name {
  flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: 14px;
}
.tier-badge {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 999px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.tier-free { background: var(--bg-tertiary); color: var(--text-muted); }
.tier-premium { background: var(--accent); color: #fff; }

.user-menu {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px;
  display: flex;
  flex-direction: column;
  font-size: 14px;
}
.user-menu a, .user-menu button {
  padding: 8px 10px;
  color: var(--text);
  border-radius: var(--radius-sm);
  text-decoration: none;
  background: none;
  border: 0;
  text-align: left;
  font: inherit;
}
.user-menu a:hover, .user-menu button:hover { background: var(--bg-secondary); text-decoration: none; }

/* =========================================================
   Main chat area
   ========================================================= */

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.hamburger {
  display: none;
  background: none;
  border: 0;
  color: var(--text);
  padding: 8px;
  border-radius: var(--radius-sm);
}
.hamburger:hover { background: var(--bg-tertiary); }
.chat-title {
  flex: 1;
  font-size: 15px;
  font-weight: 500;
  margin: 0;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  outline: none;
}
.chat-title:hover, .chat-title:focus { background: var(--bg-secondary); }
.header-right { display: flex; align-items: center; gap: 8px; }
[hidden] { display: none !important; }

/* Compare toggle (header) */
.compare-toggle-group { position: relative; }
.compare-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  font: inherit; font-size: 12.5px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
.compare-toggle:hover { background: var(--bg-secondary); }
.compare-toggle[aria-expanded="true"] { background: var(--bg-secondary); }
.compare-toggle.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.compare-toggle.is-active:hover { filter: brightness(1.05); }
.compare-toggle-label { line-height: 1; }
.compare-toggle-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px;
  background: rgba(255,255,255,0.25);
  font-size: 11px; font-weight: 600;
}
.compare-toggle:not(.is-active) .compare-toggle-count { background: var(--bg-secondary); color: var(--text); }
@media (max-width: 560px) {
  .compare-toggle-label { display: none; }
}

/* Custom model picker */
.model-picker { position: relative; }
.model-picker-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 10px 6px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.model-picker-btn:hover { background: var(--bg-secondary); }
.model-picker-btn[aria-expanded="true"] { background: var(--bg-secondary); }
.model-picker-caret { opacity: 0.65; transition: transform 150ms ease; }
.model-picker-btn[aria-expanded="true"] .model-picker-caret { transform: rotate(180deg); }
.model-picker-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 24px;
  width: min(280px, calc(100vw - 24px));
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  padding: 6px;
  z-index: 40;
  max-height: min(60vh, calc(100vh - var(--header-h) - 24px));
  overflow-y: auto;
}
@media (max-width: 640px) {
  .model-picker-panel {
    position: fixed;
    top: calc(var(--header-h) + 6px);
    right: 12px;
    left: auto;
    width: min(320px, calc(100vw - 24px));
  }
}
.model-picker-group {
  padding: 10px 10px 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.model-opt {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  text-align: left;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.model-opt:hover { background: var(--bg-secondary); }
.model-opt.is-selected { background: var(--bg-secondary); font-weight: 500; }
.model-opt.is-locked { color: var(--text-muted); cursor: pointer; }
.model-opt-badge { font-size: 11px; color: var(--text-muted); display: inline-flex; align-items: center; gap: 6px; }
.vision-chip {
  display: inline-flex; align-items: center;
  padding: 2px 6px;
  font-size: 10px; font-weight: 600;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  letter-spacing: 0.02em;
}

/* Attach popover */
.attach-group { position: relative; }
.attach-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  min-width: 180px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  padding: 4px;
  z-index: 40;
}
.attach-opt {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  text-align: left;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.attach-opt:hover { background: var(--bg-secondary); }

.tools-group { position: relative; }

/* Compare popover */
.compare-group, .compare-toggle-group { position: relative; }
.compare-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  left: auto;
  width: min(320px, calc(100vw - 24px));
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0,0,0,0.14);
  padding: 14px;
  z-index: 40;
  max-height: min(70vh, calc(100vh - var(--header-h) - 24px));
  overflow-y: auto;
  box-sizing: border-box;
}
[data-theme="dark"] .compare-menu { box-shadow: 0 12px 32px rgba(0,0,0,0.5); }
.compare-opt { min-width: 0; }
.compare-opt-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compare-menu-actions { display: flex; justify-content: flex-end; gap: 6px; flex-wrap: wrap; }
@media (max-width: 640px) {
  .compare-menu {
    position: fixed;
    top: calc(var(--header-h) + 6px);
    left: 12px;
    right: 12px;
    width: auto;
  }
}
[data-theme="dark"] .compare-menu { box-shadow: 0 12px 32px rgba(0,0,0,0.5); }
.compare-menu-title { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.compare-menu-hint { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
.compare-list { display: flex; flex-direction: column; gap: 4px; max-height: 240px; overflow-y: auto; margin-bottom: 10px; }
.compare-opt {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
.compare-opt:hover { background: var(--bg-secondary); }
.compare-opt.is-locked { color: var(--text-muted); cursor: not-allowed; }
.compare-opt input { margin: 0; accent-color: var(--accent); }
.compare-opt-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compare-opt-badge { font-size: 11px; color: var(--text-muted); text-transform: capitalize; flex-shrink: 0; }
.compare-menu-actions { display: flex; justify-content: flex-end; gap: 6px; flex-wrap: wrap; }
#btn-compare.is-active { color: var(--accent); background: var(--bg-secondary); }

/* Compare result grid */
.compare-result { margin-top: 4px; }
.compare-head { margin-bottom: 8px; }
.compare-head-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.compare-card-usage { font-size: 10px; font-weight: 400; color: var(--text-muted); margin-left: auto; }
.compare-synth-head { font-size: 11px; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px; }
.compare-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
}
.compare-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--bg);
  display: flex; flex-direction: column; gap: 6px;
  min-width: 0;
}
.compare-card-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; font-weight: 600; color: var(--text);
  padding-bottom: 6px; border-bottom: 1px solid var(--border);
}
.compare-card-head .chip { font-size: 10px; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.compare-card-body { font-size: 13.5px; line-height: 1.55; overflow-wrap: anywhere; }
.compare-card-body p:first-child { margin-top: 0; }
.compare-card-body p:last-child { margin-bottom: 0; }
.compare-card.is-error .compare-card-body { color: #b91c1c; font-size: 13px; }
.compare-synth-wrap { margin-top: 10px; display: flex; justify-content: flex-end; gap: 8px; }
.compare-synth-out {
  margin-top: 10px;
  border-left: 3px solid var(--accent);
  padding: 10px 14px;
  background: var(--bg-secondary);
  border-radius: 0 8px 8px 0;
  font-size: 14.5px;
  line-height: 1.6;
}

/* Compare: per-model chat bubbles */
.msg-compare .msg-body {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  background: var(--bg);
}
.msg-compare.is-error .msg-body { border-color: #fecaca; background: rgba(254,226,226,0.25); }
[data-theme="dark"] .msg-compare.is-error .msg-body { border-color: #7f1d1d; background: rgba(127,29,29,0.2); }
.msg-compare.is-preferred .msg-body { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.msg-compare.is-combined .msg-body {
  border-left: 3px solid var(--accent);
  background: var(--bg-secondary);
}
.compare-bubble-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 11.5px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.04em;
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--border);
}
.compare-bubble-label { color: var(--text); letter-spacing: 0.02em; text-transform: none; font-size: 13px; }
.compare-bubble-usage { margin-left: auto; font-weight: 400; }
.compare-bubble-usage .chip { font-size: 10px; color: var(--text-muted); }
.compare-bubble-preferred {
  margin-left: auto;
  font-size: 10px; font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.06em;
}
.compare-bubble-actions {
  display: flex; gap: 6px; justify-content: flex-end;
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}
.compare-combine-row {
  display: flex; justify-content: center;
  margin: 4px 0 8px;
}

.chat-scroll { flex: 1; overflow-y: auto; padding: 32px 16px 180px; }
.messages { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 28px; }

.empty-state { text-align: center; padding: 60px 16px; }
.empty-state h2 { font-size: 26px; font-weight: 500; margin: 0 0 24px; letter-spacing: -0.01em; }
.prompt-suggestions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
  max-width: 680px;
  margin: 0 auto;
}
.prompt-chip {
  text-align: left;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}
.prompt-chip:hover { background: var(--bg-secondary); }

.msg { display: flex; gap: 12px; }
.msg-user { flex-direction: row-reverse; }
.msg-assistant .msg-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--bg-tertiary); color: var(--text);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 12px;
  flex-shrink: 0;
}
.msg-body {
  max-width: 100%;
  min-width: 0;
}
.msg-user .msg-body {
  background: var(--bg-secondary);
  padding: 10px 14px;
  border-radius: 16px 16px 2px 16px;
  max-width: 80%;
}
.msg-assistant .msg-body { font-size: 16px; }
.msg-content p { margin: 0 0 12px; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content h1, .msg-content h2, .msg-content h3 {
  margin: 20px 0 8px;
  line-height: 1.3;
}
.msg-content h1 { font-size: 22px; }
.msg-content h2 { font-size: 18px; }
.msg-content h3 { font-size: 16px; }
.msg-content ul, .msg-content ol { margin: 8px 0 12px; padding-left: 24px; }
.msg-content li { margin: 4px 0; }
.msg-content pre {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  padding: 12px 14px;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 10px 0;
}
.msg-content code {
  background: var(--bg-secondary);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 0.92em;
}
.msg-content pre code { background: none; padding: 0; }
.msg-content blockquote {
  border-left: 3px solid var(--border);
  margin: 10px 0;
  padding: 4px 0 4px 14px;
  color: var(--text-muted);
}
.msg-content a { color: var(--accent); }
.msg-content hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }

.msg-attachment {
  max-width: 280px;
  max-height: 280px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: 8px;
}

.msg-actions { display: flex; gap: 6px; margin-top: 8px; opacity: 0; transition: opacity 0.15s; }
.msg:hover .msg-actions { opacity: 1; }
.msg-action {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-size: 12px;
}
.msg-action:hover { background: var(--bg-secondary); color: var(--text); }

/* File cards */
.file-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 10px;
  max-width: 420px;
}
.file-card:hover { background: var(--bg-secondary); }
.file-icon { color: var(--accent); flex-shrink: 0; width: 28px; height: 28px; }
.file-meta { flex: 1; min-width: 0; }
.file-name {
  font-weight: 500; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.file-info { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* Tables in messages */
.table-wrap { overflow-x: auto; margin: 12px 0; }
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { background: var(--bg-secondary); font-weight: 600; font-size: 13px; }
tr:last-child td { border-bottom: 0; }
tr:nth-child(even) td { background: var(--bg-secondary); }

/* =========================================================
   Composer
   ========================================================= */

.composer-wrap {
  position: sticky;
  bottom: 0;
  background: linear-gradient(180deg, transparent, var(--bg) 24px);
  padding: 12px 16px 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
}
.attachments-preview {
  max-width: 760px;
  margin: 0 auto 8px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.att-thumb {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}
.att-thumb img { width: 100%; height: 100%; object-fit: cover; }
.att-thumb button {
  position: absolute;
  top: 2px; right: 2px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  border: 0;
  width: 18px; height: 18px;
  border-radius: 50%;
  font-size: 12px;
  line-height: 1;
  display: flex; align-items: center; justify-content: center;
}

.composer {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--bg);
  box-shadow: 0 1px 3px rgba(0,0,0,0.02);
}
.composer-icon {
  background: none;
  border: 0;
  color: var(--text-muted);
  padding: 8px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}
.composer-icon:hover { background: var(--bg-secondary); color: var(--text); }
.composer-icon.is-active { color: var(--accent); background: rgba(79, 70, 229, 0.1); }
.composer textarea {
  flex: 1;
  padding: 8px 8px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  line-height: 1.5;
  resize: none;
  max-height: 200px;
  min-height: 24px;
  outline: none;
}
.btn-send {
  background: var(--accent);
  color: #fff;
  border: 0;
  padding: 8px;
  border-radius: 50%;
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.btn-send:hover { background: var(--accent-hover); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

.composer-footer {
  max-width: 760px;
  margin: 6px auto 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  color: var(--text-muted);
}

.slash-menu {
  position: absolute;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  min-width: 320px;
  max-width: 90vw;
  max-height: 280px;
  overflow-y: auto;
  z-index: 30;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.slash-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  background: none;
  border: 0;
  color: var(--text);
  border-radius: var(--radius-sm);
  font: inherit;
}
.slash-menu button:hover, .slash-menu button.is-active { background: var(--bg-secondary); }

/* =========================================================
   Modals & toasts
   ========================================================= */

.modal {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  max-width: 420px;
  width: 90vw;
  background: var(--bg);
  color: var(--text);
}
.modal::backdrop { background: rgba(0,0,0,0.45); backdrop-filter: blur(4px); }
.modal-body { padding: 28px 24px; }
.modal-body h2 { margin: 0 0 10px; font-size: 22px; }
.price { font-size: 30px; font-weight: 600; margin-bottom: 6px; }
.price-per { font-size: 14px; color: var(--text-muted); font-weight: 400; }
.benefits { padding-left: 20px; margin: 14px 0 22px; color: var(--text-muted); font-size: 14px; }
.benefits li { margin-bottom: 6px; }
.modal-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }

/* Minimal dialog (alert / confirm / prompt) */
.mini-dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0;
  max-width: 380px;
  width: 92vw;
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 24px 64px rgba(0,0,0,0.22);
  animation: mini-pop 120ms ease-out;
}
[data-theme="dark"] .mini-dialog { box-shadow: 0 24px 64px rgba(0,0,0,0.6); }
.mini-dialog::backdrop { background: rgba(10,10,12,0.45); backdrop-filter: blur(4px); }
.mini-dialog-body { padding: 22px 22px 16px; }
.mini-dialog-title { font-size: 16px; font-weight: 600; margin: 0 0 6px; letter-spacing: -0.005em; }
.mini-dialog-msg { font-size: 14px; color: var(--text-muted); line-height: 1.5; margin: 0; white-space: pre-wrap; word-break: break-word; }
.mini-dialog-input {
  width: 100%;
  margin-top: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  outline: none;
}
.mini-dialog-input:focus { border-color: var(--accent); }
.mini-dialog-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 10px 16px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  border-bottom-left-radius: 14px;
  border-bottom-right-radius: 14px;
}
.mini-dialog-btn {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  min-width: 68px;
}
.mini-dialog-btn.is-cancel { border-color: var(--border); }
.mini-dialog-btn.is-cancel:hover { background: var(--bg); }
.mini-dialog-btn.is-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.mini-dialog-btn.is-primary:hover { filter: brightness(1.05); }
.mini-dialog-btn.is-danger { background: #dc2626; color: #fff; border-color: #dc2626; }
.mini-dialog-btn.is-danger:hover { filter: brightness(1.05); }
@keyframes mini-pop { from { opacity: 0; transform: translateY(-6px) scale(0.98); } to { opacity: 1; transform: none; } }

.toast {
  position: fixed;
  bottom: 20px; left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* =========================================================
   Settings & upgrade pages
   ========================================================= */

.settings-layout, .admin-layout, .upgrade-layout {
  display: flex;
  min-height: 100vh;
  max-width: 1100px;
  margin: 0 auto;
}
.settings-nav, .admin-nav {
  width: 220px;
  padding: 24px 16px;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}
.settings-nav h2, .admin-nav h2 { font-size: 18px; margin: 0 0 12px; }
.settings-nav nav, .admin-nav nav { display: flex; flex-direction: column; gap: 2px; }
.settings-nav a, .admin-nav a {
  padding: 8px 12px;
  color: var(--text);
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
}
.settings-nav a:hover, .admin-nav a:hover { background: var(--bg-secondary); text-decoration: none; }
.settings-nav a.is-active, .admin-nav a.is-active { background: var(--bg-tertiary); font-weight: 500; }
.settings-back { display: block; color: var(--text-muted); font-size: 13px; margin-bottom: 20px; }
.settings-back:hover { text-decoration: none; color: var(--text); }

.settings-panel, .admin-panel {
  flex: 1;
  padding: 32px;
  min-width: 0;
}
.settings-panel h1, .admin-panel h1 { margin: 0 0 24px; font-size: 26px; letter-spacing: -0.01em; }
.settings-panel h2, .admin-panel h2 { margin: 28px 0 12px; font-size: 16px; }
.settings-panel hr, .admin-panel hr { border: 0; border-top: 1px solid var(--border); margin: 28px 0; }
.settings-panel .danger { color: var(--danger); }
.form { max-width: 460px; }
.profile-info {
  padding: 12px 14px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin: 16px 0;
  display: flex; flex-direction: column; gap: 4px;
}

.upgrade-layout {
  display: block;
  padding: 40px 24px;
  max-width: 520px;
  margin: 0 auto;
}
.upgrade-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  margin-top: 16px;
}
.reference-code {
  font-size: 16px; letter-spacing: 0.05em;
  background: var(--bg-secondary); padding: 10px 14px;
  border-radius: var(--radius-sm); margin: 14px 0;
}
.status-box {
  margin: 20px 0;
  padding: 14px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
}

/* Usage */
.usage-card { padding: 16px; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 20px; }
.usage-label { font-size: 13px; color: var(--text-muted); margin-bottom: 8px; }
.usage-numbers { margin-top: 8px; font-weight: 600; }
.progress { height: 8px; background: var(--bg-tertiary); border-radius: 4px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--accent); transition: width 0.3s; }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-row.wrap { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.stat { padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); }
.stat-num { font-size: 22px; font-weight: 600; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.card {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.card h3 { margin: 0 0 12px; font-size: 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }

.simple-list { list-style: none; padding: 0; margin: 0; font-size: 14px; }
.simple-list li { padding: 6px 0; display: flex; justify-content: space-between; border-bottom: 1px solid var(--border); }
.simple-list li:last-child { border-bottom: 0; }
.muted { color: var(--text-muted); }

.toolbar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; align-items: flex-end; }
.toolbar input, .toolbar select { padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); color: var(--text); font: inherit; }
.toolbar label { display: flex; flex-direction: column; font-size: 12px; color: var(--text-muted); margin: 0; }

.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.tabs a { padding: 8px 14px; color: var(--text-muted); text-decoration: none; font-size: 14px; border-bottom: 2px solid transparent; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.is-active { color: var(--text); border-bottom-color: var(--accent); font-weight: 500; }

.inline-form { display: inline-flex; align-items: center; gap: 4px; }

.users-table th, .users-table td { font-size: 13px; }

.pager { display: flex; gap: 4px; margin-top: 16px; }
.pager a { padding: 5px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); font-size: 13px; }
.pager a.is-active { background: var(--bg-tertiary); }

.msgs-preview { max-height: 70vh; overflow-y: auto; font-size: 13px; }
.msg-pre { padding: 10px 0; border-bottom: 1px solid var(--border); }

/* =========================================================
   Responsive
   ========================================================= */

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 50;
    width: min(300px, 85vw);
    min-width: 0;
    transform: translateX(-100%);
    box-shadow: 2px 0 16px rgba(0,0,0,0.18);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-close { display: inline-flex; }
  .sidebar-top { padding-right: 52px; }
  #sidebar-scrim {
    display: none;
  }
  body.sidebar-open #sidebar-scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 40;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
  .hamburger { display: inline-flex; }

  .chat-header {
    padding: 0 8px;
    gap: 6px;
  }
  .chat-title {
    font-size: 14px;
    padding: 4px 6px;
  }
  .header-right { gap: 4px; }
  .compare-toggle { padding: 6px 8px; font-size: 12px; }
  .compare-toggle-label { display: none; }
  .model-picker-btn {
    padding: 6px 8px 6px 10px;
    font-size: 12.5px;
    max-width: 140px;
  }
  .model-picker-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: inline-block;
    max-width: 110px;
    vertical-align: middle;
  }

  .chat-scroll { padding: 16px 12px 170px; }
  .messages { gap: 20px; }
  .empty-state { padding: 32px 8px; }
  .empty-state h2 { font-size: 22px; margin-bottom: 18px; }
  .prompt-suggestions { grid-template-columns: 1fr; gap: 8px; }
  .prompt-chip { padding: 12px 14px; font-size: 13.5px; }
  .msg-user .msg-body { max-width: 88%; }
  .msg-assistant .msg-body { font-size: 15px; }
  .msg-attachment { max-width: 100%; max-height: 240px; }
  .msg-content h1 { font-size: 20px; }
  .msg-content h2 { font-size: 17px; }
  .msg-content pre { font-size: 12.5px; padding: 10px 12px; }
  .file-card { max-width: 100%; }
  .msg-actions { opacity: 1; }

  .composer-wrap { padding: 8px 10px max(14px, env(safe-area-inset-bottom)); }
  .composer { padding: 6px; border-radius: 16px; gap: 4px; }
  .composer-icon { padding: 8px; }
  .composer textarea { font-size: 16px; /* prevent iOS zoom */ }
  .composer-footer { font-size: 11.5px; gap: 8px; margin-top: 4px; }
  .footer-hint { display: none; }
  .composer-footer { justify-content: flex-end; }

  .landing-footer-inner { flex-direction: column; text-align: center; }

  .settings-layout, .admin-layout, .upgrade-layout { flex-direction: column; max-width: 100%; }
  .settings-nav, .admin-nav {
    width: 100%;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
  }
  .settings-nav h2, .admin-nav h2 { font-size: 15px; margin-bottom: 8px; }
  .settings-nav nav, .admin-nav nav {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .settings-nav nav::-webkit-scrollbar,
  .admin-nav nav::-webkit-scrollbar { display: none; }
  .settings-nav a, .admin-nav a { white-space: nowrap; flex-shrink: 0; }
  .settings-panel, .admin-panel { padding: 20px 16px; }
  .settings-panel h1, .admin-panel h1 { font-size: 22px; margin-bottom: 18px; }
  .form { max-width: 100%; }

  /* Admin tables overflow on mobile */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-wrap table { min-width: 560px; }
  th, td { padding: 6px 8px; font-size: 12.5px; }

  .stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat { padding: 12px; }
  .stat-num { font-size: 18px; }

  .toolbar { gap: 6px; }
  .toolbar input, .toolbar select { font-size: 14px; }

  .modal, .mini-dialog { width: 94vw; border-radius: 14px; }
  .modal-body { padding: 22px 18px; }

  .upgrade-layout { padding: 24px 16px; }
  .upgrade-card { padding: 24px 18px; }

  .slash-menu {
    left: 12px;
    right: 12px;
    transform: none;
    min-width: 0;
    max-width: none;
    width: calc(100vw - 24px);
  }

  /* Tap target safety */
  .btn, .btn-sm, .conv-link, .conv-menu-btn, .user-menu-btn {
    min-height: 40px;
  }
  .btn-sm { min-height: 34px; }
}

@media (max-width: 420px) {
  .chat-title { max-width: 140px; }
  .model-picker-btn { max-width: 120px; }
  .model-picker-label { max-width: 92px; }
  .pricing-amount { font-size: 30px; }
}
