/* ---------- tokens ---------- */
:root {
  --bg: #f4f3ee;
  --surface: #fbfaf7;
  --surface-sunk: #eeede7;
  --text: #1c1c19;
  --muted: #66655e;
  --faint: #8d8c84;
  --border: #e0ded6;
  --border-strong: #cbc9bf;
  --accent: #1f6f5c;
  --accent-hover: #185a4b;
  --accent-soft: #e2eee9;
  --on-accent: #f4f3ee;
  --warn: #9a5b0b;
  --warn-soft: #f6ebd9;
  --danger: #a8321f;
  --danger-soft: #f6e2dd;
  --ok: #2a6b3c;
  --ok-soft: #e1ede3;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --radius: 8px;
  --radius-sm: 6px;

  --t-xs: 12px; --t-sm: 13px; --t-md: 15px; --t-lg: 20px; --t-xl: 40px;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --shadow-float: 0 1px 2px rgb(28 28 25 / 0.06), 0 8px 24px rgb(28 28 25 / 0.10);

  /* The only z-index scale in the app. */
  --z-sticky: 10;
  --z-toast: 30;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131312;
    --surface: #1b1b19;
    --surface-sunk: #232320;
    --text: #ebeae4;
    --muted: #a4a39b;
    --faint: #7c7b74;
    --border: #2c2c29;
    --border-strong: #3d3d39;
    --accent: #5bb39b;
    --accent-hover: #74c2ac;
    --accent-soft: #1e2f2a;
    --on-accent: #10201b;
    --warn: #e0a54f;
    --warn-soft: #33281a;
    --danger: #ec8a78;
    --danger-soft: #3a211c;
    --ok: #7fbf8f;
    --ok-soft: #1d2d22;
    --shadow-float: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px rgb(0 0 0 / 0.4);
  }
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
/* Author display rules (grid, flex) beat the UA's [hidden] rule; restore it. */
[hidden] { display: none !important; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 400 var(--t-md)/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: var(--t-lg); line-height: 1.2; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: var(--t-md); line-height: 1.3; font-weight: 600; }
h3 { font-size: var(--t-sm); line-height: 1.3; font-weight: 600; color: var(--muted); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
code, .mono { font-family: var(--mono); font-size: 0.92em; }
.num { font-variant-numeric: tabular-nums; }
.tabular { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: var(--t-sm); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- shell ---------- */
.shell { min-height: 100vh; display: grid; grid-template-rows: auto 1fr; }
.topbar {
  position: sticky; top: 0; z-index: var(--z-sticky);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1180px; margin: 0 auto; padding: var(--s3) var(--s5);
  display: flex; align-items: center; gap: var(--s5);
}
.brand { display: flex; align-items: center; gap: var(--s2); font-weight: 600; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand img { width: 22px; height: 22px; }
.nav { display: flex; gap: var(--s1); flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  color: var(--muted); padding: var(--s1) var(--s3); border-radius: var(--radius-sm);
  font-size: var(--t-sm); font-weight: 500; white-space: nowrap;
  transition: background-color 120ms ease, color 120ms ease;
}
.nav a:hover { color: var(--text); background: var(--surface-sunk); text-decoration: none; }
.nav a[aria-current="page"] { color: var(--text); background: var(--surface-sunk); }
.nav .sep { width: 1px; background: var(--border); margin: var(--s1) var(--s2); }
.who { display: flex; align-items: center; gap: var(--s3); font-size: var(--t-sm); }
.who .email { color: var(--muted); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main { max-width: 1180px; width: 100%; margin: 0 auto; padding: var(--s6) var(--s5) var(--s7); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s4); margin-bottom: var(--s5); flex-wrap: wrap; }
.page-head p { color: var(--muted); font-size: var(--t-sm); margin-top: var(--s1); max-width: 70ch; }
.stack { display: grid; gap: var(--s5); }
/* Grid items default to min-width: auto, so a wide table would stretch the whole
   page instead of scrolling inside .table-wrap. Let them shrink. */
.shell > *, .stack > *, .hero > * { min-width: 0; }
.row { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.panel-head { display: flex; align-items: center; gap: var(--s3); padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.panel-body { padding: var(--s5); }

/* The one large element on the overview. */
.hero { display: grid; grid-template-columns: minmax(260px, 1.1fr) 2fr; }
.hero-main { padding: var(--s5); border-right: 1px solid var(--border); display: grid; gap: var(--s3); align-content: start; }
.hero-figure { font-size: var(--t-xl); line-height: 1.05; font-weight: 600; letter-spacing: -0.02em; }
.hero-figure .unit { font-size: var(--t-lg); font-weight: 500; color: var(--muted); margin-left: var(--s1); }
.hero-stats { display: grid; grid-template-columns: repeat(2, 1fr); }
.stat { padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border); }
.stat:nth-child(odd) { border-right: 1px solid var(--border); }
.stat:nth-last-child(-n+2) { border-bottom: 0; }
.stat .label { font-size: var(--t-xs); color: var(--muted); font-weight: 500; }
.stat .value { font-size: var(--t-lg); font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .hint { font-size: var(--t-xs); color: var(--faint); margin-top: 2px; }

.stat-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stat-strip .stat { border-bottom: 0; border-right: 1px solid var(--border); }
.stat-strip .stat:last-child { border-right: 0; }

/* ---------- meter ---------- */
.meter { height: 6px; background: var(--surface-sunk); border-radius: 999px; overflow: hidden; }
.meter > span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width 200ms ease-out; }
.meter.warn > span { background: var(--warn); }
.meter.danger > span { background: var(--danger); }
.meter-caption { display: flex; justify-content: space-between; font-size: var(--t-xs); color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: var(--t-sm); }
th {
  text-align: left; font-weight: 500; color: var(--muted); font-size: var(--t-xs);
  padding: var(--s2) var(--s4); border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface);
}
td { padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.clickable { cursor: pointer; transition: background-color 100ms ease; }
tr.clickable:hover { background: var(--surface-sunk); }
.cell-main { font-weight: 500; }
td .row { gap: var(--s2); flex-wrap: nowrap; }
.cell-sub { font-size: var(--t-xs); color: var(--muted); }
.cell-meter { min-width: 140px; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: var(--s1);
  font-size: var(--t-xs); font-weight: 500; line-height: 1;
  padding: 3px var(--s2); border-radius: 999px;
  background: var(--surface-sunk); color: var(--muted); white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- controls ---------- */
button, .btn {
  font: 500 var(--t-sm)/1 var(--font);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  height: 34px; padding: 0 var(--s4);
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}
button:hover { background: var(--surface-sunk); }
button:active { transform: translateY(0.5px); }
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
button.danger { color: var(--danger); }
button.danger:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }
button.ghost { border-color: transparent; background: transparent; color: var(--muted); }
button.ghost:hover:not(:disabled) { background: var(--surface-sunk); color: var(--text); }
button.small { height: 28px; padding: 0 var(--s3); font-size: var(--t-xs); }
button.block { width: 100%; }

input, select, textarea {
  font: 400 var(--t-sm)/1.4 var(--font); color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  height: 34px; padding: 0 var(--s3); width: 100%;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
input[type="checkbox"], input[type="radio"] { width: auto; height: auto; padding: 0; accent-color: var(--accent); }
.check { display: flex; align-items: flex-start; gap: var(--s2); font-size: var(--t-sm); cursor: pointer; }
.check input { margin-top: 3px; }
textarea { height: auto; padding: var(--s2) var(--s3); resize: vertical; min-height: 72px; font-family: var(--mono); }
input:hover, select:hover, textarea:hover { border-color: var(--faint); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input:disabled, select:disabled { background: var(--surface-sunk); color: var(--muted); cursor: not-allowed; }
input[aria-invalid="true"] { border-color: var(--danger); }
.field { display: grid; gap: var(--s1); }
.field label { font-size: var(--t-sm); font-weight: 500; }
.field .help { font-size: var(--t-xs); color: var(--muted); }
.fields { display: grid; gap: var(--s4); }
.search { max-width: 260px; }
.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.segmented button { border: 0; border-radius: 0; height: 30px; background: var(--surface); color: var(--muted); }
.segmented button + button { border-left: 1px solid var(--border-strong); }
.segmented button[aria-pressed="true"] { background: var(--surface-sunk); color: var(--text); }

.radio-cards { display: grid; gap: var(--s2); }
.radio-card { display: grid; grid-template-columns: auto 1fr; gap: var(--s1) var(--s3); padding: var(--s3); border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; transition: border-color 120ms ease, background-color 120ms ease; }
.radio-card:hover { border-color: var(--border-strong); }
.radio-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.radio-card input { width: auto; height: auto; margin: 3px 0 0; accent-color: var(--accent); }
.radio-card .title { font-size: var(--t-sm); font-weight: 600; }
.radio-card .desc { grid-column: 2; font-size: var(--t-xs); color: var(--muted); }

/* ---------- states ---------- */
.notice { display: grid; gap: var(--s2); padding: var(--s4) var(--s5); border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); }
.notice.warn { background: var(--warn-soft); border-color: transparent; }
.notice.danger { background: var(--danger-soft); border-color: transparent; }
.notice h2 { font-size: var(--t-md); }
.notice p { font-size: var(--t-sm); color: var(--muted); max-width: 72ch; }
.notice.warn p, .notice.danger p { color: var(--text); }
.empty { padding: var(--s7) var(--s5); text-align: center; color: var(--muted); font-size: var(--t-sm); }
.empty strong { display: block; color: var(--text); font-size: var(--t-md); margin-bottom: var(--s1); }

.skeleton { background: var(--surface-sunk); border-radius: 4px; height: 14px; animation: pulse 1.4s ease-in-out infinite; }
.skeleton.lg { height: 40px; width: 60%; }
@keyframes pulse { 50% { opacity: 0.55; } }

.error-text { color: var(--danger); font-size: var(--t-sm); }

/* ---------- chart ---------- */
.chart { display: block; }
.chart .bar { fill: var(--accent); transition: opacity 120ms ease; }
.chart .bar:hover { opacity: 0.75; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart text { fill: var(--faint); font-size: 11px; font-family: var(--font); }

/* ---------- auth pages ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: var(--s5); }
.auth-card { width: 100%; max-width: 380px; display: grid; gap: var(--s5); }
.auth-card .brand { justify-self: start; font-size: var(--t-md); }
.auth-card .panel-body { display: grid; gap: var(--s4); }
.divider { display: flex; align-items: center; gap: var(--s3); color: var(--faint); font-size: var(--t-xs); }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ---------- dialog ---------- */
dialog {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-float);
  width: min(520px, calc(100vw - var(--s6)));
}
dialog::backdrop { background: rgb(19 19 18 / 0.45); }
dialog[open] { animation: dialog-in 160ms ease-out; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(6px); } }
.dialog-head { padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border); }
.dialog-body { padding: var(--s5); display: grid; gap: var(--s4); max-height: 70vh; overflow-y: auto; }
.dialog-foot { padding: var(--s3) var(--s5); border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: var(--s2); }
.secret {
  display: flex; gap: var(--s2); align-items: center;
  font-family: var(--mono); font-size: var(--t-xs); word-break: break-all;
  padding: var(--s3); background: var(--surface-sunk); border-radius: var(--radius-sm);
}
.secret span { flex: 1; }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: var(--s5); bottom: var(--s5); z-index: var(--z-toast); display: grid; gap: var(--s2); isolation: isolate; }
.toast {
  background: var(--text); color: var(--bg); font-size: var(--t-sm);
  padding: var(--s3) var(--s4); border-radius: var(--radius-sm); box-shadow: var(--shadow-float);
  max-width: 360px; animation: toast-in 180ms ease-out;
}
.toast.error { background: var(--danger); color: var(--surface); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}

@media (max-width: 760px) {
  .hero { grid-template-columns: 1fr; }
  .hero-main { border-right: 0; border-bottom: 1px solid var(--border); }
  .topbar-inner { flex-wrap: wrap; gap: var(--s2) var(--s3); padding: var(--s3) var(--s4); }
  .who { margin-left: auto; }
  .page-head .row { width: 100%; }
  .search { max-width: none; flex: 1 1 100%; }
  .panel-head, .panel-body, .stat { padding-left: var(--s4); padding-right: var(--s4); }
  .nav { order: 3; flex: 1 1 100%; margin: 0 calc(-1 * var(--s3)); padding: 0 var(--s2); }
  main { padding: var(--s5) var(--s4) var(--s7); }
  .who .email { display: none; }
}
