// SALUD · Video demostrativo 90s · Equipo crítico + repuesto limitado + demanda programada
// [ESCENARIO DEMOSTRATIVO] · [DATOS SINTÉTICOS] · [ACTIVOS GENÉRICOS]

const SaludDemo = () => {
  const [scene, setScene] = React.useState(0);
  const [playing, setPlaying] = React.useState(true);
  const scenes = [
    { d: 9,  label: 'La operación está planificada',                       cap: 'La red de salud coordina equipos, repuestos y actividades entre 6 establecimientos. Agenda operacional programada dentro del rango habitual.' },
    { d: 11, label: 'Una condición cambia',                                 cap: 'Un equipo biomédico crítico en el Centro C-05 muestra degradación. El repuesto necesario no está disponible localmente. Sensor emite alerta al CMMS.' },
    { d: 13, label: 'Una alerta no explica el impacto',                     cap: 'El SDM de Equipos Biomédicos conecta CMMS, WMS, ERP, compras, proveedores, agenda operacional y equipos alternativos entre centros.' },
    { d: 13, label: 'OMNIX identifica qué está en riesgo',                  cap: '18 actividades programadas dependen del equipo. Se identifican 2 equipos equivalentes en H-02 y H-04 · una compra pendiente · técnicos disponibles.' },
    { d: 14, label: 'Alternativas evaluadas bajo reglas operacionales',    cap: 'Reparar inmediatamente · trasladar equipo equivalente · reasignar repuesto · ajustar mantenimiento · acelerar compra · escalar excepción. Comparadas por tiempo, criticidad y costo.' },
    { d: 13, label: 'Aprobación humana · plan coordinado',                  cap: 'Ingeniería Clínica valida el plan (traslado + intervención + reprogramación parcial). OMNIX coordina las acciones en los sistemas autorizados.' },
    { d: 12, label: 'La continuidad se protege',                             cap: 'Equipo alternativo trasladado desde H-02. Mantenimiento en curso. Actividades críticas mantenidas. 3 actividades no críticas reprogramadas con notificación proactiva.' },
    { d: 5,  label: 'Log auditable · KPIs actualizados',                   cap: 'Cada señal, evaluación, aprobación y acción registrada. Trazabilidad completa para auditoría. Sistemas actualizados con misma versión del contexto.' },
  ];
  const totalMs = scenes.reduce((s, x) => s + x.d * 1000, 0);
  const [elapsed, setElapsed] = React.useState(0);
  React.useEffect(() => {
    if (!playing) return;
    const step = 100;
    const id = setInterval(() => {
      setElapsed((e) => {
        const next = e + step;
        let acc = 0, s = 0;
        for (let i = 0; i < scenes.length; i++) {
          acc += scenes[i].d * 1000;
          if (next < acc) { s = i; break; }
          s = i;
        }
        if (next >= totalMs) { setScene(0); return 0; }
        setScene(s);
        return next;
      });
    }, step);
    return () => clearInterval(id);
  }, [playing, totalMs]);
  const progress = Math.min(100, (elapsed / totalMs) * 100);
  const fmt = (ms) => { const s = Math.floor(ms / 1000); return `${Math.floor(s/60)}:${String(s%60).padStart(2, '0')}`; };

  return (
    <section id="demo" style={{ background: '#FFFFFF', paddingTop: 128, paddingBottom: 128 }}>
      <Container>
        <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 64, marginBottom: 56, alignItems: 'end' }}>
          <div>
            <Reveal><SectionMeta n="02" label="Demo · 90 segundos"/></Reveal>
            <Reveal delay={80}>
              <h2 style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 52, lineHeight: 1.03, letterSpacing: '-0.025em', margin: 0, color: '#000' }}>
                Equipo crítico, repuesto limitado y demanda programada.
              </h2>
            </Reveal>
          </div>
          <Reveal delay={140}>
            <p style={{ fontFamily: 'var(--font-body)', fontSize: 18, lineHeight: 1.55, color: '#52557A', margin: 0 }}>
              Escenario demostrativo con datos sintéticos y activos genéricos. OMNIX apoya la coordinación operacional entre ingeniería clínica, abastecimiento y operaciones · sin sustituir la evaluación profesional.
            </p>
          </Reveal>
        </div>

        <div style={{ display: 'grid', gridTemplateColumns: '1.55fr 1fr', gap: 24 }}>
          <Reveal y={0}>
            <div style={{ border: '1.5px solid #1E1F26', background: '#000', color: '#FFF', overflow: 'hidden' }}>
              <div style={{
                display: 'flex', justifyContent: 'space-between', alignItems: 'center',
                padding: '12px 20px', borderBottom: '1.5px solid #2E3140',
                fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.18em', textTransform: 'uppercase', color: '#96A3B5',
              }}>
                <span>OMNIX · HEALTHCARE DEMO · SCENE 0{scene+1}/08</span>
                <span style={{ color: '#F4024C', display: 'inline-flex', alignItems: 'center', gap: 6 }}>
                  <span style={{ width: 6, height: 6, borderRadius: 999, background: '#F4024C' }} className={playing ? 'omnix-blink' : ''}/>
                  {playing ? 'PLAYING' : 'PAUSED'}
                </span>
              </div>
              <div style={{ position: 'relative', aspectRatio: '16 / 10', background: '#0A0B10' }}>
                <SaludSceneStage scene={scene}/>
                <div style={{
                  position: 'absolute', top: 20, left: 20, padding: '8px 14px',
                  background: 'rgba(0,0,0,0.6)', backdropFilter: 'blur(8px)',
                  fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.18em', color: '#B8860B', textTransform: 'uppercase',
                }}>[SIMULATED] · [DATOS SINTÉTICOS] · [ACTIVOS GENÉRICOS]</div>
                <div style={{
                  position: 'absolute', bottom: 0, left: 0, right: 0,
                  padding: '20px 32px 24px',
                  background: 'linear-gradient(180deg, transparent, rgba(0,0,0,0.85) 40%)',
                }}>
                  <div style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 22, letterSpacing: '-0.015em', color: '#FFF', marginBottom: 8, lineHeight: 1.15 }}>{scenes[scene].label}</div>
                  <div style={{ fontFamily: 'var(--font-body)', fontSize: 13, color: '#96A3B5', lineHeight: 1.4, maxWidth: 640 }}>{scenes[scene].cap}</div>
                </div>
              </div>
              <div style={{ borderTop: '1.5px solid #2E3140', padding: '14px 20px', display: 'flex', alignItems: 'center', gap: 16 }}>
                <button onClick={() => setPlaying(!playing)} style={sdCtrl} aria-label={playing ? 'Pausar demo' : 'Reproducir demo'}>
                  <i data-lucide={playing ? 'pause' : 'play'} width="14" height="14"></i>
                </button>
                <button onClick={() => { setElapsed(0); setScene(0); }} style={sdCtrl} aria-label="Reiniciar demo">
                  <i data-lucide="rotate-ccw" width="14" height="14"></i>
                </button>
                <div style={{ flex: 1, height: 4, background: '#2E3140', position: 'relative' }}>
                  <div style={{ position: 'absolute', inset: 0, right: 'auto', width: `${progress}%`, background: '#F4024C', transition: 'width 100ms linear' }}/>
                </div>
                <span style={{ fontFamily: 'var(--font-mono)', fontSize: 11, color: '#96A3B5', minWidth: 68, textAlign: 'right' }}>
                  {fmt(elapsed)} / {fmt(totalMs)}
                </span>
                <button style={sdCtrl} aria-label="Silenciar"><i data-lucide="volume-x" width="14" height="14"></i></button>
                <button style={sdCtrl} aria-label="Subtítulos"><i data-lucide="captions" width="14" height="14"></i></button>
              </div>
              <div style={{ borderTop: '1.5px solid #2E3140', display: 'grid', gridTemplateColumns: `repeat(${scenes.length}, 1fr)` }}>
                {scenes.map((s, i) => (
                  <button key={i} onClick={() => {
                    const before = scenes.slice(0, i).reduce((a, x) => a + x.d * 1000, 0);
                    setElapsed(before); setScene(i);
                  }} style={{
                    padding: '10px 8px', border: 'none',
                    background: scene === i ? '#F4024C' : '#0A0B10',
                    color: scene === i ? '#FFF' : '#52557A',
                    borderRight: (i < scenes.length - 1) ? '1px solid #2E3140' : 'none',
                    fontFamily: 'var(--font-mono)', fontSize: 9, letterSpacing: '0.14em', textTransform: 'uppercase',
                    cursor: 'pointer',
                  }} aria-label={`Ir a escena ${i+1}`}>{i+1}</button>
                ))}
              </div>
            </div>
          </Reveal>

          {/* Panel explicación · 6 tarjetas */}
          <Reveal delay={100} y={0}>
            <div style={{ border: '1.5px solid #1E1F26', background: '#FAFBFD', padding: 32, height: '100%', display: 'flex', flexDirection: 'column' }}>
              <div style={{ fontFamily: 'var(--font-mono)', fontSize: 11, letterSpacing: '0.18em', color: '#F4024C', textTransform: 'uppercase', marginBottom: 12 }}>
                Qué está haciendo OMNIX
              </div>
              <p style={{ fontFamily: 'var(--font-body)', fontSize: 14, lineHeight: 1.55, color: '#1E1F26', margin: '0 0 20px' }}>
                Convierte una restricción operacional aislada en una decisión coordinada de red · con evidencia trazable · aprobación humana en decisiones críticas · rollback armado.
              </p>
              <div style={{ display: 'flex', flexDirection: 'column', gap: 8, flex: 1 }}>
                {[
                  { t: 'Condición detectada',        d: 'CMMS + sensor · degradación fuera de rango.',                            sys: 'CMMS · IoT',      auto: 'N1' },
                  { t: 'Impacto contextualizado',    d: 'Cruce con agenda operacional · equipos alternativos · técnicos.',       sys: 'Bed mgmt · OR',   auto: 'N2' },
                  { t: 'Recursos identificados',      d: 'Repuestos · técnicos · equipos equivalentes · red de centros.',         sys: 'WMS · EAM',        auto: 'N2' },
                  { t: 'Alternativas evaluadas',      d: 'Reparar · trasladar · reasignar · reprogramar · comprar · escalar.',    sys: 'CORTEX',            auto: 'N3' },
                  { t: 'Respuesta coordinada',        d: 'Ejecución cross-sistema con approval de Ingeniería Clínica.',           sys: 'RUNTIME',            auto: 'N3-N4' },
                  { t: 'Resultado auditado',          d: 'Log firmado · KPI actualizados · learning al SDM.',                      sys: 'GOV · BI',         auto: '—' },
                ].map((c, i) => (
                  <div key={c.t} style={{
                    padding: '12px 14px', background: '#FFF',
                    border: '1px solid',
                    borderColor: scene >= i ? '#F4024C' : '#E4EBF3',
                    transition: 'border-color 320ms',
                    display: 'grid', gridTemplateColumns: '22px 1fr 60px', gap: 10, alignItems: 'start',
                  }}>
                    <span style={{ fontFamily: 'var(--font-mono)', fontSize: 10, color: scene >= i ? '#F4024C' : '#96A3B5' }}>0{i+1}</span>
                    <div>
                      <div style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 13, letterSpacing: '-0.005em', color: '#000', marginBottom: 3 }}>{c.t}</div>
                      <div style={{ fontFamily: 'var(--font-body)', fontSize: 12, color: '#52557A', lineHeight: 1.4 }}>{c.d}</div>
                      <div style={{ marginTop: 3, fontFamily: 'var(--font-mono)', fontSize: 9, letterSpacing: '0.14em', color: '#0050BD' }}>SYS · {c.sys}</div>
                    </div>
                    <div style={{ fontFamily: 'var(--font-mono)', fontSize: 9, letterSpacing: '0.14em', color: '#1E1F26', textAlign: 'right', paddingTop: 4 }}>{c.auto}</div>
                  </div>
                ))}
              </div>
              <div style={{ marginTop: 14, padding: '10px 12px', background: '#FBF3D9', border: '1px solid #B8860B', fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.06em', color: '#1E1F26', lineHeight: 1.55 }}>
                Escenario demostrativo. OMNIX apoya decisiones operacionales · no sustituye la evaluación clínica, técnica o de seguridad realizada por profesionales autorizados.
              </div>
            </div>
          </Reveal>
        </div>

        {/* Transcripción accesible */}
        <Reveal delay={200}>
          <details style={{ marginTop: 32, padding: '20px 24px', border: '1px solid #E4EBF3', background: '#FAFBFD' }}>
            <summary style={{ fontFamily: 'var(--font-mono)', fontSize: 11, letterSpacing: '0.18em', color: '#F4024C', textTransform: 'uppercase', cursor: 'pointer' }}>
              Transcripción del video
            </summary>
            <div style={{ marginTop: 16, fontFamily: 'var(--font-body)', fontSize: 14, lineHeight: 1.7, color: '#1E1F26' }}>
              {scenes.map((s, i) => (
                <p key={i} style={{ margin: '0 0 10px' }}>
                  <strong>Escena {i+1} · {fmt(scenes.slice(0, i).reduce((a, x) => a + x.d * 1000, 0))} — {s.label}.</strong> {s.cap}
                </p>
              ))}
              <p style={{ margin: '16px 0 0', fontStyle: 'italic', color: '#52557A' }}>
                [ESCENARIO DEMOSTRATIVO] · [DATOS SINTÉTICOS] · [ACTIVOS GENÉRICOS]. Sin uso de datos reales de pacientes ni identificación de instituciones. OMNIX apoya decisiones operacionales · no sustituye la evaluación clínica, técnica o de seguridad realizada por profesionales autorizados.
              </p>
            </div>
          </details>
        </Reveal>
      </Container>
    </section>
  );
};

const sdCtrl = {
  width: 32, height: 32, border: '1px solid #2E3140', background: '#0A0B10',
  color: '#FFF', cursor: 'pointer', display: 'flex', alignItems: 'center', justifyContent: 'center',
};

const SaludSceneStage = ({ scene }) => (
  <div style={{ position: 'absolute', inset: 0 }}>
    {scene === 0 && <SdScene0/>}
    {scene === 1 && <SdScene1/>}
    {scene === 2 && <SdScene2/>}
    {scene === 3 && <SdScene3/>}
    {scene === 4 && <SdScene4/>}
    {scene === 5 && <SdScene5/>}
    {scene === 6 && <SdScene6/>}
    {scene === 7 && <SdScene7/>}
  </div>
);

const SdGrid = () => (
  <g stroke="#2E3140" strokeWidth="0.5" opacity="0.4">
    {Array.from({length: 17}).map((_, i) => <line key={`v${i}`} x1={i*50} y1="0" x2={i*50} y2="500"/>)}
    {Array.from({length: 11}).map((_, i) => <line key={`h${i}`} x1="0" y1={i*50} x2="800" y2={i*50}/>)}
  </g>
);

const SdScene0 = () => (
  <svg viewBox="0 0 800 500" style={{ width: '100%', height: '100%' }}>
    <SdGrid/>
    <text x="80" y="60" fontFamily="var(--font-mono)" fontSize="11" letterSpacing="0.18em" fill="#96A3B5">RED SANITARIA · 6 CENTROS · OPERACIÓN PROGRAMADA</text>
    {[
      { x: 140, y: 200, k: 'H-01' },
      { x: 320, y: 160, k: 'H-02' },
      { x: 500, y: 200, k: 'H-03' },
      { x: 660, y: 240, k: 'H-04' },
      { x: 240, y: 340, k: 'C-05' },
      { x: 460, y: 340, k: 'C-06' },
    ].map((n) => (
      <g key={n.k} transform={`translate(${n.x}, ${n.y})`}>
        <rect x="-40" y="-24" width="80" height="48" fill="#0A0B10" stroke="#0F5132" strokeWidth="1.5"/>
        <text y="-4" textAnchor="middle" fontFamily="var(--font-mono)" fontSize="11" fill="#FFF">{n.k}</text>
        <text y="14" textAnchor="middle" fontFamily="var(--font-mono)" fontSize="9" fill="#0F5132">nominal</text>
        <circle cx="24" cy="-14" r="3" fill="#0F5132">
          <animate attributeName="opacity" values="1;0.3;1" dur="1.6s" repeatCount="indefinite"/>
        </circle>
      </g>
    ))}
    {[[140,200,320,160],[320,160,500,200],[500,200,660,240],[140,200,240,340],[320,160,240,340],[500,200,460,340],[660,240,460,340]].map((r, i) => (
      <FlowPath key={i} d={`M ${r[0]} ${r[1]} L ${r[2]} ${r[3]}`} stroke="#96A3B5" strokeWidth={0.75} particleColor="#0050BD" particleSize={2.5} duration={2.8 + i * 0.15}/>
    ))}
    <g transform="translate(80, 430)">
      <text x="0" y="0" fontFamily="var(--font-mono)" fontSize="10" letterSpacing="0.14em" fill="#96A3B5">DISPONIBILIDAD RED</text>
      <text x="0" y="34" fontFamily="var(--font-display)" fontWeight="800" fontSize="32" fill="#0F5132" letterSpacing="-0.02em">94.2%</text>
      <text x="220" y="0" fontFamily="var(--font-mono)" fontSize="10" letterSpacing="0.14em" fill="#96A3B5">ACTIVIDADES PROG.</text>
      <text x="220" y="34" fontFamily="var(--font-mono)" fontSize="22" fill="#FFF">148</text>
      <text x="440" y="0" fontFamily="var(--font-mono)" fontSize="10" letterSpacing="0.14em" fill="#96A3B5">CMMS · WMS · ERP</text>
      <text x="440" y="34" fontFamily="var(--font-mono)" fontSize="18" fill="#FFF">conectados</text>
    </g>
  </svg>
);

const SdScene1 = () => (
  <svg viewBox="0 0 800 500" style={{ width: '100%', height: '100%' }}>
    <SdGrid/>
    <text x="80" y="60" fontFamily="var(--font-mono)" fontSize="11" letterSpacing="0.18em" fill="#EA384C">DEGRADACIÓN DETECTADA · C-05 · EQUIPO BIOMÉDICO CRÍTICO</text>
    <g transform="translate(240, 240)">
      <circle r="40" fill="none" stroke="#EA384C" strokeWidth="1.5" opacity="0.6">
        <animate attributeName="r" values="30;50;30" dur="1.4s" repeatCount="indefinite"/>
        <animate attributeName="opacity" values="0.6;0;0.6" dur="1.4s" repeatCount="indefinite"/>
      </circle>
      <rect x="-40" y="-24" width="80" height="48" fill="#0A0B10" stroke="#EA384C" strokeWidth="2"/>
      <text y="-4" textAnchor="middle" fontFamily="var(--font-mono)" fontSize="11" fill="#FFF">C-05</text>
      <text y="14" textAnchor="middle" fontFamily="var(--font-mono)" fontSize="9" fill="#EA384C">degradación</text>
    </g>
    <g transform="translate(500, 240)">
      <rect x="-100" y="-30" width="200" height="60" fill="#0A0B10" stroke="#EA384C" strokeWidth="1.5"/>
      <text x="0" y="-8" textAnchor="middle" fontFamily="var(--font-mono)" fontSize="10" letterSpacing="0.14em" fill="#EA384C">REPUESTO REQUERIDO</text>
      <text x="0" y="14" textAnchor="middle" fontFamily="var(--font-display)" fontWeight="700" fontSize="16" fill="#FFF">Sin stock local</text>
    </g>
    <g transform="translate(80, 400)">
      <rect x="0" y="0" width="640" height="70" fill="#FDE4E7" opacity="0.15" stroke="#EA384C" strokeWidth="1"/>
      <text x="20" y="26" fontFamily="var(--font-mono)" fontSize="10" letterSpacing="0.18em" fill="#EA384C">IMPACTO POTENCIAL · 18 ACTIVIDADES PROGRAMADAS DEPENDEN</text>
      <text x="20" y="52" fontFamily="var(--font-body)" fontSize="14" fill="#FFF">
        <tspan fill="#EA384C" fontWeight="700">6</tspan> críticas · <tspan fill="#B8860B" fontWeight="700">8</tspan> alta prioridad · <tspan fill="#96A3B5" fontWeight="700">4</tspan> reprogramables
      </text>
    </g>
  </svg>
);

const SdScene2 = () => (
  <svg viewBox="0 0 800 500" style={{ width: '100%', height: '100%' }}>
    <SdGrid/>
    <text x="80" y="60" fontFamily="var(--font-mono)" fontSize="11" letterSpacing="0.18em" fill="#96A3B5">SDM EQUIPOS BIOMÉDICOS · MULTI-SIGNAL CONTEXT</text>
    {['CMMS · historial', 'WMS · inventario', 'ERP · compras', 'Proveedores · lead time', 'Agenda operacional', 'Equipos equivalentes'].map((s, i) => (
      <g key={s} transform={`translate(60, ${100 + i * 46})`}>
        <rect x="0" y="-14" width="220" height="28" fill="#0A0B10" stroke="#0050BD" strokeWidth="1"/>
        <text x="12" y="4" fontFamily="var(--font-mono)" fontSize="11" fill="#FFF">{s}</text>
        <FlowPath d={`M 220 0 L 380 0 L 440 130`} stroke="#96A3B5" strokeWidth={0.5} particleColor="#F4024C" particleSize={2} duration={2.2 + i * 0.15}/>
      </g>
    ))}
    <g transform="translate(560, 250)">
      <circle r="70" fill="none" stroke="#F4024C" strokeWidth="1" opacity="0.3">
        <animate attributeName="r" values="60;76;60" dur="2.4s" repeatCount="indefinite"/>
      </circle>
      <rect x="-64" y="-44" width="128" height="88" fill="#000" stroke="#F4024C" strokeWidth="2"/>
      <text y="-12" textAnchor="middle" fontFamily="var(--font-display)" fontWeight="800" fontSize="14" fill="#FFF">SDM</text>
      <text y="8" textAnchor="middle" fontFamily="var(--font-display)" fontWeight="700" fontSize="12" fill="#F4024C">EQUIPOS</text>
      <text y="30" textAnchor="middle" fontFamily="var(--font-mono)" fontSize="9" letterSpacing="0.14em" fill="#96A3B5">v0.3-demo</text>
    </g>
  </svg>
);

const SdScene3 = () => (
  <svg viewBox="0 0 800 500" style={{ width: '100%', height: '100%' }}>
    <SdGrid/>
    <text x="80" y="60" fontFamily="var(--font-mono)" fontSize="11" letterSpacing="0.18em" fill="#96A3B5">RECURSOS IDENTIFICADOS · RED COMPLETA</text>
    <text x="80" y="90" fontFamily="var(--font-display)" fontWeight="700" fontSize="20" fill="#FFF">Alternativas disponibles · red de 6 centros</text>
    {[
      { k: 'EQUIPO EQUIVALENTE', n: '2', v: 'H-02 · H-04 · uso 60%',        c: '#0F5132' },
      { k: 'REPUESTO EN TRÁNSITO', n: '1', v: 'Proveedor · ETA 48h',          c: '#B8860B' },
      { k: 'TÉCNICOS DISPONIBLES', n: '3', v: 'Ing. clínica · turno diurno', c: '#0050BD' },
      { k: 'CONTRATO ACTIVO',       n: '1', v: 'SLA 4h · en vigencia',         c: '#0F5132' },
    ].map((r, i) => (
      <g key={r.k} transform={`translate(80, ${130 + i * 70})`}>
        <rect x="0" y="0" width="640" height="58" fill="#0A0B10" stroke={r.c} strokeWidth="1.5"/>
        <text x="20" y="22" fontFamily="var(--font-mono)" fontSize="10" letterSpacing="0.18em" fill={r.c}>{r.k}</text>
        <text x="20" y="46" fontFamily="var(--font-display)" fontWeight="800" fontSize="20" fill="#FFF">{r.n}</text>
        <text x="60" y="46" fontFamily="var(--font-body)" fontSize="13" fill="#96A3B5">{r.v}</text>
      </g>
    ))}
    <text x="80" y="470" fontFamily="var(--font-mono)" fontSize="10" letterSpacing="0.14em" fill="#F4024C">→ EVALUAR COMBINACIÓN ÓPTIMA · SIGUIENTE PASO</text>
  </svg>
);

const SdScene4 = () => {
  const options = [
    { k: 'WAIT-REPAIR', t: 'Esperar repuesto · reparar', time: 48, avail: 22, cost: 12, sel: false },
    { k: 'TRANSFER',    t: 'Trasladar equipo equivalente H-02', time: 4,  avail: 92, cost: 18, sel: true },
    { k: 'REASSIGN',    t: 'Reasignar repuesto de C-06', time: 8,  avail: 78, cost: 8,  sel: false },
    { k: 'RESCHEDULE',  t: 'Reprogramar actividades no críticas', time: 2,  avail: 68, cost: 22, sel: false },
    { k: 'EXPEDITE',    t: 'Compra urgente · SLA proveedor', time: 12, avail: 88, cost: 42, sel: false },
    { k: 'ESCALATE',    t: 'Escalar a red superior', time: 6,  avail: 82, cost: 32, sel: false },
  ];
  return (
    <svg viewBox="0 0 800 500" style={{ width: '100%', height: '100%' }}>
      <SdGrid/>
      <text x="80" y="60" fontFamily="var(--font-mono)" fontSize="11" letterSpacing="0.18em" fill="#96A3B5">DEEP THINK · ALTERNATIVAS COMPARADAS</text>
      <g transform="translate(80, 100)">
        <text x="0" y="0" fontFamily="var(--font-mono)" fontSize="10" letterSpacing="0.14em" fill="#96A3B5">ACCIÓN</text>
        <text x="370" y="0" fontFamily="var(--font-mono)" fontSize="10" letterSpacing="0.14em" fill="#B8860B">TIEMPO (h)</text>
        <text x="490" y="0" fontFamily="var(--font-mono)" fontSize="10" letterSpacing="0.14em" fill="#0F5132">DISPONIBILIDAD</text>
        <text x="620" y="0" fontFamily="var(--font-mono)" fontSize="10" letterSpacing="0.14em" fill="#EA384C">COSTO INCR.</text>
      </g>
      {options.map((o, i) => (
        <g key={o.k} transform={`translate(80, ${132 + i * 54})`}>
          {o.sel && <rect x="-8" y="-16" width="656" height="44" fill="#F4024C" opacity="0.08"/>}
          {o.sel && <rect x="-8" y="-16" width="4" height="44" fill="#F4024C"/>}
          <text x="0" y="0" fontFamily="var(--font-mono)" fontSize="10" letterSpacing="0.14em" fill={o.sel ? '#F4024C' : '#96A3B5'}>0{i+1} · {o.k}</text>
          <text x="0" y="18" fontFamily="var(--font-display)" fontWeight="700" fontSize="13" fill="#FFF">{o.t}</text>
          {[
            { x: 360, v: o.time, c: '#B8860B' },
            { x: 480, v: o.avail, c: '#0F5132' },
            { x: 610, v: o.cost, c: '#EA384C' },
          ].map((b, j) => (
            <g key={j}>
              <rect x={b.x} y="6" width="80" height="6" fill="#2E3140"/>
              <rect x={b.x} y="6" width={Math.min(80, b.v * 1.4)} height="6" fill={b.c}>
                <animate attributeName="width" from="0" to={Math.min(80, b.v * 1.4)} dur="0.9s" begin={`${i * 0.1}s`} fill="freeze"/>
              </rect>
              <text x={b.x} y="26" fontFamily="var(--font-mono)" fontSize="10" fill={b.c}>{b.v}{j===0?'h':'%'}</text>
            </g>
          ))}
          {o.sel && <text x="660" y="0" textAnchor="end" fontFamily="var(--font-mono)" fontSize="10" fill="#F4024C">SELECTED</text>}
        </g>
      ))}
      <text x="80" y="470" fontFamily="var(--font-mono)" fontSize="10" letterSpacing="0.14em" fill="#B8860B">
        REQUIERE APROBACIÓN · INGENIERÍA CLÍNICA · CRUCE OPERACIONAL VALIDADO
      </text>
    </svg>
  );
};

const SdScene5 = () => (
  <svg viewBox="0 0 800 500" style={{ width: '100%', height: '100%' }}>
    <SdGrid/>
    <text x="80" y="60" fontFamily="var(--font-mono)" fontSize="11" letterSpacing="0.18em" fill="#96A3B5">APPROVAL FLOW · CADENA DE RESPONSABILIDAD</text>
    {[
      { r: 'ANÁLISIS TÉCNICO',            s: '✓ Ingeniería Clínica · alternativa TRANSFER validada', t: '10:12' },
      { r: 'VALIDACIÓN LOGÍSTICA',         s: '✓ Abastecimiento · disponibilidad H-02 confirmada', t: '10:18' },
      { r: 'COORDINACIÓN OPERACIONAL',      s: '✓ Operaciones · 4 actividades a reprogramar identificadas', t: '10:24' },
      { r: 'AUTORIZACIÓN RESPONSABLE',      s: '✓ Director Ing. Clínica · dentro de umbral · acción no clínica', t: '10:31' },
    ].map((n, i) => (
      <g key={n.r} transform={`translate(80, ${110 + i * 78})`}>
        <rect x="0" y="0" width="640" height="60" fill="#0A0B10" stroke="#0F5132" strokeWidth="1.5"/>
        <text x="20" y="24" fontFamily="var(--font-mono)" fontSize="10" letterSpacing="0.14em" fill="#0F5132">{n.r}</text>
        <text x="20" y="46" fontFamily="var(--font-body)" fontSize="13" fill="#FFF">{n.s}</text>
        <text x="620" y="34" textAnchor="end" fontFamily="var(--font-mono)" fontSize="11" fill="#96A3B5">{n.t}</text>
      </g>
    ))}
    <text x="80" y="450" fontFamily="var(--font-mono)" fontSize="10" letterSpacing="0.14em" fill="#0050BD">
      ✓ CADENA COMPLETA · 4 ROLES · TRACE #HC-a4c2 · signed WORM
    </text>
  </svg>
);

const SdScene6 = () => (
  <svg viewBox="0 0 800 500" style={{ width: '100%', height: '100%' }}>
    <SdGrid/>
    <text x="80" y="60" fontFamily="var(--font-mono)" fontSize="11" letterSpacing="0.18em" fill="#96A3B5">EJECUCIÓN COORDINADA · SISTEMAS ACTUALIZADOS</text>
    <g transform="translate(400, 250)">
      <circle r="52" fill="none" stroke="#F4024C" strokeWidth="1" opacity="0.4">
        <animate attributeName="r" values="44;58;44" dur="1.6s" repeatCount="indefinite"/>
      </circle>
      <rect x="-44" y="-44" width="88" height="88" fill="#F4024C" stroke="#F4024C" strokeWidth="2"/>
      <text y="-6" textAnchor="middle" fontFamily="var(--font-display)" fontWeight="800" fontSize="14" fill="#FFF">OMNIX</text>
      <text y="16" textAnchor="middle" fontFamily="var(--font-mono)" fontSize="10" fill="#FFF">RUNTIME</text>
    </g>
    {[
      { s: 'EAM',    a: 'traslado equipo H-02 → C-05',      x: 130, y: 130 },
      { s: 'CMMS',   a: 'orden mantenimiento priorizada',   x: 670, y: 130 },
      { s: 'WMS',     a: 'reserva repuesto llegando 48h',   x: 130, y: 380 },
      { s: 'AGENDA',  a: 'reprograma 4 no críticas',        x: 670, y: 380 },
    ].map((s) => (
      <g key={s.s}>
        <FlowPath d={`M 400 250 L ${s.x} ${s.y}`} stroke="#F4024C" strokeWidth={1.5} particleColor="#F4024C" particleSize={4} duration={1.4} pulseWidth/>
        <g transform={`translate(${s.x}, ${s.y})`}>
          <rect x="-88" y="-24" width="176" height="48" fill="#0A0B10" stroke="#0F5132" strokeWidth="1.5"/>
          <text x="-74" y="-4" fontFamily="var(--font-display)" fontWeight="800" fontSize="14" fill="#FFF">{s.s}</text>
          <text x="-74" y="14" fontFamily="var(--font-mono)" fontSize="9" fill="#0F5132">✓ {s.a}</text>
        </g>
      </g>
    ))}
    <text x="80" y="480" fontFamily="var(--font-mono)" fontSize="10" letterSpacing="0.14em" fill="#0F5132">
      ✓ TX #HC-a4c2 · 4 sistemas · 240ms · signed WORM · reversible
    </text>
  </svg>
);

const SdScene7 = () => (
  <svg viewBox="0 0 800 500" style={{ width: '100%', height: '100%' }}>
    <SdGrid/>
    <text x="80" y="60" fontFamily="var(--font-mono)" fontSize="11" letterSpacing="0.18em" fill="#96A3B5">DECISION TRACE · AUDITORÍA COMPLETA</text>
    <g transform="translate(80, 100)">
      <rect x="0" y="0" width="680" height="360" fill="#0A0B10" stroke="#F4024C" strokeWidth="1.5"/>
      <text x="20" y="30" fontFamily="var(--font-mono)" fontSize="10" letterSpacing="0.18em" fill="#F4024C">TRACE · #HC-a4c2 · signed WORM · retention según jurisdicción</text>
      {[
        'timestamp:  2026-11-14 10:12:32.104 local',
        'facility:    C-05 (anonimizado en publicación)',
        'sdm:         sdm.biomedical-equipment-v0.3',
        'signals:     CMMS · sensor · WMS · ERP · agenda · red',
        'impact:      18 activities @ risk · 6 critical',
        'options:     6 evaluated · policy-scored',
        'selected:    option 02 · TRANSFER · time 4h · avail 92% · cost 18%',
        'approval:    ingeniería clínica · dentro de umbral · acción no clínica',
        'systems:     EAM · CMMS · WMS · Agenda',
        'result:      equipo equivalente trasladado · 4 no críticas reprogramadas',
        'reversible:  yes · ventana 24h',
        'evidence:    signed WORM · datos sintéticos en demo',
      ].map((line, i) => (
        <text key={i} x="20" y={60 + i * 24} fontFamily="var(--font-mono)" fontSize="11" fill="#FFF">
          <tspan fill="#52557A">{`0${i+1}  `}</tspan>{line}
        </text>
      ))}
    </g>
  </svg>
);

Object.assign(window, { SaludDemo });
