/* Home hero: fleet telemetry -> failure clusters -> starter patch.
   Lives inside .hero-instrument, which is navy in both themes, so the inks
   below are tuned for that surface rather than for the page theme. The
   markup's default state is the complete, static frame; js/fleet-viz.js
   animates it only when motion is allowed. */
.fleet-viz {
  --fv-accent: #9cc0ff;
  --fv-amber: #f3bc69;
  --fv-green: #7fdcae;
  --fv-red: #ffa8a8;
  --fv-line: rgba(255, 255, 255, 0.12);
  --fv-well: rgba(4, 10, 18, 0.42);
  --fv-mono: ui-monospace, SFMono-Regular, Consolas, monospace;
  display: grid;
  gap: var(--space-md);
}

/* :not(.sr-only) keeps the text equivalent out of the grid (it is position: absolute). */
.fleet-viz > :not(.sr-only) { position: relative; z-index: 1; min-width: 0; }
.fleet-viz .instrument-link { margin-top: 0; width: fit-content; }

/* ---- Stage: robots | wires | cluster bins ---- */
.fleet-viz__stage {
  display: grid;
  grid-template-columns: auto minmax(44px, 1fr) minmax(0, 2.1fr);
  padding: var(--space-md);
  border: 1px solid var(--fv-line);
  border-radius: var(--radius-md);
  background: var(--fv-well);
}

.fleet-viz__wires { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.fleet-viz__wire { fill: none; stroke: rgba(156, 192, 255, 0.16); stroke-width: 1; transition: stroke 240ms ease; }
.fleet-viz__wire.is-live { stroke: rgba(156, 192, 255, 0.55); }
.fleet-viz__dot-core { fill: #e6f0ff; }
.fleet-viz__dot-halo { fill: var(--fv-accent); opacity: 0.32; }

.fleet-viz__fleet,
.fleet-viz__bins { position: relative; z-index: 1; display: flex; flex-direction: column; gap: var(--space-sm); min-width: 0; }
.fleet-viz__fleet { grid-column: 1; }
.fleet-viz__bins { grid-column: 3; }

.fleet-viz__label {
  margin: 0 0 2px;
  color: var(--color-instrument-muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.3;
  text-transform: uppercase;
}

.fleet-viz__robot {
  display: grid;
  flex: 1;
  grid-template-columns: auto auto;
  align-content: center;
  justify-content: start;
  column-gap: 7px;
  padding: 0 var(--space-sm);
  border: 1px solid var(--fv-line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
}

.fleet-viz__robot strong { color: var(--color-instrument-text); font: 600 0.84rem/1.3 var(--fv-mono); }
.fleet-viz__robot small { grid-column: 2; color: var(--color-instrument-muted); font-size: 0.66rem; line-height: 1.3; }
.fleet-viz__led { align-self: center; width: 7px; height: 7px; border-radius: 50%; background: var(--fv-accent); box-shadow: 0 0 0 3px rgba(156, 192, 255, 0.16); }
.fleet-viz__robot.is-emitting { border-color: rgba(156, 192, 255, 0.6); }
.fleet-viz__robot.is-emitting .fleet-viz__led { animation: fleetVizPing 520ms ease-out; }

.fleet-viz__bin {
  display: grid;
  flex: 1;
  align-content: center;
  gap: 6px;
  padding: 10px var(--space-sm);
  border: 1px solid var(--fv-line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  transition: border-color 240ms ease, background-color 240ms ease;
}

.fleet-viz__bin-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-xs); }
.fleet-viz__bin-name { color: var(--color-instrument-text); font-size: 0.86rem; font-weight: 600; line-height: 1.25; }
.fleet-viz__count { flex: none; color: var(--color-instrument-muted); font: 0.74rem/1 var(--fv-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.fleet-viz__count b { display: inline-block; color: var(--color-instrument-text); font-size: 1.05rem; font-weight: 700; }
.fleet-viz__bin.is-bump .fleet-viz__count b { animation: fleetVizBump 360ms ease-out; }

/* The meter spans 0-4 events so the threshold tick at 3 sits at 75%. */
.fleet-viz__meter { position: relative; height: 6px; border-radius: 999px; background: rgba(255, 255, 255, 0.1); }
.fleet-viz__fill { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--fv-accent); transition: width 320ms cubic-bezier(.2, .8, .2, 1), background-color 240ms ease; }
.fleet-viz__bin[data-count="1"] .fleet-viz__fill { width: 25%; }
.fleet-viz__bin[data-count="2"] .fleet-viz__fill { width: 50%; }
.fleet-viz__bin[data-count="3"] .fleet-viz__fill { width: 75%; }
.fleet-viz__bin[data-count="4"] .fleet-viz__fill { width: 100%; }
.fleet-viz__tick { position: absolute; top: -4px; bottom: -4px; left: 75%; width: 2px; margin-left: -1px; border-radius: 1px; background: var(--fv-amber); }

.fleet-viz__bin-foot { display: flex; justify-content: space-between; gap: var(--space-xs); color: var(--color-instrument-muted); font: 0.66rem/1.2 var(--fv-mono); }
.fleet-viz__bin-foot span:last-child { color: var(--fv-amber); white-space: nowrap; }

.fleet-viz__bin.is-tripped { border-color: rgba(243, 188, 105, 0.7); background: rgba(243, 188, 105, 0.08); animation: fleetVizTrip 900ms ease-out 2; }
.fleet-viz__bin.is-tripped .fleet-viz__fill { background: var(--fv-amber); }
.fleet-viz__bin.is-tripped .fleet-viz__count b { color: var(--fv-amber); }

/* ---- Patch ticket slot: every ticket shares one grid cell, so the slot
   keeps the tallest ticket's height and nothing below it shifts. ---- */
.fleet-viz__tickets { display: grid; }
.fleet-viz__ticket,
.fleet-viz__idle { grid-area: 1 / 1; min-width: 0; }

.fleet-viz__idle {
  display: grid;
  place-items: center;
  margin: 0;
  padding: var(--space-md);
  border: 1px dashed rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-sm);
  color: var(--color-instrument-muted);
  font-size: 0.82rem;
  text-align: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 240ms ease, visibility 0s linear 240ms;
}

.fleet-viz__tickets[data-state="idle"] .fleet-viz__idle { opacity: 1; visibility: visible; transition-delay: 0s; }

.fleet-viz__ticket {
  align-self: start;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid rgba(127, 220, 174, 0.32);
  border-left: 3px solid var(--fv-green);
  border-radius: var(--radius-sm);
  background: var(--color-instrument-well);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.3);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-14px);
  transition: opacity 260ms ease, transform 260ms ease, visibility 0s linear 260ms;
}

.fleet-viz__ticket.is-active { opacity: 1; visibility: visible; transform: none; transition: opacity 320ms ease, transform 460ms cubic-bezier(.2, .8, .2, 1), visibility 0s; }

.fleet-viz__ticket-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px var(--space-sm); margin-bottom: var(--space-xs); }
.fleet-viz__ticket-kicker { color: var(--fv-green); font-size: 0.68rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.fleet-viz__ticket-head code { color: var(--color-instrument-muted); font: 0.72rem/1.3 var(--fv-mono); background: none; }

.fleet-viz__diff { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; }
.fleet-viz__diff li { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px var(--space-sm); font: 0.78rem/1.45 var(--fv-mono); }
.fleet-viz__path { min-width: 0; padding: 0; color: #a9c3e4; font: inherit; background: none; overflow-wrap: anywhere; }
.fleet-viz__change { margin-left: auto; white-space: nowrap; font-variant-numeric: tabular-nums; }
.fleet-viz__old { color: var(--fv-red); text-decoration: line-through; }
.fleet-viz__arrow { color: var(--color-instrument-muted); }
.fleet-viz__new { color: var(--fv-green); font-weight: 700; }
.fleet-viz__ticket-note { margin: var(--space-xs) 0 0; color: var(--color-instrument-muted); font-size: 0.72rem; line-height: 1.4; }

/* ---- Caption + pause control ---- */
.fleet-viz__footer { display: flex; align-items: center; justify-content: space-between; gap: var(--space-sm); min-height: 36px; }
.fleet-viz__caption { margin: 0; color: var(--color-instrument-muted); font-size: 0.82rem; }
.fleet-viz__toggle {
  flex: none;
  min-width: 68px;
  min-height: 36px;
  padding: 0 var(--space-sm);
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  background: transparent;
  color: var(--color-instrument-text);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--transition), border-color var(--transition);
}

.fleet-viz__toggle[hidden] { display: none; }
.fleet-viz__toggle:hover { border-color: var(--fv-accent); background: rgba(156, 192, 255, 0.12); }
.fleet-viz__toggle:focus-visible { outline: 3px solid var(--fv-accent); outline-offset: 2px; }

@keyframes fleetVizPing {
  0% { box-shadow: 0 0 0 0 rgba(156, 192, 255, 0.7); }
  100% { box-shadow: 0 0 0 10px rgba(156, 192, 255, 0); }
}

@keyframes fleetVizBump {
  0% { transform: translateY(-5px); color: var(--fv-accent); }
  100% { transform: none; }
}

@keyframes fleetVizTrip {
  0% { box-shadow: 0 0 0 0 rgba(243, 188, 105, 0.5); }
  100% { box-shadow: 0 0 0 12px rgba(243, 188, 105, 0); }
}

/* Stacked under the copy but still wide: put the patch slot beside the stage
   instead of stretching the wires across the whole panel. */
@media (min-width: 761px) and (max-width: 1100px) {
  .fleet-viz { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); }
  .fleet-viz > .instrument-toolbar,
  .fleet-viz__footer,
  .fleet-viz .instrument-link { grid-column: 1 / -1; }
  .fleet-viz__ticket { align-self: center; }
}

@media (max-width: 480px) {
  .fleet-viz.hero-instrument { padding: var(--space-md); }
  .fleet-viz__stage { grid-template-columns: auto minmax(32px, 1fr) minmax(0, 2.6fr); padding: var(--space-sm); }
  .fleet-viz__robot { padding: 0 var(--space-xs); column-gap: 5px; }
  .fleet-viz__bin-name { font-size: 0.8rem; }
  .fleet-viz__ticket { padding: var(--space-sm); }
}

/* Reduced motion: js/fleet-viz.js leaves the static frame in place; this
   makes sure nothing in the panel eases or pulses either. */
@media (prefers-reduced-motion: reduce) {
  .fleet-viz *, .fleet-viz *::before, .fleet-viz *::after { animation: none !important; transition: none !important; }
}

@media print {
  .fleet-viz__toggle { display: none; }
}
