/* KB Helper web UI — redesign v2 (Claude Design handoff): charcoal / signal-red, square corners */
:root, :root[data-theme="dark"] {
  /* pen.dev "AT v2" tokens — dark */
  --canvas: #0E0A09;
  --bg: #1B1311;
  --panel: #231916;
  --panel-2: #2D211D;
  --field: #1B1311;
  --hover: #3A2A25;
  --track: #3A2A25;
  --line: #43312B;
  --line-soft: rgba(67, 49, 43, .6);
  --line-strong: #5E463D;
  --red: #9C4434;          /* accent fill, white text on top */
  --red-hi: #B0503E;       /* hover fill */
  --red-text: #E58A70;     /* accent text */
  --accent-soft: rgba(156, 68, 52, .24);
  --accent-wash: #2E1D18;
  --steel: #5E463D;
  --strong: #FFFFFF;
  --paper: #F5EEE9;
  --soft: #D3C4BA;
  --muted: #A39287;
  --dim: #A39287;
  --blue: #9DB8E8;
  --ok: #62C98D;
  --warn: #E3B25B;
  --danger: #F08A78;
  --on-accent: #FFFFFF;
  --grid: rgba(255, 255, 255, .025);
  --wash: var(--wash);
  --sunk: var(--sunk);
  --shadow: 0 18px 40px rgba(0, 0, 0, .35);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, .25);
  --r: 8px; --r-sm: 6px; --r-lg: 12px; --r-pill: 999px;
  --pixel: "Teko", "Arial Narrow", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --body: "Titillium Web", system-ui, sans-serif;
  --ink: var(--bg); --char: var(--hover); --char-2: var(--panel-2);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --canvas: #BDBAB6;
  --bg: #D1D1D1;
  --panel: #ECEBE9;
  --panel-2: #F8F7F5;
  --field: #F8F7F5;
  --hover: #DCDAD6;
  --track: #DCDAD6;
  --line: #BFBBB6;
  --line-soft: rgba(191, 187, 182, .7);
  --line-strong: #A29C96;
  --red: #9C4434;
  --red-hi: #B0503E;
  --red-text: #9E4430;
  --accent-soft: rgba(158, 68, 48, .12);
  --accent-wash: #F6ECE8;
  --steel: #A29C96;
  --strong: #1E1E1E;
  --paper: #282828;
  --soft: #45403C;
  --muted: #615B56;
  --dim: #615B56;
  --blue: #17458A;
  --ok: #2E8550;
  --warn: #A86B12;
  --danger: #B83A26;
  --grid: rgba(0, 0, 0, .035);
  --wash: rgba(0, 0, 0, .04);
  --sunk: rgba(0, 0, 0, .04);
  --shadow: 0 14px 34px rgba(58, 30, 22, .14);
  --shadow-sm: 0 2px 8px rgba(58, 30, 22, .10);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; overflow-x: hidden; }
body {
  color: var(--paper);
  font: 15.5px/1.6 var(--body);
  min-height: 100vh;
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  display: flex; flex-direction: column;
  padding: 6px 40px 0;           /* 6px = brand stripe */
}
body > * { width: 100%; max-width: 1440px; margin-left: auto; margin-right: auto; }
body { position: relative; }
body::after {                    /* brand split stripe (scrolls away, like the design) */
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 6px; z-index: 50;
  background: linear-gradient(90deg, #4B4B4D 0 62%, var(--red) 62% 100%);
  pointer-events: none;
}
a { color: var(--paper); }
a:hover { color: var(--strong); }
code { font-family: var(--mono); font-size: .9em; color: var(--strong); background: var(--panel-2); padding: 1px 5px; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
::selection { background: rgba(193, 64, 49, .6); color: var(--strong); }
* { scrollbar-width: thin; scrollbar-color: rgba(193, 64, 49, .6) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: rgba(193, 64, 49, .55); }
:focus-visible { outline: 2px solid var(--red-hi); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.blink { animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- shared bits ---------- */
.kicker {
  margin: 0 0 18px; font-family: var(--mono); font-size: 14px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--red-text);
}
.panel { background: var(--panel); border: 1px solid var(--line); }
.panel-head {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--line); min-height: 59px;
}
.panel-head h2, .panel-head h4 {
  margin: 0; font-family: var(--mono); font-size: 12px; font-weight: 500; letter-spacing: .14em;
  text-transform: uppercase; color: var(--muted);
}
.card { background: var(--panel-2); border: 1px solid var(--line); border-top: 6px solid var(--red); box-shadow: var(--shadow); }
.card-head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.card-head h3 {
  margin: 0; font-family: var(--pixel); font-weight: 400; font-size: 22px; letter-spacing: .06em;
  text-transform: uppercase; color: var(--strong);
}
.head-tools { display: flex; align-items: center; gap: 10px; }
.ghost {
  height: 30px; padding: 0 12px; background: transparent; border: 1px solid var(--line-strong);
  color: var(--soft); font-family: var(--mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase;
  transition: color .2s, border-color .2s, background .2s; white-space: nowrap;
}
.ghost:hover { color: var(--strong); border-color: var(--steel); }
.ghost.danger:hover { background: var(--red); border-color: var(--red); }
.link {
  background: none; border: none; padding: 0; font-family: var(--mono); font-size: 11px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--red-text); white-space: nowrap;
}
.link:hover { color: var(--strong); }
.ask {
  height: 46px; min-width: 104px; padding: 0 20px; display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--red); color: var(--strong); border: none; box-shadow: 3px 3px 0 rgba(0,0,0,.45);
  font-family: var(--pixel); font-size: 16px; letter-spacing: .12em; text-transform: uppercase;
  transition: background .2s, transform .2s, box-shadow .2s;
}
.ask svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: square; }
.ask:hover { background: var(--red-hi); transform: translate(-1px, -1px); box-shadow: 5px 5px 0 #000; }
.ask:disabled { opacity: .45; transform: none; cursor: default; }
.ask.stop { background: var(--hover); }
.ask.stop svg { display: none; }
.section-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; flex-wrap: wrap;
  padding: 34px 0 22px;
}
.section-head h2 {
  font-family: var(--pixel); font-weight: 400; font-size: clamp(30px, 3.4vw, 44px); line-height: 1.05;
  color: var(--strong); margin: 0 0 12px; text-transform: uppercase;
}
.sub { margin: 0; color: var(--soft); max-width: 640px; }

/* switch */
.switch { display: flex; align-items: center; justify-content: space-between; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { font-family: var(--mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.switch i { width: 40px; height: 22px; flex: 0 0 40px; background: var(--field); border: 1px solid var(--line); position: relative; transition: background .2s; }
.switch i::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px;
  background: var(--steel); transition: transform .2s, background .2s;
}
.switch input:checked + i { background: rgba(193, 64, 49, .35); border-color: var(--red); }
.switch input:checked + i::after { transform: translateX(18px); background: var(--strong); }
.switch input:focus-visible + i { outline: 2px solid var(--red-hi); outline-offset: 2px; }

/* ---------- top bar ---------- */
.bar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 16px 36px;
  padding: 22px 0 18px; border-bottom: 1px solid var(--line);
}
.logo { display: flex; line-height: 0; box-shadow: 6px 6px 0 rgba(0,0,0,.45); }
.logo img { height: 56px; width: auto; display: block; }
.nav { display: flex; gap: 30px; flex-wrap: wrap; margin-right: auto; }
.nav a {
  font-family: var(--pixel); font-size: 14px; letter-spacing: .08em; text-decoration: none;
  text-transform: uppercase; color: var(--muted); padding-bottom: 4px;
  border-bottom: 3px solid transparent; transition: color .2s, border-color .2s;
}
.nav a:hover { color: var(--strong); border-bottom-color: var(--line-strong); }
.nav a.on { color: var(--strong); border-bottom-color: var(--red); }
.chips { display: flex; align-items: center; gap: 10px; font-family: var(--mono); font-size: 12px; letter-spacing: .1em; text-transform: uppercase; }
.live, .chip { display: flex; align-items: center; gap: 8px; padding: 7px 12px; border: 1px solid var(--line); white-space: nowrap; }
.live { background: var(--panel-2); color: var(--paper); }
.chip { color: var(--muted); }
.live::before { content: ""; width: 8px; height: 8px; background: var(--dim); }
.live.ok::before { background: var(--ok); animation: pulse 2s infinite; }
.live.off::before { background: var(--red-hi); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(95, 211, 138, .55); }
  70% { box-shadow: 0 0 0 8px rgba(95, 211, 138, 0); }
  100% { box-shadow: 0 0 0 0 rgba(95, 211, 138, 0); }
}

main { flex: 1; }
.view { display: none; }
.view.on { display: block; animation: fade .35s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- hero ---------- */
.hero { display: flex; flex-wrap: wrap; gap: 40px; align-items: stretch; padding: 48px 0 40px; }
.hero-text { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; }
.title {
  margin: 0 0 24px; font-family: var(--pixel); font-weight: 400; font-size: clamp(40px, 6vw, 84px);
  line-height: .98; letter-spacing: .01em; text-transform: uppercase; color: var(--strong); text-wrap: balance;
}
.title em { font-style: normal; color: var(--red-text); }
.lead { margin: 0 0 32px; max-width: 560px; font-size: 17px; line-height: 1.6; color: var(--soft); }
.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); gap: 1px;
  background: var(--line); border: 1px solid var(--line); margin-top: auto; max-width: 720px;
}
.stat { background: var(--bg); padding: 16px 18px 14px; }
.stat b { display: block; font-family: var(--pixel); font-weight: 400; font-size: 40px; line-height: 1; color: var(--strong); }
.stat small {
  display: block; margin-top: 8px; font-family: var(--mono); font-size: 11px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--muted);
}
.stat.hot { background: var(--red); }
.stat.hot small { color: var(--strong); }

/* the motif, framed like a figure in a test report */
.fig { flex: 1 1 380px; min-width: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.fig-frame {
  position: relative; flex: 1; min-height: 340px; padding: 10px;
  background: var(--panel-2); border: 1px solid var(--line); box-shadow: 0 30px 80px rgba(0,0,0,.5);
}
.fig-inner { position: relative; height: 100%; min-height: 318px; overflow: hidden; background: var(--red); }
.motif { position: absolute; inset: 0; line-height: 0; }
.motif svg { width: 100%; height: 100%; display: block; }
.motif text { font-family: var(--mono); font-weight: 600; font-size: 19px; letter-spacing: .06em; }
.scanlines { position: absolute; inset: 0; background: repeating-linear-gradient(0deg, var(--sunk) 0 1px, transparent 1px 3px); pointer-events: none; }
.scanbar {
  position: absolute; left: 0; right: 0; top: 0; height: 9%; pointer-events: none;
  background: linear-gradient(180deg, transparent, rgba(255,255,255,.16), transparent);
  animation: scan 4.5s linear infinite;
}
@keyframes scan { from { transform: translateY(-10%); } to { transform: translateY(1100%); } }
.corner { position: absolute; width: 18px; height: 18px; border: 0 solid var(--red-text); }
.corner.tl { left: -1px; top: -1px; border-left-width: 3px; border-top-width: 3px; }
.corner.tr { right: -1px; top: -1px; border-right-width: 3px; border-top-width: 3px; }
.corner.bl { left: -1px; bottom: -1px; border-left-width: 3px; border-bottom-width: 3px; }
.corner.br { right: -1px; bottom: -1px; border-right-width: 3px; border-bottom-width: 3px; }
.fig figcaption span:last-child { white-space: nowrap; }
.fig figcaption {
  display: flex; justify-content: space-between; gap: 12px; font-family: var(--mono); font-size: 11px;
  letter-spacing: .14em; text-transform: uppercase; color: var(--dim);
}
.kb-gear { animation-name: spin; animation-timing-function: linear; animation-iteration-count: infinite; transform-box: view-box; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.kb-hammer { animation: swing 3.6s infinite; transform-box: view-box; }
@keyframes swing {
  0%   { transform: rotate(-3deg);  animation-timing-function: ease-in-out; }
  45%  { transform: rotate(-14deg); animation-timing-function: cubic-bezier(.6, 0, 1, 1); }
  56%  { transform: rotate(0deg);   animation-timing-function: ease-out; }
  64%  { transform: rotate(-2deg);  animation-timing-function: ease-in-out; }
  80%, 100% { transform: rotate(-3deg); }
}
.kb-burst { opacity: 0; animation: burst 3.6s infinite; transform-box: view-box; }
@keyframes burst {
  0%, 55.9% { opacity: 0; transform: scale(.6); }
  56%       { opacity: 1; transform: scale(.8); animation-timing-function: ease-out; }
  64%       { opacity: 0; transform: scale(1.5); }
  100%      { opacity: 0; }
}
.kb-spark { opacity: 0; animation: spark 3.6s infinite; }
@keyframes spark {
  0%, 55.9% { opacity: 0; transform: translate(0, 0); }
  56%       { opacity: 1; transform: translate(0, 0); animation-timing-function: cubic-bezier(.1, .7, .3, 1); }
  68%       { opacity: 1; }
  80%       { opacity: 0; transform: translate(var(--dx), calc(var(--dy) + 24px)); }
  100%      { opacity: 0; }
}
.motif.busy .kb-gear { animation-duration: 4s !important; }

/* ---------- workbench: rail · chat · evidence ---------- */
.bench { display: flex; flex-wrap: wrap; gap: 20px; align-items: stretch; padding-bottom: 40px; }
.rail { flex: 1 1 250px; min-width: 0; display: flex; flex-direction: column; gap: 20px; }
.runs { display: flex; flex-direction: column; padding: 6px; max-height: 300px; overflow-y: auto; }
.runs-empty { margin: 0; padding: 10px; font-size: 13.5px; color: var(--dim); }
.run {
  display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; min-height: 44px; text-align: left;
  border: none; background: transparent; color: var(--paper); transition: background .15s;
}
.run:hover { background: var(--wash); }
.run.on { background: var(--hover); box-shadow: inset 3px 0 0 var(--red); }
.run small { font-family: var(--mono); font-size: 11px; letter-spacing: .08em; color: var(--dim); }
.run.on small { color: var(--red-text); }
.run span { font-size: 14px; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tune { display: flex; flex-direction: column; gap: 18px; padding: 16px; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field-label {
  display: flex; justify-content: space-between; font-family: var(--mono); font-size: 11px;
  letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
}
.field-label b { color: var(--strong); font-weight: 600; }
.seg { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.seg button {
  height: 36px; margin: 0 0 -1px -1px; border: 1px solid var(--line-strong); background: var(--field);
  color: var(--soft); font-size: 13px; position: relative; transition: background .15s;
}
.seg button:nth-child(odd) { margin-left: 0; }
.seg button:hover { background: var(--hover); }
.seg button.on { background: var(--red); border-color: var(--red); color: var(--strong); z-index: 1; }
#topk { width: 100%; accent-color: var(--red); margin: 0; }
#model {
  height: 40px; background: var(--field); border: 1px solid var(--line-strong); color: var(--strong);
  padding: 0 10px; font: 13px var(--mono); border-radius: 0;
}

.chat {
  flex: 999 1 520px; min-width: 0; display: flex; flex-direction: column;
  height: min(860px, calc(100vh - 40px)); min-height: 600px;
}
.run-status { font-family: var(--mono); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--dim); }
.run-status.busy { color: var(--red-text); }

/* pipeline rendered as a test run */
.pipeline {
  list-style: none; margin: 0; padding: 0; display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); border-bottom: 1px solid var(--line);
}
.pipeline li { display: flex; align-items: center; gap: 12px; padding: 12px 20px; }
.pipeline li + li { border-left: 1px solid var(--line-soft); }
.chk {
  width: 24px; height: 24px; flex: 0 0 24px; display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--line-strong); background: var(--field); color: var(--strong); transition: background .2s, border-color .2s;
}
.pipeline li.done .chk { background: var(--red); border-color: var(--red); }
.pipeline li.done .chk::after {
  content: ""; width: 12px; height: 6px; border: solid var(--strong); border-width: 0 0 3px 3px;
  transform: translateY(-2px) rotate(-45deg);
}
.pipeline li.active .chk { border-color: var(--red-hi); }
.pipeline li.active .chk::after { content: ""; width: 8px; height: 8px; background: var(--red-hi); animation: blink .8s steps(2) infinite; }
.pipeline li.fail .chk { border-color: var(--red-hi); }
.pipeline li.fail .chk::after { content: "×"; color: var(--red-text); font: 600 16px/1 var(--mono); }
.step { display: flex; flex-direction: column; line-height: 1.3; }
.step b { font-family: var(--mono); font-size: 12px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--strong); }
.step small { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.pipeline li:not(.done):not(.active) .step b { color: var(--muted); }

.messages { flex: 1; overflow-y: auto; padding: 26px 24px; scroll-behavior: smooth; display: flex; flex-direction: column; gap: 22px; }
.empty { text-align: center; padding: 16px 6px 6px; margin: auto 0; }
.mini-mark {
  width: 84px; height: 46px; margin: 0 auto 20px; display: flex; flex-direction: column;
  justify-content: center; align-items: flex-end; padding-right: 6px;
  background: linear-gradient(90deg, #4B4B4D 0 45%, var(--red) 45% 100%);
  box-shadow: 4px 4px 0 rgba(0,0,0,.35);
}
.mini-mark span { font-family: var(--mono); font-size: 10px; line-height: 1.3; color: rgba(255,255,255,.75); }
.empty h4 {
  font-family: var(--pixel); font-size: 26px; letter-spacing: .04em; color: var(--strong);
  margin: 0 0 6px; font-weight: 400; text-transform: uppercase;
}
.empty p { color: var(--muted); margin: 0 0 22px; }
.examples { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); gap: 10px; text-align: left; }
.examples button {
  background: var(--panel); border: 1px solid var(--line); border-top: 3px solid var(--red);
  padding: 12px 14px; color: var(--paper); text-align: left; font-size: 14.5px; line-height: 1.4;
  transition: background .2s, transform .2s;
}
.examples button:hover { background: var(--hover); transform: translateY(-2px); }

.msg { display: flex; gap: 14px; animation: fade .3s ease-out; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble {
  max-width: 78%; background: var(--red); color: var(--strong); padding: 12px 18px;
  box-shadow: 5px 5px 0 rgba(0,0,0,.4); font-size: 16px; white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.bot { align-items: flex-start; }
.msg.bot.on .avatar { box-shadow: 4px 4px 0 rgba(0,0,0,.35), 0 0 0 2px var(--red-text); }
.avatar {
  width: 40px; height: 40px; flex: 0 0 40px; display: flex; flex-direction: column; justify-content: center;
  align-items: flex-end; padding-right: 4px;
  background: linear-gradient(90deg, #4B4B4D 0 45%, var(--red) 45% 100%); box-shadow: 4px 4px 0 rgba(0,0,0,.35);
  font-family: var(--mono); font-size: 8px; line-height: 1.2; color: rgba(255,255,255,.8);
}
.msg.bot .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.msg.bot.error .answer { color: var(--red-text); }

.rewrite { margin: 0; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.rewrite b { color: var(--paper); font-weight: 400; }

.think-head {
  align-self: flex-start; display: inline-flex; align-items: center; gap: 8px; height: 30px; padding: 0 12px;
  background: var(--sunk); border: 1px solid var(--line); color: var(--muted);
  font-family: var(--mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase;
  transition: color .2s, border-color .2s;
}
.think-head:hover { color: var(--strong); border-color: var(--steel); }
.think-head::before { content: "▸"; color: var(--red-text); transition: transform .2s; }
.think { display: flex; flex-direction: column; gap: 8px; }
.think.open .think-head::before { transform: rotate(90deg); }
.think.streaming .think-head { color: var(--red-text); }
.think.streaming .think-head::before { animation: blink .8s steps(2) infinite; }
.think:not(.open) .think-body { display: none; }
.think-body {
  font-family: var(--mono); font-size: 12.5px; line-height: 1.55; color: var(--muted);
  padding: 10px 12px; white-space: pre-wrap; max-height: 220px; overflow-y: auto;
  border: 1px solid var(--line-soft); background: var(--sunk);
}

.answer { font-size: 16px; line-height: 1.65; color: var(--paper); overflow-wrap: anywhere; }
.answer > :first-child { margin-top: 0; }
.answer > :last-child { margin-bottom: 0; }
.answer p { margin: 0 0 10px; }
.answer ul, .answer ol { margin: 0 0 10px; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.answer li::marker { color: var(--red-text); }
.answer strong { color: var(--strong); }
.answer h1, .answer h2, .answer h3, .answer h4 { font-size: 1em; color: var(--strong); margin: .8em 0 .3em; }
.answer pre { background: var(--field); padding: 10px; overflow-x: auto; }
.answer table { border-collapse: collapse; margin: .5em 0; }
.answer td, .answer th { border: 1px solid var(--line); padding: 4px 8px; }
.cursor { display: inline-block; width: 9px; height: 1em; background: var(--red-text); vertical-align: -2px; margin-left: 4px; animation: blink 1s steps(2) infinite; }
.waiting { font-family: var(--mono); font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--red-text); }

.cite {
  display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px;
  padding: 0 5px; margin: 0 1px; vertical-align: 2px; background: var(--red); color: var(--strong);
  font: 600 11px/1 var(--mono); border: none; transition: background .15s, transform .15s;
}
.cite:hover { background: var(--red-hi); transform: translateY(-1px); }

.src-btn {
  align-self: flex-start; display: inline-flex; align-items: center; gap: 8px; height: 30px; padding: 0 12px;
  background: transparent; border: 1px solid var(--line); color: var(--soft);
  font-family: var(--mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase;
}
.src-btn b { color: var(--strong); font-weight: 600; }
.src-btn:hover { border-color: var(--steel); color: var(--strong); }
.msg.bot.on .src-btn { border-color: var(--red); color: var(--strong); }
.src-btn .bars { display: flex; gap: 3px; }
.src-btn .bars i { width: 5px; height: 12px; background: var(--steel); }
.src-btn .bars i.cited { background: var(--red-text); }
.src-btn .chev { display: none; color: var(--red-text); }
.m-new, .tabbar, .next { display: none; }

.meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; padding-top: 10px;
  border-top: 1px solid var(--line-soft); font-family: var(--mono); font-size: 11px; letter-spacing: .06em; color: var(--dim);
}
.meta b { color: var(--muted); font-weight: 400; }
.meta .acts { margin-left: auto; display: flex; gap: 2px; }
.meta .acts button {
  width: 34px; height: 30px; display: inline-flex; align-items: center; justify-content: center; padding: 0;
  background: transparent; border: none; color: var(--muted); transition: color .15s, background .15s;
}
.meta .acts button:hover { color: var(--strong); background: var(--track); }
.meta .acts button.on { color: var(--strong); background: var(--red); }
.meta svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: square; }

.composer {
  display: flex; align-items: flex-end; gap: 8px; margin: 0 20px 20px; padding: 6px 6px 6px 16px;
  background: var(--field); border: 1px solid var(--line); transition: border-color .2s, box-shadow .2s;
}
.composer:focus-within { border-color: var(--red-hi); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer textarea {
  flex: 1; resize: none; border: none; outline: none; background: transparent; color: var(--strong);
  font-size: 16px; line-height: 1.5; padding: 10px 0; min-height: 44px; max-height: 160px;
}
.composer textarea::placeholder { color: var(--dim); }
.composer .hint { align-self: center; font-family: var(--mono); font-size: 11px; letter-spacing: .1em; color: var(--dim); padding: 0 6px; white-space: nowrap; }

/* evidence panel */
.evidence { flex: 1 1 340px; min-width: 0; display: flex; flex-direction: column; max-height: min(860px, calc(100vh - 40px)); }
.evidence .sheet-close { display: none; }
.ev-map {
  position: relative; height: 190px; margin: 14px 16px 6px; flex: 0 0 auto; overflow: hidden;
  background-color: var(--bg);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 19px 19px; border: 1px solid var(--line);
}
.ev-map:empty { display: none; }
.ev-map .d { position: absolute; width: 5px; height: 5px; margin: -2.5px 0 0 -2.5px; border-radius: 50%; background: var(--steel); }
.ev-map .h { position: absolute; width: 9px; height: 9px; margin: -4.5px 0 0 -4.5px; border-radius: 50%; background: var(--red-text); border: 1.5px solid var(--strong); z-index: 2; }
.ev-map .hn { position: absolute; margin: -20px 0 0 6px; font: 600 10px var(--mono); color: var(--strong); z-index: 2; }
.ev-map svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.ev-map line { stroke: var(--red-text); stroke-width: 1.2; stroke-dasharray: 3 3; animation: dash 1s linear infinite; }
@keyframes dash { to { stroke-dashoffset: -8; } }
.ev-map .q { position: absolute; width: 12px; height: 12px; margin: -6px 0 0 -6px; background: var(--red); border: 2px solid var(--strong); transform: rotate(45deg); z-index: 3; }
.ev-map .qr { position: absolute; width: 14px; height: 14px; margin: -7px 0 0 -7px; border: 2px solid var(--red-text); animation: qring 1.8s ease-out infinite; z-index: 3; }
@keyframes qring { from { transform: rotate(45deg) scale(.6); opacity: 1; } to { transform: rotate(45deg) scale(2.6); opacity: 0; } }
.ev-map .cap { position: absolute; left: 8px; bottom: 6px; font-family: var(--mono); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--dim); }
.ev-list { list-style: none; margin: 0; padding: 8px 10px 14px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.ev-empty { margin: 0; padding: 16px; font-size: 13.5px; line-height: 1.55; color: var(--dim); }

/* source rows (evidence panel + map side panel) */
.src { border: 1px solid transparent; transition: border-color .2s, background .2s; }
.src.open, .src.flash { border-color: var(--red-hi); background: var(--accent-soft); }
.src > button {
  width: 100%; display: grid; grid-template-columns: 22px minmax(0, 1fr) 70px; gap: 10px; align-items: center;
  background: transparent; border: none; padding: 8px 6px; text-align: left; color: var(--paper); transition: background .15s;
}
.src > button:hover { background: var(--wash); }
.src .n { font: 600 11px/20px var(--mono); text-align: center; height: 20px; color: var(--strong); background: var(--track); }
.src.open .n { background: var(--red); }
.src .name { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.src .name small { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.src .name span { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src .score { display: flex; align-items: center; gap: 6px; font: 11px var(--mono); color: var(--muted); }
.src .score i { flex: 1; height: 4px; background: var(--track); position: relative; }
.src .score i::after { content: ""; position: absolute; inset: 0 auto 0 0; width: var(--w); background: var(--steel); }
.src.open .score i::after { background: var(--red-text); }
.src .body { display: none; margin: 0; padding: 4px 12px 14px 38px; font-size: 13.5px; line-height: 1.6; color: var(--soft); white-space: pre-line; }
.src.open .body { display: block; }

/* ---------- map ---------- */
.section-head { padding: 40px 0 28px; gap: 24px 40px; }
.section-text { flex: 1 1 520px; min-width: 0; }
.section-head .kicker { margin-bottom: 14px; }
.section-head h2 { font-size: clamp(36px, 4.6vw, 64px); line-height: 1; margin: 0 0 14px; }
.map-search { flex: 0 1 480px; min-width: min(100%, 320px); display: flex; gap: 8px; }
.map-search input, .admin input, .doc-filter {
  flex: 1; min-width: 0; height: 48px; padding: 0 14px; background: var(--field);
  border: 1px solid var(--line-strong); color: var(--strong); font-size: 15px; outline: none;
}
.map-search input:focus, .admin input:focus, .doc-filter:focus { border-color: var(--red-hi); box-shadow: 0 0 0 3px var(--accent-soft); }
.map-search input::placeholder, .doc-filter::placeholder, .admin input::placeholder { color: var(--dim); }
.map-search .ask { height: 48px; padding: 0 22px; min-width: 0; }

.map-wrap { display: flex; flex-wrap: wrap; gap: 20px; padding-bottom: 40px; }
.map-card {
  flex: 999 1 620px; min-width: 0; position: relative; background: var(--panel);
  border: 1px solid var(--line); border-top: 6px solid var(--red); box-shadow: var(--shadow);
}
.map-toolbar {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  font-family: var(--mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
}
.zoom { display: flex; gap: 2px; }
.icon-b {
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; padding: 0;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--soft); transition: color .15s, background .15s;
}
.icon-b:hover { color: var(--strong); background: var(--track); }
.icon-b svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linecap: square; }
.map-stage {
  position: relative; height: 720px; overflow: hidden; touch-action: none; cursor: grab;
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 48px 48px;
}
.map-stage.dragging { cursor: grabbing; }
#map { width: 100%; height: 100%; display: block; --k: 1; }
#map .dot {
  r: calc(4.5px * var(--k)); fill: var(--steel); stroke: var(--panel); stroke-width: 1.5; vector-effect: non-scaling-stroke;
  cursor: pointer; transition: opacity .3s, fill .3s;
}
#map .dot:hover { fill: var(--strong); r: calc(7px * var(--k)); }
#map.focus .dot:not(.hl):not(.hit) { opacity: .22; }
#map .dot.hl { fill: var(--strong); }
#map .dot.sel { stroke: var(--red-text); stroke-width: 3; }
#map .hit-dot { r: calc(7px * var(--k)); fill: var(--red-text); stroke: var(--strong); stroke-width: 2; vector-effect: non-scaling-stroke; pointer-events: none; }
#map .hit-glow { r: calc(11px * var(--k)); fill: rgba(239,97,80,.18); pointer-events: none; }
#map .hit-tag rect { fill: var(--red); }
#map .hit-tag text { font: 600 calc(11px * var(--k)) var(--mono); fill: var(--strong); }
#map .cluster { font: 500 calc(11px * var(--k)) var(--mono); letter-spacing: .1em; text-transform: uppercase; fill: var(--dim); pointer-events: none; transition: opacity .3s, fill .3s; }
#map.focus .cluster:not(.on) { opacity: .3; }
#map .cluster.on { fill: var(--strong); }
#map .cross { stroke: rgba(239,97,80,.18); stroke-width: 1; vector-effect: non-scaling-stroke; }
#map .ray { stroke: var(--red-text); stroke-width: 1.5; stroke-dasharray: 4 4; vector-effect: non-scaling-stroke; animation: dash 1s linear infinite; }
#map .q { fill: var(--red); stroke: var(--strong); stroke-width: 2.5; vector-effect: non-scaling-stroke; }
#map .q-ring { fill: none; stroke: var(--red-text); stroke-width: 2; vector-effect: non-scaling-stroke; animation: mring 1.8s ease-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes mring { from { transform: rotate(45deg) scale(.6); opacity: 1; } to { transform: rotate(45deg) scale(2.8); opacity: 0; } }
#map .q-pill rect { fill: var(--bg); stroke: var(--red); stroke-width: 1; vector-effect: non-scaling-stroke; }
#map .q-pill .shadow { fill: rgba(0,0,0,.45); stroke: none; }
#map .q-pill text { font: 600 calc(13px * var(--k)) var(--mono); fill: var(--strong); }
.tip {
  position: absolute; pointer-events: none; max-width: 260px; padding: 8px 12px; z-index: 5;
  background: var(--bg); border: 1px solid var(--line-strong); box-shadow: 0 10px 30px rgba(0,0,0,.5); font-size: 13.5px; color: var(--strong);
}
.tip small { display: block; font-family: var(--mono); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--red-text); }
.map-hint { position: absolute; left: 16px; bottom: 12px; font-family: var(--mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--dim); pointer-events: none; }

.map-side {
  flex: 1 1 320px; min-width: 0; display: flex; flex-direction: column; align-self: flex-start;
  background: var(--panel); border: 1px solid var(--line); border-top: 6px solid var(--red);
  max-height: 790px; overflow-y: auto;
}
.side-panel { padding: 16px 18px; }
.side-panel + .side-panel { border-top: 1px solid var(--line); }
.side-panel h4 { margin: 0 0 6px; font-family: var(--mono); font-size: 12px; font-weight: 500; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.side-panel h5 { margin: 0 0 10px; font-size: 16px; font-weight: 600; line-height: 1.4; color: var(--strong); }
.side-panel > p { margin: 0; font-size: 13.5px; line-height: 1.6; color: var(--soft); white-space: pre-line; }
#map-detail .src .n { background: var(--red); }
#map-detail .src .score i::after { background: var(--red-text); }
#map-detail .src-list { margin: 0 -8px; }
.side-title { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.side-title h4 { margin: 0; }
.side-title small { font-family: var(--mono); font-size: 11px; color: var(--dim); }
.legend { list-style: none; padding: 0; margin: 0 -8px; }
.legend li {
  display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 36px; padding: 6px 8px;
  cursor: pointer; font-size: 14px; color: var(--soft); transition: background .15s;
}
.legend li span { display: flex; align-items: center; gap: 10px; }
.legend li span::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--steel); }
.legend li small { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.legend li:hover { background: var(--wash); }
.legend li.on { background: var(--hover); box-shadow: inset 3px 0 0 var(--red); color: var(--strong); }
.legend li.on span::before { background: var(--strong); }

/* ---------- documents ---------- */
.mini-stats {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; background: var(--line);
  border: 1px solid var(--line); flex: 0 1 420px; min-width: min(100%, 300px);
}
.mini-stats div { background: var(--bg); padding: 12px 16px; }
.mini-stats b { display: block; font-family: var(--pixel); font-weight: 400; font-size: 30px; line-height: 1; color: var(--strong); }
.mini-stats small { display: block; margin-top: 6px; font-family: var(--mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }

.ingest { display: flex; flex-wrap: wrap; gap: 20px; margin-bottom: 28px; }
.drop {
  flex: 999 1 520px; min-width: 0; min-height: 150px; position: relative; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 26px;
  border: 2px dashed var(--line-strong); background: rgba(0,0,0,.12); cursor: pointer; text-align: center;
  transition: border-color .2s, background .2s;
}
.drop svg { width: 34px; height: 34px; fill: none; stroke: var(--red-text); stroke-width: 2; stroke-linecap: square; }
.drop b { font-family: var(--pixel); font-weight: 400; font-size: 22px; letter-spacing: .06em; text-transform: uppercase; color: var(--strong); }
.drop span { font-size: 14px; color: var(--muted); }
.drop:hover, .drop.over { border-color: var(--red-hi); background: var(--accent-soft); }
.drop:focus-within { border-color: var(--red-hi); }
.drop.busy { pointer-events: none; }
.progress { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: var(--panel-2); overflow: hidden; }
.progress i { position: absolute; inset: 0; width: 30%; background: var(--red-hi); animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(400%); } }

.job {
  flex: 1 1 360px; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 12px;
  padding: 18px 20px; background: var(--panel); border: 1px solid var(--line); border-top: 6px solid var(--red);
}
.job-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.job-state { font-family: var(--mono); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--dim); }
.job.running .job-state, .job.done .job-state { color: var(--red-text); }
.job.failed .job-state { color: var(--red-text); }
.job-meta { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.job-name { font-size: 15px; font-weight: 600; color: var(--strong); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job:not(.running):not(.done):not(.failed) .job-name { color: var(--dim); font-weight: 400; }
.job-bar { height: 10px; background: var(--bg); border: 1px solid var(--line); position: relative; overflow: hidden; }
.job-bar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background-color: var(--red); }
.job.running .job-bar i {
  width: 100%;
  background-image: repeating-linear-gradient(-45deg, rgba(255,255,255,.18) 0 8px, transparent 8px 16px);
  background-size: 22.6px 22.6px; animation: stripes .8s linear infinite;
}
.job.done .job-bar i { width: 100%; }
.job.failed .job-bar i { width: 100%; background: var(--hover); }
@keyframes stripes { to { background-position: 22.6px 0; } }
.job-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; font-family: var(--mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--dim); }
.job-steps li.ok { color: var(--paper); }
.job-steps li.now { color: var(--red-text); }
.admin { display: flex; }
.admin input { height: 40px; font-size: 14px; }

.docs-wrap { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; padding-bottom: 40px; }
.ledger { flex: 999 1 620px; min-width: 0; background: var(--panel); border: 1px solid var(--line); }
.ledger-tools {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.filter {
  display: flex; align-items: center; gap: 8px; flex: 1 1 260px; max-width: 360px; height: 40px; padding: 0 12px;
  background: var(--field); border: 1px solid var(--line-strong); cursor: text;
}
.filter:focus-within { border-color: var(--red-hi); box-shadow: 0 0 0 3px var(--accent-soft); }
.filter svg { width: 15px; height: 15px; flex: 0 0 15px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: square; }
.filter input { flex: 1; min-width: 0; background: transparent; border: none; outline: none; color: var(--strong); font-size: 14px; }
.filter input::placeholder { color: var(--dim); }
.sort { display: flex; align-items: center; gap: 10px; }
.sort > span { font-family: var(--mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.seg-inline { display: flex; }
.seg-inline button {
  height: 36px; padding: 0 14px; margin-left: -1px; border: 1px solid var(--line-strong); background: var(--field);
  color: var(--soft); font-size: 13px; position: relative; transition: background .15s;
}
.seg-inline button:first-child { margin-left: 0; }
.seg-inline button:hover { background: var(--hover); }
.seg-inline button.on { background: var(--red); border-color: var(--red); color: var(--strong); z-index: 1; }
.table-scroll { overflow-x: auto; }
.doc-table { width: 100%; min-width: 560px; border-collapse: collapse; }
.doc-table th {
  padding: 10px 14px; font-family: var(--mono); font-size: 11px; font-weight: 500; letter-spacing: .12em;
  text-transform: uppercase; color: var(--muted); text-align: left; border-bottom: 1px solid var(--line);
}
.doc-table .c-n { width: 44px; }
.doc-table .c-bar { width: 34%; }
.doc-table .c-num { width: 90px; text-align: right; }
.doc-table td { padding: 0 14px; height: 46px; border-bottom: 1px solid var(--line); }
.doc-table tbody tr { cursor: pointer; transition: background .15s; }
.doc-table tbody tr:hover { background: var(--grid); }
.doc-table tr.on { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--red); }
.doc-table tr.new td:nth-child(2) button::after { content: "new"; margin-left: 8px; padding: 1px 6px; background: var(--red); color: var(--strong); font: 600 10px/16px var(--mono); letter-spacing: .1em; text-transform: uppercase; vertical-align: 2px; }
.doc-table .idx { font-family: var(--mono); font-size: 12px; color: var(--dim); }
.doc-table td button {
  background: none; border: none; padding: 0; min-height: 44px; text-align: left; font-size: 15px; font-weight: 600; color: var(--paper);
}
.doc-table tr.on td button { color: var(--strong); }
.bar-cell { display: flex; align-items: center; gap: 10px; }
.bar-cell i { flex: 1; height: 8px; background: var(--bg); position: relative; }
.bar-cell i::after { content: ""; position: absolute; inset: 0 auto 0 0; width: var(--w); background: var(--steel); }
.doc-table tr.on .bar-cell i::after { background: var(--red-text); }
.bar-cell b { width: 22px; text-align: right; font: 400 13px var(--mono); color: var(--strong); }
.doc-table .num { text-align: right; font-family: var(--mono); font-size: 13px; color: var(--soft); }
.doc-table .num.dim { color: var(--muted); }
.doc-table .none td { height: 80px; text-align: center; color: var(--dim); cursor: default; }

.inspector {
  flex: 1 1 360px; min-width: 0; background: var(--panel-2); border: 1px solid var(--line); border-top: 6px solid var(--red);
  box-shadow: var(--shadow); position: sticky; top: 16px; max-height: calc(100vh - 32px); display: flex; flex-direction: column;
}
.insp-head { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.insp-kicker { font-family: var(--mono); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.insp-head h3 { margin: 0; font-family: var(--pixel); font-weight: 400; font-size: 24px; line-height: 1.1; text-transform: uppercase; color: var(--strong); overflow-wrap: anywhere; }
.insp-meta { font-family: var(--mono); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--soft); }
.insp-acts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.insp-acts .ghost { height: 36px; }
.insp-acts .danger { margin-left: auto; color: var(--red-text); }
.insp-acts .danger:hover { color: var(--strong); }
.insp-chunks { list-style: none; margin: 0; padding: 4px 18px 18px; overflow-y: auto; }
.insp-chunks li { padding: 14px 0; border-bottom: 1px solid var(--line-soft); }
.insp-chunks .ch-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.insp-chunks .ch-head span { font-family: var(--mono); font-size: 11px; color: var(--red-text); }
.insp-chunks h4 { margin: 0; font-size: 15px; font-weight: 600; color: var(--strong); }
.insp-chunks p { margin: 0; font-size: 14px; line-height: 1.6; color: var(--soft); white-space: pre-line; }

body > .toast { width: auto; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 70;
  background: var(--bg); border: 1px solid var(--line); border-top: 3px solid var(--red);
  padding: 10px 16px; box-shadow: var(--shadow); font-size: 14px; max-width: calc(100% - 32px);
}

.foot {
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px;
  padding: 26px 2px; font-family: var(--mono); font-size: 11.5px;
  letter-spacing: 0.1em; text-transform: uppercase; color: var(--dim);
}
.foot a:hover { color: var(--strong); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .kb-burst, .kb-spark, .scanbar { display: none; }
}

/* ---------- responsive (mobile pass comes later) ---------- */
@media (max-width: 1100px) {
  .chat, .evidence { height: auto; max-height: none; }
  .chat { min-height: 640px; }
}
@media (max-width: 700px) {
  body { padding: 5px 0 64px; }
  body::after { height: 5px; }
  .bar, .view, .foot { padding-left: 16px; padding-right: 16px; }
  .m-hide { display: none; }

  /* header: logo · online · new chat; navigation moves to the bottom tab bar */
  .bar { flex-wrap: nowrap; justify-content: space-between; gap: 10px; padding-top: 14px; padding-bottom: 12px; }
  .logo { box-shadow: 4px 4px 0 rgba(0,0,0,.45); }
  .logo img { height: 38px; }
  .nav, .chips .chip { display: none; }
  .chips { gap: 6px; font-size: 11px; }
  .live { padding: 6px 10px; letter-spacing: .08em; }
  .m-new {
    display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; padding: 0;
    background: transparent; border: 1px solid var(--line-strong); color: var(--soft);
  }
  .m-new svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linecap: square; }
  .tabbar {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    max-width: none; background: var(--panel); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; height: 64px;
    text-decoration: none; color: var(--muted); font-family: var(--pixel); font-size: 11px; letter-spacing: .06em; text-transform: uppercase;
  }
  .tabbar a.on { color: var(--strong); box-shadow: inset 0 3px 0 var(--red); }
  .tabbar svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: square; }
  .foot { display: none; }

  /* assistant: the chat is the whole screen */
  #view-assistant.view { padding: 0; }
  .hero, .rail { display: none; }
  .bench { display: block; padding: 0; }
  .chat {
    height: calc(100svh - 5px - 71px - 64px); min-height: 420px; margin: 0;
    border: none; box-shadow: none; background: transparent;
  }
  .chat > .card-head { display: none; }
  .pipeline { grid-template-columns: repeat(3, minmax(0, 1fr)); background: var(--panel); }
  .pipeline li { padding: 8px 12px; gap: 0; }
  .pipeline li + li { border-left: 1px solid var(--line); }
  .chk { display: none; }
  .step b { font-size: 11px; letter-spacing: .1em; }
  .pipeline li.done .step b::before { content: "✓ "; color: var(--red-text); }
  .pipeline li.active .step b::before { content: "▸ "; color: var(--red-text); }
  .pipeline li.fail .step b::before { content: "× "; color: var(--red-text); }
  .messages { padding: 18px 16px; gap: 16px; }
  .empty { padding-top: 8px; }
  .empty h4 { font-size: 22px; }
  .examples { grid-template-columns: 1fr; }
  .msg.user .bubble { max-width: 84%; padding: 10px 14px; box-shadow: 4px 4px 0 rgba(0,0,0,.4); font-size: 15px; }
  .avatar { display: none; }
  .msg.bot .body {
    gap: 10px; background: var(--panel-2); border: 1px solid var(--line); border-top: 4px solid var(--red);
    padding: 14px 14px 12px;
  }
  .rewrite { font-size: 11px; }
  .answer { font-size: 15px; line-height: 1.6; }
  .cite { min-width: 18px; height: 18px; font-size: 10px; }
  .src-btn {
    align-self: stretch; justify-content: space-between; min-height: 44px; height: auto; padding: 0 12px;
    background: var(--bg); border-color: var(--line-strong); color: var(--paper);
  }
  .src-btn .bars i { width: 6px; height: 14px; }
  .src-btn .chev { display: inline; }
  .src-btn > span:nth-child(2) { margin-right: auto; margin-left: 8px; }
  .meta { padding-top: 0; border-top: none; gap: 4px 14px; }
  .meta .acts button { width: 40px; height: 40px; }
  .next { display: flex; flex-direction: column; gap: 8px; }
  .next span { font-family: var(--mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--dim); }
  .next button {
    min-height: 44px; padding: 10px 14px; text-align: left; background: var(--panel); border: 1px solid var(--line);
    color: var(--paper); font-size: 14px;
  }
  .composer { margin: 0 12px 10px; padding: 5px 5px 5px 14px; background: var(--panel); border-color: var(--line-strong); align-items: center; }
  .composer .hint { display: none; }
  .composer textarea { font-size: 16px; padding: 10px 0; }
  .composer .ask { width: 52px; min-width: 52px; padding: 0; }
  .composer .ask span { display: none; }
  .composer .ask svg { width: 18px; height: 18px; }
  .composer .ask.stop span { display: inline; font-size: 11px; }
  .composer .ask.stop { width: auto; padding: 0 12px; }

  /* evidence becomes a bottom sheet */
  .evidence { display: none; }
  .evidence.sheet-open {
    display: flex; position: fixed; left: 0; right: 0; bottom: 64px; z-index: 45; max-height: min(70svh, 520px);
    background: var(--panel-2); border: none; border-top: 6px solid var(--red); box-shadow: 0 -20px 60px rgba(0,0,0,.6);
    animation: sheet .25s ease-out;
  }
  @keyframes sheet { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
  .evidence .sheet-close { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; padding: 0; border: none; }
  .evidence .sheet-close svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linecap: square; }
  .evidence .ev-map { display: none; }
  .evidence .ev-list { padding: 4px 10px 14px; }
  .src > button { min-height: 52px; }
  body.sheet-lock .messages { overflow: hidden; }

  /* map + documents */
  .section-head { padding: 24px 0 18px; }
  .map-search { min-width: 100%; }
  .map-stage { height: auto; aspect-ratio: 1000 / 720; min-height: 280px; }
  .map-toolbar { flex-wrap: nowrap; }
  .map-toolbar span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .map-hint { display: none; }
  .map-side { max-height: none; }
  .mini-stats { min-width: 100%; }
  .drop { min-height: 120px; padding: 18px; }
  .inspector { position: static; max-height: none; }
  .ledger-tools { flex-direction: column; align-items: stretch; }
  .filter { max-width: none; }
}

/* =====================================================================
   pen.dev "AT v2" layer — light/dark themes, Teko / Titillium / JetBrains,
   soft radii, full-bleed app shell. Everything above keeps the structure,
   this layer sets the look. Tokens live in :root / [data-theme] at the top.
   ===================================================================== */
html { background: var(--bg); }
body { background-color: var(--bg); background-image: none; padding: 0; font-size: 15.5px; transition: background-color .25s, color .25s; }
body::after { display: none; }
body > * { max-width: none; }
::selection { background: var(--accent-soft); color: var(--strong); }
* { scrollbar-color: var(--line-strong) transparent; }
*::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 8px; }
:focus-visible { outline: 2px solid var(--red-text); outline-offset: 2px; border-radius: 4px; }
code { border-radius: 4px; background: var(--hover); color: var(--strong); }

/* ---- buttons ---- */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; height: 42px; padding: 0 16px;
  background: var(--red); color: var(--on-accent); border: none; border-radius: var(--r-sm);
  font: 700 13px/1 var(--body); letter-spacing: .16em; text-transform: uppercase;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.12), var(--shadow-sm); transition: background .2s, transform .15s;
}
.btn-primary:hover { background: var(--red-hi); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary svg, .icon-b svg, .m-new svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ghost { height: 34px; border-radius: var(--r-sm); border-color: var(--line); font-size: 11px; color: var(--soft); background: var(--panel-2); }
.ghost:hover { border-color: var(--line-strong); color: var(--strong); }
.ghost.danger { color: var(--danger); }
.ghost.danger:hover { background: var(--red); border-color: var(--red); color: var(--on-accent); }
.icon-b {
  width: 38px; height: 38px; display: inline-flex; align-items: center; justify-content: center; padding: 0;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r); color: var(--soft);
  transition: background .2s, color .2s, border-color .2s;
}
.icon-b:hover { color: var(--strong); background: var(--hover); border-color: var(--line-strong); }
.ask {
  height: 40px; min-width: 40px; padding: 0 14px; border-radius: var(--r); box-shadow: none;
  font: 700 13px/1 var(--body); letter-spacing: .14em; color: var(--on-accent);
}
.ask svg { stroke-width: 2.5; stroke-linecap: round; }
.ask:hover { transform: none; box-shadow: none; }
.ask.stop { background: var(--hover); color: var(--strong); border: 1px solid var(--line-strong); }
.link { color: var(--red-text); }
.link:hover { color: var(--strong); }

/* ---- theme toggle ---- */
.theme-toggle .i-moon { display: none; }
:root[data-theme="light"] .theme-toggle .i-sun { display: none; }
:root[data-theme="light"] .theme-toggle .i-moon { display: block; }

/* ---- header ---- */
.bar {
  position: sticky; top: 0; z-index: 30; height: 72px; padding: 0 24px; gap: 0 40px; flex-wrap: nowrap;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.logo { box-shadow: none; border-radius: 4px; overflow: hidden; }
.logo img { height: 40px; }
.nav { gap: 6px; align-self: stretch; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 0 16px; margin-bottom: -1px;
  font: 700 13px/1 var(--body); letter-spacing: .2em; color: var(--muted);
  border-bottom: 2px solid transparent;
}
.nav a::before { content: ""; width: 16px; height: 16px; background: currentColor; opacity: .9;
  -webkit-mask: var(--ico) center / contain no-repeat; mask: var(--ico) center / contain no-repeat; }
.nav a[data-view="assistant"] { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linejoin='round'%3E%3Cpath d='M4 5h16v11H9l-5 4V5z'/%3E%3Cpath d='M8 9h8M8 12h5'/%3E%3C/svg%3E"); }
.nav a[data-view="map"] { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Ccircle cx='6' cy='7' r='2'/%3E%3Ccircle cx='17' cy='6' r='2'/%3E%3Ccircle cx='9' cy='17' r='2'/%3E%3Cpath d='M8 8l1 7M8 7h7'/%3E%3C/svg%3E"); }
.nav a[data-view="documents"] { --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linejoin='round'%3E%3Cpath d='M3 6h7l2 2h9v11H3z'/%3E%3C/svg%3E"); }
.nav a:hover { color: var(--strong); border-bottom-color: transparent; }
.nav a.on { color: var(--strong); border-bottom-color: var(--red); }
.chips { gap: 10px; text-transform: none; letter-spacing: 0; font-family: var(--body); }
.live {
  height: 38px; padding: 0 14px; border-radius: var(--r-pill); background: var(--panel-2); border: 1px solid var(--line);
  font: 600 13px/1 var(--body); letter-spacing: 0; text-transform: none; color: var(--soft);
}
.live::before { width: 8px; height: 8px; border-radius: 50%; }

/* ---- shared panels ---- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); }
.panel-head { border-bottom-color: var(--line); }
.panel-head h2, .panel-head h4, .side-panel h4 { font: 700 11px/1 var(--body); letter-spacing: .24em; color: var(--red-text); }
.card { background: var(--bg); border: 1px solid var(--line); border-top: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: none; }
.card-head h3 { font: 600 30px/1 var(--pixel); letter-spacing: .01em; text-transform: none; color: var(--strong); }
.kicker { font: 700 12px/1.4 var(--body); letter-spacing: .24em; color: var(--red-text); }
.section-head h2 { font: 600 clamp(40px, 4.6vw, 64px)/1 var(--pixel); text-transform: none; letter-spacing: .005em; color: var(--strong); }
.sub { color: var(--soft); }

/* ---- assistant: full-bleed shell on desktop ---- */
@media (min-width: 1101px) {
  #view-assistant.view.on { display: block; }
  .bench {
    display: grid; grid-template-columns: 280px minmax(0, 1fr) 360px; gap: 0; padding: 0;
    height: calc(100vh - 72px); min-height: 640px;
  }
  .rail { padding: 16px; gap: 16px; background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; }
  .chat { height: auto; min-height: 0; border: none; border-radius: 0; background: var(--bg); }
  .evidence { max-height: none; border: none; border-left: 1px solid var(--line); border-radius: 0; }
  .foot { display: none; }
}
.rail > .panel:first-child { background: transparent; border: none; border-radius: 0; flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.rail > .panel:first-child .panel-head { flex-direction: column-reverse; align-items: stretch; gap: 22px; padding: 0 0 4px; border: none; min-height: 0; }
.rail > .panel:first-child .panel-head .btn-primary { width: 100%; height: 44px; }
.runs { padding: 4px 0; max-height: none; gap: 2px; }
.runs-empty { padding: 8px 12px; color: var(--muted); }
.run { border-radius: var(--r-sm); padding: 10px 12px; }
.run:hover { background: var(--wash); }
.run.on { background: var(--panel-2); box-shadow: var(--shadow-sm); }
.run span { color: var(--paper); font-size: 14.5px; }
.run small { font-family: var(--body); letter-spacing: 0; font-size: 12px; color: var(--muted); }
.run.on small { color: var(--muted); }
#settings { background: var(--panel-2); }
#settings .panel-head { min-height: 0; padding: 12px 14px; }
.tune { gap: 14px; padding: 12px 14px 16px; }
.field-label { font: 700 10.5px/1 var(--body); letter-spacing: .18em; color: var(--muted); }
.field-label b { color: var(--strong); }
.seg { gap: 4px; }
.seg button { margin: 0; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--panel); height: 34px; color: var(--soft); }
.seg button.on { background: var(--red); border-color: var(--red); color: var(--on-accent); }
#model { border-radius: var(--r-sm); background: var(--panel); border-color: var(--line); color: var(--paper); }
/* own chevron with breathing room instead of the native arrow glued to the border */
#model {
  -webkit-appearance: none; appearance: none; cursor: pointer; padding: 0 40px 0 12px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a817a' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; background-size: 16px;
  text-overflow: ellipsis;
}
.switch span { font: 700 10.5px/1 var(--body); letter-spacing: .18em; color: var(--muted); }
.switch i { border-radius: var(--r-pill); background: var(--panel); }
.switch i::after { border-radius: 50%; }
.switch input:checked + i { background: var(--red); border-color: var(--red); }
.switch input:checked + i::after { background: var(--on-accent); }

/* chat column */
.chat > .card-head { padding: 18px 32px 14px; border-bottom: 1px solid var(--line); background: var(--bg); }
.run-status { font: 600 12px/1 var(--body); letter-spacing: 0; text-transform: none; color: var(--muted); padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--r-pill); }
.run-status.busy { color: var(--red-text); border-color: var(--red); }
.pipeline { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 32px; border-bottom: 1px solid var(--line); }
.pipeline li { padding: 5px 12px 5px 6px; gap: 8px; border: 1px solid var(--line); border-radius: var(--r-pill); background: var(--panel-2); }
.pipeline li + li { border-left: 1px solid var(--line); }
.chk { width: 18px; height: 18px; flex-basis: 18px; border-radius: 50%; border-color: var(--line-strong); background: transparent; }
.pipeline li.done .chk { background: var(--ok); border-color: var(--ok); }
.pipeline li.done .chk::after { width: 8px; height: 4px; border-color: var(--bg); border-width: 0 0 2px 2px; }
.pipeline li.active .chk::after { border-radius: 50%; }
.step { flex-direction: row; align-items: baseline; gap: 8px; }
.step b { font: 600 12.5px/1 var(--body); letter-spacing: .02em; text-transform: none; color: var(--paper); }
.step small { font: 12px/1 var(--mono); color: var(--muted); }
.messages { padding: 24px max(32px, calc((100% - 760px) / 2)); gap: 26px; }

/* empty state */
.empty { max-width: 640px; margin: auto; }
.empty .eyebrow { margin: 18px 0 8px; font: 700 11px/1 var(--body); letter-spacing: .24em; text-transform: uppercase; color: var(--red-text); }
.empty h4 { font: 600 44px/1 var(--pixel); text-transform: none; letter-spacing: .005em; color: var(--strong); margin: 0 0 10px; }
.empty p { color: var(--soft); font-size: 16px; }
.examples { gap: 10px; }
.examples button {
  border: 1px solid var(--line); border-top: 1px solid var(--line); border-radius: var(--r); background: var(--panel-2);
  padding: 14px 16px; color: var(--paper); box-shadow: var(--shadow-sm);
}
.examples button:hover { border-color: var(--red); background: var(--accent-wash); transform: translateY(-2px); }

/* brand rhomb (hammer motif in a diamond) */
.rhomb { position: relative; display: inline-grid; place-items: center; flex: 0 0 auto; }
.rhomb .shape { display: block; overflow: hidden; transform: rotate(45deg); border-radius: 6px; border: 2px solid var(--red); background: var(--red); box-shadow: var(--shadow-sm); }
.rhomb .shape img { display: block; width: 141%; height: 141%; margin: -20.5%; object-fit: cover; transform: rotate(-45deg); }
.rhomb.sm { width: 34px; height: 34px; }
.rhomb.sm .shape { width: 24px; height: 24px; border-radius: 4px; }
.rhomb.lg { width: 96px; height: 96px; margin: 0 auto; }
.rhomb.lg .shape { width: 66px; height: 66px; }
.rhomb .halo { position: absolute; inset: -6px; border-radius: 50%; background: radial-gradient(closest-side, var(--accent-soft), transparent); animation: halo 3s ease-in-out infinite; }
@keyframes halo { 50% { transform: scale(1.12); opacity: .6; } }

/* messages */
.msg.user .bubble {
  background: var(--panel-2); color: var(--strong); border: 1px solid var(--line); border-radius: 14px 14px 4px 14px;
  box-shadow: var(--shadow-sm); padding: 11px 16px; font-size: 15.5px;
}
.msg.bot { gap: 12px; }
.msg.bot.on .rhomb .shape { box-shadow: 0 0 0 3px var(--accent-soft); }
.answer { font-size: 16.5px; line-height: 1.7; color: var(--paper); }
.answer strong { color: var(--blue); font-weight: 600; }
.answer h1, .answer h2, .answer h3, .answer h4 { color: var(--strong); font-family: var(--body); }
.answer li::marker { color: var(--red-text); }
.answer ul, .answer ol { gap: 8px; }
.answer pre { border-radius: var(--r-sm); }
.cite {
  min-width: 20px; height: 20px; padding: 0 5px; border-radius: 4px; vertical-align: 1px;
  background: var(--accent-soft); color: var(--red-text); border: 1px solid color-mix(in srgb, var(--red) 45%, transparent);
  font: 600 11px/1 var(--mono);
}
.cite:hover { background: var(--red); color: var(--on-accent); transform: none; }
.rewrite { font: 13px/1.4 var(--body); color: var(--muted); }
.rewrite b { color: var(--soft); font-weight: 600; }
.think-head { border-radius: var(--r-pill); background: var(--panel-2); border-color: var(--line); font: 600 12px/1 var(--body); letter-spacing: 0; text-transform: none; }
.think-body { border-radius: var(--r); background: var(--panel); border-color: var(--line); }
.src-btn { height: 32px; border-radius: var(--r-pill); background: var(--panel-2); font: 600 12px/1 var(--body); letter-spacing: 0; text-transform: none; }
.src-btn .bars i { border-radius: 2px; background: var(--line-strong); }
.msg.bot.on .src-btn { border-color: var(--red); color: var(--strong); }
.meta { border-top: none; padding-top: 2px; font: 12px/1 var(--body); letter-spacing: 0; color: var(--muted); }
.meta .acts { margin-left: 0; order: -1; }
.meta .acts button { border-radius: var(--r-sm); color: var(--muted); }
.meta .acts button:hover { background: var(--hover); color: var(--strong); }
.meta .acts button.on { background: var(--accent-soft); color: var(--red-text); }
.meta svg { stroke-linecap: round; stroke-linejoin: round; }
.next { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.next > span { width: 100%; font: 700 11px/1 var(--body); letter-spacing: .24em; text-transform: uppercase; color: var(--red-text); margin-bottom: 4px; }
.next button {
  min-height: 38px; padding: 8px 16px; border-radius: var(--r-pill); background: var(--panel-2); border: 1px solid var(--line);
  color: var(--paper); font: 600 14px/1.2 var(--body); transition: border-color .2s, background .2s;
}
.next button::after { content: " ↗"; color: var(--muted); }
.next button:hover { border-color: var(--red); background: var(--accent-wash); }
.waiting { font: 600 13px/1 var(--body); letter-spacing: 0; text-transform: none; color: var(--red-text); }

/* composer */
.composer {
  margin: 0 max(32px, calc((100% - 760px) / 2)) 24px; padding: 8px 8px 8px 18px; align-items: center;
  background: var(--panel-2); border: 1px solid var(--line-strong); border-radius: var(--r-lg); box-shadow: var(--shadow);
}
.composer:focus-within { border-color: var(--red); box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow); }
.composer textarea { color: var(--strong); }
.composer textarea::placeholder { color: var(--muted); }
.composer .hint { font: 600 12px/1 var(--body); letter-spacing: 0; color: var(--muted); }

/* sources panel */
.evidence { background: var(--panel); }
.evidence .panel-head { padding: 18px 20px 12px; min-height: 0; }
.evidence .panel-head h2 { font: 600 30px/1 var(--pixel); letter-spacing: .01em; text-transform: none; color: var(--strong); }
.ev-map { margin: 12px 16px 4px; border-radius: var(--r); border-color: var(--line); background-color: var(--bg); background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px); }
.ev-map .h, .ev-map .q { border-color: var(--panel-2); }
.ev-list { padding: 10px 14px 18px; gap: 10px; }
.ev-empty { color: var(--muted); }
.src { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-sm); overflow: hidden; }
.src.open, .src.flash { border-color: var(--red); background: var(--accent-wash); }
.src > button { padding: 12px 12px; grid-template-columns: 24px minmax(0, 1fr) 64px; }
.src > button:hover { background: var(--wash); }
.src .n { border-radius: 5px; background: var(--accent-soft); color: var(--red-text); height: 22px; line-height: 22px; }
.src.open .n { background: var(--red); color: var(--on-accent); }
.src .name span { color: var(--blue); font-weight: 600; font-size: 15px; }
.src .name small { font-family: var(--mono); color: var(--muted); }
.src .score { color: var(--soft); }
.src .score i { height: 4px; background: repeating-linear-gradient(90deg, var(--track) 0 9px, transparent 9px 12px); }
.src .score i::after { background: repeating-linear-gradient(90deg, var(--red-text) 0 9px, transparent 9px 12px); }
.src .body { color: var(--soft); padding: 0 14px 14px 46px; }

/* ---- map + documents ---- */
#view-map, #view-documents { padding: 0 32px; max-width: 1440px; margin: 0 auto; }
.map-card, .map-side, .ledger, .inspector, .job, .mini-stats, .tip { border-radius: var(--r-lg); overflow: hidden; }
.map-card, .inspector, .job { border-top-width: 1px !important; border-top-color: var(--line) !important; }
.map-card { background: var(--panel); }
.map-search input, .admin input, .doc-filter, .filter { border-radius: var(--r); background: var(--panel-2); border-color: var(--line); color: var(--strong); }
.map-search .ask { height: 48px; }
#map .dot { fill: var(--steel); stroke: var(--panel); }
#map .hit-dot, #map .q { stroke: var(--panel); }
#map .hit-tag text, #map .q-pill text { fill: var(--on-accent); }
#map .q-pill rect { fill: var(--red); stroke: none; }
#map .cluster.on, #map .dot.hl, #map .dot:hover { fill: var(--strong); }
.legend li { border-radius: var(--r-sm); }
.legend li.on { box-shadow: none; background: var(--panel-2); color: var(--strong); }
.legend li.on span::before { background: var(--red); }
.mini-stats b, .drop b { font-family: var(--pixel); font-weight: 600; text-transform: none; letter-spacing: .01em; }
.mini-stats b { font-size: 36px; }
.drop { border-radius: var(--r-lg); border-color: var(--line-strong); background: var(--panel); }
.drop b { font-size: 26px; }
.job-bar, .job-bar i { border-radius: var(--r-pill); }
.seg-inline button { border-radius: 0; }
.seg-inline button:first-child { border-radius: var(--r-sm) 0 0 var(--r-sm); }
.seg-inline button:last-child { border-radius: 0 var(--r-sm) var(--r-sm) 0; }
.seg-inline button.on, .doc-table tr.new td:nth-child(2) button::after { color: var(--on-accent); }
.doc-table tr.on { box-shadow: inset 3px 0 0 var(--red); background: var(--accent-wash); }
.insp-head h3 { font-family: var(--pixel); font-weight: 600; font-size: 32px; text-transform: none; color: var(--strong); }

/* white text that sits on an accent fill stays white in both themes */
.seg button.on, .ask, .btn-primary, .pipeline li.done .chk, #map .hit-tag text { color: var(--on-accent); }

/* ---- mobile: same look + Liquid Glass tab bar ---- */
@media (max-width: 700px) {
  .bar { height: 64px; padding: 0 16px; }
  .logo img { height: 34px; }
  .m-new { border-radius: var(--r); background: var(--red); border-color: var(--red); color: var(--on-accent); }
  .theme-toggle { width: 44px; height: 44px; }
  #view-map, #view-documents { padding: 0 16px; }
  .chat { height: calc(100svh - 64px); background: var(--bg); }
  .pipeline { padding: 8px 12px; background: var(--panel); }
  .messages { padding: 16px 16px 180px; }
  .msg.user .bubble { box-shadow: var(--shadow-sm); }
  .msg.bot .body { background: var(--panel-2); border: 1px solid var(--line); border-top: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); }
  .next button { min-height: 44px; }
  .composer {
    position: fixed; left: 12px; right: 12px; bottom: 92px; z-index: 41; margin: 0;
    background: color-mix(in srgb, var(--panel-2) 72%, transparent);
    -webkit-backdrop-filter: blur(18px) saturate(170%); backdrop-filter: blur(18px) saturate(170%);
  }
  .composer .ask { width: 44px; min-width: 44px; height: 44px; }
  .tabbar {
    left: 14px; right: 14px; bottom: calc(14px + env(safe-area-inset-bottom)); height: 66px; padding: 6px; gap: 4px;
    border-radius: 33px; border: 1px solid rgba(255,255,255,.16);
    background-color: color-mix(in srgb, var(--panel) 45%, transparent);
    background-image: linear-gradient(180deg, rgba(255,255,255,.16), rgba(255,255,255,.04) 46%, rgba(0,0,0,.08));
    -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%);
    box-shadow: inset 0 1px 0 rgba(255,255,255,.38), inset 0 -1px 1px rgba(0,0,0,.25), 0 14px 34px rgba(0,0,0,.4);
  }
  .tabbar a {
    height: auto; border-radius: 27px; color: var(--soft); font: 700 10.5px/1 var(--body); letter-spacing: .1em;
    transition: background .25s, color .25s, transform .2s;
  }
  .tabbar a:active { transform: scale(.93); }
  .tabbar a.on {
    box-shadow: inset 0 1px 0 rgba(255,255,255,.5), inset 0 -2px 5px rgba(0,0,0,.2), 0 4px 16px color-mix(in srgb, var(--red) 50%, transparent);
    background: linear-gradient(180deg, color-mix(in srgb, var(--red-hi) 88%, transparent), color-mix(in srgb, var(--red) 75%, transparent));
    color: var(--on-accent);
  }
  .tabbar svg { stroke-linecap: round; stroke-linejoin: round; }
  .evidence.sheet-open { bottom: 0; z-index: 50; border-top: none; border-radius: 18px 18px 0 0; background: var(--panel); padding-bottom: env(safe-area-inset-bottom); }
}
@media (max-width: 700px) {
  .msg.bot > .rhomb { display: none; }
  /* three equal steps that always fit the screen: label on top, timing below */
  .pipeline { flex-wrap: nowrap; gap: 6px; overflow: hidden; }
  .pipeline li { flex: 1 1 0; min-width: 0; padding: 6px 10px; border-radius: 12px; }
  .pipeline .step { flex-direction: column; align-items: flex-start; gap: 3px; min-width: 0; width: 100%; }
  .pipeline .step b { font-size: 12px; white-space: nowrap; }
  .pipeline .step small { font-size: 10.5px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  /* body > * gives every top-level element width:100%, which overrode left/right and pushed the tab bar off-centre */
  .tabbar { width: auto; max-width: none; margin: 0; left: 12px; right: 12px; }
  /* solid backdrop behind the composer + tab bar so messages don't show through the gaps */
  #view-assistant.on .chat::after {
    content: ""; position: fixed; left: 0; right: 0; bottom: 0; z-index: 39; pointer-events: none;
    height: calc(180px + env(safe-area-inset-bottom));
    background: linear-gradient(180deg, transparent, var(--bg) 34px);
  }
  .composer { bottom: calc(92px + env(safe-area-inset-bottom)); }
  /* the chat screen never scrolls as a page: only the message list scrolls, so the header stays put */
  html:has(#view-assistant.on), body:has(#view-assistant.on) { height: 100%; overflow: hidden; overscroll-behavior: none; }
  /* pin header + chat to the screen: even if iOS scrolls the page for the keyboard, nothing shifts */
  body:has(#view-assistant.on) .bar { position: fixed; top: 0; left: 0; right: 0; z-index: 42; width: auto; }
  #view-assistant.on .chat { position: fixed; top: 64px; left: 0; right: 0; bottom: 0; height: auto; min-height: 0; }
  /* last answer's buttons scroll clear of the composer + tab bar */
  .messages { padding-bottom: calc(200px + env(safe-area-inset-bottom)); }
  .messages { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
}
@media (prefers-reduced-motion: reduce) { .rhomb .halo { animation: none; } }


/* ---- four features: not-in-KB, cited vs unused sources, chat search, collapsible answer style ---- */
.noanswer {
  display: flex; flex-direction: column; gap: 10px; padding: 16px 18px; border-radius: var(--r);
  background: var(--panel-2); border: 1px dashed var(--line-strong);
}
.noanswer h4 { margin: 0; font: 600 18px/1.3 var(--body); color: var(--strong); }
.noanswer p { margin: 0; font-size: 15px; color: var(--soft); }
.noanswer-acts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 2px; }
.noanswer-acts button, .noanswer-acts a {
  display: inline-flex; align-items: center; min-height: 38px; padding: 0 14px; border-radius: var(--r-pill);
  background: var(--panel); border: 1px solid var(--line); color: var(--paper); font: 600 14px/1 var(--body);
  text-decoration: none; transition: border-color .2s, background .2s;
}
.noanswer-acts button:hover, .noanswer-acts a:hover { border-color: var(--red); background: var(--accent-wash); color: var(--strong); }

.ev-sep {
  display: flex; align-items: center; gap: 10px; margin: 8px 2px 0;
  font: 700 10.5px/1 var(--body); letter-spacing: .22em; text-transform: uppercase; color: var(--red-text);
}
.ev-sep::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.src.unused { box-shadow: none; background: transparent; }
.src.unused:not(.open) > button { opacity: .62; }
.src.unused .n { background: var(--track); color: var(--muted); }
.src.unused .name span { color: var(--soft); }
.src.unused .score i::after { background: repeating-linear-gradient(90deg, var(--line-strong) 0 9px, transparent 9px 12px); }

.chat-search {
  display: flex; align-items: center; gap: 8px; height: 42px; margin: 4px 0 6px; padding: 0 12px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r);
  transition: border-color .2s, box-shadow .2s;
}
.chat-search:focus-within { border-color: var(--red); box-shadow: 0 0 0 3px var(--accent-soft); }
.chat-search svg { width: 16px; height: 16px; flex: 0 0 16px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.chat-search input { flex: 1; min-width: 0; border: none; outline: none; background: transparent; color: var(--strong); font-size: 14.5px; }
.chat-search input::placeholder { color: var(--muted); }
.chat-search input::-webkit-search-cancel-button { filter: grayscale(1); }

#settings { overflow: hidden; }
.style-toggle {
  width: 100%; display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 60px;
  background: transparent; border: none; text-align: left; color: var(--paper); transition: background .15s;
}
.style-toggle:hover { background: var(--wash); }
.style-ico { width: 32px; height: 32px; flex: 0 0 32px; display: grid; place-items: center; border-radius: var(--r-sm); background: var(--hover); color: var(--soft); }
.style-ico svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.style-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; line-height: 1.25; }
.style-txt b { font: 600 15px/1.2 var(--body); color: var(--strong); }
.style-txt small { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.style-chev { width: 16px; height: 16px; flex: 0 0 16px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform .2s; }
#settings.open .style-chev { transform: rotate(90deg); }
#settings.open .style-toggle { border-bottom: 1px solid var(--line); }
#settings .tune:not([hidden]) { animation: fade .2s ease-out; }

/* ---- model picker: chip in the composer + pop-up menu ---- */
@media (min-width: 701px) { .composer { position: relative; } }   /* on mobile it stays position: fixed */
.composer textarea { min-width: 0; }
.model-pick { position: static; display: flex; align-self: center; }   /* menus anchor to the composer */
.model-chip {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 10px 0 9px; max-width: 190px;
  border: 1px solid var(--line); border-radius: var(--r-pill); background: transparent; color: var(--paper);
  font: 600 12.5px/1 var(--body); cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, color .15s;
}
.model-chip:hover, .model-pick.open .model-chip { background: var(--wash); border-color: var(--line-strong); color: var(--strong); }
.model-chip:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
.model-chip span { overflow: hidden; text-overflow: ellipsis; }
.model-chip svg { flex: none; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.model-chip .mc-ic { width: 13px; height: 13px; color: var(--red); fill: var(--red); stroke: none; }
.model-chip .mc-chev { width: 14px; height: 14px; color: var(--muted); transition: transform .2s; }
.model-pick.open .mc-chev { transform: rotate(180deg); }

.model-menu {
  position: absolute; left: 0; bottom: calc(100% + 8px); z-index: 60; width: 320px;
  padding: 6px; background: var(--panel-2); border: 1px solid var(--line-strong); border-radius: var(--r-lg);
  box-shadow: var(--shadow), 0 18px 40px rgba(0,0,0,.18); animation: mm-in .16s ease-out; transform-origin: bottom left;
}
.model-menu[hidden] { display: none; }
@keyframes mm-in { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }
.mm-head { margin: 0; padding: 8px 10px 6px; font: 700 11px/1 var(--body); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.mm-item {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px; border: none; border-radius: var(--r);
  background: transparent; color: var(--paper); text-align: left; cursor: pointer;
}
.mm-item:hover, .mm-item:focus-visible { background: var(--wash); outline: none; }
.mm-item.on { background: var(--accent-wash); }
.mm-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1; }
.mm-text b { display: flex; align-items: center; gap: 8px; font: 600 14px/1.2 var(--mono); color: var(--strong); }
.mm-text small { font-size: 12.5px; color: var(--muted); }
.mm-tag { font: 600 10.5px/1 var(--body); font-style: normal; letter-spacing: .04em; padding: 3px 7px; border-radius: var(--r-pill); border: 1px solid var(--line); color: var(--muted); }
.mm-check { flex: none; width: 18px; height: 18px; fill: none; stroke: var(--red); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; visibility: hidden; }
.mm-item.on .mm-check { visibility: visible; }
.mm-foot { margin: 4px 0 0; padding: 8px 10px 6px; border-top: 1px solid var(--line); font-size: 12px; line-height: 1.45; color: var(--muted); }

@media (max-width: 700px) {
  .model-chip { height: 36px; max-width: 128px; padding: 0 8px; }
  .model-chip .mc-ic { display: none; }
  .model-pick { position: static; }
  .model-menu { left: 0; right: 0; bottom: calc(100% + 10px); width: auto; }
}

/* composer in two rows, like ChatGPT / Claude: text on top, chips + Ask below */
.composer { flex-wrap: wrap; align-items: center; row-gap: 4px; column-gap: 6px; padding: 10px 10px 10px 18px; }
.composer textarea { flex: 1 1 100%; order: 0; padding: 6px 0; min-height: 36px; }
.composer .model-pick { order: 1; }
.composer .hint { order: 2; margin-left: auto; }
.composer .ask { order: 3; }
.model-chip .sc-ic { width: 15px; height: 15px; color: var(--muted); }
.style-menu { width: 300px; }
@media (max-width: 700px) {
  .composer { padding: 8px 8px 8px 14px; }
  .composer textarea { padding: 6px 0; }
  .composer .ask { margin-left: auto; }
  .model-chip { max-width: 150px; }
  .style-menu { width: auto; }
  .messages { padding-bottom: calc(240px + env(safe-area-inset-bottom)); }
  #view-assistant.on .chat::after { height: calc(230px + env(safe-area-inset-bottom)); }
}

/* answer style menu: same list language as the model menu */
.tone-list { display: flex; flex-direction: column; gap: 2px; }
.mm-text b.t { font: 600 14px/1.2 var(--body); letter-spacing: 0; color: var(--strong); }
.mm-item { padding: 9px 10px; }
.mm-sep { height: 1px; margin: 6px 4px; background: var(--line); }
.mm-row { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: var(--r); }
.mm-switch { cursor: pointer; }
.mm-switch:hover { background: var(--wash); }
.stepper { display: flex; align-items: center; gap: 2px; padding: 2px; border: 1px solid var(--line); border-radius: var(--r-pill); background: var(--panel); }
.stepper b { min-width: 22px; text-align: center; font: 600 14px/1 var(--mono); color: var(--strong); }
.stepper button { display: grid; place-items: center; width: 28px; height: 28px; border: none; border-radius: 50%; background: transparent; color: var(--paper); cursor: pointer; }
.stepper button:hover:not(:disabled) { background: var(--wash); }
.stepper button:disabled { opacity: .35; cursor: default; }
.stepper svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.mm-switch input { position: absolute; opacity: 0; pointer-events: none; }
.mm-switch i { flex: 0 0 36px; width: 36px; height: 20px; border-radius: var(--r-pill); background: var(--line-strong); position: relative; transition: background .2s; }
.mm-switch i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .2s; }
.mm-switch input:checked + i { background: var(--red); }
.mm-switch input:checked + i::after { transform: translateX(16px); }
.mm-switch input:focus-visible + i { outline: 2px solid var(--red); outline-offset: 2px; }
@media (max-width: 700px) {
  .tone-list { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 0 4px; }
  .tone-list .mm-item { padding: 10px 12px; border: 1px solid var(--line); }
  .tone-list .mm-item.on { border-color: var(--red); }
  .tone-list small, .tone-list .mm-check { display: none; }
  .model-menu { max-height: calc(100svh - 64px - 260px); overflow-y: auto; }
}
