/* Fabler admin dashboard. One stylesheet, no external assets. The only script is the
   sign-in pages' passkey script (auth.js).
   Light theme by default, dark via prefers-color-scheme. Colours are
   custom properties; components below only use the tokens. */

:root {
  color-scheme: light dark;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --fs-xs: 0.75rem;
  --fs-sm: 0.8125rem;
  --fs-md: 0.875rem;
  --fs-base: 0.9375rem;
  --fs-lg: 1.0625rem;
  --fs-xl: 1.375rem;
  --fs-2xl: 1.875rem;

  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px;
  --radius: 10px;
  --radius-sm: 6px;
  --sidebar-w: 236px;

  --bg: #f5f5f8;
  --surface: #ffffff;
  --surface-2: #f8f8fb;
  --surface-hover: #f3f1fa;
  --border: #e5e4ec;
  --border-strong: #cfcdd9;
  --text: #17161d;
  --text-2: #4a4857;
  --text-3: #63616f;
  --link: #5b2fc0;

  --accent: #6c3fd6;
  --accent-fg: #ffffff;
  --accent-hover: #5a2fc2;
  --accent-soft: #f1ebff;
  --accent-soft-fg: #5326b6;
  --focus: #7c4ce6;

  --side-bg: #15131b;
  --side-text: #c8c5d4;
  --side-muted: #8f8b9e;
  --side-hover: #221f2b;
  --side-active-bg: rgba(184, 133, 252, 0.16);
  --side-active-fg: #ffffff;
  --side-accent: rgb(184, 133, 252);
  --side-border: #24212d;

  --ok-bg: #e5f5eb;   --ok-fg: #13612f;   --ok-border: #a8dbb9;
  --warn-bg: #fdf2d6; --warn-fg: #7a4e00; --warn-border: #f0d27e;
  --info-bg: #e7effc; --info-fg: #1c4a91; --info-border: #b3cbf1;
  --bad-bg: #fde8e7;  --bad-fg: #a01f19;  --bad-border: #f0b4b0;
  --neutral-bg: #efeef3; --neutral-fg: #4a4857;
  --danger: #c4302a;
  --danger-hover: #a52520;
  --danger-fg: #ffffff;
  --danger-soft: #fff6f5;

  --shadow: 0 1px 2px rgba(20, 16, 40, 0.05), 0 1px 1px rgba(20, 16, 40, 0.03);
  --progress-track: #ecebf2;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0d12;
    --surface: #17161d;
    --surface-2: #1c1b23;
    --surface-hover: #221f2c;
    --border: #2a2833;
    --border-strong: #3a3745;
    --text: #ecebf2;
    --text-2: #b9b6c6;
    --text-3: #9895a8;
    --link: #c9a6ff;

    --accent: rgb(184, 133, 252);
    --accent-fg: #1a1226;
    --accent-hover: #c9a2ff;
    --accent-soft: rgba(184, 133, 252, 0.14);
    --accent-soft-fg: #d4b8ff;
    --focus: rgb(184, 133, 252);

    --side-bg: #0b0a0f;
    --side-hover: #1a1822;
    --side-border: #1f1d27;

    --ok-bg: rgba(64, 196, 110, 0.14);  --ok-fg: #86e0a6;   --ok-border: rgba(64, 196, 110, 0.35);
    --warn-bg: rgba(245, 180, 40, 0.14); --warn-fg: #f6cf75; --warn-border: rgba(245, 180, 40, 0.35);
    --info-bg: rgba(90, 150, 250, 0.15); --info-fg: #a3c4ff; --info-border: rgba(90, 150, 250, 0.35);
    --bad-bg: rgba(240, 85, 75, 0.15);   --bad-fg: #ffa59e;  --bad-border: rgba(240, 85, 75, 0.4);
    --neutral-bg: #26242f; --neutral-fg: #c2bfcf;
    --danger: #d9443c;
    --danger-hover: #e65a52;
    --danger-fg: #ffffff;
    --danger-soft: rgba(240, 85, 75, 0.06);

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --progress-track: #2a2833;
  }
}

/* ---- base ------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }
html { font: var(--fs-base)/1.5 var(--font); color: var(--text); background: var(--bg); -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
code, pre, .mono { font-family: var(--mono); font-size: 0.875em; }
h1, h2, h3 { margin: 0; line-height: 1.25; color: var(--text); }
p { margin: 0 0 var(--sp-3); }
strong { font-weight: 650; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
::selection { background: rgba(184, 133, 252, 0.35); }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: var(--sp-4); top: -100px; z-index: 100; background: var(--surface); color: var(--text); padding: var(--sp-2) var(--sp-4); border-radius: var(--radius-sm); box-shadow: var(--shadow); }
.skip:focus { top: var(--sp-4); }
.muted { color: var(--text-3); }
.small { font-size: var(--fs-sm); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

/* ---- app shell -------------------------------------------------------- */

.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: var(--sp-4);
  background: var(--side-bg); color: var(--side-text);
  border-right: 1px solid var(--side-border);
  padding: var(--sp-5) var(--sp-3) var(--sp-4);
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-1) var(--sp-2) var(--sp-3); color: #fff; text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, rgb(184, 133, 252), #8b5cf6); color: #160d24;
  font-weight: 800; font-size: 0.95rem;
}
.brand-name { font-weight: 650; font-size: var(--fs-lg); letter-spacing: -0.01em; }
.brand-sub { color: var(--side-muted); font-weight: 500; }

.sidenav ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.sidenav a {
  position: relative; display: flex; align-items: center; gap: var(--sp-3);
  padding: 8px var(--sp-3); border-radius: var(--radius-sm);
  color: var(--side-text); font-size: var(--fs-base); font-weight: 500; text-decoration: none;
}
.sidenav a:hover { background: var(--side-hover); color: #fff; text-decoration: none; }
.sidenav a[aria-current="page"] { background: var(--side-active-bg); color: var(--side-active-fg); }
.sidenav a[aria-current="page"]::before {
  content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--side-accent);
}
.sidenav a[aria-current="page"] .icon { stroke: var(--side-accent); }
.sidenav a:focus-visible, .brand:focus-visible { outline-color: var(--side-accent); }

.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.sidebar-foot {
  margin-top: auto; display: flex; flex-direction: column; gap: var(--sp-2);
  padding: var(--sp-3); border-top: 1px solid var(--side-border);
}
.who { display: flex; flex-direction: column; min-width: 0; }
.who-label { font-size: var(--fs-xs); color: var(--side-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.who-email { color: #fff; font-size: var(--fs-md); font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.env {
  align-self: flex-start; font-size: var(--fs-xs); font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em;
  padding: 2px 8px; border-radius: 999px; background: #2a2735; color: #d9d5e6; border: 1px solid #3a3647;
}
.env-prod, .env-production { background: #5b1512; color: #ffd6d3; border-color: #8c2620; }

.main-col { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-4) var(--sp-6); flex-wrap: wrap;
  padding: var(--sp-5) var(--sp-8) var(--sp-5);
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-title { min-width: 0; flex: 1 1 320px; }
.topbar h1 { font-size: var(--fs-xl); font-weight: 650; letter-spacing: -0.015em; overflow-wrap: anywhere; }

.crumbs ol { list-style: none; display: flex; flex-wrap: wrap; align-items: center; gap: 2px; margin: 0 0 var(--sp-1); padding: 0; font-size: var(--fs-sm); color: var(--text-3); }
.crumbs li { display: inline-flex; align-items: center; min-width: 0; }
.crumbs li + li::before { content: "/"; margin: 0 6px; color: var(--border-strong); }
.crumbs a { color: var(--text-3); }
.crumbs a:hover { color: var(--text); }
.crumbs li[aria-current] { color: var(--text-2); }
.crumbs .id { max-width: 16ch; }

.search { position: relative; display: flex; gap: var(--sp-2); flex: 0 1 380px; }
.search input[type=search] { flex: 1; min-width: 0; padding-left: 34px; }
.search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-3); display: flex; pointer-events: none; }
.search-icon .icon { width: 16px; height: 16px; }

main { width: 100%; max-width: 1280px; padding: var(--sp-6) var(--sp-8) var(--sp-10); display: flex; flex-direction: column; gap: var(--sp-5); }
main:focus { outline: none; }
.foot { max-width: 1280px; padding: 0 var(--sp-8) var(--sp-8); color: var(--text-3); font-size: var(--fs-sm); }

/* ---- banners ---------------------------------------------------------- */

.banner { margin: 0; padding: var(--sp-3) var(--sp-4); border-radius: var(--radius-sm); border: 1px solid; font-size: var(--fs-md); overflow-wrap: anywhere; }
.banner-ok { background: var(--ok-bg); color: var(--ok-fg); border-color: var(--ok-border); }
.banner-bad { background: var(--bad-bg); color: var(--bad-fg); border-color: var(--bad-border); }
.banner-info { background: var(--info-bg); color: var(--info-fg); border-color: var(--info-border); }

/* ---- cards ------------------------------------------------------------ */

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: var(--sp-5); min-width: 0;
}
.card-flush { padding: 0; overflow: clip; }
.card-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: var(--sp-2) var(--sp-3); margin-bottom: var(--sp-4); }
.card-flush > .card-head { padding: var(--sp-4) var(--sp-5) 0; margin-bottom: var(--sp-3); }
.card-head h2 { font-size: var(--fs-lg); font-weight: 650; overflow-wrap: anywhere; }
.card-meta { color: var(--text-3); font-size: var(--fs-sm); }
.card-link { margin-left: auto; font-size: var(--fs-sm); font-weight: 550; }
.note { color: var(--text-3); font-size: var(--fs-sm); margin: var(--sp-4) 0 0; }
.lede { color: var(--text-2); margin: 0; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-5); align-items: start; }
.grid-wide-left { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }

.empty-state { text-align: center; padding: var(--sp-10) var(--sp-6); }
.empty-title { font-size: var(--fs-lg); font-weight: 600; margin-bottom: var(--sp-1); }
.empty-inline { color: var(--text-3); margin: 0; }
.pad { padding: 0 var(--sp-5) var(--sp-5); }

/* ---- overview --------------------------------------------------------- */

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-4); }
.stat {
  display: flex; flex-direction: column; gap: 2px; padding: var(--sp-4) var(--sp-5);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  color: var(--text); text-decoration: none; position: relative;
}
a.stat:hover { border-color: var(--border-strong); background: var(--surface-hover); text-decoration: none; }
.stat-label { color: var(--text-2); font-size: var(--fs-md); font-weight: 550; }
.stat-value { font-size: var(--fs-2xl); font-weight: 680; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat-unit { font-size: var(--fs-lg); font-weight: 550; color: var(--text-3); margin-left: 3px; }
.stat-sub { color: var(--text-3); font-size: var(--fs-sm); }
.stat-warn { border-color: var(--warn-border); }
.stat-warn::before, .stat-bad::before { content: ""; position: absolute; left: -1px; top: 12px; bottom: 12px; width: 3px; border-radius: 0 3px 3px 0; }
.stat-warn::before { background: var(--warn-fg); }
.stat-warn .stat-value { color: var(--warn-fg); }
.stat-bad { border-color: var(--bad-border); }
.stat-bad::before { background: var(--danger); }
.stat-bad .stat-value { color: var(--bad-fg); }

.breakdown { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-3); }
.breakdown li { display: grid; grid-template-columns: 8.5rem minmax(0, 1fr) 4.5rem; align-items: center; gap: var(--sp-3); }
.breakdown a:hover { text-decoration: none; }
.breakdown .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
progress { -webkit-appearance: none; appearance: none; width: 100%; height: 8px; border: 0; border-radius: 999px; background: var(--progress-track); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--progress-track); border-radius: 999px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 999px; }
progress.bar-ready::-webkit-progress-value { background: var(--ok-fg); }
progress.bar-ready::-moz-progress-bar { background: var(--ok-fg); }
progress.bar-generating::-webkit-progress-value { background: var(--warn-fg); }
progress.bar-generating::-moz-progress-bar { background: var(--warn-fg); }
progress.bar-frozen::-webkit-progress-value { background: var(--info-fg); }
progress.bar-frozen::-moz-progress-bar { background: var(--info-fg); }
progress.bar-failed::-webkit-progress-value, progress.bar-banned::-webkit-progress-value { background: var(--danger); }
progress.bar-failed::-moz-progress-bar, progress.bar-banned::-moz-progress-bar { background: var(--danger); }
progress.bar-guest::-webkit-progress-value { background: var(--text-3); }
progress.bar-guest::-moz-progress-bar { background: var(--text-3); }

/* ---- pills ------------------------------------------------------------ */

.pills { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
td.pills { display: table-cell; }
td.pills .pill + .pill { margin-left: 4px; }
.pill {
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
  padding: 1px 9px; border-radius: 999px; font-size: var(--fs-xs); font-weight: 600; line-height: 1.6;
  background: var(--neutral-bg); color: var(--neutral-fg); border: 1px solid transparent;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.85; }
.pill-tier::before, .pill-deleted::before { display: none; }
.pill-ready { background: var(--ok-bg); color: var(--ok-fg); }
.pill-generating { background: var(--warn-bg); color: var(--warn-fg); }
.pill-frozen { background: var(--info-bg); color: var(--info-fg); }
.pill-failed { background: var(--bad-bg); color: var(--bad-fg); }
.pill-flag { background: var(--warn-bg); color: var(--warn-fg); }
.pill-sample { background: var(--accent-soft); color: var(--accent-soft-fg); }
.pill-guest { background: var(--neutral-bg); color: var(--neutral-fg); }
.pill-banned { background: var(--danger); color: var(--danger-fg); }
.pill-banned::before { background: #fff; }
.pill-deleted { background: transparent; color: var(--text-3); border: 1px dashed var(--border-strong); }
.pill-tier { background: transparent; color: var(--text-2); border-color: var(--border-strong); font-weight: 550; }

/* ---- forms and buttons ------------------------------------------------ */

input[type=text], input[type=search], select, textarea {
  font: inherit; font-size: var(--fs-md); color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 7px 10px; min-height: 36px; width: 100%; min-width: 0;
}
input::placeholder { color: var(--text-3); opacity: 1; }
input[type=text]:hover, input[type=search]:hover, select:hover { border-color: var(--text-3); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
select { padding-right: 28px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
  font: inherit; font-size: var(--fs-md); font-weight: 600; line-height: 1;
  min-height: 36px; padding: 0 14px; border-radius: var(--radius-sm); cursor: pointer;
  background: var(--surface); color: var(--text); border: 1px solid var(--border-strong);
  text-decoration: none;
}
.btn:hover { background: var(--surface-hover); text-decoration: none; }
.btn-primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--danger); color: var(--danger-fg); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
.btn-danger-ghost { background: transparent; color: var(--bad-fg); border-color: var(--bad-border); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--text-2); }
.btn:disabled, .btn[aria-disabled="true"] { cursor: not-allowed; background: transparent; color: var(--text-3); border-color: var(--border); opacity: 0.8; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-label { font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); }
.field-note { font-weight: 400; color: var(--text-3); }
.field-grow { flex: 1 1 280px; }
.field-amount { flex: 0 0 7.5rem; }

.toolbar {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--sp-3);
  padding: var(--sp-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.toolbar select { min-width: 11rem; }

/* ---- actions ---------------------------------------------------------- */

.actions { display: flex; flex-direction: column; gap: var(--sp-3); }
.action {
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2);
  padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-3);
}
.action-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.action-title { font-weight: 650; }
.action-hint { color: var(--text-2); font-size: var(--fs-sm); }
.action-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--sp-3); }
.action-form .field { flex: 1 1 220px; }
.action-form .field-amount { flex: 0 0 7.5rem; }
.action-disabled .action-title { color: var(--text-2); }

details.action { padding: 0; gap: 0; }
details.action > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4);
  padding: var(--sp-4); border-radius: var(--radius-sm);
}
details.action > summary::-webkit-details-marker { display: none; }
details.action > summary:hover .btn-danger-ghost { background: var(--bad-bg); }
details.action[open] > summary { border-bottom: 1px dashed var(--bad-border); border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
details.action[open] > summary .btn-danger-ghost { visibility: hidden; }
details.action > .action-form { padding: var(--sp-4); }
.action-danger { border-color: var(--bad-border); background: var(--danger-soft); }
.action-danger .action-title { color: var(--bad-fg); }

/* ---- detail pages ----------------------------------------------------- */

.page-head {
  display: flex; flex-direction: column; gap: var(--sp-4);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: var(--sp-5);
}
.page-head > .pills:empty { display: none; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: var(--sp-4) var(--sp-6); margin: 0; }
.facts-compact { margin-bottom: var(--sp-4); }
.fact { min-width: 0; }
.fact dt { font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); margin-bottom: 2px; }
.fact dd { margin: 0; overflow-wrap: break-word; }
.fact-wide { grid-column: span 2; }
.fact dd .mono { overflow-wrap: anywhere; }
.fact dd .mono { font-size: var(--fs-sm); color: var(--text-2); }
.fact-big dd { font-size: var(--fs-md); color: var(--text-2); }
.fact-big dd strong { font-size: var(--fs-xl); color: var(--text); font-variant-numeric: tabular-nums; }

.usertext {
  white-space: pre-wrap; overflow-wrap: anywhere; margin: 0;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: var(--sp-4) var(--sp-5);
}
.reading { max-width: 68ch; font-size: var(--fs-base); line-height: 1.7; }
.card > .reading { max-width: 72ch; }

.thread { padding: var(--sp-3) var(--sp-5) var(--sp-2); border-top: 1px solid var(--border); }
.thread h3 { font-size: var(--fs-base); font-weight: 650; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.thread-meta { color: var(--text-3); font-size: var(--fs-sm); margin: 4px 0 0; }

.report .card-head h2 { font-size: var(--fs-lg); }
.report-details { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--sp-4); }
.card-error { border-color: var(--bad-border); }
.error-message { font-size: var(--fs-lg); overflow-wrap: anywhere; }

/* ---- tables ----------------------------------------------------------- */

.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: clip; }
.table-wrap { overflow: visible; }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-md); }
table.data th, table.data td { text-align: left; vertical-align: middle; padding: 10px var(--sp-4); border-bottom: 1px solid var(--border); }
table.data th:first-child, table.data td:first-child { padding-left: var(--sp-5); }
table.data th:last-child, table.data td:last-child { padding-right: var(--sp-5); }
table.data thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2); color: var(--text-3);
  font-size: var(--fs-xs); font-weight: 650; text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap;
  border-bottom-color: var(--border-strong);
}
table.data tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 55%, var(--surface)); }
table.data tbody tr:hover td { background: var(--surface-hover); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data td.wrap { overflow-wrap: anywhere; min-width: 10rem; }
td.pos { color: var(--ok-fg); font-weight: 600; }
td.neg { color: var(--bad-fg); font-weight: 600; }
td.empty { text-align: center; color: var(--text-3); padding: var(--sp-10) var(--sp-4); }
.cell-main { min-width: 14rem; }
.cell-main > a { font-weight: 600; overflow-wrap: anywhere; }
.cell-main .sub { display: block; margin-top: 1px; }

code.id {
  display: inline-block; max-width: 12ch; vertical-align: bottom;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: var(--fs-sm); color: var(--text-3);
}
a code.id, a > .id { color: inherit; }
.cell-main .sub code.id { max-width: 22ch; }
code.action-code { font-size: var(--fs-sm); background: var(--neutral-bg); color: var(--text); padding: 1px 6px; border-radius: 4px; }
code.json { font-size: var(--fs-xs); color: var(--text-2); overflow-wrap: anywhere; }

.pager { display: flex; align-items: center; justify-content: flex-end; gap: var(--sp-2); }
.pager-page { color: var(--text-3); font-size: var(--fs-sm); padding: 0 var(--sp-2); font-variant-numeric: tabular-nums; }

/* ---- narrow screens --------------------------------------------------- */

@media (max-width: 1100px) {
  .grid-2, .grid-wide-left { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center;
    gap: var(--sp-2) var(--sp-4); padding: var(--sp-3) var(--sp-4); border-right: 0; border-bottom: 1px solid var(--side-border);
    overflow: visible;
  }
  .brand { padding: 0; }
  .brand-mark { width: 26px; height: 26px; }
  .sidenav { order: 3; flex: 1 0 100%; overflow-x: auto; margin: 0 calc(-1 * var(--sp-4)); padding: 0 var(--sp-4); }
  .sidenav ul { flex-direction: row; gap: 4px; }
  .sidenav a { padding: 6px 10px; white-space: nowrap; font-size: var(--fs-md); }
  .sidenav a .icon { width: 16px; height: 16px; }
  .sidenav a[aria-current="page"]::before { left: 10px; right: 10px; top: auto; bottom: -1px; width: auto; height: 2px; border-radius: 2px; }
  .sidebar-foot { margin: 0 0 0 auto; flex-direction: row; align-items: center; gap: var(--sp-3); padding: 0; border: 0; min-width: 0; }
  .who-label { display: none; }
  .who-email { max-width: 40vw; font-size: var(--fs-sm); }
  .topbar { padding: var(--sp-4); align-items: stretch; flex-direction: column; }
  .topbar-title { flex: none; }
  .search { flex: none; }
  main { padding: var(--sp-4) var(--sp-4) var(--sp-8); gap: var(--sp-4); }
  .foot { padding: 0 var(--sp-4) var(--sp-6); }
  .table-card, .table-wrap { overflow-x: auto; }
  .breakdown li { grid-template-columns: 7.5rem minmax(0, 1fr) 3.5rem; }
}

@media (max-width: 520px) {
  .fact-wide { grid-column: auto; }
  .stats { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--sp-3); }
  .stat { padding: var(--sp-3) var(--sp-4); }
  .stat-value { font-size: var(--fs-xl); }
  details.action > summary { flex-direction: column; align-items: flex-start; }
}

@media (prefers-reduced-motion: no-preference) {
  .btn, .sidenav a, a.stat, input, select { transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease; }
}

/* "Write a sample story" on the Books page. */
details.sample-new { margin-bottom: var(--sp-4); }
details.sample-new > summary { cursor: pointer; display: flex; align-items: baseline; flex-wrap: wrap; gap: var(--sp-2) var(--sp-3); }
details.sample-new > summary h2 { display: inline; font-size: var(--fs-lg); font-weight: 650; }
details.sample-new[open] > summary { margin-bottom: var(--sp-4); }
.stack-form { display: flex; flex-direction: column; gap: var(--sp-3); align-items: stretch; }
.stack-form textarea { font: inherit; width: 100%; }
.stack-form > .btn { align-self: flex-start; }
.row-fields { display: flex; flex-wrap: wrap; gap: var(--sp-3); }

/* Sign-in pages (no sidebar) and the account page. */
.auth-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--sp-4); background: var(--bg); }
.auth-card { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: var(--sp-4); padding: var(--sp-6); }
.auth-card h1 { font-size: var(--fs-xl); }
.auth-brand { display: flex; align-items: center; gap: var(--sp-2); }
.auth-title { font-weight: 650; margin-right: auto; }
.auth-lead { color: var(--text-2); }
.auth-note { color: var(--text-3); font-size: var(--fs-sm); }
.auth-form { display: flex; flex-direction: column; gap: var(--sp-3); }
.auth-btn { min-height: 44px; font-size: var(--fs-base); }
.auth-row { display: flex; flex-wrap: wrap; gap: var(--sp-3); }
.auth-link { display: block; user-select: all; overflow-wrap: anywhere; }
input[type=password] {
  font: inherit; font-size: var(--fs-md); color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 7px 10px; min-height: 36px; width: 100%; min-width: 0;
}
a.who-email { text-decoration: none; }
a.who-email:hover { text-decoration: underline; }
.signout { margin: 0; }
.btn-signout { font: inherit; font-size: var(--fs-sm); color: var(--side-text); background: transparent; border: 1px solid var(--side-border); border-radius: var(--radius-sm); padding: 4px 10px; cursor: pointer; }
.btn-signout:hover { background: var(--side-hover); color: #fff; }
