:root {
  --bg: #f4f2ec;
  --panel: #ffffff;
  --ink: #1c2622;
  --muted: #66716b;
  --line: #dcd8cc;
  --line-soft: #ebe8de;
  --brand: #1d5a49;
  --brand-ink: #ffffff;
  --brand-soft: #e3efe9;
  --accent: #b5731a;
  --accent-soft: #fbf0dc;
  --danger: #a73a2b;
  --danger-soft: #f8e4e0;
  --ok: #2c7a4b;
  --ok-soft: #e1f2e7;
  --side: #17352d;
  --side-ink: #dfe9e4;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(20, 30, 26, .06), 0 2px 8px rgba(20, 30, 26, .04);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111715; --panel: #1a2220; --ink: #e6ece9; --muted: #98a59f; --line: #2c3834; --line-soft: #232d2a;
    --brand: #4fae92; --brand-ink: #08241c; --brand-soft: #1b3029; --accent: #e0a24a; --accent-soft: #33291a;
    --danger: #e27d6e; --danger-soft: #3a2220; --ok: #66c28a; --ok-soft: #1c3226; --side: #0c1412; --side-ink: #c9d6d0;
  }
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; line-height: 1.45; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.55rem; margin: 0 0 .2rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 1.2rem 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { padding: 4px 10px 16px; border-bottom: 1px solid rgba(255,255,255,.1); margin-bottom: 10px; }
.brand b { display: block; font-size: 1.02rem; line-height: 1.25; color: #fff; }
.brand span { font-size: .75rem; opacity: .65; }
.side nav a, .side .navlabel { display: block; padding: 8px 10px; border-radius: 6px; color: var(--side-ink); font-size: .93rem; }
.side nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.side nav a.on { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; }
.navlabel { text-transform: uppercase; font-size: .68rem !important; letter-spacing: .09em; opacity: .5; margin-top: 12px; padding-bottom: 2px !important; }
.userbox { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid rgba(255,255,255,.1); font-size: .85rem; }
.userbox button { margin-top: 8px; }
main { padding: 26px 32px 80px; max-width: 1280px; width: 100%; }
.pagehead { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.pagehead p { margin: 0; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* surfaces */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px; }
.card.flush { padding: 0; overflow: hidden; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, 1fr); } .g3 { grid-template-columns: repeat(3, 1fr); } .g4 { grid-template-columns: repeat(4, 1fr); }
.stat { padding: 16px 18px; }
.stat .n { font-size: 1.9rem; font-weight: 650; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .05em; }
.stat a { font-size: .82rem; }

/* flash */
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 10px; border: 1px solid; font-size: .94rem; }
.flash.ok { background: var(--ok-soft); border-color: #a9d5b8; color: var(--ok); }
.flash.warn { background: var(--accent-soft); border-color: #e6c78d; color: #7d5010; }
.flash.error { background: var(--danger-soft); border-color: #e3aaa1; color: var(--danger); }
@media (prefers-color-scheme: dark) { .flash.warn { color: var(--accent); } }

/* buttons & inputs */
button, .btn { font: inherit; cursor: pointer; border-radius: 6px; padding: 7px 14px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); display: inline-block; text-decoration: none; }
button:hover, .btn:hover { border-color: var(--brand); text-decoration: none; }
button.primary, .btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
button.primary:hover { filter: brightness(1.1); }
button.danger, .btn.danger { color: var(--danger); border-color: #dca9a1; }
button.link { border: 0; background: none; padding: 0; color: inherit; opacity: .8; text-decoration: underline; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.sm, .btn.sm { padding: 3px 9px; font-size: .85rem; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--brand); }
textarea { min-height: 140px; resize: vertical; }
label { font-size: .8rem; color: var(--muted); display: block; margin-bottom: 3px; font-weight: 500; }
.field.bool { display: flex; align-items: center; gap: 8px; padding-top: 22px; }
.field.bool label { margin: 0; color: var(--ink); font-size: .93rem; }
.field .help { font-size: .75rem; color: var(--muted); margin-top: 2px; }
.fgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 14px; }
.fgrid .s2 { grid-column: span 2; } .fgrid .s4 { grid-column: span 4; }
input.money, input.num { text-align: right; font-variant-numeric: tabular-nums; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.inline-form > div { flex: 1 1 140px; }
.searchbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.searchbar input[type=search], .searchbar input[type=text] { flex: 2 1 260px; }
.searchbar select, .searchbar input[type=date], .searchbar input[type=number] { flex: 0 1 160px; }

/* tables */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
th { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); background: color-mix(in srgb, var(--bg) 60%, var(--panel)); position: sticky; top: 0; font-weight: 600; white-space: nowrap; }
tbody tr:hover { background: color-mix(in srgb, var(--brand-soft) 45%, transparent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.total td { font-weight: 700; border-top: 2px solid var(--ink); background: var(--bg); }
.tablewrap { overflow-x: auto; }
.pill { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--line-soft); }
.pill.A, .pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.I, .pill.bad { background: var(--danger-soft); color: var(--danger); }
.pill.P, .pill.warn { background: var(--accent-soft); color: #8a5712; }
.empty { padding: 36px; text-align: center; color: var(--muted); }
.pager { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 12px 4px; }

/* tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: none; padding: 10px 16px; color: var(--muted); white-space: nowrap; }
.tabs button[aria-selected=true] { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.tabpanel[hidden] { display: none; }
.actionbar { position: fixed; left: 232px; right: 0; bottom: 0; background: var(--panel); border-top: 1px solid var(--line); padding: 10px 32px; display: flex; gap: 10px; align-items: center; z-index: 5; box-shadow: 0 -4px 14px rgba(0,0,0,.05); }
.actionbar .grow { flex: 1; }

/* combo */
.combo { position: relative; }
.combo ul { position: absolute; z-index: 20; left: 0; right: 0; top: 100%; margin: 2px 0 0; padding: 4px; list-style: none; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); max-height: 240px; overflow: auto; }
.combo li { padding: 6px 8px; border-radius: 4px; cursor: pointer; }
.combo li:hover, .combo li.sel { background: var(--brand-soft); }
.combo li.new { color: var(--accent); }

/* fee panel */
.feegrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.totalbox { display: flex; justify-content: space-between; align-items: baseline; padding: 14px 16px; background: var(--brand-soft); border-radius: var(--radius); margin-top: 14px; }
.totalbox b { font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.balance.bad { color: var(--danger); } .balance.good { color: var(--ok); }
.notes { margin: 10px 0 0; padding: 0; list-style: none; }
.notes li { background: var(--accent-soft); border-left: 3px solid var(--accent); padding: 6px 10px; margin-bottom: 4px; font-size: .88rem; border-radius: 3px; }

/* bars */
.bars { display: flex; align-items: flex-end; gap: 8px; height: 150px; padding-top: 8px; }
.bars .b { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; font-size: .7rem; color: var(--muted); }
.bars .b i { display: block; width: 100%; background: var(--brand); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.bars .b:hover i { opacity: 1; }

/* login */
.authwrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.authcard { width: 100%; max-width: 400px; }
.authcard h1 { text-align: center; }
.authcard .sub { text-align: center; color: var(--muted); margin-bottom: 18px; }
.authcard .field { margin-bottom: 12px; }

/* reports index */
.replist { list-style: none; margin: 0; padding: 0; }
.replist li { padding: 9px 0; border-bottom: 1px solid var(--line-soft); }
.replist li:last-child { border: 0; }
.replist .d { color: var(--muted); font-size: .85rem; display: block; }

/* lookup (law enforcement) */
.lea { border-left: 6px solid var(--ok); }
.lea.bad { border-left-color: var(--danger); } .lea.warn { border-left-color: var(--accent); }
.lea h2 { font-size: 1.5rem; margin: 0; }
.kv { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px 20px; margin-top: 12px; }
.kv dt { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }

@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .actionbar { left: 0; padding: 10px 14px; }
  main { padding: 18px 14px 90px; }
  .fgrid, .feegrid, .kv, .g4, .g3 { grid-template-columns: repeat(2, 1fr); }
  .g2 { grid-template-columns: 1fr; }
}
@media (max-width: 560px) { .fgrid, .feegrid, .kv, .g4 { grid-template-columns: 1fr; } .fgrid .s2, .fgrid .s4 { grid-column: auto; } }

/* print */
.noprint { }
.paper { background: #fff; color: #000; }
@media print {
  body { background: #fff; color: #000; }
  .side, .actionbar, .noprint, .flash { display: none !important; }
  .shell { display: block; } main { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 0; padding: 0; }
  .pagebreak { page-break-after: always; }
  th { position: static; }
}
