/* Screen-specific rules. Written in Tasks 3-8. */

/* ---------- Documents ---------- */
/* Two states get colour and nothing else does: a document that needs a human, and one
   that failed. Everything else is text, because a screen where five things are
   highlighted has nothing highlighted. */
.summary.needs {
  font-size: var(--text-xl);
  color: var(--ink-muted);
  letter-spacing: -0.01em;
  margin: 0 0 var(--space-4);
}
.summary.needs strong { color: var(--ink-strong); font-weight: 620; }
.summary.replayed { font-size: var(--text-sm); color: var(--ink-faint); }

.dropzone {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.dropzone input[type="file"] { color: var(--ink-muted); flex: 1; }
.dropzone input[type="file"]::file-selector-button {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  padding: var(--space-1) var(--space-3);
  margin-right: var(--space-3);
  cursor: pointer;
}

.inbox tr.needs-you td { background: var(--attention-bg); }
.inbox tr.needs-you:hover td { background: var(--attention-bg); }
.inbox a.needs { color: var(--attention-ink); font-weight: 600; }
.inbox .ok { color: var(--good); }

/* ---------- Reviewer ---------- */
.reviewer {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(300px, 1fr);
  gap: var(--space-5);
  align-items: start;
}
.page-pane {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-2);
}
.canvas { position: relative; width: 100%; background: var(--paper); border-radius: var(--radius-sm); overflow: hidden; }
.canvas img { display: block; width: 100%; height: auto; }
.span {
  position: absolute;
  border: 1px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  cursor: crosshair;
}
.span.hit, .canvas .span.highlighted {
  border-color: var(--attention);
  background: color-mix(in srgb, var(--attention) 28%, transparent);
  outline: none;
}
.pages { display: flex; gap: var(--space-3); margin-bottom: var(--space-3); }
.pages a { color: var(--ink-muted); text-decoration: none; font-size: var(--text-sm); }
.pages a.current { color: var(--accent-ink); font-weight: 600; }

.provenance { color: var(--ink-faint); font-size: var(--text-sm); margin: 0 0 var(--space-3); }
.fields h2 { font-size: var(--text-base); color: var(--ink-strong); }
.fields ol { list-style: none; padding: 0; margin: 0; }
.fields .note { font-size: var(--text-sm); color: var(--ink-faint); margin-top: var(--space-4); }
.field.editing form { display: flex; gap: var(--space-2); align-items: baseline; flex-wrap: wrap; margin-top: var(--space-2); }
.field.editing input.edit-value { min-width: 12rem; }
form.accept { margin: var(--space-3) 0; }

.template-badge { margin: var(--space-3) 0; }
.template-badge .badge {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  cursor: pointer;
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  background: var(--accent-bg);
  color: var(--accent-ink);
  border: 1px solid var(--accent-line);
}
.rule-detail {
  margin-top: var(--space-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-3);
}
.rule-detail h3 { margin: 0 0 var(--space-1); font-size: var(--text-base); color: var(--ink-strong); }
.rule-detail ol.rules { margin: var(--space-2) 0 var(--space-3); padding-left: var(--space-4); }
.rule-detail .rule.demoted { opacity: 0.62; }

/* The result sits at the *top* of the panel now, because the panel is re-rendered
   around it rather than having a banner appended underneath a stale list. */
.save-result { margin: 0 0 var(--space-4); }
.save-result .failed-rules { margin: var(--space-2) 0 0; padding-left: var(--space-4); }

/* In flight. Two labels in one button, swapped by htmx's own `htmx-request` class —
   no script, and no width jump, because the button keeps whichever label is wider. */
form.accept button .busy { display: none; }
form.accept.htmx-request button .idle { display: none; }
form.accept.htmx-request button .busy { display: inline; }
form.accept button:disabled { cursor: progress; opacity: 0.7; }
.save-result .accepted-line { font-weight: 600; color: var(--ink-strong); margin: 0 0 var(--space-1); }
.save-result .concern, .reason.concern { color: var(--attention-ink); margin: var(--space-2) 0 0; }

.spans-raw { margin-top: var(--space-4); }
.spans-raw summary { cursor: pointer; color: var(--ink-muted); }
.spans { max-height: 60vh; overflow-y: auto; margin: var(--space-2) 0 0; padding: 0; list-style: none; }
.spans li { display: flex; gap: var(--space-2); padding: var(--space-1) var(--space-2); border-bottom: 1px solid var(--line-soft); font-size: var(--text-sm); }
.spans li.hit { background: var(--attention-bg); }
.spans .ord { color: var(--ink-faint); font-variant-numeric: tabular-nums; min-width: 2.5ch; }
.spans .text { flex: 1; }

/* Step-through: the same fields, one at a time, with the page cropped to the span. */
.step-toggle { margin-bottom: var(--space-3); }
.step-counter {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
  color: var(--attention-ink);
  margin: 0 0 var(--space-2);
}
.reviewer.stepping .canvas { transition: transform 0.25s ease; }
.reviewer.stepping .field.stepped { border-left-width: 3px; padding: var(--space-4); }
.reviewer.stepping .field.stepped .value { font-size: var(--text-figure); line-height: 1.15; }
.reviewer.stepping .field.stepped .reason { font-size: var(--text-base); }
.reviewer.stepping details.accepted, .reviewer.stepping .spans-raw { display: none; }

/* ---------- Records ---------- */
/* The table is dense on purpose: a person scanning a ledger wants rows per screen,
   not air. Only the filters and the totals get room. */
.filters { margin: 0 0 var(--space-4); }
.filters .search, .add-filter { display: flex; gap: var(--space-2); align-items: center; margin-bottom: var(--space-2); }
.filters input[type="search"], .filters .filter-token { min-width: 24rem; }
.chips { list-style: none; display: flex; flex-wrap: wrap; gap: var(--space-1); padding: 0; margin: 0; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: 999px;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: var(--text-sm);
}
.chip .remove { text-decoration: none; color: var(--ink-faint); font-weight: 600; }
.chip .remove:hover { color: var(--bad); }
.chips .clear, .filters .clear { font-size: var(--text-sm); color: var(--ink-muted); }

table.records { font-size: var(--text-sm); }
table.records td { padding: var(--space-1) var(--space-3); }
table.records th a { color: inherit; text-decoration: none; }
table.records th.sorted a { color: var(--accent-ink); }
table.records th.sorted.desc a::after { content: " ↓"; }
table.records th.sorted.asc a::after { content: " ↑"; }
/* The mark §8.4 asks for, and it is a mark rather than a number. */
table.records tr.unreviewed td:first-child { box-shadow: inset 3px 0 0 var(--attention); }

.pager { display: flex; gap: var(--space-4); align-items: center; margin-top: var(--space-3); color: var(--ink-muted); }
.totals { margin: 0 0 var(--space-4); }
.views { margin-top: var(--space-5); }
.view-list { list-style: none; padding: 0; margin: 0 0 var(--space-3); }
.view-list li { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-1) 0; }
.view-list li.broken .name { color: var(--ink-faint); text-decoration: line-through; }
.save-view { display: flex; gap: var(--space-2); }

/* ---------- Templates ---------- */
/* Counts of what happened, never a rate. A demoted template is not broken, so its
   reason is amber and not red. */
table.templates td { vertical-align: top; }
table.templates tr.demoted { opacity: 0.62; }
table.templates .reason { margin: var(--space-1) 0 0; color: var(--attention-ink); font-size: var(--text-sm); }

/* ---------- Queue ---------- */
/* The debug view, and it should look like one. */
table.jobs { font: var(--text-sm) var(--font-mono); }
table.jobs td { padding: var(--space-1) var(--space-3); }
.retry { margin-left: var(--space-2); font-size: var(--text-sm); padding: 2px var(--space-2); }

/* ---------- Trust ---------- */
/* Numbers over a population, laid out so the split each came from is never further
   away than the heading above it. */
.trust section h2 { font-size: var(--text-base); }
.trust pre {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--ink-muted);
  overflow-x: auto;
}
.source { color: var(--ink-faint); font-size: var(--text-sm); margin: var(--space-1) 0 0; }

/* The two plots. Drawn for a dark ground: the ink has to carry, so the strokes are the
   state colours at full strength and the fills are the same colours held back. */
.reliability-plot, .pair-plot { width: 100%; height: auto; display: block; margin: var(--space-2) 0; }
.reliability-plot { max-width: 400px; }
.pair-plot { max-width: 640px; }
.reliability-plot .axis { stroke: var(--line); stroke-width: 1.5; }
.reliability-plot .diagonal { stroke: var(--ink-faint); stroke-width: 1; stroke-dasharray: 4 4; }
.reliability-plot .bin { fill: color-mix(in srgb, var(--accent) 40%, transparent); stroke: var(--accent); stroke-width: 1; }
.reliability-plot .axis-label { fill: var(--ink-faint); font-size: var(--text-xs); text-anchor: middle; }
.pair-plot .line { fill: none; stroke-width: 2; }
.pair-plot .line.auto-accepted { stroke: var(--accent); }
.pair-plot .line.precision-at-auto-accept { stroke: var(--good); }
.pair-plot .line.faint { opacity: 0.35; stroke-dasharray: 5 4; stroke-width: 1.5; }
.pair-plot .mark { stroke: none; }
.pair-plot .mark.auto-accepted { fill: var(--accent); }
.pair-plot .mark.precision-at-auto-accept { fill: var(--good); }
.pair-plot .mark.faint { opacity: 0.4; }
.replay-points a circle { fill: color-mix(in srgb, var(--accent) 40%, transparent); stroke: var(--accent); }
.replay-points a:hover circle { fill: var(--accent); }
ul.legend { list-style: none; padding: 0; margin: 0 0 var(--space-3); color: var(--ink-muted); font-size: var(--text-sm); }
ul.legend .swatch { display: inline-block; width: 14px; height: 3px; vertical-align: middle; }
ul.legend .swatch.auto-accepted { background: var(--accent); }
ul.legend .swatch.precision { background: var(--good); }
ul.legend .faint-note { margin-top: var(--space-1); max-width: 70ch; }
table.runs { font-variant-numeric: tabular-nums; }

.budget form { display: flex; align-items: center; gap: var(--space-2); margin: var(--space-3) 0; }
.budget input[type="number"] { width: 8rem; }
.budget .stated { margin: var(--space-1) 0 0; color: var(--ink-muted); }
dl.derived { margin: var(--space-2) 0 0; }
dl.derived dt { color: var(--ink-faint); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: var(--tracking-label); margin-top: var(--space-2); }
dl.derived dd { margin: 2px 0 0; font-variant-numeric: tabular-nums; }

.ground-truth h2 { font-size: var(--text-base); margin: 0 0 var(--space-1); }
.ground-truth tr.wrong td { background: var(--bad-bg); }
.ground-truth tr.right td { background: var(--good-bg); }

/* The login screen. The first thing anyone sees, so it uses the same tokens as
   everything behind it — a form on a different-looking page reads as a different
   application, which is exactly the wrong impression at a password prompt. */
.login-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
}

.login {
  width: min(22rem, 90vw);
}

.login-brand {
  margin: 0;
  font-size: var(--text-xl);
  color: var(--ink-strong);
}

.login-sub {
  margin: 0 0 var(--space-5);
  color: var(--ink-muted);
}

.login form {
  display: grid;
  gap: var(--space-2);
}

.login label {
  color: var(--ink-faint);
  font-size: var(--text-sm);
}

.login input {
  padding: var(--space-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

.login button {
  margin-top: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--ink-strong);
  color: var(--bg);
  font: inherit;
  cursor: pointer;
}

.login-error {
  margin: 0 0 var(--space-3);
  color: var(--bad);
  font-size: var(--text-sm);
}
