/* ═══════════════════════════════════════════════════════════════════════════
   ODISHA ASSISTANT — Temple stone & sindoor
   Pattachitra cream · temple ink · sindoor + Konark ochre · Eczar + IBM Plex
   Motifs: Konark chariot wheel, pattachitra beaded dividers, Odia script
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Design tokens ──────────────────────────────────────────────────────── */
:root {
  /* Paper / ink — temple marble, clean off-white with neutral stone greys */
  --paper:         #fbfaf7;   /* marble off-white */
  --paper-raised:  #ffffff;   /* pure white cards */
  --paper-sunk:    #f1f0ec;   /* pale stone */
  --ink:           #191612;   /* deep temple ink */
  --ink-soft:      #4a453f;
  --ink-muted:     #8a857c;
  --line:          #e7e4dc;   /* light stone line */
  --line-strong:   #cfcbc0;

  /* Accents — sindoor vermilion is the ONLY chromatic warmth */
  --accent:        #c1272d;   /* sindoor (vermilion) */
  --accent-hover:  #9c1c22;
  --accent-tint:   #f8e3e0;   /* cool blush, not cream */
  --accent-warm:   #c1272d;   /* alias → we no longer use ochre in general UI */
  --accent-deep:   #7a1417;
  --on-accent:     #ffffff;   /* text/icon color on sindoor surfaces */
  --jade:          #2c5f4c;   /* success only */
  --danger:        #b83229;
  --danger-tint:   #fbe7e4;

  /* Surfaces */
  --user-bubble:   #f1f0ec;   /* stone grey, not cream */
  --assistant-bg:  transparent;
  --code-bg:       #191612;
  --code-text:     #eceae5;
  --code-inline:   #f1f0ec;

  /* Effects */
  --shadow-1: 0 1px 2px rgba(25,22,18,0.04), 0 2px 6px rgba(25,22,18,0.05);
  --shadow-2: 0 4px 14px rgba(25,22,18,0.08), 0 24px 48px rgba(25,22,18,0.08);
  --shadow-pop: 0 20px 60px rgba(25,22,18,0.18);
  --grain-opacity: 0.025;

  /* Typography — Eczar (Indian-designed serif) + IBM Plex Sans (institutional) */
  --f-display: "Eczar", "Noto Serif Oriya", Georgia, serif;
  --f-sans:    "IBM Plex Sans", "Noto Sans Oriya", ui-sans-serif, system-ui, sans-serif;
  --f-mono:    "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --f-oriya:   "Noto Serif Oriya", "Noto Sans Oriya", "Eczar", serif;

  /* Pattachitra beaded ornament — repeating vermilion dots */
  --beaded-line: radial-gradient(circle at center, var(--accent) 1.2px, transparent 1.7px) 0 0 / 10px 4px repeat-x;

  /* Motion */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);

  /* Layout */
  --sidebar-w: 288px;
  --thread-max: 760px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-pill: 999px;
}

[data-theme="dark"] {
  /* Temple slate — clean graphite with glowing sindoor */
  --paper:         #131215;
  --paper-raised:  #1c1b1f;
  --paper-sunk:    #0e0d10;
  --ink:           #ebe8e0;
  --ink-soft:      #b8b4aa;
  --ink-muted:     #7a7770;
  --line:          #28272b;
  --line-strong:   #3c3b40;

  --accent:        #e8554a;    /* glowing sindoor */
  --accent-hover:  #f26d62;
  --accent-tint:   #2e1714;
  --accent-warm:   #e8554a;    /* alias — no ochre in dark either */
  --accent-deep:   #ff7a6e;
  --on-accent:     #ffffff;    /* text on sindoor stays white in dark too */
  --jade:          #5fa88a;
  --danger:        #e26a5e;
  --danger-tint:   #2e1714;

  --user-bubble:   #22212a;
  --code-bg:       #0a090c;
  --code-text:     #e7e4da;
  --code-inline:   #26252b;

  --shadow-1: 0 1px 2px rgba(0,0,0,0.45), 0 2px 6px rgba(0,0,0,0.35);
  --shadow-2: 0 4px 14px rgba(0,0,0,0.55), 0 24px 48px rgba(0,0,0,0.45);
  --shadow-pop: 0 20px 60px rgba(0,0,0,0.65);
  --grain-opacity: 0.035;

  --beaded-line: radial-gradient(circle at center, var(--accent) 1.2px, transparent 1.7px) 0 0 / 10px 4px repeat-x;
}

/* ── Reset & base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--f-sans);
  font-size: 15px;
  line-height: 1.55;
  font-feature-settings: "ss01", "cv11";
  display: flex;
  flex-direction: row;
  overflow: hidden;
  position: relative;
}

/* Paper grain — atmospheric, not decorative */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml;utf8,<svg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.7 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  mix-blend-mode: multiply;
}
[data-theme="dark"] body::before { mix-blend-mode: screen; }

kbd {
  font-family: var(--f-mono);
  font-size: 10.5px;
  font-weight: 500;
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--paper-sunk);
  color: var(--ink-soft);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  line-height: 1;
  vertical-align: middle;
}

::selection { background: var(--accent-tint); color: var(--ink); }

/* ── Custom scrollbar ──────────────────────────────────────────────────── */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: var(--radius-pill);
  border: 2px solid var(--paper);
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--line-strong); background-clip: padding-box; }
*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ═══════════════════════════════════════════════════════════════════════
   SIDEBAR
   ═══════════════════════════════════════════════════════════════════════ */

#sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  height: 100vh;
  background: var(--paper-sunk);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: margin-left 0.35s var(--ease-out);
  position: relative;
  z-index: 20;
}

body.sidebar-collapsed #sidebar { margin-left: calc(var(--sidebar-w) * -1); }

.sidebar-top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 18px 16px 14px;
}
.brand {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}
.brand-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  color: var(--accent);
  filter: drop-shadow(0 1px 2px rgba(193,39,45,0.35));
  transition: transform 1.2s var(--ease-out);
}
.brand:hover .brand-mark { transform: rotate(60deg); }

.brand-name {
  display: flex;
  flex-direction: column;
  gap: 1px;
  line-height: 1;
}
.brand-script {
  font-family: var(--f-oriya);
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
  letter-spacing: 0.02em;
  line-height: 1;
  opacity: 0.85;
}
.brand-wordmark {
  font-family: var(--f-display);
  font-weight: 500;
  font-size: 16px;
  letter-spacing: 0.005em;
  color: var(--ink);
}
.brand-dot {
  color: var(--accent);
  margin: 0 2px;
  font-weight: 600;
}
.oriya { font-family: var(--f-oriya); font-weight: 500; }

.sidebar-actions { padding: 0 14px 10px; }

.primary-btn {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--ink);
  color: var(--paper);
  border: 1px solid var(--ink);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font: 500 13.5px/1 var(--f-sans);
  cursor: pointer;
  transition: transform 0.15s var(--ease-out), background 0.15s, box-shadow 0.15s;
  box-shadow: var(--shadow-1);
}
.primary-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-2); background: var(--ink-soft); }
.primary-btn:active { transform: translateY(0); }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.primary-btn .kbd-hint {
  margin-left: auto;
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.75);
  border: none;
  padding: 2px 6px;
  font-size: 10.5px;
}
[data-theme="dark"] .primary-btn .kbd-hint { background: rgba(0,0,0,0.35); color: rgba(237,230,213,0.7); }

.sidebar-search {
  position: relative;
  margin: 0 14px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: var(--ink-muted);
}
.sidebar-search:focus-within { border-color: var(--line-strong); outline: none; }
.sidebar-search input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font: 400 13px/1.3 var(--f-sans);
  color: var(--ink);
}
.sidebar-search input::placeholder { color: var(--ink-muted); }

#sessions-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px 12px;
  mask-image: linear-gradient(to bottom, black calc(100% - 20px), transparent);
}

.session-group-label {
  font-family: var(--f-sans);
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-muted);
  padding: 14px 8px 6px;
}

.session-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--ink-soft);
  font-size: 13.5px;
  line-height: 1.3;
  margin: 1px 0;
  border: 1px solid transparent;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  position: relative;
}
.session-row:hover { background: var(--paper); color: var(--ink); }
.session-row.active {
  background: var(--paper);
  border-color: var(--line);
  color: var(--ink);
  font-weight: 500;
}
.session-row.active::before {
  content: "";
  position: absolute;
  left: -2px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  border-radius: 2px;
  background: var(--accent);
}
.session-row .s-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session-row .s-del {
  background: none;
  border: none;
  color: var(--ink-muted);
  cursor: pointer;
  padding: 3px;
  border-radius: 5px;
  opacity: 0;
  transition: opacity 0.12s, color 0.12s, background 0.12s;
  display: grid;
  place-items: center;
}
.session-row:hover .s-del { opacity: 1; }
.session-row .s-del:hover { color: var(--danger); background: var(--danger-tint); }

.sidebar-footer {
  padding: 10px 14px 14px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 6px;
  align-items: center;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.icon-btn:hover {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--line);
}
#theme-toggle .moon { display: none; }
[data-theme="dark"] #theme-toggle .sun { display: none; }
[data-theme="dark"] #theme-toggle .moon { display: block; }

#sidebar-open {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 30;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-1);
}
body.sidebar-collapsed #sidebar-open { display: inline-grid; }

#sidebar-scrim {
  position: fixed;
  inset: 0;
  background: rgba(26,23,20,0.4);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 15;
}

/* ═══════════════════════════════════════════════════════════════════════
   MAIN COLUMN
   ═══════════════════════════════════════════════════════════════════════ */

#app-main {
  flex: 1;
  min-width: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--paper);
}
#app-main::before {
  /* Temple-frieze: pattachitra beaded band across the very top */
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--beaded-line);
  opacity: 0.55;
  pointer-events: none;
  z-index: 1;
}
[data-theme="dark"] #app-main::before { opacity: 0.75; }

#thread-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 56px 24px 180px;
  display: flex;
  justify-content: center;
  scroll-behavior: smooth;
  position: relative;
}

#thread {
  width: 100%;
  max-width: var(--thread-max);
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* ── Welcome ────────────────────────────────────────────────────────────── */
.welcome {
  padding: 40px 4px 24px;
  animation: fade-rise 0.7s var(--ease-out) both;
}
.welcome-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--f-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 26px;
  opacity: 0;
  animation: fade-rise 0.6s var(--ease-out) 0.05s both;
}
.welcome-eyebrow .oriya {
  font-family: var(--f-oriya);
  font-size: 15px;
  letter-spacing: 0;
  text-transform: none;
  font-weight: 500;
  color: var(--accent);
}
.welcome-eyebrow .eyebrow-sep {
  width: 48px;
  height: 4px;
  background: var(--beaded-line);
  display: inline-block;
}

.welcome-title {
  font-family: var(--f-display);
  font-weight: 500;
  font-size: clamp(38px, 5.4vw, 58px);
  line-height: 1.04;
  letter-spacing: -0.018em;
  margin: 0 0 22px;
  color: var(--ink);
  opacity: 0;
  animation: fade-rise 0.7s var(--ease-out) 0.1s both;
}
.welcome-title em {
  font-style: italic;
  font-weight: 500;
  color: var(--accent);
  background: linear-gradient(180deg, transparent 76%, var(--accent-tint) 76%, var(--accent-tint) 94%, transparent 94%);
  padding: 0 2px;
}
.welcome-lede .oriya { color: var(--accent); font-size: 1.04em; }
.welcome-lede {
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink-soft);
  max-width: 560px;
  margin: 0 0 32px;
  opacity: 0;
  animation: fade-rise 0.7s var(--ease-out) 0.17s both;
}

.prompt-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.prompt-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  padding: 16px 18px;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  font: inherit;
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.2s var(--ease-out), border-color 0.15s, box-shadow 0.15s;
  opacity: 0;
  animation: fade-rise 0.6s var(--ease-out) both;
  position: relative;
  overflow: hidden;
}
.prompt-card:nth-child(1) { animation-delay: 0.24s; }
.prompt-card:nth-child(2) { animation-delay: 0.30s; }
.prompt-card:nth-child(3) { animation-delay: 0.36s; }
.prompt-card:nth-child(4) { animation-delay: 0.42s; }
.prompt-card::after {
  content: "→";
  position: absolute;
  right: 18px;
  top: 16px;
  color: var(--ink-muted);
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  font-family: var(--f-sans);
}
.prompt-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--shadow-1);
}
.prompt-card:hover::after { opacity: 1; transform: translateX(2px); color: var(--accent); }
.pc-label {
  font-family: var(--f-mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.pc-text {
  font-size: 14.5px;
  line-height: 1.4;
  color: var(--ink);
  font-weight: 400;
}
.pc-text strong { font-weight: 600; color: var(--ink); }

/* ═══════════════════════════════════════════════════════════════════════
   MESSAGES
   ═══════════════════════════════════════════════════════════════════════ */

.msg {
  display: flex;
  gap: 14px;
  animation: msg-in 0.4s var(--ease-out) both;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-avatar {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--f-oriya);
  font-size: 16px;
  font-weight: 500;
  color: var(--on-accent);
  background: radial-gradient(circle at 30% 30%, var(--accent), var(--accent-deep) 85%);
  letter-spacing: 0;
  box-shadow: 0 2px 8px rgba(193,39,45,0.28), inset 0 1px 0 rgba(255,255,255,0.12);
  margin-top: 2px;
  position: relative;
}
.msg-avatar::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 1px dotted var(--accent);
  opacity: 0.35;
}
.msg-avatar.user {
  background: var(--paper-sunk);
  color: var(--ink-soft);
  border: 1px solid var(--line);
  box-shadow: none;
  font-family: var(--f-sans);
}
.msg-avatar.user::after { display: none; }

.msg-body { flex: 1; min-width: 0; }
.msg-role {
  font-family: var(--f-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 6px;
  font-weight: 500;
}
.msg-role .msg-badge {
  display: inline-block;
  padding: 1px 6px;
  margin-left: 6px;
  border-radius: var(--radius-pill);
  background: var(--accent-tint);
  color: var(--accent);
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: none;
  font-weight: 500;
}

.msg-user .msg-content {
  font-size: 15.5px;
  line-height: 1.55;
  color: var(--ink);
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* Assistant answer */
.answer {
  font-size: 15.5px;
  line-height: 1.72;
  color: var(--ink);
  word-wrap: break-word;
}
.answer > *:first-child { margin-top: 0; }
.answer > *:last-child  { margin-bottom: 0; }
.answer p { margin: 0 0 14px; }
.answer h1, .answer h2, .answer h3 {
  font-family: var(--f-display);
  font-weight: 600;
  letter-spacing: -0.012em;
  line-height: 1.2;
  margin: 22px 0 10px;
  color: var(--ink);
}
.answer h1 { font-size: 1.55em; }
.answer h2 { font-size: 1.3em; }
.answer h3 { font-size: 1.12em; }
.answer strong { font-weight: 600; color: var(--ink); }
.answer em { font-style: italic; }
.answer a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.answer a:hover { color: var(--accent-hover); }
.answer ul, .answer ol { padding-left: 24px; margin: 0 0 14px; }
.answer li { margin: 4px 0; }
.answer li::marker { color: var(--ink-muted); }
.answer blockquote {
  margin: 14px 0;
  padding: 2px 0 2px 16px;
  border-left: 2px solid var(--accent);
  color: var(--ink-soft);
  font-style: italic;
}
.answer hr { border: none; border-top: 1px solid var(--line); margin: 22px 0; }

/* Inline code */
.answer code {
  font-family: var(--f-mono);
  font-size: 0.9em;
  background: var(--code-inline);
  color: var(--ink);
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid var(--line);
}

/* Code blocks with header + copy */
.code-block {
  margin: 14px 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--line-strong);
  background: var(--code-bg);
  box-shadow: var(--shadow-1);
}
.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: rgba(0,0,0,0.25);
  color: rgba(255,255,255,0.7);
  font-family: var(--f-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
}
.code-lang { text-transform: lowercase; }
.code-copy {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font: inherit;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 5px;
  transition: background 0.12s, color 0.12s;
}
.code-copy:hover { background: rgba(255,255,255,0.1); color: #fff; }
.code-copy.copied { color: #98d5b2; }
.code-block pre {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
  font-family: var(--f-mono);
  font-size: 13px;
  line-height: 1.55;
  color: var(--code-text);
}
.code-block pre code { background: none; border: none; padding: 0; color: inherit; font-size: inherit; }

/* Citations */
.answer sup { line-height: 0; }
.answer sup a.cite {
  display: inline-block;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  margin: 0 1px;
  border-radius: var(--radius-pill);
  background: var(--accent-tint);
  color: var(--accent);
  font: 500 10.5px/18px var(--f-mono);
  text-align: center;
  text-decoration: none;
  border: 1px solid transparent;
  transition: all 0.12s;
  cursor: pointer;
  vertical-align: 2px;
}
.answer sup a.cite:hover {
  background: var(--accent);
  color: var(--paper);
  transform: translateY(-1px);
}

/* Sources grid */
.sources-block { margin-top: 22px; animation: msg-in 0.45s var(--ease-out) 0.1s both; }
.sources-label {
  font-family: var(--f-mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-muted);
  font-weight: 500;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.sources-label::after {
  content: "";
  flex: 1;
  height: 4px;
  background: var(--beaded-line);
  opacity: 0.55;
}
.sources {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.src-card {
  display: flex;
  gap: 12px;
  padding: 12px 14px;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: inherit;
  transition: transform 0.18s var(--ease-out), border-color 0.15s, box-shadow 0.15s;
}
.src-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--shadow-1);
}
.src-card.flash {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
  animation: flash-pulse 1.2s var(--ease-out);
}
@keyframes flash-pulse {
  0%   { box-shadow: 0 0 0 0 var(--accent); }
  100% { box-shadow: 0 0 0 3px var(--accent-tint); }
}
.src-card .num {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--accent-tint);
  color: var(--accent);
  font: 600 11px/22px var(--f-mono);
  text-align: center;
}
.src-card .body { min-width: 0; flex: 1; }
.src-card .head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
}
.src-card .fav { width: 13px; height: 13px; border-radius: 3px; }
.src-card .domain {
  font-family: var(--f-mono);
  font-size: 10.5px;
  color: var(--ink-muted);
  letter-spacing: 0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.src-card .title {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* Message action toolbar */
.msg-actions {
  display: flex;
  gap: 2px;
  margin-top: 10px;
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 0.18s, transform 0.18s;
}
.msg-assistant:hover .msg-actions,
.msg-actions:focus-within { opacity: 1; transform: translateY(0); }
.act-btn {
  display: inline-grid;
  grid-auto-flow: column;
  align-items: center;
  gap: 4px;
  padding: 5px 8px;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--ink-muted);
  cursor: pointer;
  font: 500 11.5px/1 var(--f-sans);
  transition: all 0.12s;
}
.act-btn:hover { background: var(--paper-raised); color: var(--ink); border-color: var(--line); }
.act-btn.active-up { color: var(--jade); }
.act-btn.active-down { color: var(--danger); }
.act-btn.copied { color: var(--jade); }
.act-btn svg { opacity: 0.85; }

/* Thinking state (legacy inline-bubble fallback) */
.thinking {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 4px 2px;
  color: var(--ink-muted);
  font-size: 14px;
  font-style: italic;
  font-family: var(--f-display);
  font-weight: 400;
  letter-spacing: 0.005em;
}
.thinking .waves {
  display: inline-flex;
  gap: 3px;
  align-items: center;
  height: 14px;
}
.thinking .waves span {
  width: 3px;
  height: 8px;
  background: var(--accent);
  border-radius: 2px;
  animation: wave 1.1s var(--ease-in-out) infinite;
}
.thinking .waves span:nth-child(2) { animation-delay: 0.12s; }
.thinking .waves span:nth-child(3) { animation-delay: 0.24s; }
.thinking .waves span:nth-child(4) { animation-delay: 0.36s; }
@keyframes wave {
  0%, 100% { transform: scaleY(0.4); opacity: 0.4; }
  50%      { transform: scaleY(1.6); opacity: 1; }
}

/* ═══════════════════════════════════════════════════════════════════════
   REASONING DISCLOSURE — "Thought for X.Ys" staged chain
   ═══════════════════════════════════════════════════════════════════════ */

.reasoning {
  margin: 2px 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--paper-sunk);
  overflow: hidden;
  font-family: var(--f-mono);
  font-size: 12.5px;
  color: var(--ink-soft);
  transition: background 0.2s;
}
.reasoning[open] { background: var(--paper-sunk); }

.reasoning-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  cursor: pointer;
  list-style: none;
  user-select: none;
  color: var(--ink-soft);
  transition: background 0.12s, color 0.12s;
}
.reasoning-summary::-webkit-details-marker { display: none; }
.reasoning-summary:hover { background: var(--paper); color: var(--ink); }
.reasoning-summary .chev {
  transition: transform 0.2s var(--ease-out);
  flex: 0 0 auto;
  color: var(--ink-muted);
}
.reasoning[open] .reasoning-summary .chev { transform: rotate(90deg); }
.reasoning-label {
  font-weight: 500;
  letter-spacing: 0.02em;
}
.reasoning-timer {
  margin-left: auto;
  padding: 1px 7px;
  border-radius: var(--radius-pill);
  background: var(--paper);
  color: var(--ink-muted);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  border: 1px solid var(--line);
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}
.reasoning.is-live .reasoning-timer {
  background: var(--accent-tint);
  color: var(--accent);
  border-color: transparent;
}

.reasoning-steps {
  list-style: none;
  margin: 0;
  padding: 4px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: relative;
}
.reasoning-steps::before {
  /* thin rail connecting the step dots */
  content: "";
  position: absolute;
  left: 20px;
  top: 12px;
  bottom: 16px;
  width: 1px;
  background: var(--line);
}
.step {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  color: var(--ink-muted);
  transition: color 0.2s;
  position: relative;
}
.step-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--paper);
  border: 1px solid var(--line-strong);
  position: relative;
  z-index: 1;
}
.step-icon::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--line-strong);
  transition: background 0.2s, transform 0.2s;
}
.step.is-active { color: var(--ink); }
.step.is-active .step-icon { border-color: var(--accent); background: var(--accent-tint); }
.step.is-active .step-icon::before {
  background: var(--accent);
  animation: step-pulse 1.1s var(--ease-in-out) infinite;
}
.step.is-done { color: var(--ink-soft); }
.step.is-done .step-icon { border-color: var(--jade); background: var(--jade); }
.step.is-done .step-icon::before {
  background: var(--on-accent);
  width: 4px;
  height: 4px;
}
@keyframes step-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.5); opacity: 0.6; }
}
.step-text { flex: 1; min-width: 0; }
.step-text em {
  font-style: normal;
  color: var(--ink);
  font-weight: 500;
}

/* Collapsed-done state: the summary alone is the whole UI */
.reasoning.is-collapsed .reasoning-steps { display: none; }
.reasoning.is-done:not([open]) {
  background: transparent;
  border-color: var(--line);
}
.reasoning.is-done .reasoning-summary { padding: 7px 11px; font-size: 12px; }
.reasoning.is-done .reasoning-label::before {
  content: "✓ ";
  color: var(--jade);
  font-weight: 600;
  margin-right: 2px;
}

/* Raw <pre> during streaming — gets styled like a code block immediately
   so partial code doesn't flash gray-on-white. The final enhance wraps it
   in .code-block with header + language label + copy button. */
.answer pre {
  margin: 14px 0;
  padding: 14px 16px;
  background: var(--code-bg);
  color: var(--code-text);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  overflow-x: auto;
  font-family: var(--f-mono);
  font-size: 13px;
  line-height: 1.55;
  box-shadow: var(--shadow-1);
}
.answer .code-block pre { margin: 0; border: none; border-radius: 0; box-shadow: none; }
.answer pre code { background: none; border: none; padding: 0; color: inherit; font-size: inherit; }

/* Streaming cursor */
.stream-cursor {
  display: inline-block;
  width: 8px;
  height: 1em;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: -2px;
  animation: blink 1s step-end infinite;
  border-radius: 1px;
}
@keyframes blink { 50% { opacity: 0; } }

/* Error */
.msg-error {
  background: var(--danger-tint);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  font-family: var(--f-sans);
}

/* ═══════════════════════════════════════════════════════════════════════
   COMPOSER
   ═══════════════════════════════════════════════════════════════════════ */

#composer-wrap {
  position: sticky;
  bottom: 0;
  padding: 12px 24px 20px;
  background: linear-gradient(to top, var(--paper) 70%, transparent);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 5;
}

#input-form {
  width: 100%;
  max-width: var(--thread-max);
}

.composer {
  display: flex;
  flex-direction: column;
  background: var(--paper-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  transition: border-color 0.15s, box-shadow 0.15s;
  overflow: hidden;
}
.composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint), var(--shadow-1);
}

#input {
  width: 100%;
  resize: none;
  border: none;
  outline: none;
  background: none;
  padding: 16px 18px 4px;
  font: 400 15.5px/1.55 var(--f-sans);
  color: var(--ink);
  max-height: 260px;
  overflow-y: auto;
}
#input::placeholder { color: var(--ink-muted); }

.composer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px 10px 12px;
  gap: 8px;
}

.composer-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.composer-meta {
  font-family: var(--f-mono);
  font-size: 10.5px;
  color: var(--ink-muted);
  letter-spacing: 0.02em;
}
.composer-meta kbd { font-size: 10px; padding: 1px 4px; }

/* ── Voice button (opens full-screen voice conversation) ─────────────── */
.voice-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 14px 0 12px;
  background: var(--paper-sunk);
  color: var(--ink-soft);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  font: 500 12.5px/1 var(--f-sans);
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.15s, box-shadow 0.15s;
  flex: 0 0 auto;
}
.voice-btn:hover {
  background: var(--paper-raised);
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(193,39,45,0.14);
}
.voice-btn:active { transform: scale(0.97); }
.voice-btn svg { color: var(--accent); flex: 0 0 auto; }
.voice-btn .label { font-weight: 500; }

/* ── Dictation language pill (cycles Auto / EN / OD) ─────────────────── */
.dictate-lang {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  padding: 0 10px;
  background: transparent;
  color: var(--ink-muted);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  font: 500 10.5px/1 var(--f-mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  flex: 0 0 auto;
  min-width: 46px;
}
.dictate-lang:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-tint);
}
.dictate-lang[data-active-lang="en"] {
  color: var(--accent);
  border-color: var(--accent);
}
.dictate-lang[data-active-lang="od"] {
  color: var(--accent);
  border-color: var(--accent);
  font-family: var(--f-sans);
  font-size: 12px;
  letter-spacing: 0.02em;
  text-transform: none;
}

/* ── Dictate button (voice-typing into the input box) ────────────────── */
.dictate-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  background: var(--paper-sunk);
  color: var(--ink-soft);
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.15s, box-shadow 0.15s;
  flex: 0 0 auto;
}
.dictate-btn:hover {
  background: var(--paper-raised);
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(193,39,45,0.14);
}
.dictate-btn:active { transform: scale(0.94); }
.dictate-btn svg { flex: 0 0 auto; }
.dictate-btn .i-mic  { display: block; }
.dictate-btn .i-stop { display: none; }
.dictate-dot {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: transparent;
  transition: background 0.15s, box-shadow 0.15s;
}
.dictate-btn.is-listening {
  background: var(--accent);
  color: var(--on-accent);
  border-color: transparent;
  /* Pulse intensity is driven by --level (0-1) set from the mic analyser,
     so the button "breathes" with the user's voice — clear signal that
     we're hearing them. */
  box-shadow: 0 0 0 calc(3px + var(--level, 0) * 7px) rgba(193,39,45,0.18);
}
.dictate-btn.is-listening .i-mic  { display: none; }
.dictate-btn.is-listening .i-stop { display: block; }
.dictate-btn.is-listening .dictate-dot {
  background: #fff;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.35);
  animation: dictate-pulse 1.1s ease-in-out infinite;
}
.dictate-btn.is-error {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-tint);
}
.dictate-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
@keyframes dictate-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.45; transform: scale(0.7); }
}

/* ── Speaker button inside message-actions ───────────────────────────── */
.act-speak .i-stop { display: none; }
.act-speak.is-speaking {
  color: var(--accent);
  background: var(--accent-tint);
  border-color: transparent;
}
.act-speak.is-speaking .i-speaker { display: none; }
.act-speak.is-speaking .i-stop { display: block; }
.act-speak.is-speaking span::after {
  content: "";
  display: inline-block;
  width: 3px;
  height: 3px;
  margin-left: 4px;
  border-radius: 50%;
  background: currentColor;
  animation: speak-blink 1s ease-in-out infinite;
  vertical-align: middle;
}
@keyframes speak-blink { 50% { opacity: 0.25; } }

.send-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  padding: 9px 16px;
  border-radius: var(--radius-md);
  font: 500 13.5px/1 var(--f-sans);
  cursor: pointer;
  transition: transform 0.15s var(--ease-out), background 0.15s, box-shadow 0.15s;
  box-shadow: 0 2px 6px rgba(193,39,45,0.30);
  min-height: 36px;
}
.send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(193,39,45,0.40);
}
.send-btn:active { transform: translateY(0); }
.send-btn:disabled {
  background: var(--paper-sunk);
  color: var(--ink-muted);
  cursor: not-allowed;
  box-shadow: none;
}
.send-btn svg { display: block; }
.send-btn .i-send  { display: block; }
.send-btn .i-stop  { display: none; }
.send-btn.is-stop { background: var(--ink); color: var(--on-accent); box-shadow: 0 2px 6px rgba(25,22,18,0.25); }
.send-btn.is-stop:hover:not(:disabled) { background: var(--ink-soft); box-shadow: 0 4px 12px rgba(25,22,18,0.35); }
.send-btn.is-stop .i-send { display: none; }
.send-btn.is-stop .i-stop { display: block; }
[data-theme="dark"] .send-btn.is-stop { background: var(--paper-raised); color: var(--ink); }
[data-theme="dark"] .send-btn.is-stop:hover:not(:disabled) { background: var(--paper-sunk); }

.composer-caption {
  font-family: var(--f-sans);
  font-size: 11.5px;
  color: var(--ink-muted);
  text-align: center;
  letter-spacing: 0.01em;
}

/* ═══════════════════════════════════════════════════════════════════════
   VOICE MODE — full-screen conversational overlay (orb + live caption)
   ═══════════════════════════════════════════════════════════════════════ */

.voice-mode {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: none;
  align-items: center;
  justify-content: center;
}
.voice-mode.open { display: flex; }

.voice-scrim {
  position: absolute;
  inset: 0;
  background: radial-gradient(
    ellipse at center,
    rgba(25,22,18,0.55) 0%,
    rgba(25,22,18,0.78) 55%,
    rgba(25,22,18,0.92) 100%
  );
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  animation: voice-scrim-in 0.35s var(--ease-out);
}
[data-theme="dark"] .voice-scrim {
  background: radial-gradient(
    ellipse at center,
    rgba(8,7,10,0.58) 0%,
    rgba(8,7,10,0.82) 55%,
    rgba(8,7,10,0.96) 100%
  );
}
@keyframes voice-scrim-in { from { opacity: 0; } to { opacity: 1; } }

.voice-card {
  position: relative;
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 28px 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  color: var(--paper);
  animation: voice-card-in 0.45s var(--ease-out);
}
@keyframes voice-card-in {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.voice-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.voice-title-wrap { flex: 1; min-width: 0; }
.voice-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--f-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.7);
}
.voice-eyebrow .oriya {
  font-family: var(--f-oriya);
  font-size: 15px;
  letter-spacing: 0;
  text-transform: none;
  font-weight: 500;
  color: var(--accent);
}
.voice-eyebrow .eyebrow-sep {
  width: 36px;
  height: 4px;
  background: var(--beaded-line);
  opacity: 0.85;
  display: inline-block;
}
.voice-title {
  font-family: var(--f-display);
  font-weight: 500;
  font-size: clamp(24px, 3.2vw, 30px);
  line-height: 1.15;
  letter-spacing: -0.012em;
  margin: 10px 0 0;
  color: #fff;
}
.voice-title em {
  font-style: italic;
  color: var(--accent);
  font-weight: 500;
}

.voice-close {
  color: rgba(255,255,255,0.75);
  border-color: transparent;
  background: rgba(255,255,255,0.08);
}
.voice-close:hover {
  background: rgba(255,255,255,0.16);
  color: #fff;
  border-color: transparent;
}

/* ── The orb stage ─────────────────────────────────────────────────── */
.voice-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  padding: 22px 0 4px;
}

.orb {
  --level: 0;                   /* 0..1, driven by JS for listening/speaking */
  --size: 220px;
  position: relative;
  width: var(--size);
  height: var(--size);
  display: grid;
  place-items: center;
  transition: transform 0.2s var(--ease-out);
}
.orb > * {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  will-change: transform, opacity;
}

/* Core — the solid sindoor sphere */
.orb-core {
  background:
    radial-gradient(circle at 32% 28%, #ffc8a0 0%, var(--accent) 38%, var(--accent-deep) 78%, #4a0d11 100%);
  box-shadow:
    inset 0 0 40px rgba(255,255,255,0.18),
    inset 0 -30px 60px rgba(0,0,0,0.45),
    0 18px 60px rgba(193,39,45,0.35),
    0 6px 24px rgba(25,22,18,0.55);
  transform: scale(calc(0.96 + var(--level) * 0.18));
  transition: transform 0.12s ease-out;
}

/* Subtle highlight crescent */
.orb-shine {
  background:
    radial-gradient(circle at 30% 22%, rgba(255,255,255,0.55) 0%, rgba(255,255,255,0.08) 28%, transparent 50%);
  mix-blend-mode: screen;
  opacity: 0.8;
  pointer-events: none;
}

/* Thin conic ring — sits outside the core */
.orb-ring {
  inset: -14px;
  background: conic-gradient(from 0deg,
    rgba(255,255,255,0.0) 0deg,
    rgba(255,255,255,0.55) 90deg,
    rgba(193,39,45,0.0) 180deg,
    rgba(255,255,255,0.35) 270deg,
    rgba(255,255,255,0.0) 360deg);
  -webkit-mask: radial-gradient(circle, transparent 55%, #000 58%, #000 62%, transparent 65%);
          mask: radial-gradient(circle, transparent 55%, #000 58%, #000 62%, transparent 65%);
  opacity: 0;
  transition: opacity 0.25s;
}

/* Halo — large soft glow */
.orb-halo {
  inset: -60px;
  background: radial-gradient(circle, rgba(232,85,74,0.32) 0%, rgba(232,85,74,0.08) 40%, transparent 65%);
  filter: blur(8px);
  transform: scale(calc(0.85 + var(--level) * 0.35));
  transition: transform 0.2s ease-out, opacity 0.25s;
  opacity: 0.6;
  pointer-events: none;
}

/* ── State machine ─────────────────────────────────────────────────── */

/* Idle — gentle breathing + halo fade */
.orb.is-idle .orb-core { animation: orb-breathe 3.2s ease-in-out infinite; }
.orb.is-idle .orb-halo { animation: orb-halo-breathe 3.2s ease-in-out infinite; opacity: 0.35; }
@keyframes orb-breathe {
  0%, 100% { transform: scale(0.95); }
  50%      { transform: scale(1.03); }
}
@keyframes orb-halo-breathe {
  0%, 100% { opacity: 0.25; transform: scale(0.82); }
  50%      { opacity: 0.55; transform: scale(1.02); }
}

/* Listening — scale is driven by --level (mic amplitude); halo glows */
.orb.is-listening .orb-core {
  animation: none;
  transform: scale(calc(0.97 + var(--level) * 0.22));
}
.orb.is-listening .orb-halo {
  animation: none;
  opacity: calc(0.4 + var(--level) * 0.5);
  transform: scale(calc(0.9 + var(--level) * 0.5));
}
.orb.is-listening .orb-ring { opacity: 0.4; animation: orb-ring-spin 14s linear infinite; }

/* Thinking — conic ring spins fast, core dims slightly */
.orb.is-thinking .orb-core { animation: orb-breathe 1.6s ease-in-out infinite; filter: saturate(0.85) brightness(0.92); }
.orb.is-thinking .orb-halo { animation: orb-halo-breathe 1.6s ease-in-out infinite; }
.orb.is-thinking .orb-ring { opacity: 1; animation: orb-ring-spin 1.6s linear infinite; }

/* Speaking — rhythmic pulse, ring on */
.orb.is-speaking .orb-core { animation: orb-speak 0.95s ease-in-out infinite; }
.orb.is-speaking .orb-halo { animation: orb-speak-halo 0.95s ease-in-out infinite; }
.orb.is-speaking .orb-ring { opacity: 0.7; animation: orb-ring-spin 3.8s linear infinite; }
@keyframes orb-speak {
  0%, 100% { transform: scale(0.96); }
  40%      { transform: scale(1.08); }
  60%      { transform: scale(1.02); }
}
@keyframes orb-speak-halo {
  0%, 100% { opacity: 0.35; transform: scale(0.9); }
  40%      { opacity: 0.75; transform: scale(1.15); }
  60%      { opacity: 0.55; transform: scale(1.0); }
}
@keyframes orb-ring-spin { to { transform: rotate(360deg); } }

/* ── Status label + live caption ───────────────────────────────────── */
.voice-state {
  font-family: var(--f-mono);
  font-size: 11.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.7);
  min-height: 14px;
  transition: color 0.2s;
}
.voice-card[data-state="listening"] .voice-state { color: #fff; }
.voice-card[data-state="thinking"] .voice-state,
.voice-card[data-state="speaking"] .voice-state { color: var(--accent); }

.voice-caption {
  font-family: var(--f-display);
  font-size: clamp(16px, 2.1vw, 19px);
  font-style: italic;
  font-weight: 400;
  line-height: 1.45;
  text-align: center;
  color: rgba(255,255,255,0.92);
  min-height: 1.8em;
  max-width: 560px;
  padding: 0 10px;
  word-break: break-word;
  overflow-wrap: break-word;
  opacity: 0;
  transition: opacity 0.25s;
}
.voice-caption.show { opacity: 1; }

/* ── Controls row ──────────────────────────────────────────────────── */
.voice-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding-top: 10px;
}
.voice-ctrl-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.85);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.15s;
}
.voice-ctrl-btn:hover {
  background: rgba(255,255,255,0.16);
  color: #fff;
}
.voice-ctrl-btn:active { transform: scale(0.96); }
.voice-ctrl-btn .i-off { display: none; }
.voice-ctrl-btn[aria-pressed="true"] {
  background: rgba(255,255,255,0.92);
  color: var(--ink);
  border-color: transparent;
}
.voice-ctrl-btn[aria-pressed="true"] .i-on { display: none; }
.voice-ctrl-btn[aria-pressed="true"] .i-off { display: block; }
.voice-ctrl-btn[disabled] { opacity: 0.35; cursor: not-allowed; }

/* Interrupt — the stop/square button. Only lights up while the assistant
   is thinking or speaking; otherwise it sits disabled. */
.voice-interrupt-btn {
  color: #fff;
}
.voice-card[data-state="speaking"] .voice-interrupt-btn,
.voice-card[data-state="thinking"] .voice-interrupt-btn {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  animation: voice-interrupt-pulse 1.4s ease-in-out infinite;
}
.voice-card[data-state="speaking"] .voice-interrupt-btn:hover,
.voice-card[data-state="thinking"] .voice-interrupt-btn:hover {
  background: var(--accent-hover);
  animation: none;
}
@keyframes voice-interrupt-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(193,39,45,0.55); }
  50%      { box-shadow: 0 0 0 8px rgba(193,39,45,0); }
}

.voice-end-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 18px 0 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-pill);
  font: 500 13.5px/1 var(--f-sans);
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 14px rgba(193,39,45,0.4);
}
.voice-end-btn:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 6px 18px rgba(193,39,45,0.55); }
.voice-end-btn:active { transform: translateY(0); }
.voice-end-btn svg { transform: rotate(0deg); }

/* ═══════════════════════════════════════════════════════════════════════
   MODAL
   ═══════════════════════════════════════════════════════════════════════ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(26,23,20,0.4);
  backdrop-filter: blur(4px);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 10vh 20px 20px;
  z-index: 100;
  animation: backdrop-in 0.2s var(--ease-out);
}
.modal-backdrop.open { display: flex; }
@keyframes backdrop-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - 14vh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-pop);
  animation: modal-in 0.25s var(--ease-out);
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--line);
}
.modal-title-wrap { flex: 1; }
.modal-header h3 {
  font-family: var(--f-display);
  font-weight: 600;
  font-size: 21px;
  letter-spacing: -0.012em;
  margin: 0 0 4px;
}
.modal-sub { font-size: 13px; color: var(--ink-soft); margin: 0; line-height: 1.4; }
.modal-body { padding: 20px 22px 22px; overflow-y: auto; }

/* Ingest form */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}
.field-label {
  font-family: var(--f-mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-muted);
  font-weight: 500;
}
#ingest-url {
  padding: 11px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  font: 400 14px/1.3 var(--f-sans);
  background: var(--paper);
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#ingest-url:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}
#ingest-form .primary-btn { width: auto; margin-bottom: 18px; }

.jobs-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}
.jobs-label {
  font-family: var(--f-mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-muted);
  font-weight: 500;
}
.jobs-hint { font-size: 11px; color: var(--ink-muted); font-style: italic; }

.job-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 12px;
  align-items: center;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  background: var(--paper);
  font-size: 13px;
}
.job-row .job-url {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}
.job-row .job-meta {
  grid-column: 1 / -1;
  font-family: var(--f-mono);
  font-size: 11px;
  color: var(--ink-muted);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.job-row .job-meta .err { color: var(--danger); }

.pill {
  font-family: var(--f-mono);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 4px 9px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.pill.queued    { background: var(--paper-sunk); color: var(--ink-muted); }
.pill.crawling  { background: #e0edfb; color: #1d4ed8; }
.pill.ingesting { background: #d6f5ea; color: #0f766e; }
.pill.done      { background: #dcfce7; color: #166534; }
.pill.failed    { background: var(--danger-tint); color: var(--danger); }
[data-theme="dark"] .pill.crawling { background: #1a2a44; color: #93b7ee; }
[data-theme="dark"] .pill.ingesting { background: #122e27; color: #5ac6a2; }
[data-theme="dark"] .pill.done { background: #14321c; color: #86d49c; }

/* ── Empty state ─────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--ink-muted);
}
.empty-state.compact { padding: 28px 14px; }
.empty-glyph {
  font-family: var(--f-display);
  font-size: 40px;
  line-height: 1;
  color: var(--accent);
  opacity: 0.55;
  margin-bottom: 10px;
}
.empty-state.compact .empty-glyph { font-size: 30px; margin-bottom: 6px; }
.empty-title {
  font-weight: 500;
  color: var(--ink-soft);
  font-size: 13.5px;
  margin-bottom: 2px;
}
.empty-sub { font-size: 12.5px; }

/* Shortcuts modal */
.shortcuts-modal { max-width: 440px; }
.shortcut-list { margin: 0; display: flex; flex-direction: column; gap: 4px; }
.shortcut-list > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 2px;
  border-bottom: 1px dashed var(--line);
}
.shortcut-list > div:last-child { border-bottom: none; }
.shortcut-list dt { display: inline-flex; gap: 4px; margin: 0; }
.shortcut-list dd { margin: 0; color: var(--ink-soft); font-size: 13.5px; }

/* ── Citation hover card (Perplexity-style preview) ───────────────────── */
#cite-card {
  position: fixed;
  display: none;
  max-width: 320px;
  min-width: 240px;
  padding: 12px 14px 10px;
  background: var(--paper-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-2);
  z-index: 200;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--ink);
  pointer-events: none;
  animation: cite-in 0.15s var(--ease-out);
}
/* Arrow tail — position set via --cc-arrow-x/--cc-arrow-side by JS */
#cite-card::before,
#cite-card::after {
  content: "";
  position: absolute;
  left: var(--cc-arrow-x, 50%);
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
}
#cite-card[data-side="top"]::before {
  bottom: -7px;
  border-top: 7px solid var(--line-strong);
}
#cite-card[data-side="top"]::after {
  bottom: -6px;
  border-top: 7px solid var(--paper-raised);
}
#cite-card[data-side="bottom"]::before {
  top: -7px;
  border-bottom: 7px solid var(--line-strong);
  border-top: none;
}
#cite-card[data-side="bottom"]::after {
  top: -6px;
  border-bottom: 7px solid var(--paper-raised);
  border-top: none;
}
@keyframes cite-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
#cite-card .cc-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
  padding-bottom: 7px;
  border-bottom: 1px dashed var(--line);
}
#cite-card .cc-num {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--accent-tint);
  color: var(--accent);
  font: 600 10.5px/20px var(--f-mono);
  text-align: center;
  flex: 0 0 auto;
}
#cite-card .cc-fav {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex: 0 0 auto;
}
#cite-card .cc-domain {
  font-family: var(--f-mono);
  font-size: 10.5px;
  color: var(--ink-muted);
  letter-spacing: 0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
#cite-card .cc-title {
  font-weight: 600;
  margin-bottom: 5px;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.35;
  font-family: var(--f-display);
  letter-spacing: -0.002em;
}
#cite-card .cc-snippet {
  color: var(--ink-soft);
  font-family: var(--f-sans);
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.5;
}
#cite-card .cc-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px dashed var(--line);
  font-family: var(--f-mono);
  font-size: 10.5px;
  color: var(--ink-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
#cite-card .cc-foot .cc-hint {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}
#cite-card .cc-foot kbd { font-size: 9.5px; padding: 1px 4px; }

/* ── Toast ──────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translate(-50%, 12px);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  font: 500 12.5px/1 var(--f-sans);
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s var(--ease-out);
  pointer-events: none;
  z-index: 300;
  box-shadow: var(--shadow-2);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── Keyframes ──────────────────────────────────────────────────────── */
@keyframes fade-rise {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════════════ */

@media (max-width: 900px) {
  #sidebar {
    position: fixed;
    left: 0; top: 0;
    height: 100vh;
    box-shadow: var(--shadow-pop);
  }
  body:not(.sidebar-collapsed) #sidebar-scrim { opacity: 1; pointer-events: auto; }
  body.sidebar-collapsed #sidebar-open { display: inline-grid; }
  body:not(.sidebar-collapsed) #sidebar-open { display: none; }
  /* Default to collapsed on small screens */
  body { /* runtime-controlled class handles this */ }
}

@media (max-width: 620px) {
  #thread-wrap { padding: 48px 16px 160px; }
  .welcome { padding: 20px 0; }
  .prompt-cards { grid-template-columns: 1fr; }
  .composer-meta { display: none; }
  .composer-row { padding: 6px 8px 8px 16px; }
  #composer-wrap { padding: 10px 14px 16px; }
  .msg { gap: 10px; }
  .welcome-title { font-size: 36px; }
  .voice-card { padding: 22px 18px 18px; gap: 14px; }
  .voice-title { font-size: 22px; }
  .orb { --size: 180px; }
  .voice-stage { gap: 16px; padding: 14px 0 4px; }
  .voice-controls { gap: 10px; }
  .voice-end-btn { height: 40px; padding: 0 14px; font-size: 12.5px; }
  .voice-ctrl-btn { width: 40px; height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
