:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --rule: #e3e6ea;
  --accent: #1e3a5f;
  --accent-ink: #ffffff;
  --accent-soft: #e8eef5;
  --ok: #067647;
  --ok-soft: #e7f6ec;
  --warn: #b54708;
  --warn-soft: #fef4e6;
  --bad: #b42318;
  --bad-soft: #fdecea;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1a1f25;
    --ink: #e6e8eb;
    --muted: #9aa3ad;
    --rule: #2b323a;
    --accent: #7aa5d8;
    --accent-ink: #0d1520;
    --accent-soft: #1f2c3b;
    --ok: #5cc98a;
    --ok-soft: #16301f;
    --warn: #f0a85a;
    --warn-soft: #33240f;
    --bad: #f0857a;
    --bad-soft: #3a1a17;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 28px 0 10px; }
h3 { font-size: 14px; margin: 18px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }

/* top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--rule); }
.topbar .wrap { display: flex; align-items: center; gap: 24px; min-height: 54px; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--ink); font-size: 15px; }
.brand:hover { text-decoration: none; }
nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
nav a { color: var(--muted); padding: 6px 10px; border-radius: 6px; font-weight: 500; white-space: nowrap; }
nav a:hover { background: var(--bg); color: var(--ink); text-decoration: none; }
nav a.active { color: var(--accent); background: var(--accent-soft); }
.user { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.user form { margin: 0; }
@media (max-width: 760px) {
  .topbar .wrap { gap: 4px 16px; padding-top: 10px; }
  .user { margin-left: auto; }
  nav { order: 3; flex: 0 0 100%; flex-wrap: nowrap; overflow-x: auto; margin: 0 -10px; padding-bottom: 6px; }
  .kpi .value { font-size: 19px; }
}
.linkbtn { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font: inherit; }

main.wrap { padding-top: 24px; padding-bottom: 60px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap;
  margin-bottom: 18px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.card h2:first-child, .card h3:first-child { margin-top: 0; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow); }
.kpi .label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.kpi .value { font-size: 22px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.kpi.bad .value { color: var(--bad); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-60-40 { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; align-items: start; }
@media (max-width: 860px) { .grid2, .grid-60-40 { grid-template-columns: 1fr; } }

/* tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: middle; }
th { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  background: var(--bg); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tfoot td { font-weight: 650; border-top: 2px solid var(--rule); border-bottom: 0; }
tr.projected td { color: var(--muted); }
tr.muted-row td { color: var(--muted); }
table.kv td { padding: 6px 0; }
table.kv td:first-child { color: var(--muted); }
table.kv td:last-child { text-align: right; font-weight: 550; font-variant-numeric: tabular-nums; }
table.kv tr:last-child td { border-bottom: 0; }
td.empty { text-align: center; color: var(--muted); padding: 28px; }

/* badges */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  white-space: nowrap; }
.badge.current, .badge.paid, .badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.past_due, .badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.next, .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.scheduled, .badge.neutral { background: var(--bg); color: var(--muted); }

/* buttons + forms */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 6px;
  border: 1px solid var(--rule); background: var(--surface); color: var(--ink); font: inherit; font-weight: 550;
  cursor: pointer; white-space: nowrap; }
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 3px 9px; font-size: 12px; }
form.stack > div, .form-row { margin-bottom: 14px; }
label { display: block; font-weight: 550; margin-bottom: 4px; }
input[type=text], input[type=email], input[type=number], input[type=date], input[type=password], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--rule); border-radius: 6px; background: var(--surface);
  color: var(--ink); font: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=checkbox] { width: 16px; height: 16px; vertical-align: -3px; accent-color: var(--accent); }
.checkbox-row label { display: inline; font-weight: 550; margin-left: 6px; }
.helptext, .help { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
.errorlist { color: var(--bad); margin: 4px 0; padding: 0; list-style: none; font-size: 13px; }
.form-actions { display: flex; gap: 8px; align-items: center; margin-top: 18px; flex-wrap: wrap; }
.form-actions .spacer { flex: 1; }
.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.inline-form > div { margin: 0; }
.inline-form input { width: auto; }
fieldset { border: 0; padding: 0; margin: 0 0 8px; }
legend { font-weight: 650; font-size: 15px; margin-bottom: 10px; }

/* messages + notices */
.messages { list-style: none; padding: 0; margin: 0 0 18px; }
.messages li, .notice { padding: 10px 14px; border-radius: 6px; margin-bottom: 8px; border: 1px solid var(--rule);
  background: var(--surface); }
.messages li.success, .notice.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.messages li.error, .notice.bad { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.messages li.info, .messages li.warning, .notice.warn { background: var(--warn-soft); border-color: transparent;
  color: var(--warn); }
.notice.info { background: var(--accent-soft); border-color: transparent; }
.checklist { margin: 6px 0 0; padding-left: 20px; }
.checklist li.done { color: var(--muted); text-decoration: line-through; }

details summary { cursor: pointer; font-weight: 600; margin: 24px 0 10px; }
.calc { background: var(--accent-soft); border-radius: var(--radius); padding: 16px; position: sticky; top: 16px; }
.calc .big { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.login-card { max-width: 380px; margin: 60px auto; }
