/* linkhub admin — the whole stylesheet.
 *
 * Served under a CSP with style-src 'self', so this file is the only place
 * styling may live: no <style> block, no style="" attribute. Geometry that
 * has to be computed (bar widths, tooltip offsets) is written through the
 * CSSOM from app.js, which the policy permits.
 *
 * Contents
 *   1. tokens          6. cards + stats
 *   2. base            7. charts
 *   3. layout          8. tables
 *   4. buttons         9. feedback (banners, toasts, dialogs, empty states)
 *   5. forms          10. gate (login / invite / forced change)
 */

/* ------------------------------------------------------------------ 1 */

:root {
  color-scheme: light dark;

  /* Type: a 1.2 minor third off a 15px body, which is the size a dense
     table stays readable at without shrinking the interface elsewhere. */
  --fs-2xs: 0.6875rem;
  --fs-xs:  0.75rem;
  --fs-sm:  0.8125rem;
  --fs-md:  0.9375rem;
  --fs-lg:  1.0625rem;
  --fs-xl:  1.3125rem;
  --fs-2xl: 1.625rem;
  --fs-stat: 2.0625rem;

  --lh-tight: 1.2;
  --lh-snug: 1.4;
  --lh-body: 1.6;

  /* Spacing: a 4px rhythm. Every gap and pad below is one of these. */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.5rem;
  --sp-6: 2rem;
  --sp-7: 3rem;
  --sp-8: 4rem;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;

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

  --page: 1200px;

  /* Light */
  --bg: #f3f4f7;
  --bg-tint: #eceef4;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --surface-3: #eef0f5;
  --text: #14161c;
  --text-2: #4c5665;
  --text-3: #6b7480;
  --border: #e3e6eb;
  --border-2: #cbd1da;
  --accent: #5148d9;
  --accent-2: #4038c0;
  --accent-soft: #ecebfb;
  --accent-ink: #ffffff;
  --onair: #e5484d;
  --ok: #147a51;
  --ok-soft: #e2f4ea;
  --warn: #8a5a00;
  --warn-soft: #fbf0d8;
  --danger: #bc2436;
  --danger-soft: #fdeaec;
  --grid: #ecedf2;
  --chart-fill-a: rgba(81, 72, 217, 0.22);
  --chart-fill-b: rgba(81, 72, 217, 0.01);
  --chart-bot: #b0771f;
  --shadow-1: 0 1px 2px rgba(17, 22, 35, 0.06), 0 1px 3px rgba(17, 22, 35, 0.04);
  --shadow-2: 0 6px 16px rgba(17, 22, 35, 0.10), 0 2px 4px rgba(17, 22, 35, 0.05);
  --shadow-3: 0 18px 45px rgba(17, 22, 35, 0.22);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0f14;
    --bg-tint: #12151b;
    --surface: #171a21;
    --surface-2: #1c2029;
    --surface-3: #242935;
    --text: #edf0f6;
    --text-2: #a7b0be;
    --text-3: #7b8493;
    --border: #262b35;
    --border-2: #363d4a;
    --accent: #8f88ff;
    --accent-2: #a9a3ff;
    --accent-soft: #201f38;
    --accent-ink: #12101f;
    --onair: #ff6369;
    --ok: #52cd8e;
    --ok-soft: #10281e;
    --warn: #e0a33e;
    --warn-soft: #2b2312;
    --danger: #ff7684;
    --danger-soft: #2d161a;
    --grid: #232833;
    --chart-fill-a: rgba(143, 136, 255, 0.26);
    --chart-fill-b: rgba(143, 136, 255, 0.01);
    --chart-bot: #dda653;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 6px 18px rgba(0, 0, 0, 0.45);
    --shadow-3: 0 18px 45px rgba(0, 0, 0, 0.6);
  }
}

/* ------------------------------------------------------------------ 2 */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: var(--fs-md);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, p, figure { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

::selection { background: var(--accent-soft); color: var(--text); }

[hidden] { display: none !important; }

.offscreen {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skiplink {
  position: absolute;
  left: var(--sp-4);
  top: -4rem;
  z-index: 50;
  padding: var(--sp-2) var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  transition: top 120ms ease;
}
.skiplink:focus { top: var(--sp-4); }

.mono { font-family: var(--mono); font-size: 0.92em; }
.num { font-variant-numeric: tabular-nums; }
.dim { color: var(--text-3); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.mark-bg { fill: var(--accent); }
.mark-link { stroke: var(--accent-ink); }
.mark-dot { fill: var(--onair); }

/* ------------------------------------------------------------------ 3 */

.boot {
  min-height: 70vh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: var(--sp-4);
  color: var(--text-3);
  padding: var(--sp-6);
  text-align: center;
}
.boot-mark {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid var(--border-2);
  border-top-color: var(--accent);
  animation: spin 700ms linear infinite;
}
.boot-text { max-width: 44ch; font-size: var(--fs-sm); }

@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .boot-mark { animation-duration: 3s; }
  * { scroll-behavior: auto !important; }
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: var(--page);
  margin: 0 auto;
  padding: var(--sp-3) var(--sp-5);
  display: flex;
  align-items: center;
  gap: var(--sp-5);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--text);
  font-weight: 650;
  letter-spacing: -0.01em;
  flex: none;
}
.brand:hover { text-decoration: none; }
.brand-name { font-size: var(--fs-lg); }

.nav {
  display: flex;
  gap: var(--sp-1);
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }
.nav-item {
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: 550;
  white-space: nowrap;
}
.nav-item:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }

.topbar-end {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex: none;
}
.whoami { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.whoami-name {
  font-size: var(--fs-sm);
  color: var(--text-2);
  max-width: 18ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main {
  max-width: var(--page);
  margin: 0 auto;
  padding: var(--sp-6) var(--sp-5) var(--sp-8);
}
.main:focus { outline: none; }

.banners {
  max-width: var(--page);
  margin: 0 auto;
  padding: var(--sp-4) var(--sp-5) 0;
}
.banners:empty { padding: 0; }

.footer {
  max-width: var(--page);
  margin: 0 auto;
  padding: 0 var(--sp-5) var(--sp-7);
  color: var(--text-3);
  font-size: var(--fs-xs);
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2) var(--sp-5);
  justify-content: space-between;
  border-top: 1px solid var(--border);
  padding-top: var(--sp-4);
}
.footer-dim { opacity: 0.75; }

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-3) var(--sp-5);
  margin-bottom: var(--sp-5);
}
.page-title {
  font-size: var(--fs-2xl);
  line-height: var(--lh-tight);
  letter-spacing: -0.02em;
  font-weight: 660;
}
.page-sub {
  color: var(--text-3);
  font-size: var(--fs-sm);
  margin-top: var(--sp-1);
  max-width: 68ch;
}
.page-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }

.stack { display: grid; gap: var(--sp-5); }
.stack-sm { display: grid; gap: var(--sp-3); }
.row { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }
.row-between { justify-content: space-between; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  font-size: var(--fs-sm);
  color: var(--text-3);
  margin-bottom: var(--sp-3);
}
.back-link:hover { color: var(--accent); }

/* ------------------------------------------------------------------ 4 */

.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--text);
  --btn-bd: var(--border-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 0.5rem 0.875rem;
  min-height: 2.25rem;
  border: 1px solid var(--btn-bd);
  border-radius: var(--radius-sm);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 560;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 120ms ease, border-color 120ms ease,
              color 120ms ease, transform 60ms ease;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn[disabled]:active { transform: none; }

.btn-primary {
  --btn-bg: var(--accent);
  --btn-fg: var(--accent-ink);
  --btn-bd: var(--accent);
}
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }

.btn-ghost { --btn-bg: transparent; --btn-bd: transparent; --btn-fg: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }

.btn-subtle { --btn-bg: var(--surface-2); --btn-bd: var(--border); }

.btn-danger { --btn-fg: var(--danger); --btn-bd: var(--border-2); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }

.btn-sm { padding: 0.3125rem 0.625rem; min-height: 1.875rem; font-size: var(--fs-xs); }
.btn-block { width: 100%; }

.btn-copy.is-copied {
  --btn-bg: var(--ok-soft);
  --btn-fg: var(--ok);
  --btn-bd: var(--ok);
}

.linkish {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--accent);
  cursor: pointer;
  text-align: left;
}
.linkish:hover { text-decoration: underline; }

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  scrollbar-width: none;
  max-width: 100%;
}
.segmented::-webkit-scrollbar { display: none; }
.seg-btn {
  border: 0;
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: var(--fs-xs);
  font-weight: 560;
  padding: 0.375rem 0.6875rem;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
}
.seg-btn:hover { color: var(--text); background: var(--surface-3); }
.seg-btn[aria-pressed="true"] {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-1);
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-xs);
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
}
.switch input { accent-color: var(--accent); width: 1rem; height: 1rem; margin: 0; }

/* ------------------------------------------------------------------ 5 */

.field { display: grid; gap: var(--sp-1); }
.field > label, .label {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0.01em;
}
.hint { font-size: var(--fs-xs); color: var(--text-3); line-height: var(--lh-snug); }

input[type="text"], input[type="email"], input[type="password"],
input[type="search"], input[type="number"], input[type="datetime-local"],
input[type="url"], select, textarea {
  width: 100%;
  padding: 0.5rem 0.6875rem;
  min-height: 2.25rem;
  font: inherit;
  font-size: var(--fs-sm);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
textarea { min-height: 5rem; resize: vertical; line-height: var(--lh-snug); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--danger); }

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 2rem;
}

.form-grid {
  display: grid;
  gap: var(--sp-4);
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}
.form-wide { grid-column: 1 / -1; }
.form-actions {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
  flex-wrap: wrap;
  margin-top: var(--sp-4);
}

.field-error {
  color: var(--danger);
  font-size: var(--fs-xs);
  font-weight: 550;
}

.formerror {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-3);
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid var(--danger);
  border-color: color-mix(in srgb, var(--danger) 30%, transparent);
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
}
.formok {
  padding: var(--sp-3);
  border-radius: var(--radius-sm);
  background: var(--ok-soft);
  color: var(--ok);
  border: 1px solid var(--ok);
  border-color: color-mix(in srgb, var(--ok) 30%, transparent);
  font-size: var(--fs-sm);
}

.searchbox { position: relative; flex: 1 1 15rem; min-width: 12rem; }
.searchbox input { padding-right: 2.25rem; }
.searchbox .clear {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  font: inherit;
  line-height: 1;
  padding: 0.375rem 0.5rem;
  border-radius: var(--radius-sm);
}
.searchbox .clear:hover { color: var(--text); background: var(--surface-3); }

.toolbar {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: var(--sp-4);
}
.toolbar .spacer { flex: 1 1 auto; }
.toolbar select { width: auto; min-width: 8.5rem; }

/* ------------------------------------------------------------------ 6 */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
}
.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}
.card-title {
  font-size: var(--fs-md);
  font-weight: 620;
  letter-spacing: -0.005em;
}
.card-sub {
  font-size: var(--fs-xs);
  color: var(--text-3);
  margin-top: 2px;
  max-width: 70ch;
  line-height: var(--lh-snug);
}
.card-body { padding: var(--sp-5); }
.card-body-flush { padding: 0; }
.card-foot {
  padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--border);
  font-size: var(--fs-xs);
  color: var(--text-3);
}

.grid-stats {
  display: grid;
  gap: var(--sp-4);
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
}
.grid-2 {
  display: grid;
  gap: var(--sp-5);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 21rem), 1fr));
}

.stat { padding: var(--sp-4) var(--sp-5); }
.stat-label {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0.005em;
}
.stat-value {
  font-size: var(--fs-stat);
  line-height: 1.1;
  font-weight: 640;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  margin-top: var(--sp-2);
}
.stat-note {
  font-size: var(--fs-xs);
  color: var(--text-3);
  margin-top: var(--sp-1);
  line-height: var(--lh-snug);
}
.stat-accent .stat-value { color: var(--accent); }

.info {
  border: 0;
  background: var(--surface-3);
  color: var(--text-3);
  width: 1.0625rem;
  height: 1.0625rem;
  border-radius: 50%;
  font-size: var(--fs-2xs);
  font-weight: 700;
  line-height: 1;
  cursor: help;
  padding: 0;
  flex: none;
}
.info:hover { background: var(--accent-soft); color: var(--accent); }

.kv {
  display: grid;
  grid-template-columns: minmax(7.5rem, auto) 1fr;
  gap: var(--sp-2) var(--sp-4);
  font-size: var(--fs-sm);
  align-items: baseline;
}
.kv dt { color: var(--text-3); font-size: var(--fs-xs); font-weight: 600; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  padding: 0.125rem 0.5rem;
  border-radius: var(--radius-pill);
  font-size: var(--fs-2xs);
  font-weight: 650;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  background: var(--surface-3);
  color: var(--text-2);
  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); }

.shorturl {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
}
.shorturl-text {
  font-family: var(--mono);
  font-size: var(--fs-sm);
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.copyonce {
  border: 1px solid var(--warn);
  background: var(--warn-soft);
  border-radius: var(--radius);
  padding: var(--sp-4);
  display: grid;
  gap: var(--sp-3);
}
.copyonce-title {
  font-size: var(--fs-sm);
  font-weight: 680;
  color: var(--warn);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.copyonce-note { font-size: var(--fs-xs); color: var(--text-2); line-height: var(--lh-snug); }
.copyonce-value {
  font-family: var(--mono);
  font-size: var(--fs-sm);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  padding: var(--sp-3);
  overflow-wrap: anywhere;
  user-select: all;
}

/* ------------------------------------------------------------------ 7 */

.chart-wrap { position: relative; }
.chart {
  display: block;
  width: 100%;
  height: auto;
  touch-action: pan-y;
}
.chart:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.c-grid { stroke: var(--grid); stroke-width: 1; }
.c-axis { fill: var(--text-3); font-size: 11px; font-family: var(--sans); }
.c-axis-y { text-anchor: end; }
/* stop-color is a real CSS property, so the area gradient follows the theme.
   A presentation attribute could not carry var(). */
.c-stop-a { stop-color: var(--chart-fill-a); }
.c-stop-b { stop-color: var(--chart-fill-b); }
.c-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.c-line-bot { stroke: var(--chart-bot); stroke-width: 1.5; stroke-dasharray: 3 3; fill: none; }
.c-dot { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }
.c-cursor { stroke: var(--accent); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0.7; }
.c-hit { fill: transparent; }
.c-hit:hover { fill: var(--accent); fill-opacity: 0.06; }
.c-peak { fill: var(--text-3); font-size: 10px; font-family: var(--sans); }

.chart-tip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  transform: translate(-50%, -100%);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-2);
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-xs);
  line-height: 1.35;
  white-space: nowrap;
}
.chart-tip[hidden] { display: none; }
.chart-tip-label { color: var(--text-3); }
.chart-tip-value { font-weight: 650; font-variant-numeric: tabular-nums; }

.chart-legend {
  display: flex;
  gap: var(--sp-4);
  flex-wrap: wrap;
  font-size: var(--fs-xs);
  color: var(--text-3);
  margin-top: var(--sp-3);
}
.legend-key { display: inline-flex; align-items: center; gap: var(--sp-2); }
.legend-swatch { width: 12px; height: 3px; border-radius: 2px; background: var(--accent); }
.legend-swatch-bot { background: var(--chart-bot); }

.bars { display: grid; gap: var(--sp-3); }
.bar-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 var(--sp-3);
  align-items: baseline;
  font-size: var(--fs-sm);
}
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-label-self { color: var(--text-3); font-style: italic; }
.bar-meta {
  font-size: var(--fs-xs);
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.bar-meta b { color: var(--text); font-weight: 640; }
.bar-track {
  grid-column: 1 / -1;
  height: 7px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  margin-top: var(--sp-1);
  overflow: hidden;
}
.bar-fill {
  display: block;
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--accent);
  /* width is written from app.js via the CSSOM; the CSP forbids style="". */
  width: 0;
  transition: width 260ms cubic-bezier(0.22, 0.7, 0.3, 1);
}
.bar-fill-2 {
  background: var(--accent);
  background: color-mix(in srgb, var(--accent) 62%, var(--surface-3));
}

.toplinks { display: grid; }
.toplink {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 var(--sp-4);
  padding: var(--sp-3) var(--sp-5);
  border-bottom: 1px solid var(--border);
  align-items: baseline;
}
.toplink:last-child { border-bottom: 0; }
.toplink:hover { background: var(--surface-2); }
.toplink-name { font-size: var(--fs-sm); font-weight: 560; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toplink-slug { font-family: var(--mono); font-size: var(--fs-xs); color: var(--text-3); }
.toplink-count { font-variant-numeric: tabular-nums; font-weight: 640; font-size: var(--fs-sm); }
.toplink-track { grid-column: 1 / -1; height: 5px; border-radius: var(--radius-pill); background: var(--surface-3); margin-top: 6px; overflow: hidden; }

/* ------------------------------------------------------------------ 8 */

.table-wrap { overflow-x: auto; }
table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}
.table th, .table td {
  text-align: left;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  font-size: var(--fs-2xs);
  font-weight: 680;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-3);
  white-space: nowrap;
  z-index: 1;
}
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num, .table .col-num { text-align: right; font-variant-numeric: tabular-nums; }
.table .col-actions { text-align: right; white-space: nowrap; }

.th-sort {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
  padding: 0;
  text-transform: inherit;
  letter-spacing: inherit;
}
.th-sort:hover { color: var(--text); }
.th-sort .caret { opacity: 0; font-size: 0.9em; }
th[aria-sort] .th-sort { color: var(--accent); }
th[aria-sort] .caret { opacity: 1; }

.cell-title { display: grid; gap: 2px; min-width: 12rem; max-width: 26rem; }
.cell-target {
  font-size: var(--fs-xs);
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rowactions { display: inline-flex; gap: var(--sp-1); justify-content: flex-end; }

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--border);
  font-size: var(--fs-xs);
  color: var(--text-3);
  flex-wrap: wrap;
}
.pager-btns { display: flex; gap: var(--sp-2); }

/* ------------------------------------------------------------------ 9 */

.banner {
  display: flex;
  gap: var(--sp-3);
  align-items: flex-start;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius);
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
  border: 1px solid var(--border-2);
  background: var(--surface);
  margin-bottom: var(--sp-3);
}
.banner-warn {
  background: var(--warn-soft);
  border-color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 40%, transparent);
  color: var(--warn);
}
.banner-danger {
  background: var(--danger-soft);
  border-color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 40%, transparent);
  color: var(--danger);
}
.banner-body { flex: 1; }
.banner-body b { font-weight: 680; }
.banner-note { display: block; color: var(--text-2); font-size: var(--fs-xs); margin-top: 2px; }

.note {
  font-size: var(--fs-xs);
  color: var(--text-3);
  line-height: var(--lh-snug);
  border-left: 2px solid var(--border-2);
  padding-left: var(--sp-3);
}

.empty {
  display: grid;
  justify-items: center;
  gap: var(--sp-3);
  text-align: center;
  padding: var(--sp-7) var(--sp-5);
  color: var(--text-3);
}
.empty-title { font-size: var(--fs-lg); font-weight: 620; color: var(--text); }
.empty-text { max-width: 46ch; font-size: var(--fs-sm); line-height: var(--lh-snug); }
.empty-glyph {
  width: 2.75rem; height: 2.75rem;
  border-radius: var(--radius);
  background: var(--surface-3);
  display: grid;
  place-content: center;
  color: var(--text-3);
  font-size: var(--fs-lg);
}

.skeleton {
  background: linear-gradient(90deg, var(--surface-3), var(--surface-2), var(--surface-3));
  background-size: 200% 100%;
  animation: shimmer 1.3s linear infinite;
  border-radius: var(--radius-sm);
  height: 1rem;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.skeleton-chart { height: 13rem; border-radius: var(--radius); }

.toasts {
  position: fixed;
  right: var(--sp-4);
  bottom: var(--sp-4);
  z-index: 60;
  display: grid;
  gap: var(--sp-2);
  justify-items: end;
  pointer-events: none;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-left: 3px solid var(--ok);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-2);
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-sm);
  max-width: min(24rem, calc(100vw - 2rem));
  animation: rise 180ms ease-out;
}
.toast-warn { border-left-color: var(--warn); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

.modal {
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-3);
  padding: var(--sp-5);
  max-width: min(30rem, calc(100vw - 2rem));
  width: 100%;
}
.modal::backdrop { background: rgba(10, 12, 18, 0.5); backdrop-filter: blur(2px); }
.modal-title { font-size: var(--fs-lg); font-weight: 640; margin-bottom: var(--sp-2); }
.modal-body { font-size: var(--fs-sm); color: var(--text-2); line-height: var(--lh-snug); }
.modal-body p + p { margin-top: var(--sp-2); }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  margin-top: var(--sp-5);
}

/* ----------------------------------------------------------------- 10 */

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--sp-5);
  background: var(--bg);
  background:
    radial-gradient(90rem 40rem at 50% -20rem,
                    color-mix(in srgb, var(--accent) 12%, transparent), transparent),
    var(--bg);
}
.gate-inner {
  width: 100%;
  max-width: 25rem;
  display: grid;
  gap: var(--sp-5);
}
.gate-brand { display: flex; align-items: center; gap: var(--sp-3); }
.gate-name { font-size: var(--fs-xl); font-weight: 660; letter-spacing: -0.02em; line-height: 1.1; }
.gate-sub { font-size: var(--fs-xs); color: var(--text-3); }
.gate-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  padding: var(--sp-5);
  display: grid;
  gap: var(--sp-4);
}
.gate-title { font-size: var(--fs-lg); font-weight: 640; }
.gate-lede { font-size: var(--fs-sm); color: var(--text-2); line-height: var(--lh-snug); margin-top: var(--sp-1); }

/* ----------------------------------------------------------------- 11 */

@media (max-width: 860px) {
  .topbar-inner { flex-wrap: wrap; padding: var(--sp-3) var(--sp-4); gap: var(--sp-3); }
  .nav { order: 3; flex-basis: 100%; }
  .topbar-end { margin-left: auto; }
  .main { padding: var(--sp-5) var(--sp-4) var(--sp-7); }
  .banners { padding: var(--sp-3) var(--sp-4) 0; }
  .footer { padding-left: var(--sp-4); padding-right: var(--sp-4); }
  .card-body, .card-head { padding: var(--sp-4); }
  .toplink { padding-left: var(--sp-4); padding-right: var(--sp-4); }
  .pager { padding-left: var(--sp-4); padding-right: var(--sp-4); }
  .page-title { font-size: var(--fs-xl); }
  .stat-value { font-size: 1.75rem; }
}

@media (max-width: 620px) {
  .whoami-name { display: none; }
  .kv { grid-template-columns: 1fr; gap: var(--sp-1); }
  .kv dd { margin-bottom: var(--sp-2); }
  .table th, .table td { padding: var(--sp-2) var(--sp-3); }
  .toasts { left: var(--sp-4); justify-items: stretch; }
}
