/* ---------------------------------------------------------------------------
   Design tokens.

   Colours come from the dataviz reference palette, unchanged, and the dark
   column is the same hues re-stepped for the dark surface - not an automatic
   inversion. The categorical slots in use are validated as a set:

     light  #2a78d6 #eb6834 #1baf7a   all-pairs PASS (surface #fcfcfb)
     dark   #3987e5 #d95926 #199e70   all-pairs PASS (surface #1a1a19)

   Light-mode aqua sits at 2.74:1 against the surface, below the 3:1 line, so
   wherever it carries meaning the value is also written out or present in a
   table - the relief rule, not an oversight.

   Dark values are declared twice on purpose: once under prefers-color-scheme
   for the OS setting, once under .theme-dark for the in-page toggle, so the
   toggle wins in both directions.
--------------------------------------------------------------------------- */

.app-root {
  color-scheme: light;

  --plane:          #f9f9f7;
  --surface:        #fcfcfb;
  --surface-sunk:   #f3f2ee;
  --ink:            #0b0b0b;
  --ink-2:          #52514e;
  --muted:          #898781;
  --grid:           #e1e0d9;
  --axis:           #c3c2b7;
  --border:         rgba(11, 11, 11, 0.10);

  --series-1:       #2a78d6;   /* equity, P&L        */
  --series-2:       #eb6834;   /* fees               */
  --series-3:       #1baf7a;   /* cash / invested    */
  --ramp-1-light:   #cde2fb;   /* meter track        */

  --good:           #0ca30c;
  --warning:        #fab219;
  --serious:        #ec835a;
  --critical:       #d03b3b;
  --up-text:        #006300;   /* success as TEXT needs the darker step */
  --down-text:      #b32020;

  --radius: 10px;
  --gutter: 16px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .app-root:not(.theme-light) {
    color-scheme: dark;
    --plane:        #0d0d0d;
    --surface:      #1a1a19;
    --surface-sunk: #121211;
    --ink:          #ffffff;
    --ink-2:        #c3c2b7;
    --muted:        #898781;
    --grid:         #2c2c2a;
    --axis:         #383835;
    --border:       rgba(255, 255, 255, 0.10);
    --series-1:     #3987e5;
    --series-2:     #d95926;
    --series-3:     #199e70;
    --ramp-1-light: #184f95;
    --up-text:      #0ca30c;
    --down-text:    #e66767;
  }
}

.app-root.theme-dark {
  color-scheme: dark;
  --plane:        #0d0d0d;
  --surface:      #1a1a19;
  --surface-sunk: #121211;
  --ink:          #ffffff;
  --ink-2:        #c3c2b7;
  --muted:        #898781;
  --grid:         #2c2c2a;
  --axis:         #383835;
  --border:       rgba(255, 255, 255, 0.10);
  --series-1:     #3987e5;
  --series-2:     #d95926;
  --series-3:     #199e70;
  --ramp-1-light: #184f95;
  --up-text:      #0ca30c;
  --down-text:    #e66767;
}

/* --- base ---------------------------------------------------------------- */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #f9f9f7;
}

@media (prefers-color-scheme: dark) {
  html, body { background: #0d0d0d; }
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

.app-root {
  min-height: 100vh;
  background: var(--plane);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  overflow-x: hidden;
}

.wrap {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding-left: var(--gutter);
  padding-right: var(--gutter);
}

h1 { font-size: 1.5rem; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0 0 12px; letter-spacing: -0.005em; }
h3 { font-size: 0.92rem; margin: 0 0 8px; color: var(--ink-2); }

a { color: var(--series-1); text-decoration: none; }
a:hover { text-decoration: underline; }

p { margin: 0 0 10px; }

.muted { color: var(--muted); }
.ink-2 { color: var(--ink-2); }
.small { font-size: 0.82rem; }
.mono {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}
.num { font-variant-numeric: tabular-nums; }
.up   { color: var(--up-text); }
.down { color: var(--down-text); }
.nowrap { white-space: nowrap; }

/* --- chrome -------------------------------------------------------------- */

.site-head {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 5;
}

.head-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  flex-wrap: wrap;
  padding-top: 8px;
  padding-bottom: 8px;
}

.brand { display: flex; align-items: center; gap: 9px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 10px; height: 10px; border-radius: 3px;
  background: var(--series-1);
  display: inline-block;
}
.brand-text { font-weight: 600; letter-spacing: -0.01em; }

.head-right { display: flex; align-items: center; gap: 12px; }
.head-note { color: var(--muted); font-size: 0.8rem; }

.theme-btn {
  font: inherit;
  font-size: 0.8rem;
  color: var(--ink-2);
  background: var(--surface-sunk);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 11px;
  cursor: pointer;
  min-height: 28px;
}
.theme-btn:hover { color: var(--ink); }

main.wrap { padding-top: 20px; padding-bottom: 32px; }

.site-foot {
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.8rem;
  padding: 16px 0 28px;
}
.site-foot p { max-width: 62ch; margin: 0; }

/* --- cards --------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.card > :last-child { margin-bottom: 0; }

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.card-head h2 { margin: 0; }

/* --- badges -------------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.74rem;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-sunk);
  color: var(--ink-2);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.badge-ok      .dot { background: var(--good); }
.badge-stale   .dot { background: var(--warning); }
.badge-error   .dot { background: var(--critical); }
.badge-unknown .dot { background: var(--muted); }
.badge-error { color: var(--down-text); }

.pill {
  display: inline-block;
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--surface-sunk);
  border: 1px solid var(--border);
  color: var(--ink-2);
  margin: 0 4px 4px 0;
  white-space: nowrap;
}
.pill-mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }

/* --- notices ------------------------------------------------------------- */

.notice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border: 1px solid var(--border);
  border-left: 3px solid var(--muted);
  background: var(--surface);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
}
.notice-warning  { border-left-color: var(--warning); }
.notice-critical { border-left-color: var(--critical); }
.notice-icon { flex: none; font-weight: 700; line-height: 1.35; }
.notice-warning  .notice-icon { color: var(--warning); }
.notice-critical .notice-icon { color: var(--critical); }
.notice-body { min-width: 0; }
.notice-body strong { display: block; margin-bottom: 2px; }
.notice-body p { margin: 0; color: var(--ink-2); font-size: 0.88rem; }

/* --- stat tiles ---------------------------------------------------------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.tile { background: var(--surface); padding: 12px 14px; }
.tile .label {
  font-size: 0.76rem;
  color: var(--muted);
  display: block;
  margin-bottom: 3px;
}
.tile .value { font-size: 1.22rem; font-weight: 600; letter-spacing: -0.01em; }
.tile .sub { font-size: 0.76rem; color: var(--muted); display: block; margin-top: 2px; }

.hero {
  font-size: 3rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.05;
  display: block;
}

/* --- tables -------------------------------------------------------------- */

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
table.data th {
  text-align: left;
  font-size: 0.74rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 0 10px 8px 0;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
}
table.data td {
  padding: 10px 10px 10px 0;
  border-bottom: 1px solid var(--grid);
  vertical-align: middle;
}
table.data tr:last-child td { border-bottom: 0; }
table.data .r { text-align: right; padding-right: 14px; }
table.data th.r { text-align: right; padding-right: 14px; }
table.data th:last-child, table.data td:last-child { padding-right: 0; }

.rank {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 0.95rem;
  width: 1.6rem;
}

.theory-name { font-weight: 600; color: var(--ink); display: block; }
.theory-name:hover { text-decoration: underline; }
.theory-sub { color: var(--muted); font-size: 0.78rem; }

/* --- meter (fees against P&L) ------------------------------------------- */

.meter {
  display: block;
  width: 100%;
  max-width: 130px;
  height: 6px;
  border-radius: 3px;
  background: var(--ramp-1-light);
  overflow: hidden;
  margin-top: 4px;
}
.meter > span {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: var(--series-1);
}
.meter.over > span { background: var(--warning); }

/* --- charts -------------------------------------------------------------- */

.chart { width: 100%; height: auto; display: block; touch-action: pan-y; }
.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .axis-line { stroke: var(--axis); stroke-width: 1; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .ref-line  { stroke: var(--axis); stroke-width: 1; stroke-dasharray: none; }
.chart .series-line {
  fill: none;
  stroke: var(--series-1);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.chart .series-area { fill: var(--series-1); opacity: 0.10; }
.chart .end-dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart .val-label { fill: var(--ink-2); font-size: 11px; }
.chart .row-label { fill: var(--ink-2); font-size: 11px; }
/* The fee comparison is only two bars: let it scale down on a phone, but
   stop it stretching its type across a desktop card. */
.fee-chart { max-width: 560px; }
.fee-chart text { font-size: 12px; }
.chart .bar-1 { fill: var(--series-1); }

/* Hover layer: pure CSS, no JS interop. Each band owns a crosshair, a dot
   and a tooltip that appear together on hover or keyboard focus. */
.chart .band rect.hit { fill: transparent; }
.chart .band .band-art { opacity: 0; pointer-events: none; }
.chart .band:hover .band-art,
.chart .band:focus .band-art,
.chart .band:focus-visible .band-art { opacity: 1; }
.chart .band { outline: none; }
.chart .cross { stroke: var(--axis); stroke-width: 1; }
.chart .hover-dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart .tip-box {
  fill: var(--surface);
  stroke: var(--axis);
  stroke-width: 1;
  rx: 5;
}
.chart .tip-text { fill: var(--ink); font-size: 11px; }
.chart .tip-text.dim { fill: var(--muted); }

.spark { display: block; width: 84px; height: 26px; }
.spark .spark-line {
  fill: none;
  stroke: var(--series-1);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.spark .spark-dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.spark .spark-base { stroke: var(--grid); stroke-width: 1; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; margin: 0 0 10px; padding: 0; list-style: none; }
.legend li { display: flex; align-items: center; gap: 6px; font-size: 0.78rem; color: var(--ink-2); }
.legend .key { width: 12px; height: 3px; border-radius: 2px; flex: none; }

details.table-view { margin-top: 12px; }
details.table-view > summary {
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--ink-2);
  padding: 4px 0;
}
details.table-view .scroll { max-height: 320px; overflow: auto; margin-top: 8px; }

/* --- pass detail --------------------------------------------------------- */

.prose { max-width: 72ch; white-space: pre-wrap; color: var(--ink); }
.prose.secondary { color: var(--ink-2); }

.console {
  background: var(--surface-sunk);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  white-space: pre;
  margin: 0;
  color: var(--ink);
  max-height: 70vh;
}

.action-row {
  border: 1px solid var(--border);
  border-left: 3px solid var(--series-1);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
  background: var(--surface);
}
.action-row.sell { border-left-color: var(--series-2); }
.action-row.rejected { border-left-color: var(--muted); }
.action-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.action-kind {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: var(--ink-2);
}
.evidence {
  margin: 8px 0 0;
  background: var(--surface-sunk);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--ink-2);
  overflow-x: auto;
}

.src { padding: 8px 0; border-bottom: 1px solid var(--grid); }
.src:last-child { border-bottom: 0; }
.src .head { font-weight: 600; }

.passlist a { display: block; }

.crumb { font-size: 0.82rem; color: var(--muted); margin-bottom: 10px; }
.crumb a { color: var(--ink-2); }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* --- narrow -------------------------------------------------------------- */

.only-wide { display: block; }
.only-narrow { display: none; }

@media (max-width: 720px) {
  .only-wide { display: none; }
  .only-narrow { display: block; }

  .grid-2 { grid-template-columns: 1fr; }
  .head-note { display: none; }
  .hero { font-size: 2.4rem; }

  /* The leaderboard keeps its table semantics and restacks into one card per
     theory, so a phone never gets a sideways scrollbar. */
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack thead { display: none; }
  table.stack tr {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 10px;
  }
  table.stack td {
    border: 0;
    padding: 3px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    text-align: left;
  }
  table.stack td.r { text-align: right; }
  table.stack td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex: none;
  }
  table.stack td.full { display: block; }
  table.stack td.full::before { content: none; }

  /* Nothing in a stacked cell may refuse to wrap, or the row sets a minimum
     width for the whole page and the layout scrolls sideways. */
  table.stack td { flex-wrap: wrap; }
  table.stack td > * { min-width: 0; }
  .meter { max-width: 100%; }
  .fee-cell .meter { margin-left: 0; width: 100%; }
  .fee-cell .theory-sub { white-space: normal; }
}

/* --- framework error strip ------------------------------------------------ */

#blazor-error-ui {
  background: #fab219;
  color: #0b0b0b;
  bottom: 0;
  box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
  display: none;
  left: 0;
  padding: 10px 16px 10px 20px;
  position: fixed;
  width: 100%;
  z-index: 1000;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 0.88rem;
}

#blazor-error-ui .dismiss {
  cursor: pointer;
  position: absolute;
  right: 12px;
  top: 8px;
}

/* --- universe badge ------------------------------------------------------- */

.universe { display: inline-flex; flex-wrap: wrap; gap: 0; align-items: center; }
.pill-odd {
  color: var(--ink);
  border-color: var(--warning);
  background: var(--surface);
  font-weight: 600;
}
.pill-odd span { color: var(--warning); }

/* --- pass body ----------------------------------------------------------- */

.pass-meta { display: flex; flex-wrap: wrap; gap: 0; margin-bottom: 12px; }
ul.plain { list-style: none; margin: 0 0 10px; padding: 0; }
ul.plain li { padding: 5px 0; border-bottom: 1px solid var(--grid); }
ul.plain li:last-child { border-bottom: 0; }
details summary { cursor: pointer; }

/* --- pass log ------------------------------------------------------------ */

.pass-item { border-bottom: 1px solid var(--grid); }
.pass-item:last-child { border-bottom: 0; }
.pass-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 4px 0;
}
.pass-flags { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.disclose {
  font: inherit;
  font-size: 0.88rem;
  background: none;
  border: 0;
  color: var(--ink);
  cursor: pointer;
  padding: 6px 0;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
}
.disclose:hover { color: var(--series-1); }
.disclose .chev {
  width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1;
  flex: none;
}

.pass-item-body {
  padding: 8px 0 18px;
  border-top: 1px solid var(--grid);
  margin-top: 4px;
}

.more {
  font: inherit;
  font-size: 0.85rem;
  margin-top: 12px;
  background: var(--surface-sunk);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--ink-2);
  padding: 8px 14px;
  cursor: pointer;
  min-height: 36px;
}
.more:hover { color: var(--ink); }

.pill-held { border-color: var(--series-1); color: var(--ink); font-weight: 600; }

/* --- leaderboard fee cell ------------------------------------------------ */

.fee-cell .meter { margin-left: auto; margin-bottom: 3px; max-width: 110px; }
.fee-cell .theory-sub { white-space: nowrap; }

/* Blazor focuses the <h1> on navigation; that focus ring is for keyboard
   users, not for everyone arriving on the page. */
h1:focus, h1:focus-visible { outline: none; }

/* --- a row whose last publish failed -------------------------------------- */

/* The numbers stay on the board at their last known value, so the row is
   marked as well as badged - never colour alone: the row also says
   "last known" in words beside the figure. */
table.data tr.row-error td:first-child { box-shadow: inset 2px 0 0 var(--critical); }
@media (max-width: 720px) {
  table.stack tr.row-error { border-left: 3px solid var(--critical); }
  table.stack tr.row-error td:first-child { box-shadow: none; }
}
