:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #e6effa;
  --series-1: #2a78d6;
  --good: #0a7d32;
  --good-soft: #e3f3e8;
  --warn: #9a5b00;
  --warn-soft: #fbefd9;
  --bad: #c22b2b;
  --bad-soft: #fbe4e4;
  --grid: #e8e7e2;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 1px 1px rgba(0, 0, 0, .03);
  --radius: 12px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2e2e2b;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #8f8e86;
    --accent: #3987e5;
    --accent-soft: #1c2b40;
    --series-1: #3987e5;
    --good: #4cc677;
    --good-soft: #15291c;
    --warn: #e3a33b;
    --warn-soft: #2e2311;
    --bad: #ef7676;
    --bad-soft: #341919;
    --grid: #2a2a27;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 15px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.small { font-size: 12.5px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }

/* ---------- layout */
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; font-weight: 650; font-size: 15px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
}
.nav a {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-radius: 8px; color: var(--text-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav .count {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: var(--accent-ink);
  font-size: 11.5px; font-weight: 600; display: grid; place-items: center;
}
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding: 0 4px; }
.me { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center;
  font-weight: 600; font-size: 12px; color: var(--text-2); overflow: hidden; flex: none;
}
.avatar img { width: 100%; height: 100%; }
.main { padding: 28px 32px 48px; max-width: 1180px; width: 100%; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head p { margin: 4px 0 0; }

/* ---------- pieces */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid-side { grid-template-columns: minmax(0, 1fr) 360px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 550; background: var(--surface-2); color: var(--text-2); white-space: nowrap;
}
.pill svg { width: 12px; height: 12px; }
.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.info { background: var(--accent-soft); color: var(--accent); }

.hero { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 16px; margin-bottom: 16px; }
.hero-figure { font-size: 52px; font-weight: 650; letter-spacing: -.02em; line-height: 1.05; margin: 6px 0 8px; }
.hero-label { font-size: 13px; color: var(--text-2); font-weight: 500; }
.hero-actions { margin-top: 14px; }

.stat-label { color: var(--text-2); font-size: 12.5px; font-weight: 500; }
.stat-value { font-size: 24px; font-weight: 620; letter-spacing: -.01em; margin-top: 4px; }
.stat-sub { color: var(--text-3); font-size: 12.5px; margin-top: 2px; }

.split-bar { display: flex; gap: 2px; height: 8px; border-radius: 4px; overflow: hidden; margin: 12px 0 8px; }
.split-bar span:first-child { background: var(--series-1); }
.split-bar span:last-child { background: var(--text-3); opacity: .55; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; vertical-align: 1px; }

/* ---------- chart */
.chart-wrap { position: relative; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-text { fill: var(--text-3); font-size: 11px; font-family: var(--font); }
.chart .bar { fill: var(--series-1); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart g.on .bar { opacity: .8; }
.chart .baseline { stroke: var(--border); stroke-width: 1; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--text); color: var(--surface); padding: 7px 10px;
  border-radius: 8px; font-size: 12px; line-height: 1.4; white-space: nowrap; transform: translate(-50%, calc(-100% - 10px));
  opacity: 0; transition: opacity .08s;
}
.tooltip.show { opacity: 1; }
.tooltip b { font-weight: 600; }

.hbars { display: flex; flex-direction: column; gap: 12px; }
.hbar-top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.hbar-track { height: 8px; border-radius: 4px; background: var(--surface-2); margin-top: 5px; overflow: hidden; }
.hbar-fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; }

/* ---------- tables */
.table-wrap { overflow-x: auto; margin: 0 -20px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { padding-left: 20px; }
th:last-child, td:last-child { padding-right: 20px; }
th { font-size: 12px; font-weight: 550; color: var(--text-2); background: var(--surface); position: sticky; top: 0; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.r, th.r { text-align: right; }
td.wrap { white-space: normal; min-width: 200px; }
tr.voided td { color: var(--text-3); }
tr.voided td.amt { text-decoration: line-through; }
.empty { padding: 28px 0 10px; text-align: center; color: var(--text-3); }

/* ---------- forms */
label { display: block; font-size: 12.5px; font-weight: 550; color: var(--text-2); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field { margin-bottom: 12px; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 12px; }
.money-input { position: relative; }
.money-input span { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-3); }
.money-input input { padding-left: 22px; }
.hint { font-size: 12px; color: var(--text-3); margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 550;
  font-size: 13px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.good { background: var(--good); color: #fff; border-color: transparent; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.block { width: 100%; }
form.inline { display: inline; }

.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 9px; margin-bottom: 16px; }
.tabs button {
  flex: 1; font: inherit; font-weight: 550; font-size: 13px; border: 0; background: transparent; color: var(--text-2);
  padding: 7px 8px; border-radius: 7px; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { margin: 0; }
.filters input, .filters select { width: auto; min-width: 140px; }

/* ---------- requests */
.request {
  display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); flex-wrap: wrap;
}
.request:first-of-type { border-top: 0; padding-top: 0; }
.request-body { flex: 1; min-width: 200px; }
.request-title { font-weight: 550; }
.request-note { color: var(--text-2); font-size: 12.5px; margin-top: 2px; }

.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; font-weight: 500; display: flex; gap: 8px; align-items: center; }
.flash.ok { background: var(--good-soft); color: var(--good); }
.flash.error { background: var(--bad-soft); color: var(--bad); }

.banner {
  display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--radius);
  background: var(--accent-soft); color: var(--text); margin-bottom: 16px; border: 1px solid transparent;
}
.banner.warn { background: var(--warn-soft); }
.banner svg { flex: none; width: 18px; height: 18px; margin-top: 1px; color: var(--accent); }
.banner.warn svg { color: var(--warn); }

dialog {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text);
  padding: 20px; width: min(440px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(0, 0, 0, .4); }
dialog h2 { margin-bottom: 6px; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; font-size: 13px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; }

.pager { display: flex; justify-content: space-between; align-items: center; padding-top: 14px; }

/* ---------- login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(380px, 100%); text-align: center; padding: 32px 28px; }
.login-card .brand-mark { width: 44px; height: 44px; border-radius: 12px; font-size: 18px; margin: 0 auto 16px; }
.login-card h1 { margin-bottom: 6px; }
.login-card p { margin: 0 0 22px; }
.discord-btn { background: #5865f2; color: #fff; border: 0; padding: 11px 16px; font-size: 14px; }
.discord-btn:hover { background: #4c58e0; }
.discord-btn svg { width: 20px; height: 20px; }

/* ---------- responsive */
@media (max-width: 1020px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main, .hero, .grid-side { grid-template-columns: minmax(0, 1fr); }
  .grid-side > #record { order: -1; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: sticky; top: 0; z-index: 5; height: auto; flex-direction: row; align-items: center; gap: 4px;
    padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--border); overflow-x: auto;
  }
  .brand { padding: 0 8px 0 0; }
  .brand span:last-child { display: none; }
  .nav { display: flex; gap: 2px; }
  .nav a { padding: 7px 9px; }
  .sidebar-foot { margin: 0 0 0 auto; flex-direction: row; padding: 0; }
  .sidebar-foot .me-name, .sidebar-foot .sync-wrap { display: none; }
  .main { padding: 20px 16px 40px; }
  .grid-2, .fields { grid-template-columns: 1fr; }
  .hero-figure { font-size: 44px; }
  .table-wrap { margin: 0 -20px; }
}
@media (max-width: 420px) {
  .grid-4 { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card { padding: 16px; }
  .stat-value { font-size: 20px; }
}
