/* Invoice reader. One accent (blue); amber marks what is in doubt; green/red only for status. */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e1e4e9;
  --border-strong: #c9ced6;
  --text: #19212c;
  --muted: #5b6575;
  --accent: #2b5bd7;
  --accent-text: #ffffff;
  --accent-soft: #e8eefc;
  --doubt: #b25e00;          /* text on light */
  --doubt-line: #e39a2b;     /* frames, underlines */
  --doubt-soft: #fff3df;
  --ok: #1d7a4b;
  --ok-soft: #e3f4ea;
  --bad: #b42318;
  --bad-soft: #fdecea;
  --page-shadow: 0 1px 2px rgba(16, 24, 40, .08), 0 2px 8px rgba(16, 24, 40, .06);
  --radius: 10px;
  --focus: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #191d23;
    --surface-2: #20252d;
    --border: #2b313b;
    --border-strong: #3b4350;
    --text: #e5e8ed;
    --muted: #98a2b1;
    --accent: #7ea2ff;
    --accent-text: #0c1426;
    --accent-soft: #1d2a47;
    --doubt: #f2b75e;
    --doubt-line: #e9a23b;
    --doubt-soft: #332613;
    --ok: #5fcf95;
    --ok-soft: #15301f;
    --bad: #ff8a80;
    --bad-soft: #3a1714;
    --page-shadow: 0 1px 3px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
p { margin: 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
#view:focus { outline: none; }

/* ------------------------------------------------------------ chrome */
.topbar {
  display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap;
  padding: 14px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-weight: 600; font-size: 16px; }
.brand-mark { width: 22px; height: 22px; color: var(--accent); align-self: center; }
.topbar-note { color: var(--muted); font-size: 13.5px; }
main { padding: 24px 28px 40px; max-width: 1480px; margin: 0 auto; }
.banner { background: var(--bad-soft); color: var(--bad); text-align: center; font-size: 14px; padding: 8px 16px; border-bottom: 1px solid var(--border); }

/* the access code */
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 0; width: min(420px, calc(100vw - 32px)); box-shadow: var(--page-shadow); }
dialog::backdrop { background: rgba(16, 24, 40, .45); }
dialog form { display: grid; gap: 10px; padding: 22px; }
dialog p { font-size: 14px; }
dialog label { font-size: 13.5px; font-weight: 500; margin-top: 4px; }
dialog input { font: inherit; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); color: var(--text); }
dialog input:focus-visible { outline: none; box-shadow: var(--focus); border-color: var(--accent); }
.field-error { color: var(--bad); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* ------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-size: 14px; font-weight: 500;
  border-radius: 8px; border: 1px solid transparent;
  padding: 7px 14px; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-quiet { background: transparent; color: var(--muted); border-color: transparent; padding: 5px 8px; }
.btn-quiet:hover { color: var(--text); background: var(--surface-2); }
.btn-accept { background: var(--accent); color: var(--accent-text); padding: 5px 12px; font-size: 13.5px; }
.btn-keep { background: transparent; color: var(--text); border-color: var(--border-strong); padding: 5px 12px; font-size: 13.5px; }
.btn-keep:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn .muted { font-weight: 400; font-size: 12.5px; }
.agrees { font-size: 11.5px; font-weight: 500; padding: 1px 6px; border-radius: 999px; background: color-mix(in srgb, var(--accent-text) 22%, transparent); }

/* ------------------------------------------------------------ home */
.home { display: grid; gap: 28px; }
.upload-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; display: grid; gap: 18px;
}
.dropzone {
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius);
  padding: 28px 16px; display: grid; justify-items: center; gap: 6px; text-align: center;
  transition: background .15s, border-color .15s;
}
.dropzone.is-over { background: var(--accent-soft); border-color: var(--accent); }
.drop-icon { width: 30px; height: 30px; color: var(--muted); }
.drop-title { font-weight: 600; font-size: 16px; }
.drop-sub { color: var(--muted); font-size: 13.5px; margin-bottom: 8px; }
.dropzone label.btn:has(+ input:focus-visible) { box-shadow: var(--focus); }
.upload-error { color: var(--bad); background: var(--bad-soft); border-radius: 6px; padding: 6px 10px; font-size: 13.5px; margin-top: 6px; }

.samples { display: flex; align-items: center; gap: 6px 12px; flex-wrap: wrap; }
.samples-label { color: var(--muted); font-size: 14px; }
.samples-note { color: var(--muted); font-size: 12.5px; flex-basis: 100%; }
.sample-buttons { display: flex; gap: 8px; flex-wrap: wrap; }

.privacy {
  display: flex; gap: 10px; align-items: flex-start;
  font-size: 13.5px; color: var(--muted);
  border-top: 1px solid var(--border); padding-top: 14px;
}
.privacy svg { width: 18px; height: 18px; flex: none; margin-top: 2px; color: var(--muted); }
.privacy strong { color: var(--text); font-weight: 600; }

.section-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }

/* document list */
.doctable { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.doctable th { text-align: left; font-size: 12.5px; font-weight: 500; color: var(--muted); padding: 10px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.doctable td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; font-size: 14px; }
.doctable tr:last-child td { border-bottom: 0; }
.doctable tbody tr { cursor: pointer; }
.doctable tbody tr:hover td { background: var(--surface-2); }
.doctable .fname a { color: var(--text); font-weight: 500; text-decoration: none; overflow-wrap: anywhere; }
.doctable .fname a:hover { text-decoration: underline; }
.doctable .fname .muted { font-size: 12.5px; display: block; }
.doctable th.num { text-align: right; }
.empty { background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius); padding: 28px; text-align: center; color: var(--muted); }
.needs-code { display: grid; gap: 12px; justify-items: center; }

/* status badge */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 500; line-height: 1;
  padding: 5px 9px; border-radius: 999px; white-space: nowrap;
  background: var(--surface-2); color: var(--muted);
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.needs_review { background: var(--doubt-soft); color: var(--doubt); }
.badge.failed { background: var(--bad-soft); color: var(--bad); }
.badge.processing { background: var(--accent-soft); color: var(--accent); }
.badge.processing::before { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }

.progress { display: grid; gap: 5px; min-width: 150px; max-width: 220px; justify-items: start; }
.progress .bar { width: 100%; }
.progress-text { font-size: 12.5px; color: var(--muted); }
.bar { height: 5px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; width: 0; height: 100%; background: var(--accent); border-radius: 3px; transition: width .4s; }

/* ------------------------------------------------------------ review */
.review { display: grid; gap: 16px; }
.review-head { display: grid; gap: 4px; }
.back { font-size: 14px; text-decoration: none; width: fit-content; }
.back:hover { text-decoration: underline; }
.review-title { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.review-title h1 { overflow-wrap: anywhere; }
.review-meta { font-size: 13.5px; }

/* header fields */
.fields {
  display: grid; grid-template-columns: 2.2fr 1.3fr 1fr .7fr 1fr 1fr 1.1fr; gap: 1px;
  margin: 0; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.fields > div { padding: 12px 16px; background: var(--surface); min-width: 0; }
.fields dt { font-size: 12.5px; color: var(--muted); margin-bottom: 2px; }
.fields dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.fields .money dd { font-variant-numeric: tabular-nums; }
.fields .sub { display: block; font-size: 12.5px; color: var(--muted); font-weight: 400; }
.fields .total dd { font-size: 17px; font-weight: 600; }
.fields .doubt dd { color: var(--doubt); font-weight: 600; }

/* the split */
.workarea {
  display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); gap: 16px;
  height: calc(100vh - 120px); min-height: 520px;
}
.docpane, .datapane {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: auto; overscroll-behavior: contain; min-height: 0;
}
.docpane { position: relative; background: var(--surface-2); padding: 16px; scroll-behavior: auto; }
.docpane:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* pages and the marks on them (placed in percent of the page box) */
.pages { display: grid; gap: 16px; }
.page { position: relative; background: #fff; box-shadow: var(--page-shadow); border-radius: 2px; overflow: hidden; outline: 3px solid transparent; transition: outline-color .3s; }
.page canvas, .page img { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
.page img { object-fit: contain; background: #2a2a2a; }
.page.is-target { outline-color: var(--doubt-line); }
.page-label { position: absolute; right: 8px; bottom: 6px; font-size: 11px; color: #6b7280; background: rgba(255,255,255,.85); padding: 1px 6px; border-radius: 4px; }
.page-loading { position: absolute; inset: 0; display: grid; place-items: center; color: #9ca3af; font-size: 13px; }
.page canvas ~ .page-loading { display: none; }

.mark { position: absolute; pointer-events: none; border-radius: 3px; }
.mark.value { border: 2px solid var(--doubt-line); background: rgba(227, 154, 43, .10); margin: -3px; padding: 3px; box-sizing: content-box; }
.mark.value.is-active { box-shadow: 0 0 0 4px rgba(227, 154, 43, .28); animation: ring 1.2s ease-out 1; }
.mark.band { background: rgba(227, 154, 43, .20); border-top: 1.5px solid var(--doubt-line); border-bottom: 1.5px solid var(--doubt-line); border-radius: 0; }
.mark.band.is-active { background: rgba(227, 154, 43, .32); }
.mark.focus-band { background: rgba(43, 91, 215, .10); border-left: 3px solid #2b5bd7; border-radius: 0; }
.mark.resolved { border-color: #1d7a4b; background: rgba(29, 122, 75, .08); }
.mark.band.resolved { background: rgba(29, 122, 75, .12); border-color: #1d7a4b; }
.mark.resolved.is-active { box-shadow: 0 0 0 4px rgba(29, 122, 75, .22); }
@keyframes ring { 0% { box-shadow: 0 0 0 10px rgba(227, 154, 43, 0); } 30% { box-shadow: 0 0 0 6px rgba(227, 154, 43, .45); } 100% { box-shadow: 0 0 0 4px rgba(227, 154, 43, .28); } }

/* data pane */
.datapane { position: relative; display: flex; flex-direction: column; }
#r-body { display: flex; flex-direction: column; min-height: 100%; }
.summary { padding: 16px 18px; border-bottom: 1px solid var(--border); display: grid; gap: 10px; }
.summary h2 { font-size: 16px; }
.summary p { color: var(--muted); font-size: 14px; }
.summary.ok h2 { color: var(--ok); display: flex; align-items: center; gap: 8px; }
.summary.ok h2 svg { width: 20px; height: 20px; }

.switch { display: inline-flex; align-items: center; gap: 8px; font: inherit; font-size: 13.5px; color: var(--text); background: none; border: 0; cursor: pointer; padding: 4px 2px; }
.switch .track { width: 30px; height: 18px; border-radius: 9px; background: var(--border-strong); position: relative; transition: background .15s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch[aria-checked="true"] .track { background: var(--accent); }
.switch[aria-checked="true"] .track::after { transform: translateX(12px); }
.switch:focus-visible { outline: none; }
.switch:focus-visible .track { box-shadow: var(--focus); }

/* an issue of a page or of the document (no row) */
.docissue { margin: 14px 18px 0; padding: 12px 14px; border-radius: 8px; background: var(--doubt-soft); border-left: 3px solid var(--doubt-line); display: grid; gap: 4px; }
.docissue-title { font: inherit; font-weight: 600; font-size: 14px; color: var(--doubt); display: flex; align-items: center; gap: 6px; background: none; border: 0; padding: 0; cursor: pointer; width: fit-content; }
.docissue-title svg { width: 14px; height: 14px; }
.docissue-title:hover { text-decoration: underline; }
.docissue p { font-size: 14px; }
.docissue > .why-actions, .docissue > .resolved-note { margin-top: 6px; padding-left: 0; }
.docissue.is-resolved { background: var(--surface-2); border-left-color: var(--ok); }
.docissue.is-resolved .docissue-title { color: var(--muted); }

/* rows */
.rows { padding: 6px 0 12px; }
.rows-head, .row-main {
  display: grid;
  grid-template-columns: 7.2em minmax(0, 1fr) 4.6em 3.2em 5.2em 3.4em 6.4em;
  gap: 10px; align-items: baseline; padding: 0 18px;
}
.rows-head { position: sticky; top: 0; z-index: 2; background: var(--surface); font-size: 12px; color: var(--muted); padding-top: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.rows-head .num { text-align: right; }
.page-sep { font-size: 12px; font-weight: 600; color: var(--muted); padding: 12px 18px 4px; letter-spacing: .02em; text-transform: uppercase; }

.row { border-bottom: 1px solid var(--border); scroll-margin-top: 40px; }
.row:last-child { border-bottom: 0; }
.row-main { padding-top: 9px; padding-bottom: 9px; font-size: 14px; cursor: pointer; border-left: 3px solid transparent; padding-left: 15px; }
.row-main:hover { background: var(--surface-2); }
.row-main:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 0; }
.row.is-selected .row-main { border-left-color: var(--accent); background: var(--accent-soft); }
.cell { min-width: 0; overflow-wrap: anywhere; }
.cell.sku { font-variant-numeric: tabular-nums; font-size: 13.5px; }
.cell.desc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.problem .cell.desc { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.cell.unit { color: var(--muted); }
.cell.doubt { color: var(--doubt); font-weight: 600; }
.cell.doubt span { background: var(--doubt-soft); box-shadow: inset 0 -2px 0 var(--doubt-line); padding: 1px 4px; border-radius: 3px; }

.cell.fixed span { color: var(--ok); font-weight: 600; }
.was { display: block; font-size: 11.5px; color: var(--muted); text-decoration: line-through; font-weight: 400; }
.cell.fixed .was { color: var(--muted); font-weight: 400; }
.fields .checked dd { color: var(--ok); }

.why { padding: 0 18px 12px 18px; display: grid; gap: 10px; }
.why-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding-left: 24px; }
.choice-intro { font-size: 13.5px; padding-left: 24px; }
.resolved-note { font-size: 13.5px; color: var(--ok); display: flex; align-items: center; gap: 6px; padding-left: 24px; }
.resolved-note svg { width: 16px; height: 16px; flex: none; }
.resolved-note .btn-quiet { font-size: 13px; }
.issue-error { font-size: 13.5px; color: var(--bad); padding-left: 24px; }
.row.is-resolved .why-text { color: var(--muted); }
.row.is-resolved .why-text svg { color: var(--muted); }
.allclear { margin: 18px; padding: 14px; border-radius: 8px; background: var(--ok-soft); color: var(--ok); font-weight: 500; font-size: 14px; }
.why-text { font-size: 14px; display: flex; gap: 8px; align-items: flex-start; }
.why-text svg, .follows svg { width: 16px; height: 16px; flex: none; margin-top: 3px; color: var(--doubt); }
.follows { font-size: 13.5px; color: var(--muted); display: flex; gap: 8px; margin-left: 24px; padding-left: 10px; border-left: 2px solid var(--border); }
.follows-label { font-weight: 600; }
.follows.is-settled { color: var(--ok); border-left-color: var(--ok); }
.follows.is-settled svg { color: var(--ok); }

/* waiting, reading, failed */
.state { padding: 28px 24px; display: grid; gap: 14px; align-content: start; }
.state h2 { font-size: 18px; }
.state .bar { height: 7px; }
.state.failed h2 { color: var(--bad); }
.state .reason { font-size: 15px; }
.state .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.state .fine { font-size: 13px; color: var(--muted); }
.read-before { border-top: 1px solid var(--border); }
.read-before > summary { cursor: pointer; padding: 12px 18px; font-size: 14px; }
#r-body > .empty { margin: 18px; }

/* details (diagnostics) */
.details { margin-top: auto; border-top: 1px solid var(--border); }
.details > summary { list-style: none; cursor: pointer; padding: 12px 18px; font-size: 13.5px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.details > summary::-webkit-details-marker { display: none; }
.details > summary::before { content: "›"; display: inline-block; transition: transform .15s; font-size: 16px; line-height: 1; }
.details[open] > summary::before { transform: rotate(90deg); }
.details > summary:hover { color: var(--text); }
.details > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 0; }
.details-body { padding: 0 18px 18px; display: grid; gap: 16px; font-size: 13px; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px 16px; margin: 0; }
.kv dt { color: var(--muted); font-size: 12px; }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 500; overflow-wrap: anywhere; }
.mini { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.mini th { text-align: left; font-weight: 500; color: var(--muted); padding: 4px 8px 4px 0; border-bottom: 1px solid var(--border); }
.mini td { padding: 4px 8px 4px 0; border-bottom: 1px solid var(--border); vertical-align: top; }
.mini th.num, .mini td.num { text-align: right; white-space: nowrap; }
.mini td.model { white-space: nowrap; }
.details-body > div:has(.mini) { overflow-x: auto; }
.details h3 { font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .03em; }

/* ------------------------------------------------------------ narrow screens */
@media (max-width: 1100px) {
  .fields { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .fields > div:first-child { grid-column: span 2; }
}
@media (max-width: 960px) {
  main { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .workarea { grid-template-columns: 1fr; grid-template-rows: 42vh minmax(0, 1fr); height: calc(100vh - 40px); }
  .rows-head, .row-main { grid-template-columns: 6.4em minmax(0, 1fr) 4.2em 4.8em 3.2em 6em; }
  .rows-head .h-unit, .cell.unit { display: none; }
  .doctable .col-size, .doctable .col-time { display: none; }
}
@media (max-width: 640px) {
  .fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rows-head, .row-main { grid-template-columns: 5.6em minmax(0, 1fr) 3.4em 3em 5.6em; gap: 8px; }
  .rows-head .h-price, .cell.price { display: none; }
  .doctable .col-pages { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
