:root {
  --bg: #0f1216; --panel: #171b21; --line: #262c35; --fg: #e6e9ee; --muted: #8b97a8;
  --accent: #4da3ff; --ok: #46c07a; --bad: #e5604d; --hot: #e5a33d;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 15px; margin: 0 0 10px; }
h3 { font-size: 13px; margin: 14px 0 6px; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

nav { display: flex; align-items: center; gap: 14px; padding: 0 18px; height: 48px;
  background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
nav .brand { font-weight: 700; letter-spacing: .12em; }
nav a { color: var(--muted); padding: 4px 0; border-bottom: 2px solid transparent; }
nav a:hover { color: var(--fg); }
nav a.on { color: var(--fg); border-bottom-color: var(--accent); }
nav a.sub { font-size: 12px; margin-left: -10px; }
nav .spacer { flex: 1; }

main { max-width: 760px; margin: 0 auto; padding: 24px 18px 60px; }
main.wide { max-width: 1180px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 16px; margin-bottom: 16px; }
.card.narrow, .login { max-width: 380px; margin: 8vh auto 0; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }

label { display: block; margin: 12px 0; font-size: 13px; color: var(--muted); }
input, textarea, button { font: inherit; }
input, textarea { width: 100%; margin-top: 4px; padding: 8px 10px; border-radius: 7px;
  border: 1px solid var(--line); background: #0c0f13; color: var(--fg); }
input:focus, textarea:focus { outline: 1px solid var(--accent); }
button { margin-top: 10px; padding: 8px 16px; border: 0; border-radius: 7px;
  background: var(--accent); color: #04101f; font-weight: 600; cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }
button.danger { background: var(--bad); color: #200; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row input { width: auto; flex: 0 1 200px; margin: 0; }
.row button { margin: 0; }
.chk { display: flex; align-items: center; gap: 5px; margin: 0; white-space: nowrap; }
.chk input { width: auto; margin: 0; }
.uname { min-width: 110px; }

.flash { background: #2a2118; border: 1px solid #4b3a22; color: #f0d9a8;
  padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.warn { background: #2a1a18; border: 1px solid #5a2f28; color: #f2bdb2;
  padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }

/* chat */
.chatgrid { display: grid; grid-template-columns: 220px 1fr; gap: 18px; align-items: start; }
.threads { display: flex; flex-direction: column; gap: 4px; }
.threads .newbtn { padding: 8px 10px; border: 1px dashed var(--line); border-radius: 8px;
  text-align: center; margin-bottom: 6px; }
.threads .thread { display: flex; align-items: center; gap: 4px; padding: 0 4px 0 10px;
  border-radius: 7px; font-size: 13px; }
.threads .thread a { flex: 1; min-width: 0; padding: 7px 0; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.threads .thread:hover { background: var(--panel); }
.threads .thread.on { background: var(--panel); }
.threads .thread.on a { color: var(--fg); }
/* faint rather than hover-hidden: a touch screen has no hover to reveal them with */
.threadops { display: flex; gap: 2px; opacity: .35; }
.threads .thread:hover .threadops, .threadops:focus-within { opacity: 1; }
.threadops button { background: none; border: 0; color: var(--muted); cursor: pointer;
  padding: 3px 5px; border-radius: 5px; font-size: 12px; line-height: 1; }
.threadops button:hover { background: var(--bg); color: var(--fg); }
.chat h1 { display: flex; align-items: baseline; gap: 12px; }
.kblink { font-size: 12px; font-weight: 400; }
#log { height: calc(100vh - 260px); min-height: 300px; overflow-y: auto; padding-right: 6px; }
.msg { margin-bottom: 14px; }
.msg .bubble { white-space: pre-wrap; padding: 10px 14px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line); }
.msg.user .bubble { background: #18304a; border-color: #24486e; margin-left: 15%; }
.bubble.pending { color: var(--muted); font-style: italic; }
.bubble.err { border-color: var(--bad); color: #f2bdb2; }
#composer { display: flex; gap: 10px; align-items: flex-end; margin-top: 12px; }
#composer textarea { margin: 0; resize: vertical; }
#composer button { margin: 0; }

.think { margin-bottom: 6px; font-size: 12px; }
.think summary { cursor: pointer; color: var(--muted); font-style: italic; }
.thinkbody { white-space: pre-wrap; color: var(--muted); border-left: 2px solid var(--line);
             padding: 6px 0 6px 10px; margin-top: 4px; max-height: 320px; overflow-y: auto; }

.sources { margin-top: 6px; font-size: 12px; }
.sources summary { cursor: pointer; color: var(--muted); }
.src { padding: 6px 0; border-bottom: 1px solid var(--line); }
.src:last-child { border-bottom: 0; }
.score { color: var(--ok); font-variant-numeric: tabular-nums; }

/* kb */
.pipeline { display: flex; align-items: stretch; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.pipeline .stage { flex: 1 1 160px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.pipeline .stage b { font-size: 13px; }
.pipeline .stat { margin-top: 4px; color: var(--accent); font-variant-numeric: tabular-nums; }
.pipeline .arrow { align-self: center; color: var(--muted); }
#pres { margin-top: 12px; }
#probe { display: flex; gap: 10px; }
#probe input { margin: 0; }
#probe button { margin: 0; }
table.kv { width: 100%; font-size: 13px; border-collapse: collapse; }
table.kv td { padding: 4px 0; border-bottom: 1px solid var(--line); }
table.kv td:first-child { color: var(--muted); width: 40%; }

/* bars + rows */
.bar { display: grid; grid-template-columns: 96px 1fr 90px; align-items: center; gap: 8px;
  font-size: 12px; margin: 3px 0; }
.bar span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar i { height: 8px; background: var(--accent); border-radius: 4px; display: block; min-width: 2px; }
.bar i.hot { background: var(--hot); }
.bar b { text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }
.kvrow { display: flex; justify-content: space-between; font-size: 13px; padding: 3px 0;
  border-bottom: 1px solid var(--line); gap: 10px; }
.kvrow b.ok { color: var(--ok); } .kvrow b.bad { color: var(--bad); }

/* dense cells — 56 CPUs and 30 thermal sensors, one small box each instead of one
   labelled row each. The number is in the box; the fill repeats it for scanning, and
   `title` holds the long name. Translucent fill on purpose: a solid accent behind
   10px text is unreadable, and rgba works in both themes without a second rule. */
/* grid, not flex-wrap: auto-fill keeps every cell the same width and stops the last
   row stretching its two survivors across the whole card. */
.cellgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(30px, 1fr));
  gap: 3px; margin-top: 7px; }
.cellgrid.wide { grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); }
.cell { --fill: rgba(77, 163, 255, .38); padding: 0 4px;
  font-size: 10px; font-style: normal; line-height: 17px; text-align: center;
  font-variant-numeric: tabular-nums; border-radius: 3px; cursor: default;
  background: linear-gradient(to right, var(--fill) var(--p), var(--line) var(--p)); }
.cell.hot { --fill: rgba(229, 163, 61, .6); font-weight: 700; }

/* /system only: seven live cards on one screen. The chat and KB pages keep the roomier
   spacing — this is a dashboard you scan, not prose you read. */
/* columns, not a grid: the cards are wildly different heights (Power is 5 rows, GPUs is
   two cards of four), and a grid row is as tall as its tallest cell — which left a band of
   dead space under the short ones. Column flow packs them. Reading order goes down each
   column instead of across; on a dashboard you scan, that costs nothing. */
.sys .cols { display: block; columns: 270px; column-gap: 16px; }
.sys .card { padding: 12px 13px; margin-bottom: 16px; break-inside: avoid; }
/* the used/total strings ("381.8 GB / 875.4 GB") wrapped and squeezed the bar to a dot */
.sys .bar { grid-template-columns: 74px 1fr 112px; }
.sys .bar b { white-space: nowrap; }
.sys h1 { margin-bottom: 12px; }
.sys h2 { margin-bottom: 4px; }
.sys h3 { margin: 11px 0 3px; }
.sys .bar { margin: 2px 0; }
.sys .kvrow { padding: 2px 0; }

/* phone view. One media block, no separate template and no JS: the pages are already
   flex/grid, so the phone layout is the same markup with the columns collapsed. */
@media (max-width: 720px) {
  nav { height: auto; min-height: 48px; padding: 6px 12px; gap: 12px; row-gap: 2px; }
  nav .spacer { flex-basis: 100%; }          /* account/sign-out drop to their own row */
  main, main.wide { padding: 14px 12px 32px; }
  h1 { font-size: 18px; }
  /* auto-fit keeps a 320px track on a 360px screen once padding is off, which scrolls
     the whole page sideways. One column below 720px, always. */
  .cols { grid-template-columns: 1fr; }
  .sys .cols { columns: 1; }
  .card { padding: 13px; }
  /* 16px is the threshold under which iOS Safari zooms the page on focus */
  input, textarea { font-size: 16px; }
  .row input { flex: 1 1 100%; }
  .bar { grid-template-columns: 68px 1fr 84px; gap: 6px; }

  .chatgrid { grid-template-columns: 1fr; }
  .threads { flex-direction: row; overflow-x: auto; gap: 6px; padding-bottom: 4px; }
  .threads .newbtn { margin: 0; white-space: nowrap; }
  .threads .thread { flex: 0 0 auto; max-width: 62vw; }
  .threadops button { padding: 7px; }        /* thumb-sized: there is no hover here */
  /* dvh, not vh: mobile browsers count the collapsing URL bar in vh, so the composer
     sits under it on load. Browsers without dvh keep the vh rule above. */
  #log { height: calc(100vh - 300px); height: calc(100dvh - 300px); min-height: 220px; }
  .msg.user .bubble { margin-left: 6%; }
}

/* web research — the approval button and web-sourced answers */
.webask { margin-top: 8px; padding: 10px; border-radius: 8px;
  border: 1px dashed var(--hot); background: rgba(229, 163, 61, 0.07); }
.webask .small { display: block; color: var(--muted); margin-bottom: 7px; }
.webask.quiet { border: 0; background: none; padding: 4px 0; }
.webask.quiet .webbtn { background: none; color: var(--muted); border: 1px solid var(--line);
  font-weight: 400; padding: 4px 9px; font-size: 12px; }
.webask.quiet .webbtn:hover { color: var(--fg); border-color: var(--accent); }
.webbtn { background: var(--hot); color: #201400; }
/* web answers are visually distinct from KB answers on purpose: the client must be
   able to tell curated corpus from something we pulled off the internet today */
.sources.web summary { color: var(--hot); }
.sources.web .src { border-left: 2px solid var(--hot); padding-left: 8px; }
.kbgrew { display: block; margin-top: 6px; color: var(--ok); font-size: 12px; }

/* retrieval trace (static/trace.js) — evidence cards per answer + the aggregate SVG map */
.trace, .tracemap { display: block; width: 100%; max-width: 100%; height: auto; }
/* SVG bits (aggregate map): dot columns + curved links */
.tdot { fill: var(--panel); stroke: var(--line); }
.tlabel { fill: var(--muted); font-size: 11px; text-anchor: middle;
  font-family: inherit; pointer-events: none; }
.tlabel.end { text-anchor: end; } .tlabel.start { text-anchor: start; }
.tcol { fill: var(--muted); font-size: 10px; letter-spacing: .12em; text-anchor: middle;
  text-transform: uppercase; }
.tn { cursor: default; }
.tn.q { cursor: pointer; }
.tn.cited .tdot { stroke: var(--accent); fill: #16222f; }
.tn.cited .tlabel { fill: var(--fg); }
.tn:hover .tdot { stroke: var(--ok); }
.tedge { fill: none; stroke: var(--muted); stroke-dasharray: 3 3; }
.tedge.cited { stroke: var(--accent); stroke-dasharray: none; }
.tedge.on { stroke: var(--ok); stroke-opacity: 1 !important; }
.tsummary { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line);
  font-size: 12px; white-space: pre-wrap; }
.tnote { color: var(--muted); font-size: 12px; padding: 4px 0; }

/* per-answer evidence view (renderTrace): plain-HTML cards, one per document.
   "used" is claimed only when the answer names the file or quotes it word-for-word. */
.tlead { font-size: 13px; margin: 6px 0 10px; }
.tanswer, .tsrc { background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; margin: 8px 0; }
.tsectitle { font-size: 11px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 4px; }
.tsrchead { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tsrchead b { font-size: 13px; overflow-wrap: anywhere; }
.tbadge { font-size: 11px; padding: 1px 8px; border-radius: 10px;
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.tbadge.used { border-color: var(--accent); color: var(--accent); }
.teng { display: block; color: var(--muted); font-size: 11px; margin-top: 2px;
  overflow-wrap: anywhere; }
.tmatch { font-size: 12px; color: var(--muted); margin-top: 4px; }
.tmatch.yes { color: var(--ok); }
.ttext, .tpassage { white-space: pre-wrap; font-size: 13px; margin-top: 6px;
  overflow-wrap: anywhere; }
.tsrc details { margin-top: 6px; }
.tsrc summary { cursor: pointer; color: var(--accent); font-size: 12px; }

/* One colour per document, cycled by trace.js (tc1..tc6) and inherited by everything
   inside that document's card. Both the solid and the translucent value are spelled
   out: color-mix() would be tidier, but this box is offline and old browsers would
   fall back to a solid block of colour over the text. */
.tc1 { --doc: #4da3ff; --docbg: rgba(77, 163, 255, .22); }
.tc2 { --doc: #46c07a; --docbg: rgba(70, 192, 122, .22); }
.tc3 { --doc: #e5a33d; --docbg: rgba(229, 163, 61, .22); }
.tc4 { --doc: #c78bf0; --docbg: rgba(199, 139, 240, .22); }
.tc5 { --doc: #4fd0d8; --docbg: rgba(79, 208, 216, .22); }
.tc6 { --doc: #e5604d; --docbg: rgba(229, 96, 77, .22); }

.trace mark { background: var(--docbg, rgba(70, 192, 122, .18)); color: var(--fg);
  border-bottom: 2px solid var(--doc, var(--ok)); border-radius: 2px; padding: 0 1px; }
.trace mark.tmulti { border-bottom-style: double; }   /* phrase shared by two documents */
.trace .ttext mark { cursor: pointer; }
.tsup { font-size: 10px; font-weight: 700; vertical-align: super; line-height: 0;
  color: var(--doc, var(--ok)); padding-left: 2px; }

/* numbered document chips: the legend up top, the same number on each evidence card */
.tlegend { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 10px; }
.tchip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 3px 10px 3px 4px; color: var(--muted); font: inherit; font-size: 12px;
  text-align: left; overflow-wrap: anywhere; cursor: pointer; }
.tchip:hover { border-color: var(--doc, var(--accent)); }
.tchip.used { color: var(--fg); }
.tnum { display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 19px; height: 19px; border-radius: 50%; font-size: 11px; font-weight: 700;
  color: #0f1216; background: var(--doc, var(--muted)); }
.tsrc.used { border-color: var(--doc, var(--accent)); }

/* the borrowed phrases, quoted in full — click one to light it up in the answer */
.tquote { display: block; width: 100%; margin-top: 4px; padding: 5px 9px; text-align: left;
  font: inherit; font-size: 12px; color: var(--fg); background: var(--docbg, var(--bg));
  border: 0; border-left: 3px solid var(--doc, var(--accent)); border-radius: 4px;
  cursor: pointer; overflow-wrap: anywhere; }
.tquote:hover { filter: brightness(1.25); }
.tflash { animation: tflash 1.5s ease-out; }
@keyframes tflash {
  0%, 55% { box-shadow: 0 0 0 3px var(--doc, var(--accent)); }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* light theme — toggled by the nav button (base.html), persisted in localStorage */
html.light {
  --bg: #f2f4f7; --panel: #ffffff; --line: #d8dee6; --fg: #1c2530; --muted: #5b6774;
  --accent: #1f6fd6; --ok: #1f8a4d; --bad: #c23c2a; --hot: #a8690f;
}
html.light input, html.light textarea { background: #fff; }
html.light .flash { background: #fbf3dd; border-color: #e3d3a4; color: #6b5320; }
html.light .warn { background: #fceae6; border-color: #e9c2b9; color: #8a3325; }
html.light .msg.user .bubble { background: #dcebfc; border-color: #b8d4f1; }
html.light .tn.cited .tdot { fill: #e8f1fb; }
nav .themebtn { margin: 0; padding: 2px 9px; background: none; border: 1px solid var(--line);
  border-radius: 6px; color: var(--muted); font-size: 14px; line-height: 1.4; cursor: pointer; }
nav .themebtn:hover { color: var(--fg); border-color: var(--accent); }
