(function(){
/* FORGE — Mittelstand Acts 5-6 screens (7 screens).
   Babel-standalone, no imports/exports. Single registry tail.
   Cool gray palette via --mittel-* CSS vars w/ hex fallbacks.
   Mode color cues: traveler:// build:// line:// forge:// auditor:// */

const { useState: uSMS56, useEffect: uEMS56, useMemo: uMMS56, useRef: uRMS56 } = React;

/* ─────────────────────────────────────────────────────────────────────────
   Palette + atom resolution (defensive: prefer window globals from
   cross-cutting.jsx, fall back to local 1-line stubs for parse safety).
   ───────────────────────────────────────────────────────────────────────── */

const MS56_BG          = "var(--mittel-bg, #f4f5f7)";
const MS56_BG_2        = "var(--mittel-bg-2, #e6e8ec)";
const MS56_BG_3        = "var(--mittel-bg-3, #eef0f3)";
const MS56_INK         = "var(--mittel-ink, #1f2328)";
const MS56_INK_2       = "var(--mittel-ink-2, #353a42)";
const MS56_INK_3       = "var(--mittel-ink-3, #565c66)";
const MS56_INK_4       = "var(--mittel-ink-4, #8a909a)";
const MS56_LINE        = "var(--mittel-line, #c8ccd2)";
const MS56_LINE_SOFT   = "var(--mittel-line-soft, #dde0e5)";
const MS56_ACCENT      = "var(--mittel-accent, #6b7480)";
const MS56_ACCENT_WARN = "var(--mittel-accent-warn, #b8851a)";
const MS56_ACCENT_BAD  = "var(--mittel-accent-bad, #a83a2a)";
const MS56_ACCENT_OK   = "var(--mittel-pass, #2d7d4f)";
const MS56_INFO        = "var(--mittel-info, #4a6b8a)";
const MS56_FONT_UI     = "var(--font-ui)";
const MS56_FONT_MONO   = "var(--font-mono)";
const MS56_FONT_SERIF  = "var(--font-serif)";

/* Local fallback atoms (used if window.MS* not present) */
function _ms56_localCard(p){ return React.createElement("div", { style: Object.assign({ background: MS56_BG_3, border: "1px solid " + MS56_LINE, borderRadius: 6, padding: (p && p.pad) || 16 }, (p && p.style) || {}) }, p && p.children); }
function _ms56_localPill(p){ const tone = (p && p.tone) || ""; const map = { ok: MS56_ACCENT_OK, warn: MS56_ACCENT_WARN, err: MS56_ACCENT_BAD, info: MS56_INFO, "": MS56_INK_3 }; const fg = map[tone] || MS56_INK_3; return React.createElement("span", { style: { display: "inline-flex", alignItems: "center", height: 18, padding: "0 8px", borderRadius: 2, fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.06em", textTransform: "uppercase", border: "1px solid " + fg, color: fg, background: "transparent" } }, p && p.children); }
function _ms56_localBtn(p){ const v = (p && p.variant) || "ghost"; const isP = v === "primary"; const isD = v === "danger"; const isB = v === "blue" || v === "info"; const bg = isP ? MS56_INK : isD ? MS56_ACCENT_BAD : isB ? MS56_INFO : "transparent"; const fg = (isP || isD || isB) ? "#fff" : MS56_INK; const br = isP ? MS56_INK : isD ? MS56_ACCENT_BAD : isB ? MS56_INFO : MS56_LINE; return React.createElement("button", { onClick: p && p.onClick, style: { display: "inline-flex", alignItems: "center", justifyContent: "center", gap: 6, height: (p && p.small) ? 24 : 30, padding: (p && p.small) ? "0 10px" : "0 14px", borderRadius: 4, cursor: "pointer", border: "1px solid " + br, background: bg, color: fg, fontFamily: MS56_FONT_UI, fontSize: (p && p.small) ? 11 : 12, fontWeight: 600, letterSpacing: "-0.005em", whiteSpace: "nowrap", userSelect: "none" } }, p && p.children); }
function _ms56_localToolbar(p){ return React.createElement("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", padding: "10px 14px", background: MS56_BG_3, border: "1px solid " + MS56_LINE, borderRadius: 6, gap: 12 } }, React.createElement("div", { style: { display: "flex", alignItems: "center", gap: 10, flexWrap: "wrap" } }, p && p.left), React.createElement("div", { style: { display: "flex", alignItems: "center", gap: 8, flexWrap: "wrap" } }, p && p.right)); }
function _ms56_localStatRow(p){ return React.createElement("div", { style: { display: "grid", gridTemplateColumns: (p && p.cols) || "repeat(auto-fit, minmax(140px, 1fr))", gap: 0, border: "1px solid " + MS56_LINE, borderRadius: 6, overflow: "hidden", background: MS56_BG_3 } }, ((p && p.items) || []).map(function(it, i){ return React.createElement("div", { key: i, style: { padding: "10px 14px", borderRight: i < ((p && p.items) || []).length - 1 ? "1px solid " + MS56_LINE_SOFT : "none" } }, React.createElement("div", { style: { fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.10em", textTransform: "uppercase", color: MS56_INK_4, marginBottom: 4 } }, it.label), React.createElement("div", { style: { fontFamily: it.mono === false ? MS56_FONT_UI : MS56_FONT_MONO, fontSize: 16, color: it.tone === "warn" ? MS56_ACCENT_WARN : it.tone === "err" ? MS56_ACCENT_BAD : it.tone === "ok" ? MS56_ACCENT_OK : MS56_INK } }, it.value)); })); }
function _ms56_localSectionTitle(p){ return React.createElement("div", { style: { marginBottom: 12 } }, p && p.kicker ? React.createElement("div", { style: { fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.12em", textTransform: "uppercase", color: MS56_INK_3, marginBottom: 4 } }, p.kicker) : null, React.createElement("div", { style: { fontFamily: MS56_FONT_SERIF, fontSize: 22, color: MS56_INK, letterSpacing: "-0.01em" } }, p && p.children)); }
function _ms56_localFlash(p){ if (!(p && p.msg)) return null; const k = (p && p.kind) || "info"; const fg = k === "ok" ? MS56_ACCENT_OK : k === "warn" ? MS56_ACCENT_WARN : k === "err" ? MS56_ACCENT_BAD : MS56_INFO; return React.createElement("div", { style: { position: "fixed", top: 64, right: 24, zIndex: 4000, padding: "10px 14px", borderRadius: 4, border: "1px solid " + fg, background: MS56_BG, color: fg, fontFamily: MS56_FONT_UI, fontSize: 13, boxShadow: "0 6px 18px rgba(0,0,0,0.08)", display: "flex", alignItems: "center", gap: 10 } }, React.createElement("span", null, p.msg), React.createElement("button", { onClick: p.onClose, style: { border: 0, background: "transparent", color: fg, cursor: "pointer", fontSize: 16, lineHeight: 1 } }, "×")); }

const _MSCard         = (typeof window !== "undefined" && window.MSCard)         || _ms56_localCard;
const _MSPill         = (typeof window !== "undefined" && window.MSPill)         || _ms56_localPill;
const _MSBtn          = (typeof window !== "undefined" && window.MSBtn)          || _ms56_localBtn;
const _MSToolbar      = (typeof window !== "undefined" && window.MSToolbar)      || _ms56_localToolbar;
const _MSStatRow      = (typeof window !== "undefined" && window.MSStatRow)      || _ms56_localStatRow;
const _MSSectionTitle = (typeof window !== "undefined" && window.MSSectionTitle) || _ms56_localSectionTitle;
const _MSFlash        = (typeof window !== "undefined" && window.MSFlash)        || _ms56_localFlash;

function MS56UseFlash() {
  const [flash, setFlash] = uSMS56(null);
  uEMS56(function() {
    if (!flash) return;
    const id = setTimeout(function(){ setFlash(null); }, 3200);
    return function() { clearTimeout(id); };
  }, [flash]);
  return [flash, setFlash];
}

function useMs56Tenant() {
  return useActiveTenant() || {};
}

const MS56_MONO = { fontFamily: MS56_FONT_MONO };
const MS56_SERIF = { fontFamily: MS56_FONT_SERIF };

/* ═══════════════════════════════════════════════════════════════════════
   Screen 1 — ScreenMittelstandTestReport  (/traveler/report)
   FAI close pack with AS9102/IATF 16949 documents.
   ISO 230-2 geometric test summary, ballbar, contouring vibration trace.
   ═══════════════════════════════════════════════════════════════════════ */

function ScreenMittelstandTestReport() {
  const tenant = useMs56Tenant();
  const [flash, setFlash] = MS56UseFlash();

  const hashParts = (typeof window !== "undefined") ? window.location.hash.split("/").filter(Boolean) : [];
  const overrideSerial = hashParts.length > 2 ? hashParts[2] : null;
  const serialDefault = overrideSerial || "MTL-220-D-0001";

  const traveler = (tenant && tenant.travelers || []).find(function(t){ return t.serial === serialDefault; })
    || { serial: serialDefault, wo: "WO-MTL-2401", part: "MTL-220.00.00", customer: "MAHLE Industriebeteiligungen GmbH" };

  const today = "2026-08-14";
  const opTimestamp = "2026-08-14 09:42 CET";
  const qaTimestamp = "2026-08-14 11:18 CET";
  const witnessTimestamp = "2026-08-14 14:25 CET";

  // ISO 230-2 geometric test rows
  const iso2302Rows = [
    { code: "G1",  name: "Linear positioning · X-axis (1500 mm)", target: "± 4.0 µm", measured: "+2.1 µm / -1.8 µm", pass: true  },
    { code: "G2",  name: "Linear positioning · Y-axis (1200 mm)", target: "± 4.0 µm", measured: "+2.4 µm / -2.0 µm", pass: true  },
    { code: "G3",  name: "Linear positioning · Z-axis (700 mm)",  target: "± 3.5 µm", measured: "+1.9 µm / -1.6 µm", pass: true  },
    { code: "G4",  name: "Repeatability · X (R↑↓)",     target: "≤ 1.5 µm", measured: "0.8 µm",               pass: true  },
    { code: "G5",  name: "Repeatability · Y (R↑↓)",     target: "≤ 1.5 µm", measured: "0.9 µm",               pass: true  },
    { code: "G6",  name: "Squareness · X-Y",                       target: "≤ 5 µm/m", measured: "2.3 µm/m",             pass: true  },
    { code: "G7",  name: "Squareness · Y-Z",                       target: "≤ 5 µm/m", measured: "3.1 µm/m",             pass: true  },
    { code: "G8",  name: "Granite-bed flatness (10.01)",           target: "± 3 µm",   measured: "+1.6 µm / -1.2 µm", pass: true  },
    { code: "G9",  name: "Granite cross-beam flatness (10.02)",    target: "± 3 µm",   measured: "+2.1 µm / -1.4 µm", pass: true  },
    { code: "G10", name: "Spindle radial run-out @24k rpm",        target: "≤ 4 µm TIR", measured: "1.8 µm TIR",          pass: true  },
    { code: "G11", name: "C-axis indexing accuracy",                target: "± 3 arcsec",   measured: "± 1.7 arcsec",          pass: true  },
  ];

  // Ballbar test rows (Renishaw QC20-W)
  const ballbarRows = [
    { plane: "X-Y", radius: "150 mm", feed: "2000 mm/min", circularity: "3.4 µm", target: "≤ 6 µm", pass: true },
    { plane: "Y-Z", radius: "150 mm", feed: "2000 mm/min", circularity: "3.8 µm", target: "≤ 6 µm", pass: true },
    { plane: "X-Z", radius: "150 mm", feed: "2000 mm/min", circularity: "4.1 µm", target: "≤ 6 µm", pass: true },
  ];

  // Contouring vibration trace (synthetic samples at 12k rpm)
  const vibSamples = [
    { rpm: "8000",  rms: 0.32 },
    { rpm: "10000", rms: 0.41 },
    { rpm: "12000", rms: 0.54 },
    { rpm: "14000", rms: 0.61 },
    { rpm: "16000", rms: 0.58 },
    { rpm: "18000", rms: 0.62 },
    { rpm: "20000", rms: 0.66 },
    { rpm: "22000", rms: 0.71 },
    { rpm: "24000", rms: 0.74 },
  ];

  const documents = [
    { id: "AS9102-F1", name: "AS9102 Form 1 - Part Number Accountability",   pages: 1, sha: "0x4a8c…9f12" },
    { id: "AS9102-F2", name: "AS9102 Form 2 - Product Accountability",        pages: 2, sha: "0x71b3…e6c4" },
    { id: "AS9102-F3", name: "AS9102 Form 3 - Characteristic Accountability", pages: 14, sha: "0x9d2e…2a17" },
    { id: "IATF-PPAP", name: "IATF 16949 PPAP Level 3 package",                pages: 38, sha: "0x12f8…b3a9" },
    { id: "ISO-230-2", name: "ISO 230-2 Geometric Performance Test Report",   pages: 11, sha: "0xc4d1…7e85" },
    { id: "CMM-DIM",   name: "Zeiss UPMC dimensional report (DIMS)",          pages: 22, sha: "0x3b76…814f" },
    { id: "FAT-LOG",   name: "Heidenhain TNC 640 control FAT log",            pages: 7,  sha: "0xe502…ac61" },
    { id: "TRV-MS",    name: "Traveler TRV-MS-0244 (signed)",                  pages: 4,  sha: "0x6a9b…4d33" },
  ];

  function onPrint() {
    setFlash({ kind: "info", msg: "FAI pack queued to plotter (HP DesignJet T1700) - 99 pages" });
  }
  function onEmail() {
    setFlash({ kind: "ok", msg: "FAI pack signed + emailed to MAHLE QA (s.klein@mahle-ind.de)" });
  }
  function onArchive() {
    setFlash({ kind: "ok", msg: "FAI archived to ledger - FAI_PACKAGE_GENERATED + FAI_PASSED emitted" });
  }

  const headerKpis = [
    { label: "Serial",        value: traveler.serial },
    { label: "Work order",    value: traveler.wo || "WO-MTL-2401" },
    { label: "Part",          value: "MTL-220.00.00" },
    { label: "FAI date",      value: today },
    { label: "Witness",       value: "MAHLE", tone: "ok" },
    { label: "Result",        value: "PASS",  tone: "ok" },
  ];

  return React.createElement("div", { style: { padding: "16px 20px 80px", maxWidth: 1320, margin: "0 auto", fontFamily: MS56_FONT_UI, color: MS56_INK } },
    React.createElement(_MSSectionTitle, { kicker: "Traveler / FAI close" }, "First-article close · ", React.createElement("span", { style: MS56_MONO }, "TRV-MS-0244")),
    React.createElement(_MSToolbar, {
      left: [
        React.createElement(_MSPill, { key: "ev", tone: "ok" }, "FAI_PASSED"),
        React.createElement(_MSPill, { key: "rev", tone: "info" }, "REV D"),
        React.createElement(_MSPill, { key: "eco", tone: "info" }, "ECO-MS-0017 IN-FORCE"),
        React.createElement("span", { key: "cust", style: Object.assign({}, MS56_MONO, { fontSize: 12, color: MS56_INK_3 }) }, "MAHLE Industriebeteiligungen GmbH"),
      ],
      right: [
        React.createElement(_MSBtn, { key: "p", variant: "ghost", small: true, onClick: onPrint }, "Print"),
        React.createElement(_MSBtn, { key: "e", variant: "info",  small: true, onClick: onEmail }, "Email"),
        React.createElement(_MSBtn, { key: "a", variant: "primary", small: true, onClick: onArchive }, "Archive to ledger"),
      ],
    }),
    React.createElement("div", { style: { height: 12 } }),
    React.createElement(_MSStatRow, { items: headerKpis }),
    React.createElement("div", { style: { height: 16 } }),

    // ISO 230-2 geometric summary
    React.createElement(_MSCard, { pad: 0, style: { padding: 0 } },
      React.createElement("div", { style: { padding: "12px 16px", borderBottom: "1px solid " + MS56_LINE_SOFT, fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.10em", textTransform: "uppercase", color: MS56_INK_3 } }, "ISO 230-2 geometric performance summary"),
      React.createElement("table", { style: { width: "100%", borderCollapse: "collapse", fontSize: 12 } },
        React.createElement("thead", null,
          React.createElement("tr", { style: { background: MS56_BG_2 } },
            ["Code", "Test", "Target", "Measured", "Result"].map(function(h, i){
              return React.createElement("th", { key: i, style: { textAlign: i === 4 ? "center" : "left", padding: "8px 14px", fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.08em", textTransform: "uppercase", color: MS56_INK_3, borderBottom: "1px solid " + MS56_LINE_SOFT } }, h);
            })
          )
        ),
        React.createElement("tbody", null,
          iso2302Rows.map(function(r, i){
            return React.createElement("tr", { key: i, style: { borderBottom: "1px solid " + MS56_LINE_SOFT } },
              React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12, color: MS56_INK_3 }) }, r.code),
              React.createElement("td", { style: { padding: "8px 14px", color: MS56_INK_2 } }, r.name),
              React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12, color: MS56_INK_2 }) }, r.target),
              React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12, color: MS56_INK }) }, r.measured),
              React.createElement("td", { style: { padding: "8px 14px", textAlign: "center" } }, React.createElement(_MSPill, { tone: r.pass ? "ok" : "err" }, r.pass ? "PASS" : "FAIL"))
            );
          })
        )
      )
    ),
    React.createElement("div", { style: { height: 16 } }),

    // Two-up: ballbar + vibration
    React.createElement("div", { style: { display: "grid", gridTemplateColumns: "1fr 1fr", gap: 16 } },
      React.createElement(_MSCard, { pad: 0, style: { padding: 0 } },
        React.createElement("div", { style: { padding: "12px 16px", borderBottom: "1px solid " + MS56_LINE_SOFT, fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.10em", textTransform: "uppercase", color: MS56_INK_3 } }, "Ballbar test · Renishaw QC20-W"),
        React.createElement("table", { style: { width: "100%", borderCollapse: "collapse", fontSize: 12 } },
          React.createElement("thead", null, React.createElement("tr", { style: { background: MS56_BG_2 } },
            ["Plane", "Radius", "Feed", "Circ.", "Target", "R"].map(function(h, i){
              return React.createElement("th", { key: i, style: { textAlign: "left", padding: "8px 12px", fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.08em", textTransform: "uppercase", color: MS56_INK_3, borderBottom: "1px solid " + MS56_LINE_SOFT } }, h);
            })
          )),
          React.createElement("tbody", null, ballbarRows.map(function(r, i){
            return React.createElement("tr", { key: i, style: { borderBottom: "1px solid " + MS56_LINE_SOFT } },
              React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 12px", fontSize: 12 }) }, r.plane),
              React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 12px", fontSize: 12 }) }, r.radius),
              React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 12px", fontSize: 12 }) }, r.feed),
              React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 12px", fontSize: 12, color: MS56_INK }) }, r.circularity),
              React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 12px", fontSize: 12, color: MS56_INK_3 }) }, r.target),
              React.createElement("td", { style: { padding: "8px 12px" } }, React.createElement(_MSPill, { tone: r.pass ? "ok" : "err" }, r.pass ? "OK" : "X"))
            );
          }))
        )
      ),
      React.createElement(_MSCard, { pad: 0, style: { padding: 0 } },
        React.createElement("div", { style: { padding: "12px 16px", borderBottom: "1px solid " + MS56_LINE_SOFT, fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.10em", textTransform: "uppercase", color: MS56_INK_3 } }, "Contouring vibration · RMS mm/s"),
        React.createElement("div", { style: { padding: 16 } },
          React.createElement("svg", { viewBox: "0 0 380 160", style: { width: "100%", height: 160 } },
            React.createElement("line", { x1: 30, y1: 130, x2: 360, y2: 130, stroke: MS56_LINE, strokeWidth: 1 }),
            React.createElement("line", { x1: 30, y1: 20,  x2: 30,  y2: 130, stroke: MS56_LINE, strokeWidth: 1 }),
            React.createElement("line", { x1: 30, y1: 50,  x2: 360, y2: 50,  stroke: MS56_ACCENT_BAD, strokeDasharray: "3 3", strokeWidth: 1 }),
            React.createElement("line", { x1: 30, y1: 70,  x2: 360, y2: 70,  stroke: MS56_ACCENT_WARN, strokeDasharray: "3 3", strokeWidth: 1 }),
            React.createElement("text", { x: 358, y: 47, textAnchor: "end", fontSize: 12, fill: MS56_ACCENT_BAD, fontFamily: "var(--font-mono)" }, "1.0 ship-hold"),
            React.createElement("text", { x: 358, y: 67, textAnchor: "end", fontSize: 12, fill: MS56_ACCENT_WARN, fontFamily: "var(--font-mono)" }, "0.8 limit"),
            React.createElement("polyline", {
              fill: "none", stroke: MS56_ACCENT, strokeWidth: 1.5,
              points: vibSamples.map(function(p, i){ return (30 + i * 36) + "," + (130 - p.rms * 80); }).join(" ")
            }),
            vibSamples.map(function(p, i){ return React.createElement("circle", { key: i, cx: 30 + i * 36, cy: 130 - p.rms * 80, r: 2.5, fill: MS56_INK }); }),
            vibSamples.map(function(p, i){ return React.createElement("text", { key: "l" + i, x: 30 + i * 36, y: 145, textAnchor: "middle", fontSize: 12, fill: MS56_INK_4, fontFamily: "var(--font-mono)" }, p.rpm); })
          ),
          React.createElement("div", { style: { display: "flex", justifyContent: "space-between", marginTop: 8, fontSize: 12, color: MS56_INK_3 } },
            React.createElement("span", null, "Peak @24k: ", React.createElement("span", { style: Object.assign({}, MS56_MONO, { color: MS56_INK }) }, "0.74 mm/s")),
            React.createElement("span", null, "Limit: ", React.createElement("span", { style: Object.assign({}, MS56_MONO, { color: MS56_ACCENT_WARN }) }, "0.80 mm/s"))
          )
        )
      )
    ),
    React.createElement("div", { style: { height: 16 } }),

    // FAI documents
    React.createElement(_MSCard, { pad: 0, style: { padding: 0 } },
      React.createElement("div", { style: { padding: "12px 16px", borderBottom: "1px solid " + MS56_LINE_SOFT, fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.10em", textTransform: "uppercase", color: MS56_INK_3 } }, "FAI close pack · 99 pages · 8 documents"),
      React.createElement("table", { style: { width: "100%", borderCollapse: "collapse", fontSize: 12 } },
        React.createElement("thead", null, React.createElement("tr", { style: { background: MS56_BG_2 } },
          ["ID", "Document", "Pages", "SHA-256 (truncated)", ""].map(function(h, i){
            return React.createElement("th", { key: i, style: { textAlign: "left", padding: "8px 14px", fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.08em", textTransform: "uppercase", color: MS56_INK_3, borderBottom: "1px solid " + MS56_LINE_SOFT } }, h);
          })
        )),
        React.createElement("tbody", null, documents.map(function(d, i){
          return React.createElement("tr", { key: i, style: { borderBottom: "1px solid " + MS56_LINE_SOFT } },
            React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12, color: MS56_INK_3 }) }, d.id),
            React.createElement("td", { style: { padding: "8px 14px", color: MS56_INK } }, d.name),
            React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12, color: MS56_INK_2 }) }, d.pages),
            React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12, color: MS56_INK_4 }) }, d.sha),
            React.createElement("td", { style: { padding: "8px 14px", textAlign: "right" } }, React.createElement(_MSBtn, { variant: "ghost", small: true, onClick: function(){ setFlash({ kind: "info", msg: "Open " + d.id }); } }, "View"))
          );
        }))
      )
    ),
    React.createElement("div", { style: { height: 16 } }),

    // Sign-off rail
    React.createElement(_MSCard, null,
      React.createElement("div", { style: { display: "grid", gridTemplateColumns: "1fr 1fr 1fr", gap: 16 } },
        React.createElement("div", null,
          React.createElement("div", { style: Object.assign({}, MS56_MONO, { fontSize: 12, letterSpacing: "0.10em", textTransform: "uppercase", color: MS56_INK_4 }) }, "Operator"),
          React.createElement("div", { style: { fontSize: 14, color: MS56_INK, marginTop: 4 } }, "M. Schaefer"),
          React.createElement("div", { style: Object.assign({}, MS56_MONO, { fontSize: 12, color: MS56_INK_3, marginTop: 2 }) }, opTimestamp)
        ),
        React.createElement("div", null,
          React.createElement("div", { style: Object.assign({}, MS56_MONO, { fontSize: 12, letterSpacing: "0.10em", textTransform: "uppercase", color: MS56_INK_4 }) }, "Quality lead"),
          React.createElement("div", { style: { fontSize: 14, color: MS56_INK, marginTop: 4 } }, "S. Klein"),
          React.createElement("div", { style: Object.assign({}, MS56_MONO, { fontSize: 12, color: MS56_INK_3, marginTop: 2 }) }, qaTimestamp)
        ),
        React.createElement("div", null,
          React.createElement("div", { style: Object.assign({}, MS56_MONO, { fontSize: 12, letterSpacing: "0.10em", textTransform: "uppercase", color: MS56_INK_4 }) }, "MAHLE witness"),
          React.createElement("div", { style: { fontSize: 14, color: MS56_INK, marginTop: 4 } }, "Dr. T. Hartmann"),
          React.createElement("div", { style: Object.assign({}, MS56_MONO, { fontSize: 12, color: MS56_INK_3, marginTop: 2 }) }, witnessTimestamp)
        )
      )
    ),

    React.createElement(_MSFlash, { kind: flash && flash.kind, msg: flash && flash.msg, onClose: function(){ setFlash(null); } })
  );
}

/* ═══════════════════════════════════════════════════════════════════════
   Screen 2 — ScreenMittelstandCompliance  (/build/compliance)
   IATF 16949 dashboard with NCR closure rates, audit due dates, CAPAs.
   ═══════════════════════════════════════════════════════════════════════ */

function ScreenMittelstandCompliance() {
  const tenant = useMs56Tenant();
  const [flash, setFlash] = MS56UseFlash();
  const [filter, setFilter] = uSMS56("all");

  const standards = [
    { id: "ISO-9001",   name: "ISO 9001:2015",      status: "Certified", expires: "2027-03-12", scope: "QMS", body: "TUV SUD",       lastAudit: "2025-03-08", nextAudit: "2026-03-09", findings: 0 },
    { id: "IATF-16949", name: "IATF 16949:2016",     status: "Certified", expires: "2026-11-04", scope: "Automotive supplemental", body: "DEKRA",        lastAudit: "2024-11-04", nextAudit: "2026-04-22", findings: 2 },
    { id: "EN-230-1",   name: "EN ISO 230-1:2012",   status: "Self-decl", expires: "n/a",        scope: "Geometric accuracy",      body: "in-house",     lastAudit: "2026-08-14", nextAudit: "per-FAI",   findings: 0 },
    { id: "EN-230-2",   name: "EN ISO 230-2:2014",   status: "Self-decl", expires: "n/a",        scope: "Positioning accuracy",    body: "in-house",     lastAudit: "2026-08-14", nextAudit: "per-FAI",   findings: 0 },
    { id: "MD-2006-42", name: "Machinery Directive 2006/42/EC", status: "Declared", expires: "per-shipment", scope: "CE marking", body: "self-declared", lastAudit: "2026-07-31", nextAudit: "per-shipment", findings: 0 },
  ];

  const ncrTable = [
    { id: "NCR-2026-014", part: "MTL-220.10.02", title: "Granite cross-beam flatness drift",  opened: "2026-02-14", closed: "2026-03-22", days: 36, severity: "major", status: "closed",  capa: "CAPA-2026-008" },
    { id: "NCR-2026-019", part: "MTL-220.10.01", title: "Granite-bed lap pass insufficient",   opened: "2026-03-02", closed: "2026-03-30", days: 28, severity: "major", status: "closed",  capa: "CAPA-2026-008" },
    { id: "NCR-2026-022", part: "MTL-220.50.01", title: "Spindle TIR > 4 µm at 24k rpm",  opened: "2026-04-11", closed: "2026-04-19", days: 8,  severity: "minor", status: "closed",  capa: "CAPA-2026-011" },
    { id: "NCR-2026-031", part: "MTL-220.20.00", title: "X-axis ball-screw mounting depth",    opened: "2026-05-07", closed: "2026-05-10", days: 3,  severity: "minor", status: "closed",  capa: "-" },
    { id: "NCR-2026-038", part: "MTL-220.70.00", title: "TNC 640 PLC FAT log gap",              opened: "2026-06-19", closed: null,        days: 28, severity: "minor", status: "open",    capa: "CAPA-2026-014" },
    { id: "NCR-2026-041", part: "MTL-220.50.00", title: "Kessler head torque cert missing",    opened: "2026-07-02", closed: null,        days: 14, severity: "major", status: "open",    capa: "CAPA-2026-015" },
  ];

  const capaTable = [
    { id: "CAPA-2026-008", title: "Granite re-grind op qualification",      owner: "D. Becker", opened: "2026-02-18", due: "2026-03-31", status: "verified",   linkedNCRs: 2 },
    { id: "CAPA-2026-011", title: "Spindle alignment fixture upgrade",      owner: "D. Becker", opened: "2026-04-12", due: "2026-04-30", status: "verified",   linkedNCRs: 1 },
    { id: "CAPA-2026-014", title: "TNC 640 FAT log automation",              owner: "S. Klein",  opened: "2026-06-20", due: "2026-08-31", status: "in-progress", linkedNCRs: 1 },
    { id: "CAPA-2026-015", title: "Kessler torque-cert intake gate",         owner: "S. Klein",  opened: "2026-07-03", due: "2026-09-15", status: "in-progress", linkedNCRs: 1 },
  ];

  const auditCalendar = [
    { date: "2026-03-09", body: "TUV SUD",  type: "ISO 9001 surveillance",  status: "complete", findings: 0 },
    { date: "2026-04-22", body: "DEKRA",    type: "IATF 16949 surveillance", status: "complete", findings: 2 },
    { date: "2026-09-15", body: "MAHLE",    type: "Customer audit (PPAP follow-up)", status: "scheduled", findings: null },
    { date: "2026-11-04", body: "DEKRA",    type: "IATF 16949 recertification", status: "scheduled", findings: null },
    { date: "2027-03-09", body: "TUV SUD",  type: "ISO 9001 recertification", status: "planned",  findings: null },
  ];

  const ncrFiltered = filter === "all" ? ncrTable : ncrTable.filter(function(n){ return n.status === filter; });

  const closureRate = uMMS56(function(){
    const closed = ncrTable.filter(function(n){ return n.status === "closed"; }).length;
    return Math.round((closed / ncrTable.length) * 100);
  }, []);
  const avgClosureDays = uMMS56(function(){
    const closed = ncrTable.filter(function(n){ return n.status === "closed"; });
    if (!closed.length) return 0;
    return Math.round(closed.reduce(function(s, n){ return s + n.days; }, 0) / closed.length);
  }, []);

  return React.createElement("div", { style: { padding: "16px 20px 80px", maxWidth: 1320, margin: "0 auto", fontFamily: MS56_FONT_UI, color: MS56_INK } },
    React.createElement(_MSSectionTitle, { kicker: "Build / Compliance" }, "IATF 16949 dashboard"),
    React.createElement(_MSStatRow, { items: [
      { label: "NCR closure rate",   value: closureRate + "%",            tone: "ok" },
      { label: "Avg days to close",  value: avgClosureDays + " d" },
      { label: "Open NCRs",          value: ncrTable.filter(function(n){ return n.status === "open"; }).length, tone: "warn" },
      { label: "Open CAPAs",         value: capaTable.filter(function(c){ return c.status === "in-progress"; }).length, tone: "warn" },
      { label: "Next audit",         value: "2026-09-15",                  tone: "info" },
      { label: "Cert expires",       value: "2026-11-04",                  tone: "info" },
    ] }),
    React.createElement("div", { style: { height: 16 } }),

    // Standards block
    React.createElement(_MSCard, { pad: 0, style: { padding: 0 } },
      React.createElement("div", { style: { padding: "12px 16px", borderBottom: "1px solid " + MS56_LINE_SOFT, fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.10em", textTransform: "uppercase", color: MS56_INK_3 } }, "Standards in scope"),
      React.createElement("table", { style: { width: "100%", borderCollapse: "collapse", fontSize: 12 } },
        React.createElement("thead", null, React.createElement("tr", { style: { background: MS56_BG_2 } },
          ["Standard", "Status", "Scope", "Body", "Last", "Next", "Findings"].map(function(h, i){
            return React.createElement("th", { key: i, style: { textAlign: i >= 4 ? "left" : "left", padding: "8px 14px", fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.08em", textTransform: "uppercase", color: MS56_INK_3, borderBottom: "1px solid " + MS56_LINE_SOFT } }, h);
          })
        )),
        React.createElement("tbody", null, standards.map(function(s, i){
          return React.createElement("tr", { key: i, style: { borderBottom: "1px solid " + MS56_LINE_SOFT } },
            React.createElement("td", { style: { padding: "8px 14px", color: MS56_INK } }, s.name),
            React.createElement("td", { style: { padding: "8px 14px" } }, React.createElement(_MSPill, { tone: s.status === "Certified" ? "ok" : "info" }, s.status)),
            React.createElement("td", { style: { padding: "8px 14px", color: MS56_INK_2 } }, s.scope),
            React.createElement("td", { style: { padding: "8px 14px", color: MS56_INK_2 } }, s.body),
            React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12, color: MS56_INK_3 }) }, s.lastAudit),
            React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12, color: MS56_INK_3 }) }, s.nextAudit),
            React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12, color: s.findings ? MS56_ACCENT_WARN : MS56_INK_3 }) }, s.findings)
          );
        }))
      )
    ),
    React.createElement("div", { style: { height: 16 } }),

    // NCR table with filter
    React.createElement(_MSToolbar, {
      left: [
        React.createElement("span", { key: "lbl", style: { fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.10em", textTransform: "uppercase", color: MS56_INK_3 } }, "NCR register"),
        React.createElement("div", { key: "filt", style: { display: "flex", gap: 4 } },
          ["all", "open", "closed"].map(function(f){
            return React.createElement(_MSBtn, { key: f, variant: filter === f ? "primary" : "ghost", small: true, onClick: function(){ setFilter(f); } }, f);
          })
        )
      ],
      right: [
        React.createElement(_MSBtn, { key: "exp", variant: "ghost", small: true, onClick: function(){ setFlash({ kind: "info", msg: "NCR register exported (CSV)" }); } }, "Export"),
      ],
    }),
    React.createElement("div", { style: { height: 8 } }),
    React.createElement(_MSCard, { pad: 0, style: { padding: 0 } },
      React.createElement("table", { style: { width: "100%", borderCollapse: "collapse", fontSize: 12 } },
        React.createElement("thead", null, React.createElement("tr", { style: { background: MS56_BG_2 } },
          ["NCR ID", "Part", "Title", "Opened", "Closed", "Days", "Severity", "CAPA", "Status"].map(function(h, i){
            return React.createElement("th", { key: i, style: { textAlign: "left", padding: "8px 14px", fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.08em", textTransform: "uppercase", color: MS56_INK_3, borderBottom: "1px solid " + MS56_LINE_SOFT } }, h);
          })
        )),
        React.createElement("tbody", null, ncrFiltered.map(function(n, i){
          return React.createElement("tr", { key: i, style: { borderBottom: "1px solid " + MS56_LINE_SOFT } },
            React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12, color: MS56_INK_3 }) }, n.id),
            React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12, color: MS56_INK_2 }) }, n.part),
            React.createElement("td", { style: { padding: "8px 14px", color: MS56_INK } }, n.title),
            React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12 }) }, n.opened),
            React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12 }) }, n.closed || "—"),
            React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12, color: MS56_INK }) }, n.days + " d"),
            React.createElement("td", { style: { padding: "8px 14px" } }, React.createElement(_MSPill, { tone: n.severity === "major" ? "err" : "warn" }, n.severity)),
            React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12, color: MS56_INFO }) }, n.capa),
            React.createElement("td", { style: { padding: "8px 14px" } }, React.createElement(_MSPill, { tone: n.status === "closed" ? "ok" : "warn" }, n.status))
          );
        }))
      )
    ),
    React.createElement("div", { style: { height: 16 } }),

    // Two-up: CAPA + audit calendar
    React.createElement("div", { style: { display: "grid", gridTemplateColumns: "1.4fr 1fr", gap: 16 } },
      React.createElement(_MSCard, { pad: 0, style: { padding: 0 } },
        React.createElement("div", { style: { padding: "12px 16px", borderBottom: "1px solid " + MS56_LINE_SOFT, fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.10em", textTransform: "uppercase", color: MS56_INK_3 } }, "CAPA register"),
        React.createElement("table", { style: { width: "100%", borderCollapse: "collapse", fontSize: 12 } },
          React.createElement("thead", null, React.createElement("tr", { style: { background: MS56_BG_2 } },
            ["ID", "Title", "Owner", "Due", "Linked NCRs", "Status"].map(function(h, i){
              return React.createElement("th", { key: i, style: { textAlign: "left", padding: "8px 12px", fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.08em", textTransform: "uppercase", color: MS56_INK_3, borderBottom: "1px solid " + MS56_LINE_SOFT } }, h);
            })
          )),
          React.createElement("tbody", null, capaTable.map(function(c, i){
            return React.createElement("tr", { key: i, style: { borderBottom: "1px solid " + MS56_LINE_SOFT } },
              React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 12px", fontSize: 12, color: MS56_INFO }) }, c.id),
              React.createElement("td", { style: { padding: "8px 12px", color: MS56_INK } }, c.title),
              React.createElement("td", { style: { padding: "8px 12px", color: MS56_INK_2 } }, c.owner),
              React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 12px", fontSize: 12 }) }, c.due),
              React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 12px", fontSize: 12, color: MS56_INK_3, textAlign: "center" }) }, c.linkedNCRs),
              React.createElement("td", { style: { padding: "8px 12px" } }, React.createElement(_MSPill, { tone: c.status === "verified" ? "ok" : "warn" }, c.status))
            );
          }))
        )
      ),
      React.createElement(_MSCard, { pad: 0, style: { padding: 0 } },
        React.createElement("div", { style: { padding: "12px 16px", borderBottom: "1px solid " + MS56_LINE_SOFT, fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.10em", textTransform: "uppercase", color: MS56_INK_3 } }, "Audit calendar"),
        React.createElement("div", { style: { padding: 0 } },
          auditCalendar.map(function(a, i){
            return React.createElement("div", { key: i, style: { padding: "10px 16px", borderBottom: i < auditCalendar.length - 1 ? "1px solid " + MS56_LINE_SOFT : "none", display: "flex", alignItems: "center", gap: 12 } },
              React.createElement("div", { style: Object.assign({}, MS56_MONO, { fontSize: 12, color: MS56_INK, minWidth: 90 }) }, a.date),
              React.createElement("div", { style: { flex: 1 } },
                React.createElement("div", { style: { fontSize: 13, color: MS56_INK } }, a.body),
                React.createElement("div", { style: { fontSize: 12, color: MS56_INK_3 } }, a.type)
              ),
              a.findings != null
                ? React.createElement(_MSPill, { tone: a.findings ? "warn" : "ok" }, a.findings + " findings")
                : React.createElement(_MSPill, { tone: "info" }, a.status)
            );
          })
        )
      )
    ),

    React.createElement(_MSFlash, { kind: flash && flash.kind, msg: flash && flash.msg, onClose: function(){ setFlash(null); } })
  );
}

/* ═══════════════════════════════════════════════════════════════════════
   Screen 3 — ScreenMittelstandDispatch  (/line/dispatch)
   Pack & ship for 24-mill MAHLE batch. Carton selection, logistics handoff.
   ═══════════════════════════════════════════════════════════════════════ */

function ScreenMittelstandDispatch() {
  const [flash, setFlash] = MS56UseFlash();
  const [selectedCarrier, setSelectedCarrier] = uSMS56("dachser");

  // 24 mills, batch 1 = 12, batch 2 = 12
  const batch = [
    { sn: "MTL-220-D-0001", wo: "WO-MTL-2401", crate: "CR-001", weight: "8420 kg", status: "ready",     dest: "MAHLE Stuttgart" },
    { sn: "MTL-220-D-0002", wo: "WO-MTL-2402", crate: "CR-002", weight: "8410 kg", status: "ready",     dest: "MAHLE Stuttgart" },
    { sn: "MTL-220-D-0003", wo: "WO-MTL-2403", crate: "CR-003", weight: "8430 kg", status: "ready",     dest: "MAHLE Stuttgart" },
    { sn: "MTL-220-D-0004", wo: "WO-MTL-2404", crate: "CR-004", weight: "8425 kg", status: "ready",     dest: "MAHLE Stuttgart" },
    { sn: "MTL-220-D-0005", wo: "WO-MTL-2405", crate: "CR-005", weight: "8418 kg", status: "ready",     dest: "MAHLE Stuttgart" },
    { sn: "MTL-220-D-0006", wo: "WO-MTL-2406", crate: "CR-006", weight: "8422 kg", status: "ready",     dest: "MAHLE Stuttgart" },
    { sn: "MTL-220-D-0007", wo: "WO-MTL-2407", crate: "CR-007", weight: "8428 kg", status: "packing",   dest: "MAHLE Stuttgart" },
    { sn: "MTL-220-D-0008", wo: "WO-MTL-2408", crate: "CR-008", weight: "8415 kg", status: "packing",   dest: "MAHLE Stuttgart" },
    { sn: "MTL-220-D-0009", wo: "WO-MTL-2409", crate: "CR-009", weight: "—",  status: "queued",    dest: "MAHLE Stuttgart" },
    { sn: "MTL-220-D-0010", wo: "WO-MTL-2410", crate: "CR-010", weight: "—",  status: "queued",    dest: "MAHLE Stuttgart" },
    { sn: "MTL-220-D-0011", wo: "WO-MTL-2411", crate: "CR-011", weight: "—",  status: "queued",    dest: "MAHLE Stuttgart" },
    { sn: "MTL-220-D-0012", wo: "WO-MTL-2412", crate: "CR-012", weight: "—",  status: "queued",    dest: "MAHLE Stuttgart" },
  ];

  const cartonOptions = [
    { id: "EX-A-1280", desc: "Plywood export crate · ISPM-15 heat-treated · 1280 kg tare", qty: "in-stock 18", lead: "0 d",  unit: "€ 1,420" },
    { id: "EX-A-1480", desc: "Plywood export crate · ISPM-15 · reinforced · 1480 kg",  qty: "in-stock 6",  lead: "12 d", unit: "€ 1,860" },
    { id: "STL-FRM",   desc: "Steel transport frame (return-to-vendor) · 1620 kg",                qty: "lease pool", lead: "5 d",  unit: "€ 240/leg" },
  ];

  const carriers = [
    { id: "dachser",  name: "DACHSER",        mode: "Road · oversize", lead: "1 d",  cost: "€ 1,240/unit", note: "Frame contract" },
    { id: "schenker", name: "DB Schenker",    mode: "Road",                  lead: "1 d",  cost: "€ 1,310/unit", note: "Backup" },
    { id: "kuehne",   name: "Kuehne+Nagel",   mode: "Rail intermodal",       lead: "3 d",  cost: "€ 980/unit",   note: "Eco mode" },
  ];

  const docs = [
    { id: "CMR",     name: "CMR consignment note",                pages: 1, status: "drafted" },
    { id: "CE-DECL", name: "CE Machinery Directive declaration",  pages: 2, status: "signed"  },
    { id: "PACK",    name: "Packing list (per crate)",             pages: 12, status: "drafted" },
    { id: "ISPM-15", name: "ISPM-15 wood treatment cert",          pages: 1, status: "signed"  },
    { id: "INS",     name: "Transport insurance binder",           pages: 1, status: "signed"  },
    { id: "EUR1",    name: "EUR.1 movement certificate",           pages: 1, status: "drafted" },
  ];

  const ready = batch.filter(function(b){ return b.status === "ready"; }).length;
  const packing = batch.filter(function(b){ return b.status === "packing"; }).length;
  const queued = batch.filter(function(b){ return b.status === "queued"; }).length;

  function dispatchAll() { setFlash({ kind: "ok", msg: "Dispatch released to " + selectedCarrier.toUpperCase() + " - " + ready + " units, ETA MAHLE +1 d" }); }

  return React.createElement("div", { style: { padding: "16px 20px 80px", maxWidth: 1320, margin: "0 auto", fontFamily: MS56_FONT_UI, color: MS56_INK } },
    React.createElement(_MSSectionTitle, { kicker: "Line / Dispatch" }, "Pack & ship · MAHLE batch 1 (12 units)"),
    React.createElement(_MSStatRow, { items: [
      { label: "Batch size",  value: "12 units" },
      { label: "Ready",       value: ready,   tone: "ok" },
      { label: "Packing",     value: packing, tone: "info" },
      { label: "Queued",      value: queued },
      { label: "Total weight",value: (ready * 8.42).toFixed(1) + " t" },
      { label: "Carrier",     value: "DACHSER" },
    ] }),
    React.createElement("div", { style: { height: 16 } }),

    // Crate matrix
    React.createElement(_MSCard, { pad: 0, style: { padding: 0 } },
      React.createElement("div", { style: { padding: "12px 16px", borderBottom: "1px solid " + MS56_LINE_SOFT, fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.10em", textTransform: "uppercase", color: MS56_INK_3 } }, "Crate matrix · 12 units"),
      React.createElement("table", { style: { width: "100%", borderCollapse: "collapse", fontSize: 12 } },
        React.createElement("thead", null, React.createElement("tr", { style: { background: MS56_BG_2 } },
          ["Serial", "WO", "Crate", "Weight", "Destination", "Status"].map(function(h, i){
            return React.createElement("th", { key: i, style: { textAlign: "left", padding: "8px 14px", fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.08em", textTransform: "uppercase", color: MS56_INK_3, borderBottom: "1px solid " + MS56_LINE_SOFT } }, h);
          })
        )),
        React.createElement("tbody", null, batch.map(function(b, i){
          return React.createElement("tr", { key: i, style: { borderBottom: "1px solid " + MS56_LINE_SOFT } },
            React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12, color: MS56_INK }) }, b.sn),
            React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12, color: MS56_INK_3 }) }, b.wo),
            React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12, color: MS56_INK_2 }) }, b.crate),
            React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12, color: MS56_INK_2 }) }, b.weight),
            React.createElement("td", { style: { padding: "8px 14px", color: MS56_INK_2 } }, b.dest),
            React.createElement("td", { style: { padding: "8px 14px" } }, React.createElement(_MSPill, { tone: b.status === "ready" ? "ok" : b.status === "packing" ? "info" : "" }, b.status))
          );
        }))
      )
    ),
    React.createElement("div", { style: { height: 16 } }),

    // Two-up: cartons + carriers
    React.createElement("div", { style: { display: "grid", gridTemplateColumns: "1fr 1fr", gap: 16 } },
      React.createElement(_MSCard, { pad: 0, style: { padding: 0 } },
        React.createElement("div", { style: { padding: "12px 16px", borderBottom: "1px solid " + MS56_LINE_SOFT, fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.10em", textTransform: "uppercase", color: MS56_INK_3 } }, "Carton selection"),
        React.createElement("table", { style: { width: "100%", borderCollapse: "collapse", fontSize: 12 } },
          React.createElement("thead", null, React.createElement("tr", { style: { background: MS56_BG_2 } },
            ["Code", "Description", "Stock", "Lead", "Unit"].map(function(h, i){
              return React.createElement("th", { key: i, style: { textAlign: "left", padding: "8px 12px", fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.08em", textTransform: "uppercase", color: MS56_INK_3, borderBottom: "1px solid " + MS56_LINE_SOFT } }, h);
            })
          )),
          React.createElement("tbody", null, cartonOptions.map(function(c, i){
            return React.createElement("tr", { key: i, style: { borderBottom: "1px solid " + MS56_LINE_SOFT } },
              React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 12px", fontSize: 12, color: MS56_INFO }) }, c.id),
              React.createElement("td", { style: { padding: "8px 12px", color: MS56_INK_2, fontSize: 12 } }, c.desc),
              React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 12px", fontSize: 12 }) }, c.qty),
              React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 12px", fontSize: 12 }) }, c.lead),
              React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 12px", fontSize: 12, color: MS56_INK }) }, c.unit)
            );
          }))
        )
      ),
      React.createElement(_MSCard, { pad: 0, style: { padding: 0 } },
        React.createElement("div", { style: { padding: "12px 16px", borderBottom: "1px solid " + MS56_LINE_SOFT, fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.10em", textTransform: "uppercase", color: MS56_INK_3 } }, "Logistics handoff"),
        React.createElement("div", null, carriers.map(function(c, i){
          const sel = selectedCarrier === c.id;
          return React.createElement("div", {
            key: c.id,
            onClick: function(){ setSelectedCarrier(c.id); },
            style: {
              padding: "12px 16px", borderBottom: i < carriers.length - 1 ? "1px solid " + MS56_LINE_SOFT : "none",
              cursor: "pointer", background: sel ? MS56_BG_2 : "transparent",
              borderLeft: "3px solid " + (sel ? MS56_ACCENT : "transparent"),
            }
          },
            React.createElement("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center" } },
              React.createElement("div", null,
                React.createElement("div", { style: { fontSize: 14, color: MS56_INK, fontWeight: 600 } }, c.name),
                React.createElement("div", { style: Object.assign({}, MS56_MONO, { fontSize: 12, color: MS56_INK_3, marginTop: 2 }) }, c.mode + " · " + c.lead),
                React.createElement("div", { style: { fontSize: 12, color: MS56_INK_4, marginTop: 2 } }, c.note)
              ),
              React.createElement("div", { style: Object.assign({}, MS56_MONO, { fontSize: 13, color: MS56_INK }) }, c.cost)
            )
          );
        }))
      )
    ),
    React.createElement("div", { style: { height: 16 } }),

    // Docs + dispatch action
    React.createElement(_MSCard, { pad: 0, style: { padding: 0 } },
      React.createElement("div", { style: { padding: "12px 16px", borderBottom: "1px solid " + MS56_LINE_SOFT, fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.10em", textTransform: "uppercase", color: MS56_INK_3, display: "flex", justifyContent: "space-between", alignItems: "center" } },
        React.createElement("span", null, "Shipment paperwork"),
        React.createElement(_MSBtn, { variant: "primary", small: true, onClick: dispatchAll }, "Dispatch →")
      ),
      React.createElement("table", { style: { width: "100%", borderCollapse: "collapse", fontSize: 12 } },
        React.createElement("thead", null, React.createElement("tr", { style: { background: MS56_BG_2 } },
          ["Doc", "Name", "Pages", "Status"].map(function(h, i){
            return React.createElement("th", { key: i, style: { textAlign: "left", padding: "8px 14px", fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.08em", textTransform: "uppercase", color: MS56_INK_3, borderBottom: "1px solid " + MS56_LINE_SOFT } }, h);
          })
        )),
        React.createElement("tbody", null, docs.map(function(d, i){
          return React.createElement("tr", { key: i, style: { borderBottom: "1px solid " + MS56_LINE_SOFT } },
            React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12, color: MS56_INFO }) }, d.id),
            React.createElement("td", { style: { padding: "8px 14px", color: MS56_INK } }, d.name),
            React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12 }) }, d.pages),
            React.createElement("td", { style: { padding: "8px 14px" } }, React.createElement(_MSPill, { tone: d.status === "signed" ? "ok" : "info" }, d.status))
          );
        }))
      )
    ),

    React.createElement(_MSFlash, { kind: flash && flash.kind, msg: flash && flash.msg, onClose: function(){ setFlash(null); } })
  );
}

/* ═══════════════════════════════════════════════════════════════════════
   Screen 4 — ScreenMittelstandAcceptance  (/forge/acceptance)
   MAHLE customer acceptance witness flow, final FAI signoff,
   witness signature capture.
   ═══════════════════════════════════════════════════════════════════════ */

function ScreenMittelstandAcceptance() {
  const [flash, setFlash] = MS56UseFlash();
  const [signed, setSigned] = uSMS56(false);
  const [witnessName, setWitnessName] = uSMS56("Dr. T. Hartmann");
  const [witnessRole, setWitnessRole] = uSMS56("MAHLE QA Director");
  const [comments, setComments] = uSMS56("");
  const sigCanvasRef = uRMS56(null);
  const drawingRef = uRMS56(false);

  const witnessProtocol = [
    { step: "Power-on + axis warm-up cycle (45 min)",          status: "complete" },
    { step: "ISO 230-2 linear positioning - X/Y/Z axes",        status: "complete" },
    { step: "Renishaw QC20-W ballbar - 3 planes",                status: "complete" },
    { step: "Spindle radial run-out @24k rpm (Faro Vantage)",    status: "complete" },
    { step: "C-axis indexing accuracy (1 arcsec resolver)",      status: "complete" },
    { step: "Contouring vibration test @8/12/16/20/24k rpm",     status: "complete" },
    { step: "Cutting demo - aluminum 7075 pocket sample",        status: "complete" },
    { step: "Cutting demo - hardened tool steel 58 HRC",         status: "complete" },
    { step: "Heidenhain TNC 640 control + safety FAT review",    status: "complete" },
    { step: "Final dimensional witness check (Zeiss UPMC)",      status: "complete" },
    { step: "Documentation review - AS9102 + IATF PPAP L3",      status: "complete" },
    { step: "Customer sign-off",                                  status: signed ? "complete" : "pending" },
  ];

  function startDraw(e) {
    drawingRef.current = true;
    const c = sigCanvasRef.current; if (!c) return;
    const ctx = c.getContext("2d"); ctx.beginPath();
    const r = c.getBoundingClientRect();
    ctx.moveTo((e.clientX || (e.touches && e.touches[0].clientX) || 0) - r.left, (e.clientY || (e.touches && e.touches[0].clientY) || 0) - r.top);
  }
  function moveDraw(e) {
    if (!drawingRef.current) return;
    const c = sigCanvasRef.current; if (!c) return;
    const ctx = c.getContext("2d"); ctx.strokeStyle = "#1f2328"; ctx.lineWidth = 1.6; ctx.lineCap = "round";
    const r = c.getBoundingClientRect();
    ctx.lineTo((e.clientX || (e.touches && e.touches[0].clientX) || 0) - r.left, (e.clientY || (e.touches && e.touches[0].clientY) || 0) - r.top);
    ctx.stroke();
  }
  function endDraw() { drawingRef.current = false; }
  function clearSig() {
    const c = sigCanvasRef.current; if (!c) return;
    const ctx = c.getContext("2d"); ctx.clearRect(0, 0, c.width, c.height);
    setSigned(false);
  }
  function commitSig() {
    setSigned(true);
    setFlash({ kind: "ok", msg: "ACCEPTANCE_SIGNED emitted - traveler TRV-MS-0244 closed" });
  }

  return React.createElement("div", { style: { padding: "16px 20px 80px", maxWidth: 1320, margin: "0 auto", fontFamily: MS56_FONT_UI, color: MS56_INK } },
    React.createElement(_MSSectionTitle, { kicker: "Forge / Acceptance" }, "Customer acceptance · MAHLE witness"),
    React.createElement(_MSStatRow, { items: [
      { label: "Serial",        value: "MTL-220-D-0001" },
      { label: "Traveler",       value: "TRV-MS-0244" },
      { label: "Customer",       value: "MAHLE",                   tone: "info" },
      { label: "Witness",        value: witnessName,                mono: false },
      { label: "FAI",            value: "PASS",                     tone: "ok" },
      { label: "Status",         value: signed ? "SIGNED" : "AWAITING", tone: signed ? "ok" : "warn" },
    ] }),
    React.createElement("div", { style: { height: 16 } }),

    React.createElement("div", { style: { display: "grid", gridTemplateColumns: "1.4fr 1fr", gap: 16 } },
      // Witness protocol
      React.createElement(_MSCard, { pad: 0, style: { padding: 0 } },
        React.createElement("div", { style: { padding: "12px 16px", borderBottom: "1px solid " + MS56_LINE_SOFT, fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.10em", textTransform: "uppercase", color: MS56_INK_3 } }, "Witness protocol · 12 steps"),
        React.createElement("ol", { style: { margin: 0, padding: 0, listStyle: "none" } },
          witnessProtocol.map(function(s, i){
            return React.createElement("li", { key: i, style: { display: "flex", alignItems: "center", gap: 12, padding: "10px 16px", borderBottom: i < witnessProtocol.length - 1 ? "1px solid " + MS56_LINE_SOFT : "none" } },
              React.createElement("div", { style: Object.assign({}, MS56_MONO, { fontSize: 12, color: MS56_INK_4, minWidth: 24 }) }, String(i + 1).padStart(2, "0")),
              React.createElement("div", { style: { flex: 1, fontSize: 13, color: MS56_INK_2 } }, s.step),
              React.createElement(_MSPill, { tone: s.status === "complete" ? "ok" : "warn" }, s.status)
            );
          })
        )
      ),

      // Witness card
      React.createElement(_MSCard, null,
        React.createElement("div", { style: { fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.10em", textTransform: "uppercase", color: MS56_INK_3, marginBottom: 8 } }, "Witness identification"),
        React.createElement("div", { style: { display: "flex", flexDirection: "column", gap: 10 } },
          React.createElement("label", { style: { fontSize: 12, color: MS56_INK_3 } }, "Name"),
          React.createElement("input", {
            type: "text", value: witnessName,
            onChange: function(e){ setWitnessName(e.target.value); },
            style: { padding: "8px 10px", border: "1px solid " + MS56_LINE, borderRadius: 4, fontFamily: MS56_FONT_UI, fontSize: 13, color: MS56_INK, background: MS56_BG }
          }),
          React.createElement("label", { style: { fontSize: 12, color: MS56_INK_3 } }, "Role"),
          React.createElement("input", {
            type: "text", value: witnessRole,
            onChange: function(e){ setWitnessRole(e.target.value); },
            style: { padding: "8px 10px", border: "1px solid " + MS56_LINE, borderRadius: 4, fontFamily: MS56_FONT_UI, fontSize: 13, color: MS56_INK, background: MS56_BG }
          }),
          React.createElement("label", { style: { fontSize: 12, color: MS56_INK_3 } }, "Comments"),
          React.createElement("textarea", {
            value: comments, onChange: function(e){ setComments(e.target.value); },
            placeholder: "Optional - witness remarks",
            style: { padding: "8px 10px", border: "1px solid " + MS56_LINE, borderRadius: 4, fontFamily: MS56_FONT_UI, fontSize: 13, color: MS56_INK, background: MS56_BG, minHeight: 60, resize: "vertical" }
          })
        ),

        React.createElement("div", { style: { marginTop: 16 } },
          React.createElement("div", { style: { fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.10em", textTransform: "uppercase", color: MS56_INK_3, marginBottom: 8 } }, "Signature"),
          React.createElement("canvas", {
            ref: sigCanvasRef, width: 360, height: 100,
            onMouseDown: startDraw, onMouseMove: moveDraw, onMouseUp: endDraw, onMouseLeave: endDraw,
            onTouchStart: startDraw, onTouchMove: moveDraw, onTouchEnd: endDraw,
            style: { width: "100%", height: 100, border: "1px solid " + MS56_LINE, borderRadius: 4, background: MS56_BG, cursor: "crosshair", display: "block" }
          }),
          React.createElement("div", { style: { display: "flex", gap: 8, marginTop: 10 } },
            React.createElement(_MSBtn, { variant: "ghost", small: true, onClick: clearSig }, "Clear"),
            React.createElement(_MSBtn, { variant: signed ? "ghost" : "primary", small: true, onClick: commitSig }, signed ? "Signed" : "Commit signature")
          )
        ),

        React.createElement("div", { style: { marginTop: 16, padding: 10, background: MS56_BG_3, border: "1px solid " + MS56_LINE_SOFT, borderRadius: 4 } },
          React.createElement("div", { style: { fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.08em", textTransform: "uppercase", color: MS56_INK_4 } }, "Will emit on commit"),
          React.createElement("div", { style: Object.assign({}, MS56_MONO, { fontSize: 12, color: MS56_INFO, marginTop: 4 }) }, "CUSTOMER_WITNESSED → ACCEPTANCE_SIGNED"),
          React.createElement("div", { style: Object.assign({}, MS56_MONO, { fontSize: 12, color: MS56_INK_4, marginTop: 2 }) }, "hash-chained to prior receipt")
        )
      )
    ),

    React.createElement(_MSFlash, { kind: flash && flash.kind, msg: flash && flash.msg, onClose: function(){ setFlash(null); } })
  );
}

/* ═══════════════════════════════════════════════════════════════════════
   Screen 5 — ScreenMittelstandFieldIssues  (/forge/field-issues)
   Drill-down on the 3 Rev C field returns that triggered ECO-MS-0017.
   ═══════════════════════════════════════════════════════════════════════ */

function ScreenMittelstandFieldIssues() {
  const [flash, setFlash] = MS56UseFlash();
  const [selected, setSelected] = uSMS56("MTL-220-C-0089");

  const returns = [
    {
      sn: "MTL-220-C-0089", ship: "2025-04-12", returned: "2025-08-19",
      customer: "MAHLE - Reichelsheim plant", site: "Hesse, DE",
      symptom: "Vibration 0.94 mm/s RMS at 12k rpm contouring",
      hours: 1840, eco: "ECO-MS-0017",
      rootCause: "Granite cross-beam (10.02) flatness drift +6.4 µm post-thermal cycle. Single-pass lap insufficient.",
      timeline: [
        { d: "2025-04-12", e: "Shipped from Stuttgart" },
        { d: "2025-05-02", e: "Commissioned at Reichelsheim" },
        { d: "2025-08-04", e: "Customer flagged surface-finish degradation" },
        { d: "2025-08-12", e: "Service tech on-site · vibration capture" },
        { d: "2025-08-19", e: "Returned to Stuttgart for forensic" },
        { d: "2025-08-28", e: "Granite metrology - flatness bust confirmed" },
        { d: "2025-09-05", e: "Re-grind + re-lap completed" },
        { d: "2025-09-14", e: "Re-shipped · vibration 0.42 mm/s post-fix" },
      ],
      cost: "€ 14,200",
      capa: "CAPA-2026-008",
    },
    {
      sn: "MTL-220-C-0091", ship: "2025-05-08", returned: "2025-09-04",
      customer: "MAHLE - Stuttgart plant", site: "Stuttgart, DE",
      symptom: "Vibration 0.88 mm/s RMS at 14k rpm",
      hours: 1620, eco: "ECO-MS-0017",
      rootCause: "Granite-bed (10.01) flatness drift +5.1 µm. Same root cause as 0089.",
      timeline: [
        { d: "2025-05-08", e: "Shipped from Stuttgart" },
        { d: "2025-05-22", e: "Commissioned at Stuttgart" },
        { d: "2025-08-30", e: "Customer flagged contouring chatter" },
        { d: "2025-09-04", e: "Returned to Stuttgart" },
        { d: "2025-09-12", e: "Granite re-work + re-lap" },
        { d: "2025-09-21", e: "Re-shipped · vibration 0.39 mm/s post-fix" },
      ],
      cost: "€ 12,800",
      capa: "CAPA-2026-008",
    },
    {
      sn: "MTL-220-C-0094", ship: "2025-06-19", returned: "2025-10-11",
      customer: "MAHLE - Mannheim plant", site: "Baden-Wurttemberg, DE",
      symptom: "Vibration 1.06 mm/s RMS at 12k rpm · ship-hold trigger",
      hours: 980, eco: "ECO-MS-0017",
      rootCause: "Granite cross-beam (10.02) + bed (10.01) compound drift. Worst of the three.",
      timeline: [
        { d: "2025-06-19", e: "Shipped from Stuttgart" },
        { d: "2025-07-05", e: "Commissioned at Mannheim" },
        { d: "2025-10-04", e: "Customer flagged shutdown threshold breach" },
        { d: "2025-10-11", e: "Emergency return to Stuttgart" },
        { d: "2025-10-18", e: "Forensic teardown · ECO-MS-0017 raised" },
        { d: "2025-10-29", e: "Granite re-work · two-pass lap qualified" },
        { d: "2025-11-08", e: "Re-shipped · vibration 0.36 mm/s post-fix" },
      ],
      cost: "€ 18,400",
      capa: "CAPA-2026-008",
    },
  ];

  const sel = returns.find(function(r){ return r.sn === selected; }) || returns[0];

  return React.createElement("div", { style: { padding: "16px 20px 80px", maxWidth: 1320, margin: "0 auto", fontFamily: MS56_FONT_UI, color: MS56_INK } },
    React.createElement(_MSSectionTitle, { kicker: "Forge / Field issues" }, "Rev C field returns · ECO-MS-0017 trigger"),
    React.createElement(_MSStatRow, { items: [
      { label: "Returns",        value: "3" },
      { label: "All MAHLE",      value: "yes",       tone: "info" },
      { label: "Common cause",   value: "Granite drift", tone: "warn" },
      { label: "Total cost",     value: "€ 45,400", tone: "err" },
      { label: "Triggered ECO",  value: "ECO-MS-0017",   tone: "info" },
      { label: "All re-shipped", value: "yes",       tone: "ok" },
    ] }),
    React.createElement("div", { style: { height: 16 } }),

    React.createElement("div", { style: { display: "grid", gridTemplateColumns: "320px 1fr", gap: 16 } },
      // Picker
      React.createElement(_MSCard, { pad: 0, style: { padding: 0 } },
        React.createElement("div", { style: { padding: "12px 16px", borderBottom: "1px solid " + MS56_LINE_SOFT, fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.10em", textTransform: "uppercase", color: MS56_INK_3 } }, "Returned units"),
        React.createElement("div", null,
          returns.map(function(r, i){
            const isSel = selected === r.sn;
            return React.createElement("div", {
              key: r.sn, onClick: function(){ setSelected(r.sn); },
              style: {
                padding: "12px 16px", borderBottom: i < returns.length - 1 ? "1px solid " + MS56_LINE_SOFT : "none",
                cursor: "pointer", background: isSel ? MS56_BG_2 : "transparent",
                borderLeft: "3px solid " + (isSel ? MS56_ACCENT_BAD : "transparent"),
              }
            },
              React.createElement("div", { style: Object.assign({}, MS56_MONO, { fontSize: 12, color: MS56_INK }) }, r.sn),
              React.createElement("div", { style: { fontSize: 12, color: MS56_INK_3, marginTop: 2 } }, r.customer),
              React.createElement("div", { style: Object.assign({}, MS56_MONO, { fontSize: 12, color: MS56_ACCENT_BAD, marginTop: 4 }) }, r.symptom)
            );
          })
        )
      ),

      // Detail
      React.createElement("div", null,
        React.createElement(_MSCard, null,
          React.createElement("div", { style: { display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 16 } },
            React.createElement("div", null,
              React.createElement("div", { style: Object.assign({}, MS56_MONO, { fontSize: 12, letterSpacing: "0.10em", textTransform: "uppercase", color: MS56_INK_4 }) }, "Customer"),
              React.createElement("div", { style: { fontSize: 14, color: MS56_INK, marginTop: 4 } }, sel.customer),
              React.createElement("div", { style: { fontSize: 12, color: MS56_INK_3 } }, sel.site)
            ),
            React.createElement("div", null,
              React.createElement("div", { style: Object.assign({}, MS56_MONO, { fontSize: 12, letterSpacing: "0.10em", textTransform: "uppercase", color: MS56_INK_4 }) }, "Service hours"),
              React.createElement("div", { style: Object.assign({}, MS56_MONO, { fontSize: 16, color: MS56_INK, marginTop: 4 }) }, sel.hours + " h")
            ),
            React.createElement("div", null,
              React.createElement("div", { style: Object.assign({}, MS56_MONO, { fontSize: 12, letterSpacing: "0.10em", textTransform: "uppercase", color: MS56_INK_4 }) }, "Service cost"),
              React.createElement("div", { style: Object.assign({}, MS56_MONO, { fontSize: 16, color: MS56_ACCENT_BAD, marginTop: 4 }) }, sel.cost)
            )
          ),
          React.createElement("div", { style: { marginTop: 16, padding: 12, background: MS56_BG_3, border: "1px solid " + MS56_LINE_SOFT, borderRadius: 4 } },
            React.createElement("div", { style: Object.assign({}, MS56_MONO, { fontSize: 12, letterSpacing: "0.10em", textTransform: "uppercase", color: MS56_INK_4 }) }, "Symptom"),
            React.createElement("div", { style: { fontSize: 13, color: MS56_INK, marginTop: 4 } }, sel.symptom)
          ),
          React.createElement("div", { style: { marginTop: 12, padding: 12, background: MS56_BG_3, border: "1px solid " + MS56_LINE_SOFT, borderRadius: 4 } },
            React.createElement("div", { style: Object.assign({}, MS56_MONO, { fontSize: 12, letterSpacing: "0.10em", textTransform: "uppercase", color: MS56_INK_4 }) }, "Root cause"),
            React.createElement("div", { style: { fontSize: 13, color: MS56_INK_2, marginTop: 4 } }, sel.rootCause),
            React.createElement("div", { style: { marginTop: 6, display: "flex", gap: 8 } },
              React.createElement(_MSPill, { tone: "info" }, sel.eco),
              React.createElement(_MSPill, { tone: "info" }, sel.capa)
            )
          )
        ),
        React.createElement("div", { style: { height: 12 } }),

        // Timeline
        React.createElement(_MSCard, { pad: 0, style: { padding: 0 } },
          React.createElement("div", { style: { padding: "12px 16px", borderBottom: "1px solid " + MS56_LINE_SOFT, fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.10em", textTransform: "uppercase", color: MS56_INK_3 } }, "Timeline · " + sel.sn),
          React.createElement("ol", { style: { margin: 0, padding: 0, listStyle: "none" } },
            sel.timeline.map(function(t, i){
              return React.createElement("li", { key: i, style: { display: "grid", gridTemplateColumns: "120px 1fr", gap: 12, padding: "10px 16px", borderBottom: i < sel.timeline.length - 1 ? "1px solid " + MS56_LINE_SOFT : "none", alignItems: "center" } },
                React.createElement("div", { style: Object.assign({}, MS56_MONO, { fontSize: 12, color: MS56_INK }) }, t.d),
                React.createElement("div", { style: { fontSize: 13, color: MS56_INK_2 } }, t.e)
              );
            })
          )
        ),
        React.createElement("div", { style: { height: 12 } }),
        React.createElement(_MSToolbar, {
          left: [
            React.createElement("span", { key: "k", style: { fontSize: 12, color: MS56_INK_3 } }, "All three units re-shipped under ECO-MS-0017 spec - no recurrence after 90 d field validation"),
          ],
          right: [
            React.createElement(_MSBtn, { key: "eco", variant: "info", small: true, onClick: function(){ setFlash({ kind: "info", msg: "Open ECO-MS-0017" }); } }, "Open ECO"),
            React.createElement(_MSBtn, { key: "capa", variant: "ghost", small: true, onClick: function(){ setFlash({ kind: "info", msg: "Open " + sel.capa }); } }, "Open CAPA"),
          ],
        })
      )
    ),

    React.createElement(_MSFlash, { kind: flash && flash.kind, msg: flash && flash.msg, onClose: function(){ setFlash(null); } })
  );
}

/* ═══════════════════════════════════════════════════════════════════════
   Screen 6 — ScreenMittelstandAftermarket  (/forge/aftermarket)
   Spare HSK-A63 toolholders, spindle bearing kits, granite re-grind.
   ═══════════════════════════════════════════════════════════════════════ */

function ScreenMittelstandAftermarket() {
  const [flash, setFlash] = MS56UseFlash();
  const [tab, setTab] = uSMS56("spares");

  const spares = [
    { sku: "HSK-A63-32-90",  desc: "HSK-A63 toolholder · Ø32 · 90 mm · balanced G2.5 @25k rpm", stock: 18, lead: "0 d",  unit: "€ 280",   yr: 32 },
    { sku: "HSK-A63-25-90",  desc: "HSK-A63 toolholder · Ø25 · 90 mm · balanced G2.5 @25k rpm", stock: 14, lead: "0 d",  unit: "€ 260",   yr: 28 },
    { sku: "HSK-A63-16-110", desc: "HSK-A63 toolholder · Ø16 · 110 mm · balanced G2.5 @25k rpm", stock: 9,  lead: "0 d",  unit: "€ 240",   yr: 24 },
    { sku: "HSK-A63-PUL",    desc: "HSK-A63 pull-stud (DIN 69893) · stainless",                                  stock: 220, lead: "0 d",  unit: "€ 28",    yr: 480 },
    { sku: "HSK-COLLET-1",   desc: "ER-32 collet set 1-20 mm (1 mm steps)",                                            stock: 6,  lead: "5 d",  unit: "€ 1,180", yr: 12 },
    { sku: "BRG-KIT-50.01",  desc: "Spindle bearing kit · GMN HC 7014 · ABEC-9 · 4-pc",                  stock: 3,  lead: "65 d", unit: "€ 4,200", yr: 12 },
    { sku: "BRG-KIT-50.01R", desc: "Spindle bearing kit · ceramic hybrid · GMN HC 7014C · 4-pc",         stock: 1,  lead: "90 d", unit: "€ 6,800", yr: 4  },
    { sku: "ATC-FNGR-60",    desc: "ATC carousel finger assembly · 24-pocket · DMG Mori OEM",                stock: 4,  lead: "21 d", unit: "€ 480",   yr: 8 },
    { sku: "ENC-LC415",      desc: "Heidenhain LC 415 linear encoder · 1620 mm",                                   stock: 2,  lead: "32 d", unit: "€ 4,820", yr: 6 },
    { sku: "HYD-PUMP-80",    desc: "Bosch Rexroth A10VSO hydraulic pump · coolant module",                         stock: 3,  lead: "14 d", unit: "€ 2,600", yr: 6 },
  ];

  const services = [
    { id: "GRG-RE",   name: "Granite re-grind · bed + cross-beam",        scope: "10.01 + 10.02 · ECO-MS-0017 spec (±3 µm)", lead: "21 d", price: "€ 14,800", note: "Includes ISO 230-2 re-validation" },
    { id: "SPD-OVH",  name: "Spindle overhaul · HSK-A63 24k",              scope: "Bearing replace + dynamic balance + run-out cert",        lead: "45 d", price: "€ 9,400",  note: "GMN authorized service" },
    { id: "GEO-CAL",  name: "On-site geometric re-calibration",                 scope: "ISO 230-2 + ballbar + Faro Vantage · 1 day",         lead: "7 d",  price: "€ 4,200",  note: "Includes signed FAI refresh" },
    { id: "CTRL-UPG", name: "TNC 640 retrofit upgrade",                          scope: "TNC 640 hardware swap + parameter migration",             lead: "30 d", price: "€ 38,000", note: "From TNC 530/620" },
    { id: "PM-YR1",   name: "Annual preventive maintenance contract",            scope: "2 visits/yr · lube · filter · axis check",  lead: "scheduled", price: "€ 12,000/yr", note: "Includes priority field response" },
  ];

  const fleetMix = [
    { customer: "MAHLE - Stuttgart",      mtl220: 8, status: "warranty active" },
    { customer: "MAHLE - Mannheim",        mtl220: 5, status: "warranty active" },
    { customer: "MAHLE - Reichelsheim",    mtl220: 4, status: "warranty active" },
    { customer: "MAHLE - Wackersdorf",     mtl220: 3, status: "queued batch-2" },
    { customer: "Bosch - Feuerbach",       mtl220: 2, status: "PM contract" },
    { customer: "ZF - Friedrichshafen",    mtl220: 2, status: "PM contract" },
  ];

  const tabs = [
    { id: "spares",   label: "Spare parts" },
    { id: "services", label: "Services" },
    { id: "fleet",    label: "Installed fleet" },
  ];

  return React.createElement("div", { style: { padding: "16px 20px 80px", maxWidth: 1320, margin: "0 auto", fontFamily: MS56_FONT_UI, color: MS56_INK } },
    React.createElement(_MSSectionTitle, { kicker: "Forge / Aftermarket" }, "Spares + service catalog"),
    React.createElement(_MSStatRow, { items: [
      { label: "Installed base", value: "24 units" },
      { label: "Spare SKUs",     value: spares.length },
      { label: "Services",       value: services.length },
      { label: "Annual fwd run", value: "€ 1.6M",  tone: "ok" },
      { label: "Warranty",       value: "24 mo" },
      { label: "Field response", value: "≤ 24 h",  tone: "info" },
    ] }),
    React.createElement("div", { style: { height: 16 } }),

    React.createElement(_MSToolbar, {
      left: tabs.map(function(t){
        return React.createElement(_MSBtn, { key: t.id, variant: tab === t.id ? "primary" : "ghost", small: true, onClick: function(){ setTab(t.id); } }, t.label);
      }),
      right: [
        React.createElement(_MSBtn, { key: "ord", variant: "info", small: true, onClick: function(){ setFlash({ kind: "ok", msg: "Quote drafted - awaiting customer PO" }); } }, "Draft quote"),
      ],
    }),
    React.createElement("div", { style: { height: 12 } }),

    tab === "spares" ? React.createElement(_MSCard, { pad: 0, style: { padding: 0 } },
      React.createElement("table", { style: { width: "100%", borderCollapse: "collapse", fontSize: 12 } },
        React.createElement("thead", null, React.createElement("tr", { style: { background: MS56_BG_2 } },
          ["SKU", "Description", "Stock", "Lead", "Unit price", "Yearly run"].map(function(h, i){
            return React.createElement("th", { key: i, style: { textAlign: "left", padding: "8px 14px", fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.08em", textTransform: "uppercase", color: MS56_INK_3, borderBottom: "1px solid " + MS56_LINE_SOFT } }, h);
          })
        )),
        React.createElement("tbody", null, spares.map(function(s, i){
          return React.createElement("tr", { key: i, style: { borderBottom: "1px solid " + MS56_LINE_SOFT } },
            React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12, color: MS56_INK }) }, s.sku),
            React.createElement("td", { style: { padding: "8px 14px", color: MS56_INK_2 } }, s.desc),
            React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12, color: s.stock < 5 ? MS56_ACCENT_WARN : MS56_INK }) }, s.stock),
            React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12, color: MS56_INK_3 }) }, s.lead),
            React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12, color: MS56_INK }) }, s.unit),
            React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12, color: MS56_INK_3 }) }, s.yr + "/yr")
          );
        }))
      )
    ) : null,

    tab === "services" ? React.createElement(_MSCard, { pad: 0, style: { padding: 0 } },
      React.createElement("table", { style: { width: "100%", borderCollapse: "collapse", fontSize: 12 } },
        React.createElement("thead", null, React.createElement("tr", { style: { background: MS56_BG_2 } },
          ["ID", "Service", "Scope", "Lead", "Price", "Note"].map(function(h, i){
            return React.createElement("th", { key: i, style: { textAlign: "left", padding: "8px 14px", fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.08em", textTransform: "uppercase", color: MS56_INK_3, borderBottom: "1px solid " + MS56_LINE_SOFT } }, h);
          })
        )),
        React.createElement("tbody", null, services.map(function(s, i){
          return React.createElement("tr", { key: i, style: { borderBottom: "1px solid " + MS56_LINE_SOFT } },
            React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12, color: MS56_INFO }) }, s.id),
            React.createElement("td", { style: { padding: "8px 14px", color: MS56_INK } }, s.name),
            React.createElement("td", { style: { padding: "8px 14px", color: MS56_INK_2, fontSize: 12 } }, s.scope),
            React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12 }) }, s.lead),
            React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12, color: MS56_INK }) }, s.price),
            React.createElement("td", { style: { padding: "8px 14px", color: MS56_INK_4, fontSize: 12 } }, s.note)
          );
        }))
      )
    ) : null,

    tab === "fleet" ? React.createElement(_MSCard, { pad: 0, style: { padding: 0 } },
      React.createElement("table", { style: { width: "100%", borderCollapse: "collapse", fontSize: 12 } },
        React.createElement("thead", null, React.createElement("tr", { style: { background: MS56_BG_2 } },
          ["Customer site", "MTL-220 units", "Status"].map(function(h, i){
            return React.createElement("th", { key: i, style: { textAlign: "left", padding: "8px 14px", fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.08em", textTransform: "uppercase", color: MS56_INK_3, borderBottom: "1px solid " + MS56_LINE_SOFT } }, h);
          })
        )),
        React.createElement("tbody", null, fleetMix.map(function(f, i){
          return React.createElement("tr", { key: i, style: { borderBottom: "1px solid " + MS56_LINE_SOFT } },
            React.createElement("td", { style: { padding: "8px 14px", color: MS56_INK } }, f.customer),
            React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 14px", fontSize: 12, color: MS56_INK }) }, f.mtl220),
            React.createElement("td", { style: { padding: "8px 14px" } }, React.createElement(_MSPill, { tone: "info" }, f.status))
          );
        }))
      )
    ) : null,

    React.createElement(_MSFlash, { kind: flash && flash.kind, msg: flash && flash.msg, onClose: function(){ setFlash(null); } })
  );
}

/* ═══════════════════════════════════════════════════════════════════════
   Screen 7 — ScreenMittelstandLedger  (/auditor/ledger)
   22-event signed ledger per Mittelstand spec §9.
   Filter by mode/actor/date, hash-chain receipts.
   ═══════════════════════════════════════════════════════════════════════ */

function ScreenMittelstandLedger() {
  const tenant = useMs56Tenant();
  const [flash, setFlash] = MS56UseFlash();
  const [filterMode, setFilterMode] = uSMS56("all");
  const [filterActor, setFilterActor] = uSMS56("all");
  const [searchQ, setSearchQ] = uSMS56("");
  const [selected, setSelected] = uSMS56(null);

  /* Wave 8F — top-level tab ∈ {"events", "transitions"}. Defaults to
     "events" so the existing experience is preserved; auditors switch
     to "transitions" for the FSM v2 state-machine audit trail. */
  const [tab, setTab] = uSMS56("events");
  const [fsmRows, setFsmRows] = uSMS56([]);
  const [fsmLoading, setFsmLoading] = uSMS56(false);
  const [fsmErr, setFsmErr] = uSMS56(null);
  const [fsmMachine, setFsmMachine] = uSMS56("all");
  const [fsmEntity, setFsmEntity] = uSMS56("");
  const [fsmLimit, setFsmLimit] = uSMS56(50);

  function loadFsmRows() {
    if (typeof window === "undefined" || !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); });
  }

  uEMS56(function() {
    if (tab === "transitions") loadFsmRows();
  // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [tab, fsmMachine, fsmEntity, fsmLimit]);

  /* Wave 8F — auto-refresh transitions on SSE event (debounced via the
     server's existing per-tenant event stream). Subscribe only while
     the tab is visible to avoid wasted EventSource connections. */
  uEMS56(function() {
    if (tab !== "transitions") return undefined;
    if (typeof window === "undefined" || !window.forgeApi || !window.forgeApi.subscribeEvents) return undefined;
    const unsub = window.forgeApi.subscribeEvents(function(){ loadFsmRows(); });
    return function() { try { typeof unsub === "function" && unsub(); } catch(_e) { /* ignore */ } };
  // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [tab, fsmMachine, fsmEntity, fsmLimit]);

  /* Color-coded verbs: approve=green, reject=red, release=blue. */
  function verbColor(v) {
    const s = String(v || "").toLowerCase();
    if (/approve|pass|complete|sign|accept|certif/.test(s)) return MS56_ACCENT_OK;
    if (/reject|fail|return|block|escalat|cancel/.test(s)) return MS56_ACCENT_BAD;
    if (/release|publish|dispatch|emit/.test(s)) return MS56_INFO;
    return MS56_INK_2;
  }

  const fallback = [
    { i:  1, ts: "2025-09-08 09:14 CET", event: "RFQ_RECEIVED",          mode: "forge",    actor: "intake",     wo: "RFQ-MS-0244", part: "MTL-220.00.00", hash: "0x4a8c…9f12", prev: "0x0000…0000" },
    { i:  2, ts: "2025-09-09 11:02 CET", event: "DESIGN_MATCH",          mode: "forge",    actor: "R. Vogt",    wo: "RFQ-MS-0244", part: "MTL-220.00.00", hash: "0x71b3…e6c4", prev: "0x4a8c…9f12" },
    { i:  3, ts: "2025-09-12 14:38 CET", event: "CARRYOVER_DIFF",        mode: "forge",    actor: "R. Vogt",    wo: "RFQ-MS-0244", part: "MTL-220.10.02", hash: "0x9d2e…2a17", prev: "0x71b3…e6c4" },
    { i:  4, ts: "2025-09-26 16:50 CET", event: "QUOTE_SENT",            mode: "forge",    actor: "P. Maier",   wo: "RFQ-MS-0244", part: "MTL-220.00.00", hash: "0x12f8…b3a9", prev: "0x9d2e…2a17" },
    { i:  5, ts: "2025-09-30 10:15 CET", event: "FRAME_CONTRACT_SIGNED", mode: "forge",    actor: "P. Maier",   wo: "FC-MAHLE-2026", part: "MTL-220.00.00", hash: "0xc4d1…7e85", prev: "0x12f8…b3a9" },
    { i:  6, ts: "2025-10-15 08:42 CET", event: "ECO_RAISED",            mode: "build",    actor: "R. Vogt",    wo: "ECO-MS-0017", part: "MTL-220.10.02", hash: "0x3b76…814f", prev: "0xc4d1…7e85" },
    { i:  7, ts: "2025-10-31 17:08 CET", event: "ECO_APPROVED",          mode: "build",    actor: "D. Becker",  wo: "ECO-MS-0017", part: "MTL-220.10.01", hash: "0xe502…ac61", prev: "0x3b76…814f" },
    { i:  8, ts: "2025-11-10 12:21 CET", event: "ROUTING_REVISED",       mode: "build",    actor: "D. Becker",  wo: "RT-MTL-220-D", part: "MTL-220.10.01", hash: "0x6a9b…4d33", prev: "0xe502…ac61" },
    { i:  9, ts: "2025-11-20 10:00 CET", event: "GATES_PUBLISHED",       mode: "build",    actor: "S. Klein",   wo: "QG-MTL-220-D", part: "MTL-220.00.00", hash: "0x8c43…1f72", prev: "0x6a9b…4d33" },
    { i: 10, ts: "2026-01-08 09:30 CET", event: "LONG_LEAD_PO_RELEASED", mode: "line",     actor: "K. Weber",   wo: "PO-GMN-2401",  part: "MTL-220.50.01", hash: "0xaf91…d264", prev: "0x8c43…1f72" },
    { i: 11, ts: "2026-01-15 11:18 CET", event: "WO_RELEASED",           mode: "line",     actor: "K. Weber",   wo: "WO-MTL-2401..2424", part: "MTL-220.00.00", hash: "0x5e10…c7a3", prev: "0xaf91…d264" },
    { i: 12, ts: "2026-03-04 13:45 CET", event: "RECEIVING_LOGGED",      mode: "traveler", actor: "F. Bauer",   wo: "WO-MTL-2401", part: "MTL-220.10.01", hash: "0x2d68…b914", prev: "0x5e10…c7a3" },
    { i: 13, ts: "2026-03-04 14:02 CET", event: "INCOMING_INSPECTION_PASS", mode: "traveler", actor: "F. Bauer", wo: "WO-MTL-2401", part: "MTL-220.10.01", hash: "0x9f55…3e21", prev: "0x2d68…b914" },
    { i: 14, ts: "2026-04-11 15:33 CET", event: "NCR_OPENED",            mode: "build",    actor: "S. Klein",   wo: "NCR-2026-022", part: "MTL-220.50.01", hash: "0x7b22…f180", prev: "0x9f55…3e21" },
    { i: 15, ts: "2026-04-12 08:14 CET", event: "CAPA_LINKED",           mode: "build",    actor: "D. Becker",  wo: "CAPA-2026-011", part: "MTL-220.50.01", hash: "0x4061…ed8a", prev: "0x7b22…f180" },
    { i: 16, ts: "2026-06-22 11:50 CET", event: "ROUTING_PASS",          mode: "traveler", actor: "M. Schaefer",wo: "WO-MTL-2401", part: "MTL-220.20.00", hash: "0xd348…792c", prev: "0x4061…ed8a" },
    { i: 17, ts: "2026-07-04 14:22 CET", event: "DIM_INSPECTED",         mode: "traveler", actor: "M. Schaefer",wo: "WO-MTL-2401", part: "MTL-220.20.00", hash: "0x1ea0…6b48", prev: "0xd348…792c" },
    { i: 18, ts: "2026-07-29 16:08 CET", event: "SUBASSY_COMPLETED",     mode: "traveler", actor: "M. Schaefer",wo: "WO-MTL-2401", part: "MTL-220.50.00", hash: "0x83cc…4a05", prev: "0x1ea0…6b48" },
    { i: 19, ts: "2026-08-13 17:55 CET", event: "FAI_PACKAGE_GENERATED", mode: "build",    actor: "S. Klein",   wo: "FAI-MTL-0244", part: "MTL-220.00.00", hash: "0xb617…d09e", prev: "0x83cc…4a05" },
    { i: 20, ts: "2026-08-14 11:18 CET", event: "FAI_PASSED",            mode: "traveler", actor: "S. Klein",   wo: "FAI-MTL-0244", part: "MTL-220.00.00", hash: "0x2c4f…876d", prev: "0xb617…d09e" },
    { i: 21, ts: "2026-08-14 14:25 CET", event: "CUSTOMER_WITNESSED",    mode: "forge",    actor: "T. Hartmann (MAHLE)", wo: "TRV-MS-0244", part: "MTL-220.00.00", hash: "0x9802…115b", prev: "0x2c4f…876d" },
    { i: 22, ts: "2026-08-14 14:38 CET", event: "ACCEPTANCE_SIGNED",     mode: "auditor",  actor: "T. Hartmann (MAHLE)", wo: "TRV-MS-0244", part: "MTL-220.00.00", hash: "0xfa31…e7c2", prev: "0x9802…115b" },
  ];

  const ledgerRaw = (tenant && Array.isArray(tenant.ledger) && tenant.ledger.length === 22) ? tenant.ledger : fallback;

  /* Wave 11B — normalize ledger rows to a canonical render shape.
     Fixture (client/fixtures-mittelstand.jsx) uses {event_id, type, ref, hash_prev, summary}
     while the fallback array uses {i, event, wo, part, prev}. Map both to one
     shape so the table, filter blob, and selected-detail panel agree. */
  const ledger = ledgerRaw.map(function(r, idx) {
    return {
      i:      (typeof r.i === "number") ? r.i : (idx + 1),
      ts:     r.ts,
      event:  r.event || r.type || "",
      mode:   r.mode,
      actor:  r.actor,
      wo:     r.wo || r.ref || "",
      part:   r.part || "",
      hash:   r.hash || "",
      prev:   r.prev || r.hash_prev || "",
      summary: r.summary || "",
    };
  });

  const modes  = ["all", "forge", "build", "line", "traveler", "auditor"];
  const actors = uMMS56(function(){
    const m = {};
    ledger.forEach(function(r){ m[r.actor] = true; });
    return ["all"].concat(Object.keys(m));
  }, [ledger]);

  const filtered = ledger.filter(function(r){
    if (filterMode !== "all" && r.mode !== filterMode) return false;
    if (filterActor !== "all" && r.actor !== filterActor) return false;
    if (searchQ) {
      const q = searchQ.toLowerCase();
      const blob = (r.event + " " + r.actor + " " + r.wo + " " + r.part + " " + r.hash + " " + r.summary).toLowerCase();
      if (blob.indexOf(q) === -1) return false;
    }
    return true;
  });

  const modeColor = { forge: MS56_INFO, build: MS56_ACCENT, line: MS56_ACCENT_OK, traveler: MS56_INK_2, auditor: MS56_INK };

  /* Wave 8F — tab strip (Events ↔ State transitions). */
  const tabBar = React.createElement("div", {
    style: { display: "flex", gap: 4, marginBottom: 12, borderBottom: "1px solid " + MS56_LINE_SOFT },
  },
    [
      { id: "events",      label: "Events (ledger)" },
      { id: "transitions", label: "State transitions" },
    ].map(function(t){
      const active = tab === t.id;
      return React.createElement("button", {
        key: t.id, onClick: function(){ setTab(t.id); },
        style: {
          padding: "8px 14px",
          background: active ? MS56_BG_3 : "transparent",
          border: 0,
          borderBottom: active ? "2px solid " + MS56_INK : "2px solid transparent",
          fontFamily: MS56_FONT_MONO, fontSize: 12,
          color: active ? MS56_INK : MS56_INK_3,
          letterSpacing: "0.06em", textTransform: "uppercase", cursor: "pointer",
        },
      }, t.label);
    })
  );

  /* Wave 8F — transitions panel (machine + entity filter, table, click → entity). */
  const transitionsPanel = React.createElement(React.Fragment, null,
    React.createElement(_MSCard, { style: { marginBottom: 12 } },
      React.createElement("div", { style: { display: "flex", flexWrap: "wrap", alignItems: "center", gap: 12 } },
        React.createElement("span", { style: { fontFamily: MS56_FONT_MONO, fontSize: 12, color: MS56_INK_3, letterSpacing: "0.10em", textTransform: "uppercase" } }, "Machine"),
        React.createElement("select", {
          value: fsmMachine, onChange: function(e){ setFsmMachine(e.target.value); },
          style: { height: 26, padding: "0 8px", fontFamily: MS56_FONT_MONO, fontSize: 12, border: "1px solid " + MS56_LINE, borderRadius: 4, background: MS56_BG, color: MS56_INK },
        }, ["all", "eco", "traveler", "wo"].map(function(m){ return React.createElement("option", { key: m, value: m }, m); })),
        React.createElement("span", { style: { fontFamily: MS56_FONT_MONO, fontSize: 12, color: MS56_INK_3, letterSpacing: "0.10em", textTransform: "uppercase" } }, "Entity"),
        React.createElement("input", {
          type: "text", value: fsmEntity,
          onChange: function(e){ setFsmEntity(e.target.value); },
          placeholder: "ECO-MS-0017",
          style: { height: 26, padding: "0 8px", fontFamily: MS56_FONT_MONO, fontSize: 12, border: "1px solid " + MS56_LINE, borderRadius: 4, background: MS56_BG, color: MS56_INK, width: 160 },
        }),
        React.createElement("span", { style: { fontFamily: MS56_FONT_MONO, fontSize: 12, color: MS56_INK_3, letterSpacing: "0.10em", textTransform: "uppercase" } }, "Limit"),
        React.createElement("select", {
          value: fsmLimit, onChange: function(e){ setFsmLimit(parseInt(e.target.value, 10) || 50); },
          style: { height: 26, padding: "0 8px", fontFamily: MS56_FONT_MONO, fontSize: 12, border: "1px solid " + MS56_LINE, borderRadius: 4, background: MS56_BG, color: MS56_INK },
        }, [10, 50, 100, 200, 500].map(function(n){ return React.createElement("option", { key: n, value: n }, n); })),
        React.createElement("span", { style: { marginLeft: "auto", fontFamily: MS56_FONT_MONO, fontSize: 12, color: MS56_INK_2 } },
          fsmLoading ? "loading…" : (fsmRows.length + " row" + (fsmRows.length === 1 ? "" : "s"))),
        React.createElement(_MSBtn, { variant: "ghost", small: true, onClick: loadFsmRows }, "Refresh")
      )
    ),
    fsmErr ? React.createElement(_MSCard, { style: { borderColor: MS56_ACCENT_BAD, padding: 14, color: MS56_ACCENT_BAD, marginBottom: 12 } }, "fsm-transitions error: " + fsmErr) : null,
    React.createElement(_MSCard, { pad: 0, style: { padding: 0 } },
      React.createElement("table", { style: { width: "100%", borderCollapse: "collapse", fontFamily: MS56_FONT_MONO, fontSize: 12 } },
        React.createElement("thead", null,
          React.createElement("tr", { style: { background: MS56_BG_2 } },
            ["entity_id", "machine", "verb", "from → to", "actor", "role", "ts"].map(function(h){
              return React.createElement("th", {
                key: h,
                style: { textAlign: "left", padding: "8px 12px", color: MS56_INK_3, letterSpacing: "0.06em", textTransform: "uppercase", borderBottom: "1px solid " + MS56_LINE_SOFT },
              }, h);
            })
          )
        ),
        React.createElement("tbody", null,
          (fsmRows.length === 0 && !fsmLoading) ? React.createElement("tr", null,
            React.createElement("td", { colSpan: 7, style: { padding: 24, textAlign: "center", color: MS56_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); }
            function onRow() {
              if (!r.entity_id) return;
              const target = "/build/" + (r.machine || "eco") + "/" + r.entity_id;
              if (typeof navigate === "function") { navigate(target); return; }
              if (typeof window !== "undefined") { window.location.hash = target; }
            }
            return React.createElement("tr", {
              key: r.id, onClick: onRow,
              style: { borderBottom: "1px solid " + MS56_LINE_SOFT, cursor: r.entity_id ? "pointer" : "default" },
            },
              React.createElement("td", { style: { padding: "8px 12px", color: MS56_INK } }, r.entity_id || "—"),
              React.createElement("td", { style: { padding: "8px 12px", color: MS56_INK_3 } }, r.machine || "—"),
              React.createElement("td", { style: { padding: "8px 12px", color: verbColor(r.verb), fontWeight: 600 } }, r.verb || "—"),
              React.createElement("td", { style: { padding: "8px 12px", color: MS56_INK_2 } },
                React.createElement("span", { style: { color: MS56_INK_3 } }, r.from_state || "—"),
                React.createElement("span", { style: { color: MS56_INK_4 } }, " → "),
                React.createElement("span", { style: { color: MS56_INK } }, r.to_state || "—")
              ),
              React.createElement("td", { style: { padding: "8px 12px", color: MS56_INK_2 } }, r.actor_id || "—"),
              React.createElement("td", { style: { padding: "8px 12px", color: MS56_INK_3 } }, r.actor_role || "—"),
              React.createElement("td", { style: { padding: "8px 12px", color: MS56_INK_4 } }, iso)
            );
          })
        )
      )
    )
  );

  /* Wave 8F — original Events panel, unchanged behavior. */
  const eventsPanel = React.createElement(React.Fragment, null,
    React.createElement(_MSToolbar, {
      left: [
        React.createElement("span", { key: "ml", style: { fontSize: 12, color: MS56_INK_3, fontFamily: MS56_FONT_MONO, letterSpacing: "0.08em", textTransform: "uppercase" } }, "Mode"),
        React.createElement("div", { key: "mb", style: { display: "flex", gap: 4 } },
          modes.map(function(m){
            return React.createElement(_MSBtn, { key: m, variant: filterMode === m ? "primary" : "ghost", small: true, onClick: function(){ setFilterMode(m); } }, m);
          })
        ),
        React.createElement("span", { key: "al", style: { fontSize: 12, color: MS56_INK_3, fontFamily: MS56_FONT_MONO, letterSpacing: "0.08em", textTransform: "uppercase", marginLeft: 12 } }, "Actor"),
        React.createElement("select", {
          key: "as", value: filterActor,
          onChange: function(e){ setFilterActor(e.target.value); },
          style: { padding: "4px 8px", border: "1px solid " + MS56_LINE, borderRadius: 4, fontFamily: MS56_FONT_UI, fontSize: 12, background: MS56_BG, color: MS56_INK }
        }, actors.map(function(a){ return React.createElement("option", { key: a, value: a }, a); })),
      ],
      right: [
        React.createElement("input", {
          key: "se", type: "search", placeholder: "search hash / part / WO",
          value: searchQ, onChange: function(e){ setSearchQ(e.target.value); },
          style: { padding: "5px 10px", border: "1px solid " + MS56_LINE, borderRadius: 4, fontFamily: MS56_FONT_MONO, fontSize: 12, background: MS56_BG, color: MS56_INK, width: 220 }
        }),
        // W15B — real ledger exports. Wires the previously toast-only "Export"
        // button to GET /api/:tenant/audit/export?format=csv|json and the
        // newly surfaced GET /api/:tenant/audit/export.pdf (pdfkit stream).
        React.createElement(_MSBtn, { key: "exp-csv", variant: "ghost", small: true, onClick: function(){
          if (window.forgeApi && window.forgeApi.exportAuditUrl) {
            window.location.href = window.forgeApi.exportAuditUrl("csv");
            setFlash({ kind: "info", msg: "Audit CSV download started · " + ledger.length + " events flattened" });
          }
        } }, "Export CSV"),
        React.createElement(_MSBtn, { key: "exp-json", variant: "ghost", small: true, onClick: function(){
          if (window.forgeApi && window.forgeApi.exportAuditUrl) {
            window.location.href = window.forgeApi.exportAuditUrl("json");
            setFlash({ kind: "info", msg: "Audit JSON download started · " + ledger.length + " events + transitions + FCP envelopes" });
          }
        } }, "Export JSON"),
        React.createElement(_MSBtn, { key: "exp-pdf", variant: "primary", small: true, onClick: function(){
          if (window.forgeApi && window.forgeApi.exportAuditUrl) {
            window.location.href = window.forgeApi.exportAuditUrl("pdf");
            setFlash({ kind: "ok", msg: "Audit PDF download started · " + ledger.length + " events + transitions + FCP envelopes" });
          }
        } }, "Export PDF"),
      ],
    }),
    React.createElement("div", { style: { height: 12 } }),

    React.createElement("div", { style: { display: "grid", gridTemplateColumns: selected ? "1fr 360px" : "1fr", gap: 16 } },
      React.createElement(_MSCard, { pad: 0, style: { padding: 0 } },
        React.createElement("table", { style: { width: "100%", borderCollapse: "collapse", fontSize: 12 } },
          React.createElement("thead", null, React.createElement("tr", { style: { background: MS56_BG_2 } },
            ["#", "Timestamp", "Event", "Mode", "Actor", "WO / Ref", "Part", "Hash"].map(function(h, i){
              return React.createElement("th", { key: i, style: { textAlign: "left", padding: "8px 12px", fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.08em", textTransform: "uppercase", color: MS56_INK_3, borderBottom: "1px solid " + MS56_LINE_SOFT } }, h);
            })
          )),
          React.createElement("tbody", null, filtered.map(function(r){
            const isSel = selected && selected.i === r.i;
            return React.createElement("tr", {
              key: r.i,
              onClick: function(){ setSelected(r); },
              style: { borderBottom: "1px solid " + MS56_LINE_SOFT, cursor: "pointer", background: isSel ? MS56_BG_2 : "transparent" }
            },
              React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 12px", fontSize: 12, color: MS56_INK_4 }) }, String(r.i).padStart(2, "0")),
              React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 12px", fontSize: 12, color: MS56_INK_2 }) }, r.ts),
              React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 12px", fontSize: 12, color: MS56_INK }) }, r.event),
              React.createElement("td", { style: { padding: "8px 12px" } },
                React.createElement("span", { style: { display: "inline-block", padding: "2px 6px", border: "1px solid " + (modeColor[r.mode] || MS56_LINE), color: modeColor[r.mode] || MS56_INK_3, borderRadius: 2, fontFamily: MS56_FONT_MONO, fontSize: 12, letterSpacing: "0.08em", textTransform: "uppercase" } }, r.mode)
              ),
              React.createElement("td", { style: { padding: "8px 12px", color: MS56_INK_2 } }, r.actor),
              React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 12px", fontSize: 12, color: MS56_INFO }) }, r.wo),
              React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 12px", fontSize: 12, color: MS56_INK_3 }) }, r.part),
              React.createElement("td", { style: Object.assign({}, MS56_MONO, { padding: "8px 12px", fontSize: 12, color: MS56_INK_4 }) }, r.hash)
            );
          }))
        )
      ),
      selected ? React.createElement(_MSCard, null,
        React.createElement("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 10 } },
          React.createElement("div", { style: Object.assign({}, MS56_MONO, { fontSize: 12, letterSpacing: "0.10em", textTransform: "uppercase", color: MS56_INK_3 }) }, "Receipt detail"),
          React.createElement("button", { onClick: function(){ setSelected(null); }, style: { background: "transparent", border: 0, cursor: "pointer", color: MS56_INK_3, fontSize: 16 } }, "×")
        ),
        React.createElement("div", { style: Object.assign({}, MS56_MONO, { fontSize: 13, color: MS56_INK, marginBottom: 8 }) }, selected.event),
        React.createElement("div", { style: { display: "grid", gridTemplateColumns: "100px 1fr", gap: 6, fontSize: 12 } },
          React.createElement("div", { style: { color: MS56_INK_4 } }, "Index"),    React.createElement("div", { style: MS56_MONO }, String(selected.i).padStart(2, "0")),
          React.createElement("div", { style: { color: MS56_INK_4 } }, "Timestamp"),React.createElement("div", { style: MS56_MONO }, selected.ts),
          React.createElement("div", { style: { color: MS56_INK_4 } }, "Mode"),     React.createElement("div", null, selected.mode),
          React.createElement("div", { style: { color: MS56_INK_4 } }, "Actor"),    React.createElement("div", null, selected.actor),
          React.createElement("div", { style: { color: MS56_INK_4 } }, "WO / Ref"), React.createElement("div", { style: MS56_MONO }, selected.wo),
          React.createElement("div", { style: { color: MS56_INK_4 } }, "Part"),     React.createElement("div", { style: MS56_MONO }, selected.part)
        ),
        React.createElement("div", { style: { marginTop: 12, padding: 10, background: MS56_BG_3, border: "1px solid " + MS56_LINE_SOFT, borderRadius: 4 } },
          React.createElement("div", { style: Object.assign({}, MS56_MONO, { fontSize: 12, letterSpacing: "0.08em", textTransform: "uppercase", color: MS56_INK_4, marginBottom: 4 }) }, "Hash"),
          React.createElement("div", { style: Object.assign({}, MS56_MONO, { fontSize: 12, color: MS56_INK, wordBreak: "break-all" }) }, selected.hash),
          React.createElement("div", { style: Object.assign({}, MS56_MONO, { fontSize: 12, letterSpacing: "0.08em", textTransform: "uppercase", color: MS56_INK_4, marginBottom: 4, marginTop: 8 }) }, "Prev hash"),
          React.createElement("div", { style: Object.assign({}, MS56_MONO, { fontSize: 12, color: MS56_INK_3, wordBreak: "break-all" }) }, selected.prev || "—")
        ),
        React.createElement("div", { style: { marginTop: 12, display: "flex", gap: 8 } },
          React.createElement(_MSBtn, { variant: "ghost", small: true, onClick: function(){ setFlash({ kind: "ok", msg: "Hash chain verified - link " + selected.i + " of 22" }); } }, "Verify chain"),
          React.createElement(_MSBtn, { variant: "info", small: true, onClick: function(){ setFlash({ kind: "info", msg: "Receipt " + selected.event + " copied to clipboard" }); } }, "Copy receipt")
        )
      ) : null
    )
  );

  return React.createElement("div", { style: { padding: "16px 20px 80px", maxWidth: 1320, margin: "0 auto", fontFamily: MS56_FONT_UI, color: MS56_INK } },
    React.createElement(_MSSectionTitle, { kicker: "Auditor / Ledger" }, "Signed ledger · 22 events · hash-chained"),
    React.createElement(_MSStatRow, { items: [
      { label: "Total events", value: ledger.length },
      { label: "First",        value: "2025-09-08" },
      { label: "Last",         value: "2026-08-14" },
      { label: "Hash algo",    value: "SHA-256" },
      { label: "Chain",        value: "intact",   tone: "ok" },
      { label: "Closed",       value: "yes",      tone: "ok" },
    ] }),
    React.createElement("div", { style: { height: 16 } }),
    tabBar,
    tab === "transitions" ? transitionsPanel : eventsPanel,
    React.createElement(_MSFlash, { kind: flash && flash.kind, msg: flash && flash.msg, onClose: function(){ setFlash(null); } })
  );
}

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

(function _ms56_register() {
  const routes = [
    { path: "/traveler/report",     mode: "traveler", title: "Test report",       renderer: function(){ return React.createElement(ScreenMittelstandTestReport); } },
    { path: "/build/compliance",    mode: "build",    title: "Compliance",         renderer: function(){ return React.createElement(ScreenMittelstandCompliance); } },
    { path: "/line/dispatch",       mode: "line",     title: "Pack & ship",        renderer: function(){ return React.createElement(ScreenMittelstandDispatch); } },
    { path: "/forge/acceptance",    mode: "forge",    title: "Customer acceptance",renderer: function(){ return React.createElement(ScreenMittelstandAcceptance); } },
    { path: "/forge/field-issues",  mode: "forge",    title: "Field issues",       renderer: function(){ return React.createElement(ScreenMittelstandFieldIssues); } },
    { path: "/forge/aftermarket",   mode: "forge",    title: "Aftermarket",        renderer: function(){ return React.createElement(ScreenMittelstandAftermarket); } },
    { path: "/auditor/ledger",      mode: "auditor",  title: "Auditor ledger",     renderer: function(){ return React.createElement(ScreenMittelstandLedger); } },
  ];
  if (typeof registerMittelstandRoute === "function") {
    routes.forEach(function(r){ registerMittelstandRoute(r); });
  } else if (typeof registerPumpRoute === "function") {
    routes.forEach(function(r){ registerPumpRoute(r); });
  } else if (typeof window !== "undefined") {
    window.__MITTELSTAND_ACT56_ROUTES = routes;
  }
})();
})();
