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

/* ── Dark theme (default) ──────────────────────────────────────── */
:root,
[data-theme="dark"] {
  --bg:              #0f1117;
  --surface:         #1a1d27;
  --surface2:        #22263a;
  --border:          #2e3350;
  --accent:          #6c63ff;
  --accent-dim:      #4a44b5;
  --green:           #22c55e;
  --yellow:          #f59e0b;
  --red:             #ef4444;
  --text:            #e2e8f0;
  --text-dim:        #94a3b8;
  --text-faint:      #475569;
  --radius:          12px;
  --sidebar-bg:      #1a1744;
  --sidebar-border:  rgba(255,255,255,0.07);
  --sidebar-text:    rgba(165,180,252,0.85);
  --sidebar-faint:   rgba(165,180,252,0.45);
  --sidebar-hover:   rgba(255,255,255,0.07);
  --sidebar-active:  rgba(108,99,255,0.22);
  --popup-bg:        #1e1c30;
  --font:            'DM Sans', system-ui, -apple-system, sans-serif;
  --theme-icon:      "☀️";
}

/* ── Light theme ───────────────────────────────────────────────── */
[data-theme="light"] {
  --bg:              #f3f4f8;
  --surface:         #ffffff;
  --surface2:        #eaecf4;
  --border:          #d5d9ec;
  --accent:          #5b52e8;
  --accent-dim:      #4038c0;
  --text:            #1a1c2e;
  --text-dim:        #556088;
  --text-faint:      #8a93b8;
  --popup-bg:        #ffffff;
  --theme-icon:      "🌙";
}

html, body { height: 100%; font-family: var(--font); background: var(--bg); color: var(--text); transition: background 0.2s, color 0.2s; }

.hidden { display: none !important; }

/* ── Screens ───────────────────────────────────────────────────── */
.screen { height: 100vh; }

/* ── Login ─────────────────────────────────────────────────────── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: radial-gradient(ellipse at 60% 40%, #1e1a3a 0%, var(--bg) 70%);
}
[data-theme="light"] #login-screen {
  background: radial-gradient(ellipse at 60% 40%, #e8e3ff 0%, var(--bg) 70%);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}
.tessa-logo-icon { width: 68px; height: 68px; margin-bottom: 0.5rem; display: block; }
.logo h1 { font-size: 1.5rem; font-weight: 700; }
.login-tagline {
  font-size: 0.78rem;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.55;
}
.login-tagline strong { color: var(--text-dim); font-weight: 600; }

.field { display: flex; flex-direction: column; gap: 0.4rem; }
.field label { font-size: 0.8rem; color: var(--text-dim); letter-spacing: 0.02em; }
.field input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
  font-family: var(--font);
}
.field input:focus { border-color: var(--accent); }

#login-form { display: flex; flex-direction: column; gap: 1rem; }
#login-form button[type=submit] {
  margin-top: 0.25rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.7rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  font-family: var(--font);
}
#login-form button[type=submit]:hover { background: var(--accent-dim); }

.error {
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: 8px;
  color: var(--red);
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
}
.no-access {
  background: rgba(245,158,11,0.1);
  border: 1px solid rgba(245,158,11,0.35);
  border-radius: 8px;
  color: var(--yellow);
  font-size: 0.85rem;
  padding: 0.6rem 0.75rem;
  line-height: 1.5;
}
.no-access p:first-child { font-weight: 600; margin-bottom: 2px; }

/* ── App layout ────────────────────────────────────────────────── */
#app-screen { display: flex; height: 100vh; position: relative; }

/* ── Sidebar overlay (mobile) ──────────────────────────────────── */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 199;
}

/* ── Sidebar ───────────────────────────────────────────────────── */
#sidebar {
  width: 252px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1rem 1rem;
  gap: 0.85rem;
  z-index: 200;
  transition: transform 0.25s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.25rem;
  flex-shrink: 0;
}

.sidebar-brand { display: flex; align-items: center; gap: 0.6rem; }
.brand-labels { display: flex; flex-direction: column; gap: 1px; }
.brand-name { font-weight: 700; font-size: 1.05rem; color: #fff; line-height: 1; }
.brand-suite {
  font-size: 0.62rem;
  font-weight: 500;
  color: var(--sidebar-faint);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.apps-menu-btn {
  background: none;
  border: none;
  color: var(--sidebar-faint);
  cursor: pointer;
  padding: 5px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.apps-menu-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }

.tessa-logo-sm { width: 28px; height: 28px; flex-shrink: 0; display: block; }

/* ── Sidebar nav ───────────────────────────────────────────────── */
.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 0.5rem; overflow: hidden; min-height: 0; }

.nav-btn {
  width: 100%;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  color: #a5b4fc;
  padding: 0.5rem 0.75rem;
  font-size: 0.83rem;
  font-family: var(--font);
  cursor: pointer;
  text-align: left;
  transition: background 0.1s, color 0.1s;
  flex-shrink: 0;
}
.nav-btn:hover { background: rgba(79,70,229,0.2); color: #e0e7ff; }

/* ── Sidebar footer (user card + actions) ──────────────────────── */
.sidebar-footer {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--sidebar-border);
}

.user-card {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.25rem;
}
.user-avatar {
  width: 34px; height: 34px;
  background: var(--accent-dim);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.user-info { overflow: hidden; flex: 1; }
.user-name { font-size: 0.83rem; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 0.7rem; color: var(--sidebar-faint); text-transform: capitalize; margin-top: 1px; }

.sidebar-footer-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ── Icon button (theme toggle) ────────────────────────────────── */
.icon-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 7px;
  color: var(--sidebar-faint);
  cursor: pointer;
  padding: 5px 7px;
  font-size: 0.85rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.icon-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }

#logout-btn {
  flex: 1;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 7px;
  color: rgba(255,255,255,0.35);
  padding: 0.4rem 0.6rem;
  font-size: 0.78rem;
  font-family: var(--font);
  cursor: pointer;
  text-align: center;
  transition: color 0.15s, border-color 0.15s;
}
#logout-btn:hover { color: var(--red); border-color: rgba(239,68,68,0.5); }

.sidebar-tagline {
  font-size: 0.62rem;
  color: var(--sidebar-faint);
  line-height: 1.5;
  padding: 0.5rem 0.25rem 0;
  border-top: 1px solid var(--sidebar-border);
}
.sidebar-tagline a {
  color: rgba(165,180,252,0.6);
  text-decoration: none;
}
.sidebar-tagline a:hover {
  color: #a5b4fc;
  text-decoration: underline;
}

/* ── Conversation history list ─────────────────────────────────── */
.conv-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
}
.conv-list::-webkit-scrollbar { width: 4px; }
.conv-list::-webkit-scrollbar-track { background: transparent; }
.conv-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }

.conv-empty { font-size: 0.75rem; color: var(--sidebar-faint); text-align: center; padding: 1rem 0.5rem; }

.conv-item {
  width: 100%;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--sidebar-text);
  padding: 0.45rem 0.6rem;
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: background 0.1s;
  min-width: 0;
  font-family: var(--font);
}
.conv-item:hover { background: var(--sidebar-hover); }
.conv-item-active { background: var(--sidebar-active) !important; color: #e0e7ff; }

.conv-title {
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
  color: inherit;
}
.conv-time { font-size: 0.67rem; color: var(--sidebar-faint); display: block; }

/* ── Main panel ────────────────────────────────────────────────── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  min-width: 0;
}

/* ── Mobile top bar (hidden on desktop) ────────────────────────── */
#mobile-topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 0.75rem;
}

.mobile-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  flex: 1;
}
.tessa-logo-xs { width: 22px; height: 22px; display: block; }

#hamburger-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 5px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
#hamburger-btn:hover { background: var(--surface2); color: var(--text); }

#mobile-theme-btn {
  border-color: var(--border);
  color: var(--text-dim);
}
#mobile-theme-btn:hover { background: var(--surface2); color: var(--text); }

/* ── Activity feed ─────────────────────────────────────────────── */
.activity-feed {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.25rem;
  max-height: 180px;
  overflow-y: auto;
  flex-shrink: 0;
}
.activity-header {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin-bottom: 0.5rem;
}
.activity-item {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  padding: 0.4rem 0;
  border-top: 1px solid var(--border);
}
.activity-item:first-of-type { border-top: none; }
.activity-item-header { display: flex; align-items: center; gap: 0.5rem; }

.db-tag {
  font-size: 0.7rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  color: var(--accent);
  flex-shrink: 0;
  font-family: monospace;
}
.activity-reason {
  font-size: 0.75rem;
  color: var(--text-faint);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.activity-sql {
  font-family: monospace;
  font-size: 0.72rem;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-all;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  margin: 0;
  max-height: 140px;
  overflow-y: auto;
  line-height: 1.5;
}
.activity-rows { font-size: 0.7rem; color: var(--green); flex-shrink: 0; }

/* ── Conversation ──────────────────────────────────────────────── */
#conversation {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 1.25rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.msg {
  display: flex;
  gap: 0.75rem;
  max-width: 720px;
}
.msg.user      { align-self: flex-end; flex-direction: row-reverse; }
.msg.assistant { align-self: flex-start; }

.msg-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.78rem; font-weight: 700;
  flex-shrink: 0;
}
.msg.user .msg-avatar      { background: var(--accent-dim); color: #fff; }
.msg.assistant .msg-avatar { background: var(--surface2); color: var(--text-dim); }

.msg-bubble {
  padding: 0.7rem 1rem;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.55;
  max-width: 560px;
  position: relative;
}
.msg.user .msg-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.assistant .msg-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

/* Streaming bubble */
.streaming-content {
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Thinking dots ─────────────────────────────────────────────── */
.thinking-bubble {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0.8rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}
.dot {
  width: 7px; height: 7px;
  background: var(--text-faint);
  border-radius: 50%;
  animation: bounce 1.2s infinite ease-in-out;
}
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40%           { transform: translateY(-6px); }
}

/* ── Audio waveform badge ───────────────────────────────────────── */
.audio-wave {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 14px;
  margin-left: 8px;
  vertical-align: middle;
  opacity: 0.75;
}
.audio-wave span {
  display: block; width: 3px;
  background: var(--green);
  border-radius: 2px;
  animation: wave-bar 0.9s infinite ease-in-out;
}
.audio-wave span:nth-child(1) { height: 5px;  animation-delay: 0s; }
.audio-wave span:nth-child(2) { height: 12px; animation-delay: 0.2s; }
.audio-wave span:nth-child(3) { height: 8px;  animation-delay: 0.1s; }
.audio-wave span:nth-child(4) { height: 5px;  animation-delay: 0.3s; }
@keyframes wave-bar {
  0%, 100% { transform: scaleY(0.4); }
  50%       { transform: scaleY(1.2); }
}

/* ── Message actions ───────────────────────────────────────────── */
.msg-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
  margin-top: 6px;
  opacity: 0;
  transition: opacity 0.15s;
}
.msg:hover .msg-actions { opacity: 1; }

.msg-action-btn {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 11px;
  font-family: var(--font);
  padding: 3px 7px;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: background 0.12s, color 0.12s;
  line-height: 1;
}
.msg-action-btn:hover { background: rgba(255,255,255,0.14); color: var(--text); }
[data-theme="light"] .msg.assistant .msg-action-btn {
  background: rgba(0,0,0,0.04);
  border-color: var(--border);
  color: var(--text-dim);
}
[data-theme="light"] .msg.assistant .msg-action-btn:hover { background: var(--surface2); }
.msg.user .msg-action-btn { background: rgba(0,0,0,0.15); border-color: rgba(255,255,255,0.15); color: rgba(255,255,255,0.7); }
.msg.user .msg-action-btn:hover { background: rgba(0,0,0,0.25); color: #fff; }

/* ── Input area ────────────────────────────────────────────────── */
#input-area {
  padding: 0.6rem 1.25rem 0.85rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
}

#status-bar {
  font-size: 0.75rem;
  color: var(--text-dim);
  min-height: 1em;
  text-align: center;
  width: 100%;
  max-width: 640px;
}

/* ── Single input row ──────────────────────────────────────────── */
#text-input-row {
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 640px;
  gap: 0.4rem;
}

#text-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 1rem;
  color: var(--text);
  font-size: 0.9rem;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
  min-width: 0;
  height: 42px;
}
#text-input:focus { border-color: var(--accent); }
#text-input::placeholder { color: var(--text-faint); }

/* ── Mic button (inline, circular) ────────────────────────────── */
#voice-btn-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#voice-btn {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  position: relative;
  z-index: 1;
  flex-shrink: 0;
}
#voice-btn svg { width: 18px; height: 18px; }
#voice-btn:hover { border-color: var(--accent); color: var(--accent); }
#voice-btn.recording { background: var(--red); border-color: var(--red); color: #fff; transform: scale(1.06); }
#voice-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

#pulse-ring {
  position: absolute;
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 2px solid var(--red);
  opacity: 0;
  pointer-events: none;
}
#pulse-ring.active { animation: pulse-ring 1s infinite ease-out; }

#speaker-pulse {
  position: absolute;
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 2px solid var(--green);
  opacity: 0;
  pointer-events: none;
}
#speaker-pulse.active { animation: pulse-ring 1.4s infinite ease-out; }

@keyframes pulse-ring {
  0%   { transform: scale(1);   opacity: 0.7; }
  100% { transform: scale(1.7); opacity: 0; }
}

/* ── Stop button (inline, replaces send while audio plays) ─────── */
#stop-btn {
  width: 42px; height: 42px;
  background: var(--red);
  border: none;
  border-radius: 10px;
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, transform 0.1s;
  animation: fade-in 0.15s ease;
  flex-shrink: 0;
}
#stop-btn svg { width: 16px; height: 16px; }
#stop-btn:hover { background: #c0392b; transform: scale(1.04); }

@keyframes fade-in {
  from { opacity: 0; transform: scale(0.85); }
  to   { opacity: 1; transform: scale(1); }
}

/* ── Send button ───────────────────────────────────────────────── */
#send-btn {
  width: 42px; height: 42px;
  background: var(--accent);
  border: none;
  border-radius: 10px;
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
#send-btn svg { width: 17px; height: 17px; }
#send-btn:hover { background: var(--accent-dim); }
#send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Apps menu popup ───────────────────────────────────────────── */
.apps-menu-popup {
  position: fixed;
  z-index: 9999;
  background: var(--popup-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.35);
  padding: 10px 8px 12px;
  width: 252px;
}
.apps-menu-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-faint);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  padding: 0 6px 8px;
}
.apps-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; }

.app-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 4px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text-dim);
  transition: background 0.12s;
}
.app-item:hover { background: var(--surface2); }
.app-item-current { outline: 1px solid rgba(108,99,255,0.4); }

.app-item-icon {
  width: 42px; height: 42px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.app-item-name { font-size: 11px; font-weight: 500; text-align: center; line-height: 1.3; color: var(--text-dim); }
.apps-loading { padding: 14px 8px; font-size: 13px; color: var(--text-faint); text-align: center; grid-column: 1/-1; }
.apps-menu-footer { border-top: 1px solid var(--border); margin-top: 8px; padding: 8px 8px 0; }
.dapps-link { font-size: 11px; color: var(--accent); text-decoration: none; font-weight: 500; }
.dapps-link:hover { text-decoration: underline; }

/* ── Visualizations ────────────────────────────────────────────── */
.msg.viz-msg { max-width: min(860px, 96%); width: 100%; }

.viz-card {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  padding: 1rem 1.1rem;
  overflow: hidden;
}
.viz-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
}
.viz-table-wrapper { overflow-x: auto; }
.viz-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.viz-table th {
  background: var(--surface2);
  color: var(--text-dim);
  padding: 0.45rem 0.85rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.75rem;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.viz-table th:first-child { border-radius: 6px 0 0 0; }
.viz-table th:last-child  { border-radius: 0 6px 0 0; }
.viz-table td {
  padding: 0.45rem 0.85rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  white-space: nowrap;
}
.viz-table tbody tr:last-child td { border-bottom: none; }
.viz-table tbody tr:hover td { background: var(--surface2); }
.chart-container { position: relative; width: 100%; height: 260px; }

/* ── Markdown content ───────────────────────────────────────────── */
.msg-content { line-height: 1.6; }
.msg.assistant .msg-content h1,
.msg.assistant .msg-content h2,
.msg.assistant .msg-content h3 {
  font-size: 0.95rem; font-weight: 700;
  margin: 0.9rem 0 0.4rem; color: var(--text);
}
.msg.assistant .msg-content h3:first-child { margin-top: 0; }
.msg.assistant .msg-content p { margin: 0.4rem 0; }
.msg.assistant .msg-content ul,
.msg.assistant .msg-content ol { padding-left: 1.4rem; margin: 0.4rem 0; }
.msg.assistant .msg-content li { margin: 0.2rem 0; }
.msg.assistant .msg-content strong { color: var(--text); font-weight: 700; }
.msg.assistant .msg-content hr { border: none; border-top: 1px solid var(--border); margin: 0.75rem 0; }
.msg.assistant .msg-content blockquote {
  border-left: 3px solid var(--accent);
  background: rgba(108,99,255,0.08);
  margin: 0.6rem 0;
  padding: 0.5rem 0.85rem;
  border-radius: 0 8px 8px 0;
  color: var(--text);
  font-style: normal;
}
.msg.assistant .msg-content table {
  width: 100%; border-collapse: collapse; font-size: 0.82rem;
  margin: 0.6rem 0; border-radius: 8px; overflow: hidden;
}
.msg.assistant .msg-content th {
  background: rgba(108,99,255,0.2); color: var(--text);
  font-weight: 600; text-align: left;
  padding: 0.45rem 0.7rem; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.msg.assistant .msg-content td {
  padding: 0.4rem 0.7rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.msg.assistant .msg-content tr:last-child td { border-bottom: none; }
.msg.assistant .msg-content tr:nth-child(even) td { background: var(--surface2); }
.msg.assistant .msg-content tr:hover td { background: rgba(108,99,255,0.06); }

/* ── Settings modal ────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  backdrop-filter: blur(2px);
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}
.modal-close-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: background 0.15s, color 0.15s;
}
.modal-close-btn:hover { background: var(--surface2); color: var(--text); }

.modal-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.settings-row {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.settings-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}
.settings-label > span:first-child {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.settings-hint {
  font-size: 0.72rem;
  color: var(--text-faint);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

.pill-group {
  display: flex;
  gap: 6px;
}
.pill {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  font-family: var(--font);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.pill:hover { background: var(--border); color: var(--text); }
.pill.pill-active {
  background: rgba(108,99,255,0.18);
  border-color: var(--accent);
  color: var(--accent);
}
.pill-badge {
  font-size: 0.65rem;
  font-weight: 700;
  background: var(--green);
  color: #fff;
  padding: 1px 5px;
  border-radius: 4px;
  line-height: 1.4;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.pill.pill-active .pill-badge { opacity: 1; }

/* ── Scrollbar ─────────────────────────────────────────────────── */
::-webkit-scrollbar        { width: 5px; }
::-webkit-scrollbar-track  { background: transparent; }
::-webkit-scrollbar-thumb  { background: var(--border); border-radius: 3px; }

/* ── Mobile responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0,0,0,0.4);
  }
  #sidebar.sidebar-open {
    transform: translateX(0);
  }
  #sidebar-overlay.overlay-visible {
    display: block;
  }
  #mobile-topbar {
    display: flex;
  }
  #conversation {
    padding: 1rem 0.85rem 0.5rem;
  }
  #input-area {
    padding: 0.5rem 0.85rem 0.75rem;
  }
  .msg { max-width: 100%; }
  .msg-bubble { max-width: calc(100vw - 80px); font-size: 0.88rem; }
  #text-input-row { max-width: 100%; }
}

@media (max-width: 480px) {
  #voice-hint { display: none; }
  .msg-bubble { font-size: 0.85rem; padding: 0.6rem 0.85rem; }
  .login-card { padding: 2rem 1.25rem; }
}
