// === Escena 01 — "Mi día" (contrato) ===
// La portada del módulo comercial: la tarjeta «Mi día» con sus filas «Hoy HH:mm» + minutos +
// título, el estado vacío POR SUSTITUCIÓN (son las dos ramas del if de Dashboard:31/52 y el
// producto no puede pintarlas juntas), los dos botones de alta, el botón «Modo guía» y las seis
// píldoras todavía sin valor. Cierra con La Única Cosa como PROMESA.
function EscenaPN01({ t }){
  // LOCUCIÓN (audio/escena-01.mp3): abres por la mañana → la portada → lo primero es tu día →
  // hora y duración → agenda libre por hoy → dos botones para crear → la mitad de arriba →
  // debajo hay seis números → LA ÚNICA COSA (promesa).
  const T = {
    head:0.0,        // "Abres por la mañana" -> eyebrow EL PANEL · CÓMO SE LEE + título
    portada:4.6,    // "la portada del módulo comercial" -> la ventana entera entra
    midia:7.6,      // "Lo primero que ves es tu día" -> «Mi día» al frente, lo demás se atenúa
    filas:10.8,     // "con su hora y su duración" -> las 3 filas de agenda en cascada
    filaStep:0.16,   // (incremento entre filas de la cascada)
    vacio:15.5,     // "agenda libre por hoy" -> las 3 filas SE SUSTITUYEN por el estado vacío
    vacioDur:1.35,   // (cuánto dura la sustitución antes de que vuelvan las filas)
    botones:18.0,   // "dos botones para crear" -> «Oportunidad» y «Evento» se iluminan
    mitad:21.0,     // "Eso es la mitad de arriba" -> «Mi día» baja a 0.34; foco en «Modo guía»
    pildoras:23.1,  // "Debajo hay seis números" -> las 6 píldoras, en gris y sin valor
    unica1:26.0,    // "De los seis, dos traen lista" -> ÚNICA COSA mitad 1 (promesa)
    unica2:28.4,    // "Esa lista es el trabajo de hoy" -> ÚNICA COSA mitad 2, queda fija
  };

  // ── Maqueta (13/08/2026, sesión de Nuria Peláez). Fecha legible = «Hoy HH:mm» (RegionService:71-85) ──
  const AGENDA = [
    { hora:'Hoy 10:00', min:'45 min.', txt:'Llamada de seguimiento - Envases Duero' },
    { hora:'Hoy 12:30', min:'60 min.', txt:'Visita técnica - Talleres Ordás' },
    { hora:'Hoy 16:00', min:'30 min.', txt:'Demostración - Cerámicas Vall' },
  ];
  // Los seis marcadores, con su color literal del marcado (Dashboard:63-68)
  const PILLS = [
    { k:'payments',       tit:'Pipeline Total',   col:'#2e7d32' },
    { k:'balance',        tit:'Ponderado',        col:'#1565c0' },
    { k:'handshake',      tit:'Abiertas',         col:'#6a1b9a' },
    { k:'event_upcoming', tit:'Cierre Este Mes',  col:'#e65100' },
    { k:'warning',        tit:'Estancadas',       col:'#bf360c' },
    { k:'event_busy',     tit:'Sin evento',       col:'#ff6f00' },
  ];

  const Ico = ({ n, s=24, c='#0F172A', w=2 })=>{
    const P = {
      today:<><rect x="3" y="5" width="18" height="16" rx="2.5"/><path d="M3 10 H21"/><path d="M8 3 V7 M16 3 V7"/></>,
      event:<><rect x="3" y="5" width="18" height="16" rx="2.5"/><path d="M3 10 H21"/><path d="M8 3 V7 M16 3 V7"/><path d="M7.5 14 H11 M7.5 17.5 H15"/></>,
      event_available:<><rect x="3" y="5" width="18" height="16" rx="2.5"/><path d="M3 10 H21"/><path d="M8 3 V7 M16 3 V7"/><path d="M8.5 15.5 L11 18 L16 13"/></>,
      event_upcoming:<><rect x="3" y="5" width="18" height="16" rx="2.5"/><path d="M3 10 H21"/><path d="M8 3 V7 M16 3 V7"/><path d="M12 18.5 V13 M9.6 15.2 L12 12.8 L14.4 15.2"/></>,
      event_busy:<><rect x="3" y="5" width="18" height="16" rx="2.5"/><path d="M3 10 H21"/><path d="M8 3 V7 M16 3 V7"/><path d="M9.5 13.5 L14.5 18.5 M14.5 13.5 L9.5 18.5"/></>,
      warning:<><path d="M12 3.6 L21.4 19.6 H2.6 Z"/><path d="M12 9.6 V14"/><circle cx="12" cy="16.9" r="0.9" fill={c} stroke="none"/></>,
      payments:<><rect x="2.2" y="7.6" width="15.6" height="10.8" rx="2"/><circle cx="10" cy="13" r="2.5"/><path d="M6 5.2 H19.8 A2 2 0 0 1 21.8 7.2 V15.4"/></>,
      balance:<><path d="M12 4 V20 M6.5 20 H17.5 M3.6 8.4 H20.4"/><path d="M3.6 8.4 L1.2 14.4 H6 Z"/><path d="M20.4 8.4 L18 14.4 H22.8 Z"/></>,
      handshake:<><path d="M12.4 9.2 L9.6 6.4 A2 2 0 0 0 6.8 6.4 L2.6 10.6 A2 2 0 0 0 2.6 13.4 L4.6 15.4"/><path d="M11.6 9.2 L14.4 6.4 A2 2 0 0 1 17.2 6.4 L21.4 10.6 A2 2 0 0 1 21.4 13.4 L19.4 15.4"/><path d="M7.6 12.6 L11 16 A1.8 1.8 0 0 0 13.6 16 L16.6 12.8"/></>,
      school:<><path d="M12 4 L22 8.6 L12 13.2 L2 8.6 Z"/><path d="M6.4 10.6 V15.6 C6.4 17.2 9 18.6 12 18.6 C15 18.6 17.6 17.2 17.6 15.6 V10.6"/></>,
      plus:<><path d="M12 5 V19 M5 12 H19"/></>,
    };
    return <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke={c} strokeWidth={w} strokeLinecap="round" strokeLinejoin="round">{P[n]}</svg>;
  };

  // ── Progresos ──
  const wnP = clamp((t-T.portada)/0.85,0,1), wnE = Easing.easeOutCubic(wnP);
  const mdP = clamp((t-T.midia)/0.65,0,1), mdE = Easing.easeOutBack(mdP);
  const dimOtros = clamp((t-T.midia)/0.7,0,1);
  const vaIn  = clamp((t-T.vacio)/0.32,0,1);
  const vaOut = clamp((t-T.vacio-T.vacioDur)/0.32,0,1);
  const vacio = clamp(vaIn - vaOut, 0, 1);
  const btP = clamp((t-T.botones)/0.5,0,1), btE = Easing.easeOutBack(btP);
  const btGlow = t >= T.botones && t < T.botones+1.2 ? Math.sin((t-T.botones)/1.2*Math.PI) : 0;
  const mtP = clamp((t-T.mitad)/0.6,0,1);
  const guiaE = Easing.easeOutBack(clamp((t-T.mitad)/0.5,0,1));
  const guiaGlow = t >= T.mitad && t < T.mitad+1.2 ? Math.sin((t-T.mitad)/1.2*Math.PI) : 0;
  const plP = clamp((t-T.pildoras)/0.6,0,1);

  const opMidia  = wnE * lerp(1, 0.34, mtP);
  const opPills  = wnE * lerp(lerp(1, 0.40, dimOtros), 1, plP);
  const opListas = wnE * lerp(1, 0.26, dimOtros);
  const opGuia   = wnE * lerp(lerp(1, 0.40, dimOtros), 1, mtP);

  // Acto final · La Única Cosa (promesa)
  const veloOp = t < T.unica1 ? 0 : clamp((t-T.unica1)/0.7,0,1)*0.94;
  const u1P = clamp((t-T.unica1)/0.6,0,1), u1E = Easing.easeOutCubic(u1P);
  const u2P = clamp((t-T.unica2)/0.6,0,1), u2E = Easing.easeOutCubic(u2P);

  // ── Una fila de la agenda: fecha legible · minutos si > 0 · texto principal (Dashboard:36-47) ──
  const FilaAgenda = ({ a, i })=>{
    const p = clamp((t-T.filas-i*T.filaStep)/0.5,0,1), e = Easing.easeOutCubic(p);
    return (
      <div style={{display:'flex', alignItems:'center', gap:22, height:80, padding:'0 26px',
                   borderBottom:i < 2 ? '1px solid #EEF2F6' : 'none',
                   opacity:e, transform:`translateY(${(1-e)*14}px)`}}>
        <Ico n="event" s={30} c="#2196f3" w={1.9}/>
        <span className="f-mono" style={{fontSize:25, fontWeight:600, color:'#0F172A', minWidth:150}}>{a.hora}</span>
        <span className="f-plex" style={{fontSize:21, color:'#94A3B8', minWidth:96}}>{a.min}</span>
        <span className="f-plex" style={{fontSize:27, color:'#0F172A'}}>{a.txt}</span>
      </div>
    );
  };

  // ── Píldora compacta: icono + valor + título (KpiCard:62-76). Aquí todavía sin valor ──
  const Pildora = ({ p })=>(
    <div style={{height:120, display:'flex', alignItems:'center', gap:14, padding:'0 22px',
                 background:'#fff', border:'1px solid #E2E8F0', borderRadius:14}}>
      <Ico n={p.k} s={58} c="#CBD5E1" w={1.7}/>
      <div style={{lineHeight:1.15}}>
        <div style={{width:Math.max(74, p.tit.length*9), height:34, borderRadius:8, background:'#EDF1F6'}}/>
        <div className="f-plex" style={{fontSize:22, color:'#94A3B8', marginTop:9, whiteSpace:'nowrap'}}>{p.tit}</div>
      </div>
    </div>
  );

  // ── Cabecera de una tarjeta de lista (solo se ve el borde superior en esta escena) ──
  const CabLista = ({ icon, tit, col })=>(
    <div style={{width:838, background:'#fff', border:'1px solid #E2E8F0', borderRadius:14, overflow:'hidden'}}>
      <div style={{display:'flex', alignItems:'center', gap:13, padding:'22px 26px', borderBottom:'1px solid #EEF2F6'}}>
        <Ico n={icon} s={28} c={col} w={2}/>
        <span className="f-plex" style={{fontSize:29, fontWeight:700, color:'#0F172A'}}>{tit}</span>
      </div>
      <div style={{height:120, padding:'0 26px', display:'flex', alignItems:'center'}}>
        <div style={{width:520, height:22, borderRadius:6, background:'#F1F5F9'}}/>
      </div>
    </div>
  );

  return (
    <SlideCanvas variant="light">
      <DemoHeader t={t} eyebrow="EL PANEL · CÓMO SE LEE" title={<span>Tu día, y seis números debajo</span>}/>

      {/* ─────────── La portada del módulo comercial ─────────── */}
      {wnP > 0 && (
        <div style={{position:'absolute', left:80, top:150, width:1760, height:866,
                     borderRadius:18, border:'1px solid #E2E8F0', background:'#F6F8FB',
                     boxShadow:'0 34px 84px rgba(15,23,42,0.13)', overflow:'hidden',
                     opacity:wnE*(1-veloOp/0.94*0.85), transform:`translateY(${(1-wnE)*26}px)`}}>
          <BrowserChrome url="play.dinaup.com/App/CRM" title="CRM — Dinaup"/>
          <DinaupAppHeader breadcrumb={["CRM","Inicio"]} company="Suministros del Norte, S.L." initials="NP"/>

          {/* Botón «Modo guía», arriba a la derecha (Dashboard:18-19) */}
          <div style={{position:'absolute', left:0, right:30, top:158, display:'flex', justifyContent:'flex-end',
                       opacity:opGuia}}>
            <span style={{display:'inline-flex', alignItems:'center', gap:10, padding:'10px 20px',
                          border:`1.6px solid ${0 < guiaGlow ? '#0085FF' : '#CBD5E1'}`, borderRadius:9, background:'#fff',
                          transform:`scale(${lerp(1, 1.06, mtP*guiaE)})`,
                          boxShadow:0 < guiaGlow ? `0 0 ${guiaGlow*30}px rgba(0,133,255,0.42)` : 'none'}}>
              <Ico n="school" s={22} c={0 < guiaGlow ? '#0085FF' : '#64748B'} w={1.9}/>
              <span className="f-plex" style={{fontSize:20, fontWeight:600, color:0 < guiaGlow ? '#0085FF' : '#334155'}}>Modo guía</span>
            </span>
          </div>

          {/* ── Tarjeta «Mi día» (Dashboard:23-29) ── */}
          <div style={{position:'absolute', left:30, top:216, width:1700,
                       background:'#fff', border:'1px solid #E2E8F0', borderRadius:16,
                       opacity:opMidia,
                       transform:`scale(${lerp(1, 1.012, mdE*(1-mtP))}) translateY(${(1-Easing.easeOutCubic(clamp((t-T.portada)/0.9,0,1)))*10}px)`,
                       boxShadow:mdP > 0 && mtP < 1 ? `0 ${lerp(4,30,mdE*(1-mtP))}px ${lerp(14,70,mdE*(1-mtP))}px rgba(15,23,42,${lerp(0.05,0.16,mdE*(1-mtP))})` : '0 2px 10px rgba(15,23,42,0.05)'}}>
            {/* Cabecera: icono today + «Mi día» + los dos botones de alta */}
            <div style={{display:'flex', alignItems:'center', gap:14, padding:'20px 26px', borderBottom:'1px solid #EEF2F6'}}>
              <Ico n="today" s={30} c="#0F172A" w={2}/>
              <span className="f-plex" style={{fontSize:30, fontWeight:700, color:'#0F172A'}}>Mi día</span>
              <div style={{flex:1}}/>
              {['Oportunidad','Evento'].map((b,i)=>(
                <span key={b} style={{display:'inline-flex', alignItems:'center', gap:8, padding:'9px 18px', marginLeft:12,
                                      border:`1.6px solid ${0 < btGlow ? '#0085FF' : '#CBD5E1'}`, borderRadius:9,
                                      background:0 < btGlow ? 'rgba(0,133,255,0.07)' : '#fff',
                                      transform:`scale(${lerp(1, 1.05, btE*(0 < btGlow ? 1 : 0))})`,
                                      boxShadow:0 < btGlow ? `0 0 ${btGlow*24}px rgba(0,133,255,0.35)` : 'none'}}>
                  <Ico n="plus" s={19} c={0 < btGlow ? '#0085FF' : '#64748B'} w={2.4}/>
                  <span className="f-plex" style={{fontSize:20, fontWeight:600, color:0 < btGlow ? '#0085FF' : '#334155'}}>{b}</span>
                </span>
              ))}
            </div>
            {/* Cuerpo: las 3 filas de hoy  ·  O  ·  «Agenda libre por hoy». Nunca a la vez */}
            <div style={{position:'relative', height:240}}>
              <div style={{position:'absolute', inset:0, opacity:1-vacio}}>
                {AGENDA.map((a,i)=> <FilaAgenda key={a.hora} a={a} i={i}/>)}
              </div>
              <div style={{position:'absolute', inset:0, display:'flex', alignItems:'center', justifyContent:'center', gap:16,
                           opacity:vacio, transform:`scale(${lerp(0.97,1,Easing.easeOutCubic(vacio))})`}}>
                <Ico n="event_available" s={40} c="#94A3B8" w={1.8}/>
                <span className="f-plex" style={{fontSize:32, color:'#64748B'}}>Agenda libre por hoy</span>
              </div>
            </div>
          </div>

          {/* ── Los seis marcadores, todavía en gris y sin valor ── */}
          <div style={{position:'absolute', left:30, top:560, width:1700, display:'flex', justifyContent:'space-between',
                       opacity:opPills}}>
            {PILLS.map(p => <Pildora key={p.tit} p={p}/>)}
          </div>

          {/* ── Las dos tarjetas de lista, asomando por el pie de la ventana ── */}
          <div style={{position:'absolute', left:30, top:702, width:1700, display:'flex', gap:24, opacity:opListas}}>
            <CabLista icon="event_upcoming" tit="Cierre Este Mes" col="#e65100"/>
            <CabLista icon="warning" tit="Oportunidades Estancadas" col="#bf360c"/>
          </div>
        </div>
      )}

      {/* ─────────── La Única Cosa · PROMESA ─────────── */}
      {veloOp > 0 && <div style={{position:'absolute', inset:0, background:'#fff', opacity:veloOp}}/>}
      {u1P > 0 && (
        <div className="f-plex" style={{position:'absolute', left:0, right:0, top:412, textAlign:'center', fontSize:72, fontWeight:800,
                                        letterSpacing:'-0.03em', color:'#0F172A', opacity:u1E, transform:`translateY(${(1-u1E)*18}px)`}}>
          De los seis números, dos traen lista.
        </div>
      )}
      {u2P > 0 && (
        <div className="f-plex" style={{position:'absolute', left:0, right:0, top:524, textAlign:'center', fontSize:72, fontWeight:800,
                                        letterSpacing:'-0.03em', opacity:u2E, transform:`translateY(${(1-u2E)*18}px)`}}>
          <span className="grad-text">Esa lista es el trabajo de hoy.</span>
        </div>
      )}
    </SlideCanvas>
  );
}
Object.assign(window, { EscenaPN01 });
