/* global React */
const { useState, useEffect, useRef } = React;

// ── Shared frame components (local to this file) ──────────────────────────────

function PPPhone({ children }) {
  return (
    <div style={{
      width: 260, height: 520,
      background: "oklch(0.11 0.03 250)",
      borderRadius: 40,
      border: "7px solid oklch(0.20 0.04 250)",
      boxShadow: "0 0 0 1px oklch(0.28 0.04 250), 0 50px 100px -20px oklch(0.08 0.04 250 / 0.7), inset 0 1px 0 oklch(0.30 0.04 250)",
      position: "relative", overflow: "hidden", flexShrink: 0,
    }}>
      <div style={{ position:"absolute", top:0, left:"50%", transform:"translateX(-50%)", width:78, height:24, background:"oklch(0.11 0.03 250)", borderRadius:"0 0 16px 16px", zIndex:10 }} />
      <div style={{ display:"flex", justifyContent:"space-between", alignItems:"center", padding:"7px 20px 0", fontSize:9, fontFamily:"var(--font-mono)", color:"oklch(0.60 0.03 240)", position:"relative", zIndex:5 }}>
        <span>9:41</span><span>●●● ▲</span>
      </div>
      <div style={{ position:"absolute", inset:0, top:30, overflowY:"hidden" }}>{children}</div>
      <div style={{ position:"absolute", bottom:9, left:"50%", transform:"translateX(-50%)", width:88, height:4, background:"oklch(0.30 0.03 250)", borderRadius:2 }} />
    </div>
  );
}

function PPBrowser({ children, url = "app.gropp.tech" }) {
  return (
    <div style={{
      width: 480, height: 340,
      background: "oklch(0.97 0.005 240)",
      borderRadius: 12,
      border: "1px solid oklch(0.82 0.02 240)",
      boxShadow: "0 4px 6px -1px oklch(0.50 0.06 240 / 0.07), 0 30px 80px -20px oklch(0.45 0.08 240 / 0.18)",
      overflow: "hidden", flexShrink: 0,
    }}>
      <div style={{ background:"oklch(0.93 0.006 240)", borderBottom:"1px solid oklch(0.86 0.01 240)", padding:"9px 14px", display:"flex", alignItems:"center", gap:8 }}>
        <div style={{ display:"flex", gap:5 }}>
          {["oklch(0.68 0.14 25)","oklch(0.73 0.14 80)","oklch(0.63 0.17 145)"].map((c,i)=>(
            <div key={i} style={{ width:11, height:11, borderRadius:"50%", background:c }} />
          ))}
        </div>
        <div style={{ flex:1, background:"oklch(0.97 0.005 240)", border:"1px solid oklch(0.86 0.01 240)", borderRadius:5, padding:"3px 11px", fontFamily:"var(--font-mono)", fontSize:9.5, color:"oklch(0.50 0.03 240)", letterSpacing:"0.04em" }}>
          {url}
        </div>
      </div>
      <div style={{ height:"calc(100% - 40px)", overflow:"hidden" }}>{children}</div>
    </div>
  );
}

// ── Driver App mock — 4 screens ───────────────────────────────────────────────

function DriverAppMock({ isEs }) {
  const [screen, setScreen] = useState(0);
  const screens = isEs
    ? ["Ruta", "Parada", "Entrega", "Copiloto"]
    : ["Route", "Stop", "POD", "Copilot"];

  useEffect(() => {
    const id = setInterval(() => setScreen(s => (s + 1) % 4), 3000);
    return () => clearInterval(id);
  }, []);

  return (
    <div style={{ height:"100%", display:"flex", flexDirection:"column", background:"oklch(0.12 0.03 250)" }}>
      {/* screen switcher tabs */}
      <div style={{ display:"flex", borderBottom:"1px solid oklch(0.20 0.03 250)", flexShrink:0 }}>
        {screens.map((s, i) => (
          <button key={i} onClick={() => setScreen(i)} style={{
            flex:1, padding:"6px 0", fontSize:8.5, fontFamily:"var(--font-mono)", letterSpacing:"0.06em",
            background: i===screen ? "oklch(0.18 0.04 250)" : "transparent",
            color: i===screen ? "var(--accent)" : "oklch(0.42 0.03 240)",
            border:"none", borderBottom: i===screen ? "1.5px solid var(--accent)" : "1.5px solid transparent",
            cursor:"pointer", transition:"all .2s",
          }}>{s}</button>
        ))}
      </div>

      {/* screens */}
      <div style={{ flex:1, position:"relative", overflow:"hidden" }}>
        {screen === 0 && <DARouteScreen isEs={isEs} />}
        {screen === 1 && <DAStopScreen isEs={isEs} />}
        {screen === 2 && <DAPodScreen isEs={isEs} />}
        {screen === 3 && <DAVoiceScreen isEs={isEs} />}
      </div>
    </div>
  );
}

function DARouteScreen({ isEs }) {
  const [dot, setDot] = useState(0);
  useEffect(() => { const id = setInterval(() => setDot(d=>(d+1)%40), 80); return ()=>clearInterval(id); }, []);
  const stops = [[50,130],[100,90],[180,60],[220,35]];
  const progress = Math.min(dot/39, 1);
  const px = 50 + progress*(220-50), py = 130 + progress*(35-130);
  return (
    <div style={{ height:"100%", display:"flex", flexDirection:"column" }}>
      <div style={{ flex:1, background:"oklch(0.17 0.035 245)", position:"relative" }}>
        <svg viewBox="0 0 260 200" style={{ width:"100%", height:"100%" }}>
          {[40,70,100,130,160].map(y=><line key={y} x1={0} y1={y} x2={260} y2={y} stroke="oklch(0.23 0.03 240)" strokeWidth={1}/>)}
          {[50,100,150,200].map(x=><line key={x} x1={x} y1={0} x2={x} y2={200} stroke="oklch(0.23 0.03 240)" strokeWidth={1}/>)}
          <polyline points="50,130 100,90 180,60 220,35" fill="none" stroke="oklch(0.40 0.04 240)" strokeWidth={3} strokeLinecap="round"/>
          <polyline points="50,130 100,90 180,60 220,35" fill="none" stroke="var(--accent)" strokeWidth={2.5} strokeLinecap="round" strokeDasharray={`${progress*400} 400`}/>
          {stops.map(([x,y],i)=>(
            <g key={i}>
              <circle cx={x} cy={y} r={i===0?7:5.5} fill={i===0?"var(--accent)":"oklch(0.28 0.04 250)"} stroke={i===0?"var(--accent)":"oklch(0.42 0.08 240)"} strokeWidth={1.5}/>
              <text x={x+9} y={y+4} fontSize={7.5} fontFamily="var(--font-mono)" fill="oklch(0.70 0.03 240)">#{i+1}</text>
            </g>
          ))}
          <circle cx={px} cy={py} r={8} fill="var(--accent)" opacity={0.18}/>
          <circle cx={px} cy={py} r={4.5} fill="var(--accent)"/>
          <text x={8} y={188} fontSize={8} fontFamily="var(--font-mono)" fill="oklch(0.50 0.03 240)">ETA 14:32 · 3.2 km</text>
        </svg>
      </div>
      <div style={{ padding:"10px 14px", display:"flex", justifyContent:"space-between", alignItems:"center", borderTop:"1px solid oklch(0.20 0.03 250)" }}>
        <div>
          <div style={{ fontFamily:"var(--font-mono)", fontSize:7.5, color:"oklch(0.42 0.03 240)", letterSpacing:"0.08em" }}>{isEs?"PRÓXIMA PARADA":"NEXT STOP"}</div>
          <div style={{ fontSize:11, fontWeight:500, color:"oklch(0.88 0.02 240)", marginTop:1 }}>Av. Italia 3421</div>
        </div>
        <div style={{ background:"var(--accent)", borderRadius:6, padding:"6px 12px", fontSize:9.5, color:"white", fontWeight:500 }}>→ Nav</div>
      </div>
    </div>
  );
}

function DAStopScreen({ isEs }) {
  const [checked, setChecked] = useState([false,false,false]);
  useEffect(() => {
    const id = setInterval(() => setChecked(c => {
      const idx = c.findIndex(v=>!v); if(idx<0) return [false,false,false];
      return c.map((v,i)=>i<=idx?true:v);
    }), 1000);
    return ()=>clearInterval(id);
  }, []);
  const tasks = isEs
    ? ["Tocar timbre / portero","Verificar dirección","Tomar foto de entrega"]
    : ["Ring bell / doorman","Verify address","Capture delivery photo"];
  return (
    <div style={{ height:"100%", padding:"14px", display:"flex", flexDirection:"column", gap:10 }}>
      <div style={{ background:"oklch(0.18 0.04 250)", borderRadius:8, padding:"10px 12px" }}>
        <div style={{ fontFamily:"var(--font-mono)", fontSize:7.5, color:"var(--accent)", letterSpacing:"0.1em", marginBottom:4 }}>PARADA #3</div>
        <div style={{ fontSize:12, fontWeight:500, color:"oklch(0.88 0.02 240)" }}>Av. Italia 3421</div>
        <div style={{ fontSize:10, color:"oklch(0.50 0.03 240)", marginTop:2 }}>Gabriela Pereyra · Apto 802</div>
        <div style={{ marginTop:6, fontSize:9, color:"oklch(0.55 0.04 240)", fontStyle:"italic" }}>
          {isEs?"Notas: dejar con portero si no responde":"Notes: leave with doorman if no answer"}
        </div>
      </div>
      <div style={{ fontFamily:"var(--font-mono)", fontSize:8, color:"oklch(0.42 0.03 240)", letterSpacing:"0.1em" }}>CHECKLIST</div>
      {tasks.map((t,i)=>(
        <div key={i} style={{ display:"flex", alignItems:"center", gap:9, transition:"opacity .4s", opacity:checked[i]?0.5:1 }}>
          <div style={{ width:15, height:15, borderRadius:"50%", border:`1.5px solid ${checked[i]?"oklch(0.62 0.18 145)":"var(--accent)"}`, display:"flex", alignItems:"center", justifyContent:"center", flexShrink:0, background:checked[i]?"oklch(0.62 0.18 145 / 0.15)":"transparent", transition:"all .3s" }}>
            {checked[i] && <div style={{ width:6, height:6, borderRadius:"50%", background:"oklch(0.62 0.18 145)" }}/>}
          </div>
          <span style={{ fontSize:10.5, color:checked[i]?"oklch(0.40 0.03 240)":"oklch(0.82 0.02 240)", textDecoration:checked[i]?"line-through":"none", transition:"all .3s" }}>{t}</span>
        </div>
      ))}
      <div style={{ marginTop:"auto", display:"flex", gap:8 }}>
        <div style={{ flex:1, background:"oklch(0.18 0.04 250)", borderRadius:7, padding:"8px", textAlign:"center", fontSize:9.5, color:"oklch(0.60 0.03 240)" }}>
          {isEs?"Llamar cliente":"Call client"}
        </div>
        <div style={{ flex:1, background:"var(--accent)", borderRadius:7, padding:"8px", textAlign:"center", fontSize:9.5, color:"white", fontWeight:500 }}>
          {isEs?"Iniciar POD":"Start POD"}
        </div>
      </div>
    </div>
  );
}

function DAPodScreen({ isEs }) {
  const [step, setStep] = useState(0);
  useEffect(() => { const id = setInterval(()=>setStep(s=>Math.min(s+1,3)), 1200); return ()=>clearInterval(id); },[]);
  return (
    <div style={{ height:"100%", display:"flex", flexDirection:"column", padding:14, gap:10 }}>
      <div style={{ fontFamily:"var(--font-mono)", fontSize:8, color:"var(--accent)", letterSpacing:"0.1em" }}>
        {isEs?"PRUEBA DE ENTREGA":"PROOF OF DELIVERY"}
      </div>
      {/* photo area */}
      <div style={{ background:"oklch(0.17 0.04 245)", borderRadius:8, height:90, display:"flex", alignItems:"center", justifyContent:"center", position:"relative", overflow:"hidden", border: step>=1?"1.5px solid oklch(0.62 0.18 145)":"1.5px solid oklch(0.25 0.04 250)", transition:"border .4s" }}>
        {step<1
          ? <div style={{ textAlign:"center" }}>
              <div style={{ fontSize:20, marginBottom:4 }}>📷</div>
              <div style={{ fontSize:9, fontFamily:"var(--font-mono)", color:"oklch(0.42 0.03 240)" }}>{isEs?"Tomar foto":"Take photo"}</div>
            </div>
          : <>
              <svg viewBox="0 0 200 90" style={{ width:"100%", height:"100%" }}>
                <rect width={200} height={90} fill="oklch(0.22 0.04 245)"/>
                <rect x={60} y={20} width={80} height={50} rx={4} fill="oklch(0.28 0.05 245)"/>
                <text x={100} y={50} textAnchor="middle" fontSize={9} fontFamily="var(--font-mono)" fill="oklch(0.55 0.04 240)">{isEs?"foto capturada":"photo captured"}</text>
              </svg>
              <div style={{ position:"absolute", top:6, right:8, background:"oklch(0.62 0.18 145)", borderRadius:4, padding:"2px 6px", fontSize:7.5, fontFamily:"var(--font-mono)", color:"white" }}>✓ OK</div>
            </>
        }
      </div>
      {/* signature */}
      <div style={{ background:"oklch(0.97 0.005 240)", borderRadius:8, height:70, display:"flex", alignItems:"center", justifyContent:"center", position:"relative", border: step>=2?"1.5px solid oklch(0.62 0.18 145)":"1.5px solid oklch(0.82 0.02 240)", transition:"border .4s" }}>
        {step<2
          ? <div style={{ fontSize:9, fontFamily:"var(--font-mono)", color:"oklch(0.55 0.03 240)" }}>{isEs?"Firma digital":"Digital signature"}</div>
          : <>
              <svg viewBox="0 0 200 70" style={{ width:"100%", height:"100%" }}>
                <path d="M 30 50 Q 60 20, 80 45 T 120 35 Q 140 20, 160 40 T 190 35" fill="none" stroke="oklch(0.30 0.04 250)" strokeWidth={1.8} strokeLinecap="round"/>
              </svg>
              <div style={{ position:"absolute", top:5, right:8, background:"oklch(0.62 0.18 145)", borderRadius:4, padding:"2px 6px", fontSize:7.5, fontFamily:"var(--font-mono)", color:"white" }}>✓ {isEs?"firmado":"signed"}</div>
            </>
        }
      </div>
      <div style={{ background: step>=3?"oklch(0.62 0.18 145)":"oklch(0.22 0.04 250)", borderRadius:8, padding:"10px", textAlign:"center", fontSize:10.5, color:"white", fontWeight:500, transition:"background .5s" }}>
        {step>=3 ? (isEs?"✓ Entrega confirmada":"✓ Delivery confirmed") : (isEs?"Confirmar entrega":"Confirm delivery")}
      </div>
    </div>
  );
}

function DAVoiceScreen({ isEs }) {
  const [active, setActive] = useState(0);
  const qa = isEs
    ? [
        { q:"¿Cuál es la próxima parada?", a:"Av. Italia 3421, en 6 min. Dejar con portero." },
        { q:"¿Tengo tiempo para almorzar?", a:"Sí. 25 min ahora, seguís en ventana." },
        { q:"¿Hay tráfico adelante?", a:"Corte en Bv. España. Te re-ruteo, −4 min." },
      ]
    : [
        { q:"What's the next stop?", a:"Av. Italia 3421, 6 min away. Leave with doorman." },
        { q:"Time for lunch break?", a:"Yes. 25 min now, still within window." },
        { q:"Any traffic ahead?", a:"Block on Bv. España. Re-routing, −4 min." },
      ];
  useEffect(() => { const id = setInterval(()=>setActive(a=>(a+1)%qa.length), 2800); return()=>clearInterval(id); },[]);
  return (
    <div style={{ height:"100%", display:"flex", flexDirection:"column", alignItems:"center", padding:"14px 14px 20px", gap:12 }}>
      {/* waveform */}
      <div style={{ width:64, height:64, borderRadius:"50%", background:"var(--accent)", display:"flex", alignItems:"center", justifyContent:"center", boxShadow:"0 0 0 12px oklch(0.55 0.18 245 / 0.12)", position:"relative" }}>
        <div style={{ display:"flex", gap:2.5, alignItems:"center", height:24 }}>
          {[8,14,20,14,8,18,12].map((h,i)=>(
            <div key={i} style={{ width:2.5, height:h, background:"white", borderRadius:2, opacity:0.85, animation:`ppVoiceBar ${0.5+i*0.1}s ease-in-out infinite alternate`, animationDelay:`${i*0.07}s` }}/>
          ))}
          <style>{`@keyframes ppVoiceBar{from{transform:scaleY(.25)}to{transform:scaleY(1)}}`}</style>
        </div>
        <div style={{ position:"absolute", bottom:-5, right:-5, width:20, height:20, borderRadius:"50%", background:"oklch(0.62 0.18 145)", display:"flex", alignItems:"center", justifyContent:"center", fontSize:10 }}>●</div>
      </div>
      <div style={{ fontFamily:"var(--font-mono)", fontSize:8.5, color:"var(--accent)", letterSpacing:"0.12em" }}>HEY GROPP · {isEs?"ACTIVO":"ACTIVE"}</div>
      <div style={{ width:"100%", display:"flex", flexDirection:"column", gap:8, flex:1 }}>
        {qa.map((item,i)=>(
          <div key={i} style={{ opacity: i===active?1:0.3, transition:"opacity .4s" }}>
            <div style={{ background:"oklch(0.20 0.04 250)", borderRadius:"10px 10px 10px 2px", padding:"7px 10px", fontSize:9.5, color:"oklch(0.70 0.02 240)", marginBottom:4, maxWidth:"80%" }}>
              {item.q}
            </div>
            {i===active && (
              <div style={{ background:"var(--accent)", borderRadius:"10px 10px 2px 10px", padding:"7px 10px", fontSize:9.5, color:"white", marginLeft:"auto", maxWidth:"80%", animation:"ppFadeIn .3s ease" }}>
                {item.a}
                <style>{`@keyframes ppFadeIn{from{opacity:0;transform:translateY(4px)}to{opacity:1;transform:none}}`}</style>
              </div>
            )}
          </div>
        ))}
      </div>
    </div>
  );
}

// ── Web Dashboard mock — 3 views ──────────────────────────────────────────────

function WebDashMock({ isEs }) {
  const [view, setView] = useState(0);
  const views = isEs ? ["Mapa en vivo","Alertas","Analytics"] : ["Live map","Alerts","Analytics"];
  useEffect(() => { const id = setInterval(()=>setView(v=>(v+1)%3), 3500); return()=>clearInterval(id); },[]);

  return (
    <div style={{ height:"100%", display:"grid", gridTemplateColumns:"110px 1fr", background:"oklch(0.97 0.005 240)" }}>
      {/* sidebar */}
      <div style={{ background:"oklch(0.13 0.03 250)", borderRight:"1px solid oklch(0.20 0.03 250)", paddingTop:10, display:"flex", flexDirection:"column", gap:1 }}>
        {views.map((v,i)=>(
          <button key={i} onClick={()=>setView(i)} style={{
            display:"block", width:"100%", padding:"7px 12px", textAlign:"left", border:"none",
            fontFamily:"var(--font-mono)", fontSize:9, letterSpacing:"0.06em",
            background: i===view ? "oklch(0.20 0.05 250)" : "transparent",
            color: i===view ? "var(--accent)" : "oklch(0.42 0.03 240)",
            borderLeft: i===view ? "2px solid var(--accent)" : "2px solid transparent",
            cursor:"pointer", transition:"all .2s",
          }}>{v}</button>
        ))}
        <div style={{ marginTop:"auto", padding:"10px 12px", borderTop:"1px solid oklch(0.20 0.03 250)" }}>
          <div style={{ fontFamily:"var(--font-mono)", fontSize:7.5, color:"oklch(0.35 0.03 240)", letterSpacing:"0.08em" }}>GROPP</div>
          <div style={{ fontFamily:"var(--font-mono)", fontSize:7.5, color:"oklch(0.35 0.03 240)", letterSpacing:"0.08em" }}>FLOW</div>
        </div>
      </div>
      {/* main */}
      <div style={{ overflow:"hidden", position:"relative" }}>
        {view===0 && <WDBMapView isEs={isEs}/>}
        {view===1 && <WDBAlertsView isEs={isEs}/>}
        {view===2 && <WDBAnalyticsView isEs={isEs}/>}
      </div>
    </div>
  );
}

function WDBMapView({ isEs }) {
  const [t, setT] = useState(0);
  useEffect(()=>{ const id=setInterval(()=>setT(x=>x+1),120); return()=>clearInterval(id); },[]);
  const vehicles = [
    { x0:60, y0:220, x1:200, y1:80, color:"var(--accent)", label:"J.P" },
    { x0:30, y0:150, x1:240, y1:190, color:"oklch(0.62 0.18 145)", label:"M.A" },
    { x0:120, y0:270, x1:100, y1:60, color:"oklch(0.65 0.18 35)", label:"C.S" },
  ];
  return (
    <div style={{ height:"100%", display:"flex", flexDirection:"column" }}>
      {/* topbar */}
      <div style={{ padding:"6px 12px", display:"flex", gap:8, alignItems:"center", borderBottom:"1px solid oklch(0.88 0.01 240)", background:"oklch(0.96 0.006 240)" }}>
        <div style={{ width:7, height:7, borderRadius:"50%", background:"oklch(0.62 0.18 145)" }}/>
        <span style={{ fontFamily:"var(--font-mono)", fontSize:8, color:"oklch(0.40 0.03 240)", letterSpacing:"0.08em" }}>{isEs?"EN VIVO · 47 CHOFERES":"LIVE · 47 DRIVERS"}</span>
        <span style={{ marginLeft:"auto", fontFamily:"var(--font-mono)", fontSize:8, color:"var(--accent)" }}>96.3% {isEs?"a tiempo":"on-time"}</span>
      </div>
      <div style={{ flex:1, background:"oklch(0.19 0.035 245)", position:"relative" }}>
        <svg viewBox="0 0 370 270" style={{ width:"100%", height:"100%" }}>
          {[40,80,120,160,200,240].map(y=><line key={y} x1={0} y1={y} x2={370} y2={y} stroke="oklch(0.25 0.03 240)" strokeWidth={1}/>)}
          {[50,100,150,200,250,300,350].map(x=><line key={x} x1={x} y1={0} x2={x} y2={270} stroke="oklch(0.25 0.03 240)" strokeWidth={1}/>)}
          {vehicles.map((v,i)=>{
            const p = (t*0.6 + i*30) % 100 / 100;
            const cx = v.x0 + p*(v.x1-v.x0), cy = v.y0 + p*(v.y1-v.y0);
            return (
              <g key={i}>
                <line x1={v.x0} y1={v.y0} x2={v.x1} y2={v.y1} stroke={v.color} strokeWidth={1.5} strokeDasharray="4 3" opacity={0.4}/>
                <circle cx={cx} cy={cy} r={9} fill={v.color} opacity={0.18}/>
                <circle cx={cx} cy={cy} r={5.5} fill={v.color}/>
                <text x={cx+8} y={cy+3.5} fontSize={7.5} fontFamily="var(--font-mono)" fill={v.color}>{v.label}</text>
              </g>
            );
          })}
        </svg>
      </div>
    </div>
  );
}

function WDBAlertsView({ isEs }) {
  const alerts = isEs
    ? [
        { lvl:"warn", label:"C. Soria — ruta demorada +18 min", t:"14:03", action:"Reasignar" },
        { lvl:"ok",   label:"M. Alves — 9/9 paradas completadas", t:"13:58", action:"Ver" },
        { lvl:"info", label:"Reclamo #312 → insertado en ruta", t:"13:55", action:"Ver" },
        { lvl:"warn", label:"Vehículo VAN-09 — señal GPS débil", t:"13:44", action:"Alertar" },
      ]
    : [
        { lvl:"warn", label:"C. Soria — route delayed +18 min", t:"14:03", action:"Reassign" },
        { lvl:"ok",   label:"M. Alves — 9/9 stops completed", t:"13:58", action:"View" },
        { lvl:"info", label:"Complaint #312 → inserted in route", t:"13:55", action:"View" },
        { lvl:"warn", label:"Vehicle VAN-09 — weak GPS signal", t:"13:44", action:"Alert" },
      ];
  const lvlColor = { warn:"oklch(0.65 0.18 35)", ok:"oklch(0.62 0.18 145)", info:"var(--accent)" };
  const lvlBg = { warn:"oklch(0.97 0.04 35)", ok:"oklch(0.96 0.04 145)", info:"oklch(0.95 0.04 245)" };
  return (
    <div style={{ height:"100%", display:"flex", flexDirection:"column" }}>
      <div style={{ padding:"8px 12px", borderBottom:"1px solid oklch(0.88 0.01 240)", fontFamily:"var(--font-mono)", fontSize:8, color:"oklch(0.40 0.03 240)", letterSpacing:"0.1em", background:"oklch(0.96 0.006 240)" }}>
        {isEs?"ALERTAS · IA TRIAJE":"ALERTS · AI TRIAGE"}
      </div>
      <div style={{ flex:1, padding:"8px", display:"flex", flexDirection:"column", gap:6, overflowY:"hidden" }}>
        {alerts.map((a,i)=>(
          <div key={i} style={{ display:"flex", alignItems:"center", gap:8, background:lvlBg[a.lvl], borderRadius:6, padding:"7px 10px", border:`1px solid ${lvlColor[a.lvl]}20` }}>
            <div style={{ width:7, height:7, borderRadius:"50%", background:lvlColor[a.lvl], flexShrink:0 }}/>
            <div style={{ flex:1, fontSize:9.5, color:"oklch(0.28 0.04 250)" }}>{a.label}</div>
            <span style={{ fontFamily:"var(--font-mono)", fontSize:8, color:"oklch(0.55 0.03 240)" }}>{a.t}</span>
            <div style={{ background:"white", border:`1px solid ${lvlColor[a.lvl]}`, borderRadius:4, padding:"2px 7px", fontSize:8, color:lvlColor[a.lvl], cursor:"pointer", whiteSpace:"nowrap" }}>{a.action}</div>
          </div>
        ))}
      </div>
    </div>
  );
}

function WDBAnalyticsView({ isEs }) {
  const bars = [62,78,91,84,96,88,73];
  const days = isEs ? ["L","M","X","J","V","S","D"] : ["M","T","W","T","F","S","S"];
  return (
    <div style={{ height:"100%", display:"flex", flexDirection:"column" }}>
      <div style={{ padding:"8px 12px", borderBottom:"1px solid oklch(0.88 0.01 240)", fontFamily:"var(--font-mono)", fontSize:8, color:"oklch(0.40 0.03 240)", letterSpacing:"0.1em", background:"oklch(0.96 0.006 240)" }}>
        {isEs?"ANALYTICS · SEMANA":"ANALYTICS · WEEK"}
      </div>
      <div style={{ padding:"12px 14px", flex:1, display:"flex", flexDirection:"column", gap:12 }}>
        <div style={{ display:"grid", gridTemplateColumns:"repeat(3,1fr)", gap:8 }}>
          {[
            { num:"96.3%", label: isEs?"a tiempo":"on-time" },
            { num:"−38%", label: isEs?"km/ruta":"km/route" },
            { num:"5.4M", label: isEs?"paradas":"stops" },
          ].map((m,i)=>(
            <div key={i} style={{ background:"oklch(0.94 0.008 240)", borderRadius:6, padding:"8px", textAlign:"center" }}>
              <div style={{ fontFamily:"var(--font-mono)", fontSize:13, fontWeight:600, color:"var(--accent)" }}>{m.num}</div>
              <div style={{ fontFamily:"var(--font-mono)", fontSize:7.5, color:"oklch(0.52 0.03 240)", marginTop:2, letterSpacing:"0.06em" }}>{m.label}</div>
            </div>
          ))}
        </div>
        <div style={{ flex:1, display:"flex", alignItems:"flex-end", gap:5, paddingBottom:18, position:"relative" }}>
          <div style={{ position:"absolute", bottom:18, left:0, right:0, fontFamily:"var(--font-mono)", fontSize:7, color:"oklch(0.60 0.03 240)", letterSpacing:"0.06em" }}>{isEs?"PUNTUALIDAD / DÍA":"ON-TIME / DAY"}</div>
          {bars.map((h,i)=>(
            <div key={i} style={{ flex:1, display:"flex", flexDirection:"column", alignItems:"center", gap:3 }}>
              <div style={{ width:"100%", height:`${h*1.4}px`, background: h>=85?"var(--accent)":"oklch(0.65 0.18 35)", borderRadius:"3px 3px 0 0", opacity:0.85 }}/>
              <span style={{ fontFamily:"var(--font-mono)", fontSize:7.5, color:"oklch(0.50 0.03 240)" }}>{days[i]}</span>
            </div>
          ))}
        </div>
      </div>
    </div>
  );
}

// ── Supervisor App mock — 3 views ─────────────────────────────────────────────

function SupervisorMock({ isEs }) {
  const [view, setView] = useState(0);
  const views = isEs ? ["Scores","Incidente","Coaching"] : ["Scores","Incident","Coaching"];
  useEffect(()=>{ const id=setInterval(()=>setView(v=>(v+1)%3), 3500); return()=>clearInterval(id); },[]);
  return (
    <div style={{ height:"100%", display:"grid", gridTemplateColumns:"110px 1fr", background:"oklch(0.97 0.005 240)" }}>
      <div style={{ background:"oklch(0.13 0.03 250)", borderRight:"1px solid oklch(0.20 0.03 250)", paddingTop:10, display:"flex", flexDirection:"column", gap:1 }}>
        {views.map((v,i)=>(
          <button key={i} onClick={()=>setView(i)} style={{
            display:"block", width:"100%", padding:"7px 12px", textAlign:"left", border:"none",
            fontFamily:"var(--font-mono)", fontSize:9, letterSpacing:"0.06em",
            background: i===view ? "oklch(0.20 0.05 250)" : "transparent",
            color: i===view ? "var(--accent)" : "oklch(0.42 0.03 240)",
            borderLeft: i===view ? "2px solid var(--accent)" : "2px solid transparent",
            cursor:"pointer", transition:"all .2s",
          }}>{v}</button>
        ))}
        <div style={{ marginTop:"auto", padding:"10px 12px", borderTop:"1px solid oklch(0.20 0.03 250)" }}>
          <div style={{ fontFamily:"var(--font-mono)", fontSize:7.5, color:"oklch(0.35 0.03 240)" }}>GROPP</div>
          <div style={{ fontFamily:"var(--font-mono)", fontSize:7.5, color:"oklch(0.35 0.03 240)" }}>SUPERVISOR</div>
        </div>
      </div>
      <div style={{ overflow:"hidden" }}>
        {view===0 && <SVScoresView isEs={isEs}/>}
        {view===1 && <SVIncidentView isEs={isEs}/>}
        {view===2 && <SVCoachingView isEs={isEs}/>}
      </div>
    </div>
  );
}

function SVScoresView({ isEs }) {
  const drivers = [
    { name:"M. Alves",  score:96, trend:"+2", incidents:0, bar:96 },
    { name:"J. Pérez",  score:91, trend:"+3", incidents:0, bar:91 },
    { name:"R. Torres", score:83, trend:"+1", incidents:1, bar:83 },
    { name:"C. Soria",  score:74, trend:"−5", incidents:2, bar:74 },
  ];
  const sc = s => s>=85?"oklch(0.58 0.18 145)":s>=70?"oklch(0.68 0.16 75)":"oklch(0.60 0.18 35)";
  return (
    <div style={{ height:"100%", display:"flex", flexDirection:"column" }}>
      <div style={{ padding:"8px 12px", borderBottom:"1px solid oklch(0.88 0.01 240)", fontFamily:"var(--font-mono)", fontSize:8, color:"oklch(0.40 0.03 240)", letterSpacing:"0.1em", background:"oklch(0.96 0.006 240)" }}>
        {isEs?"SCORES SEMANALES":"WEEKLY SCORES"}
      </div>
      <div style={{ padding:"8px 12px", display:"flex", flexDirection:"column", gap:8 }}>
        {drivers.map((d,i)=>(
          <div key={i} style={{ display:"flex", alignItems:"center", gap:10 }}>
            <div style={{ width:26, height:26, borderRadius:"50%", background:"var(--accent)", display:"flex", alignItems:"center", justifyContent:"center", color:"white", fontSize:10, fontWeight:600, flexShrink:0 }}>{d.name[0]}</div>
            <div style={{ flex:1 }}>
              <div style={{ display:"flex", justifyContent:"space-between", marginBottom:3 }}>
                <span style={{ fontSize:10, fontWeight:500 }}>{d.name}</span>
                <span style={{ fontFamily:"var(--font-mono)", fontSize:11, fontWeight:600, color:sc(d.score) }}>{d.score}</span>
              </div>
              <div style={{ background:"oklch(0.90 0.01 240)", borderRadius:3, height:4, overflow:"hidden" }}>
                <div style={{ width:`${d.bar}%`, height:"100%", background:sc(d.score), borderRadius:3, transition:"width .8s" }}/>
              </div>
            </div>
            <span style={{ fontFamily:"var(--font-mono)", fontSize:8.5, color:d.trend.startsWith("+")?"oklch(0.58 0.18 145)":"oklch(0.60 0.18 35)", width:24, textAlign:"right" }}>{d.trend}</span>
          </div>
        ))}
      </div>
    </div>
  );
}

function SVIncidentView({ isEs }) {
  return (
    <div style={{ height:"100%", display:"flex", flexDirection:"column" }}>
      <div style={{ padding:"8px 12px", borderBottom:"1px solid oklch(0.88 0.01 240)", fontFamily:"var(--font-mono)", fontSize:8, color:"oklch(0.40 0.03 240)", letterSpacing:"0.1em", background:"oklch(0.96 0.006 240)" }}>
        {isEs?"INCIDENTE · C. SORIA · 14:02":"INCIDENT · C. SORIA · 14:02"}
      </div>
      <div style={{ padding:"10px 12px", display:"flex", flexDirection:"column", gap:10 }}>
        {/* video placeholder */}
        <div style={{ background:"oklch(0.15 0.04 250)", borderRadius:8, height:100, display:"flex", alignItems:"center", justifyContent:"center", position:"relative", overflow:"hidden" }}>
          <svg viewBox="0 0 300 100" style={{ width:"100%", height:"100%", position:"absolute", inset:0 }}>
            <rect width={300} height={100} fill="oklch(0.15 0.04 250)"/>
            <rect x={10} y={15} width={150} height={70} rx={4} fill="oklch(0.20 0.04 248)"/>
            <circle cx={85} cy={50} r={14} fill="none" stroke="oklch(0.55 0.03 240)" strokeWidth={1.5}/>
            <polygon points="81,44 81,56 93,50" fill="oklch(0.55 0.03 240)"/>
            <line x1={170} y1={15} x2={170} y2={85} stroke="oklch(0.25 0.03 240)" strokeWidth={1}/>
            <text x={180} y={28} fontSize={7.5} fontFamily="var(--font-mono)" fill="oklch(0.42 0.03 240)">14:02:11</text>
            <text x={180} y={42} fontSize={7.5} fontFamily="var(--font-mono)" fill="oklch(0.60 0.18 35)">FRENADA BRUSCA</text>
            <text x={180} y={56} fontSize={7.5} fontFamily="var(--font-mono)" fill="oklch(0.42 0.03 240)">−0.82g</text>
            <text x={180} y={70} fontSize={7.5} fontFamily="var(--font-mono)" fill="oklch(0.42 0.03 240)">67 km/h → 12 km/h</text>
          </svg>
          <div style={{ position:"absolute", top:6, right:8, background:"oklch(0.62 0.18 145)", borderRadius:4, padding:"2px 7px", fontSize:7.5, fontFamily:"var(--font-mono)", color:"white" }}>✓ {isEs?"FIRMADO":"SIGNED"}</div>
        </div>
        <div style={{ display:"flex", gap:6 }}>
          <div style={{ flex:1, background:"oklch(0.97 0.03 35)", border:"1px solid oklch(0.88 0.08 35)", borderRadius:6, padding:"7px 9px" }}>
            <div style={{ fontFamily:"var(--font-mono)", fontSize:7.5, color:"oklch(0.50 0.12 35)", letterSpacing:"0.08em", marginBottom:3 }}>{isEs?"EVENTO":"EVENT"}</div>
            <div style={{ fontSize:9.5, color:"oklch(0.30 0.08 35)" }}>{isEs?"Frenada brusca · −0.82g":"Hard braking · −0.82g"}</div>
          </div>
          <div style={{ flex:1, background:"oklch(0.96 0.008 240)", border:"1px solid oklch(0.88 0.01 240)", borderRadius:6, padding:"7px 9px" }}>
            <div style={{ fontFamily:"var(--font-mono)", fontSize:7.5, color:"oklch(0.50 0.03 240)", letterSpacing:"0.08em", marginBottom:3 }}>HASH</div>
            <div style={{ fontSize:8, fontFamily:"var(--font-mono)", color:"oklch(0.42 0.03 240)", wordBreak:"break-all" }}>a3f2c9d…</div>
          </div>
        </div>
        <div style={{ display:"flex", gap:6 }}>
          <div style={{ flex:1, background:"oklch(0.94 0.01 240)", borderRadius:6, padding:"7px 9px", textAlign:"center", fontSize:9, color:"oklch(0.40 0.03 240)" }}>{isEs?"Exportar PDF":"Export PDF"}</div>
          <div style={{ flex:1, background:"var(--accent)", borderRadius:6, padding:"7px 9px", textAlign:"center", fontSize:9, color:"white" }}>{isEs?"Enviar a RRHH":"Send to HR"}</div>
        </div>
      </div>
    </div>
  );
}

function SVCoachingView({ isEs }) {
  return (
    <div style={{ height:"100%", display:"flex", flexDirection:"column" }}>
      <div style={{ padding:"8px 12px", borderBottom:"1px solid oklch(0.88 0.01 240)", fontFamily:"var(--font-mono)", fontSize:8, color:"oklch(0.40 0.03 240)", letterSpacing:"0.1em", background:"oklch(0.96 0.006 240)" }}>
        {isEs?"BRIEF IA · C. SORIA · SEMANA 17":"AI BRIEF · C. SORIA · WEEK 17"}
      </div>
      <div style={{ padding:"10px 12px", display:"flex", flexDirection:"column", gap:8 }}>
        <div style={{ background:"color-mix(in oklch, var(--accent) 8%, transparent)", border:"1px solid color-mix(in oklch, var(--accent) 20%, transparent)", borderRadius:7, padding:"9px 11px" }}>
          <div style={{ fontFamily:"var(--font-mono)", fontSize:7.5, color:"var(--accent)", letterSpacing:"0.1em", marginBottom:5 }}>AI · {isEs?"RESUMEN":"SUMMARY"}</div>
          <div style={{ fontSize:9.5, color:"oklch(0.32 0.04 250)", lineHeight:1.55 }}>
            {isEs
              ? "C. Soria mostró mejora en velocidad pero registró 2 frenadas bruscas en Zona 4. Score bajó −5 pts respecto a semana anterior."
              : "C. Soria improved on speed but recorded 2 hard-braking events in Zone 4. Score down −5 pts from previous week."}
          </div>
        </div>
        <div>
          <div style={{ fontFamily:"var(--font-mono)", fontSize:7.5, color:"oklch(0.42 0.03 240)", letterSpacing:"0.1em", marginBottom:5 }}>{isEs?"TOP 3 EVENTOS":"TOP 3 EVENTS"}</div>
          {[
            isEs ? "Frenada brusca · 14:02 · Bv. España" : "Hard braking · 14:02 · Bv. España",
            isEs ? "Velocidad excesiva · 11:34 · Ruta 8" : "Excess speed · 11:34 · Route 8",
            isEs ? "Distancia corta · 09:48 · Gral. Flores" : "Short following dist. · 09:48 · Gral. Flores",
          ].map((e,i)=>(
            <div key={i} style={{ display:"flex", gap:7, alignItems:"center", padding:"4px 0", borderBottom:"1px solid oklch(0.92 0.005 240)" }}>
              <div style={{ width:15, height:15, borderRadius:"50%", background:"oklch(0.65 0.18 35)", display:"flex", alignItems:"center", justifyContent:"center", fontSize:8, color:"white", flexShrink:0 }}>{i+1}</div>
              <span style={{ fontSize:9, color:"oklch(0.35 0.04 250)" }}>{e}</span>
            </div>
          ))}
        </div>
        <div style={{ background:"oklch(0.94 0.008 240)", borderRadius:6, padding:"8px 10px", fontSize:9, color:"oklch(0.40 0.03 240)", lineHeight:1.5 }}>
          <span style={{ fontFamily:"var(--font-mono)", color:"var(--accent)", fontSize:7.5, letterSpacing:"0.08em" }}>GOAL · </span>
          {isEs ? "Mantener distancia de 3s en zona urbana durante toda la semana." : "Maintain 3s following distance in urban areas all week."}
        </div>
        <div style={{ background:"var(--accent)", borderRadius:7, padding:"8px", textAlign:"center", fontSize:9.5, color:"white", fontWeight:500, cursor:"pointer" }}>
          {isEs?"Revisar y enviar →":"Review and send →"}
        </div>
      </div>
    </div>
  );
}

// ── Feature list component ─────────────────────────────────────────────────────

function FeatureModule({ num, title, body, chips }) {
  return (
    <div style={{ display:"flex", gap:16, alignItems:"flex-start" }}>
      <div style={{ fontFamily:"var(--font-mono)", fontSize:10, color:"var(--accent)", background:"color-mix(in oklch, var(--accent) 10%, transparent)", border:"1px solid color-mix(in oklch, var(--accent) 20%, transparent)", borderRadius:4, padding:"3px 7px", flexShrink:0, marginTop:2, letterSpacing:"0.08em" }}>{num}</div>
      <div>
        <div style={{ fontSize:15, fontWeight:500, marginBottom:4 }}>{title}</div>
        <div style={{ fontSize:13.5, color:"var(--fog)", lineHeight:1.55, marginBottom:chips?8:0 }}>{body}</div>
        {chips && (
          <div style={{ display:"flex", flexWrap:"wrap", gap:5 }}>
            {chips.map((c,i)=>(
              <span key={i} style={{ fontFamily:"var(--font-mono)", fontSize:9.5, color:"oklch(0.42 0.03 240)", background:"oklch(0.93 0.01 240)", border:"1px solid oklch(0.86 0.02 240)", borderRadius:4, padding:"2px 7px", letterSpacing:"0.04em" }}>{c}</span>
            ))}
          </div>
        )}
      </div>
    </div>
  );
}

// ── Connection flow ───────────────────────────────────────────────────────────

function ConnectionFlow({ isEs }) {
  const nodes = isEs
    ? [
        { label:"App\nChofer", sub:"iOS · Android", x:80, y:80 },
        { label:"Gropp\nFlow", sub:"AI Core", x:240, y:80, center:true },
        { label:"Web\nDashboard", sub:"Despacho", x:400, y:80 },
        { label:"App\nSupervisor", sub:"Gestión de flota", x:240, y:200 },
      ]
    : [
        { label:"Driver\nApp", sub:"iOS · Android", x:80, y:80 },
        { label:"Gropp\nFlow", sub:"AI Core", x:240, y:80, center:true },
        { label:"Web\nDashboard", sub:"Dispatch", x:400, y:80 },
        { label:"Supervisor\nApp", sub:"Fleet mgmt", x:240, y:200 },
      ];
  const flows = isEs
    ? [
        { x1:110, y1:80, x2:200, y2:80, label:"telemetría + POD" },
        { x1:280, y1:80, x2:370, y2:80, label:"rutas + alertas" },
        { x1:240, y1:115, x2:240, y2:165, label:"scores + clips" },
      ]
    : [
        { x1:110, y1:80, x2:200, y2:80, label:"telemetry + POD" },
        { x1:280, y1:80, x2:370, y2:80, label:"routes + alerts" },
        { x1:240, y1:115, x2:240, y2:165, label:"scores + clips" },
      ];

  return (
    <div style={{ position:"relative", height:260, width:"100%" }}>
      <svg viewBox="0 0 480 260" style={{ width:"100%", height:"100%", maxWidth:520, margin:"0 auto", display:"block" }}>
        {/* flows */}
        {flows.map((f,i)=>(
          <g key={i}>
            <line x1={f.x1} y1={f.y1} x2={f.x2} y2={f.y2} stroke="var(--accent)" strokeWidth={1.5} strokeDasharray="5 3">
              <animate attributeName="stroke-dashoffset" from="0" to="-16" dur="1.4s" repeatCount="indefinite"/>
            </line>
            <text x={(f.x1+f.x2)/2} y={(f.y1+f.y2)/2-6} textAnchor="middle" fontSize={8.5} fontFamily="var(--font-mono)" fill="oklch(0.55 0.03 240)">{f.label}</text>
          </g>
        ))}
        {/* nodes */}
        {nodes.map((n,i)=>(
          <g key={i}>
            <rect x={n.x-38} y={n.y-28} width={76} height={56} rx={8}
              fill={n.center ? "var(--accent)" : "oklch(0.14 0.03 250)"}
              stroke={n.center ? "var(--accent)" : "oklch(0.28 0.04 250)"} strokeWidth={1.5}/>
            {n.label.split("\n").map((line,li)=>(
              <text key={li} x={n.x} y={n.y + li*14 - 6} textAnchor="middle" fontSize={10} fontFamily="var(--font-display)" fontWeight={500}
                fill={n.center ? "white" : "oklch(0.82 0.02 240)"}>{line}</text>
            ))}
            <text x={n.x} y={n.y+26} textAnchor="middle" fontSize={8} fontFamily="var(--font-mono)"
              fill={n.center ? "rgba(255,255,255,0.7)" : "oklch(0.45 0.03 240)"}>{n.sub}</text>
          </g>
        ))}
      </svg>
    </div>
  );
}

// ── Section header ─────────────────────────────────────────────────────────────

function SectionHead({ eyebrow, title_a, title_b, title_c, sub, light }) {
  return (
    <div className="pp-section-head">
      <div className="eyebrow">{eyebrow}</div>
      <h2 style={{ color: light ? "var(--ink-2)" : undefined }}>
        {title_a}<span className="accent">{title_b}</span>{title_c}
      </h2>
      <p style={{ color: light ? "oklch(0.72 0.03 240)" : "var(--fog)" }}>{sub}</p>
    </div>
  );
}

// ── Platform Page ─────────────────────────────────────────────────────────────

function PlatformPage({ lang, onBack }) {
  const isEs = lang === "es";

  const copy = {
    hero: isEs
      ? { eyebrow:"// PLATAFORMA · TRES HERRAMIENTAS", title_a:"Una plataforma. ", title_b:"Tres roles.", title_c:"", sub:"Cada actor tiene su herramienta pensada para él — el chofer en el camión, el despachador frente al mapa, el supervisor gestionando la flota. Sin dashboards genéricos, sin funciones de más." }
      : { eyebrow:"// PLATFORM · THREE TOOLS", title_a:"One platform. ", title_b:"Three roles.", title_c:"", sub:"Every stakeholder gets a tool built for them — the driver in the truck, the dispatcher at the map, the supervisor managing the fleet. No generic dashboards, no bloat." },

    driver: {
      eyebrow: isEs ? "// 01 · APP DEL CHOFER" : "// 01 · DRIVER APP",
      tag: isEs ? "MÓVIL · iOS & Android" : "MOBILE · iOS & Android",
      title_a: isEs ? "Navegación que " : "Navigation that ",
      title_b: isEs ? "conoce el trabajo" : "knows the job",
      title_c: ".",
      sub: isEs
        ? "Una app de ruta que guía cada parada, captura pruebas de entrega, habla por voz y funciona offline. Hecha para el chofer, no para el jefe."
        : "A route app that guides every stop, captures delivery proof, talks back via voice, and works offline. Built for the driver, not the manager.",
      modules: isEs
        ? [
            { num:"01", title:"Navegación con re-ruteo en vivo", body:"Las rutas se actualizan en tiempo real — tráfico, cierres, reagendamientos. El chofer siempre ve la versión optimizada.", chips:["tiempo real","offline-first","modo noche"] },
            { num:"02", title:"Detalle de parada", body:"Datos del cliente, notas de entrega, historial y contacto directo — todo en una pantalla antes de tocar timbre.", chips:["notas del cliente","historial","contacto 1-tap"] },
            { num:"03", title:"Prueba de entrega digital", body:"Foto + firma en la app. Firmados y sincronizados al instante. Sin papel, sin pérdida.", chips:["foto","firma digital","sync automático"] },
            { num:"04", title:"Copiloto de voz 'Hey Gropp'", body:"Manos libres. El chofer pregunta, el copiloto responde — próxima parada, tiempo libre, a quién llamar.", chips:["manos libres","es-UY","wake-word"] },
          ]
        : [
            { num:"01", title:"Turn-by-turn with live re-routing", body:"Routes update in real time — traffic, closures, customer changes. The driver always sees the optimized version.", chips:["real-time","offline-first","night mode"] },
            { num:"02", title:"Stop detail view", body:"Customer data, delivery notes, history and direct contact — all on one screen before knocking.", chips:["customer notes","history","1-tap contact"] },
            { num:"03", title:"Digital proof of delivery", body:"Photo + signature in-app. Signed and synced instantly. No paper, no loss.", chips:["photo","digital signature","auto-sync"] },
            { num:"04", title:"'Hey Gropp' voice copilot", body:"Hands-free. The driver asks, the copilot answers — next stop, free time, who to call.", chips:["hands-free","en-US","wake-word"] },
          ],
    },

    web: {
      eyebrow: isEs ? "// 02 · WEB DASHBOARD" : "// 02 · WEB DASHBOARD",
      tag: isEs ? "NAVEGADOR · Despacho" : "BROWSER · Dispatch",
      title_a: isEs ? "Control de flota " : "Fleet control ",
      title_b: isEs ? "en vivo" : "in real time",
      title_c: isEs ? " para despacho." : " for dispatch.",
      sub: isEs
        ? "Centro de operaciones en tiempo real. Mapa vivo, alertas priorizadas por IA y comunicación directa con cada chofer — en una sola ventana."
        : "A real-time operations center. Live map, AI-prioritized alerts, and direct driver communication — in one window.",
      modules: isEs
        ? [
            { num:"01", title:"Mapa en vivo con toda la flota", body:"Cada vehículo rastreado en tiempo real, con código de color por estado, ETA y número de paradas restantes.", chips:["tiempo real","ETA live","estado por color"] },
            { num:"02", title:"Triaje de alertas con IA", body:"La IA prioriza los eventos que necesitan atención humana — rutas demoradas, incidentes, escaladas de clientes.", chips:["prioridad IA","filtros","escalada"] },
            { num:"03", title:"Intervención de ruta con un clic", body:"Bloquea una parada, cambia un chofer o empuja un re-plan completo. Aprobación en un clic, ejecución en sub-segundo.", chips:["1-clic","re-plan","swap chofer"] },
            { num:"04", title:"Analytics e informes de turno", body:"Resúmenes de fin de día generados automáticamente. Exporta a PDF o empuja a tu TMS.", chips:["auto-resumen","PDF","API TMS"] },
          ]
        : [
            { num:"01", title:"Live map with all vehicles", body:"Every driver tracked in real time, color-coded by status, ETA accuracy, and remaining stops.", chips:["real-time","live ETA","color status"] },
            { num:"02", title:"AI-prioritized alert triage", body:"AI surfaces events that need human attention — late routes, incidents, customer escalations.", chips:["AI priority","filters","escalation"] },
            { num:"03", title:"One-click route intervention", body:"Lock a stop, swap a driver, or push a full re-plan. One-click approval, sub-second execution.", chips:["1-click","re-plan","driver swap"] },
            { num:"04", title:"Analytics & shift reports", body:"End-of-day summaries generated automatically. Export to PDF or push to your TMS.", chips:["auto-summary","PDF","TMS API"] },
          ],
    },

    supervisor: {
      eyebrow: isEs ? "// 03 · APP SUPERVISOR" : "// 03 · SUPERVISOR APP",
      tag: isEs ? "NAVEGADOR · Gestión de flota" : "BROWSER · Fleet management",
      title_a: isEs ? "Rendimiento del conductor, " : "Driver performance, ",
      title_b: isEs ? "de un vistazo" : "at a glance",
      title_c: ".",
      sub: isEs
        ? "Una vista dedicada para supervisores — scores, incidentes, briefings de coaching generados por IA y evidencia de cumplimiento lista para el seguro."
        : "A dedicated view for fleet managers — scores, incidents, AI-written coaching briefs, and compliance evidence ready for insurance.",
      modules: isEs
        ? [
            { num:"01", title:"Dashboard de score por chofer", body:"Scores semanales y mensuales por conductor, con líneas de tendencia y comparación entre pares.", chips:["semanal","mensual","comparación"] },
            { num:"02", title:"Revisión de incidentes con video", body:"Cada evento marcado enlaza a un clip firmado e inalterable. Hash criptográfico, listo para aseguradoras.", chips:["clip firmado","hash","seguros"] },
            { num:"03", title:"Brief de coaching con IA", body:"Gropp IA redacta un resumen por chofer por semana — top 3 eventos, clips y un objetivo personal.", chips:["IA semanal","objetivo personal","PDF"] },
            { num:"04", title:"Cumplimiento y retención", body:"Configura la retención por tipo de evento. Los datos se alinean con la legislación laboral local de LATAM.", chips:["configurable","LATAM","exportable"] },
          ]
        : [
            { num:"01", title:"Driver score dashboard", body:"Weekly and monthly scores per driver, with trend lines and peer comparison.", chips:["weekly","monthly","peer compare"] },
            { num:"02", title:"Incident review with video", body:"Every flagged event links to a signed, tamper-proof clip. Cryptographic hash, insurance-ready.", chips:["signed clip","hash","insurance"] },
            { num:"03", title:"AI coaching brief", body:"Gropp AI writes a summary per driver per week — top 3 events, clips, and a personal goal.", chips:["AI weekly","personal goal","PDF"] },
            { num:"04", title:"Compliance & retention", body:"Configure retention per event type. Data stays aligned with LATAM local labor law.", chips:["configurable","LATAM","exportable"] },
          ],
    },

    connect: {
      eyebrow: isEs ? "// 04 · TODO CONECTADO" : "// 04 · ALL CONNECTED",
      title_a: isEs ? "Tres vistas, " : "Three views, ",
      title_b: isEs ? "un solo modelo de datos" : "one data model",
      title_c: ".",
      sub: isEs
        ? "La telemetría del chofer alimenta el mapa del despachador. El evento de la cabina alimenta el informe del supervisor. El reclamo del cliente se convierte en una parada para el chofer. Todo en tiempo real, sin piping manual."
        : "Driver telemetry feeds the dispatcher's map. Cabin events feed the supervisor's report. A customer complaint becomes a driver stop. All real-time, no manual piping.",
    },
  };

  return (
    <>
      <style>{`
        .pp-hero { padding: 120px 0 80px; background: var(--ink); position: relative; overflow: hidden; }
        .pp-hero-bg { position:absolute; inset:0; background: radial-gradient(60% 80% at 80% 50%, color-mix(in oklch, var(--accent) 12%, transparent), transparent 70%); pointer-events:none; }
        .pp-hero-grid { position:absolute; inset:0; background-image: linear-gradient(oklch(0.30 0.04 250 / 0.25) 1px, transparent 1px), linear-gradient(90deg, oklch(0.30 0.04 250 / 0.25) 1px, transparent 1px); background-size: 60px 60px; pointer-events:none; }
        .pp-hero-inner { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 24px; align-items: center; margin-top: 48px; }
        .pp-hero-card { background: oklch(0.17 0.04 250); border: 1px solid oklch(0.24 0.04 250); border-radius: 12px; padding: 20px; }
        .pp-hero-card-tag { font-family: var(--font-mono); font-size: 9.5px; letter-spacing: 0.12em; color: var(--accent); margin-bottom: 8px; }
        .pp-hero-card-title { font-size: 15px; font-weight: 500; color: var(--ink-2); margin-bottom: 4px; }
        .pp-hero-card-sub { font-size: 12px; color: oklch(0.50 0.03 240); }

        .pp-section-head { margin-bottom: 64px; max-width: 680px; }
        .pp-section-head h2 { font-size: clamp(32px, 4vw, 58px); letter-spacing: -0.025em; font-weight: 500; line-height: 1.04; margin: 10px 0 16px; }
        .pp-section-head h2 .accent { color: var(--accent); }
        .pp-section-head p { font-size: 16px; color: var(--fog); line-height: 1.65; }

        .pp-platform-section { padding: 100px 0; }
        .pp-platform-section--dark { background: var(--ink); }
        .pp-platform-section--mist { background: oklch(0.96 0.008 240); }

        .pp-split { display: grid; grid-template-columns: 1fr 1fr; gap: 80px; align-items: center; }
        .pp-split--flip { }
        .pp-split--flip .pp-device { order: -1; }

        .pp-modules { display: flex; flex-direction: column; gap: 28px; }
        .pp-tag { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.14em; color: var(--accent); background: color-mix(in oklch, var(--accent) 10%, transparent); border: 1px solid color-mix(in oklch, var(--accent) 22%, transparent); padding: 4px 11px; border-radius: 999px; display: inline-block; margin-bottom: 8px; }
        .pp-section-title { font-size: clamp(26px, 3vw, 42px); letter-spacing: -0.022em; font-weight: 500; line-height: 1.08; margin-bottom: 12px; }
        .pp-section-title .accent { color: var(--accent); }
        .pp-section-sub { font-size: 15px; line-height: 1.65; margin-bottom: 32px; }

        .pp-device { display: flex; justify-content: center; align-items: center; position: relative; }
        .pp-device-glow { position: absolute; inset: -60px; background: radial-gradient(50% 50% at 50% 50%, color-mix(in oklch, var(--accent) 14%, transparent), transparent 70%); pointer-events: none; }

        .pp-connect { padding: 100px 0; background: var(--bone); }

        @media (max-width: 1000px) {
          .pp-split { grid-template-columns: 1fr; gap: 48px; }
          .pp-split--flip .pp-device { order: 0; }
          .pp-hero-inner { grid-template-columns: 1fr; }
        }
      `}</style>

      {/* HERO */}
      <section className="pp-hero">
        <div className="pp-hero-bg"></div>
        <div className="pp-hero-grid"></div>
        <div className="container">
          <div className="eyebrow" style={{ color:"oklch(0.55 0.03 240)" }}>{copy.hero.eyebrow}</div>
          <h1 style={{ fontSize:"clamp(36px, 5vw, 72px)", fontWeight:500, letterSpacing:"-0.028em", lineHeight:1.02, color:"var(--ink-2)", marginTop:16, maxWidth:700 }}>
            {copy.hero.title_a}<span style={{ color:"var(--accent)" }}>{copy.hero.title_b}</span>{copy.hero.title_c}
          </h1>
          <p style={{ fontSize:17, color:"oklch(0.62 0.03 240)", lineHeight:1.65, maxWidth:540, marginTop:20 }}>{copy.hero.sub}</p>

          <div className="pp-hero-inner">
            {[
              { tag: isEs?"01 · CHOFER":"01 · DRIVER", title: isEs?"App del Chofer":"Driver App", sub: isEs?"iOS & Android · offline-first":"iOS & Android · offline-first", icon:"📱" },
              { tag: isEs?"02 · DESPACHO":"02 · DISPATCH", title: isEs?"Web Dashboard":"Web Dashboard", sub: isEs?"Mapa en vivo · alertas IA":"Live map · AI alerts", icon:"🖥" },
              { tag: isEs?"03 · SUPERVISOR":"03 · SUPERVISOR", title: isEs?"App Supervisor":"Supervisor App", sub: isEs?"Scores · coaching · evidencia":"Scores · coaching · evidence", icon:"📊" },
            ].map((c,i)=>(
              <div key={i} className="pp-hero-card">
                <div className="pp-hero-card-tag">{c.tag}</div>
                <div style={{ fontSize:24, marginBottom:8 }}>{c.icon}</div>
                <div className="pp-hero-card-title">{c.title}</div>
                <div className="pp-hero-card-sub">{c.sub}</div>
              </div>
            ))}
          </div>
        </div>
      </section>

      {/* DRIVER APP */}
      <section className="pp-platform-section">
        <div className="container">
          <div className="pp-split">
            <div className="pp-modules">
              <div>
                <span className="pp-tag">{copy.driver.tag}</span>
                <h2 className="pp-section-title">
                  {copy.driver.title_a}<span className="accent">{copy.driver.title_b}</span>{copy.driver.title_c}
                </h2>
                <p className="pp-section-sub" style={{ color:"var(--fog)" }}>{copy.driver.sub}</p>
              </div>
              {copy.driver.modules.map((m,i)=>(
                <FeatureModule key={i} {...m}/>
              ))}
            </div>
            <div className="pp-device">
              <div className="pp-device-glow"/>
              <PPPhone>
                <DriverAppMock isEs={isEs}/>
              </PPPhone>
            </div>
          </div>
        </div>
      </section>

      {/* WEB DASHBOARD */}
      <section className="pp-platform-section pp-platform-section--mist">
        <div className="container">
          <div className="pp-split pp-split--flip">
            <div className="pp-device">
              <div className="pp-device-glow"/>
              <PPBrowser url="flow.gropp.tech">
                <WebDashMock isEs={isEs}/>
              </PPBrowser>
            </div>
            <div className="pp-modules">
              <div>
                <span className="pp-tag">{copy.web.tag}</span>
                <h2 className="pp-section-title">
                  {copy.web.title_a}<span className="accent">{copy.web.title_b}</span>{copy.web.title_c}
                </h2>
                <p className="pp-section-sub" style={{ color:"var(--fog)" }}>{copy.web.sub}</p>
              </div>
              {copy.web.modules.map((m,i)=>(
                <FeatureModule key={i} {...m}/>
              ))}
            </div>
          </div>
        </div>
      </section>

      {/* SUPERVISOR APP */}
      <section className="pp-platform-section">
        <div className="container">
          <div className="pp-split">
            <div className="pp-modules">
              <div>
                <span className="pp-tag">{copy.supervisor.tag}</span>
                <h2 className="pp-section-title">
                  {copy.supervisor.title_a}<span className="accent">{copy.supervisor.title_b}</span>{copy.supervisor.title_c}
                </h2>
                <p className="pp-section-sub" style={{ color:"var(--fog)" }}>{copy.supervisor.sub}</p>
              </div>
              {copy.supervisor.modules.map((m,i)=>(
                <FeatureModule key={i} {...m}/>
              ))}
            </div>
            <div className="pp-device">
              <div className="pp-device-glow"/>
              <PPBrowser url="supervisor.gropp.tech">
                <SupervisorMock isEs={isEs}/>
              </PPBrowser>
            </div>
          </div>
        </div>
      </section>

      {/* HOW THEY CONNECT */}
      <section className="pp-connect">
        <div className="container">
          <SectionHead {...copy.connect}/>
          <ConnectionFlow isEs={isEs}/>
        </div>
      </section>
    </>
  );
}

window.PlatformPage = PlatformPage;
