/* grandprix console. Palette: the validated dataviz reference instance
   (categorical slots 1-8, status colors, chart chrome), light and dark. */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --surface-3: #ebeae4;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-3: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --border-strong: rgba(11, 11, 11, 0.18);
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 1px 1px rgba(11, 11, 11, 0.02);
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --s4: #eda100;
  --s5: #e87ba4;
  --s6: #008300;
  --s7: #6250d6;
  --s8: #e34948;
  --s-muted: #898781;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --track: #cde2fb;
  --banner-crit: #fdf0f0;
  --banner-warn: #fff7e6;
  --banner-info: #eef5fd;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #222220;
    --surface-3: #2c2c2a;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --ink-3: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.18);
    --shadow: none;
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --s4: #c98500;
    --s5: #d55181;
    --s6: #008300;
    --s7: #9085e9;
    --s8: #e66767;
    --track: #104281;
    --banner-crit: #2a1515;
    --banner-warn: #2a2210;
    --banner-info: #13202f;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 14px; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-3); margin: 18px 0 8px; }
p { margin: 0; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
code.mono, .mono { font-family: var(--mono); font-size: 12px; }
code.mono.muted { color: var(--ink-2); }
em { font-style: normal; }

/* ---- top bar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 24px;
  height: 52px;
  padding: 0 24px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand, .login-brand { display: flex; align-items: center; gap: 8px; color: var(--ink); font-weight: 650; font-size: 15px; letter-spacing: -0.02em; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 18px; height: 18px; border-radius: 5px; background: var(--ink); position: relative; flex: none; }
.brand-mark::after {
  content: "";
  position: absolute;
  left: 4px; right: 4px; top: 8px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 -4px 0 var(--accent), 0 4px 0 color-mix(in srgb, var(--accent) 50%, transparent);
}
.brand-sub { color: var(--ink-3); font-weight: 450; }
.nav { display: flex; gap: 2px; flex: 1; }
.nav a { color: var(--ink-2); padding: 6px 10px; border-radius: 6px; font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav a[aria-current="page"] { color: var(--ink); background: var(--surface-3); }
.who { display: flex; align-items: center; gap: 12px; color: var(--ink-2); font-size: 13px; }
.who form { margin: 0; }
.tz { color: var(--ink-3); font-size: 12px; }

/* ---- buttons, fields ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  font: 500 13px var(--sans);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.primary { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.btn.primary:hover { opacity: 0.88; }
.btn:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-3); }
.field > span { font-weight: 500; }
.field input, .field select {
  height: 30px;
  min-width: 120px;
  padding: 0 8px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  font: 13px var(--sans);
}
.field select { max-width: 240px; }
.field.actions { flex-direction: row; align-items: flex-end; gap: 6px; }

/* ---- page ---- */
.main { max-width: 1480px; margin: 0 auto; padding: 24px 24px 64px; display: flex; flex-direction: column; gap: 16px; transition: opacity 0.2s; }
.main.refreshing { opacity: 0.92; }
.pagehead { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.pagehead p { margin-top: 4px; }
.pagehead-r { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.crumb { color: var(--ink-3); font-size: 13px; margin-bottom: 2px !important; }
.crumb a { color: var(--ink-2); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; box-shadow: var(--shadow); }
.tile-l { color: var(--ink-2); font-size: 12px; font-weight: 500; }
.tile-v { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; margin-top: 4px; line-height: 1.15; }
.tile-s { color: var(--ink-3); font-size: 12px; margin-top: 4px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); min-width: 0; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.card-h .sub { color: var(--ink-3); font-size: 12px; margin-top: 2px; }
.card-b { padding: 12px 16px 16px; }
.card-b > h3:first-child { margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid2.wide-left { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 1000px) { .grid2, .grid2.wide-left { grid-template-columns: minmax(0, 1fr); } .nav { overflow-x: auto; } .tz { display: none; } }

.empty { color: var(--ink-3); padding: 16px 0; font-size: 13px; }
.banner { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border); font-size: 13px; }
.banner.crit { background: var(--banner-crit); border-color: color-mix(in srgb, var(--critical) 40%, transparent); }
.banner.warn { background: var(--banner-warn); border-color: color-mix(in srgb, var(--warning) 50%, transparent); }
.banner.info { background: var(--banner-info); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.banner-i { flex: none; width: 18px; height: 18px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 11px; font-weight: 700; color: #fff; margin-top: 1px; }
.banner.crit .banner-i { background: var(--critical); }
.banner.warn .banner-i { background: var(--warning); color: #0b0b0b; }
.banner.info .banner-i { background: var(--accent); }

/* ---- badges (icon + label, never color alone) ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 20px;
  padding: 0 8px 0 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.badge-i { font-size: 11px; font-weight: 700; line-height: 1; }
.badge-i.dot { font-size: 9px; }
.badge.ok .badge-i { color: var(--good); }
.badge.crit .badge-i { color: var(--critical); }
.badge.warn .badge-i { color: #b57f00; }
.badge.serious .badge-i { color: var(--serious); }
.badge.info .badge-i { color: var(--accent); }
.badge.muted { color: var(--ink-2); }
.badge.muted .badge-i { color: var(--ink-3); }
@media (prefers-color-scheme: dark) { .badge.warn .badge-i { color: var(--warning); } }
.tag { display: inline-block; padding: 0 6px; border-radius: 4px; background: var(--surface-3); color: var(--ink-2); font-size: 11px; font-weight: 500; line-height: 18px; }

/* ---- tables ---- */
.tablewrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left;
  font-weight: 500;
  font-size: 12px;
  color: var(--ink-3);
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--surface);
}
table.data td { padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
table.data th:first-child, table.data td:first-child { padding-left: 0; }
table.data th:last-child, table.data td:last-child { padding-right: 0; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data tr.group td { background: var(--surface-2); }
table.data.fixed { table-layout: fixed; }
table.projects col.c-repo { width: 28%; }
table.projects col.c-last { width: 11%; }
table.projects col.c-spark { width: 150px; }
table.data.fixed td { overflow: hidden; text-overflow: ellipsis; }
table.data td.indent { width: 12px; }
.stack { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.branch { display: inline-block; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; font-family: var(--mono); font-size: 12px; color: var(--ink-2); }
a.ext::after { content: " \2197"; font-size: 11px; }

.alerts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.alerts li { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.blocked { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }

/* ---- meters ---- */
.meters { display: flex; flex-direction: column; gap: 12px; }
.meterrow { display: grid; grid-template-columns: 140px minmax(80px, 1fr) 190px; align-items: center; gap: 12px; font-size: 13px; }
.meter-l { color: var(--ink-2); }
.meter-v { font-variant-numeric: tabular-nums; white-space: nowrap; }
svg.meter { width: 100%; height: 8px; display: block; }
svg.meter .track { fill: var(--track); }
svg.meter .fill { fill: var(--s1); }
svg.meter.warn .fill { fill: var(--warning); }
svg.meter.crit .fill { fill: var(--critical); }
svg.meter .marker { fill: var(--ink); }
.diskrow { display: inline-grid; grid-template-columns: 120px auto; gap: 10px; align-items: center; }

/* ---- filters, pager, segmented ---- */
.filters { display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: flex-end; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 7px; overflow: hidden; }
.seg a { padding: 5px 10px; color: var(--ink-2); font-size: 13px; font-weight: 500; }
.seg a + a { border-left: 1px solid var(--border); }
.seg a:hover { background: var(--surface-2); text-decoration: none; }
.seg a[aria-current="page"] { background: var(--surface-3); color: var(--ink); }

.kv { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: 6px 16px; margin: 0; font-size: 13px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ---- charts ---- */
figure.chart { margin: 0; }
svg.plot { width: 100%; height: auto; display: block; overflow: visible; }
svg.plot text { font-family: var(--sans); font-size: 11px; fill: var(--ink-3); font-variant-numeric: tabular-nums; }
svg.plot .endlabel { fill: var(--ink-2); font-size: 11px; }
svg.plot .lanelabel { fill: var(--ink-2); font-size: 12px; }
svg.plot .reflabel { fill: var(--ink-2); paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; }
svg.plot .grid { stroke: var(--grid); stroke-width: 1; }
svg.plot .axis { stroke: var(--axis); stroke-width: 1; }
svg.plot .ref { stroke: var(--ink-3); stroke-width: 1; }
svg.plot .mark { stroke: var(--ink-3); stroke-width: 1; }
svg .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg .line.s1 { stroke: var(--s1); } svg .line.s2 { stroke: var(--s2); } svg .line.s3 { stroke: var(--s3); } svg .line.s4 { stroke: var(--s4); }
svg .line.s5 { stroke: var(--s5); } svg .line.s6 { stroke: var(--s6); } svg .line.s7 { stroke: var(--s7); } svg .line.s8 { stroke: var(--s8); }
svg .line.smuted, svg .line.muted { stroke: var(--s-muted); }
svg .area { stroke: none; fill-opacity: 0.1; }
svg .area.a1 { fill: var(--s1); } svg .area.a2 { fill: var(--s2); } svg .area.a3 { fill: var(--s3); }
svg .f1 { fill: var(--s1); } svg .f2 { fill: var(--s2); } svg .f3 { fill: var(--s3); } svg .f4 { fill: var(--s4); }
svg .f5 { fill: var(--s5); } svg .f6 { fill: var(--s6); } svg .f7 { fill: var(--s7); } svg .f8 { fill: var(--s8); }
svg .fmuted { fill: var(--s-muted); }
svg .end, svg .dot { stroke: var(--surface); stroke-width: 2; }
svg .crosshair { stroke: var(--ink-3); stroke-width: 1; visibility: hidden; }
svg .crosshair.on { visibility: visible; }
svg .hit { fill: transparent; cursor: default; }
svg .hit:hover, svg .hit:focus { fill: color-mix(in srgb, var(--ink) 5%, transparent); outline: none; }
svg.plot:focus { outline: none; }
svg.plot:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }
.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 4px 16px; padding: 0; margin: 8px 0 0; font-size: 12px; color: var(--ink-2); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.key { display: inline-block; flex: none; }
.key.line { width: 14px; height: 2px; border-radius: 1px; }
.key.rect { width: 10px; height: 10px; border-radius: 2px; }
.k1 { background: var(--s1); } .k2 { background: var(--s2); } .k3 { background: var(--s3); } .k4 { background: var(--s4); }
.k5 { background: var(--s5); } .k6 { background: var(--s6); } .k7 { background: var(--s7); } .k8 { background: var(--s8); }
.kmuted { background: var(--s-muted); }
details.tableview { margin-top: 8px; font-size: 12px; }
details.tableview summary { color: var(--ink-3); cursor: pointer; width: max-content; }
details.tableview .tablewrap { max-height: 280px; overflow: auto; margin-top: 6px; }
.empty-plot { display: grid; place-items: center; color: var(--ink-3); font-size: 13px; border: 1px dashed var(--grid); border-radius: 8px; }
.empty-plot.h160 { height: 160px; }
.empty-plot.h80 { height: 80px; }
svg.spark { width: 120px; height: 28px; display: block; }
svg.spark .end { stroke-width: 1.5; }
.spark-empty { color: var(--ink-3); }

.tip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  min-width: 140px;
  max-width: 320px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
  font-size: 12px;
}
.tip-t { color: var(--ink-3); margin-bottom: 4px; }
.tip-r { display: grid; grid-template-columns: 14px 1fr auto; align-items: center; gap: 6px; line-height: 1.6; }
.tip-r .v { font-weight: 600; color: var(--ink); text-align: right; font-variant-numeric: tabular-nums; order: 3; }
.tip-r .n { color: var(--ink-2); }

/* ---- login ---- */
.login-body { min-height: 100vh; display: grid; place-items: center; }
.login { width: 100%; max-width: 380px; padding: 24px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 16px; }
.login-card h1 { font-size: 18px; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-form .field input { height: 36px; font-size: 14px; }
.login-form .btn { height: 36px; justify-content: center; margin-top: 4px; }

/* ---- v2: heatmap (sequential blue ramp; anchor flips in dark), mini marks, pass/fail strip ---- */
:root {
  --q1: #cde2fb; --q2: #9ec5f4; --q3: #6da7ec; --q4: #3987e5; --q5: #256abf; --q6: #104281;
}
@media (prefers-color-scheme: dark) {
  :root { --q1: #184f95; --q2: #1c5cab; --q3: #2a78d6; --q4: #5598e7; --q5: #86b6ef; --q6: #cde2fb; }
}
.hscroll { overflow-x: auto; }
svg.plot.heat { width: auto; max-width: none; }
svg .cell.q1, .cellkey.q1 { fill: var(--q1); background: var(--q1); }
svg .cell.q2, .cellkey.q2 { fill: var(--q2); background: var(--q2); }
svg .cell.q3, .cellkey.q3 { fill: var(--q3); background: var(--q3); }
svg .cell.q4, .cellkey.q4 { fill: var(--q4); background: var(--q4); }
svg .cell.q5, .cellkey.q5 { fill: var(--q5); background: var(--q5); }
svg .cell.q6, .cellkey.q6 { fill: var(--q6); background: var(--q6); }
svg .cell-empty { fill: var(--surface-2); stroke: var(--grid); stroke-width: 1; }
.cellkey.none { background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--grid); }
svg .cell:hover, svg .cell:focus, svg .cell-empty:hover { stroke: var(--ink); stroke-width: 1.5; outline: none; }
.legend.scale { gap: 4px 12px; }
svg.mini { display: block; overflow: visible; }
svg.mini:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
svg .track-mini { fill: var(--surface-3); }
svg .tick { fill: var(--ink-2); }
svg .declared { fill: var(--ink); }
svg .fcrit { fill: var(--critical); }
.pf { display: flex; flex-wrap: wrap; gap: 3px; }
.pf-c {
  display: inline-grid;
  place-items: center;
  width: 17px;
  height: 17px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  color: #fff;
  text-decoration: none;
}
.pf-c:hover { text-decoration: none; filter: brightness(1.1); }
.pf-c.pass { background: var(--good); }
.pf-c.fail { background: var(--critical); }
.pf-c.running { background: var(--accent); }
.pf-c.cancelled, .pf-c.other { background: var(--surface-3); color: var(--ink-2); }
table.data.mainruns { table-layout: fixed; }
table.mainruns col.c-wf { width: 22%; }
table.mainruns col.c-strip { width: 38%; }
table.mainruns col.c-state { width: 16%; }
table.data td.wf { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alerts .age { margin-left: auto; white-space: nowrap; }
.note { margin-top: 10px !important; }
.nav a { padding: 6px 9px; }

/* ---- egress ---- */
.flags { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.flags li { overflow-wrap: anywhere; }
.scrollbox { max-height: 420px; overflow: auto; }
table.data td.name { max-width: 360px; overflow-wrap: anywhere; word-break: break-all; }
table.data td.detail { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid2.tight { gap: 12px; }
h2.section { font-size: 16px; margin-top: 8px; }
.alert-text { overflow-wrap: anywhere; }

@media (forced-colors: active) {
  svg .line { stroke: CanvasText; }
  .badge { border-color: CanvasText; }
}
