:root {
  /* Light theme (default) */
  --ink: #18212b; --ink-2: #4a5663; --ink-3: #6f7a86;
  --paper: #f4f6f5; --surface: #ffffff; --line: #dde3e1; --line-2: #edf1ef;
  --rail: #ffffff; --rail-ink: #33424a; --rail-hi: #0b2326; --rail-mute: #6c7e81; --rail-edge: #dde3e1;
  --rail-hover: #eef4f2; --rail-on: #e1f1ed; --rail-bar: #0f766e; --rail-line: rgba(14,47,51,.12);
  --accent: #0f766e; --accent-ink: #ffffff; --accent-soft: #e3f2ef;
  --warn: #b45309; --warn-soft: #fdf1e3; --bad: #b42318; --bad-soft: #fde8e6; --good: #15803d; --good-soft: #e5f4e9;
  --s1: #00897b; --s2: #c2850c;
  --focus: #2563eb;
  --f-body: "IBM Plex Sans", system-ui, sans-serif;
  --f-display: var(--f-display);
  --r: 6px; --r-lg: 10px;
  --shadow: 0 1px 2px rgba(16, 40, 44, .06), 0 6px 20px rgba(16, 40, 44, .07);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #e7ecea; --ink-2: #aab5b3; --ink-3: #7d8a88;
    --paper: #0f1716; --surface: #16201f; --line: #26322f; --line-2: #1c2725;
    --rail: #0a1f21; --rail-ink: #c9dcdb; --rail-hi: #ffffff; --rail-mute: #7fa3a2; --rail-edge: transparent;
    --rail-hover: rgba(255,255,255,.06); --rail-on: rgba(94,234,212,.13); --rail-bar: #5eead4; --rail-line: rgba(255,255,255,.12);
    --accent: #2bb3a3; --accent-ink: #04211e; --accent-soft: #12332f;
    --warn-soft: #34240f; --bad-soft: #3a1714; --good-soft: #12301c; --warn: #f0a04b; --bad: #f2786b; --good: #4ade80;
    --s1: #14a394; --s2: #b97f1a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --ink: #e7ecea; --ink-2: #aab5b3; --ink-3: #7d8a88;
    --paper: #0f1716; --surface: #16201f; --line: #26322f; --line-2: #1c2725;
    --rail: #0a1f21; --rail-ink: #c9dcdb; --rail-hi: #ffffff; --rail-mute: #7fa3a2; --rail-edge: transparent;
    --rail-hover: rgba(255,255,255,.06); --rail-on: rgba(94,234,212,.13); --rail-bar: #5eead4; --rail-line: rgba(255,255,255,.12);
    --accent: #2bb3a3; --accent-ink: #04211e; --accent-soft: #12332f;
    --warn-soft: #34240f; --bad-soft: #3a1714; --good-soft: #12301c; --warn: #f0a04b; --bad: #f2786b; --good: #4ade80;
    --s1: #14a394; --s2: #b97f1a;
    color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 var(--f-body); color: var(--ink); background: var(--paper); -webkit-font-smoothing: antialiased; }
.num, td.n, th.n, input.n { font-variant-numeric: tabular-nums; text-align: right; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font: 700 22px/1.2 var(--f-display); letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--ink-3); }
.small { font-size: 12.5px; }
.boot { padding: 40vh 0 0; text-align: center; color: var(--ink-3); }
[hidden] { display: none !important; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.rail { background: var(--rail); border-right: 1px solid var(--rail-edge); color: var(--rail-ink); position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 14px 10px 24px; display: flex; flex-direction: column; gap: 2px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; color: var(--rail-hi); }
.brand svg { flex: none; }
.brand b { font: 700 17px var(--f-display); letter-spacing: .01em; display: block; }
.brand span { font-size: 12px; color: var(--rail-mute); display: block; max-width: 150px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grp-wrap { margin-top: 8px; }
.rail .grp { width: 100%; display: flex; justify-content: space-between; align-items: center; background: none; border: 0; border-radius: 5px; margin: 0; padding: 6px 10px; font: 500 12px var(--f-body); color: var(--rail-mute); cursor: pointer; text-align: left; }
.rail .grp:hover { color: var(--rail-hi); background: var(--rail-hover); }
.rail .grp.static { cursor: default; }
.rail .grp.static:hover { background: none; color: var(--rail-mute); }
.grp .chev { transition: transform .15s; }
.grp-wrap.shut .chev { transform: rotate(-90deg); }
.grp-wrap.shut .grp-items { display: none; }
.grp-wrap.shut.has-on .grp-items { display: block; }
.grp-wrap.shut.has-on .grp-items a:not(.on) { display: none; }
.grp-items { display: flex; flex-direction: column; gap: 2px; }
.grp-wrap.shut.has-on .grp-items { display: flex; }
.rail-foot { margin-top: auto !important; padding-top: 14px !important; font-size: 12.5px !important; color: var(--rail-mute) !important; }
button.icon { padding: 7px 8px; }
.rail a { color: var(--rail-ink); display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; border-radius: 5px; font-size: 13.5px; }
.rail a:hover { background: var(--rail-hover); text-decoration: none; color: var(--rail-hi); }
.rail a.on { background: var(--rail-on); color: var(--rail-hi); box-shadow: inset 3px 0 0 var(--rail-bar); font-weight: 500; }
.rail .lock { font-size: 11px; color: var(--rail-mute); }
.main { min-width: 0; display: flex; flex-direction: column; }
.top { height: 54px; display: flex; align-items: center; gap: 12px; padding: 0 22px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 20; }
.top .grow { flex: 1; }
.menu-btn { display: none; }
.banner { padding: 8px 22px; font-size: 13px; background: var(--warn-soft); color: var(--warn); border-bottom: 1px solid var(--line); }
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.page { padding: 22px; max-width: 1360px; width: 100%; }
.page-head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .grow { flex: 1; min-width: 200px; }
.page-head p { margin: 4px 0 0; color: var(--ink-2); }

/* ---------- controls ---------- */
button, .btn { font: inherit; font-weight: 500; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 7px 13px; border-radius: var(--r); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; line-height: 1.25; }
button:hover, .btn:hover { border-color: var(--ink-3); text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.07); }
button.danger { color: var(--bad); }
button.ghost { border-color: transparent; background: transparent; }
button.ghost:hover { background: var(--line-2); }
button.sm { padding: 4px 9px; font-size: 12.5px; }
button:disabled { opacity: .5; cursor: not-allowed; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 7px 9px; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
textarea { min-height: 64px; resize: vertical; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--ink-2); font-weight: 500; }
label.chk { display: flex; gap: 8px; align-items: center; font-size: 13.5px; color: var(--ink); }
.grid { display: grid; gap: 12px 14px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.grid .wide { grid-column: 1 / -1; }
.grid .w2 { grid-column: span 2; }
.search { max-width: 280px; }

/* ---------- panels & tables ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
.panel > .ph { padding: 12px 16px; border-bottom: 1px solid var(--line-2); display: flex; align-items: center; gap: 10px; }
.panel > .pb { padding: 16px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.tbl-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--ink-2); background: var(--surface); position: sticky; top: 0; white-space: nowrap; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--line-2); }
tfoot td { font-weight: 600; border-top: 1px solid var(--line); border-bottom: 0; }
.empty { padding: 42px 16px; text-align: center; color: var(--ink-2); }
.empty b { display: block; color: var(--ink); font-size: 15px; margin-bottom: 4px; }
.pill { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.pill.posted { background: var(--good-soft); color: var(--good); }
.pill.draft { background: var(--warn-soft); color: var(--warn); }
.pill.void { background: var(--bad-soft); color: var(--bad); text-decoration: line-through; }
.pill.acc { background: var(--accent-soft); color: var(--accent); }
.bar { height: 5px; background: var(--line-2); border-radius: 3px; overflow: hidden; width: 70px; display: inline-block; vertical-align: middle; margin-right: 6px; }
.bar i { display: block; height: 100%; background: var(--accent); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 8px 14px; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.on { color: var(--ink); border-color: var(--accent); font-weight: 600; text-decoration: none; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line-2); }
.filters input, .filters select { width: auto; }

/* ---------- dashboard ---------- */
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); overflow: hidden; margin-bottom: 16px; }
.figure { padding: 14px 16px; border-right: 1px solid var(--line-2); }
.figure:last-child { border-right: 0; }
.figure .k { font-size: 12.5px; color: var(--ink-2); }
.figure .v { font: 600 21px/1.3 var(--f-body); font-variant-numeric: tabular-nums; margin-top: 2px; }
.figure .s { font-size: 12px; color: var(--ink-3); }
.figure .s.bad { color: var(--bad); }
.cols { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; }
.cols > *, .stack > * { min-width: 0; }
.panel > .ph { flex-wrap: wrap; }
.chart { width: 100%; height: 210px; display: block; }

/* ---------- document sheet ---------- */
.sheet { background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 36px 40px; position: relative; box-shadow: var(--shadow); }
.sheet-head { display: flex; justify-content: space-between; gap: 24px; padding-bottom: 18px; border-bottom: 2px solid var(--ink); }
.sheet-head .co b { font-size: 17px; display: block; }
.sheet-head .co div { color: var(--ink-2); font-size: 12.5px; }
.sheet-head .co img { max-height: 56px; max-width: 180px; display: block; margin-bottom: 8px; }
.sheet-title { text-align: right; }
.sheet-title h1 { font-size: 26px; text-transform: none; }
.sheet-title .no { font: 600 15px var(--f-body); font-variant-numeric: tabular-nums; margin-top: 4px; }
.sheet-meta { display: grid; grid-template-columns: 1.4fr 1fr; gap: 24px; padding: 18px 0; }
.sheet-meta .lbl { font-size: 11.5px; color: var(--ink-3); font-weight: 600; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 14px; font-size: 13px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }
.sheet table th { background: transparent; border-bottom: 1px solid var(--ink); color: var(--ink); }
.sheet table td { font-size: 13px; }
.sheet-foot { display: grid; grid-template-columns: 1fr 300px; gap: 24px; margin-top: 14px; }
.totals { font-variant-numeric: tabular-nums; }
.totals div { display: flex; justify-content: space-between; padding: 3px 0; }
.totals .grand { border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 8px; font-size: 16px; font-weight: 700; }
.signs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; margin-top: 54px; font-size: 12px; color: var(--ink-2); }
.signs div { border-top: 1px solid var(--ink-3); padding-top: 5px; }
.sheet .foot-note { margin-top: 22px; font-size: 11.5px; color: var(--ink-3); }
/* the rubber stamp */
.stamp { display: inline-block; margin: 6px 0 14px 8px; transform: rotate(-7deg); transform-origin: left center; border: 3px double currentColor; border-radius: 6px; padding: 4px 14px 3px; font: 700 26px/1 var(--f-display); letter-spacing: .12em; opacity: .78; pointer-events: none; mix-blend-mode: multiply; }
.stamp.posted { color: var(--good); }
.stamp.draft { color: var(--warn); }
.stamp.void { color: var(--bad); }
.stamp small { display: block; font: 600 10px var(--f-body); letter-spacing: .04em; text-align: center; margin-top: 2px; }
.sheet.modern .sheet-head { border-bottom: 0; background: var(--accent); color: var(--accent-ink); margin: -36px -40px 0; padding: 26px 40px; border-radius: 4px 4px 0 0; }
.sheet.modern .sheet-head .co div { color: inherit; opacity: .85; }
.sheet.modern table th { border-bottom-color: var(--accent); color: var(--accent); }
.doc-layout { display: grid; grid-template-columns: minmax(0, 1fr) 270px; gap: 18px; align-items: start; }
.side { display: flex; flex-direction: column; gap: 12px; position: sticky; top: 72px; }
.side .panel .pb { padding: 12px 14px; }
.related a { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 5px 0; font-size: 13px; border-bottom: 1px solid var(--line-2); }

/* ---------- editor ---------- */
.editor .lines td { padding: 4px 6px; }
.editor .lines input, .editor .lines select { padding: 5px 7px; }
.editor .lines td.amt { min-width: 110px; }
.ac { position: relative; }
.ac-list { position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 2px); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); max-height: 300px; overflow-y: auto; min-width: 320px; }
.ac-list div { padding: 7px 10px; cursor: pointer; border-bottom: 1px solid var(--line-2); font-size: 13px; }
.ac-list div:hover, .ac-list div.hi { background: var(--accent-soft); }
.ac-list small { color: var(--ink-3); display: block; }
.scan { display: flex; gap: 8px; align-items: center; }
.scan input { max-width: 260px; }
.sumbox { min-width: 280px; margin-left: auto; }

/* ---------- modal / toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 25, 27, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--surface); border-radius: var(--r-lg); width: 100%; max-width: 640px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 920px; }
.modal header { padding: 14px 18px; border-bottom: 1px solid var(--line-2); display: flex; align-items: center; }
.modal header h2 { flex: 1; }
.modal .mb { padding: 18px; }
.modal footer { padding: 12px 18px; border-top: 1px solid var(--line-2); display: flex; justify-content: flex-end; gap: 8px; }
#toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--ink); color: var(--surface); padding: 10px 14px; border-radius: var(--r); max-width: 380px; font-size: 13.5px; box-shadow: var(--shadow); }
.toast.err { background: var(--bad); color: #fff; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth-art { background: var(--rail); border-right: 1px solid var(--rail-edge); color: var(--rail-ink); padding: 48px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-art h1 { font-size: 40px; line-height: 1.05; color: var(--rail-hi); max-width: 13ch; }
.auth-art p { max-width: 42ch; color: var(--rail-mute); font-size: 15px; }
.ledger { font: 500 13px/1.9 var(--f-body); font-variant-numeric: tabular-nums; border-top: 1px solid var(--rail-line); max-width: 440px; }
.ledger div { display: flex; justify-content: space-between; border-bottom: 1px solid var(--rail-line); padding: 4px 0; }
.ledger span:last-child { color: var(--rail-bar); }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 32px; }
.auth-form form { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; }
.auth-form .alt { font-size: 13px; color: var(--ink-2); }
.err-msg { color: var(--bad); font-size: 13px; min-height: 18px; }

/* ---------- responsive ---------- */
@media screen and (max-width: 1080px) { .doc-layout, .cols { grid-template-columns: 1fr; } .side { position: static; } }
@media screen and (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: fixed; z-index: 40; left: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; }
  .shell.nav-open .rail { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .menu-btn { display: inline-flex; }
  .top, .page { padding-left: 16px; padding-right: 16px; }
  .auth { grid-template-columns: 1fr; }
  .auth-art { padding: 28px 20px; }
  .auth-art h1 { font-size: 28px; }
  .ledger { display: none; }
  .sheet { padding: 22px 16px; }
  .sheet.modern .sheet-head { margin: -22px -16px 0; padding: 20px 16px; }
  .sheet-head, .sheet-meta, .sheet-foot { grid-template-columns: 1fr; flex-direction: column; }
  .sheet-title { text-align: left; }
  .stamp { font-size: 20px; }
  .search { max-width: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- print ---------- */
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; }
  .rail, .top, .banner, .side, .page-head, .no-print, #toasts { display: none !important; }
  .shell { display: block; }
  .page { padding: 0; max-width: none; }
  .doc-layout { display: block; }
  .sheet { border: 0; box-shadow: none; padding: 0; }
  .sheet.modern .sheet-head { margin: 0 0 0; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .panel { border: 0; }
  th { position: static; }
  .print-report h1 { margin-bottom: 8px; }
}

/* chart */
.chart .gl { stroke: var(--line-2); stroke-width: 1; }
.chart .ax { fill: var(--ink-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .b1 { fill: var(--s1); }
.chart .b2 { fill: var(--s2); }
.chart g[data-tip]:hover rect { fill: var(--line-2); }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin: 0 5px 0 12px; vertical-align: -1px; }
.sw.s1 { background: var(--s1); } .sw.s2 { background: var(--s2); }
.tip { position: absolute; top: 14px; transform: translateX(-50%); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 8px 10px; font-size: 12.5px; box-shadow: var(--shadow); pointer-events: none; font-variant-numeric: tabular-nums; white-space: nowrap; }
:root[data-theme="dark"] .stamp { mix-blend-mode: normal; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .stamp { mix-blend-mode: normal; } }

/* appearance + menu settings */
.choice { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.choice label { position: relative; border: 1px solid var(--line); border-radius: var(--r-lg); padding: 12px 14px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; background: var(--surface); }
.choice label:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice label:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
.choice .sample { font-size: 20px; color: var(--ink); line-height: 1.2; }
.swatch { height: 56px; border-radius: 6px; border: 1px solid var(--line); display: grid; grid-template-columns: 34% 1fr; overflow: hidden; margin-bottom: 4px; }
.swatch i:first-child { border-right: 1px solid rgba(0,0,0,.08); }
.menu-groups { columns: 3 220px; column-gap: 24px; }
.menu-groups section { break-inside: avoid; margin-bottom: 18px; }
.menu-groups h3 { margin-bottom: 6px; }
.menu-groups label.chk { padding: 3px 0; }
.danger-zone { border-color: var(--bad); }
.danger-zone .ph h2 { color: var(--bad); }
button.solid-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
