/* ============================================================================
   components/pipeline.css — the Executive Office pipeline explainer.

   Design rules this component is built to obey:

   1. The six stages are readable as a static diagram. A visitor who never
      interacts still learns the pipeline by reading left to right. The chips
      are the comprehension layer and must never be what degrades.
   2. Play-driven, never scroll-triggered and never autoplay. The user opts
      in. Nobody is trapped in an animation.
   3. Chips are simultaneously progress indicator and navigation, so a
      skeptical visitor can jump straight to the interesting part.
   4. Real tablist semantics with arrow-key support. The reference
      implementation this pattern came from omits them; ours does not.
   5. Under reduced motion the animation does not run, but every stage stays
      selectable and the schematic still highlights.
   ============================================================================ */

.pipeline {
  /* Escapes into the GUTTER only, not across the rail.
     It previously claimed the rail's full width (--rail-w + --space-2xl),
     which put 240px of the diagram underneath a position:sticky rail. Sticky
     is a positioned element, so the rail painted on top: "Human review"
     collided with the rail rule and hit-testing inside the diagram returned
     rail links. Escaping only into the gutter gives both a column of their
     own — the fix is layout, not overflow suppression. */
  width: calc(100% + var(--space-2xl));
  border: var(--hairline);
  border-radius: var(--radius-l);
  background: var(--surface);
  overflow: hidden;
  margin-block: var(--space-l);
}

/* ---- Controls bar -------------------------------------------------------- */

.pl-bar {
  display: flex;
  align-items: center;
  gap: var(--space-s);
  padding: var(--space-s) var(--space-m);
  border-bottom: var(--hairline);
  background: var(--surface-2);
  flex-wrap: wrap;
}

.pl-scenarios { display: flex; gap: var(--space-3xs); }

.pl-scenario {
  font: inherit;
  font-family: var(--font-mono);
  font-size: var(--step--2);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  padding: var(--space-3xs) var(--space-2xs);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-s);
  background: transparent;
  /* --ink-3 measured 4.27:1 here against the pipeline panel — below AA for
     10.9px text, with no large-text exemption. --ink-2 clears it. */
  color: var(--ink-2);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out);
}
.pl-scenario:hover { color: var(--ink); border-color: var(--line-strong); }
.pl-scenario[aria-pressed="true"] {
  color: var(--gold);
  border-color: var(--gold-line);
  background: var(--gold-wash);
}

.pl-transport { margin-left: auto; display: flex; gap: var(--space-2xs); }

.pl-btn {
  font: inherit;
  font-size: var(--step--1);
  padding: var(--space-3xs) var(--space-s);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}
.pl-btn:hover { border-color: var(--gold); color: var(--gold); }
.pl-btn--primary { background: var(--gold); color: var(--gold-ink); border-color: var(--gold); font-weight: 550; }
.pl-btn--primary:hover { background: var(--gold-deep); border-color: var(--gold-deep); color: var(--gold-ink); }

/* ---- The flow --------------------------------------------------------------
   Six stages in a row, each a tab. Connectors are drawn between them; the
   return path from 04 to 03 lives in the second grid row and is only laid
   out when it fires, so a clean run has no unexplained gap.              */

.pl-flow {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-template-rows: auto auto;
  column-gap: var(--space-s);
  padding: var(--space-l) var(--space-m) var(--space-m);
  border-bottom: var(--hairline);
  position: relative;
}

.pl-stage {
  grid-row: 1;
  position: relative;
  font: inherit;
  text-align: left;
  padding: var(--space-m) 0 var(--space-s) 0;
  background: transparent;
  border: none;
  border-top: 2px solid var(--line-2);
  cursor: pointer;
  color: var(--ink-3);
  display: flex; flex-direction: column; gap: 2px;
  transition: color var(--dur-base) var(--ease-out), border-color var(--dur-base) var(--ease-out);
}
/* the node dot, sitting on the top rule */
.pl-stage::before {
  content: "";
  position: absolute;
  left: 0; top: -6px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--line-strong);
  transition: background-color var(--dur-base) var(--ease-out), border-color var(--dur-base) var(--ease-out);
}
/* the connector: the rule itself continues across the gap to the next node */
.pl-stage:not(:nth-child(6))::after {
  content: "";
  position: absolute;
  top: -2px; right: calc(-1 * var(--space-s)); width: var(--space-s); height: 2px;
  background: var(--line-2);
}
.pl-stage:hover { color: var(--ink-2); }
.pl-stage:focus-visible { outline: var(--focus-ring); outline-offset: 4px; }

.pl-stage-n { font-family: var(--font-mono); font-size: var(--step--2); letter-spacing: var(--tracking-label); color: var(--ink-3); }
.pl-stage-name { font-family: var(--font-display); font-variation-settings: var(--fraunces-display); font-size: var(--step-1); line-height: 1.15; font-weight: 600; color: var(--ink-2); }
.pl-stage-role { font-family: var(--font-mono); font-size: var(--step--2); letter-spacing: 0.04em; color: var(--ink-3); margin-top: var(--space-3xs); }

.pl-stage[data-state="done"] { border-top-color: var(--line-strong); }
.pl-stage[data-state="done"]::before { background: var(--line-strong); border-color: var(--line-strong); }
.pl-stage[aria-selected="true"] { color: var(--ink); border-top-color: var(--gold); }
.pl-stage[aria-selected="true"] .pl-stage-name { color: var(--ink); }
.pl-stage[aria-selected="true"]::before { background: var(--gold); border-color: var(--gold); }
.pl-stage[aria-selected="true"] .pl-stage-n { color: var(--gold); }

/* The human gate is marked permanently. Governance is the differentiator. */
.pl-stage--gate .pl-stage-name { color: var(--ink); }
.pl-stage--gate::before { background: var(--gold-wash); border-color: var(--gold); }

/* Failure at 04 */
.pl-stage[data-state="failed"] { border-top-color: var(--fail); }
.pl-stage[data-state="failed"]::before { background: var(--fail); border-color: var(--fail); }
.pl-stage[data-state="failed"] .pl-stage-name, .pl-stage[data-state="failed"] .pl-stage-n { color: var(--fail); }

/* The return path. Drawn as a bracket under 03–04 with the arrow landing on
   Production. Hidden with display:none so it reserves nothing until it fires. */
.pl-loop {
  grid-row: 2; grid-column: 3 / 5;
  display: none;
  margin-top: var(--space-2xs);
  padding: var(--space-s) var(--space-s) 0;
  border: 2px solid var(--fail);
  border-top: none;
  border-radius: 0 0 var(--radius-m) var(--radius-m);
  position: relative;
  font-family: var(--font-mono);
  font-size: var(--step--2);
  letter-spacing: 0.02em;
  color: var(--fail);
  text-align: center;
  height: 2.2rem;
  white-space: nowrap;
}
.pl-loop::before { /* arrowhead pointing up into Production */
  content: "";
  position: absolute; left: -6px; top: -8px;
  width: 0; height: 0;
  border-left: 5px solid transparent; border-right: 5px solid transparent;
  border-bottom: 8px solid var(--fail);
}
.pl-loop span { position: absolute; left: 50%; bottom: -0.65em; transform: translateX(-50%); background: var(--surface); padding-inline: var(--space-2xs); }
.pl-loop[data-on="true"] { display: block; }

/* ---- Rules strip: governance as a static fact, not a play-state -------- */
.pl-rules { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-m); margin: 0; padding: var(--space-m); border-bottom: var(--hairline); background: var(--bg-sunk); }
.pl-rules div { display: flex; flex-direction: column; gap: var(--space-3xs); }
.pl-rules dt { font-family: var(--font-mono); font-size: var(--step--2); letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--gold); }
.pl-rules dd { margin: 0; font-size: var(--step--1); line-height: 1.4; color: var(--ink-2); }
@media (max-width: 700px) { .pl-rules { grid-template-columns: 1fr; gap: var(--space-s); } }

/* ---- Narration ------------------------------------------------------------- */

.pl-narration {
  padding: var(--space-m);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-2xs);
  min-height: 7.5rem;
}
.pl-narration-label { font-family: var(--font-mono); font-size: var(--step--2); letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--ink-3); }
.pl-narration-text { font-size: var(--step-1); line-height: 1.4; color: var(--ink); margin: 0; max-width: 52ch; font-family: var(--font-display); font-variation-settings: var(--fraunces-display); font-weight: 500; }
.pl-narration-sub { font-size: var(--step--1); color: var(--ink-2); margin: 0; max-width: 60ch; }

/* ---- Mobile -------------------------------------------------------------
   The flow turns vertical. Connectors run down the left; the return path is
   drawn as a bracket beside 03–04 so the loop stays visible on a phone.   */

@media (max-width: 1023px) { .pipeline { width: 100%; } }
@media (max-width: 700px) {
  .pl-flow { grid-template-columns: 1.25rem minmax(0, 1fr); grid-template-rows: none; column-gap: var(--space-s); row-gap: 0; padding: var(--space-m) var(--space-m) var(--space-s); }
  .pl-stage { border-top: none; border-left: 2px solid var(--line-2); padding: var(--space-xs) 0 var(--space-xs) var(--space-m); margin: 0; }
  .pl-stage::before { left: -6px; top: 1.05rem; }
  .pl-stage:not(:nth-child(6))::after { display: none; }
  .pl-stage[data-state="done"] { border-left-color: var(--line-strong); }
  .pl-stage[aria-selected="true"] { border-left-color: var(--gold); }
  .pl-stage[data-state="failed"] { border-left-color: var(--fail); }
  .pl-stage:last-of-type { border-left-color: transparent; }
  .pl-loop { height: auto; margin: 0; padding: var(--space-2xs) 0 var(--space-2xs) var(--space-m); border: none; border-left: 2px solid var(--fail); border-radius: 0; text-align: left; white-space: normal; }
  .pl-loop::before { left: -6px; top: 50%; transform: translateY(-50%) rotate(-90deg); border-left: 5px solid transparent; border-right: 5px solid transparent; border-bottom: 8px solid var(--fail); }
  .pl-loop span { position: static; transform: none; background: none; padding: 0; }
  .pl-loop span::before { content: "\2191  "; }
  /* Source order puts the loop after 06; on mobile place it between 04 and 05 */
  .pl-flow { display: flex; flex-direction: column; padding-left: calc(var(--space-m) + 6px); }
  .pl-stage[data-i="0"] { order: 1; } .pl-stage[data-i="1"] { order: 2; } .pl-stage[data-i="2"] { order: 3; }
  .pl-stage[data-i="3"] { order: 4; } .pl-loop { order: 5; } .pl-stage[data-i="4"] { order: 6; } .pl-stage[data-i="5"] { order: 7; }
  .pl-bar { gap: var(--space-2xs); }
  .pl-transport { margin-left: 0; width: 100%; }
  .pl-btn { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .pl-loop, .pl-stage { transition: none; }
}

/* ---- LIGHT-THEME INSTRUMENTATION CONTRAST -------------------------------
   Governance labels sit on the sunk rules panel and the pressed scenario
   button on its own gold wash; both measure ~4.16:1 in light theme at
   10.9-11.5px. Locked gold is preserved; the labels take --ink-2 in light
   only. The pressed button keeps its gold wash background and border, so
   the selected state still reads as gold. Dark theme untouched.        */
@media (prefers-color-scheme: light) {
  .pl-rules dt { color: var(--ink-2); }
  .pl-scenario[aria-pressed="true"] { color: var(--ink); }
}
:root[data-theme="light"] .pl-rules dt { color: var(--ink-2); }
:root[data-theme="light"] .pl-scenario[aria-pressed="true"] { color: var(--ink); }
