(function(){
/* FORGE — Aetherion (Space tenant) Acts 5–6 screens.
   Wave A1 / Space / Agent #7.

   Babel-standalone, NO ES imports / exports. React.createElement only.
   Atom resolvers at top with one-line fallbacks. CSS vars are --space-*
   with hex fallbacks. Mono for codes, ITAR markers visible per screen,
   mass and power values render with units. No emoji. Defensive route
   registration tail.

   Screens:
     S1  ScreenAetherionTestReport   /traveler/report     — TVAC report PDF
     S2  ScreenAetherionCompliance   /build/compliance    — AS9100/ITAR/ECSS
     S3  ScreenAetherionDispatch     /line/dispatch       — Falcon 9 manifest
     S4  ScreenAetherionAcceptance   /forge/acceptance    — FRR sign-off
     S5  ScreenAetherionFieldIssues  /forge/field-issues  — anomaly tracker
     S6  ScreenAetherionAftermarket  /forge/aftermarket   — flight spares
     S7  ScreenAetherionLedger       /auditor/ledger      — 22-event ledger
*/

const { createElement: AEh56, useState: uSAE56, useEffect: uEAE56, useMemo: uMAE56 } = React;

// ──────────────────────────────────────────────────────────────────────
// Atom resolvers — defensive: prefer window.AE*, fall back to inline.
// ──────────────────────────────────────────────────────────────────────
const AECard = (typeof window !== "undefined" && window.AECard) || function (props) {
  return AEh56("div", { style: Object.assign({ background: "var(--bg-1)", border: "1px solid var(--line)", borderRadius: 8, padding: props.pad || 16, color: "var(--ink)" }, props.style || {}) }, props.children);
};
const AEPill = (typeof window !== "undefined" && window.AEPill) || function (props) {
  const tones = { ok: "var(--ok)", warn: "var(--warn)", err: "var(--err)", info: "#2D5BEA", "": "var(--ink-3)" };
  const c = tones[props.tone || ""] || tones[""];
  return AEh56("span", { style: { display: "inline-flex", alignItems: "center", height: 20, padding: "0 8px", borderRadius: 999, fontFamily: "var(--font-mono)", fontSize: 12, letterSpacing: "0.06em", textTransform: "uppercase", border: "1px solid " + c, color: c, background: "transparent" } }, props.children);
};
const AEBtn = (typeof window !== "undefined" && window.AEBtn) || function (props) {
  const variant = props.variant || "ghost";
  const map = { primary: { bg: "#2D5BEA", fg: "#FFFFFF", br: "#2D5BEA" }, ghost: { bg: "transparent", fg: "var(--ink)", br: "var(--line)" }, soft: { bg: "var(--bg-1)", fg: "var(--ink)", br: "var(--line)" }, danger: { bg: "var(--err)", fg: "#FFFFFF", br: "var(--err)" } };
  const s = map[variant] || map.ghost;
  return AEh56("button", { onClick: props.onClick, style: { display: "inline-flex", alignItems: "center", justifyContent: "center", gap: 6, height: props.small ? 26 : 30, padding: props.small ? "0 10px" : "0 14px", borderRadius: 6, cursor: "pointer", border: "1px solid " + s.br, background: s.bg, color: s.fg, fontFamily: "var(--font-ui)", fontSize: props.small ? 11 : 12, fontWeight: 600, letterSpacing: "-0.005em", whiteSpace: "nowrap" } }, props.children);
};
const AEToolbar = (typeof window !== "undefined" && window.AEToolbar) || function (props) {
  return AEh56("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", padding: "10px 16px", background: "var(--bg-1)", border: "1px solid var(--line)", borderRadius: 8, gap: 12 } },
    AEh56("div", { style: { display: "flex", alignItems: "center", gap: 10, flexWrap: "wrap" } }, props.left),
    AEh56("div", { style: { display: "flex", alignItems: "center", gap: 8, flexWrap: "wrap" } }, props.right));
};
const AEStatRow = (typeof window !== "undefined" && window.AEStatRow) || function (props) {
  return AEh56("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "baseline", padding: "6px 0", borderBottom: "1px dashed var(--line)", gap: 12 } },
    AEh56("span", { style: { fontFamily: "var(--font-ui)", fontSize: 12, color: "var(--ink-3)", textTransform: "uppercase", letterSpacing: "0.06em" } }, props.label),
    AEh56("span", { style: { fontFamily: "var(--font-mono)", fontSize: 13, color: "var(--ink)" } }, props.value, props.unit ? AEh56("span", { style: { color: "var(--ink-3)", marginLeft: 4 } }, props.unit) : null));
};
const AESectionTitle = (typeof window !== "undefined" && window.AESectionTitle) || function (props) {
  return AEh56("div", { style: { marginBottom: 12 } },
    props.kicker ? AEh56("div", { style: { fontFamily: "var(--font-mono)", fontSize: 12, letterSpacing: "0.10em", textTransform: "uppercase", color: "var(--ink-3)", marginBottom: 4 } }, props.kicker) : null,
    AEh56("div", { style: { fontFamily: "var(--font-serif, serif)", fontSize: 22, color: "var(--ink-2)", letterSpacing: "-0.01em" } }, props.children));
};
const AEFlash = (typeof window !== "undefined" && window.AEFlash) || function (props) {
  if (!props.msg) return null;
  const tones = { ok: "var(--ok)", warn: "var(--warn)", err: "var(--err)", info: "#2D5BEA" };
  const c = tones[props.kind || "info"] || tones.info;
  return AEh56("div", { style: { position: "fixed", top: 64, right: 24, zIndex: 4000, padding: "10px 14px", borderRadius: 8, border: "1px solid " + c, background: "var(--bg-1)", color: c, fontFamily: "var(--font-ui)", fontSize: 13, display: "flex", alignItems: "center", gap: 10 } },
    AEh56("span", null, props.msg),
    AEh56("button", { onClick: props.onClose, style: { border: 0, background: "transparent", color: c, cursor: "pointer", fontSize: 16, lineHeight: 1 } }, "x"));
};
const AEMassPowerBadge = (typeof window !== "undefined" && window.AEMassPowerBadge) || function (props) {
  return AEh56("span", { style: { fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--ink)" } },
    AEh56("span", null, props.mass != null ? props.mass + " g" : "—"),
    AEh56("span", { style: { color: "var(--ink-3)", margin: "0 6px" } }, "·"),
    AEh56("span", null, props.power != null ? props.power + " W" : "—"),
    props.heritage ? AEh56("span", { style: { color: "var(--ink-3)", marginLeft: 6 } }, "· " + props.heritage) : null);
};

// ITAR marker block — visible on every screen.
// Wave 3E: also surfaces the active actor's clearance state so a non-US
// Person can see they will be blocked at release time. Reads from
// window.__forgeCurrentUser (populated by client/api.js ensureAuth()).
function AEItarBar(props) {
  const cur = (typeof window !== "undefined" && window.__forgeCurrentUser) || null;
  const isUsPerson = !!(cur && cur.regulatory_ids && cur.regulatory_ids.us_person === true);
  const isExplicitNonUs = !!(cur && cur.regulatory_ids && cur.regulatory_ids.us_person === false);
  const badgeColor = isUsPerson ? "var(--ok)" : (isExplicitNonUs ? "var(--err)" : "var(--ink-3)");
  const badgeLabel = isUsPerson ? "ITAR CLEARED" : (isExplicitNonUs ? "NON-US PERSON" : "UNKNOWN CLEARANCE");
  return AEh56("div", { style: { padding: "6px 12px", background: "var(--line)", border: "1px solid var(--line-strong)", borderRadius: 6, fontFamily: "var(--font-mono)", fontSize: 12, letterSpacing: "0.10em", textTransform: "uppercase", color: "var(--warn)", display: "flex", alignItems: "center", gap: 10 } },
    AEh56("span", null, "ITAR · §126.18 US-PERSONS ONLY"),
    AEh56("span", { style: { color: "var(--ink-3)" } }, "·"),
    AEh56("span", { style: { color: "var(--ink-3)" } }, props.scope || "aetherion-itar plane"),
    cur ? AEh56("span", { style: { marginLeft: "auto", display: "inline-flex", alignItems: "center", gap: 6 } },
      AEh56("span", { style: { color: "var(--ink-3)" } }, "actor"),
      AEh56("span", { style: { color: "var(--ink)", textTransform: "none", letterSpacing: 0 } }, cur.name || ""),
      AEh56("span", {
        style: {
          padding: "2px 6px", borderRadius: 999,
          border: "1px solid " + badgeColor, color: badgeColor,
          fontSize: 11, letterSpacing: "0.10em",
        },
      }, badgeLabel)
    ) : null);
}

// shared mono code style
const AECodeSx = { fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--ink)", letterSpacing: 0 };
const AELabelSx = { fontFamily: "var(--font-ui)", fontSize: 12, color: "var(--ink-3)", textTransform: "uppercase", letterSpacing: "0.06em" };
const AEPageWrap = { padding: 24, background: "var(--bg-0)", color: "var(--ink)", minHeight: "100vh", fontFamily: "var(--font-ui)" };
const AEGridTwo = { display: "grid", gridTemplateColumns: "1fr 1fr", gap: 16 };
const AEGridThree = { display: "grid", gridTemplateColumns: "1fr 1fr 1fr", gap: 16 };

// hash-flash helper
function useAEFlash() {
  const [flash, setFlash] = uSAE56(null);
  uEAE56(function () { if (!flash) return; const id = setTimeout(function () { setFlash(null); }, 3000); return function () { clearTimeout(id); }; }, [flash]);
  return [flash, setFlash];
}


/* ═══════════════════════════════════════════════════════════════════════
   S1 — ScreenAetherionTestReport  /traveler/report
   TVAC test report PDF · EMI baseline · vibration spectrum · shock SRS
   Print, email, archive.
   ═══════════════════════════════════════════════════════════════════════ */

function ScreenAetherionTestReport() {
  const [flash, setFlash] = useAEFlash();
  const [tab, setTab] = uSAE56("tvac");

  const tvacRun = { id: "TVAC-AET-014R", started: "2026-05-25T08:12Z", finished: "2026-05-28T19:48Z", cycles: 24, hot: "+85.0", cold: "-40.0", ramp: 90, vacuum: "1.2e-5", verdict: "PASS" };
  const tvacRows = [
    { code: "TVAC-01", name: "Vacuum stability",       target: "<= 1e-4 torr",    measured: "1.2e-5 torr", pass: true },
    { code: "TVAC-02", name: "Hot dwell -- thermal",   target: "+85.0 +/-1.5 C",  measured: "+85.2 C",     pass: true },
    { code: "TVAC-03", name: "Cold dwell -- thermal",  target: "-40.0 +/-1.5 C",  measured: "-40.4 C",     pass: true },
    { code: "TVAC-04", name: "Hinge HG-03 pre-load",   target: ">= 0.50 Nm",      measured: "0.54 Nm",     pass: true },
    { code: "TVAC-05", name: "Hinge HG-03 strain",     target: "<= 8 ustrain",    measured: "5.3 ustrain", pass: true },
    { code: "TVAC-06", name: "Battery v drift @ cold", target: "<= 80 mV",        measured: "62 mV",       pass: true },
    { code: "TVAC-07", name: "OBC reset count",        target: "0",               measured: "0",           pass: true },
    { code: "TVAC-08", name: "X-band PA temp",         target: "<= +72 C",        measured: "+68.4 C",     pass: true },
  ];

  const emiRows = [
    { code: "CE102",  name: "Conducted emissions 10kHz-10MHz",  envelope: "MIL-STD-461G", margin: "+6 dB",  pass: true },
    { code: "CS101",  name: "Conducted susceptibility power",   envelope: "MIL-STD-461G", margin: "+11 dB", pass: true },
    { code: "RE102",  name: "Radiated emissions 10kHz-18GHz",   envelope: "MIL-STD-461G", margin: "+4 dB",  pass: true },
    { code: "RS103",  name: "Radiated susceptibility 2V/m",     envelope: "MIL-STD-461G", margin: "+8 dB",  pass: true },
  ];

  const vibSpectrum = [
    { hz: 20,  g2hz: 0.013 }, { hz: 50,  g2hz: 0.023 }, { hz: 80,  g2hz: 0.040 }, { hz: 100, g2hz: 0.048 },
    { hz: 200, g2hz: 0.060 }, { hz: 350, g2hz: 0.052 }, { hz: 500, g2hz: 0.038 }, { hz: 800, g2hz: 0.024 },
    { hz: 1200, g2hz: 0.012 }, { hz: 2000, g2hz: 0.005 },
  ];
  const shockSrs = [
    { hz: 100, g: 60 }, { hz: 200, g: 180 }, { hz: 500, g: 600 }, { hz: 1000, g: 1400 },
    { hz: 2000, g: 2100 }, { hz: 4000, g: 2400 }, { hz: 8000, g: 2300 }, { hz: 10000, g: 2050 },
  ];

  function archive() { setFlash({ kind: "ok", msg: "Report TVAC-AET-014R archived to ledger://aetherion/qual/2026" }); }
  function emailRpt() { setFlash({ kind: "info", msg: "Email queued to mission-director@aetherion · cc Aperture Earth" }); }
  function printRpt() { setFlash({ kind: "info", msg: "Print job sent · 18 pages · letter-pdf · TVAC-AET-014R" }); }

  function vibChart() {
    const w = 360, h = 180, pad = 28;
    const xs = vibSpectrum.map(function (p) { return p.hz; });
    const ys = vibSpectrum.map(function (p) { return p.g2hz; });
    const xmin = Math.min.apply(null, xs), xmax = Math.max.apply(null, xs);
    const ymin = 0, ymax = Math.max.apply(null, ys);
    const sx = function (x) { return pad + (Math.log10(x) - Math.log10(xmin)) / (Math.log10(xmax) - Math.log10(xmin)) * (w - pad - 8); };
    const sy = function (y) { return h - pad - (y - ymin) / (ymax - ymin) * (h - pad - 8); };
    const d = vibSpectrum.map(function (p, i) { return (i ? "L" : "M") + sx(p.hz).toFixed(1) + "," + sy(p.g2hz).toFixed(1); }).join(" ");
    return AEh56("svg", { width: w, height: h, style: { background: "var(--bg-0)", border: "1px solid var(--line)", borderRadius: 6 } },
      AEh56("path", { d: d, fill: "none", stroke: "#2D5BEA", strokeWidth: 1.6 }),
      AEh56("text", { x: pad, y: 14, fontFamily: "var(--font-mono)", fontSize: 12, fill: "var(--ink-3)" }, "Random vib PSD · 20-2000 Hz · g^2/Hz"));
  }

  function srsChart() {
    const w = 360, h = 180, pad = 28;
    const xs = shockSrs.map(function (p) { return p.hz; });
    const ys = shockSrs.map(function (p) { return p.g; });
    const xmin = Math.min.apply(null, xs), xmax = Math.max.apply(null, xs);
    const ymax = Math.max.apply(null, ys);
    const sx = function (x) { return pad + (Math.log10(x) - Math.log10(xmin)) / (Math.log10(xmax) - Math.log10(xmin)) * (w - pad - 8); };
    const sy = function (y) { return h - pad - (y / ymax) * (h - pad - 8); };
    const d = shockSrs.map(function (p, i) { return (i ? "L" : "M") + sx(p.hz).toFixed(1) + "," + sy(p.g).toFixed(1); }).join(" ");
    return AEh56("svg", { width: w, height: h, style: { background: "var(--bg-0)", border: "1px solid var(--line)", borderRadius: 6 } },
      AEh56("path", { d: d, fill: "none", stroke: "#2D5BEA", strokeWidth: 1.6 }),
      AEh56("text", { x: pad, y: 14, fontFamily: "var(--font-mono)", fontSize: 12, fill: "var(--ink-3)" }, "Pyroshock SRS · 100-10000 Hz · g · 2000g half-sine"));
  }

  return AEh56("div", { style: AEPageWrap },
    AEh56(AEFlash, { kind: flash && flash.kind, msg: flash && flash.msg, onClose: function () { setFlash(null); } }),
    AEh56(AEItarBar, { scope: "traveler://aetherion/test-report" }),
    AEh56("div", { style: { height: 16 } }),
    AEh56(AESectionTitle, { kicker: "TVAC test report · KESTREL-3" }, "TVAC-AET-014R · post-ECO-AET-0042 re-test"),
    AEh56(AEToolbar, {
      left: AEh56(React.Fragment, null,
        AEh56("span", { style: AECodeSx }, "WO-AET-001R"),
        AEh56(AEPill, { tone: "ok" }, "PASS"),
        AEh56(AEPill, { tone: "info" }, "24 / 24 cycles")),
      right: AEh56(React.Fragment, null,
        AEh56(AEBtn, { onClick: printRpt, small: true, variant: "ghost" }, "Print"),
        AEh56(AEBtn, { onClick: emailRpt, small: true, variant: "ghost" }, "Email"),
        AEh56(AEBtn, { onClick: archive, small: true, variant: "primary" }, "Archive to ledger"))
    }),
    AEh56("div", { style: { height: 16 } }),
    AEh56("div", { style: AEGridTwo },
      AEh56(AECard, null,
        AEh56(AEStatRow, { label: "Run id",       value: tvacRun.id }),
        AEh56(AEStatRow, { label: "Started",      value: tvacRun.started }),
        AEh56(AEStatRow, { label: "Finished",     value: tvacRun.finished }),
        AEh56(AEStatRow, { label: "Cycles",       value: String(tvacRun.cycles) }),
        AEh56(AEStatRow, { label: "Hot dwell",    value: tvacRun.hot, unit: "C" }),
        AEh56(AEStatRow, { label: "Cold dwell",   value: tvacRun.cold, unit: "C" }),
        AEh56(AEStatRow, { label: "Ramp",         value: String(tvacRun.ramp), unit: "min" }),
        AEh56(AEStatRow, { label: "Vacuum p95",   value: tvacRun.vacuum, unit: "torr" }),
        AEh56(AEStatRow, { label: "Verdict",      value: tvacRun.verdict })),
      AEh56(AECard, null,
        AEh56("div", { style: { display: "flex", gap: 8, marginBottom: 10 } },
          AEh56(AEBtn, { small: true, variant: tab === "tvac" ? "primary" : "ghost", onClick: function () { setTab("tvac"); } }, "TVAC"),
          AEh56(AEBtn, { small: true, variant: tab === "emi" ? "primary" : "ghost", onClick: function () { setTab("emi"); } }, "EMI baseline"),
          AEh56(AEBtn, { small: true, variant: tab === "vib" ? "primary" : "ghost", onClick: function () { setTab("vib"); } }, "Vibration"),
          AEh56(AEBtn, { small: true, variant: tab === "shock" ? "primary" : "ghost", onClick: function () { setTab("shock"); } }, "Shock SRS")),
        tab === "tvac" ? AEh56("table", { style: { width: "100%", borderCollapse: "collapse", fontFamily: "var(--font-mono)", fontSize: 12 } },
          AEh56("thead", null, AEh56("tr", { style: { color: "var(--ink-3)", textAlign: "left" } },
            AEh56("th", { style: { padding: 6 } }, "Code"), AEh56("th", { style: { padding: 6 } }, "Test"), AEh56("th", { style: { padding: 6 } }, "Target"), AEh56("th", { style: { padding: 6 } }, "Measured"), AEh56("th", { style: { padding: 6 } }, ""))),
          AEh56("tbody", null, tvacRows.map(function (r) {
            return AEh56("tr", { key: r.code, style: { borderTop: "1px solid var(--line)", color: "var(--ink)" } },
              AEh56("td", { style: { padding: 6 } }, r.code),
              AEh56("td", { style: { padding: 6 } }, r.name),
              AEh56("td", { style: { padding: 6, color: "var(--ink-3)" } }, r.target),
              AEh56("td", { style: { padding: 6 } }, r.measured),
              AEh56("td", { style: { padding: 6 } }, AEh56(AEPill, { tone: r.pass ? "ok" : "err" }, r.pass ? "PASS" : "FAIL")));
          }))) : null,
        tab === "emi" ? AEh56("table", { style: { width: "100%", borderCollapse: "collapse", fontFamily: "var(--font-mono)", fontSize: 12 } },
          AEh56("thead", null, AEh56("tr", { style: { color: "var(--ink-3)", textAlign: "left" } },
            AEh56("th", { style: { padding: 6 } }, "Code"), AEh56("th", { style: { padding: 6 } }, "Description"), AEh56("th", { style: { padding: 6 } }, "Envelope"), AEh56("th", { style: { padding: 6 } }, "Margin"), AEh56("th", { style: { padding: 6 } }, ""))),
          AEh56("tbody", null, emiRows.map(function (r) {
            return AEh56("tr", { key: r.code, style: { borderTop: "1px solid var(--line)", color: "var(--ink)" } },
              AEh56("td", { style: { padding: 6 } }, r.code),
              AEh56("td", { style: { padding: 6 } }, r.name),
              AEh56("td", { style: { padding: 6, color: "var(--ink-3)" } }, r.envelope),
              AEh56("td", { style: { padding: 6 } }, r.margin),
              AEh56("td", { style: { padding: 6 } }, AEh56(AEPill, { tone: "ok" }, "PASS")));
          }))) : null,
        tab === "vib" ? vibChart() : null,
        tab === "shock" ? srsChart() : null)),
    AEh56("div", { style: { height: 16 } }),
    AEh56(AECard, null,
      AEh56("div", { style: AELabelSx }, "Sign-off chain"),
      AEh56("div", { style: { height: 8 } }),
      AEh56("div", { style: { display: "grid", gridTemplateColumns: "1fr 1fr 1fr 1fr", gap: 12 } },
        AEh56(AEStatRow, { label: "Test eng",  value: "K. Iyer · 2026-05-28" }),
        AEh56(AEStatRow, { label: "QA",        value: "R. Banerjee · 2026-05-29" }),
        AEh56(AEStatRow, { label: "Mech CCB",  value: "M. Sato · 2026-05-29" }),
        AEh56(AEStatRow, { label: "Mission director", value: "pending · 2026-06-01 target" }))));
}


/* ═══════════════════════════════════════════════════════════════════════
   S2 — ScreenAetherionCompliance  /build/compliance
   AS9100 · ITAR · ECSS dashboard · NCRs · CAPA · waivers
   ═══════════════════════════════════════════════════════════════════════ */

function ScreenAetherionCompliance() {
  const [flash, setFlash] = useAEFlash();
  const [filter, setFilter] = uSAE56("all");

  const ncrs = [
    { id: "NCR-AET-019", title: "Hinge HG-03 pre-load loss in TVAC cycle 14", sev: "critical", status: "closed via ECO-AET-0042", opened: "2026-04-22", part: "KESTREL-3.60.HG.03" },
    { id: "NCR-AET-021", title: "EPS card silkscreen rev mismatch",            sev: "minor",    status: "rework complete",          opened: "2026-04-30", part: "KESTREL-3.20.02" },
    { id: "NCR-AET-022", title: "Harness overbraid scuff at J6 entry",         sev: "minor",    status: "rework complete",          opened: "2026-05-01", part: "KESTREL-3.80.04" },
    { id: "NCR-AET-024", title: "Star-tracker boresight 32 um residual",       sev: "major",    status: "open · CAPA pending",      opened: "2026-05-04", part: "KESTREL-3.30.01" },
  ];
  const capa = [
    { id: "CAPA-AET-007", action: "Add Belleville stack qual loop to all hinge SKUs", owner: "M. Sato",     due: "2026-06-10", status: "in-progress" },
    { id: "CAPA-AET-008", action: "Re-issue boresight align WI with 4-point check",    owner: "P. Aravind",  due: "2026-06-04", status: "open" },
    { id: "CAPA-AET-009", action: "Audit Glenair lot 4421 overbraid handling",         owner: "K. Iyer",     due: "2026-06-15", status: "in-progress" },
  ];
  const waivers = [
    { id: "WAIVER-AET-005", title: "Single-point hinge inspection accepted",  scope: "KESTREL-3.60.HG.03", granted: "2026-05-04", expires: "launch +30 d", state: "active" },
    { id: "WAIVER-AET-003", title: "Cleanroom Class 7 -> 8 during shaker run", scope: "TVAC chamber",       granted: "2026-04-12", expires: "2026-04-15",   state: "expired" },
  ];

  const matrix = [
    { code: "AS9100 8.1.1",  name: "Operational risk management (FMEA register)",   state: "ok" },
    { code: "AS9100 8.3.4",  name: "Design verification + validation matrix",       state: "ok" },
    { code: "AS9100 8.4.3",  name: "Supplier control · sub-supplier qual file",     state: "ok" },
    { code: "AS9100 8.5.1",  name: "Production process verification (FAI AS9102B)", state: "ok" },
    { code: "AS9100 8.7",    name: "Nonconformity output control (NCR + waiver)",   state: "warn" },
    { code: "AS9100 9.2",    name: "Internal audit (quarterly cadence)",            state: "ok" },
    { code: "ITAR 126.18",   name: "US-persons only access plane",                  state: "ok" },
    { code: "ITAR 130.10",   name: "Brokering registration on file",                state: "ok" },
    { code: "EAR 740.20",    name: "License exception STA scope review",            state: "ok" },
    { code: "ECSS-E-10-03",  name: "Environmental test (vib/shock/TVAC/EMC)",       state: "ok" },
    { code: "ECSS-Q-70",     name: "EEE parts derating",                            state: "ok" },
    { code: "ECSS-Q-70-08",  name: "Manual soldering of high-rel",                  state: "ok" },
    { code: "ECSS-E-32-08",  name: "Mechanical part stress",                        state: "warn" },
    { code: "NASA-STD-8739", name: "Workmanship cert review",                       state: "ok" },
  ];

  const chosen = filter === "all" ? ncrs : ncrs.filter(function (n) { return n.sev === filter; });

  return AEh56("div", { style: AEPageWrap },
    AEh56(AEFlash, { kind: flash && flash.kind, msg: flash && flash.msg, onClose: function () { setFlash(null); } }),
    AEh56(AEItarBar, { scope: "build://aetherion/compliance" }),
    AEh56("div", { style: { height: 16 } }),
    AEh56(AESectionTitle, { kicker: "AS9100 · ITAR · ECSS dashboard" }, "Compliance posture · KESTREL-3 program"),
    AEh56("div", { style: { height: 16 } }),
    AEh56("div", { style: AEGridThree },
      AEh56(AECard, null,
        AEh56("div", { style: AELabelSx }, "AS9100 clauses"),
        AEh56("div", { style: { fontFamily: "var(--font-mono)", fontSize: 22, color: "var(--ink)", marginTop: 6 } }, "5 / 6"),
        AEh56("div", { style: { fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--ink-3)" } }, "ok · 1 in warn (8.7)")),
      AEh56(AECard, null,
        AEh56("div", { style: AELabelSx }, "ITAR + EAR"),
        AEh56("div", { style: { fontFamily: "var(--font-mono)", fontSize: 22, color: "var(--ok)", marginTop: 6 } }, "ok"),
        AEh56("div", { style: { fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--ink-3)" } }, "126.18 plane active · 12 US-persons")),
      AEh56(AECard, null,
        AEh56("div", { style: AELabelSx }, "ECSS test matrix"),
        AEh56("div", { style: { fontFamily: "var(--font-mono)", fontSize: 22, color: "var(--ink)", marginTop: 6 } }, "3 / 4"),
        AEh56("div", { style: { fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--ink-3)" } }, "E-32-08 awaits mech stress sign-off"))),
    AEh56("div", { style: { height: 16 } }),
    AEh56(AECard, null,
      AEh56("div", { style: AELabelSx }, "Clause matrix"),
      AEh56("div", { style: { height: 8 } }),
      AEh56("table", { style: { width: "100%", borderCollapse: "collapse", fontFamily: "var(--font-mono)", fontSize: 12 } },
        AEh56("thead", null, AEh56("tr", { style: { textAlign: "left", color: "var(--ink-3)" } },
          AEh56("th", { style: { padding: 6 } }, "Code"),
          AEh56("th", { style: { padding: 6 } }, "Description"),
          AEh56("th", { style: { padding: 6 } }, "State"))),
        AEh56("tbody", null, matrix.map(function (m) {
          return AEh56("tr", { key: m.code, style: { borderTop: "1px solid var(--line)", color: "var(--ink)" } },
            AEh56("td", { style: { padding: 6 } }, m.code),
            AEh56("td", { style: { padding: 6 } }, m.name),
            AEh56("td", { style: { padding: 6 } }, AEh56(AEPill, { tone: m.state === "ok" ? "ok" : (m.state === "warn" ? "warn" : "err") }, m.state)));
        })))),
    AEh56("div", { style: { height: 16 } }),
    AEh56("div", { style: AEGridTwo },
      AEh56(AECard, null,
        AEh56("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 8 } },
          AEh56("div", { style: AELabelSx }, "Nonconformities"),
          AEh56("div", { style: { display: "flex", gap: 6 } },
            ["all", "critical", "major", "minor"].map(function (k) {
              return AEh56(AEBtn, { key: k, small: true, variant: filter === k ? "primary" : "ghost", onClick: function () { setFilter(k); } }, k);
            }))),
        chosen.map(function (n) {
          return AEh56("div", { key: n.id, style: { padding: "10px 0", borderTop: "1px solid var(--line)" } },
            AEh56("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", gap: 8 } },
              AEh56("span", { style: AECodeSx }, n.id),
              AEh56(AEPill, { tone: n.sev === "critical" ? "err" : (n.sev === "major" ? "warn" : "info") }, n.sev)),
            AEh56("div", { style: { fontSize: 12, color: "var(--ink)", marginTop: 4 } }, n.title),
            AEh56("div", { style: { fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--ink-3)", marginTop: 4 } }, n.part + " · opened " + n.opened + " · " + n.status));
        })),
      AEh56(AECard, null,
        AEh56("div", { style: AELabelSx }, "CAPA register"),
        AEh56("div", { style: { height: 8 } }),
        capa.map(function (c) {
          return AEh56("div", { key: c.id, style: { padding: "10px 0", borderTop: "1px solid var(--line)" } },
            AEh56("div", { style: { display: "flex", justifyContent: "space-between" } },
              AEh56("span", { style: AECodeSx }, c.id),
              AEh56(AEPill, { tone: c.status === "in-progress" ? "info" : "warn" }, c.status)),
            AEh56("div", { style: { fontSize: 12, color: "var(--ink)", marginTop: 4 } }, c.action),
            AEh56("div", { style: { fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--ink-3)", marginTop: 4 } }, "owner " + c.owner + " · due " + c.due));
        }))),
    AEh56("div", { style: { height: 16 } }),
    AEh56(AECard, null,
      AEh56("div", { style: AELabelSx }, "Active waivers"),
      AEh56("div", { style: { height: 8 } }),
      AEh56("table", { style: { width: "100%", borderCollapse: "collapse", fontFamily: "var(--font-mono)", fontSize: 12 } },
        AEh56("thead", null, AEh56("tr", { style: { textAlign: "left", color: "var(--ink-3)" } },
          AEh56("th", { style: { padding: 6 } }, "Id"),
          AEh56("th", { style: { padding: 6 } }, "Title"),
          AEh56("th", { style: { padding: 6 } }, "Scope"),
          AEh56("th", { style: { padding: 6 } }, "Granted"),
          AEh56("th", { style: { padding: 6 } }, "Expires"),
          AEh56("th", { style: { padding: 6 } }, ""))),
        AEh56("tbody", null, waivers.map(function (w) {
          return AEh56("tr", { key: w.id, style: { borderTop: "1px solid var(--line)", color: "var(--ink)" } },
            AEh56("td", { style: { padding: 6 } }, w.id),
            AEh56("td", { style: { padding: 6 } }, w.title),
            AEh56("td", { style: { padding: 6 } }, w.scope),
            AEh56("td", { style: { padding: 6 } }, w.granted),
            AEh56("td", { style: { padding: 6 } }, w.expires),
            AEh56("td", { style: { padding: 6 } }, AEh56(AEPill, { tone: w.state === "active" ? "ok" : "warn" }, w.state)));
        })))),
    AEh56("div", { style: { height: 16, textAlign: "right" } },
      AEh56(AEBtn, { small: true, variant: "ghost", onClick: function () { setFlash({ kind: "info", msg: "Compliance snapshot exported · attached to ledger://aetherion/audit" }); } }, "Export snapshot")));
}


/* ═══════════════════════════════════════════════════════════════════════
   S3 — ScreenAetherionDispatch  /line/dispatch
   Falcon 9 Transporter-15 launch manifest prep · ITAR customs · GSE
   ═══════════════════════════════════════════════════════════════════════ */

function ScreenAetherionDispatch() {
  const [flash, setFlash] = useAEFlash();
  const [step, setStep] = uSAE56(0);

  const flight = {
    vehicle: "Falcon 9 Block 5",
    mission: "Transporter-15",
    pad: "SLC-4E · Vandenberg",
    date: "2026-09-10T13:24Z",
    deployer: "EXOLaunch EXOpod 12U slot B-04",
    orbit: "SSO 525 km · LTAN 06:00 dawn-dusk",
    integrator: "SpaceX · payload integration team K",
  };

  const manifest = [
    { line: "M-01", item: "KESTREL-3 flight unit",            sn: "KESTREL-3.FU-01", mass: "12460 g", power: "70.0 W", note: "primary payload slot" },
    { line: "M-02", item: "Flight battery (charged 80%)",     sn: "BAT-AET-FU-01",   mass: "720 g",   power: "0.6 W",  note: "Li-ion 80 Wh · DOT-SP 21221" },
    { line: "M-03", item: "Arm-key · safe / arm plug",        sn: "SAP-AET-007",     mass: "120 g",   power: "0 W",    note: "remove before flight tag attached" },
    { line: "M-04", item: "Flight harness pigtail",           sn: "HARN-AET-PT-3",   mass: "85 g",    power: "0 W",    note: "Glenair 38999 series III" },
    { line: "M-05", item: "Spare M3 A286 fasteners + Belleville stack", sn: "FK-AET-12", mass: "60 g", power: "0 W",  note: "ESD bag · tag CR-2026-014" },
  ];

  const customs = [
    { code: "USML XV(a)",  doc: "Spacecraft articles -- USML Cat XV(a) declaration", status: "filed" },
    { code: "DSP-5",       doc: "Permanent export of unclassified articles",         status: "approved · 2026-08-14" },
    { code: "EEI-AES",     doc: "Electronic export information (AESDirect)",         status: "draft · awaiting B/L" },
    { code: "ITAR-126.18", doc: "US-persons handling chain attested",                status: "signed" },
    { code: "TAA",         doc: "Technical assistance agreement (none -- domestic)", status: "n/a" },
  ];

  const container = {
    id: "ATA-300-AET-002",
    type: "ATA-300 Cat I shock/vib container",
    iata: "double-walled · 50 mm Ester-foam · GFRP shell",
    drop: "1.2 m drop tested · 10 g 11 ms half-sine",
    humidity: "RH 35 %  +/- 5 %  buffered with silica + Drierite",
    purge: "GN2 0.05 psig continuous purge during transit",
    sensor: "Shockwatch 2 (75 g) + ShockLog 298 9-axis · arm at depart",
    cleanroom: "ISO 14644-1 Class 7 bag-and-purge inside",
  };

  const gse = [
    { code: "GSE-AET-12", item: "Solar array hold-down strap · cleanroom", status: "packed" },
    { code: "GSE-AET-13", item: "Star-tracker baffle cap + lanyard",       status: "packed" },
    { code: "GSE-AET-14", item: "Battery charge cart · 28 Vdc 20 A",       status: "shipping separate" },
    { code: "GSE-AET-15", item: "RF tester · X-band CW + UHF TT&C jig",    status: "shipping separate" },
    { code: "GSE-AET-16", item: "Mate / demate harness J1..J9 service set", status: "packed" },
  ];

  const steps = ["Manifest review", "ITAR + customs", "Container seal", "GSE pack", "Hand-off to integrator"];

  function advance() {
    if (step >= steps.length - 1) { setFlash({ kind: "ok", msg: "Dispatch hand-off recorded · ledger event LAUNCH_MANIFEST_LOCKED queued" }); return; }
    setStep(prev => prev + 1);
    setFlash({ kind: "info", msg: "Step advanced -> " + steps[step + 1] });
  }
  function rollback() {
    if (step <= 0) { setFlash({ kind: "warn", msg: "Already at first step" }); return; }
    setStep(prev => prev - 1);
  }

  return AEh56("div", { style: AEPageWrap },
    AEh56(AEFlash, { kind: flash && flash.kind, msg: flash && flash.msg, onClose: function () { setFlash(null); } }),
    AEh56(AEItarBar, { scope: "line://aetherion/dispatch" }),
    AEh56("div", { style: { height: 16 } }),
    AEh56(AESectionTitle, { kicker: "Launch manifest prep · " + flight.mission }, "Dispatch · Falcon 9 Transporter-15"),
    AEh56("div", { style: { height: 16 } }),
    AEh56(AECard, null,
      AEh56("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 12 } },
        AEh56("div", { style: AELabelSx }, "Hand-off ladder"),
        AEh56("div", null,
          AEh56(AEBtn, { small: true, variant: "ghost", onClick: rollback }, "Back"),
          AEh56("span", { style: { display: "inline-block", width: 8 } }),
          AEh56(AEBtn, { small: true, variant: "primary", onClick: advance }, step >= steps.length - 1 ? "Finalize" : "Advance"))),
      AEh56("div", { style: { display: "grid", gridTemplateColumns: "repeat(5, 1fr)", gap: 8 } },
        steps.map(function (s, i) {
          const done = i < step, here = i === step;
          return AEh56("div", { key: s, style: { padding: 10, border: "1px solid " + (here ? "#2D5BEA" : "var(--line)"), borderRadius: 6, background: done ? "var(--line)" : "transparent" } },
            AEh56("div", { style: { fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--ink-3)" } }, "Step " + (i + 1)),
            AEh56("div", { style: { fontSize: 12, color: "var(--ink-2)", marginTop: 4 } }, s),
            AEh56("div", { style: { marginTop: 6 } },
              AEh56(AEPill, { tone: done ? "ok" : (here ? "info" : "") }, done ? "done" : (here ? "active" : "pending"))));
        }))),
    AEh56("div", { style: { height: 16 } }),
    AEh56("div", { style: AEGridTwo },
      AEh56(AECard, null,
        AEh56("div", { style: AELabelSx }, "Flight manifest"),
        AEh56("div", { style: { height: 8 } }),
        AEh56(AEStatRow, { label: "Vehicle",     value: flight.vehicle }),
        AEh56(AEStatRow, { label: "Mission",     value: flight.mission }),
        AEh56(AEStatRow, { label: "Pad",         value: flight.pad }),
        AEh56(AEStatRow, { label: "T-0",         value: flight.date }),
        AEh56(AEStatRow, { label: "Deployer",    value: flight.deployer }),
        AEh56(AEStatRow, { label: "Orbit",       value: flight.orbit }),
        AEh56(AEStatRow, { label: "Integrator",  value: flight.integrator })),
      AEh56(AECard, null,
        AEh56("div", { style: AELabelSx }, "Container · " + container.id),
        AEh56("div", { style: { height: 8 } }),
        AEh56(AEStatRow, { label: "Type",        value: container.type }),
        AEh56(AEStatRow, { label: "Construction", value: container.iata }),
        AEh56(AEStatRow, { label: "Drop spec",   value: container.drop }),
        AEh56(AEStatRow, { label: "Humidity",    value: container.humidity }),
        AEh56(AEStatRow, { label: "Purge",       value: container.purge }),
        AEh56(AEStatRow, { label: "Sensor",      value: container.sensor }),
        AEh56(AEStatRow, { label: "Cleanroom",   value: container.cleanroom }))),
    AEh56("div", { style: { height: 16 } }),
    AEh56(AECard, null,
      AEh56("div", { style: AELabelSx }, "Manifest items"),
      AEh56("table", { style: { width: "100%", borderCollapse: "collapse", fontFamily: "var(--font-mono)", fontSize: 12, marginTop: 8 } },
        AEh56("thead", null, AEh56("tr", { style: { textAlign: "left", color: "var(--ink-3)" } },
          AEh56("th", { style: { padding: 6 } }, "Line"),
          AEh56("th", { style: { padding: 6 } }, "Item"),
          AEh56("th", { style: { padding: 6 } }, "Serial"),
          AEh56("th", { style: { padding: 6 } }, "Mass"),
          AEh56("th", { style: { padding: 6 } }, "Power"),
          AEh56("th", { style: { padding: 6 } }, "Note"))),
        AEh56("tbody", null, manifest.map(function (m) {
          return AEh56("tr", { key: m.line, style: { borderTop: "1px solid var(--line)", color: "var(--ink)" } },
            AEh56("td", { style: { padding: 6 } }, m.line),
            AEh56("td", { style: { padding: 6 } }, m.item),
            AEh56("td", { style: { padding: 6 } }, m.sn),
            AEh56("td", { style: { padding: 6 } }, m.mass),
            AEh56("td", { style: { padding: 6 } }, m.power),
            AEh56("td", { style: { padding: 6, color: "var(--ink-3)" } }, m.note));
        })))),
    AEh56("div", { style: { height: 16 } }),
    AEh56("div", { style: AEGridTwo },
      AEh56(AECard, null,
        AEh56("div", { style: AELabelSx }, "ITAR + customs filings"),
        AEh56("div", { style: { height: 8 } }),
        customs.map(function (c) {
          return AEh56("div", { key: c.code, style: { padding: "8px 0", borderTop: "1px solid var(--line)" } },
            AEh56("div", { style: { display: "flex", justifyContent: "space-between" } },
              AEh56("span", { style: AECodeSx }, c.code),
              AEh56(AEPill, { tone: c.status.indexOf("approved") >= 0 || c.status.indexOf("signed") >= 0 || c.status.indexOf("filed") >= 0 ? "ok" : (c.status.indexOf("draft") >= 0 ? "warn" : "info") }, c.status)),
            AEh56("div", { style: { fontSize: 12, color: "var(--ink)", marginTop: 4 } }, c.doc));
        })),
      AEh56(AECard, null,
        AEh56("div", { style: AELabelSx }, "GSE inventory"),
        AEh56("div", { style: { height: 8 } }),
        gse.map(function (g) {
          return AEh56("div", { key: g.code, style: { padding: "8px 0", borderTop: "1px solid var(--line)", display: "flex", justifyContent: "space-between" } },
            AEh56("div", null,
              AEh56("div", { style: AECodeSx }, g.code),
              AEh56("div", { style: { fontSize: 12, color: "var(--ink)", marginTop: 4 } }, g.item)),
            AEh56("div", null, AEh56(AEPill, { tone: g.status === "packed" ? "ok" : "info" }, g.status)));
        }))));
}


/* ═══════════════════════════════════════════════════════════════════════
   S4 — ScreenAetherionAcceptance  /forge/acceptance
   Aperture Earth Analytics witness flow · FRR signoff
   ═══════════════════════════════════════════════════════════════════════ */

function ScreenAetherionAcceptance() {
  const [flash, setFlash] = useAEFlash();
  const [signed, setSigned] = uSAE56({ aetherion: false, customer: false, mission: false });

  const witnesses = [
    { name: "Diane Ortega",   role: "Aperture Earth · Mission Lead",        on: true,  badge: "AEA-LEAD-01" },
    { name: "Dr. Henry Voss", role: "Aperture Earth · Payload SE",          on: true,  badge: "AEA-PAY-04" },
    { name: "M. Sato",        role: "Aetherion · Mech Lead",                on: true,  badge: "AET-MECH-01" },
    { name: "P. Aravind",     role: "Aetherion · ADCS Lead",                on: true,  badge: "AET-ADCS-01" },
    { name: "K. Iyer",        role: "Aetherion · Test Eng",                 on: true,  badge: "AET-TEST-02" },
    { name: "R. Banerjee",    role: "Aetherion · QA Lead",                  on: true,  badge: "AET-QA-01" },
    { name: "Cmdr Ila Park",  role: "Mission Director · external chair",    on: true,  badge: "MD-EXT-AET" },
  ];

  const frrAgenda = [
    { code: "FRR-01", topic: "Mass + power budget close-out",           status: "ok" },
    { code: "FRR-02", topic: "ECO-AET-0042 hinge re-test summary",      status: "ok" },
    { code: "FRR-03", topic: "TVAC-AET-014R full pass",                 status: "ok" },
    { code: "FRR-04", topic: "Vibration + shock margin",                status: "ok" },
    { code: "FRR-05", topic: "EMI / EMC MIL-STD-461G coverage",         status: "ok" },
    { code: "FRR-06", topic: "Radiation TID 30 krad confirmed",         status: "ok" },
    { code: "FRR-07", topic: "Star-tracker boresight 32 um residual",   status: "warn" },
    { code: "FRR-08", topic: "Cleanroom log + ESD continuity",          status: "ok" },
    { code: "FRR-09", topic: "Open NCR / waiver review",                status: "warn" },
    { code: "FRR-10", topic: "Launch day ConOps + comms plan",          status: "ok" },
    { code: "FRR-11", topic: "Customer acceptance of as-built",         status: "open" },
  ];

  const acceptance = {
    pn: "KESTREL-3.00.00 rev D",
    sn: "KESTREL-3.FU-01",
    mass_dry: 12.460,
    mass_cap: 14.000,
    power_bol: 70.0,
    power_payload_avg: 32.0,
    delta_v: 30,
    // $4.2M rendered via forgeI18n when loaded; fallback preserves legibility.
    contract: "Aperture Earth FFP CR-2026-014 · " + ((typeof window !== "undefined" && window.forgeI18n && window.forgeI18n.formatMoneyMinor && window.forgeI18n.formatMoneyMinor("420000000", "USD")) || "$4.2M"),
  };

  function sign(role) {
    const next = Object.assign({}, signed); next[role] = true; setSigned(next);
    setFlash({ kind: "ok", msg: "Signed by " + role + " · ledger event ACC_PASSED queued on full sign" });
  }
  const allSigned = signed.aetherion && signed.customer && signed.mission;

  return AEh56("div", { style: AEPageWrap },
    AEh56(AEFlash, { kind: flash && flash.kind, msg: flash && flash.msg, onClose: function () { setFlash(null); } }),
    AEh56(AEItarBar, { scope: "forge://aetherion/acceptance" }),
    AEh56("div", { style: { height: 16 } }),
    AEh56(AESectionTitle, { kicker: "Flight readiness review · KESTREL-3" }, "Acceptance · Aperture Earth witness flow"),
    AEh56("div", { style: { height: 16 } }),
    AEh56("div", { style: AEGridTwo },
      AEh56(AECard, null,
        AEh56("div", { style: AELabelSx }, "Vehicle under acceptance"),
        AEh56("div", { style: { height: 8 } }),
        AEh56(AEStatRow, { label: "Part number", value: acceptance.pn }),
        AEh56(AEStatRow, { label: "Serial",      value: acceptance.sn }),
        AEh56(AEStatRow, { label: "Mass dry",    value: acceptance.mass_dry.toFixed(3), unit: "kg" }),
        AEh56(AEStatRow, { label: "Mass cap",    value: acceptance.mass_cap.toFixed(3), unit: "kg" }),
        AEh56(AEStatRow, { label: "Power BOL",   value: acceptance.power_bol.toFixed(1), unit: "W" }),
        AEh56(AEStatRow, { label: "Payload avg", value: acceptance.power_payload_avg.toFixed(1), unit: "W" }),
        AEh56(AEStatRow, { label: "Delta-v EOL", value: String(acceptance.delta_v), unit: "m/s" }),
        AEh56(AEStatRow, { label: "Contract",    value: acceptance.contract })),
      AEh56(AECard, null,
        AEh56("div", { style: AELabelSx }, "Witnesses on site"),
        AEh56("div", { style: { height: 8 } }),
        witnesses.map(function (w) {
          return AEh56("div", { key: w.badge, style: { padding: "8px 0", borderTop: "1px solid var(--line)" } },
            AEh56("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center" } },
              AEh56("div", null,
                AEh56("div", { style: { fontSize: 12, color: "var(--ink-2)" } }, w.name),
                AEh56("div", { style: { fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--ink-3)", marginTop: 2 } }, w.role + " · " + w.badge)),
              AEh56(AEPill, { tone: "ok" }, "on site")));
        }))),
    AEh56("div", { style: { height: 16 } }),
    AEh56(AECard, null,
      AEh56("div", { style: AELabelSx }, "FRR agenda"),
      AEh56("table", { style: { width: "100%", borderCollapse: "collapse", fontFamily: "var(--font-mono)", fontSize: 12, marginTop: 8 } },
        AEh56("thead", null, AEh56("tr", { style: { textAlign: "left", color: "var(--ink-3)" } },
          AEh56("th", { style: { padding: 6 } }, "Code"),
          AEh56("th", { style: { padding: 6 } }, "Topic"),
          AEh56("th", { style: { padding: 6 } }, "State"))),
        AEh56("tbody", null, frrAgenda.map(function (r) {
          return AEh56("tr", { key: r.code, style: { borderTop: "1px solid var(--line)", color: "var(--ink)" } },
            AEh56("td", { style: { padding: 6 } }, r.code),
            AEh56("td", { style: { padding: 6 } }, r.topic),
            AEh56("td", { style: { padding: 6 } }, AEh56(AEPill, { tone: r.status === "ok" ? "ok" : (r.status === "warn" ? "warn" : "info") }, r.status)));
        })))),
    AEh56("div", { style: { height: 16 } }),
    AEh56(AECard, null,
      AEh56("div", { style: AELabelSx }, "Sign-off ladder"),
      AEh56("div", { style: { display: "grid", gridTemplateColumns: "1fr 1fr 1fr", gap: 12, marginTop: 10 } },
        AEh56("div", { style: { padding: 12, border: "1px solid " + (signed.aetherion ? "var(--ok)" : "var(--line)"), borderRadius: 6 } },
          AEh56("div", { style: AELabelSx }, "Aetherion (vendor)"),
          AEh56("div", { style: { fontSize: 12, color: "var(--ink-2)", margin: "6px 0" } }, "Mission director · Aetherion"),
          AEh56(AEBtn, { small: true, variant: signed.aetherion ? "ghost" : "primary", onClick: function () { sign("aetherion"); } }, signed.aetherion ? "signed" : "Sign")),
        AEh56("div", { style: { padding: 12, border: "1px solid " + (signed.customer ? "var(--ok)" : "var(--line)"), borderRadius: 6 } },
          AEh56("div", { style: AELabelSx }, "Customer"),
          AEh56("div", { style: { fontSize: 12, color: "var(--ink-2)", margin: "6px 0" } }, "Diane Ortega · Aperture Earth"),
          AEh56(AEBtn, { small: true, variant: signed.customer ? "ghost" : "primary", onClick: function () { sign("customer"); } }, signed.customer ? "signed" : "Sign")),
        AEh56("div", { style: { padding: 12, border: "1px solid " + (signed.mission ? "var(--ok)" : "var(--line)"), borderRadius: 6 } },
          AEh56("div", { style: AELabelSx }, "External mission director"),
          AEh56("div", { style: { fontSize: 12, color: "var(--ink-2)", margin: "6px 0" } }, "Cmdr Ila Park · independent chair"),
          AEh56(AEBtn, { small: true, variant: signed.mission ? "ghost" : "primary", onClick: function () { sign("mission"); } }, signed.mission ? "signed" : "Sign"))),
      AEh56("div", { style: { marginTop: 16, padding: 12, border: "1px solid " + (allSigned ? "var(--ok)" : "var(--line)"), borderRadius: 6, background: allSigned ? "var(--bg-1)" : "transparent" } },
        AEh56("div", { style: AELabelSx }, "ACC verdict"),
        AEh56("div", { style: { fontFamily: "var(--font-mono)", fontSize: 18, color: allSigned ? "var(--ok)" : "var(--ink-3)", marginTop: 6 } }, allSigned ? "ACCEPTED · ledger event ACC_PASSED" : "awaiting all three signatures"))));
}


/* ═══════════════════════════════════════════════════════════════════════
   S5 — ScreenAetherionFieldIssues  /forge/field-issues
   On-orbit anomaly tracker. For demo, populate w/ TVAC chatter NCR.
   ═══════════════════════════════════════════════════════════════════════ */

function ScreenAetherionFieldIssues() {
  const [flash, setFlash] = useAEFlash();
  const [selected, setSelected] = uSAE56("FA-AET-001");

  const issues = [
    { id: "FA-AET-001", title: "Hinge HG-03 pre-load loss (TVAC chatter, pre-launch)", phase: "pre-launch", sev: "critical", state: "closed via ECO-AET-0042", opened: "2026-04-22", closed: "2026-05-28", impact: "schedule slip 11 d, no flight loss" },
    { id: "FA-AET-002", title: "Star-tracker boresight residual 32 um",                phase: "pre-launch", sev: "major",    state: "open · CAPA-AET-008",      opened: "2026-05-04", closed: "—",          impact: "pointing 0.018 deg over budget" },
    { id: "FA-AET-003", title: "Battery pack cold-soak v drift 62 mV (margin 80 mV)",  phase: "pre-launch", sev: "minor",    state: "monitoring",               opened: "2026-05-12", closed: "—",          impact: "no waiver, telemetry watch" },
    { id: "FA-AET-004", title: "X-band PA peak 68.4 C in TVAC hot dwell",              phase: "pre-launch", sev: "minor",    state: "closed · within margin",   opened: "2026-05-13", closed: "2026-05-20", impact: "thermal margin reduced 4 C" },
    { id: "FA-AET-005", title: "OBC card ECC scrub event during EMI run RS103",        phase: "pre-launch", sev: "minor",    state: "closed · CSL traced",      opened: "2026-05-14", closed: "2026-05-22", impact: "single-event, no upset" },
  ];

  const detail = issues.find(function (i) { return i.id === selected; }) || issues[0];

  // Drill-down for FA-AET-001 (TVAC chatter)
  const tvacDrill = {
    run: "TVAC-AET-014",
    cycle: "14 of 24",
    profile: "-40 C -> +85 C, 90 min ramps",
    instrument: "strain gauge SG-HG-03 + torque audit",
    finding: "50 um pre-load loss, torque 0.42 Nm vs spec 0.55 +/- 0.05 Nm",
    rca: "M3 A2-70 + Nord-Lock fatigues at -40 C; PDR Belleville modeling covered 25 cycles, flight profile is 60 BOL + 200 op",
    fix: "M3 A286 stainless DIN EN 2516 + 4x Belleville DIN 2093 series-parallel HHHL + Vibra-Tite 213, re-torque audit at +1 d",
    retest: "TVAC-AET-014R: 24 cycles -40 / +85, strain + torque audit at cycle 24, plus shock-survival 2000g half-sine 0.5 ms",
    massImpact: "+9.6 g top-assy (+2.4 g x 4 hinges), margin 11.0% -> 10.93%",
    schedImpact: "11 d slip · ACC 2026-07-04 -> 2026-07-15 · LAUNCH holds",
    ledger: ["NCR_LOGGED · NCR-AET-019", "ECO_RAISED · ECO-AET-0042", "ECO_BOARD_REVIEW · Mech CCB + Q&MA", "WAIVER_GRANTED · WAIVER-AET-005", "TVAC_TEST_RUN · TVAC-AET-014R"],
  };

  const filterCounts = {
    open: issues.filter(function (i) { return i.state.indexOf("open") >= 0 || i.state.indexOf("monitoring") >= 0; }).length,
    closed: issues.filter(function (i) { return i.state.indexOf("closed") >= 0; }).length,
    critical: issues.filter(function (i) { return i.sev === "critical"; }).length,
  };

  return AEh56("div", { style: AEPageWrap },
    AEh56(AEFlash, { kind: flash && flash.kind, msg: flash && flash.msg, onClose: function () { setFlash(null); } }),
    AEh56(AEItarBar, { scope: "forge://aetherion/field-issues" }),
    AEh56("div", { style: { height: 16 } }),
    AEh56(AESectionTitle, { kicker: "Field anomaly tracker · KESTREL-3" }, "Field issues · pre-launch + on-orbit"),
    AEh56("div", { style: { height: 16 } }),
    AEh56("div", { style: AEGridThree },
      AEh56(AECard, null,
        AEh56("div", { style: AELabelSx }, "Open"),
        AEh56("div", { style: { fontFamily: "var(--font-mono)", fontSize: 22, color: "var(--warn)", marginTop: 6 } }, String(filterCounts.open))),
      AEh56(AECard, null,
        AEh56("div", { style: AELabelSx }, "Closed"),
        AEh56("div", { style: { fontFamily: "var(--font-mono)", fontSize: 22, color: "var(--ok)", marginTop: 6 } }, String(filterCounts.closed))),
      AEh56(AECard, null,
        AEh56("div", { style: AELabelSx }, "Critical (lifetime)"),
        AEh56("div", { style: { fontFamily: "var(--font-mono)", fontSize: 22, color: "var(--err)", marginTop: 6 } }, String(filterCounts.critical)))),
    AEh56("div", { style: { height: 16 } }),
    AEh56("div", { style: { display: "grid", gridTemplateColumns: "320px 1fr", gap: 16 } },
      AEh56(AECard, null,
        AEh56("div", { style: AELabelSx }, "Issue list"),
        AEh56("div", { style: { height: 8 } }),
        issues.map(function (i) {
          const sel = i.id === selected;
          return AEh56("div", { key: i.id, onClick: function () { setSelected(i.id); }, style: { padding: 10, border: "1px solid " + (sel ? "#2D5BEA" : "var(--line)"), borderRadius: 6, marginBottom: 8, cursor: "pointer", background: sel ? "var(--bg-1)" : "transparent" } },
            AEh56("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center" } },
              AEh56("span", { style: AECodeSx }, i.id),
              AEh56(AEPill, { tone: i.sev === "critical" ? "err" : (i.sev === "major" ? "warn" : "info") }, i.sev)),
            AEh56("div", { style: { fontSize: 12, color: "var(--ink)", marginTop: 4 } }, i.title),
            AEh56("div", { style: { fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--ink-3)", marginTop: 4 } }, i.phase + " · " + i.state));
        })),
      AEh56(AECard, null,
        AEh56("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 8 } },
          AEh56("div", null,
            AEh56("div", { style: AELabelSx }, detail.id),
            AEh56("div", { style: { fontSize: 14, color: "var(--ink-2)", marginTop: 4 } }, detail.title)),
          AEh56(AEPill, { tone: detail.sev === "critical" ? "err" : (detail.sev === "major" ? "warn" : "info") }, detail.sev)),
        AEh56("div", { style: { display: "grid", gridTemplateColumns: "1fr 1fr", gap: 12, marginTop: 8 } },
          AEh56(AEStatRow, { label: "Phase",   value: detail.phase }),
          AEh56(AEStatRow, { label: "State",   value: detail.state }),
          AEh56(AEStatRow, { label: "Opened",  value: detail.opened }),
          AEh56(AEStatRow, { label: "Closed",  value: detail.closed }),
          AEh56(AEStatRow, { label: "Impact",  value: detail.impact })),
        detail.id === "FA-AET-001" ? AEh56("div", { style: { marginTop: 16 } },
          AEh56("div", { style: AELabelSx }, "TVAC chatter drill-down"),
          AEh56("div", { style: { height: 8 } }),
          AEh56(AEStatRow, { label: "Run",          value: tvacDrill.run }),
          AEh56(AEStatRow, { label: "Cycle",        value: tvacDrill.cycle }),
          AEh56(AEStatRow, { label: "Profile",      value: tvacDrill.profile }),
          AEh56(AEStatRow, { label: "Instrument",   value: tvacDrill.instrument }),
          AEh56(AEStatRow, { label: "Finding",      value: tvacDrill.finding }),
          AEh56(AEStatRow, { label: "Root cause",   value: tvacDrill.rca }),
          AEh56(AEStatRow, { label: "Fix",          value: tvacDrill.fix }),
          AEh56(AEStatRow, { label: "Re-test plan", value: tvacDrill.retest }),
          AEh56(AEStatRow, { label: "Mass impact",  value: tvacDrill.massImpact }),
          AEh56(AEStatRow, { label: "Schedule",     value: tvacDrill.schedImpact }),
          AEh56("div", { style: { height: 12 } }),
          AEh56("div", { style: AELabelSx }, "Ledger trail"),
          AEh56("div", { style: { display: "flex", flexDirection: "column", gap: 6, marginTop: 8 } },
            tvacDrill.ledger.map(function (l, i) { return AEh56("div", { key: i, style: AECodeSx }, "· " + l); })),
          AEh56("div", { style: { height: 12 } }),
          AEh56("div", null,
            AEh56(AEBtn, { small: true, variant: "ghost", onClick: function () { setFlash({ kind: "info", msg: "Anomaly export · attached to traveler://aetherion/test/s4" }); } }, "Export anomaly packet"))) : null,
        detail.id !== "FA-AET-001" ? AEh56("div", { style: { marginTop: 16 } },
          AEh56("div", { style: AELabelSx }, "Detail"),
          AEh56("div", { style: { fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--ink)", marginTop: 8, lineHeight: 1.5 } }, "Tracking on telemetry. No drill-down available pre-launch -- link the on-orbit packet on first downlink contact.")) : null)));
}


/* ═══════════════════════════════════════════════════════════════════════
   S6 — ScreenAetherionAftermarket  /forge/aftermarket
   Flight spares inventory · replacement parts pipeline
   ═══════════════════════════════════════════════════════════════════════ */

function ScreenAetherionAftermarket() {
  const [flash, setFlash] = useAEFlash();
  const [tab, setTab] = uSAE56("spares");

  const spares = [
    { sku: "KESTREL-3.10.01-FS", desc: "ISIS 12U structure base · flight spare",      qual: "qual-passed",     qty: 1, loc: "Bay-A-12", mass: 1820, power: 0,  heritage: "TRL-9" },
    { sku: "KESTREL-3.20.01-FS", desc: "AAC Sirius OBC · flight spare",               qual: "qual-passed",     qty: 1, loc: "Bay-A-14", mass: 380,  power: 4.2, heritage: "TRL-9 · ISS-6Y" },
    { sku: "KESTREL-3.20.02-FS", desc: "AAC Starbuck EPS · flight spare",             qual: "qual-passed",     qty: 1, loc: "Bay-A-15", mass: 420,  power: 4.2, heritage: "TRL-9 · ISS-6Y" },
    { sku: "KESTREL-3.30.01-FS", desc: "Sodern Auriga CP star tracker · flight spare", qual: "qual-passed",     qty: 1, loc: "Bay-B-04", mass: 280,  power: 1.6, heritage: "TRL-8" },
    { sku: "KESTREL-3.30.02-EM", desc: "Blue Canyon RWp050 reaction wheel · EM",       qual: "engineering-model", qty: 1, loc: "Bay-B-05", mass: 220,  power: 3.2, heritage: "TRL-8" },
    { sku: "KESTREL-3.60.HG.03-FS", desc: "Honeybee hinge · rev C · flight spare",     qual: "qual-passed",     qty: 4, loc: "Bay-C-02", mass: 42,   power: 0,  heritage: "TRL-9" },
    { sku: "KESTREL-3.70.00-FS", desc: "80 Wh Li-ion 8s2p pack · flight spare",        qual: "qual-passed",     qty: 1, loc: "Bay-C-08", mass: 720,  power: 0.6, heritage: "TRL-9" },
    { sku: "KESTREL-3.A0.00-FS", desc: "RF deck LNA + diplexer · flight spare",        qual: "qual-passed",     qty: 1, loc: "Bay-D-01", mass: 240,  power: 1.4, heritage: "TRL-9" },
    { sku: "KESTREL-3.B0.00-EM", desc: "1m-GSD imager · engineering model",           qual: "engineering-model", qty: 1, loc: "Bay-D-09", mass: 3270, power: 25.0, heritage: "TRL-6" },
    { sku: "KESTREL-3.80-FK",    desc: "Glenair 38999 fastener kit · 24-piece",        qual: "flight-spare",    qty: 6, loc: "Drawer-3", mass: 60,   power: 0,  heritage: "TRL-9" },
  ];

  const pipeline = [
    { id: "REP-AET-001", part: "M3 A286 stainless · DIN EN 2516", supplier: "Glenair / Belleville House",  qty: 240, due: "2026-06-04", status: "in-transit", note: "ECO-AET-0042 driven" },
    { id: "REP-AET-002", part: "DIN 2093 Belleville washer",      supplier: "Schnorr GmbH",                qty: 240, due: "2026-06-04", status: "in-transit", note: "HHHL stack" },
    { id: "REP-AET-003", part: "RWp050 EM -> flight upgrade kit", supplier: "Blue Canyon Technologies",    qty: 1,   due: "2026-07-30", status: "ordered",    note: "for 2nd flight unit" },
    { id: "REP-AET-004", part: "Auriga CP firmware v3.1.4 dvd",   supplier: "Sodern",                      qty: 1,   due: "2026-06-12", status: "ordered",    note: "boresight algorithm patch" },
    { id: "REP-AET-005", part: "MLI blanket Aerogel 2 mm cuts",   supplier: "Sheldahl",                    qty: 8,   due: "2026-06-20", status: "draft RFQ",  note: "production restock" },
  ];

  const replacementPolicy = [
    { sku: "KESTREL-3.60.HG.03-FS", policy: "1-for-4 · ECO-AET-0042 obligates full hinge swap on any TVAC strain trip" },
    { sku: "KESTREL-3.20.01-FS",    policy: "1-for-1 · OBC swap requires 24 h soak + flight FW reflash" },
    { sku: "KESTREL-3.70.00-FS",    policy: "1-for-1 · battery swap requires 8 h conditioning + capacity test" },
    { sku: "KESTREL-3.B0.00-EM",    policy: "EM only · no payload spare exists this contract; requires CR-amend for FU2" },
  ];

  const list = tab === "spares" ? spares : (tab === "pipeline" ? pipeline : replacementPolicy);

  function order(line) {
    setFlash({ kind: "info", msg: "Replenishment ticket queued for " + (line.sku || line.id) + " · supplier acknowledged" });
  }

  return AEh56("div", { style: AEPageWrap },
    AEh56(AEFlash, { kind: flash && flash.kind, msg: flash && flash.msg, onClose: function () { setFlash(null); } }),
    AEh56(AEItarBar, { scope: "forge://aetherion/aftermarket" }),
    AEh56("div", { style: { height: 16 } }),
    AEh56(AESectionTitle, { kicker: "Flight spares + replacement pipeline" }, "Aftermarket · KESTREL-3 program"),
    AEh56("div", { style: { height: 16 } }),
    AEh56(AEToolbar, {
      left: AEh56(React.Fragment, null,
        AEh56(AEBtn, { small: true, variant: tab === "spares" ? "primary" : "ghost", onClick: function () { setTab("spares"); } }, "Inventory"),
        AEh56(AEBtn, { small: true, variant: tab === "pipeline" ? "primary" : "ghost", onClick: function () { setTab("pipeline"); } }, "Replenishment pipeline"),
        AEh56(AEBtn, { small: true, variant: tab === "policy" ? "primary" : "ghost", onClick: function () { setTab("policy"); } }, "Replacement policy")),
      right: AEh56(React.Fragment, null,
        AEh56("span", { style: { fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--ink-3)" } },
          "spares ", AEh56("span", { style: { color: "var(--ink)" } }, String(spares.length)), " · pipeline ", AEh56("span", { style: { color: "var(--ink)" } }, String(pipeline.length))))
    }),
    AEh56("div", { style: { height: 16 } }),
    tab === "spares" ? AEh56(AECard, null,
      AEh56("table", { style: { width: "100%", borderCollapse: "collapse", fontFamily: "var(--font-mono)", fontSize: 12 } },
        AEh56("thead", null, AEh56("tr", { style: { textAlign: "left", color: "var(--ink-3)" } },
          AEh56("th", { style: { padding: 6 } }, "SKU"),
          AEh56("th", { style: { padding: 6 } }, "Description"),
          AEh56("th", { style: { padding: 6 } }, "Mass · Power"),
          AEh56("th", { style: { padding: 6 } }, "Qty"),
          AEh56("th", { style: { padding: 6 } }, "Loc"),
          AEh56("th", { style: { padding: 6 } }, "Qual"),
          AEh56("th", { style: { padding: 6 } }, ""))),
        AEh56("tbody", null, spares.map(function (s) {
          return AEh56("tr", { key: s.sku, style: { borderTop: "1px solid var(--line)", color: "var(--ink)" } },
            AEh56("td", { style: { padding: 6 } }, s.sku),
            AEh56("td", { style: { padding: 6 } }, s.desc),
            AEh56("td", { style: { padding: 6 } }, AEh56(AEMassPowerBadge, { mass: s.mass, power: s.power, heritage: s.heritage })),
            AEh56("td", { style: { padding: 6 } }, String(s.qty)),
            AEh56("td", { style: { padding: 6, color: "var(--ink-3)" } }, s.loc),
            AEh56("td", { style: { padding: 6 } }, AEh56(AEPill, { tone: s.qual === "qual-passed" || s.qual === "flight-spare" ? "ok" : "info" }, s.qual)),
            AEh56("td", { style: { padding: 6 } }, AEh56(AEBtn, { small: true, variant: "ghost", onClick: function () { order(s); } }, "Order +1")));
        })))) : null,
    tab === "pipeline" ? AEh56(AECard, null,
      AEh56("table", { style: { width: "100%", borderCollapse: "collapse", fontFamily: "var(--font-mono)", fontSize: 12 } },
        AEh56("thead", null, AEh56("tr", { style: { textAlign: "left", color: "var(--ink-3)" } },
          AEh56("th", { style: { padding: 6 } }, "Id"),
          AEh56("th", { style: { padding: 6 } }, "Part"),
          AEh56("th", { style: { padding: 6 } }, "Supplier"),
          AEh56("th", { style: { padding: 6 } }, "Qty"),
          AEh56("th", { style: { padding: 6 } }, "Due"),
          AEh56("th", { style: { padding: 6 } }, "Status"),
          AEh56("th", { style: { padding: 6 } }, "Note"))),
        AEh56("tbody", null, pipeline.map(function (p) {
          return AEh56("tr", { key: p.id, style: { borderTop: "1px solid var(--line)", color: "var(--ink)" } },
            AEh56("td", { style: { padding: 6 } }, p.id),
            AEh56("td", { style: { padding: 6 } }, p.part),
            AEh56("td", { style: { padding: 6 } }, p.supplier),
            AEh56("td", { style: { padding: 6 } }, String(p.qty)),
            AEh56("td", { style: { padding: 6 } }, p.due),
            AEh56("td", { style: { padding: 6 } }, AEh56(AEPill, { tone: p.status === "in-transit" ? "info" : (p.status === "ordered" ? "ok" : "warn") }, p.status)),
            AEh56("td", { style: { padding: 6, color: "var(--ink-3)" } }, p.note));
        })))) : null,
    tab === "policy" ? AEh56(AECard, null,
      AEh56("div", { style: AELabelSx }, "Replacement policy"),
      AEh56("div", { style: { height: 8 } }),
      replacementPolicy.map(function (r) {
        return AEh56("div", { key: r.sku, style: { padding: "10px 0", borderTop: "1px solid var(--line)" } },
          AEh56("div", { style: AECodeSx }, r.sku),
          AEh56("div", { style: { fontSize: 12, color: "var(--ink)", marginTop: 4 } }, r.policy));
      })) : null,
    AEh56("div", { style: { height: 16, textAlign: "right" } },
      AEh56(AEBtn, { small: true, variant: "ghost", onClick: function () { setFlash({ kind: "ok", msg: "Aftermarket snapshot exported · attached to ledger://aetherion" }); } }, "Export snapshot")));
}


/* ═══════════════════════════════════════════════════════════════════════
   S7 — ScreenAetherionLedger  /auditor/ledger
   22-event signed ledger from spec §9. Filter mode/actor/date · hash-chain
   ═══════════════════════════════════════════════════════════════════════ */

function ScreenAetherionLedger() {
  const [flash, setFlash] = useAEFlash();
  const [filterMode, setFilterMode] = uSAE56("all");
  const [filterActor, setFilterActor] = uSAE56("all");
  const [dateFrom, setDateFrom] = uSAE56("");
  const [dateTo, setDateTo] = uSAE56("");

  // Wave 3E — tab + FSM transitions panel
  const [tab, setTab] = uSAE56("events");
  const [fsmRows, setFsmRows] = uSAE56([]);
  const [fsmLoading, setFsmLoading] = uSAE56(false);
  const [fsmErr, setFsmErr] = uSAE56(null);
  const [fsmMachine, setFsmMachine] = uSAE56("all");
  const [fsmEntity, setFsmEntity] = uSAE56("");
  const [fsmLimit, setFsmLimit] = uSAE56(50);
  function loadFsmRows() {
    if (!window.forgeApi || !window.forgeApi.fsmTransitions) return;
    setFsmLoading(true); setFsmErr(null);
    const filters = { limit: fsmLimit };
    if (fsmMachine && fsmMachine !== "all") filters.machine = fsmMachine;
    if (fsmEntity) filters.entity_id = fsmEntity;
    window.forgeApi.fsmTransitions(filters)
      .then(function(r){ setFsmRows((r && r.rows) || []); setFsmLoading(false); })
      .catch(function(e){ setFsmErr(e && e.message || String(e)); setFsmLoading(false); });
  }
  uEAE56(function() {
    if (tab === "transitions") loadFsmRows();
  // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [tab, fsmMachine, fsmEntity, fsmLimit]);

  // Spec §9 — 22 events, ISO-8601 Zulu, mode `forge`
  const events = [
    { event_id: "evt-aet-001", ts: "2025-01-08T14:22Z", type: "RFQ_RECEIVED",         mode: "forge", actor: "Aperture Earth", summary: "Aperture Earth RFQ for 12U EO bus",                            ref: "RFQ-AEA-2025-001" },
    { event_id: "evt-aet-002", ts: "2025-01-12T17:45Z", type: "LOI_SIGNED",            mode: "forge", actor: "M. Sato",        summary: "Aperture Earth LOI · $4.2M FFP",                               ref: "LOI-AEA-001" },
    { event_id: "evt-aet-003", ts: "2025-01-22T09:10Z", type: "MISSION_BASELINED",     mode: "forge", actor: "P. Aravind",     summary: "KESTREL-3 mission baseline rev A locked",                      ref: "MB-KESTREL-3-A" },
    { event_id: "evt-aet-004", ts: "2025-03-04T18:02Z", type: "SRR_CLOSED",            mode: "forge", actor: "Cmdr Ila Park",  summary: "SRR review passed · 7 actions tracked",                        ref: "SRR-KESTREL-3" },
    { event_id: "evt-aet-005", ts: "2025-03-12T11:30Z", type: "MASS_BUDGET_LOCKED",    mode: "forge", actor: "M. Sato",        summary: "Mass budget 14.0 kg cap · margin policy 10%",                  ref: "MB-MASS-A" },
    { event_id: "evt-aet-006", ts: "2025-03-12T11:35Z", type: "POWER_BUDGET_LOCKED",   mode: "forge", actor: "EPS team",       summary: "Power budget 70 W BOL · margin policy 5 W",                    ref: "MB-POWER-A" },
    { event_id: "evt-aet-007", ts: "2025-06-18T16:45Z", type: "PDR_CLOSED",            mode: "forge", actor: "Cmdr Ila Park",  summary: "PDR passed · propulsion trade study attached",                 ref: "PDR-KESTREL-3" },
    { event_id: "evt-aet-008", ts: "2025-06-18T16:50Z", type: "PROPULSION_TRADE_DONE", mode: "forge", actor: "Prop team",      summary: "Cold-gas R-236fa selected over Hall thruster",                 ref: "TRADE-PROP-002" },
    { event_id: "evt-aet-009", ts: "2025-10-22T17:12Z", type: "CDR_CLOSED",            mode: "forge", actor: "Cmdr Ila Park",  summary: "CDR passed · mass margin 11.4%",                               ref: "CDR-KESTREL-3" },
    { event_id: "evt-aet-010", ts: "2025-10-30T10:20Z", type: "SUPPLIER_QUALIFIED",    mode: "forge", actor: "K. Iyer",        summary: "Honeybee + ISIS + AAC Clyde + BCT cleared at PDR",             ref: "SUP-Q-KESTREL-3" },
    { event_id: "evt-aet-011", ts: "2026-01-10T08:00Z", type: "FAB_RELEASED",          mode: "forge", actor: "R. Banerjee",    summary: "FAB-A WO-AET-001 released",                                    ref: "WO-AET-001" },
    { event_id: "evt-aet-012", ts: "2026-04-22T22:14Z", type: "TVAC_TEST_RUN",         mode: "forge", actor: "K. Iyer",        summary: "TVAC-AET-014 run on integrated vehicle",                       ref: "TVAC-AET-014" },
    { event_id: "evt-aet-013", ts: "2026-04-22T23:02Z", type: "NCR_LOGGED",            mode: "forge", actor: "R. Banerjee",    summary: "NCR-AET-019 hinge fastener pre-load loss",                     ref: "NCR-AET-019" },
    { event_id: "evt-aet-014", ts: "2026-04-24T11:18Z", type: "ECO_RAISED",            mode: "forge", actor: "M. Sato",        summary: "ECO-AET-0042 raised against KESTREL-3.60.HG.03",               ref: "ECO-AET-0042" },
    { event_id: "evt-aet-015", ts: "2026-05-02T15:45Z", type: "ECO_BOARD_REVIEW",      mode: "forge", actor: "Mech CCB",       summary: "Mech CCB + Q&MA signed",                                       ref: "ECO-AET-0042-CCB" },
    { event_id: "evt-aet-016", ts: "2026-05-04T09:00Z", type: "WAIVER_GRANTED",        mode: "forge", actor: "R. Banerjee",    summary: "WAIVER-AET-005 · single-point hinge inspection",               ref: "WAIVER-AET-005" },
    { event_id: "evt-aet-017", ts: "2026-05-28T19:48Z", type: "QUAL_PASSED",           mode: "forge", actor: "K. Iyer",        summary: "Vibration qual at GEVS+3 dB envelope passed",                  ref: "QUAL-VIB-AET" },
    { event_id: "evt-aet-018", ts: "2026-05-30T14:20Z", type: "EMC_PASSED",            mode: "forge", actor: "K. Iyer",        summary: "EMI / EMC per MIL-STD-461G passed",                            ref: "QUAL-EMC-AET" },
    { event_id: "evt-aet-019", ts: "2026-06-04T08:00Z", type: "ITAR_EXPORT_RECORDED",  mode: "forge", actor: "Compliance",     summary: "ITAR-controlled drawing pull logged for FAB-B",                ref: "ITAR-EXP-014" },
    { event_id: "evt-aet-020", ts: "2026-07-15T17:00Z", type: "ACC_PASSED",            mode: "forge", actor: "Cmdr Ila Park",  summary: "Flight acceptance signed by Mission Director",                 ref: "ACC-KESTREL-3" },
    { event_id: "evt-aet-021", ts: "2026-07-15T17:30Z", type: "CUSTOMER_ACCEPTED",     mode: "forge", actor: "Diane Ortega",   summary: "Aperture Earth pre-launch sign-off",                           ref: "CUST-ACC-AEA" },
    { event_id: "evt-aet-022", ts: "2026-09-10T13:24Z", type: "LAUNCH_MANIFEST_LOCKED", mode: "forge", actor: "SpaceX team K", summary: "Falcon 9 Transporter-15 manifest confirmed",                   ref: "MANIFEST-T15-AET" },
  ];

  // hash-chain: synthetic but stable
  const chain = uMAE56(function () {
    function djb2(s) { let h = 5381; for (let i = 0; i < s.length; i++) h = ((h << 5) + h) + s.charCodeAt(i); return (h >>> 0).toString(16).padStart(8, "0"); }
    let prev = "00000000";
    return events.map(function (e) {
      const seed = prev + e.event_id + e.ts + e.type + e.actor + e.summary + e.ref;
      const h = djb2(seed) + djb2(seed + ":2") + djb2(seed + ":3") + djb2(seed + ":4");
      const out = Object.assign({}, e, { prev_hash: prev, hash: h });
      prev = h.slice(0, 16);
      return out;
    });
  }, []);

  const actors = uMAE56(function () {
    const set = {}; events.forEach(function (e) { set[e.actor] = true; }); return ["all"].concat(Object.keys(set).sort());
  }, []);

  const filtered = chain.filter(function (e) {
    if (filterMode !== "all" && e.mode !== filterMode) return false;
    if (filterActor !== "all" && e.actor !== filterActor) return false;
    if (dateFrom && e.ts < dateFrom) return false;
    if (dateTo && e.ts > dateTo) return false;
    return true;
  });

  function verify() {
    setFlash({ kind: "ok", msg: "Hash chain verified · " + chain.length + " events · 0 mismatches · synthetic djb2 chain (production: ed25519)" });
  }
  function exportLedger(format) {
    // Wave 3E — real download. JSON is the machine-readable artifact;
    // CSV flattens events for spreadsheet review.
    const fmt = format || "json";
    if (window.forgeApi && window.forgeApi.exportAuditUrl) {
      window.location.href = window.forgeApi.exportAuditUrl(fmt);
      setFlash({ kind: "ok", msg: "Audit " + fmt.toUpperCase() + " download started · ledger + transitions + FCP envelopes" });
    } else {
      setFlash({ kind: "info", msg: "Audit export API unavailable" });
    }
  }

  function modeColor(m) { return m === "forge" ? "#2D5BEA" : (m === "auditor" ? "var(--ink-3)" : "var(--ok)"); }

  // Wave 3E — signing-algorithm banner. Honest about HMAC-SHA256 v1 + per-tenant v2 plan.
  const algBanner = AEh56("div", {
    style: {
      background: "var(--bg-1)", border: "1px solid var(--line)",
      borderLeft: "3px solid var(--warn)", borderRadius: 4,
      padding: "8px 12px", marginBottom: 12,
      fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--ink-2)", lineHeight: 1.45,
    },
  },
    AEh56("span", { style: { color: "var(--ink-2)", fontWeight: 600 } }, "Signature algorithm"),
    " · v1 uses HMAC-SHA256. Production deploys upgrade per tenant: ed25519 (Aetherion), eIDAS QES (Mittelstand), DSC Class 3 (Tritan). PDF rendering requires print-to-PDF — use JSON for machine-readable audit."
  );

  // Wave 3E — tab strip.
  const tabBar = AEh56("div", { style: { display: "flex", gap: 4, marginBottom: 12, borderBottom: "1px solid var(--line)" } },
    [
      { id: "events",      label: "Events (ledger)" },
      { id: "transitions", label: "State transitions" },
    ].map(function(t){
      const active = tab === t.id;
      return AEh56("button", {
        key: t.id, onClick: function(){ setTab(t.id); },
        style: {
          padding: "8px 14px",
          background: active ? "var(--bg-1)" : "transparent",
          border: 0,
          borderBottom: active ? "2px solid var(--ink-2)" : "2px solid transparent",
          fontFamily: "var(--font-mono)", fontSize: 12, color: active ? "var(--ink-2)" : "var(--ink-3)",
          letterSpacing: "0.06em", textTransform: "uppercase", cursor: "pointer",
        },
      }, t.label);
    })
  );

  // Wave 3E — transitions panel.
  const transitionsPanel = AEh56("div", null,
    AEh56(AECard, { style: { marginBottom: 12 } },
      AEh56("div", { style: { display: "flex", flexWrap: "wrap", alignItems: "center", gap: 12 } },
        AEh56("span", { style: AELabelSx }, "Machine"),
        AEh56("select", { value: fsmMachine, onChange: function(e){ setFsmMachine(e.target.value); },
          style: { padding: "4px 8px", background: "var(--bg-1)", color: "var(--ink)", border: "1px solid var(--line)", borderRadius: 6, fontFamily: "var(--font-mono)", fontSize: 12 } },
          ["all", "eco", "traveler", "wo"].map(function(m){ return AEh56("option", { key: m, value: m }, m); })),
        AEh56("span", { style: AELabelSx }, "Entity"),
        AEh56("input", { value: fsmEntity, onChange: function(e){ setFsmEntity(e.target.value); }, placeholder: "ECO-AET-0042",
          style: { padding: "4px 8px", background: "var(--bg-1)", color: "var(--ink)", border: "1px solid var(--line)", borderRadius: 6, fontFamily: "var(--font-mono)", fontSize: 12, width: 160 } }),
        AEh56("span", { style: AELabelSx }, "Limit"),
        AEh56("select", { value: fsmLimit, onChange: function(e){ setFsmLimit(parseInt(e.target.value, 10) || 50); },
          style: { padding: "4px 8px", background: "var(--bg-1)", color: "var(--ink)", border: "1px solid var(--line)", borderRadius: 6, fontFamily: "var(--font-mono)", fontSize: 12 } },
          [10, 50, 100, 200, 500].map(function(n){ return AEh56("option", { key: n, value: n }, n); })),
        AEh56("span", { style: { marginLeft: "auto", fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--ink-2)" } },
          fsmLoading ? "loading…" : (fsmRows.length + " rows")),
        AEh56(AEBtn, { small: true, variant: "ghost", onClick: loadFsmRows }, "Refresh")
      )
    ),
    fsmErr ? AEh56(AECard, { style: { borderColor: "var(--err)", padding: 14, color: "var(--err)", marginBottom: 12 } }, "fsm-transitions error: " + fsmErr) : null,
    AEh56(AECard, null,
      AEh56("table", { style: { width: "100%", borderCollapse: "collapse", fontFamily: "var(--font-mono)", fontSize: 12 } },
        AEh56("thead", null, AEh56("tr", { style: { textAlign: "left", color: "var(--ink-3)" } },
          ["entity_id", "machine", "verb", "from → to", "actor", "role", "ts"].map(function(h){
            return AEh56("th", { key: h, style: { padding: "8px 12px", letterSpacing: "0.06em", textTransform: "uppercase", borderBottom: "1px solid var(--line)" } }, h);
          })
        )),
        AEh56("tbody", null,
          fsmRows.length === 0 && !fsmLoading ? AEh56("tr", null, AEh56("td", { colSpan: 7, style: { padding: 24, textAlign: "center", color: "var(--ink-3)" } }, "No transitions recorded yet. (FSM v2 must be enabled for this tenant — set FORGE_FSM_V2=all.)")) : null,
          fsmRows.map(function(r){
            let iso = ""; try { iso = new Date(r.ts).toISOString().slice(0, 19) + "Z"; } catch(_e) { iso = String(r.ts); }
            return AEh56("tr", { key: r.id, style: { borderTop: "1px solid var(--line)", color: "var(--ink)" } },
              AEh56("td", { style: { padding: "8px 12px", color: "var(--ink-2)" } }, r.entity_id),
              AEh56("td", { style: { padding: "8px 12px", color: "var(--ink-3)" } }, r.machine),
              AEh56("td", { style: { padding: "8px 12px", color: "#2D5BEA" } }, r.verb),
              AEh56("td", { style: { padding: "8px 12px" } },
                AEh56("span", { style: { color: "var(--ink-3)" } }, r.from_state),
                AEh56("span", { style: { color: "var(--ink-4)" } }, " → "),
                AEh56("span", { style: { color: "var(--ink-2)" } }, r.to_state)
              ),
              AEh56("td", { style: { padding: "8px 12px", color: "var(--ink)" } }, r.actor_id || "—"),
              AEh56("td", { style: { padding: "8px 12px", color: "var(--ink-3)" } }, r.actor_role || "—"),
              AEh56("td", { style: { padding: "8px 12px", color: "var(--ink-4)" } }, iso)
            );
          })
        )
      )
    )
  );

  return AEh56("div", { style: AEPageWrap },
    AEh56(AEFlash, { kind: flash && flash.kind, msg: flash && flash.msg, onClose: function () { setFlash(null); } }),
    AEh56(AEItarBar, { scope: "auditor://aetherion/ledger" }),
    AEh56("div", { style: { height: 16 } }),
    AEh56(AESectionTitle, { kicker: "Signed event ledger · KESTREL-3 program" }, "Auditor ledger · 22 events · LOI to launch-manifest lock"),
    AEh56("div", { style: { height: 12 } }),
    algBanner,
    tabBar,
    tab === "transitions" ? transitionsPanel : AEh56(React.Fragment, null,
      AEh56(AEToolbar, {
        left: AEh56(React.Fragment, null,
          AEh56("span", { style: AELabelSx }, "Mode"),
          ["all", "forge", "auditor", "line"].map(function (m) {
            return AEh56(AEBtn, { key: m, small: true, variant: filterMode === m ? "primary" : "ghost", onClick: function () { setFilterMode(m); } }, m);
          }),
          AEh56("span", { style: { display: "inline-block", width: 12 } }),
          AEh56("span", { style: AELabelSx }, "Actor"),
          AEh56("select", { value: filterActor, onChange: function (e) { setFilterActor(e.target.value); }, style: { padding: "4px 8px", background: "var(--bg-1)", color: "var(--ink)", border: "1px solid var(--line)", borderRadius: 6, fontFamily: "var(--font-mono)", fontSize: 12 } },
            actors.map(function (a) { return AEh56("option", { key: a, value: a }, a); })),
          AEh56("span", { style: { display: "inline-block", width: 12 } }),
          AEh56("span", { style: AELabelSx }, "Date"),
          AEh56("input", { value: dateFrom, onChange: function (e) { setDateFrom(e.target.value); }, placeholder: "from ISO", style: { padding: "4px 8px", background: "var(--bg-1)", color: "var(--ink)", border: "1px solid var(--line)", borderRadius: 6, fontFamily: "var(--font-mono)", fontSize: 12, width: 140 } }),
          AEh56("input", { value: dateTo, onChange: function (e) { setDateTo(e.target.value); }, placeholder: "to ISO", style: { padding: "4px 8px", background: "var(--bg-1)", color: "var(--ink)", border: "1px solid var(--line)", borderRadius: 6, fontFamily: "var(--font-mono)", fontSize: 12, width: 140 } })),
        right: AEh56(React.Fragment, null,
          AEh56(AEBtn, { small: true, variant: "ghost", onClick: verify }, "Verify chain"),
          AEh56(AEBtn, { small: true, variant: "ghost", onClick: function(){ exportLedger("csv"); } }, "Export CSV"),
          AEh56(AEBtn, { small: true, variant: "ghost", onClick: function(){ exportLedger("json"); } }, "Export JSON"),
          // W15B — wires GET /api/:tenant/audit/export.pdf (pdfkit stream).
          AEh56(AEBtn, { small: true, variant: "primary", onClick: function(){ exportLedger("pdf"); } }, "Export PDF"))
      }),
      AEh56("div", { style: { height: 16 } }),
      AEh56(AECard, null,
        AEh56("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 8 } },
          AEh56("div", { style: AELabelSx }, "Showing " + filtered.length + " of " + chain.length + " events"),
          AEh56("div", { style: { fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--ink-3)" } }, "head hash · " + (chain[chain.length - 1] && chain[chain.length - 1].hash.slice(0, 32)))),
        AEh56("div", { style: { display: "flex", flexDirection: "column", gap: 8, marginTop: 8 } },
          filtered.map(function (e, i) {
            return AEh56("div", { key: e.event_id, style: { padding: 12, border: "1px solid var(--line)", borderRadius: 6 } },
              AEh56("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", gap: 8 } },
                AEh56("div", { style: { display: "flex", alignItems: "center", gap: 10 } },
                  AEh56("span", { style: { fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--ink-3)" } }, "#" + (i + 1).toString().padStart(2, "0")),
                  AEh56("span", { style: { fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--ink)" } }, e.ts),
                  AEh56("span", { style: { display: "inline-block", padding: "2px 8px", borderRadius: 999, border: "1px solid " + modeColor(e.mode), color: modeColor(e.mode), fontFamily: "var(--font-mono)", fontSize: 12, letterSpacing: "0.06em", textTransform: "uppercase" } }, e.mode)),
                AEh56("span", { style: { fontFamily: "var(--font-mono)", fontSize: 12, color: "#2D5BEA", letterSpacing: "0.06em" } }, e.type)),
              AEh56("div", { style: { fontSize: 13, color: "var(--ink-2)", marginTop: 6 } }, e.summary),
              AEh56("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", marginTop: 6, gap: 8 } },
                AEh56("span", { style: { fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--ink-3)" } }, "actor " + e.actor + " · ref " + e.ref),
                AEh56("span", { style: { fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--ink-3)" } },
                  "prev ", AEh56("span", { style: { color: "var(--ink)" } }, e.prev_hash.slice(0, 12)),
                  "  hash ", AEh56("span", { style: { color: "var(--ink)" } }, e.hash.slice(0, 16)))));
          })))
    )
  );
}


/* ═══════════════════════════════════════════════════════════════════════
   Defensive route registration tail
   ═══════════════════════════════════════════════════════════════════════ */

(function registerSpaceAct56Routes() {
  if (typeof window === "undefined") return;
  // Expose components on window for downstream consumers / hot reload.
  window.ScreenAetherionTestReport  = ScreenAetherionTestReport;
  window.ScreenAetherionCompliance  = ScreenAetherionCompliance;
  window.ScreenAetherionDispatch    = ScreenAetherionDispatch;
  window.ScreenAetherionAcceptance  = ScreenAetherionAcceptance;
  window.ScreenAetherionFieldIssues = ScreenAetherionFieldIssues;
  window.ScreenAetherionAftermarket = ScreenAetherionAftermarket;
  window.ScreenAetherionLedger      = ScreenAetherionLedger;

  // Route shape must match what registry-index.jsx (registerAetherionRoute)
  // expects: { path, mode, title, renderer }. The previous loop passed three
  // positional args (hash, comp, opts) and pushed a bare string into
  // AETHERION_ROUTES, which crashed app-shell.jsx#onPick on r.path.split.
  const routes = [
    { hash: "#/traveler/report",     comp: ScreenAetherionTestReport,   mode: "traveler", title: "TVAC test report" },
    { hash: "#/build/compliance",    comp: ScreenAetherionCompliance,   mode: "build",    title: "AS9100 / ITAR / ECSS compliance" },
    { hash: "#/line/dispatch",       comp: ScreenAetherionDispatch,     mode: "line",     title: "Falcon 9 dispatch manifest" },
    { hash: "#/forge/acceptance",    comp: ScreenAetherionAcceptance,   mode: "forge",    title: "FRR acceptance sign-off" },
    { hash: "#/forge/field-issues",  comp: ScreenAetherionFieldIssues,  mode: "forge",    title: "On-orbit anomaly tracker" },
    { hash: "#/forge/aftermarket",   comp: ScreenAetherionAftermarket,  mode: "forge",    title: "Flight spares & aftermarket" },
    { hash: "#/auditor/ledger",      comp: ScreenAetherionLedger,       mode: "auditor",  title: "22-event audit ledger" },
  ];

  function toRouteObject(r) {
    const path = r.hash.replace(/^#/, "");
    return {
      path:     path,
      mode:     r.mode,
      title:    r.title || path,
      renderer: function () { return React.createElement(r.comp); },
    };
  }

  // Prefer the Aetherion-specific registry helper if present.
  const reg = (window.registerSpaceRoute && typeof window.registerSpaceRoute === "function")
    ? window.registerSpaceRoute
    : (window.registerRoute && typeof window.registerRoute === "function" ? window.registerRoute : null);

  if (reg) {
    routes.forEach(function (r) {
      try { reg(toRouteObject(r)); } catch (err) { /* swallow */ }
    });
  } else {
    // Registry not loaded yet — queue routes so a later loader can flush
    // them. Match the act1-2 pattern (window.__SPACE_ACT12_PENDING_ROUTES)
    // rather than corrupting window.SPACE_ROUTES (an array per
    // registry-index.jsx) with object-shaped assignments.
    window.__SPACE_ACT56_PENDING_ROUTES =
      (window.__SPACE_ACT56_PENDING_ROUTES || []).concat(routes.map(toRouteObject));
  }
})();
})();
