/* tcgweb — design tokens first; every component below is written against
   roles, never raw hex, so light/dark and the theme toggle swap in one place.
   Light values live on bare :root. Dark is redefined under both the OS media
   query and an explicit [data-theme] stamp, so the toggle wins either way.

   Accent is #4a4099. The neutrals are biased slightly toward it rather than
   being pure grey, so the whole surface reads as one family.

   The four chart series are a validated categorical set — all six checks in
   the data-viz method pass in both modes (lightness band, chroma floor, CVD
   separation, normal-vision floor, contrast). Do not substitute a hue here
   without re-running the validator; the ordering is the CVD-safety mechanism,
   not a cosmetic choice.

   No webfont is loaded. The CSP is default-src 'self', and a private ledger
   should not phone a font CDN on every page view — so the stacks below resolve
   to SF Pro / SF Mono on the Mac this is read from, Segoe on Windows. */

:root {
  color-scheme: light;

  /* surfaces */
  --plane:        #f5f5f9;
  --surface:      #ffffff;
  --surface-2:    #fbfbfd;
  --sunk:         #f0f0f6;
  --raised:       #ffffff;

  /* ink */
  --ink:          #14131c;
  --ink-2:        #4b4a5c;
  --muted:        #86849a;
  --faint:        #a9a7ba;

  /* lines */
  --line:         rgba(20, 19, 28, 0.09);
  --line-2:       rgba(20, 19, 28, 0.16);

  /* accent */
  --accent:       #4a4099;
  --accent-2:     #6155b8;
  --accent-ink:   #403889;
  --accent-soft:  #edecf8;
  --accent-line:  rgba(74, 64, 153, 0.22);
  --on-accent:    #ffffff;

  /* chart series — validated set, light mode */
  --series-1:     #4a4099;
  --series-2:     #00917f;
  --series-3:     #c2691f;
  --series-4:     #b23a6b;

  /* chart chrome */
  --grid:         rgba(20, 19, 28, 0.07);
  --axis:         rgba(20, 19, 28, 0.16);

  /* status — reserved, never reused as a series */
  --good:         #0f8a46;
  --good-soft:    #e7f5ed;
  --warning:      #a86a08;
  --warning-soft: #fbf2e3;
  --critical:     #c0332f;
  --critical-soft:#fceceb;

  /* form */
  --r-lg: 16px;
  --r:    12px;
  --r-sm: 8px;
  --r-pill: 999px;
  --shadow-1: 0 1px 2px rgba(20, 19, 28, 0.05);
  --shadow-2: 0 2px 4px rgba(20, 19, 28, 0.04), 0 12px 32px rgba(20, 19, 28, 0.07);

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

  --rail: 232px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane:        #0a0910;
    --surface:      #14131b;
    --surface-2:    #17161f;
    --sunk:         #1c1b25;
    --raised:       #1b1a24;

    --ink:          #f2f1f7;
    --ink-2:        #b4b1c6;
    --muted:        #817f96;
    --faint:        #605e72;

    --line:         rgba(255, 255, 255, 0.08);
    --line-2:       rgba(255, 255, 255, 0.15);

    --accent:       #7d6fd8;
    --accent-2:     #9284e6;
    --accent-ink:   #a99ded;
    --accent-soft:  #1d1a2e;
    --accent-line:  rgba(125, 111, 216, 0.30);
    --on-accent:    #ffffff;

    --series-1:     #7d6fd8;
    --series-2:     #1fa997;
    --series-3:     #c47a22;
    --series-4:     #d95c95;

    --grid:         rgba(255, 255, 255, 0.06);
    --axis:         rgba(255, 255, 255, 0.14);

    --good:         #3cb371;
    --good-soft:    #10241a;
    --warning:      #d99a2b;
    --warning-soft: #241c0e;
    --critical:     #e5645f;
    --critical-soft:#2a1413;

    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-2: 0 2px 4px rgba(0, 0, 0, 0.4), 0 12px 32px rgba(0, 0, 0, 0.45);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:        #0a0910;
  --surface:      #14131b;
  --surface-2:    #17161f;
  --sunk:         #1c1b25;
  --raised:       #1b1a24;
  --ink:          #f2f1f7;
  --ink-2:        #b4b1c6;
  --muted:        #817f96;
  --faint:        #605e72;
  --line:         rgba(255, 255, 255, 0.08);
  --line-2:       rgba(255, 255, 255, 0.15);
  --accent:       #7d6fd8;
  --accent-2:     #9284e6;
  --accent-ink:   #a99ded;
  --accent-soft:  #1d1a2e;
  --accent-line:  rgba(125, 111, 216, 0.30);
  --on-accent:    #ffffff;
  --series-1:     #7d6fd8;
  --series-2:     #1fa997;
  --series-3:     #c47a22;
  --series-4:     #d95c95;
  --grid:         rgba(255, 255, 255, 0.06);
  --axis:         rgba(255, 255, 255, 0.14);
  --good:         #3cb371;
  --good-soft:    #10241a;
  --warning:      #d99a2b;
  --warning-soft: #241c0e;
  --critical:     #e5645f;
  --critical-soft:#2a1413;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-2: 0 2px 4px rgba(0, 0, 0, 0.4), 0 12px 32px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font: 400 14px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

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

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ======================================================= shell + left rail */

.shell { display: grid; grid-template-columns: var(--rail) 1fr; min-height: 100vh; }

.rail {
  position: sticky; top: 0; align-self: start;
  height: 100vh; display: flex; flex-direction: column;
  padding: 20px 14px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.mark {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 8px 22px;
}
.mark .glyph {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  background: linear-gradient(140deg, var(--accent) 0%, var(--accent-2) 100%);
  display: grid; place-items: center;
  color: #fff; font: 600 13px/1 var(--mono); letter-spacing: -0.03em;
}
.mark .wordmark { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.mark .wordmark b { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }
.mark .wordmark span {
  font: 400 11px/1.3 var(--mono); color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.rail nav { display: flex; flex-direction: column; gap: 2px; }
.rail nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 10px; border-radius: var(--r-sm);
  color: var(--ink-2); font-weight: 500; font-size: 13.5px;
  transition: background .12s, color .12s;
}
.rail nav a svg { width: 17px; height: 17px; flex: none; opacity: .78; }
.rail nav a:hover { background: var(--sunk); color: var(--ink); }
.rail nav a[aria-current="page"] {
  background: var(--accent-soft); color: var(--accent-ink); font-weight: 600;
}
.rail nav a[aria-current="page"] svg { opacity: 1; }

.rail .spacer { flex: 1; min-height: 20px; }

.rail-foot {
  display: flex; gap: 6px; padding-top: 14px; border-top: 1px solid var(--line);
}
.rail-foot form { margin: 0; flex: 1; }

/* ====================================================================== top */

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 14px;
  height: 60px; padding: 0 28px;
  background: color-mix(in srgb, var(--plane) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.crumb { font-size: 13px; color: var(--muted); display: flex; gap: 7px; align-items: center; }
.crumb b { color: var(--ink); font-weight: 550; }
.topbar .spacer { flex: 1; }
.stamp { font: 400 11.5px/1 var(--mono); color: var(--faint); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 32px; padding: 0 12px;
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink-2);
  font: 500 12.5px/1 var(--sans); cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.btn:hover { background: var(--sunk); color: var(--ink); border-color: var(--line-2); }
.btn.icon { width: 32px; padding: 0; }
.btn svg { width: 15px; height: 15px; }

/* ==================================================================== page */

main { padding: 26px 28px 80px; }
.page { max-width: 1400px; margin: 0 auto; }

.eyebrow {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 11px 5px 9px; margin-bottom: 16px;
  border: 1px solid var(--line-2); border-radius: var(--r-pill);
  font: 600 10.5px/1 var(--sans); letter-spacing: .13em; text-transform: uppercase;
  color: var(--ink-2); background: var(--surface);
}
.eyebrow::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); flex: none;
}

.page-head { margin-bottom: 24px; }
.page-head h1 {
  margin: 0; font-size: 34px; line-height: 1.08; font-weight: 600;
  letter-spacing: -0.028em; text-wrap: balance;
}
.page-head p { margin: 9px 0 0; color: var(--muted); font-size: 14.5px; max-width: 68ch; }

/* ================================================================= filters */

.filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }

.seg {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--sunk); border: 1px solid var(--line);
  border-radius: var(--r-pill);
}
.seg a {
  padding: 6px 13px; border-radius: var(--r-pill);
  font-size: 12.5px; font-weight: 500; color: var(--muted);
  max-width: 24ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  transition: background .12s, color .12s;
}
.seg a:hover { color: var(--ink); }
.seg a.on {
  background: var(--surface); color: var(--ink); font-weight: 600;
  box-shadow: var(--shadow-1);
}
.seg a .n { font-family: var(--mono); font-size: 11px; color: var(--faint); margin-left: 5px; }

/* pill filters with a colour key, per the series slots */
.pills { display: flex; gap: 7px; flex-wrap: wrap; }
.pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 13px; border-radius: var(--r-pill);
  border: 1px solid var(--line-2); background: var(--surface);
  font-size: 12.5px; color: var(--ink-2);
}
.pill i { width: 7px; height: 7px; border-radius: 50%; flex: none; }

input[type="search"], input[type="password"], select {
  font: inherit; font-size: 13px; height: 34px; padding: 0 12px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
}
input[type="search"] { min-width: 220px; }
input::placeholder { color: var(--faint); }

/* =================================================================== cards */

.grid { display: grid; gap: 14px; }
.grid.tiles  { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid.halves { grid-template-columns: repeat(auto-fit, minmax(430px, 1fr)); align-items: start; }
.grid.thirds { grid-template-columns: repeat(auto-fit, minmax(310px, 1fr)); align-items: start; }
.grid + .grid, .grid + .card, .card + .card, .card + .grid { margin-top: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 18px 20px;
}
.card > h2 {
  margin: 0; font-size: 14.5px; font-weight: 600; letter-spacing: -0.012em;
}
.card > .sub { margin: 5px 0 16px; color: var(--muted); font-size: 12.5px; max-width: 70ch; }
.card.flush { padding: 18px 0 0; }
.card.flush > h2, .card.flush > .sub { padding: 0 20px; }

/* ==================================================================== hero */

.hero {
  position: relative; overflow: hidden;
  border-radius: var(--r-lg);
  padding: 30px 32px;
  color: #fff;
  background:
    radial-gradient(120% 150% at 92% 8%, rgba(255,255,255,.24) 0%, rgba(255,255,255,0) 55%),
    linear-gradient(108deg, #3d3480 0%, var(--accent) 34%, #5a63bd 64%, #3f8fa8 100%);
  display: grid; gap: 26px;
  grid-template-columns: minmax(260px, 1.15fr) minmax(0, 2fr);
  align-items: end;
}
.hero-figure .label {
  font: 600 10.5px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase;
  color: rgba(255,255,255,.72);
}
.hero-figure .value {
  margin-top: 12px;
  font: 600 clamp(40px, 5.2vw, 58px)/1 var(--sans);
  letter-spacing: -0.035em;
}
.hero-figure .note {
  margin: 12px 0 0; font-size: 13px; line-height: 1.5;
  color: rgba(255,255,255,.82); max-width: 44ch;
}
.hero-figure .note strong { color: #fff; font-weight: 600; }

.hero-tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.glass {
  background: rgba(255,255,255,.13);
  border: 1px solid rgba(255,255,255,.18);
  border-radius: var(--r);
  padding: 15px 16px;
}
.glass .label {
  font: 600 10px/1 var(--sans); letter-spacing: .12em; text-transform: uppercase;
  color: rgba(255,255,255,.74);
}
.glass .value {
  margin-top: 8px; font-size: 26px; font-weight: 600; letter-spacing: -0.025em;
}
.glass .foot { margin-top: 5px; font-size: 11.5px; color: rgba(255,255,255,.7); }
.hero .spark { grid-column: 1 / -1; }

/* ============================================================== stat tiles */

.tile { position: relative; overflow: hidden; }
.tile .head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.tile .label {
  font: 600 10.5px/1.3 var(--sans); letter-spacing: .11em; text-transform: uppercase;
  color: var(--muted);
}
.tile .chip {
  width: 26px; height: 26px; border-radius: 7px; flex: none;
  display: grid; place-items: center;
  background: var(--sunk); color: var(--muted);
}
.tile .chip svg { width: 13px; height: 13px; }
.tile .value {
  margin-top: 12px;
  font: 600 27px/1.05 var(--sans); letter-spacing: -0.028em;
}
.tile .foot { margin-top: 7px; font-size: 12px; color: var(--muted); }

.up   { color: var(--good); }
.down { color: var(--critical); }

/* =================================================================== chips */

.chip-tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: var(--r-pill);
  font: 500 11px/1.55 var(--sans);
  border: 1px solid var(--line-2); color: var(--ink-2); background: var(--surface);
  white-space: nowrap;
}
.chip-tag.good { color: var(--good);     background: var(--good-soft);     border-color: transparent; }
.chip-tag.warn { color: var(--warning);  background: var(--warning-soft);  border-color: transparent; }
.chip-tag.bad  { color: var(--critical); background: var(--critical-soft); border-color: transparent; }
.chip-tag::before {
  content: ""; width: 5px; height: 5px; border-radius: 50%;
  background: currentColor; flex: none;
}
.chip-tag.plain::before { display: none; }

/* ================================================================== tables */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; white-space: nowrap;
  font: 600 10.5px/1 var(--sans); letter-spacing: .09em; text-transform: uppercase;
  color: var(--muted);
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
thead th a { color: inherit; }
thead th a.on { color: var(--accent-ink); }
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: var(--sunk); }
tfoot td {
  padding: 13px 14px; border-top: 1px solid var(--line-2);
  font-weight: 600; background: var(--surface-2);
}
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-family: var(--mono); font-size: 12px; }
.name { font-weight: 550; }
.name .set { display: block; color: var(--muted); font-weight: 400; font-size: 11.5px; margin-top: 2px; }
.dim { color: var(--muted); }

.empty { padding: 44px 20px; text-align: center; color: var(--muted); font-size: 13px; }
.empty strong { display: block; color: var(--ink); font-weight: 600; font-size: 14.5px; margin-bottom: 6px; }
.empty code { font-family: var(--mono); font-size: 12px; background: var(--sunk); padding: 2px 6px; border-radius: 5px; }

/* ================================================================== charts */

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axisline { stroke: var(--axis); stroke-width: 1; }
.chart text { fill: var(--muted); font: 11px var(--sans); font-variant-numeric: tabular-nums; }
.chart text.value { fill: var(--ink); font-weight: 600; }

.legend { display: flex; gap: 16px; flex-wrap: wrap; margin: 0 0 14px; font-size: 12.5px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }

.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--raised); color: var(--ink);
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  box-shadow: var(--shadow-2);
  padding: 9px 11px; font-size: 12px; min-width: 132px;
  transform: translate(-50%, -118%); opacity: 0; transition: opacity .09s;
}
.tooltip.on { opacity: 1; }
.tooltip .t { color: var(--muted); margin-bottom: 5px; font-size: 11px; }
.tooltip .r { display: flex; justify-content: space-between; gap: 16px; }
.tooltip .r + .r { margin-top: 3px; }
.tooltip .r b { font-variant-numeric: tabular-nums; font-weight: 600; }

details.tableview { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
details.tableview summary {
  cursor: pointer; color: var(--muted); font-size: 12px; list-style: none;
  display: inline-flex; align-items: center; gap: 6px;
}
details.tableview summary::-webkit-details-marker { display: none; }
details.tableview summary::before { content: "▸"; font-size: 9px; }
details.tableview[open] summary::before { content: "▾"; }
details.tableview summary:hover { color: var(--ink); }

/* horizontal bars */
.bars { display: grid; gap: 11px; }
.bars .row { display: grid; grid-template-columns: minmax(100px, 32%) 1fr auto; gap: 14px; align-items: center; }
.bars .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.bars .track {
  display: block; height: 10px; border-radius: 4px; overflow: hidden;
  background: var(--sunk);
}
.bars .fill {
  display: block; height: 100%; min-width: 3px;
  border-radius: 0 4px 4px 0;              /* rounded data-end, square baseline */
  background: var(--series-1);
}
.bars .val { font-variant-numeric: tabular-nums; font-size: 12.5px; color: var(--ink-2); }

/* =================================================================== login */

.login-wrap {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(60% 55% at 50% 0%, var(--accent-soft) 0%, transparent 70%),
    var(--plane);
}
.login-card {
  width: 100%; max-width: 370px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 30px;
  box-shadow: var(--shadow-2);
}
.login-card .mark { padding: 0 0 20px; }
.login-card h1 { margin: 0 0 4px; font-size: 20px; font-weight: 600; letter-spacing: -0.02em; }
.login-card p.sub { margin: 0 0 22px; color: var(--muted); font-size: 13px; }
.login-card label {
  display: block; font: 600 10.5px/1 var(--sans); letter-spacing: .1em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 8px;
}
.login-card input { width: 100%; height: 40px; }
.login-card button {
  width: 100%; height: 40px; margin-top: 16px;
  background: var(--accent); color: var(--on-accent);
  border: 0; border-radius: var(--r-sm);
  font: 600 13.5px/1 var(--sans); cursor: pointer;
  transition: filter .12s;
}
.login-card button:hover { filter: brightness(1.1); }
.alert {
  margin-top: 16px; padding: 10px 12px; border-radius: var(--r-sm);
  font-size: 12.5px; background: var(--critical-soft); color: var(--critical);
}
.alert.info { background: var(--sunk); color: var(--ink-2); }
.alert code { font-family: var(--mono); font-size: 11.5px; }

footer.foot {
  margin-top: 40px; padding-top: 18px; border-top: 1px solid var(--line);
  color: var(--faint); font-size: 12px;
  display: flex; gap: 16px; flex-wrap: wrap; justify-content: space-between;
}

/* ============================================================== responsive */

@media (max-width: 1000px) {
  .shell { grid-template-columns: 1fr; }
  .rail {
    position: static; height: auto; flex-direction: row; align-items: center;
    gap: 12px; padding: 10px 16px; overflow-x: auto;
    border-right: 0; border-bottom: 1px solid var(--line);
  }
  .rail .mark { padding: 0; }
  .rail .mark .wordmark { display: none; }
  .rail nav { flex-direction: row; gap: 4px; }
  .rail nav a span { display: none; }
  .rail nav a { padding: 9px; }
  .rail .spacer { display: none; }
  .rail-foot { padding-top: 0; border-top: 0; margin-left: auto; }
  .topbar { padding: 0 16px; }
  main { padding: 20px 16px 56px; }
  .hero { grid-template-columns: 1fr; padding: 24px; }
  .page-head h1 { font-size: 27px; }
  .grid.halves, .grid.thirds { grid-template-columns: 1fr; }
}

@media print {
  .rail, .topbar, .filters, .btn { display: none; }
  .shell { grid-template-columns: 1fr; }
  .card { break-inside: avoid; border-color: #999; }
  .hero { color: #000; background: none; border: 1px solid #999; }
}
