:root {
  --bg: #fbfbfa; --panel: #fff; --line: #e4e4e1; --ink: #1c1c1a; --muted: #74746e;
  --accent: #2f6f4f; --warn: #8a5a00; --bad: #a33; --radius: 6px;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
}
header {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .85rem 1.25rem; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 600; text-decoration: none; color: var(--ink); }
main { max-width: 1000px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
h1 { font-size: 1.35rem; margin: 0 0 1rem; }
h2 { font-size: 1rem; margin: 1.75rem 0 .6rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.row { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.between { justify-content: space-between; }

button, .btn {
  font: inherit; padding: .45rem .9rem; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  cursor: pointer; text-decoration: none; display: inline-block;
}
button:hover:not(:disabled), .btn:hover { border-color: #c9c9c4; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

table { width: 100%; border-collapse: collapse; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: .6rem .75rem; border-bottom: 1px solid var(--line);
  font-size: .9rem; }
th { color: var(--muted); font-weight: 500; background: #f6f6f4; }
tr:last-child td { border-bottom: 0; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f7f9f8; }

.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px;
  font-size: .78rem; border: 1px solid; white-space: nowrap; }
.badge.completed { color: var(--accent); border-color: #bcd8c8; background: #f0f7f3; }
.badge.processing, .badge.pending, .badge.queued, .badge.running {
  color: var(--warn); border-color: #e6d3a8; background: #fdf8ec; }
.badge.failed { color: var(--bad); border-color: #e8c2c2; background: #fdf2f2; }

.panel { background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem 1.15rem; }
.notice { border-left: 3px solid var(--warn); }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1.25rem; margin: 0; }
dl.facts dt { color: var(--muted); font-size: .87rem; }
dl.facts dd { margin: 0; font-size: .87rem; }
code, pre, .mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }
pre.viewer { background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem; overflow: auto; max-height: 72vh;
  font-size: .82rem; white-space: pre; }
pre.wrap { white-space: pre-wrap; word-break: break-word; }
.chunk { background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .8rem 1rem; margin-bottom: .6rem; }
.chunk header { all: unset; display: flex; gap: .75rem; align-items: center;
  color: var(--muted); font-size: .8rem; margin-bottom: .4rem; }
.chunk p { margin: 0; white-space: pre-wrap; font-size: .88rem; }
.error { border-left: 3px solid var(--bad); }
.error strong { color: var(--bad); }
.tabs { display: flex; gap: .4rem; margin: 1rem 0; flex-wrap: wrap; }
.tabs a.active { background: var(--ink); color: #fff; border-color: var(--ink); }
input[type=file] { font: inherit; }
@media (max-width: 640px) {
  dl.facts { grid-template-columns: 1fr; }
  th:nth-child(n+5), td:nth-child(n+5) { display: none; }
}

/* A chunk's figures. Constrained rather than full-bleed: a figure is context
   for the text, and a 1100px crop of a textbook page would bury it. */
.visuals { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: .75rem; }
.visuals figure { margin: 0; padding: .5rem; border: 1px solid var(--line);
  border-radius: 6px; background: var(--bg); max-width: 320px; }
.visuals figure img { display: block; max-width: 100%; height: auto;
  margin: .35rem 0; border-radius: 4px; }
.visuals figcaption { font-size: .78rem; color: var(--muted); }

/* Rendered Markdown. Sized for reading a textbook page, not for a full-bleed
   document view: the AST and chunk screens are for structure, this is prose. */
.markdown { line-height: 1.55; }
.markdown h1, .markdown h2, .markdown h3,
.markdown h4, .markdown h5, .markdown h6 { line-height: 1.25; margin: 1.2em 0 .4em; }
.markdown h1 { font-size: 1.5rem; }
.markdown h2 { font-size: 1.28rem; }
.markdown h3 { font-size: 1.12rem; }
.markdown h4, .markdown h5, .markdown h6 { font-size: 1rem; }
.markdown p { margin: 0 0 .8em; }
.markdown ul, .markdown ol { margin: 0 0 .8em; padding-left: 1.4rem; }
.markdown li { margin: .15em 0; }
.markdown blockquote { margin: 0 0 .8em; padding: .2rem 0 .2rem .8rem;
  border-left: 3px solid var(--line); color: var(--muted); }
.markdown hr { border: 0; border-top: 1px solid var(--line); margin: 1.4em 0; }
.markdown code { font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .86em; background: var(--panel); padding: .1em .3em; border-radius: 3px; }
.markdown pre.md-code { background: var(--panel); border: 1px solid var(--line);
  border-radius: 6px; padding: .7rem; overflow-x: auto; }
.markdown pre.md-code code { background: none; padding: 0; }
.markdown .md-table { border-collapse: collapse; margin: 0 0 1em; display: block;
  overflow-x: auto; max-width: 100%; }
.markdown .md-table th, .markdown .md-table td { border: 1px solid var(--line);
  padding: .3rem .5rem; text-align: left; font-size: .88rem; }
.markdown .md-table th { background: var(--panel); }
.markdown .md-figure { margin: 1em 0; }
.markdown .md-figure img { display: block; max-width: min(100%, 420px);
  height: auto; border: 1px solid var(--line); border-radius: 6px; }
.markdown .md-figure figcaption { font-size: .8rem; color: var(--muted); margin-top: .3rem; }
.markdown .md-missing-image { color: var(--muted); font-style: italic; }
.markdown .md-link { text-decoration: underline dotted; }

/* A generated description. Marked as derived and set apart from the caption:
   the caption is what the book printed, this is what a model said, and a
   reader must never have to guess which is which. */
.visuals figure .derived { margin: .4rem 0 0; font-size: .78rem; line-height: 1.4;
  color: var(--muted); border-left: 2px solid var(--line); padding-left: .5rem; }
.visuals figure .derived::before { content: "AI · "; opacity: .7; }

/* Text the document itself printed inside a figure — labels, axis names.
   Styled apart from the AI description below it, because one was read off the
   page and the other was written by a model, and a reader must be able to
   tell them apart at a glance. */
.visuals figure .labels { margin: .35rem 0 0; font-size: .75rem; line-height: 1.35;
  color: var(--fg); opacity: .75; }
.visuals figure .status { margin: .35rem 0 0; font-size: .75rem; font-style: italic; }

/* Corpus search. A result has to say where it came from and why it matched,
   and AI-written evidence has to be visibly not a quotation from the page. */
.navlink { margin-left: 1rem; font-size: .9rem; color: var(--muted); text-decoration: none; }
.navlink:hover { color: var(--fg); text-decoration: underline; }
#search input { padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--fg); font-size: .95rem; }
.hit-thumb { width: 96px; height: auto; border: 1px solid var(--line); border-radius: 4px; }
.derived-tag { font-size: .68rem; letter-spacing: .04em; padding: .05rem .3rem;
  border: 1px solid var(--line); border-radius: 3px; color: var(--muted); }

/* Who is signed in and where. Read-only: the organization comes from the
   server's view of this person's membership, never from a control they can
   change — a browser that could pick an organization would be the boundary
   phase 34 removed. */
.identity { margin-left: auto; margin-right: 1rem; font-size: .85rem; }


/* --- education ----------------------------------------------------------
 * `origin` is colour-coded because it is the field a teacher has to read:
 * whether a topic came from the document, from a model, or from a person.
 */
.origin {
  display: inline-block; font-size: 11px; line-height: 1.6;
  padding: 0 6px; border-radius: 9px; margin-right: 6px; white-space: nowrap;
}
.origin-extracted   { background: #e8eef5; color: #2b4a6f; }
.origin-ai_suggested{ background: #efe6fa; color: #5b3a86; }
.origin-human       { background: #e4f3e6; color: #2c6b39; }

.ok   { color: #2c6b39; }
.warn { color: #9a5b00; }

table.kv { border-collapse: collapse; margin: 4px 0 8px; }
table.kv td { padding: 3px 14px 3px 0; }
table.kv tr.total td { border-top: 1px solid #d6dbe1; padding-top: 6px; }
td.num, th.num { text-align: right; }
/* `.row` is already a flex utility in this stylesheet, so a clickable table
   row needs its own name — reusing it turns the <tr> into a flex container
   and the table stops being a table. */
tr.course-row { cursor: pointer; }
tr.course-row:hover { background: #f4f7fa; }
table.list td { vertical-align: top; }

tr.topic-row { cursor: pointer; }
tr.topic-row:hover { background: #f4f7fa; }
td.chevron { width: 1.2rem; color: var(--muted); user-select: none; }
tr.topic-detail > td { background: #fbfcfd; padding: 0; }
.detail { padding: .75rem 1rem 1rem 2.2rem; }
.detail-head { margin: 0 0 .25rem; }
blockquote.evidence {
  margin: .5rem 0; padding: .5rem .75rem; border-left: 3px solid #d6dbe1;
  background: #fff; border-radius: 0 4px 4px 0;
}
.evidence-meta { font-size: .75rem; color: var(--muted); margin-bottom: .25rem; }
.evidence-text { white-space: pre-wrap; font-size: .86rem; line-height: 1.5; }
.error-text { color: #a33; }

tr.unit-row { cursor: pointer; }
tr.unit-row:hover { background: #f4f7fa; }
tr.unit-detail > td { background: #fbfcfd; padding: .25rem .5rem .5rem 1.5rem; }
table.list.inner { margin: 0; background: transparent; }
table.list.inner th { font-weight: 500; color: var(--muted); }

.kind {
  display: inline-block; padding: 0 5px; border-radius: 3px;
  font-size: 11px; background: #eceff3; color: #44546a;
}
.kind-table   { background: #e6f0fa; color: #24557f; }
.kind-formula { background: #fdf0e2; color: #8a5416; }
.kind-list    { background: #eef3e8; color: #4a6b34; }

table.evidence-table {
  border-collapse: collapse; margin: .4rem 0; font-size: .82rem;
  background: #fff; width: 100%;
}
table.evidence-table td {
  border: 1px solid #dde2e8; padding: .2rem .4rem; vertical-align: top;
}
pre.evidence-formula {
  margin: .4rem 0; padding: .4rem .6rem; background: #fbf7f1;
  border-radius: 4px; font-size: .84rem; white-space: pre-wrap;
  overflow-x: auto;
}
.evidence-figures { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .5rem; }
.evidence-figures figure { margin: 0; max-width: 260px; }
.evidence-figures img {
  display: block; max-width: 100%; height: auto; border: 1px solid #dde2e8;
  border-radius: 4px; background: #fff;
}
.evidence-figures figcaption { font-size: .7rem; color: var(--muted); }
