/* ═══════════════════════════════════════════════════════════════════════════
   Mergestro control plane — component layer for THE TRACE
   ═══════════════════════════════════════════════════════════════════════════
   Housing is dark; the chart paper is the only lit surface. Every interactive
   component here carries the seven states Operate mode requires — default,
   hover, focus, active, disabled, loading, error — and no state is signalled by
   hue alone, so a console stays readable when it is dimmed, printed, or read by
   someone who cannot separate red from green.
   ═══════════════════════════════════════════════════════════════════════════ */

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background: hsl(var(--bg-page));
  color: hsl(var(--foreground));
  font-family: var(--font-sans);
  font-size: var(--t-base);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
}

/* The housing carries a faint machined grain. It never touches the paper. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image: repeating-linear-gradient(
    0deg, hsl(var(--foreground) / 0.014) 0 1px, transparent 1px 3px);
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: hsl(var(--border-strong));
  border-radius: var(--r-lg);
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-track { background: transparent; }

button, input { font-family: var(--font-sans); }

/* One focus treatment for the whole console. Never removed, never subtle. */
:focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease);
}
.btn-sm { height: 26px; padding: 0 10px; font-size: var(--t-sm); }
.btn-md { height: 32px; padding: 0 13px; font-size: var(--t-base); }
.btn-lg { height: 40px; padding: 0 18px; font-size: var(--t-md); }
.btn-full { width: 100%; }

.btn-primary { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.btn-primary:hover { background: hsl(var(--primary) / 0.86); }
.btn-primary:active { background: hsl(var(--primary) / 0.74); }

.btn-neutral {
  background: hsl(var(--card));
  color: hsl(var(--fg-soft));
  border-color: hsl(var(--border-strong));
}
.btn-neutral:hover { background: hsl(var(--card-2)); color: hsl(var(--foreground)); }
.btn-neutral:active { background: hsl(var(--card-3)); }

/* Destructive reads as destructive before it is pressed, not after. */
.btn-kill {
  background: transparent;
  color: hsl(var(--alarm));
  border-color: hsl(var(--alarm) / 0.55);
}
.btn-kill:hover { background: hsl(var(--alarm) / 0.14); border-color: hsl(var(--alarm)); }
.btn-kill:active { background: hsl(var(--alarm) / 0.22); }

.btn:disabled, .btn[aria-disabled="true"] {
  opacity: 0.42;
  cursor: not-allowed;
  filter: saturate(0.4);
}
.btn[data-loading="true"] { cursor: progress; opacity: 0.7; }
.btn .icon { flex-shrink: 0; }

/* ── The chart strip ──────────────────────────────────────────────────────────
   The core component. A strip of time-ruled paper: repo in the margin, the
   trace across it, a NOW edge on the right. This is the lit surface — nothing
   else on the page competes with it. */
.strip {
  display: grid;
  grid-template-columns: 190px 1fr;
  background: hsl(var(--paper));
  border: 1px solid hsl(var(--paper-edge));
  border-radius: var(--r-sm);
  overflow: hidden;
  box-shadow: var(--shadow-panel);
}
.strip + .strip { margin-top: 6px; }

.strip__margin {
  padding: 10px 12px;
  border-right: 1px solid hsl(var(--paper-edge));
  background: hsl(var(--paper-ruled));
  min-width: 0;
}
.strip__repo {
  font-family: var(--font-mono);
  font-size: var(--t-base);
  font-weight: 600;
  color: hsl(var(--ink));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.strip__meta {
  font-size: var(--t-xs);
  color: hsl(var(--ink) / 0.62);
  margin-top: 3px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.strip__plot { position: relative; min-width: 0; }
.strip__plot svg { display: block; width: 100%; height: 68px; }

/* Time rules, printed on the paper the way a chart roll is. */
.strip__plot::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    90deg, hsl(var(--rule) / 0.16) 0 1px, transparent 1px 56px);
}
/* The NOW edge. */
.strip__plot::after {
  content: "";
  position: absolute;
  top: 0; bottom: 0; right: 0;
  width: 2px;
  background: hsl(var(--rule) / 0.7);
}

/* A repo that stopped reporting. The flatline is the product's whole point, so
   it is stated in words as well as drawn — never colour or shape alone. */
.strip--quiet { filter: saturate(0.25); }
.strip--quiet .strip__repo { color: hsl(var(--ink) / 0.55); }

.axis {
  display: flex;
  justify-content: space-between;
  padding: 4px 12px 0 202px;
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  color: hsl(var(--muted-2));
}

/* ── Readout ──────────────────────────────────────────────────────────────────
   Replaces the stat card. Deliberately NOT the hero-metric template: the label
   leads, the number is mono and modest, and the qualifier sits with it rather
   than as decorative sub-text. A console is read by scanning many values, not
   by admiring one. */
.readout {
  padding: 10px 14px;
  border-left: 1px solid hsl(var(--border));
  min-width: 0;
}
.readout:first-child { border-left: none; }
.readout__label {
  font-size: var(--t-xs);
  text-transform: uppercase;
  letter-spacing: var(--eyebrow-tracking);
  color: hsl(var(--muted-foreground));
  white-space: nowrap;
}
.readout__value {
  font-family: var(--font-mono);
  font-size: var(--t-xl);
  font-weight: 600;
  line-height: var(--lh-tight);
  margin-top: 3px;
  color: hsl(var(--foreground));
  font-variant-numeric: tabular-nums;
}
.readout__value.is-alarm { color: hsl(var(--alarm)); }
.readout__value.is-pass { color: hsl(var(--pass)); }
.readout__value.is-degraded { color: hsl(var(--degraded)); }
.readout__note {
  font-size: var(--t-xs);
  color: hsl(var(--muted-2));
  margin-top: 2px;
}
.readout-bank {
  display: flex;
  flex-wrap: wrap;
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--r-lg);
  overflow: hidden;
}
.readout-bank > .readout { flex: 1 1 130px; }

/* Legacy statcard, restyled so any un-migrated call site inherits the console
   rather than the old dashboard. */
.statcard {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--r-lg);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.statcard .value {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: var(--t-xl);
  line-height: var(--lh-tight);
  font-variant-numeric: tabular-nums;
}
.statcard .label {
  font-size: var(--t-xs);
  text-transform: uppercase;
  letter-spacing: var(--eyebrow-tracking);
  color: hsl(var(--muted-foreground));
}
.statcard .sub { font-family: var(--font-mono); font-size: var(--t-xs); color: hsl(var(--muted-2)); }

/* ── Live dot / avatar ───────────────────────────────────────────────────── */
.livedot { display: inline-flex; align-items: center; gap: 7px; font-size: var(--t-sm); color: hsl(var(--fg-soft)); }
.livedot .dot { width: 7px; height: 7px; border-radius: 50%; animation: awol-pulse 2s ease-in-out infinite; }

.avatar {
  border-radius: var(--r-sm);
  background: hsl(var(--card-2));
  color: hsl(var(--fg-soft));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  font-weight: 600;
  flex-shrink: 0;
}

/* ── Pills ────────────────────────────────────────────────────────────────── */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: var(--r-sm);
  border: 1px solid currentcolor;
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  font-weight: 500;
  white-space: nowrap;
}
.pill .dot { width: 5px; height: 5px; border-radius: 50%; background: currentcolor; }
.pill .dot.pulse { animation: awol-pulse 1.6s ease-in-out infinite; }

/* ── Panels ──────────────────────────────────────────────────────────────── */
.card {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--r-lg);
  overflow: hidden;
}
.card-head {
  padding: 10px 14px;
  border-bottom: 1px solid hsl(var(--border));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: hsl(var(--housing-raised));
}
.eyebrow {
  font-size: var(--t-xs);
  text-transform: uppercase;
  letter-spacing: var(--eyebrow-tracking);
  color: hsl(var(--muted-foreground));
  font-weight: 600;
}
.h-display {
  font-family: var(--font-sans);
  font-weight: 600;
  letter-spacing: var(--display-tracking);
  line-height: var(--lh-tight);
  font-size: var(--t-xl);
  margin: 0;
}
.screen-sub {
  font-size: var(--t-base);
  color: hsl(var(--muted-foreground));
  margin-top: 4px;
  max-width: 78ch;
}
.mono { font-family: var(--font-mono); }

/* ── Inputs ──────────────────────────────────────────────────────────────── */
.input {
  width: 100%;
  background: hsl(var(--input));
  border: 1px solid hsl(var(--border-strong));
  color: hsl(var(--foreground));
  padding: 8px 11px;
  border-radius: var(--r-md);
  font-size: var(--t-base);
  font-family: var(--font-mono);
  outline: none;
}
.input:focus-visible { border-color: hsl(var(--ring)); outline-offset: 1px; }
.input[aria-invalid="true"] { border-color: hsl(var(--alarm)); }
.input:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Rail ────────────────────────────────────────────────────────────────── */
.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  cursor: pointer;
  font-size: var(--t-base);
  background: transparent;
  color: hsl(var(--fg-soft));
  font-weight: 500;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.nav-btn:hover { background: hsl(var(--card-2)); color: hsl(var(--foreground)); }
/* Selection is a lit edge on the housing, not a filled tab. */
.nav-btn.active {
  background: hsl(var(--card-2));
  color: hsl(var(--foreground));
  border-color: hsl(var(--border-strong));
  box-shadow: inset 2px 0 0 hsl(var(--primary));
  font-weight: 600;
}
.nav-badge {
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  font-weight: 600;
  padding: 0 6px;
  border-radius: var(--r-sm);
  background: hsl(var(--card-3));
  color: hsl(var(--fg-soft));
  margin-left: auto;
}
.nav-btn.active .nav-badge { background: hsl(var(--primary) / 0.2); color: hsl(var(--primary)); }

/* ── Chips ───────────────────────────────────────────────────────────────── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: var(--r-md);
  border: 1px solid hsl(var(--border-strong));
  cursor: pointer;
  font-size: var(--t-sm);
  font-weight: 500;
  background: transparent;
  color: hsl(var(--muted-foreground));
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.chip:hover { color: hsl(var(--foreground)); background: hsl(var(--card-2)); }
.chip.active {
  background: hsl(var(--card-3));
  color: hsl(var(--foreground));
  border-color: hsl(var(--foreground) / 0.5);
}
.chip .count { font-family: var(--font-mono); font-size: var(--t-xs); opacity: 0.75; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.grid-head {
  display: grid;
  gap: 12px;
  padding: 8px 16px;
  border-bottom: 1px solid hsl(var(--border));
  font-size: var(--t-xs);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: hsl(var(--muted-2));
  background: hsl(var(--housing-raised));
}
.grid-row {
  display: grid;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid hsl(var(--border));
  align-items: center;
}
.grid-row:last-child, .list-row:last-child { border-bottom: none; }
.list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid hsl(var(--border));
}
.row-click { cursor: pointer; transition: background var(--dur-fast) var(--ease); }
.row-click:hover { background: hsl(var(--card-2)); }
.row-click:focus-visible { background: hsl(var(--card-2)); }

/* A PR reference that opens its own dependency slice. It is a real <button>, so
   it is tabbable and announced as a control; the underline only appears on hover
   or focus, because a wall of permanently-underlined mono in a dense table reads
   as noise rather than as affordance. */
.linkish {
  border: none;
  background: transparent;
  padding: 0;
  color: inherit;
  font-family: var(--font-mono);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 3px;
  transition: text-decoration-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.linkish:hover { color: hsl(var(--primary)); text-decoration-color: currentColor; }
.linkish:focus-visible { color: hsl(var(--primary)); text-decoration-color: currentColor; }

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  background: hsl(var(--housing-raised));
  border: 1px solid hsl(var(--border-strong));
  color: hsl(var(--foreground));
  padding: 9px 16px;
  border-radius: var(--r-md);
  font-size: var(--t-base);
  box-shadow: var(--shadow-pop);
  display: flex;
  align-items: center;
  gap: 9px;
}
.toast .dot { width: 6px; height: 6px; border-radius: 50%; background: hsl(var(--primary)); }

/* ── Confirm ──────────────────────────────────────────────────────────────────
   Kill ejects a batch. It gets a confirmation, inline rather than modal, and
   the confirming control names the act rather than saying "OK". */
.confirm {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid hsl(var(--alarm) / 0.5);
  background: hsl(var(--alarm) / 0.09);
  border-radius: var(--r-md);
  font-size: var(--t-sm);
  color: hsl(var(--foreground));
}
.confirm__q { flex: 1; min-width: 0; }

/* ── Empty & loading ──────────────────────────────────────────────────────────
   An empty state teaches the interface. It says what would fill this and how,
   never "no data". */
.empty {
  padding: 20px 16px;
  color: hsl(var(--muted-foreground));
  font-size: var(--t-base);
}
.empty strong { color: hsl(var(--fg-soft)); font-weight: 600; display: block; margin-bottom: 3px; }
.empty code {
  font-family: var(--font-mono);
  font-size: var(--t-sm);
  background: hsl(var(--card-2));
  padding: 1px 5px;
  border-radius: var(--r-sm);
}

.skeleton {
  background: linear-gradient(90deg,
    hsl(var(--card-2)) 0%, hsl(var(--card-3)) 50%, hsl(var(--card-2)) 100%);
  background-size: 200% 100%;
  animation: awol-shimmer 1.4s linear infinite;
  border-radius: var(--r-sm);
}
@keyframes awol-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

/* ── Heat bar — edge failure rate. Width carries the value, a printed number
      repeats it, so the bar is never the only encoding. ───────────────────── */
.heat {
  height: 5px;
  border-radius: var(--r-sm);
  background: hsl(var(--card-3));
  overflow: hidden;
}
.heat__fill { height: 100%; background: hsl(var(--alarm)); }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.shell { display: flex; min-height: 100vh; position: relative; z-index: 1; }
.rail {
  width: 236px;
  flex-shrink: 0;
  border-right: 1px solid hsl(var(--border));
  background: hsl(var(--housing-raised));
  display: flex;
  flex-direction: column;
}
.screen-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.screen-main { flex: 1; overflow-y: auto; padding: 22px 26px 56px; }

.two-col { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 1100px) {
  .two-col { grid-template-columns: minmax(0, 1fr); }
  .rail { width: 64px; }
  .rail .rail-label, .nav-btn span:not(.nav-badge) { display: none; }
  /* The batch footer, its action group and the kill confirmation are three
     nested non-wrapping flex rows. Narrow, the confirmation question and both
     buttons stay on one line and push Cancel off-screen — you would have to
     scroll sideways to back out of a destructive action. Let all three wrap, and
     give the question its own row so the two buttons stay side by side. */
  .batch-foot, .batch-actions, .confirm { flex-wrap: wrap; }
  .confirm__q { flex: 1 0 100%; }
}

/* F.3/F.4 — the audit and key tables. Plain semantic tables (the data is genuinely tabular),
   styled to the same housing the grid rows use. */
.table { width: 100%; border-collapse: collapse; background: hsl(var(--card)); border: 1px solid hsl(var(--border)); border-radius: var(--r-lg); overflow: hidden; }
.table th {
  text-align: left; padding: 9px 14px; font-size: var(--t-xs); text-transform: uppercase;
  letter-spacing: 0.07em; color: hsl(var(--muted-2)); background: hsl(var(--housing-raised));
  border-bottom: 1px solid hsl(var(--border));
}
.table td { padding: 9px 14px; font-size: var(--t-sm); border-bottom: 1px solid hsl(var(--border)); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }

/* The ORDER guide: four strategies that pair naturally — two ordered by time, two
   by blast radius. `auto-fit` fitted three across on a wide card and left the
   fourth alone on its own row, which reads as a layout bug and breaks the pairing.
   Two columns, or one when there is no room for two. */
.strategy-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 22px; }
@media (max-width: 780px) { .strategy-grid { grid-template-columns: 1fr; } }

/* Forge links. A PR number that opens the PR — the console's numbers were dead ends, and an
   operator checking one had to reconstruct the URL by hand.

   Deliberately not styled as a classic link: these sit inside dense mono rows, and blue-and-
   underlined on every PR number would turn the board into a wall of decoration. Inherited
   colour, underline on hover only, and the arrow glyph carries the "leaves this page" signal
   that `target=_blank` otherwise gives no warning of. */
.ext-link {
  color: inherit;
  text-decoration: none;
  border-radius: var(--r-sm, 3px);
}
.ext-link:hover,
.ext-link:focus-visible {
  color: hsl(var(--primary));
  text-decoration: underline;
  text-underline-offset: 2px;
}
/* Keyboard users get the same affordance as the mouse: the row is dense, so the ring is what
   says which of a dozen numbers is about to open. */
.ext-link:focus-visible {
  outline: 2px solid hsl(var(--primary) / 0.55);
  outline-offset: 2px;
}

/* ── Sidebar: settings group, collapse, and the icon buttons in the user row ───────────────── */

/* The group header reads as a row, not a nav item: same metrics, no active state, and a caret
   that turns. It is a <button> because it toggles rather than navigates. */
.nav-group {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 10px;
  margin-top: 6px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: transparent;
  cursor: pointer;
  font-size: var(--t-base);
  font-family: inherit;
  color: hsl(var(--muted-foreground));
}
.nav-group:hover { background: hsl(var(--card-2)); color: hsl(var(--foreground)); }
.nav-caret { display: flex; transition: transform 120ms ease; }
.nav-caret.open { transform: rotate(180deg); }
/* The rule down the left of the group's children — the only thing saying these five belong to
   the header above rather than continuing the flat list. */
.nav-subgroup {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-left: 11px;
  margin-left: 8px;
  border-left: 1px solid hsl(var(--border));
}

/* Collapsed: a square that centres its icon. The label span is not rendered at all rather than
   hidden, so nothing reserves width it cannot use. */
.nav-btn-collapsed { justify-content: center; padding: 9px 0; gap: 0; }
/* A count cannot fit at 64px, so the badge degrades to a corner dot: the row still says "there is
   something here", which is what the number was for at a glance. */
.nav-badge-dot {
  position: absolute;
  top: 5px;
  right: 9px;
  min-width: 7px;
  width: 7px;
  height: 7px;
  padding: 0;
  border-radius: 50%;
}
.nav-btn-collapsed { position: relative; }
.nav-sep { height: 1px; background: hsl(var(--border)); margin: 8px 6px; }

/* Shared by the gear and the sign-out control in the user row. */
.icon-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  color: hsl(var(--muted-foreground));
  display: flex;
  padding: 5px;
  border-radius: var(--r-lg);
}
.icon-btn:hover { background: hsl(var(--card-2)); color: hsl(var(--foreground)); }
/* Lit while any settings screen is open, so the gear is not the one control that gives no feedback
   about where you already are. */
.icon-btn.on { color: hsl(var(--primary)); background: hsl(var(--card-2)); }

/* Pinned to the bottom edge, below the user row: the last thing in the rail, where a collapse
   control is looked for, and out of the way of the navigation itself. */
.nav-collapse {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 10px;
  border: none;
  border-top: 1px solid hsl(var(--border));
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  font-size: var(--t-xs);
  color: hsl(var(--muted-2));
}
.nav-collapse:hover { background: hsl(var(--card-2)); color: hsl(var(--foreground)); }
