:root {
  --brand: #7A8B4F; --brand-ink: #3F4A24; --brand-soft: #EEF1E4; --brand-hover: #6A7A42;
  --bg: #F6F5F0; --surface: #FFFFFF; --surface-2: #FAFAF6; --ink: #1D1F1A; --muted: #6B6E63; --faint: #9A9C92;
  --line: #E3E1D8; --line-strong: #CFCCC0;
  --pos: #2F7D4F; --pos-soft: #E6F2EA; --neg: #B3412E; --neg-soft: #F8E7E3; --warn: #9A6514; --warn-soft: #FBF0DC; --info: #2C5F8A; --info-soft: #E5EEF6;
  --radius: 10px; --shadow: 0 1px 2px rgba(29,31,26,.06), 0 1px 1px rgba(29,31,26,.04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #9BAE68; --brand-ink: #CFDBA8; --brand-soft: #2A3020; --brand-hover: #AFC27A;
    --bg: #141512; --surface: #1C1E19; --surface-2: #22241F; --ink: #ECEDE6; --muted: #A3A69A; --faint: #75786D;
    --line: #30332B; --line-strong: #44483D;
    --pos: #6CC08E; --pos-soft: #1D3125; --neg: #E8806B; --neg-soft: #3A221D; --warn: #E0B05C; --warn-soft: #36291A; --info: #7FB0DA; --info-soft: #1C2A36;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.5 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--brand-ink); }
button, input, select, textarea { font: inherit; color: inherit; }
.num, .money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.neg { color: var(--neg); } .pos { color: var(--pos); } .muted { color: var(--muted); } .small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; text-decoration: none; color: var(--ink); }
.brand img { width: 34px; height: 34px; border-radius: 8px; }
.brand b { font: 600 15px/1.2 var(--serif); display: block; }
.brand span { font-size: 12px; color: var(--muted); }
.nav { padding: 4px 10px 16px; flex: 1; }
.nav h6 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); margin: 16px 10px 4px; font-weight: 600; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; font-size: 14.5px; }
.nav a svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--brand-soft); color: var(--brand-ink); font-weight: 600; }
.nav a.active svg { color: var(--brand); }
.nav .count { margin-left: auto; background: var(--brand); color: #fff; font-size: 11px; font-weight: 700; border-radius: 99px; padding: 1px 7px; }
.side-foot { border-top: 1px solid var(--line); padding: 12px 14px; font-size: 13px; }
.side-foot .who { display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-ink); display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.main { min-width: 0; }
.topbar { display: none; }
.page { max-width: 1180px; margin: 0 auto; padding: 28px 32px 80px; }
.page-head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { font: 600 26px/1.2 var(--serif); margin: 0; letter-spacing: -.01em; }
.page-head .sub { color: var(--muted); font-size: 14px; margin-top: 4px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.crumb { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.crumb a { color: var(--muted); }

/* ---------- components ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card h2 { font: 600 16px/1.3 var(--font); margin: 0 0 12px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.card-head h2 { margin: 0; }
.card-head .actions { margin-left: auto; display: flex; gap: 8px; }
.grid { display: grid; gap: 16px; }
.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)); }
.stack > * + * { margin-top: 16px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 500; text-decoration: none; white-space: nowrap; min-height: 38px; }
.btn:hover { background: var(--surface-2); }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-hover); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { color: #141512; } }
.btn.danger { color: var(--neg); border-color: color-mix(in srgb, var(--neg) 40%, var(--line)); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; cursor: pointer; padding: 6px; border-radius: 6px; color: var(--muted); display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; }

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.badge.draft { background: var(--surface-2); }
.badge.submitted, .badge.approved, .badge.unmatched { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.posted, .badge.paid, .badge.matched { background: var(--pos-soft); color: var(--pos); border-color: transparent; }
.badge.reversed, .badge.void, .badge.ignored { background: var(--neg-soft); color: var(--neg); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }

/* forms */
label.f { display: block; font-size: 13px; font-weight: 600; color: var(--muted); }
label.f > span { display: block; margin-bottom: 4px; }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; padding: 8px 10px; font-size: 15px; font-weight: 400; color: var(--ink); min-height: 38px; }
textarea.input { min-height: 72px; resize: vertical; }
input.input, select.input { height: 40px; }
table.edit input.input, table.edit select.input { height: 36px; }
.toolbar .check { min-height: 40px; }
.input:focus { outline: 2px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: 0; border-color: var(--brand); }
.input.money-in { text-align: right; font-variant-numeric: tabular-nums; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px 16px; }
.form-grid .span2 { grid-column: span 2; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.hint { font-size: 13px; color: var(--muted); margin-top: 4px; font-weight: 400; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 18px; }

/* tables */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
table.t td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t .num { text-align: right; }
table.t tbody tr.link { cursor: pointer; }
table.t tbody tr.link:hover td { background: var(--surface-2); }
table.t tr.sec td { font-weight: 700; background: var(--surface-2); text-transform: uppercase; font-size: 12px; letter-spacing: .06em; color: var(--muted); }
table.t tr.tot td { font-weight: 700; border-top: 1px solid var(--line-strong); }
table.t tr.grand td { font-weight: 700; border-top: 2px solid var(--ink); font-size: 15px; }
table.t td.ind { padding-left: 28px; }
table.edit td { padding: 6px 6px; }
table.edit .input { min-height: 36px; padding: 6px 8px; font-size: 14px; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty svg { width: 40px; height: 40px; color: var(--line-strong); margin-bottom: 8px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; text-decoration: none; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; font-size: 14px; }
.tabs a.active { color: var(--brand-ink); border-color: var(--brand); }
.toolbar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .input { width: auto; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 7px 12px; cursor: pointer; font-size: 13px; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--brand-soft); color: var(--brand-ink); font-weight: 600; }

/* KPI */
.kpi { padding: 16px 18px; }
.kpi .label { font-size: 13px; color: var(--muted); font-weight: 500; }
.kpi .value { font: 600 24px/1.3 var(--font); font-variant-numeric: tabular-nums; margin-top: 4px; letter-spacing: -.01em; }
.kpi .foot { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.todo { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.todo:last-child { border-bottom: 0; }
.todo:hover { background: var(--surface-2); }
.todo .dot { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: var(--warn-soft); color: var(--warn); font-weight: 700; font-size: 13px; flex: none; }
.todo .dot.ok { background: var(--pos-soft); color: var(--pos); }
.todo .go { margin-left: auto; color: var(--faint); }
.row-item { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.row-item:last-child { border-bottom: 0; }
.chart svg { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 12px; font-family: var(--font); }

/* takings counter */
.denoms { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.denom { display: grid; grid-template-columns: 58px 1fr; align-items: center; gap: 8px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.denom b { font-size: 14px; }
.denom input { text-align: center; }
.denom small { grid-column: 2; text-align: center; color: var(--muted); font-size: 12px; margin-top: -4px; }
.tally { display: flex; gap: 10px; flex-wrap: wrap; }
.tally div { flex: 1; min-width: 140px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; }
.tally span { display: block; font-size: 12px; color: var(--muted); }
.tally b { font-size: 18px; font-variant-numeric: tabular-nums; }
.tally .bad { border-color: var(--neg); background: var(--neg-soft); }
.tally .good { border-color: var(--pos); background: var(--pos-soft); }
.quick { display: flex; gap: 8px; flex-wrap: wrap; }
.notice { padding: 12px 16px; border-radius: 8px; font-size: 14px; background: var(--info-soft); color: var(--info); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.bad { background: var(--neg-soft); color: var(--neg); }
.notice.good { background: var(--pos-soft); color: var(--pos); }

/* modal + toast */
.modal-bg { position: fixed; inset: 0; background: rgba(20,21,18,.45); display: grid; place-items: center; z-index: 50; padding: 16px; animation: fade .12s; }
.modal { background: var(--surface); border-radius: 14px; width: min(560px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { width: min(880px, 100%); }
.modal-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-head .icon-btn { margin-left: auto; }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--surface); }
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.2); animation: fade .15s; max-width: 90vw; }
.toast.err { background: var(--neg); color: #fff; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }
.loading { padding: 60px; text-align: center; color: var(--muted); }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, var(--brand-soft), var(--bg) 60%); }
.login { width: min(400px, 100%); padding: 32px; }
.login .logo { width: 64px; height: 64px; border-radius: 14px; display: block; margin: 0 auto 14px; }
.login h1 { font: 600 22px var(--serif); text-align: center; margin: 0 0 4px; }
.login p { text-align: center; color: var(--muted); margin: 0 0 22px; font-size: 14px; }

/* report */
.report-head { text-align: center; padding: 22px 20px 6px; }
.report-head h2 { font: 600 20px var(--serif); margin: 0; }
.report-head .church { font-size: 13px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.report-head .period { color: var(--muted); font-size: 14px; margin-top: 2px; }

/* mobile */
.bottom-nav { display: none; }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.2); }
  .app.menu-open .sidebar { transform: none; }
  .app.menu-open::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 30; }
  .topbar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
  .topbar b { font: 600 16px var(--serif); }
  .page { padding: 18px 16px 100px; }
  .page-head h1 { font-size: 22px; }
  .page-head .actions { margin-left: 0; width: 100%; }
  .g2, .g3 { grid-template-columns: 1fr; } .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid .span2 { grid-column: auto; }
  .bottom-nav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--line); z-index: 20; padding-bottom: env(safe-area-inset-bottom); }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 7px; text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 500; }
  .bottom-nav a svg { width: 22px; height: 22px; }
  .bottom-nav a.active { color: var(--brand-ink); }
  .kpi .value { font-size: 20px; }
  table.t.stack-mobile thead { display: none; }
  table.t.stack-mobile tr { display: grid; grid-template-columns: 1fr auto; padding: 10px 12px; border-bottom: 1px solid var(--line); gap: 2px 12px; }
  table.t.stack-mobile td { border: 0; padding: 0; }
  table.t.stack-mobile td.m-hide { display: none; }
  table.t.stack-mobile td:first-child { font-weight: 600; }
  .modal-bg { place-items: end center; padding: 0; }
  .modal { border-radius: 16px 16px 0 0; max-height: 92vh; }
}

@media print {
  .sidebar, .topbar, .bottom-nav, .page-head .actions, .toolbar, .no-print, .tabs { display: none !important; }
  .app { display: block; } body { background: #fff; color: #000; font-size: 12px; }
  .page { padding: 0; max-width: none; }
  .card { border: 0; box-shadow: none; }
  table.t th { background: none; }
  table.t td, table.t th { padding: 4px 6px; }
}
