:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2f6f4f;
  --accent-soft: #e7f2ec;
  --bar: #2f6f4f;
  --bar-2: #9ca3af;
  --warn: #9a6700;
  --warn-soft: #fff4d6;
  --bad: #9f1239;
  --bad-soft: #ffe4e6;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --panel: #171a20;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --line: #2a2f38;
    --accent: #6fcf97;
    --accent-soft: #16322a;
    --bar: #6fcf97;
    --bar-2: #4b5563;
    --warn: #f2c94c;
    --warn-soft: #3a3016;
    --bad: #fda4af;
    --bad-soft: #3b1720;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --panel: #171a20; --text: #e5e7eb; --muted: #9ca3af; --line: #2a2f38;
  --accent: #6fcf97; --accent-soft: #16322a; --bar: #6fcf97; --bar-2: #4b5563;
  --warn: #f2c94c; --warn-soft: #3a3016; --bad: #fda4af; --bad-soft: #3b1720; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px;
  padding: 12px 24px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.mark { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--text); color: var(--panel); font-size: 11px; }
.spacer { flex: 1; }
select, input, button, .ghost {
  font: inherit; color: inherit; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; min-height: 34px;
}
button, .ghost { cursor: pointer; }
.ghost:hover, button:hover { border-color: var(--muted); }
.link { text-decoration: none; display: inline-flex; align-items: center; }
.tabs { display: flex; gap: 4px; }
.tabs a { padding: 6px 10px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
.tabs a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }

main { max-width: 1240px; margin: 0 auto; padding: 24px; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 15px; margin: 0 0 12px; }
.sub { color: var(--muted); margin: 0 0 20px; }
.note { color: var(--muted); font-size: 12px; margin-top: 10px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi, .panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.kpi { padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.kpi .hint { color: var(--muted); font-size: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 12px; margin-bottom: 16px; }
.panel { padding: 16px; min-width: 0; }

.chart { width: 100%; height: auto; display: block; }
.chart rect { fill: var(--bar); }
.chart .axis { fill: var(--muted); font-size: 10px; }
.chart .empty { fill: var(--muted); font-size: 12px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar input[type="search"] { min-width: 240px; flex: 1; max-width: 360px; }
.toolbar .count { color: var(--muted); margin-left: auto; }

.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--bg); }
.email { font-weight: 500; }
.muted { color: var(--muted); }
.tpl { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.paying { background: var(--accent-soft); color: var(--accent); }
.badge.single { background: var(--accent-soft); color: var(--accent); opacity: 0.8; }
.badge.unclear { background: var(--warn-soft); color: var(--warn); }
.badge.lapsed { background: var(--bad-soft); color: var(--bad); }
.badge.free { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }

.pager { display: flex; gap: 8px; justify-content: flex-end; align-items: center; margin-top: 12px; }
.back { display: inline-block; margin-bottom: 12px; color: var(--muted); text-decoration: none; }
.error { background: var(--bad-soft); color: var(--bad); padding: 12px 16px; border-radius: var(--radius); }
.loading { color: var(--muted); }

@media (max-width: 640px) {
  .topbar { padding: 10px 16px; }
  main { padding: 16px; }
  .toolbar input[type="search"] { min-width: 0; max-width: none; width: 100%; }
  .grid2 { grid-template-columns: 1fr; }
}
