/* Tokens taken from the Flutter app's DARK palette
   (StColorScheme.dark in lib/ui/design/st_theme.dart) so the dashboard reads as
   the same product. Kept as CSS custom properties — change a value here, not at
   a call site. No webfont: the box serves this offline-capable, and Inter's
   fallback stack is close enough to justify not shipping ~100KB per visit.

   DARK ONLY, deliberately. This page lives on a wall display / a second monitor
   next to a terminal, so there is no light variant and no prefers-color-scheme
   branch to keep in sync — one palette, always. `color-scheme: dark` below tells
   the browser to render form controls and scrollbars to match, which is the bit
   people forget and then wonder why the <select> is a white rectangle. */
:root {
  color-scheme: dark;

  --brand: #cc5500;
  --brand-text: #ff7a33; /* lifted orange — legible on dark */
  --brand-tint: #2a1b10;

  --canvas: #0c0a09; /* stone-950 */
  --card: #1c1917; /* stone-900 */
  --muted: #292524; /* stone-800 */

  --border: #292524; /* stone-800 */
  --border-strong: #44403c; /* stone-700 */

  --text-primary: #fafaf9; /* stone-50 */
  --text-secondary: #d6d3d1; /* stone-300 */
  --text-tertiary: #a8a29e; /* stone-400 */

  --success: #22c55e;
  --success-bg: #0f2e1a;
  --success-text: #4ade80; /* green-400 */
  --danger: #ef4444;
  --danger-bg: #3a1a1a;
  --danger-text: #f87171; /* red-400 */
  --warn-bg: #33260a;
  --warn-text: #fbbf24; /* amber-400 */

  --radius: 12px;
  --radius-sm: 8px;
  /* On dark, a soft grey shadow is invisible — depth has to come from a real
     black drop plus the panel borders doing most of the separating. */
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.3);
  --brand-tint-border: #4a2f1a;
  --danger-border: #5c2626;
  --danger-surface: #241514;

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

* { box-sizing: border-box; }

/* Available to screen readers, absent for everyone else. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--canvas);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

.topbar {
  display: flex;
  /* center, not baseline: an <img> has no text baseline, so baseline alignment
     hangs the logo off the h1's and reads as misaligned. */
  align-items: center;
  gap: 12px;
  padding: 20px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
/* Intrinsic size is 753x216; height drives it and width:auto keeps the ratio,
   with the width/height attributes on the tag reserving space so the header
   doesn't jump as it loads. */
.topbar .logo {
  height: 26px;
  width: auto;
  display: block;
}
/* Separates the brand from the page title without another border. */
.topbar h1 {
  margin: 0;
  padding-left: 12px;
  border-left: 1px solid var(--border-strong);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.topbar .sub { color: var(--text-tertiary); font-size: 13px; }

.layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 24px;
  padding: 24px;
  align-items: start;
  max-width: 1500px;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- run list ---------- */

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.panel-head h2 { margin: 0; font-size: 14px; font-weight: 600; }

.filter {
  font: inherit;
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  max-width: 190px;
}

.runs { list-style: none; margin: 0; padding: 6px; max-height: 72vh; overflow-y: auto; }

.run {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  cursor: pointer;
}
.run:hover { background: var(--muted); }
.run[aria-current="true"] { background: var(--brand-tint); border-color: var(--brand-tint-border); }
.run:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }

.run-top { display: flex; align-items: center; gap: 8px; }
.run-id { font-family: var(--mono); font-size: 12px; color: var(--text-secondary); }
.run-meta {
  display: flex;
  gap: 8px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-tertiary);
}
.run-product { font-weight: 600; color: var(--text-primary); font-size: 13px; }

/* ---------- badges + chips ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge--passed { background: var(--success-bg); color: var(--success-text); }
.badge--failed { background: var(--danger-bg); color: var(--danger-text); }
.badge--skipped { background: var(--warn-bg); color: var(--warn-text); }

.chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--muted);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

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

.detail-head { padding: 18px 20px; border-bottom: 1px solid var(--border); }
.detail-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.detail-title h2 { margin: 0; font-size: 17px; font-weight: 700; }
.detail-sub {
  margin-top: 6px;
  color: var(--text-tertiary);
  font-size: 12px;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1px;
  background: var(--border);
  border-bottom: 1px solid var(--border);
}
.metric { background: var(--card); padding: 14px 20px; }
.metric-value { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.metric-label {
  font-size: 11px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 2px;
}
.metric--pass .metric-value { color: var(--success-text); }
.metric--fail .metric-value { color: var(--danger-text); }

/* Stat tiles double as status filters. They are <button>s, so reset the browser
   chrome and re-establish the grid cell look. */
.metric--filter {
  font: inherit;
  color: inherit;
  text-align: left;
  border: 0;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}
.metric--filter:hover:not(:disabled) { background: var(--muted); }
.metric--filter:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
.metric--filter:disabled { cursor: default; opacity: 0.45; }
/* The active filter is underlined in brand AND tinted — colour alone would be
   the only signal for which tile is doing the filtering. */
.metric--filter[aria-pressed="true"] {
  background: var(--brand-tint);
  border-bottom-color: var(--brand);
}

/* ---------- groups ---------- */

.group-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 18px 8px 6px;
}
.group-name {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}
.group-count { margin-left: auto; font-size: 12px; color: var(--text-tertiary); }
.chip--suite { background: var(--brand-tint); color: var(--brand-text); }

.section-file {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-tertiary);
}

/* Pass-rate bar: the one place a number alone reads worse than a shape. */
.rate { padding: 14px 20px; border-bottom: 1px solid var(--border); }
.rate-head {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.rate-track {
  height: 8px;
  border-radius: 999px;
  background: var(--muted);
  overflow: hidden;
  display: flex;
}
.rate-fill { height: 100%; }
.rate-fill--passed { background: var(--success); }
.rate-fill--failed { background: var(--danger); }
.rate-fill--skipped { background: var(--border-strong); }

.rate-note {
  margin-top: 8px;
  font-size: 12px;
  color: var(--danger-text);
}

.sections { padding: 8px 12px 16px; }

details.section {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-top: 8px;
  background: var(--card);
}
details.section > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  list-style: none;
  border-radius: var(--radius-sm);
}
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary:hover { background: var(--muted); }
details.section > summary:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
.section-name { font-weight: 600; font-family: var(--mono); font-size: 13px; }
.section-count { color: var(--text-tertiary); font-size: 12px; margin-left: auto; }

.marker { color: var(--text-tertiary); font-size: 11px; width: 10px; }
details[open] > summary .marker { transform: rotate(90deg); }
.marker { display: inline-block; transition: transform 0.12s ease; }

.tests { list-style: none; margin: 0; padding: 0 12px 10px; }
.test {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 7px 8px;
  border-top: 1px solid var(--border);
}
.test-name { flex: 1; min-width: 0; }
.test-dur { color: var(--text-tertiary); font-size: 12px; font-variant-numeric: tabular-nums; }

.failure {
  margin: 4px 8px 10px;
  border: 1px solid var(--danger-border);
  border-left: 3px solid var(--danger);
  border-radius: var(--radius-sm);
  background: var(--danger-surface);
  padding: 10px 12px;
}
.failure-message {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--danger-text);
  white-space: pre-wrap;
  word-break: break-word;
}
.failure-meta {
  margin-top: 8px;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 12px;
}
.failure-meta a { color: var(--brand-text); }
.failure-loc { font-family: var(--mono); color: var(--text-secondary); }

.empty-section {
  padding: 10px 14px 12px;
  font-size: 12px;
  color: var(--danger-text);
}

.placeholder {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-tertiary);
}

.error {
  margin: 24px;
  padding: 14px 16px;
  border: 1px solid var(--danger-border);
  background: var(--danger-bg);
  color: var(--danger-text);
  border-radius: var(--radius);
}
.error code { font-family: var(--mono); }

/* ---------- live run banner ---------- */

/* Sits above the history layout and is hidden entirely when nothing is running,
   so the page reads as pure history the rest of the time. */
.live {
  margin: 24px 24px 0;
  max-width: 1452px;
  border-color: var(--brand-tint-border);
}
.live-hint { font-size: 12px; color: var(--text-tertiary); }

.live-run {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.live-counts { font-size: 12px; color: var(--text-secondary); }
/* The currently-running test name; truncates rather than reflowing the row on
   every event. */
.live-latest {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-tertiary);
  max-width: 46ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge--live {
  background: var(--brand-tint);
  color: var(--brand-text);
}
/* A quiet pulse: enough to read as "happening now" without becoming the loudest
   thing on a wall display. Respects reduced-motion. */
.badge--live::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brand-text);
  animation: live-pulse 1.6s ease-in-out infinite;
}
@keyframes live-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}
@media (prefers-reduced-motion: reduce) {
  .badge--live::before { animation: none; }
}
