:root {
  --bg: #e4e0d5;
  --surface: #f1efe8;
  --card: #fcfbf7;
  --card2: #f1efe8;
  --text: #1a231d;
  --text-dim: #6c7269;
  --border: #e2ddd0;
  --hair: #eeeadf;
  --primary: #0b5d3b;
  --primary-ink: #fdfcf6;
  --primary-soft: #dceee3;
  --teal: #5dcaa5;
  --brass: #b5813f;
  --amber: #ef9f27;
  --coral: #ed93b1;
  --user-bubble: #0b5d3b;
  --user-ink: #fbfaf3;
  --conf-high: #0b5d3b;
  --conf-med: #b7770f;
  --conf-low: #c0413b;
  --doc-bg: #dceee3;
  --doc-ink: #0b5d3b;
  --judg-bg: #fbe7c9;
  --judg-ink: #8c560a;
  --scrim: rgba(20, 24, 20, 0.42);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #08100c;
    --surface: #101613;
    --card: #1a211d;
    --card2: #202824;
    --text: #eceae1;
    --text-dim: #98a199;
    --border: #2c352f;
    --hair: #232b26;
    --primary: #43c08f;
    --primary-ink: #052318;
    --primary-soft: #123528;
    --teal: #5dcaa5;
    --brass: #cfa063;
    --amber: #f0a93e;
    --coral: #ed93b1;
    --user-bubble: #1c6a49;
    --user-ink: #ecfbf3;
    --conf-high: #52c99a;
    --conf-med: #f0a93e;
    --conf-low: #f17e76;
    --doc-bg: #123528;
    --doc-ink: #7fe0b8;
    --judg-bg: #3a2c13;
    --judg-ink: #f0c078;
    --scrim: rgba(0, 0, 0, 0.55);
  }
}

/* 💕 Easter egg — "Scott mode": a chat turns pink + hearty. Toggled per-chat by app.js. */
body.scott-mode {
  --bg: #ffe0ee; --surface: #ffd4e6; --card: #fff5fa; --card2: #ffe6f1;
  --text: #4a1230; --text-dim: #9c6b82; --border: #f6bcd6; --hair: #fbd4e6;
  --primary: #d6407f; --primary-ink: #fff5fa; --primary-soft: #ffd5e6;
  --user-bubble: #d6407f; --user-ink: #fff5fa; --doc-bg: #ffd5e6; --doc-ink: #b12a63;
}
.hearts { position: fixed; inset: 0; pointer-events: none; z-index: 9999; overflow: hidden; }
.hearts .heart { position: absolute; bottom: -40px; font-size: 26px; will-change: transform, opacity;
  animation: heart-rise var(--dur, 4s) ease-in forwards; opacity: 0; }
@keyframes heart-rise {
  0% { transform: translateY(0) scale(0.6) rotate(0deg); opacity: 0; }
  12% { opacity: 0.95; }
  100% { transform: translateY(-102vh) scale(1.1) rotate(var(--rot, 20deg)); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) { .hearts .heart { animation-duration: 0.01ms; opacity: 0; } }

/* 😤 Easter egg — "Tyler mode": a chat turns dark + angry-red while the bot roasts you. Per-chat. */
body.tyler-mode {
  --bg: #201314; --surface: #2a181a; --card: #311b1d; --card2: #3b2123;
  --text: #f4e3e3; --text-dim: #bb8a8a; --border: #5e2e30; --hair: #3f2325;
  --primary: #d13b2f; --primary-ink: #fff2f0; --primary-soft: #4a2020;
  --user-bubble: #b3332a; --user-ink: #fff2f0; --doc-bg: #3a1e1e; --doc-ink: #ffc9c3;
}
.snarks { position: fixed; inset: 0; pointer-events: none; z-index: 9999; overflow: hidden; }
.snarks .snark { position: absolute; bottom: -40px; font-size: 26px; will-change: transform, opacity;
  animation: heart-rise var(--dur, 4s) ease-in forwards; opacity: 0; }
@media (prefers-reduced-motion: reduce) { .snarks .snark { animation-duration: 0.01ms; opacity: 0; } }

/* 👶 Easter egg — "Zak mode": a chat turns soft pastel nursery while the bot baby-talks you. Per-chat. */
body.zak-mode {
  --bg: #eaf4ff; --surface: #dff0ff; --card: #f4f9ff; --card2: #e6f2ff;
  --text: #33415c; --text-dim: #8aa0c0; --border: #bcd8f5; --hair: #d8ecff;
  --primary: #6db3f2; --primary-ink: #ffffff; --primary-soft: #d6ebff;
  --user-bubble: #7ec4f0; --user-ink: #0f314f; --doc-bg: #ffe3f1; --doc-ink: #c65b93;
}
.coos { position: fixed; inset: 0; pointer-events: none; z-index: 9999; overflow: hidden; }
.coos .coo { position: absolute; bottom: -40px; font-size: 26px; will-change: transform, opacity;
  animation: heart-rise var(--dur, 4s) ease-in forwards; opacity: 0; }
@media (prefers-reduced-motion: reduce) { .coos .coo { animation-duration: 0.01ms; opacity: 0; } }

/* 🕊️ Easter egg — "Kyle mode": a chat turns refined ivory + amethyst while the bot speaks in verse. */
body.kyle-mode {
  --bg: #f7f4ee; --surface: #efe9dd; --card: #fbf9f4; --card2: #f2ecdf;
  --text: #2c2a3a; --text-dim: #7a7488; --border: #d8cdb6; --hair: #e7ddc9;
  --primary: #6b5b95; --primary-ink: #fbf9f4; --primary-soft: #e6dff0;
  --user-bubble: #6b5b95; --user-ink: #fbf9f4; --doc-bg: #ece4f5; --doc-ink: #5a4a86;
}
.verses { position: fixed; inset: 0; pointer-events: none; z-index: 9999; overflow: hidden; }
.verses .verse { position: absolute; bottom: -40px; font-size: 26px; will-change: transform, opacity;
  animation: heart-rise var(--dur, 4s) ease-in forwards; opacity: 0; }
@media (prefers-reduced-motion: reduce) { .verses .verse { animation-duration: 0.01ms; opacity: 0; } }

/* ☕ Easter egg — "Travis mode": a chat goes near-black + electric-orange while the bot rages. Per-chat. */
body.travis-mode {
  --bg: #1a1613; --surface: #241d18; --card: #2b221b; --card2: #35291f;
  --text: #f6e9dd; --text-dim: #c39d80; --border: #5c3d22; --hair: #3d2c1d;
  --primary: #ff5a1f; --primary-ink: #2a1206; --primary-soft: #4a2a12;
  --user-bubble: #d9481a; --user-ink: #fff3ec; --doc-bg: #3a2113; --doc-ink: #ffb27a;
}
.rages { position: fixed; inset: 0; pointer-events: none; z-index: 9999; overflow: hidden; }
.rages .rage { position: absolute; bottom: -40px; font-size: 26px; will-change: transform, opacity;
  animation: heart-rise var(--dur, 4s) ease-in forwards; opacity: 0; }
@media (prefers-reduced-motion: reduce) { .rages .rage { animation-duration: 0.01ms; opacity: 0; } }

/* 🐕 Easter egg — "Griffin mode": a chat goes cozy warm-gold while the bot wanders adorably. Per-chat. */
body.griffin-mode {
  --bg: #fdf6e3; --surface: #f7ecd0; --card: #fffaf0; --card2: #f5ead2;
  --text: #4a3f2a; --text-dim: #9a8867; --border: #e6d4a8; --hair: #efe1c2;
  --primary: #d99a2b; --primary-ink: #fffaf0; --primary-soft: #f3e2bd;
  --user-bubble: #d99a2b; --user-ink: #402f12; --doc-bg: #f2e6c8; --doc-ink: #8a6d2a;
}
.wanders { position: fixed; inset: 0; pointer-events: none; z-index: 9999; overflow: hidden; }
.wanders .wander { position: absolute; bottom: -40px; font-size: 26px; will-change: transform, opacity;
  animation: heart-rise var(--dur, 4s) ease-in forwards; opacity: 0; }
@media (prefers-reduced-motion: reduce) { .wanders .wander { animation-duration: 0.01ms; opacity: 0; } }

/* 💼 Rob mode — corporate blue/gray boardroom. */
body.rob-mode {
  --bg: #eef2f6; --surface: #e2e8f0; --card: #f8fafc; --card2: #eaeff5;
  --text: #1f2d3d; --text-dim: #6b7a8d; --border: #cbd6e2; --hair: #dde5ee;
  --primary: #2b6cb0; --primary-ink: #f8fafc; --primary-soft: #dbe7f5;
  --user-bubble: #2b6cb0; --user-ink: #f8fafc; --doc-bg: #e3edf8; --doc-ink: #1d4e82;
}
.memos { position: fixed; inset: 0; pointer-events: none; z-index: 9999; overflow: hidden; }
.memos .memo { position: absolute; bottom: -40px; font-size: 26px; will-change: transform, opacity;
  animation: heart-rise var(--dur, 4s) ease-in forwards; opacity: 0; }
@media (prefers-reduced-motion: reduce) { .memos .memo { animation-duration: 0.01ms; opacity: 0; } }

/* 🕵️ Jesse mode — dark room, acid-green paranoia. */
body.jesse-mode {
  --bg: #12160f; --surface: #1a2013; --card: #1f2818; --card2: #26311c;
  --text: #d8f0c0; --text-dim: #8ca877; --border: #3c5230; --hair: #2a3720;
  --primary: #6fbf3f; --primary-ink: #12160f; --primary-soft: #2f3f22;
  --user-bubble: #5aa233; --user-ink: #0f1409; --doc-bg: #26311c; --doc-ink: #b6e08a;
}
.clues { position: fixed; inset: 0; pointer-events: none; z-index: 9999; overflow: hidden; }
.clues .clue { position: absolute; bottom: -40px; font-size: 26px; will-change: transform, opacity;
  animation: heart-rise var(--dur, 4s) ease-in forwards; opacity: 0; }
@media (prefers-reduced-motion: reduce) { .clues .clue { animation-duration: 0.01ms; opacity: 0; } }

/* 🧓 Ken mode — warm woody porch sepia. */
body.ken-mode {
  --bg: #efe6d6; --surface: #e6d9c2; --card: #f6efe1; --card2: #ece0cb;
  --text: #4a3a28; --text-dim: #927b5e; --border: #d3c1a0; --hair: #e2d4bb;
  --primary: #8b5e34; --primary-ink: #f6efe1; --primary-soft: #e6d3b6;
  --user-bubble: #8b5e34; --user-ink: #f6efe1; --doc-bg: #ecdfc8; --doc-ink: #6b4a28;
}
.yarns { position: fixed; inset: 0; pointer-events: none; z-index: 9999; overflow: hidden; }
.yarns .yarn { position: absolute; bottom: -40px; font-size: 26px; will-change: transform, opacity;
  animation: heart-rise var(--dur, 4s) ease-in forwards; opacity: 0; }
@media (prefers-reduced-motion: reduce) { .yarns .yarn { animation-duration: 0.01ms; opacity: 0; } }

/* 🌑 Jackson mode — muted, desaturated slate/ash (resignation). */
body.jackson-mode {
  --bg: #1c1f22; --surface: #24282c; --card: #2a2f33; --card2: #32383d;
  --text: #cfd6da; --text-dim: #8a9296; --border: #454d53; --hair: #333a3f;
  --primary: #6b7a83; --primary-ink: #eef2f4; --primary-soft: #39424a;
  --user-bubble: #55636b; --user-ink: #eef2f4; --doc-bg: #2f363b; --doc-ink: #a9b4ba;
}
.voids { position: fixed; inset: 0; pointer-events: none; z-index: 9999; overflow: hidden; }
.voids .void { position: absolute; bottom: -40px; font-size: 26px; will-change: transform, opacity;
  animation: heart-rise var(--dur, 4s) ease-in forwards; opacity: 0; }
@media (prefers-reduced-motion: reduce) { .voids .void { animation-duration: 0.01ms; opacity: 0; } }

/* 😬 Tristen mode — garish, clashing magenta/yellow cringe. */
body.tristen-mode {
  --bg: #f3e6ff; --surface: #e9d4ff; --card: #faf2ff; --card2: #efdcff;
  --text: #3a1d5c; --text-dim: #8a6bb0; --border: #d8b4f5; --hair: #e6d0fa;
  --primary: #b83db8; --primary-ink: #ffffff; --primary-soft: #f0d6f5;
  --user-bubble: #cf3fb0; --user-ink: #ffffff; --doc-bg: #ffe9b0; --doc-ink: #9a5a00;
}
.cringes { position: fixed; inset: 0; pointer-events: none; z-index: 9999; overflow: hidden; }
.cringes .cringe { position: absolute; bottom: -40px; font-size: 26px; will-change: transform, opacity;
  animation: heart-rise var(--dur, 4s) ease-in forwards; opacity: 0; }
@media (prefers-reduced-motion: reduce) { .cringes .cringe { animation-duration: 0.01ms; opacity: 0; } }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--surface);
  color: var(--text);
}
.hidden { display: none !important; }
.error { color: var(--conf-low); font-weight: 500; }
.mascot { object-fit: contain; display: block; }
.mascot.logo { width: 32px; height: 32px; }
.mascot.hero { width: auto; height: 250px; max-width: 90%; }
.float { animation: jbFloat 5s ease-in-out infinite; }

@keyframes jbFloat { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes jbFade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes jbDot { 0%,60%,100% { transform: translateY(0); opacity: 0.4; } 30% { transform: translateY(-4px); opacity: 1; } }
@keyframes jbScrim { from { opacity: 0; } to { opacity: 1; } }
@keyframes jbDrawer { from { transform: translateX(-100%); } to { transform: translateX(0); } }
@keyframes jbPop { from { opacity: 0; transform: translate(-50%, -48%) scale(0.96); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }

/* ---- buttons ---- */
.primary-btn {
  height: 54px; border: none; border-radius: 14px; background: var(--primary); color: var(--primary-ink);
  font: inherit; font-size: 17px; font-weight: 500; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.icon-btn {
  width: 44px; height: 44px; border: none; background: transparent; color: var(--text);
  cursor: pointer; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center;
  font-size: 26px; line-height: 1;
}
.icon-btn:hover { background: var(--card2); }
.plus-btn { color: var(--primary); font-size: 27px; }
.hamburger { flex-direction: column; gap: 4px; }
.hamburger span { width: 19px; height: 2px; background: currentColor; border-radius: 2px; }

/* ---- gate ---- */
.gate {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 44px 30px 40px; gap: 6px;
}
.gate-title { font-size: 27px; font-weight: 500; letter-spacing: -0.4px; margin: 6px 0 0; }
.gate-sub { font-size: 16px; color: var(--text-dim); line-height: 1.5; max-width: 280px; margin: 4px 0 0; }
.gate-form { width: 100%; max-width: 320px; margin-top: 24px; display: flex; flex-direction: column; gap: 12px; }
.gate-form label { text-align: left; font-size: 13px; font-weight: 500; color: var(--text-dim); }
#gate-input {
  height: 54px; border-radius: 14px; border: 1px solid var(--border); background: var(--card); color: var(--text);
  font-size: 20px; letter-spacing: 6px; text-align: center; padding: 0 16px; outline: none; width: 100%;
}
#gate-input:focus { border-color: var(--primary); }

/* ---- app shell ---- */
.app { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: 10px 10px; padding-top: max(12px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--hair);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand-name { font-size: 19px; font-weight: 500; letter-spacing: -0.3px; }

.transcript {
  flex: 1; overflow-y: auto; overflow-x: hidden; padding: 18px 16px 8px;
  display: flex; flex-direction: column; gap: 18px;
}

/* ---- empty state ---- */
.empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 20px 14px; gap: 6px; min-height: 60vh;
}
.empty-title { font-size: 21px; font-weight: 500; letter-spacing: -0.3px; margin-top: 8px; }
.empty-sub { font-size: 15.5px; color: var(--text-dim); line-height: 1.5; max-width: 300px; margin: 2px 0 0; }
.role-pill {
  margin-top: 16px; display: inline-flex; align-items: center; gap: 7px; padding: 10px 18px;
  border-radius: 999px; border: 1.5px solid var(--primary); background: var(--primary-soft);
  color: var(--primary); font: inherit; font-size: 14px; font-weight: 500; cursor: pointer;
}
.role-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--primary); }
.role-pill .caret { font-size: 11px; }

/* ---- persona selector (topbar) ---- */
.persona-pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px;
  border-radius: 999px; border: 1.5px solid var(--primary); background: var(--primary-soft);
  color: var(--primary); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  white-space: nowrap; max-width: 48vw; overflow: hidden;
}
.persona-pill:hover { filter: brightness(0.97); }
.persona-pill-emoji { font-size: 16px; line-height: 1; }
.persona-pill .caret { font-size: 11px; opacity: 0.75; }
#persona-pill-text { overflow: hidden; text-overflow: ellipsis; }
.persona-popover { width: 260px; max-height: 76vh; overflow-y: auto; }
.role-opt .opt-emoji { margin-right: 9px; }
@media (max-width: 560px) { .brand-name { display: none; } }

/* ---- Design / BOM mode toggle + bill-of-materials tables ---- */
.design-pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 7px 12px;
  border-radius: 999px; border: 1.5px solid var(--border, #cfc9ba);
  background: transparent; color: var(--muted, #6b7a72);
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.design-pill:hover { border-color: var(--primary); color: var(--primary); }
.design-pill.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.design-pill-emoji { font-size: 15px; line-height: 1; }
.a-raw { overflow-x: auto; }
.a-raw table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 13px; }
.a-raw th, .a-raw td {
  border: 1px solid rgba(128, 128, 128, 0.3); padding: 6px 9px; text-align: left; vertical-align: top;
}
.a-raw thead th { background: rgba(128, 128, 128, 0.12); font-weight: 600; }

/* ---- role popover ---- */
.role-scrim { position: fixed; inset: 0; z-index: 45; }
.role-popover {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 240px; z-index: 46;
  background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 6px;
  box-shadow: 0 14px 34px -12px rgba(0, 0, 0, 0.4); animation: jbPop 0.15s ease both;
}
.role-popover-label {
  font-size: 11px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-dim); padding: 6px 10px 4px;
}
.role-opt {
  width: 100%; text-align: left; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 10px; border-radius: 9px; border: none; background: transparent; color: var(--text);
  font: inherit; font-size: 15px; cursor: pointer;
}
.role-opt.active { background: var(--card2); }
.role-opt .check { color: var(--primary); font-weight: 500; }

/* ---- messages ---- */
.msg { display: flex; flex-direction: column; animation: jbFade 0.35s ease both; }
.msg.user > .wrap { align-self: flex-end; max-width: 82%; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.user-bubble {
  background: var(--user-bubble); color: var(--user-ink); padding: 12px 15px;
  border-radius: 20px 20px 6px 20px; font-size: 16px; line-height: 1.5; white-space: pre-wrap;
}
.bubble-images { display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.bubble-images img { width: 92px; height: 92px; object-fit: cover; border-radius: 13px; border: 1px solid var(--border); }

/* ---- answer card ---- */
.answer { align-self: flex-start; width: 100%; }
.answer-card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.a-direct { padding: 15px 17px; background: var(--primary-soft); border-bottom: 1px solid var(--hair); }
.a-body { padding: 6px 17px 15px; display: flex; flex-direction: column; }
.a-section { padding-top: 14px; }
.a-label {
  font-size: 11.5px; font-weight: 500; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--text-dim); margin-bottom: 6px;
}
.a-direct .a-label { color: var(--primary); margin-bottom: 5px; }
.a-direct .a-text { font-size: 17px; line-height: 1.5; font-weight: 500; }
.a-text { font-size: 16px; line-height: 1.6; }
.a-text p { margin: 0 0 8px; }
.a-text p:last-child { margin-bottom: 0; }
.a-text code { background: var(--card2); border-radius: 5px; padding: 1px 5px; font-family: ui-monospace, Menlo, monospace; font-size: 0.9em; }
.a-text strong { font-weight: 500; }

.doc-row { display: flex; gap: 8px; align-items: baseline; font-size: 15.5px; line-height: 1.5; margin-bottom: 9px; }
.doc-row:last-child { margin-bottom: 0; }
.chip {
  flex-shrink: 0; font-size: 11px; font-weight: 500; padding: 3px 8px; border-radius: 6px;
  white-space: nowrap; transform: translateY(-1px);
}
.chip.doc { background: var(--doc-bg); color: var(--doc-ink); }
.chip.judg { background: var(--judg-bg); color: var(--judg-ink); }

.step-row { display: flex; gap: 11px; align-items: flex-start; font-size: 15.5px; line-height: 1.5; margin-bottom: 9px; }
.step-row:last-child { margin-bottom: 0; }
.kd-list { margin: 0; padding-left: 20px; font-size: 15.5px; line-height: 1.55; }
.kd-list li { margin-bottom: 7px; }
.kd-list li:last-child { margin-bottom: 0; }
.kd-list code { background: var(--card2); border-radius: 5px; padding: 1px 5px; font-family: ui-monospace, Menlo, monospace; font-size: 0.9em; }
.step-n {
  flex-shrink: 0; width: 23px; height: 23px; border-radius: 50%; background: var(--primary-soft);
  color: var(--primary); font-size: 13px; font-weight: 500; display: flex; align-items: center; justify-content: center; margin-top: 1px;
}
.mistake-row { display: flex; gap: 9px; align-items: flex-start; font-size: 15.5px; line-height: 1.5; margin-bottom: 8px; }
.mistake-row:last-child { margin-bottom: 0; }
.mistake-row .warn { flex-shrink: 0; color: var(--amber); margin-top: 1px; }

.tag { font-weight: 500; }
.tag-doc { color: var(--doc-ink); }
.tag-judge { color: var(--judg-ink); }

/* Control bar under the Direct Answer: confidence · manual pages · sources */
.a-top { padding: 12px 17px 0; }
.a-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.conf-pill {
  display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid; font-size: 13px; font-weight: 600; line-height: 1;
}
.conf-pill .dot { width: 8px; height: 8px; border-radius: 50%; }
.conf-why { margin-top: 7px; font-size: 13px; line-height: 1.45; color: var(--muted, #6b7280); }
.pages-btn, .sources-btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border);
  background: var(--card2); color: var(--text); font: inherit; font-size: 13px; font-weight: 500;
  padding: 6px 12px; border-radius: 999px; cursor: pointer; line-height: 1.1;
}
.pages-btn:hover, .sources-btn:hover { border-color: var(--teal); color: var(--teal); }
.pages-btn .n, .sources-btn .n {
  display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px;
  padding: 0 5px; border-radius: 999px; background: var(--card); border: 1px solid var(--border);
  font-size: 11.5px; font-weight: 600;
}
.sources-btn .caret { font-size: 12px; color: var(--text-dim); transition: transform 0.2s; }
.a-top.sources-open .sources-btn .caret { transform: rotate(180deg); }
.a-sources-list { display: none; flex-direction: column; gap: 7px; padding-top: 11px; }
.a-top.sources-open .a-sources-list { display: flex; }
.src-row { display: flex; gap: 8px; align-items: baseline; font-size: 13px; line-height: 1.45; color: var(--text-dim); word-break: break-word; }
.src-row .sec { color: var(--teal); flex-shrink: 0; }
.src-row .src-loc { flex: 1; min-width: 0; }

/* Manual-pages viewer — scroll through every cited page, real drawings and all */
.pageview {
  position: fixed; inset: 0; z-index: 60; display: none; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.62);
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}
.pageview.open { display: flex; }
.pageview-box {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px; overflow: hidden;
  width: min(960px, 100%); max-height: 100%; display: flex; flex-direction: column;
  box-shadow: 0 24px 60px -18px rgba(0, 0, 0, 0.6);
}
.pageview-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--hair); background: var(--surface); flex-shrink: 0;
}
.pageview-cap { font-size: 14px; font-weight: 600; color: var(--text); }
.pv-close {
  border: 1px solid var(--border); background: var(--card2); color: var(--text); font: inherit;
  font-size: 15px; width: 32px; height: 32px; border-radius: 8px; cursor: pointer; line-height: 1; flex-shrink: 0;
}
.pv-close:hover { border-color: var(--teal); color: var(--teal); }
.pageview-stage {
  overflow: auto; background: var(--card2); display: flex; flex-direction: column; align-items: center;
  gap: 16px; padding: 16px; min-height: 200px;
}
.pv-item { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.pv-item-cap { align-self: flex-start; font-size: 12px; color: var(--text-dim); }
.pv-img {
  max-width: 100%; height: auto; display: block; background: #fff; border-radius: 4px;
  box-shadow: 0 2px 10px -4px rgba(0, 0, 0, 0.4);
}
.pv-msg { color: var(--text-dim); font-size: 13.5px; padding: 24px 20px; text-align: center; }

.a-cost { margin-top: 13px; font-size: 12px; color: var(--text-dim); display: flex; align-items: center; gap: 7px; }
.a-cost .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--text-dim); opacity: 0.5; }
.a-error-note { margin-top: 8px; }

/* Clarify card — the gate's follow-up question with tappable option chips */
.clarify-body { gap: 14px; padding-top: 12px; }
.clarify-q { display: flex; flex-direction: column; gap: 8px; }
.clarify-qtext { font-size: 14.5px; font-weight: 500; color: var(--text); line-height: 1.4; }
.clarify-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.clarify-chip {
  border: 1px solid var(--teal); background: color-mix(in srgb, var(--teal) 10%, transparent);
  color: var(--text); font: inherit; font-size: 13.5px; font-weight: 500; line-height: 1.2;
  padding: 8px 14px; border-radius: 999px; cursor: pointer;
}
.clarify-chip:hover { background: color-mix(in srgb, var(--teal) 22%, transparent); }
.clarify-chip:active { transform: translateY(1px); }
/* chips that carry a "what's different" note become a small two-line card */
.clarify-chip.has-note {
  display: inline-flex; flex-direction: column; align-items: flex-start; gap: 2px;
  border-radius: 12px; padding: 8px 13px; text-align: left; max-width: 270px;
}
.clarify-chip .chip-label { font-weight: 600; }
.clarify-chip .chip-note { font-size: 11.5px; font-weight: 400; color: var(--text-dim); line-height: 1.25; }
.clarify-hint { font-size: 12.5px; color: var(--text-dim); margin-top: 2px; }

/* Answer feedback — installer 👍/👎 (review queue for Jackson; never auto-changes anything) */
.a-fb { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 17px 14px; border-top: 1px solid var(--hair); }
.a-fb .fb-q { font-size: 13px; color: var(--text-dim); }
.a-fb .fb-btn {
  border: 1px solid var(--border); background: var(--card2); font-size: 15px; line-height: 1;
  width: 34px; height: 30px; border-radius: 8px; cursor: pointer;
}
.a-fb .fb-btn:hover { border-color: var(--teal); }
.a-fb .fb-note {
  flex: 1 1 220px; min-width: 180px; font: inherit; font-size: 13px; padding: 7px 9px; resize: vertical;
  border: 1px solid var(--border); border-radius: 8px; background: var(--card); color: var(--text);
}
.a-fb .fb-send {
  border: 1px solid var(--teal); background: color-mix(in srgb, var(--teal) 12%, transparent); color: var(--text);
  font: inherit; font-size: 13px; font-weight: 500; padding: 7px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.a-fb .fb-done { font-size: 13px; color: var(--text-dim); }

/* raw markdown fallback for answers that don't parse */
.a-raw { padding: 15px 17px; font-size: 16px; line-height: 1.6; }
.a-raw h3 { font-size: 15px; color: var(--primary); margin: 14px 0 4px; }
.a-raw h3:first-child { margin-top: 0; }
.a-raw p { margin: 6px 0; }
.a-raw ul, .a-raw ol { margin: 6px 0; padding-left: 22px; }

/* ---- error card ---- */
.err-card { align-self: flex-start; max-width: 92%; display: flex; gap: 9px; align-items: flex-start; }
.err-card .mascot { width: 32px; height: 32px; flex-shrink: 0; margin-top: 2px; }
.err-body { background: var(--card); border: 1px solid var(--conf-low); border-radius: 14px; padding: 15px 16px; display: flex; flex-direction: column; gap: 8px; }
.err-title { display: flex; align-items: center; gap: 8px; color: var(--conf-low); font-weight: 500; font-size: 14.5px; }
.err-title .bang { width: 20px; height: 20px; border-radius: 50%; background: var(--conf-low); color: var(--card); display: inline-flex; align-items: center; justify-content: center; font-size: 13px; }
.err-msg { font-size: 15.5px; line-height: 1.55; }
.retry-btn { align-self: flex-start; margin-top: 2px; padding: 9px 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--card2); color: var(--text); font: inherit; font-size: 14px; font-weight: 500; cursor: pointer; }

/* ---- thinking ---- */
.thinking { align-self: flex-start; display: flex; gap: 9px; align-items: center; animation: jbFade 0.3s ease both; }
.thinking .mascot { width: 46px; height: 46px; flex-shrink: 0; }
.thinking-bubble { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 12px 16px; display: flex; flex-direction: column; gap: 5px; }
.thinking-dots { display: flex; align-items: center; gap: 6px; }
.thinking-dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--teal); }
.thinking-dots span:nth-child(1) { animation: jbDot 1.2s ease-in-out 0s infinite; }
.thinking-dots span:nth-child(2) { animation: jbDot 1.2s ease-in-out 0.15s infinite; }
.thinking-dots span:nth-child(3) { animation: jbDot 1.2s ease-in-out 0.3s infinite; }
.thinking-status { font-size: 13.5px; color: var(--text-dim); }

/* ---- composer ---- */
.composer { border-top: 1px solid var(--hair); background: var(--surface); padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
.attachments { display: flex; gap: 8px; padding: 4px 2px 10px; flex-wrap: wrap; }
.stg { position: relative; width: 66px; height: 66px; border-radius: 11px; overflow: hidden; border: 1px solid var(--border); }
.stg img { width: 100%; height: 100%; object-fit: cover; }
.stg-del { position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 50%; border: none; background: rgba(20, 24, 20, 0.72); color: #fff; font-size: 12px; cursor: pointer; display: flex; align-items: center; justify-content: center; line-height: 1; }
.composer-card { display: flex; align-items: flex-end; gap: 8px; border: 1px solid var(--border); background: var(--card); border-radius: 18px; padding: 8px 10px; }
.attach-btn { width: 36px; height: 36px; flex-shrink: 0; border-radius: 10px; border: 1px solid var(--border); background: var(--card2); color: var(--text); cursor: pointer; display: flex; align-items: center; justify-content: center; }
#question { flex: 1; min-width: 0; border: none; background: transparent; color: var(--text); font: inherit; font-size: 16px; line-height: 1.4; resize: none; outline: none; min-height: 40px; max-height: 40vh; padding: 8px 0; }
.send-btn { width: 40px; height: 40px; flex-shrink: 0; border-radius: 12px; border: none; background: var(--primary); color: var(--primary-ink); cursor: pointer; display: flex; align-items: center; justify-content: center; }
.send-btn:disabled { opacity: 0.5; }

/* ---- drawer ---- */
.overlay { position: fixed; inset: 0; z-index: 45; background: var(--scrim); animation: jbScrim 0.25s ease both; }
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: 80%; max-width: 320px; z-index: 46;
  background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column;
  transform: translateX(-100%); transition: transform 0.28s cubic-bezier(0.22, 0.61, 0.36, 1);
  padding-top: env(safe-area-inset-top);
}
.drawer.open { transform: translateX(0); box-shadow: 14px 0 40px -18px rgba(0, 0, 0, 0.4); }
.drawer-head { padding: 16px 16px 12px; display: flex; align-items: center; justify-content: space-between; font-size: 18px; font-weight: 500; }
.drawer-head .icon-btn { font-size: 19px; color: var(--text-dim); width: 38px; height: 38px; }
.drawer-new { padding: 4px 12px 12px; }
.new-chat-btn { width: 100%; height: 46px; border-radius: 12px; border: 1px dashed var(--primary); background: var(--primary-soft); color: var(--primary); font: inherit; font-size: 15px; font-weight: 500; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; }
.new-chat-btn .plus { font-size: 18px; }
.export-btn { width: 100%; height: 40px; margin-top: 8px; border-radius: 12px; border: 1px solid var(--border); background: var(--card2); color: var(--text-dim); font: inherit; font-size: 13.5px; font-weight: 500; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; }
.export-btn:hover { border-color: var(--teal); color: var(--text); }
.chat-list { list-style: none; margin: 0; padding: 4px 8px 16px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.chat-list li { display: flex; align-items: center; gap: 4px; border-radius: 12px; }
.chat-list li.active { background: var(--card2); }
.chat-open { flex: 1; min-width: 0; text-align: left; padding: 12px; border: none; background: transparent; cursor: pointer; font: inherit; display: flex; flex-direction: column; gap: 3px; }
.chat-open .title { font-size: 15px; font-weight: 500; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-open .when { font-size: 12.5px; color: var(--text-dim); }
.chat-del { width: 40px; height: 44px; flex-shrink: 0; border: none; background: transparent; color: var(--text-dim); cursor: pointer; display: flex; align-items: center; justify-content: center; }
.chat-del:hover { color: var(--conf-low); }

/* Batch delete (multi-select "clean up old chats") */
.drawer-head-actions { display: flex; align-items: center; gap: 6px; }
.text-btn { border: none; background: transparent; color: var(--primary); font: inherit; font-size: 14px; font-weight: 500; cursor: pointer; padding: 6px 8px; border-radius: 8px; }
.text-btn:hover { background: var(--card2); }
.batch-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 14px 10px; }
.batch-bar.hidden { display: none; }
.batch-all { display: inline-flex; align-items: center; gap: 7px; font-size: 14px; color: var(--text-dim); cursor: pointer; }
.batch-all input, .chat-check { width: 17px; height: 17px; accent-color: var(--primary); cursor: pointer; flex-shrink: 0; }
.batch-del-btn { border: 1px solid var(--conf-low); background: transparent; color: var(--conf-low); font: inherit; font-size: 14px; font-weight: 500; padding: 7px 14px; border-radius: 10px; cursor: pointer; }
.batch-del-btn:hover:not(:disabled) { background: var(--conf-low); color: #fff; }
.batch-del-btn:disabled { opacity: 0.4; cursor: default; }
.chat-list.select-mode li { padding-left: 10px; }
.chat-list.select-mode li.checked { background: var(--primary-soft); }
.chat-list.select-mode .chat-open { cursor: pointer; }

/* wider screens: center the column like a phone-width app */
@media (min-width: 640px) {
  .transcript, .composer, .empty { max-width: 720px; width: 100%; margin-left: auto; margin-right: auto; }
  .topbar { max-width: 720px; width: 100%; margin: 0 auto; }
}

/* ---- Zoho/Supabase sign-in additions ---- */
.gate-sso { margin-top: 4px; }
.drawer-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: auto; padding: 12px 16px; border-top: 1px solid rgba(0, 0, 0, 0.08);
}
.signed-in-as {
  font-size: 12px; color: #7c8a82; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
