/* Layout and components. Every value here comes from theme.css — if you find
   yourself typing a hex code or a font size in this file, add a token instead.
   That rule is the whole reason a redesign is cheap. */

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

body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font: var(--fs-md)/1.5 var(--sans);
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: var(--fs-lg); }
h2 { font-size: var(--fs-md); }

a { color: var(--focus); }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.mono { font-family: var(--mono); }
.muted { color: var(--ink-muted); }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; text-align: right; }

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

.shell {
  max-width: 1500px;
  margin: 0 auto;
  padding: var(--gap);
  display: flex;
  flex-direction: column;
  gap: var(--gap-lg);
}

.topbar {
  display: flex;
  align-items: center;
  gap: var(--gap);
  flex-wrap: wrap;
  padding: var(--gap) 0 0;
}
.topbar .spacer { flex: 1; }
.topbar .stamp { font-size: var(--fs-xs); color: var(--ink-muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card > header {
  display: flex;
  align-items: baseline;
  gap: var(--gap);
  flex-wrap: wrap;
  padding: var(--pad);
  border-bottom: 1px solid var(--rule);
}
.card > header .spacer { flex: 1; }
.card > .body { padding: var(--pad); }

/* --- controls ------------------------------------------------------------- */

button, select, input, .chip {
  font: inherit;
  color: inherit;
  border-radius: var(--radius-sm);
  border: 1px solid var(--edge);
  background: var(--surface-sunk);
  min-height: var(--control-h);
  padding: 0 0.5rem;
}
button, .chip { cursor: pointer; }
button:hover, .chip:hover { border-color: var(--ink-muted); }
button[aria-pressed="true"] { background: var(--bar-strong); color: #fff; border-color: transparent; }
button.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
button.ghost:hover { background: var(--surface-sunk); }

/* A button that opens something has to look like it does. Styled as a link
   rather than as a button because it sits inside a table cell, where a real
   button would put a box around every row's first column — but it keeps the
   underline and the colour shift, which are the two things that say "this
   does something" without needing a hover to discover it. */
button.link {
  background: transparent;
  border-color: transparent;
  padding: 0 0.15rem;
  color: var(--ink);
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
  text-decoration-color: var(--ink-muted);
}
button.link:hover,
button.link:focus-visible {
  color: var(--focus);
  text-decoration-style: solid;
  text-decoration-color: currentColor;
  background: transparent;
}
/* Fingers are not mouse pointers: on a phone the whole cell is the target. */
@media (max-width: 900px) {
  button.link { padding: 0.25rem 0; min-height: 2rem; }
}
input[type="number"], input[type="text"], input[type="date"] { min-width: 0; }
input[type="checkbox"] { min-height: 0; accent-color: var(--bar-strong); }
label { font-size: var(--fs-sm); color: var(--ink-2); }
select[multiple] { padding: 0.25rem; height: auto; }

/* Filter bar. A <details> so the whole thing folds away on a phone, where it
   would otherwise be most of the first screen. */
.filters > summary {
  padding: var(--pad);
  cursor: pointer;
  font-weight: 600;
  list-style: none;
  display: flex;
  align-items: center;
  gap: var(--gap);
}
.filters > summary::-webkit-details-marker { display: none; }
.filters > summary::before { content: "▸"; color: var(--ink-muted); }
.filters[open] > summary::before { content: "▾"; }
.filters > summary .spacer { flex: 1; }

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--gap);
  padding: 0 var(--pad) var(--pad);
}
.field { display: flex; flex-direction: column; gap: 0.25rem; }
.field-head { display: flex; align-items: baseline; gap: 0.4rem; }
.field-head .spacer { flex: 1; }
.field-head .count { font-size: var(--fs-xs); }

/* Small, but never below the 2rem the rest of the controls use — these are
   here precisely because the thing underneath them is hard to hit on a phone,
   so they cannot be fiddly themselves. */
button.mini {
  min-height: 1.5rem;
  padding: 0 0.5rem;
  font-size: var(--fs-xs);
  background: transparent;
}
button.mini:hover { background: var(--surface-sunk); }
/* 44px on touch, which is the smallest target Apple and Android both call
   reliable. These buttons exist *because* the control below them is hard to
   hit with a thumb, so shipping them at 32px would be missing the point. */
@media (max-width: 900px) {
  button.mini { min-height: 2.75rem; min-width: 2.75rem; padding: 0 0.9rem; }
}
.field.row { flex-direction: row; align-items: center; gap: 0.5rem; }
.field .pair { display: flex; gap: 0.375rem; }
.field .pair > * { flex: 1; }
.field select[multiple] { height: 7.5rem; }

/* --- filter impact -------------------------------------------------------
   A single stacked bar with both segments labelled in text. The bar is the
   glance; the sentence under it is the answer. Colour is never the only
   channel — the counts and percentages are always printed. */

.impact .track {
  display: flex;
  height: 0.75rem;
  border-radius: var(--radius-pill);
  overflow: hidden;
  background: var(--bar-track);
}
.impact .kept { background: var(--bar-strong); }
/* 2px of surface between the two fills, so they read as two marks. */
.impact .cut { background: var(--bar-track); border-left: 2px solid var(--surface); }
.impact .legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap);
  margin-top: 0.5rem;
  font-size: var(--fs-sm);
}
.impact .legend span::before {
  content: "";
  display: inline-block;
  width: 0.625rem; height: 0.625rem;
  border-radius: 3px;
  margin-right: 0.375rem;
  vertical-align: baseline;
}
.impact .legend .k::before { background: var(--bar-strong); }
.impact .legend .c::before { background: var(--bar-track); }
.impact ul { margin: 0.5rem 0 0; padding-left: 1.125rem; font-size: var(--fs-sm); color: var(--ink-2); }

/* --- stat tiles ----------------------------------------------------------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--gap);
}
.tile { padding: var(--pad); }
.tile .k { font-size: var(--fs-xs); color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.tile .v { font-size: var(--fs-hero); font-weight: 600; line-height: 1.2; margin-top: 0.125rem; }
.tile .s { font-size: var(--fs-xs); color: var(--ink-2); }

/* --- outcome histogram ---------------------------------------------------
   Ordered buckets from total loss to big win. Polarity, so the two arms take
   the reserved status hues — but every bar carries its count and its label, so
   a reader who cannot separate the hues loses nothing. */

/* The two spreads answer the same question at two moments, so they sit side
   by side on the same buckets — the comparison is the point, and stacking them
   would put a scroll between the two halves of it. */
.spreads { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap-lg); }
.spreads h3 { font-size: var(--fs-sm); margin: 0 0 0.15rem; }
.spreads .hint { margin: 0 0 0.6rem; font-size: var(--fs-xs); }
@media (max-width: 900px) { .spreads { grid-template-columns: 1fr; } }

.hist { display: flex; flex-direction: column; gap: 0.375rem; }
.hist .row { display: grid; grid-template-columns: 5.5rem 1fr 4.5rem; align-items: center; gap: 0.5rem; font-size: var(--fs-sm); }
.hist .bar { height: 0.875rem; border-radius: 0 4px 4px 0; min-width: 2px; }
.hist .bar.down { background: var(--critical); }
.hist .bar.flat { background: var(--ink-muted); }
.hist .bar.up { background: var(--good); }
.hist .row .num { color: var(--ink-2); }

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

.scroll { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-sunk);
  text-align: left;
  font-weight: 600;
  color: var(--ink-2);
  padding: 0.5rem var(--pad);
  white-space: nowrap;
  border-bottom: 1px solid var(--rule);
}
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--ink); }
thead th[aria-sort]::after { content: " ↕"; color: var(--ink-muted); }
thead th[aria-sort="ascending"]::after { content: " ↑"; color: var(--ink); }
thead th[aria-sort="descending"]::after { content: " ↓"; color: var(--ink); }
tbody td { padding: 0.5rem var(--pad); border-bottom: 1px solid var(--rule); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-sunk); }

/* Share-of-calls cell: a fixed-width magnitude bar, then the number. One hue,
   because it is one measure. */
.share {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
}
.share .track {
  width: 4rem;
  height: 0.5rem;
  flex: none;
  border-radius: var(--radius-pill);
  background: var(--bar-track);
  overflow: hidden;
}
.share .fill { height: 100%; background: var(--bar-strong); border-radius: var(--radius-pill); }
.share .txt { font-variant-numeric: tabular-nums; min-width: 3rem; text-align: right; }

.delta { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
.delta.up { color: var(--good-ink); }
.delta.down { color: var(--critical-ink); }
.delta.none { color: var(--ink-muted); font-weight: 400; }

.pill {
  display: inline-block;
  padding: 0 0.4rem;
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  background: var(--surface-sunk);
  color: var(--ink-2);
  border: 1px solid var(--edge);
}
.pill.gone { background: var(--critical-wash); color: var(--critical-ink); border-color: transparent; }
.pill.first { background: var(--good-wash); color: var(--good-ink); border-color: transparent; }

/* Category chips. The dot carries the slot colour, the text carries the
   meaning — colour is never alone. */
.chips { display: flex; flex-wrap: wrap; gap: 0.25rem; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.05rem 0.45rem;
  min-height: 0;
  font-size: var(--fs-xs);
  border-radius: var(--radius-pill);
  background: var(--surface-sunk);
}
.chip::before {
  content: ""; width: 0.5rem; height: 0.5rem; border-radius: 50%;
  background: var(--chip-color, var(--cat-x)); flex: none;
}
.chip.on { border-color: var(--chip-color, var(--cat-x)); background: var(--surface); }
.chip.add { color: var(--ink-muted); }
.chip.add::before { display: none; }

/* --- category editor ------------------------------------------------------ */

dialog {
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  padding: 0;
  max-width: min(30rem, 92vw);
  width: 100%;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }

/* Scoped to [open], and it has to be. The browser hides a closed <dialog> with
   `display: none` from its own stylesheet, so ANY unconditional `display` here
   overrides that and leaves the dialog sitting on the page after Close —
   unstyled by a backdrop, not modal, and impossible to get rid of.
   The column layout is what lets the title and footer stay put while only the
   body scrolls, so a dialog taller than the window can still be closed. */
dialog[open] {
  display: flex;
  flex-direction: column;
  max-height: 92vh;
}
dialog h2, dialog footer { flex: none; }
dialog .body { overflow-y: auto; }
dialog .body { padding: var(--pad); display: flex; flex-direction: column; gap: var(--gap); }
dialog h2 { padding: var(--pad); border-bottom: 1px solid var(--rule); }
dialog footer { padding: var(--pad); border-top: 1px solid var(--rule); display: flex; gap: 0.5rem; justify-content: flex-end; }

.pickers { display: flex; flex-wrap: wrap; gap: 0.375rem; }

/* --- sign-in -------------------------------------------------------------- */

.gate {
  max-width: 20rem;
  margin: 12vh auto;
  padding: var(--gap-lg);
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: var(--gap);
}
.gate form { display: flex; flex-direction: column; gap: var(--gap); }
.gate input { min-height: 2.5rem; }
.gate button { min-height: 2.5rem; background: var(--bar-strong); color: #fff; border-color: transparent; }
.error { color: var(--critical-ink); font-size: var(--fs-sm); margin: 0; }
.hint { color: var(--ink-muted); font-size: var(--fs-sm); margin: 0; }

/* --- phones ---------------------------------------------------------------
   Tables become stacked cards. Every <td> carries a data-label written by the
   renderer, so the label column here is generated rather than duplicated in
   the markup — a new column needs no change in this file. */

@media (max-width: 900px) {
  .shell { padding: 0.5rem; gap: var(--gap); }
  thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tbody tr {
    border-bottom: 1px solid var(--rule);
    padding: 0.5rem 0;
  }
  tbody tr:hover { background: transparent; }
  tbody td {
    border: 0;
    padding: 0.15rem var(--pad);
    display: grid;
    grid-template-columns: 8rem 1fr;
    gap: 0.5rem;
    text-align: left;
  }
  tbody td::before {
    content: attr(data-label);
    color: var(--ink-muted);
    font-size: var(--fs-xs);
  }
  tbody td.num { text-align: left; }
  /* The phone layout already prints the figure under its own label; the bar
     has no neighbours to be compared against there, so it only costs width. */
  .share { justify-content: flex-start; }
  .share .track { display: none; }
  .share .txt { min-width: 0; text-align: left; }
  .tile .v { font-size: var(--fs-lg); }
  .hist .row { grid-template-columns: 4.25rem 1fr 4.5rem; font-size: var(--fs-xs); }
}

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

/* The reset button sits under the filter grid rather than in it, so it does
   not take a grid cell away from an actual filter. Its own rule rather than an
   inline style, because the page's Content-Security-Policy forbids those —
   which is also why nothing in this project ever sets style="" in markup. */
.filter-actions { padding: 0 var(--pad) var(--pad); }

/* --- collapsible sections -------------------------------------------------
   Same shape as the filter bar, so a card that folds looks like a card that
   folds everywhere on the page. The state is remembered per section. */

.card > summary {
  padding: var(--pad);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: baseline;
  gap: var(--gap);
  font-size: var(--fs-md);
  font-weight: 600;
}
.card > summary::-webkit-details-marker { display: none; }
.card > summary::before { content: "▸"; color: var(--ink-muted); font-weight: 400; }
.card[open] > summary::before { content: "▾"; }
.card > summary .spacer { flex: 1; }
.card > summary .muted { font-weight: 400; }
.card[open] > summary { border-bottom: 1px solid var(--rule); }

/* --- donut ---------------------------------------------------------------- */

.pie { display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap-lg); }
.donut { width: 180px; height: 180px; flex: none; }
.donut .donut-value { font: 600 1.25rem var(--sans); fill: var(--ink); }
.donut .donut-label { font: 400 var(--fs-xs) var(--sans); fill: var(--ink-muted); }

/* The legend is not decoration: it is the channel that carries slice identity
   for anyone who cannot separate the hues, so it always shows name and count. */
.pie-legend { display: flex; flex-direction: column; gap: 0.3rem; min-width: 12rem; max-width: 18rem; }
.pie-legend .row { display: grid; grid-template-columns: 0.75rem 1fr auto; align-items: center; gap: 0.5rem; font-size: var(--fs-sm); }
.pie-legend .dot { width: 0.75rem; height: 0.75rem; border-radius: 3px; }
.pie-legend .n { font-variant-numeric: tabular-nums; color: var(--ink-2); }

/* --- caller detail dialog ------------------------------------------------- */

dialog.wide { max-width: min(58rem, 94vw); }
dialog.wide .body { gap: var(--gap-lg); }
.detail-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr)); gap: var(--gap); }
.detail-stats .k { font-size: var(--fs-xs); color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.detail-stats .v { font-size: var(--fs-lg); font-weight: 600; }
.detail-section > h3 { font-size: var(--fs-sm); color: var(--ink-2); margin: 0 0 0.35rem; font-weight: 600; }
.detail-section table { font-size: var(--fs-sm); }
.detail-section .empty { color: var(--ink-muted); font-size: var(--fs-sm); }

/* The ticker, its disambiguator and its call count are one label. Left to
   wrap, a three-word cell makes every row three lines tall in a column that
   has plenty of width available to it. */
.tokencell { display: inline-flex; align-items: baseline; gap: 0.3rem; white-space: nowrap; }

/* The basket figure and the share carried by its top position read as one
   value, so they stay on one line together. On a phone the column becomes a
   stacked row with its own label and has the full width, so it can wrap. */
.basketcell { white-space: nowrap; }

/* A price established by hand rather than observed. Marked with an asterisk
   and a tooltip rather than a colour: it is a note about provenance, not a
   result, and the status hues are spoken for. */
.derived { white-space: nowrap; }

/* A recovered call is a real call with a reconstructed origin, so the pill is
   an annotation rather than a status: it borrows the muted ink instead of a
   status colour, which are reserved for what a call is worth. */
.pill.recovered { border-style: dashed; }
@media (max-width: 900px) { .basketcell { white-space: normal; } }

/* Bold like the plain ticker it replaces, so the column does not change
   weight, plus the dotted underline every other opener on this page uses. */
a.token {
  color: var(--ink);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
  text-decoration-color: var(--ink-muted);
}
a.token:hover,
a.token:focus-visible {
  color: var(--focus);
  text-decoration-style: solid;
  text-decoration-color: currentColor;
}
@media (max-width: 900px) { .tokencell { flex-wrap: wrap; white-space: normal; } }
/* Stacked, not side by side. Each list now carries seven columns — ticker,
   two market caps, peak, result, categories, the dead toggle — and half a
   dialog is not enough width for that. Full width each also suits lists that
   page rather than stopping at ten. */
.detail-cols { display: flex; flex-direction: column; gap: var(--gap-lg); }
.detail-section > .more { margin-top: 0.5rem; }

/* --- the dead-by-hand flag ------------------------------------------------ */

button.flag {
  min-height: 0;
  padding: 0.05rem 0.45rem;
  font-size: var(--fs-xs);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--ink-muted);
  white-space: nowrap;
}
button.flag:hover { color: var(--critical-ink); border-color: var(--critical-ink); }
button.flag[aria-pressed="true"] {
  background: var(--critical-wash);
  color: var(--critical-ink);
  border-color: transparent;
}
.pill.flagged { background: var(--critical-wash); color: var(--critical-ink); border-color: transparent; }

@media (max-width: 900px) {
  .pie { justify-content: center; }
  dialog.wide { max-width: 96vw; }
}

/* --- the $1-per-token basket ---------------------------------------------
   Set apart from the stat tiles because it answers a different question: the
   tiles describe a typical call, this describes a portfolio, and on a
   power-law distribution those two disagree. */
.basket {
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: var(--pad);
  background: var(--surface-sunk);
}
.basket .row { display: flex; flex-wrap: wrap; gap: var(--gap-lg); align-items: baseline; }
.basket .leg .k { font-size: var(--fs-xs); color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.basket .leg .v { font-size: var(--fs-lg); font-weight: 650; }
.basket .leg .v .x { font-size: var(--fs-md); color: var(--ink-2); font-weight: 400; }
.basket .caveat { margin-top: 0.5rem; font-size: var(--fs-sm); color: var(--ink-2); }
.basket .caveat strong { color: var(--ink); }
