/* ═══════════════════════════════════════════════════════════
   MedAdvisor — Style Guide v2
   Palette: deep navy base · polymorphic sky/rose accents
   Font: Inter (Google Fonts)
═══════════════════════════════════════════════════════════ */

/* ── Design tokens ───────────────────────────────────────── */
:root {
  /* Surfaces */
  --bg:       #090e18;
  --surface:  #0f1623;
  --surface2: #172031;
  --surface3: #1e2a40;

  /* Borders */
  --border:   #25334d;
  --border-2: #304060;

  /* Text */
  --text:       #dce5f5;
  --text-muted: #637092;
  --text-dim:   #38475e;

  /* Accent — overridden per person below */
  --accent:      #38bdf8;
  --accent-rgb:  56, 189, 248;
  --accent-dim:  rgba(56, 189, 248, 0.10);
  --accent-glow: rgba(56, 189, 248, 0.18);

  /* Person palette (for fixed reference, e.g. avatars on picker) */
  --vivek-color: #38bdf8;
  --bhumi-color: #f472b6;

  /* Semantic */
  --error:   #f87171;
  --success: #4ade80;
  --warning: #fbbf24;

  /* Geometry */
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;

  /* Layout */
  --sidebar-w: 264px;
  --header-h:  56px;

  /* Typography */
  --font:      "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", Consolas, "Liberation Mono", monospace;
}

/* Polymorphic accent switching */
body[data-person="vivek"] {
  --accent:      #38bdf8;
  --accent-rgb:  56, 189, 248;
  --accent-dim:  rgba(56, 189, 248, 0.10);
  --accent-glow: rgba(56, 189, 248, 0.18);
}
body[data-person="bhumi"] {
  --accent:      #f472b6;
  --accent-rgb:  244, 114, 182;
  --accent-dim:  rgba(244, 114, 182, 0.10);
  --accent-glow: rgba(244, 114, 182, 0.18);
}

/* ── Reset & base ────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button {
  font-family: inherit;
  cursor: pointer;
  touch-action: manipulation; /* eliminates 300ms tap delay on mobile */
}

svg {
  display: block;
  width: 1em;
  height: 1em;
  flex-shrink: 0;
}

.svg-defs { display: none; }

/* ── Screens ─────────────────────────────────────────────── */
.screen {
  display: none;
}

.screen.active {
  display: flex;
  flex-direction: column;
  height: var(--vvh, 100dvh); /* JS sets --vvh via visualViewport; dvh is the fallback */
  animation: fade-in 0.22s ease;
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ═══════════════════════════════════════════════════════════
   PICKER SCREEN
═══════════════════════════════════════════════════════════ */
#picker-screen.active {
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

/* Subtle dot-grid background */
#picker-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 28px 28px;
  pointer-events: none;
}

/* Ambient radial glow from top */
#picker-screen::after {
  content: '';
  position: absolute;
  width: 800px;
  height: 500px;
  top: -120px;
  left: 50%;
  transform: translateX(-50%);
  background: radial-gradient(ellipse, rgba(56, 189, 248, 0.07) 0%, transparent 65%);
  pointer-events: none;
}

.picker-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(420px, calc(100vw - 2.5rem));
}

/* Logo block */
.picker-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.625rem;
  margin-bottom: 1rem;
  color: var(--vivek-color);
}

.logo-icon { color: inherit; }

.logo-lg {
  width: 54px;
  height: 54px;
  font-size: 54px;
  filter: drop-shadow(0 0 14px rgba(56, 189, 248, 0.35));
}

.logo-sm {
  width: 22px;
  height: 22px;
  font-size: 22px;
}

.logo-wordmark {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text);
}

/* Tagline */
.picker-tagline {
  color: var(--text-muted);
  font-size: 0.875rem;
  text-align: center;
  max-width: 300px;
  line-height: 1.55;
  margin-bottom: 2rem;
}

/* "Who are you?" label */
.picker-prompt {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  align-self: flex-start;
  margin-bottom: 0.5rem;
}

/* Person list */
.person-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.person-card {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.875rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  text-align: left;
  transition: background 0.15s, border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}

.person-card:hover {
  background: var(--surface2);
  transform: translateY(-2px);
}

.person-card:active {
  transform: translateY(0);
  box-shadow: none !important;
}

.person-card[data-person="vivek"]:hover {
  border-color: rgba(56, 189, 248, 0.4);
  box-shadow: 0 8px 28px rgba(0,0,0,0.35), 0 0 0 1px rgba(56, 189, 248, 0.2);
}

.person-card[data-person="bhumi"]:hover {
  border-color: rgba(244, 114, 182, 0.4);
  box-shadow: 0 8px 28px rgba(0,0,0,0.35), 0 0 0 1px rgba(244, 114, 182, 0.2);
}

/* Avatar */
.person-avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem;
  font-weight: 700;
  flex-shrink: 0;
  color: #fff;
}

.person-avatar[data-person="vivek"] { background: var(--vivek-color); }
.person-avatar[data-person="bhumi"] { background: var(--bhumi-color); }

.person-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.person-name {
  font-weight: 600;
  font-size: 0.9375rem;
}

.person-meta {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.person-arrow {
  width: 16px;
  height: 16px;
  font-size: 16px;
  color: var(--text-dim);
  transition: color 0.15s, transform 0.15s;
}

.person-card:hover .person-arrow { transform: translateX(3px); }
.person-card[data-person="vivek"]:hover .person-arrow { color: var(--vivek-color); }
.person-card[data-person="bhumi"]:hover .person-arrow { color: var(--bhumi-color); }

/* ═══════════════════════════════════════════════════════════
   CHAT SCREEN
═══════════════════════════════════════════════════════════ */
#chat-screen.active { overflow: hidden; }

/* ── Header ──────────────────────────────────────────────── */
.chat-header {
  height: var(--header-h);
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 0.75rem 0 0.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  position: relative;
  z-index: 101; /* always above the mobile sidebar drawer */
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

/* Icon button */
.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-xs);
  background: transparent;
  border: none;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: background 0.12s, color 0.12s;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--surface2);
  color: var(--text);
}

/* Brand */
.header-brand {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--accent);
  margin-left: 0.25rem;
}

.brand-name {
  font-weight: 700;
  font-size: 0.9375rem;
  letter-spacing: -0.01em;
  color: var(--text);
}

/* Person badge */
.person-badge {
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(var(--accent-rgb), 0.25);
  transition: background 0.3s, color 0.3s, border-color 0.3s;
  margin-left: 0.375rem;
  white-space: nowrap;
}

/* Model segmented control */
.model-seg {
  display: flex;
  align-items: center;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}

.seg-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: calc(var(--radius-sm) - 4px);
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  line-height: 1.5;
}

.seg-btn:hover { color: var(--text); background: var(--surface3); }

.seg-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
}

/* ── Chat body layout ────────────────────────────────────── */
.chat-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.22s ease, opacity 0.22s ease;
}

.sidebar.collapsed {
  width: 0;
  opacity: 0;
  pointer-events: none;
}

.sidebar-backdrop { display: none; }

/* Prevent background scroll when mobile sidebar drawer is open */
body.sidebar-open { overflow: hidden; }

.sidebar-top {
  padding: 0.625rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.new-chat-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4375rem;
  background: var(--accent-dim);
  border: 1px solid rgba(var(--accent-rgb), 0.22);
  color: var(--accent);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.875rem;
  font-size: 0.875rem;
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.new-chat-btn svg { width: 15px; height: 15px; font-size: 15px; }

.new-chat-btn:hover {
  background: rgba(var(--accent-rgb), 0.16);
  border-color: rgba(var(--accent-rgb), 0.38);
}

/* Conversation list */
.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.25rem 0 0.5rem;
}

.conv-group-label {
  padding: 0.875rem 0.875rem 0.3rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.conv-item {
  display: flex;
  align-items: center;
  padding: 0.5rem 0.625rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
  margin: 1px 0.375rem;
  transition: background 0.12s;
  min-width: 0;
}

.conv-item:hover { background: var(--surface2); }

.conv-item.active {
  background: var(--accent-dim);
}

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

.conv-title {
  display: block;
  font-size: 0.8125rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

.conv-item.active .conv-title { color: var(--accent); }

.conv-title-input {
  background: var(--surface3);
  border: 1px solid var(--accent);
  border-radius: var(--radius-xs);
  color: var(--text);
  font: inherit;
  font-size: 0.8125rem;
  padding: 1px 5px;
  width: 100%;
  outline: none;
  line-height: 1.4;
}

.conv-date {
  display: block;
  font-size: 0.6875rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.conv-delete {
  display: none;
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 1rem;
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.12s, background 0.12s;
}

.conv-item:hover .conv-delete { display: flex; align-items: center; }

.conv-delete:hover {
  color: var(--error);
  background: rgba(248, 113, 113, 0.12);
}

.conv-empty {
  padding: 2.5rem 1.25rem;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.8125rem;
  line-height: 1.6;
}

/* ── Chat main ───────────────────────────────────────────── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Messages ────────────────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 1.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  overscroll-behavior: contain;
}

/* Message wrapper handles alignment */
.msg-wrap {
  display: flex;
  flex-direction: column;
  animation: msg-in 0.2s ease;
}

.msg-wrap.user { align-items: flex-end; }
.msg-wrap.assistant { align-items: flex-start; }

@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Bubbles */
.message {
  word-break: break-word;
  line-height: 1.65;
  font-size: 0.9375rem;
}

.message.user {
  max-width: 68%;
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  padding: 0.625rem 1rem;
  border-radius: var(--radius-md);
  border-bottom-right-radius: 4px;
}

.message.assistant {
  max-width: 88%;
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 2px solid var(--accent);
  padding: 0.875rem 1.0625rem;
  border-radius: var(--radius-md);
  border-top-left-radius: 4px;
  transition: border-top-color 0.3s;
}

/* Markdown styling inside assistant messages */
.message.assistant p + p { margin-top: 0.55rem; }

.message.assistant ul,
.message.assistant ol {
  padding-left: 1.375rem;
  margin: 0.5rem 0;
}

.message.assistant li + li { margin-top: 0.3rem; }

.message.assistant h1,
.message.assistant h2,
.message.assistant h3,
.message.assistant h4 {
  margin: 0.875rem 0 0.3rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
}

.message.assistant h1 {
  font-size: 1.15em;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.3rem;
}
.message.assistant h2 { font-size: 1.07em; }
.message.assistant h3 { font-size: 1.0em; }

.message.assistant strong { color: var(--text); font-weight: 600; }

.message.assistant em { color: var(--text-muted); }

.message.assistant code {
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.875em;
  font-family: var(--font-mono);
}

.message.assistant pre {
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 0.875rem 1rem;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 0.625rem 0;
}

.message.assistant pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.875em;
}

.message.assistant blockquote {
  border-left: 3px solid var(--border-2);
  padding-left: 0.875rem;
  color: var(--text-muted);
  margin: 0.5rem 0;
  font-style: italic;
}

.message.assistant table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75rem 0;
  font-size: 0.875em;
}

.message.assistant th,
.message.assistant td {
  border: 1px solid var(--border);
  padding: 0.4rem 0.75rem;
  text-align: left;
}

.message.assistant th {
  background: var(--surface2);
  font-weight: 600;
  color: var(--accent);
  font-size: 0.8125em;
  letter-spacing: 0.02em;
}

.message.assistant tr:hover td { background: rgba(255,255,255,0.02); }

.message.assistant hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.75rem 0;
}

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

/* Typing indicator (shown while streaming starts) */
.typing-dots {
  display: flex;
  gap: 5px;
  padding: 0.2rem 0.1rem;
  align-items: center;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: typing-bounce 1.1s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.16s; }
.typing-dot:nth-child(3) { animation-delay: 0.32s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* Suggestion chips */
.suggestions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-top: 0.75rem;
  max-width: 88%;
  align-self: flex-start;
}

.suggestion-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  text-align: left;
  line-height: 1.45;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.suggestion-chip:hover {
  background: var(--surface3);
  border-color: var(--accent);
  color: var(--text);
}

/* ── Chat footer ─────────────────────────────────────────── */
.chat-footer {
  flex-shrink: 0;
  padding: 0.75rem 1.25rem 0.875rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.input-row {
  display: flex;
  gap: 0.625rem;
  align-items: flex-end;
}

.message-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9375rem;
  line-height: 1.55;
  padding: 0.625rem 1rem;
  resize: none;
  max-height: 160px;
  overflow-y: auto;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.message-input::placeholder { color: var(--text-dim); }

.message-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.message-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.send-btn {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.1s, background 0.3s;
}

.send-btn:hover { opacity: 0.87; }
.send-btn:active { transform: scale(0.95); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Stop button state */
.send-btn.is-stop { background: rgba(248, 113, 113, 0.15); }
.send-btn.is-stop:hover { background: rgba(248, 113, 113, 0.28); opacity: 1; color: var(--error); }
.stop-icon { width: 16px; height: 16px; }

/* Mic button */
.mic-btn {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  background: var(--surface3);
  border: 1px solid var(--border);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.mic-btn:hover { color: var(--text); border-color: var(--border-2); }
.mic-btn:active { transform: scale(0.95); }
.mic-btn.recording {
  color: var(--error);
  background: rgba(248, 113, 113, 0.12);
  border-color: rgba(248, 113, 113, 0.4);
  animation: mic-pulse 1.4s ease-in-out infinite;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.35); }
  50%       { box-shadow: 0 0 0 7px rgba(248, 113, 113, 0); }
}

.footer-disclaimer {
  font-size: 0.6875rem;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.45;
}

/* ═══════════════════════════════════════════════════════════
   SPINNER
═══════════════════════════════════════════════════════════ */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  font-size: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ═══════════════════════════════════════════════════════════
   UTILITY
═══════════════════════════════════════════════════════════ */
.hidden { display: none !important; }

/* ═══════════════════════════════════════════════════════════
   SCROLLBARS
═══════════════════════════════════════════════════════════ */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-2); }

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE — MOBILE (≤640px)
═══════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  /* Sidebar: fixed drawer, HIDDEN BY DEFAULT via CSS — no JS needed on load.
     Shows only when .mobile-open is added. Starts below the header so the
     hamburger and header are always accessible. */
  .sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    bottom: 0;
    width: var(--sidebar-w) !important; /* override desktop .collapsed width:0 */
    opacity: 1 !important;              /* override desktop .collapsed opacity:0 */
    height: auto;
    z-index: 100;
    pointer-events: none;
    transition: transform 0.22s ease;
    transform: translateX(calc(-1 * var(--sidebar-w)));
  }

  .sidebar.mobile-open {
    transform: translateX(0);
    pointer-events: auto;
  }

  /* Backdrop — covers content area below the header */
  .sidebar-backdrop {
    display: block;
    position: fixed;
    top: var(--header-h);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s;
  }

  .sidebar-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
  }

  .message.user { max-width: 88%; }
  .message.assistant { max-width: 95%; }

  .suggestions { grid-template-columns: 1fr; max-width: 95%; }

  .brand-name { display: none; }

  .messages { padding: 1rem 1rem 0.5rem; }

  /* Safe area inset for iOS home indicator */
  .chat-footer {
    padding: 0.625rem 0.875rem calc(0.75rem + env(safe-area-inset-bottom));
  }

  /* Prevent iOS Safari from zooming into focused inputs (requires >= 16px) */
  .message-input,
  .form-group input[type="email"],
  .form-group input[type="password"],
  .form-group input[type="text"] {
    font-size: 16px;
  }

  /* Conversation delete: always visible on touch (no hover state on mobile) */
  .conv-item .conv-delete {
    display: flex;
    align-items: center;
    opacity: 0.45;
  }

  .conv-item:hover .conv-delete,
  .conv-item:active .conv-delete {
    opacity: 1;
  }

  /* Tighten login card on small screens */
  .login-card {
    padding: 1.75rem 1.25rem;
    border-radius: var(--radius-md);
  }
}

@media (max-width: 420px) {
  .model-seg { display: none; }
}

@media (max-width: 360px) {
  .user-menu {
    width: calc(100vw - 1.5rem);
  }
}

/* ═══════════════════════════════════════════════════════════
   LOGIN PAGE
═══════════════════════════════════════════════════════════ */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  background: var(--bg);
}

.login-wrap {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.25rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  box-shadow: 0 24px 64px rgba(0,0,0,0.45);
}

.login-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  color: var(--vivek-color);
}

.login-logo-icon {
  width: 48px;
  height: 48px;
  color: var(--vivek-color);
  filter: drop-shadow(0 0 12px rgba(56, 189, 248, 0.3));
}

.login-logo-text {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text);
}

.login-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.5;
  margin-top: -0.5rem;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

/* ── Shared form styles ───────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.form-group label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
}

.form-group .optional {
  color: var(--text-dim);
  font-weight: 400;
}

.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="text"] {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9375rem;
  padding: 0.625rem 0.875rem;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.6875rem 1rem;
  font-size: 0.9375rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: opacity 0.15s, transform 0.1s;
  min-height: 44px;
}

.btn-primary:hover { opacity: 0.87; }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-secondary {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 0.6rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.btn-secondary:hover { background: var(--surface3); color: var(--text); }

.btn-label { pointer-events: none; }

.btn-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(0, 0, 0, 0.25);
  border-top-color: #000;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

/* ── Passkey button ───────────────────────────────────────── */
.login-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-dim);
  font-size: 0.8125rem;
}
.login-divider::before,
.login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.passkey-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.btn-passkey {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.6875rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.625rem;
  transition: background 0.15s, border-color 0.15s;
  min-height: 44px;
}

.btn-passkey:hover {
  background: var(--surface3);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-passkey:disabled { opacity: 0.5; cursor: not-allowed; }

.passkey-icon { width: 18px; height: 18px; font-size: 18px; flex-shrink: 0; }

/* ── Error message ────────────────────────────────────────── */
.error-msg {
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.25);
  color: var(--error);
  border-radius: var(--radius-xs);
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  line-height: 1.5;
}

/* ═══════════════════════════════════════════════════════════
   USER MENU (account dropdown in header)
═══════════════════════════════════════════════════════════ */
.user-menu-wrap {
  position: relative;
}

.user-avatar-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #000;
  border: none;
  font-size: 0.875rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s, box-shadow 0.15s;
  flex-shrink: 0;
}

.user-avatar-btn[data-person="vivek"] { background: var(--vivek-color); }
.user-avatar-btn[data-person="bhumi"] { background: var(--bhumi-color); color: #fff; }

.user-avatar-btn:hover {
  opacity: 0.85;
  box-shadow: 0 0 0 2px var(--accent-dim);
}

.user-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 260px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 16px 48px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.03);
  display: none;
  flex-direction: column;
  z-index: 200;
  overflow: hidden;
}

.user-menu.open { display: flex; }

.user-menu-header {
  padding: 0.875rem 1rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.user-menu-email {
  font-size: 0.8125rem;
  color: var(--text-muted);
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu-section {
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.user-menu-label {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.passkey-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.passkey-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.25rem;
}

.passkey-item-name {
  flex: 1;
  font-size: 0.8125rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.passkey-delete {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 1rem;
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.12s, background 0.12s;
}

.passkey-delete:hover {
  color: var(--error);
  background: rgba(248, 113, 113, 0.1);
}

.passkey-empty {
  font-size: 0.8rem;
  color: var(--text-dim);
  font-style: italic;
  padding: 0.25rem 0.25rem;
}

.user-menu-action {
  background: transparent;
  border: none;
  text-align: left;
  padding: 0.375rem 0.25rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  border-radius: var(--radius-xs);
  transition: color 0.12s, background 0.12s;
}

.user-menu-action:hover {
  color: var(--text);
  background: var(--surface2);
}

.user-menu-action--danger:hover {
  color: var(--error);
  background: rgba(248, 113, 113, 0.08);
}

.user-menu-divider {
  height: 1px;
  background: var(--border);
  margin: 0;
}

/* Logout button area padding */
.user-menu > .user-menu-action--danger {
  margin: 0.375rem 0.625rem 0.625rem;
}

/* ═══════════════════════════════════════════════════════════
   PASSKEY REGISTRATION MODAL
═══════════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 1rem;
  backdrop-filter: blur(4px);
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
}

.modal-title {
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--text);
}

.modal-body {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.55;
  margin-top: -0.25rem;
}

.modal-actions {
  display: flex;
  gap: 0.625rem;
  justify-content: flex-end;
  margin-top: 0.25rem;
}

.modal-actions .btn-secondary {
  padding: 0.5rem 0.875rem;
}

.modal-actions .btn-primary {
  width: auto;
  padding: 0.5rem 1.125rem;
  min-height: 38px;
}
