/* ============================================================================
 * Fleet Pulse — a real-time vitals monitor with a live ECG/oscilloscope
 * system-ai-x.com  ·  feature slug: fleet-pulse-a-real-time-vitals-monitor-w
 *
 * A hospital-telemetry instrument for the S.A.M fleet. A canvas oscilloscope
 * traces a continuous waveform whose rhythm is driven by live brain-data.json
 * signals (bridge jobs = heart rate, pods = load, coverage gap = arrhythmia,
 * mood = baseline tone). Surrounding it: SVG gauges, odometer counters, and
 * per-region freshness decay meters that visibly age between polls.
 *
 * Pure CSS tokens from style.css (--accent, --accent-2, --mono, --ease-out,
 * --radius, --hairline, --surface-2). Light + dark aware. reduced-motion safe.
 * ==========================================================================*/

.fp {
  position: relative;
  padding: clamp(64px, 9vw, 120px) var(--gutter);
  scroll-margin-top: 80px;
}

.fp__head {
  max-width: var(--essay);
  margin: 0 auto clamp(28px, 4vw, 44px);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}
.fp__head h2 { margin: 10px 0 0; }
.fp__lede {
  margin: 14px 0 0;
  max-width: 56ch;
  color: var(--fg-dim);
  font-size: 16px;
  line-height: 1.55;
}

/* live status pill in the head ---------------------------------------------*/
.fp__status {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 8px 14px;
  border: 1px solid var(--hairline-strong);
  border-radius: 999px;
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--fg-dim);
  white-space: nowrap;
  transition: border-color .4s var(--ease-out), color .4s var(--ease-out);
}
.fp__status .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #38e08a;
  box-shadow: 0 0 10px #38e08a, 0 0 22px rgba(56,224,138,.6);
  animation: pulse-blip 1.4s var(--ease-in-out) infinite;
}
.fp[data-flatline="1"] .fp__status .dot {
  background: #ff5a6a; box-shadow: 0 0 10px #ff5a6a, 0 0 22px rgba(255,90,106,.6);
}
.fp[data-flatline="1"] .fp__status { border-color: rgba(255,90,106,.5); color: #ff8a96; }
@keyframes pulse-blip {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.5); opacity: .55; }
}

/* main instrument shell -----------------------------------------------------*/
.fp__shell {
  max-width: var(--wide, 1180px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
  gap: clamp(16px, 2.2vw, 26px);
}
@media (max-width: 940px) {
  .fp__shell { grid-template-columns: 1fr; }
}

.fp-panel {
  position: relative;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background:
    radial-gradient(120% 140% at 50% 0%, var(--accent-soft), transparent 60%),
    color-mix(in oklab, var(--bg-elev) 86%, transparent);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  box-shadow: 0 30px 80px -50px var(--accent-glow), inset 0 1px 0 rgba(255,255,255,.05);
  overflow: hidden;
  isolation: isolate;
}
.fp-panel::after { /* specular edge */
  content: "";
  position: absolute; inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(135deg, rgba(255,255,255,.16), transparent 40%, transparent 70%, var(--accent-glow-2));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
  pointer-events: none; opacity: .7;
}

/* the scope well ------------------------------------------------------------*/
.fp-scope { padding: 20px 22px 18px; }
.fp-scope__bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; margin-bottom: 14px; flex-wrap: wrap;
}
.fp-scope__title {
  font-family: var(--mono); font-size: 11px; letter-spacing: .18em;
  text-transform: uppercase; color: var(--fg-faint);
  display: inline-flex; align-items: center; gap: 9px;
}
.fp-scope__bpm {
  font-family: var(--mono); font-variant-numeric: tabular-nums;
  display: inline-flex; align-items: baseline; gap: 6px;
}
.fp-scope__bpm b {
  font-size: 30px; font-weight: 600; letter-spacing: -.02em;
  color: var(--fg);
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.fp-scope__bpm span {
  font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--fg-faint);
}

.fp-well {
  position: relative;
  border-radius: var(--radius-sm);
  background: #04060a;
  border: 1px solid rgba(56,189,248,.14);
  overflow: hidden;
  aspect-ratio: 16 / 7;
  min-height: 200px;
}
html[data-theme="light"] .fp-well {
  background: #060912;
  border-color: rgba(56,189,248,.2);
}
.fp-well canvas { display: block; width: 100%; height: 100%; }
.fp-well::before { /* CRT vignette */
  content: ""; position: absolute; inset: 0; z-index: 2; pointer-events: none;
  background: radial-gradient(120% 120% at 50% 50%, transparent 55%, rgba(0,0,0,.55) 100%);
}
.fp-well::after { /* scanlines */
  content: ""; position: absolute; inset: 0; z-index: 2; pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,.18) 0 1px, transparent 1px 3px);
  opacity: .35; mix-blend-mode: overlay;
}
.fp-well__legend {
  position: absolute; left: 12px; bottom: 10px; z-index: 3;
  display: flex; gap: 14px; flex-wrap: wrap;
  font-family: var(--mono); font-size: 10px; letter-spacing: .1em; text-transform: uppercase;
  pointer-events: none;
}
.fp-well__legend i {
  display: inline-flex; align-items: center; gap: 6px; color: rgba(220,235,255,.75); font-style: normal;
}
.fp-well__legend i::before {
  content: ""; width: 16px; height: 2px; border-radius: 2px; box-shadow: 0 0 8px currentColor;
}
.fp-well__legend i.t-vitals::before { background: #57f6b0; color: #57f6b0; }
.fp-well__legend i.t-load::before   { background: #38bdf8; color: #38bdf8; box-shadow: 0 0 8px #38bdf8; }
.fp-well__flatline {
  position: absolute; inset: 0; z-index: 4; display: none;
  align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 11px; letter-spacing: .26em; text-transform: uppercase;
  color: #ff8a96; text-shadow: 0 0 14px rgba(255,90,106,.7);
  pointer-events: none;
}
.fp[data-flatline="1"] .fp-well__flatline { display: flex; animation: pulse-flat-fade 2s steps(2) infinite; }
@keyframes pulse-flat-fade { 0%,49%{opacity:.85} 50%,100%{opacity:.25} }

/* readout strip under the scope --------------------------------------------*/
.fp-vitals {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 1px; margin-top: 16px;
  border: 1px solid var(--hairline); border-radius: var(--radius-sm);
  overflow: hidden; background: var(--hairline);
}
@media (max-width: 560px) { .fp-vitals { grid-template-columns: repeat(2, 1fr); } }
.fp-vital {
  background: var(--surface-2);
  padding: 13px 15px; display: flex; flex-direction: column; gap: 4px;
}
.fp-vital__l {
  font-family: var(--mono); font-size: 9.5px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--fg-faint);
}
.fp-vital__v {
  font-family: var(--mono); font-variant-numeric: tabular-nums;
  font-size: 22px; font-weight: 600; letter-spacing: -.01em; color: var(--fg);
}
.fp-vital__v small { font-size: 11px; font-weight: 500; color: var(--fg-faint); margin-left: 3px; }

/* gauge column --------------------------------------------------------------*/
.fp-side { display: flex; flex-direction: column; gap: clamp(16px, 2.2vw, 26px); }

.fp-gauges {
  padding: 20px 22px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 22px 16px;
}
.fp-gauge { display: flex; flex-direction: column; align-items: center; gap: 9px; text-align: center; }
.fp-gauge__dial {
  position: relative; width: 100%; max-width: 120px; aspect-ratio: 1;
}
.fp-gauge__dial svg { width: 100%; height: 100%; transform: rotate(-90deg); overflow: visible; }
.fp-gauge__track { fill: none; stroke: color-mix(in oklab, var(--fg) 12%, transparent); stroke-width: 7; }
.fp-gauge__arc {
  fill: none; stroke: url(#pulseGaugeGrad); stroke-width: 7; stroke-linecap: round;
  transition: stroke-dashoffset .9s var(--ease-out), stroke .6s var(--ease-out);
  filter: drop-shadow(0 0 6px var(--accent-glow-2));
}
.fp-gauge[data-alarm="1"] .fp-gauge__arc { stroke: #ff5a6a; filter: drop-shadow(0 0 8px rgba(255,90,106,.7)); }
.fp-gauge__num {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1px;
}
.fp-gauge__num b {
  font-family: var(--mono); font-variant-numeric: tabular-nums;
  font-size: clamp(18px, 4vw, 23px); font-weight: 600; color: var(--fg); letter-spacing: -.02em;
}
.fp-gauge__num span { font-family: var(--mono); font-size: 9px; letter-spacing: .1em; color: var(--fg-faint); }
.fp-gauge__label {
  font-family: var(--mono); font-size: 9.5px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--fg-dim);
}

/* freshness decay meters ----------------------------------------------------*/
.fp-fresh { padding: 18px 22px 20px; }
.fp-fresh__head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 14px;
}
.fp-fresh__head h3 {
  font-family: var(--mono); font-size: 11px; letter-spacing: .16em;
  text-transform: uppercase; color: var(--fg-faint); margin: 0; font-weight: 500;
}
.fp-fresh__count {
  font-family: var(--mono); font-size: 11px; color: var(--fg-dim); font-variant-numeric: tabular-nums;
}
.fp-fresh__list { display: flex; flex-direction: column; gap: 9px; }
.fp-fresh__row { display: grid; grid-template-columns: 92px 1fr auto; align-items: center; gap: 10px; }
.fp-fresh__name {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .04em; color: var(--fg-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.fp-fresh__bartrack {
  height: 6px; border-radius: 4px; overflow: hidden;
  background: color-mix(in oklab, var(--fg) 9%, transparent);
}
.fp-fresh__barfill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, #38e08a, #57f6b0);
  border-radius: 4px;
  transform-origin: left center;
  box-shadow: 0 0 8px rgba(56,224,138,.5);
}
.fp-fresh__row[data-missing="1"] .fp-fresh__barfill {
  background: linear-gradient(90deg, #ff5a6a, #ff8a96); box-shadow: 0 0 8px rgba(255,90,106,.55);
}
.fp-fresh__row[data-aging="1"] .fp-fresh__barfill {
  background: linear-gradient(90deg, #f5b942, #ffd479); box-shadow: 0 0 8px rgba(245,185,66,.5);
}
.fp-fresh__age {
  font-family: var(--mono); font-size: 9.5px; color: var(--fg-faint);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}

/* reduced motion ------------------------------------------------------------*/
@media (prefers-reduced-motion: reduce) {
  .fp__status .dot { animation: none; }
  .fp-gauge__arc { transition: none; }
  .fp-well__flatline { animation: none; }
  .fp-fresh__barfill { transition: none !important; }
}

/* light theme tuning --------------------------------------------------------*/
html[data-theme="light"] .fp-well__legend i { color: rgba(220,235,255,.85); }
html[data-theme="light"] .fp-vital__v { color: var(--fg); }

/* surface-map button parity (added entry) ----------------------------------*/
.surface-map__button[data-map-target="fleet-pulse"] .glyph { color: #38e08a; }
