// === CASO REAL · 50 empleados (13s) — su app delante, Dinaup detrás, cambios por chat ===
// Izquierda: la app del cliente ("PORTAL", paleta violeta) con su listado de pedidos.
// Beat 2: la app se eleva y debajo asoma la capa "Backend: Dinaup" (datos · usuarios ·
// permisos · API). Derecha: una app de CHAT de código (burbujas, no terminal): el junior
// teclea EN LA CASILLA "Añade un filtro por estado en pedidos", envía, el asistente
// resume el cambio (chips "3 archivos · build OK") y el filtro APARECE en la app de la
// izquierda con un pulso. Banda final: "Lo que construyes hoy son las bases de mañana."

function SlideBackend({ t }){
  // --- timeline (sincronizada con cues slide_backend) ---
  // cue1 0.5-3.0   'Esta es su app: su marca, su diseño'
  // cue2 3.0-5.8   'Detrás, todo el backend es Dinaup'
  // cue3 5.8-8.8   'El junior pide los cambios a la IA, en un chat'
  // cue4 8.8-11.0  'Y la app crece: sin base de datos propia'
  // cue5 11.0-12.7 'Lo que construyes hoy son las bases de mañana'
  const winLeftAt  = 0.8;    // entra la ventana PORTAL (centrada: es la protagonista)
  const rowsAt     = 1.4;    // filas de pedidos en cascada
  const brandAt    = 2.2;    // pulso en el logo PORTAL (cue "su marca")
  const liftAt     = 3.15;   // la app se eleva…
  const layerAt    = 3.35;   // …y asoma la capa backend
  const chipsAt    = 3.9;    // chips datos · usuarios · permisos · API
  const moveAt     = 4.9;    // la app se desliza a la izquierda: hace sitio al chat
  const winChatAt  = 5.5;    // entra la app de chat de código
  const typeAt     = 6.15;   // el junior teclea EN LA CASILLA
  const sendAt     = 7.7;    // envía: la casilla se vacía
  const userMsgAt  = 7.83;   // y ENTONCES aparece su burbuja
  const steps = [            // el asistente trabaja (estilo Claude Code, sin código)
    { start:8.15, done:8.60, doing:'Leyendo el proyecto…',              doneTxt:'Proyecto leído' },
    { start:8.65, done:9.10, doing:'Editando src/pages/Pedidos.jsx…',   doneTxt:'src/pages/Pedidos.jsx · listo' },
  ];
  const answerAt   = 9.2;    // burbuja del asistente (resumen, 2 líneas)
  const aiChipsAt  = 9.90;   // chips "3 archivos" · "build OK"
  const pingAt     = 9.95;   // pulso que viaja del chat a la app
  const filtroAt   = 10.25;  // el filtro nuevo aparece en PORTAL (cue "la app crece")
  const datosGlowAt= 10.55;  // la capa "datos" respira: sin base de datos propia
  const bandAt     = 11.2;   // banda final (muere ≥0.8s antes del dur)

  const promptTxt = 'Añade un filtro por estado en pedidos';

  const pedidos = [
    { num:'PED-2041', cliente:'Talleres Ruiz S.L.', ciudad:'Getafe',  importe:'1.240,00 €', estado:'En preparación',    fg:'#B45309', bg:'rgba(245,158,11,0.14)', br:'rgba(245,158,11,0.35)' },
    { num:'PED-2040', cliente:'Hotel Miramar',      ciudad:'Málaga',  importe:'386,50 €',   estado:'Enviado',           fg:'#6D28D9', bg:'rgba(109,40,217,0.10)', br:'rgba(109,40,217,0.30)' },
    { num:'PED-2039', cliente:'Clínica Andrade',    ciudad:'Sevilla', importe:'2.118,75 €', estado:'Pendiente de pago', fg:'#BE123C', bg:'rgba(190,18,60,0.10)',  br:'rgba(190,18,60,0.30)'  },
  ];

  // Entradas
  const badgeP = clamp((t-0.2)/0.5, 0, 1);
  const badgeE = Easing.easeOutBack(badgeP);
  const wL     = Easing.easeOutCubic(clamp((t-winLeftAt)/0.6, 0, 1));
  const liftE  = Easing.easeInOutCubic(clamp((t-liftAt)/0.7, 0, 1));
  const moveE  = Easing.easeInOutCubic(clamp((t-moveAt)/0.7, 0, 1));
  const shiftX = lerp(480, 0, moveE); // 480 = centrado (560-80); 0 = posición final izquierda
  const wChat  = Easing.easeOutCubic(clamp((t-winChatAt)/0.6, 0, 1));
  const bandE  = Easing.easeOutCubic(clamp((t-bandAt)/0.7, 0, 1));

  // Foco por ventana mientras el caption habla de ella
  const glowPortal = animate({from:0,to:1,start:0.7,end:1.1,ease:Easing.easeOutCubic,t})   * animate({from:1,to:0,start:3.0,end:3.4,ease:Easing.easeInOutQuad,t})
                   + animate({from:0,to:1,start:10.2,end:10.6,ease:Easing.easeOutCubic,t}) * animate({from:1,to:0,start:11.6,end:12.0,ease:Easing.easeInOutQuad,t});
  const glowChat   = animate({from:0,to:1,start:5.9,end:6.3,ease:Easing.easeOutCubic,t})   * animate({from:1,to:0,start:9.6,end:10.0,ease:Easing.easeInOutQuad,t});

  const typing  = t >= typeAt && t < sendAt;      // texto en la casilla
  const pressed = t >= sendAt && t < sendAt+0.3;  // feedback del botón enviar

  // Asterisco de 8 puntas — icono del asistente de código
  const spark = (size, color='#fff') => (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none">
      <path d="M12 2.6 V21.4 M2.6 12 H21.4 M5.4 5.4 L18.6 18.6 M18.6 5.4 L5.4 18.6" stroke={color} strokeWidth="2.4" strokeLinecap="round"/>
    </svg>
  );

  const spinnerSvg = (
    <svg width="13" height="13" viewBox="0 0 24 24" fill="none" style={{transform:`rotate(${(t*340)%360}deg)`, flexShrink:0}}>
      <path d="M12 3 A9 9 0 0 1 21 12" stroke="#E0916F" strokeWidth="3.2" strokeLinecap="round"/>
    </svg>
  );

  return (
    <SlideCanvas variant="dark-deep">

      {/* Badge CASO REAL · 50 EMPLEADOS (estilo TimeBadge, sin hora) */}
      <div style={{position:'absolute', top:44, left:60, zIndex:6, display:'flex', alignItems:'center', gap:12, padding:'10px 18px 10px 14px', background:'rgba(15,23,42,0.92)', border:'1px solid rgba(255,255,255,0.10)', borderRadius:14, boxShadow:'0 12px 32px rgba(15,23,42,0.25)', backdropFilter:'blur(10px)', opacity:clamp(badgeP*1.3,0,1), transform:`translateY(${(1-badgeE)*-14}px) scale(${lerp(0.85,1,badgeE)})`}}>
        <div style={{width:34, height:34, borderRadius:10, background:'linear-gradient(135deg,#0085FF,#56E16A)', display:'flex', alignItems:'center', justifyContent:'center'}}>
          <svg width="17" height="17" viewBox="0 0 24 24" fill="none">
            <circle cx="9" cy="8" r="3.2" stroke="#fff" strokeWidth="1.8"/>
            <path d="M3.5 19 C3.5 15.5 6 13.5 9 13.5 C12 13.5 14.5 15.5 14.5 19" stroke="#fff" strokeWidth="1.8" strokeLinecap="round"/>
            <circle cx="16.5" cy="9" r="2.4" stroke="#fff" strokeWidth="1.6"/>
            <path d="M16 13.2 C18.6 13.4 20.5 15.2 20.5 18" stroke="#fff" strokeWidth="1.6" strokeLinecap="round"/>
          </svg>
        </div>
        <div>
          <div className="f-mono" style={{fontSize:15, fontWeight:700, color:'#fff', lineHeight:1, letterSpacing:'0.08em'}}>CASO REAL</div>
          <div className="f-mono" style={{fontSize:9, fontWeight:600, color:'rgba(255,255,255,0.55)', letterSpacing:'2.5px', marginTop:3, textTransform:'uppercase'}}>50 empleados</div>
        </div>
      </div>

      {/* Cabecera */}
      <div style={{position:'absolute', top:40, left:0, right:0, textAlign:'center', opacity:clamp(t/0.5,0,1), zIndex:5}}>
        <div className="f-plex" style={{fontSize:14, fontWeight:600, letterSpacing:'2px', color:'#62B4FF'}}>FRONTEND PROPIO · BACKEND DINAUP</div>
        <h2 className="f-plex" style={{fontSize:42, fontWeight:700, letterSpacing:'-0.03em', margin:'14px 0 0', color:'#fff'}}>
          Su app por fuera. <span className="grad-text">Dinaup por dentro.</span>
        </h2>
      </div>

      {/* ===== IZQUIERDA — la app del cliente "PORTAL" (paleta violeta) =====
          Entra CENTRADA (beats 1-2: es la protagonista) y en moveAt se desliza
          a su posición final izquierda para hacer sitio a la app de chat. */}
      <div style={{position:'absolute', inset:0, zIndex:2, transform:`translateX(${shiftX}px)`, pointerEvents:'none'}}>
      <div style={{position:'absolute', top:186, left:80, width:800, height:508, borderRadius:12, overflow:'hidden', background:'#fff', boxShadow:`0 ${30+liftE*14}px ${80+liftE*24}px rgba(0,0,0,0.5), 0 0 ${40*glowPortal}px rgba(124,58,237,${0.5*glowPortal})`, opacity:wL, transform:`translateY(${(1-wL)*24 - liftE*12}px)`}}>
        {/* Chrome de navegador propio (no Dinaup) */}
        <div style={{height:34, background:'#241D33', display:'flex', alignItems:'flex-end', padding:'0 0 0 10px'}}>
          <div style={{height:28, minWidth:250, maxWidth:290, background:'#332A47', borderRadius:'8px 8px 0 0', display:'flex', alignItems:'center', gap:8, padding:'0 10px 0 12px', fontSize:11, color:'#E7E2F5', marginBottom:0}}>
            <div style={{width:13, height:13, borderRadius:3, background:'#7C3AED', color:'#fff', fontSize:8.5, fontWeight:800, display:'flex', alignItems:'center', justifyContent:'center', flexShrink:0}}>P</div>
            <span style={{flex:1, overflow:'hidden', textOverflow:'ellipsis', whiteSpace:'nowrap', fontWeight:500}}>Pedidos — Portal Suministros Vega</span>
            <span style={{fontSize:13, color:'#A79FC0', lineHeight:1, opacity:0.7}}>×</span>
          </div>
          <div style={{flex:1}}/>
          <div style={{display:'flex', alignSelf:'stretch'}}>
            <div style={{width:42, display:'flex', alignItems:'center', justifyContent:'center'}}><svg width="9" height="9" viewBox="0 0 10 10"><path d="M0 5 H10" stroke="#A79FC0" strokeWidth="1"/></svg></div>
            <div style={{width:42, display:'flex', alignItems:'center', justifyContent:'center'}}><svg width="9" height="9" viewBox="0 0 10 10"><rect x="0.5" y="0.5" width="9" height="9" fill="none" stroke="#A79FC0" strokeWidth="1"/></svg></div>
            <div style={{width:42, display:'flex', alignItems:'center', justifyContent:'center'}}><svg width="9" height="9" viewBox="0 0 10 10"><path d="M0 0 L10 10 M10 0 L0 10" stroke="#A79FC0" strokeWidth="1"/></svg></div>
          </div>
        </div>
        <div style={{height:34, background:'#332A47', display:'flex', alignItems:'center', padding:'0 12px', gap:8}}>
          <svg width="14" height="14" viewBox="0 0 24 24" fill="none"><path d="M15 6 L9 12 L15 18" stroke="#A79FC0" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"/></svg>
          <svg width="14" height="14" viewBox="0 0 24 24" fill="none"><path d="M9 6 L15 12 L9 18" stroke="#5A5273" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"/></svg>
          <div style={{flex:1, height:24, background:'#241D33', borderRadius:100, display:'flex', alignItems:'center', padding:'0 12px', gap:7, fontSize:10.5, color:'#C9C2DC'}}>
            <svg width="10" height="10" viewBox="0 0 24 24" fill="none"><rect x="5" y="10" width="14" height="10" rx="2" stroke="#8F86AD" strokeWidth="2"/><path d="M8 10 V7 a4 4 0 0 1 8 0 V10" stroke="#8F86AD" strokeWidth="2"/></svg>
            <span>portal.suministrosvega.es/pedidos</span>
          </div>
        </div>
        {/* Cabecera de la app — su marca */}
        <div style={{height:52, background:'linear-gradient(90deg,#4C1D95,#6D28D9)', display:'flex', alignItems:'center', padding:'0 18px', gap:14}}>
          <div style={{position:'relative'}}>
            <div style={{width:28, height:28, borderRadius:7, background:'#fff', color:'#5B21B6', fontSize:15, fontWeight:800, fontFamily:"'IBM Plex Sans',sans-serif", display:'flex', alignItems:'center', justifyContent:'center'}}>P</div>
            {t >= brandAt && t < brandAt + 1.0 && (()=>{
              const p = clamp((t-brandAt)/1.0, 0, 1);
              return <div style={{position:'absolute', inset:-7, border:'2px solid rgba(255,255,255,0.85)', borderRadius:12, transform:`scale(${lerp(0.75,1.55,Easing.easeOutCubic(p))})`, opacity:1-p, pointerEvents:'none'}}/>;
            })()}
          </div>
          <span className="f-plex" style={{fontSize:13, fontWeight:700, color:'#fff', letterSpacing:'3px'}}>PORTAL</span>
          <div style={{width:1, height:20, background:'rgba(255,255,255,0.25)'}}/>
          <div style={{display:'flex', gap:6, fontSize:12, fontFamily:"'IBM Plex Sans',sans-serif"}}>
            <span style={{padding:'5px 12px', background:'rgba(255,255,255,0.18)', borderRadius:100, color:'#fff', fontWeight:600}}>Pedidos</span>
            <span style={{padding:'5px 12px', color:'rgba(255,255,255,0.7)'}}>Clientes</span>
            <span style={{padding:'5px 12px', color:'rgba(255,255,255,0.7)'}}>Envíos</span>
          </div>
          <div style={{flex:1}}/>
          <div style={{width:26, height:26, borderRadius:100, background:'#A78BFA', color:'#2E1065', fontSize:10.5, fontWeight:700, fontFamily:"'IBM Plex Sans',sans-serif", display:'flex', alignItems:'center', justifyContent:'center'}}>LV</div>
        </div>
        {/* Cuerpo — listado de pedidos */}
        <div style={{position:'relative', height:'calc(100% - 120px)', background:'#F7F5FB', padding:'16px 24px'}}>
          <div style={{display:'flex', alignItems:'center', justifyContent:'space-between', marginBottom:12}}>
            <div style={{display:'flex', alignItems:'center', gap:10}}>
              <div className="f-plex" style={{fontSize:20, fontWeight:700, color:'#2E1065'}}>Pedidos</div>
              <span style={{padding:'3px 9px', background:'rgba(109,40,217,0.10)', border:'1px solid rgba(109,40,217,0.25)', borderRadius:100, fontSize:10.5, fontWeight:700, color:'#6D28D9', fontFamily:"'IBM Plex Sans',sans-serif"}}>3 nuevos</span>
            </div>
            <div style={{display:'flex', alignItems:'center', gap:10}}>
              {/* Filtro nuevo — aparece cuando el cambio del chat llega a la app */}
              {t >= filtroAt && (()=>{
                const p = clamp((t-filtroAt)/0.45, 0, 1);
                const e = Easing.easeOutBack(p);
                const cyc = ((t-filtroAt)*0.9) % 1;
                return (
                  <div style={{position:'relative', transform:`scale(${lerp(0.5,1,e)})`, opacity:clamp(p*1.4,0,1)}}>
                    <div style={{display:'flex', alignItems:'center', gap:6, padding:'7px 12px', background:'#F5F3FF', border:'1px solid #7C3AED', borderRadius:8, fontSize:12, fontWeight:600, color:'#5B21B6', fontFamily:"'IBM Plex Sans',sans-serif"}}>
                      Estado · Todos <span style={{fontSize:9, opacity:0.7}}>▾</span>
                    </div>
                    {t < filtroAt + 1.5 && <div style={{position:'absolute', inset:-5, border:'2px solid rgba(124,58,237,0.7)', borderRadius:12, transform:`scale(${lerp(0.92,1.3,Easing.easeOutCubic(cyc))})`, opacity:1-cyc, pointerEvents:'none'}}/>}
                  </div>
                );
              })()}
              <div style={{display:'flex', alignItems:'center', gap:7, width:170, padding:'7px 12px', background:'#fff', border:'1px solid #E4E0F0', borderRadius:8, fontSize:12, color:'#8B84A3', fontFamily:"'IBM Plex Sans',sans-serif"}}>
                <svg width="12" height="12" viewBox="0 0 24 24" fill="none"><circle cx="11" cy="11" r="6" stroke="#8B84A3" strokeWidth="2"/><path d="M15.5 15.5 L20 20" stroke="#8B84A3" strokeWidth="2" strokeLinecap="round"/></svg>
                Buscar pedido
              </div>
            </div>
          </div>

          <div style={{display:'grid', gridTemplateColumns:'110px 1fr 130px 170px', padding:'9px 16px', background:'#EDE9F7', borderRadius:8, fontSize:9.5, color:'#8B84A3', letterSpacing:1, textTransform:'uppercase', fontWeight:700, fontFamily:"'JetBrains Mono',monospace"}}>
            <div>Pedido</div><div>Cliente</div><div style={{textAlign:'right'}}>Importe</div><div style={{textAlign:'right'}}>Estado</div>
          </div>

          <div style={{display:'flex', flexDirection:'column', gap:9, marginTop:9}}>
            {pedidos.map((pd,i)=>{
              const p = clamp((t-(rowsAt+i*0.28))/0.45, 0, 1);
              const e = Easing.easeOutCubic(p);
              return (
                <div key={i} style={{display:'grid', gridTemplateColumns:'110px 1fr 130px 170px', alignItems:'center', height:62, padding:'0 16px', background:'#fff', border:'1px solid #EAE6F4', borderRadius:10, boxShadow:'0 2px 8px rgba(46,16,101,0.05)', opacity:e, transform:`translateY(${(1-e)*12}px)`}}>
                  <span className="f-mono" style={{fontSize:12.5, fontWeight:600, color:'#6D28D9'}}>{pd.num}</span>
                  <div>
                    <div className="f-plex" style={{fontSize:13.5, fontWeight:600, color:'#1E1B2E'}}>{pd.cliente}</div>
                    <div style={{fontSize:11, color:'#8B84A3', marginTop:2, fontFamily:"'IBM Plex Sans',sans-serif"}}>{pd.ciudad}</div>
                  </div>
                  <span className="f-mono" style={{fontSize:13.5, fontWeight:700, color:'#1E1B2E', textAlign:'right'}}>{pd.importe}</span>
                  <div style={{textAlign:'right'}}>
                    <span style={{display:'inline-block', padding:'4px 10px', background:pd.bg, border:`1px solid ${pd.br}`, borderRadius:100, fontSize:11, fontWeight:600, color:pd.fg, fontFamily:"'IBM Plex Sans',sans-serif"}}>{pd.estado}</span>
                  </div>
                </div>
              );
            })}
          </div>

          <div style={{position:'absolute', left:24, right:24, bottom:12, display:'flex', justifyContent:'space-between', fontSize:11, color:'#8B84A3', fontFamily:"'IBM Plex Sans',sans-serif", opacity:clamp((t-rowsAt-1.0)/0.5,0,1)}}>
            <span>Mostrando 3 de 128 pedidos</span>
            <span>Actualizado hace 1 min</span>
          </div>
        </div>
      </div>

      {/* ===== Capa backend — asoma bajo la app al elevarse (rayos X) ===== */}
      {t >= layerAt && (()=>{
        const lp = clamp((t-layerAt)/0.75, 0, 1);
        const le = Easing.easeOutCubic(lp);
        const datosGlow = animate({from:0,to:1,start:datosGlowAt,end:datosGlowAt+0.4,ease:Easing.easeOutCubic,t}) * animate({from:1,to:0,start:11.7,end:12.2,ease:Easing.easeInOutQuad,t});
        const backChips = ['datos','usuarios','permisos','API'];
        return (
          <div style={{position:'absolute', top:706, left:130, width:700, height:84, zIndex:-1, borderRadius:14, background:'linear-gradient(135deg,#0D1B31,#111F3C)', border:'1px solid rgba(0,133,255,0.35)', boxShadow:`0 18px 44px rgba(0,0,0,0.45), 0 0 ${26*le}px rgba(0,133,255,0.22)`, display:'flex', alignItems:'center', gap:14, padding:'0 24px', opacity:lp, transform:`translateY(${(1-le)*-84}px)`}}>
            <DinaupLogo mark size={26}/>
            <span className="f-plex" style={{fontSize:17, fontWeight:700, color:'#fff', whiteSpace:'nowrap'}}>Backend: Dinaup</span>
            <div style={{width:1, height:30, background:'rgba(255,255,255,0.14)'}}/>
            <div style={{display:'flex', gap:8}}>
              {backChips.map((c,i)=>{
                const cp = clamp((t-(chipsAt+i*0.25))/0.4, 0, 1);
                const ce = Easing.easeOutBack(cp);
                const hot = c === 'datos' ? datosGlow : 0;
                return (
                  <span key={i} className="f-mono" style={{padding:'5px 12px', borderRadius:100, fontSize:11, fontWeight:600, letterSpacing:'0.5px', whiteSpace:'nowrap', background:`rgba(${hot>0 ? '0,193,255' : '255,255,255'},${0.07+hot*0.10})`, border:`1px solid rgba(${hot>0 ? '0,193,255' : '255,255,255'},${0.16+hot*0.55})`, color: hot > 0.5 ? '#fff' : 'rgba(255,255,255,0.85)', boxShadow:`0 0 ${14*hot}px rgba(0,193,255,${0.45*hot})`, opacity:clamp(cp*1.3,0,1), transform:`scale(${lerp(0.6,1,ce)})`}}>{c}</span>
                );
              })}
            </div>
          </div>
        );
      })()}
      </div>

      {/* ===== DERECHA — app de chat de código (burbujas, no terminal) ===== */}
      <div style={{position:'absolute', top:186, left:960, width:880, height:604, zIndex:2, borderRadius:12, overflow:'hidden', background:'#16181D', border:'1px solid rgba(255,255,255,0.09)', boxShadow:`0 40px 100px rgba(0,0,0,0.5), 0 0 ${34*glowChat}px rgba(217,119,87,${0.40*glowChat})`, opacity:wChat, transform:`translateX(${(1-wChat)*46}px)`}}>

        {/* Barra de título de la app */}
        <div style={{height:46, background:'#21242B', borderBottom:'1px solid rgba(255,255,255,0.07)', display:'flex', alignItems:'center', padding:'0 0 0 14px', gap:10}}>
          <div style={{width:24, height:24, borderRadius:7, background:'#D97757', display:'flex', alignItems:'center', justifyContent:'center', flexShrink:0}}>{spark(12)}</div>
          <span className="f-plex" style={{fontSize:12.5, fontWeight:600, color:'#C6CBD4'}}>Asistente de código</span>
          <span style={{width:1, height:14, background:'rgba(255,255,255,0.12)'}}/>
          <span className="f-mono" style={{fontSize:10.5, color:'#6B7280'}}>portal-frontend</span>
          <div style={{flex:1}}/>
          <div style={{display:'flex', alignSelf:'stretch'}}>
            <div style={{width:42, display:'flex', alignItems:'center', justifyContent:'center'}}><svg width="9" height="9" viewBox="0 0 10 10"><path d="M0 5 H10" stroke="#8B93A1" strokeWidth="1"/></svg></div>
            <div style={{width:42, display:'flex', alignItems:'center', justifyContent:'center'}}><svg width="9" height="9" viewBox="0 0 10 10"><rect x="0.5" y="0.5" width="9" height="9" fill="none" stroke="#8B93A1" strokeWidth="1"/></svg></div>
            <div style={{width:42, display:'flex', alignItems:'center', justifyContent:'center'}}><svg width="9" height="9" viewBox="0 0 10 10"><path d="M0 0 L10 10 M10 0 L0 10" stroke="#8B93A1" strokeWidth="1"/></svg></div>
          </div>
        </div>

        {/* Hilo de mensajes */}
        <div style={{position:'relative', height:'calc(100% - 124px)', padding:'16px 22px', display:'flex', flexDirection:'column', gap:12, overflow:'hidden'}}>

          {/* Chip de sesión */}
          <div style={{alignSelf:'center', display:'flex', alignItems:'center', gap:7, opacity:clamp((t-winChatAt-0.4)/0.4,0,1)}}>
            <span style={{width:5, height:5, borderRadius:100, background:'#56E16A'}}/>
            <span className="f-mono" style={{fontSize:10.5, color:'#7A8190'}}>portal-frontend · rama main</span>
          </div>

          {/* Estado vacío hasta que llega el primer mensaje */}
          {t < userMsgAt && (
            <div style={{position:'absolute', top:104, left:0, right:0, textAlign:'center', color:'rgba(255,255,255,0.28)', fontSize:12, fontStyle:'italic', opacity:clamp((t-winChatAt-0.6)/0.5,0,1) * clamp((userMsgAt-t)/0.3,0,1)}}>
              Sin mensajes todavía
            </div>
          )}

          {/* Burbuja del junior — aparece DESPUÉS de enviar */}
          {t >= userMsgAt && (()=>{
            const p = clamp((t-userMsgAt)/0.4, 0, 1);
            return (
              <div style={{alignSelf:'flex-end', maxWidth:560, opacity:p, transform:`translateY(${(1-Easing.easeOutCubic(p))*10}px)`}}>
                <div style={{display:'flex', alignItems:'center', justifyContent:'flex-end', gap:7, marginBottom:5}}>
                  <span className="f-plex" style={{fontSize:10.5, fontWeight:600, color:'rgba(255,255,255,0.55)'}}>Junior · Suministros Vega</span>
                  <div style={{width:20, height:20, borderRadius:100, background:'linear-gradient(135deg,#7C3AED,#A78BFA)', display:'flex', alignItems:'center', justifyContent:'center', fontSize:9.5, fontWeight:700, color:'#fff', fontFamily:"'IBM Plex Sans',sans-serif"}}>J</div>
                </div>
                <div style={{background:'rgba(0,133,255,0.16)', border:'1px solid rgba(0,133,255,0.34)', borderRadius:'14px 14px 4px 14px', padding:'10px 13px', fontSize:13, color:'#fff', lineHeight:1.45}}>
                  {promptTxt}
                </div>
              </div>
            );
          })()}

          {/* El asistente trabaja — pasos, sin volcar código */}
          {t >= steps[0].start && (
            <div style={{alignSelf:'flex-start', width:440}}>
              <div style={{background:'rgba(255,255,255,0.05)', border:'1px solid rgba(255,255,255,0.10)', borderRadius:'14px 14px 14px 4px', padding:'11px 14px', display:'flex', flexDirection:'column', gap:6}}>
                {steps.map((s,i)=>{
                  if (t < s.start) return null;
                  const done = t >= s.done;
                  return (
                    <div key={i} style={{display:'flex', alignItems:'center', gap:9, height:24, opacity:clamp((t-s.start)/0.3,0,1)}}>
                      {done
                        ? <span style={{width:13, textAlign:'center', fontSize:11, color:'#10B981', flexShrink:0}}>✓</span>
                        : spinnerSvg}
                      <span className="f-mono" style={{fontSize:11.5, color: done ? 'rgba(255,255,255,0.55)' : '#F3E8E2'}}>{done ? s.doneTxt : s.doing}</span>
                    </div>
                  );
                })}
              </div>
            </div>
          )}

          {/* Respuesta del asistente — resumen en 2 líneas + chips */}
          {t >= answerAt && (()=>{
            const p = clamp((t-answerAt)/0.45, 0, 1);
            const l1 = clamp((t-answerAt-0.15)/0.4, 0, 1);
            const l2 = clamp((t-answerAt-0.50)/0.4, 0, 1);
            return (
              <div style={{alignSelf:'flex-start', maxWidth:640, opacity:p, transform:`translateY(${(1-Easing.easeOutCubic(p))*10}px)`}}>
                <div style={{display:'flex', alignItems:'center', gap:7, marginBottom:5}}>
                  <div style={{width:20, height:20, borderRadius:6, background:'#D97757', display:'flex', alignItems:'center', justifyContent:'center', flexShrink:0}}>{spark(10)}</div>
                  <span className="f-plex" style={{fontSize:10.5, fontWeight:600, color:'rgba(255,255,255,0.55)'}}>Asistente</span>
                </div>
                <div style={{background:'rgba(255,255,255,0.05)', border:'1px solid rgba(255,255,255,0.10)', borderRadius:'14px 14px 14px 4px', padding:'12px 14px'}}>
                  <div style={{fontSize:13.5, color:'#fff', lineHeight:1.5, opacity:l1}}>Hecho: filtro por estado en el listado de pedidos.</div>
                  <div style={{fontSize:13.5, color:'rgba(255,255,255,0.72)', lineHeight:1.5, marginTop:4, opacity:l2}}>Los datos ya viven en Dinaup: sin base de datos propia.</div>
                  <div style={{display:'flex', gap:8, marginTop:11, height:26}}>
                    {[
                      { txt:'3 archivos', fg:'#C6CBD4', bg:'rgba(255,255,255,0.07)', br:'rgba(255,255,255,0.16)' },
                      { txt:'✓ build OK', fg:'#6EE7B7', bg:'rgba(16,185,129,0.12)',  br:'rgba(16,185,129,0.38)' },
                    ].map((c,i)=>{
                      const cp = clamp((t-(aiChipsAt+i*0.15))/0.4, 0, 1);
                      const ce = Easing.easeOutBack(cp);
                      return <span key={i} className="f-mono" style={{display:'inline-flex', alignItems:'center', padding:'0 11px', borderRadius:100, fontSize:11, fontWeight:700, color:c.fg, background:c.bg, border:`1px solid ${c.br}`, whiteSpace:'nowrap', opacity:clamp(cp*1.3,0,1), transform:`scale(${lerp(0.6,1,ce)})`}}>{c.txt}</span>;
                    })}
                  </div>
                </div>
              </div>
            );
          })()}
        </div>

        {/* Casilla de entrada — aquí teclea el junior (regla global de chats) */}
        <div style={{position:'absolute', left:0, right:0, bottom:0, height:78, padding:'0 18px', display:'flex', alignItems:'center', borderTop:'1px solid rgba(255,255,255,0.07)', background:'#1A1D23'}}>
          <div style={{flex:1, display:'flex', alignItems:'center', gap:10, background:'#0F1116', border:`1.5px solid ${typing ? 'rgba(217,119,87,0.55)' : 'rgba(255,255,255,0.12)'}`, borderRadius:12, padding:'0 8px 0 14px', height:48}}>
            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" style={{flexShrink:0, opacity:0.5}}><path d="M12 5 V19 M5 12 H19" stroke="#C6CBD4" strokeWidth="2" strokeLinecap="round"/></svg>
            <div style={{flex:1, fontSize:13.5, fontFamily:"'IBM Plex Sans',sans-serif", overflow:'hidden', whiteSpace:'nowrap'}}>
              {typing
                ? <span style={{color:'#fff'}}><Typewriter text={promptTxt} start={typeAt} cps={28} t={t} caret/></span>
                : <span style={{color:'rgba(255,255,255,0.38)'}}>Pide un cambio en tu app…</span>}
            </div>
            <div style={{position:'relative', flexShrink:0}}>
              <div style={{width:34, height:34, borderRadius:9, background: typing || pressed ? '#D97757' : 'rgba(255,255,255,0.08)', display:'flex', alignItems:'center', justifyContent:'center', transform:`scale(${pressed ? 0.86 : 1})`, transition:'background 150ms'}}>
                <svg width="15" height="15" viewBox="0 0 24 24" fill="none"><path d="M12 19 V6 M6.5 11 L12 5.5 L17.5 11" stroke={typing || pressed ? '#fff' : '#8B93A1'} strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"/></svg>
              </div>
              {pressed && (()=>{
                const p = clamp((t-sendAt)/0.3, 0, 1);
                return <div style={{position:'absolute', inset:-6, border:'2px solid rgba(217,119,87,0.8)', borderRadius:13, transform:`scale(${lerp(0.85,1.35,Easing.easeOutCubic(p))})`, opacity:1-p, pointerEvents:'none'}}/>;
              })()}
            </div>
          </div>
        </div>
      </div>

      {/* ===== Pulso que viaja del chat al filtro de la app (el cambio llega) ===== */}
      {t >= pingAt && t < filtroAt + 0.12 && (()=>{
        const p = Easing.easeInOutQuad(clamp((t-pingAt)/(filtroAt+0.1-pingAt), 0, 1));
        const x = (1-p)*(1-p)*995 + 2*(1-p)*p*740 + p*p*588;
        const y = (1-p)*(1-p)*480 + 2*(1-p)*p*240 + p*p*328;
        return <div style={{position:'absolute', left:x-5, top:y-5, width:10, height:10, borderRadius:100, background:'#00C1FF', boxShadow:'0 0 16px rgba(0,193,255,0.9), 0 0 40px rgba(0,133,255,0.5)', zIndex:20, opacity: p < 0.1 ? p/0.1 : 1, pointerEvents:'none'}}/>;
      })()}

      {/* ===== Banda final ===== */}
      <div style={{position:'absolute', left:0, right:0, bottom:0, height:96, overflow:'hidden', pointerEvents:'none', zIndex:8}}>
        <div style={{position:'absolute', inset:0, background:'rgba(3,10,24,0.92)', borderTop:'1px solid rgba(255,255,255,0.12)', boxShadow:'0 -20px 60px rgba(0,0,0,0.45)', display:'flex', alignItems:'center', justifyContent:'center', gap:16, transform:`translateY(${(1-bandE)*100}%)`, opacity:bandE}}>
          <DinaupLogo mark size={30}/>
          <div className="f-plex" style={{fontSize:25, letterSpacing:'-0.015em'}}>
            <span style={{color:'#fff', fontWeight:700}}>Lo que construyes hoy</span>
            <span style={{color:'rgba(255,255,255,0.65)', fontWeight:500}}> son las bases de mañana.</span>
          </div>
        </div>
      </div>

      <SocialCaption t={t} cues={CAPTIONS.slide_backend}/>
    </SlideCanvas>
  );
}

Object.assign(window, { SlideBackend });
