:root {
  --bg: #f3f5fa; --surface: #ffffff; --ink: #18203a; --muted: #5e6880; --line: #e0e5ef;
  --accent: #2747d8; --accent-ink: #ffffff; --accent-soft: #e6ebfd;
  --gold: #d69e1c; --gold-soft: #fbf1d8; --ok: #1f9d73; --err: #c93a50;
  --radius: 10px; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1426; --surface: #171e35; --ink: #e8ecf7; --muted: #98a2bb; --line: #29324e;
    --accent: #7d93ff; --accent-ink: #0f1426; --accent-soft: #232d55;
    --gold: #f0bd45; --gold-soft: #3a3016; --ok: #4fd1a5; --err: #ff7b8e; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.55 Manrope, system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1 { font-size: 1.75rem; line-height: 1.2; margin: 0; font-weight: 800; letter-spacing: -.02em; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; font-weight: 700; }
code { font: 13px ui-monospace, Menlo, Consolas, monospace; background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 20px; }
main.wrap { padding-bottom: 60px; }

/* top bar */
.top { background: var(--surface); border-bottom: 1px solid var(--line); margin-bottom: 28px; }
.top-in { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 60px; flex-wrap: wrap; }
.brand { font-weight: 800; color: var(--ink); display: flex; align-items: center; gap: 10px; font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.mark { width: 22px; height: 22px; display: inline-block; vertical-align: -4px; margin-right: 6px;
  background: conic-gradient(var(--ink) 0 25%, transparent 0 50%, var(--ink) 0 75%, transparent 0) 0 0 / 11px 11px;
  border: 3px solid var(--accent); border-radius: 4px; }
.brand .mark { margin: 0; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav a { color: var(--muted); padding: 6px 12px; border-radius: 8px; font-weight: 600; }
nav a:hover { background: var(--bg); text-decoration: none; color: var(--ink); }
nav a[aria-current] { color: var(--accent); background: var(--accent-soft); }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.actions, .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.hint { color: var(--muted); max-width: 72ch; margin: -6px 0 20px; }
.panel .hint { margin: -4px 0 14px; font-size: .9rem; }
.muted { color: var(--muted); }
.small, small { font-size: .82rem; }
.nowrap { white-space: nowrap; }
.r { text-align: right; }
.ellipsis { display: block; max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inline { display: inline; }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-weight: 600; font-size: .9rem; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.danger { color: var(--err); }
.btn.danger:hover { border-color: var(--err); }
.btn.sm { padding: 4px 10px; font-size: .8rem; }

/* forms */
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: .88rem; }
label small { font-weight: 400; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
.form { display: flex; flex-direction: column; gap: 14px; }
.form h2 { margin: 0; }

.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 20px; }
.filters label { min-width: 150px; flex: 0 1 180px; }
.filters label.check { flex: 0 0 auto; padding-bottom: 9px; }

/* surfaces */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 20px; min-width: 0; }
.grid-side { display: grid; grid-template-columns: minmax(280px, 360px) 1fr; gap: 20px; align-items: start; }
.grid-side > * { min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.grid2 .wide { grid-column: 1 / -1; }
.chart { position: relative; height: 240px; }
.chart.tall { height: 300px; }
.scroll { overflow-x: auto; }
@media (max-width: 860px) { .grid-side, .grid2 { grid-template-columns: 1fr; } }

/* KPI strip — one continuous ruled band rather than separate cards */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 20px; }
.kpis > div { padding: 16px 20px; border-left: 1px solid var(--line); }
.kpis > div:first-child { border-left: 0; }
.kpis b { display: block; font-size: 1.9rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpis b small { font-size: .95rem; color: var(--muted); font-weight: 600; }
.kpis span { color: var(--muted); font-size: .85rem; }
@media (max-width: 700px) { .kpis { grid-template-columns: 1fr 1fr; } .kpis > div:nth-child(3) { border-left: 0; } .kpis > div:nth-child(n+3) { border-top: 1px solid var(--line); } }

/* tables */
table { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
th { text-align: left; font-size: .78rem; font-weight: 700; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th.r { text-align: right; }
th.sorter { cursor: pointer; user-select: none; }
th.sorter:hover { color: var(--ink); }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tr.muted td { color: var(--muted); }

/* the leaderboard is the signature element */
.board td { vertical-align: middle; padding: 12px 10px; }
.rank { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--bg); font-weight: 800; font-size: .85rem; }
.board tr.lead { background: var(--gold-soft); }
.board tr.lead .rank { background: var(--gold); color: #1d1503; }
.bar-cell { position: relative; min-width: 150px; }
.bar-cell .bar { position: absolute; left: 10px; top: 50%; height: 8px; transform: translateY(-50%); width: calc((100% - 100px) * var(--w) / 100);
  background: var(--accent); opacity: .22; border-radius: 4px; }
.board tr.lead .bar { background: var(--gold); opacity: .5; }
.bar-cell b { position: relative; }

.tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 3px; }
.tag { font-size: .72rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.tag:hover { text-decoration: none; filter: brightness(.96); }
.pill { font-size: .7rem; padding: 1px 7px; border-radius: 999px; font-weight: 700; }
.pill.off { background: var(--err); color: #fff; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 18px; font-weight: 600; border: 1px solid; }
.flash.ok { border-color: var(--ok); color: var(--ok); background: color-mix(in srgb, var(--ok) 10%, transparent); }
.flash.err { border-color: var(--err); color: var(--err); background: color-mix(in srgb, var(--err) 10%, transparent); }

.empty { text-align: center; padding: 60px 20px; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty p { color: var(--muted); }

body.center { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.card.narrow { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: flex; flex-direction: column; gap: 16px; }
.card h1 { font-size: 1.4rem; }

dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); padding: 24px; max-width: 360px; width: calc(100% - 32px); text-align: center; }
dialog::backdrop { background: rgba(10, 14, 30, .5); }
dialog .row { justify-content: center; }
.qr-box svg { width: 240px; height: 240px; display: block; margin: 0 auto; border-radius: 6px; }
#qrLink { word-break: break-all; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
