/*
 * Statement Desk.
 *
 * Paper white, ink black, hairlines. Saturated colour is reserved for one
 * question - can this line be trusted - and a single accent for anything
 * interactive. Nothing else is coloured, because nothing else means anything.
 * See docs/DESIGN.md.
 */

:root {
  --ink: #101418;
  --ink-2: #46505c;
  --ink-3: #6b7683;
  --rule: #e4e8ec;
  --rule-strong: #c8d0d8;
  --paper: #ffffff;
  --page: #f5f6f7;
  --sunk: #f0f2f4;

  --ok: #146c43;
  --ok-bg: #e7f6ec;
  --warn: #8a5200;
  --warn-bg: #fdf3e0;
  --bad: #b42318;
  --bad-bg: #fdeceb;
  --muted: #5a6470;
  --muted-bg: #eceff2;
  --accent: #3346c8;
  --accent-bg: #eef0fd;

  --radius: 6px;
  --shadow: 0 1px 2px rgba(16, 20, 24, 0.06);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

/*
 * Every icon in this app is inline SVG carrying only a viewBox. Without a size
 * it defaults to the full width of its container, so one missing rule turns an
 * icon into a full-page graphic. Sizing by default makes that failure mode
 * impossible; the more specific rules below still win where they exist.
 */
svg { width: 16px; height: 16px; flex: none; }

html, body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}

.app { display: grid; grid-template-columns: 236px 1fr; grid-template-rows: 52px 1fr; min-height: 100vh; }

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

.topbar {
  grid-column: 1 / -1;
  position: sticky; top: 0; z-index: 6;
  display: flex; align-items: center; gap: 14px;
  padding: 0 16px;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand b { font-size: 15px; letter-spacing: -0.2px; }
.brand span { color: var(--ink-3); font-size: 12px; }
.topbar .spacer { flex: 1; }
.topbar-status { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600;
  background: var(--ok-bg); color: var(--ok);
  border: 1px solid rgba(20, 108, 67, 0.18);
}
.pill svg { width: 13px; height: 13px; }

/* --------------------------------------------------------------------- nav */

.nav {
  background: var(--paper);
  border-right: 1px solid var(--rule);
  padding: 10px 10px 16px;
  display: flex; flex-direction: column; gap: 1px;
  position: sticky; top: 52px; align-self: start;
  max-height: calc(100vh - 52px); overflow-y: auto;
}
.nav button {
  display: flex; align-items: center; gap: 9px;
  width: 100%; padding: 9px 10px; flex: none;
  background: none; border: 0; border-radius: var(--radius);
  font: inherit; font-weight: 500; color: var(--ink-2); text-align: left; cursor: pointer;
  border-left: 2px solid transparent;
}
.nav button svg { width: 16px; height: 16px; flex: none; opacity: 0.75; }
.nav button .step { flex: 1; }
.nav button:hover { background: var(--sunk); }
.nav button.active { background: var(--accent-bg); color: var(--accent); font-weight: 600; border-left-color: var(--accent); }
.nav button.active svg { opacity: 1; }
.nav button .count:empty { display: none; }
.nav button .count {
  font-size: 11px; font-variant-numeric: tabular-nums; font-weight: 700;
  padding: 1px 7px; border-radius: 999px; background: var(--sunk); color: var(--ink-2);
}
.nav button .count.warn { background: var(--warn-bg); color: var(--warn); }
.nav button .count.bad { background: var(--bad-bg); color: var(--bad); }
.nav button .count.muted { background: var(--sunk); color: var(--ink-3); }
.nav button.active .count { background: var(--paper); }
.nav-foot {
  margin-top: 14px; padding: 10px; border-top: 1px solid var(--rule);
  font-size: 11.5px; color: var(--ink-3); line-height: 1.5;
}

/* -------------------------------------------------------------------- main */

main { padding: 18px 20px 40px; }

.screen-head { display: flex; align-items: flex-start; gap: 13px; margin-bottom: 16px; }
.step-marker {
  width: 26px; height: 26px; flex: none; margin-top: 2px;
  border-radius: 50%; background: var(--ink); color: var(--paper);
  font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.screen-head h1 { font-size: 19px; margin: 0; letter-spacing: -0.3px; }
.screen-head p { margin: 1px 0 0; color: var(--ink-3); font-size: 12.5px; max-width: 78ch; }
.screen-head .spacer { flex: 1; }
.screen-head .sub { font-size: 12.5px; color: var(--ink-3); }
.screen-head .btn + .btn { margin-left: 8px; }

.card {
  background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card + .card, .card + .banner, .banner + .card, .two-col + .card, .card + .two-col, .workspace + .next-step, .two-col + .next-step, .card + .next-step, .banner + .two-col { margin-top: 14px; }
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--rule);
}
.card-head h2 { font-size: 13px; margin: 0; letter-spacing: -0.1px; }
.card-head .spacer { flex: 1; }
.card-head .sub { font-size: 12px; color: var(--ink-3); }
.card-body { padding: 14px; }
.card-body.tight { padding: 0; }

.two-col { display: grid; grid-template-columns: minmax(320px, 1fr) minmax(300px, 1fr); gap: 14px; align-items: start; }
.browser { display: grid; grid-template-columns: minmax(340px, 500px) 1fr; gap: 14px; align-items: start; }
.add-row { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--rule); }
/* A rule's keywords are read as much as edited, so they wrap instead of
   scrolling out of sight inside a one-line field. */
.rule-keywords { width: 100%; font: inherit; font-size: 12px; font-family: var(--mono); resize: vertical; min-height: 40px; line-height: 1.5; }
.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); cursor: pointer; }
.switch input { width: auto; }
.add-row input { flex: 1; }

/* ------------------------------------------------------------------ blocks */

.banner {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 13px; border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--paper); font-size: 12.5px; color: var(--ink-2);
}
.banner svg { width: 15px; height: 15px; flex: none; margin-top: 2px; color: var(--ink-3); }
.banner b { color: var(--ink); }
.banner.warn { border-color: rgba(138, 82, 0, 0.3); background: var(--warn-bg); }
.banner.warn svg { color: var(--warn); }
.banner .btn { margin-left: 8px; }

.next-step {
  display: flex; align-items: center; gap: 12px; margin-top: 14px;
  padding: 10px 13px; border: 1px dashed var(--rule-strong); border-radius: var(--radius);
  font-size: 12.5px; color: var(--ink-2);
}
.next-step .btn { margin-left: auto; }

.all-clear { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.all-clear svg { width: 22px; height: 22px; color: var(--ok); flex: none; }

.filters { display: flex; gap: 6px; flex-wrap: wrap; }

.facts { margin: 0; display: grid; grid-template-columns: 1fr; gap: 6px; }
.facts > div { display: flex; justify-content: space-between; gap: 14px; font-size: 12.5px; border-bottom: 1px dotted var(--rule); padding-bottom: 5px; }
.facts dt { color: var(--ink-3); }
.facts dd { margin: 0; font-variant-numeric: tabular-nums; }

.footnote { margin: 12px 0 0; font-size: 11.5px; color: var(--ink-3); line-height: 1.55; }

.explain { margin: 0 0 10px; font-size: 13px; color: var(--ink-2); }

.notes { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 9px; }
.notes li { display: flex; gap: 9px; font-size: 12.5px; color: var(--ink-2); align-items: flex-start; }
.notes li svg { width: 15px; height: 15px; margin-top: 2px; }
.notes li b { color: var(--ink); }
.notes li.ok svg { color: var(--ok); }
.notes li.warn svg { color: var(--warn); }
.notes li.bad svg { color: var(--bad); }
.notes li.muted svg { color: var(--muted); }

/* ---------------------------------------------------------------- drop bar */

.dropbar {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; margin-bottom: 14px;
  border: 1.5px dashed var(--rule-strong); border-radius: var(--radius);
  background: var(--paper); font-size: 12.5px; color: var(--ink-2);
  transition: border-color 0.12s, background 0.12s;
}
.dropbar svg { width: 16px; height: 16px; color: var(--ink-3); }
.dropbar .spacer { flex: 1; }
.dropbar.over { border-color: var(--accent); background: var(--accent-bg); }

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

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: var(--radius);
  border: 1px solid var(--rule-strong); background: var(--paper); color: var(--ink);
  font: inherit; font-size: 13px; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; }
.btn:hover { background: var(--sunk); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #2a3bb0; }
.btn.ghost { border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--sunk); }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn.small svg { width: 13px; height: 13px; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:disabled:hover { background: var(--paper); }

/* ----------------------------------------------------------------- tables */

/*
 * Fixed layout with a declared width per column. Auto layout kept giving the
 * slack to whichever column asked loudest, which collapsed the prose columns on
 * a wide screen - a note column 123px wide next to a 929px document column. Every
 * table declares its widths in the markup instead.
 */
table.data { width: 100%; border-collapse: collapse; font-size: 12.5px; table-layout: fixed; }
table.data th {
  text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--ink-3); font-weight: 700; padding: 8px 12px; border-bottom: 1px solid var(--rule-strong);
  background: var(--paper); position: sticky; top: 52px; z-index: 2;
}
table.data td { padding: 7px 12px; border-bottom: 1px solid var(--rule); vertical-align: top; overflow-wrap: break-word; }
/* Numeric columns take only the width they need; the slack goes to the text
   columns that benefit from it. */
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr.clickable { cursor: pointer; }
table.data tbody tr.clickable:hover td { background: #fafbfc; }
table.data tbody tr.selected td { background: var(--accent-bg); }
table.data tbody tr.row-bad td { background: var(--bad-bg); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
/* Numbers never wrap, but a two-word heading may take a second line rather than
   overflow a fixed column. */
table.data th.num { white-space: normal; }
.date, .nowrap { white-space: nowrap; }
.date { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 11.5px; }
.dim { color: var(--ink-3); }
.filename { font-family: var(--mono); font-size: 11.5px; overflow-wrap: anywhere; }
.bad-text { color: var(--bad); font-weight: 650; }
.ok-text { color: var(--ok); font-weight: 650; }
.warn-text { color: var(--warn); }

.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 7px; vertical-align: 1px; background: var(--muted); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }
.dot.ok { background: var(--ok); }

/* ------------------------------------------------------------------ chips */

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 650;
  border: 1px solid transparent; white-space: nowrap;
}
.chip.ok { background: var(--ok-bg); color: var(--ok); border-color: rgba(20,108,67,0.2); }
.chip.warn { background: var(--warn-bg); color: var(--warn); border-color: rgba(138,82,0,0.2); }
.chip.bad { background: var(--bad-bg); color: var(--bad); border-color: rgba(180,35,24,0.2); }
.chip.muted { background: var(--muted-bg); color: var(--muted); border-color: var(--rule); }
.tag { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--ink-3); font-weight: 700; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.tile { border: 1px solid var(--rule); border-radius: var(--radius); padding: 10px 12px; }
.tile .k { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--ink-3); font-weight: 700; }
.tile .v { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.4px; margin-top: 2px; }
.tile .n { font-size: 11.5px; color: var(--ink-3); }

/* --------------------------------------------------------- review worklist */

.workspace { display: grid; grid-template-columns: minmax(280px, 340px) 1fr; gap: 14px; align-items: start; }
.queue { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.queue-head { padding: 9px 12px; border-bottom: 1px solid var(--rule); }
.queue-item {
  display: flex; align-items: flex-start; gap: 8px; width: 100%; text-align: left;
  padding: 10px 12px; border: 0; border-bottom: 1px solid var(--rule); border-left: 2px solid transparent;
  background: var(--paper); font: inherit; cursor: pointer;
}
.queue-item:last-child { border-bottom: 0; }
.queue-item:hover { background: #fafbfc; }
.queue-item.active { background: var(--accent-bg); border-left-color: var(--accent); }
.queue-item .dot { margin-top: 6px; flex: none; }
.queue-main { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }
.queue-title { font-size: 12.5px; font-weight: 600; }
.queue-main .dim { font-size: 11px; }
.queue-flag { font-size: 10.5px; color: var(--ink-3); white-space: nowrap; }

.resolution .card { margin: 0; }
.decision-grid { display: grid; grid-template-columns: minmax(360px, 1.35fr) minmax(330px, 1fr); gap: 0; }
.document-side { padding: 14px; border-right: 1px solid var(--rule); }
.form-side { padding: 14px; }
.edit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 4px; }
.field { margin-bottom: 10px; }
.field .k { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--ink-3); font-weight: 700; margin-bottom: 3px; }
.field .v { font-size: 12.5px; }
.field .source { font-family: var(--mono); font-size: 11.5px; background: var(--sunk); border: 1px solid var(--rule); border-radius: 4px; padding: 6px 8px; overflow-wrap: anywhere; }
.form-input, .cat-input, .field input, .field select {
  width: 100%; font: inherit; font-size: 12.5px; padding: 5px 8px;
  border: 1px solid var(--rule-strong); border-radius: var(--radius);
  background: var(--paper); color: var(--ink); font-variant-numeric: tabular-nums;
}
.cat-input { border-color: transparent; }
.cat-input:hover { border-color: var(--rule-strong); }
.actions { display: flex; gap: 8px; align-items: center; margin-top: 14px; flex-wrap: wrap; }

select#preset { font: inherit; font-size: 12.5px; padding: 6px 9px; border-radius: var(--radius); border: 1px solid var(--rule-strong); background: var(--paper); color: var(--ink); }

/* --------------------------------------------------------- document pane */

.docview { border: 1px solid var(--rule-strong); border-radius: var(--radius); background: var(--paper); overflow: hidden; }
.docview-bar { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-bottom: 1px solid var(--rule); flex-wrap: wrap; }
.docview-bar .spacer { flex: 1; }
.docview-page { display: inline-flex; align-items: center; gap: 3px; }
.docview-hint { font-size: 11.5px; color: var(--ink-3); }
.docview-page .mono { padding: 0 4px; color: var(--ink-2); }
.docview-stage {
  position: relative; height: 600px; overflow: auto; padding: 12px;
  background: #eceef0; display: flex; justify-content: center; align-items: flex-start;
}
.docview-canvas { position: relative; flex: none; background: #fff; box-shadow: 0 1px 4px rgba(16, 20, 24, 0.18); }
.docview-canvas canvas, .docview-canvas img { display: block; }
.docview-canvas img { max-width: none; }
.docview-overlay { position: absolute; inset: 0; pointer-events: none; }
.docview-overlay .box { position: absolute; border-radius: 2px; }
.docview-overlay .box.date { background: rgba(51, 70, 200, 0.10); outline: 1px solid rgba(51, 70, 200, 0.5); }
.docview-overlay .box.description { background: rgba(16, 20, 24, 0.05); outline: 1px solid rgba(16, 20, 24, 0.14); }
.docview-overlay .box.amount { background: rgba(51, 70, 200, 0.14); outline: 1.5px solid var(--accent); }
.docview-overlay .box.balance { background: rgba(20, 108, 67, 0.14); outline: 1.5px solid var(--ok); }
.docview-overlay .box.balance.bad { background: rgba(180, 35, 24, 0.16); outline: 2px solid var(--bad); }
.docview-loading {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 9px;
  background: rgba(236, 238, 240, 0.88); font-size: 12.5px; color: var(--ink-2);
}
.docview-note { padding: 7px 10px; border-top: 1px solid var(--rule); font-size: 11.5px; color: var(--ink-3); }

/* A workbook has no page to fit to, so its grid takes the pane's full width
   rather than shrink-wrapping into a small block in the middle. */
.docview[data-kind="spreadsheet"] .docview-canvas { width: 100%; }
.docview[data-kind="spreadsheet"] .docview-stage { padding: 12px; }
.docview-sheet { width: 100%; }
table.sheet { width: 100%; border-collapse: collapse; font-size: 11.5px; font-family: var(--mono); }
table.sheet td { padding: 5px 8px; border: 1px solid var(--rule); white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; min-width: 56px; }
table.sheet td.rownum { background: var(--sunk); color: var(--ink-3); text-align: right; width: 40px; min-width: 40px; font-variant-numeric: tabular-nums; }
table.sheet tr.sheet-target td { background: var(--accent-bg); }

/* ------------------------------------------------------------- feedback */

.progress { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--ink-2); }
.spinner { width: 14px; height: 14px; border: 2px solid var(--rule-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { padding: 26px; text-align: center; color: var(--ink-3); font-size: 13px; }

/* ---------------------------------------------------------------- about */

dialog.about { border: 1px solid var(--rule); border-radius: 10px; padding: 0; max-width: 780px; width: calc(100vw - 40px); box-shadow: 0 12px 40px rgba(16,20,24,0.18); }
dialog.about::backdrop { background: rgba(16, 20, 24, 0.35); }
dialog.about .card-head { padding: 13px 16px; }
dialog.about .card-body { padding: 16px; max-height: 72vh; overflow: auto; }
dialog.about h3 { font-size: 12.5px; margin: 18px 0 6px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--ink-3); }
dialog.about h3:first-child { margin-top: 0; }
dialog.about p { margin: 0 0 8px; font-size: 13px; color: var(--ink-2); }
dialog.about ul { margin: 0 0 8px; padding-left: 18px; font-size: 13px; color: var(--ink-2); }
dialog.about code { font-family: var(--mono); font-size: 12px; background: var(--sunk); padding: 1px 5px; border-radius: 4px; }

@media (max-width: 1100px) {
  .workspace, .decision-grid, .browser, .two-col { grid-template-columns: 1fr; }
  .document-side { border-right: 0; border-bottom: 1px solid var(--rule); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; }
  .nav { position: static; flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--rule); max-height: none; }
  .nav-foot { display: none; }
  .docview-stage { height: 380px; }
}
