:root {
  --bg: #f6f5f1;
  --panel: #ffffff;
  --ink: #1d2422;
  --muted: #5d6865;
  --line: #e3e1da;
  --brand: #1f6f68;
  --brand-ink: #ffffff;
  --brand-soft: #e3f0ee;
  --warn: #9a5b00;
  --warn-soft: #fdf1dc;
  --bad: #a3292b;
  --bad-soft: #fbe6e6;
  --good: #1d6b3a;
  --good-soft: #e2f3e8;
  --info-soft: #e8eef8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; }
h1 { font-family: Fraunces, Georgia, serif; font-size: 1.7rem; font-weight: 600; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
.boot { padding: 4rem; text-align: center; color: var(--muted); }

/* layout */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { background: #16302d; color: #dfe9e7; padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 18px; color: #fff; text-decoration: none; }
.brand b { font-family: Fraunces, Georgia, serif; font-size: 1.05rem; font-weight: 600; display: block; line-height: 1.2; }
.brand small { color: #9fbab6; font-size: .75rem; }
.nav-group { margin: 14px 0 4px; padding: 0 10px; font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: #8aa9a4; }
.side a.nav { display: block; color: #dfe9e7; text-decoration: none; padding: 8px 10px; border-radius: 8px; margin: 1px 0; }
.side a.nav:hover { background: rgba(255,255,255,.07); }
.side a.nav.on { background: #2a5c56; color: #fff; font-weight: 600; }
.side .me { margin-top: 24px; padding: 10px; border-top: 1px solid rgba(255,255,255,.1); font-size: .85rem; color: #b9cdca; }
.side .me button { margin-top: 6px; }
.main { padding: 28px 32px 60px; max-width: 1280px; width: 100%; min-width: 0; }
.topbar { display: none; }

.pagehead { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; margin-bottom: 18px; }
.pagehead p { margin: 0; color: var(--muted); max-width: 70ch; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* panels */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.panel > h2:first-child { margin-top: 0; }
.grid { display: grid; gap: 14px; }
.grid.k4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid.k2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .l { color: var(--muted); font-size: .8rem; }
.kpi .v { font-size: 1.45rem; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi .s { color: var(--muted); font-size: .78rem; }

.banner { border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; border: 1px solid; }
.banner.info { background: var(--info-soft); border-color: #c9d6ec; }
.banner.warn { background: var(--warn-soft); border-color: #f0d6a6; }
.banner.good { background: var(--good-soft); border-color: #b9dfc6; }
.banner.bad { background: var(--bad-soft); border-color: #efc0c0; }

.todo { list-style: none; padding: 0; margin: 0; }
.todo li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.todo li:last-child { border-bottom: 0; }
.todo .n { font-weight: 700; background: var(--warn-soft); color: var(--warn); border-radius: 99px; padding: 0 10px; min-width: 32px; text-align: center; }
.todo .n.zero { background: var(--good-soft); color: var(--good); }

/* buttons & forms */
.btn { font: inherit; font-weight: 500; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 8px 14px; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { border-color: #c9c6bb; background: #fbfaf7; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: #185b55; }
.btn.danger { color: var(--bad); border-color: #e7b9b9; }
.btn.sm { padding: 4px 10px; font-size: .85rem; }
.btn.ghost { background: transparent; border-color: transparent; color: inherit; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.side .btn { background: transparent; color: #dfe9e7; border-color: rgba(255,255,255,.2); }

label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: .85rem; font-weight: 500; margin-bottom: 4px; }
label.f small, .hint { display: block; color: var(--muted); font-size: .78rem; margin-top: 3px; }
input, select, textarea { font: inherit; width: 100%; padding: 8px 10px; border: 1px solid #cfccc2; border-radius: 8px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: var(--brand); }
input[type=checkbox] { width: auto; margin-right: 6px; transform: scale(1.15); }
label.chk { display: flex; align-items: flex-start; gap: 4px; margin-bottom: 12px; cursor: pointer; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 14px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; margin-bottom: 12px; }
.filters label { font-size: .78rem; color: var(--muted); }
.filters input, .filters select { width: auto; min-width: 140px; padding: 6px 8px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 14px; padding: 10px 14px 2px; }
legend { font-weight: 600; font-size: .85rem; padding: 0 4px; }

/* tables */
.tw { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #faf9f6; position: sticky; top: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #faf9f5; }
tr.head td { font-weight: 700; background: #f4f3ee; }
tr.sub td { font-weight: 600; border-top: 1px solid #bdbab0; }
tr.total td { font-weight: 700; border-top: 2px solid var(--ink); border-bottom: 3px double var(--ink); }
tr.spacer td { border: 0; padding: 6px; }
td.ind { padding-left: 26px; }
.empty { padding: 26px; text-align: center; color: var(--muted); }

.pill { display: inline-block; font-size: .75rem; font-weight: 600; padding: 1px 9px; border-radius: 99px; background: #eceae4; color: #4b524f; white-space: nowrap; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.brand { background: var(--brand-soft); color: var(--brand); }

.bar { height: 8px; background: #ebe9e2; border-radius: 99px; overflow: hidden; margin: 6px 0; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); cursor: pointer; text-decoration: none; color: inherit; display: block; }
.card:hover { border-color: #b9c9c6; }
.card .meta { color: var(--muted); font-size: .82rem; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { font: inherit; background: none; border: 0; padding: 9px 14px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--ink); font-weight: 600; border-bottom-color: var(--brand); }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }

/* modal */
.overlay { position: fixed; inset: 0; background: rgba(20,30,28,.45); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; z-index: 50; overflow-y: auto; }
.dialog { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.dialog.wide { max-width: 920px; }
.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: 18px 20px; }
.dialog footer { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.err { color: var(--bad); background: var(--bad-soft); border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; display: none; }
.err.show { display: block; }

#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #16302d; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 420px; }
.toast.bad { background: var(--bad); }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #16302d, #1f6f68); }
.auth .box { background: #fff; border-radius: 14px; padding: 28px; width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.auth .box h1 { margin-bottom: 4px; }
.auth .box p.sub { color: var(--muted); margin-top: 0; }
.linkbtn { background: none; border: 0; color: var(--brand); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }

/* receipt / report print */
.doc { background: #fff; border: 1px solid var(--line); padding: 36px 40px; max-width: 800px; margin: 0 auto; }
.doc .orghead { display: flex; justify-content: space-between; border-bottom: 2px solid var(--ink); padding-bottom: 12px; margin-bottom: 18px; gap: 16px; }
.doc .amt { font-size: 1.6rem; font-weight: 700; }
.reporthead { text-align: center; margin-bottom: 12px; }
.reporthead h2 { font-family: Fraunces, Georgia, serif; font-size: 1.25rem; margin-bottom: 2px; }
.reporthead p { margin: 0; color: var(--muted); }
.stamp { border: 2px solid var(--bad); color: var(--bad); display: inline-block; padding: 4px 12px; font-weight: 700; transform: rotate(-4deg); }

.help h2 { margin-top: 1.4em; }
.help ol, .help ul { padding-left: 1.3em; }
.help li { margin-bottom: 4px; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85em; }
.muted { color: var(--muted); }
.right { text-align: right; }
.mt { margin-top: 14px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 40; left: 0; top: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: #16302d; color: #fff; position: sticky; top: 0; z-index: 30; }
  .topbar b { font-family: Fraunces, Georgia, serif; }
  .topbar .btn { color: #fff; border-color: rgba(255,255,255,.3); background: transparent; }
  .main { padding: 18px 16px 60px; }
  .row2, .row3 { grid-template-columns: 1fr; }
  .doc { padding: 20px; }
}

@media print {
  body { background: #fff; }
  .side, .topbar, .noprint, .pagehead .actions, .filters, .tabs, #toasts { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; max-width: none; }
  .panel, .doc { border: 0; box-shadow: none; padding: 0; }
  th { position: static; }
}
