/*
 * The panel's stylesheet. Complete on its own: nothing here depends on a CDN, and the
 * fonts beside it are served by this binary, so the panel looks the same on a laptop
 * with no route to the internet as on one with a fibre line.
 *
 * Dark is the base, not a retrofit. These pages are read at three in the morning at
 * least as often as at noon, and the light variant below is the inversion rather than
 * the other way round.
 *
 * Two rules govern colour here, and both exist because of what this panel is for:
 *
 *   1. Colour only ever means state. Nothing is tinted to decorate, so an operator
 *      scanning a column can trust that anything coloured is telling them something.
 *   2. Never-measured is not a colour. It is a hatch -- a void in the bar rather than
 *      a third shade -- because a shade sits on a scale with the other two and would
 *      read as a verdict. It is the absence of one.
 */

@font-face {
  font-family: "IBM Plex Sans";
  src: url("/static/fonts/plex-sans-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Sans";
  src: url("/static/fonts/plex-sans-600.woff2") format("woff2");
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("/static/fonts/plex-mono-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

:root {
  color-scheme: dark light;

  --ground: #0e1216;
  --raised: #161c23;
  --rule: #242d37;
  --rule-soft: #1a222a;
  --ink: #e0e6ed;
  --ink-dim: #8d9aaa;
  --ink-faint: #5e6c7c;

  /* Quiet on purpose. Links have to be findable without competing with the three
   * colours that carry a verdict. */
  --accent: #6fa8dc;
  --accent-soft: #16283a;

  /* Distinct hue, not distinct shade: two verdicts that differ only in lightness are
   * two verdicts that get confused on a dimmed screen at 3am. */
  --alarm: #e8675b;
  --alarm-soft: #2b1614;
  --intact: #58b87c;
  --intact-soft: #12291c;
  --unknown: #d6a03c;
  --unknown-soft: #2a2113;

  --sans: "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --gap: 1.5rem;
  --pad: 1.75rem;
}

@media (prefers-color-scheme: light) {
  :root {
    --ground: #f6f7f9;
    --raised: #ffffff;
    --rule: #d7dce3;
    --rule-soft: #e8ebf0;
    --ink: #171b21;
    --ink-dim: #59616e;
    --ink-faint: #7c8694;

    --accent: #1b5cc4;
    --accent-soft: #e6eefb;

    --alarm: #b3261e;
    --alarm-soft: #fdeceb;
    --intact: #1b6b3a;
    --intact-soft: #e7f4ec;
    --unknown: #8a6100;
    --unknown-soft: #fdf3df;
  }
}

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

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.875rem;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* Every figure in this panel is compared against the one above it, so figures line up
 * by column rather than by accident of glyph width. */
.num, .metric-value, .count, td.num, th.num, .big,
.share-pct, .share-count, .pager-at { font-variant-numeric: tabular-nums; }

.mono, code { font-family: var(--mono); font-size: 0.9em; }

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

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

/* ---- chrome -------------------------------------------------------------- */

.chrome {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0 var(--pad);
  height: 46px;
  border-bottom: 1px solid var(--rule);
  background: var(--ground);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  font-size: 0.95rem;
}

.tabs { display: flex; gap: 1.25rem; margin-left: 0.5rem; }

/* The current tab is marked by a rule sitting on the chrome's own border rather than
 * by a filled pill: one line of colour is enough to answer "where am I", and a pill
 * would be a second coloured object competing with the verdicts. */
.tab {
  color: var(--ink-dim);
  padding: 0 0.1rem;
  line-height: 44px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--ink); text-decoration: none; }
.tab.on { color: var(--ink); border-bottom-color: var(--accent); }

.who { margin-left: auto; display: flex; align-items: center; gap: 0.75rem; color: var(--ink-dim); }
.who-name { color: var(--ink); }

main { padding: var(--pad) var(--pad) 4rem; }

.chrome-foot {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1rem var(--pad) 2rem;
  color: var(--ink-faint);
  font-size: 0.75rem;
  border-top: 1px solid var(--rule-soft);
}

.title {
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 0 0 1.5rem;
}
.title .count { color: var(--ink-dim); font-weight: 400; margin-left: 0.5rem; }

/* ---- bands --------------------------------------------------------------- */

/* No cards. A band is separated from the next by a rule and by space, so the page has
 * one reading order instead of a grid of equally-weighted boxes. */
.band { padding-block: var(--gap); border-top: 1px solid var(--rule-soft); }
.band:first-of-type { border-top: 0; padding-top: 0; }

.band-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-dim);
  margin: 0 0 1rem;
}

.band-split {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: var(--gap) 3rem;
}

/* ---- the counts ---------------------------------------------------------- */

.metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 2.5rem;
  padding-bottom: var(--gap);
}

.metric { display: flex; flex-direction: column-reverse; gap: 0.15rem; color: inherit; }
.metric:hover { text-decoration: none; }
.metric:hover .metric-value { color: var(--accent); }

.metric-label { font-size: 0.75rem; color: var(--ink-dim); }
.metric-value { font-size: 1.75rem; font-weight: 600; line-height: 1.1; letter-spacing: -0.02em; }

/* Only the two states an operator acts on are coloured. Live, flaky and candidate are
 * the ordinary run of the pool and take the page's own ink. */
.m-quarantine .metric-value { color: var(--alarm); }
.m-dead .metric-value { color: var(--ink-faint); }

/* ---- the interception bar ------------------------------------------------ */

.intbar {
  display: flex;
  height: 2.25rem;
  border: 1px solid var(--rule);
  border-radius: 2px;
  overflow: hidden;
  background: var(--ground);
}

.intbar-seg { display: block; height: 100%; }
.intbar-seg.is-intact { background: var(--intact); }
.intbar-seg.is-alarm { background: var(--alarm); }

/* The void. Hatched rather than filled, because every filled segment in this bar is a
 * measurement and this one is the absence of one. An operator who reads the bar
 * without reading the key still sees that this part was never looked at. */
.intbar-seg.is-void {
  background: repeating-linear-gradient(
    -45deg,
    var(--unknown-soft) 0 5px,
    transparent 5px 10px
  );
  border-left: 1px solid var(--rule);
}

.intkey {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1.75rem;
  list-style: none;
  margin: 0.85rem 0 0;
  padding: 0;
  font-size: 0.8rem;
  color: var(--ink-dim);
}
.intkey b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.intkey li { display: flex; align-items: center; gap: 0.5rem; }

.key-swatch {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 1px;
  flex: none;
}
.key-swatch.is-intact { background: var(--intact); }
.key-swatch.is-alarm { background: var(--alarm); }
.key-swatch.is-void {
  background: repeating-linear-gradient(-45deg, var(--unknown) 0 2px, transparent 2px 4px);
  border: 1px solid var(--rule);
}

/* The reasoning behind the split is worth reading once and is noise on every visit
 * after that, so it is a disclosure rather than a paragraph that never goes away. */
.note-more { margin-top: 0.9rem; font-size: 0.8rem; color: var(--ink-dim); max-width: 76ch; }
.note-more summary { cursor: pointer; color: var(--ink-faint); }
.note-more summary:hover { color: var(--ink); }
.note-more p { margin: 0.6rem 0 0; line-height: 1.6; }

/* ---- cards ---------------------------------------------------------------
 *
 * The markup still groups the overview into cards. The band treatment above is where
 * this is going, but a half-migrated stylesheet that leaves live markup unstyled is
 * worse than either end state, so these keep a treatment consistent with the rest:
 * a flat region with a rule, no shadow, and no radius competing with the badges.
 */

.cards { display: grid; gap: var(--gap); }
.cards.two-up { grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); }

.card {
  border: 1px solid var(--rule-soft);
  border-radius: 3px;
  padding: 1.1rem 1.25rem;
  background: var(--raised);
}

/* Only the two that carry a finding are tinted, and they are tinted on the edge rather
 * than filled: a filled panel would out-shout the table, which is where the work is. */
.card.danger { border-color: var(--alarm); }
.card.warn { border-color: var(--unknown); border-style: dashed; }

.card-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-dim);
  margin: 0 0 0.75rem;
}
.card.danger .card-title { color: var(--alarm); }
.card.warn .card-title { color: var(--unknown); }

.big {
  font-size: 1.75rem;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.02em;
  margin: 0 0 0.5rem;
}
.card.danger .big { color: var(--alarm); }
.card.warn .big { color: var(--unknown); }

/* ---- shares (protocols, anonymity) --------------------------------------- */

.shares { display: flex; flex-direction: column; gap: 0.4rem; }
.share { display: grid; grid-template-columns: 8rem 1fr 3.5rem 3rem; align-items: center; gap: 0.75rem; }
.share-label { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-bar { height: 0.4rem; background: var(--accent); border-radius: 1px; min-width: 1px; }
.share-pct, .share-count { font-size: 0.8rem; color: var(--ink-dim); text-align: right; }

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

.table-wrap { overflow-x: auto; }

.grid { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }

.grid th {
  text-align: left;
  font-weight: 600;
  font-size: 0.7rem;
  color: var(--ink-faint);
  padding: 0 0.6rem 0.5rem;
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}
.grid td { padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--rule-soft); }
.grid th:first-child, .grid td:first-child { padding-left: 0; }
.grid th:last-child, .grid td:last-child { padding-right: 0; }
.grid th.num, .grid td.num { text-align: right; }
.grid tbody tr:hover { background: var(--raised); }
.grid tr.empty td { color: var(--ink-faint); padding: 1.25rem 0; }
.grid.tight td { padding-block: 0.3rem; }

.grid th.sortable a { color: var(--ink-faint); }
.grid th.sortable a:hover { color: var(--ink); text-decoration: none; }
.grid th.on a { color: var(--ink); }
.grid th.on a::after { content: attr(data-dir); margin-left: 0.3rem; color: var(--accent); }

/* ---- badges and chips ---------------------------------------------------- */

.badge {
  display: inline-block;
  padding: 0.05rem 0.4rem;
  border-radius: 2px;
  font-size: 0.7rem;
  border: 1px solid var(--rule);
  color: var(--ink-dim);
  white-space: nowrap;
}
.badge[data-state="live"] { color: var(--intact); border-color: var(--intact); }
.badge[data-state="quarantine"] { color: var(--alarm); border-color: var(--alarm); }
.badge[data-state="dead"] { color: var(--ink-faint); }

/* A dotted border for anything never measured, everywhere it appears. The shape says
 * "no reading was taken" before the colour or the text does. */
.verdict-card, .pill, .chip { display: inline-block; white-space: nowrap; }

.pill {
  padding: 0.05rem 0.4rem;
  border-radius: 2px;
  font-size: 0.7rem;
  border: 1px solid transparent;
}
.pill[data-verdict="intact"], .pill[data-mitm="clean"], .pill[data-google="yes"], .pill[data-cloudflare="yes"] {
  color: var(--intact); border-color: var(--intact); background: var(--intact-soft);
}
.pill[data-verdict="intercepting"], .pill[data-mitm="intercepting"], .pill[data-google="no"], .pill[data-cloudflare="no"] {
  color: var(--alarm); border-color: var(--alarm); background: var(--alarm-soft);
}
.pill[data-mitm="not-assessed"], .pill[data-google="untested"], .pill[data-cloudflare="untested"] {
  color: var(--unknown); border-style: dotted; border-color: var(--unknown); background: transparent;
}

.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.chip {
  padding: 0.05rem 0.4rem;
  border: 1px solid var(--rule);
  border-radius: 2px;
  font-size: 0.7rem;
  color: var(--ink-dim);
  font-family: var(--mono);
}
.chip-leak { color: var(--unknown); border-color: var(--unknown); }
.chip-auth { color: var(--ink-dim); }
.chip-check { color: var(--accent); border-color: var(--accent); }

.glyph { color: var(--ink-faint); }
.dim { color: var(--ink-dim); }
.nowrap { white-space: nowrap; }
.inline { display: inline; }
.link { color: var(--accent); }

/* ---- filters ------------------------------------------------------------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem 1.25rem;
  padding-bottom: var(--gap);
  border-bottom: 1px solid var(--rule-soft);
  margin-bottom: var(--gap);
}
.filter-line { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem 1.25rem; width: 100%; }
.filter-actions { display: flex; gap: 0.5rem; margin-left: auto; }

.field { display: flex; flex-direction: column; gap: 0.25rem; }
.field.grow { flex: 1 1 18rem; }
.field-label { font-size: 0.7rem; color: var(--ink-faint); }

.field-input {
  background: var(--raised);
  border: 1px solid var(--rule);
  border-radius: 2px;
  color: var(--ink);
  font: inherit;
  font-size: 0.8125rem;
  padding: 0.3rem 0.5rem;
  min-width: 0;
}
.field-input::placeholder { color: var(--ink-faint); }
.field-input:focus-visible { border-color: var(--accent); outline-offset: 0; }

/* Checkbox groups carried a fieldset legend, which draws a notch in the border and is
 * the most recognisable piece of default browser chrome there is. */
.chips legend, .filters legend {
  font-size: 0.7rem;
  color: var(--ink-faint);
  padding: 0;
  margin-bottom: 0.3rem;
}
.filters fieldset { border: 0; padding: 0; margin: 0; }
.filters label { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.8125rem; }
.filters input[type="checkbox"] { accent-color: var(--accent); margin: 0; }

/* ---- buttons ------------------------------------------------------------- */

.button {
  font: inherit;
  font-size: 0.8125rem;
  padding: 0.32rem 0.85rem;
  border-radius: 2px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--ground);
  cursor: pointer;
}
.button:hover { filter: brightness(1.08); }
.button.quiet { background: transparent; color: var(--ink-dim); border-color: var(--rule); }
.button.quiet:hover { color: var(--ink); border-color: var(--ink-dim); filter: none; }
.button.danger { background: transparent; color: var(--alarm); border-color: var(--alarm); }
.button.danger:hover { background: var(--alarm-soft); filter: none; }

/* ---- pager --------------------------------------------------------------- */

.pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding-top: 0.9rem;
  color: var(--ink-dim);
  font-size: 0.8rem;
}
.pager-links { display: flex; gap: 0.75rem; }
.pager-page { color: var(--accent); }
.pager-at { color: var(--ink); }

/* ---- detail -------------------------------------------------------------- */

.pairs { display: grid; grid-template-columns: minmax(8rem, max-content) 1fr; gap: 0.35rem 1.25rem; margin: 0; }
.pairs dt { color: var(--ink-dim); font-size: 0.8125rem; }
.pairs dd { margin: 0; }
.pairs dd.num { text-align: left; }

.actions { display: flex; flex-direction: column; gap: 1.25rem; align-items: flex-start; }
.actions form { display: flex; align-items: flex-end; gap: 0.6rem; flex-wrap: wrap; }
.actions form.stack { flex-direction: column; align-items: stretch; max-width: 26rem; width: 100%; }
.actions form.stack .button { align-self: flex-start; }
.note { color: var(--ink-dim); font-size: 0.78rem; margin: 0; max-width: 60ch; line-height: 1.5; }

.ladder { display: flex; flex-wrap: wrap; gap: 0.4rem; list-style: none; padding: 0; margin: 0; }
.rung-n { padding: 0.05rem 0.45rem; border: 1px solid var(--rule); border-radius: 2px; font-size: 0.72rem; color: var(--ink-dim); font-family: var(--mono); }
.rung-here { border-color: var(--accent); color: var(--accent); }
.rung-wait { color: var(--ink-faint); }

/* ---- messages ------------------------------------------------------------ */

.alert {
  border: 1px solid var(--alarm);
  background: var(--alarm-soft);
  color: var(--ink);
  padding: 0.6rem 0.8rem;
  border-radius: 2px;
  margin-bottom: 1.25rem;
  font-size: 0.8125rem;
}
.warn-text { color: var(--unknown); }
.failure { color: var(--alarm); }
.status { color: var(--ink-dim); font-size: 0.8rem; }

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

/* The one page reached before anyone is identified, so it is the one place the panel
 * says what it is rather than assuming you know. */
.signin {
  max-width: 20rem;
  margin: 12vh auto 0;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.signin .title { margin-bottom: 0.25rem; }
.signin .button { width: 100%; }

/* ---- responsive ---------------------------------------------------------- */

@media (max-width: 640px) {
  :root { --pad: 1rem; --gap: 1.25rem; }
  .chrome { gap: 0.75rem; overflow-x: auto; }
  .tabs { gap: 0.9rem; }
  .metrics { gap: 1.25rem 2rem; }
  .metric-value { font-size: 1.4rem; }
  .share { grid-template-columns: 6rem 1fr 3rem; }
  .share-count { display: none; }
  .pairs { grid-template-columns: 1fr; gap: 0 0; }
  .pairs dt { margin-top: 0.6rem; }
}

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