/* Itqan design language — see design.md for the source of every token.
   One dark panel per page carries the single rounded corner; gold only marks headings and bars.
   Fonts load via <link> in templates; no @import here so first paint isn't blocked. */

:root {
  --navy-900: #003049;
  --navy-700: #0e4362;
  --blue-600: #2c5887;
  --gold-500: #dfb93e;
  --ink: #20282d;
  --ink-muted: #547079;
  --on-dark: #ffffff;
  --on-dark-muted: #aec5cd;
  --surface: #ffffff;
  --surface-paper: #ededed;
  --surface-tint: rgba(0, 48, 73, 0.06);
  --surface-on-dark: rgba(255, 255, 255, 0.06);
  --line: #d9d9d9;
  --line-on-dark: rgba(255, 255, 255, 0.1);
  --field-line: rgba(14, 67, 98, 0.4);
  --focus-ring: rgba(14, 67, 98, 0.25);
  /* Status colors are not in design.md. Warning is orange so it never reads as brand gold. */
  --ok: #1b6e52;
  --ok-soft: #e4f2ec;
  --error: #b3261e;
  --error-soft: #fbeae8;
  --warn: #b4530a;
  --warn-ink: #8a3f06;
  --warn-soft: #fdeedd;
  --info-soft: #e6edf5;
  --radius-sm: 4px;
  --radius-md: 10px;
  --radius-pill: 999px;
  --corner: 48px;
  --shadow-float: 0 8px 24px rgba(0, 48, 73, 0.12);
  --head-h: 56px;
  --sticky-top: calc(var(--head-h) + 16px);
  --pane-max: calc(100vh - var(--head-h) - 32px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh;
  color: var(--ink); background: var(--surface);
  font: 400 15px/26px "IBM Plex Sans Arabic", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--info-soft); }
svg { flex-shrink: 0; }
img { max-width: 100%; }
[hidden] { display: none !important; }
a { color: var(--blue-600); text-underline-offset: 3px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--navy-700); outline-offset: 2px; }
bdi, .num { font-variant-numeric: tabular-nums; }

h1 { font-size: 28px; line-height: 40px; font-weight: 700; color: var(--blue-600); margin: 0; overflow-wrap: anywhere; }
h2 { font-size: 16px; line-height: 26px; font-weight: 600; color: var(--ink); margin: 0; }
.page-title { border-inline-start: 4px solid var(--gold-500); padding-inline-start: 12px; }
.eyebrow {
  display: inline-block; margin: 0 0 8px; padding: 2px 8px;
  font-size: 13px; line-height: 20px; font-weight: 500;
  color: var(--ink-muted); background: var(--surface-tint); border-radius: var(--radius-sm);
}
.count {
  font-size: 13px; line-height: 20px; font-weight: 500; white-space: nowrap;
  color: var(--ink-muted); background: var(--surface-tint);
  padding: 2px 8px; border-radius: var(--radius-sm); font-variant-numeric: tabular-nums;
}
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}
.skip {
  position: absolute; inset-inline-start: 16px; top: -72px; z-index: 100;
  background: var(--navy-900); color: var(--on-dark); padding: 8px 16px;
  border-radius: var(--radius-sm); text-decoration: none;
}
.skip:focus { top: 12px; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 20px; border: 1px solid var(--navy-700); border-radius: var(--radius-pill);
  background: var(--navy-700); color: var(--on-dark);
  font-size: 14px; font-weight: 500; line-height: 1; text-decoration: none; white-space: nowrap;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.btn:hover:not(:disabled) { background: var(--navy-900); border-color: var(--navy-900); }
.btn:disabled { opacity: 0.45; }
.btn svg { width: 14px; height: 14px; }
.btn-secondary { background: transparent; color: var(--navy-700); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-tint); border-color: var(--navy-700); }
.btn-danger { background: var(--error); border-color: var(--error); }
.btn-danger:hover:not(:disabled) { background: #8f1d17; border-color: #8f1d17; }
.btn-sm { height: 30px; padding: 0 14px; font-size: 13px; }

input, select, textarea {
  height: 36px; width: 100%; min-width: 0; padding: 0 12px;
  border: 1px solid var(--field-line); border-radius: var(--radius-sm);
  background: var(--surface); font-size: 14px;
}
textarea { height: auto; min-height: 84px; padding: 6px 12px; resize: vertical; }
select { width: auto; cursor: pointer; }
input::placeholder, textarea::placeholder { color: var(--ink-muted); opacity: 0.8; }
input:focus, select:focus, textarea:focus { border-color: var(--navy-700); outline: 2px solid var(--focus-ring); outline-offset: 0; }
input:disabled, textarea:disabled { background: var(--surface-paper); color: var(--ink-muted); border-color: var(--line); }

.icon-btn {
  display: inline-grid; place-items: center; width: 30px; height: 30px; padding: 0;
  border: 0; border-radius: var(--radius-pill); background: transparent; color: var(--navy-700);
  transition: background 0.12s, color 0.12s;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { background: var(--surface-tint); }
.icon-btn.is-danger:hover { background: var(--error-soft); color: var(--error); }

/* Segmented switch: years, quarters, and the invoice state filter. */
.quarter-switch, .year-tabs, .status-legend {
  display: inline-flex; align-items: stretch; overflow: clip;
  border: 1px solid var(--field-line); border-radius: var(--radius-sm); background: var(--surface);
}
.quarter-cell, .year-tab, .legend-filter {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 30px; padding: 0 12px; border: 0; background: transparent;
  font-size: 13px; font-weight: 500; color: var(--navy-700); text-decoration: none; white-space: nowrap; cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.quarter-switch > * + *, .year-tabs > * + *, .legend-filter + .legend-filter { border-inline-start: 1px solid var(--field-line); }
.quarter-cell.is-empty { color: var(--ink-muted); font-weight: 400; }
:is(.quarter-cell, .year-tab, .legend-filter):hover { background: var(--surface-tint); }
:is(.quarter-cell, .year-tab)[aria-current], .quarter-cell:has(input:checked), .legend-filter.active { background: var(--navy-700); color: var(--on-dark); }
:is(.quarter-cell, .year-tab, .legend-filter):focus-visible, .quarter-cell:has(input:focus-visible) { outline-offset: -2px; }
:is(.quarter-cell, .year-tab)[aria-current]:focus-visible, .quarter-cell:has(input:checked:focus-visible), .legend-filter.active:focus-visible { outline-color: var(--on-dark); outline-offset: -4px; }
.quarter-cell input { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); border: 0; }
.quarter-switch-label { display: inline-flex; align-items: center; padding: 0 10px; font-size: 13px; font-weight: 500; color: var(--ink-muted); background: var(--surface-paper); }
.tally, .legend-count { font-size: 12px; font-variant-numeric: tabular-nums; opacity: 0.75; }

/* Status: one chip for documents, invoices and the reading progress. Blue is the working state. */
.status-chip, .state-badge, #progress, .scanning-pill {
  display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0; margin: 0;
  padding: 1px 10px; border-radius: var(--radius-pill);
  font-size: 12px; line-height: 20px; font-weight: 500; white-space: nowrap;
  color: var(--blue-600); background: var(--info-soft);
}
.status-chip::before, .state-badge::before, #progress::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-chip.ready, .state-badge.complete { color: var(--ok); background: var(--ok-soft); }
.status-chip.failed, .state-badge.missing { color: var(--error); background: var(--error-soft); }
.state-badge.needs_review { color: var(--warn-ink); background: var(--warn-soft); }
.status-chip.paused, #progress.is-paused { color: var(--ink-muted); background: var(--surface-paper); }
.dot { width: 8px; height: 8px; display: inline-block; border-radius: 50%; flex-shrink: 0; background: var(--blue-600); }
.dot.complete { background: var(--ok); }
.dot.missing { background: var(--error); }
.dot.needs_review { background: var(--warn); }

/* ---------- navigation ---------- */
.site-head { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 50; }
.site-head-inner { max-width: 1180px; height: var(--head-h); margin: 0 auto; padding: 0 24px; display: flex; align-items: stretch; gap: 24px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 700; color: var(--blue-600); text-decoration: none; white-space: nowrap; }
.brand-mark { width: 24px; height: 24px; fill: currentColor; }
.brand-mark .gold { fill: var(--gold-500); }
.head-nav { flex: 1; display: flex; align-items: stretch; gap: 4px; min-width: 0; }
.nav-link {
  display: inline-flex; align-items: center; padding: 0 12px; margin-bottom: -1px;
  font-size: 14px; font-weight: 500; color: var(--ink-muted); text-decoration: none; white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.nav-link:hover { color: var(--navy-700); }
.nav-link[aria-current="page"] { color: var(--navy-700); font-weight: 600; border-bottom-color: var(--gold-500); }
.head-nav form { margin: 0; margin-inline-start: auto; display: flex; align-items: center; }

/* ---------- layout ---------- */
.wrap { max-width: 1180px; margin: 0 auto; padding: 32px 24px 64px; }
.wrap.wide, .site-head-inner.wide { max-width: 1600px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head h1 { display: flex; align-items: center; gap: 12px; }

.panel { border: 1px solid var(--line); border-radius: var(--radius-md); padding: 20px 24px; min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }

/* The page's one dark panel. Inside it the text and line tokens flip, so shared rows need no second set of rules. */
.panel-dark {
  --ink: var(--on-dark); --ink-muted: var(--on-dark-muted);
  --line: var(--line-on-dark); --surface-tint: var(--surface-on-dark);
  background: var(--navy-900); color: var(--ink);
  border: 0; border-radius: 0; border-end-end-radius: var(--corner);
}
.panel-dark :is(h1, h2, a) { color: var(--on-dark); }
.panel-dark .btn-secondary { border-color: var(--on-dark); color: var(--on-dark); }
.panel-dark .btn-secondary:hover:not(:disabled) { border-color: var(--on-dark); }

/* ---------- home ---------- */
.home-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 24px; align-items: start; }
.home-main { min-width: 0; }
.home-main:only-child { grid-column: 1 / -1; }
.toolbar { display: flex; gap: 8px; margin-bottom: 8px; }
.toolbar .grow { flex: 1 1 280px; position: relative; min-width: 0; }
.toolbar .grow svg { position: absolute; inset-inline-start: 10px; top: 10px; width: 16px; height: 16px; fill: var(--ink-muted); pointer-events: none; }
.toolbar .grow input { padding-inline-start: 34px; }
.toolbar select { flex: 0 1 200px; }
.ledger-count { font-size: 12px; line-height: 18px; color: var(--ink-muted); margin: 0 0 12px; font-variant-numeric: tabular-nums; }

.folder-ledger { border: 1px solid var(--line); border-radius: var(--radius-md); overflow: clip; }
.ledger-head, .folder-row {
  display: grid; grid-template-columns: minmax(0, 1fr) 150px 80px 100px 20px;
  gap: 12px; align-items: center; padding: 8px 16px;
}
.ledger-head { font-size: 13px; line-height: 20px; font-weight: 500; color: var(--ink-muted); background: var(--surface-paper); }
.ledger-head span:nth-child(3), .ledger-head span:nth-child(4) { text-align: end; }
.folder-row { color: var(--ink); text-decoration: none; border-top: 1px solid var(--line); transition: background 0.12s; }
.folder-row:hover { background: var(--surface-tint); }
.folder-row:focus-visible { outline-offset: -2px; }
.folder-cell-main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.folder-cell-text { min-width: 0; display: flex; flex-direction: column; }
/* Solid blocks keep square corners. */
.initials {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 36px; height: 36px; background: var(--surface-tint); color: var(--blue-600);
  font-size: 13px; font-weight: 600;
}
.folder-name { font-size: 15px; line-height: 24px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vat { font-size: 12px; line-height: 18px; color: var(--ink-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.practice { font-size: 13px; color: var(--ink-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.practice:empty::before { content: "—"; color: var(--line); }
.filecount, .updated { justify-self: end; font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.updated { color: var(--ink-muted); }
.go { color: var(--line); justify-self: end; transition: color 0.12s; }
.folder-row:hover .go { color: var(--navy-700); }

.home-side { min-width: 0; position: sticky; top: var(--sticky-top); }
.home-side .panel { padding: 20px 24px 32px; }
.home-side .ledger { max-height: min(60vh, 540px); overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--line-on-dark) transparent; }
.home-side .ledger-side { flex-direction: column; align-items: flex-end; gap: 4px; }

/* ---------- document rows ---------- */
.ledger { list-style: none; margin: 0 -12px; padding: 0; }
.ledger li { position: relative; display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-top: 1px solid var(--line); transition: background 0.12s; }
.ledger li:hover { background: var(--surface-tint); }
/* The whole row opens the document: the name's link stretches over it, and the row's own controls sit above. */
.doc-name::after { content: ""; position: absolute; inset: 0; }
.doc-name:focus-visible { outline: 0; }
.doc-name:focus-visible::after { outline: 2px solid var(--navy-700); outline-offset: -2px; }
.ledger-side :is(a, button) { position: relative; z-index: 1; }
.ledger-main { min-width: 0; flex: 1 1 auto; }
.doc-name { display: inline-block; max-width: 100%; vertical-align: top; font-weight: 600; color: var(--ink); text-decoration: none; overflow-wrap: anywhere; }
.ledger .meta { font-size: 12px; line-height: 18px; color: var(--ink-muted); overflow-wrap: anywhere; }
.ledger-side { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.ledger .open { font-size: 13px; font-weight: 500; white-space: nowrap; text-decoration: none; }
.ledger .open:hover { text-decoration: underline; }

/* ---------- empty state: the gold square sits behind the start of the heading ---------- */
.empty { max-width: 520px; margin: 48px auto; padding: 0 24px; }
.empty h2 { position: relative; isolation: isolate; font-size: 20px; line-height: 30px; color: var(--blue-600); margin-bottom: 8px; padding: 16px 0 0; padding-inline-start: 16px; }
.empty h2::before { content: ""; position: absolute; z-index: -1; top: 0; inset-inline-start: 0; width: 40px; height: 40px; background: var(--gold-500); }
.empty p { color: var(--ink-muted); margin: 0 0 20px; padding-inline-start: 16px; }
.empty .btn { margin-inline-start: 16px; }

/* ---------- customer folder ---------- */
.crumbs { font-size: 13px; line-height: 20px; color: var(--ink-muted); margin-bottom: 12px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.crumbs a { color: var(--ink-muted); text-decoration: none; }
.crumbs a:hover { color: var(--navy-700); text-decoration: underline; }
.crumbs [aria-current="page"] { color: var(--ink); overflow-wrap: anywhere; }
.folder-head { display: flex; gap: 16px; align-items: center; padding: 24px; padding-inline-end: 40px; margin-bottom: 24px; }
.folder-head .initials { width: 48px; height: 48px; font-size: 16px; color: var(--on-dark); }
.folder-meta { min-width: 0; flex: 1 1 auto; }
.folder-head .meta { font-size: 13px; line-height: 20px; color: var(--ink-muted); margin: 4px 0 0; padding-inline-start: 16px; overflow-wrap: anywhere; }
.folder-head .actions { display: flex; gap: 8px; flex-shrink: 0; }

.folder-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
.folder-main { min-width: 0; }
.folder-side { min-width: 0; position: sticky; top: var(--sticky-top); }

/* Tax period: a year switch and a quarter switch, side by side on one slim row. */
.period-nav { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; }
.year-tabs { list-style: none; margin: 0; padding: 0; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.year-tabs li { flex-shrink: 0; display: flex; }
/* Under the filter: the selection it produced and the one action that belongs to a quarter. */
.period-result {
  display: flex; align-items: center; justify-content: space-between; gap: 6px 12px; flex-wrap: wrap;
  margin: 8px 0 4px; padding: 6px 12px; padding-inline-end: 6px;
  font-size: 13px; line-height: 20px; color: var(--ink-muted); background: var(--surface-tint); border-radius: var(--radius-sm);
}
.period-result p { margin: 0; font-variant-numeric: tabular-nums; }
.period-result strong { color: var(--navy-700); font-weight: 600; }
.period-wait, .period-help.is-set { color: var(--warn-ink); }
.period-flag { color: var(--error); font-weight: 600; }
.period-hint { font-size: 12px; }
.upload-hint { margin: 12px 0 0; font-size: 14px; color: var(--ink-muted); }

/* Upload: the label line, then year and quarters as one joined control, above a one-line drop area. */
.period-field { display: flex; align-items: center; gap: 4px 8px; flex-wrap: wrap; border: 0; padding: 0; margin: 0 0 12px; min-width: 0; }
.period-label, .period-clear { font-size: 13px; line-height: 20px; font-weight: 500; color: var(--ink-muted); }
.period-label { flex: 1; }
.period-clear { padding: 0; border: 0; background: none; color: var(--blue-600); text-decoration: underline; text-underline-offset: 3px; }
.period-field .quarter-switch { flex: 1 0 100%; display: grid; grid-template-columns: auto repeat(4, minmax(0, 1fr)); }
.period-field select {
  height: 30px; padding: 0 8px; border: 0; border-radius: 0; background-color: var(--surface-paper);
  font-size: 13px; font-weight: 600; color: var(--navy-700); font-variant-numeric: tabular-nums;
}
.period-field select:focus { outline: 2px solid var(--navy-700); outline-offset: -2px; }
.period-field .quarter-cell { padding: 0 4px; }
.period-field:disabled { opacity: 0.6; }
.period-field:disabled :is(.quarter-cell, select) { cursor: not-allowed; }
.period-help { flex: 1 0 100%; margin: 0; font-size: 12px; line-height: 18px; color: var(--ink-muted); }
.dropzone {
  position: relative; display: flex; align-items: center; gap: 2px 8px; flex-wrap: wrap;
  padding: 8px 12px; border: 1px dashed var(--field-line); border-radius: var(--radius-sm); cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.dropzone:hover, .dropzone:focus-within, .dropzone.dragover { background: var(--surface-tint); border-color: var(--navy-700); }
.dropzone:focus-within { outline: 2px solid var(--focus-ring); }
.dropzone.has-file { border-style: solid; border-color: var(--navy-700); }
.dropzone-icon { display: flex; color: var(--navy-700); }
.dropzone strong { font-size: 14px; font-weight: 600; }
.dropzone > span:not(.dropzone-icon) { font-size: 13px; color: var(--ink-muted); }
.dropzone input[type="file"] { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); border: 0; }
.upload-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.picked-wrap { display: flex; align-items: center; gap: 4px; min-width: 0; max-width: 100%; }
.picked { font-size: 13px; color: var(--ink-muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.picked-remove { width: 24px; height: 24px; }
.picked-remove:disabled { opacity: 0.4; }
.upload-progress { margin-top: 12px; }
.upload-progress-meta { display: flex; justify-content: space-between; gap: 4px 12px; flex-wrap: wrap; font-size: 12px; line-height: 18px; color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.upload-progress.is-error .upload-progress-meta { color: var(--error); }
progress { display: block; width: 100%; height: 4px; margin-top: 6px; border: 0; appearance: none; background: var(--surface-tint); }
progress::-webkit-progress-bar { background: var(--surface-tint); }
progress::-webkit-progress-value { background: var(--navy-700); }
progress::-moz-progress-bar { background: var(--navy-700); }

/* ---------- dialog ---------- */
.customer-dialog {
  border: 1px solid var(--line); border-radius: var(--radius-md); padding: 24px;
  max-width: 480px; width: calc(100% - 32px); box-shadow: var(--shadow-float);
  background: var(--surface); color: var(--ink);
}
.customer-dialog::backdrop { background: rgba(0, 48, 73, 0.45); }
.customer-dialog h2 { font-size: 20px; line-height: 30px; color: var(--blue-600); margin-bottom: 4px; }
.dialog-intro { color: var(--ink-muted); font-size: 14px; margin: 0 0 20px; }
.dialog-field { display: grid; gap: 4px; margin-bottom: 16px; }
.dialog-field label, .field-label { font-size: 13px; line-height: 20px; font-weight: 500; color: var(--ink-muted); }
.req { color: var(--error); }
.dialog-field small { font-size: 12px; line-height: 18px; color: var(--ink-muted); }
.alias-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.alias-list:empty { display: none; }
.alias-row { display: flex; align-items: center; gap: 8px; }
.alias-remove { flex-shrink: 0; width: 36px; height: 36px; border: 0; border-radius: var(--radius-pill); background: transparent; color: var(--ink-muted); font-size: 18px; line-height: 1; }
.alias-remove:hover { background: var(--error-soft); color: var(--error); }
.alias-add { justify-self: start; padding: 0; border: 0; background: none; color: var(--blue-600); font-size: 13px; font-weight: 500; text-decoration: underline; text-underline-offset: 3px; }
.alias-add:disabled { opacity: 0.5; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 24px; flex-wrap: wrap; }
.dialog-error { margin: -8px 0 0; font-size: 13px; color: var(--error); }

/* ---------- review workspace ---------- */
.document-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px 24px; flex-wrap: wrap; margin-bottom: 16px; }
.document-head .eyebrow { margin-bottom: 4px; }
.document-title { min-width: 0; flex: 1 1 320px; }
.document-title h1 { font-size: 22px; line-height: 32px; margin-bottom: 8px; }
.doc-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
@keyframes pulse { 50% { opacity: 0.3; } }
#progress:not(.is-paused)::before, .worker-dot.busy { animation: pulse 1.6s ease-in-out infinite; }
.doc-period { margin: 0; font-size: 12px; line-height: 20px; color: var(--ink-muted); cursor: help; }
.doc-period strong { color: var(--ink); font-weight: 600; }
.usage-line { margin: 4px 0 0; font-size: 12px; line-height: 18px; color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.usage-line:empty { display: none; }
#preparation-error { color: var(--error); }
.download-area { flex-shrink: 0; display: grid; gap: 8px; justify-items: end; }
.download-area p { font-size: 12px; line-height: 18px; color: var(--ink-muted); margin: 0; }
.action-row { display: flex; align-items: center; gap: 12px; }
/* Excel and JSON read as one joined pill; both only read the document. */
.download-actions { display: inline-flex; }
.download-actions .btn:first-child { border-start-end-radius: 0; border-end-end-radius: 0; }
.download-actions .btn:last-child { border-start-start-radius: 0; border-end-start-radius: 0; margin-inline-start: -1px; padding: 0 14px; }
/* Scan controls change the document, so they sit apart from the downloads. */
.scan-controls { display: flex; align-items: center; gap: 2px; padding-inline-start: 12px; border-inline-start: 1px solid var(--line); }

.progress-strip { display: grid; grid-template-columns: 1fr 1fr 1.5fr auto; margin-bottom: 16px; padding-inline-end: 24px; }
.metric { padding: 12px 24px; display: grid; grid-template-columns: 1fr auto; gap: 0 16px; align-content: center; min-width: 0; border-inline-end: 1px solid var(--line); }
.metric-label { font-size: 13px; line-height: 20px; font-weight: 500; color: var(--ink-muted); }
.metric strong { grid-column: 2; grid-row: 1 / 3; align-self: center; font-size: 28px; line-height: 40px; font-weight: 700; font-variant-numeric: tabular-nums; }
.metric-detail, #worker-detail { font-size: 12px; line-height: 18px; color: var(--ink-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Gold fills the bar, never text. */
.grouping-metric progress { grid-row: 3; grid-column: 1 / -1; }
.grouping-metric progress::-webkit-progress-value { background: var(--gold-500); }
.grouping-metric progress::-moz-progress-bar { background: var(--gold-500); }
.worker-meter { display: flex; gap: 10px; align-items: center; padding: 12px 24px; font-size: 14px; min-width: 0; }
.worker-meter strong { font-variant-numeric: tabular-nums; }
.worker-text { display: flex; flex-direction: column; line-height: 20px; min-width: 0; }
.worker-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--on-dark-muted); flex-shrink: 0; opacity: 0.5; }
.worker-dot.busy { background: var(--on-dark); opacity: 1; }

.desk-grid { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 16px; align-items: start; }
.invoice-index, .source-pane, .fields-pane {
  border: 1px solid var(--line); border-radius: var(--radius-md); overflow: clip; min-width: 0;
  display: flex; flex-direction: column;
}
.invoice-index { position: sticky; top: var(--sticky-top); max-height: var(--pane-max); min-height: 220px; }
.index-heading { display: grid; gap: 8px; padding: 12px 16px 0; }
.index-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.index-title h2 { display: flex; align-items: center; gap: 8px; }
.status-legend { display: grid; grid-template-columns: repeat(3, 1fr); }
.legend-filter { padding: 0 4px; min-width: 0; font-size: 12px; color: var(--ink); }
.invoice-search { display: grid; gap: 4px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.invoice-search label { font-size: 13px; line-height: 20px; font-weight: 500; color: var(--ink-muted); }
#invoice-search-status { margin: 0; font-size: 12px; line-height: 18px; color: var(--ink-muted); }
#page-nav { overflow-y: auto; min-height: 0; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.page-tab {
  display: block; width: 100%; min-width: 0; padding: 8px 16px; text-align: start;
  border: 0; border-bottom: 1px solid var(--line); border-inline-start: 3px solid var(--blue-600);
  background: transparent; transition: background 0.12s;
}
.page-tab:hover { background: var(--surface-tint); }
.page-tab:focus-visible { outline-offset: -2px; }
.page-tab.complete { border-inline-start-color: var(--ok); }
.page-tab.missing { border-inline-start-color: var(--error); }
.page-tab.needs_review { border-inline-start-color: var(--warn); }
.page-tab.active { background: var(--info-soft); }
.tab-name { display: block; font-size: 14px; line-height: 22px; font-weight: 600; overflow-wrap: anywhere; unicode-bidi: plaintext; font-variant-numeric: tabular-nums; }
.page-tab.active .tab-name { color: var(--navy-700); }
.tab-detail { display: block; font-size: 12px; line-height: 18px; color: var(--ink-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-nav { font-size: 14px; color: var(--ink-muted); margin: 0; padding: 24px 16px; text-align: center; }

/* direction: ltr puts the scanned page on the left of the fields; the panes themselves stay RTL. */
.review-grid { display: grid; grid-template-columns: auto minmax(440px, 1fr); gap: 16px; align-items: start; min-width: 0; direction: ltr; }
.review-grid > * { direction: rtl; }
@media (min-width: 1500px) {
  .desk-grid { grid-template-columns: 370px minmax(0, 1fr); }
  .review-grid { grid-template-columns: auto minmax(540px, 1fr); }
}
.pane-heading { padding: 10px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.utility:empty { display: none; }
#source-pages { display: flex; gap: 6px; flex-wrap: wrap; padding: 10px 16px 0; }
#source-pages:empty { display: none; }
#source-pages button {
  height: 26px; padding: 0 12px; border: 1px solid var(--navy-700); border-radius: var(--radius-pill);
  background: transparent; color: var(--navy-700); font-size: 12px; font-variant-numeric: tabular-nums;
}
#source-pages button:hover { background: var(--surface-tint); }
#source-pages button.active { background: var(--navy-700); color: var(--on-dark); }
/* The whole page stays in view beside the fields: the pane pins to the viewport and hugs the image scaled to fit it. */
.source-pane { position: sticky; top: var(--sticky-top); max-height: var(--pane-max); min-width: 300px; }
.image-wrap {
  background: var(--surface-paper); padding: 12px; margin-top: 10px; flex: 0 1 auto; min-height: 0; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
}
/* 126px is the pane chrome above and around the image; if the page tabs wrap, the image shrinks further instead of clipping. */
.image-wrap img {
  display: block; width: auto; height: auto; max-width: min(100%, 760px); max-height: calc(var(--pane-max) - 126px);
  flex: 0 1 auto; min-height: 0; object-fit: contain; background: #fff; border: 1px solid var(--line);
}
.image-wrap img:not([hidden]) { cursor: crosshair; }
.image-wrap p { margin: 96px 0; color: var(--ink-muted); }
.preview-lens {
  position: fixed; z-index: 60; width: 320px; height: 210px; pointer-events: none;
  border: 2px solid var(--navy-700); border-radius: var(--radius-md);
  background-color: #fff; background-repeat: no-repeat; box-shadow: var(--shadow-float);
}

#fields { padding: 4px 16px; }
.field { padding: 10px 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: minmax(130px, 0.7fr) minmax(0, 1.3fr); gap: 4px 16px; align-items: center; }
.field:last-child { border-bottom: 0; }
.field label { font-size: 13px; line-height: 20px; font-weight: 500; color: var(--ink-muted); overflow-wrap: anywhere; }
.field input, .field textarea { font-variant-numeric: tabular-nums; }
.field small, .field .evidence-link { grid-column: 2; }
.evidence-link {
  justify-self: start; max-width: 100%; padding: 0; border: 0; background: transparent;
  font-size: 12px; line-height: 18px; color: var(--ink-muted); text-align: start; overflow-wrap: anywhere;
  text-decoration: underline; text-underline-offset: 3px;
}
.evidence-link::before { content: "↖ "; }
.evidence-link:hover { color: var(--navy-700); }
.field.has-warning input { border-color: var(--warn); }
.field small, .warnings, #review-conflict {
  font-size: 12px; line-height: 18px; color: var(--warn-ink); background: var(--warn-soft);
  padding: 6px 10px; border-radius: var(--radius-sm); overflow-wrap: anywhere;
}
.fields-empty { color: var(--ink-muted); padding: 32px 0; text-align: center; margin: 0; }
.warnings { margin: 12px 16px 0; font-size: 13px; line-height: 20px; }
.warnings summary { cursor: pointer; font-weight: 600; }
.warnings ul { margin: 6px 0 2px; padding-inline-start: 20px; }

/* Another reviewer changed the invoice: pick a value per field, then reapply the draft. */
#review-conflict { margin: 12px 16px; padding: 12px; font-size: 13px; line-height: 20px; display: grid; gap: 8px; justify-items: start; }
#review-conflict p { margin: 0; }
#review-conflict fieldset { border: 0; border-top: 1px solid var(--line); margin: 0; padding: 8px 0 0; width: 100%; display: grid; gap: 4px; color: var(--ink); }
#review-conflict legend { padding: 0; font-weight: 600; }
#review-conflict label { display: flex; align-items: center; gap: 8px; }
#review-conflict input { width: auto; height: auto; accent-color: var(--navy-700); }
#review-conflict button {
  height: 30px; padding: 0 14px; border: 1px solid var(--navy-700); border-radius: var(--radius-pill);
  background: transparent; color: var(--navy-700); font-size: 13px; font-weight: 500;
}
#review-conflict button:disabled { opacity: 0.45; }

#page-actions {
  position: sticky; bottom: 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 12px 16px; margin-top: 8px; background: var(--surface); border-top: 1px solid var(--line);
}
#mark-reviewed.is-reviewed { color: var(--ink-muted); border-color: var(--line); }
#save-state { font-size: 13px; color: var(--ink-muted); }
.review-tools { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 16px; }
.review-tools:has(button:not([hidden])) { padding-block: 12px; }
.group-actions, #split-controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.group-actions { padding: 10px 16px; border-top: 1px solid var(--line); background: var(--surface-paper); }
.group-actions select { height: 30px; font-size: 13px; }

/* ---------- responsive ---------- */
@media (max-width: 1200px) {
  .review-grid { grid-template-columns: minmax(0, 1fr); }
  .source-pane { position: static; max-height: none; min-width: 0; }
  .image-wrap { min-height: 320px; }
  .image-wrap img { max-height: none; }
}
@media (max-width: 1100px) {
  .desk-grid, .home-grid, .folder-layout { grid-template-columns: minmax(0, 1fr); }
  .folder-side { position: static; order: -1; }
  .home-side, .invoice-index { position: static; max-height: none; }
  .home-side .ledger { max-height: none; }
  .home-side .ledger-side { flex-direction: row; align-items: center; }
  #page-nav { max-height: 320px; }
}
@media (max-width: 860px) {
  .site-head-inner { padding: 0 16px; gap: 12px; }
  .brand span { display: none; }
  .nav-link { padding: 0 8px; }
  .wrap { padding: 24px 16px 48px; }
  h1 { font-size: 24px; line-height: 34px; }
  .page-head .btn { width: 100%; }
  .toolbar { flex-wrap: wrap; }
  .toolbar select { flex: 1 1 100%; }
  .ledger-head, .folder-row { grid-template-columns: minmax(0, 1fr) 48px 20px; }
  .ledger-head span:nth-child(2), .ledger-head span:nth-child(4), .folder-row .practice, .folder-row .updated { display: none; }
  .folder-head { flex-wrap: wrap; padding: 20px 16px 28px; }
  .folder-head .actions { width: 100%; padding-inline-start: 16px; }
  .panel { padding: 16px; }
  .ledger li { flex-wrap: wrap; gap: 6px 12px; }
  .ledger-side, .home-side .ledger-side { width: 100%; justify-content: space-between; }
  .download-area { width: 100%; justify-items: stretch; }
  .action-row { justify-content: space-between; }
  .download-actions { flex: 1; }
  .download-actions .btn:first-child { flex: 1; }
  .progress-strip { grid-template-columns: 1fr 1fr; padding-inline-end: 0; padding-bottom: 8px; }
  .metric { padding: 12px 16px; }
  .metric:nth-child(2) { border-inline-end: 0; }
  .grouping-metric, .worker-meter { grid-column: 1 / -1; border-inline-end: 0; border-top: 1px solid var(--line); }
  .worker-meter { padding: 12px 16px; }
  .field { grid-template-columns: 1fr; }
  .field small, .field .evidence-link { grid-column: 1; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
@media print {
  .site-head, .download-area, .review-tools, .group-actions, #page-actions,
  .invoice-index, .toolbar, .upload-row, .folder-head .actions { display: none !important; }
  .wrap, .wrap.wide { max-width: none; padding: 0; }
}
