// === F7 · Flex — Del card al listado (16s) ===
// La sección "Partidas" (recién creada en el caso del minigolf) se abre y ya
// es una aplicación completa: listado con columnas configurables, filtro por
// pista y exportación a CSV. Sincronizado con CAPTIONS.slide_flexlistado
// (cues 0.5 / 3.2 / 6.4 / 9.6 / 12.6).
// Beats: click card 1.2 · tabla 2.0-3.2 · columnas 3.2-6.4 · filtro 6.4-9.6 ·
// export 9.6-12.6 · claim 12.6-15.2 (reposo, autoplay hold).

function SlideFlexListado({ t }){
  // ---------- Timeline ----------
  const clickCardAt = 1.2;   // click en la card "Partidas"
  const listInAt    = 1.8;   // entra el listado
  const rowsAt      = 2.05;  // filas escalonadas (cue 2.0-3.2)
  const colClickAt  = 3.8;   // abre "Columnas"
  const totalOnAt   = 4.6;   // añade la columna Total
  const njugOffAt   = 5.45;  // quita Nº jugadores
  const colCloseAt  = 6.15;  // se cierra el panel de columnas
  const fltClickAt  = 7.0;   // abre "Filtrar"
  const pista4At    = 7.9;   // elige Pista = 4
  const fltCloseAt  = 8.15;  // se cierra el panel de filtro
  const chipAt      = 8.45;  // chip "Pista = 4" en cabecera
  const counterAt   = 9.0;   // contador "3 de 6"
  const exportAt    = 10.5;  // click en Exportar CSV
  const toastAt     = 11.0;  // toast "partidas.csv descargado"
  const claimAt     = 12.6;  // claim final (cue 12.6-15.7)

  // ---------- Geometría ----------
  // Ventana 1440×860 en (240,150). Chrome 76 + nav (52+44+2) = contenido en y rel 174.
  const CONT_Y = 174;

  // ---------- Datos (minigolf, 8 €/jugador) ----------
  const ROWS = [
    { hora:'17:30', jug:'María López',  ini:'ML', pista:4, njug:3, ticket:'TK-2041', total:'24,00 €' },
    { hora:'17:45', jug:'Jorge Ferrer', ini:'JF', pista:2, njug:2, ticket:'TK-2042', total:'16,00 €' },
    { hora:'18:00', jug:'Lucía Ortega', ini:'LO', pista:4, njug:4, ticket:'TK-2043', total:'32,00 €' },
    { hora:'18:15', jug:'Andrés Vidal', ini:'AV', pista:1, njug:2, ticket:'TK-2044', total:'16,00 €' },
    { hora:'18:30', jug:'Carmen Ruiz',  ini:'CR', pista:4, njug:5, ticket:'TK-2045', total:'40,00 €' },
    { hora:'18:45', jug:'Pablo Serra',  ini:'PS', pista:3, njug:2, ticket:'TK-2046', total:'16,00 €' },
  ];

  const CARDS = [
    { n:'Ventas',    dato:'96 tickets hoy',     ic:'ventas' },
    { n:'Compras',   dato:'12 pendientes',      ic:'compras' },
    { n:'Productos', dato:'1.032 referencias',  ic:'productos' },
    { n:'Clientes',  dato:'1.284 clientes',     ic:'clientes' },
    { n:'Análisis',  dato:'4 paneles',          ic:'analisis' },
    { n:'Partidas',  dato:'6 partidas hoy',     ic:'partidas',  nueva:true },
    { n:'Vehículos', dato:'38 este mes',        ic:'vehiculos', nueva:true },
    { n:'Licencias', dato:'52 activas',         ic:'licencias', nueva:true },
  ];

  // ---------- Iconos SVG de línea (cero emojis en la UI) ----------
  const flIco = (name, size, color, sw) => {
    const s = { stroke: color, strokeWidth: sw || 1.7, strokeLinecap:'round', strokeLinejoin:'round', fill:'none' };
    if (name === 'ventas')    return <svg width={size} height={size} viewBox="0 0 24 24"><path d="M4 4 H11.2 L20 12.8 L12.8 20 L4 11.2 Z" {...s}/><circle cx="8.2" cy="8.2" r="1.4" {...s}/></svg>;
    if (name === 'compras')   return <svg width={size} height={size} viewBox="0 0 24 24"><path d="M3.5 4.5 H6 L8.4 14.5 H17.6 L19.8 7.5 H7" {...s}/><circle cx="9.6" cy="18.6" r="1.5" {...s}/><circle cx="16.4" cy="18.6" r="1.5" {...s}/></svg>;
    if (name === 'productos') return <svg width={size} height={size} viewBox="0 0 24 24"><path d="M12 3.5 L20 7.5 V16.5 L12 20.5 L4 16.5 V7.5 Z" {...s}/><path d="M4 7.5 L12 11.5 L20 7.5" {...s}/><path d="M12 11.5 V20.5" {...s}/></svg>;
    if (name === 'clientes')  return <svg width={size} height={size} viewBox="0 0 24 24"><circle cx="9" cy="8.4" r="3" {...s}/><path d="M3.6 19 A5.6 5.6 0 0 1 14.4 19" {...s}/><circle cx="16.8" cy="9.4" r="2.3" {...s}/><path d="M15.9 18.7 A4.4 4.4 0 0 1 20.6 19" {...s}/></svg>;
    if (name === 'analisis')  return <svg width={size} height={size} viewBox="0 0 24 24"><path d="M5 20 V13" {...s} strokeWidth="2"/><path d="M10 20 V7" {...s} strokeWidth="2"/><path d="M15 20 V11" {...s} strokeWidth="2"/><path d="M20 20 V5" {...s} strokeWidth="2"/></svg>;
    if (name === 'partidas')  return <svg width={size} height={size} viewBox="0 0 24 24"><path d="M7 20.5 V4" {...s}/><path d="M7 4.6 L16.5 7.3 L7 10.4" {...s}/><path d="M3.6 20.5 H13" {...s}/></svg>;
    if (name === 'vehiculos') return <svg width={size} height={size} viewBox="0 0 24 24"><path d="M4.8 14.6 L6.2 10.4 C6.5 9.5 7.3 9 8.2 9 H15.8 C16.7 9 17.5 9.5 17.8 10.4 L19.2 14.6" {...s}/><rect x="3.6" y="14.6" width="16.8" height="3.8" rx="1.7" {...s}/><circle cx="7.8" cy="19.6" r="1.3" {...s}/><circle cx="16.2" cy="19.6" r="1.3" {...s}/></svg>;
    if (name === 'licencias') return <svg width={size} height={size} viewBox="0 0 24 24"><circle cx="8" cy="15.5" r="3.6" {...s}/><path d="M10.7 12.8 L19.5 4" {...s}/><path d="M16.2 7.3 L19 10.1" {...s}/><path d="M13.4 10.1 L15.4 12.1" {...s}/></svg>;
    if (name === 'lupa')      return <svg width={size} height={size} viewBox="0 0 24 24"><circle cx="11" cy="11" r="6" {...s}/><path d="M15.5 15.5 L20 20" {...s}/></svg>;
    if (name === 'puzzle')    return <svg width={size} height={size} viewBox="0 0 24 24"><path d="M9.5 4.5 A2 2 0 0 1 13.5 4.5 C13.5 5.4 13 6 13 6 H16 A1.5 1.5 0 0 1 17.5 7.5 V10.5 C17.5 10.5 18.1 10 19 10 A2 2 0 0 1 19 14 C18.1 14 17.5 13.5 17.5 13.5 V16.5 A1.5 1.5 0 0 1 16 18 H7.5 A1.5 1.5 0 0 1 6 16.5 V13.5 C6 13.5 5.4 14 4.5 14 A2 2 0 0 1 4.5 10 C5.4 10 6 10.5 6 10.5 V7.5 A1.5 1.5 0 0 1 7.5 6 H10 C10 6 9.5 5.4 9.5 4.5 Z" {...s} strokeWidth="1.6"/></svg>;
    if (name === 'columnas')  return <svg width={size} height={size} viewBox="0 0 24 24"><rect x="4" y="5" width="4.4" height="14" rx="1.2" {...s} strokeWidth="1.6"/><rect x="9.8" y="5" width="4.4" height="14" rx="1.2" {...s} strokeWidth="1.6"/><rect x="15.6" y="5" width="4.4" height="14" rx="1.2" {...s} strokeWidth="1.6"/></svg>;
    if (name === 'filtrar')   return <svg width={size} height={size} viewBox="0 0 24 24"><path d="M4 5 H20 L14.2 12.4 V18.6 L9.8 16.4 V12.4 Z" {...s} strokeWidth="1.6"/></svg>;
    if (name === 'exportar')  return <svg width={size} height={size} viewBox="0 0 24 24"><path d="M12 4 V13.5" {...s} strokeWidth="1.9"/><path d="M8.2 10 L12 13.8 L15.8 10" {...s} strokeWidth="1.9"/><path d="M5 17.5 V19.5 H19 V17.5" {...s} strokeWidth="1.9"/></svg>;
    if (name === 'check')     return <svg width={size} height={size} viewBox="0 0 24 24"><path d="M4.5 12.5 L9.5 17.5 L19.5 6.5" {...s} strokeWidth="2.4"/></svg>;
    return null;
  };

  const checkbox = (on) => on
    ? <span style={{width:16,height:16,borderRadius:4,background:'var(--dn-primary)',display:'inline-flex',alignItems:'center',justifyContent:'center',flexShrink:0}}><svg width="10" height="10" viewBox="0 0 24 24" fill="none"><path d="M4.5 12.5 L9.5 17.5 L19.5 6.5" stroke="#fff" strokeWidth="3.4" strokeLinecap="round" strokeLinejoin="round"/></svg></span>
    : <span style={{width:16,height:16,borderRadius:4,border:'1.5px solid #CBD5E1',background:'#fff',flexShrink:0}}/>;

  // ---------- Estados derivados ----------
  const winP  = clamp((t-0.25)/0.55, 0, 1);
  const winE  = Easing.easeOutCubic(winP);

  const dashO = t < 1.35 ? 1 : 1 - clamp((t-1.35)/0.45, 0, 1);
  const listP = clamp((t-listInAt)/0.45, 0, 1);
  const listE = Easing.easeOutCubic(listP);

  // Columnas: Total entra (peso 0→180) · Nº jugadores se pliega (210→0).
  const wTotal = animate({ from:0,   to:180, start:totalOnAt+0.05, end:totalOnAt+0.75, ease:Easing.easeInOutCubic, t });
  const oTotal = clamp((t-(totalOnAt+0.3))/0.45, 0, 1);
  const wNjug  = animate({ from:210, to:0,   start:njugOffAt+0.05, end:njugOffAt+0.75, ease:Easing.easeInOutCubic, t });
  const oNjug  = 1 - clamp((t-njugOffAt)/0.3, 0, 1);

  const COLS = [
    { k:'hora',   h:'Hora',         w:150,    o:1 },
    { k:'jug',    h:'Jugador',      w:400,    o:1 },
    { k:'pista',  h:'Pista',        w:180,    o:1 },
    { k:'njug',   h:'Nº jugadores', w:wNjug,  o:oNjug,  right:true },
    { k:'ticket', h:'Ticket',       w:190,    o:1 },
    { k:'total',  h:'Total',        w:wTotal, o:oTotal, right:true },
  ];

  // Paneles: abren/cierran con mínimo de ambas rampas.
  const colPanelP = Math.min(clamp((t-colClickAt)/0.28, 0, 1), 1 - clamp((t-colCloseAt)/0.22, 0, 1));
  const fltPanelP = Math.min(clamp((t-fltClickAt)/0.28, 0, 1), 1 - clamp((t-fltCloseAt)/0.22, 0, 1));

  const filterOn = t >= chipAt;

  // ---------- Cursor orgánico (coordenadas de lienzo 1920×1080) ----------
  // Regla global: cada trayecto es una curva bezier (1 control lateral),
  // easeInOut con aterrizaje (llega decelerando), pausa ≥0.18s ANTES de cada
  // click, y el destino es el CENTRO REAL de cada control. Centros verificados:
  //   card Partidas: grid en x 272-1648 (4 col de 330.5, gap 18), fila 2 en
  //     y 628-778 → centro (786,703)
  //   toolbar (y 354-394, borde dcho 1648): Exportar 1490-1648 → (1569,374) ·
  //     Filtrar 1370-1480 → (1425,374) · Columnas 1232-1360 → (1296,374)
  //   panel Columnas (1110,402 · items 38px tras header 36+8): Total i5 →
  //     (1235,655) · Nº jugadores i3 → (1235,579)
  //   panel Filtrar (1220,402 · items 40px): Pista 4 i3 → (1350,586)
  const CURSOR_LEGS = [
    { t0:0.45, t1:1.02,  from:{x:1560,y:1002}, to:{x:786,y:703},  bend:-90 }, // card Partidas · click 1.2
    { t0:2.9,  t1:3.58,  from:{x:786,y:703},   to:{x:1296,y:374}, bend:70 },  // Columnas · click 3.8
    { t0:4.0,  t1:4.42,  from:{x:1296,y:374},  to:{x:1235,y:655}, bend:-36 }, // item Total · click 4.6
    { t0:5.0,  t1:5.25,  from:{x:1235,y:655},  to:{x:1235,y:579}, bend:-20 }, // item Nº jugadores · click 5.45
    { t0:6.2,  t1:6.82,  from:{x:1235,y:579},  to:{x:1425,y:374}, bend:55 },  // Filtrar · click 7.0
    { t0:7.15, t1:7.7,   from:{x:1425,y:374},  to:{x:1350,y:586}, bend:-30 }, // opción Pista 4 · click 7.9
    { t0:9.4,  t1:10.22, from:{x:1350,y:586},  to:{x:1569,y:374}, bend:65 },  // Exportar CSV · click 10.5
    { t0:11.6, t1:12.5,  from:{x:1569,y:374},  to:{x:1636,y:724}, bend:-45 }, // reposo
  ];
  const easeCursor = (p) => Easing.easeInOutCubic(Math.pow(p, 0.82)); // la llegada dura más que la salida
  const cursorAt = (tt) => {
    let rest = CURSOR_LEGS[0].from;
    for (let i = 0; i < CURSOR_LEGS.length; i++){
      const leg = CURSOR_LEGS[i];
      if (tt <= leg.t0) return rest;
      if (tt < leg.t1){
        const e = easeCursor((tt - leg.t0) / (leg.t1 - leg.t0));
        const a = leg.from, b = leg.to;
        const len = Math.hypot(b.x - a.x, b.y - a.y) || 1;
        const c = { x:(a.x + b.x)/2 - (b.y - a.y)/len * leg.bend, y:(a.y + b.y)/2 + (b.x - a.x)/len * leg.bend };
        const v = 1 - e;
        return { x: v*v*a.x + 2*v*e*c.x + e*e*b.x, y: v*v*a.y + 2*v*e*c.y + e*e*b.y };
      }
      rest = leg.to;
    }
    return rest;
  };
  const clicks = [clickCardAt, colClickAt, totalOnAt, njugOffAt, fltClickAt, pista4At, exportAt];
  const cur = cursorAt(t);
  const clicking = clicks.some(c => t >= c && t < c + 0.5);

  // ---------- Claim final: la ventana se retira, el claim toma el centro ----------
  const claimP  = clamp((t-claimAt)/0.7, 0, 1);
  const claimE  = Easing.easeInOutCubic(claimP);
  const groupO  = lerp(1, 0.08, claimE);
  const groupS  = lerp(1, 0.975, claimE);

  // ---------- Sub-renderers ----------
  const toolBtn = (label, ic, w, active, pressed, primary) => (
    <div className="f-plex" style={{
      width:w, height:40, display:'flex', alignItems:'center', justifyContent:'center', gap:7,
      borderRadius:9, fontSize:13, fontWeight:600, flexShrink:0,
      background: primary ? 'var(--dn-primary)' : active ? 'rgba(0,133,255,0.06)' : '#fff',
      border: primary ? '1px solid transparent' : `1px solid ${active ? 'rgba(0,133,255,0.45)' : '#E2E8F0'}`,
      color: primary ? '#fff' : active ? 'var(--dn-primary)' : '#334155',
      boxShadow: primary ? '0 6px 18px rgba(0,133,255,0.30)' : '0 2px 6px rgba(15,23,42,0.05)',
      transform: pressed ? 'scale(0.94)' : 'scale(1)',
    }}>
      {flIco(ic, 15, primary ? '#fff' : active ? '#0085FF' : '#64748B')}
      {label}
    </div>
  );

  const cell = (col, children) => (
    <div key={col.k} style={{flexGrow:col.w, flexShrink:col.w, flexBasis:0, minWidth:0, overflow:'hidden', whiteSpace:'nowrap', opacity:col.o, textAlign: col.right ? 'right' : 'left', padding:'0 6px'}}>
      {children}
    </div>
  );

  return (
    <SlideCanvas variant="light">
      <DemoHeader t={t} eyebrow="FLEX · DEL CARD AL LISTADO" title={<>Tu sección, <span className="grad-text">ya en marcha.</span></>}/>

      {/* ===== Grupo ventana + cursor (se retira en el claim) ===== */}
      <div style={{position:'absolute', inset:0, opacity:groupO, transform:`scale(${groupS})`}}>

        <div style={{position:'absolute', top:150, left:240, width:1440, height:860, background:'#fff', borderRadius:12, border:'1px solid #E2E8F0', boxShadow:'0 30px 80px rgba(0,133,255,0.15)', overflow:'hidden', opacity:winP, transform:`translateY(${(1-winE)*18}px)`}}>
          <BrowserChrome url="play.dinaup.com/Flex/Partidas" title="Flex — Dinaup"/>

          {/* ===== Nav doble piso (np3 simplificada) ===== */}
          <div style={{height:52, display:'flex', alignItems:'center', padding:'0 22px', background:'#fff'}}>
            <DinaupLogo size={20}/>
            <div style={{flex:1}}/>
            <div style={{display:'flex', alignItems:'center', gap:8, height:32, padding:'0 8px 0 12px', background:'#F1F5F9', border:'1px solid #E2E8F0', borderRadius:100}}>
              {flIco('lupa', 14, '#64748B')}
              <span style={{fontSize:12.5, color:'#64748B'}}>Buscar</span>
              <span className="f-mono" style={{fontSize:10, fontWeight:600, color:'#94A3B8', background:'#fff', border:'1px solid #CBD5E1', borderRadius:5, padding:'2px 6px'}}>Ctrl K</span>
            </div>
            <div className="f-plex" style={{width:30, height:30, borderRadius:100, marginLeft:14, background:'linear-gradient(135deg,#0085FF,#56E16A)', color:'#fff', display:'flex', alignItems:'center', justifyContent:'center', fontSize:12, fontWeight:700}}>M</div>
          </div>
          <div style={{height:44, display:'flex', alignItems:'center', padding:'0 16px', borderTop:'1px solid #F1F5F9', background:'#fff'}}>
            {['Inicio','Ventas','Compras','Productos','Análisis'].map((l,i)=>(
              <span key={i} style={{padding:'0 12px', fontSize:13, fontWeight:500, color:'#64748B'}}>{l}</span>
            ))}
            <div style={{flex:1}}/>
            <div className="f-plex" style={{display:'flex', alignItems:'center', gap:7, height:30, padding:'0 14px', borderRadius:100, background:'rgba(0,133,255,0.08)', border:'1px solid rgba(0,133,255,0.35)', color:'#0085FF', fontSize:13, fontWeight:700, marginRight:6}}>
              {flIco('puzzle', 15, '#0085FF')}
              Flex
            </div>
          </div>
          <div style={{height:2, display:'flex'}}>
            {['#00C1FF','#FF6751','#56E16A','#FFDC18'].map((c,i)=><div key={i} style={{flex:1, background:c}}/>)}
          </div>

          {/* Fondo del contenido */}
          <div style={{position:'absolute', top:CONT_Y, left:0, right:0, bottom:0, background:'#F8FAFC'}}/>

          {/* ===== ESTADO 1 — dashboard de secciones ===== */}
          {dashO > 0 && (
            <div style={{position:'absolute', top:CONT_Y, left:0, right:0, bottom:0, opacity:dashO, transform:`scale(${lerp(1, 0.985, 1-dashO)})`}}>
              <div className="f-mono" style={{position:'absolute', top:92, left:32, fontSize:10, fontWeight:700, letterSpacing:2, color:'#94A3B8', textTransform:'uppercase'}}>Tus secciones</div>
              <div className="f-mono" style={{position:'absolute', top:92, right:32, fontSize:10, color:'#94A3B8'}}>3 nuevas esta semana</div>
              <div style={{position:'absolute', top:136, left:32, right:32, display:'grid', gridTemplateColumns:'repeat(4, 1fr)', gap:18}}>
                {CARDS.map((c,i)=>{
                  const isTarget = c.n === 'Partidas';
                  const glowP = isTarget ? clamp((t-0.85)/0.35, 0, 1) : 0;
                  const pressed = isTarget && t >= clickCardAt && t < clickCardAt + 0.2;
                  return (
                    <div key={i} style={{
                      position:'relative', height:150, background:'#fff', borderRadius:12, padding:'18px 18px 0',
                      border:`1px solid ${glowP > 0 ? `rgba(0,133,255,${0.15+glowP*0.45})` : '#E2E8F0'}`,
                      boxShadow:`0 ${6+glowP*8}px ${18+glowP*16}px rgba(0,133,255,${0.05+glowP*0.14})`,
                      transform: pressed ? 'scale(0.97)' : 'scale(1)',
                    }}>
                      <div style={{width:40, height:40, borderRadius:10, background: c.nueva ? 'rgba(0,133,255,0.10)' : '#F1F5F9', display:'flex', alignItems:'center', justifyContent:'center', marginBottom:12}}>
                        {flIco(c.ic, 21, c.nueva ? '#0085FF' : '#475569')}
                      </div>
                      <div className="f-plex" style={{fontSize:15.5, fontWeight:700, color:'#0F172A', letterSpacing:'-0.01em'}}>{c.n}</div>
                      <div style={{fontSize:12, color:'#64748B', marginTop:3}}>{c.dato}</div>
                      {c.nueva && (
                        <span className="f-mono" style={{position:'absolute', top:12, right:12, fontSize:8, fontWeight:700, letterSpacing:1.2, color:'#059669', background:'rgba(16,185,129,0.10)', border:'1px solid rgba(16,185,129,0.25)', borderRadius:100, padding:'3px 7px'}}>NUEVA</span>
                      )}
                    </div>
                  );
                })}
              </div>
            </div>
          )}

          {/* ===== ESTADO 2 — el listado de Partidas ===== */}
          {t >= 1.7 && (
            <div style={{position:'absolute', top:CONT_Y, left:0, right:0, bottom:0, opacity:listP, transform:`translateY(${(1-listE)*10}px)`}}>

              {/* Cabecera de página */}
              <div style={{position:'absolute', left:32, top:26, display:'flex', gap:14, alignItems:'center'}}>
                <div style={{width:44, height:44, borderRadius:11, background:'rgba(0,133,255,0.10)', display:'flex', alignItems:'center', justifyContent:'center', flexShrink:0}}>
                  {flIco('partidas', 23, '#0085FF')}
                </div>
                <div>
                  <div style={{display:'flex', alignItems:'center', gap:8}}>
                    <span className="f-plex" style={{fontSize:21, fontWeight:700, color:'#0F172A', letterSpacing:'-0.02em'}}>Partidas</span>
                    <span className="f-mono" style={{fontSize:8.5, fontWeight:700, letterSpacing:1.4, color:'#0085FF', background:'rgba(0,133,255,0.08)', border:'1px solid rgba(0,133,255,0.28)', borderRadius:100, padding:'3px 8px'}}>FLEX</span>
                  </div>
                  <div style={{fontSize:11.5, color:'#64748B', marginTop:2}}>Hoy · 6 registros</div>
                </div>
              </div>

              {/* Chip de filtro activo + contador */}
              {t >= chipAt && (()=>{
                const p = clamp((t-chipAt)/0.4, 0, 1);
                const e = Easing.easeOutBack(p);
                const cp = clamp((t-counterAt)/0.4, 0, 1);
                return (
                  <div style={{position:'absolute', left:330, top:36, display:'flex', alignItems:'center', gap:12, opacity:clamp(p*1.3,0,1), transform:`scale(${lerp(0.8,1,e)})`}}>
                    <span className="f-plex" style={{display:'inline-flex', alignItems:'center', gap:7, height:28, padding:'0 12px', borderRadius:100, background:'rgba(0,133,255,0.08)', border:'1px solid rgba(0,133,255,0.35)', color:'#0085FF', fontSize:12, fontWeight:700}}>
                      {flIco('filtrar', 12, '#0085FF')}
                      Pista = 4
                      <span style={{fontSize:13, fontWeight:400, opacity:0.6, marginLeft:2}}>×</span>
                    </span>
                    {t >= counterAt && (
                      <span className="f-mono" style={{fontSize:11.5, color:'#64748B', opacity:cp}}>3 de 6 partidas</span>
                    )}
                  </div>
                );
              })()}

              {/* Toolbar */}
              <div style={{position:'absolute', right:32, top:30, display:'flex', gap:10}}>
                {toolBtn('Columnas', 'columnas', 128, colPanelP > 0, t >= colClickAt && t < colClickAt+0.2, false)}
                {toolBtn('Filtrar', 'filtrar', 110, fltPanelP > 0, t >= fltClickAt && t < fltClickAt+0.2, false)}
                {toolBtn('Exportar CSV', 'exportar', 158, false, t >= exportAt && t < exportAt+0.2, true)}
              </div>

              {/* Tabla */}
              <div style={{position:'absolute', left:32, right:32, top:96, background:'#fff', border:'1px solid #E2E8F0', borderRadius:10, overflow:'hidden', boxShadow:'0 6px 18px rgba(15,23,42,0.05)'}}>
                <div style={{display:'flex', alignItems:'center', height:42, padding:'0 16px', background:'#F1F5F9', borderBottom:'1px solid #E2E8F0'}}>
                  {COLS.map(c => cell(c, <span className="f-mono" style={{fontSize:10, fontWeight:700, letterSpacing:1.2, color:'#64748B', textTransform:'uppercase'}}>{c.h}</span>))}
                </div>
                {ROWS.map((r,i)=>{
                  const entP = Easing.easeOutCubic(clamp((t-(rowsAt+i*0.17))/0.35, 0, 1));
                  const match = r.pista === 4;
                  const fadeP = match ? 0 : clamp((t-8.35)/0.5, 0, 1);
                  const collP = match ? 0 : Easing.easeInOutCubic(clamp((t-8.65)/0.6, 0, 1));
                  const h = lerp(54, 0, collP);
                  const rowO = entP * (1-fadeP);
                  if (h < 0.5) return null;
                  return (
                    <div key={i} style={{display:'flex', alignItems:'center', height:h, padding:'0 16px', overflow:'hidden', borderBottom:`1px solid rgba(226,232,240,${0.9*(1-collP)})`, opacity:rowO, transform:`translateY(${(1-entP)*8}px)`}}>
                      {cell(COLS[0], <span className="f-mono" style={{fontSize:12.5, color:'#334155'}}>{r.hora}</span>)}
                      {cell(COLS[1], (
                        <span style={{display:'inline-flex', alignItems:'center', gap:10}}>
                          <span className="f-plex" style={{width:26, height:26, borderRadius:100, background:'#F1F5F9', color:'#475569', display:'inline-flex', alignItems:'center', justifyContent:'center', fontSize:9.5, fontWeight:700, flexShrink:0}}>{r.ini}</span>
                          <span style={{fontSize:13, fontWeight:600, color:'#0F172A'}}>{r.jug}</span>
                        </span>
                      ))}
                      {cell(COLS[2], filterOn && match
                        ? <span className="f-plex" style={{display:'inline-block', padding:'3px 10px', borderRadius:100, background:'rgba(0,133,255,0.08)', border:'1px solid rgba(0,133,255,0.30)', color:'#0085FF', fontSize:11.5, fontWeight:700}}>Pista {r.pista}</span>
                        : <span style={{fontSize:13, color:'#334155'}}>Pista {r.pista}</span>)}
                      {cell(COLS[3], <span className="f-mono" style={{fontSize:12.5, color:'#334155'}}>{r.njug}</span>)}
                      {cell(COLS[4], <span className="f-mono" style={{fontSize:12.5, fontWeight:600, color:'var(--dn-primary)'}}>{r.ticket}</span>)}
                      {cell(COLS[5], <span className="f-mono" style={{fontSize:13, fontWeight:700, color:'#0F172A'}}>{r.total}</span>)}
                    </div>
                  );
                })}
              </div>
            </div>
          )}

          {/* ===== Panel Columnas (dropdown) ===== */}
          {colPanelP > 0 && (()=>{
            const e = Easing.easeOutCubic(colPanelP);
            const items = [
              { n:'Hora',         on:true },
              { n:'Jugador',      on:true },
              { n:'Pista',        on:true },
              { n:'Nº jugadores', on: t < njugOffAt, hl:[5.25,5.7] },
              { n:'Ticket',       on:true },
              { n:'Total',        on: t >= totalOnAt, hl:[4.42,4.9] },
              { n:'Duración',     on:false },
            ];
            return (
              <div style={{position:'absolute', left:870, top:252, width:250, background:'#fff', border:'1px solid #E2E8F0', borderRadius:12, boxShadow:'0 20px 50px rgba(15,23,42,0.16)', padding:'8px 0', zIndex:8, opacity:colPanelP, transform:`translateY(${(1-e)*-8}px) scale(${lerp(0.97,1,e)})`}}>
                <div className="f-mono" style={{height:36, display:'flex', alignItems:'center', padding:'0 16px', fontSize:9, fontWeight:700, letterSpacing:1.8, color:'#94A3B8', textTransform:'uppercase', borderBottom:'1px solid #F1F5F9'}}>Columnas visibles</div>
                {items.map((it,i)=>{
                  const hov = it.hl && t >= it.hl[0] && t < it.hl[1];
                  return (
                    <div key={i} style={{height:38, display:'flex', alignItems:'center', gap:11, padding:'0 14px', background: hov ? 'rgba(0,133,255,0.06)' : 'transparent'}}>
                      {checkbox(it.on)}
                      <span style={{fontSize:12.5, color:'#0F172A', fontWeight: it.on ? 600 : 400, opacity: it.on ? 1 : 0.65}}>{it.n}</span>
                    </div>
                  );
                })}
              </div>
            );
          })()}

          {/* ===== Panel Filtrar (dropdown) ===== */}
          {fltPanelP > 0 && (()=>{
            const e = Easing.easeOutCubic(fltPanelP);
            const opts = [
              { n:'Pista 1', c:'1' },
              { n:'Pista 2', c:'1' },
              { n:'Pista 3', c:'1' },
              { n:'Pista 4', c:'3', target:true },
            ];
            return (
              <div style={{position:'absolute', left:980, top:252, width:260, background:'#fff', border:'1px solid #E2E8F0', borderRadius:12, boxShadow:'0 20px 50px rgba(15,23,42,0.16)', padding:'8px 0', zIndex:8, opacity:fltPanelP, transform:`translateY(${(1-e)*-8}px) scale(${lerp(0.97,1,e)})`}}>
                <div className="f-mono" style={{height:36, display:'flex', alignItems:'center', padding:'0 16px', fontSize:9, fontWeight:700, letterSpacing:1.8, color:'#94A3B8', textTransform:'uppercase', borderBottom:'1px solid #F1F5F9'}}>Filtrar por · Pista</div>
                {opts.map((o,i)=>{
                  const sel = o.target && t >= pista4At;
                  const hov = o.target && t >= 7.72 && t < pista4At;
                  return (
                    <div key={i} style={{height:40, display:'flex', alignItems:'center', gap:10, padding:'0 16px', background: sel ? 'var(--dn-primary)' : hov ? 'rgba(0,133,255,0.07)' : 'transparent'}}>
                      <span style={{fontSize:12.5, fontWeight:600, color: sel ? '#fff' : '#0F172A'}}>{o.n}</span>
                      <div style={{flex:1}}/>
                      <span className="f-mono" style={{fontSize:10.5, color: sel ? 'rgba(255,255,255,0.75)' : '#94A3B8'}}>{o.c}</span>
                    </div>
                  );
                })}
              </div>
            );
          })()}

          {/* ===== Toast exportación ===== */}
          {t >= toastAt && (()=>{
            const p = clamp((t-toastAt)/0.5, 0, 1);
            const e = Easing.easeOutBack(p);
            return (
              <div style={{position:'absolute', right:24, bottom:24, display:'flex', alignItems:'center', gap:12, padding:'12px 18px 12px 12px', background:'#fff', border:'1px solid #E2E8F0', borderRadius:12, boxShadow:'0 16px 44px rgba(15,23,42,0.16)', zIndex:9, opacity:clamp(p*1.3,0,1), transform:`translateY(${(1-e)*22}px)`}}>
                <div style={{width:36, height:36, borderRadius:10, background:'rgba(16,185,129,0.12)', display:'flex', alignItems:'center', justifyContent:'center', flexShrink:0}}>
                  {flIco('check', 18, '#059669')}
                </div>
                <div>
                  <div className="f-plex" style={{fontSize:13, fontWeight:700, color:'#0F172A'}}>partidas.csv descargado</div>
                  <div className="f-mono" style={{fontSize:10, color:'#64748B', marginTop:2}}>3 filas · listo en Descargas</div>
                </div>
              </div>
            );
          })()}
        </div>

        {/* Cursor */}
        {t >= 0.45 && <CineCursor x={cur.x} y={cur.y} clicking={clicking}/>}
      </div>

      {/* ===== Claim final ===== */}
      {t >= claimAt && (()=>{
        const eyeP = clamp((t-(claimAt+0.05))/0.5, 0, 1);
        const hP   = Easing.easeOutCubic(clamp((t-(claimAt+0.2))/0.8, 0, 1));
        const recP = clamp((t-(claimAt+1.4))/0.6, 0, 1);
        return (
          <div style={{position:'absolute', left:0, right:0, top:426, textAlign:'center', zIndex:40}}>
            {/* Velo blanco suave para despegar el claim de la ventana atenuada */}
            <div style={{position:'absolute', left:360, right:360, top:-90, height:380, background:'radial-gradient(ellipse 60% 60% at 50% 48%, rgba(255,255,255,0.94), transparent 72%)', opacity:claimE, pointerEvents:'none'}}/>
            <div className="f-mono" style={{position:'relative', fontSize:12, fontWeight:700, letterSpacing:4, color:'#0085FF', textTransform:'uppercase', opacity:eyeP}}>Dinaup Flex</div>
            <div className="f-plex" style={{position:'relative', fontSize:64, fontWeight:700, letterSpacing:'-0.035em', color:'#0F172A', lineHeight:1.1, marginTop:18, opacity:hP, transform:`translateY(${(1-hP)*16}px)`}}>
              Tus datos, <span className="grad-text">a tu manera.</span>
            </div>
            <div className="f-mono" style={{position:'relative', fontSize:13, color:'#94A3B8', letterSpacing:1.5, marginTop:26, opacity:recP}}>Columnas · Filtros · Exportación</div>
          </div>
        );
      })()}

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

Object.assign(window, { SlideFlexListado });
