:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f0f2f5; --border: #e3e6eb;
  --text: #0f1419; --muted: #5f6b7a; --faint: #8a94a3;
  --accent: #4f46e5; --accent-2: #6366f1; --accent-soft: #eef0ff;
  --ok: #16a34a; --ok-soft: #e8f7ee; --warn: #d97706; --warn-soft: #fdf3e2; --bad: #dc2626; --bad-soft: #fdecec;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
  --radius: 14px;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0b0d12; --surface: #13161d; --surface-2: #1a1e27; --border: #252a35;
  --text: #e8ebf0; --muted: #9aa3b2; --faint: #6b7483;
  --accent: #818cf8; --accent-2: #a5b4fc; --accent-soft: #1e2140;
  --ok: #4ade80; --ok-soft: #10261a; --warn: #fbbf24; --warn-soft: #2a2110; --bad: #f87171; --bad-soft: #2c1414;
  --shadow: 0 1px 2px rgba(0,0,0,.3);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
svg.i { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button { font: inherit; cursor: pointer; }

/* ---------- layout ---------- */
.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px;
  padding: 12px 24px; background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: -.01em; }
.logo { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--accent), #8b5cf6); }
.logo svg.i { width: 17px; height: 17px; }
.nav { display: flex; gap: 4px; margin-left: 16px; }
.nav button { background: none; border: 0; color: var(--muted); padding: 7px 12px; border-radius: 9px; display: flex; gap: 7px; align-items: center; }
.nav button:hover { background: var(--surface-2); color: var(--text); }
.nav button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.spacer { flex: 1; }
.iconbtn { background: var(--surface); border: 1px solid var(--border); color: var(--muted); width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; }
.iconbtn:hover { color: var(--text); }
.updated { color: var(--faint); font-size: 13px; }
main { max-width: 1200px; margin: 0 auto; padding: 24px; }
h1 { font-size: 22px; margin: 4px 0 18px; letter-spacing: -.02em; }
h2 { font-size: 15px; margin: 28px 0 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

/* ---------- cards ---------- */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); }
.stats { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-bottom: 8px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 13px; display: flex; gap: 8px; align-items: center; }
.stat .value { font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 6px; }
.stat .sub { color: var(--faint); font-size: 13px; }
.card-head { display: flex; align-items: flex-start; gap: 10px; }
.card-head .title { font-weight: 650; font-size: 16px; }
.card-head .meta { color: var(--muted); font-size: 13px; }
.badge { margin-left: auto; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.ok { color: var(--ok); } .warn { color: var(--warn); } .bad { color: var(--bad); }
.badge.ok { background: var(--ok-soft); } .badge.warn { background: var(--warn-soft); } .badge.bad { background: var(--bad-soft); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin-top: 14px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 4px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; width: 0; transition: width .4s; }
.bar.warn > i { background: var(--warn); } .bar.bad > i { background: var(--bad); }
.meter { margin-top: 12px; font-size: 13px; color: var(--muted); }
.meter .row { display: flex; justify-content: space-between; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.chip { font-size: 12px; padding: 3px 9px; border-radius: 8px; background: var(--surface-2); color: var(--muted); display: inline-flex; gap: 6px; align-items: center; }
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); }
.chip.off::before { background: var(--bad); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: 13px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
td { padding: 12px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: 0; }
.table-card { padding: 0; overflow-x: auto; }
.paid { display: inline-flex; gap: 8px; align-items: center; }
.paid input { font: inherit; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 4px 8px; }
.journal-day { margin-bottom: 14px; }
.journal-day .date { font-weight: 650; margin-bottom: 8px; }
.md { font-size: 14px; color: var(--text); }
.md h3 { font-size: 14px; margin: 12px 0 6px; color: var(--muted); }
.md ul { margin: 0; padding-left: 18px; } .md li { margin: 3px 0; }
.md code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.empty { color: var(--faint); padding: 18px; text-align: center; }
.btn { background: var(--accent); color: #fff; border: 0; padding: 10px 16px; border-radius: 10px; font-weight: 600; }
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.hidden { display: none !important; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 50; }

/* ---------- auth pages ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 20% -10%, var(--accent-soft), transparent 60%), var(--bg); }
.auth .card { width: 100%; max-width: 380px; padding: 28px; }
.auth h1 { margin: 16px 0 4px; }
.auth p.lead { color: var(--muted); margin: 0 0 20px; font-size: 14px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input { width: 100%; font: inherit; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); outline: none; }
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field input.code { letter-spacing: .4em; font-size: 20px; text-align: center; font-variant-numeric: tabular-nums; }
.auth .btn { width: 100%; padding: 12px; }
.err { color: var(--bad); font-size: 14px; min-height: 20px; margin-bottom: 8px; }
.qr { background: #fff; padding: 12px; border-radius: 12px; width: 200px; margin: 0 auto 12px; }
.qr svg { display: block; width: 100%; height: auto; }
.secret { text-align: center; font-family: ui-monospace, monospace; font-size: 13px; color: var(--muted); word-break: break-all; margin-bottom: 18px; }
.auth-top { display: flex; justify-content: space-between; align-items: center; }

@media (max-width: 760px) {
  .top { padding: 10px 14px; flex-wrap: wrap; }
  .nav { order: 3; width: 100%; margin: 6px 0 0; overflow-x: auto; }
  .updated { display: none; }
  main { padding: 16px 14px; }
  .grid { grid-template-columns: 1fr; }
}
