:root {
  /* Ag I/O Ontology curation stages (ag-io-ontology docs/curation-taxonomy.html) */
  --c-discovery: #2563EB; --c-discovery-bg: #DFEAFD;
  --c-retrieval: #4F46E5; --c-retrieval-bg: #E3E1FC;
  --c-parsing: #C026D3; --c-parsing-bg: #F8DFFA;
  --c-inventory: #DC2626; --c-inventory-bg: #FBE0DF;
  --c-cleaning: #EA580C; --c-cleaning-bg: #FCE4D3;
  --c-standardization: #CA8A04; --c-standardization-bg: #F8ECC9;
  --c-interpolation: #65A30D; --c-interpolation-bg: #E6F0D2;
  --c-derivation: #15803D; --c-derivation-bg: #DCEDE1;
  --bg: #f6f5f2;
  --panel: #ffffff;
  --ink: #1d1d1b;
  --muted: #6b6a66;
  --line: #e2e0da;
  --accent: #1f6feb;
  --accent-soft: #dbe8ff;
  --error: #c62828;
  --error-soft: #fde7e7;
  --warn: #9a6200;
  --warn-soft: #fff1d6;
  --ok: #2e7d32;
  --ok-soft: #e3f3e4;
  --band: rgba(31, 111, 235, 0.16);
  --band-edge: rgba(31, 111, 235, 0.65);
  --block-bg: #f0eee8;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --c-discovery: #5B9BFF; --c-discovery-bg: #1E2C48;
    --c-retrieval: #818CF8; --c-retrieval-bg: #24234A;
    --c-parsing: #E879F9; --c-parsing-bg: #3B1F42;
    --c-inventory: #F87171; --c-inventory-bg: #3D2320;
    --c-cleaning: #FB923C; --c-cleaning-bg: #3D2914;
    --c-standardization: #FACC15; --c-standardization-bg: #3B3116;
    --c-interpolation: #A3E635; --c-interpolation-bg: #2A3419;
    --c-derivation: #4ADE80; --c-derivation-bg: #1B3324;
    --bg: #151514; --panel: #1f1f1d; --ink: #ecebe6; --muted: #a09e97; --line: #34332f;
    --accent: #6ea8ff; --accent-soft: #1d3150; --error: #ff8a80; --error-soft: #3d1e1e;
    --warn: #ffcc66; --warn-soft: #3a2f17; --ok: #81c784; --ok-soft: #1d3320;
    --band: rgba(110, 168, 255, 0.2); --band-edge: rgba(110, 168, 255, 0.8); --block-bg: #2a2926;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex; flex-direction: column; overflow: hidden; }
button { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 6px; padding: 4px 10px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
select { font: inherit; padding: 3px 6px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); max-width: 100%; }

.bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--panel);
  border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.bar label { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.bar label.grow { flex: 1; min-width: 200px; }
.bar label.grow select { flex: 1; }
.brand { font-weight: 700; letter-spacing: 0.04em; }
.brand span { font-weight: 400; color: var(--muted); }
.chip { padding: 2px 10px; border-radius: 999px; background: var(--block-bg); color: var(--muted); font-size: 12px; }
.chip.done { background: var(--ok-soft); color: var(--ok); }
.chip.not_needed { background: var(--block-bg); text-decoration: line-through; }
.chip.in_progress { background: var(--accent-soft); color: var(--accent); }
.progress { position: relative; width: 140px; height: 18px; border-radius: 9px; background: var(--block-bg); overflow: hidden; }
.progress div { height: 100%; background: var(--ok-soft); width: 0; }
.progress span { position: absolute; inset: 0; text-align: center; font-size: 12px; line-height: 18px; color: var(--muted); }

main { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); min-height: 0; }
.scan { display: flex; flex-direction: column; border-right: 1px solid var(--line); min-height: 0; }
.scan-tools { display: flex; gap: 6px; padding: 6px 10px; align-items: center; border-bottom: 1px solid var(--line); }
#geom-note { color: var(--muted); font-size: 12px; margin-left: 8px; }
.scan-view { flex: 1; overflow: auto; position: relative; background: #8a8a86; cursor: grab; }
.scan-view.dragging { cursor: grabbing; }
.scan-canvas { position: relative; transform-origin: 0 0; }
.scan-canvas img { display: block; user-select: none; -webkit-user-drag: none; }
/* Highlights on the scan are fills, not borders, blended with multiply so the printed digits stay dark. */
.band { position: absolute; left: 0; right: 0; background: rgba(31, 111, 235, 0.14); mix-blend-mode: multiply;
  pointer-events: none; }
.band.approx { background: rgba(31, 111, 235, 0.08); }
.cellbox { position: absolute; background: rgba(255, 214, 0, 0.55); mix-blend-mode: multiply; border-radius: 2px;
  pointer-events: none; }

.work { display: flex; flex-direction: column; min-height: 0; }
.title { padding: 6px 12px; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--line);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid-wrap { flex: 1; overflow: auto; min-height: 0; scroll-padding: 80px 12px 12px 236px; }
.grid { border-collapse: separate; border-spacing: 0; font-family: var(--mono); font-size: 13px; }
.grid td, .grid th { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  padding: 2px 8px; white-space: nowrap; text-align: right; position: relative; min-width: 64px; height: 24px; }
.grid td.label { text-align: left; font-family: system-ui, sans-serif; min-width: 190px; max-width: 190px;
  overflow: hidden; text-overflow: ellipsis; position: sticky; left: 46px; z-index: 1; background: var(--panel); }
.grid tr.block td.label, .grid tr.header td.label { background: var(--block-bg); }
.grid th.gutter, .grid td.gutter { position: sticky; left: 0; z-index: 2; background: var(--panel);
  min-width: 46px; color: var(--muted); font-size: 11px; text-align: right; }
.grid tr.header td { background: var(--block-bg); font-family: system-ui, sans-serif; font-size: 12px;
  text-align: center; white-space: normal; position: sticky; z-index: 1; }
.grid tr.block td.label { font-weight: 700; }
.grid tr.block td { background: var(--block-bg); }
.grid tr.section td.label { font-style: italic; color: var(--muted); }
.grid tr.state td { font-weight: 700; }
.grid tr.other td.label { font-style: italic; }
.grid tr.confirmed td.gutter::before { content: "✓ "; color: var(--ok); font-weight: 700; }
.grid tr.confirmed td:not(.gutter) { background-image: linear-gradient(var(--ok-soft), var(--ok-soft)); }
.grid tr.current td { box-shadow: inset 0 2px 0 var(--band-edge), inset 0 -2px 0 var(--band-edge); }
.grid td.verified { box-shadow: inset 0 -2px 0 var(--ok); }
.grid td.error { background: var(--error-soft) !important; }
.grid td.warning { background: var(--warn-soft) !important; }
.grid td.culprit::after { content: ""; position: absolute; right: 2px; top: 2px; width: 6px; height: 6px;
  border-radius: 50%; background: var(--error); }
.grid td.sel { outline: 2px solid var(--accent); outline-offset: -2px; }
.grid td.cur { outline: 3px solid var(--accent); outline-offset: -3px; }
.grid td .sug { color: var(--accent); font-size: 11px; margin-left: 6px; }
.grid td input { font: inherit; width: 100%; border: none; outline: none; background: var(--panel);
  color: var(--ink); text-align: inherit; padding: 0; }

.issues { border-top: 1px solid var(--line); background: var(--panel); max-height: 38%; overflow: auto; padding: 8px 12px; }
.issues-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.table-actions { display: flex; gap: 6px; }
.flag { border-left: 4px solid var(--line); padding: 6px 10px; margin: 6px 0; background: var(--bg); border-radius: 4px; }
.flag.error { border-color: var(--error); }
.flag.warning { border-color: var(--warn); }
.flag .msg { margin-bottom: 4px; }
.flag .rule { color: var(--muted); font-size: 11px; font-family: var(--mono); }
.flag .acts { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 4px; }
.flag .conf { color: var(--muted); font-size: 12px; }
.cand { display: flex; gap: 8px; align-items: center; font-size: 13px; margin: 3px 0; }
.cand code { font-family: var(--mono); }
#all-flags { padding-left: 20px; margin: 6px 0; }
#all-flags li { cursor: pointer; margin: 2px 0; }
#all-flags li:hover { color: var(--accent); }
#all-flags li.error::marker { color: var(--error); }
#all-flags li.warning::marker { color: var(--warn); }
.empty { color: var(--muted); }

.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); display: flex; flex-direction: column;
  align-items: center; justify-content: center; color: #fff; z-index: 10; }
.overlay[hidden] { display: none; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 4px solid rgba(255,255,255,.3);
  border-top-color: #fff; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
dialog { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--ink); max-width: 520px; }
dialog dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
dialog dt { font-family: var(--mono); color: var(--accent); }
dialog dd { margin: 0; }

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; grid-template-rows: 40% 60%; }
  .scan { border-right: none; border-bottom: 1px solid var(--line); }
}

.realign table { border-collapse: collapse; font-family: var(--mono); font-size: 12px; margin: 4px 0; }
.realign td, .realign th { border: 1px solid var(--line); padding: 1px 6px; text-align: right; }
.realign th { color: var(--muted); font-weight: 400; }
.realign td.chg { background: var(--accent-soft); color: var(--accent); }
#totals { list-style: none; padding: 0; margin: 6px 0; }
#totals li { padding: 6px 8px; margin: 4px 0; border-left: 4px solid var(--warn); background: var(--bg); border-radius: 4px;
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
#totals li.violation { border-color: var(--error); }
#totals .tl { flex-basis: 100%; font-size: 12px; color: var(--muted); }
#totals .tm { margin-right: 6px; }
#totals button { padding: 1px 8px; font-size: 12px; }

/* year picker: a custom menu, because native option colours don't render on macOS */
.picker { position: relative; }
.picker > button { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.picker > button::after { content: "▾"; margin-left: auto; color: var(--muted); }
.swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; display: inline-block; }
.picker ul { position: absolute; top: calc(100% + 4px); left: 0; z-index: 20; list-style: none; margin: 0; padding: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.18);
  width: 360px; max-height: 70vh; overflow: auto; }
.picker ul[hidden] { display: none; }
.picker li { display: grid; grid-template-columns: 14px 44px 1fr; gap: 4px 8px; align-items: center; padding: 6px 8px;
  border-radius: 6px; cursor: pointer; }
.picker li:hover, .picker li.active { background: var(--bg); }
.picker li.disabled { cursor: not-allowed; opacity: .75; }
.picker li .yr { font-weight: 700; font-variant-numeric: tabular-nums; }
.picker li .st { font-size: 12px; color: var(--muted); }
.picker li .mini { grid-column: 3; height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.picker li .mini div { height: 100%; }
.picker .legend { display: flex; flex-wrap: wrap; gap: 6px 10px; padding: 8px 8px 2px; border-top: 1px solid var(--line);
  margin-top: 6px; font-size: 11px; color: var(--muted); }
.picker .legend span { display: inline-flex; align-items: center; gap: 4px; }
.home-link { color: var(--muted); text-decoration: none; font-size: 13px; }
.home-link:hover { color: var(--accent); }
.realign td.und { background: var(--block-bg); color: var(--muted); }
.realign input.lbl { font: inherit; width: 120px; border: 1px solid var(--line); border-radius: 4px; padding: 1px 4px;
  background: var(--panel); color: var(--ink); }

/* editing toolbar */
.toolbar { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; padding: 5px 12px; background: var(--panel);
  border-bottom: 1px solid var(--line); }
.tgroup { display: flex; align-items: center; gap: 4px; }
.tgroup + .tgroup { border-left: 1px solid var(--line); padding-left: 12px; }
.tg { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-right: 2px; }
.toolbar button { padding: 3px 9px; font-size: 13px; line-height: 1.3; }
.toolbar button:disabled { opacity: .38; cursor: default; border-color: var(--line); }
.toolbar button.hot { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.saved { font-size: 12px; color: var(--muted); white-space: nowrap; }
.saved.ok { color: var(--ok); }
.saved.error { color: var(--error); font-weight: 600; }

.ai-read { font-size: 12px; color: var(--muted); margin: 6px 2px; }
.flag .explain { font-size: 12.5px; line-height: 1.45; margin: 6px 0; padding: 6px 8px; border-left: 3px solid var(--c-parsing);
  background: var(--panel-2, rgba(127, 127, 127, 0.08)); }
.grid td.auto::before { content: "auto"; position: absolute; left: 2px; top: 1px; font-size: 8px; line-height: 1;
  color: var(--c-parsing); letter-spacing: 0.02em; }

/* hover summaries on the toolbar (shown on disabled buttons too, with the reason they're off) */
.toolbar .has-tip { position: relative; display: inline-flex; }
.toolbar .tg.has-tip { cursor: help; }
.toolbar .has-tip > button:disabled { pointer-events: none; }
.toolbar .has-tip .tip { display: none; position: absolute; top: calc(100% + 6px); left: 0; z-index: 40; width: 290px;
  padding: 9px 11px; border-radius: 8px; background: var(--panel); color: var(--ink); border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18); font-size: 12px; font-weight: 400; line-height: 1.45; text-align: left;
  text-transform: none; letter-spacing: normal; white-space: normal; }
.toolbar .has-tip .tip.right { left: auto; right: 0; }
.toolbar .has-tip .tip strong { display: block; margin-bottom: 3px; }
.toolbar .has-tip .tip .why { display: block; margin-top: 5px; font-style: normal; color: var(--muted); }
.toolbar .has-tip .tip .why:empty { display: none; }
.toolbar .has-tip:hover .tip, .toolbar .has-tip:focus-within .tip { display: block; }

/* "you've made this change n times — make it everywhere?" */
.repeat-bar { position: fixed; left: 50%; transform: translateX(-50%); bottom: 18px; z-index: 50; display: flex;
  align-items: center; gap: 14px; max-width: min(860px, calc(100vw - 32px)); padding: 10px 14px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--accent); box-shadow: 0 10px 30px rgba(0, 0, 0, .2); font-size: 13px; }
.repeat-bar[hidden] { display: none; }
.repeat-bar code { background: var(--accent-soft); padding: 0 4px; border-radius: 4px; }
.repeat-bar .acts { display: flex; gap: 6px; flex-wrap: wrap; }
.readonly-banner { background: #fff4d6; color: #6b4e00; border-bottom: 1px solid #e8d391; padding: 6px 16px;
  font-size: 13px; text-align: center; }
@media (prefers-color-scheme: dark) { .readonly-banner { background: #3a3110; color: #f1dc9a; border-color: #5c4d18; } }

/* notes on cells: a corner mark on the cell, the notes and a quiet "add a note" line under the flags */
.grid td.noted { position: relative; }
.grid td.noted::after { content: ""; position: absolute; right: 0; top: 0; border-style: solid; border-width: 0 7px 7px 0;
  border-color: transparent var(--c-standardization) transparent transparent; }
.notes { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.note { font-size: 13px; line-height: 1.4; padding: 6px 8px; border-radius: 6px; background: var(--block-bg); }
.note.bug { background: var(--error-soft); } .note.suggestion { background: var(--accent-soft); }
.note.resolved { opacity: .55; }
.note-kind { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.note-meta { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }
.note .linkish, .linkish { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-size: 11px; margin-left: 6px; }
.note-form textarea { width: 100%; box-sizing: border-box; resize: vertical; font: inherit; font-size: 13px; padding: 5px 8px;
  border: 1px dashed var(--line); border-radius: 6px; background: transparent; color: var(--ink); }
.note-form textarea:focus { border-style: solid; border-color: var(--accent); outline: none; background: var(--panel); }
.note-form textarea::placeholder { color: var(--muted); opacity: .8; }
.note-actions[hidden] { display: none; }
.note-actions { display: flex; align-items: center; gap: 10px; margin-top: 6px; font-size: 12px; flex-wrap: wrap; }
.note-actions .grow { flex: 1; } .note-hint { color: var(--muted); font-size: 11px; }
.note.peculiarity { background: var(--warn-soft); }
.history { font-size: 12px; margin-top: 4px; }
.history summary { color: var(--muted); cursor: pointer; }
.history ol { margin: 4px 0 0; padding-left: 18px; line-height: 1.5; }
.history .muted { color: var(--muted); }
