/* 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.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. */

.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); }
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); }
dialog {
  max-height: 92vh;
  display: flex;
  flex-direction: column;
}
dialog h2, dialog footer { flex: none; }
dialog .body { overflow-y: auto; }
.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); }
.detail-cols { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap-lg); }

/* --- 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) {
  .detail-cols { grid-template-columns: 1fr; }
  .pie { justify-content: center; }
  dialog.wide { max-width: 96vw; }
}
