(function(){
/* FORGE — Aetherion (Space) tenant Act 1-2 screens
   Mission intake → propulsion trade study → heritage config audit → FFP quote.
   Babel-standalone in-browser React. NO ES imports / exports.
   Globals used: React, navigate, registerSpaceRoute (or registerAetherionRoute), Icons.
   Hook destructures uniquely aliased to avoid global scope collisions.

   Source of truth for every part number, mass / power value, gate code,
   ledger ref, and timestamp: forge-web/demo/tenant-spec/space.md (§1-3, §6).
   Cool blues palette per §10. No emoji. Mass and power always rendered with
   units in monospace via tnum. */

const { useState: uSAE12, useMemo: uMAE12, useEffect: uEAE12 } = React;

// ───────── shared cool-blue atoms (mirror landing.jsx + space.md §10) ──────
// Deep-navy surface, mission-blue accent, slate labels — sat-ops vibe.
const AE_INK            = "oklch(0.20 0.04 260)";   // deep navy primary surface ink
const AE_INK_2          = "oklch(0.36 0.04 260)";   // body text
const AE_INK_3          = "oklch(0.50 0.03 250)";   // muted slate (labels)
const AE_INK_4          = "oklch(0.66 0.02 250)";   // tertiary
const AE_BG             = "oklch(0.985 0.005 240)"; // primary paper surface
const AE_BG_2           = "oklch(0.95 0.008 240)";  // raised
const AE_BG_3           = "oklch(0.97 0.006 240)";  // card
const AE_LINE           = "oklch(0.86 0.012 240)";
const AE_LINE_S         = "oklch(0.91 0.010 240)";
const AE_ACCENT         = "oklch(0.62 0.16 255)";   // mission-blue (#4F8FFF-ish)
const AE_ACCENT_DEEP    = "oklch(0.45 0.18 260)";   // deeper variant
const AE_ACCENT_INK     = "oklch(0.16 0.02 260)";   // ink on accent
const AE_GREEN          = "oklch(0.66 0.13 165)";   // pass / TRL-9
const AE_RED            = "oklch(0.58 0.18 28)";    // critical
const AE_AMBER          = "oklch(0.78 0.13 85)";    // pending / TRL-7
const AE_VIOLET         = "oklch(0.58 0.16 295)";   // new dev / TRL-6
const AE_GRAY           = "oklch(0.78 0.005 240)";

const AE_FONT_UI    = "var(--font-ui)";
const AE_FONT_MONO  = "var(--font-mono)";
const AE_FONT_SERIF = "var(--font-serif)";

// ───────── shared root + helpers ─────────
function aeRoot() {
  return {
    background: AE_BG,
    color: AE_INK,
    minHeight: "100vh",
    overflowY: "auto",
    fontFamily: AE_FONT_UI,
    fontSize: 14,
    lineHeight: 1.5,
    width: "100%",
    position: "absolute",
    inset: 0,
    WebkitFontSmoothing: "antialiased",
  };
}

function aeContainer() {
  return { maxWidth: 1280, margin: "0 auto", padding: "32px 40px", width: "100%" };
}

function aeMono() {
  return {
    fontFamily: AE_FONT_MONO,
    fontSize: 12,
    letterSpacing: "0.08em",
    textTransform: "uppercase",
    color: AE_INK_3,
  };
}

function AECard(props) {
  const merged = Object.assign({
    background: AE_BG_3,
    border: `1px solid ${AE_LINE}`,
    borderRadius: 10,
    padding: 20,
  }, props.style || {});
  return React.createElement("div", { style: merged }, props.children);
}

function AEPill(props) {
  const tone = props.tone || "default";
  const palette = {
    default: { bg: AE_BG_3, fg: AE_INK_2,    bd: AE_LINE  },
    accent:  { bg: AE_BG_3, fg: AE_ACCENT,   bd: AE_ACCENT },
    deep:    { bg: AE_BG_3, fg: AE_ACCENT_DEEP, bd: AE_ACCENT_DEEP },
    green:   { bg: AE_BG_3, fg: AE_GREEN,    bd: AE_GREEN },
    red:     { bg: AE_BG_3, fg: AE_RED,      bd: AE_RED   },
    amber:   { bg: AE_BG_3, fg: AE_AMBER,    bd: AE_AMBER },
    violet:  { bg: AE_BG_3, fg: AE_VIOLET,   bd: AE_VIOLET },
    mute:    { bg: AE_BG_2, fg: AE_INK_4,    bd: AE_LINE  },
  }[tone] || { bg: AE_BG_3, fg: AE_INK_2, bd: AE_LINE };
  return (
    <span style={{
      display: "inline-flex", alignItems: "center", gap: 6,
      height: 22, padding: "0 10px", borderRadius: 999,
      fontFamily: AE_FONT_MONO, fontSize: 12,
      letterSpacing: "0.08em", textTransform: "uppercase",
      border: `1px solid ${palette.bd}`,
      color: palette.fg, background: palette.bg,
    }}>{props.children}</span>
  );
}

function AEBtn(props) {
  const variant = props.variant || "primary";
  const [h, setH] = uSAE12(false);
  const base = {
    display: "inline-flex", alignItems: "center", justifyContent: "center",
    gap: 8, cursor: "pointer", fontFamily: AE_FONT_UI, fontWeight: 600,
    letterSpacing: "-0.005em", borderRadius: 8,
    transition: "transform .12s ease, background .12s ease, border-color .12s ease",
    border: "1px solid transparent", whiteSpace: "nowrap", userSelect: "none",
    height: 38, padding: "0 18px", fontSize: 13,
    transform: h ? "translateY(-1px)" : "translateY(0)",
  };
  let palette;
  if (variant === "primary") {
    palette = { background: AE_ACCENT, color: AE_ACCENT_INK, borderColor: AE_ACCENT };
  } else if (variant === "secondary") {
    palette = {
      background: h ? AE_INK : "transparent",
      color: h ? AE_BG : AE_INK,
      borderColor: AE_INK,
    };
  } else if (variant === "danger") {
    palette = {
      background: h ? AE_RED : "transparent",
      color: h ? AE_BG : AE_RED,
      borderColor: AE_RED,
    };
  } else {
    palette = {
      background: h ? AE_BG_2 : "transparent",
      color: AE_INK_2,
      borderColor: AE_LINE,
    };
  }
  return (
    <button
      onClick={props.onClick}
      onMouseEnter={() => setH(true)}
      onMouseLeave={() => setH(false)}
      style={Object.assign({}, base, palette, props.style || {})}
    >{props.children}</button>
  );
}

function AEHeader(props) {
  return (
    <div style={{ marginBottom: 28 }}>
      <div style={Object.assign({}, aeMono(), { marginBottom: 8, color: AE_ACCENT })}>{props.eyebrow}</div>
      <h1 style={{
        fontFamily: AE_FONT_SERIF, fontSize: 34, fontWeight: 600,
        letterSpacing: "-0.015em", margin: 0, color: AE_INK,
      }}>{props.title}</h1>
      {props.subtitle && (
        <div style={{ marginTop: 8, color: AE_INK_3, fontSize: 14 }}>{props.subtitle}</div>
      )}
    </div>
  );
}

function aeRowBtn() {
  return {
    padding: "4px 10px",
    fontFamily: AE_FONT_MONO,
    fontSize: 12,
    letterSpacing: "0.06em",
    textTransform: "uppercase",
    color: AE_INK_2,
    background: AE_BG_3,
    border: `1px solid ${AE_LINE}`,
    borderRadius: 6,
    cursor: "pointer",
  };
}

function aeCellHead() {
  return {
    padding: "8px 12px",
    fontFamily: AE_FONT_MONO,
    fontSize: 12,
    letterSpacing: "0.06em",
    textTransform: "uppercase",
    color: AE_INK_3,
    background: AE_BG_2,
    border: `1px solid ${AE_LINE_S}`,
    fontWeight: 500,
    whiteSpace: "nowrap",
  };
}

function aeDiffH() {
  return {
    textAlign: "left",
    padding: "12px 14px",
    fontFamily: AE_FONT_MONO,
    fontSize: 12,
    letterSpacing: "0.08em",
    textTransform: "uppercase",
    color: AE_INK_3,
    fontWeight: 500,
    borderBottom: `1px solid ${AE_LINE}`,
  };
}

function aeDiffC() {
  return { padding: "10px 14px", verticalAlign: "top" };
}

// helper: safe nav
function aeNav(path) {
  if (typeof navigate === "function") navigate(path);
}

// fmt money in USD
function aeUsd(n) {
  if (n == null) return "";
  if (n >= 1e6) return "$" + (n / 1e6).toFixed(2) + "M";
  if (n >= 1e3) return "$" + Math.round(n / 1e3) + "k";
  return "$" + n.toLocaleString("en-US");
}

// ════════════════════════════════════════════════════════════════════
// 1 · ScreenAetherionMissionIntake — /forge/rfq
// Aperture Earth Analytics LOI ($4.2M FFP) intake.
// Mission requirements: 525 km SSO, 50 Mbps X-band, 14 kg, 32 W.
// ════════════════════════════════════════════════════════════════════
function ScreenAetherionMissionIntake() {
  const [customer,    setCustomer]    = uSAE12("Aperture Earth Analytics, Inc.");
  const [contact,     setContact]     = uSAE12("Dr. Lena Park · Director, Mission Systems");
  const [busClass,    setBusClass]    = uSAE12("12U");
  const [orbitAlt,    setOrbitAlt]    = uSAE12(525);
  const [orbitInc,    setOrbitInc]    = uSAE12(97.6);
  const [orbitFrame,  setOrbitFrame]  = uSAE12("SSO · dawn-dusk");
  const [downlinkBW,  setDownlinkBW]  = uSAE12(50);
  const [downlinkBd]                  = uSAE12("X-band · 8025-8400 MHz");
  const [massCap,     setMassCap]     = uSAE12(14.0);
  const [powerAvg,    setPowerAvg]    = uSAE12(32.0);
  const [gsd,         setGsd]         = uSAE12(1.0);
  const [contractVal, setContractVal] = uSAE12(4.2);
  const [contractKind,setContractKind]= uSAE12("FFP");
  const [launchDue,   setLaunchDue]   = uSAE12("2026-09-10");
  const [classified,  setClassified]  = uSAE12(false);
  const [itar,        setItar]        = uSAE12(true);
  const [notes,       setNotes]       = uSAE12(
    "Aperture Earth validation flight for 1m-GSD X-band downlink architecture. " +
    "Single-flight pathfinder; no constellation commitments yet. Falcon 9 " +
    "Transporter-15 manifest preference; rideshare slot reserved through " +
    "Exolaunch. ITAR-controlled subsystems (RF, ADCS) — US-persons only on " +
    "design reviews. Customer expects flight-heritage on 80%+ of bus subs."
  );
  const [flash, setFlash] = uSAE12("");
  uEAE12(() => {
    if (!flash) return;
    const t = setTimeout(() => setFlash(""), 2400);
    return () => clearTimeout(t);
  }, [flash]);

  // Locale-aware money helper — keeps the FFP/ROM qualifiers untouched so the
  // shorthand survives even when forgeI18n has already resolved.
  function _aeMoney(minor, fallback) {
    var i18n = (typeof window !== "undefined") ? window.forgeI18n : null;
    if (i18n && typeof i18n.formatMoneyMinor === "function") {
      var out = i18n.formatMoneyMinor(minor, "USD");
      if (out) return out;
    }
    return fallback;
  }
  function _aeDate(iso) {
    var i18n = (typeof window !== "undefined") ? window.forgeI18n : null;
    if (i18n && typeof i18n.formatDate === "function" && /^\d{4}-\d{2}-\d{2}$/.test(iso)) {
      return i18n.formatDate(iso) || iso;
    }
    return iso;
  }

  // Prior engagements with Aperture Earth + adjacent EO contractors
  const priorRFQs = [
    { id: "RFQ-2024-007", date: "2024-08-12", bus: "6U technology demo · S-band",
      val: _aeMoney("180000000", "$1.8M") + " · FFP", status: "lost", note: "Lost — schedule slip risk" },
    { id: "LOI-2024-022", date: "2024-11-04", bus: "12U EO concept · X-band",
      val: _aeMoney("420000000", "$4.2M") + " · FFP", status: "won",  note: "This LOI · KESTREL-3 baseline" },
    { id: "RFI-2025-031", date: "2025-02-18", bus: "Constellation study · 8 sat",
      val: _aeMoney("3200000000", "$32M") + " ROM",   status: "open", note: "Phase B follow-on contingent on KESTREL-3 ACC" },
  ];

  // Heritage assets that can carry into this build
  const heritage = [
    { pn: "KESTREL-2.20.00", sub: "Avionics · OBC + EPS stack",
      trl: "TRL-9 · ISS-6Y", note: "AAC Clyde Sirius / Starbuck — 6 yrs ISS" },
    { pn: "KESTREL-2.50.00", sub: "Comms · X-band 50 Mbps + UHF TT&C",
      trl: "TRL-9",          note: "Direct port — same waveform, antenna gain" },
    { pn: "KESTREL-2.60.00", sub: "Solar array · 4× deployable wing",
      trl: "TRL-9 · ISS-6Y", note: "Honeybee hinge sub w/ Mars 2020 heritage" },
    { pn: "KESTREL-2.70.00", sub: "Battery pack · 80 Wh Li-ion (8s2p)",
      trl: "TRL-9",          note: "Re-qualify cell lot · TID delta" },
  ];

  const fld = {
    width: "100%",
    height: 38,
    padding: "0 12px",
    fontFamily: AE_FONT_UI,
    fontSize: 14,
    color: AE_INK,
    background: AE_BG,
    border: `1px solid ${AE_LINE}`,
    borderRadius: 8,
    outline: "none",
  };
  const lbl = Object.assign({}, aeMono(), { display: "block", marginBottom: 6 });

  function onSubmit() {
    setFlash("Mission intake committed · MISSION-AET-001 routed to PDR pre-work.");
    setTimeout(() => aeNav("/forge/matcher"), 700);
  }
  function onDecline() {
    setFlash("LOI declined · sales lead notified, ledger entry queued.");
  }

  return (
    <div style={aeRoot()}>
      <div style={aeContainer()}>
        <AEHeader
          eyebrow="Forge · MISSION-INTAKE"
          title="Inbound LOI — Aperture Earth Analytics"
          subtitle="Capture mission envelope. Lock contract terms. Open propulsion trade."
        />

        <div style={{ display: "grid", gridTemplateColumns: "1fr 380px", gap: 24 }}>
          {/* ───── Form ───── */}
          <AECard>
            <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 18 }}>
              <div style={aeMono()}>LOI-2024-022 · draft · KESTREL-3 baseline</div>
              <div style={{ display: "flex", gap: 8 }}>
                <AEPill tone="accent">12U bus</AEPill>
                <AEPill tone="amber">ITAR-controlled</AEPill>
                <AEPill tone="deep">FFP</AEPill>
              </div>
            </div>

            {/* customer block */}
            <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 16, marginBottom: 16 }}>
              <div>
                <label style={lbl} htmlFor="fld-space-1">Customer · legal entity</label>
                <input id="fld-space-1" style={fld} value={customer} onChange={(e) => setCustomer(e.target.value)} />
              </div>
              <div>
                <label style={lbl} htmlFor="fld-space-2">Primary contact</label>
                <input id="fld-space-2" style={fld} value={contact} onChange={(e) => setContact(e.target.value)} />
              </div>
            </div>

            {/* mission block */}
            <div style={{
              padding: 14, marginBottom: 16,
              background: AE_BG_2,
              border: `1px solid ${AE_LINE_S}`,
              borderRadius: 8,
            }}>
              <div style={Object.assign({}, aeMono(), { marginBottom: 10, color: AE_ACCENT })}>
                Mission envelope · binding at SRR
              </div>

              <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr 1fr", gap: 16, marginBottom: 12 }}>
                <div>
                  <label style={lbl} htmlFor="fld-space-3">Bus class</label>
                  <select id="fld-space-3" style={fld} value={busClass} onChange={(e) => setBusClass(e.target.value)}>
                    <option>3U</option><option>6U</option>
                    <option>12U</option><option>16U</option>
                    <option>ESPA-class</option>
                  </select>
                </div>
                <div>
                  <label style={lbl} htmlFor="fld-space-4">Mass cap (kg)</label>
                  <input
                    id="fld-space-4"
                    type="number" step="0.1" style={fld}
                    value={massCap} onChange={(e) => setMassCap(Number(e.target.value))}
                  />
                </div>
                <div>
                  <label style={lbl} htmlFor="fld-space-5">Payload power avg (W)</label>
                  <input
                    id="fld-space-5"
                    type="number" step="0.1" style={fld}
                    value={powerAvg} onChange={(e) => setPowerAvg(Number(e.target.value))}
                  />
                </div>
              </div>

              <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr 1fr", gap: 16, marginBottom: 12 }}>
                <div>
                  <label style={lbl} htmlFor="fld-space-6">Orbit altitude (km)</label>
                  <input
                    id="fld-space-6"
                    type="number" step="1" style={fld}
                    value={orbitAlt} onChange={(e) => setOrbitAlt(Number(e.target.value))}
                  />
                </div>
                <div>
                  <label style={lbl} htmlFor="fld-space-7">Inclination (deg)</label>
                  <input
                    id="fld-space-7"
                    type="number" step="0.1" style={fld}
                    value={orbitInc} onChange={(e) => setOrbitInc(Number(e.target.value))}
                  />
                </div>
                <div>
                  <label style={lbl} htmlFor="fld-space-8">Frame</label>
                  <select id="fld-space-8" style={fld} value={orbitFrame} onChange={(e) => setOrbitFrame(e.target.value)}>
                    <option>SSO · dawn-dusk</option>
                    <option>SSO · noon-midnight</option>
                    <option>ISS · 51.6°</option>
                    <option>Equatorial · 0°</option>
                  </select>
                </div>
              </div>

              <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr 1fr", gap: 16 }}>
                <div>
                  <label style={lbl} htmlFor="fld-space-9">Downlink (Mbps)</label>
                  <input
                    id="fld-space-9"
                    type="number" step="1" style={fld}
                    value={downlinkBW} onChange={(e) => setDownlinkBW(Number(e.target.value))}
                  />
                </div>
                <div>
                  <label style={lbl} htmlFor="fld-space-10">Band</label>
                  <input id="fld-space-10" style={fld} value={downlinkBd} disabled />
                </div>
                <div>
                  <label style={lbl} htmlFor="fld-space-11">Imager GSD (m)</label>
                  <input
                    id="fld-space-11"
                    type="number" step="0.1" style={fld}
                    value={gsd} onChange={(e) => setGsd(Number(e.target.value))}
                  />
                </div>
              </div>
            </div>

            {/* contract block */}
            <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr 1fr", gap: 16, marginBottom: 16 }}>
              <div>
                <label style={lbl} htmlFor="fld-space-12">Contract value</label>
                <div style={{ display: "flex", gap: 6 }}>
                  <span style={{
                    height: 38, lineHeight: "38px", padding: "0 10px",
                    fontFamily: AE_FONT_MONO, fontSize: 14, color: AE_INK_3,
                    background: AE_BG_2, border: `1px solid ${AE_LINE}`,
                    borderRight: 0, borderRadius: "8px 0 0 8px",
                  }}>$</span>
                  <input
                    id="fld-space-12"
                    type="number" step="0.1"
                    style={Object.assign({}, fld, { borderRadius: "0 8px 8px 0" })}
                    value={contractVal}
                    onChange={(e) => setContractVal(Number(e.target.value))}
                  />
                  <span style={{
                    height: 38, lineHeight: "38px", padding: "0 10px",
                    fontFamily: AE_FONT_MONO, fontSize: 14, color: AE_INK_3,
                  }}>M</span>
                </div>
              </div>
              <div>
                <label style={lbl} htmlFor="fld-space-13">Contract kind</label>
                <select id="fld-space-13" style={fld} value={contractKind} onChange={(e) => setContractKind(e.target.value)}>
                  <option>FFP</option>
                  <option>FP-EPA</option>
                  <option>CPFF</option>
                  <option>CPIF</option>
                  <option>T&M</option>
                </select>
              </div>
              <div>
                <label style={lbl} htmlFor="fld-space-14">Launch target</label>
                <input
                  id="fld-space-14"
                  type="date" style={fld}
                  value={launchDue} onChange={(e) => setLaunchDue(e.target.value)}
                />
              </div>
            </div>

            {/* compliance toggles */}
            <div style={{
              display: "grid", gridTemplateColumns: "1fr 1fr", gap: 12,
              padding: 14, background: AE_BG_2,
              border: `1px solid ${AE_LINE_S}`, borderRadius: 8, marginBottom: 16,
            }}>
              <div style={{ display: "inline-flex", alignItems: "center", gap: 10 }}>
                <input id="fld-space-15" type="checkbox" checked={itar} onChange={(e) => setItar(e.target.checked)} />
                <label htmlFor="fld-space-15" style={{ cursor: "pointer" }}>
                  <span style={Object.assign({}, aeMono(), { color: itar ? AE_ACCENT_DEEP : AE_INK_4 })}>
                    ITAR-controlled
                  </span>
                  <div style={{ fontSize: 12, color: AE_INK_3, marginTop: 2 }}>
                    US-persons only on design reviews · drawing pulls signed
                  </div>
                </label>
              </div>
              <div style={{ display: "inline-flex", alignItems: "center", gap: 10 }}>
                <input id="fld-space-16" type="checkbox" checked={classified} onChange={(e) => setClassified(e.target.checked)} />
                <label htmlFor="fld-space-16" style={{ cursor: "pointer" }}>
                  <span style={Object.assign({}, aeMono(), { color: classified ? AE_ACCENT_DEEP : AE_INK_4 })}>
                    classified payload
                  </span>
                  <div style={{ fontSize: 12, color: AE_INK_3, marginTop: 2 }}>
                    SCI / SAP gating · facility clearance verification
                  </div>
                </label>
              </div>
            </div>

            <div style={{ marginBottom: 20 }}>
              <label style={lbl} htmlFor="fld-space-17">Notes · mission context</label>
              <textarea
                id="fld-space-17"
                style={Object.assign({}, fld, { height: 96, padding: "10px 12px", resize: "vertical", lineHeight: 1.55 })}
                value={notes}
                onChange={(e) => setNotes(e.target.value)}
              />
            </div>

            {flash && (
              <div style={{
                marginBottom: 12, padding: 10,
                background: "oklch(0.95 0.06 165)",
                border: `1px solid ${AE_GREEN}`,
                color: AE_GREEN, borderRadius: 8,
                fontFamily: AE_FONT_MONO, fontSize: 12,
              }}>{flash}</div>
            )}

            <div style={{ display: "flex", gap: 10, justifyContent: "flex-end" }}>
              <AEBtn variant="tertiary" onClick={() => {
                const _q = (err) => err && (err.status === 404 || err.status === 400);
                if (window.forgeApi && typeof window.forgeApi.mutate === "function") {
                  window.forgeApi.mutate("missions", { op: "add", path: "/-", value: { id: "MISSION-AET-001", status: "draft", ts: Date.now() } })
                    .then(() => setFlash("Draft saved · MISSION-AET-001 (draft)"))
                    .catch((err) => setFlash(_q(err) ? "Draft queued · MISSION-AET-001 (draft)" : `Save failed · ${(err && err.message) || "unknown"}`));
                } else {
                  setFlash("Draft queued · MISSION-AET-001 (draft)");
                }
              }}>Save draft</AEBtn>
              <AEBtn variant="danger" onClick={onDecline}>Decline LOI</AEBtn>
              <AEBtn variant="primary" onClick={onSubmit}>
                Submit · open propulsion trade →
              </AEBtn>
            </div>
          </AECard>

          {/* ───── Right rail ───── */}
          <div style={{ display: "flex", flexDirection: "column", gap: 16 }}>
            <AECard>
              <div style={Object.assign({}, aeMono(), { marginBottom: 14 })}>Mission summary</div>
              <div style={{ display: "grid", gridTemplateColumns: "auto 1fr", rowGap: 8, columnGap: 14, fontSize: 12 }}>
                <span style={{ color: AE_INK_3 }}>bus</span>
                <span style={{ fontFamily: AE_FONT_MONO, color: AE_INK }}>{busClass} · KESTREL-3</span>
                <span style={{ color: AE_INK_3 }}>orbit</span>
                <span style={{ fontFamily: AE_FONT_MONO, color: AE_INK }}>{orbitAlt} km · {orbitInc}° · {orbitFrame}</span>
                <span style={{ color: AE_INK_3 }}>downlink</span>
                <span style={{ fontFamily: AE_FONT_MONO, color: AE_INK }}>{downlinkBW} Mbps · {downlinkBd}</span>
                <span style={{ color: AE_INK_3 }}>imager</span>
                <span style={{ fontFamily: AE_FONT_MONO, color: AE_INK }}>{gsd.toFixed(1)} m GSD</span>
                <span style={{ color: AE_INK_3 }}>mass cap</span>
                <span style={{ fontFamily: AE_FONT_MONO, color: AE_INK }}>{massCap.toFixed(1)} kg</span>
                <span style={{ color: AE_INK_3 }}>payload power</span>
                <span style={{ fontFamily: AE_FONT_MONO, color: AE_INK }}>{powerAvg.toFixed(1)} W avg</span>
                <span style={{ color: AE_INK_3 }}>contract</span>
                <span style={{ fontFamily: AE_FONT_MONO, color: AE_INK }}>${contractVal.toFixed(1)}M · {contractKind}</span>
                <span style={{ color: AE_INK_3 }}>launch</span>
                <span style={{ fontFamily: AE_FONT_MONO, color: AE_INK }}>{launchDue}</span>
              </div>
            </AECard>

            <AECard>
              <div style={Object.assign({}, aeMono(), { marginBottom: 14 })}>Aperture Earth · prior engagement</div>
              <div style={{ display: "flex", flexDirection: "column", gap: 12 }}>
                {priorRFQs.map((r) => {
                  const tone = r.status === "won" ? "green" : r.status === "lost" ? "red" : "amber";
                  return (
                    <div key={r.id} style={{
                      borderTop: `1px solid ${AE_LINE_S}`,
                      paddingTop: 12,
                    }}>
                      <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 6 }}>
                        <span style={{ fontFamily: AE_FONT_MONO, fontSize: 12, color: AE_INK }}>{r.id}</span>
                        <AEPill tone={tone}>{r.status}</AEPill>
                      </div>
                      <div style={{ fontSize: 13, color: AE_INK_2, marginBottom: 4 }}>
                        {r.bus} · {r.val}
                      </div>
                      <div style={{ fontSize: 12, color: AE_INK_4 }}>
                        {_aeDate(r.date)} — {r.note}
                      </div>
                    </div>
                  );
                })}
              </div>
            </AECard>

            <AECard style={{ background: AE_BG_2 }}>
              <div style={Object.assign({}, aeMono(), { marginBottom: 10 })}>Heritage hint</div>
              <div style={{ fontFamily: AE_FONT_SERIF, fontSize: 16, color: AE_INK, marginBottom: 8 }}>
                4 of 11 subs flight-proven from KESTREL-2
              </div>
              <div style={{ fontSize: 12, color: AE_INK_3, lineHeight: 1.6, marginBottom: 12 }}>
                Avionics, Comms, Solar array, Battery — ISS / Mars 2020 heritage. Re-qual delta
                limited to TID + cell lot reverification. Likely TRL-9 carryover ~36% by mass.
              </div>
              <div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
                {heritage.map((h) => (
                  <div key={h.pn} style={{
                    fontSize: 12, color: AE_INK_2, padding: "6px 8px",
                    background: AE_BG, borderRadius: 6,
                    border: `1px solid ${AE_LINE_S}`,
                  }}>
                    <span style={{ fontFamily: AE_FONT_MONO, color: AE_INK }}>{h.pn}</span>
                    <span style={{ color: AE_INK_3 }}> · {h.sub} · </span>
                    <span style={{ fontFamily: AE_FONT_MONO, color: AE_GREEN }}>{h.trl}</span>
                  </div>
                ))}
              </div>
            </AECard>
          </div>
        </div>
      </div>
    </div>
  );
}

// ════════════════════════════════════════════════════════════════════
// 2 · ScreenAetherionTradeStudy — /forge/matcher
// Propulsion subsystem trade study (cold gas vs micro-resistojet vs none)
// Mass / power / cost / delta-v tradeoffs.
// Selectors mutate row visibility (band filter + spec filters).
// ════════════════════════════════════════════════════════════════════
function ScreenAetherionTradeStudy() {
  // Three propulsion candidates — synthetic but plausible per LEO 525km dV-30m/s
  const candidates = [
    {
      id: "P-CG-R236",
      name: "Cold-gas · R-236fa",
      vendor: "Aetherion in-house · KESTREL-2 heritage",
      mass: 1860, power: 2.0, cost: 142000,
      dv: 35, isp: 65, trl: "TRL-7",
      tankP: 22, propMass: 460, dryMass: 1400,
      pros: "Deep heritage. Self-pressurizing R-236fa. No moving parts in flight tank. Safe handling.",
      cons: "Lowest Isp. Heavy for delta-v > 50 m/s. Plume contamination risk for star tracker FOV.",
      winner: true,
    },
    {
      id: "P-MR-H2O",
      name: "Micro-resistojet · H₂O",
      vendor: "Bradford Engineering · COMET-1KW class",
      mass: 1240, power: 35.0, cost: 268000,
      dv: 48, isp: 180, trl: "TRL-6",
      tankP: 5, propMass: 320, dryMass: 920,
      pros: "Higher Isp. Water propellant — green / range-safe. Mass savings 620 g.",
      cons: "TRL-6, single flight history. 35 W draw exceeds 32 W payload budget — needs duty cycle. " +
            "Heater warm-up 18 min before each burn.",
      winner: false,
    },
    {
      id: "P-NONE",
      name: "No propulsion · drag-only deorbit",
      vendor: "n/a",
      mass: 0, power: 0, cost: 0,
      dv: 0, isp: null, trl: "n/a",
      tankP: null, propMass: 0, dryMass: 0,
      pros: "Zero mass, zero cost. Frees 1.86 kg for payload growth or extra solar.",
      cons: "Violates 25-yr deorbit guideline at 525 km BOL. ITU / FCC deorbit waiver required. " +
            "No collision-avoidance maneuver capability.",
      winner: false,
    },
  ];

  const [filterBand,    setFilterBand]    = uSAE12("all");        // all | low-power | high-isp | heritage
  const [showWaivers,   setShowWaivers]   = uSAE12(false);
  const [maxMass,       setMaxMass]       = uSAE12(2400);          // g
  const [minDV,         setMinDV]         = uSAE12(25);            // m/s
  const [activeId,      setActiveId]      = uSAE12("P-CG-R236");

  // visibility logic — selectors mutate row visibility
  function rowVisible(c) {
    if (filterBand === "low-power" && c.power > 5)  return false;
    if (filterBand === "high-isp"  && (c.isp == null || c.isp < 100)) return false;
    if (filterBand === "heritage"  && c.trl !== "TRL-7" && c.trl !== "TRL-9" && c.trl !== "TRL-8") return false;
    if (c.mass > maxMass) return false;
    if (c.dv  < minDV)    return false;
    if (!showWaivers && c.id === "P-NONE" && c.dv < minDV) return false;
    return true;
  }

  const visible = candidates.filter(rowVisible);

  // chart geometry — mass (X) vs delta-v (Y), bubble = cost
  const W = 720, H = 320, P = 52;
  const minM = 0,  maxM = 2200;
  const minV = -5, maxV = 60;
  function xS(m) { return P + ((m - minM) / (maxM - minM)) * (W - P * 2); }
  function yS(v) { return H - P - ((v - minV) / (maxV - minV)) * (H - P * 2); }

  function lock() {
    aeNav("/forge/carryover");
  }

  return (
    <div style={aeRoot()}>
      <div style={aeContainer()}>
        <AEHeader
          eyebrow="Forge · TRADE-STUDY"
          title="Propulsion trade study · KESTREL-3"
          subtitle={"Required Δv 30 m/s for end-of-life deorbit · 14 kg mass cap, 32 W payload power. " +
            "Three candidates ranked on mass / power / cost / TRL."}
        />

        {/* filter bar */}
        <AECard style={{ marginBottom: 24, padding: 16 }}>
          <div style={{ display: "grid", gridTemplateColumns: "1fr auto auto auto", gap: 16, alignItems: "center" }}>
            <div>
              <div style={Object.assign({}, aeMono(), { marginBottom: 6 })}>Band filter</div>
              <div style={{ display: "flex", gap: 6, flexWrap: "wrap" }}>
                {[
                  ["all",         "all"],
                  ["heritage",    "heritage"],
                  ["low-power",   "low-power"],
                  ["high-isp",    "high-isp"],
                ].map(([v, l]) => (
                  <button
                    key={v}
                    onClick={() => setFilterBand(v)}
                    style={Object.assign({}, aeRowBtn(), {
                      background: filterBand === v ? AE_ACCENT : AE_BG_3,
                      color:      filterBand === v ? AE_ACCENT_INK : AE_INK_2,
                      borderColor:filterBand === v ? AE_ACCENT : AE_LINE,
                    })}
                  >{l}</button>
                ))}
              </div>
            </div>
            <div>
              <div style={Object.assign({}, aeMono(), { marginBottom: 6 })}>Max mass</div>
              <input id="ae-act1-2-f1" name="ae-act1-2-f1"
                type="range" min="800" max="2400" step="100"
                value={maxMass}
                onChange={(e) => setMaxMass(Number(e.target.value))}
                style={{ width: 120 }}
              />
              <div style={{ fontFamily: AE_FONT_MONO, fontSize: 12, color: AE_INK, marginTop: 4 }}>
                {maxMass} g
              </div>
            </div>
            <div>
              <div style={Object.assign({}, aeMono(), { marginBottom: 6 })}>Min Δv</div>
              <input id="ae-act1-2-f2" name="ae-act1-2-f2"
                type="range" min="0" max="60" step="5"
                value={minDV}
                onChange={(e) => setMinDV(Number(e.target.value))}
                style={{ width: 120 }}
              />
              <div style={{ fontFamily: AE_FONT_MONO, fontSize: 12, color: AE_INK, marginTop: 4 }}>
                {minDV} m/s
              </div>
            </div>
            <label style={{ display: "inline-flex", alignItems: "center", gap: 8, cursor: "pointer" }}>
              <input id="ae-act1-2-f3" name="ae-act1-2-f3" type="checkbox" checked={showWaivers} onChange={(e) => setShowWaivers(e.target.checked)} />
              <span style={aeMono()}>show waiver paths</span>
            </label>
          </div>
        </AECard>

        {/* ───── Scatter chart — Δv (Y) vs mass (X) ───── */}
        <AECard style={{ marginBottom: 24, padding: 24 }}>
          <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 12 }}>
            <div style={aeMono()}>Δv (m/s) × MASS (g) · bubble = unit cost</div>
            <div style={{ display: "flex", gap: 10 }}>
              <AEPill tone="red">Δv floor 30 m/s</AEPill>
              <AEPill tone="accent">candidates</AEPill>
            </div>
          </div>

          <svg width={W} height={H} style={{ display: "block", margin: "0 auto" }}>
            {/* y grid */}
            {[0, 15, 30, 45, 60].map((v) => (
              <g key={"gv" + v}>
                <line x1={P} y1={yS(v)} x2={W - P} y2={yS(v)} stroke={AE_LINE_S} strokeDasharray="2 4" />
                <text x={P - 10} y={yS(v) + 4} textAnchor="end" fontFamily={AE_FONT_MONO} fontSize="10" fill={AE_INK_4}>{v}</text>
              </g>
            ))}
            {/* x grid */}
            {[0, 500, 1000, 1500, 2000].map((m) => (
              <g key={"gm" + m}>
                <line x1={xS(m)} y1={P} x2={xS(m)} y2={H - P} stroke={AE_LINE_S} strokeDasharray="2 4" />
                <text x={xS(m)} y={H - P + 16} textAnchor="middle" fontFamily={AE_FONT_MONO} fontSize="10" fill={AE_INK_4}>{m}</text>
              </g>
            ))}

            {/* axes */}
            <line x1={P} y1={H - P} x2={W - P} y2={H - P} stroke={AE_LINE} />
            <line x1={P} y1={P}     x2={P}     y2={H - P} stroke={AE_LINE} />
            <text x={W / 2} y={H - 12} textAnchor="middle" fontFamily={AE_FONT_MONO} fontSize="11" fill={AE_INK_3}>MASS · g</text>
            <text x={14} y={H / 2} transform={`rotate(-90 14 ${H / 2})`} textAnchor="middle" fontFamily={AE_FONT_MONO} fontSize="11" fill={AE_INK_3}>Δv · m/s</text>

            {/* Δv floor band — 30 m/s */}
            <line
              x1={P} y1={yS(30)} x2={W - P} y2={yS(30)}
              stroke={AE_RED} strokeWidth="1" strokeDasharray="4 3"
            />
            <text x={W - P + 4} y={yS(30) + 4} fontFamily={AE_FONT_MONO} fontSize="10" fill={AE_RED}>floor 30</text>

            {/* candidate bubbles */}
            {visible.map((c) => {
              const r = c.cost > 0 ? 8 + (c.cost / 30000) : 8;
              const isActive = c.id === activeId;
              return (
                <g key={c.id} style={{ cursor: "pointer" }} onClick={() => setActiveId(c.id)}>
                  <circle
                    cx={xS(c.mass)} cy={yS(c.dv)} r={Math.min(r, 28)}
                    fill={c.winner ? AE_ACCENT : AE_ACCENT_DEEP}
                    fillOpacity={isActive ? 0.65 : 0.3}
                    stroke={c.winner ? AE_ACCENT : AE_ACCENT_DEEP}
                    strokeWidth={isActive ? 2.5 : 1}
                  />
                  <text
                    x={xS(c.mass)} y={yS(c.dv) - Math.min(r, 28) - 6}
                    textAnchor="middle"
                    fontFamily={AE_FONT_MONO} fontSize="11"
                    fill={isActive ? AE_INK : AE_INK_2}
                    fontWeight={isActive ? 700 : 400}
                  >{c.id}</text>
                </g>
              );
            })}
          </svg>
        </AECard>

        {/* ───── Trade table ───── */}
        <AECard>
          <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 12 }}>
            <div style={aeMono()}>candidates · {visible.length} of {candidates.length} visible</div>
            <AEPill tone="green">selected: P-CG-R236 (cold-gas)</AEPill>
          </div>

          <div style={{ overflow: "auto" }}>
            <table style={{ width: "100%", borderCollapse: "collapse", fontSize: 13 }}>
              <thead>
                <tr style={{ background: AE_BG_2, borderBottom: `1px solid ${AE_LINE}` }}>
                  {["P/N", "name", "vendor", "mass", "power", "Δv", "Isp", "TRL", "$ NRE", "actions"].map((c) => (
                    <th key={c} style={{
                      textAlign: "left", padding: "10px 12px",
                      fontFamily: AE_FONT_MONO, fontSize: 12,
                      letterSpacing: "0.08em", textTransform: "uppercase",
                      color: AE_INK_3,
                    }}>{c}</th>
                  ))}
                </tr>
              </thead>
              <tbody>
                {visible.map((c) => {
                  const isActive = c.id === activeId;
                  return (
                    <tr key={c.id} style={{
                      borderBottom: `1px solid ${AE_LINE_S}`,
                      background: c.winner ? "oklch(0.96 0.04 250)" : isActive ? AE_BG_2 : "transparent",
                      cursor: "pointer",
                    }} onClick={() => setActiveId(c.id)}>
                      <td style={{ padding: "10px 12px", fontFamily: AE_FONT_MONO, color: AE_INK, fontWeight: c.winner ? 600 : 400 }}>{c.id}</td>
                      <td style={{ padding: "10px 12px", color: AE_INK }}>{c.name}</td>
                      <td style={{ padding: "10px 12px", color: AE_INK_3, fontSize: 12 }}>{c.vendor}</td>
                      <td style={{ padding: "10px 12px", fontFamily: AE_FONT_MONO, color: c.mass > 1500 ? AE_AMBER : AE_INK }}>{c.mass} g</td>
                      <td style={{ padding: "10px 12px", fontFamily: AE_FONT_MONO, color: c.power > 32 ? AE_RED : AE_INK }}>{c.power.toFixed(1)} W</td>
                      <td style={{ padding: "10px 12px", fontFamily: AE_FONT_MONO, color: c.dv >= 30 ? AE_GREEN : AE_RED, fontWeight: 600 }}>{c.dv} m/s</td>
                      <td style={{ padding: "10px 12px", fontFamily: AE_FONT_MONO, color: AE_INK_2 }}>{c.isp != null ? c.isp + " s" : "—"}</td>
                      <td style={{ padding: "10px 12px", fontFamily: AE_FONT_MONO, color: c.trl === "TRL-9" ? AE_GREEN : c.trl === "TRL-7" ? AE_AMBER : c.trl === "TRL-6" ? AE_VIOLET : AE_INK_4 }}>{c.trl}</td>
                      <td style={{ padding: "10px 12px", fontFamily: AE_FONT_MONO, color: AE_INK }}>{c.cost > 0 ? aeUsd(c.cost) : "—"}</td>
                      <td style={{ padding: "10px 12px" }}>
                        <div style={{ display: "flex", gap: 6, flexWrap: "wrap" }}>
                          <button onClick={(e) => { e.stopPropagation(); aeNav("/forge/carryover"); }} style={aeRowBtn()}>heritage</button>
                          <button onClick={(e) => { e.stopPropagation(); aeNav("/forge/quote"); }} style={aeRowBtn()}>quote</button>
                        </div>
                      </td>
                    </tr>
                  );
                })}
              </tbody>
            </table>
          </div>

          {/* selected candidate detail */}
          {(() => {
            const sel = candidates.find((c) => c.id === activeId);
            if (!sel) return null;
            return (
              <div style={{
                marginTop: 22, padding: 18,
                background: "oklch(0.96 0.03 250)",
                border: `1px solid ${AE_ACCENT}`,
                borderRadius: 10,
              }}>
                <div style={Object.assign({}, aeMono(), { color: AE_ACCENT, marginBottom: 8 })}>
                  Detail · {sel.id}
                </div>
                <div style={{ fontFamily: AE_FONT_SERIF, fontSize: 18, color: AE_INK, marginBottom: 12 }}>
                  {sel.name} · {sel.vendor}
                </div>
                <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 18 }}>
                  <div>
                    <div style={Object.assign({}, aeMono(), { marginBottom: 6, color: AE_GREEN })}>pros</div>
                    <div style={{ fontSize: 13, color: AE_INK_2, lineHeight: 1.6 }}>{sel.pros}</div>
                  </div>
                  <div>
                    <div style={Object.assign({}, aeMono(), { marginBottom: 6, color: AE_RED })}>cons</div>
                    <div style={{ fontSize: 13, color: AE_INK_2, lineHeight: 1.6 }}>{sel.cons}</div>
                  </div>
                </div>
                {sel.tankP != null && (
                  <div style={{
                    marginTop: 14, padding: 12,
                    background: AE_BG_3,
                    border: `1px solid ${AE_LINE_S}`,
                    borderRadius: 8,
                    display: "grid", gridTemplateColumns: "repeat(4, 1fr)", gap: 12, fontSize: 12,
                  }}>
                    <div>
                      <div style={aeMono()}>dry mass</div>
                      <div style={{ fontFamily: AE_FONT_MONO, fontSize: 13, color: AE_INK }}>{sel.dryMass} g</div>
                    </div>
                    <div>
                      <div style={aeMono()}>propellant</div>
                      <div style={{ fontFamily: AE_FONT_MONO, fontSize: 13, color: AE_INK }}>{sel.propMass} g</div>
                    </div>
                    <div>
                      <div style={aeMono()}>tank P</div>
                      <div style={{ fontFamily: AE_FONT_MONO, fontSize: 13, color: AE_INK }}>{sel.tankP} bar</div>
                    </div>
                    <div>
                      <div style={aeMono()}>NRE</div>
                      <div style={{ fontFamily: AE_FONT_MONO, fontSize: 13, color: AE_INK }}>{aeUsd(sel.cost)}</div>
                    </div>
                  </div>
                )}
              </div>
            );
          })()}

          <div style={{ marginTop: 18, display: "flex", justifyContent: "flex-end", gap: 10 }}>
            <AEBtn variant="tertiary" onClick={() => aeNav("/forge/rfq")}>← back to mission intake</AEBtn>
            <AEBtn variant="primary" onClick={lock}>
              Lock cold-gas R-236fa → heritage audit
            </AEBtn>
          </div>
        </AECard>
      </div>
    </div>
  );
}

// ════════════════════════════════════════════════════════════════════
// 3 · ScreenAetherionConfigAudit — /forge/carryover
// Heritage configuration audit: which subs carry from KESTREL-2 (TRL-9),
// which are new dev (TRL 6+). Diff view.
// ════════════════════════════════════════════════════════════════════
function ScreenAetherionConfigAudit() {
  const [flash, setFlash] = uSAE12("");
  uEAE12(() => {
    if (!flash) return;
    const t = setTimeout(() => setFlash(""), 2400);
    return () => clearTimeout(t);
  }, [flash]);

  // KESTREL-2 → KESTREL-3 audit per space.md §3 (eleven L1 subassemblies).
  // status: "carry" (TRL-9 direct port) | "requal" (TRL-8/9 with delta) |
  //         "swap" (component change within sub) | "new" (TRL-6 new dev)
  const rows = [
    {
      pn: "KESTREL-3.10.00", sub: "Primary structure (skeletonized)",
      lhs: "K2.10 · 6U Al-7075 frame",
      rhs: "K3.10 · 12U Al-7075 + Ti-6Al-4V brackets",
      mass: 2640, power: 0,
      lhsTrl: "TRL-9", rhsTrl: "TRL-9",
      status: "swap",
      note: "12U bus geometry · re-FEM, vibe re-qual GEVS+3 dB", supplier: "ISIS",
    },
    {
      pn: "KESTREL-3.20.00", sub: "Avionics · OBC + EPS stack",
      lhs: "K2.20 · Sirius OBC + Starbuck EPS",
      rhs: "K3.20 · Sirius OBC + Starbuck EPS (same)",
      mass: 1180, power: 8.4,
      lhsTrl: "TRL-9 · ISS-6Y", rhsTrl: "TRL-9 · ISS-6Y",
      status: "carry",
      note: "Direct port. 6 yr ISS heritage. No firmware delta.", supplier: "AAC Clyde Space",
    },
    {
      pn: "KESTREL-3.30.00", sub: "ADCS · star tracker + 3 RWs",
      lhs: "K2.30 · single Auriga + 2 RWs",
      rhs: "K3.30 · single Auriga + 3 RWp050",
      mass: 920, power: 11.2,
      lhsTrl: "TRL-8", rhsTrl: "TRL-8",
      status: "swap",
      note: "+1 reaction wheel for 3-axis margin. Sodern + Blue Canyon.", supplier: "Sodern · Blue Canyon",
    },
    {
      pn: "KESTREL-3.40.00", sub: "Propulsion · cold gas R-236fa",
      lhs: "K2.40 · drag-only deorbit (none)",
      rhs: "K3.40 · cold-gas R-236fa · 30 m/s Δv",
      mass: 1860, power: 2.0,
      lhsTrl: "n/a", rhsTrl: "TRL-7",
      status: "new",
      note: "New dev · trade study locked P-CG-R236. Re-qual full envelope.", supplier: "Aetherion in-house",
    },
    {
      pn: "KESTREL-3.50.00", sub: "Comms · X-band 50 Mbps + UHF TT&C",
      lhs: "K2.50 · X-band 50 Mbps + UHF",
      rhs: "K3.50 · X-band 50 Mbps + UHF (same)",
      mass: 860, power: 18.0,
      lhsTrl: "TRL-9", rhsTrl: "TRL-9",
      status: "carry",
      note: "Direct port. Same waveform, antenna gain pattern.", supplier: "Aetherion in-house",
    },
    {
      pn: "KESTREL-3.60.00", sub: "Solar array · 4× deployable wing",
      lhs: "K2.60 · 2-wing deployable",
      rhs: "K3.60 · 4-wing deployable, Honeybee hinge sub",
      mass: 1320, power: 0,
      lhsTrl: "TRL-9 · ISS-6Y", rhsTrl: "TRL-9 · ISS-6Y",
      status: "swap",
      note: "+2 wings for power margin. ECO-AET-0042 hinge fastener change.", supplier: "Honeybee Robotics",
    },
    {
      pn: "KESTREL-3.70.00", sub: "Battery pack · 80 Wh Li-ion (8s2p)",
      lhs: "K2.70 · 80 Wh 8s2p (cell lot 22Q3)",
      rhs: "K3.70 · 80 Wh 8s2p (cell lot 25Q4)",
      mass: 720, power: 0.6,
      lhsTrl: "TRL-9", rhsTrl: "TRL-9",
      status: "requal",
      note: "Cell lot delta · TID re-test required, 30 krad LEO profile.", supplier: "EaglePicher",
    },
    {
      pn: "KESTREL-3.80.00", sub: "Harness · MIL-DTL-38999 + Glenair",
      lhs: "K2.80 · MIL-DTL-38999 series III",
      rhs: "K3.80 · MIL-DTL-38999 series III + overbraid",
      mass: 580, power: 0,
      lhsTrl: "TRL-9", rhsTrl: "TRL-9",
      status: "swap",
      note: "Overbraid added for harness cleanliness. HRD-AET-001 routing.", supplier: "Glenair · Amphenol",
    },
    {
      pn: "KESTREL-3.90.00", sub: "Thermal · MLI + heaters + Aerogel",
      lhs: "K2.90 · MLI + heaters",
      rhs: "K3.90 · MLI + heaters + Aerogel pads (payload)",
      mass: 410, power: 3.4,
      lhsTrl: "TRL-9", rhsTrl: "TRL-9",
      status: "swap",
      note: "Aerogel pads added for imager focal-plane stability.", supplier: "Aetherion in-house",
    },
    {
      pn: "KESTREL-3.A0.00", sub: "RF deck · LNA + diplexer",
      lhs: "K2.A0 · LNA + diplexer",
      rhs: "K3.A0 · LNA + diplexer (same)",
      mass: 240, power: 1.4,
      lhsTrl: "TRL-9", rhsTrl: "TRL-9",
      status: "carry",
      note: "Direct port. Same RF chain.", supplier: "Aetherion in-house",
    },
    {
      pn: "KESTREL-3.B0.00", sub: "Payload · 1m-GSD imager + X-band",
      lhs: "K2.B0 · 3m-GSD imager",
      rhs: "K3.B0 · 1m-GSD imager · custom",
      mass: 3270, power: 25.0,
      lhsTrl: "TRL-7", rhsTrl: "TRL-6",
      status: "new",
      note: "New optical bench. f/4.5, 220 mm aperture. Full qual campaign.", supplier: "Aperture Earth supplied",
    },
  ];

  const carryCount  = rows.filter((r) => r.status === "carry").length;
  const requalCount = rows.filter((r) => r.status === "requal").length;
  const swapCount   = rows.filter((r) => r.status === "swap").length;
  const newCount    = rows.filter((r) => r.status === "new").length;

  // mass + power totals split by carry / new
  const totalMass    = rows.reduce((a, r) => a + r.mass, 0);
  const carryMass    = rows.filter((r) => r.status === "carry" || r.status === "requal").reduce((a, r) => a + r.mass, 0);
  const newMass      = rows.filter((r) => r.status === "new" || r.status === "swap").reduce((a, r) => a + r.mass, 0);
  const carryPctMass = ((carryMass / totalMass) * 100).toFixed(1);

  function statusStyle(s) {
    if (s === "carry")  return { bg: "oklch(0.96 0.04 165)", fg: AE_GREEN,        label: "carry"  };
    if (s === "requal") return { bg: "oklch(0.97 0.03 245)", fg: AE_ACCENT_DEEP,  label: "re-qual" };
    if (s === "swap")   return { bg: "oklch(0.97 0.04 85)",  fg: AE_AMBER,        label: "swap"   };
    if (s === "new")    return { bg: "oklch(0.96 0.05 295)", fg: AE_VIOLET,       label: "new dev"};
    return { bg: AE_BG_3, fg: AE_INK_4, label: s };
  }

  return (
    <div style={aeRoot()}>
      <div style={aeContainer()}>
        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "flex-end", marginBottom: 24 }}>
          <AEHeader
            eyebrow="Forge · CONFIG-AUDIT"
            title="Heritage configuration audit · KESTREL-2 → KESTREL-3"
            subtitle={
              "Subsystem-level diff. Carry rows are TRL-9 direct ports. Re-qual is " +
              "delta requalification. Swap is component change within a sub. New dev " +
              "is TRL ≤ 7 first-flight hardware."
            }
          />
          <div style={{ display: "flex", gap: 10 }}>
            <AEBtn variant="tertiary" onClick={() => { setFlash("Re-derive vs KESTREL-1 queued — v2"); if (window.forgeToast) window.forgeToast({ msg: "Re-derive vs KESTREL-1 queued — v2", kind: "info" }); }}>Re-derive vs KESTREL-1</AEBtn>
          </div>
        </div>

        {flash && (
          <div style={{
            marginBottom: 16, padding: 12,
            background: "oklch(0.95 0.06 165)",
            border: `1px solid ${AE_GREEN}`,
            color: AE_GREEN, borderRadius: 8,
            fontFamily: AE_FONT_MONO, fontSize: 12,
          }}>{flash}</div>
        )}

        {/* summary tiles */}
        <div style={{ display: "grid", gridTemplateColumns: "repeat(5, 1fr)", gap: 12, marginBottom: 24 }}>
          {[
            { l: "carry",     v: carryCount,  tone: "green",  d: "TRL-9 direct port" },
            { l: "re-qual",   v: requalCount, tone: "accent", d: "delta requalification" },
            { l: "swap",      v: swapCount,   tone: "amber",  d: "component change" },
            { l: "new dev",   v: newCount,    tone: "violet", d: "TRL ≤ 7 first flight" },
            { l: "carry by mass", v: carryPctMass + "%", tone: "deep", d: `${(carryMass / 1000).toFixed(2)} kg of ${(totalMass / 1000).toFixed(2)} kg` },
          ].map((t) => (
            <AECard key={t.l} style={{ padding: 16 }}>
              <div style={Object.assign({}, aeMono(), { marginBottom: 6 })}>{t.l}</div>
              <div style={{ fontFamily: AE_FONT_SERIF, fontSize: 28, color: AE_INK, marginBottom: 4 }}>{t.v}</div>
              <div style={{ fontSize: 12, color: AE_INK_3 }}>{t.d}</div>
            </AECard>
          ))}
        </div>

        {/* mass/power band */}
        <AECard style={{ marginBottom: 24, padding: 18 }}>
          <div style={Object.assign({}, aeMono(), { marginBottom: 12 })}>Mass &amp; power split · carry vs new</div>
          <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 24 }}>
            <div>
              <div style={{ fontSize: 12, color: AE_INK_3, marginBottom: 6 }}>
                Mass · {(totalMass / 1000).toFixed(2)} kg total
              </div>
              <div style={{
                display: "flex", height: 20, background: AE_BG_2,
                border: `1px solid ${AE_LINE}`, borderRadius: 4, overflow: "hidden",
              }}>
                <div style={{
                  width: `${(carryMass / totalMass) * 100}%`,
                  background: AE_GREEN,
                  display: "flex", alignItems: "center", justifyContent: "flex-end",
                  paddingRight: 8, color: AE_BG, fontFamily: AE_FONT_MONO, fontSize: 12,
                }}>{(carryMass / 1000).toFixed(2)} kg</div>
                <div style={{
                  width: `${(newMass / totalMass) * 100}%`,
                  background: AE_VIOLET,
                  display: "flex", alignItems: "center", justifyContent: "flex-start",
                  paddingLeft: 8, color: AE_BG, fontFamily: AE_FONT_MONO, fontSize: 12,
                }}>{(newMass / 1000).toFixed(2)} kg</div>
              </div>
              <div style={{ display: "flex", justifyContent: "space-between", fontSize: 12, color: AE_INK_3, marginTop: 4 }}>
                <span>carry / re-qual</span>
                <span>swap / new dev</span>
              </div>
            </div>
            <div>
              <div style={{ fontSize: 12, color: AE_INK_3, marginBottom: 6 }}>
                Power · {rows.reduce((a, r) => a + r.power, 0).toFixed(1)} W total
              </div>
              <div style={{
                display: "flex", height: 20, background: AE_BG_2,
                border: `1px solid ${AE_LINE}`, borderRadius: 4, overflow: "hidden",
              }}>
                {(() => {
                  const totalP   = rows.reduce((a, r) => a + r.power, 0);
                  const carryP   = rows.filter((r) => r.status === "carry" || r.status === "requal").reduce((a, r) => a + r.power, 0);
                  const newP     = totalP - carryP;
                  return (
                    <>
                      <div style={{
                        width: `${(carryP / totalP) * 100}%`,
                        background: AE_GREEN,
                        display: "flex", alignItems: "center", justifyContent: "flex-end",
                        paddingRight: 8, color: AE_BG, fontFamily: AE_FONT_MONO, fontSize: 12,
                      }}>{carryP.toFixed(1)} W</div>
                      <div style={{
                        width: `${(newP / totalP) * 100}%`,
                        background: AE_VIOLET,
                        display: "flex", alignItems: "center", justifyContent: "flex-start",
                        paddingLeft: 8, color: AE_BG, fontFamily: AE_FONT_MONO, fontSize: 12,
                      }}>{newP.toFixed(1)} W</div>
                    </>
                  );
                })()}
              </div>
              <div style={{ display: "flex", justifyContent: "space-between", fontSize: 12, color: AE_INK_3, marginTop: 4 }}>
                <span>carry / re-qual</span>
                <span>swap / new dev</span>
              </div>
            </div>
          </div>
        </AECard>

        {/* diff table */}
        <AECard style={{ overflow: "auto", padding: 0 }}>
          <table style={{ width: "100%", borderCollapse: "collapse", fontSize: 12 }}>
            <thead>
              <tr style={{ background: AE_BG_2 }}>
                <th style={aeDiffH()}>P/N</th>
                <th style={aeDiffH()}>Subsystem</th>
                <th style={Object.assign({}, aeDiffH(), { background: "oklch(0.94 0.012 30)" })}>KESTREL-2 (predecessor)</th>
                <th style={Object.assign({}, aeDiffH(), { background: "oklch(0.94 0.018 250)" })}>KESTREL-3 (current)</th>
                <th style={aeDiffH()}>mass</th>
                <th style={aeDiffH()}>power</th>
                <th style={aeDiffH()}>TRL</th>
                <th style={aeDiffH()}>status</th>
                <th style={aeDiffH()}>note</th>
              </tr>
            </thead>
            <tbody>
              {rows.map((r) => {
                const s = statusStyle(r.status);
                return (
                  <tr key={r.pn} style={{
                    background: s.bg,
                    borderTop: `1px solid ${AE_LINE_S}`,
                    color: AE_INK,
                  }}>
                    <td style={Object.assign({}, aeDiffC(), { fontFamily: AE_FONT_MONO, fontWeight: 500 })}>{r.pn}</td>
                    <td style={aeDiffC()}>
                      <div style={{ fontWeight: 500 }}>{r.sub}</div>
                      <div style={{ fontSize: 12, color: AE_INK_3, marginTop: 2 }}>{r.supplier}</div>
                    </td>
                    <td style={Object.assign({}, aeDiffC(), { fontFamily: AE_FONT_MONO, color: AE_INK_2 })}>
                      {r.lhs}
                      <div style={{ fontSize: 12, color: r.lhsTrl === "n/a" ? AE_INK_4 : AE_INK_3, marginTop: 4 }}>{r.lhsTrl}</div>
                    </td>
                    <td style={Object.assign({}, aeDiffC(), { fontFamily: AE_FONT_MONO, color: AE_INK })}>
                      {r.rhs}
                      <div style={{ fontSize: 12, color: r.rhsTrl.indexOf("TRL-9") === 0 ? AE_GREEN : r.rhsTrl.indexOf("TRL-7") === 0 ? AE_AMBER : r.rhsTrl.indexOf("TRL-6") === 0 ? AE_VIOLET : AE_INK_3, marginTop: 4 }}>{r.rhsTrl}</div>
                    </td>
                    <td style={Object.assign({}, aeDiffC(), { fontFamily: AE_FONT_MONO, color: AE_INK })}>{r.mass} g</td>
                    <td style={Object.assign({}, aeDiffC(), { fontFamily: AE_FONT_MONO, color: AE_INK })}>{r.power.toFixed(1)} W</td>
                    <td style={Object.assign({}, aeDiffC(), { fontFamily: AE_FONT_MONO, fontSize: 12, color: AE_INK_3 })}>—</td>
                    <td style={aeDiffC()}>
                      <span style={{
                        fontFamily: AE_FONT_MONO, fontSize: 12,
                        letterSpacing: "0.06em", textTransform: "uppercase",
                        color: s.fg, fontWeight: 600,
                      }}>{s.label}</span>
                    </td>
                    <td style={Object.assign({}, aeDiffC(), { color: AE_INK_3, fontSize: 12 })}>{r.note}</td>
                  </tr>
                );
              })}
            </tbody>
          </table>
        </AECard>

        {/* footer summary */}
        <div style={{
          marginTop: 24, padding: 20,
          background: "oklch(0.96 0.03 250)",
          border: `1px solid ${AE_ACCENT}`,
          borderRadius: 10,
          display: "grid", gridTemplateColumns: "1fr auto", gap: 18, alignItems: "center",
        }}>
          <div>
            <div style={Object.assign({}, aeMono(), { color: AE_ACCENT, marginBottom: 6 })}>Net config posture</div>
            <div style={{ fontFamily: AE_FONT_SERIF, fontSize: 22, color: AE_INK, marginBottom: 4 }}>
              {carryPctMass}% by mass carries from KESTREL-2 · 2 new-dev subs
            </div>
            <div style={{ fontSize: 13, color: AE_INK_2 }}>
              Propulsion (P-CG-R236) and Payload (1m-GSD imager) drive the qualification campaign.
              Avionics, Comms, Solar wing, RF deck, Battery — direct ports; re-qual delta limited
              to cell lot TID re-test on the battery pack.
            </div>
          </div>
          <AEBtn variant="primary" onClick={() => aeNav("/forge/quote")}>Open FFP quote →</AEBtn>
        </div>
      </div>
    </div>
  );
}

// ════════════════════════════════════════════════════════════════════
// 4 · ScreenAetherionQuote — /forge/quote
// $4.2M FFP build with launch service slot ($380k Falcon 9 Transporter-15),
// insurance, qualification campaign costs.
// ════════════════════════════════════════════════════════════════════
function ScreenAetherionQuote() {
  const [marginPct,    setMarginPct]    = uSAE12(14);     // FFP margin
  const [contingPct,   setContingPct]   = uSAE12(8);      // contingency
  const [insIncluded,  setInsIncluded]  = uSAE12(true);
  const [launchVendor, setLaunchVendor] = uSAE12("falcon9-t15");
  const [flash, setFlash] = uSAE12("");
  const mountedRef = React.useRef(true);
  uEAE12(() => {
    mountedRef.current = true;
    return () => { mountedRef.current = false; };
  }, []);
  uEAE12(() => {
    if (!flash) return;
    const t = setTimeout(() => { if (mountedRef.current) setFlash(""); }, 2400);
    return () => clearTimeout(t);
  }, [flash]);

  // Cost stack (USD) — synthetic but plausible against $4.2M FFP cap
  // Hardware NRE + recurring + qual campaign + launch + insurance + margin.
  const STRUCTURE     = 142000;
  const AVIONICS      = 318000;
  const ADCS          = 412000;
  const PROPULSION    = 142000;   // cold-gas R-236fa per trade study
  const COMMS         = 215000;
  const SOLAR_ARRAY   = 184000;
  const BATTERY       = 64000;
  const HARNESS       = 38000;
  const THERMAL       = 47000;
  const RF_DECK       = 51000;
  const PAYLOAD       = 1480000;  // 1m-GSD custom imager + X-band downlink
  const HARDWARE      = STRUCTURE + AVIONICS + ADCS + PROPULSION + COMMS +
                        SOLAR_ARRAY + BATTERY + HARNESS + THERMAL + RF_DECK + PAYLOAD;

  const QUAL_VIB      = 78000;
  const QUAL_TVAC     = 92000;
  const QUAL_EMC      = 64000;
  const QUAL_RAD      = 56000;
  const QUAL_SHOCK    = 28000;
  const QUAL_CLEAN    = 18000;
  const QUAL          = QUAL_VIB + QUAL_TVAC + QUAL_EMC + QUAL_RAD + QUAL_SHOCK + QUAL_CLEAN;

  const LAUNCH_VENDORS = {
    "falcon9-t15": { name: "Falcon 9 Transporter-15 · rideshare slot",
                      cost: 380000, broker: "Exolaunch", date: "2026-09-10",
                      orbit: "SSO 525 km dawn-dusk · 14 kg slot" },
    "electron":   { name: "Rocket Lab Electron · dedicated",
                      cost: 1100000, broker: "Rocket Lab",  date: "2026-10-22",
                      orbit: "SSO 525 km · dedicated trajectory" },
    "vega-c":     { name: "Arianespace Vega-C · rideshare",
                      cost: 540000, broker: "Arianespace", date: "2026-11-04",
                      orbit: "SSO 530 km · partial inclination delta" },
  };
  const launch = LAUNCH_VENDORS[launchVendor];

  const INSURANCE     = insIncluded ? 168000 : 0;     // 4% of HW + launch
  const PM_FEE        = 156000;
  const ITAR_COMPLIANCE = 38000;
  const SUBTOTAL      = HARDWARE + QUAL + launch.cost + INSURANCE + PM_FEE + ITAR_COMPLIANCE;
  const CONTINGENCY   = Math.round(SUBTOTAL * (contingPct / 100));
  const PRE_MARGIN    = SUBTOTAL + CONTINGENCY;
  const MARGIN        = Math.round(PRE_MARGIN * (marginPct / 100));
  const FFP_PRICE     = PRE_MARGIN + MARGIN;
  const FFP_CAP       = 4200000;
  const HEADROOM      = FFP_CAP - FFP_PRICE;

  function fmt(n) {
    if (n >= 1e6) return "$" + (n / 1e6).toFixed(2) + "M";
    if (n >= 1e3) return "$" + Math.round(n / 1e3).toLocaleString("en-US") + "k";
    return "$" + n.toLocaleString("en-US");
  }

  function send() {
    setFlash("Quote QT-AET-2026-001 sent to Aperture Earth · ledger entry queued.");
    setTimeout(() => { if (mountedRef.current) aeNav("/auditor/ledger"); }, 700);
  }

  return (
    <div style={aeRoot()}>
      <div style={aeContainer()}>
        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "flex-end", marginBottom: 24 }}>
          <AEHeader
            eyebrow="Forge · FFP-QUOTE"
            title="FFP quote — Aperture Earth · KESTREL-3 (12U)"
            subtitle="Single-flight FFP. Hardware + qualification + launch + insurance. Adjust margin and contingency live."
          />
          <div style={{ display: "flex", gap: 8 }}>
            <AEBtn variant="tertiary" onClick={() => {
              const _q = (err) => err && (err.status === 404 || err.status === 400);
              if (window.forgeApi && typeof window.forgeApi.mutate === "function") {
                window.forgeApi.mutate("quotes", { op: "add", path: "/-", value: { id: "QT-AET-2026-001", status: "draft", ts: Date.now() } })
                  .then(() => setFlash("Draft saved · QT-AET-2026-001 (draft)"))
                  .catch((err) => setFlash(_q(err) ? "Draft queued · QT-AET-2026-001 (draft)" : `Save failed · ${(err && err.message) || "unknown"}`));
              } else {
                setFlash("Draft queued · QT-AET-2026-001 (draft)");
              }
            }}>Save draft</AEBtn>
            <AEBtn variant="tertiary" onClick={() => {
              if (window.forgeApi && typeof window.forgeApi.exportAuditUrl === "function") {
                window.location.href = window.forgeApi.exportAuditUrl("pdf");
                setFlash("Quote PDF download started · audit PDF");
              } else {
                setFlash("PDF download queued — v2");
              }
            }}>Download PDF</AEBtn>
            <AEBtn variant="tertiary" onClick={() => { setFlash("Email send queued — v2"); if (window.forgeToast) window.forgeToast({ msg: "Email send queued — v2", kind: "info" }); }}>Send via email</AEBtn>
          </div>
        </div>

        {flash && (
          <div style={{
            marginBottom: 16, padding: 12,
            background: "oklch(0.95 0.06 165)",
            border: `1px solid ${AE_GREEN}`,
            color: AE_GREEN, borderRadius: 8,
            fontFamily: AE_FONT_MONO, fontSize: 12,
          }}>{flash}</div>
        )}

        <div style={{ display: "grid", gridTemplateColumns: "1fr 340px", gap: 24 }}>
          {/* ───── Quote sheet ───── */}
          <AECard style={{ padding: 36, background: "white" }}>
            {/* letterhead */}
            <div style={{
              display: "flex", justifyContent: "space-between", alignItems: "flex-start",
              paddingBottom: 18, borderBottom: `2px solid ${AE_INK}`,
            }}>
              <div>
                <div style={{
                  fontFamily: AE_FONT_SERIF, fontSize: 28, fontWeight: 700,
                  letterSpacing: "-0.02em", color: AE_INK,
                }}>
                  Aetherion Microsat, Inc.
                </div>
                <div style={{ fontSize: 12, color: AE_INK_3, marginTop: 4 }}>
                  Sunnyvale, CA · ISO 14644-1 Class 7 cleanroom · CAGE 7AB23 · DUNS 080213118
                </div>
                <div style={{ fontSize: 12, color: AE_INK_3, marginTop: 2 }}>
                  ITAR registered · M-12345 · AS9100D certified · NASA-STD-8739 compliant
                </div>
              </div>
              <div style={{ textAlign: "right" }}>
                <div style={Object.assign({}, aeMono(), { fontSize: 12, marginBottom: 6 })}>Quote</div>
                <div style={{ fontFamily: AE_FONT_MONO, fontSize: 14, color: AE_INK }}>QT-AET-2026-001</div>
                <div style={{ fontSize: 12, color: AE_INK_3, marginTop: 4 }}>Issued: 2026-05-09</div>
                <div style={{ fontSize: 12, color: AE_INK_3 }}>Valid: 30 days · LOI signed 2025-01-12</div>
              </div>
            </div>

            {/* customer block */}
            <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 24, marginTop: 22, marginBottom: 22 }}>
              <div>
                <div style={Object.assign({}, aeMono(), { marginBottom: 6 })}>BILL TO</div>
                <div style={{ fontFamily: AE_FONT_SERIF, fontSize: 16, color: AE_INK }}>Aperture Earth Analytics, Inc.</div>
                <div style={{ fontSize: 12, color: AE_INK_3, lineHeight: 1.6, marginTop: 4 }}>
                  1850 Saratoga Ave, Suite 220<br />
                  San Jose, CA 95129<br />
                  Attn: Procurement — Dr. Lena Park
                </div>
              </div>
              <div>
                <div style={Object.assign({}, aeMono(), { marginBottom: 6 })}>DELIVERY</div>
                <div style={{ fontFamily: AE_FONT_SERIF, fontSize: 16, color: AE_INK }}>{launch.name}</div>
                <div style={{ fontSize: 12, color: AE_INK_3, lineHeight: 1.6, marginTop: 4 }}>
                  Broker: {launch.broker}<br />
                  Window: {launch.date}<br />
                  Orbit: {launch.orbit}
                </div>
              </div>
            </div>

            {/* line item table */}
            <table style={{ width: "100%", borderCollapse: "collapse", fontSize: 13, marginBottom: 18 }}>
              <thead>
                <tr style={{ borderBottom: `1px solid ${AE_INK}` }}>
                  {["Line", "Description", "Qty", "USD"].map((c) => (
                    <th key={c} style={Object.assign({}, aeDiffH(), { borderBottom: "none" })}>{c}</th>
                  ))}
                </tr>
              </thead>
              <tbody>
                {[
                  { line: "1.0",  desc: "Bus hardware · 11 subassemblies · KESTREL-3.00.00",      qty: 1, val: HARDWARE },
                  { line: "1.1",  desc: "  Primary structure (skeletonized)",                      qty: 1, val: STRUCTURE,   indent: true },
                  { line: "1.2",  desc: "  Avionics · OBC + EPS stack (AAC Clyde Sirius/Starbuck)", qty: 1, val: AVIONICS,    indent: true },
                  { line: "1.3",  desc: "  ADCS · Auriga + 3× RWp050",                              qty: 1, val: ADCS,        indent: true },
                  { line: "1.4",  desc: "  Propulsion · cold-gas R-236fa (P-CG-R236)",              qty: 1, val: PROPULSION,  indent: true },
                  { line: "1.5",  desc: "  Comms · X-band 50 Mbps + UHF TT&C",                       qty: 1, val: COMMS,       indent: true },
                  { line: "1.6",  desc: "  Solar array · 4× deployable wing (Honeybee)",            qty: 1, val: SOLAR_ARRAY, indent: true },
                  { line: "1.7",  desc: "  Battery pack · 80 Wh Li-ion 8s2p",                        qty: 1, val: BATTERY,     indent: true },
                  { line: "1.8",  desc: "  Harness · MIL-DTL-38999 + Glenair overbraid",              qty: 1, val: HARNESS,     indent: true },
                  { line: "1.9",  desc: "  Thermal · MLI + heaters + Aerogel pads",                   qty: 1, val: THERMAL,     indent: true },
                  { line: "1.10", desc: "  RF deck · LNA + diplexer",                                  qty: 1, val: RF_DECK,     indent: true },
                  { line: "1.11", desc: "  Payload · 1m-GSD imager + X-band downlink",                qty: 1, val: PAYLOAD,     indent: true },
                  { line: "2.0",  desc: "Qualification campaign · ECSS-E-ST-10-03",                  qty: 1, val: QUAL },
                  { line: "2.1",  desc: "  Vibration qual (sine + random, GEVS+3 dB)",                qty: 1, val: QUAL_VIB,    indent: true },
                  { line: "2.2",  desc: "  TVAC · 24 cycles −40 / +85 °C, 1e-5 torr",                  qty: 1, val: QUAL_TVAC,   indent: true },
                  { line: "2.3",  desc: "  EMI / EMC per MIL-STD-461G",                                qty: 1, val: QUAL_EMC,    indent: true },
                  { line: "2.4",  desc: "  Radiation · 30 krad TID + DDD per ECSS-E-ST-10-04",        qty: 1, val: QUAL_RAD,    indent: true },
                  { line: "2.5",  desc: "  Pyroshock · 2000g half-sine 0.5 ms",                         qty: 1, val: QUAL_SHOCK,  indent: true },
                  { line: "2.6",  desc: "  Cleanroom log + ISO 14644-2 monthlies",                     qty: 1, val: QUAL_CLEAN,  indent: true },
                  { line: "3.0",  desc: launch.name,                                                    qty: 1, val: launch.cost, key: "launch" },
                  { line: "4.0",  desc: "Launch + on-orbit insurance (4% of HW + launch)",              qty: 1, val: INSURANCE,   key: "ins", grey: !insIncluded },
                  { line: "5.0",  desc: "Program management fee",                                       qty: 1, val: PM_FEE },
                  { line: "6.0",  desc: "ITAR / EAR compliance + drawing-pull controls",                qty: 1, val: ITAR_COMPLIANCE },
                ].map((r) => (
                  <tr key={r.line} style={{ borderBottom: `1px solid ${AE_LINE_S}`, opacity: r.grey ? 0.55 : 1 }}>
                    <td style={Object.assign({}, aeDiffC(), { fontFamily: AE_FONT_MONO, color: AE_INK_3, width: 60 })}>{r.line}</td>
                    <td style={Object.assign({}, aeDiffC(), { paddingLeft: r.indent ? 32 : 14, color: r.indent ? AE_INK_2 : AE_INK })}>{r.desc}</td>
                    <td style={Object.assign({}, aeDiffC(), { fontFamily: AE_FONT_MONO, color: AE_INK_3, width: 50 })}>{r.qty}</td>
                    <td style={Object.assign({}, aeDiffC(), {
                      fontFamily: AE_FONT_MONO,
                      color: r.indent ? AE_INK_3 : AE_INK,
                      fontWeight: r.indent ? 400 : 600,
                      textAlign: "right", width: 110,
                    })}>{fmt(r.val)}</td>
                  </tr>
                ))}
              </tbody>
            </table>

            {/* pricing breakdown */}
            <div style={{ background: AE_BG_2, padding: 16, borderRadius: 8, marginBottom: 18 }}>
              <div style={Object.assign({}, aeMono(), { marginBottom: 10, color: AE_ACCENT_DEEP })}>FFP price stack</div>
              <div style={{ display: "grid", gridTemplateColumns: "1fr auto", rowGap: 6, fontSize: 13 }}>
                <span style={{ color: AE_INK_2 }}>Subtotal · hardware + qual + launch + ins + PM + ITAR</span>
                <span style={{ fontFamily: AE_FONT_MONO, textAlign: "right" }}>{fmt(SUBTOTAL)}</span>
                <span style={{ color: AE_INK_2 }}>Contingency ({contingPct}%)</span>
                <span style={{ fontFamily: AE_FONT_MONO, textAlign: "right" }}>{fmt(CONTINGENCY)}</span>
                <span style={{ color: AE_INK_2 }}>Margin ({marginPct}%, FFP)</span>
                <span style={{ fontFamily: AE_FONT_MONO, textAlign: "right" }}>{fmt(MARGIN)}</span>
                <span style={{ color: AE_INK, fontWeight: 600, borderTop: `1px solid ${AE_LINE}`, paddingTop: 6, marginTop: 4 }}>FFP price</span>
                <span style={{ fontFamily: AE_FONT_MONO, fontWeight: 700, fontSize: 16, textAlign: "right", borderTop: `1px solid ${AE_LINE}`, paddingTop: 6, marginTop: 4, color: AE_ACCENT_DEEP }}>{fmt(FFP_PRICE)}</span>
                <span style={{ color: AE_INK_3, fontSize: 12 }}>FFP cap (LOI)</span>
                <span style={{ fontFamily: AE_FONT_MONO, fontSize: 12, textAlign: "right", color: AE_INK_3 }}>{fmt(FFP_CAP)}</span>
                <span style={{ color: HEADROOM >= 0 ? AE_GREEN : AE_RED, fontSize: 12, fontWeight: 600 }}>
                  Headroom · {HEADROOM >= 0 ? "under cap" : "over cap"}
                </span>
                <span style={{ fontFamily: AE_FONT_MONO, fontSize: 12, textAlign: "right", color: HEADROOM >= 0 ? AE_GREEN : AE_RED, fontWeight: 600 }}>
                  {HEADROOM >= 0 ? "+" : "−"}{fmt(Math.abs(HEADROOM))}
                </span>
              </div>
            </div>

            {/* terms */}
            <div style={{ fontSize: 12, color: AE_INK_3, lineHeight: 1.7 }}>
              <div style={Object.assign({}, aeMono(), { color: AE_INK_2, marginBottom: 6 })}>Terms</div>
              Payment: 25% at LOI countersignature · 25% at PDR closure · 25% at CDR closure · 25% at flight acceptance.<br />
              Delivery: Aetherion to broker per launch service agreement; insurance assignable to buyer at separation.<br />
              Schedule: 2026-09-10 launch target. 90-day liquidated-damages clause from miss against agreed manifest.<br />
              IP: design IP retained by Aetherion. Mission data + on-orbit telemetry licensed exclusively to Aperture Earth.<br />
              Compliance: ITAR (22 CFR §125) · EAR · AS9100 · NASA-STD-8739 · ECSS-Q-ST-70.<br />
              Warranty: 30 days post-LEOP for workmanship; latent defects per AS9100 8.7. No warranty on launch outcome.
            </div>

            <div style={{ marginTop: 28, paddingTop: 18, borderTop: `1px solid ${AE_LINE}`, fontSize: 12, color: AE_INK_4, textAlign: "right" }}>
              Authorized signatory · J. Reyes (Mission Director) · Aetherion Microsat, Inc.
            </div>
          </AECard>

          {/* ───── Right rail · margin model + launch picker ───── */}
          <div style={{ display: "flex", flexDirection: "column", gap: 16 }}>
            <AECard>
              <div style={Object.assign({}, aeMono(), { marginBottom: 14 })}>Launch service slot</div>
              <div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
                {Object.keys(LAUNCH_VENDORS).map((k) => {
                  const v = LAUNCH_VENDORS[k];
                  const sel = launchVendor === k;
                  return (
                    <button
                      key={k}
                      onClick={() => setLaunchVendor(k)}
                      style={{
                        textAlign: "left",
                        padding: 12,
                        background: sel ? "oklch(0.96 0.03 250)" : AE_BG_3,
                        border: `1px solid ${sel ? AE_ACCENT : AE_LINE}`,
                        borderRadius: 8,
                        cursor: "pointer",
                      }}
                    >
                      <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}>
                        <span style={{ fontFamily: AE_FONT_MONO, fontSize: 12, color: AE_INK }}>{k}</span>
                        <span style={{ fontFamily: AE_FONT_MONO, fontSize: 12, color: sel ? AE_ACCENT_DEEP : AE_INK_3, fontWeight: 600 }}>
                          {fmt(v.cost)}
                        </span>
                      </div>
                      <div style={{ fontSize: 12, color: AE_INK_2, marginTop: 4 }}>{v.name}</div>
                      <div style={{ fontSize: 12, color: AE_INK_4, marginTop: 2 }}>{v.date} · {v.broker}</div>
                    </button>
                  );
                })}
              </div>
            </AECard>

            <AECard>
              <div style={Object.assign({}, aeMono(), { marginBottom: 14 })}>FFP model</div>

              <div style={{ marginBottom: 14 }}>
                <div style={{ display: "flex", justifyContent: "space-between", marginBottom: 6 }}>
                  <span style={{ fontSize: 12, color: AE_INK_3 }}>Margin %</span>
                  <span style={{ fontFamily: AE_FONT_MONO, fontSize: 12, color: AE_INK }}>{marginPct}%</span>
                </div>
                <input id="ae-act1-2-f4" name="ae-act1-2-f4"
                  type="range" min="6" max="22" value={marginPct}
                  onChange={(e) => setMarginPct(Number(e.target.value))}
                  style={{ width: "100%" }}
                />
              </div>

              <div style={{ marginBottom: 14 }}>
                <div style={{ display: "flex", justifyContent: "space-between", marginBottom: 6 }}>
                  <span style={{ fontSize: 12, color: AE_INK_3 }}>Contingency %</span>
                  <span style={{ fontFamily: AE_FONT_MONO, fontSize: 12, color: AE_INK }}>{contingPct}%</span>
                </div>
                <input id="ae-act1-2-f5" name="ae-act1-2-f5"
                  type="range" min="2" max="18" value={contingPct}
                  onChange={(e) => setContingPct(Number(e.target.value))}
                  style={{ width: "100%" }}
                />
              </div>

              <label style={{ display: "inline-flex", alignItems: "center", gap: 8, cursor: "pointer", marginBottom: 14 }}>
                <input id="ae-act1-2-f6" name="ae-act1-2-f6" type="checkbox" checked={insIncluded} onChange={(e) => setInsIncluded(e.target.checked)} />
                <span style={aeMono()}>include insurance</span>
              </label>

              <div style={{
                marginTop: 4, padding: 14,
                background: AE_BG_2,
                border: `1px solid ${AE_LINE}`,
                borderRadius: 8,
              }}>
                <div style={Object.assign({}, aeMono(), { marginBottom: 8, color: AE_ACCENT_DEEP })}>Live recompute</div>
                <div style={{ display: "grid", gridTemplateColumns: "1fr auto", rowGap: 5, fontSize: 12 }}>
                  <span style={{ color: AE_INK_3 }}>Hardware</span>
                  <span style={{ fontFamily: AE_FONT_MONO, textAlign: "right" }}>{fmt(HARDWARE)}</span>
                  <span style={{ color: AE_INK_3 }}>Qual campaign</span>
                  <span style={{ fontFamily: AE_FONT_MONO, textAlign: "right" }}>{fmt(QUAL)}</span>
                  <span style={{ color: AE_INK_3 }}>Launch</span>
                  <span style={{ fontFamily: AE_FONT_MONO, textAlign: "right" }}>{fmt(launch.cost)}</span>
                  <span style={{ color: AE_INK_3 }}>Insurance</span>
                  <span style={{ fontFamily: AE_FONT_MONO, textAlign: "right" }}>{insIncluded ? fmt(INSURANCE) : "—"}</span>
                  <span style={{ color: AE_INK_3 }}>PM + ITAR</span>
                  <span style={{ fontFamily: AE_FONT_MONO, textAlign: "right" }}>{fmt(PM_FEE + ITAR_COMPLIANCE)}</span>
                  <span style={{ color: AE_INK_3, borderTop: `1px solid ${AE_LINE_S}`, paddingTop: 5, marginTop: 4 }}>Subtotal</span>
                  <span style={{ fontFamily: AE_FONT_MONO, textAlign: "right", borderTop: `1px solid ${AE_LINE_S}`, paddingTop: 5, marginTop: 4 }}>{fmt(SUBTOTAL)}</span>
                  <span style={{ color: AE_INK_3 }}>Contingency</span>
                  <span style={{ fontFamily: AE_FONT_MONO, textAlign: "right" }}>{fmt(CONTINGENCY)}</span>
                  <span style={{ color: AE_INK_3 }}>Margin</span>
                  <span style={{ fontFamily: AE_FONT_MONO, textAlign: "right" }}>{fmt(MARGIN)}</span>
                  <span style={{ color: AE_INK, fontWeight: 600 }}>FFP price</span>
                  <span style={{ fontFamily: AE_FONT_MONO, textAlign: "right", fontWeight: 700, color: AE_ACCENT_DEEP }}>{fmt(FFP_PRICE)}</span>
                </div>
                <div style={{
                  marginTop: 12, padding: 8,
                  background: HEADROOM >= 0 ? "oklch(0.95 0.06 165)" : "oklch(0.95 0.06 28)",
                  border: `1px solid ${HEADROOM >= 0 ? AE_GREEN : AE_RED}`,
                  borderRadius: 6,
                  fontSize: 12, color: HEADROOM >= 0 ? AE_GREEN : AE_RED,
                  fontFamily: AE_FONT_MONO, textAlign: "center", fontWeight: 600,
                }}>
                  {HEADROOM >= 0
                    ? "under FFP cap by " + fmt(HEADROOM)
                    : "OVER FFP CAP by " + fmt(Math.abs(HEADROOM)) + " — re-scope or escalate"}
                </div>
              </div>
            </AECard>

            <AEBtn variant="primary" onClick={send} style={{ height: 48, fontSize: 14 }}>
              Send to Aperture Earth →
            </AEBtn>
            <AEBtn variant="tertiary" onClick={() => aeNav("/forge/carryover")} style={{ height: 36, fontSize: 12 }}>
              ← back to heritage audit
            </AEBtn>
          </div>
        </div>
      </div>
    </div>
  );
}

// ════════════════════════════════════════════════════════════════════
// Register routes
// Prefer registerSpaceRoute (per task brief); fall back to
// registerAetherionRoute or registerPumpRoute if the Space registry
// has not yet been wired by Wave-A1 / agent #12 (registry-index.jsx).
// ════════════════════════════════════════════════════════════════════
(function registerAct12() {
  const routes = [
    { path: "/forge/rfq",       mode: "forge", title: "Mission intake (Aetherion)",    renderer: () => React.createElement(ScreenAetherionMissionIntake) },
    { path: "/forge/matcher",   mode: "forge", title: "Propulsion trade study",         renderer: () => React.createElement(ScreenAetherionTradeStudy) },
    { path: "/forge/carryover", mode: "forge", title: "Heritage configuration audit",   renderer: () => React.createElement(ScreenAetherionConfigAudit) },
    { path: "/forge/quote",     mode: "forge", title: "FFP quote — Aperture Earth",     renderer: () => React.createElement(ScreenAetherionQuote) },
  ];
  const reg = (typeof registerSpaceRoute      === "function") ? registerSpaceRoute
            : (typeof registerAetherionRoute  === "function") ? registerAetherionRoute
            : (typeof registerPumpRoute       === "function") ? registerPumpRoute
            : null;
  if (!reg) {
    if (typeof window !== "undefined") {
      window.__SPACE_ACT12_PENDING_ROUTES = (window.__SPACE_ACT12_PENDING_ROUTES || []).concat(routes);
    }
    return;
  }
  routes.forEach(reg);
})();

// expose screen components on window for cross-act linkage + dev console
if (typeof window !== "undefined") {
  window.ScreenAetherionMissionIntake = ScreenAetherionMissionIntake;
  window.ScreenAetherionTradeStudy    = ScreenAetherionTradeStudy;
  window.ScreenAetherionConfigAudit   = ScreenAetherionConfigAudit;
  window.ScreenAetherionQuote         = ScreenAetherionQuote;
}
})();
