/* Tokens. Accounts-payable paper: cool off-white, blue-black ink, carbon-copy
   blue for values traced to the page, an auditor's red pencil for problems. */
:root {
  --paper: #F5F6F1;
  --slip: #FFFFFF;
  --ink: #1D2433;
  --muted: #5D6677;
  --rule: #D5DAD2;
  --carbon: #2F4AA0;
  --carbon-wash: #DCE3F7;
  --pencil: #B8322A;
  --pencil-wash: #F6E1DE;
  --ok: #2E6B45;

  --sans: "Instrument Sans", system-ui, sans-serif;
  --slip-face: "Courier Prime", "Courier New", monospace;

  /* Modular scale, ratio 1.25 from 16px. */
  --s-1: 0.8rem;
  --s0: 1rem;
  --s1: 1.25rem;
  --s2: 1.563rem;
  --s3: 1.953rem;
  --s4: 2.441rem;

  --gutter: clamp(16px, 4vw, 48px);
  color-scheme: light;
}

[hidden] { display: none !important; }

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 var(--s0)/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.15; font-weight: 600; }
p { margin: 0; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

:focus-visible { outline: 2px solid var(--carbon); outline-offset: 3px; }

/* ── masthead ─────────────────────────────────────────────── */

.masthead {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end;
  gap: 16px 32px;
  padding: 40px var(--gutter) 28px;
  max-width: 1180px; margin: 0 auto;
}
.masthead h1 { font-size: var(--s4); font-weight: 700; letter-spacing: -0.02em; }
.lede { margin-top: 10px; max-width: 34em; font-size: var(--s1); color: var(--muted); line-height: 1.4; }

.server { display: flex; align-items: center; gap: 8px; font-size: var(--s-1); color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.server[data-state="ready"] .dot { background: var(--ok); }
.server[data-state="waking"] .dot { background: var(--carbon); animation: pulse 1.4s ease-in-out infinite; }
.server[data-state="down"] .dot { background: var(--pencil); }
@keyframes pulse { 50% { opacity: 0.25; } }

main { max-width: 1180px; margin: 0 auto; padding: 0 var(--gutter) 48px; display: grid; gap: 40px; }

/* ── intake ───────────────────────────────────────────────── */

.drop { display: grid; gap: 12px; }
.drop-target {
  display: grid; gap: 4px; justify-items: center; text-align: center;
  padding: 28px 16px;
  border: 1.5px dashed var(--muted);
  border-radius: 4px;
  background: var(--slip);
  cursor: pointer;
}
.drop-target strong { font-size: var(--s1); font-weight: 600; }
.drop-target span { color: var(--muted); font-size: var(--s-1); }
.drop-target[data-over="true"], .drop-target:hover { border-color: var(--carbon); color: var(--carbon); }
.drop:has(input[type=file]:focus-visible) .drop-target { outline: 2px solid var(--carbon); outline-offset: 3px; }
.drop[aria-busy="true"] .drop-target { opacity: 0.55; cursor: progress; }

.drop-actions { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 24px; font-size: var(--s-1); }
.check { display: inline-flex; gap: 8px; align-items: center; }
.check input { accent-color: var(--carbon); width: 16px; height: 16px; }
.link-button {
  font: inherit; color: var(--carbon); background: none; border: 0; padding: 0;
  text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}
.link-button:disabled { color: var(--muted); cursor: default; }

.notice {
  padding: 12px 14px; border-left: 3px solid var(--pencil); background: var(--pencil-wash);
  font-size: var(--s-1);
}

/* ── run heading ──────────────────────────────────────────── */

.run-heading { display: grid; gap: 6px; border-bottom: 1px solid var(--rule); padding-bottom: 14px; }
.run-heading h2 { font-size: var(--s3); letter-spacing: -0.01em; }
.caption { color: var(--muted); font-size: var(--s-1); max-width: 60em; }

/* ── evidence: the page next to the record ────────────────── */

.evidence {
  display: grid; gap: 32px;
  grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  align-items: start;
}
.evidence h3, .timeline h3, .webhook h3 { font-size: var(--s1); margin-bottom: 4px; }

/* The one memorable thing: a paper slip whose lines are the OCR text, with
   carbon-blue marks where the model's values were found. */
.slip {
  margin: 14px 0 0;
  padding: 22px 22px 26px;
  background: var(--slip);
  font: 400 0.92rem/1.7 var(--slip-face);
  color: var(--ink);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 1px 0 var(--rule), 0 14px 28px -18px rgba(29, 36, 51, 0.35);
  border-top: 5px solid var(--carbon);
  max-height: 34rem; overflow: auto;
}
.slip mark {
  background: var(--carbon-wash);
  color: var(--carbon);
  font-weight: 700;
  border-bottom: 2px solid var(--carbon);
  padding: 0 1px;
}
.slip mark:target, .slip mark[data-active="true"] { background: var(--carbon); color: var(--slip); }

.fields, .lines { width: 100%; border-collapse: collapse; margin-top: 14px; font-size: 0.95rem; }
.fields th, .lines th {
  text-align: left; font-weight: 500; color: var(--muted); font-size: var(--s-1);
  padding: 0 10px 6px 0; border-bottom: 1.5px solid var(--ink);
}
.fields td, .lines td { padding: 9px 10px 9px 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
.fields td:nth-child(2) { font-variant-numeric: tabular-nums; font-weight: 500; }
.fields td:first-child { color: var(--muted); width: 32%; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.lines caption { text-align: left; font-weight: 600; padding: 22px 0 0; }

.found, .not-found, .not-checked { display: inline-flex; gap: 6px; align-items: baseline; font-size: var(--s-1); }
.found { color: var(--carbon); }
.found button {
  font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px;
}
.not-found { color: var(--pencil); font-weight: 600; }
.not-checked { color: var(--muted); }
.tick { font-weight: 700; }

.checks { margin-top: 22px; display: grid; gap: 8px; font-size: var(--s-1); }
.checks p { padding-left: 12px; border-left: 3px solid var(--ok); }
.checks p.error { border-left-color: var(--pencil); color: var(--pencil); }
.checks p.warning { border-left-color: var(--carbon); }

/* ── timeline: a real sequence, so it is numbered ─────────── */

.steps { list-style: none; margin: 14px 0 0; padding: 0; counter-reset: step; display: grid; gap: 0; }
.steps li {
  counter-increment: step;
  display: grid; grid-template-columns: 2.2rem minmax(0, 11rem) minmax(0, 1fr) auto;
  gap: 4px 12px; align-items: baseline;
  padding: 10px 0; border-bottom: 1px solid var(--rule);
}
.steps li::before { content: counter(step); color: var(--muted); font-variant-numeric: tabular-nums; }
.steps .name { font-weight: 600; }
.steps .detail { color: var(--muted); font-size: var(--s-1); }
.steps .time { font-variant-numeric: tabular-nums; font-size: var(--s-1); color: var(--muted); }
.steps li[data-kind="retry"] .name { color: var(--pencil); }
.steps li[data-kind="pending"] { color: var(--muted); }
.steps li[data-kind="pending"] .name::after { content: "…"; }

/* ── webhook ──────────────────────────────────────────────── */

.payload {
  margin: 12px 0 0; padding: 14px 16px; background: var(--slip);
  font: 400 0.8rem/1.55 var(--slip-face); white-space: pre-wrap; overflow-wrap: anywhere;
  max-height: 16rem; overflow: auto; border-left: 3px solid var(--carbon);
}

footer { max-width: 1180px; margin: 0 auto; padding: 0 var(--gutter) 48px; color: var(--muted); font-size: var(--s-1); }
footer p { max-width: 60em; padding-top: 24px; border-top: 1px solid var(--rule); }

@media (max-width: 820px) {
  .evidence { grid-template-columns: minmax(0, 1fr); }
  .masthead h1 { font-size: var(--s3); }
  /* Number and time stay on the name's row; the detail drops beneath the name. */
  .steps li {
    grid-template-columns: 2rem minmax(0, 1fr) auto;
    grid-template-areas: "num name time" ". detail detail";
  }
  .steps li::before { grid-area: num; }
  .steps .name { grid-area: name; }
  .steps .time { grid-area: time; }
  .steps .detail { grid-area: detail; }
  .steps .detail:empty { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .server[data-state="waking"] .dot { animation: none; }
  * { scroll-behavior: auto !important; }
}
