/* ================================================================
   SEM Support Agent — Sage Teal Theme
   ================================================================
   Fonts:   Source Code Pro (headings, code, metadata)
            Inter (body text)
   Palette: Deep green-black bg, sage-teal accent, warm gold secondary
   ================================================================ */

/* ── Design Tokens ──────────────────────────────────────── */
:root {
  --bg:         #0B1210;
  --surface:    #131E1A;
  --surface2:   #1D2B25;
  --surface3:   #273830;
  --border:     #273830;
  --border-hl:  #3C5548;
  --text:       #E2EDE6;
  --text-dim:   #7A9688;
  --accent:     #5B9A8B;
  --accent2:    #7AB5A5;
  --accent3:    #D4A657;
  --danger:     #f87171;
  --danger-bg:  #2d1518;
  --font:       'Inter', 'Segoe UI', system-ui, sans-serif;
  --mono:       'Source Code Pro', 'Fira Code', 'Cascadia Code', monospace;
  --radius:     6px;
  --radius-sm:  3px;
  --shadow-sm:  0 2px 12px rgba(0,0,0,0.35);
  --shadow-glow: 0 0 24px rgba(91, 154, 139, 0.08);
  --transition: 0.2s ease;
}

/* ── Light Theme Override ──────────────────────────────── */
[data-theme="light"] {
  --bg:         #F4F9F7;
  --surface:    #ffffff;
  --surface2:   #ECF3F0;
  --surface3:   #DBE8E2;
  --border:     #C0D1C8;
  --border-hl:  #97B5A6;
  --text:       #1A2420;
  --text-dim:   #5A7568;
  --accent:     #3E8474;
  --accent2:    #2E7464;
  --accent3:    #B8902F;
  --danger:     #dc2626;
  --danger-bg:  #fef2f2;
  --shadow-sm:  0 2px 12px rgba(0,0,0,0.08);
  --shadow-glow: 0 0 24px rgba(62, 132, 116, 0.06);
}

/* ── Reset & Base ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  /* Subtle radial glow at top for depth */
  background-image: radial-gradient(ellipse at 50% 0%, rgba(91, 154, 139, 0.04) 0%, transparent 60%);
  background-attachment: fixed;
  /* Distinctive top accent bar */
  border-top: 3px solid var(--accent);
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition);
}
a:hover { color: #7ABFAE; text-decoration: underline; }

/* Light theme: softer link hover, neutral body glow */
[data-theme="light"] a:hover { color: #2E7464; }
[data-theme="light"] body {
  background-image: radial-gradient(ellipse at 50% 0%, rgba(62, 132, 116, 0.05) 0%, transparent 60%);
}

/* ── Header ─────────────────────────────────────────────── */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(11, 18, 16, 0.82);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  min-height: 56px;
  display: flex;
  align-items: center;
}
[data-theme="light"] header { background: rgba(244, 249, 247, 0.85); }

/* Theme toggle button */
.theme-toggle-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 1.1rem;
  padding: 0.2rem 0.45rem;
  cursor: pointer;
  transition: all var(--transition);
  line-height: 1;
  flex-shrink: 0;
  margin-left: auto;
}
.theme-toggle-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--surface2);
}

/* Rate limit indicator pill in header */
.rate-indicator {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.15rem 0.5rem;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
  white-space: nowrap;
}
.rate-indicator.rate-low {
  color: var(--accent3);
  border-color: var(--accent3);
}
.rate-indicator.rate-exhausted {
  color: var(--danger);
  border-color: var(--danger);
}

.header-inner {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  letter-spacing: -0.01em;
}
.logo:hover { color: var(--accent); text-decoration: none; }

.logo-icon {
  color: var(--accent);
  font-size: 1.1rem;
  filter: drop-shadow(0 0 4px rgba(91, 154, 139, 0.4));
}

.header-model {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  background: var(--surface);
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  white-space: nowrap;
  letter-spacing: 0.02em;
}

nav {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  margin-left: auto;
  flex-wrap: wrap;
}

/* Hamburger menu button — hidden on desktop */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.4rem;
  cursor: pointer;
  margin-left: auto;
}
.hamburger-bar {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text-dim);
  border-radius: 1px;
  transition: all 0.2s ease;
}
.hamburger-open .hamburger-bar:nth-child(1) { transform: rotate(45deg) translate(4px, 4px); }
.hamburger-open .hamburger-bar:nth-child(2) { opacity: 0; }
.hamburger-open .hamburger-bar:nth-child(3) { transform: rotate(-45deg) translate(4px, -4px); }

.nav-link {
  font-size: 0.82rem;
  color: var(--text-dim);
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
  text-decoration: none;
  white-space: nowrap;
}
.nav-link:hover {
  color: var(--text);
  background: var(--surface);
  text-decoration: none;
}
.nav-link.active {
  color: var(--accent);
  background: rgba(91, 154, 139, 0.10);
}

.nav-user {
  font-size: 0.8rem;
  color: var(--text-dim);
  font-family: var(--mono);
  margin-left: 0.75rem;
  letter-spacing: 0.01em;
}

/* ── Main / Footer ──────────────────────────────────────── */
main {
  flex: 1;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

/* When sidebar is present, main becomes full-width flex container */
main.has-sidebar {
  max-width: 100%;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: stretch;
}
main.has-sidebar .main-content-area {
  flex: 1;
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
  min-width: 0;
}

footer {
  text-align: center;
  padding: 1.25rem;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-dim);
  font-family: var(--mono);
  letter-spacing: 0.02em;
}

.footer-text { opacity: 0.7; }

/* ── Card (frosted glass) ───────────────────────────────── */
.card {
  background: rgba(19, 30, 26, 0.65);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(39, 56, 48, 0.6);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-glow);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.card:hover {
  border-color: var(--border-hl);
  border-left-color: var(--accent2);
}

/* ── Form Elements ──────────────────────────────────────── */
textarea, select, input[type="text"], input[type="email"],
input[type="password"], input[type="number"], input[type="search"] {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.75rem;
  font-family: var(--font);
  font-size: 0.9rem;
  width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

textarea:focus, select:focus, input[type="text"]:focus,
input[type="email"]:focus, input[type="password"]:focus,
input[type="number"]:focus, input[type="search"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91, 154, 139, 0.14);
}

textarea::placeholder, input::placeholder {
  color: var(--text-dim);
  opacity: 0.65;
}

select {
  cursor: pointer;
  appearance: auto;
}

label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-dim);
  display: block;
  margin-bottom: 0.3rem;
}

/* ── Query form (ask page) ──────────────────────────────── */
.query-form { display: flex; flex-direction: column; gap: 0.75rem; }
.form-row { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.form-row > div { flex: 1; min-width: 160px; }

.controls-row {
  display: flex;
  gap: 1.25rem;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 0.25rem;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
}

.checkbox-label input[type="checkbox"] {
  width: auto;
  accent-color: var(--accent);
}

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  text-decoration: none;
  line-height: 1.4;
}

.btn-primary {
  background: linear-gradient(180deg, #5B9A8B, #4A8A7B);
  color: #0B1210;
  box-shadow: 0 2px 8px rgba(91, 154, 139, 0.25);
}
.btn-primary:hover {
  background: linear-gradient(180deg, #69A89A, #5B9A8B);
  box-shadow: 0 4px 16px rgba(91, 154, 139, 0.35);
  transform: translateY(-1px);
  color: #0B1210;
  text-decoration: none;
}
.btn-primary:active {
  transform: translateY(0);
  box-shadow: 0 1px 4px rgba(91, 154, 139, 0.25);
}
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(91, 154, 139, 0.08);
  text-decoration: none;
}

/* ── View Mode Tabs ─────────────────────────────────────── */
.view-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 1.25rem;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 3px;
  border: 1px solid var(--border);
}

.view-tab {
  flex: 1;
  text-align: center;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  border: none;
  background: transparent;
  font-family: var(--font);
}

.view-tab:hover { color: var(--text); background: var(--surface2); }

.view-tab.active {
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
}

/* ── Answer Area ────────────────────────────────────────── */
#answer-area:empty::after {
  content: 'Your answer will appear here\2026';
  display: block;
  text-align: center;
  padding: 2rem;
  color: var(--text-dim);
  font-style: italic;
  opacity: 0.5;
}

.answer-block {
  padding: 1rem 0;
}

.answer-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-bottom: 0.75rem;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ── Answer text typography ─────────────────────────────── */
.answer-text {
  line-height: 1.72;
  font-size: 0.95rem;
  color: var(--text);
  letter-spacing: 0.01em;
}

.answer-text p { margin-bottom: 0.6rem; }
.answer-text p:last-child { margin-bottom: 0; }

.answer-text code {
  background: var(--surface2);
  padding: 0.15rem 0.4rem;
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 0.86em;
  color: var(--accent);
  border: 1px solid rgba(39, 56, 48, 0.5);
}

.answer-text pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  overflow-x: auto;
  margin: 0.6rem 0;
  font-family: var(--mono);
  font-size: 0.86em;
  line-height: 1.5;
}

.answer-text pre code {
  background: none;
  padding: 0;
  border: none;
  color: var(--text);
}

.answer-text h1, .answer-text h2, .answer-text h3 {
  margin: 1rem 0 0.4rem;
  font-family: var(--mono);
  color: var(--accent);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.answer-text h1 { font-size: 1.3rem; }
.answer-text h2 { font-size: 1.15rem; }
.answer-text h3 { font-size: 1.05rem; }

.answer-text ul, .answer-text ol {
  margin: 0.3rem 0 0.6rem 1.5rem;
}
.answer-text li { margin-bottom: 0.25rem; }

.answer-text blockquote {
  border-left: 3px solid var(--accent);
  padding: 0.4rem 0 0.4rem 0.75rem;
  color: var(--text-dim);
  margin: 0.5rem 0;
  font-style: italic;
  background: rgba(91, 154, 139, 0.04);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.answer-text table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.5rem 0;
  font-size: 0.9rem;
}
.answer-text th, .answer-text td {
  border: 1px solid var(--border);
  padding: 0.4rem 0.6rem;
  text-align: left;
}
.answer-text th {
  background: var(--surface);
  color: var(--text-dim);
  font-weight: 600;
  font-family: var(--mono);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.answer-text strong { color: var(--text); font-weight: 700; }

/* ── Metadata Strip ─────────────────────────────────────── */
.metadata-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.25rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  padding: 0.75rem 0;
  border-top: 1px solid var(--border);
}

/* Compact metadata bar (streaming pages) */
.metadata-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 0;
  border-top: 1px solid var(--border);
  margin-top: 0.75rem;
}

.meta-pill {
  font-family: var(--mono);
  font-size: 0.7rem;
  padding: 0.12rem 0.45rem;
  border-radius: 10px;
  background: var(--surface);
  color: var(--text-dim);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.meta-pill.deep {
  background: rgba(196, 149, 106, 0.12);
  border-color: rgba(196, 149, 106, 0.3);
  color: var(--accent3);
}

/* ── Collapsible Context Docs (streaming pages) ─────────── */
.context-docs-panel {
  margin-top: 0.5rem;
}

.context-docs-panel summary {
  font-size: 0.75rem;
  color: var(--text-dim);
  cursor: pointer;
  font-family: var(--mono);
  padding: 0.25rem 0;
  letter-spacing: 0.02em;
}

.context-docs-panel summary:hover {
  color: var(--accent);
}

.context-docs-panel[open] summary {
  color: var(--accent);
  margin-bottom: 0.35rem;
}

.context-docs-panel .context-doc-list {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.context-docs-panel .context-doc-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.72rem;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid transparent;
  transition: border-color var(--transition);
}

.context-docs-panel .context-doc-item:hover {
  border-color: var(--border);
}

.doc-role {
  color: var(--accent);
  font-family: var(--mono);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.65rem;
  letter-spacing: 0.04em;
  min-width: 3.5rem;
}

.doc-name {
  color: var(--text);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-tokens {
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 0.68rem;
  white-space: nowrap;
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.meta-label {
  color: var(--text-dim);
  text-transform: uppercase;
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.meta-value {
  color: var(--text);
}

/* ── Tier Badges ────────────────────────────────────────── */
.tier-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.12rem 0.45rem;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 700;
  font-family: var(--mono);
  letter-spacing: 0.04em;
}

.tier-0 { background: rgba(122, 181, 165, 0.15); color: #7AB5A5; }
.tier-1 { background: rgba(91, 154, 139, 0.15); color: var(--accent); }
.tier-2 { background: rgba(196, 149, 106, 0.15); color: var(--accent3); }
.tier-3 { background: rgba(248, 113, 113, 0.15); color: var(--danger); }

/* ── Confidence Tags ────────────────────────────────────── */
.confidence-tag {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.1rem 0.4rem;
  border-radius: 8px;
  letter-spacing: 0.03em;
}

.confidence-tag.high    { background: rgba(122, 181, 165, 0.12); color: #7AB5A5; }
.confidence-tag.medium  { background: rgba(196, 149, 106, 0.12); color: var(--accent3); }
.confidence-tag.low     { background: rgba(248, 113, 113, 0.12); color: var(--danger); }

/* ── Context docs list ──────────────────────────────────── */
.context-docs {
  margin-top: 0.5rem;
}

.context-docs summary {
  font-size: 0.78rem;
  color: var(--text-dim);
  cursor: pointer;
  font-family: var(--mono);
}

.context-doc-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-top: 0.4rem;
}

.context-doc-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid transparent;
  transition: border-color var(--transition);
}
.context-doc-item:hover {
  border-color: var(--border);
}

.doc-score {
  color: var(--accent);
  font-family: var(--mono);
  font-weight: 600;
  min-width: 3.5rem;
}

.doc-name {
  color: var(--text);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Debug Panel ────────────────────────────────────────── */
.debug-panel {
  margin-top: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
}

.debug-panel summary {
  font-size: 0.78rem;
  font-family: var(--mono);
  color: var(--text-dim);
  cursor: pointer;
  letter-spacing: 0.03em;
}

.debug-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 0.75rem;
  margin-top: 0.5rem;
  font-size: 0.78rem;
}

.debug-key {
  color: var(--text-dim);
  font-family: var(--mono);
  white-space: nowrap;
}

.debug-val {
  color: var(--text);
  word-break: break-word;
  font-family: var(--mono);
}

/* ── HTMX Loading & Spinner ─────────────────────────────── */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-flex; }
.htmx-request.htmx-indicator { display: inline-flex; }

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Settings Page ──────────────────────────────────────── */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.setting-field label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  font-family: var(--mono);
  margin-bottom: 0.3rem;
}

.setting-value {
  font-size: 0.9rem;
  color: var(--text);
  word-break: break-all;
}

.model-select {
  min-width: 200px;
}

.model-badge {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--accent);
  letter-spacing: 0.02em;
}

/* ── Utility Classes ────────────────────────────────────── */
.mt-1  { margin-top: 0.5rem; }
.mt-2  { margin-top: 1rem; }
.mb-1  { margin-bottom: 0.5rem; }
.text-dim { color: var(--text-dim); }
.text-sm  { font-size: 0.85rem; }
.text-xs  { font-size: 0.75rem; }
.mono     { font-family: var(--mono); }

/* ── Chat Mode ──────────────────────────────────────────── */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 56px - 4rem);
  min-height: 400px;
  padding: 0;
  overflow: hidden;
}

.chat-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  background: rgba(19, 30, 26, 0.5);
  flex-wrap: wrap;
}

.chat-toolbar-left,
.chat-toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.chat-hint-select {
  width: auto;
  min-width: 120px;
  font-size: 0.8rem;
  padding: 0.3rem 0.5rem;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scroll-behavior: smooth;
}

.chat-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  font-style: italic;
}

.chat-empty-inner {
  animation: heroFadeUp 0.5s ease both;
}

.chat-empty-icon {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
  filter: drop-shadow(0 0 10px rgba(91, 154, 139, 0.25));
  animation: emptyPulse 3s ease-in-out infinite;
}

@keyframes emptyPulse {
  0%, 100% { transform: scale(1); opacity: 0.8; }
  50%      { transform: scale(1.06); opacity: 1; }
}

.chat-empty-title {
  font-family: var(--mono);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.3rem;
  letter-spacing: -0.01em;
}

.chat-empty-sub {
  color: var(--text-dim);
  font-size: 0.88rem;
  font-style: normal;
  max-width: 380px;
  margin: 0 auto 1rem;
  line-height: 1.5;
}

.chat-empty-suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
}

.suggestion-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0.35rem 0.75rem;
  border-radius: 16px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font);
  font-style: normal;
}

.suggestion-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(91, 154, 139, 0.08);
}

/* Follow-up suggestion chips (post-answer) */
.followup-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.75rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
  align-items: center;
}
.followup-label {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-right: 0.25rem;
  white-space: nowrap;
}

.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: msgSlideIn 0.25s ease;
}

@keyframes msgSlideIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.chat-user {
  align-self: flex-end;
}

.chat-assistant {
  align-self: flex-start;
}

.chat-system {
  align-self: center;
  max-width: 90%;
}

.chat-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-bottom: 0.2rem;
  padding: 0 0.35rem;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.chat-user .chat-label { text-align: right; }

.chat-bubble {
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius);
  font-size: 0.92rem;
  line-height: 1.6;
  word-break: break-word;
}

.chat-user .chat-bubble {
  background: linear-gradient(135deg, #4A8A7B 0%, #5B9A8B 100%);
  color: #0B1210;
  border-bottom-right-radius: 3px;
  font-weight: 500;
}

.chat-assistant .chat-bubble {
  background: var(--surface2);
  color: var(--text);
  border-bottom-left-radius: 3px;
  border: 1px solid var(--border);
}

/* Chat bubble markdown */
.chat-bubble p { margin-bottom: 0.4rem; }
.chat-bubble p:last-child { margin-bottom: 0; }
.chat-bubble code {
  font-family: var(--mono);
  font-size: 0.86em;
  padding: 0.1rem 0.3rem;
  border-radius: var(--radius-sm);
}
.chat-user .chat-bubble code {
  background: rgba(0,0,0,0.15);
}
.chat-assistant .chat-bubble code {
  background: var(--surface);
  color: var(--accent);
  border: 1px solid rgba(39, 56, 48, 0.5);
}
.chat-bubble pre {
  margin: 0.4rem 0;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-size: 0.84em;
}
.chat-user .chat-bubble pre { background: rgba(0,0,0,0.15); }
.chat-assistant .chat-bubble pre {
  background: var(--surface);
  border: 1px solid var(--border);
}
.chat-bubble pre code {
  background: none;
  padding: 0;
  border: none;
  color: inherit;
}
.chat-bubble strong { font-weight: 700; }
.chat-bubble h1, .chat-bubble h2, .chat-bubble h3 {
  margin: 0.5rem 0 0.3rem;
  font-family: var(--mono);
}
.chat-assistant .chat-bubble h1,
.chat-assistant .chat-bubble h2,
.chat-assistant .chat-bubble h3 { color: var(--accent); }
.chat-bubble ul, .chat-bubble ol {
  margin: 0.2rem 0 0.4rem 1.2rem;
}

.chat-meta {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.15rem 0.35rem;
  margin-top: 0.2rem;
}

/* ── Chat Input ─────────────────────────────────────────── */
.chat-input-form {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  background: rgba(19, 30, 26, 0.5);
}

.chat-input-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.chat-input-row textarea {
  flex: 1;
  resize: none;
  min-height: 42px;
  max-height: 120px;
  font-size: 0.92rem;
  line-height: 1.5;
  padding: 0.55rem 0.75rem;
}

.chat-input-row .btn {
  padding: 0.55rem 1.25rem;
  white-space: nowrap;
  align-self: flex-end;
}

/* ── Attach / Image Upload Button ───────────────────────── */
.btn-attach {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.4rem 0.55rem;
  color: var(--text-dim);
  transition: color 0.15s, border-color 0.15s, transform 0.15s;
  flex-shrink: 0;
  align-self: flex-end;
  line-height: 1;
}
.btn-attach:hover { color: var(--accent); border-color: var(--accent); }
.btn-attach.uploading {
  opacity: 0.5;
  pointer-events: none;
  animation: pulse-attach 0.8s ease-in-out infinite;
}
@keyframes pulse-attach { 0%,100% { opacity: 0.5; } 50% { opacity: 0.9; } }

/* ── Image Preview Row ──────────────────────────────────── */
.image-preview-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0;
}
.image-preview-thumb {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.25rem 0.5rem 0.25rem 0.25rem;
  max-width: 280px;
}
.image-preview-thumb img {
  height: 48px;
  max-width: 80px;
  object-fit: cover;
  border-radius: 5px;
}
.image-preview-name {
  font-size: 0.75rem;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
}
.image-preview-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: var(--danger, #f87171);
  color: #fff;
  font-size: 0.7rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.image-preview-remove:hover { background: #ef4444; }

/* ── User bubble image thumbnail ────────────────────────── */
.user-image-thumb {
  max-width: 200px;
  max-height: 150px;
  border-radius: 6px;
  margin-bottom: 0.35rem;
  display: block;
}

/* ── Drag-and-drop overlay ──────────────────────────────── */
.drag-over {
  outline: 2px dashed var(--accent) !important;
  outline-offset: -4px;
  background: rgba(99, 102, 241, 0.05) !important;
}

/* ── Guided Mode ────────────────────────────────────────── */
.guided-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 1.5rem;
  min-height: calc(100vh - 56px - 5rem);
}

.guided-sidebar {
  position: sticky;
  top: calc(56px + 1.5rem);
  align-self: start;
  max-height: calc(100vh - 56px - 3rem);
  overflow-y: auto;
}

.step-list { list-style: none; }

.step-item {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.5rem 0.3rem;
  font-size: 0.85rem;
  color: var(--text-dim);
  cursor: default;
  transition: color var(--transition);
}

.step-item.current {
  color: var(--text);
  font-weight: 600;
}

.step-item.completed {
  color: var(--accent2);
}

.step-item.upcoming {
  opacity: 0.5;
}

/* Step marker (circle) */
.step-marker {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  flex-shrink: 0;
  transition: all var(--transition);
  font-family: var(--mono);
}

.step-item.current .step-marker {
  border-color: var(--accent);
  background: rgba(91, 154, 139, 0.14);
  color: var(--accent);
  box-shadow: 0 0 8px rgba(91, 154, 139, 0.15);
}

.step-item.completed .step-marker {
  border-color: var(--accent2);
  background: rgba(122, 181, 165, 0.12);
  color: var(--accent2);
}

.step-name { padding-top: 1px; }

/* Connector line between steps */
.step-item:not(:last-child)::after {
  content: '';
  position: absolute;
  left: 10px;
  top: calc(0.5rem + 22px + 2px);
  width: 2px;
  height: calc(100% - 22px - 0.5rem);
  background: var(--border);
}

.step-item.completed:not(:last-child)::after {
  background: var(--accent2);
}

.guided-main {
  padding: 0.5rem 0;
}

.guided-welcome {
  text-align: center;
  padding: 2rem 1rem;
  animation: heroFadeUp 0.5s ease both;
}

.guided-welcome h2 {
  font-family: var(--mono);
  color: var(--accent);
  margin-bottom: 0.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.guided-welcome p {
  color: var(--text-dim);
  max-width: 480px;
  margin: 0 auto 1.5rem;
}

/* Guided step content entrance */
.guided-step-header {
  animation: heroFadeUp 0.4s ease both;
}

.guided-step-answer {
  animation: heroFadeUp 0.4s ease both;
  animation-delay: 0.1s;
}

.guided-followup-section {
  animation: heroFadeUp 0.4s ease both;
  animation-delay: 0.18s;
}

.guided-nav-buttons {
  animation: heroFadeUp 0.4s ease both;
  animation-delay: 0.25s;
}

.step-header {
  margin-bottom: 1rem;
}

.step-header h2 {
  font-family: var(--mono);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.25rem;
  letter-spacing: -0.01em;
}

.step-header .step-subtitle {
  color: var(--text-dim);
  font-size: 0.92rem;
}

.followup-section {
  margin-top: 1.5rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.followup-section h4 {
  font-size: 0.88rem;
  font-family: var(--mono);
  color: var(--accent3);
  margin-bottom: 0.75rem;
}

.followup-section textarea {
  margin-bottom: 0.5rem;
}

.guided-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.guided-complete {
  text-align: center;
  padding: 3rem 1rem;
}

.guided-complete h2 {
  color: var(--accent2);
  font-family: var(--mono);
  margin-bottom: 0.5rem;
}

.guided-complete p {
  color: var(--text-dim);
  margin-bottom: 1.5rem;
}

/* ── Typewriter Animation ───────────────────────────────── */
.typewriter-pending {
  visibility: hidden;
  position: absolute;
  pointer-events: none;
}

.typewriter-cursor::after {
  content: '';
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--accent);
  margin-left: 1px;
  vertical-align: text-bottom;
  animation: twBlink 0.7s step-end infinite;
}

@keyframes twBlink { 50% { opacity: 0; } }

/* ── Small Button Variant ───────────────────────────────── */
.btn-sm {
  padding: 0.35rem 0.8rem;
  font-size: 0.78rem;
}

/* ── Feedback System ────────────────────────────────────── */
.feedback-wrapper {
  margin-top: 0.5rem;
}

.btn-feedback {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.75rem;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-feedback:hover {
  border-color: var(--accent3);
  color: var(--accent3);
  background: rgba(196, 149, 106, 0.06);
}

.feedback-form-container {
  margin-top: 0.5rem;
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--accent3);
  border-radius: var(--radius);
}

.feedback-form .feedback-field {
  margin-bottom: 0.6rem;
}
.feedback-form .feedback-field label {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-bottom: 0.25rem;
}
.feedback-form textarea {
  min-height: 60px;
  font-size: 0.85rem;
}
.feedback-form input[type="file"] {
  font-size: 0.8rem;
  color: var(--text-dim);
  padding: 0.3rem 0;
}

/* ── Paste / drop zone for images ── */
.paste-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.paste-zone:hover,
.paste-zone:focus {
  border-color: var(--accent3);
  background: rgba(196, 149, 106, 0.04);
  outline: none;
}
.paste-zone-active {
  border-color: var(--accent3) !important;
  background: rgba(196, 149, 106, 0.08) !important;
}

.paste-zone-hint {
  font-size: 0.78rem;
  color: var(--text-dim);
}
.paste-browse-link {
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
  font-size: 0.78rem;
}

.paste-preview {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.paste-preview img {
  max-height: 80px;
  max-width: 200px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  object-fit: contain;
}

/* Attachment chip */
.paste-attachment {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.2rem 0.5rem;
  font-size: 0.78rem;
  color: var(--text);
}
.paste-attach-icon {
  font-size: 0.9rem;
}
.paste-attach-name {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.paste-remove-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 0.7rem;
  cursor: pointer;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.paste-remove-btn:hover {
  border-color: #e74c3c;
  color: #e74c3c;
  background: rgba(231, 76, 60, 0.08);
}

.feedback-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.feedback-success {
  padding: 0.5rem 0.75rem;
  background: rgba(122, 181, 165, 0.1);
  border: 1px solid var(--accent2);
  border-radius: var(--radius-sm);
  color: var(--accent2);
  font-size: 0.82rem;
  font-weight: 600;
  margin-top: 0.4rem;
}

/* ── Streaming Cursor ───────────────────────────────────── */
.streaming-cursor {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink-stream 0.8s step-end infinite;
}
@keyframes blink-stream {
  50% { opacity: 0; }
}

/* ── Loading indicator inline ───────────────────────────── */
#loading-indicator {
  align-items: center;
  gap: 0.5rem;
}

/* ── Answer text during streaming ───────────────────────── */
#stream-answer-text {
  line-height: 1.72;
  font-size: 0.95rem;
  animation: fadeIn 0.3s ease;
}
#stream-answer-text p { margin-bottom: 0.5rem; }
#stream-answer-text p:last-child { margin-bottom: 0; }
#stream-answer-text ol, #stream-answer-text ul {
  margin: 0.3rem 0 0.5rem 1.4rem;
}
#stream-answer-text code {
  background: var(--surface2);
  padding: 0.1rem 0.35rem;
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 0.88em;
  color: var(--accent);
  border: 1px solid rgba(39, 56, 48, 0.5);
}
#stream-answer-text strong { color: var(--text); font-weight: 700; }
#stream-answer-text h1, #stream-answer-text h2, #stream-answer-text h3 {
  margin: 0.6rem 0 0.3rem;
  color: var(--accent);
  font-family: var(--mono);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Chat bubble during streaming ───────────────────────── */
#stream-chat-bubble code {
  background: rgba(0,0,0,0.2);
  padding: 0.1rem 0.3rem;
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 0.88em;
}

/* ── Scrollbar styling ──────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--border-hl);
}

/* ── Selection ──────────────────────────────────────────── */
::selection {
  background: rgba(91, 154, 139, 0.25);
  color: var(--text);
}

/* ── Hero Section (Landing Page) ───────────────────────── */
.hero {
  text-align: center;
  padding: 3.5rem 1rem 2rem;
}

/* Staggered entrance animation for hero children */
.hero-icon,
.hero-title,
.hero-tagline,
.hero-search {
  animation: heroFadeUp 0.6s ease both;
}
.hero-icon    { animation-delay: 0s; }
.hero-title   { animation-delay: 0.08s; }
.hero-tagline { animation-delay: 0.16s; }
.hero-search  { animation-delay: 0.24s; }

@keyframes heroFadeUp {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}

.hero-icon {
  font-size: 3rem;
  margin-bottom: 0.75rem;
  filter: drop-shadow(0 0 12px rgba(91, 154, 139, 0.25));
  display: inline-block;
}

.hero-title {
  font-family: var(--mono);
  font-size: 2.1rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, var(--accent), #7ABFAE, var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.5rem;
}

.hero-tagline {
  color: var(--text-dim);
  font-size: 1.05rem;
  max-width: 560px;
  margin: 0 auto 2rem;
  line-height: 1.55;
  letter-spacing: 0.01em;
}

.hero-search {
  max-width: 640px;
  margin: 0 auto;
}

.hero-input-wrap {
  display: flex;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.hero-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91, 154, 139, 0.14), 0 0 20px rgba(91, 154, 139, 0.08);
}

.hero-input-wrap input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 1.05rem;
  padding: 0.85rem 1.25rem;
  outline: none;
  font-family: var(--font);
}

.hero-input-wrap input::placeholder {
  color: var(--text-dim);
}

.hero-ask-btn {
  border-radius: 0;
  padding: 0.85rem 1.75rem;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-left: 1px solid var(--border);
}

.advanced-options {
  margin-top: 0.75rem;
  text-align: left;
}

.advanced-options summary {
  cursor: pointer;
  font-size: 0.85rem;
  text-align: center;
}

/* ── Quick Topics ──────────────────────────────────────── */
.quick-topics {
  margin-top: 2rem;
  animation: heroFadeUp 0.6s ease both;
  animation-delay: 0.35s;
}

.section-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.75rem;
  font-family: var(--mono);
}

.topic-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

.topic-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 1rem;
  border-radius: 20px;
  font-size: 0.86rem;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  font-family: var(--font);
}

.topic-btn:hover {
  background: var(--surface2);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Mode Cards ────────────────────────────────────────── */
.mode-cards {
  margin-top: 2.5rem;
  animation: heroFadeUp 0.6s ease both;
  animation-delay: 0.45s;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.mode-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.5rem 1rem;
  background: rgba(19, 30, 26, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
  transition: border-color var(--transition), transform var(--transition), box-shadow var(--transition);
  text-decoration: none;
}

.mode-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(91, 154, 139, 0.10);
  text-decoration: none;
}

.mode-icon {
  font-size: 1.75rem;
  margin-bottom: 0.5rem;
  filter: drop-shadow(0 0 6px rgba(91, 154, 139, 0.15));
}

.mode-label {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
  margin-bottom: 0.25rem;
}

.mode-desc {
  font-size: 0.82rem;
  color: var(--text-dim);
  line-height: 1.4;
}

/* ── Inline Settings Bar (Ask page) ─────────────────────── */
.inline-settings-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  margin-top: 0.75rem;
  animation: heroFadeUp 0.5s ease both;
  animation-delay: 0.32s;
}

.inline-setting {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.inline-setting-label {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0;
  white-space: nowrap;
}

.inline-select {
  width: auto;
  min-width: 110px;
  font-size: 0.78rem;
  padding: 0.2rem 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
}

.inline-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(91, 154, 139, 0.1);
}

.inline-status {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--accent2);
}

/* ── Guest Banner ──────────────────────────────────────── */
.guest-banner {
  text-align: center;
  padding: 0.75rem 1rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-top: 2rem;
  font-size: 0.88rem;
  color: var(--text-dim);
}

.guest-banner a {
  color: var(--accent3);
  font-weight: 600;
}

/* ── Admin Panel ───────────────────────────────────────── */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.admin-table th,
.admin-table td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.admin-table th {
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-family: var(--mono);
}

.admin-table tr:hover td {
  background: var(--surface2);
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  font-size: 0.78rem;
  font-weight: 600;
  font-family: var(--mono);
}

.badge-admin  { background: rgba(91, 154, 139, 0.15); color: var(--accent); }
.badge-user   { background: rgba(122, 181, 165, 0.15); color: var(--accent2); }
.badge-guest  { background: rgba(126, 143, 166, 0.15); color: var(--text-dim); }
.badge-active { background: rgba(122, 181, 165, 0.15); color: var(--accent2); }
.badge-inactive { background: rgba(248, 113, 113, 0.15); color: var(--danger); }

/* ── Answer Toolbar (ask page) ──────────────────────────── */
.answer-toolbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

/* ── Copy-Answer Button ─────────────────────────────────── */
.btn-copy-answer {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.78rem;
  padding: 0.22rem 0.65rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: var(--font);
}
.btn-copy-answer:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(91, 154, 139, 0.08);
}
.btn-copy-answer.copied {
  border-color: var(--accent2);
  color: var(--accent2);
  background: rgba(122, 181, 165, 0.08);
}

/* ── Chat Bubble Wrapper (for hover copy button) ────────── */
.chat-bubble-wrap {
  position: relative;
}
.btn-copy-bubble {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.72rem;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, border-color 0.15s, color 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}
.chat-bubble-wrap:hover .btn-copy-bubble,
.btn-copy-bubble:focus { opacity: 1; }
.chat-bubble-wrap:hover .btn-export,
.btn-export:focus { opacity: 1 !important; }
.btn-copy-bubble:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.btn-copy-bubble.copied {
  opacity: 1;
  border-color: var(--accent2);
  color: var(--accent2);
}

/* ── Code Block Copy Button ─────────────────────────────── */
.code-copy-btn {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.72rem;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, border-color 0.15s, color 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}
pre:hover .code-copy-btn,
.code-copy-btn:focus { opacity: 1; }
.code-copy-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.code-copy-btn.copied {
  opacity: 1;
  border-color: var(--accent2);
  color: var(--accent2);
}

/* ── Search-Type Pill Toggle ────────────────────────────── */
.search-type-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: help;
  position: relative;
}

.toggle-label {
  white-space: nowrap;
}

.pill-toggle {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
  padding: 2px;
  gap: 2px;
}

.pill-opt {
  all: unset;
  font-family: var(--font);
  font-size: 0.78rem;
  padding: 0.2rem 0.65rem;
  border-radius: 16px;
  color: var(--text-dim);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
  line-height: 1.4;
}

.pill-opt:hover {
  color: var(--text);
  background: var(--surface2);
}

.pill-opt.active {
  background: var(--accent);
  color: #0B1210;
  font-weight: 600;
}

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
  header {
    height: auto;
    min-height: 56px;
  }

  .header-inner {
    padding: 0 0.75rem;
    gap: 0.5rem;
    flex-wrap: wrap;
  }

  .header-model { display: none; }

  /* Show hamburger, hide nav by default */
  .hamburger { display: flex; }

  /* Theme toggle & rate indicator stay in top row */
  .theme-toggle-btn { margin-left: 0; }

  nav {
    display: none;
    width: 100%;
    flex-direction: column;
    gap: 0;
    padding: 0.4rem 0;
    border-top: 1px solid var(--border);
    margin-top: 0.25rem;
    order: 10; /* push below top row when wrapping */
  }
  nav.nav-open { display: flex; }

  .nav-link {
    font-size: 0.85rem;
    padding: 0.45rem 0.65rem;
    width: 100%;
  }

  main {
    padding: 1rem 0.75rem 2rem;
  }

  .hero { padding: 2rem 0.5rem 1.5rem; }
  .hero-title { font-size: 1.6rem; }

  .card-grid {
    grid-template-columns: 1fr;
  }

  .guided-layout {
    grid-template-columns: 1fr;
  }

  .guided-sidebar {
    position: static;
    max-height: none;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.75rem;
    margin-bottom: 0.75rem;
  }

  .chat-toolbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .chat-toolbar-right {
    flex-wrap: wrap;
    gap: 0.4rem;
  }

  .form-row {
    flex-direction: column;
  }
}

@media (max-width: 480px) {
  .hero-title { font-size: 1.35rem; }
  .hero-tagline { font-size: 0.92rem; }

  .hero-input-wrap input {
    font-size: 0.95rem;
    padding: 0.75rem 1rem;
  }

  .hero-ask-btn {
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
  }

  .topic-btn {
    font-size: 0.82rem;
    padding: 0.4rem 0.8rem;
  }

  .chat-msg { max-width: 95%; }
}

/* ================================================================
   UX Polish — Toast Notifications, Keyboard Shortcuts,
   Thumbs Up/Down, Admin Stats, Export Button
   ================================================================ */

/* ── Toast Notifications ───────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column-reverse;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 1.1rem;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.85rem;
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(12px);
  animation: toastSlideIn 0.3s ease forwards;
  max-width: 360px;
  line-height: 1.4;
}

.toast.toast-success { border-color: var(--accent2); }
.toast.toast-success .toast-icon { color: var(--accent2); }
.toast.toast-info    { border-color: var(--accent); }
.toast.toast-info .toast-icon    { color: var(--accent); }
.toast.toast-error   { border-color: var(--danger); }
.toast.toast-error .toast-icon   { color: var(--danger); }
.toast.toast-warning { border-color: var(--accent3); }
.toast.toast-warning .toast-icon { color: var(--accent3); }

.toast-icon { font-size: 1.05rem; flex-shrink: 0; }

.toast.toast-exit { animation: toastSlideOut 0.25s ease forwards; }

@keyframes toastSlideIn {
  from { opacity: 0; transform: translateX(40px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes toastSlideOut {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(40px); }
}

/* ── Keyboard Shortcuts Modal ──────────────────────────── */
.shortcut-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.15s ease;
}

.shortcut-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 2rem;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}

.shortcut-modal h3 {
  margin: 0 0 1rem;
  font-family: var(--mono);
  font-size: 1rem;
  color: var(--accent);
}

.shortcut-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.shortcut-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}

.shortcut-list li:last-child { border-bottom: none; }

.shortcut-list kbd {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  background: var(--surface2);
  border: 1px solid var(--border-hl);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--accent);
  min-width: 1.6rem;
  text-align: center;
}

.shortcut-close {
  display: block;
  margin: 1rem auto 0;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0.3rem 1.2rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.82rem;
  transition: all 0.15s;
}
.shortcut-close:hover { border-color: var(--accent); color: var(--accent); }

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── Export / Download Button ──────────────────────────── */
.btn-export {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.78rem;
  padding: 0.22rem 0.65rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: var(--font);
}
.btn-export:hover {
  border-color: var(--accent3);
  color: var(--accent3);
  background: rgba(196, 149, 106, 0.06);
}

/* ── Thumbs Up / Down Quick Rating ─────────────────────── */
.quick-rating {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: 0.5rem;
}

.btn-thumb {
  background: none;
  border: 1px solid transparent;
  color: var(--text-dim);
  font-size: 1rem;
  padding: 0.15rem 0.3rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1;
  opacity: 0.6;
}
.btn-thumb:hover {
  opacity: 1;
  border-color: var(--border-hl);
  background: var(--surface2);
}
.btn-thumb.voted {
  opacity: 1;
  border-color: var(--accent);
  background: rgba(91, 154, 139, 0.1);
  color: var(--accent);
}
.btn-thumb.voted-down {
  border-color: var(--danger);
  background: rgba(248, 113, 113, 0.1);
  color: var(--danger);
}
.rating-thanks {
  font-size: 0.72rem;
  color: var(--accent2);
  font-family: var(--mono);
}

/* ── Admin Stats Cards ─────────────────────────────────── */
.admin-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  text-align: center;
}

.stat-card .stat-value {
  display: block;
  font-family: var(--mono);
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}

.stat-card .stat-label {
  display: block;
  font-size: 0.78rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 0.3rem;
}

.stat-card.stat-accent2 .stat-value { color: var(--accent2); }
.stat-card.stat-accent3 .stat-value { color: var(--accent3); }
.stat-card.stat-danger  .stat-value { color: var(--danger); }

/* Admin analytics charts grid */
.admin-charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.chart-card {
  padding: 1rem 1.25rem !important;
  position: relative;
}
.chart-wrapper {
  position: relative;
  width: 100%;
  height: 220px;
}
.chart-title {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--text-dim);
  margin: 0 0 0.75rem;
  font-weight: 500;
}

/* Top models mini-bar chart */
.model-bar-chart {
  margin-top: 0.5rem;
}
.model-bar-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
  font-size: 0.8rem;
}
.model-bar-label {
  min-width: 120px;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 0.75rem;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.model-bar-track {
  flex: 1;
  height: 8px;
  background: var(--surface2);
  border-radius: 4px;
  overflow: hidden;
}
.model-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 4px;
  transition: width 0.5s ease;
}
.model-bar-count {
  min-width: 30px;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* ── Accessibility Focus Visible ───────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:focus-visible,
a:focus-visible,
select:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  z-index: 10001;
  background: var(--accent);
  color: var(--bg);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  transition: top 0.2s;
}
.skip-link:focus {
  top: 0.5rem;
  text-decoration: none;
  color: var(--bg);
}

/* ── Light Theme Extras ────────────────────────────────── */
[data-theme="light"] .shortcut-overlay { background: rgba(0,0,0,0.3); }
[data-theme="light"] .shortcut-modal  { box-shadow: 0 8px 40px rgba(0,0,0,0.12); }
[data-theme="light"] .logo-icon       { filter: none; }
[data-theme="light"] .chat-user .chat-bubble {
  background: linear-gradient(180deg, #3E8474 0%, #4A9A8B 100%);
  color: #fff;
}
[data-theme="light"] .chat-user .chat-bubble pre { background: rgba(0,0,0,0.08); }

/* ── Error Card & Retry Button (R2.1) ─────────────────── */
.error-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 1.5rem;
  border-radius: var(--radius);
  background: var(--danger-bg, rgba(248,113,113,0.08));
  border: 1px solid var(--danger, #f87171);
  text-align: center;
}
.error-card-icon {
  font-size: 2rem;
  line-height: 1;
}
.error-card-msg {
  color: var(--danger, #f87171);
  font-size: 0.95rem;
  line-height: 1.5;
}
.error-card-partial {
  color: var(--text-dim);
  font-size: 0.82rem;
  font-style: italic;
  margin-top: -0.25rem;
}
.btn-retry {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 1.1rem;
  border-radius: var(--radius-sm);
  background: var(--danger, #f87171);
  color: #fff;
  font-weight: 600;
  font-size: 0.85rem;
  border: none;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn-retry:hover { background: #ef4444; transform: translateY(-1px); }
.btn-retry:active { transform: translateY(0); }

/* Chat bubble error variant */
.chat-bubble .error-card {
  padding: 1rem;
  border: none;
  background: none;
}

/* ── Skeleton Loading Placeholders (R2.3) ─────────────── */
@keyframes skeleton-pulse {
  0% { opacity: 0.6; }
  50% { opacity: 0.3; }
  100% { opacity: 0.6; }
}
.skeleton-block {
  border-radius: var(--radius-sm);
  background: var(--surface2, #2a2a3a);
  animation: skeleton-pulse 1.4s ease-in-out infinite;
}
.skeleton-answer {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.25rem 0;
}
.skeleton-line {
  height: 0.85rem;
  border-radius: 4px;
  background: var(--surface2, #2a2a3a);
  animation: skeleton-pulse 1.4s ease-in-out infinite;
}
.skeleton-line:nth-child(1) { width: 90%; }
.skeleton-line:nth-child(2) { width: 100%; animation-delay: 0.1s; }
.skeleton-line:nth-child(3) { width: 75%; animation-delay: 0.2s; }
.skeleton-line:nth-child(4) { width: 85%; animation-delay: 0.3s; }
.skeleton-line:nth-child(5) { width: 60%; animation-delay: 0.4s; }
.skeleton-chat-bubble {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 200px;
}
.skeleton-chat-bubble .skeleton-line:nth-child(1) { width: 80%; }
.skeleton-chat-bubble .skeleton-line:nth-child(2) { width: 95%; }
.skeleton-chat-bubble .skeleton-line:nth-child(3) { width: 65%; }

/* ================================================================= */
/* Conversation History Sidebar                                      */
/* ================================================================= */

/* Flex wrapper around sidebar + main content */
.page-with-sidebar {
  display: flex;
  min-height: calc(100vh - 56px);    /* minus header */
  width: 100%;
}

/* When sidebar is present, main stretches to fill remaining space */
.page-with-sidebar > main {
  flex: 1;
  max-width: 960px;
  margin: 0 auto;
}

/* Sidebar panel */
.history-sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--surface, #141a24);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: calc(100vh - 56px);
  position: sticky;
  top: 56px;                         /* below header */
  overflow: hidden;
  transition: width 0.25s ease, min-width 0.25s ease, opacity 0.2s ease;
  z-index: 10;
}

.history-sidebar.collapsed {
  width: 0;
  min-width: 0;
  border-right: none;
  opacity: 0;
  pointer-events: none;
}

/* Sidebar header row */
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 0.75rem 0.5rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-header .btn-new-chat {
  flex: 1;
  padding: 0.45rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  transition: background 0.15s;
}
.sidebar-header .btn-new-chat:hover { background: var(--accent-hover, #4196f0); }

.btn-collapse-sidebar {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0.25rem;
  border-radius: 4px;
  line-height: 1;
}
.btn-collapse-sidebar:hover { background: var(--surface2); }

/* Search input */
.sidebar-search {
  padding: 0.5rem 0.75rem;
  flex-shrink: 0;
}
.sidebar-search input {
  width: 100%;
  padding: 0.4rem 0.65rem;
  font-size: 0.78rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface2, #1e2636);
  color: var(--text);
  outline: none;
}
.sidebar-search input:focus {
  border-color: var(--accent);
}
.sidebar-search input::placeholder {
  color: var(--text-dim);
}

/* Scrollable conversation list */
.sidebar-convos {
  flex: 1;
  overflow-y: auto;
  padding: 0.25rem 0;
}

/* Individual conversation item */
.sidebar-conv-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  border-radius: 6px;
  margin: 1px 0.4rem;
  transition: background 0.12s;
  position: relative;
}
.sidebar-conv-item:hover {
  background: var(--surface2, #1e2636);
}
.sidebar-conv-item.active {
  background: var(--surface2, #1e2636);
  border-left: 3px solid var(--accent);
  padding-left: calc(0.75rem - 3px);
}

.sidebar-conv-title {
  flex: 1;
  font-size: 0.8rem;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.sidebar-conv-meta {
  font-size: 0.68rem;
  color: var(--text-dim);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Actions (shown on hover) */
.sidebar-conv-actions {
  display: none;
  align-items: center;
  gap: 0.2rem;
  flex-shrink: 0;
}
.sidebar-conv-item:hover .sidebar-conv-actions {
  display: flex;
}
.sidebar-conv-item:hover .sidebar-conv-meta {
  display: none;
}
.sidebar-conv-actions button {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0.15rem 0.3rem;
  border-radius: 4px;
  line-height: 1;
}
.sidebar-conv-actions button:hover {
  background: var(--surface, #141a24);
  color: var(--text);
}

/* Empty state */
.sidebar-empty {
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.8rem;
}

/* Toggle button (visible when sidebar is collapsed) */
.btn-open-sidebar {
  position: fixed;
  left: 0;
  top: 56px;
  z-index: 20;
  background: var(--surface, #141a24);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 6px 6px 0;
  padding: 0.5rem 0.35rem;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 1rem;
  line-height: 1;
  display: none;   /* shown via JS when collapsed */
}
.btn-open-sidebar:hover { background: var(--surface2); }

/* ── Responsive ──────────────────────────────── */
@media (max-width: 768px) {
  .history-sidebar {
    position: fixed;
    left: 0;
    top: 56px;
    height: calc(100vh - 56px);
    z-index: 100;
    box-shadow: 4px 0 20px rgba(0,0,0,0.4);
  }
  .history-sidebar.collapsed {
    box-shadow: none;
  }
  /* Backdrop overlay */
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    top: 56px;
    background: rgba(0,0,0,0.5);
    z-index: 99;
  }
  .sidebar-backdrop.active {
    display: block;
  }
}

/* ── Analytics Dashboard ──────────────────────────────── */
.analytics-section-title {
  margin: 1.5rem 0 0.75rem;
  font-family: var(--mono);
  font-size: 0.95rem;
  color: var(--text-dim);
  font-weight: 500;
}

.username-badge {
  display: inline-block;
  background: var(--elevated);
  color: var(--accent);
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 500;
}

.scope-badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 3px;
  font-size: 0.72rem;
  font-family: var(--mono);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--elevated);
  color: var(--text-dim);
}
.scope-badge.scope-sem { color: var(--accent); border: 1px solid rgba(91,154,139,0.3); }
.scope-badge.scope-general { color: var(--accent2); border: 1px solid rgba(139,167,199,0.3); }
.scope-badge.scope-auto { color: var(--text-dim); border: 1px solid rgba(255,255,255,0.1); }

.recent-questions-card {
  padding: 0 !important;
  max-height: 500px;
  overflow-y: auto;
}

.recent-q-item {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.recent-q-item:last-child { border-bottom: none; }
.recent-q-item:hover { background: var(--elevated); }

.recent-q-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
  flex-wrap: wrap;
}

.recent-q-time {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--text-dim);
  font-family: var(--mono);
}

.recent-q-content {
  font-size: 0.88rem;
  color: var(--text-primary);
  line-height: 1.45;
}

/* Responsive charts for analytics */
@media (max-width: 768px) {
  .admin-charts-grid[style*="grid-template-columns: 2fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
}

/* ═══════════════════════════════════════════════════════════
   Admin Feedback Review
   ═══════════════════════════════════════════════════════════ */

/* ── Filter bar ─────────────────────────────────── */
.fb-filters-row {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  flex-wrap: wrap;
}
.fb-filter-label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.78rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.fb-filter-label select,
.fb-filter-label input {
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--corner);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-family: var(--font-mono);
}
.fb-filter-search { flex: 1; min-width: 180px; }
.fb-filter-count {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-dim);
  white-space: nowrap;
}

/* ── Table rows ─────────────────────────────────── */
.fb-row { cursor: pointer; }
.fb-row:hover { background: var(--bg-elevated); }

/* ── Status badges ──────────────────────────────── */
.fb-status-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.fb-status-new {
  background: rgba(91, 154, 139, 0.15);
  color: #5B9A8B;
  border: 1px solid rgba(91, 154, 139, 0.35);
}
.fb-status-reviewed {
  background: rgba(167, 139, 250, 0.15);
  color: #a78bfa;
  border: 1px solid rgba(167, 139, 250, 0.3);
}
.fb-status-resolved {
  background: rgba(122, 181, 165, 0.15);
  color: #7AB5A5;
  border: 1px solid rgba(122, 181, 165, 0.3);
}

/* ── Mode badges ────────────────────────────────── */
.fb-mode-badge {
  display: inline-block;
  padding: 0.12rem 0.45rem;
  border-radius: var(--corner);
  font-size: 0.72rem;
  font-family: var(--font-mono);
  background: var(--bg-elevated);
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.fb-mode-quick_rating { color: #fbbf24; border-color: rgba(251, 191, 36, 0.3); }
.fb-mode-chat { color: #60a5fa; border-color: rgba(96, 165, 250, 0.3); }
.fb-mode-single { color: #f472b6; border-color: rgba(244, 114, 182, 0.3); }

/* ── Modal overlay ──────────────────────────────── */
.fb-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}
.fb-modal {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--corner-lg, 10px);
  width: 100%;
  max-width: 720px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}
.fb-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.fb-modal-header h3 { margin: 0; font-size: 1.1rem; }
.fb-modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
}
.fb-modal-close:hover { color: var(--text-primary); }
.fb-modal-body { padding: 1.25rem; }

/* ── Meta row ───────────────────────────────────── */
.fb-meta-row {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

/* ── Detail sections ────────────────────────────── */
.fb-detail-section { margin-bottom: 1rem; }
.fb-detail-section h4 {
  font-size: 0.78rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.35rem;
}
.fb-detail-text {
  font-size: 0.88rem;
  color: var(--text-primary);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.fb-detail-response {
  max-height: 200px;
  overflow-y: auto;
  padding: 0.75rem;
  background: var(--bg-elevated);
  border-radius: var(--corner);
  border: 1px solid var(--border);
}
.fb-detail-feedback {
  padding: 0.75rem;
  background: rgba(91, 154, 139, 0.05);
  border-left: 3px solid #5B9A8B;
  border-radius: 0 var(--corner) var(--corner) 0;
}
.fb-detail-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem 1.5rem;
  font-size: 0.82rem;
  color: var(--text-dim);
}
.fb-detail-meta-grid code {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--accent);
}

/* ── Screenshot ─────────────────────────────────── */
.fb-screenshot {
  max-width: 100%;
  border-radius: var(--corner);
  border: 1px solid var(--border);
  margin-top: 0.5rem;
}

/* ── Admin controls in modal ────────────────────── */
.fb-admin-controls {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.fb-admin-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
}
.fb-admin-row select {
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--corner);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-family: var(--font-mono);
}
.fb-admin-controls textarea {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--corner);
  background: var(--bg-elevated);
  color: var(--text-primary);
  resize: vertical;
}

/* Generic buttons for modal */
.btn-sm {
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  border-radius: var(--corner);
  cursor: pointer;
  font-family: var(--font-mono);
  border: 1px solid var(--border);
}
.btn-primary {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
  font-weight: 600;
}
.btn-primary:hover { opacity: 0.85; }
.btn-danger {
  background: rgba(248, 113, 113, 0.15);
  color: #f87171;
  border-color: rgba(248, 113, 113, 0.3);
}
.btn-danger:hover { background: rgba(248, 113, 113, 0.25); }

/* ── Responsive ─────────────────────────────────── */
@media (max-width: 768px) {
  .fb-filters-row { flex-direction: column; }
  .fb-modal { max-width: 100%; max-height: 92vh; }
  .fb-detail-meta-grid { grid-template-columns: 1fr; }
}
