(function(){
/* FORGE — Aetherion Microsat dashboard.
   Wave A1 / Space / Agent #9. Spec: forge-web/demo/tenant-spec/space.md.

   This screen overrides /forge/dashboard for the aetherion tenant. It is
   registered through registerPumpRoute so it sits in the route table
   ahead of BUILTIN_ROUTES (router.jsx merges tenant -> pump -> builtin).
   The renderer dispatches by tenant id: aetherion gets ScreenAetherion-
   Dashboard, every other tenant falls back to the existing Screen-
   Dashboard in dashboard-viewer.jsx (DO NOT MODIFY). The KESTREL-3 hero
   ECO is pinned top-right; six KPIs from spec §4 ride a strip; the nine
   gates from §5 render as colored bars; the right rail carries alerts
   that link to lane consoles. Cool blues, mono digits, ITAR markers,
   no emoji, no glyph stand-ins.

   Globals consumed: React, Panel, Pill, Btn, Tag, Progress, I, navigate,
   getActiveTenant, useActiveTenant, registerPumpRoute. */

const { useState: uSAE, useEffect: uEAE, useMemo: uMAE } = React;

/* ---------- spec-locked fixture (matches space.md) ---------- */

// Aetherion contract value — $4.2M FFP. Held as minor units (cents) so the
// locale-aware Intl path handles the "$4,200,000.00" formatting; we keep
// the " FFP" suffix as a free-text qualifier appended at render time.
const AET_CONTRACT_MINOR = "420000000"; // 4,200,000 USD × 100 cents
const AET_CONTRACT_CCY   = "USD";
function aetContractLabel() {
  var i18n = (typeof window !== "undefined") ? window.forgeI18n : null;
  if (i18n && typeof i18n.formatMoneyMinor === "function") {
    var out = i18n.formatMoneyMinor(AET_CONTRACT_MINOR, AET_CONTRACT_CCY);
    if (out) return out + " FFP";
  }
  return "$4.2M FFP";
}

const AET_PROGRAM = {
  code:           "KESTREL-3",
  bus:            "12U Cubesat",
  name:           "KESTREL-3 12U Cubesat",
  customer:       "Aperture Earth Analytics",
  customer_short: "Aperture Earth",
  contract:       "$4.2M FFP",            // legacy shorthand; render via aetContractLabel()
  contract_minor: AET_CONTRACT_MINOR,
  contract_ccy:   AET_CONTRACT_CCY,
  loi_signed:     "2025-01-12",
  launch:         "2026-09-10",
  launch_label:   "Falcon 9 Transporter-15",
  orbit:          "sun-sync LEO 525 km · dawn-dusk",
  mass_cap_kg:    14.000,
  mass_dry_kg:    12.460,
  mass_margin_pc: 11.0,
  power_bol_w:    70.0,
  power_pl_w:     32.0,
  power_margin_w: 8,
  itar:           true,
};

const AET_KPIS = [
  { k: "Mass margin",         v: "11.0%",  d: "1.54 kg / 14.00 kg cap", trend: "down", units: "kg" },
  { k: "Power margin",        v: "8 W",    d: "70 W BOL · 32 W pl",     trend: "flat", units: "W"  },
  { k: "Open NCRs",           v: "2",      d: "1 critical · hinge",     trend: "flat" },
  { k: "Days to launch",      v: "124",    d: "T-0 2026-09-10",         trend: "down" },
  { k: "Qual gate pass rate", v: "94%",    d: "118 / 126 tests",        trend: "up"   },
  { k: "Telemetry latency",   v: "112 ms", d: "uplink p95 last 24h",    trend: "flat" },
];

const AET_GATES = [
  { id: "SRR",    label: "System review",         state: "passed",    date: "2025-03-04", note: "7 actions" },
  { id: "PDR",    label: "Preliminary design",    state: "passed",    date: "2025-06-18", note: "propulsion trade attached" },
  { id: "CDR",    label: "Critical design",       state: "passed",    date: "2025-10-22", note: "mass margin 11.4%" },
  { id: "FAB",    label: "Fabrication",           state: "passed",    date: "2026-01-30", note: "FAB-A · FAB-B re-issue 2026-05-05" },
  { id: "ASSY",   label: "Assembly",              state: "in-flight", date: "2026-02 — present", note: "integration ongoing" },
  { id: "I&T",    label: "Integration + test",    state: "in-flight", date: "paused",      note: "paused for ECO retest" },
  { id: "TVAC",   label: "Thermal vacuum",        state: "in-flight", date: "2026-05-28",  note: "partial re-test target" },
  { id: "ACC",    label: "Flight acceptance",     state: "upcoming",  date: "2026-07-15",  note: "Mission Director sign" },
  { id: "LAUNCH", label: "Manifest lock",         state: "upcoming",  date: "2026-09-10",  note: "Falcon 9 Transporter-15" },
];

const AET_HERO_ECO = {
  id:        "ECO-AET-0042",
  title:     "Solar-array hinge fastener — A2-70 → A286 + Belleville",
  target_pn: "KESTREL-3.60.HG.03",
  rev:       "B → C",
  opened:    "2026-04-24",
  owner:     "M. Sato · Mech Lead",
  severity:  "critical",
  state:     "board-review · pending Mission Director sign-off",
  trigger:   "TVAC-AET-014 cycle 14/24 — 50 µm pre-load loss on hinge HG-03",
  mass_g:    9.6,
  margin_before_pc: 11.00,
  margin_after_pc:  10.93,
  schedule_days:    11,
  acc_was:   "2026-07-04",
  acc_now:   "2026-07-15",
  approvals: [
    { who: "Originator · M. Sato",   state: "signed",  on: "2026-04-24" },
    { who: "Mech CCB",                state: "signed",  on: "2026-05-02" },
    { who: "Q&MA",                    state: "signed",  on: "2026-05-04" },
    { who: "Mission Director",        state: "pending", on: "target 2026-05-12" },
  ],
  retest:    "TVAC-AET-014R · 24 cycles −40 / +85 °C, 90 min ramps + 2000g shock",
  itar:      true,
};

const AET_ALERTS = [
  {
    sev:   "critical",
    title: "TVAC chatter NCR-AET-019",
    body:  "Hinge HG-03 pre-load 0.42 Nm vs spec 0.55 ± 0.05 Nm. ECO-AET-0042 raised, board pending.",
    route: "/build/eco",
    link:  "Open ECO",
  },
  {
    sev:   "warn",
    title: "Mass margin trend",
    body:  "11.4% (CDR) → 11.0% (current) → 10.93% post-ECO. Policy floor 10.0%. Watch BCT RW addendum.",
    route: "/forge/ebom",
    link:  "Open mass budget",
  },
  {
    sev:   "info",
    title: "ITAR clearance · Glenair pull",
    body:  "FAB-B harness drawing pull logged 2026-05-05. ITAR_EXPORT_RECORDED on ledger. US-persons only.",
    route: "/auditor/ledger",
    link:  "View receipt",
  },
  {
    sev:   "info",
    title: "Telemetry uplink",
    body:  "X-band p95 112 ms last 24 h. UHF TT&C nominal. No re-baseline needed for ACC.",
    route: "/forge/analytics",
    link:  "Open analytics",
  },
];

/* ---------- color helpers (tenant-scoped, no neon) ---------- */

function aetGateColor(state) {
  if (state === "passed")    return "var(--ok)";
  if (state === "in-flight") return "var(--space-accent, var(--info))";
  return "var(--line-strong)";
}

function aetGateBg(state) {
  if (state === "passed")    return "color-mix(in oklch, var(--ok) 14%, transparent)";
  if (state === "in-flight") return "color-mix(in oklch, var(--space-accent, var(--info)) 16%, transparent)";
  return "color-mix(in oklch, var(--ink-4) 8%, transparent)";
}

function aetGateLabel(state) {
  if (state === "passed")    return "passed";
  if (state === "in-flight") return "in-flight";
  return "upcoming";
}

function aetSevTone(sev) {
  if (sev === "critical") return "danger";
  if (sev === "warn")     return "warn";
  return "accent";
}

function aetMonoStyle(extra) {
  return Object.assign({
    fontFamily: "var(--font-mono)",
    color: "var(--space-mono-color, var(--ink))",
    fontFeatureSettings: '"tnum","ss01"',
  }, extra || {});
}

/* ---------- ITAR badge ---------- */

// Hoisted style atoms — extracted from inline JSX for react-doctor compliance.
const _ae_dash_itarBase = {
  display: "inline-flex",
  alignItems: "center",
  gap: 4,
  padding: "1px 6px",
  borderRadius: 3,
  border: "1px solid var(--err)",
  color: "var(--err)",
  fontFamily: "var(--font-mono)",
  fontSize: 12,
  letterSpacing: "0.04em",
  background: "color-mix(in oklch, var(--err) 8%, transparent)",
};
const _ae_dash_lifecycleBarBase = {
  display: "grid",
  gridTemplateRows: "auto 6px auto",
  gap: 6,
  padding: "8px 10px",
  border: "1px solid var(--space-line, var(--line-soft))",
  borderRadius: 4,
  minWidth: 0,
};
const _ae_dash_rootStyle = {
  padding: 14,
  display: "grid",
  gridTemplateRows: "auto auto auto 1fr auto",
  gap: 14,
  minHeight: 0,
  height: "100%",
  background: "var(--bg-0)",
  // Tenant-scoped CSS vars (in case tokens.css patch from agent #11 hasn't shipped).
  // These are local fallbacks only — the canonical values live in tokens.css.
  // eslint-disable-next-line no-undef
  ["--space-ink"]:        "var(--space-ink, #0B1220)",
  ["--space-accent"]:     "var(--space-accent, #4F8FFF)",
  ["--space-slate"]:      "var(--space-slate, #5B6B82)",
  ["--space-line"]:       "var(--space-line, #1A2438)",
  ["--space-mono-color"]: "var(--space-mono-color, #C9D6F0)",
};

function ITARBadge({ inline }) {
  return (
    <span
      title="ITAR controlled · US persons only"
      style={{ ..._ae_dash_itarBase, marginLeft: inline ? 8 : 0 }}
    >
      ITAR
    </span>
  );
}

/* ---------- T-minus calc ---------- */

function aetDaysToLaunch(launchIso) {
  try {
    const today = new Date("2026-05-09T00:00:00Z");
    const t0    = new Date(launchIso + "T00:00:00Z");
    const ms    = t0.getTime() - today.getTime();
    const d     = Math.round(ms / 86400000);
    return d;
  } catch (e) {
    return 124;
  }
}

/* ---------- hero band ---------- */

function AetherionHero({ program }) {
  const days = aetDaysToLaunch(program.launch);
  const tCode = days >= 0 ? "T-" + String(days) + "d" : "T+" + String(Math.abs(days)) + "d";
  return (
    <div
      style={{
        position: "relative",
        padding: "16px 18px",
        border: "1px solid var(--space-line, var(--line))",
        borderRadius: 6,
        background: "linear-gradient(180deg, var(--space-ink, var(--bg-1)) 0%, var(--bg-1) 100%)",
        overflow: "hidden",
      }}
    >
      <div
        aria-hidden
        style={{
          position: "absolute",
          inset: 0,
          background: "radial-gradient(circle at 92% 10%, color-mix(in oklch, var(--space-accent, var(--info)) 22%, transparent), transparent 55%)",
          pointerEvents: "none",
        }}
      />
      <div style={{ position: "relative", display: "flex", justifyContent: "space-between", alignItems: "flex-start", gap: 18 }}>
        <div style={{ minWidth: 0, flex: 1 }}>
          <div className="label" style={{ color: "var(--space-slate, var(--ink-3))", letterSpacing: "0.04em" }}>
            AETHERION MICROSAT · MISSION-CLASS HARDWARE
          </div>
          <div
            className="serif"
            style={{
              fontSize: 30,
              lineHeight: 1.1,
              marginTop: 6,
              color: "var(--ink)",
              letterSpacing: "-0.01em",
            }}
          >
            {program.code} {program.bus} · {program.customer} · Launch {program.launch}
            <span style={aetMonoStyle({ fontSize: 18, marginLeft: 14, color: "var(--space-accent, var(--info))" })}>
              ({tCode})
            </span>
          </div>
          <div className="muted" style={{ fontSize: 12, marginTop: 8, display: "flex", gap: 10, flexWrap: "wrap", alignItems: "center" }}>
            <span>{aetContractLabel()}</span>
            <span style={{ color: "var(--ink-4)" }}>·</span>
            <span>{program.orbit}</span>
            <span style={{ color: "var(--ink-4)" }}>·</span>
            <span>{program.launch_label}</span>
            {program.itar ? <ITARBadge inline /> : null}
          </div>
        </div>
        <div style={{ display: "flex", flexDirection: "column", gap: 6, alignItems: "flex-end" }}>
          <span style={aetMonoStyle({ fontSize: 12, color: "var(--space-slate, var(--ink-3))" })}>
            today · {(window.forgeI18n && window.forgeI18n.formatDate("2026-05-09")) || "2026-05-09"} UTC
          </span>
          <span style={aetMonoStyle({ fontSize: 12, color: "var(--ink-3)" })}>
            mass {program.mass_dry_kg.toFixed(3)} / {program.mass_cap_kg.toFixed(3)} kg
          </span>
          <span style={aetMonoStyle({ fontSize: 12, color: "var(--ink-3)" })}>
            power {program.power_bol_w.toFixed(1)} W BOL · {program.power_pl_w.toFixed(1)} W pl
          </span>
        </div>
      </div>
    </div>
  );
}

/* ---------- KPI strip (six tiles, mono, units) ---------- */

function AetherionKPI({ k, v, d, trend }) {
  const trendColor = trend === "up" ? "var(--ok)" : trend === "down" ? "var(--info)" : "var(--ink-4)";
  const arrow      = trend === "up" ? "▲" : trend === "down" ? "▼" : "·";
  return (
    <div
      style={{
        padding: "12px 14px",
        border: "1px solid var(--space-line, var(--line-soft))",
        borderRadius: 5,
        background: "var(--bg-1)",
        minWidth: 0,
      }}
    >
      <div className="label" style={{ color: "var(--space-slate, var(--ink-3))" }}>{k}</div>
      <div style={{ display: "flex", alignItems: "baseline", gap: 8, marginTop: 6 }}>
        <div style={aetMonoStyle({ fontSize: 22, letterSpacing: "-0.01em", color: "var(--ink)" })}>{v}</div>
        <div style={aetMonoStyle({ fontSize: 12, color: trendColor })}>{arrow}</div>
      </div>
      <div className="mono" style={{ fontSize: 12, color: "var(--ink-3)", marginTop: 4 }}>{d}</div>
    </div>
  );
}

function AetherionKPIStrip({ kpis }) {
  return (
    <div
      style={{
        display: "grid",
        gridTemplateColumns: "repeat(6, minmax(0, 1fr))",
        gap: 10,
      }}
    >
      {kpis.map(function(kpi) {
        return <AetherionKPI key={kpi.k} {...kpi} />;
      })}
    </div>
  );
}

/* ---------- live stack: nine gates as bars ---------- */

function AetherionLifecycleBar({ gate, idx, total }) {
  const color = aetGateColor(gate.state);
  const bg    = aetGateBg(gate.state);
  return (
    <div
      role="listitem"
      aria-label={gate.id + " — " + aetGateLabel(gate.state)}
      title={gate.id + " — " + aetGateLabel(gate.state)}
      style={{ ..._ae_dash_lifecycleBarBase, background: bg, overflow: "hidden" }}
    >
      <div style={{ display: "flex", alignItems: "baseline", minWidth: 0 }}>
        <span style={aetMonoStyle({ fontSize: 12, color: "var(--ink)", minWidth: 0, flex: "1 1 0", overflow: "hidden", whiteSpace: "nowrap" })}>
          {String(idx + 1).padStart(2, "0")}
        </span>
      </div>
      <div style={{ height: 6, background: "var(--bg-3)", borderRadius: 3, overflow: "hidden" }}>
        <div style={{ width: "100%", height: "100%", background: color, transform: `scaleX(${gate.state === "passed" ? 1 : gate.state === "in-flight" ? 0.55 : 0})`, transformOrigin: "left center", transition: "transform .3s ease" }} />
      </div>
    </div>
  );
}

function AetherionLifecycleStack({ gates }) {
  return (
    <Panel title="Lifecycle · 9 gates">
      <div style={{ padding: 12 }}>
        <div
          role="list"
          style={{
            display: "grid",
            gridTemplateColumns: "repeat(9, minmax(0, 1fr))",
            gap: 6,
          }}
        >
          {gates.map(function(g, i) {
            return <AetherionLifecycleBar key={g.id} gate={g} idx={i} total={gates.length} />;
          })}
        </div>
        <div style={{ display: "flex", gap: 14, marginTop: 12, flexWrap: "wrap" }}>
          <span style={aetMonoStyle({ fontSize: 12, color: "var(--ink-3)" })}>
            <span style={{ display: "inline-block", width: 10, height: 4, background: "var(--ok)", verticalAlign: "middle", marginRight: 6 }} />
            passed (4)
          </span>
          <span style={aetMonoStyle({ fontSize: 12, color: "var(--ink-3)" })}>
            <span style={{ display: "inline-block", width: 10, height: 4, background: "var(--space-accent, var(--info))", verticalAlign: "middle", marginRight: 6 }} />
            in-flight (3)
          </span>
          <span style={aetMonoStyle({ fontSize: 12, color: "var(--ink-3)" })}>
            <span style={{ display: "inline-block", width: 10, height: 4, background: "var(--line-strong)", verticalAlign: "middle", marginRight: 6 }} />
            upcoming (2)
          </span>
        </div>
      </div>
    </Panel>
  );
}

/* ---------- pinned hero ECO card ---------- */

function AetherionECOCard({ eco }) {
  const tone = aetSevTone(eco.severity);
  return (
    <Panel
      title="Hero ECO · pinned"
      right={
        <>
          <Pill tone={tone}>{eco.severity}</Pill>
          {eco.itar ? <ITARBadge inline /> : null}
        </>
      }
    >
      <div style={{ padding: 14, display: "grid", gap: 12 }}>
        <div>
          <div style={aetMonoStyle({ fontSize: 13, color: "var(--space-accent, var(--info))" })}>{eco.id}</div>
          <div style={{ fontSize: 14, color: "var(--ink)", marginTop: 4, lineHeight: 1.35 }}>{eco.title}</div>
          <div style={aetMonoStyle({ fontSize: 12, color: "var(--ink-3)", marginTop: 4 })}>
            {eco.target_pn} · rev {eco.rev}
          </div>
        </div>

        <div className="hr" />

        <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 10 }}>
          <div>
            <div className="label" style={{ color: "var(--space-slate, var(--ink-3))" }}>Mass impact</div>
            <div style={aetMonoStyle({ fontSize: 14, color: "var(--ink)", marginTop: 2 })}>+{eco.mass_g.toFixed(1)} g</div>
            <div style={aetMonoStyle({ fontSize: 12, color: "var(--ink-3)" })}>
              margin {eco.margin_before_pc.toFixed(2)}% → {eco.margin_after_pc.toFixed(2)}%
            </div>
          </div>
          <div>
            <div className="label" style={{ color: "var(--space-slate, var(--ink-3))" }}>Schedule slip</div>
            <div style={aetMonoStyle({ fontSize: 14, color: "var(--warn)", marginTop: 2 })}>+{eco.schedule_days} d</div>
            <div style={aetMonoStyle({ fontSize: 12, color: "var(--ink-3)" })}>
              ACC {eco.acc_was} → {eco.acc_now}
            </div>
          </div>
        </div>

        <div>
          <div className="label" style={{ color: "var(--space-slate, var(--ink-3))" }}>Trigger</div>
          <div style={{ fontSize: 12, color: "var(--ink-2)", marginTop: 3, lineHeight: 1.4 }}>{eco.trigger}</div>
        </div>

        <div>
          <div className="label" style={{ color: "var(--space-slate, var(--ink-3))" }}>Retest plan</div>
          <div style={aetMonoStyle({ fontSize: 12, color: "var(--ink-2)", marginTop: 3, lineHeight: 1.4 })}>
            {eco.retest}
          </div>
        </div>

        <div>
          <div className="label" style={{ color: "var(--space-slate, var(--ink-3))" }}>Approvals</div>
          <div style={{ display: "grid", gap: 4, marginTop: 4 }}>
            {eco.approvals.map(function(a) {
              const ok = a.state === "signed";
              return (
                <div key={a.who} style={{ display: "grid", gridTemplateColumns: "1fr auto auto", gap: 8, alignItems: "center" }}>
                  <span style={{ fontSize: 12, color: "var(--ink-2)" }}>{a.who}</span>
                  <span style={aetMonoStyle({ fontSize: 12, color: "var(--ink-4)" })}>{a.on}</span>
                  <Pill tone={ok ? "ok" : "warn"}>{a.state}</Pill>
                </div>
              );
            })}
          </div>
        </div>

        <div style={{ display: "flex", gap: 6, marginTop: 4 }}>
          <Btn size="sm" variant="primary" icon="ArrowRight" onClick={function() { if (typeof navigate === "function") navigate("/build/eco"); }}>
            Open ECO
          </Btn>
          <Btn size="sm" icon="Eye" onClick={function() { if (typeof navigate === "function") navigate("/build/routing"); }}>
            Open routing
          </Btn>
        </div>
      </div>
    </Panel>
  );
}

/* ---------- right-rail alerts ---------- */

function AetherionAlertCard({ alert }) {
  const tone     = aetSevTone(alert.sev);
  const accent   = alert.sev === "critical" ? "var(--err)" : alert.sev === "warn" ? "var(--warn)" : "var(--space-accent, var(--info))";
  return (
    <div
      style={{
        padding: 10,
        border: "1px solid var(--space-line, var(--line-soft))",
        borderLeft: "3px solid " + accent,
        borderRadius: 4,
        background: "var(--bg-1)",
        display: "grid",
        gap: 6,
      }}
    >
      <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", gap: 6 }}>
        <span style={{ fontSize: 12, color: "var(--ink)" }}>{alert.title}</span>
        <Pill tone={tone}>{alert.sev}</Pill>
      </div>
      <div style={{ fontSize: 12, color: "var(--ink-3)", lineHeight: 1.45 }}>{alert.body}</div>
      <div>
        <Btn
          size="sm"
          variant="ghost"
          icon="ArrowRight"
          onClick={function() { if (typeof navigate === "function") navigate(alert.route); }}
        >
          {alert.link}
        </Btn>
      </div>
    </div>
  );
}

function AetherionAlertsRail({ alerts }) {
  return (
    <Panel title="Alerts · ITAR plane">
      <div style={{ padding: 12, display: "grid", gap: 8 }}>
        {alerts.map(function(a) {
          return <AetherionAlertCard key={a.title} alert={a} />;
        })}
        <div className="hr" />
        <div style={aetMonoStyle({ fontSize: 12, color: "var(--ink-4)" })}>
          aetherion-itar plane · US-persons only · no MCP egress · no AI-call egress
        </div>
      </div>
    </Panel>
  );
}

/* ---------- action footer (open ECO / routing / FRR / ledger) ---------- */

function AetherionActions() {
  return (
    <div
      style={{
        display: "flex",
        flexWrap: "wrap",
        gap: 8,
        padding: "10px 12px",
        border: "1px solid var(--space-line, var(--line-soft))",
        borderRadius: 5,
        background: "var(--bg-1)",
      }}
    >
      <span className="label" style={{ color: "var(--space-slate, var(--ink-3))", marginRight: 4, alignSelf: "center" }}>
        actions
      </span>
      <Btn size="sm" variant="primary" icon="ArrowRight" onClick={function() { if (typeof navigate === "function") navigate("/build/eco"); }}>
        Open ECO · ECO-AET-0042
      </Btn>
      <Btn size="sm" icon="Workflow" onClick={function() { if (typeof navigate === "function") navigate("/build/routing"); }}>
        Open routing
      </Btn>
      <Btn size="sm" icon="Check" onClick={function() { if (typeof navigate === "function") navigate("/forge/acceptance"); }}>
        Open FRR
      </Btn>
      <Btn size="sm" icon="Database" onClick={function() { if (typeof navigate === "function") navigate("/auditor/ledger"); }}>
        View ledger
      </Btn>
    </div>
  );
}

/* ---------- mass + power budget mini-panel ---------- */

function AetherionBudgetCard({ program }) {
  const mass_used_pc  = (program.mass_dry_kg / program.mass_cap_kg);
  const power_used_pc = ((program.power_pl_w + (program.power_bol_w - program.power_pl_w - program.power_margin_w)) / program.power_bol_w);
  return (
    <Panel title="Budgets · mass + power">
      <div style={{ padding: 14, display: "grid", gap: 14 }}>
        <div>
          <div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline" }}>
            <span className="label" style={{ color: "var(--space-slate, var(--ink-3))" }}>Mass</span>
            <span style={aetMonoStyle({ fontSize: 12, color: "var(--ink-2)" })}>
              {program.mass_dry_kg.toFixed(3)} / {program.mass_cap_kg.toFixed(3)} kg
            </span>
          </div>
          <div style={{ marginTop: 4 }}>
            <Progress value={mass_used_pc} color="var(--space-accent, var(--info))" height={6} />
          </div>
          <div style={aetMonoStyle({ fontSize: 12, color: "var(--ink-3)", marginTop: 4 })}>
            margin {program.mass_margin_pc.toFixed(1)}% · floor 10.0% · drift -0.07% post-ECO
          </div>
        </div>
        <div>
          <div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline" }}>
            <span className="label" style={{ color: "var(--space-slate, var(--ink-3))" }}>Power</span>
            <span style={aetMonoStyle({ fontSize: 12, color: "var(--ink-2)" })}>
              {(program.power_bol_w - program.power_margin_w).toFixed(1)} / {program.power_bol_w.toFixed(1)} W BOL
            </span>
          </div>
          <div style={{ marginTop: 4 }}>
            <Progress value={Math.min(1, power_used_pc)} color="var(--space-accent, var(--info))" height={6} />
          </div>
          <div style={aetMonoStyle({ fontSize: 12, color: "var(--ink-3)", marginTop: 4 })}>
            payload {program.power_pl_w.toFixed(1)} W · margin {program.power_margin_w} W · floor 5 W
          </div>
        </div>
        <div>
          <div className="label" style={{ color: "var(--space-slate, var(--ink-3))" }}>Delta-v</div>
          <div style={aetMonoStyle({ fontSize: 12, color: "var(--ink)", marginTop: 3 })}>
            30 m/s · cold-gas R-236fa · 25-yr deorbit compliant
          </div>
        </div>
      </div>
    </Panel>
  );
}

/* ---------- compliance roll-up ---------- */

function AetherionComplianceCard() {
  const items = [
    { k: "AS9100",                 v: "8.7 NCR open · 1 critical",   tone: "warn" },
    { k: "ECSS-Q-ST-70",           v: "EEE derating · cleared",      tone: "ok"   },
    { k: "ITAR data plane",        v: "us-persons only · no MCP",    tone: "info" },
    { k: "MIL-STD-461G",           v: "EMC report queued ACC -7d",   tone: "info" },
    { k: "GEVS / NASA-STD-7001",   v: "vibration env · +3 dB margin", tone: "ok"  },
    { k: "ISO 14644-1 cleanroom",  v: "Class 7 entry log nominal",   tone: "ok"   },
  ];
  return (
    <Panel title="Compliance · gates">
      <div style={{ padding: 12, display: "grid", gap: 6 }}>
        {items.map(function(it, i) {
          return (
            <div key={it.k} style={{ display: "grid", gridTemplateColumns: "140px 1fr auto", gap: 8, alignItems: "center", padding: "4px 0", borderBottom: i < items.length - 1 ? "1px solid var(--line-soft)" : "0" }}>
              <span style={aetMonoStyle({ fontSize: 12, color: "var(--space-slate, var(--ink-3))" })}>{it.k}</span>
              <span style={{ fontSize: 12, color: "var(--ink-2)", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }}>{it.v}</span>
              <Pill tone={it.tone}>{it.tone === "warn" ? "watch" : it.tone === "ok" ? "passing" : "tracked"}</Pill>
            </div>
          );
        })}
      </div>
    </Panel>
  );
}

/* ---------- main screen ---------- */

function ScreenAetherionDashboard() {
  // Use tenant-shaped fixture data when available; otherwise fall back to spec-locked fixture.
  const tenant  = useActiveTenant();
  const program = (tenant && tenant.program && tenant.program.code === "KESTREL-3") ? Object.assign({}, AET_PROGRAM, tenant.program) : AET_PROGRAM;
  const kpis    = (tenant && Array.isArray(tenant.kpis) && tenant.kpis.length === 6 && tenant.kpis[0] && tenant.kpis[0].k === "Mass margin") ? tenant.kpis : AET_KPIS;
  const gates   = (tenant && Array.isArray(tenant.gates) && tenant.gates.length === 9) ? tenant.gates : AET_GATES;
  const eco     = (tenant && tenant.heroEco && tenant.heroEco.id === "ECO-AET-0042") ? tenant.heroEco : AET_HERO_ECO;
  const alerts  = (tenant && Array.isArray(tenant.alerts) && tenant.alerts.length) ? tenant.alerts : AET_ALERTS;

  return (
    <div
      data-tenant="aetherion"
      style={_ae_dash_rootStyle}
    >
      <AetherionHero program={program} />

      <AetherionKPIStrip kpis={kpis} />

      <div
        style={{
          display: "grid",
          gridTemplateColumns: "1.4fr 1fr 0.9fr",
          gap: 14,
          minHeight: 0,
        }}
      >
        <AetherionLifecycleStack gates={gates} />
        <AetherionECOCard eco={eco} />
        <AetherionAlertsRail alerts={alerts} />
      </div>

      <div
        style={{
          display: "grid",
          gridTemplateColumns: "1fr 1fr",
          gap: 14,
          minHeight: 0,
        }}
      >
        <AetherionBudgetCard program={program} />
        <AetherionComplianceCard />
      </div>

      {/* Wave 3C item 26: mount the live ActivityStream so Aetherion gets
          the same SSE-backed timeline as Tritan. SSE channel is tenant-aware
          via api.js so this Just Works. */}
      {(function() {
        const AS = (typeof window !== "undefined") ? window.ActivityStream : null;
        if (!AS) return null;
        return React.createElement(AS, { title: "Activity · KESTREL-3 timeline" });
      })()}

      <AetherionActions />
    </div>
  );
}

/* ---------- route registration ---------- */
/* registerPumpRoute is the existing tenant-route channel (router.jsx merges
   PUMP_ROUTES before BUILTIN_ROUTES). We register /forge/dashboard with a
   dispatching renderer: aetherion gets ScreenAetherionDashboard, every
   other tenant falls through to the existing ScreenDashboard in
   dashboard-viewer.jsx (DO NOT MODIFY). */

function aetherionDashboardRouteRenderer() {
  const t = (typeof getActiveTenant === "function") ? getActiveTenant() : null;
  const isAetherion = !!(t && t.tenant && (t.tenant.id === "aetherion" || t.tenant.id === "htu220"));
  if (isAetherion) {
    return React.createElement(ScreenAetherionDashboard);
  }
  // Fall through to the global ScreenDashboard. We do this via window lookup
  // so tenants like Tritan keep their existing renderers
  // without us importing them.
  const Fallback = (typeof window !== "undefined" && typeof window.ScreenDashboard === "function") ? window.ScreenDashboard : null;
  if (Fallback) return React.createElement(Fallback);
  return React.createElement("div", { style: { padding: 14, color: "var(--ink-3)" } }, "ScreenDashboard not loaded");
}

if (typeof registerAetherionRoute === "function") {
  registerAetherionRoute({
    path:     "/forge/dashboard",
    mode:     "forge",
    title:    "Mission dashboard",
    renderer: aetherionDashboardRouteRenderer,
  });
}

if (typeof window !== "undefined") {
  window.ScreenAetherionDashboard           = ScreenAetherionDashboard;
  window.aetherionDashboardRouteRenderer    = aetherionDashboardRouteRenderer;
  // Expose the spec-locked fixture so other agents (and tests) can read it.
  window.AET_DASHBOARD_FIXTURE = {
    program: AET_PROGRAM,
    kpis:    AET_KPIS,
    gates:   AET_GATES,
    heroEco: AET_HERO_ECO,
    alerts:  AET_ALERTS,
  };
}
})();
