/* RE:SOURCE finance dashboard. Private, offline; never part of the storefront. */
:root {
  --bg: #f2f2f0; --surface: #ffffff; --ink: #0b0b0b; --muted: #5e5e5e; --line: #e2e2e0; --line-strong: #c9c9c6;
  --accent: #e2401c; --side: #0b0b0b; --side-ink: #f2f2f0; --side-muted: #9a9a96;
  --good: #0a7a35; --good-bg: #e7f4ec; --warn: #8a5200; --warn-bg: #fff3dd; --bad: #b3261e; --bad-bg: #fdecea; --info-bg: #eef3fb; --info: #1d4f91;
  --s1: #257de0; --s2: #f47230; --s3: #00b894; --neutral: #8e8e8a;
  --radius: 4px; --font: "Archivo", "Helvetica Neue", Arial, system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.45 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.num, td.n, th.n, .kpi .v { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); font-size: 13px; }
.neg { color: var(--bad); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* layout */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 22px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 18px; }
.brand { display: flex; flex-direction: column; gap: 8px; padding: 0 8px 14px; border-bottom: 1px solid #2a2a28; }
.brand img { width: 150px; height: auto; display: block; }
.brand span { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--side-muted); font-weight: 600; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav button { all: unset; cursor: pointer; display: flex; justify-content: space-between; align-items: center; padding: 9px 10px; border-radius: var(--radius); font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--side-muted); }
.nav button:hover { color: var(--side-ink); background: #1b1b1a; }
.nav button[aria-current="page"] { color: var(--ink); background: var(--side-ink); }
.nav button:focus-visible { outline: 3px solid var(--accent); }
.nav .count { font-size: 11px; background: var(--accent); color: #fff; border-radius: 10px; padding: 1px 7px; letter-spacing: 0; }
.nav .grp { font-size: 10px; letter-spacing: .14em; color: #6f6f6b; padding: 12px 10px 4px; text-transform: uppercase; font-weight: 700; }
.side .foot { margin-top: auto; font-size: 12px; color: var(--side-muted); padding: 0 8px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--line); padding: 10px 24px; display: flex; flex-wrap: wrap; gap: 12px 18px; align-items: center; justify-content: space-between; }
.topbar .file { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.topbar .file strong { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; }
.topbar .actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.state { font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 10px; background: var(--good-bg); color: var(--good); }
.state.dirty { background: var(--warn-bg); color: var(--warn); }
.view { padding: 20px 24px 80px; max-width: 1360px; width: 100%; }
.banner { padding: 10px 24px; font-size: 13px; font-weight: 600; }
.banner.demo { background: var(--ink); color: #fff; letter-spacing: .04em; }
.banner.bad { background: var(--bad); color: #fff; }

/* headings */
h1 { font-size: 26px; line-height: 1.1; margin: 0; text-transform: uppercase; letter-spacing: -.01em; font-weight: 800; }
h2 { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; margin: 0 0 12px; font-weight: 700; }
h3 { font-size: 15px; margin: 0 0 8px; }
.head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: end; gap: 12px; margin-bottom: 16px; }
.head p { margin: 6px 0 0; max-width: 70ch; }
section.block { margin-top: 26px; }

/* controls */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; min-height: 38px; border: 1px solid var(--ink); background: var(--ink); color: #fff; border-radius: var(--radius); cursor: pointer; font-size: 13px; font-weight: 600; letter-spacing: .04em; text-decoration: none; white-space: nowrap; }
.btn:hover { background: #2b2b2a; }
.btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn.ghost:hover { border-color: var(--ink); }
.btn.small { min-height: 30px; padding: 4px 10px; font-size: 12px; }
.btn.danger { background: var(--surface); color: var(--bad); border-color: var(--bad); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.seg button { all: unset; cursor: pointer; padding: 7px 12px; font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); border-right: 1px solid var(--line); white-space: nowrap; }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.seg button:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 18px; }
.filters .lbl { font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.filters input[type="date"] { padding: 5px 8px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); }
.filters .range { font-size: 13px; color: var(--muted); margin-left: auto; }
label.f { display: block; font-size: 12px; font-weight: 600; letter-spacing: .04em; color: var(--muted); margin: 10px 0 4px; }
.in, select.in, textarea.in { width: 100%; padding: 8px 10px; min-height: 38px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); }
textarea.in { min-height: 70px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
.check { display: flex; gap: 8px; align-items: flex-start; margin-top: 12px; font-size: 14px; }
.check input { margin-top: 3px; width: 18px; height: 18px; }

/* cards and KPIs */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; min-width: 0; }
.card > h2 { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; min-height: 92px; display: flex; flex-direction: column; gap: 4px; }
.kpi .k { font-size: 11px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.kpi .v { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.kpi .s { font-size: 12px; color: var(--muted); }
.kpi.total { background: var(--ink); border-color: var(--ink); color: #fff; }
.kpi:not(.total) .neg { color: inherit; } /* a deduction is not an alarm; only a negative total is */
.kpi.total .neg { color: #ff9b8f; }
.kpi.total .k, .kpi.total .s { color: #bdbdb8; }
.kgroup { font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 22px 0 8px; display: flex; justify-content: space-between; }
.note { font-size: 12px; color: var(--muted); border-left: 3px solid var(--line-strong); padding: 6px 10px; margin: 14px 0 0; background: var(--surface); }
.disclaimer { font-size: 12px; color: var(--muted); padding: 8px 12px; border: 1px dashed var(--line-strong); border-radius: var(--radius); margin-bottom: 14px; background: var(--surface); }

/* status */
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; padding: 2px 8px; border-radius: 10px; white-space: nowrap; background: #ececea; color: #333; }
.pill.good { background: var(--good-bg); color: var(--good); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.info { background: var(--info-bg); color: var(--info); }
.pill::before { font-size: 11px; }
.pill.good::before { content: "✓"; } .pill.warn::before { content: "!"; } .pill.bad::before { content: "✕"; } .pill.info::before { content: "i"; font-style: italic; }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius); font-size: 14px; margin: 0 0 10px; }
.alert.warn { background: var(--warn-bg); color: #5c3700; } .alert.bad { background: var(--bad-bg); color: #7d1a14; } .alert.good { background: var(--good-bg); color: #08532a; } .alert.info { background: var(--info-bg); color: #163b6c; }
.alert b.ic { flex: none; width: 20px; height: 20px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 12px; color: #fff; }
.alert.warn b.ic { background: var(--warn); } .alert.bad b.ic { background: var(--bad); } .alert.good b.ic { background: var(--good); } .alert.info b.ic { background: var(--info); }
ul.issues { list-style: none; margin: 0; padding: 0; }
ul.issues li { display: flex; gap: 10px; align-items: baseline; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
ul.issues li:last-child { border-bottom: 0; }
.checklist li { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; list-style: none; }
.checklist { padding: 0; margin: 0; }

/* tables */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th { text-align: left; font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); background: #fafaf8; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.n, th.n { text-align: right; white-space: nowrap; }
tr.total td { font-weight: 700; background: #fafaf8; border-top: 1px solid var(--line-strong); }
tr.void td { color: #9a9a96; text-decoration: line-through; }
tr.void td.acts, tr.void td.keep { text-decoration: none; }
td.acts { white-space: nowrap; text-align: right; }
td.acts .btn + .btn { margin-left: 4px; }
.sub { display: block; font-size: 12px; color: var(--muted); }

/* charts */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .grid.zero { stroke: var(--line-strong); }
.chart .axis { font-size: 11px; fill: var(--muted); }
.chart .lbl { font-size: 12px; fill: var(--ink); }
.chart .val { font-size: 12px; fill: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.chart .hit { fill: transparent; }
.chart .hit:hover { fill: rgba(0, 0, 0, .04); }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; color: var(--ink); margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i, .tip i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }
.legend b.ln, .tip b.ln { display: inline-block; width: 14px; border-top: 2px solid; }
.tip { position: fixed; z-index: 50; pointer-events: none; background: var(--ink); color: #fff; font-size: 12px; line-height: 1.5; padding: 8px 10px; border-radius: var(--radius); max-width: 280px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.tip i { margin-right: 6px; vertical-align: -1px; } .tip b.ln { margin-right: 6px; vertical-align: 3px; }
details.tbl summary { cursor: pointer; font-size: 12px; color: var(--muted); margin-top: 8px; }
details.tbl table { margin-top: 6px; }

/* cash panel */
.cash { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 12px 16px; }
.cash div { display: flex; flex-direction: column; gap: 2px; }
.cash .k { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.cash .v { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* dialog */
dialog { border: 0; border-radius: 6px; padding: 0; width: min(620px, 94vw); max-height: 92vh; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(11, 11, 11, .55); }
dialog form { display: flex; flex-direction: column; max-height: 92vh; }
dialog header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
dialog header h2 { margin: 0; }
dialog .body { padding: 6px 20px 18px; overflow-y: auto; }
dialog footer { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; background: #fafaf8; }
dialog .err { margin-top: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }

#toast { position: fixed; right: 20px; bottom: 20px; z-index: 60; max-width: 460px; background: var(--ink); color: #fff; padding: 12px 16px; border-radius: var(--radius); font-size: 14px; box-shadow: 0 8px 30px rgba(0,0,0,.3); }
#toast.error { background: var(--bad); }

/* statements */
.statement { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.statement .tot { display: flex; justify-content: space-between; font-weight: 700; border-top: 2px solid var(--ink); padding-top: 8px; margin-top: 8px; }
.steps { counter-reset: s; display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 18px; }
.steps div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; font-size: 13px; }
.steps div::before { counter-increment: s; content: counter(s); display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--ink); color: #fff; font-size: 11px; font-weight: 700; margin-right: 8px; }

@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .steps { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 14px; gap: 10px; }
  .brand { border: 0; padding: 0; } .brand img { width: 110px; } .brand span, .side .foot, .nav .grp { display: none; }
  .nav { flex-direction: row; overflow-x: auto; width: 100%; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; } .span2 { grid-column: auto; }
  .view { padding: 16px 14px 60px; } .topbar { padding: 10px 14px; }
}
@media print {
  .side, .topbar, .filters, .btn, .banner.demo, .no-print { display: none !important; }
  .app { display: block; } body { background: #fff; } .view { padding: 0; }
  .card, .statement { break-inside: avoid; border-color: #999; }
}
@media (prefers-reduced-motion: no-preference) { .btn, .nav button, .seg button { transition: background-color .15s, color .15s, border-color .15s; } }
