/* ==========================================================================
   InstantAI Web — Production Design System
   Match: iOS Athletic Native / Electric Cyan / Lightning
   ========================================================================== */

/* ---------- Design Tokens ---------- */
:root {
  /* Core palette (from Color+Extensions.swift) */
  --instant-black: #040812;
  --instant-white: #F0F6FF;
  --instant-accent: #00D9FF;
  --instant-cyan-glow: #5CE7FF;
  --instant-deep-blue: #051829;
  --instant-electric-haze: #0B2433;
  --instant-cold-black: #07101C;
  --instant-cold-black-elev: #0F1B2B;
  --instant-secondary: #8FA0B5;
  --instant-muted: #556377;
  --instant-success: #22E3AE;
  --instant-error: #FF3B5C;
  --instant-warning: #FFB340;

  /* Surfaces */
  --bg: #040812;
  --card: #0F1B2B;
  --card-elevated: #17263A;
  --divider: #1E2D42;
  --divider-subtle: rgba(255, 255, 255, 0.06);

  /* Text */
  --text-primary: #F0F6FF;
  --text-secondary: #8FA0B5;
  --text-muted: #556377;

  /* Accent */
  --accent: #00D9FF;
  --accent-glow: #5CE7FF;
  --accent-dim: rgba(0, 217, 255, 0.12);
  --accent-medium: rgba(0, 217, 255, 0.20);

  /* Radii (from DesignSystem.swift) */
  --radius-card: 24px;
  --radius-button: 18px;
  --radius-pill: 999px;
  --radius-tile: 20px;
  --radius-sheet: 32px;

  /* Spacing (from DesignSystem.swift) */
  --screen-pad: 20px;
  --section-gap: 32px;
  --card-pad: 20px;
  --card-gap: 12px;

  /* Button heights */
  --btn-h-primary: 58px;
  --btn-h-secondary: 48px;
  --btn-h-compact: 40px;

  /* Message spacing */
  --msg-h-pad: 16px;
  --msg-v-pad: 12px;
  --msg-gap: 20px;

  /* Motion (CSS cubic-bezier approximations of SwiftUI springs) */
  --motion-quick: cubic-bezier(0.34, 0.80, 0.64, 1);
  --motion-responsive: cubic-bezier(0.34, 1.20, 0.64, 1);
  --motion-smooth: cubic-bezier(0.34, 0.80, 0.64, 1);
  --motion-dramatic: cubic-bezier(0.34, 1.40, 0.64, 1);
  --motion-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --motion-punchy: cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Fonts */
  --font-body: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", system-ui, sans-serif;
  --font-rounded: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-mono: "SF Mono", ui-monospace, Monaco, "Cascadia Code", "Courier New", monospace;

  /* Safe areas */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ---------- Reset ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overflow-x: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 17px;
  font-weight: 400;
  line-height: 1.47;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
}

/* ---------- App Shell ---------- */
#app {
  width: 100%;
  height: 100%;
  height: 100dvh;
  position: relative;
  overflow: hidden;
  overflow-x: hidden;
  background: var(--bg);
}

/* Desktop: two-panel layout */
@media (min-width: 768px) {
  #app {
    display: flex;
    flex-direction: row;
    max-width: 100%;
    margin: 0;
    border: none;
  }
}

/* ---------- Typography (match DesignSystem.swift) ---------- */
.t-hero-numeral { font-size: 156px; font-weight: 800; font-family: var(--font-rounded); line-height: 1; }
.t-display-numeral { font-size: 96px; font-weight: 800; font-family: var(--font-rounded); line-height: 1; }
.t-large-numeral { font-size: 64px; font-weight: 800; font-family: var(--font-rounded); line-height: 1; }
.t-medium-numeral { font-size: 44px; font-weight: 800; font-family: var(--font-rounded); line-height: 1; }
.t-small-numeral { font-size: 28px; font-weight: 700; font-family: var(--font-rounded); line-height: 1; }
.t-mega { font-size: 56px; font-weight: 800; font-family: var(--font-rounded); line-height: 1.05; }
.t-title { font-size: 38px; font-weight: 800; font-family: var(--font-rounded); line-height: 1.1; }
.t-section { font-size: 24px; font-weight: 700; font-family: var(--font-rounded); line-height: 1.2; }
.t-card-title { font-size: 17px; font-weight: 600; font-family: var(--font-rounded); }
.t-eyebrow {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1.8px;
  color: var(--text-secondary);
}
.t-eyebrow-lg {
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1.8px;
  color: var(--text-secondary);
}
.t-body { font-size: 17px; font-weight: 400; }
.t-body-em { font-size: 17px; font-weight: 600; }
.t-subtitle { font-size: 15px; font-weight: 500; }
.t-caption { font-size: 13px; font-weight: 400; color: var(--text-secondary); }
.t-caption-em { font-size: 13px; font-weight: 600; }
.t-micro { font-size: 11px; font-weight: 500; }
.t-speed {
  font-size: 14px;
  font-weight: 800;
  font-family: var(--font-rounded);
  color: var(--accent);
}

/* ---------- Glass Material ---------- */
.glass {
  background: rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 0.5px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-card);
}

.glass-elevated {
  background: rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 0.5px solid rgba(255, 255, 255, 0.10);
  border-radius: var(--radius-card);
}

/* ---------- Atmospheric Background ---------- */
.atmosphere {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.atmosphere::before {
  content: '';
  position: absolute;
  top: -40%;
  left: -20%;
  width: 140%;
  height: 80%;
  background: radial-gradient(ellipse at center, rgba(0, 217, 255, 0.06) 0%, transparent 70%);
  animation: atmosphereFloat 20s ease-in-out infinite alternate;
}

.atmosphere::after {
  content: '';
  position: absolute;
  bottom: -30%;
  right: -20%;
  width: 100%;
  height: 60%;
  background: radial-gradient(ellipse at center, rgba(5, 24, 41, 0.8) 0%, transparent 70%);
}

@keyframes atmosphereFloat {
  from { transform: translateY(0) scale(1); }
  to { transform: translateY(20px) scale(1.05); }
}

/* ---------- Buttons ---------- */
button {
  border: none;
  background: none;
  cursor: pointer;
  font-family: inherit;
  color: inherit;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-rounded);
  transition: transform 0.2s var(--motion-quick), opacity 0.2s ease, box-shadow 0.3s ease;
}

.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.4; cursor: default; pointer-events: none; }

.btn-primary {
  background: var(--accent);
  color: var(--instant-black);
  border-radius: var(--radius-button);
  height: var(--btn-h-primary);
  font-size: 17px;
  font-weight: 700;
  padding: 0 28px;
  width: 100%;
  max-width: 360px;
}

.btn-primary:hover:not(:disabled) {
  box-shadow: 0 0 24px rgba(0, 217, 255, 0.3);
}

.btn-secondary {
  background: var(--card);
  color: var(--text-primary);
  border-radius: var(--radius-button);
  height: var(--btn-h-secondary);
  padding: 0 20px;
  font-size: 15px;
  font-weight: 600;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-button);
  height: var(--btn-h-secondary);
  padding: 0 16px;
  font-size: 15px;
  font-weight: 500;
}

/* Icon buttons */
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  color: var(--text-primary);
  transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn:active { background: rgba(255, 255, 255, 0.06); }
.icon-btn:hover { background: rgba(255, 255, 255, 0.06); }
.icon-btn svg { width: 22px; height: 22px; }

.icon-btn-sm {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  color: var(--text-secondary);
  transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn-sm:active { background: rgba(255, 255, 255, 0.06); }
.icon-btn-sm:hover { background: rgba(255, 255, 255, 0.06); color: var(--text-primary); }
.icon-btn-sm svg { width: 18px; height: 18px; }

/* ---------- Screens ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
   ONBOARDING
   ========================================================================== */
.onb-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  height: 100dvh;
  width: 100%;
  padding: var(--safe-top) var(--screen-pad) 0;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}

/* Desktop: center onboarding content */
@media (min-width: 768px) {
  .onb-screen {
    padding: 60px 40px 0;
  }
  .onb-body {
    max-width: 560px;
    width: 100%;
  }
  .onb-footer {
    max-width: 560px;
    width: 100%;
  }
  .welcome-title {
    font-size: 56px !important;
  }
  .welcome-sub {
    font-size: 18px !important;
    max-width: 480px;
  }
  .btn-primary {
    max-width: 400px;
  }
  .speed-compare {
    max-width: 560px;
    width: 100%;
  }
}

.onb-atmosphere {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.onb-atmosphere::before {
  content: '';
  position: absolute;
  top: 10%;
  left: 50%;
  transform: translateX(-50%);
  width: 300px;
  height: 300px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(0, 217, 255, 0.12) 0%, transparent 70%);
  filter: blur(60px);
}

.onb-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  position: relative;
  z-index: 1;
}

.onb-footer {
  padding: 20px 0 max(32px, calc(32px + env(safe-area-inset-bottom, 0px)));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  position: relative;
  z-index: 1;
}

/* Page dots */
.page-dots {
  display: flex;
  gap: 8px;
}

.page-dots .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: all 0.3s var(--motion-smooth);
}

.page-dots .dot.active {
  width: 24px;
  border-radius: 3px;
  background: var(--accent);
}

/* Onboarding: Welcome screen */
.welcome-hero {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.welcome-bolt {
  width: 72px;
  height: 72px;
  color: var(--accent);
  filter: drop-shadow(0 0 20px rgba(0, 217, 255, 0.4));
  animation: boltFloat 3s ease-in-out infinite;
}

.welcome-bolt svg {
  width: 72px;
  height: 72px;
}

@keyframes boltFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.welcome-title {
  font-size: 36px;
  font-weight: 800;
  font-family: var(--font-rounded);
  line-height: 1.1;
  background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent) 60%, var(--accent-glow) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-sub {
  font-size: 17px;
  color: var(--text-secondary);
  max-width: 300px;
  line-height: 1.5;
}

/* Onboarding: Speed comparison */
.speed-compare {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  text-align: center;
}

.speed-compare-title {
  font-size: 22px;
  font-weight: 700;
  font-family: var(--font-rounded);
  color: var(--text-primary);
}

.compare-rows {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.compare-row {
  background: var(--card);
  border-radius: 16px;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.compare-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.compare-text {
  font-size: 18px;
  font-weight: 600;
  min-height: 28px;
  text-align: left;
}

.compare-text.slow {
  color: var(--text-secondary);
}

.compare-text.fast {
  color: var(--accent);
}

.compare-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-dim);
  color: var(--accent);
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  font-size: 15px;
  font-weight: 700;
  font-family: var(--font-rounded);
  margin-top: 8px;
  align-self: center;
  opacity: 0;
  transform: scale(0.8);
  transition: all 0.4s var(--motion-spring);
}

.compare-badge.visible {
  opacity: 1;
  transform: scale(1);
}

/* Onboarding: CTA screen */
.cta-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}

.cta-bolt {
  width: 88px;
  height: 88px;
  color: var(--accent);
  filter: drop-shadow(0 0 30px rgba(0, 217, 255, 0.5));
}

.cta-bolt svg {
  width: 88px;
  height: 88px;
}

.cta-title {
  font-size: 32px;
  font-weight: 800;
  font-family: var(--font-rounded);
  color: var(--text-primary);
}

.cta-sub {
  font-size: 17px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.btn-cta {
  animation: ctaGlow 2s ease-in-out infinite alternate;
}

@keyframes ctaGlow {
  from { box-shadow: 0 0 0 rgba(0, 217, 255, 0.2); }
  to { box-shadow: 0 0 30px rgba(0, 217, 255, 0.4); }
}

/* ==========================================================================
   CHAT VIEW
   ========================================================================== */
.chat-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  position: relative;
  width: 100%;
}

/* Desktop: chat fills remaining space next to sidebar */
@media (min-width: 768px) {
  .chat-view {
    flex: 1;
    min-width: 0;
    width: auto;
    height: 100%;
  }
}

/* Top bar */
.chat-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  padding: var(--safe-top) 8px 0;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
  border-bottom: 0.5px solid var(--divider-subtle);
  background: rgba(4, 8, 18, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

/* Desktop: hide hamburger, adjust topbar */
@media (min-width: 768px) {
  .chat-topbar {
    padding: 0 16px;
    min-height: 56px;
  }

  #btnHamburger {
    display: none;
  }
}

.mode-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.06);
  border: 0.5px solid rgba(255, 255, 255, 0.08);
  padding: 7px 16px;
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-rounded);
  color: var(--text-primary);
  transition: all 0.2s var(--motion-quick);
}

.mode-pill:active { transform: scale(0.95); background: rgba(255, 255, 255, 0.10); }
.mode-pill:hover { background: rgba(255, 255, 255, 0.10); }
.mode-pill .mode-emoji { font-size: 14px; }

/* Message list */
.message-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 0;
  display: flex;
  flex-direction: column;
  gap: var(--msg-gap);
  scroll-behavior: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Desktop: center messages at comfortable reading width */
@media (min-width: 768px) {
  .message-list {
    padding: 24px 0;
    gap: 24px;
  }

  .message-user,
  .message-assistant {
    max-width: 760px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    padding-left: 24px;
    padding-right: 24px;
  }

  .empty-chat {
    max-width: 760px;
    margin: 0 auto;
  }
}

/* User messages */
.message-user {
  padding: 0 var(--screen-pad);
  display: flex;
  justify-content: flex-end;
  animation: msgSlideUp 0.3s var(--motion-smooth);
  position: relative;
}

.user-bubble {
  background: rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 0.5px solid rgba(255, 255, 255, 0.08);
  padding: var(--msg-v-pad) var(--msg-h-pad);
  border-radius: 18px 18px 4px 18px;
  max-width: 85%;
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: break-word;
  white-space: pre-wrap;
  font-size: 16px;
  line-height: 1.45;
  color: var(--text-primary);
}

/* Assistant messages */
.message-assistant {
  padding: 0 var(--screen-pad);
  position: relative;
  animation: msgFadeIn 0.2s ease-out;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

@keyframes msgSlideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes msgFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Assistant text (markdown rendered) */
.assistant-text {
  color: var(--text-primary);
  font-size: 16.5px;
  line-height: 1.55;
  overflow-wrap: break-word;
  word-break: break-word;
  min-width: 0;
}

.assistant-text p { margin: 0 0 12px; }
.assistant-text p:last-child { margin-bottom: 0; }
.assistant-text ul, .assistant-text ol { margin: 0 0 12px 20px; }
.assistant-text li { margin-bottom: 4px; }
.assistant-text li::marker { color: var(--text-muted); }
.assistant-text strong { font-weight: 600; color: var(--text-primary); }
.assistant-text em { font-style: italic; }

.assistant-text code {
  font-family: var(--font-mono);
  font-size: 14px;
  background: rgba(0, 217, 255, 0.08);
  color: var(--accent);
  padding: 2px 6px;
  border-radius: 5px;
  word-break: break-all;
}

.assistant-text pre {
  background: rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 0.5px solid rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  padding: 14px 16px;
  margin: 8px 0 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
  max-width: 100%;
}

/* When code block has a language label, add top padding */
.code-block-wrap .assistant-text pre,
.code-block-wrap pre {
  padding-top: 32px;
}

.assistant-text pre code {
  background: transparent;
  padding: 0;
  color: var(--text-primary);
  font-size: 13px;
  line-height: 1.55;
}

.assistant-text img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

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

.assistant-text blockquote {
  border-left: 3px solid var(--accent);
  padding: 0 0 0 14px;
  margin: 0 0 12px;
  color: var(--text-secondary);
}

.assistant-text h1 { font-size: 22px; font-weight: 700; margin: 16px 0 8px; }
.assistant-text h2 { font-size: 19px; font-weight: 700; margin: 14px 0 8px; }
.assistant-text h3 { font-size: 17px; font-weight: 600; margin: 12px 0 6px; }
.assistant-text h4 { font-size: 16px; font-weight: 600; margin: 10px 0 6px; }

.assistant-text hr {
  border: none;
  border-top: 0.5px solid var(--divider-subtle);
  margin: 16px 0;
}

.assistant-text table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0 12px;
  font-size: 14px;
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.assistant-text th, .assistant-text td {
  padding: 8px 12px;
  border: 0.5px solid var(--divider);
  text-align: left;
}

.assistant-text th {
  background: var(--card);
  font-weight: 600;
}

/* Copy button on assistant messages */
.msg-actions {
  display: flex;
  gap: 4px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.message-assistant:hover .msg-actions { opacity: 1; }

/* On mobile, always show */
@media (hover: none) {
  .msg-actions { opacity: 0.6; }
}

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  padding: 5px 10px;
  min-height: 44px;
  border-radius: 8px;
  transition: all 0.15s ease;
}

.copy-btn:hover { background: rgba(255, 255, 255, 0.06); color: var(--text-secondary); }
.copy-btn svg { width: 14px; height: 14px; }
.copy-btn.copied { color: var(--instant-success); }

/* Speed counter badge */
.speed-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 800;
  font-family: var(--font-rounded);
  color: var(--accent);
  background: var(--accent-dim);
  padding: 4px 10px;
  border-radius: 8px;
  margin-top: 8px;
  transition: opacity 0.5s ease-out;
}

.speed-badge.faded {
  opacity: 0;
}

/* Pre-token bolt animation */
.pre-token-bolt {
  display: flex;
  align-items: center;
  height: 36px;
}

.pulse-bolt {
  width: 24px;
  height: 24px;
  color: var(--accent);
  animation: boltPulse 0.5s ease-in-out infinite alternate;
  filter: drop-shadow(0 0 8px rgba(0, 217, 255, 0.4));
}

@keyframes boltPulse {
  from { transform: scale(0.85); opacity: 0.5; }
  to { transform: scale(1.1); opacity: 1; }
}

/* Empty state */
.empty-chat {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  gap: 24px;
  flex: 1;
}

.empty-bolt {
  width: 64px;
  height: 64px;
  color: var(--accent);
  opacity: 0.4;
  filter: drop-shadow(0 0 16px rgba(0, 217, 255, 0.2));
}

.empty-bolt svg {
  width: 64px;
  height: 64px;
}

.empty-title {
  font-size: 24px;
  font-weight: 700;
  font-family: var(--font-rounded);
  color: var(--text-primary);
  text-align: center;
}

@media (min-width: 768px) {
  .empty-title {
    font-size: 28px;
  }

  .empty-bolt {
    width: 72px;
    height: 72px;
  }

  .empty-bolt svg {
    width: 72px;
    height: 72px;
  }
}

.suggestion-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  max-width: 400px;
}

.suggestion-chip {
  background: rgba(255, 255, 255, 0.04);
  border: 0.5px solid rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  padding: 14px 12px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  line-height: 1.35;
  transition: all 0.2s var(--motion-quick);
}

.suggestion-chip:hover {
  background: rgba(0, 217, 255, 0.06);
  border-color: rgba(0, 217, 255, 0.2);
}

.suggestion-chip:active {
  transform: scale(0.96);
  background: rgba(255, 255, 255, 0.08);
}

/* Input bar */
.input-bar-wrap {
  flex-shrink: 0;
  padding: 8px 0 max(12px, calc(12px + env(safe-area-inset-bottom, 0px)));
  border-top: 0.5px solid var(--divider-subtle);
  background: rgba(4, 8, 18, 0.90);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  position: relative;
  z-index: 2;
}

.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 0 12px;
  min-height: 52px;
}

/* Desktop: center input bar at comfortable width */
@media (min-width: 768px) {
  .input-bar-wrap {
    padding: 12px 24px max(16px, calc(16px + env(safe-area-inset-bottom, 0px)));
    border-top: none;
  }

  .input-bar {
    max-width: 760px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 0.5px solid rgba(255, 255, 255, 0.08);
    border-radius: 22px;
    padding: 4px 8px 4px 12px;
    min-height: 56px;
  }

  .input-field {
    background: transparent;
    border: none;
    padding: 12px 12px;
    border-radius: 0;
  }

  .input-field:focus {
    border-color: transparent;
  }

  .quick-chip-row {
    max-width: 760px;
    margin: 0 auto;
  }

  .attachment-preview {
    max-width: 760px;
    margin: 0 auto;
  }
}

.input-left-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  padding-bottom: 8px;
}

.input-field-wrap {
  flex: 1;
  position: relative;
}

.input-field {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 0.5px solid rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  outline: none;
  padding: 12px 16px;
  border-radius: 22px;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.4;
  min-height: 44px;
  max-height: 120px;
  resize: none;
  overflow-y: auto;
  transition: border-color 0.2s ease;
}

.input-field::placeholder { color: var(--text-muted); }
.input-field:focus { border-color: rgba(0, 217, 255, 0.3); }

.send-btn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  background: var(--accent);
  border-radius: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--instant-black);
  transition: transform 0.2s var(--motion-punchy), opacity 0.2s ease, box-shadow 0.3s ease;
  margin-bottom: 0;
  box-shadow: 0 0 12px rgba(0, 217, 255, 0.15);
}

.send-btn svg { width: 18px; height: 18px; }
.send-btn:disabled { opacity: 0.3; cursor: default; box-shadow: none; }
.send-btn:active:not(:disabled) { transform: scale(0.88); }
.send-btn:hover:not(:disabled) { box-shadow: 0 0 24px rgba(0, 217, 255, 0.4); }

/* Search toggle active state */
.search-active {
  color: var(--accent) !important;
  background: var(--accent-dim);
}

/* Quick chips row */
.quick-chip-row {
  display: flex;
  gap: 8px;
  padding: 0 var(--screen-pad) 10px;
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
}

.quick-chip-row::-webkit-scrollbar { display: none; }

.quick-chip {
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.04);
  border: 0.5px solid rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s ease;
}

.quick-chip:hover { background: rgba(255, 255, 255, 0.06); color: var(--text-primary); }
.quick-chip:active { background: rgba(255, 255, 255, 0.08); }

/* Scroll to bottom pill */
.scroll-pill {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 140px;
  background: var(--accent);
  color: var(--instant-black);
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 700;
  font-family: var(--font-rounded);
  cursor: pointer;
  z-index: 3;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  transition: all 0.2s var(--motion-quick);
  opacity: 0;
  pointer-events: none;
}

.scroll-pill.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ==========================================================================
   ARTIFACT READER MODAL
   ========================================================================== */
.artifact-card {
  background: var(--card);
  border: 0.5px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 16px;
  margin-top: 8px;
  cursor: pointer;
  transition: all 0.2s var(--motion-quick);
  display: flex;
  align-items: center;
  gap: 12px;
}

.artifact-card:hover { background: var(--card-elevated); }
.artifact-card:active { transform: scale(0.98); }

.artifact-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--accent-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  flex-shrink: 0;
}

.artifact-icon svg { width: 20px; height: 20px; }

.artifact-info { flex: 1; min-width: 0; }
.artifact-title { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.artifact-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.artifact-chevron { color: var(--text-muted); font-size: 18px; }

/* Reader modal */
.reader-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 50;
  animation: fadeIn 0.2s ease;
}

.reader-modal {
  position: fixed;
  top: 5%;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 480px;
  max-height: 88vh;
  background: var(--card);
  border: 0.5px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sheet);
  z-index: 51;
  display: flex;
  flex-direction: column;
  animation: readerSlideUp 0.35s var(--motion-smooth);
  overflow: hidden;
}

@media (min-width: 768px) {
  .reader-modal {
    max-width: 700px;
  }
}

@keyframes readerSlideUp {
  from { opacity: 0; transform: translateX(-50%) translateY(40px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.reader-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 0.5px solid var(--divider-subtle);
  flex-shrink: 0;
}

.reader-title { font-size: 17px; font-weight: 600; }

.reader-close {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 18px;
}

.reader-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  -webkit-overflow-scrolling: touch;
}

.reader-body .assistant-text {
  font-size: 16px;
  line-height: 1.6;
}

/* ==========================================================================
   SOURCES SECTION
   ========================================================================== */
.sources-section {
  margin-top: 12px;
}

.sources-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.sources-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.source-card {
  background: rgba(255, 255, 255, 0.03);
  border: 0.5px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  text-decoration: none;
  color: inherit;
  transition: background 0.15s ease;
}

.source-card:hover { background: rgba(255, 255, 255, 0.06); }

.source-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  margin-top: 1px;
  color: var(--text-muted);
}

.source-body { flex: 1; min-width: 0; }
.source-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.source-snippet {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.source-url {
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.6;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================================================================
   HISTORY SIDEBAR
   ========================================================================== */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 20;
  animation: fadeIn 0.2s ease;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 85%;
  max-width: 360px;
  background: var(--bg);
  border-right: 0.5px solid var(--divider-subtle);
  z-index: 21;
  display: flex;
  flex-direction: column;
  animation: slideInLeft 0.35s var(--motion-smooth);
}

/* Desktop: sidebar is always visible, inline in flex layout */
@media (min-width: 768px) {
  .sidebar-backdrop {
    display: none !important;
  }

  .sidebar {
    position: relative;
    top: auto;
    left: auto;
    bottom: auto;
    width: 280px;
    max-width: 280px;
    min-width: 280px;
    flex-shrink: 0;
    z-index: 1;
    animation: none;
    transform: none !important;
    background: #0A0E1A;
    border-right: 1px solid rgba(255, 255, 255, 0.06);
  }

  .sidebar-closing {
    animation: none;
    transform: none !important;
  }

  /* Persistent sidebar container: no scroll lock, always in flow */
  #sidebarRoot {
    display: contents;
  }
}

@keyframes slideInLeft {
  from { transform: translateX(-100%); }
  to { transform: translateX(0); }
}

.sidebar-closing {
  animation: slideOutLeft 0.25s var(--motion-quick) forwards;
}

@keyframes slideOutLeft {
  from { transform: translateX(0); }
  to { transform: translateX(-100%); }
}

.sb-header {
  padding: calc(16px + var(--safe-top)) 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

@media (min-width: 768px) {
  .sb-header {
    padding: 20px 16px 16px;
    border-bottom: 0.5px solid rgba(255, 255, 255, 0.04);
  }
}

.sb-title {
  font-size: 20px;
  font-weight: 700;
  font-family: var(--font-rounded);
  color: var(--text-primary);
}

@media (min-width: 768px) {
  .sb-title {
    font-size: 18px;
    font-weight: 800;
  }
}

.sb-new-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-dim);
  color: var(--accent);
  padding: 10px 16px;
  min-height: 44px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.sb-new-btn:hover {
  background: var(--accent-medium);
  box-shadow: 0 0 12px rgba(0, 217, 255, 0.15);
}

.sb-search {
  padding: 0 16px 12px;
}

.sb-search input {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 0.5px solid rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  padding: 10px 14px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 16px;
  min-height: 44px;
  outline: none;
  transition: border-color 0.2s ease;
}

.sb-search input::placeholder { color: var(--text-muted); }
.sb-search input:focus { border-color: rgba(0, 217, 255, 0.3); }

.conv-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

.conv-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  border-bottom: 0.5px solid var(--divider-subtle);
  transition: background 0.15s ease, border-color 0.15s ease;
  border-left: 3px solid transparent;
}

.conv-row:active { background: rgba(255, 255, 255, 0.04); }

/* Active conversation highlight */
.conv-row.active {
  background: rgba(0, 217, 255, 0.04);
  border-left-color: var(--accent);
}

/* Desktop: hover states for conv rows */
@media (min-width: 768px) {
  .conv-row:hover {
    background: rgba(255, 255, 255, 0.04);
  }

  .conv-row.active:hover {
    background: rgba(0, 217, 255, 0.06);
  }
}

.conv-text { flex: 1; min-width: 0; }

.conv-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-preview {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.conv-time {
  font-size: 11px;
  color: var(--text-muted);
}

.conv-mode-icon {
  font-size: 14px;
}

.conv-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  gap: 12px;
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
}

.sb-footer {
  padding: 12px 16px max(12px, calc(12px + env(safe-area-inset-bottom, 0px)));
  border-top: 0.5px solid var(--divider-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sb-footer-version {
  font-size: 11px;
  color: var(--text-muted);
}

/* ==========================================================================
   MODE TOGGLE (Bottom Sheet)
   ========================================================================== */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 30;
  animation: fadeIn 0.2s ease;
}

.mode-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 480px;
  margin: 0 auto;
  background: var(--card);
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  padding: 12px 16px max(24px, calc(24px + env(safe-area-inset-bottom, 0px)));
  z-index: 31;
  max-height: 80%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: sheetUp 0.35s var(--motion-smooth);
}

/* Desktop: center mode sheet in viewport */
@media (min-width: 768px) {
  .mode-sheet {
    max-width: 440px;
    border-radius: var(--radius-sheet);
    bottom: auto;
    top: 50%;
    left: 50%;
    right: auto;
    transform: translate(-50%, -50%);
    animation: fadeIn 0.2s ease;
    border: 0.5px solid rgba(255, 255, 255, 0.08);
  }
}

@keyframes sheetUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--text-muted);
  border-radius: 2px;
  margin: 0 auto 20px;
  opacity: 0.5;
}

.mode-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mode-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1.5px solid transparent;
  text-align: left;
  padding: 14px 16px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: all 0.2s var(--motion-quick);
}

.mode-card.active {
  border-color: var(--accent);
  background: rgba(0, 217, 255, 0.04);
}

.mode-card:active { transform: scale(0.98); }

.mc-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mc-emoji { font-size: 20px; }

.mc-title {
  font-size: 17px;
  font-weight: 700;
  font-family: var(--font-rounded);
  flex: 1;
}

.mc-check {
  color: var(--accent);
  font-size: 18px;
  font-weight: 700;
}

.mc-desc {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* ==========================================================================
   ANIMATIONS
   ========================================================================== */
.fade-in { animation: fadeIn 0.3s ease-out; }
.slide-up { animation: slideUp 0.35s var(--motion-smooth); }

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Stagger animation helper */
.stagger-1 { animation-delay: 0ms; }
.stagger-2 { animation-delay: 80ms; }
.stagger-3 { animation-delay: 160ms; }
.stagger-4 { animation-delay: 240ms; }

/* ---------- Utility ---------- */
.hidden { display: none !important; }

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.08); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.14); }

/* Firefox scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.08) transparent;
}

/* Selection color */
::selection {
  background: rgba(0, 217, 255, 0.25);
  color: var(--text-primary);
}

/* KaTeX overrides for dark theme */
.katex { color: var(--text-primary); }
.katex .katex-html { color: var(--text-primary); }

/* Code block copy button — see enhanced version below */

/* Focus visible for keyboard navigation */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Prevent body scroll on iOS when modals open */
body.no-scroll {
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ==========================================================================
   AUTH SCREENS
   ========================================================================== */
.auth-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  height: 100dvh;
  padding: var(--screen-pad);
  padding-bottom: max(var(--screen-pad), env(safe-area-inset-bottom, 0px));
  background: var(--bg);
  position: relative;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.auth-container {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.auth-card {
  width: 100%;
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

.auth-hero {
  text-align: center;
  margin-bottom: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.auth-hero .welcome-bolt {
  width: 48px;
  height: 48px;
  margin-bottom: 4px;
}

.auth-hero .welcome-bolt svg {
  width: 48px;
  height: 48px;
}

.auth-title {
  font-size: 26px;
  font-weight: 800;
  font-family: var(--font-rounded);
  color: var(--text-primary);
}

.auth-sub {
  font-size: 15px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.auth-error {
  width: 100%;
  background: rgba(255, 59, 92, 0.12);
  border: 0.5px solid rgba(255, 59, 92, 0.3);
  color: var(--instant-error);
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  margin-bottom: 16px;
  text-align: center;
}

.auth-success {
  width: 100%;
  background: rgba(34, 227, 174, 0.12);
  border: 0.5px solid rgba(34, 227, 174, 0.3);
  color: var(--instant-success);
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  margin-bottom: 16px;
  text-align: center;
}

.auth-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-field input {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 0.5px solid rgba(255, 255, 255, 0.10);
  color: var(--text-primary);
  padding: 14px 16px;
  border-radius: 14px;
  font-family: inherit;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s ease;
}

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

.auth-field input:focus {
  border-color: rgba(0, 217, 255, 0.4);
}

.auth-submit {
  margin-top: 4px;
}

.auth-link {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 12px;
  cursor: pointer;
  transition: color 0.15s ease;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.auth-link:hover {
  color: var(--accent);
}

.auth-divider {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--text-muted);
  font-size: 13px;
}

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

.auth-social {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-social-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 0.5px solid rgba(255, 255, 255, 0.10);
  color: var(--text-primary);
  padding: 14px;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s var(--motion-quick);
}

.auth-social-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.auth-social-btn:active {
  transform: scale(0.98);
}

.auth-toggle {
  margin-top: 20px;
  font-size: 14px;
  color: var(--text-secondary);
}

.auth-link-inline {
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.auth-link-inline:hover {
  opacity: 0.8;
}

.auth-skip {
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s ease;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.auth-skip:hover {
  color: var(--text-secondary);
}

/* ==========================================================================
   SETTINGS PANEL
   ========================================================================== */
.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 85%;
  max-width: 400px;
  background: var(--bg);
  border-left: 0.5px solid var(--divider-subtle);
  z-index: 21;
  display: flex;
  flex-direction: column;
  animation: slideInRight 0.35s var(--motion-smooth);
}

/* Desktop: settings panel slides in from right */
@media (min-width: 768px) {
  .settings-panel {
    max-width: 420px;
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.4);
  }
}

@keyframes slideInRight {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.settings-closing {
  animation: slideOutRight 0.25s var(--motion-quick) forwards;
}

@keyframes slideOutRight {
  from { transform: translateX(0); }
  to { transform: translateX(100%); }
}

.settings-header {
  padding: calc(16px + var(--safe-top)) 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 0.5px solid var(--divider-subtle);
}

.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

.settings-section {
  margin-bottom: 28px;
}

.settings-section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.settings-row {
  margin-bottom: 12px;
}

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

.settings-input {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 0.5px solid rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  padding: 12px 14px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 16px;
  min-height: 44px;
  outline: none;
  transition: border-color 0.2s ease;
}

.settings-input:focus {
  border-color: rgba(0, 217, 255, 0.3);
}

.settings-input[readonly] {
  opacity: 0.6;
  cursor: default;
}

.settings-hint {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 10px;
}

.settings-textarea {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 0.5px solid rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  -webkit-appearance: none;
  padding: 12px 14px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.5;
  outline: none;
  resize: vertical;
  min-height: 80px;
  transition: border-color 0.2s ease;
}

.settings-textarea:focus {
  border-color: rgba(0, 217, 255, 0.3);
}

.settings-textarea::placeholder {
  color: var(--text-muted);
}

.settings-save-memory {
  margin-top: 10px;
  width: 100%;
}

.settings-mode-row {
  display: flex;
  gap: 8px;
}

.settings-mode-option {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 8px;
  background: rgba(255, 255, 255, 0.03);
  border: 1.5px solid transparent;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.2s var(--motion-quick);
}

.settings-mode-option.active {
  border-color: var(--accent);
  background: rgba(0, 217, 255, 0.04);
}

.settings-mode-option:active {
  transform: scale(0.96);
}

.settings-mode-emoji {
  font-size: 20px;
}

.settings-mode-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.settings-tier-card {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-tier-name {
  font-size: 17px;
  font-weight: 700;
  font-family: var(--font-rounded);
  color: var(--text-primary);
}

.settings-tier-desc {
  font-size: 14px;
  color: var(--text-secondary);
}

.settings-upgrade {
  margin-top: 8px;
}

.settings-signout {
  width: 100%;
  margin-bottom: 12px;
}

.settings-delete {
  width: 100%;
  color: var(--instant-error) !important;
}

.settings-signin {
  width: 100%;
}

/* History sidebar: settings button */
.sb-footer-settings {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.15s ease;
  min-height: 44px;
  padding: 8px 4px;
}

.sb-footer-settings:hover {
  color: var(--text-primary);
}

/* ==========================================================================
   TOPBAR RIGHT ACTIONS
   ========================================================================== */
.topbar-right {
  display: flex;
  align-items: center;
  gap: 0;
}

/* ==========================================================================
   ATTACHMENT PREVIEW
   ========================================================================== */
.attachment-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px var(--screen-pad) 4px;
  flex-wrap: wrap;
}

.attach-thumb {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 10px;
  overflow: hidden;
  border: 0.5px solid rgba(255, 255, 255, 0.10);
}

.attach-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.attach-pdf-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.06);
  border: 0.5px solid rgba(255, 255, 255, 0.10);
  padding: 8px 12px;
  border-radius: 10px;
  color: var(--text-secondary);
  font-size: 13px;
}

.attach-pdf-badge svg {
  flex-shrink: 0;
  color: var(--accent);
}

.attach-name {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attach-remove {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 28px;
  height: 28px;
  background: rgba(0, 0, 0, 0.7);
  color: var(--text-primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
  z-index: 1;
}

.attach-pdf-badge .attach-remove {
  position: static;
  background: rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

/* ==========================================================================
   USER MESSAGE EDIT & IMAGE
   ========================================================================== */
.user-msg-actions {
  position: absolute;
  left: var(--screen-pad);
  top: 50%;
  transform: translateY(-50%);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.message-user:hover .user-msg-actions {
  opacity: 1;
}

@media (hover: none) {
  .user-msg-actions {
    opacity: 0.5;
  }
}

.edit-msg-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  color: var(--text-muted);
  transition: all 0.15s ease;
  cursor: pointer;
}

.edit-msg-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-secondary);
}

.user-image-preview {
  margin-bottom: 8px;
  border-radius: 12px;
  overflow: hidden;
  max-width: min(200px, 100%);
}

.user-image-preview img {
  width: 100%;
  display: block;
  border-radius: 12px;
}

.user-pdf-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--accent);
  margin-bottom: 6px;
  opacity: 0.8;
}

.user-pdf-badge svg {
  flex-shrink: 0;
}

.user-text {
  display: block;
}

/* Edit mode */
.edit-textarea {
  width: 100%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(0, 217, 255, 0.3);
  color: var(--text-primary);
  padding: 10px 12px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.4;
  resize: vertical;
  min-height: 60px;
  outline: none;
}

.edit-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  justify-content: flex-end;
}

.edit-cancel {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.edit-cancel:hover {
  background: rgba(255, 255, 255, 0.06);
}

.edit-save {
  font-size: 13px;
  font-weight: 600;
  color: var(--instant-black);
  background: var(--accent);
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.edit-save:active {
  transform: scale(0.96);
}

/* ==========================================================================
   REGENERATE BUTTON
   ========================================================================== */
.regen-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  padding: 5px 10px;
  min-height: 44px;
  border-radius: 8px;
  transition: all 0.15s ease;
  cursor: pointer;
}

.regen-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-secondary);
}

.regen-btn svg {
  width: 14px;
  height: 14px;
}

/* ==========================================================================
   FOLLOW-UP CHIPS
   ========================================================================== */
.followup-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.followup-chip {
  background: rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 0.5px solid rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  padding: 10px 14px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  line-height: 1.3;
  max-width: 100%;
  text-align: left;
  transition: all 0.2s var(--motion-quick);
}

.followup-chip:hover {
  background: rgba(0, 217, 255, 0.06);
  border-color: rgba(0, 217, 255, 0.2);
}

.followup-chip:active {
  transform: scale(0.97);
  background: rgba(0, 217, 255, 0.10);
}

/* ==========================================================================
   CODE BLOCK COPY (enhanced)
   ========================================================================== */
.code-block-wrap {
  position: relative;
  max-width: 100%;
  overflow: hidden;
}

.code-block-lang {
  position: absolute;
  top: 8px;
  left: 12px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  z-index: 1;
  opacity: 0.6;
}

.code-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  padding: 8px 12px;
  min-height: 36px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease;
  cursor: pointer;
  z-index: 1;
}

.code-block-wrap:hover .code-copy-btn {
  opacity: 1;
}

.code-copy-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  color: var(--text-secondary);
}

/* On touch devices, always show */
@media (hover: none) {
  .code-copy-btn {
    opacity: 0.7;
  }
}

/* ==========================================================================
   RESPONSIVE MOBILE (480px and below)
   ========================================================================== */
@media (max-width: 480px) {
  :root {
    --screen-pad: 14px;
    --msg-gap: 14px;
  }

  .chat-topbar {
    padding: var(--safe-top) 6px 0;
  }

  .mode-pill {
    padding: 6px 12px;
    font-size: 13px;
  }

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

  .suggestion-chip {
    padding: 12px 10px;
    font-size: 12px;
    min-height: 44px;
  }

  /* Full-screen sidebar on mobile */
  .sidebar {
    width: 100%;
    max-width: 100%;
  }

  /* Full-screen settings on mobile */
  .settings-panel {
    width: 100%;
    max-width: 100%;
  }

  /* Settings body scrollable */
  .settings-body {
    padding-bottom: max(16px, env(safe-area-inset-bottom, 0px));
  }

  /* Mode sheet: full width */
  .mode-sheet {
    max-width: 100%;
    border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  }

  /* Mode cards stack vertically (already column, enforce full-width) */
  .mode-card {
    padding: 16px;
    min-height: 44px;
  }

  /* Input bar: keep touch targets at 44px minimum */
  .input-left-actions {
    gap: 0;
  }

  .icon-btn-sm {
    width: 44px;
    height: 44px;
  }

  .icon-btn-sm svg {
    width: 18px;
    height: 18px;
  }

  /* Ensure touch targets are min 44px */
  .conv-row {
    min-height: 56px;
    padding: 12px 14px;
  }

  .quick-chip {
    padding: 8px 12px;
    font-size: 12px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  /* Follow-up chips */
  .followup-chip {
    padding: 10px 14px;
    font-size: 13px;
    min-height: 44px;
  }

  /* Auth card */
  .auth-card {
    padding: 24px 16px;
  }

  /* Auth buttons full width on mobile */
  .auth-submit,
  .auth-social-btn {
    width: 100%;
    min-height: 48px;
  }

  .btn-primary {
    max-width: 100%;
  }

  /* Artifact cards full width */
  .artifact-card {
    width: 100%;
  }

  /* Reader modal full-width on small screens */
  .reader-modal {
    width: calc(100% - 16px);
    max-height: 90dvh;
    top: 2%;
  }

  /* Paywall full-width */
  .paywall-sheet {
    max-width: 100%;
  }

  /* Onboarding: make buttons full-width */
  .onb-footer .btn-primary {
    max-width: 100%;
    width: 100%;
  }

  /* Onboarding: readable text */
  .welcome-title {
    font-size: 30px;
  }

  .welcome-sub {
    font-size: 16px;
  }

  .cta-title {
    font-size: 28px;
  }

  .speed-compare-title {
    font-size: 20px;
  }
}

/* Touch-friendly sizing at 375px (iPhone SE) */
@media (max-width: 375px) {
  .empty-title {
    font-size: 20px;
  }

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

  .auth-social-btn {
    padding: 12px;
    font-size: 14px;
  }

  .btn-primary {
    height: 52px;
    font-size: 16px;
  }

  .welcome-title {
    font-size: 26px;
  }

  .cta-title {
    font-size: 24px;
  }

  .speed-compare {
    max-width: 100%;
  }
}

/* Desktop: already handled by two-panel layout above */

/* ==========================================================================
   Paywall Sheet
   ========================================================================== */
.paywall-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  z-index: 900;
}

.paywall-sheet {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  max-height: 90dvh;
  background: var(--card);
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  padding: 12px 20px max(32px, calc(32px + env(safe-area-inset-bottom, 0px)));
  z-index: 901;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: slideUpSheet 0.3s ease-out;
}

@keyframes slideUpSheet {
  from { transform: translateX(-50%) translateY(100%); }
  to { transform: translateX(-50%) translateY(0); }
}

.paywall-header {
  text-align: center;
  padding: 8px 0 16px;
}

.paywall-bolt {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  color: var(--accent);
  filter: drop-shadow(0 0 12px var(--accent));
}

.paywall-bolt svg {
  width: 100%;
  height: 100%;
}

.paywall-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 4px;
}

.paywall-sub {
  font-size: 14px;
  color: var(--text-secondary);
  margin: 0;
}

.paywall-plans {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 16px 0;
}

.paywall-plan-card {
  background: var(--card-elevated);
  border: 1.5px solid var(--divider);
  border-radius: var(--radius-card);
  padding: 20px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.2s, transform 0.15s;
  position: relative;
  width: 100%;
  font-family: inherit;
  color: var(--text-primary);
}

.paywall-plan-card:hover {
  border-color: var(--accent);
  transform: scale(1.01);
}

.paywall-plan-card:active {
  transform: scale(0.99);
}

.paywall-plan-featured {
  border-color: var(--accent);
  background: linear-gradient(135deg, rgba(0, 217, 255, 0.08), rgba(0, 217, 255, 0.02));
}

.paywall-plan-badge {
  position: absolute;
  top: -10px;
  right: 16px;
  background: var(--accent);
  color: var(--instant-black);
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  letter-spacing: 0.5px;
}

.paywall-plan-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}

.paywall-plan-name {
  font-size: 20px;
  font-weight: 700;
}

.paywall-plan-price {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
}

.paywall-price-period {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-secondary);
}

.paywall-plan-features {
  list-style: none;
  padding: 0;
  margin: 0;
}

.paywall-plan-features li {
  font-size: 14px;
  color: var(--text-secondary);
  padding: 4px 0;
  padding-left: 20px;
  position: relative;
}

.paywall-plan-features li::before {
  content: '\2713';
  position: absolute;
  left: 0;
  color: var(--instant-success);
  font-weight: 600;
}

.paywall-plan-loading {
  opacity: 0.6;
  pointer-events: none;
}

.paywall-plan-loading::after {
  content: 'Redirecting...';
  display: block;
  text-align: center;
  margin-top: 12px;
  font-size: 13px;
  color: var(--accent);
}

.paywall-footer {
  text-align: center;
  padding-top: 8px;
}

.paywall-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 12px 16px;
  min-height: 44px;
  font-family: inherit;
}

.paywall-close-btn:hover {
  color: var(--text-secondary);
}

/* ==========================================================================
   Toast Notifications
   ========================================================================== */
.app-toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  opacity: 0;
  z-index: 9999;
  padding: 12px 24px;
  border-radius: var(--radius-button);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  backdrop-filter: blur(16px);
  transition: opacity 0.3s, transform 0.3s;
  max-width: 90vw;
  text-align: center;
  pointer-events: none;
}

.app-toast-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.app-toast-success {
  background: rgba(34, 227, 174, 0.15);
  border: 1px solid var(--instant-success);
}

.app-toast-info {
  background: rgba(0, 217, 255, 0.12);
  border: 1px solid var(--accent);
}

.app-toast-error {
  background: rgba(255, 59, 92, 0.15);
  border: 1px solid var(--instant-error);
}

/* ==========================================================================
   Settings: Manage Subscription button
   ========================================================================== */
.settings-manage-sub {
  margin-top: 8px;
}

.settings-manage-sub.hidden {
  display: none;
}
