/* Squol landing — shared components */
const { useState, useEffect, useRef } = React;

/* ---------- Icons ---------- */
const Icon = {
  arrow: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M5 12h14M13 6l6 6-6 6"/></svg>,
  close: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M18 6L6 18M6 6l12 12"/></svg>,
  check: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M5 13l4 4L19 7"/></svg>,
  school: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M3 10l9-5 9 5-9 5-9-5z"/><path d="M6 11.5V17c0 1 3 3 6 3s6-2 6-3v-5.5"/><path d="M21 10v6"/></svg>,
  users: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><circle cx="9" cy="8" r="3.5"/><path d="M2 21c0-3.5 3.1-6 7-6s7 2.5 7 6"/><circle cx="17" cy="9" r="2.5"/><path d="M22 19c0-2.5-2-4.5-5-4.5"/></svg>,
  link: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M10 14a4.5 4.5 0 006.4 0l3-3a4.5 4.5 0 00-6.4-6.4l-1 1"/><path d="M14 10a4.5 4.5 0 00-6.4 0l-3 3a4.5 4.5 0 006.4 6.4l1-1"/></svg>,
  shield: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M12 3l8 3v6c0 5-3.5 8.5-8 9-4.5-.5-8-4-8-9V6l8-3z"/></svg>,
  bell: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M6 9a6 6 0 1112 0v3l2 4H4l2-4V9z"/><path d="M10 19a2 2 0 004 0"/></svg>,
  chart: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M4 19V5"/><path d="M4 19h16"/><rect x="8" y="11" width="3" height="6"/><rect x="13" y="7" width="3" height="10"/><rect x="18" y="13" width="3" height="4"/></svg>,
  lock: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><rect x="5" y="11" width="14" height="9" rx="2"/><path d="M8 11V8a4 4 0 018 0v3"/></svg>,
  family: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><circle cx="8" cy="8" r="3"/><circle cx="16" cy="8" r="3"/><path d="M2 20c0-3 2.5-5 6-5s6 2 6 5"/><path d="M14 20c.5-2 2.5-3.5 5-3.5s4.5 1.5 5 3.5"/></svg>,
  calendar: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><rect x="3" y="5" width="18" height="16" rx="2"/><path d="M3 10h18M8 3v4M16 3v4"/></svg>,
  grade: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M12 2l3 6 6.5 1-5 4.5L18 20l-6-3-6 3 1.5-6.5L2.5 9 9 8z"/></svg>,
  teacher: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><circle cx="12" cy="7" r="3.5"/><path d="M4 20c1.5-4 5-6 8-6s6.5 2 8 6"/><path d="M16 18l3 1v3l-3-1-3 1v-3l3-1z" fill="currentColor" stroke="none" opacity=".3"/></svg>,
  megaphone: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M3 11v2a2 2 0 002 2h2l8 4V5L7 9H5a2 2 0 00-2 2z"/><path d="M19 8a4 4 0 010 8"/></svg>,
  qr: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/><path d="M14 14h3v3M21 14v3M14 17v4h3M17 21h4"/></svg>,
  scan: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M3 7V5a2 2 0 012-2h2M17 3h2a2 2 0 012 2v2M21 17v2a2 2 0 01-2 2h-2M7 21H5a2 2 0 01-2-2v-2M3 12h18"/></svg>,
  clock: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><circle cx="12" cy="12" r="9"/><path d="M12 7v5l3.5 2"/></svg>,
  printer: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M6 9V3h12v6"/><rect x="3" y="9" width="18" height="9" rx="2"/><path d="M7 14h10v7H7z"/><path d="M3 9l3-3M21 9l-3-3" opacity="0" /></svg>,
  apple: (p) => <svg viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M16.4 12.6c0-2.7 2.2-4 2.3-4-1.3-1.8-3.2-2.1-3.9-2.1-1.6-.2-3.2 1-4 1-.8 0-2.1-.9-3.5-.9-1.8 0-3.5 1-4.4 2.7-1.9 3.2-.5 8 1.4 10.7.9 1.3 2 2.7 3.4 2.7 1.4-.1 1.9-.9 3.5-.9s2.1.9 3.5.9c1.5 0 2.4-1.3 3.3-2.7 1-1.5 1.4-3 1.4-3.1 0-.1-2.7-1-2.7-4.3zM13.8 4.8c.7-.9 1.2-2.1 1-3.4-1.1.1-2.4.7-3.1 1.6-.6.8-1.2 2-1 3.2 1.2.1 2.4-.6 3.1-1.4z"/></svg>,
  android: (p) => <svg viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M5.5 9h13c.3 0 .5.2.5.5V18c0 1.1-.9 2-2 2H7c-1.1 0-2-.9-2-2V9.5c0-.3.2-.5.5-.5zM3 11c0-.6.4-1 1-1s1 .4 1 1v5c0 .6-.4 1-1 1s-1-.4-1-1v-5zM19 11c0-.6.4-1 1-1s1 .4 1 1v5c0 .6-.4 1-1 1s-1-.4-1-1v-5zM9 20v2c0 .6.4 1 1 1s1-.4 1-1v-2H9zM13 20v2c0 .6.4 1 1 1s1-.4 1-1v-2h-2zM8 4l-1.5-2.5c-.1-.2 0-.4.2-.5.2-.1.4 0 .5.2L8.7 3.7c1-.4 2.1-.7 3.3-.7s2.3.3 3.3.7L16.8 1.2c.1-.2.3-.3.5-.2.2.1.3.3.2.5L16 4c2 1.1 3.4 3 3.5 5h-15c.1-2 1.5-3.9 3.5-5zM9.5 6.5a.6.6 0 100 1.2.6.6 0 000-1.2zm5 0a.6.6 0 100 1.2.6.6 0 000-1.2z"/></svg>,
  web: (p) => <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" {...p}><circle cx="12" cy="12" r="9"/><path d="M3 12h18M12 3a14 14 0 010 18M12 3a14 14 0 000 18"/></svg>,
  whatsapp: (p) => <svg viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M17.5 14.4c-.3-.1-1.7-.8-2-.9-.3-.1-.5-.2-.7.2-.2.3-.7.9-.9 1.1-.2.2-.3.2-.6.1-.3-.1-1.2-.5-2.3-1.5-.9-.8-1.4-1.7-1.6-2-.2-.3 0-.5.1-.7.1-.1.3-.3.4-.5.1-.2.2-.3.3-.5.1-.2 0-.4 0-.5 0-.1-.7-1.6-.9-2.2-.2-.6-.5-.5-.7-.5h-.6c-.2 0-.5.1-.8.4-.3.3-1 1-1 2.5s1.1 2.9 1.2 3.1c.1.2 2.1 3.2 5.1 4.5.7.3 1.3.5 1.7.6.7.2 1.4.2 1.9.1.6-.1 1.7-.7 2-1.4.2-.7.2-1.3.2-1.4-.1-.1-.3-.2-.5-.3zM12 2C6.5 2 2 6.5 2 12c0 1.8.5 3.5 1.3 5L2 22l5.1-1.3c1.5.8 3.1 1.3 4.9 1.3 5.5 0 10-4.5 10-10S17.5 2 12 2z"/></svg>,
};

/* ---------- Phone Mockup ---------- */
function Phone({ children, time = "9:41", className = "", style = {} }) {
  return (
    <div className={`phone ${className}`} style={style}>
      <div className="screen">
        <div className="notch" />
        <div className="status-bar">
          <span>{time}</span>
          <div className="icons">
            <svg viewBox="0 0 18 12" fill="currentColor"><circle cx="2" cy="10" r="1.5"/><circle cx="6" cy="10" r="1.5"/><circle cx="10" cy="10" r="1.5"/><circle cx="14" cy="10" r="1.5"/></svg>
            <svg viewBox="0 0 18 12" fill="none" stroke="currentColor" strokeWidth="1.2"><path d="M9 2c2 0 3.7.7 5 2"/><path d="M9 5c1 0 2 .4 2.7 1"/><circle cx="9" cy="8" r="1" fill="currentColor"/></svg>
            <svg viewBox="0 0 24 12" fill="none"><rect x="1" y="2" width="20" height="8" rx="2" stroke="currentColor" strokeWidth="1.2"/><rect x="3" y="4" width="16" height="4" rx="1" fill="currentColor"/><rect x="22" y="4" width="1.5" height="4" rx="0.5" fill="currentColor"/></svg>
          </div>
        </div>
        {children}
      </div>
    </div>
  );
}

/* Phone with screenshot fill */
function PhoneScreenshot({ src, time, className, style, topPad = 56 }) {
  return (
    <Phone time={time} className={className} style={style}>
      <div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, paddingTop: 0, background: '#ECEDF0' }}>
        <img src={src} alt="" style={{
          width: '100%',
          display: 'block',
          marginTop: topPad,
        }} />
      </div>
    </Phone>
  );
}

/* ---------- Browser Window ---------- */
function BrowserWindow({ children, url = "app.squol.mx", className = "", style = {} }) {
  return (
    <div className={`browser ${className}`} style={style}>
      <div className="browser-chrome">
        <div className="dots">
          <span style={{background:'#FF5F57'}}/>
          <span style={{background:'#FEBC2E'}}/>
          <span style={{background:'#28C840'}}/>
        </div>
        <div className="addr">
          <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2"><rect x="5" y="11" width="14" height="9" rx="2"/><path d="M8 11V8a4 4 0 018 0v3"/></svg>
          <span>{url}</span>
        </div>
        <div style={{ width: 56 }}/>
      </div>
      <div className="browser-body">
        {children}
      </div>
    </div>
  );
}

function BrowserScreenshot({ src, url, className, style }) {
  return (
    <BrowserWindow url={url} className={className} style={style}>
      <img src={src} alt="" style={{ width: '100%', display: 'block' }} />
    </BrowserWindow>
  );
}

/* ---------- QR Credential Card (phone screen) ---------- */
function QrCredentialPhone({ className, style }) {
  return (
    <Phone time="9:41" className={className} style={style}>
      <div style={{
        position: 'absolute', inset: 0,
        background: 'linear-gradient(180deg, #F4F6F8 0%, #E9ECF0 100%)',
        paddingTop: 56,
      }}>
        {/* Top header */}
        <div style={{ padding: '20px 22px 16px', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
          <div>
            <div style={{ fontSize: 13, color: '#6B7785', fontWeight: 500 }}>Mi credencial</div>
            <div style={{ fontSize: 22, fontWeight: 800, color: '#0E2330', letterSpacing: '-0.02em', marginTop: 2 }}>Camilo Ramírez</div>
          </div>
          <div style={{
            width: 36, height: 36, borderRadius: 12, background: '#fff',
            border: '1px solid #E2E4E9', display: 'flex', alignItems: 'center', justifyContent: 'center',
            color: '#0E2330'
          }}>
            <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.7 1.7 0 00.3 1.8l.1.1a2 2 0 11-2.8 2.8l-.1-.1a1.7 1.7 0 00-1.8-.3 1.7 1.7 0 00-1 1.5V21a2 2 0 11-4 0v-.1a1.7 1.7 0 00-1.1-1.5 1.7 1.7 0 00-1.8.3l-.1.1a2 2 0 11-2.8-2.8l.1-.1a1.7 1.7 0 00.3-1.8 1.7 1.7 0 00-1.5-1H3a2 2 0 110-4h.1a1.7 1.7 0 001.5-1.1 1.7 1.7 0 00-.3-1.8l-.1-.1a2 2 0 112.8-2.8l.1.1a1.7 1.7 0 001.8.3H9a1.7 1.7 0 001-1.5V3a2 2 0 114 0v.1a1.7 1.7 0 001 1.5 1.7 1.7 0 001.8-.3l.1-.1a2 2 0 112.8 2.8l-.1.1a1.7 1.7 0 00-.3 1.8V9a1.7 1.7 0 001.5 1H21a2 2 0 110 4h-.1a1.7 1.7 0 00-1.5 1z"/></svg>
          </div>
        </div>

        {/* Credential card */}
        <div style={{ margin: '0 18px', padding: 0, borderRadius: 20, overflow: 'hidden',
          background: 'linear-gradient(160deg, #1B3A4B 0%, #0E2330 100%)',
          color: '#fff',
          boxShadow: '0 30px 50px -25px rgba(11,34,50,0.5)',
          position: 'relative'
        }}>
          {/* Subtle accent glow */}
          <div style={{ position: 'absolute', top: -20, right: -20, width: 120, height: 120, borderRadius: '50%',
            background: 'radial-gradient(closest-side, rgba(255,138,31,0.25), transparent 70%)' }} />

          <div style={{ padding: '18px 18px 14px', display: 'flex', alignItems: 'center', justifyContent: 'space-between', borderBottom: '1px solid rgba(255,255,255,0.08)' }}>
            <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
              <div style={{ width: 18, height: 18, borderRadius: 5, background: '#1657F0', position: 'relative' }}>
                <div style={{ position: 'absolute', top: 2, right: 2, width: 6, height: 6, borderRadius: '50%', background: '#FF8A1F', border: '1px solid #fff' }} />
              </div>
              <span style={{ fontSize: 13, fontWeight: 700, letterSpacing: '-0.01em' }}>Colegio Aurora</span>
            </div>
            <span style={{ fontSize: 10, fontWeight: 600, letterSpacing: '0.1em', textTransform: 'uppercase', color: 'rgba(255,255,255,0.6)' }}>2026 — 2027</span>
          </div>

          <div style={{ padding: '18px', display: 'flex', gap: 14, alignItems: 'center' }}>
            {/* Student photo placeholder */}
            <div style={{
              width: 76, height: 92, borderRadius: 12,
              background: 'linear-gradient(180deg, #5b6f7d 0%, #34495a 100%)',
              flex: '0 0 76px',
              position: 'relative',
              overflow: 'hidden',
              border: '2px solid rgba(255,255,255,0.15)',
            }}>
              <div style={{ position: 'absolute', bottom: -10, left: '50%', transform: 'translateX(-50%)', width: 60, height: 60, borderRadius: '50%', background: 'rgba(255,255,255,0.15)' }}/>
              <div style={{ position: 'absolute', top: 16, left: '50%', transform: 'translateX(-50%)', width: 36, height: 36, borderRadius: '50%', background: 'rgba(255,255,255,0.25)' }}/>
            </div>
            <div style={{ flex: 1, minWidth: 0 }}>
              <div style={{ fontSize: 11, color: 'rgba(255,255,255,0.55)', textTransform: 'uppercase', letterSpacing: '0.08em', fontWeight: 600 }}>Alumno</div>
              <div style={{ fontSize: 17, fontWeight: 700, marginTop: 2, letterSpacing: '-0.01em' }}>Camilo Ramírez</div>
              <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 8, marginTop: 12, fontSize: 11 }}>
                <div>
                  <div style={{ color: 'rgba(255,255,255,0.5)' }}>Grupo</div>
                  <div style={{ fontWeight: 700, marginTop: 2 }}>1° A</div>
                </div>
                <div>
                  <div style={{ color: 'rgba(255,255,255,0.5)' }}>Matrícula</div>
                  <div style={{ fontWeight: 700, marginTop: 2 }}>A-0184</div>
                </div>
              </div>
            </div>
          </div>

          {/* QR */}
          <div style={{ background: '#fff', margin: '0 14px 14px', borderRadius: 14, padding: 14, display: 'flex', alignItems: 'center', gap: 12 }}>
            <QrCodeSvg size={88} />
            <div style={{ color: '#0E2330', fontSize: 11, lineHeight: 1.4 }}>
              <div style={{ fontWeight: 700, fontSize: 13 }}>Escanea para verificar</div>
              <div style={{ color: '#6B7785', marginTop: 4 }}>El código se renueva cada 30 segundos</div>
              <div style={{ marginTop: 6, display: 'flex', alignItems: 'center', gap: 4, color: '#19A05C', fontWeight: 600 }}>
                <span style={{ width: 6, height: 6, borderRadius: '50%', background: '#19A05C' }}/>
                Activo
              </div>
            </div>
          </div>
        </div>

        {/* Last entry */}
        <div style={{ margin: '18px 18px 0', padding: 14, background: '#fff', borderRadius: 14, border: '1px solid #E2E4E9', display: 'flex', alignItems: 'center', gap: 12 }}>
          <div style={{ width: 36, height: 36, borderRadius: 10, background: '#E7F6EC', color: '#19A05C', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
            <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2"><path d="M5 13l4 4L19 7"/></svg>
          </div>
          <div style={{ flex: 1 }}>
            <div style={{ fontSize: 13, fontWeight: 700, color: '#0E2330' }}>Entrada registrada</div>
            <div style={{ fontSize: 11, color: '#6B7785', marginTop: 2 }}>Hoy 07:42 · Acceso principal</div>
          </div>
        </div>
      </div>
    </Phone>
  );
}

/* ---------- Persona Scene — photo + optional floating mockup ---------- */
function PersonaScene({ persona }) {
  if (persona === 'directores') {
    // Wide landscape photo (man at desk) — no extra mockup
    return (
      <div className="persona-scene wide">
        <div className="photo-frame" style={{ aspectRatio: '5/4' }}>
          <img src="assets/persona-director.png" alt="Director consultando estadísticas" />
          <div className="photo-vignette"/>
        </div>
        <div className="float-badge bl">
          <div className="badge-icon"><Icon.chart/></div>
          <div>
            <div className="badge-h">Promedio 3°A</div>
            <div className="badge-p">8.7 · +0.3 vs mes anterior</div>
          </div>
        </div>
      </div>
    );
  }

  if (persona === 'padres') {
    return (
      <div className="persona-scene">
        <div className="photo-frame" style={{ aspectRatio: '3/4' }}>
          <img src="assets/persona-mama.png" alt="Madre recibiendo notificación Squol" />
          <div className="photo-vignette"/>
        </div>
        <div className="float-badge bl pill">
          <span className="pulse"/>
          <span>3 notificaciones hoy</span>
        </div>
      </div>
    );
  }

  if (persona === 'docentes') {
    return (
      <div className="persona-scene wide">
        <div className="photo-frame" style={{ aspectRatio: '5/4' }}>
          <img src="assets/persona-profesor.png" alt="Docente impartiendo clase" />
          <div className="photo-vignette"/>
        </div>
        <div className="float-badge tl">
          <div className="badge-icon"><Icon.calendar/></div>
          <div>
            <div className="badge-h">Próxima cita</div>
            <div className="badge-p">Sra. Pérez · 14:30</div>
          </div>
        </div>
      </div>
    );
  }

  if (persona === 'alumnos') {
    return (
      <div className="persona-scene">
        <div className="photo-frame" style={{ aspectRatio: '4/5' }}>
          <img src="assets/persona-alumno.png" alt="Alumno mostrando credencial QR" />
          <div className="photo-vignette"/>
        </div>
        <div className="float-badge tr">
          <div className="badge-icon green"><Icon.scan/></div>
          <div>
            <div className="badge-h">Acceso autorizado</div>
            <div className="badge-p">José Antonio · 2° Sec.</div>
          </div>
        </div>
      </div>
    );
  }

  return null;
}
function QrCodeSvg({ size = 80 }) {
  // deterministic-ish pattern
  const cells = 21;
  const data = [];
  const seed = 1337;
  const rand = (i) => {
    const x = Math.sin(seed + i * 13.37) * 10000;
    return (x - Math.floor(x)) > 0.5;
  };
  for (let y = 0; y < cells; y++) {
    for (let x = 0; x < cells; x++) {
      const i = y * cells + x;
      // finder patterns: corners
      const inFinder = (
        (x < 7 && y < 7) ||
        (x >= cells - 7 && y < 7) ||
        (x < 7 && y >= cells - 7)
      );
      if (!inFinder && rand(i)) data.push([x, y]);
    }
  }
  return (
    <svg viewBox={`0 0 ${cells} ${cells}`} width={size} height={size} style={{ display: 'block', shapeRendering: 'crispEdges' }}>
      <rect width={cells} height={cells} fill="#fff"/>
      {/* finders */}
      {[[0,0],[cells-7,0],[0,cells-7]].map(([fx,fy], i) => (
        <g key={i}>
          <rect x={fx} y={fy} width="7" height="7" fill="#0E2330"/>
          <rect x={fx+1} y={fy+1} width="5" height="5" fill="#fff"/>
          <rect x={fx+2} y={fy+2} width="3" height="3" fill="#0E2330"/>
        </g>
      ))}
      {data.map(([x,y], i) => (
        <rect key={i} x={x} y={y} width="1" height="1" fill="#0E2330"/>
      ))}
    </svg>
  );
}

/* ---------- Squol Logo ---------- */
function SquolMark({ size = 28 }) {
  return (
    <div className="squol-mark" style={{ width: size, height: size, fontSize: size * 0.55 }}>
      <span style={{ marginRight: 5 }}>s</span>
    </div>
  );
}

function SquolLogo({ inverted = false }) {
  return (
    <div className="brand">
      <img src="assets/logo-squol.png" alt="Squol" />
      <span>Squol</span>
    </div>
  );
}

/* ---------- Reveal hook ---------- */
function useReveal() {
  const ref = useRef(null);
  useEffect(() => {
    const el = ref.current;
    if (!el) return;
    const io = new IntersectionObserver((entries) => {
      entries.forEach(e => {
        if (e.isIntersecting) {
          e.target.classList.add('in');
        }
      });
    }, { threshold: 0.12 });
    io.observe(el);
    return () => io.disconnect();
  }, []);
  return ref;
}

function Reveal({ children, delay = 0, as: As = 'div', className = '', style = {} }) {
  const ref = useReveal();
  return (
    <As ref={ref} className={`reveal ${className}`} style={{ ...style, transitionDelay: `${delay}ms` }}>
      {children}
    </As>
  );
}

function TermsPrivacyModal({ isOpen, activeTab: initialTab, onClose }) {
  const [activeTab, setActiveTab] = React.useState(initialTab || 'terms');

  React.useEffect(() => {
    if (isOpen) {
      setActiveTab(initialTab || 'terms');
      document.body.style.overflow = 'hidden';
    } else {
      document.body.style.overflow = '';
    }
    return () => {
      document.body.style.overflow = '';
    };
  }, [isOpen, initialTab]);

  if (!isOpen) return null;

  return (
    <div className="legal-modal-overlay" onClick={onClose}>
      <div className="legal-modal-container" onClick={(e) => e.stopPropagation()}>
        <div className="legal-modal-header">
          <div className="legal-modal-tabs">
            <button
              className={`legal-modal-tab ${activeTab === 'terms' ? 'active' : ''}`}
              onClick={() => setActiveTab('terms')}
            >
              Términos y Condiciones
            </button>
            <button
              className={`legal-modal-tab ${activeTab === 'privacy' ? 'active' : ''}`}
              onClick={() => setActiveTab('privacy')}
            >
              Aviso de Privacidad
            </button>
          </div>
          <button className="legal-modal-close" onClick={onClose} aria-label="Cerrar">
            <Icon.close style={{ width: 20, height: 20 }} />
          </button>
        </div>
        <div className="legal-modal-body">
          {activeTab === 'terms' ? (
            <div className="legal-content">
              <h2>Términos y Condiciones de Uso</h2>
              <p className="legal-subtitle">Última actualización: Mayo 2026</p>
              <p>Bienvenido a Squol. Al acceder y utilizar nuestra plataforma, usted acepta cumplir con los siguientes términos y condiciones:</p>
              
              <h3>1. Aceptación de los Términos</h3>
              <p>Al registrarse y utilizar los servicios de Squol, usted manifiesta bajo protesta de decir verdad que es mayor de edad, responsable del manejo de la cuenta y padre, madre o tutor del menor registrado, o personal escolar autorizado por la institución educativa.</p>
              
              <h3>2. Descripción del Servicio</h3>
              <p>Squol es una plataforma digital de comunicación escolar que facilita la interacción entre la institución educativa, los docentes, prefectos, y los padres o tutores legales de los alumnos. El servicio incluye el envío de notificaciones, control de credenciales, avisos y seguimiento escolar.</p>
              
              <h3>3. Uso Responsable de la Cuenta</h3>
              <p>Usted es el único responsable de mantener la confidencialidad de su contraseña y de todas las actividades que ocurran bajo su cuenta. Se compromete a notificar de inmediato cualquier uso no autorizado de su cuenta.</p>
              
              <h3>4. Privacidad y Datos Personales</h3>
              <p>La recopilación y el uso de sus datos personales se rigen por nuestro Aviso de Privacidad. Al utilizar la plataforma, acepta que registremos la Fecha, Hora exacta e IP pública de su registro y aceptación de términos como prueba legal de su consentimiento.</p>
              
              <h3>5. Limitación de Responsabilidad</h3>
              <p>Squol no será responsable por daños indirectos, incidentales o consecuentes derivados del uso o la imposibilidad de usar la plataforma.</p>
            </div>
          ) : (
            <div className="legal-content">
              <h2>Aviso de Privacidad Simplificado</h2>
              <p className="legal-subtitle">Última actualización: Mayo 2026</p>
              <p>En Squol (Aryento Studio), nos comprometemos a proteger la privacidad y seguridad de sus datos personales y los de sus hijos menores de edad.</p>
              
              <h3>1. Datos Personales Recabados</h3>
              <p>Para la prestación de nuestros servicios, recabamos:</p>
              <ul>
                <li>Nombre completo, correo electrónico, y teléfono de contacto del padre/madre/tutor o personal de la escuela.</li>
                <li>Nombre completo, grado y grupo del alumno menor de edad.</li>
                <li>Fotografía del menor (únicamente para fines de identificación escolar y credenciales digitales/físicas).</li>
                <li>Datos de auditoría técnica: Dirección IP pública, fecha y hora del consentimiento digital.</li>
              </ul>
              
              <h3>2. Finalidades del Tratamiento</h3>
              <p>Los datos personales recabados serán utilizados exclusivamente para:</p>
              <ul>
                <li>La creación, validación y gestión de la cuenta del usuario en Squol.</li>
                <li>La generación y emisión de la credencial digital y física del alumno.</li>
                <li>El envío de notificaciones y alertas escolares oficiales.</li>
                <li>El cumplimiento de obligaciones legales de consentimiento (auditoría digital).</li>
              </ul>
              
              <h3>3. Autorización de Fotografía del Menor</h3>
              <p>De conformidad con las leyes vigentes, la fotografía del alumno menor de edad se utilizará <strong>únicamente</strong> para fines de identificación escolar dentro del marco de la credencial oficial. No será transferida a terceros no autorizados ni se utilizará para fines publicitarios sin su consentimiento expreso.</p>
              
              <h3>4. Derechos ARCO</h3>
              <p>Usted puede ejercer sus derechos de Acceso, Rectificación, Cancelación y Oposición escribiendo directamente a nuestro correo de contacto oficial: <strong>hola@squol.app</strong>.</p>
            </div>
          )}
        </div>
      </div>
      <style>{`
        .legal-modal-overlay {
          position: fixed;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          background-color: rgba(14, 35, 48, 0.75);
          backdrop-filter: blur(10px);
          -webkit-backdrop-filter: blur(10px);
          display: flex;
          align-items: center;
          justify-content: center;
          z-index: 10000;
          opacity: 0;
          animation: fadeInLegal 0.3s ease forwards;
        }
        .legal-modal-container {
          width: 92%;
          max-width: 680px;
          max-height: 80vh;
          background: #ffffff;
          border-radius: 24px;
          box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.4);
          border: 1px solid rgba(255, 255, 255, 0.2);
          display: flex;
          flex-direction: column;
          overflow: hidden;
          transform: translateY(30px);
          animation: slideUpLegal 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
          color: #0E2330;
        }
        .legal-modal-header {
          display: flex;
          align-items: center;
          justify-content: space-between;
          border-bottom: 1px solid rgba(0, 0, 0, 0.06);
          padding: 12px 24px;
          background: #f8fafc;
        }
        .legal-modal-tabs {
          display: flex;
          gap: 8px;
        }
        .legal-modal-tab {
          border: none;
          background: none;
          padding: 14px 18px;
          font-family: 'Plus Jakarta Sans', sans-serif;
          font-size: 15px;
          font-weight: 700;
          color: #64748b;
          cursor: pointer;
          position: relative;
          transition: all 0.2s ease;
          border-radius: 8px;
        }
        .legal-modal-tab:hover {
          color: #0E2330;
          background: rgba(0, 0, 0, 0.03);
        }
        .legal-modal-tab.active {
          color: var(--accent, #FF8A1F);
          background: rgba(255, 138, 31, 0.06);
        }
        .legal-modal-tab.active::after {
          content: '';
          position: absolute;
          bottom: 0;
          left: 18px;
          right: 18px;
          height: 3px;
          background-color: var(--accent, #FF8A1F);
          border-radius: 99px;
        }
        .legal-modal-close {
          border: none;
          background: rgba(0, 0, 0, 0.05);
          width: 40px;
          height: 40px;
          border-radius: 50%;
          display: flex;
          align-items: center;
          justify-content: center;
          cursor: pointer;
          color: #64748b;
          transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
        }
        .legal-modal-close:hover {
          background: rgba(239, 68, 68, 0.1);
          color: #ef4444;
          transform: rotate(90deg);
        }
        .legal-modal-body {
          flex: 1;
          overflow-y: auto;
          padding: 32px;
          background: #ffffff;
        }
        .legal-content {
          font-family: 'Plus Jakarta Sans', sans-serif;
          line-height: 1.7;
          font-size: 14.5px;
          color: #334155;
        }
        .legal-content h2 {
          font-size: 22px;
          font-weight: 800;
          margin-top: 0;
          margin-bottom: 8px;
          color: #0E2330;
          letter-spacing: -0.5px;
        }
        .legal-subtitle {
          font-size: 13px;
          color: #64748b;
          margin-bottom: 24px;
          font-weight: 500;
        }
        .legal-content h3 {
          font-size: 16px;
          font-weight: 800;
          margin-top: 24px;
          margin-bottom: 8px;
          color: #0E2330;
          letter-spacing: -0.3px;
        }
        .legal-content p {
          margin-top: 0;
          margin-bottom: 16px;
        }
        .legal-content ul {
          margin-top: 0;
          margin-bottom: 16px;
          padding-left: 24px;
        }
        .legal-content li {
          margin-bottom: 8px;
        }
        @keyframes fadeInLegal {
          to { opacity: 1; }
        }
        @keyframes slideUpLegal {
          to { transform: translateY(0); }
        }
      `}</style>
    </div>
  );
}

Object.assign(window, { Icon, Phone, PhoneScreenshot, BrowserWindow, BrowserScreenshot, QrCredentialPhone, QrCodeSvg, SquolMark, SquolLogo, Reveal, useReveal, PersonaScene, TermsPrivacyModal });
