:root {
  --bg: #0f172a;
  --bg-raised: #16203a;
  --bg-soft: #1d2942;
  --border: #2a3859;
  --text: #e6ecf8;
  --text-dim: #93a2c4;
  --accent: #60a5fa;
  --warn: #fbbf24;
  --bad: #f87171;
  --good: #34d399;
  /* Annotation verdicts: stripes, chips and the Review list. */
  --rv-pending: #60a5fa;
  --rv-accepted: var(--good);
  --rv-rejected: var(--bad);
  --rv-corrected: #fb923c;
  --rv-added: #facc15;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

/* Any display rule outranks the user agent's [hidden] rule; hidden must always win. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button, select, input {
  font: inherit;
  color: inherit;
}

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 16px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, #3b82f6, #a855f7);
  font-weight: 700; font-size: 12px; letter-spacing: 0.5px;
}

.brand-title { font-weight: 600; }
.brand-sub {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
  color: var(--text-dim);
  font-size: 11px;
}
.brand-sub .src-badge { cursor: default; }

.topbar-controls { display: flex; gap: 10px; align-items: center; }

.top-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 4px 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}
.top-btn:hover, .top-btn:focus-visible { border-color: var(--accent); }
.top-btn[aria-expanded="true"] { background: #24345a; }
.top-btn.busy { border-color: var(--warn); }
.top-add { min-height: 30px; padding: 4px 14px; }

.doc-stats { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.stat {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 11px;
  color: var(--text-dim);
}
.stat b { color: var(--text); font-weight: 600; }
.stat.src-ef, .stat.src-di, .stat.src-cu, .stat.src-gt { border-color: var(--src-color); color: var(--src-color); }
.stat.src-ef b, .stat.src-di b, .stat.src-cu b, .stat.src-gt b { color: var(--src-color); }

/* ---------- layout ---------- */
.layout {
  /* The splitter writes this back as an inline style; the viewer takes what is left. */
  --panel-w: 430px;
  --library-w: 260px;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: auto auto auto minmax(0, 1fr) auto var(--panel-w);
  /* Named areas, so a hidden column (thumbnails before a document, the folded Library
     splitter) collapses instead of shifting everything after it one column left. */
  grid-template-areas: "library lsplit thumbs viewer psplit panel";
}

.library-splitter { grid-area: lsplit; }
.panel-splitter { grid-area: psplit; }
.thumbs { grid-area: thumbs; }
.viewer { grid-area: viewer; }
.panel { grid-area: panel; }

.splitter {
  position: relative;
  width: 7px;
  background: var(--bg-raised);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  cursor: col-resize;
}
.splitter::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 26px;
  border-radius: 2px;
  background: var(--border);
}
.splitter:hover::before, .splitter:focus-visible::before, body.resizing .splitter::before {
  background: var(--accent);
}
.splitter:focus-visible { outline: none; }

/* A drag that leaves the handle must not select text or flicker the cursor. */
body.resizing { cursor: col-resize; user-select: none; }

.thumbs {
  width: 108px;
  overflow-y: auto;
  padding: 10px 8px;
  background: var(--bg-raised);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.thumb {
  background: none;
  border: 2px solid transparent;
  border-radius: 6px;
  padding: 0;
  cursor: pointer;
  position: relative;
  line-height: 0;
}
.thumb img { width: 100%; border-radius: 4px; display: block; }
.thumb span {
  position: absolute; bottom: 3px; right: 4px;
  background: rgba(0, 0, 0, 0.65);
  border-radius: 4px;
  font-size: 10px; line-height: 1.4;
  padding: 0 4px;
}
.thumb.active { border-color: var(--accent); }

/* ---------- viewer ---------- */
.viewer { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.toolbar {
  display: flex;
  gap: 18px;
  align-items: center;
  flex-wrap: wrap;
  padding: 7px 12px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
}

.toolbar-group { display: flex; align-items: center; gap: 6px; }

.toolbar button {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  min-width: 28px;
  height: 26px;
  cursor: pointer;
}
.toolbar button:hover { border-color: var(--accent); }
.toolbar button.text-btn { padding: 0 9px; font-size: 11px; }

.page-indicator, .zoom-indicator { font-size: 11px; color: var(--text-dim); min-width: 52px; text-align: center; }

.switch, .slider { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text-dim); }
.slider input { width: 78px; }

.toolbar-group.sources { gap: 8px; padding: 0 8px; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
.sources-caption { font-size: 10px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-dim); }
.source-switch { font-weight: 700; letter-spacing: 0.4px; color: var(--src-color, var(--text-dim)); }
.source-switch .style-mark { color: var(--src-color, var(--text-dim)); }
.source-switch:has(input:not(:checked)) { opacity: 0.45; }

.canvas-wrap {
  flex: 1 1 auto;
  overflow: auto;
  padding: 18px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  /* "safe" keeps a page wider than the wrap aligned to the start instead of centring it,
     which would push its left edge into overflow that no scrollbar can reach. */
  justify-content: safe center;
  align-items: safe flex-start;
  background:
    repeating-linear-gradient(45deg, #0d1424 0 10px, #101832 10px 20px);
}

.page-stage {
  position: relative;
  line-height: 0;
  box-shadow: var(--shadow);
  background: #fff;
  /* The stage carries the exact pixel size of the rendered page. As a flex item it would
     otherwise shrink to the wrap width while keeping that height, squashing the page. */
  flex: 0 0 auto;
}

#page-img { display: block; }

.overlay { position: absolute; inset: 0; }
.overlay.hidden-boxes .bbox { display: none; }

.bbox {
  position: absolute;
  /* --box-color is set per box in JS; currentColor cannot be used because the label
     chip below needs the field color as its background and dark text of its own. */
  --box-color: #94a3b8;
  border: 1.5px solid var(--box-color);
  border-radius: 2px;
  cursor: pointer;
  transition: box-shadow 0.1s ease, opacity 0.1s ease;
}

.bbox.dim { opacity: 0.12; }

.bbox.hover,
.bbox.selected {
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.55), 0 0 14px 2px var(--box-color);
  z-index: 5;
}
.bbox.selected { border-width: 2.5px; }
/* Same field, a different source than the one under the cursor. */
.bbox.related { box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.3); z-index: 4; }

.bbox .bbox-tag {
  position: absolute;
  bottom: 100%;
  left: -1px;
  margin-bottom: 2px;
  background: var(--box-color);
  color: #0b1120;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.5;
  padding: 0 5px;
  border-radius: 3px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}
/* One chip per stack: the nearest box owns it, the tooltip names the rest. */
.bbox.hover-primary .bbox-tag,
.bbox.selected .bbox-tag { opacity: 1; }

/* Row union boxes stay invisible until their table row is hovered or selected. */
.bbox.row-box { opacity: 0; background: none !important; }
.bbox.row-box.hover,
.bbox.row-box.selected,
.bbox.row-box.related { opacity: 1; }

/* Table cells from the raw responses: their own layer, below the field boxes. */
.overlay-tables { z-index: 0; }
.tbox {
  position: absolute;
  --box-color: #7dd3fc;
  border: 1px solid var(--box-color);
  border-radius: 2px;
  opacity: 0.5;
  pointer-events: none;
}
.tbox.kind-table { border-width: 2px; opacity: 0.75; }
.tbox.kind-columnHeader { background: rgba(125, 211, 252, 0.12); }

/* ---------- overlay tooltip (every box under the cursor at once) ---------- */
.box-tip {
  position: fixed;
  z-index: 40;
  /* Never hit-testable: the cursor must stay on the page, or the hover would drop. */
  pointer-events: none;
  max-width: 340px;
  /* A deep stack is already capped in JS; this is the last guard against a tooltip
     taller than the window. */
  max-height: 70vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: rgba(14, 22, 42, 0.97);
  box-shadow: var(--shadow);
  font-size: 11.5px;
}

.box-tip .tip-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
}

.box-tip .tip-row {
  border-left: 3px solid var(--row-color, var(--border));
  padding: 1px 0 1px 6px;
  opacity: 0.78;
}
.box-tip .tip-row.primary { opacity: 1; }

.box-tip .tip-head { display: flex; align-items: center; gap: 5px; }
.box-tip .tip-label { color: var(--text-dim); }
.box-tip .tip-value { font-weight: 600; word-break: break-word; }
.box-tip .tip-sub { color: var(--text-dim); font-size: 10.5px; word-break: break-word; }
.box-tip .tip-sub.native { font-family: "Cascadia Mono", Consolas, monospace; color: #c4b5fd; }

.legend {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  padding: 6px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-raised);
  font-size: 11px;
  color: var(--text-dim);
}
.legend-item { display: flex; align-items: center; gap: 5px; }
.legend-hint { font-style: italic; }
.legend-sep { width: 1px; height: 14px; background: var(--border); }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }

/* Short line that previews a source's border style (solid / dashed / dotted). */
.style-mark {
  width: 16px;
  height: 0;
  flex: 0 0 auto;
  border-top: 2px solid currentColor;
}

/* ---------- panel ---------- */
.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--bg-raised);
}

.tabs { display: flex; align-items: stretch; border-bottom: 1px solid var(--border); }

.panel-actions { display: flex; align-items: center; gap: 2px; padding: 0 6px 0 8px; }
.panel-actions .icon-btn { margin-left: 0; font-size: 18px; }
.panel-wide-btn {
  white-space: nowrap;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  color: var(--accent);
  font-size: 11px;
  cursor: pointer;
}
.panel-wide-btn:hover, .panel-wide-btn:focus-visible { border-color: var(--accent); }
.panel-rail { display: none; }

/* A vertical label in a folded rail, so what comes back reads at a glance. */
.rail-btn {
  writing-mode: vertical-rl;
  padding: 10px 4px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}
.rail-btn:hover, .rail-btn:focus-visible { color: var(--text); border-color: var(--accent); }

/* Folded: a narrow rail, as the Library does. Columns are set here rather than through
   --panel-w, which the splitter writes as an inline style that would win. */
.layout.panel-folded { grid-template-columns: auto auto auto minmax(0, 1fr) auto 40px; }
.layout.panel-folded .panel-splitter { display: none; }
.layout.panel-folded .panel > :not(.panel-rail) { display: none; }
.layout.panel-folded .panel-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0;
}

/* Wide: the panel takes the page's place ("Fields preview"). */
.layout.panel-wide {
  grid-template-columns: auto auto minmax(0, 1fr);
  grid-template-areas: "library lsplit panel";
}
.layout.panel-wide .viewer,
.layout.panel-wide .thumbs,
.layout.panel-wide .panel-splitter { display: none; }

/* Fields preview has the width for cards: several fields per line instead of one. */
.layout.panel-wide #tab-fields.active,
.layout.panel-wide #tab-fields .section:not(.checks) {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 6px;
  align-content: start;
}
.layout.panel-wide #tab-fields.active > :not(.frow),
.layout.panel-wide #tab-fields .section > .section-head { grid-column: 1 / -1; }
.layout.panel-wide #tab-fields .frow { margin-bottom: 0; }
/* An open editor needs the room of a whole line. */
.layout.panel-wide #tab-fields .frow:has(.rv-editor) { grid-column: 1 / -1; }
/* Annotating, the verdict and its buttons sit on the label's line rather than below. */
.layout.panel-wide .frow:has(> .rv-bar) {
  display: grid;
  grid-template-columns: minmax(min-content, 1fr) auto;
  grid-template-areas: "head bar" "cells cells";
  column-gap: 6px;
  align-content: start;
}
.layout.panel-wide .frow:has(> .rv-bar).hidden { display: none; }
.layout.panel-wide .frow:has(> .rv-bar) > .frow-head { grid-area: head; }
.layout.panel-wide .frow:has(> .rv-bar) > .fcells { grid-area: cells; }
.layout.panel-wide .frow > .rv-bar {
  grid-area: bar;
  align-self: start;
  justify-content: flex-end;
  margin: 0 0 4px;
  padding: 0;
  border: 0;
}

.tab {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 9px 4px;
  cursor: pointer;
  color: var(--text-dim);
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.search-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border); }

#search {
  flex: 1;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 9px;
}

#name-mode {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 4px;
  font-size: 11px;
}

.hit-count { font-size: 11px; color: var(--text-dim); white-space: nowrap; }

.panel-body { flex: 1 1 auto; overflow-y: auto; min-height: 0; }

.tab-pane { display: none; padding: 8px 10px 40px; }
.tab-pane.active { display: block; }

.section { margin-bottom: 14px; }

.section-head {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 2px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-dim);
  position: sticky;
  top: 0;
  background: var(--bg-raised);
  z-index: 2;
}
.section-head .count { margin-left: auto; text-transform: none; letter-spacing: 0; }

/* ---------- field rows (one row per field, one cell per source) ---------- */
.frow {
  border: 1px solid transparent;
  border-left: 3px solid var(--row-color, var(--border));
  border-radius: 5px;
  background: var(--bg-soft);
  margin-bottom: 5px;
  padding: 5px 7px;
  cursor: pointer;
}
/* Hover and selection outline the row but keep its color stripes (left: field, right: verdict). */
.frow:hover, .frow.hover, .frow.selected {
  border-color: var(--accent);
  border-left-color: var(--row-color, var(--border));
}
.frow.selected { background: #24345a; }
.frow.hidden { display: none; }

.frow-head {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  color: var(--text-dim);
  font-size: 11px;
  margin-bottom: 4px;
}
.frow-label { color: var(--text); font-weight: 600; }

.fcells { display: grid; gap: 4px; }
.fcells.split { grid-template-columns: repeat(var(--columns, 2), minmax(0, 1fr)); }

.fcell {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 6px;
  background: rgba(255, 255, 255, 0.02);
  min-width: 0;
}
.fcell.hover, .fcell.selected { border-color: var(--accent); background: #2b3c65; }
.fcell.missing { border-style: dashed; opacity: 0.55; }
.fcell.missing.absent-missing { opacity: 0.8; border-color: var(--warn); }
.fcell.missing.absent-missing .fcell-value { color: var(--warn); }
.fcell.missing.absent-na { opacity: 0.4; }
.fcell-absent { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 2px; }
.fcell-absent .src-badge { border-style: dashed; color: var(--warn); }
.missing-toggle { flex: 0 0 auto; white-space: nowrap; }
.missing-row .frow-label { color: var(--text-dim); }
.fcell.compact { padding: 3px 4px; font-size: 11.5px; }

.fcell-head { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-bottom: 2px; }
.fcell-value { font-weight: 600; word-break: break-word; white-space: pre-wrap; }
.fcell-value.dim { font-weight: 400; color: var(--text-dim); }
.fcell-sub { color: var(--text-dim); font-size: 11px; word-break: break-word; }
.fcell-sub.native { font-family: "Cascadia Mono", Consolas, monospace; color: #c4b5fd; }
.fcell-sub.dim { opacity: 0.8; }

.src-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.4px;
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--src-color, var(--border));
  color: var(--src-color, var(--text-dim));
  background: rgba(255, 255, 255, 0.03);
  white-space: nowrap;
  cursor: pointer;
}
.src-badge b { font-weight: 600; opacity: 0.95; }
.src-badge i { font-style: normal; opacity: 0.85; }
.src-badge.off { opacity: 0.5; }
.src-badge.tiny { font-size: 9px; padding: 0 4px; }
.src-badge.hover, .src-badge.selected { background: var(--src-color); color: #0b1120; }
.src-badge.related { background: rgba(255, 255, 255, 0.12); }

.src-ef { --src-color: #7dd3fc; }
.src-di { --src-color: #c4b5fd; }
.src-cu { --src-color: #fdba74; }
.src-gt { --src-color: #86efac; }

.chip {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-dim);
  white-space: nowrap;
}
.chip.currency { color: var(--text); }
.chip.no-loc { border-color: var(--warn); color: var(--warn); }
.chip.differs { border-color: var(--bad); color: var(--bad); }
.chip.conf-high { border-color: var(--good); color: var(--good); }
.chip.conf-mid { border-color: var(--warn); color: var(--warn); }
.chip.conf-low { border-color: var(--bad); color: var(--bad); }

/* A page number or count: a page icon, then the number. */
.page-tag { display: inline-flex; align-items: center; gap: 3px; }
.page-tag::before {
  --page-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 14'%3E%3Cpath d='M1.5.75h6l3 3v9.5h-9z M7.5.75v3h3' fill='none' stroke='black' stroke-width='1.3' stroke-linejoin='round'/%3E%3C/svg%3E");
  content: "";
  width: 0.85em;
  height: 1em;
  background: currentColor;
  -webkit-mask: var(--page-icon) center / contain no-repeat;
  mask: var(--page-icon) center / contain no-repeat;
}

.conf-high { color: var(--good); }
.conf-mid { color: var(--warn); }
.conf-low { color: var(--bad); }

.items-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.items-table th {
  text-align: left;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
  padding: 5px 6px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-raised);
}
.items-table td {
  padding: 4px 5px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  vertical-align: top;
}
.items-table tbody tr { cursor: pointer; }
.items-table tbody tr.hover, .items-table tbody tr.selected { background: #24345a; }
.items-table tr.hidden { display: none; }
.items-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.items-table td.differs { background: rgba(248, 113, 113, 0.08); }
.items-table td.idx { color: var(--text-dim); }
.items-table .row-badges { display: flex; flex-direction: column; gap: 2px; margin-top: 3px; }
.items-table .th-native {
  text-transform: none;
  letter-spacing: 0;
  font-family: "Cascadia Mono", Consolas, monospace;
  color: #c4b5fd;
  margin-top: 2px;
}
.cell-sub { color: var(--text-dim); font-size: 10px; }

.checks { margin-top: 6px; }
.check {
  display: flex;
  gap: 7px;
  align-items: flex-start;
  flex-wrap: wrap;
  padding: 5px 8px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: var(--bg-soft);
  margin-bottom: 4px;
  cursor: pointer;
  font-size: 11px;
}
.check.selected { border-color: var(--accent); background: #24345a; }
.check .marker,
.ck-marker { display: inline-flex; align-items: center; justify-content: center; }
.check .marker { flex: 0 0 auto; height: 1.45em; }
.check.warning .marker { color: var(--warn); }
.check.info .marker { color: var(--accent); }
.json-sources { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.json-source {
  background: var(--bg-soft);
  border: 1px solid var(--src-color, var(--border));
  color: var(--src-color, var(--text-dim));
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 11px;
  cursor: pointer;
}
.json-source.active { background: var(--src-color); color: #0b1120; font-weight: 600; }
.json-facts { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 8px; }

.json-tree { font-family: "Cascadia Mono", Consolas, monospace; font-size: 11.5px; }
.json-tree details { margin-left: 12px; }
.json-tree summary { cursor: pointer; color: var(--accent); }
.json-leaf { margin-left: 12px; white-space: pre-wrap; word-break: break-word; }
.json-key { color: #c4b5fd; }
.json-string { color: #86efac; }
.json-number { color: #fcd34d; }
.json-null { color: var(--text-dim); }

.empty { color: var(--text-dim); padding: 12px 4px; }

/* ---------- dropzone / toast ---------- */
.dropzone {
  position: fixed;
  inset: 0;
  background: rgba(8, 13, 26, 0.85);
  display: none;
  place-items: center;
  z-index: 50;
}
.dropzone.active { display: grid; }
.dropzone-inner {
  border: 2px dashed var(--accent);
  border-radius: 14px;
  padding: 44px 64px;
  font-size: 16px;
}

.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 9px 16px;
  box-shadow: var(--shadow);
  z-index: 60;
  max-width: 70vw;
}
.toast.error { border-left-color: var(--bad); }

/* ---------- shared controls ---------- */
.job-count {
  min-width: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--warn);
  color: #1b1403;
  font-size: 10px;
  font-weight: 700;
  text-align: center;
}

.icon-btn {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1;
  padding: 0 4px;
  cursor: pointer;
}
.icon-btn:hover { color: var(--text); }

.primary-btn {
  background: var(--accent);
  border: none;
  border-radius: 6px;
  color: #0b1120;
  font-weight: 600;
  padding: 7px 10px;
  cursor: pointer;
}
.primary-btn:hover { filter: brightness(1.08); }
.primary-btn:disabled { opacity: 0.6; cursor: default; }

.library .text-btn, .add-dialog .text-btn, #tab-history .text-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 11px;
  cursor: pointer;
  padding: 0;
}
.library .text-btn:disabled, .add-dialog .text-btn:disabled, #tab-history .text-btn:disabled { opacity: 0.5; cursor: default; }
#tab-history .text-btn:hover { text-decoration: underline; }
#tab-history > .text-btn { font-size: 12px; margin-top: 4px; }

.process-field { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--text-dim); }
.process-field input, .process-field select {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  color: var(--text);
}
.process-field input:focus-visible, .process-field select:focus-visible { border-color: var(--accent); }
.process-field input:disabled, .process-field select:disabled { opacity: 0.5; }

.process-envelope { font-size: 11px; color: var(--text-dim); }
.process-envelope summary { cursor: pointer; padding: 2px 0; }
.process-envelope .process-field, .process-envelope .add-hint { margin-top: 6px; }

.process-config {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 8px 10px;
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.config-title { font-weight: 600; color: var(--warn); }
.config-line { word-break: break-word; }
.config-group { color: var(--text-dim); }
.config-key {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 10.5px;
  padding: 0 4px;
  border-radius: 4px;
  background: var(--bg-soft);
  display: inline-block;
  max-width: 100%;
  overflow-wrap: anywhere;
}
.config-warn { color: var(--warn); }
.config-dim { color: var(--text-dim); }

.job-status {
  flex: 0 0 auto;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  border-radius: 4px;
  padding: 1px 5px;
  background: var(--border);
}
.job-status-finished { background: var(--good); color: #052e21; }
.job-status-failed, .job-status-timeout { background: var(--bad); color: #2d0909; }
.job-status-sent, .job-status-classified, .job-status-uploading { background: var(--warn); color: #1b1403; }
.job-status-waiting { background: var(--border); color: var(--warn); }
.job-status-analyzing { background: var(--warn); color: #1b1403; }
.job-service {
  flex: 0 0 auto;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.4px;
  padding: 0 4px;
  border: 1px solid var(--src-color, var(--border));
  border-radius: 4px;
  color: var(--src-color, var(--text-dim));
}
.job-service-ef { --src-color: #7dd3fc; }
.job-service-di { --src-color: #c4b5fd; }
.job-service-cu { --src-color: #fdba74; }
/* ---------- library ---------- */
.library {
  grid-area: library;
  width: var(--library-w);
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-raised);
  overflow: hidden;
}

.library-head { display: flex; align-items: center; gap: 6px; padding: 8px 10px 4px; }
.library-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-dim);
}
.library-rail { display: none; }

.library-search { padding: 4px 10px 6px; }
.library-filter {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
}
.library-filter:focus-visible { outline: none; border-color: var(--accent); }

.library-notes { display: flex; flex-direction: column; gap: 4px; padding: 0 10px 6px; }
.lib-note {
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 6px;
  border-left: 3px solid var(--accent);
  background: var(--bg-soft);
}
.lib-note.warn { border-left-color: var(--warn); color: var(--warn); }
.lib-note.dim { border-left-color: var(--border); color: var(--text-dim); }

.library-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 0 6px 8px; }
.library-footer {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  padding: 6px 10px;
  border-top: 1px solid var(--border);
}

.lib-section { margin-top: 4px; }
.lib-section-head {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 4px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  text-align: left;
  cursor: pointer;
}
.lib-section-head:hover { color: var(--text); }
.lib-caret { width: 10px; }
.lib-count { margin-left: auto; padding: 0 6px; border-radius: 999px; background: var(--bg-soft); }
.lib-section-processing .lib-count { color: var(--warn); }
.lib-section-failed .lib-count { color: var(--bad); }
.lib-section-body { display: flex; flex-direction: column; gap: 3px; }

.lib-row {
  padding: 5px 7px;
  border: 1px solid transparent;
  border-left: 3px solid transparent;
  border-radius: 6px;
  background: var(--bg-soft);
}
.lib-doc { cursor: pointer; }
.lib-doc:hover, .lib-doc:focus-visible { border-color: var(--accent); outline: none; }
.lib-doc.current { border-left-color: var(--accent); background: #24345a; }
/* Finished while something else was on screen, and not opened yet. */
.lib-doc.fresh .lib-name::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--good);
  vertical-align: middle;
}
.lib-job.job-uploading, .lib-job.job-sent, .lib-job.job-classified { border-left-color: var(--warn); }
.lib-job.job-failed, .lib-job.job-timeout { border-left-color: var(--bad); }

.lib-line { display: flex; align-items: center; gap: 6px; min-width: 0; }
.lib-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-badges { display: flex; flex-wrap: wrap; align-items: center; gap: 3px; margin-top: 3px; }
.lib-badges .src-badge { cursor: inherit; }
.lib-pages { margin-left: auto; font-size: 10px; color: var(--text-dim); }
.lib-meta { margin-top: 2px; font-size: 11px; color: var(--text-dim); }
.lib-error { margin-top: 2px; font-size: 11px; color: var(--bad); word-break: break-word; }
.lib-remove { margin-left: 0; opacity: 0.55; }
.lib-row:hover .lib-remove, .lib-row:focus-within .lib-remove { opacity: 1; }
.lib-retry { flex: 0 0 auto; }
.lib-empty { padding: 12px 6px; font-size: 12px; color: var(--text-dim); }

.lib-select { flex: 0 0 auto; margin: 0; cursor: pointer; }
.lib-doc.selected { border-color: var(--border); }
.lib-selection {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 10px 6px;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--bg-soft);
  border-left: 3px solid var(--accent);
  font-size: 11px;
}
.lib-selection.off { border-left-color: var(--border); }
.lib-selection-count { flex: 1 1 auto; }
.lib-section-tools { display: flex; justify-content: flex-end; padding: 0 4px 4px; }

.lib-tag {
  padding: 0 5px;
  font-size: 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
}
.lib-tag-processed {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  border-color: var(--good);
  color: var(--good);
  cursor: pointer;
}
.lib-from { font-size: 10px; color: var(--text-dim); }
.lib-tag-processed:hover { background: var(--bg); }
.lib-tag-empty { border-style: dashed; }

.lib-folder-head { display: flex; align-items: center; gap: 6px; padding: 2px 4px 2px 7px; }
.lib-folder-toggle {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  gap: 4px;
  min-width: 0;
  padding: 0;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}
.lib-folder-toggle:hover { color: var(--text); }
.lib-folder-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-folder-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-left: 12px;
  padding-left: 6px;
  border-left: 1px solid var(--border);
}

/* Folded: a narrow rail that keeps the counts in view. */
.layout.library-collapsed .library { width: 40px; }
.layout.library-collapsed .library > :not(.library-rail) { display: none; }
.layout.library-collapsed .library-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
}
.layout.library-collapsed .library-splitter { display: none; }
/* Reads bottom to top, as a label on the left edge usually does. */
.library-expand { margin: 0; transform: rotate(180deg); }
/* The folded rail's button brings the Library back on a wide screen; the header button
   is only needed where the Library is a drawer (see the 900px query). */
#library-toggle { display: none; }
.rail-count {
  min-width: 20px;
  padding: 1px 5px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  text-align: center;
}
.rail-busy { background: var(--warn); color: #1b1403; }
.rail-failed { background: var(--bad); color: #2d0909; }

/* ---------- add documents ---------- */
.add-dialog {
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  padding: 0;
  overflow: auto;
  color: var(--text);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.add-dialog::backdrop { background: rgba(8, 13, 26, 0.7); }

.add-head { display: flex; align-items: center; padding: 12px 14px 6px; }
.add-title { font-size: 14px; font-weight: 600; }

.add-tabs { display: flex; gap: 4px; padding: 0 14px; border-bottom: 1px solid var(--border); }
.add-tab {
  padding: 7px 10px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  cursor: pointer;
}
.add-tab:hover { color: var(--text); }
.add-tab.active { color: var(--text); border-bottom-color: var(--accent); }

.add-pane { display: flex; flex-direction: column; gap: 10px; padding: 12px 14px 14px; }

.add-drop {
  display: grid;
  place-items: center;
  padding: 18px;
  border: 2px dashed var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  text-align: center;
  cursor: pointer;
}
.add-drop:hover { border-color: var(--accent); color: var(--text); }
.add-drop input { display: none; }

.add-rows { display: flex; flex-direction: column; gap: 4px; max-height: 40vh; overflow-y: auto; }
.add-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-left: 3px solid var(--border);
  border-radius: 6px;
  background: var(--bg-soft);
}
.add-row-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.add-row-size { font-size: 11px; color: var(--text-dim); }
.add-row-kind {
  font-size: 9px;
  letter-spacing: 0.6px;
  padding: 0 4px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
}
.add-row-type {
  max-width: 190px;
  padding: 2px 4px;
  font-size: 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
}
.add-row-state { font-size: 10px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-dim); }
.add-row .icon-btn { margin-left: 0; }
.add-row-note { flex-basis: 100%; font-size: 11px; color: var(--warn); }
.add-row-note.bad { color: var(--bad); }
.add-row-uploading { border-left-color: var(--warn); }
.add-row-uploaded { border-left-color: var(--good); }
.add-row-failed { border-left-color: var(--bad); }
.add-row-loose { border-left-color: var(--warn); }
.add-row-process { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--text-dim); }
.add-row-process:has(input:disabled) { opacity: 0.5; }
.add-row-jsons { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 4px; padding-left: 30px; }
.add-json {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  max-width: 100%;
  padding: 0 2px 0 6px;
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-dim);
}
.add-json-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.add-json .icon-btn { font-size: 13px; }
.add-process {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.process-existing { display: flex; flex-direction: column; gap: 4px; }
.process-choice { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.process-choice:has(input:disabled) { opacity: 0.5; }
.process-targets { font-size: 11px; color: var(--text-dim); }
.process-targets summary { cursor: pointer; }
.process-targets ul { margin: 4px 0 0; padding-left: 18px; max-height: 20vh; overflow-y: auto; }

.process-services { display: flex; flex-direction: column; gap: 5px; }
.process-services-title { font-size: 10px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-dim); }
.process-service-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.process-service { display: flex; align-items: center; gap: 6px; min-width: 230px; font-size: 12px; }
.process-service:has(input:disabled) { opacity: 0.5; }
/* Lines up with the label text, past the checkbox. */
.process-service-sub { margin: -1px 0 3px 19px; }
.process-service-sub[open] { border-left: 2px solid var(--border); padding: 0 0 4px 10px; margin-left: 6px; }
.process-flow {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-dim);
}
.process-flow ol { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 3px; }
.process-flow strong { color: var(--text); font-weight: 600; }
.process-flow-arrow { color: var(--accent); font-weight: 700; }.model-input {
  flex: 1 1 200px;
  min-width: 0;
  max-width: 300px;
  padding: 3px 6px;
  font-size: 11px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
}
.model-input:disabled { opacity: 0.5; }
/* The shared form lays its parts out in the pane's own column. */
.process-form { display: contents; }
.process-service-note { margin: -2px 0 3px 24px; }
.add-hint.bad { color: var(--bad); }
.add-inline { flex-direction: row; align-items: center; gap: 8px; }
.add-hint { margin: 0; font-size: 11px; color: var(--text-dim); }
.add-actions { display: flex; justify-content: flex-end; align-items: center; gap: 12px; }
.add-actions .primary-btn { padding: 7px 16px; }

.dropzone-sub { margin-top: 6px; font-size: 12px; color: var(--text-dim); text-align: center; }

/* ---------- settings ---------- */
.settings-dialog { width: min(980px, calc(100vw - 32px)); }
.settings-dialog .add-pane { gap: 8px; }
.settings-left { justify-content: flex-start; }
.settings-grow { flex: 1 1 auto; }
.settings-dirty { color: var(--warn); }
.settings-dialog a.text-btn { text-decoration: none; }
.settings-file input { display: none; }
.settings-inline { display: flex; flex-wrap: wrap; }
.settings-inline .add-row-type { max-width: 260px; }
.settings-search {
  flex: 1 1 200px;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.settings-scroll {
  max-height: 34vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.settings-scroll-tall { max-height: 52vh; }
.settings-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.settings-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 5px 6px;
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-dim);
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
}
.settings-table td { padding: 2px 4px; border-bottom: 1px solid rgba(42, 56, 89, 0.5); }
.settings-table td:last-child { width: 24px; text-align: center; }
.settings-table input, .settings-table select {
  width: 100%;
  min-width: 90px;
  padding: 3px 6px;
  font-size: 12px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid transparent;
  border-radius: 4px;
}
.settings-table select { max-width: none; }
.settings-table input:hover, .settings-table select:hover { border-color: var(--border); }
.settings-table input:focus-visible, .settings-table select:focus-visible {
  border-color: var(--accent);
  outline: none;
}
.settings-table input::placeholder { color: #55648a; }
.settings-problem td { padding: 0 8px 4px; border-bottom-color: rgba(42, 56, 89, 0.5); }

.settings-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.settings-chip {
  padding: 2px 8px;
  font-size: 11px;
  color: var(--text-dim);
  background: var(--bg-soft);
  border: 1px dashed var(--border);
  border-radius: 999px;
  cursor: pointer;
}
.settings-chip:hover { color: var(--text); border-color: var(--accent); }
.settings-chip-solid { border-style: solid; }
.settings-chip-done { color: var(--good); border-color: rgba(52, 211, 153, 0.45); }
.settings-chip-idle { opacity: 0.6; }

/* A DI or CU name guessed for a new row, until it is edited or saved. */
.settings-table input.settings-guess { border: 1px dashed var(--accent); }
.settings-guess-note { color: var(--accent); }

.settings-coverage {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 30vh;
  overflow-y: auto;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.settings-coverage-part { display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.settings-coverage-part > summary { cursor: pointer; font-weight: 600; color: var(--text); }
.settings-coverage-part[open] > summary { margin-bottom: 4px; }
.settings-coverage-part > * + * { margin-top: 4px; }
.settings-coverage-warn > summary { color: var(--warn); }
.settings-coverage-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; color: var(--text-dim); }
.settings-coverage-line .text-btn { padding: 0 4px; }
.settings-coverage-label {
  min-width: 140px;
  font-size: 10px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-dim);
}

.settings-fields {
  max-height: 30vh;
  margin-top: 6px;
  overflow: auto;
  font-size: 12px;
}
.settings-field { display: flex; align-items: baseline; gap: 8px; padding: 1px 0; color: var(--text); }
.settings-field-group .settings-field-name { color: var(--text-dim); font-weight: 600; }
.settings-field-kind { font-size: 10px; color: var(--text-dim); }
.settings-field-note { font-size: 10px; color: var(--warn); }

.settings-ai { display: flex; flex-direction: column; gap: 6px; }
.settings-ai-head { display: flex; align-items: center; gap: 8px; }
.settings-ai-head .text-btn { padding: 0 4px; }

/* ---------- check level icons ---------- */
.level-icon { width: 15px; height: 15px; flex: none; }
.level-shape { fill: currentColor; stroke: currentColor; stroke-width: 1.4; stroke-linejoin: round; }
.level-glyph { fill: none; stroke: var(--bg); stroke-width: 1.7; stroke-linecap: round; }
.level-dot { fill: var(--bg); }

/* ---------- checks legend ---------- */
.checks-dialog { width: min(760px, calc(100vw - 32px)); }
.ck-body { gap: 12px; }
.ck-body .add-hint { line-height: 1.8; }
.ck-group { display: flex; flex-direction: column; gap: 4px; }
.ck-group-head {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-dim);
  padding: 2px 2px 3px;
  border-bottom: 1px solid var(--border);
}
.ck-row {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: start;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--bg-soft);
}
.ck-row.fired { border-color: var(--border); background: #22304f; }
.ck-marker { height: 1.45em; }
.ck-body .add-hint .ck-marker { vertical-align: -0.3em; }
.ck-marker.warning { color: var(--warn); }
.ck-marker.info { color: var(--accent); }
.ck-title { font-weight: 600; }
.ck-desc { font-size: 11.5px; color: var(--text-dim); }
.ck-sources { display: flex; gap: 3px; flex-wrap: wrap; justify-content: flex-end; padding-top: 2px; }
.ck-sources .src-badge { cursor: default; }
.ck-count {
  min-width: 22px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #0b1120;
  font-size: 10.5px;
  font-weight: 700;
  text-align: center;
}
.ck-count.none { background: none; color: var(--text-dim); font-weight: 400; border: 1px solid var(--border); }
.ck-row:has(.ck-marker.warning) .ck-count:not(.none) { background: var(--warn); color: #1b1403; }
.checks .section-head .text-btn {
  margin-left: auto;
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font-size: 11px;
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
}
/* ---------- keyboard shortcuts ---------- */
.shortcuts-dialog { width: min(760px, calc(100vw - 32px)); }
.sc-body {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 14px 18px;
  align-items: start;
}
.sc-hint { grid-column: 1 / -1; }
.sc-row {
  display: grid;
  grid-template-columns: 156px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--bg-soft);
}
.sc-keys { display: flex; flex-wrap: wrap; align-items: center; gap: 3px; }
.sc-key {
  min-width: 20px;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font: 600 11px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
  text-align: center;
}
.sc-sep { font-size: 10.5px; color: var(--text-dim); }
.sc-label { font-size: 12px; }

/* ---------- annotation mode ---------- */
.annotate-btn:hover:not(:disabled), .annotate-btn:focus-visible { border-color: var(--good); }
.annotate-btn.on { background: var(--good); border-color: var(--good); color: #052e1c; font-weight: 600; }
.annotate-btn:disabled { opacity: 0.45; cursor: default; }

.rv-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 11px;
  line-height: 1.4;
  padding: 1px 7px;
  cursor: pointer;
}
.rv-btn:hover:not(:disabled) { border-color: var(--accent); }
.rv-btn:disabled { opacity: 0.5; cursor: default; }
.rv-btn.rv-accept:hover:not(:disabled) { border-color: var(--good); color: var(--good); }
.rv-btn.rv-reject:hover:not(:disabled),
.rv-btn.rv-remove-row:hover:not(:disabled) { border-color: var(--bad); color: var(--bad); }
.rv-btn.primary-btn { background: var(--accent); color: #0b1120; border-color: var(--accent); font-weight: 600; padding: 4px 10px; }

.rv-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 8px;
  margin-top: 5px;
  padding-top: 4px;
  border-top: 1px dashed var(--border);
  cursor: default;
}
.rv-bar.compact { margin-top: 3px; padding-top: 2px; gap: 2px 4px; }
.rv-bar.compact .rv-btn { padding: 0 5px; font-size: 10.5px; }
.rv-notes { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; min-width: 0; font-size: 11px; }
.rv-buttons { display: flex; gap: 3px; margin-left: auto; }
.rv-note { color: var(--text-dim); word-break: break-word; }
.rv-expected { color: var(--good); font-weight: 600; }

.rv-chip {
  display: inline-block;
  padding: 0 6px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--text-dim);
}
.rv-chip.v-pending { border-style: dashed; color: var(--rv-pending); border-color: var(--rv-pending); }
.rv-chip.v-accepted { background: rgba(52, 211, 153, 0.15); border-color: var(--rv-accepted); color: var(--rv-accepted); }
.rv-chip.v-rejected { background: rgba(248, 113, 113, 0.15); border-color: var(--rv-rejected); color: var(--rv-rejected); }
.rv-chip.v-corrected { background: rgba(251, 146, 60, 0.15); border-color: var(--rv-corrected); color: var(--rv-corrected); }
.rv-chip.v-added, .rv-chip.v-row_added { background: rgba(250, 204, 21, 0.15); border-color: var(--rv-added); color: var(--rv-added); }
.rv-chip.v-row_removed { background: rgba(248, 113, 113, 0.15); border-color: var(--rv-rejected); color: var(--rv-rejected); }
.rv-chip.v-none { border-style: dotted; }

.rv-tag { font-size: 10px; padding: 0 4px; border-radius: 3px; border: 1px solid var(--border); color: var(--text-dim); white-space: nowrap; }
/* One look per comparison: GT ones outlined (EF vs GT solid, Review vs GT double), the
   previous extraction dashed; the color says whether the two sides agree. */
.rv-cmp.rv-ok { border-color: var(--good); color: var(--good); }
.rv-cmp.rv-bad { border-color: var(--bad); color: var(--bad); }
.rv-cmp-rvgt { border-style: double; border-width: 3px; padding: 0 3px; line-height: 1.1; }
.rv-cmp-prev { border-style: dashed; border-color: var(--warn); color: var(--warn); }
.rv-btn.rv-compare.on { border-color: var(--accent); color: var(--accent); background: rgba(96, 165, 250, 0.12); }

/* EF / Review / GT / previous EF of one field, unfolded under its verdict bar. */
.rv-cmp-table {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  gap: 2px 8px;
  align-items: baseline;
  padding: 5px 7px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
  font-size: 11px;
  cursor: default;
}
.rv-cmp-who { font-weight: 600; color: var(--text-dim); text-transform: uppercase; font-size: 9.5px; letter-spacing: 0.4px; }
.rv-cmp-value { word-break: break-word; }
.rv-cmp-where { font-family: "Cascadia Mono", Consolas, monospace; font-size: 10px; color: var(--text-dim); white-space: nowrap; }
.rv-cmp-mark { font-size: 10px; color: var(--text-dim); white-space: nowrap; text-align: right; }

/* The verdict shows as the row's right stripe, so a pass down the list reads fast; the
   left one stays the source color. Declared after .frow:hover/.selected so it survives them. */
.frow[class*="rv-v-"] { border-right: 3px solid var(--rv-color); }
.frow.rv-v-pending { --rv-color: var(--rv-pending); }
.frow.rv-v-accepted { --rv-color: var(--rv-accepted); }
.frow.rv-v-rejected { --rv-color: var(--rv-rejected); }
.frow.rv-v-corrected { --rv-color: var(--rv-corrected); }
.frow.rv-v-added { --rv-color: var(--rv-added); }
.items-table td.rv-v-pending { box-shadow: inset 0 -2px 0 var(--rv-pending); }
.items-table td.rv-v-accepted { box-shadow: inset 0 -2px 0 var(--rv-accepted); }
.items-table td.rv-v-rejected { box-shadow: inset 0 -2px 0 var(--rv-rejected); }
.items-table td.rv-v-corrected { box-shadow: inset 0 -2px 0 var(--rv-corrected); }
.items-table td.rv-v-added { box-shadow: inset 0 -2px 0 var(--rv-added); }
.items-table tr.rv-v-row_removed td, .items-table td.rv-row-removed { opacity: 0.45; }
.items-table tr.rv-v-row_removed .idx { opacity: 1; }
.items-table tr.rv-v-row_added .idx { box-shadow: inset 3px 0 0 var(--rv-added); }

.rv-row-controls { display: flex; align-items: center; gap: 3px; margin-top: 3px; }
.rv-add-row, .rv-add-field { margin: 8px 0; }

.rv-holder { display: flex; flex-direction: column; gap: 6px; }
.rv-editor {
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--bg);
  padding: 7px 8px;
  cursor: default;
  min-width: 260px;
}
.rv-editor-grid { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 5px 8px; align-items: center; }
.rv-editor-label { font-size: 11px; color: var(--text-dim); }
.rv-input {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 6px;
  font-size: 12px;
}
.rv-input:focus-visible { outline: none; border-color: var(--accent); }
.rv-editor-where { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; font-size: 11px; }
.rv-editor-box { font-family: "Cascadia Mono", Consolas, monospace; color: var(--text-dim); }
.rv-editor-uses { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.rv-editor-uses .rv-btn { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rv-editor-buttons { display: flex; justify-content: flex-end; gap: 5px; margin-top: 7px; }
.rv-editor-buttons .rv-editor-save { border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* Review tab */
.rv-summary { display: flex; gap: 12px; align-items: center; padding: 6px 2px 10px; }
.rv-metric { display: flex; flex-direction: column; align-items: center; min-width: 70px; max-width: 110px; text-align: center; }
.rv-big { font-size: 22px; font-weight: 700; color: var(--good); }
.rv-metric-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-dim); }
.rv-summary-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.rv-progress { height: 6px; border-radius: 999px; background: var(--bg-soft); overflow: hidden; }
.rv-progress-bar { height: 100%; background: var(--good); transition: width 0.2s ease; }
.rv-counts { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 11px; }
.rv-reviewed { color: var(--text); margin-right: 4px; }
.rv-dim { color: var(--text-dim); }
.rv-section { padding: 8px 2px 10px; border-bottom: 1px solid var(--border); }
.rv-section:last-of-type { border-bottom: 0; }
.rv-section-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 2px 8px; margin-bottom: 4px; }
.rv-section-title { margin: 0; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text); }
.rv-section-sub { font-size: 10.5px; color: var(--text-dim); }
.rv-section-text { font-size: 11.5px; margin-bottom: 4px; }
.rv-sync { color: var(--good); }
.rv-section .rv-summary { padding: 4px 0 6px; }
.rv-footer { font-size: 10.5px; padding: 6px 2px; border-bottom: 1px solid var(--border); }
.rv-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; padding: 8px 0 0; border-top: 1px dashed var(--border); }
.rv-reviewer { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text-dim); margin-right: auto; }
.rv-reviewer .rv-input { width: 130px; }
.rv-hint { font-size: 11px; color: var(--warn); padding: 8px 2px 0; }
.rv-filter { padding: 8px 2px; }
.rv-select { background: var(--bg-soft); border: 1px solid var(--border); border-radius: 6px; padding: 4px; font-size: 11px; }
.rv-list { display: flex; flex-direction: column; gap: 4px; }
.rv-item {
  border: 1px solid transparent;
  border-left: 3px solid var(--border);
  border-radius: 5px;
  background: var(--bg-soft);
  padding: 4px 7px;
  cursor: pointer;
}
.rv-item:hover, .rv-item.hover { border-color: var(--accent); }
.rv-item.rv-v-pending { border-left-color: var(--rv-pending); }
.rv-item.rv-v-accepted { border-left-color: var(--rv-accepted); }
.rv-item.rv-v-rejected, .rv-item.rv-v-row_removed { border-left-color: var(--rv-rejected); }
.rv-item.rv-v-corrected { border-left-color: var(--rv-corrected); }
.rv-item.rv-v-added, .rv-item.rv-v-row_added { border-left-color: var(--rv-added); }
.rv-item-head { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; font-size: 11.5px; }
.rv-item-label { font-weight: 600; }
.rv-item-values { display: flex; flex-wrap: wrap; gap: 8px; font-size: 11px; color: var(--text-dim); margin-top: 2px; word-break: break-word; }

/* Drawing a box on the page for a corrected or added field. */
.overlay-pick { z-index: 8; pointer-events: none; }
.page-stage.picking { cursor: crosshair; }
.page-stage.picking .overlay:not(.overlay-pick) { pointer-events: none; }
.pick-band { position: absolute; border: 1.5px dashed var(--good); background: rgba(52, 211, 153, 0.12); }
.pick-box { position: absolute; border: 2px solid var(--good); background: rgba(52, 211, 153, 0.18); box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4); border-radius: 2px; }

.lib-tag-gt { border-color: #86efac; color: #86efac; }
.lib-tag-review { border-color: var(--warn); color: var(--warn); border-style: dashed; }

/* ---------- processing history ---------- */
.source-chip { display: inline-flex; align-items: center; gap: 2px; }
.source-ghost {
  font-weight: 700;
  letter-spacing: 0.4px;
  color: var(--src-color, var(--text-dim));
  opacity: 0.5;
  border: 1px dashed var(--src-color, var(--border));
  border-radius: 4px;
  padding: 0 2px 0 5px;
}
.source-ghost:hover { opacity: 0.85; }
.run-menu-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  padding: 2px 3px;
}
.run-menu-btn:hover { color: var(--text); border-color: var(--border); background: var(--bg-soft); }
.run-menu {
  position: fixed;
  z-index: 60;
  min-width: 280px;
  max-width: 420px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 4px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-top: 2px solid var(--src-color, var(--border));
  border-radius: 6px;
  box-shadow: var(--shadow);
}
.run-menu-title {
  padding: 4px 8px 6px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
}
.run-menu-item {
  display: grid;
  grid-template-columns: 14px 1fr;
  gap: 0 6px;
  width: 100%;
  padding: 5px 8px;
  text-align: left;
  background: none;
  border: none;
  border-radius: 4px;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
}
.run-menu-item:hover { background: var(--bg-soft); }
.run-menu-item.current { color: var(--src-color, var(--accent)); }
.run-menu-tick { grid-row: span 2; color: var(--src-color, var(--accent)); }
.run-menu-detail { grid-column: 2; font-size: 11px; color: var(--text-dim); }

/* A run count is the filled last segment of its badge, inside the badge's border. */
.src-badge .src-count,
.lib-tag .lib-tag-count {
  align-self: stretch;
  display: inline-flex;
  align-items: center;
  margin: 0 -4px 0 2px;
  padding: 0 4px;
  border-radius: 0 3px 3px 0;
  background: var(--src-color);
  color: #0b1120;
  font-size: 9px;
  font-weight: 700;
  opacity: 1;
}
.lib-tag .lib-tag-count { margin-right: -5px; background: var(--good); }

#tab-history { padding: 8px 10px 16px; }
.hist-section { margin-bottom: 14px; }
.hist-section-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.hist-section-title { font-weight: 600; }
.hist-count { color: var(--text-dim); font-size: 11px; }
.hist-section-head .text-btn { margin-left: auto; }
.hist-entry {
  padding: 6px 8px;
  margin-bottom: 4px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: 4px;
  background: var(--bg-soft);
}
.hist-entry.current { border-left-color: var(--src-color, var(--accent)); }
.hist-entry.file { border-style: dashed; border-left-style: solid; }
.hist-head { display: flex; align-items: center; gap: 6px; }
.hist-when { font-weight: 600; font-variant-numeric: tabular-nums; }
.hist-shown { border-color: var(--src-color, var(--accent)); color: var(--src-color, var(--accent)); }
.hist-actions { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; }
.hist-actions .icon-btn { margin-left: 0; }
.hist-detail { margin-top: 2px; font-size: 12px; }
.hist-meta { margin-top: 2px; font-size: 11px; color: var(--text-dim); overflow-wrap: anywhere; }
/* ---------- narrow windows ---------- */
@media (max-width: 1200px) {
  .layout { --panel-w: 360px; --library-w: 220px; }
  .thumbs { width: 84px; }
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(200px, 45vh) minmax(0, 1fr);
    grid-template-areas: "viewer" "panel";
  }
  /* The thumbnail rail and the splitters would claim their own grid row here; the
     toolbar still pages, and the panel is stacked rather than resized sideways. */
  .thumbs, .splitter { display: none; }
  .panel { border-top: 1px solid var(--border); }
  /* The Library becomes a drawer over the page; folded, it is gone entirely and the
     header button brings it back. */
  .library {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 56;
    width: min(300px, 85vw);
    box-shadow: var(--shadow);
  }
  .layout.library-collapsed .library { display: none; }
  #library-toggle { display: flex; }
  .layout.panel-wide {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas: "panel";
  }
  .layout.panel-folded {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
  }
  .layout.panel-folded .panel-rail { flex-direction: row; padding: 4px 10px; }
  .layout.panel-folded .rail-btn { writing-mode: horizontal-tb; padding: 4px 12px; }
  .topbar { flex-wrap: wrap; gap: 10px 16px; }
  .doc-stats { margin-left: 0; justify-content: flex-start; }
  .canvas-wrap { padding: 10px; }
}
