:root {
  --paper: #f4f3ef;
  --surface: #ffffff;
  --ink: #16191d;
  --ink-2: #4a5158;
  --ink-3: #7a8189;
  --line: #e2e0d9;
  --line-2: #c9c6bc;
  --dot: #d9d6cc;
  --accent: #0f6b52;
  --accent-2: #0b5340;
  --accent-tint: #e2f0ea;
  --on-accent: #ffffff;
  --panel: #16191d;
  --panel-ink: #f2f0ea;
  --panel-ink-2: #a9afb5;
  --panel-accent: #46c193;
  --on-panel-accent: #0a1712;
  --warn: #93560a;
  --warn-tint: #fcf0db;
  --warn-line: #d79a3c;
  --err: #a3261c;
  --err-tint: #fbe8e5;
  --dup: #1d5fb8;
  --focus: #2f7de1;
  --display: Bahnschrift, "DIN Alternate", "Segoe UI Variable Display", "Segoe UI", "Arial Narrow", sans-serif;
  --text: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", Consolas, Menlo, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #111316;
    --surface: #191c20;
    --ink: #ecebe6;
    --ink-2: #b3b8be;
    --ink-3: #868d94;
    --line: #2a2e33;
    --line-2: #3d434a;
    --dot: #2b3036;
    --accent: #4cc497;
    --accent-2: #6fd4ae;
    --accent-tint: #15291f;
    --on-accent: #08150f;
    --panel: #1f2328;
    --panel-ink: #ecebe6;
    --panel-ink-2: #a2a9b0;
    --panel-accent: #4cc497;
    --on-panel-accent: #08150f;
    --warn: #f0b764;
    --warn-tint: #2b2112;
    --warn-line: #a8742c;
    --err: #f2998f;
    --err-tint: #2f1714;
    --dup: #7db4f5;
    --focus: #6aa8f0;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  background: var(--paper); color: var(--ink); font: 15px/1.55 var(--text);
}
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-2); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- top bar ---- */
.topbar {
  width: 100%; max-width: 1040px; margin: 0 auto; padding: 18px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.wordmark {
  display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none;
  font: 600 1.05rem/1 var(--display); letter-spacing: .01em; white-space: nowrap;
}
.wordmark:hover { color: var(--ink); }
.mark { position: relative; width: 20px; height: 20px; }
.mark::before, .mark::after { content: ""; position: absolute; width: 13px; height: 14px; border-radius: 2px; }
.mark::before { left: 0; bottom: 0; background: var(--ink); }
.mark::after { right: 0; top: 0; background: var(--accent); }
.account { display: flex; gap: 14px; font-size: .875rem; min-width: 0; }
.account-name { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.demo-tag {
  font: 600 .72rem/1 var(--display); letter-spacing: .08em; text-transform: uppercase; white-space: nowrap;
  color: var(--warn); border: 1px dashed var(--warn-line); padding: 6px 9px; border-radius: 3px;
}

/* ---- page ---- */
.page { width: 100%; max-width: 1040px; margin: 0 auto; padding: 36px 20px 64px; flex: 1; }
.page-narrow { max-width: 720px; }
h1 { font: 600 2.2rem/1.1 var(--display); letter-spacing: -.01em; margin: 0 0 10px; }
h2 {
  font: 600 1.2rem/1.2 var(--display); margin: 48px 0 6px;
  display: flex; align-items: baseline; gap: 10px;
}
.count { font: 500 .85rem/1 var(--display); color: var(--ink-3); }
.sub { color: var(--ink-2); font-size: 1.02rem; margin: 0 0 28px; max-width: 60ch; word-break: break-word; }
.section-sub { color: var(--ink-3); margin: 0 0 14px; font-size: .9rem; }
.fine { color: var(--ink-3); font-size: .85rem; margin: 12px 0 0; max-width: 78ch; }
.back { display: inline-block; font-size: .9rem; margin-bottom: 18px; text-decoration: none; }
.back::before { content: "\2190\00a0"; }
.foot { text-align: center; color: var(--ink-3); font-size: .8rem; padding: 0 20px 28px; }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 22px; border-radius: 6px; border: 0; cursor: pointer;
  font: 600 1rem/1 var(--display); letter-spacing: .02em; text-decoration: none; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-2); color: var(--on-accent); }
.btn-primary:disabled { background: var(--line); color: var(--ink-3); cursor: not-allowed; }
.btn-wide { width: 100%; }
.btn-accent { background: var(--panel-accent); color: var(--on-panel-accent); min-width: 150px; }
.btn-accent:hover { filter: brightness(1.08); color: var(--on-panel-accent); }
.btn.is-done { background: transparent; color: var(--panel-ink-2); box-shadow: inset 0 0 0 1px var(--panel-ink-2); pointer-events: none; }

/* ---- drop zone ---- */
.upload-form { display: grid; gap: 14px; }
.dropzone {
  position: relative; display: grid; place-items: center; min-height: 300px; padding: 32px 20px;
  border: 2px dashed var(--line-2); border-radius: 10px; cursor: pointer; text-align: center;
  background-color: var(--surface);
  background-image: radial-gradient(var(--dot) 1.2px, transparent 1.2px);
  background-size: 20px 20px; background-position: 10px 10px;
  transition: border-color .15s, background-color .15s, transform .15s;
}
.dropzone > * { pointer-events: none; }                 /* drag events stay on the zone itself */
.dropzone:hover { border-color: var(--accent); }
.dropzone:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-tint); }
.dropzone.is-over { border-style: solid; border-color: var(--accent); background-color: var(--accent-tint); transform: scale(1.01); }
.dropzone.has-file { border-style: solid; border-color: var(--accent); min-height: 180px; }
.dropzone.is-busy { opacity: .6; pointer-events: none; }

.dz-empty, .dz-file { display: grid; justify-items: center; gap: 6px; }
.dz-art { width: 72px; height: 72px; color: var(--ink-2); margin-bottom: 8px; transition: transform .2s; }
.dz-art-head { fill: var(--accent); opacity: .18; }
.dropzone.is-over .dz-art { transform: translateY(-4px) rotate(-4deg); color: var(--accent); }
.dz-title { font: 600 1.45rem/1.2 var(--display); }
.dz-or { color: var(--ink-2); }
.dz-choose { color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.dz-hint { color: var(--ink-3); font-size: .82rem; margin-top: 6px; letter-spacing: .02em; }

.dz-file { grid-template-columns: auto 1fr auto; align-items: center; gap: 16px; width: 100%; max-width: 520px; text-align: left; }
.dz-file-badge {
  display: grid; place-items: center; width: 52px; height: 60px; border-radius: 4px;
  background: var(--accent); color: var(--on-accent); font: 700 .72rem/1 var(--display); letter-spacing: .06em;
}
.dz-file-text { display: grid; gap: 2px; min-width: 0; }
.dz-file-name { font: 600 1.05rem/1.3 var(--display); overflow-wrap: anywhere; }
.dz-file-meta { color: var(--ink-3); font-size: .85rem; }
.dz-change { color: var(--accent); font-weight: 600; font-size: .9rem; text-decoration: underline; text-underline-offset: 3px; }

.progress { display: grid; gap: 8px; }
.progress-track { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.progress.is-working .progress-fill { width: 30%; animation: sweep 1.3s ease-in-out infinite; }
@keyframes sweep { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
@media (prefers-reduced-motion: reduce) {
  .progress.is-working .progress-fill { animation: none; width: 100%; opacity: .45; }
  .dropzone, .dz-art { transition: none; }
}
.progress-text { margin: 0; color: var(--ink-2); font-size: .9rem; }

/* ---- sign-in and password forms ---- */
.auth { max-width: 420px; }
.auth-form { display: grid; gap: 6px; margin-top: 4px; }
.field-label { font: 600 .9rem/1.3 var(--display); letter-spacing: .02em; margin-top: 10px; }
.input {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 6px; border: 1px solid var(--line-2);
  background: var(--surface); color: var(--ink); font: inherit;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.auth-form .btn { margin-top: 20px; }
.auth .notice { margin-bottom: 8px; }

/* ---- notices ---- */
.notice { padding: 12px 16px; border-radius: 6px; border-left: 4px solid; margin: 0 0 20px; }
.notice-error { background: var(--err-tint); border-color: var(--err); }
.notice-info { background: var(--accent-tint); border-color: var(--accent); }
.upload-form .notice { margin: 0; }

/* ---- results ---- */
.figures {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  border-top: 2px solid var(--ink); border-bottom: 1px solid var(--line-2); margin: 8px 0 28px;
}
.fig { display: grid; gap: 4px; align-content: start; padding: 18px 20px 20px; border-left: 1px solid var(--line-2); }
.fig:first-child { border-left: 0; padding-left: 0; }
.fig-n { font: 600 2.6rem/1 var(--display); font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.fig-n small { font-size: 1rem; font-weight: 500; color: var(--ink-3); letter-spacing: 0; }
.fig-l { color: var(--ink-2); font-size: .88rem; }
.fig-warn .fig-n { color: var(--warn); }

.dl-panel {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  background: var(--panel); color: var(--panel-ink); border-radius: 10px; padding: 22px 24px;
}
.dl-info { display: grid; gap: 4px; min-width: 0; }
.dl-name { font: 600 1.05rem/1.3 var(--display); overflow-wrap: anywhere; }
.dl-meta { color: var(--panel-ink-2); font-size: .88rem; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.table-tall { max-height: 540px; overflow-y: auto; }
.grid { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
.grid th, .grid td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid thead th {
  position: sticky; top: 0; z-index: 1; background: var(--surface);
  font: 600 .74rem/1.2 var(--display); text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3);
  border-bottom: 1px solid var(--line-2);
}
.grid tbody tr:last-child td { border-bottom: 0; }
.grid tbody tr:hover { background: var(--paper); }
.grid .num { text-align: right; white-space: nowrap; }
.grid .ref { font: 600 .85rem/1.55 var(--mono); white-space: nowrap; color: var(--ink-2); }
.exceptions tbody td:first-child { box-shadow: inset 3px 0 0 var(--warn-line); }
.exceptions tr.ex-bad td:first-child { box-shadow: inset 3px 0 0 var(--err); }
.exceptions tr.ex-dup td:first-child { box-shadow: inset 3px 0 0 var(--dup); }
.issue { display: block; font-weight: 600; }
.row-issue { display: block; margin-top: 2px; font-size: .8rem; font-weight: 600; }
.issue-missing { color: var(--warn); }          /* PDF missing, no receipt, no supporting documents */
.issue-bad { color: var(--err); }               /* damaged or password-protected: can't be opened */
.issue-dup { color: var(--dup); }               /* the same PDF attached more than once */

.filter {
  width: 100%; max-width: 340px; margin: 10px 0 12px; padding: 10px 12px; border-radius: 6px;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); font: inherit; font-size: .9rem;
}
.filter:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }

.log { margin: 40px 0 0; }
.log summary { cursor: pointer; color: var(--ink-3); font-size: .875rem; }
.log pre {
  margin: 12px 0 0; padding: 14px 16px; border-radius: 8px; background: var(--surface); border: 1px solid var(--line);
  font: .8rem/1.55 var(--mono); color: var(--ink-2); white-space: pre-wrap; overflow-wrap: anywhere;
}
.page-narrow .log { margin-bottom: 24px; }

@media (max-width: 720px) {
  .topbar { padding: 14px 16px; }
  .demo-tag { letter-spacing: .04em; padding: 5px 7px; font-size: .66rem; }
  .page { padding-top: 20px; }
  h1 { font-size: 1.8rem; }
  .dropzone { min-height: 240px; }
  .figures { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fig { padding: 16px 14px; }
  .fig:nth-child(odd) { border-left: 0; padding-left: 0; }
  .fig:nth-child(n+3) { border-top: 1px solid var(--line-2); }
  .fig-n { font-size: 2.1rem; }
  .dl-panel { flex-direction: column; align-items: stretch; }
  .dz-file { grid-template-columns: auto 1fr; }
  .dz-change { grid-column: 2; justify-self: start; margin-top: -8px; }
}
