/* Headroom — admin-home register. Near-white ground, quiet cards with real
   space, big type on the four numbers, everything else small. One accent
   (company blue) for the entity distinction only; warnings are ink-weight;
   the single critical flag is inverse ink. */

:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-hover: #fafafb;
  --ink: #1a1c1e;
  --ink-2: #5c5f63;
  --ink-3: #6b6e73;
  --line: #e3e4e6;
  --line-strong: #c9cbce;
  --accent: #2c5fd8;        /* company */
  --accent-soft: #eef2fc;
  --danger: #c4320a;
  --shadow: 0 1px 2px rgba(23, 24, 26, 0.05), 0 2px 10px rgba(23, 24, 26, 0.04);
  --radius: 10px;
  --radius-sm: 7px;
  /* The native UI face of whatever machine this runs on — what a real admin
     tool uses, and no webfont to wait for. */
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scrollbar-color: var(--line-strong) var(--bg); }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 13.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'tnum' 1, 'cv05' 1;
}

::selection { background: var(--ink); color: var(--surface); }
input, textarea { caret-color: var(--ink); accent-color: var(--ink); }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 2px; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
a { color: inherit; }

/* ---------- Top bar ---------- */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 0 clamp(16px, 4vw, 40px);
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar .brand { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; padding: 15px 0; }
.topbar nav { display: flex; gap: 2px; }
.topbar nav a {
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink-2);
  padding: 16px 12px 13px;
  border-bottom: 2px solid transparent;
}
.topbar nav a:hover { color: var(--ink); }
.topbar nav a.active { color: var(--ink); border-bottom-color: var(--ink); font-weight: 600; }

/* ---------- Ripple strip ---------- */

.ripple {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 8px clamp(16px, 4vw, 40px);
  display: flex;
  align-items: baseline;
  gap: 18px;
  flex-wrap: wrap;
  font-size: 12.5px;
  color: var(--ink-2);
  animation: fade-in 200ms ease-out;
}
@keyframes fade-in { from { opacity: 0; transform: translateY(-3px); } }
.ripple .lead { font-weight: 600; color: var(--ink); }
.ripple .move b { color: var(--ink); font-weight: 600; }
.ripple .dismiss { margin-left: auto; color: var(--ink-3); }
.ripple .dismiss:hover { color: var(--ink); }

/* ---------- Frame ---------- */

main { max-width: 1020px; margin: 0 auto; padding: clamp(24px, 4vh, 40px) clamp(16px, 4vw, 40px) 96px; }
h1 { font-size: 20px; font-weight: 650; letter-spacing: -0.01em; }
.page-head { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }

/* ---------- Unverified marker: a symbol, not a sentence ---------- */

sup.unv {
  font-size: 0.62em;
  color: var(--ink-3);
  cursor: help;
  font-weight: 700;
  margin-left: 1px;
  vertical-align: super;
}
.srcref { position: relative; cursor: help; }
button.srcref { font: inherit; color: inherit; padding: 0; text-align: inherit; }
.popover {
  position: fixed;
  z-index: 60;
  max-width: 300px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  box-shadow: 0 6px 24px rgba(23, 24, 26, 0.16);
  padding: 11px 13px;
  font-size: 12px;
  line-height: 1.45;
  pointer-events: none;
  animation: fade-in 120ms ease-out;
}
.popover .pop-rule { font-weight: 650; }
.popover .pop-meta { color: var(--ink-2); margin-top: 3px; }
.popover .pop-src { color: var(--ink-3); margin-top: 3px; word-break: break-all; }
.popover .pop-unv { color: var(--ink); font-weight: 650; margin-top: 4px; }

/* ---------- Segmented period toggle ---------- */

.segmented { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 2px; }
.segmented button {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-2);
  padding: 5px 12px;
  border-radius: 5px;
}
.segmented button:hover { color: var(--ink); }
.segmented button.active { background: var(--ink); color: var(--surface); font-weight: 600; }

/* ---------- The four numbers ---------- */

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 44px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px 16px;
}
.stat .label { font-size: 12.5px; font-weight: 500; color: var(--ink-2); }
.stat .value { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; margin-top: 6px; line-height: 1.15; }
.stat .meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }
.stat .delta { font-size: 12px; color: var(--ink-3); white-space: nowrap; }
.stat .spark { flex: 0 0 auto; }
.stat .spark polyline { stroke: var(--line-strong); }
.stat .spark .end-dot { fill: var(--ink-2); }
.stat.entity-company { border-top: 3px solid var(--accent); }
.stat .value .none { color: var(--ink-3); }

/* ---------- Ask box ---------- */

.ask-wrap { max-width: 640px; margin: 0 auto 18px; }
.ask-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 6px 8px 6px 18px;
  transition: border-color 140ms;
}
.ask-box:focus-within { border-color: var(--ink); }
.ask-box input[type='text'] { flex: 1; border: none; background: none; font-size: 14.5px; padding: 9px 0; }
.ask-box input[type='text']:focus { outline: none; }
.ask-box input::placeholder { color: var(--ink-3); }
.ask-box .attach { color: var(--ink-3); font-size: 12.5px; padding: 8px 10px; border-radius: var(--radius-sm); white-space: nowrap; }
.ask-box .attach:hover { color: var(--ink); background: var(--surface-hover); }
.ask-box .go {
  background: var(--ink);
  color: var(--surface);
  font-weight: 600;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 8px;
}
.ask-box .go:hover { background: #33363a; }
.ask-box .go:disabled { opacity: 0.4; }
.ask-box.dragover { border-color: var(--ink); background: var(--surface-hover); }
.ask-note { text-align: center; font-size: 12px; color: var(--ink-3); margin-top: 8px; }
.ask-results { max-width: 640px; margin: 18px auto 0; }
.answer-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 20px;
  font-size: 13.5px;
  white-space: pre-wrap;
}

/* ---------- Chips ---------- */

.chips { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin: 18px 0 0; }
.chip {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 14px;
  text-decoration: none;
  transition: border-color 130ms, background 130ms;
}
.chip:hover { border-color: var(--line-strong); background: var(--surface-hover); }
.chip .n { color: var(--ink-3); font-weight: 500; }
.chip.quiet { color: var(--ink-2); }
.chip.critical { background: var(--ink); border-color: var(--ink); color: var(--surface); font-weight: 600; }
.chip.critical:hover { background: #33363a; }

/* ---------- Cards ---------- */

.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 44px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
}
.card h2 { font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 14px; }
.card .big { font-size: 20px; font-weight: 650; letter-spacing: -0.015em; }
.card .sub { font-size: 12.5px; color: var(--ink-3); margin-top: 3px; }
.card .row-line { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.card .row-line:last-child { border-bottom: none; }
.card .row-line .amt { font-weight: 600; white-space: nowrap; }
.card .row-line .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.bar { height: 6px; background: var(--bg); border-radius: 3px; margin-top: 14px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--ink); border-radius: 3px; }
.bar-legend { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-3); margin-top: 7px; }

/* ---------- Entity mark ---------- */

.entity-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); vertical-align: 0; }
.entity-dot.company { background: var(--accent); }

/* ---------- Tables (ledger) ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.list thead th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-3);
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.list thead th.num, .list td.num { text-align: right; }
.list tbody td { padding: 13px 16px; border-bottom: 1px solid var(--line); vertical-align: baseline; }
.list tbody td:nth-child(2) { white-space: nowrap; }
.list tbody tr:last-child td { border-bottom: none; }
.list tbody tr { cursor: pointer; }
.list tbody tr:hover { background: var(--surface-hover); }
.list td.num { font-weight: 600; white-space: nowrap; }
.list td .marks { margin-left: 8px; }
.mark {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--ink-2);
  background: var(--bg);
  border-radius: 5px;
  padding: 1px 7px;
  margin-left: 5px;
  vertical-align: 1px;
}
.mark.gap { color: var(--ink); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line-strong); }
.mark.q { color: var(--ink); background: var(--surface); box-shadow: inset 0 0 0 1px var(--ink); font-weight: 700; }

/* ---------- Detail panel ---------- */

.sheet-backdrop { position: fixed; inset: 0; background: rgba(23, 24, 26, 0.28); z-index: 40; animation: fade-in 150ms ease-out; }
.sheet {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(430px, 96vw);
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: -8px 0 30px rgba(23, 24, 26, 0.12);
  z-index: 41;
  padding: 26px 28px;
  overflow-y: auto;
  animation: sheet-in 200ms cubic-bezier(0.2, 0.9, 0.3, 1);
}
@keyframes sheet-in { from { transform: translateX(24px); opacity: 0; } }
.sheet h2 { font-size: 16px; font-weight: 650; }
.sheet .close { position: absolute; top: 18px; right: 18px; color: var(--ink-3); font-size: 18px; line-height: 1; padding: 6px; }
.sheet .close:hover { color: var(--ink); }
.sheet .amount-line { font-size: 24px; font-weight: 650; letter-spacing: -0.02em; margin: 4px 0 18px; }
.sheet .question {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  margin-bottom: 18px;
}
.sheet .question .actions { margin-top: 10px; display: flex; gap: 10px; }
.sheet-fields { display: grid; gap: 12px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 22px; align-items: center; }
.sheet-actions .danger-link { margin-left: auto; color: var(--ink-3); font-size: 12.5px; }
.sheet-actions .danger-link:hover { color: var(--danger); }

/* ---------- Forms ---------- */

input[type='text'], input[type='date'], input[type='number'], select, textarea {
  font: inherit;
  font-size: 13.5px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  width: 100%;
}
input:hover, select:hover, textarea:hover { border-color: var(--ink-3); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink); }
input:disabled, select:disabled { background: var(--bg); color: var(--ink-3); }
input::placeholder, textarea::placeholder { color: var(--ink-3); }
label.f { display: block; font-size: 12px; font-weight: 500; color: var(--ink-2); margin-bottom: 4px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--surface);
  border: 1px solid var(--ink);
  transition: background 130ms;
}
.btn:hover { background: #33363a; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.quiet { background: var(--surface); color: var(--ink); border-color: var(--line-strong); font-weight: 500; }
.btn.quiet:hover { border-color: var(--ink-3); background: var(--surface-hover); }
.btn.small { padding: 6px 12px; font-size: 12.5px; }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: #a72908; }

.field-grid { display: grid; gap: 12px 14px; grid-template-columns: 1fr 1fr; }
.field-grid .wide { grid-column: span 2; }
.hint { color: var(--ink-3); font-size: 12px; }
.error-note { color: var(--danger); font-size: 12.5px; margin-top: 8px; }
.empty { color: var(--ink-2); font-size: 13px; padding: 26px 0; text-align: center; }

/* ---------- Verdicts (ask box results) ---------- */

.verdict-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-top: 12px;
  text-align: left;
}
.verdict-word { font-size: 13.5px; font-weight: 650; }
.verdict-sub { color: var(--ink-2); font-size: 12.5px; margin-top: 2px; }
.verdict-body { margin-top: 12px; }
.verdict-note { font-size: 12.5px; color: var(--ink-2); border-top: 1px solid var(--line); margin-top: 12px; padding-top: 10px; }

.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
.compare .cell { padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; display: flex; justify-content: space-between; gap: 12px; }
.compare .cell .k { color: var(--ink-3); }
.compare .cell .diff { font-weight: 650; }
.compare-heads { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-3); font-weight: 600; margin-bottom: 4px; }

.candidate { display: flex; align-items: baseline; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.candidate input[type='radio'] { width: auto; }

.skeleton { position: relative; overflow: hidden; background: var(--bg); border-radius: 6px; min-height: 13px; }
.skeleton::after { content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.7), transparent); animation: shimmer 1.3s infinite; }
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* ---------- Threshold warning (dividends) ---------- */

.crossing { border: 1px solid var(--ink); border-radius: var(--radius-sm); padding: 12px 15px; font-size: 13px; margin-top: 12px; }
.crossing b { font-weight: 650; }
.crossing.unlawful { background: var(--ink); color: var(--surface); }

/* ---------- Dialog ---------- */

dialog {
  border: none;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 28px 32px;
  max-width: 620px;
  width: calc(100vw - 48px);
  box-shadow: 0 16px 50px rgba(23, 24, 26, 0.25);
}
dialog::backdrop { background: rgba(23, 24, 26, 0.35); }
.doc-paper { font-size: 13px; line-height: 1.6; white-space: pre-wrap; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 20px 24px; background: var(--bg); max-height: 50vh; overflow-y: auto; }
.dialog-actions { display: flex; gap: 10px; margin-top: 18px; justify-content: flex-end; }

@media print {
  body * { visibility: hidden; }
  dialog[open], dialog[open] * { visibility: visible; }
  dialog[open] { position: absolute; inset: 0; box-shadow: none; max-width: none; width: auto; }
  .dialog-actions { display: none; }
}

/* ---------- Export ---------- */

.export-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .cards { grid-template-columns: 1fr; }
  .export-cols, .compare, .compare-heads { grid-template-columns: 1fr; }
  .field-grid { grid-template-columns: 1fr; }
  .field-grid .wide { grid-column: span 1; }
}
@media (max-width: 480px) {
  .stats { grid-template-columns: 1fr; }
  /* Two rows: brand and save state together, nav beneath — the indicator
     must not claim a row of its own. */
  .topbar { flex-wrap: wrap; padding-bottom: 0; gap: 0 12px; }
  .topbar .brand { order: 0; padding: 12px 0 10px; }
  .topbar #sync-dot { order: 1; margin-left: auto; }
  .topbar nav { order: 2; width: 100%; overflow-x: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  .skeleton::after { animation: none; }
}

/* ---------- Hosted shell: setup, sync, offline ---------- */

.setup-wrap { min-height: 70vh; display: flex; align-items: center; justify-content: center; padding: 24px 0; }
.setup-card { max-width: 420px; width: 100%; padding: 28px 30px; }
.setup-card h1 { margin-bottom: 6px; }
.setup-lede { color: var(--ink-2); font-size: 13.5px; margin-bottom: 18px; }
.setup-card .sheet-actions { margin-top: 16px; }
.setup-foot { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }

.sync {
  margin-left: auto;
  font-size: 12px;
  color: var(--ink-3);
  white-space: nowrap;
  padding-left: 12px;
}
.sync.error { color: var(--danger); font-weight: 600; }

.offline-strip {
  background: var(--ink);
  color: var(--surface);
  font-size: 12.5px;
  font-weight: 500;
  padding: 7px clamp(16px, 4vw, 40px);
}

/* Standalone PWA: keep content clear of the notch and the home indicator. */
@supports (padding: max(0px)) {
  .topbar { padding-left: max(clamp(16px, 4vw, 40px), env(safe-area-inset-left)); padding-right: max(clamp(16px, 4vw, 40px), env(safe-area-inset-right)); }
  main {
    padding-left: max(clamp(16px, 4vw, 40px), env(safe-area-inset-left));
    padding-right: max(clamp(16px, 4vw, 40px), env(safe-area-inset-right));
    padding-bottom: max(96px, env(safe-area-inset-bottom));
  }
  .sheet { padding-bottom: max(26px, env(safe-area-inset-bottom)); }
}

/* Touch: the ledger row and the sheet are the two things used on a phone. */
@media (pointer: coarse) {
  .list tbody td { padding-top: 15px; padding-bottom: 15px; }
  .btn { padding: 11px 18px; }
  .btn.small { padding: 8px 14px; }
  .chip { padding: 8px 15px; }
  .sheet .close { padding: 10px; }
}

.offline-strip.failed { display: flex; align-items: center; gap: 16px; }
.offline-strip.failed button { color: var(--surface); opacity: 0.75; font-size: 12.5px; margin-left: auto; }
.offline-strip.failed button:hover { opacity: 1; }
.sheet-error { margin-top: 10px; }
