/*
 * InvoiceSnap. Tokens first; components only use tokens.
 * Look: a bookkeeper's ledger, not an app template. Paper and ink, serif headings like a printed
 * invoice, thin rules instead of boxes, square-ish corners, no soft shadows, statuses as text with
 * a dot, icons only where they help someone find the button. No blue anywhere, grays included.
 */

:root {
  --bg: #f4f1ea;
  --surface: #fffefb;
  --surface-2: #f7f4ee;
  --surface-3: #ebe6dc;
  --text: #1b1915;
  --text-2: #423d35;
  --text-3: #6f685d;
  --rule: #e2dccf;
  --rule-strong: #cbc3b4;
  --border-input: #8f877a;

  --ink: #1b1915;
  --ink-hover: #3a352d;
  --on-ink: #fffefb;
  --accent: #1e6141;
  --accent-hover: #164d33;
  --on-accent: #ffffff;
  --accent-soft: #e9f0e8;
  --link: #1e6141;
  --focus: #1e6141;
  --focus-ring: rgb(30 97 65 / 0.24);
  --mark-check: #5ccf8f;

  --ok: #1e6141;
  --ok-bg: #eef3ec;
  --ok-dot: #2f8a57;
  --warn: #855000;
  --warn-bg: #fbf4e2;
  --warn-dot: #c98a17;
  --warn-edge: #d9a640;
  --danger: #a3271a;
  --danger-bg: #fbefec;
  --danger-dot: #c4402f;
  --note-bg: #f7f4ee;
  --note-edge: #b8af9f;

  --toast-bg: #1b1915;
  --toast-text: #fffefb;

  --radius: 6px;
  --radius-sm: 4px;
  --shadow-pop: 0 16px 40px rgb(27 25 21 / 0.16), 0 2px 6px rgb(27 25 21 / 0.08);
  --scrim: rgb(27 25 21 / 0.45);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", Charter, "Sitka Heading", "Sitka Text", Cambria, Georgia, "Noto Serif", serif;
  --mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Menlo, Consolas, monospace;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;

  --t-fast: 120ms;
  --t-med: 180ms;
  --appbar-h: 60px;
  --content: 1080px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131210;
    --surface: #1b1a17;
    --surface-2: #22201c;
    --surface-3: #2c2924;
    --text: #efebe3;
    --text-2: #cfc8bc;
    --text-3: #a39b8d;
    --rule: #34302a;
    --rule-strong: #4a443b;
    --border-input: #7d7567;

    --ink: #efebe3;
    --ink-hover: #ffffff;
    --on-ink: #1b1915;
    --accent: #2a7a51;
    --accent-hover: #328c5e;
    --accent-soft: #1a2820;
    --link: #79cf9c;
    --focus: #79cf9c;
    --focus-ring: rgb(121 207 156 / 0.26);
    --mark-check: #1e6141;

    --ok: #79cf9c;
    --ok-bg: #18241c;
    --ok-dot: #5bbf86;
    --warn: #e7b55c;
    --warn-bg: #282013;
    --warn-dot: #e0a53b;
    --warn-edge: #a77a2a;
    --danger: #f0907f;
    --danger-bg: #2b1814;
    --danger-dot: #e06a57;
    --note-bg: #22201c;
    --note-edge: #6a6357;

    --toast-bg: #2c2924;
    --toast-text: #efebe3;

    --shadow-pop: 0 16px 40px rgb(0 0 0 / 0.55);
    --scrim: rgb(0 0 0 / 0.6);
    color-scheme: dark;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Components set display; the hidden attribute must still win. */
[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}

h1, h2, h3 {
  margin: 0;
  line-height: 1.2;
  color: var(--text);
}

/* Page titles and names read like a printed document. */
h1 { font-family: var(--serif); font-size: 2rem; font-weight: 500; letter-spacing: -0.01em; }
h2 { font-size: 1.0625rem; font-weight: 650; letter-spacing: -0.005em; }
h3 { font-size: 0.9375rem; font-weight: 650; }
@media (max-width: 480px) {
  h1 { font-size: 1.75rem; }
}

p { margin: 0; }

a {
  color: var(--link);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
a:hover { text-decoration-thickness: 2px; }

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.num {
  font-variant-numeric: tabular-nums;
}

.muted { color: var(--text-3); }
.small { font-size: 0.875rem; }
.nowrap { 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(--focus);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: 8px;
  top: -48px;
  z-index: 100;
  background: var(--surface);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
}
.skip-link:focus { top: 8px; }

/* ---------- logo ---------- */

.brand-mark { width: 30px; height: 30px; stroke: none; }
.brand-mark .bm-bg { fill: var(--ink); }
.brand-mark .bm-doc { fill: none; stroke: var(--on-ink); }
.brand-mark .bm-check { fill: none; stroke: var(--mark-check); }

/* ---------- top bar ---------- */

.appbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  min-height: var(--appbar-h);
  padding: env(safe-area-inset-top) max(var(--sp-4), env(safe-area-inset-right)) 0 max(var(--sp-4), env(safe-area-inset-left));
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  color: var(--text);
}
.appbar[hidden] { display: none; }

/* The name is the logo: a wordmark, like letterhead. */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  min-height: 44px;
}
.appbar .brand-mark { display: none; }
.brand-name {
  font-family: var(--serif);
  font-size: 1.375rem;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.appbar-right {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
}

.conn-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  max-width: 48vw;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  text-decoration: none;
  font-size: 0.875rem;
  white-space: nowrap;
  overflow: hidden;
}
.conn-pill:hover { color: var(--text); }
.conn-pill:hover .label { text-decoration: underline; text-underline-offset: 3px; }
.conn-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-3);
  flex: none;
}
.conn-pill.is-on .dot { background: var(--ok-dot); }
.conn-pill .env {
  padding: 0 5px;
  border: 1px solid var(--warn-edge);
  border-radius: 3px;
  color: var(--warn);
  font-size: 0.75rem;
  font-weight: 600;
}
.conn-pill .label { overflow: hidden; text-overflow: ellipsis; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn-on-dark { color: var(--text-2); }

/* ---------- layout ---------- */

#view {
  display: block;
  max-width: var(--content);
  margin: 0 auto;
  padding: var(--sp-5) max(var(--sp-4), env(safe-area-inset-right)) calc(var(--sp-7) + env(safe-area-inset-bottom)) max(var(--sp-4), env(safe-area-inset-left));
  outline: none;
}
#view.wide { max-width: 1280px; }
@media (min-width: 640px) {
  #view { padding-top: var(--sp-6); }
}

.boot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  min-height: 50vh;
  color: var(--text-3);
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
  padding-bottom: var(--sp-4);
  border-bottom: 1px solid var(--rule);
}
.page-head p { color: var(--text-3); margin-top: 6px; max-width: 40em; }

.stack > * + * { margin-top: var(--sp-4); }
.stack-lg > * + * { margin-top: var(--sp-5); }
.row { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }

/* A sheet of paper: flat, a hairline edge, no floating shadow. */
.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: var(--sp-4);
}
@media (min-width: 640px) {
  .card { padding: var(--sp-5) var(--sp-6); }
}
.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}
.card-head p { color: var(--text-3); font-size: 0.9375rem; margin-top: 4px; }

.section-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-3);
  margin: 0 0 var(--sp-3);
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 20px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
}
/* Words say what a button does; pictures only where they help find it. */
.btn svg { display: none; }
.capture .btn svg,
.dropzone .btn svg,
.btn[data-copy] svg { display: block; width: 18px; height: 18px; }

.btn-primary { background: var(--ink); color: var(--on-ink); }
.btn-primary:hover:not(:disabled) { background: var(--ink-hover); }
.btn-cta { background: var(--accent); color: var(--on-accent); }
.btn-cta:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { border-color: var(--border-input); background: var(--surface); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); border-color: var(--text-2); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
.btn-danger { background: transparent; color: var(--danger); border-color: transparent; }
.btn-danger:hover:not(:disabled) { text-decoration: underline; text-underline-offset: 3px; }
.btn-link {
  min-height: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--link);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 0.9375rem; }
.btn-lg { min-height: 52px; padding: 12px 24px; font-size: 1.0625rem; }
.btn-xl { min-height: 56px; width: 100%; max-width: 440px; padding: 14px 28px; font-size: 1.125rem; }
.btn-block { width: 100%; }

/* ---------- forms ---------- */

.field { display: block; min-width: 0; }
.field > span:first-child,
.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-2);
}
.field .hint {
  display: block;
  margin-top: 6px;
  font-size: 0.8125rem;
  color: var(--text-3);
}
.field .hint.warn { color: var(--warn); }

input[type="text"],
input[type="password"],
input[type="email"],
input[type="tel"],
input[type="url"],
input[type="date"],
input[type="search"],
input:not([type]),
select,
textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1.0625rem;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
textarea { min-height: 72px; max-height: 240px; resize: vertical; line-height: 1.4; field-sizing: content; }
select { cursor: pointer; padding-right: 32px; }
input:hover,
select:hover,
textarea:hover { border-color: var(--text-2); }
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
input::placeholder,
textarea::placeholder { color: var(--text-3); opacity: 0.85; }
input[readonly] { background: var(--surface-2); color: var(--text-2); }
input.num-input { text-align: right; font-variant-numeric: tabular-nums; }

.low-conf {
  border-color: var(--warn-edge) !important;
  background: var(--warn-bg) !important;
}
.low-conf:focus { border-color: var(--focus) !important; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  cursor: pointer;
  font-size: 0.9375rem;
}
.check input {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--accent);
  flex: none;
}

.grid-2 { display: grid; gap: var(--sp-4); grid-template-columns: 1fr; }
.grid-3 { display: grid; gap: var(--sp-4); grid-template-columns: 1fr; }
@media (min-width: 560px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 900px) {
  .grid-3 { grid-template-columns: 1fr 1fr 1fr; }
}
.span-all { grid-column: 1 / -1; }

.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.seg button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-height: 52px;
  padding: 8px 12px;
  border: 0;
  background: var(--surface);
  color: var(--text-2);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.seg button + button { border-left: 1px solid var(--border-input); }
.seg button strong { font-size: 0.9375rem; color: var(--text); }
.seg button small { font-size: 0.8125rem; color: var(--text-3); }
.seg button:hover { background: var(--surface-2); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); }
.seg button[aria-pressed="true"] strong,
.seg button[aria-pressed="true"] small { color: var(--on-ink); }
.seg.needs-choice { border-color: var(--warn-edge); }
.seg.needs-choice button { background: var(--warn-bg); }

/* ---------- statuses and notes ---------- */

/* A status is a word with a dot, not a badge. */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text-2);
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}
.chip::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-3);
  flex: none;
}
.chip:has(.spinner)::before { display: none; }
.chip .spinner { width: 12px; height: 12px; }
.chip-review { color: var(--warn); }
.chip-review::before { background: var(--warn-dot); }
.chip-sent { color: var(--ok); }
.chip-sent::before { background: var(--ok-dot); }
.chip-reading { color: var(--text-2); }
.chip-error { color: var(--danger); }
.chip-error::before { background: var(--danger-dot); }
.chip-kind { color: var(--text-3); }
.chip-env {
  padding: 0 5px;
  border: 1px solid var(--warn-edge);
  border-radius: 3px;
  color: var(--warn);
  font-size: 0.75rem;
}
.chip-env::before { display: none; }

/* Notes: a margin rule and plain words, like a bookkeeper's annotation. */
.callout {
  display: flex;
  gap: var(--sp-3);
  align-items: flex-start;
  padding: 10px 14px;
  border-left: 3px solid var(--note-edge);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--note-bg);
  color: var(--text);
  font-size: 0.9375rem;
}
.callout > svg { display: none; }
.callout ul { margin: 4px 0 0; padding-left: 18px; }
.callout-warn { border-left-color: var(--warn-edge); background: var(--warn-bg); }
.callout-error { border-left-color: var(--danger-dot); background: var(--danger-bg); }
.callout-ok { border-left-color: var(--ok-dot); background: var(--ok-bg); }
.callout .grow > * + * { margin-top: 6px; }
.callout strong { font-weight: 650; }

/* ---------- home ---------- */

.capture {
  display: grid;
  gap: var(--sp-3);
  grid-template-columns: 1fr 1fr;
}
.capture .btn { min-height: 76px; font-size: 1.0625rem; flex-direction: column; gap: 8px; }
.capture .btn svg { width: 24px; height: 24px; }

.dropzone {
  display: none;
  border: 1px dashed var(--border-input);
  border-radius: var(--radius);
  background: var(--surface);
  padding: var(--sp-5) var(--sp-6);
  transition: border-color var(--t-fast), background var(--t-fast);
}
.dropzone.is-over { border-color: var(--accent); border-style: solid; background: var(--accent-soft); }
.dropzone .drop-icon { display: none; }
.dropzone h2 { font-family: var(--serif); font-size: 1.375rem; font-weight: 500; letter-spacing: -0.01em; }
.dropzone p { color: var(--text-3); margin-top: 4px; }
.dropzone .row { margin-top: 0; flex-wrap: nowrap; }

@media (min-width: 900px) and (hover: hover) {
  .dropzone {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: var(--sp-5);
    align-items: center;
  }
  .dropzone h2,
  .dropzone p { grid-column: 1; }
  .dropzone .row { grid-column: 2; grid-row: 1 / span 2; }
  .capture { display: none; }
  /* the drop area already says this; the line stays for upload progress */
  .note.is-hint { display: none; }
}

.setup-steps { margin: 0; padding: 0; list-style: none; }
.setup-steps li {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 10px 0;
  border-top: 1px solid var(--rule);
}
.setup-steps li:first-child { border-top: 0; }
.step-dot {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1.5px solid var(--rule-strong);
  color: var(--text-3);
  font-size: 0.8125rem;
  font-weight: 700;
  flex: none;
}
.step-dot.done { border-color: var(--accent); background: var(--accent); color: var(--on-accent); }
.step-dot.done svg { width: 13px; height: 13px; stroke-width: 3; }

.tabs {
  display: flex;
  gap: var(--sp-5);
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--rule);
  margin-bottom: var(--sp-1);
}
.tabs button {
  min-height: 44px;
  padding: 8px 0;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  background: none;
  color: var(--text-3);
  font: inherit;
  font-weight: 600;
  font-size: 0.9375rem;
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--t-fast), border-color var(--t-fast);
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--ink); }
.tabs .count {
  margin-left: 6px;
  color: var(--text-3);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* The invoice list reads like ledger entries. */
.scan-list { list-style: none; margin: 0; padding: 0; }
.scan-row {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  gap: var(--sp-3);
  align-items: center;
  padding: 14px var(--sp-2);
  border-bottom: 1px solid var(--rule);
  color: inherit;
  text-decoration: none;
  transition: background var(--t-fast);
}
.scan-list li:last-child .scan-row { border-bottom: 0; }
.scan-row:hover { background: var(--surface-2); }
.thumb {
  width: 40px;
  height: 52px;
  border-radius: 2px;
  border: 1px solid var(--rule);
  background: var(--surface-2);
  object-fit: cover;
  display: grid;
  place-items: center;
  color: var(--text-3);
  overflow: hidden;
}
.thumb svg { width: 18px; height: 18px; }
.scan-main { min-width: 0; }
.scan-title {
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.scan-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 12px;
  margin-top: 2px;
  color: var(--text-3);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}
.scan-error { color: var(--danger); font-size: 0.875rem; margin-top: 2px; }
.scan-side { text-align: right; display: grid; justify-items: end; gap: 2px; }
.scan-amount { font-weight: 700; font-size: 1.0625rem; font-variant-numeric: tabular-nums; }

.note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 10px;
}
.note > svg { display: none; }
.list-foot { display: flex; justify-content: flex-end; padding-top: var(--sp-3); }

.empty {
  padding: var(--sp-6) var(--sp-2);
  color: var(--text-3);
}
.empty svg { display: none; }
.empty h3 { color: var(--text-2); margin-bottom: 4px; font-size: 1rem; }

/* ---------- check screen ---------- */

.review {
  display: grid;
  gap: var(--sp-5);
  grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 1000px) {
  .review { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); align-items: start; gap: var(--sp-6); }
  .review .doc-col { position: sticky; top: calc(var(--appbar-h) + var(--sp-4)); }
}

.doc-viewer {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
}
.doc-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  padding: 4px 6px 4px 14px;
  border-bottom: 1px solid var(--rule);
  font-size: 0.875rem;
  color: var(--text-3);
}
.doc-pages {
  max-height: 36vh;
  overflow: auto;
  background: var(--surface-3);
  padding: var(--sp-3);
  display: grid;
  gap: var(--sp-3);
}
@media (min-width: 640px) {
  .doc-pages { max-height: 50vh; }
}
@media (min-width: 1000px) {
  .doc-pages { max-height: calc(100vh - var(--appbar-h) - 120px); }
}
.doc-pages img {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
  box-shadow: 0 1px 3px rgb(27 25 21 / 0.18);
  cursor: zoom-in;
}
.doc-pages.zoomed img { width: 200%; max-width: none; cursor: zoom-out; }
.doc-pdf {
  display: block;
  width: 100%;
  height: 70vh;
  border: 0;
  background: #fff;
}
.doc-open {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-6) var(--sp-4);
  text-align: center;
  color: var(--text-3);
}

.match-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-top: 8px;
  font-size: 0.875rem;
  color: var(--text-2);
}
.match-line svg { display: none; }
.match-line .ok { color: var(--ok); font-weight: 600; }
.match-line .new { color: var(--text-2); font-weight: 600; }
.suggest {
  min-height: 36px;
  padding: 4px 12px;
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background var(--t-fast);
}
.suggest:hover { background: var(--surface-2); }

.picker {
  margin-top: var(--sp-2);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
}
.picker input { border: 0; border-bottom: 1px solid var(--rule); border-radius: 0; }
.picker input:focus { box-shadow: none; }
.picker ul { list-style: none; margin: 0; padding: 4px; max-height: 260px; overflow: auto; }
.picker li button {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.picker li button:hover,
.picker li button:focus-visible { background: var(--surface-2); }
.picker .picker-empty { padding: 10px; color: var(--text-3); font-size: 0.875rem; }

details.more > summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  color: var(--link);
  font-weight: 600;
  font-size: 0.9375rem;
  cursor: pointer;
  list-style: none;
}
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary svg { width: 16px; height: 16px; transition: transform var(--t-fast); }
details.more[open] > summary svg { transform: rotate(90deg); }
details.more[open] > .more-body { margin-top: var(--sp-3); }

/* lines: laid out by the form column's width (container query), not the window */
.lines { display: grid; gap: 0; container-type: inline-size; border-top: 1px solid var(--rule); }
.line {
  display: grid;
  gap: var(--sp-2) var(--sp-3);
  grid-template-columns: 1fr 1fr 1fr;
  padding: var(--sp-4) 0;
  border-bottom: 1px solid var(--rule);
}
.line.low-conf-line { box-shadow: inset 3px 0 0 var(--warn-edge); padding-left: var(--sp-3); }
.line .l-desc { grid-column: 1 / -1; }
.line .l-item { grid-column: 1 / -1; }
.line .l-foot {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
}
.line .l-warn { grid-column: 1 / -1; font-size: 0.8125rem; color: var(--warn); }
.line label > span:first-child { font-size: 0.8125rem; font-weight: 600; color: var(--text-3); display: block; margin-bottom: 4px; }
.line textarea { min-height: 44px; }
.line textarea { resize: none; }
@container (min-width: 720px) {
  .line { grid-template-columns: minmax(0, 2.4fr) minmax(0, 1.5fr) 80px 104px 116px; align-items: end; }
  .line .l-desc { grid-column: 1; grid-row: 1; }
  .line .l-item { grid-column: 2; grid-row: 1; }
  .line .l-foot { grid-column: 1 / -1; }
}

.totals {
  display: grid;
  gap: 10px;
  margin-left: auto;
  max-width: 420px;
}
.totals .t-row {
  display: grid;
  grid-template-columns: 1fr 150px;
  align-items: center;
  gap: var(--sp-3);
}
.totals .t-row > span:first-child { color: var(--text-2); font-size: 0.9375rem; }
.totals .t-value { text-align: right; font-variant-numeric: tabular-nums; padding-right: 13px; }
/* Accounting convention: a double rule closes the total. */
.totals .t-total {
  padding: 10px 0 8px;
  border-top: 1px solid var(--text);
  border-bottom: 3px double var(--text);
  font-weight: 700;
  font-size: 1.125rem;
}
.totals .t-total > span:first-child { color: var(--text); }

.actionbar {
  position: sticky;
  bottom: 0;
  z-index: 15;
  margin-top: var(--sp-5);
  padding: var(--sp-3) var(--sp-4) calc(var(--sp-3) + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--rule-strong);
}
.actionbar .row-between { flex-wrap: nowrap; }
.actionbar .save-state { font-size: 0.8125rem; color: var(--text-3); }
.ab-left { display: grid; gap: 2px; min-width: 0; }
.ab-hint { color: var(--warn); font-size: 0.875rem; font-weight: 600; }
.ab-hint:empty { display: none; }
.actionbar .btn-cta { flex: 0 1 auto; }
@media (max-width: 520px) {
  .actionbar .row-between { flex-wrap: wrap; }
  .actionbar .btn-cta { width: 100%; }
}

.result-card {
  border-color: var(--rule);
  border-top: 3px solid var(--ok-dot);
}
.result-card > .row > svg { display: none; }
.result-card h2 { font-family: var(--serif); font-size: 1.625rem; font-weight: 500; line-height: 1.2; letter-spacing: -0.01em; }

.plain-fieldset {
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
}
.plain-fieldset:disabled .card { background: var(--surface); }
.plain-fieldset:disabled input,
.plain-fieldset:disabled select,
.plain-fieldset:disabled textarea {
  background: var(--surface-2);
  color: var(--text-2);
  border-color: var(--rule);
  opacity: 1;
}
.plain-fieldset:disabled .btn,
.plain-fieldset:disabled .btn-link,
.plain-fieldset:disabled .suggest { display: none; }

/* ---------- settings ---------- */

.settings-page { max-width: 760px; margin: 0 auto; }
.settings { display: grid; gap: var(--sp-4); }
.status-line { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 0.9375rem; color: var(--text-3); white-space: nowrap; }
.status-line .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); }
.status-line.on { color: var(--ok); }
.status-line.on .dot { background: var(--ok-dot); }
.copy-field { display: flex; gap: var(--sp-2); }
.copy-field input { font-family: var(--mono); font-size: 0.875rem; }
ol.steps { margin: 0; padding-left: 20px; color: var(--text-2); font-size: 0.9375rem; }
ol.steps li + li { margin-top: 6px; }
.kbd {
  font-family: var(--mono);
  font-size: 0.8125rem;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--surface-3);
  word-break: break-all;
}

.qr-box {
  display: grid;
  justify-items: center;
  gap: var(--sp-3);
  text-align: center;
}
svg.qr {
  width: 220px;
  height: 220px;
  stroke: none;
  background: #fff;
  border: 1px solid var(--rule);
  padding: 8px;
}
.qr-link { font-family: var(--mono); font-size: 0.8125rem; color: var(--text-3); word-break: break-all; }

/* ---------- sign in and setup ---------- */

.auth-wrap {
  min-height: calc(100vh - 64px);
  display: grid;
  place-items: center;
  padding: var(--sp-5) 0;
}
.auth-card { width: 100%; max-width: 440px; }
.auth-brand { margin-bottom: var(--sp-5); }
.auth-brand .brand-mark { display: none; }
.auth-brand h1 { font-size: 2rem; }
.auth-brand p { margin-top: 6px; }

/* ---------- dialogs, toasts, spinner ---------- */

.scrim {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: var(--sp-4);
  background: var(--scrim);
  animation: fade var(--t-med) ease-out;
}
.dialog {
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 32px);
  overflow: auto;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
  padding: var(--sp-5);
  animation: rise var(--t-med) ease-out;
}
.dialog h2 { font-family: var(--serif); font-size: 1.5rem; font-weight: 500; margin-bottom: var(--sp-2); }
.dialog .dialog-body { color: var(--text-2); }
.dialog .dialog-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-top: var(--sp-5);
}

.sheet-pages {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: var(--sp-2);
  margin: var(--sp-4) 0;
}
.sheet-pages figure {
  position: relative;
  margin: 0;
}
.sheet-pages img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border: 1px solid var(--rule);
  background: var(--surface-2);
}
.sheet-pages figcaption {
  position: absolute;
  left: 6px;
  bottom: 6px;
  padding: 0 6px;
  border-radius: 2px;
  background: rgb(27 25 21 / 0.8);
  color: #fff;
  font-size: 0.75rem;
}

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(var(--sp-4) + env(safe-area-inset-bottom));
  z-index: 60;
  display: grid;
  gap: var(--sp-2);
  width: min(92vw, 440px);
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--toast-bg);
  color: var(--toast-text);
  box-shadow: var(--shadow-pop);
  font-size: 0.9375rem;
  /* Messages only inform: taps go through to whatever is underneath, like a Send button. */
  pointer-events: none;
  animation: rise var(--t-med) ease-out;
}
.toast svg { display: none; }
.toast.error { background: #8c2318; color: #fff; }

.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex: none;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .spinner { animation: spin 1.6s linear infinite !important; }
}

/* ---------- plain server pages (expired links etc.) ---------- */

.plain-page { display: grid; place-items: center; min-height: 100vh; padding: var(--sp-4); }
.plain-card {
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: var(--sp-5);
}
.plain-card h1 { font-size: 1.5rem; margin-bottom: var(--sp-2); }
.plain-card p + p { margin-top: var(--sp-4); }

/* ---------- welcome steps ---------- */

.welcome {
  max-width: 520px;
  margin: 0 auto;
  padding: var(--sp-5) 0 var(--sp-6);
  display: grid;
  justify-items: start;
  gap: var(--sp-4);
}
.welcome h1 { font-size: 2.125rem; }
.welcome-lead { font-size: 1.1875rem; color: var(--text-2); max-width: 30em; }
.welcome-step {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-3);
}
.welcome-dots { display: flex; gap: 6px; }
.welcome-dots span { width: 28px; height: 3px; background: var(--rule-strong); }
.welcome-dots span.on { background: var(--ink); }
.welcome-done-icon { display: none; }
.welcome-qr { min-height: 280px; width: 100%; display: grid; justify-items: center; align-content: center; gap: 8px; }
.welcome-qr svg.qr { width: 260px; height: 260px; padding: 12px; }
.welcome .callout { width: 100%; }
.welcome .btn-xl { max-width: none; }

.help-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: var(--sp-4);
  color: var(--text-2);
}
.help-line svg { display: none; }
.help-footer {
  max-width: var(--content);
  margin: 0 auto;
  padding: var(--sp-4) var(--sp-4) calc(var(--sp-5) + env(safe-area-inset-bottom));
  color: var(--text-3);
  font-size: 0.9375rem;
  text-align: center;
}
.help-footer a { color: var(--text); font-weight: 600; }

/* ---------- check screen summary: set like the top of an invoice ---------- */

.summary { display: grid; gap: var(--sp-4); }
.summary-kind {
  justify-self: start;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--ok);
}
.summary-kind.bill { color: var(--text-3); }
.summary-who {
  font-family: var(--serif);
  font-size: 2rem;
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: -0.01em;
}
.summary-who small {
  display: block;
  margin-top: 6px;
  font-family: var(--font);
  font-size: 0.9375rem;
  font-weight: 400;
  color: var(--text-3);
  letter-spacing: 0;
}
.facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-3) var(--sp-4);
  margin: 0;
  padding: var(--sp-4) 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}
.facts div { min-width: 0; }
.facts dt { font-size: 0.875rem; color: var(--text-3); }
.facts dd { margin: 2px 0 0; font-size: 1.125rem; font-weight: 600; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.facts .total dd { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.015em; }
.facts .warn-field dd { color: var(--warn); }
.item-list { list-style: none; margin: 0; padding: 0; }
.item-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--sp-3);
  padding: 10px 0;
  border-bottom: 1px dotted var(--rule-strong);
}
.item-list li:last-child { border-bottom: 0; }
.item-list .amt { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.kind-choice { display: grid; gap: var(--sp-3); }
.kind-choice button {
  display: grid;
  gap: 4px;
  min-height: 72px;
  padding: 14px 18px;
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.kind-choice button:hover { border-color: var(--ink); background: var(--surface-2); }
.kind-choice strong { font-size: 1.125rem; }
.kind-choice span { color: var(--text-3); }
.summary-actions { display: grid; gap: var(--sp-2); justify-items: stretch; }
.summary-actions .btn-xl { max-width: none; }
.edit-back { margin-bottom: var(--sp-3); padding-left: 0; }
/* Back links get a plain arrow (a text character, not an icon). */
.btn-ghost[href="#/"]::before,
.edit-back::before { content: "\2190"; font-weight: 400; margin-right: 2px; }
.btn-ghost[href="#/"] { padding-left: 0; }

details.advanced > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 2px;
  border-top: 1px solid var(--rule-strong);
  color: var(--text-2);
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
details.advanced > summary:hover { color: var(--text); }
details.advanced > summary::-webkit-details-marker { display: none; }
details.advanced > summary svg { width: 16px; height: 16px; transition: transform var(--t-fast); }
details.advanced[open] > summary svg { transform: rotate(90deg); }
details.advanced[open] > summary { margin-bottom: var(--sp-3); }
details.advanced > .settings { margin-top: 0; }

/* Phones: the summary (and its big button) first, the picture under it. */
@media (max-width: 999px) {
  .review.summary-mode .doc-col { order: 2; }
}
