/* FlagMatrix Studio — Tokenized neutral UI (OpenDesigner tokens + self-hosted Geist Sans / Geist Mono) */
@font-face {
  font-family: "Geist";
  src: url("/fonts/Geist-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Geist Mono";
  src: url("/fonts/GeistMono-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Palette: neutral greyscale + one accent + semantic status only */
  --bg: #ffffff;
  --bg-subtle: #f4f4f5;
  --bg-muted: #f4f4f5;
  --bg-hover: #f4f4f5;
  --bg-active: #e4e4e7;
  --bg-code: #141417;

  --ink: #111113;
  --ink-2: #4b4b52;
  --ink-3: #5c5c64;

  --border: #e4e4e7;
  --border-subtle: #e4e4e7;
  --border-strong: #d4d4d8;
  --border-input: #c9c9cf;

  --accent: #1d4ed8;
  --accent-hover: #1e40af;
  --accent-subtle: #eff4ff;

  --pass: #15803d;
  --fail: #b91c1c;
  --warn: #b45309;

  /* Type scale: 12 / 13 / 14 / 16 / 20 / 28 */
  --font-sans: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --text-xs: 12px;
  --text-sm: 13px;
  --text-base: 14px;
  --text-md: 16px;
  --text-lg: 20px;
  --text-xl: 28px;

  /* 4px spacing grid */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;

  /* Radii & layout */
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 8px;

  --topbar-h: 48px;
  --rail-w: 236px;
  --shadow-overlay: 0 12px 32px rgba(17, 17, 19, 0.14), 0 0 0 1px var(--border);

  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
h1 {
  font-size: var(--text-xl);
  line-height: 1.2;
  font-weight: 600;
  letter-spacing: -0.02em;
  text-wrap: balance;
}
h2 {
  font-size: var(--text-md);
  line-height: 1.35;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-wrap: balance;
}
h3 {
  font-size: var(--text-base);
  line-height: 1.4;
  font-weight: 600;
}
a { color: var(--accent); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { color: var(--accent-hover); }
button { font: inherit; color: inherit; }
code, .mono {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.sr-only:not(:focus) {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
a.sr-only:focus {
  position: fixed;
  z-index: 60;
  top: var(--sp-3);
  left: var(--sp-3);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  padding: var(--sp-2) var(--sp-3);
}
.muted { color: var(--ink-3); }
.text-2 { color: var(--ink-2); }
.small { font-size: var(--text-sm); }
.xs { font-size: var(--text-xs); }
.tabular { font-variant-numeric: tabular-nums; }
.trunc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: 0 var(--sp-4);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-width: 0;
}
.icon-btn.menu-btn {
  display: none;
  flex: none;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--text-base);
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--ink);
  text-decoration: none;
  flex: none;
  min-height: 28px;
}
.brand:hover { color: var(--ink); }
.brand-mark {
  width: 16px;
  height: 16px;
  display: block;
  flex: none;
}
.topbar-sep {
  color: var(--ink-3);
  font-size: var(--text-sm);
  user-select: none;
  flex: none;
}
.topbar-crumbs {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
  font-size: var(--text-sm);
  color: var(--ink-2);
  overflow: hidden;
}
.topbar-crumbs a {
  color: var(--ink-2);
  text-decoration: none;
  white-space: nowrap;
}
.topbar-crumbs a:hover { color: var(--ink); text-decoration: underline; }
.topbar-crumbs .crumb-sep { color: var(--ink-3); flex: none; }
.topbar-crumbs .crumb-cur {
  color: var(--ink);
  font-weight: 600;
  white-space: nowrap;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  flex: none;
  font-size: var(--text-xs);
  color: var(--ink-2);
}
.conn-item {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  white-space: nowrap;
}

/* ---------- shell & sidebar ---------- */
.shell {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  min-height: calc(100vh - var(--topbar-h));
}
.rail {
  background: var(--bg-subtle);
  border-right: 1px solid var(--border);
  min-height: calc(100vh - var(--topbar-h));
}
.rail-inner {
  position: sticky;
  top: var(--topbar-h);
  max-height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: var(--sp-4) var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}
.rail-section-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--ink-3);
  padding: 0 var(--sp-2) var(--sp-2);
}
.app-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}
.app-link {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr) auto;
  gap: var(--sp-2);
  align-items: center;
  padding: var(--sp-2);
  border-radius: var(--r-md);
  text-decoration: none;
  color: var(--ink-2);
  min-height: 36px;
}
.app-link:hover {
  background: var(--bg-active);
  color: var(--ink);
}
.app-link[aria-current="page"] {
  background: var(--bg-active);
  color: var(--ink);
}
.app-link .app-name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.app-link .app-meta {
  font-size: var(--text-xs);
  color: var(--ink-3);
  white-space: nowrap;
}
.app-link[aria-current="page"] .app-meta {
  color: var(--ink-2);
}
.rail-add {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink-2);
  text-decoration: none;
  border-radius: var(--r-md);
  min-height: 36px;
}
.rail-add:hover {
  background: var(--bg-active);
  color: var(--ink);
}

/* ---------- status dots & glyphs ---------- */
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border-strong);
  display: inline-block;
  flex: none;
}
.dot.pass { background: var(--pass); }
.dot.fail { background: var(--fail); }
.dot.run { background: var(--warn); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.glyph-pass { color: var(--pass); }
.glyph-fail { color: var(--fail); }
.glyph-warn { color: var(--warn); }
.glyph-muted { color: var(--ink-3); }

.spinner {
  width: 13px;
  height: 13px;
  border: 1.75px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .75s linear infinite;
  display: inline-block;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner, .dot.run, .skel { animation: none !important; }
  * { transition: none !important; }
}

/* ---------- main content ---------- */
.main {
  padding: var(--sp-6) var(--sp-10) 64px;
  max-width: 1200px;
  width: 100%;
  min-width: 0;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--ink);
  padding: 0 var(--sp-3);
  height: 36px;
  border-radius: var(--r-md);
  cursor: pointer;
  font-size: var(--text-base);
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); border-color: var(--ink-3); color: var(--ink); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  font-size: var(--text-md);
  padding: 0 var(--sp-4);
}
.btn.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #ffffff;
}
.btn.quiet {
  border-color: transparent;
  background: transparent;
  color: var(--ink-2);
}
.btn.quiet:hover {
  background: var(--bg-hover);
  color: var(--ink);
}
.btn.sm {
  height: 32px;
  padding: 0 var(--sp-3);
  font-size: var(--text-sm);
}
.btn.link-btn {
  border: 0;
  background: transparent;
  padding: var(--sp-1) var(--sp-2);
  height: auto;
  min-height: 28px;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  border-radius: var(--r-sm);
}
.btn.link-btn:hover { color: var(--accent-hover); text-decoration: underline; background: transparent; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.icon-btn {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  background: transparent;
  border-radius: var(--r-md);
  cursor: pointer;
  color: var(--ink-2);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--ink); }
.icon-btn[disabled] { opacity: .35; cursor: default; }

/* ---------- page headers & sections ---------- */
.page-head {
  display: flex;
  gap: var(--sp-4) var(--sp-6);
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
}
.page-head-main {
  display: grid;
  gap: var(--sp-2);
  min-width: 0;
  flex: 1 1 360px;
}
.page-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2) var(--sp-3);
  font-size: var(--text-sm);
  color: var(--ink-2);
  max-width: 65ch;
}
.page-head .actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

.flow-inline {
  font-size: var(--text-sm);
  color: var(--ink-2);
  line-height: 1.5;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--sp-1) var(--sp-2);
}
.flow-inline .flow-name {
  color: var(--ink);
  font-weight: 600;
}
.flow-inline .flow-step {
  display: inline-flex;
  align-items: baseline;
  gap: var(--sp-2);
}
.flow-inline .arrow { color: var(--ink-3); }

.section-stack {
  display: grid;
  gap: var(--sp-8);
  margin-top: var(--sp-6);
}
.section {
  padding-top: var(--sp-6);
  border-top: 1px solid var(--border);
  display: grid;
  gap: var(--sp-3);
}
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
}
.section-lede {
  font-size: var(--text-sm);
  color: var(--ink-2);
  max-width: 65ch;
}

/* ---------- quiet inline status / notices (no left stripes, no tinted card soup) ---------- */
.notice {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  gap: var(--sp-1) var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg);
  font-size: var(--text-sm);
  align-items: start;
}
.notice svg { margin-top: 2px; }
.notice.error { border-color: #f3c6c6; }
.notice.error svg { color: var(--fail); }
.notice.warn { border-color: #eed8b3; }
.notice.warn svg { color: var(--warn); }
.notice.ok svg { color: var(--pass); }
.notice.info svg { color: var(--accent); }
.notice-title { font-weight: 600; color: var(--ink); }
.notice-body { grid-column: 2; color: var(--ink-2); max-width: 65ch; }

/* ---------- latest run strip on app page ---------- */
.latest-strip {
  display: grid;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg-subtle);
}
.latest-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
}
.latest-counts {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  font-size: var(--text-sm);
  font-weight: 600;
}
.latest-links {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-size: var(--text-sm);
}
.latest-links a { text-decoration: none; font-weight: 600; }
.latest-links a:hover { text-decoration: underline; }
.fail-lines {
  margin: 0;
  padding-left: var(--sp-4);
  display: grid;
  gap: var(--sp-1);
  font-size: var(--text-sm);
  color: var(--ink-2);
  max-width: 65ch;
}
.fail-lines li::marker { color: var(--fail); }

/* ---------- clean data tables ---------- */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  text-align: left;
}
.data-table th {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--ink-3);
  background: var(--bg-subtle);
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: var(--sp-3);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
  color: var(--ink);
}
.data-table tr:last-child td { border-bottom: 0; }
.data-table th.num, .data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tbody tr.clickable { cursor: pointer; }
.data-table tbody tr.clickable:hover td { background: var(--bg-hover); }

.cell-title { font-weight: 600; color: var(--ink); }
.cell-sub { font-size: var(--text-xs); color: var(--ink-3); margin-top: var(--sp-1); }
.variant-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1) var(--sp-4);
}
.variant-item {
  display: inline-flex;
  align-items: baseline;
  gap: var(--sp-1);
  white-space: nowrap;
}
.variant-item.is-control { font-weight: 600; }
.split-bar {
  display: flex;
  height: 4px;
  border-radius: 2px;
  overflow: hidden;
  background: var(--bg-muted);
  gap: 0;
  margin-top: var(--sp-2);
  max-width: 240px;
}
.split-bar i { display: block; background: var(--ink-3); }
.split-bar i:nth-child(1) { background: var(--ink); }
.split-bar i:nth-child(2) { background: var(--accent); }
.split-bar i:nth-child(3) { background: #6085ea; }
.split-bar i:nth-child(n+4) { background: #a4b9f3; }

.trait-line {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1) var(--sp-3);
  margin-top: var(--sp-1);
}
.precedence {
  font-size: var(--text-sm);
  color: var(--ink-2);
  max-width: 72ch;
}
.precedence strong { font-weight: 600; color: var(--ink); }
.precedence .arrow { color: var(--ink-3); padding: 0 var(--sp-1); }

/* ---------- versions summary + expandable list ---------- */
.versions-bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
}
.version-list {
  list-style: none;
  margin: var(--sp-2) 0 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.version-list li {
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  gap: var(--sp-3);
  font-size: var(--text-sm);
}
.version-list li:last-child { border-bottom: 0; }

/* ---------- disclosures (only for secondary/technical details) ---------- */
details.disclosure {
  border-top: 1px solid var(--border);
  padding-top: var(--sp-3);
}
details.disclosure > summary {
  cursor: pointer;
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--ink-2);
  list-style: none;
  display: inline-flex;
  gap: var(--sp-2);
  align-items: center;
  min-height: 28px;
}
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary::before {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform .15s;
  margin-left: 2px;
}
details.disclosure[open] > summary::before { transform: rotate(45deg); }
details.disclosure > .body { margin-top: var(--sp-3); display: grid; gap: var(--sp-3); }

.kv {
  display: grid;
  grid-template-columns: minmax(0, 180px) minmax(0, 1fr);
  gap: var(--sp-2) var(--sp-4);
  font-size: var(--text-sm);
}
pre.code {
  margin: 0;
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-code);
  color: #e4e4e7;
  border-radius: var(--r-md);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.55;
}

/* ---------- run page header + quiet impact & safety lines ---------- */
.run-header {
  display: grid;
  gap: var(--sp-2);
  padding-bottom: var(--sp-3);
  border-bottom: 1px solid var(--border);
}
.run-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3) var(--sp-4);
  flex-wrap: wrap;
}
.run-title-group {
  display: flex;
  align-items: baseline;
  gap: var(--sp-1) var(--sp-3);
  flex-wrap: wrap;
  min-width: 0;
}
.run-title-row .actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
}
.run-counts {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink-2);
}
.run-counts .count-pass { color: var(--pass); }
.run-counts .count-fail { color: var(--fail); }
.run-counts .count-run { color: var(--warn); }
.count-sep { color: var(--ink-3); }

.progress {
  width: 100%;
  max-width: 420px;
  height: 4px;
  border: 0;
  border-radius: 2px;
  accent-color: var(--accent);
}
.progress::-webkit-progress-bar { background: var(--bg-muted); border-radius: 2px; }
.progress::-webkit-progress-value { background: var(--accent); border-radius: 2px; }

.run-meta-lines {
  display: grid;
  gap: var(--sp-1);
  margin-top: var(--sp-2);
}
.meta-line {
  display: grid;
  gap: var(--sp-2);
  font-size: var(--text-sm);
}
.meta-line-row {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  gap: var(--sp-1) var(--sp-2);
  align-items: start;
  color: var(--ink-2);
}
.meta-line-row svg { margin-top: 3px; }
.meta-line-text {
  display: flex;
  align-items: baseline;
  gap: var(--sp-1) var(--sp-2);
  flex-wrap: wrap;
}
.meta-line-text .btn.link-btn {
  padding: 0 var(--sp-1);
  min-height: 22px;
  font-size: var(--text-xs);
}
.meta-line-row.ok svg { color: var(--pass); }
.meta-line-row.bad svg { color: var(--fail); }
.meta-line-row.warn svg, .meta-line-row.unknown svg { color: var(--warn); }
.meta-line-detail {
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg-subtle);
  display: grid;
  gap: var(--sp-2);
  font-size: var(--text-sm);
  color: var(--ink-2);
  max-width: 75ch;
}
.meta-line-detail strong { color: var(--ink); font-weight: 600; }

/* ---------- THE MATRIX ---------- */
.matrix-section {
  margin-top: var(--sp-4);
  display: grid;
  gap: var(--sp-5);
}
.matrix-block {
  display: grid;
  gap: var(--sp-2);
}
.matrix-block-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
}
.matrix-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg);
}
.matrix-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  min-width: 720px;
}
.matrix-table thead th {
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border-subtle);
  padding: 6px var(--sp-3);
  text-align: left;
  vertical-align: bottom;
  font-weight: 600;
}
.matrix-table thead th:last-child { border-right: 0; }
.matrix-table thead th.col-rowhead {
  width: 210px;
  font-size: var(--text-xs);
  color: var(--ink-3);
}
.col-head-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-2);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink);
}
.col-head-sub {
  font-size: var(--text-xs);
  font-weight: 400;
  color: var(--ink-3);
  margin-top: 2px;
}

.matrix-table tbody th {
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  background: var(--bg);
  font-weight: 400;
}
.matrix-table tbody tr:last-child th,
.matrix-table tbody tr:last-child td { border-bottom: 0; }
.row-head-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink);
  line-height: 1.35;
}
.row-head-sub {
  font-size: var(--text-xs);
  color: var(--ink-3);
  margin-top: var(--sp-1);
  line-height: 1.35;
}

.matrix-table tbody td {
  padding: 6px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border-subtle);
  vertical-align: top;
  background: var(--bg);
}
.matrix-table tbody td:last-child { border-right: 0; }
.matrix-table tbody td.cell-stack {
  display: grid;
  gap: var(--sp-2);
}

/* Matrix cell button */
.m-cell {
  display: grid;
  justify-items: start;
  align-content: start;
  gap: 6px;
  width: 100%;
  padding: 6px 8px;
  margin: 0;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  text-align: left;
  cursor: pointer;
  color: inherit;
}
.m-cell:hover {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
}
.m-cell:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.m-cell.is-fail {
  background: #fffafa;
  border-color: var(--fail);
}
.m-cell.is-fail:hover {
  border-color: var(--fail);
}
.m-cell .shot {
  position: relative;
  width: 168px;
  max-width: 100%;
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  overflow: hidden;
}
.m-cell .shot.is-phone {
  width: 72px;
  border-radius: 9px;
  border-color: var(--border-strong);
}
.m-cell:not(.is-fail) .shot img {
  opacity: 0.72;
  filter: saturate(0.35);
  transition: opacity .15s, filter .15s;
}
.m-cell:hover .shot img {
  opacity: 1;
  filter: none;
}
.m-cell.is-fail .shot { border-color: var(--fail); }
.m-cell .shot img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top;
}
.m-cell .shot .ph {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--sp-2);
  font-size: var(--text-xs);
  color: var(--ink-3);
  text-align: center;
}
.m-cell-foot {
  display: grid;
  justify-items: start;
  gap: 2px;
  width: 100%;
  min-width: 0;
}
.m-cell-state {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
}
.m-cell-state.pass { color: var(--pass); }
.m-cell-state.fail { color: var(--fail); }
.m-cell-state.run { color: var(--warn); }
.m-cell-state.queued { color: var(--ink-3); }
.m-cell-dim {
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.35;
  color: var(--ink-3);
  max-width: 100%;
  overflow-wrap: anywhere;
}
.m-cell-why {
  font-size: var(--text-xs);
  line-height: 1.35;
  color: var(--fail);
  text-wrap: pretty;
}
.m-cell-empty {
  height: 100%;
  min-height: 96px;
  display: grid;
  place-items: center;
  padding: var(--sp-3);
  border-radius: var(--r-sm);
  background: var(--bg-subtle);
  color: var(--ink-3);
  font-size: var(--text-xs);
  text-align: center;
  cursor: default;
}

.hl {
  position: absolute;
  border: 2px solid var(--fail);
  border-radius: 2px;
  pointer-events: none;
}

/* Also tested row (phone / extra viewports, same cell style as the matrix) */
.also-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
}
.m-cell.m-cell-extra {
  width: 260px;
  padding: var(--sp-3);
  border-color: var(--border);
  border-radius: var(--r-md);
  background: var(--bg);
}
.m-cell.m-cell-extra:hover {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
}
.m-cell.m-cell-extra.is-fail {
  background: #fffafa;
  border-color: var(--fail);
}
.m-cell-extra-who {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--ink-2);
  line-height: 1.35;
}

/* ---------- right-side inspector drawer ---------- */
.drawer {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(640px, 100%);
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: var(--sp-6) var(--sp-6) var(--sp-10);
  border: 0;
  border-left: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
  overflow-y: auto;
  overscroll-behavior: contain;
  box-shadow: var(--shadow-overlay);
}
body:has(.drawer[open]) { overflow: hidden; }
.drawer[open] { display: flex; flex-direction: column; gap: var(--sp-5); }
.drawer::backdrop { background: rgba(17, 17, 19, 0.35); }
.drawer > * { flex: none; }
.drawer-head {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-3);
  align-items: flex-start;
  padding-bottom: var(--sp-4);
  border-bottom: 1px solid var(--border);
}
.drawer-head-titles { display: grid; gap: var(--sp-1); min-width: 0; }
.drawer-status {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--text-xs);
  font-weight: 600;
}
.drawer-status.pass { color: var(--pass); }
.drawer-status.fail { color: var(--fail); }
.drawer-status.run { color: var(--warn); }
.drawer-head h2 { font-size: var(--text-lg); line-height: 1.3; overflow-wrap: anywhere; }

.callout {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  gap: var(--sp-1) var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid #f3c6c6;
  border-radius: var(--r-md);
  background: var(--bg);
  align-items: start;
}
.callout svg { color: var(--fail); margin-top: 2px; }
.callout .t { font-weight: 600; font-size: var(--text-base); color: var(--ink); }
.callout .sub { grid-column: 2; font-size: var(--text-sm); color: var(--ink-2); }

.drawer-evidence { display: grid; gap: var(--sp-2); margin: 0; }
.drawer .big-shot {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--bg-muted);
  width: 100%;
}
.drawer .big-shot.phone { max-width: 260px; }
.drawer .big-shot img { display: block; width: 100%; height: 100%; }
.drawer .hl {
  border: 2.5px solid var(--fail);
  box-shadow: inset 0 0 0 1px #ffffff, 0 0 0 9999px rgba(17, 17, 19, 0.2);
}
.evidence-label {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--ink-2);
  font-size: var(--text-xs);
  font-weight: 600;
}
.evidence-label span {
  width: 12px;
  height: 9px;
  border: 2px solid var(--fail);
  border-radius: 2px;
  flex: none;
}

.step-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.step-list li {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto auto;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--border-subtle);
  align-items: center;
  font-size: var(--text-sm);
}
.step-list li:last-child { border-bottom: 0; }
.step-list .mark { display: grid; place-items: center; }
.step-list li.passed .mark { color: var(--pass); }
.step-list li.failed .mark { color: var(--fail); }
.step-list li.skipped { color: var(--ink-3); }
.step-list .dur { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--ink-3); }
.step-list .thumb { font-size: var(--text-xs); }

/* ---------- forms / setup / flow builder ---------- */
.stepper {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2) 0;
  list-style: none;
  padding: 0;
  margin: 0;
  counter-reset: s;
  font-size: var(--text-sm);
}
.stepper li {
  counter-increment: s;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--ink-3);
  padding-right: var(--sp-3);
}
.stepper li::before {
  content: counter(s);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  display: grid;
  place-items: center;
  font-size: var(--text-xs);
  font-weight: 600;
  background: var(--bg);
}
.stepper li[aria-current="step"] { color: var(--ink); font-weight: 600; }
.stepper li[aria-current="step"]::before {
  background: var(--ink);
  color: #ffffff;
  border-color: var(--ink);
}
.stepper li.done { color: var(--ink-2); }
.stepper li.done::before {
  content: "";
  background: var(--ink-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 6.2l2.4 2.3 4.6-5' fill='none' stroke='white' stroke-width='1.6'/%3E%3C/svg%3E") center/11px no-repeat;
  border-color: var(--ink-2);
}
.stepper li:not(:last-child)::after {
  content: "";
  width: 16px;
  height: 1px;
  background: var(--border);
  margin-left: var(--sp-1);
}

.form { display: grid; gap: var(--sp-5); max-width: 640px; }
.field { display: grid; gap: var(--sp-2); }
.field > label, .field > .label { font-weight: 600; font-size: var(--text-sm); color: var(--ink); }
.field .hint { font-size: var(--text-sm); color: var(--ink-3); max-width: 65ch; }

input[type=text], input[type=url], input[type=search], select, textarea {
  width: 100%;
  font-family: inherit;
  font-size: var(--text-base);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border-input);
  border-radius: var(--r-md);
  background: var(--bg);
  color: var(--ink);
  min-height: 36px;
}
textarea {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.55;
  min-height: 220px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 0;
  border-color: var(--accent);
}

.choice-list { display: grid; gap: var(--sp-2); }
.choice {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: var(--sp-3);
  padding: var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg);
  cursor: pointer;
  align-items: start;
}
.choice:hover { border-color: var(--border-strong); background: var(--bg-subtle); }
.choice:has(input:checked) {
  border-color: var(--accent);
  background: var(--bg);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.choice:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.choice input { margin: 3px 0 0; accent-color: var(--accent); }
.choice .t { font-weight: 600; font-size: var(--text-base); }
.choice .d { font-size: var(--text-sm); color: var(--ink-2); }

.steps-edit {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--sp-2);
  counter-reset: st;
}
.step-row {
  counter-increment: st;
  display: grid;
  grid-template-columns: 24px minmax(130px, 170px) minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: var(--sp-2);
  align-items: center;
  padding: var(--sp-2);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.step-row::before { content: counter(st); color: var(--ink-3); font-size: var(--text-xs); font-weight: 600; text-align: center; }
.step-row .row-actions { display: flex; gap: 2px; }
.step-row .f-label { grid-column: 2 / -1; }

/* ---------- empty states & skeletons ---------- */
.empty {
  padding: var(--sp-10) 0;
  max-width: 52ch;
  display: grid;
  gap: var(--sp-3);
}
.empty h1, .empty h2 { font-size: var(--text-lg); }
.empty p { color: var(--ink-2); font-size: var(--text-base); }

.skeleton-wrap { display: grid; gap: var(--sp-6); }
.skel {
  background: var(--bg-muted);
  border-radius: var(--r-sm);
  animation: skelPulse 1.4s ease-in-out infinite;
}
@keyframes skelPulse { 50% { opacity: .55; } }
.skel-head { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-4); }
.skel-title { height: 28px; width: 220px; }
.skel-btn { height: 36px; width: 132px; border-radius: var(--r-md); }
.skel-sub { height: 16px; width: 340px; max-width: 100%; }
.skel-table { height: 180px; width: 100%; border-radius: var(--r-md); }

.toast {
  position: fixed;
  left: 50%;
  bottom: var(--sp-5);
  transform: translateX(-50%);
  background: var(--ink);
  color: #ffffff;
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--r-md);
  font-size: var(--text-sm);
  z-index: 60;
  max-width: min(92vw, 520px);
  box-shadow: var(--shadow-overlay);
}

/* ---------- mobile (<= 860px) ---------- */
@media (max-width: 860px) {
  .topbar { padding: 0 var(--sp-3); gap: var(--sp-2); }
  .icon-btn.menu-btn { display: grid; }
  .topbar-sep, .topbar-crumbs { display: none; }
  .conn-label-extra { display: none; }

  .shell { grid-template-columns: 1fr; }
  .rail {
    position: fixed;
    z-index: 40;
    inset: var(--topbar-h) auto 0 0;
    width: min(280px, 85vw);
    height: calc(100vh - var(--topbar-h));
    transform: translateX(-102%);
    transition: transform .18s ease-out;
    box-shadow: var(--shadow-overlay);
    visibility: hidden;
  }
  body.nav-open .rail { transform: none; visibility: visible; }

  .main { padding: var(--sp-5) var(--sp-4) 64px; }
  h1 { font-size: 24px; }
  .btn, .icon-btn, .app-link, .rail-add { min-height: 44px; }
  .btn.link-btn { min-height: 44px; display: inline-flex; align-items: center; }
  .run-title-row { flex-direction: column; align-items: flex-start; gap: var(--sp-2); }
  .run-title-group { flex-direction: column; align-items: flex-start; gap: var(--sp-1); }
  .meta-line-text { display: block; line-height: 1.45; }
  .meta-line-text .btn.link-btn {
    padding: 0;
    min-height: 44px;
    margin: -10px 0 -10px var(--sp-2);
    vertical-align: baseline;
    font-size: var(--text-sm);
  }
  .matrix-table { min-width: 640px; }
  .matrix-table thead th.col-rowhead { width: 144px; }
  .m-cell .shot { width: 148px; }
  .m-cell .shot.is-phone { width: 72px; }
  .m-cell.m-cell-extra { width: 100%; }
  .kv { grid-template-columns: 1fr; }
  .step-row { grid-template-columns: 20px 1fr auto; }
  .step-row > .f-type { grid-column: 2 / 3; }
  .step-row .row-actions { grid-column: 3; grid-row: 1; }
  .step-row > .f-a, .step-row > .f-b { grid-column: 2 / -1 !important; }
  .stepper li:not(:last-child)::after { display: none; }
  .stepper { gap: var(--sp-2) var(--sp-3); }
  .drawer {
    inset: 0;
    width: 100%;
    height: 100dvh;
    max-width: 100%;
    max-height: 100dvh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding: 0 var(--sp-4) var(--sp-8);
  }
  .drawer-head {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--bg);
    padding: var(--sp-4) 0 var(--sp-3);
  }
  .drawer-head > button { flex: none; }
}
