/* Finbook — ledger-book design system */
:root {
  --spine: #0E3B32;
  --spine-2: #145045;
  --spine-ink: #C9DED5;
  --paper: #F3F6F4;
  --surface: #FFFFFF;
  --ink: #15201C;
  --ink-2: #33433D;
  --muted: #5F6F69;
  --rule: #DCE5E0;
  --rule-strong: #B9C8C1;
  --ruled: #EEF3F0;
  --accent: #E9A417;
  --accent-hover: #D99410;
  --accent-ink: #2B1D00;
  --green: #17704F;
  --green-bg: #E3F2EA;
  --red: #B3362B;
  --red-bg: #FBE9E6;
  --blue: #285E86;
  --blue-bg: #E5EFF7;
  --amber-bg: #FDF2D8;
  --focus: #2F7D6B;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --font: 'Hanken Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --shadow-pop: 0 18px 50px rgba(14, 59, 50, .22);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'tnum' 1, 'lnum' 1;
}
a { color: var(--green); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: 26px; font-weight: 800; }
h2 { font-size: 18px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 700; }
p { margin: 0 0 .75em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.stack { display: grid; gap: 16px; }
.spacer { height: 16px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.spine {
  background: var(--spine);
  color: var(--spine-ink);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  padding: 18px 12px;
  border-right: 6px solid var(--spine-2);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; color: #fff; }
.brand img { width: 34px; height: 34px; }
.brand b { font-size: 19px; font-weight: 800; letter-spacing: -0.02em; }
.brand small { display: block; color: var(--spine-ink); font-size: 12px; line-height: 1.2; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav { display: grid; gap: 2px; overflow-y: auto; }
.nav .sep { font-size: 12px; color: #8FB3A6; padding: 14px 10px 4px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--r-sm);
  color: var(--spine-ink); font-weight: 500; text-decoration: none;
}
.nav a svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav a.on { background: var(--surface); color: var(--spine); font-weight: 700; }
.nav a.on svg { opacity: 1; }
.nav .collect { background: var(--accent); color: var(--accent-ink); font-weight: 700; margin: 4px 0 6px; }
.nav .collect:hover { background: var(--accent-hover); color: var(--accent-ink); }
.spine-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid rgba(255,255,255,.12); font-size: 13px; }
.spine-foot b { color: #fff; display: block; }
.spine-foot button { background: none; border: 0; color: var(--spine-ink); padding: 4px 0; cursor: pointer; text-decoration: underline; }

.main { min-width: 0; }
.topbar { display: none; }
.page { max-width: 1240px; margin: 0 auto; padding: 28px 32px 80px; }
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .t { flex: 1; min-width: 220px; }
.page-head .t p { margin: 4px 0 0; color: var(--muted); }
.banner { padding: 10px 14px; border-radius: var(--r-sm); margin-bottom: 16px; font-size: 14px; }
.banner.warn { background: var(--amber-bg); color: #6B4A00; }
.banner.err { background: var(--red-bg); color: var(--red); }

.tabbar { display: none; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .spine { display: none; }
  .spine.open { display: flex; position: fixed; inset: 0 25% 0 0; z-index: 50; height: 100%; box-shadow: var(--shadow-pop); }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
  .topbar {
    display: flex; align-items: center; gap: 10px;
    background: var(--spine); color: #fff; padding: 10px 14px;
    position: sticky; top: 0; z-index: 30;
  }
  .topbar button { background: none; border: 0; color: #fff; padding: 4px; display: grid; }
  .topbar b { font-weight: 800; }
  .topbar small { color: var(--spine-ink); margin-left: auto; font-size: 12px; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .page { padding: 18px 14px 110px; }
  h1 { font-size: 22px; }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); align-items: end;
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--rule);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar a { display: grid; justify-items: center; gap: 2px; font-size: 11px; color: var(--muted); text-decoration: none; padding: 4px 0; }
  .tabbar a svg { width: 22px; height: 22px; }
  .tabbar a.on { color: var(--spine); font-weight: 700; }
  .tabbar a.big span.disc {
    width: 54px; height: 54px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
    display: grid; place-items: center; margin-top: -26px; box-shadow: 0 6px 16px rgba(233,164,23,.45);
  }
  .tabbar a.big { color: var(--ink); font-weight: 700; }
}

/* ---------- surfaces ---------- */
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); }
.panel-pad { padding: 18px 20px; }
.panel-head { display: flex; align-items: center; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--rule); flex-wrap: wrap; }
.panel-head h2 { flex: 1; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-2 > *, .grid-3 > *, .stack > *, .main, .page { min-width: 0; }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* figures strip on dashboard: a ledger "summary line" rather than a card kit */
.figures { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); }
.figures > div { padding: 16px 20px; border-left: 1px solid var(--rule); }
.figures > div:first-child { border-left: 0; }
.figures .lbl { color: var(--muted); font-size: 13px; }
.figures .val { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; margin-top: 2px; }
.figures .sub { font-size: 12px; color: var(--muted); }
@media (max-width: 900px) {
  .figures { grid-template-columns: 1fr 1fr; }
  .figures > div:nth-child(3) { border-left: 0; }
  .figures > div:nth-child(n+3) { border-top: 1px solid var(--rule); }
  .figures .val { font-size: 20px; }
}

.cashbox {
  background: var(--spine); color: #fff; border-radius: var(--r-lg);
  padding: 22px 24px; display: grid; gap: 4px; position: relative; overflow: hidden;
}
.cashbox .lbl { color: var(--spine-ink); }
.cashbox .val { font-size: 38px; font-weight: 800; letter-spacing: -0.03em; }
.cashbox .split { display: flex; gap: 24px; margin-top: 10px; color: var(--spine-ink); font-size: 14px; flex-wrap: wrap; }
.cashbox .split b { color: #fff; font-weight: 700; }
.cashbox::after { content: ''; position: absolute; right: 22px; top: 0; width: 14px; height: 46px; background: var(--accent); border-radius: 0 0 3px 3px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 14px; border-radius: var(--r-sm);
  border: 1px solid var(--rule-strong); background: var(--surface); color: var(--ink);
  font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--ruled); text-decoration: none; }
.btn svg { width: 17px; height: 17px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.dark { background: var(--spine); border-color: var(--spine); color: #fff; }
.btn.dark:hover { background: var(--spine-2); }
.btn.danger { color: var(--red); border-color: #E6BDB7; }
.btn.danger:hover { background: var(--red-bg); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--ruled); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.lg { height: 48px; padding: 0 22px; font-size: 16px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.iconbtn { border: 0; background: none; padding: 6px; border-radius: var(--r-sm); cursor: pointer; color: var(--muted); display: inline-grid; }
.iconbtn:hover { background: var(--ruled); color: var(--ink); }
.iconbtn svg { width: 18px; height: 18px; }

/* ---------- forms ---------- */
.form { display: grid; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.field { display: grid; gap: 5px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field > small { color: var(--muted); font-size: 12px; }
.input, .select, .textarea {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid var(--rule-strong); border-radius: var(--r-sm); background: var(--surface);
}
.textarea { height: auto; min-height: 72px; padding: 10px 12px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px rgba(47,125,107,.18); }
.input.amount { text-align: right; font-weight: 700; font-size: 16px; }
.input.huge { height: 64px; font-size: 30px; font-weight: 800; text-align: right; letter-spacing: -0.02em; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: 18px; height: 18px; accent-color: var(--spine); }
.seg { display: inline-flex; border: 1px solid var(--rule-strong); border-radius: var(--r-sm); overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 7px 14px; cursor: pointer; font-weight: 600; color: var(--muted); border-left: 1px solid var(--rule); }
.seg button:first-child { border-left: 0; }
.seg button.on { background: var(--spine); color: #fff; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters .field { min-width: 150px; }
.filters .search { flex: 1; min-width: 200px; }

/* ---------- tables: ruled ledger paper ---------- */
.table-wrap { overflow-x: auto; }
table.ledger { width: 100%; border-collapse: collapse; font-size: 14px; }
.ledger th {
  text-align: left; font-weight: 700; font-size: 12.5px; color: var(--muted);
  padding: 10px 12px; border-bottom: 2px solid var(--rule-strong); background: var(--surface); position: sticky; top: 0;
}
.ledger td { padding: 9px 12px; border-bottom: 1px solid var(--ruled); vertical-align: top; }
.ledger tbody tr:hover td { background: #F8FBF9; }
.ledger tr.click { cursor: pointer; }
.ledger th.num, .ledger td.num { text-align: right; }
.ledger tfoot td { font-weight: 800; border-top: 2px solid var(--rule-strong); border-bottom: 3px double var(--rule-strong); background: var(--surface); }
.ledger tr.open td { background: var(--ruled); font-weight: 600; }
.ledger td.amt-col, .ledger th.amt-col { border-left: 1px solid var(--ruled); }
.ledger .d1 td:first-child { padding-left: 28px; }
.ledger .d2 td:first-child { padding-left: 44px; }
.ledger .d3 td:first-child { padding-left: 60px; }
.ledger tr.grp td { font-weight: 700; }
.ledger tr.lvl0 td { font-weight: 800; background: #F7FAF8; }
.ledger .sub { color: var(--muted); font-size: 12.5px; }
.empty { padding: 44px 20px; text-align: center; color: var(--muted); }
.empty h3 { color: var(--ink); margin-bottom: 6px; }

.drcr { font-size: 11px; font-weight: 700; margin-left: 4px; padding: 1px 4px; border-radius: 3px; vertical-align: 1px; }
.drcr.dr { color: var(--blue); background: var(--blue-bg); }
.drcr.cr { color: var(--green); background: var(--green-bg); }

.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--ruled); color: var(--ink-2); white-space: nowrap; }
.pill.green { background: var(--green-bg); color: var(--green); }
.pill.red { background: var(--red-bg); color: var(--red); }
.pill.amber { background: var(--amber-bg); color: #7A5400; }
.pill.blue { background: var(--blue-bg); color: var(--blue); }

.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; padding: 12px 16px; color: var(--muted); font-size: 13px; }

/* ---------- key-value / passbook ---------- */
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0; border-top: 1px solid var(--rule); }
.kv > div { padding: 12px 20px; border-bottom: 1px solid var(--ruled); }
.kv dt { font-size: 12.5px; color: var(--muted); }
.kv dd { margin: 2px 0 0; font-weight: 700; }
.acct-hero { display: flex; gap: 20px; align-items: flex-start; padding: 20px; flex-wrap: wrap; }
.acct-hero .bal { margin-left: auto; text-align: right; }
.acct-hero .bal .val { font-size: 32px; font-weight: 800; letter-spacing: -0.02em; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--rule); padding: 0 12px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 12px 12px; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--spine); border-bottom-color: var(--accent); }

/* ---------- modal / toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(14,32,27,.45); display: grid; place-items: center; z-index: 60; padding: 16px; }
.modal { background: var(--surface); border-radius: var(--r-lg); width: min(640px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: var(--shadow-pop); }
.modal.wide { width: min(920px, 100%); }
.modal-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--rule); }
.modal-head h2 { flex: 1; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--rule); flex-wrap: wrap; }
@media (max-width: 640px) {
  .modal-bg { padding: 0; place-items: end stretch; }
  .modal, .modal.wide { width: 100%; border-radius: var(--r-lg) var(--r-lg) 0 0; max-height: 92vh; }
}
.toasts { position: fixed; bottom: 20px; right: 20px; display: grid; gap: 8px; z-index: 80; }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: var(--r-sm); box-shadow: var(--shadow-pop); max-width: 380px; font-weight: 500; animation: pop .18s ease-out; }
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }
@media (max-width: 900px) { .toasts { left: 14px; right: 14px; bottom: 90px; } }

/* ---------- picker ---------- */
.picker { position: relative; }
.picker-list { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--rule-strong); border-radius: var(--r-sm); box-shadow: var(--shadow-pop); max-height: 300px; overflow-y: auto; }
.picker-list button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--ruled); }
.picker-list button:hover, .picker-list button.hi { background: var(--ruled); }
.picker-list .s { color: var(--muted); font-size: 12.5px; }
.chosen { display: flex; align-items: center; gap: 10px; border: 1px solid var(--rule-strong); border-radius: var(--r-sm); padding: 6px 8px 6px 12px; min-height: 40px; background: var(--surface); }
.chosen .grow { min-width: 0; }
.chosen b { display: block; }

/* ---------- voucher entry ---------- */
.vt-row { display: grid; grid-template-columns: 1fr 140px 140px 36px; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--rule); }
.vt-head { font-size: 12.5px; color: var(--muted); font-weight: 700; border-bottom: 2px solid var(--rule-strong); }
@media (max-width: 640px) { .vt-row { grid-template-columns: 1fr 1fr; } .vt-row > :first-child { grid-column: 1 / -1; } .vt-head { display: none; } }
.totals-line { display: flex; gap: 20px; justify-content: flex-end; padding: 12px 0; font-weight: 700; flex-wrap: wrap; }
.balanced { color: var(--green); }
.unbalanced { color: var(--red); }
.hint-card { background: var(--ruled); border-radius: var(--r-sm); padding: 12px 14px; font-size: 14px; display: grid; gap: 4px; }
.hint-card .row { justify-content: space-between; }

/* agent collect list */
.collect-item { display: flex; gap: 12px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--ruled); cursor: pointer; background: var(--surface); }
.collect-item:hover { background: #F8FBF9; }
.collect-item .av { width: 40px; height: 40px; border-radius: 50%; background: var(--green-bg); color: var(--green); display: grid; place-items: center; font-weight: 800; flex: none; }
.collect-item .grow { min-width: 0; }
.collect-item b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.done-mark { color: var(--green); font-weight: 700; font-size: 13px; }

/* bars */
.bars { display: grid; grid-template-columns: repeat(14, 1fr); gap: 6px; align-items: end; height: 150px; padding: 8px 4px 0; }
.bars .b { display: grid; gap: 2px; align-items: end; height: 100%; grid-template-rows: 1fr auto; }
.bars .pair { display: flex; gap: 2px; align-items: flex-end; height: 100%; }
.bars .pair i { flex: 1; border-radius: 2px 2px 0 0; min-height: 1px; }
.bars .pair i.r { background: var(--spine); }
.bars .pair i.p { background: var(--accent); }
.bars .d { font-size: 10.5px; color: var(--muted); text-align: center; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-side { min-height: 100vh; background: var(--spine); color: var(--spine-ink); padding: 48px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-side h1 { color: #fff; font-size: 40px; max-width: 460px; letter-spacing: -0.03em; }
.auth-side p { max-width: 420px; font-size: 16px; }
.auth-side .ruled-art { position: absolute; right: 48px; top: 90px; width: 320px; background: var(--paper); border-radius: 10px; transform: rotate(-6deg); padding: 18px 22px; color: var(--ink); box-shadow: var(--shadow-pop); font-size: 14px; }
.auth-side .ruled-art div { display: flex; justify-content: space-between; border-bottom: 1px solid var(--rule); padding: 7px 0; }
.auth-side .ruled-art div:last-child { border-bottom: 3px double var(--rule-strong); font-weight: 800; }
.auth-main { display: grid; place-items: center; padding: 32px 20px; }
.auth-card { width: min(400px, 100%); }
.auth-card h2 { font-size: 24px; margin-bottom: 4px; }
.auth-card .form { margin-top: 22px; }
@media (max-width: 900px) { .auth { grid-template-columns: 1fr; } .auth-side { display: none; } }

/* ---------- receipt / print ---------- */
.receipt { background: #fff; max-width: 420px; margin: 0 auto; border: 1px solid var(--rule); border-radius: var(--r-md); padding: 22px; }
.receipt .rh { text-align: center; border-bottom: 2px solid var(--ink); padding-bottom: 12px; margin-bottom: 12px; }
.receipt .rh b { font-size: 18px; display: block; }
.receipt .rt { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.receipt table { width: 100%; border-collapse: collapse; font-size: 14px; }
.receipt td { padding: 6px 0; border-bottom: 1px dotted var(--rule-strong); }
.receipt .big { font-size: 26px; font-weight: 800; text-align: center; padding: 12px 0; border-top: 2px solid var(--ink); border-bottom: 2px solid var(--ink); margin: 12px 0; }
.receipt .foot { font-size: 12px; color: var(--muted); text-align: center; }
.print-only { display: none; }
@media print {
  @page { margin: 12mm; }
  body { background: #fff; font-size: 12px; }
  .spine, .topbar, .tabbar, .no-print, .toasts, .filters, .btn, .pager { display: none !important; }
  .shell { display: block; }
  .page { padding: 0; max-width: none; }
  .panel { border: 0; }
  .print-only { display: block; }
  .ledger th { position: static; }
  .modal-bg { position: static; background: none; padding: 0; }
  .modal { box-shadow: none; max-height: none; }
  .modal-head, .modal-foot { display: none; }
}
.hide-sm {}
@media (max-width: 640px) { .hide-sm { display: none; } }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.spin { width: 22px; height: 22px; border: 3px solid var(--rule); border-top-color: var(--spine); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.report-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0; }
.report-list a { padding: 16px 20px; border-bottom: 1px solid var(--ruled); border-right: 1px solid var(--ruled); color: var(--ink); text-decoration: none; display: grid; gap: 2px; }
.report-list a:hover { background: #F8FBF9; }
.report-list a b { font-size: 15px; }
.report-list a span { color: var(--muted); font-size: 13px; }
