:root {
  --bg: #f4f6f8; --card: #ffffff; --ink: #1c2530; --muted: #66727f; --line: #e1e6eb; --accent: #1f5fbf;
  --high: #1c7c3b; --high-bg: #e3f5e8; --med: #9a6700; --med-bg: #fff3d1; --low: #b42318; --low-bg: #fde7e4;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #11161c; --card: #19212a; --ink: #e6ebf0; --muted: #93a0ad; --line: #2a3541; --accent: #6aa5ff;
          --high: #66d98a; --high-bg: #163a24; --med: #f0c05a; --med-bg: #3a2f10; --low: #ff8f84; --low-bg: #44201c; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
.topbar { display: flex; align-items: baseline; gap: 14px; padding: 12px 24px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-weight: 650; color: var(--ink); text-decoration: none; font-size: 17px; }
.tag, .muted { color: var(--muted); } .small { font-size: 13px; }
.container { max-width: 1280px; margin: 0 auto; padding: 20px 16px 60px; }
h1 { font-size: 21px; margin: 0 0 6px; } h2 { font-size: 16px; margin: 0 0 8px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; margin-bottom: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; } .between { justify-content: space-between; }
.link { color: var(--accent); text-decoration: none; } .link:hover { text-decoration: underline; }
.mono { font-family: var(--mono); font-size: .92em; }
.banner { border-radius: 8px; padding: 10px 14px; margin: 0 0 14px; border: 1px solid; }
.banner.error { background: var(--low-bg); color: var(--low); border-color: var(--low); }
.banner.warn { background: var(--med-bg); color: var(--med); border-color: var(--med); }
.banner.ok { background: var(--high-bg); color: var(--high); border-color: var(--high); }
.drop { display: flex; flex-direction: column; gap: 6px; align-items: center; justify-content: center; border: 2px dashed var(--line);
        border-radius: 10px; padding: 40px 16px; cursor: pointer; text-align: center; }
.drop:hover, .drop.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, transparent); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
button.primary { margin-top: 14px; background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 10px 18px; font-size: 15px; cursor: pointer; }
button.primary:disabled { opacity: .5; cursor: default; }
.steps { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 6px; }
.steps li { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.steps li .dot { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); flex: none; }
.steps li.done { color: var(--ink); } .steps li.done .dot { background: var(--high); border-color: var(--high); }
.steps li.current { color: var(--ink); font-weight: 600; } .steps li.current .dot { border-color: var(--accent); border-top-color: transparent; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.summary { display: flex; gap: 28px; flex-wrap: wrap; align-items: center; }
.metric { display: grid; gap: 2px; } .metric .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.metric .value { font-size: 20px; font-weight: 650; }
.chip { display: inline-block; font-size: 11.5px; font-weight: 650; padding: 1px 8px; border-radius: 999px; letter-spacing: .02em; }
.chip.HIGH, .chip.valid, .chip.passed, .chip.approved { background: var(--high-bg); color: var(--high); }
.chip.MEDIUM, .chip.unverified, .chip.warnings, .chip.review { background: var(--med-bg); color: var(--med); }
.chip.LOW, .chip.invalid, .chip.failed, .chip.exception { background: var(--low-bg); color: var(--low); }
.layout { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 980px) { .layout { grid-template-columns: 1fr; } }
.scroll { overflow: auto; max-height: 520px; } .scroll.tall { max-height: 360px; }
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
table.grid th { text-align: left; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 6px 8px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--card); }
table.grid td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; word-break: break-word; }
table.grid tr.field { cursor: pointer; } table.grid tr.field:hover, table.grid tr.selected { background: color-mix(in srgb, var(--accent) 9%, transparent); }
.fname { font-family: var(--mono); font-size: 13px; } .num { text-align: right; font-variant-numeric: tabular-nums; }
.bar { width: 58px; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; display: inline-block; vertical-align: middle; margin-right: 6px; }
.bar > i { display: block; height: 100%; }
.bar.HIGH > i { background: var(--high); } .bar.MEDIUM > i { background: var(--med); } .bar.LOW > i { background: var(--low); }
.note { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.issues { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.issues li { padding: 7px 10px; border-radius: 6px; border-left: 3px solid; font-size: 14px; }
.issues li.error { background: var(--low-bg); border-color: var(--low); } .issues li.warning { background: var(--med-bg); border-color: var(--med); }
.issues li.info, .issues li.ok { background: var(--high-bg); border-color: var(--high); }
.preview { max-height: 760px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.stage { position: relative; } /* the overlay must span the whole image, not just the scrolled viewport */
.stage img { display: block; width: 100%; height: auto; } .overlay { position: absolute; inset: 0; pointer-events: none; }
.box { position: absolute; border: 2px solid; border-radius: 2px; pointer-events: auto; cursor: pointer; }
.box.HIGH { border-color: var(--high); background: rgba(28,124,59,.12); } .box.MEDIUM { border-color: var(--med); background: rgba(154,103,0,.14); }
.box.LOW { border-color: var(--low); background: rgba(180,35,24,.16); } .box.ocr { border: 1px solid rgba(31,95,191,.55); background: rgba(31,95,191,.07); }
.box.active { box-shadow: 0 0 0 3px rgba(31,95,191,.55); z-index: 3; }
.blocks { list-style: none; margin: 0; padding: 0; font-size: 13px; } .blocks li { display: flex; gap: 8px; padding: 3px 4px; border-bottom: 1px solid var(--line); }
.blocks li .c { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; width: 38px; } .blocks li.low .c { color: var(--low); font-weight: 650; }
select { background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; }
/* tables as printed: the headings are shown as the invoice prints them (no case change), a wide table scrolls sideways inside its card */
.scroll.wide { overflow-x: auto; max-height: none; -webkit-overflow-scrolling: touch; }
.scroll.wide:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
table.dyn { width: max-content; min-width: 100%; }
table.dyn th { text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--ink); vertical-align: bottom; min-width: 5.5rem; max-width: 16rem; white-space: normal; word-break: normal; overflow-wrap: anywhere; }
table.dyn th .h-text { display: block; font-weight: 650; }
table.dyn th .h-field { display: block; margin-top: 1px; font-size: 11px; font-weight: 400; color: var(--muted); text-transform: none; }
table.dyn th.no-heading .h-text { font-weight: 400; font-style: italic; color: var(--muted); }
table.dyn th.idx, table.dyn td.idx { position: sticky; left: 0; z-index: 1; background: var(--card); min-width: 2.4rem; }
table.dyn th.meta, table.dyn td.meta { min-width: 13rem; max-width: 24rem; } /* row notes stay readable without making every row tall */
table.dyn td.blank { color: var(--muted); }
table.dyn td.st-ambiguous, table.dyn td.st-unreadable { background: var(--low-bg); }
table.dyn td.st-inferred { background: var(--med-bg); }
table.dyn td .note.value { color: var(--accent); }
table.kv th.kv-label { text-align: left; font-weight: 600; text-transform: none; letter-spacing: 0; font-size: 14px; color: var(--ink); position: static; background: transparent; }
.table-card h2 .tid { font-weight: 400; }
.table-warnings { margin: 6px 0 8px; padding-left: 18px; color: var(--med); font-size: 13px; }
@media (max-width: 640px) { .container { padding-left: 10px; padding-right: 10px; } table.dyn { font-size: 13px; } table.dyn th { min-width: 4.5rem; } }
.layout > .col { min-width: 0; } /* a wide table scrolls inside its card instead of stretching the page */
table.dyn th.num { text-align: right; }
details.row-notes > summary { cursor: pointer; font-size: 12px; color: var(--muted); margin-top: 3px; }
table.dyn .note.warn { display: inline; margin-left: 4px; color: var(--med); cursor: help; }

/* reviewer feedback on the fields (static/js/feedback.js): a bar with the reviewer's name and progress, "Correct" / "Incorrect" buttons and a status chip in
   each row, a panel under the row for a correction */
.fb-bar { position: sticky; top: 0; z-index: 6; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; margin: 8px 0 10px; padding: 8px 12px;
          background: var(--card); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 2px 6px rgba(0,0,0,.08); }
.fb-bar[hidden] { display: none; }
.fb-who { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 650; }
.fb-who .fb-input { width: 14rem; font-weight: 400; }
.fb-bar.need-name .fb-input { border-color: var(--low); box-shadow: 0 0 0 3px var(--low-bg); }
.fb-progress { display: flex; align-items: center; gap: 8px; }
.fb-progress progress { width: 8rem; height: 8px; accent-color: var(--high); }
.fb-bar .note { flex-basis: 100%; margin: 0; }
.fb-bar-message { min-height: 1.2em; } .fb-bar-message.ok { color: var(--high); } .fb-bar-message.error { color: var(--low); }
.review-cell { white-space: nowrap; }
.fb-actions { display: flex; gap: 6px; }
.fb-state { display: flex; align-items: center; gap: 6px; margin-top: 4px; min-height: 1.4em; }
.fb-rowmsg { display: inline; margin: 0; }
.fb-btn { font: inherit; font-size: 13px; line-height: 1.2; padding: 5px 10px; border-radius: 6px; border: 1px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer; white-space: nowrap; }
.fb-btn:disabled { opacity: .5; cursor: default; }
.fb-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.fb-yes { color: var(--high); border-color: var(--high); } .fb-yes:hover:not(:disabled) { background: var(--high-bg); }
.fb-no { color: var(--low); border-color: var(--low); } .fb-no:hover:not(:disabled), .fb-no[aria-expanded="true"] { background: var(--low-bg); }
.link-button { background: none; border: 0; padding: 0 0 0 6px; color: var(--accent); cursor: pointer; font-size: 13px; }
.link-button:hover { text-decoration: underline; }
.chip.fb-unreviewed, .chip.fb-unavailable { background: var(--line); color: var(--muted); }
.chip.fb-confirmed { background: var(--high-bg); color: var(--high); }
.chip.fb-corrected, .chip.fb-not_present { background: var(--med-bg); color: var(--med); }
.chip.fb-incorrect, .chip.fb-conflict { background: var(--low-bg); color: var(--low); }
table.grid tr.review-row > td { background: color-mix(in srgb, var(--accent) 5%, transparent); padding: 10px 14px; }
table.grid tr.review-row[hidden] { display: none; }
.fb-original, .fb-status { margin: 0 0 6px; }
.fb-value { font-weight: 650; margin-right: 8px; }
.fb-positions, .fb-history { margin: 4px 0 8px; padding-left: 18px; color: var(--muted); }
.fb-inner { position: sticky; left: 0; max-width: min(100%, calc(100vw - 64px)); } /* 64px: the page and card padding on a phone */
.fb-field .fb-input { width: 100%; min-width: 0; }
.fb-history-box { margin-top: 10px; }
.fb-history-title { cursor: pointer; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-size: 12px; }
.fb-form { display: grid; gap: 10px; margin-top: 8px; }
.fb-choices { display: flex; flex-wrap: wrap; gap: 6px; }
.fb-choice { display: flex; gap: 6px; align-items: center; cursor: pointer; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); }
.fb-choice:hover { border-color: var(--accent); }
.fb-choice:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); font-weight: 600; }
.fb-fields { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: start; }
.fb-fields > .fb-field { flex: 1 1 15rem; }
.fb-field { display: grid; gap: 2px; }
.fb-input { background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font: inherit; max-width: 28rem; }
.fb-form [hidden], .review-panel [hidden] { display: none; }
.fb-submit { margin-top: 0; padding: 7px 14px; font-size: 14px; }
.fb-message { margin: 0; min-height: 1.2em; } .fb-message.ok { color: var(--high); } .fb-message.error { color: var(--low); }
