const { useState, useEffect, useRef } = React;

// ── Icons ────────────────────────────────────────────────────
const I = ({ c, s = 20, w = 1.8 }) => <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={w} strokeLinecap="round" strokeLinejoin="round">{c}</svg>;
const IconDash = (p) => <I s={p.s} c={<><rect x="3" y="3" width="7" height="9" rx="1.5"/><rect x="14" y="3" width="7" height="5" rx="1.5"/><rect x="14" y="12" width="7" height="9" rx="1.5"/><rect x="3" y="16" width="7" height="5" rx="1.5"/></>} />;
const IconStore = (p) => <I s={p.s} c={<><path d="M3 9l1.5-4h15L21 9"/><path d="M4 9v10h16V9"/><path d="M3 9a3 3 0 0 0 6 0 3 3 0 0 0 6 0 3 3 0 0 0 6 0"/></>} />;
const IconCash = (p) => <I s={p.s} c={<><rect x="2" y="6" width="20" height="12" rx="2"/><circle cx="12" cy="12" r="2.5"/></>} />;
const IconBill = (p) => <I s={p.s} c={<><path d="M3 3h16v18l-3-2-3 2-3-2-3 2-4-2V3Z"/><path d="M7 8h8M7 12h5"/></>} />;
const IconBag = (p) => <I s={p.s} c={<><path d="M4 8h16l-1.5 12a2 2 0 0 1-2 2H7.5a2 2 0 0 1-2-2L4 8Z"/><path d="M8 8V6a4 4 0 0 1 8 0v2"/></>} />;
const IconChef = (p) => <I s={p.s} c={<><path d="M6 14h12v6H6z"/><path d="M8 14V9a4 4 0 0 1 8 0v5"/><circle cx="9" cy="7" r="2"/><circle cx="15" cy="7" r="2"/></>} />;
const IconChart = (p) => <I s={p.s} c={<><path d="M3 3v18h18"/><path d="M7 14l4-4 3 3 5-7"/></>} />;
const IconUsers = (p) => <I s={p.s} c={<><circle cx="9" cy="8" r="3.5"/><path d="M3 20a6 6 0 0 1 12 0"/><circle cx="17" cy="9" r="2.5"/><path d="M15 20a5 5 0 0 1 6 0"/></>} />;
const IconWhats = (p) => <I s={p.s} c={<><path d="M4 20l1.5-4.5A8 8 0 1 1 9 19.5L4 20Z"/><path d="M9 10c0 3 2 5 5 5l1.5-1.5-2-1-1 1c-1 0-2-1-2-2l1-1-1-2L9 10Z" fill="currentColor"/></>} />;
const IconArrow = (p) => <I s={p.s} c={<><path d="M5 12h14M13 6l6 6-6 6"/></>} />;
const IconCheck = (p) => <I s={p.s} c={<path d="M5 12.5l4 4 10-10"/>} />;
const IconX = (p) => <I s={p.s} c={<><path d="M6 6l12 12M18 6L6 18"/></>} />;
const IconPlay = (p) => <I s={p.s} c={<path d="M7 4.5v15l13-7.5L7 4.5Z" fill="currentColor" stroke="none"/>} />;
const IconSun = (p) => <I s={p.s} c={<><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M2 12h2M20 12h2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"/></>} />;
const IconMoon = (p) => <I s={p.s} c={<path d="M20 14.5A8 8 0 0 1 9.5 4a7 7 0 1 0 10.5 10.5Z"/>} />;
const IconPlus = (p) => <I s={p.s} c={<><path d="M12 5v14M5 12h14"/></>} />;
const IconWhatsLogo = ({ s = 18 }) => (
  <svg width={s} height={s} viewBox="0 0 24 24" aria-hidden="true" fill="currentColor" style={{ display: 'inline-block', flexShrink: 0 }}>
    <path d="M19.05 4.91A10 10 0 0 0 12 2a10 10 0 0 0-8.5 15.16L2 22l4.95-1.45A10 10 0 0 0 12 22a10 10 0 0 0 7.05-17.09Zm-7.05 15.4a8.32 8.32 0 0 1-4.24-1.16l-.3-.18-2.94.86.88-2.86-.2-.31A8.31 8.31 0 1 1 20.31 12a8.32 8.32 0 0 1-8.31 8.31Zm4.56-6.23c-.25-.13-1.48-.73-1.71-.81-.23-.08-.4-.13-.56.13-.17.25-.65.81-.8.98-.15.17-.29.19-.54.06-.25-.13-1.06-.39-2.02-1.25a7.6 7.6 0 0 1-1.4-1.74c-.15-.25 0-.39.11-.51.12-.12.25-.29.37-.43.13-.15.17-.25.25-.42.08-.17.04-.31-.02-.44-.06-.13-.56-1.36-.77-1.86-.2-.49-.41-.42-.56-.43h-.48a.92.92 0 0 0-.66.31c-.23.25-.87.85-.87 2.07 0 1.22.9 2.4 1.02 2.57.13.17 1.77 2.7 4.28 3.79.6.26 1.07.41 1.43.53.6.19 1.15.16 1.58.1.48-.07 1.48-.6 1.69-1.18.21-.58.21-1.08.15-1.18-.06-.1-.23-.16-.48-.29Z"/>
  </svg>
);
const IconGear = (p) => <I s={p.s} c={<><circle cx="12" cy="12" r="3"/><path d="M19 12a7 7 0 0 0-.1-1.3l2-1.5-2-3.5-2.4.9a7 7 0 0 0-2.2-1.3L14 3h-4l-.3 2.3a7 7 0 0 0-2.2 1.3L5 5.7l-2 3.5 2 1.5A7 7 0 0 0 4.9 12a7 7 0 0 0 .1 1.3l-2 1.5 2 3.5 2.4-.9a7 7 0 0 0 2.2 1.3L10 21h4l.3-2.3a7 7 0 0 0 2.2-1.3l2.5.9 2-3.5-2-1.5c.1-.5.1-.9.1-1.3Z"/></>} />;

// ── Logo ─────────────────────────────────────────────────────
const Logo = ({ size = 32, white }) => (
  <span style={{ display: 'inline-flex', alignItems: 'center', gap: 10 }}>
    <span style={{ fontWeight: 500, fontSize: size * .68, letterSpacing: '-.02em', color: white ? '#fff' : 'var(--blue)' }}>
      Cardápio <b style={{ fontWeight: 800, color: white ? '#fff' : 'var(--ink)' }}>Code</b>
    </span>
  </span>
);

// ── Reveal hook ──────────────────────────────────────────────
const useInView = () => {
  const ref = useRef(null);
  const [seen, setSeen] = useState(false);
  useEffect(() => {
    if (!ref.current) return;
    const io = new IntersectionObserver(([e]) => { if (e.isIntersecting) { setSeen(true); io.disconnect(); } }, { threshold: .12 });
    io.observe(ref.current);
    return () => io.disconnect();
  }, []);
  return [ref, seen];
};
const Reveal = ({ children, delay = 0, style = {} }) => {
  const [ref, seen] = useInView();
  return <div ref={ref} className={`reveal ${seen ? 'in' : ''}`} style={{ transitionDelay: `${delay}ms`, ...style }}>{children}</div>;
};
const CountUp = ({ to, dur = 1400, suf = '', dec = 0 }) => {
  const [ref, seen] = useInView();
  const [v, setV] = useState(0);
  useEffect(() => {
    if (!seen) return;
    const s = performance.now();
    const tick = (n) => { const p = Math.min(1, (n - s) / dur); setV(to * (1 - Math.pow(1 - p, 3))); if (p < 1) requestAnimationFrame(tick); };
    requestAnimationFrame(tick);
  }, [seen]);
  return <span ref={ref}>{dec ? v.toFixed(dec) : Math.round(v).toLocaleString('pt-BR')}{suf}</span>;
};

// ── KDS Mockup (matches real screenshot) ─────────────────────
const KDSBoard = ({ compact }) => {
  const [tick, setTick] = useState(0);
  useEffect(() => { const t = setInterval(() => setTick(x => x + 1), 3200); return () => clearInterval(t); }, []);
  const ChefIcon = () => <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><path d="M17 21H7v-2h10v2zM12 3a4 4 0 0 1 4 4 4 4 0 0 1-.27 1.45A4 4 0 0 1 19 12c0 1.5-.83 2.8-2 3.46V17H7v-1.54c-1.17-.66-2-1.96-2-3.46a4 4 0 0 1 3.27-3.55A4 4 0 0 1 8 7a4 4 0 0 1 4-4z"/></svg>;
  const ClockIcon = () => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round"><circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/></svg>;
  const TruckIcon = () => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round"><path d="M3 17h13V5H3z"/><path d="M16 8h4l3 4v5h-7"/><circle cx="7.5" cy="17.5" r="1.5"/><circle cx="17.5" cy="17.5" r="1.5"/></svg>;
  const CheckIcon = () => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round"><path d="M5 12l5 5L20 7"/></svg>;
  const Arrow = () => <svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round"><path d="M5 12h14M13 5l7 7-7 7"/></svg>;
  const cols = [
    { t: 'Em preparação', Ic: ChefIcon, bg: '#F59E0B', n: 2, orders: [
      { n: '#11', t: '5min', tags: ['BALCÃO', 'MESA 1'], item: 'Duplo + Nuggets', action: 'PRONTO P/ SERVIR' },
      { n: '#1', t: '12min', tags: ['BALCÃO', 'RETIRADA'], item: 'Combo Família', action: 'PRONTO / AGUARDANDO' },
    ]},
    { t: 'Prontos para entrega', Ic: ClockIcon, bg: '#10B981', n: 1, orders: [
      { n: '#10', t: '8min', tags: ['BALCÃO', 'MESA 1'], item: 'Barca Tradicional', action: 'SERVIDO NA MESA' },
    ]},
    { t: 'Saiu p/ entrega', Ic: TruckIcon, bg: '#EF4444', n: 0, orders: [] },
    { t: 'Concluído', Ic: CheckIcon, bg: '#16A34A', n: 8, orders: [
      { n: '#7', t: '25min', tags: ['DELIVERY'], item: 'Pizza Calabresa', action: 'ENTREGUE' },
      { n: '#8', t: '32min', tags: ['BALCÃO'], item: 'Combo Big', action: 'ENTREGUE' },
    ]},
  ];
  return (
    <div className="kds-grid" style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 10, fontSize: compact ? 10 : 11 }}>
      {cols.map((col, ci) => {
        const Ic = col.Ic;
        return (
          <div key={col.t} style={{ background: 'var(--bg)', borderRadius: 10, overflow: 'hidden', minHeight: compact ? 180 : 280, borderTop: `3px solid ${col.bg}` }}>
            <div className="kds-col-header" style={{ background: col.bg, color: '#fff', padding: compact ? '6px 10px' : '8px 12px', display: 'flex', justifyContent: 'space-between', alignItems: 'center', fontWeight: 700, gap: 8 }}>
              <span style={{ display: 'inline-flex', alignItems: 'center', gap: 6 }}><Ic/>{col.t}</span>
              <span style={{ background: 'rgba(255,255,255,.25)', borderRadius: 999, padding: '1px 8px', fontSize: compact ? 10 : 11 }}>{col.n}</span>
            </div>
            <div style={{ padding: 8, display: 'flex', flexDirection: 'column', gap: 6 }}>
              {col.orders.slice(0, compact ? 2 : 3).map((o, i) => (
                <div key={`${tick}-${o.n}`} className={ci === 0 && i === 0 ? 'slot-in' : ''} style={{ background: 'var(--card)', border: '1px solid var(--line)', borderRadius: 8, padding: compact ? 7 : 9, borderLeft: `3px solid ${col.bg}`, display: 'flex', flexDirection: 'column', gap: 6 }}>
                  <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
                    <span style={{ fontWeight: 800, fontSize: compact ? 12 : 14 }}>{o.n}</span>
                    <span className="mono" style={{ color: '#EF4444', fontSize: compact ? 10 : 11, fontWeight: 700 }}>{o.t}</span>
                  </div>
                  <div style={{ display: 'flex', gap: 4, flexWrap: 'wrap' }}>
                    {o.tags.map(tag => (
                      <span key={tag} style={{ background: 'var(--bg)', color: 'var(--ink-2)', padding: '2px 6px', borderRadius: 4, fontSize: compact ? 8 : 9, fontWeight: 700, letterSpacing: '.04em', border: '1px solid var(--line)' }}>{tag}</span>
                    ))}
                  </div>
                  <div style={{ display: 'flex', alignItems: 'center', gap: 5, fontSize: compact ? 10 : 11 }}>
                    <span style={{ background: '#F59E0B', color: '#fff', padding: '1px 5px', borderRadius: 3, fontSize: compact ? 8 : 9, fontWeight: 700 }}>1×</span>
                    <span style={{ color: 'var(--ink-2)', fontWeight: 500 }}>{o.item}</span>
                  </div>
                  <button style={{ background: '#7C3AED', color: '#fff', border: 0, borderRadius: 6, padding: compact ? '5px 8px' : '7px 10px', fontSize: compact ? 9 : 10, fontWeight: 700, letterSpacing: '.03em', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', gap: 6, cursor: 'default' }}>
                    {o.action} <Arrow/>
                  </button>
                </div>
              ))}
              {col.orders.length === 0 && (
                <div style={{ textAlign: 'center', padding: '24px 10px', color: 'var(--muted-2)', fontSize: compact ? 9 : 10, display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 6, opacity: .5 }}>
                  <Ic/> Vazio
                </div>
              )}
            </div>
          </div>
        );
      })}
    </div>
  );
};

// ── Dashboard / Relatório mockup ─────────────────────────────
const RelatoryMock = () => (
  <div style={{ background: 'var(--bg)', borderRadius: 12, padding: 16 }}>
    <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', marginBottom: 14 }}>
      <div>
        <div style={{ fontSize: 18, fontWeight: 700 }}>Relatório</div>
        <div style={{ fontSize: 11, color: 'var(--muted)' }}>Acompanhe o desempenho do seu negócio</div>
      </div>
      <div style={{ display: 'flex', gap: 4 }}>
        {['Hoje','7 dias','30 dias','Personalizado'].map((t,i) => (
          <span key={t} style={{ padding: '4px 10px', borderRadius: 6, fontSize: 10, fontWeight: 600, background: i === 2 ? 'var(--orange)' : 'var(--card)', color: i === 2 ? '#fff' : 'var(--ink-2)', border: i === 2 ? 'none' : '1px solid var(--line)' }}>{t}</span>
        ))}
      </div>
    </div>
    <div style={{ background: 'var(--card)', borderRadius: 8, padding: 10, marginBottom: 10, display: 'flex', alignItems: 'center', gap: 8, border: '1px solid var(--line)' }}>
      <span style={{ color: 'var(--green)' }}>✓</span>
      <span style={{ fontSize: 11, fontWeight: 600 }}>Estoque em dia</span>
      <span style={{ fontSize: 10, color: 'var(--muted)' }}>Nenhum item vencendo ou em falta</span>
    </div>
    <div className="kpi-grid-4" style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 8, marginBottom: 10 }}>
      {[
        { l: 'TOTAL DE PEDIDOS', v: '13', s: '0 cancelados' },
        { l: 'FATURAMENTO', v: 'R$ 1.420,00', s: '' },
        { l: 'TICKET MÉDIO', v: 'R$ 109,23', s: '' },
        { l: 'PEDIDOS VÁLIDOS', v: '13', s: '' },
      ].map(k => (
        <div key={k.l} style={{ background: 'var(--card)', border: '1px solid var(--line)', borderRadius: 8, padding: 10 }}>
          <div style={{ fontSize: 8.5, color: 'var(--muted)', fontWeight: 600, letterSpacing: '.05em' }}>{k.l}</div>
          <div className="mono" style={{ fontSize: 16, fontWeight: 700, marginTop: 2 }}>{k.v}</div>
          {k.s && <div style={{ fontSize: 9, color: 'var(--muted)' }}>{k.s}</div>}
        </div>
      ))}
    </div>
    <div className="status-grid" style={{ display: 'grid', gridTemplateColumns: '6fr 4fr 4fr 4fr 4fr 4fr', gap: 6, marginBottom: 10 }}>
      {[{c:'#F59E0B',v:0,l:'Em análise'},{c:'#F59E0B',v:2,l:'Na cozinha'},{c:'#3B82F6',v:0,l:'Aguardando'},{c:'#EF4444',v:0,l:'Saiu entrega'},{c:'#10B981',v:11,l:'Entregues'},{c:'#EF4444',v:0,l:'Cancelados'}].map((s,i) => (
        <div key={i} style={{ background: 'var(--card)', borderLeft: `3px solid ${s.c}`, padding: '8px 10px', borderRadius: 6, border: '1px solid var(--line)', borderLeftWidth: 3 }}>
          <div style={{ fontSize: 18, fontWeight: 700 }}>{s.v}</div>
          <div style={{ fontSize: 9, color: 'var(--muted)' }}>{s.l}</div>
        </div>
      ))}
    </div>
    <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 8 }}>
      <div style={{ background: 'var(--card)', border: '1px solid var(--line)', borderRadius: 8, padding: 10 }}>
        <div style={{ fontSize: 10, fontWeight: 600, marginBottom: 8 }}>Faturamento no período</div>
        <svg viewBox="0 0 220 60" style={{ width: '100%', height: 50 }}>
          {[8,12,6,10,14,8,11,9,16,13,38,55].map((h,i) => (
            <rect key={i} x={i * 19} y={60 - h} width="14" height={h} rx="2" fill={i > 9 ? '#F59E0B' : '#F59E0B'} opacity={i > 9 ? 1 : .3}/>
          ))}
        </svg>
      </div>
      <div style={{ background: 'var(--card)', border: '1px solid var(--line)', borderRadius: 8, padding: 10 }}>
        <div style={{ fontSize: 10, fontWeight: 600, marginBottom: 8 }}>Por tipo</div>
        <div style={{ display: 'flex', justifyContent: 'space-between', padding: '2px 0', fontSize: 10.5 }}>
          <span>🛵 Entrega</span><span className="mono" style={{ fontWeight: 600 }}>R$ 820 · 7</span>
        </div>
        <div style={{ display: 'flex', justifyContent: 'space-between', padding: '2px 0', fontSize: 10.5 }}>
          <span>🛍 Retirada</span><span className="mono" style={{ fontWeight: 600 }}>R$ 600 · 6</span>
        </div>
      </div>
    </div>
  </div>
);

// ── Catalog storefront mockup (cliente) ──────────────────────
const StorefrontMock = () => {
  // Decorative banner — use the real Bonjour Sucree imagery uploaded.
  const Banner = () => (
    <div style={{ width: '100%', height: 90, overflow: 'hidden', background: '#FFD6E7' }}>
      <img src="assets/bonjour-banner.png" alt="" style={{ width: '100%', height: '100%', objectFit: 'cover', display: 'block' }}/>
    </div>
  );

  // Cake-pot product tile — cute SVG mason-jar-with-frosting per flavor
  const Cake = ({ top, base, sprinkleColors, label }) => (
    <svg viewBox="0 0 60 60" style={{ width: 44, height: 44 }}>
      {/* jar */}
      <rect x="14" y="22" width="32" height="32" rx="3" fill={base}/>
      <rect x="14" y="22" width="32" height="6" rx="3" fill="#FFFFFF" opacity=".18"/>
      <rect x="14" y="48" width="32" height="6" rx="3" fill="#000" opacity=".08"/>
      {/* cream/topping */}
      <path d="M14 22 Q 22 10, 30 18 T 46 22 L 46 28 L 14 28 Z" fill={top}/>
      <circle cx="22" cy="16" r="3" fill={top}/>
      <circle cx="30" cy="13" r="3.6" fill={top}/>
      <circle cx="38" cy="16" r="3" fill={top}/>
      {/* sprinkles */}
      {sprinkleColors.map((c, i) => (
        <rect key={i} x={18 + i * 5} y={14 + (i % 2) * 3} width="2" height="1" fill={c} transform={`rotate(${(i*23) % 60} ${19 + i*5} ${14 + (i%2)*3})`}/>
      ))}
      <title>{label}</title>
    </svg>
  );

  const products = [
    { n: 'Bolo de pote brigadeiro', p: 'R$ 10,00', top: '#5B3A1E', base: '#7B4B26', spr: ['#fff', '#FCD34D', '#FBC4DC', '#fff'] },
    { n: 'Bolo de pote prestígio M', p: 'R$ 10,00', top: '#FFFFFF', base: '#5B3A1E', spr: ['#5B3A1E', '#5B3A1E', '#fff', '#5B3A1E'] },
    { n: 'Bolo de pote limão M', p: 'R$ 10,00', top: '#D9F99D', base: '#FEF9C3', spr: ['#84CC16', '#fff', '#84CC16', '#FCD34D'] },
    { n: 'Bolo de pote doce de leite M', p: 'R$ 10,00', top: '#FCD34D', base: '#F59E0B', spr: ['#fff', '#7B4B26', '#fff', '#7B4B26'] },
  ];

  return (
    <div style={{ background: '#FFF7ED', borderRadius: 12, overflow: 'hidden', border: '1px solid var(--line)' }}>
      <Banner />
      <div style={{ padding: '0 14px', marginTop: -22, position: 'relative' }}>
        <div style={{ width: 50, height: 50, borderRadius: '50%', background: '#fff', border: '3px solid #fff', boxShadow: '0 4px 10px rgba(0,0,0,.08)', margin: '0 auto', overflow: 'hidden' }}>
          <img src="assets/bonjour-logo.png" alt="Bonjour Sucree" style={{ width: '100%', height: '100%', objectFit: 'cover', display: 'block' }}/>
        </div>
        <div style={{ textAlign: 'center', marginTop: 6 }}>
          <div style={{ fontWeight: 700, fontSize: 14, color: '#7C2D12', letterSpacing: '-.01em' }}>Bonjour Sucree</div>
          <div style={{ fontSize: 9.5, color: 'var(--muted)' }}>📍 Guarujá - SP · Mais informações</div>
          <div style={{ fontSize: 9.5, color: '#EC4899', fontWeight: 700, marginTop: 2 }}>● Aberto agora</div>
        </div>
      </div>
      <div style={{ padding: '10px 14px', borderTop: '1px solid var(--line)', marginTop: 12 }}>
        <div style={{ display: 'flex', gap: 8, alignItems: 'center', padding: '4px 0', fontSize: 10 }}>
          <span>🛵</span><span style={{ color: '#EC4899', fontWeight: 600 }}>Calcular taxa e tempo de entrega</span>
        </div>
        <div style={{ display: 'flex', gap: 8, alignItems: 'center', padding: '4px 0', fontSize: 10 }}>
          <span>🏆</span>
          <div><div style={{ fontWeight: 600 }}>Programa de fidelidade</div><div style={{ fontSize: 9, color: 'var(--muted)' }}>A cada R$ 1,00 em compras você ganha 1 ponto</div></div>
        </div>
      </div>
      <div style={{ padding: 14, background: '#fff', display: 'grid', gridTemplateColumns: '1.4fr 1fr', gap: 10 }}>
        <div style={{ background: '#fff', border: '1px solid var(--line)', borderRadius: 8, padding: 10 }}>
          <div style={{ fontSize: 10.5, fontWeight: 700, color: '#EC4899', marginBottom: 6, display: 'flex', alignItems: 'center', gap: 4 }}>🍰 Bolo de Pote <span style={{ color: 'var(--muted)', marginLeft: 'auto' }}>{products.length}</span></div>
          {products.map((it, i) => (
            <div key={i} style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '6px 0', borderTop: i ? '1px solid var(--line)' : 'none' }}>
              <div>
                <div style={{ fontSize: 10.5, fontWeight: 600, color: 'var(--ink)' }}>{it.n}</div>
                <div className="mono" style={{ fontSize: 10.5, fontWeight: 700, color: '#EC4899', marginTop: 2 }}>{it.p}</div>
              </div>
              <div style={{ width: 44, height: 44, borderRadius: 8, background: '#FFF1F5', display: 'grid', placeItems: 'center', flexShrink: 0, marginLeft: 8 }}>
                <Cake top={it.top} base={it.base} sprinkleColors={it.spr} label={it.n}/>
              </div>
            </div>
          ))}
        </div>
        <div style={{ background: '#fff', border: '1px solid var(--line)', borderRadius: 8, padding: 10, fontSize: 10, display: 'flex', flexDirection: 'column' }}>
          <div style={{ fontWeight: 700, marginBottom: 8 }}>Sua sacola</div>
          <div style={{ flex: 1, display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: 4, color: 'var(--muted)', textAlign: 'center', padding: '12px 4px' }}>
            <div style={{ fontSize: 22, opacity: .35 }}>🛍️</div>
            <div style={{ fontSize: 10, fontWeight: 600, color: 'var(--ink-2)' }}>Sua sacola está vazia</div>
            <div style={{ fontSize: 9 }}>Adicione produtos para fazer seu pedido</div>
          </div>
          <div style={{ background: '#FEF3C7', border: '1px solid #FDE68A', borderRadius: 6, padding: 6, fontSize: 9, color: '#92400E', display: 'flex', alignItems: 'center', gap: 6 }}>
            <span>🏆</span>
            <div>
              <div style={{ fontWeight: 700 }}>Programa de fidelidade</div>
              <div>A cada R$ 1,00 você ganha 1 ponto</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
};

// ── Header ───────────────────────────────────────────────────
const Header = ({ dark, setDark }) => {
  const [s, setS] = useState(false);
  useEffect(() => {
    const h = () => setS(window.scrollY > 10);
    h(); window.addEventListener('scroll', h, { passive: true });
    return () => window.removeEventListener('scroll', h);
  }, []);
  return (
    <header style={{ position: 'sticky', top: 0, zIndex: 100, background: s ? 'color-mix(in oklab, var(--bg) 80%, transparent)' : 'transparent', backdropFilter: s ? 'blur(12px) saturate(150%)' : 'none', borderBottom: s ? '1px solid var(--line)' : '1px solid transparent', transition: 'all .25s' }}>
      <div className="container" style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', height: 68 }}>
        <a href="#"><Logo size={30} /></a>
        <nav className="hide-sm" style={{ display: 'flex', gap: 28, fontSize: 14, fontWeight: 500, color: 'var(--ink-2)' }}>
          {['Produto', 'KDS', 'Planos', 'Clientes'].map(n => <a key={n} href={`#${n.toLowerCase()}`} style={{ opacity: .85 }}>{n}</a>)}
        </nav>
        <div style={{ display: 'flex', gap: 8, alignItems: 'center' }}>
          <button onClick={() => setDark(!dark)} className="btn btn-ghost" style={{ width: 40, padding: 0, justifyContent: 'center' }}>{dark ? <IconSun s={16}/> : <IconMoon s={16}/>}</button>
          <a href="https://wa.me/5511913077669" target="_blank" rel="noopener" className="btn btn-whats"><IconWhatsLogo s={16}/> Entrar em contato</a>
        </div>
      </div>
    </header>
  );
};

// ── Hero ─────────────────────────────────────────────────────
const Hero = () => (
  <section style={{ paddingTop: 56, paddingBottom: 40, position: 'relative', overflow: 'hidden' }}>
    <div aria-hidden style={{ position: 'absolute', top: -150, right: -100, width: 500, height: 500, background: 'radial-gradient(closest-side, rgba(30,102,245,.1), transparent 70%)' }} />
    <div aria-hidden style={{ position: 'absolute', top: 100, left: -100, width: 400, height: 400, background: 'radial-gradient(closest-side, rgba(245,158,11,.08), transparent 70%)' }} />
    <div className="container grid-md-1" style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 48, alignItems: 'center', position: 'relative' }}>
      <div>
        <Reveal><span className="eyebrow"><span className="dot"/> Pedidos, cozinha e entregas num só lugar</span></Reveal>
        <Reveal delay={80}>
          <h1 className="title" style={{ margin: '22px 0 18px', display: 'flex', alignItems: 'center', gap: 18, flexWrap: 'wrap' }}>
            <span>Tudo pronto<br/>pra <span style={{ color: 'var(--orange)' }}>abrir</span>.</span>
            <img src="assets/mascot-skater.png" alt="" className="hero-mascot" style={{ width: 'clamp(110px, 14vw, 170px)', height: 'auto', objectFit: 'contain', filter: 'drop-shadow(0 12px 24px rgba(15,17,21,.18))', flexShrink: 0 }}/>
          </h1>
        </Reveal>
        <Reveal delay={140}>
          <p className="lede" style={{ fontSize: 19 }}>
            O sistema que seu restaurante precisa — cardápio online, KDS na cozinha, caixa, entregas e relatórios. Tudo num só login, sem taxa por pedido.
          </p>
        </Reveal>
        <Reveal delay={200}>
          <div style={{ marginTop: 28, display: 'flex', gap: 12, flexWrap: 'wrap' }}>
            <a href="https://wa.me/5511913077669" target="_blank" rel="noopener" className="btn btn-whats btn-lg"><IconWhatsLogo s={18}/> Entrar em contato <IconArrow s={16}/></a>
          </div>
        </Reveal>
        <Reveal delay={280}>
          <div style={{ marginTop: 32, paddingTop: 22, borderTop: '1px solid var(--line)', display: 'flex', gap: 32, flexWrap: 'wrap' }}>
            <div><div style={{ fontSize: 26, fontWeight: 800, letterSpacing: '-.02em' }}>+<CountUp to={500}/></div><div style={{ fontSize: 11, color: 'var(--muted)', fontWeight: 500 }}>lojas ativas</div></div>
            <div><div style={{ fontSize: 26, fontWeight: 800, letterSpacing: '-.02em' }}><CountUp to={12} dec={1} suf="k"/></div><div style={{ fontSize: 11, color: 'var(--muted)', fontWeight: 500 }}>pedidos/mês</div></div>
            <div><div style={{ fontSize: 26, fontWeight: 800, letterSpacing: '-.02em' }}><CountUp to={99.9} dec={1} suf="%"/></div><div style={{ fontSize: 11, color: 'var(--muted)', fontWeight: 500 }}>uptime</div></div>
          </div>
        </Reveal>
      </div>

      {/* Split visual — matches login page aesthetic */}
      <Reveal delay={120}>
        <div className="demo-card" style={{ background: '#0F1115', borderRadius: 20, padding: 24, color: '#fff', position: 'relative', overflow: 'hidden', boxShadow: 'var(--shadow-lg)' }}>
          <div style={{ textAlign: 'center', marginBottom: 18, position: 'relative', zIndex: 1 }}>
            <h3 style={{ fontSize: 22, fontWeight: 700, letterSpacing: '-.02em' }}>Tudo pronto pra abrir</h3>
            <p style={{ fontSize: 12, color: '#9CA3AF', marginTop: 4 }}>Pedidos, cozinha e entregas num só lugar</p>
          </div>
          <div className="kds-wrap" style={{ background: '#13161C', borderRadius: 12, padding: 10, minWidth: 0, overflow: 'hidden' }}>
            <KDSBoard compact />
          </div>
          <div className="floaty" style={{ marginTop: 12, background: '#0A0C10', border: '1px solid #1E2128', borderRadius: 10, padding: 12 }}>
            <div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 6 }}>
              <span style={{ fontSize: 12, fontWeight: 700, color: '#F59E0B' }}>#1042</span>
              <span style={{ fontSize: 10, color: '#9CA3AF' }}>⏱ 4min</span>
            </div>
            <div style={{ background: 'rgba(59,130,246,.15)', color: '#60A5FA', padding: '3px 8px', borderRadius: 4, fontSize: 10, textAlign: 'center', marginBottom: 6 }}>Preparar em até 15:00</div>
            <div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 11 }}>
              <span>1× Josefa Clara</span>
            </div>
            <div style={{ display: 'flex', justifyContent: 'space-between', marginTop: 4 }}>
              <span style={{ fontSize: 10, color: '#9CA3AF' }}>Pix</span>
              <span className="mono" style={{ fontSize: 13, fontWeight: 700 }}>R$ 48,90</span>
            </div>
          </div>
          <div style={{ marginTop: 16, textAlign: 'center', fontSize: 9, color: '#4B5563', letterSpacing: '.15em' }}>PDV MODERNO · OPERACIONAL</div>
        </div>
      </Reveal>
    </div>
  </section>
);

// ── Features / Modules bento ─────────────────────────────────
const Modules = () => {
  const mods = [
    { i: IconBag, t: 'Meus Pedidos', d: 'Kanban visual com tempo de preparo, cliente, pagamento e status. Tudo em uma tela.', c: 'var(--orange)' },
    { i: IconChef, t: 'Cozinha (KDS)', d: 'Quatro colunas coloridas: em preparo, prontos, saiu pra entrega, concluído. Sem papel, sem grito.', c: '#10B981' },
    { i: IconStore, t: 'Catálogo online', d: 'Link próprio do tipo cardapiocode.app/sua-loja. Cliente pede do celular sem baixar app.', c: 'var(--blue)' },
    { i: IconCash, t: 'Caixa & PDV', d: 'Abertura, sangria, fechamento. Comanda, balcão, delivery e retirada num só PDV.', c: '#6B7280' },
    { i: IconChart, t: 'Desempenho', d: 'Faturamento, ticket médio, status dos pedidos e produtos mais vendidos — em tempo real.', c: 'var(--blue)' },
    { i: IconBill, t: 'Contas a Receber', d: 'Fiado organizado por cliente, vencimento e método. Chega de caderninho.', c: 'var(--orange)' },
    { i: IconUsers, t: 'Clientes & Fidelidade', d: 'Cadastro automático, programa de pontos e histórico de compras por cliente.', c: '#EC4899' },
    { i: IconWhats, t: 'WhatsApp', d: 'Confirmação, status do pedido e mensagens automáticas direto no WhatsApp da loja.', c: '#25D366' },
  ];
  return (
    <section id="produto">
      <div className="container">
        <Reveal>
          <span className="eyebrow"><span className="dot"/> Módulos</span>
          <h2 className="title" style={{ margin: '16px 0 14px' }}>Um sistema completo,<br/>do cardápio ao fechamento.</h2>
          <p className="lede">13 módulos integrados. Ativa só o que precisa, paga uma mensalidade só.</p>
        </Reveal>
        <div className="grid-md-2 grid-sm-1" style={{ marginTop: 40, display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 14 }}>
          {mods.map((m, i) => {
            const Ic = m.i;
            return (
              <Reveal key={m.t} delay={i * 40}>
                <div className="card" style={{ padding: 22, height: '100%', display: 'flex', flexDirection: 'column', gap: 12, transition: 'transform .2s', cursor: 'default' }}
                  onMouseEnter={e => e.currentTarget.style.transform = 'translateY(-4px)'}
                  onMouseLeave={e => e.currentTarget.style.transform = 'none'}>
                  <span style={{ width: 40, height: 40, borderRadius: 10, background: m.c, color: '#fff', display: 'grid', placeItems: 'center' }}><Ic s={18} /></span>
                  <div>
                    <div style={{ fontSize: 16, fontWeight: 700, letterSpacing: '-.01em', marginBottom: 4 }}>{m.t}</div>
                    <div style={{ fontSize: 13, color: 'var(--muted)', lineHeight: 1.5 }}>{m.d}</div>
                  </div>
                </div>
              </Reveal>
            );
          })}
        </div>
      </div>
    </section>
  );
};

// ── KDS spotlight section ────────────────────────────────────
const KDSSection = () => (
  <section id="kds" style={{ background: 'var(--card)', borderTop: '1px solid var(--line)', borderBottom: '1px solid var(--line)' }}>
    <div className="container">
      <Reveal>
        <span className="eyebrow"><span className="dot"/> KDS em tempo real</span>
        <h2 className="title" style={{ margin: '16px 0 14px' }}>Cozinha que não perde pedido.</h2>
        <p className="lede">Quatro colunas, cores que sua brigada entende sem treinamento. Pedido entra, vira card com timer, muda de coluna ao toque.</p>
      </Reveal>
      <Reveal delay={120}>
        <div className="demo-card" style={{ marginTop: 40, background: 'var(--bg)', border: '1px solid var(--line)', borderRadius: 16, padding: 20 }}>
          <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }}>
            <div>
              <div style={{ fontSize: 16, fontWeight: 700 }}>Últimos pedidos</div>
              <div style={{ fontSize: 11, color: 'var(--muted)' }}>Modo teste · Loja Admin — teste</div>
            </div>
            <div style={{ display: 'flex', gap: 8 }}>
              <span style={{ fontSize: 11, color: 'var(--muted)', display: 'flex', alignItems: 'center', gap: 4 }}>⏱ 25 min</span>
              <span style={{ fontSize: 11, color: 'var(--muted)', display: 'flex', alignItems: 'center', gap: 4 }}>🍳 25-115 min</span>
              <button style={{ padding: '6px 14px', borderRadius: 6, background: 'var(--orange)', color: '#fff', fontSize: 12, fontWeight: 700, display: 'inline-flex', alignItems: 'center', gap: 4 }}><IconPlus s={12}/> NOVO PEDIDO</button>
            </div>
          </div>
          <KDSBoard />
        </div>
      </Reveal>
    </div>
  </section>
);

// ── Relatório section ────────────────────────────────────────
const RelatorySection = () => (
  <section>
    <div className="container grid-md-1" style={{ display: 'grid', gridTemplateColumns: '1fr 1.3fr', gap: 60, alignItems: 'center' }}>
      <Reveal>
        <div>
          <span className="eyebrow"><span className="dot"/> Desempenho</span>
          <h2 className="title" style={{ margin: '16px 0 14px' }}>Seu negócio<br/>em números claros.</h2>
          <p className="lede">Hoje, 7 dias, 30 dias ou personalizado. Faturamento, ticket médio, pedidos por status e produtos campeões — sem planilha.</p>
          <ul style={{ marginTop: 22, padding: 0, listStyle: 'none', display: 'flex', flexDirection: 'column', gap: 10 }}>
            {['Faturamento por período e tipo (entrega/retirada)', 'Status dos pedidos em 6 colunas coloridas', 'Ranking de produtos e formas de pagamento', 'Alertas de estoque em falta ou vencendo'].map(x => (
              <li key={x} style={{ display: 'flex', gap: 10, fontSize: 14.5 }}>
                <span style={{ color: 'var(--blue)', marginTop: 2 }}><IconCheck s={16}/></span> {x}
              </li>
            ))}
          </ul>
        </div>
      </Reveal>
      <Reveal delay={120}>
        <div className="card" style={{ padding: 0, overflow: 'hidden', borderRadius: 16, background: '#fff' }}>
          <img src="assets/dash-real.png" alt="Relatório do Cardápio Code" style={{ display: 'block', width: '100%', height: 'auto' }}/>
        </div>
      </Reveal>
    </div>
  </section>
);

// ── Storefront showcase ──────────────────────────────────────
const StorefrontSection = () => (
  <section style={{ background: '#FFF7ED', borderTop: '1px solid #FED7AA', borderBottom: '1px solid #FED7AA' }}>
    <div className="container grid-md-1" style={{ display: 'grid', gridTemplateColumns: '1.2fr 1fr', gap: 60, alignItems: 'center' }}>
      <Reveal>
        <div className="card" style={{ padding: 0, overflow: 'hidden' }}>
          <StorefrontMock />
        </div>
      </Reveal>
      <Reveal delay={120}>
        <div>
          <span className="eyebrow" style={{ background: '#FEF3C7', color: '#B45309' }}><span className="dot" style={{ background: '#F59E0B' }}/> Catálogo online</span>
          <h2 className="title" style={{ margin: '16px 0 14px' }}>Seu link,<br/>sua marca.</h2>
          <p className="lede">Cada loja ganha um endereço próprio — <b>cardapiocode.app/sua-loja</b>. Cliente pede direto, sem baixar app, sem pagar comissão pra marketplace.</p>
          <div style={{ marginTop: 22, display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 10 }}>
            {[
              { l: 'Zero comissão', v: 'Mensalidade fixa' },
              { l: 'Programa de pontos', v: 'Fidelidade nativa' },
              { l: 'Cupons', v: 'Desconto fixo ou %' },
              { l: 'Cálculo de entrega', v: 'Taxa e tempo por CEP' },
            ].map(x => (
              <div key={x.l} style={{ background: '#fff', border: '1px solid #FED7AA', borderRadius: 10, padding: 12 }}>
                <div style={{ fontSize: 12.5, fontWeight: 700 }}>{x.l}</div>
                <div style={{ fontSize: 11.5, color: 'var(--muted)' }}>{x.v}</div>
              </div>
            ))}
          </div>
        </div>
      </Reveal>
    </div>
  </section>
);

// ── Plans ────────────────────────────────────────────────────
const Plans = () => {
  // 12 features that the admin's plan-config screen shows, in order.
  const FEATURES = [
    'Delivery',
    'Retirada',
    'Mesas e Comandas',
    'Garçom',
    'Motoboys',
    'Cozinha (KDS)',
    'Cardápio Digital',
    'CRM de Clientes',
    'Programa de Fidelidade',
    'Cupons de Desconto',
    'Relatórios',
    'Auditoria',
  ];
  // ON-feature indexes per plan, mirroring the admin screenshot.
  const plans = [
    {
      n: 'Mesa', d: 'Plano focado em atendimento local — mesas, comandas e garçom.',
      tag: 'MESA', tagC: '#10B981', icon: '🪑',
      on: [2, 3, 5, 6, 7, 10], // Mesas, Garçom, Cozinha (KDS), Cardápio, CRM, Relatórios
    },
    {
      n: 'Delivery', d: 'Plano focado em pedidos online — cardápio digital, delivery e motoboy.',
      tag: 'DELIVERY', tagC: '#1E66F5', icon: '🛵',
      on: [0, 1, 4, 5, 6, 9, 10], // Delivery, Retirada, Motoboys, Cozinha (KDS), Cardápio, Cupons, Relatórios
    },
    {
      n: 'Plus', d: 'Plano completo — todas as funcionalidades liberadas.',
      tag: 'PLUS', tagC: '#F59E0B', icon: '👑', featured: true,
      on: [0,1,2,3,4,5,6,7,8,9,10,11], // todas
    },
  ];
  return (
    <section id="planos">
      <div className="container">
        <Reveal>
          <span className="eyebrow"><span className="dot"/> Planos</span>
          <h2 className="title" style={{ margin: '16px 0 14px' }}>Três planos.<br/>Escolha o tamanho da sua operação.</h2>
          <p className="lede">Cada plano agrupa as features liberadas para a loja. Mude quando quiser, sem multa.</p>
        </Reveal>
        <div className="grid-md-1" style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 16, marginTop: 40 }}>
          {plans.map((p, i) => {
            const enabled = p.on.length;
            const total = FEATURES.length;
            const isFeat = !!p.featured;
            return (
              <Reveal key={p.n} delay={i * 80}>
                <div style={{ background: isFeat ? 'var(--ink)' : 'var(--card)', color: isFeat ? '#fff' : 'var(--ink)', borderRadius: 18, padding: 28, border: '1px solid ' + (isFeat ? 'var(--ink)' : 'var(--line)'), height: '100%', display: 'flex', flexDirection: 'column', position: 'relative', boxShadow: isFeat ? '0 30px 60px -20px rgba(0,0,0,.3)' : 'var(--shadow)' }}>
                  <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', gap: 8 }}>
                    <div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
                      <div style={{ width: 36, height: 36, borderRadius: 10, background: isFeat ? 'rgba(255,255,255,.08)' : 'var(--bg)', border: '1px solid ' + (isFeat ? 'rgba(255,255,255,.12)' : 'var(--line)'), display: 'grid', placeItems: 'center', fontSize: 18 }}>{p.icon}</div>
                      <span style={{ background: p.tagC, color: '#fff', padding: '3px 10px', borderRadius: 4, fontSize: 10, fontWeight: 700, letterSpacing: '.05em' }}>{p.tag}</span>
                    </div>
                    <span className="mono" style={{ fontSize: 11, fontWeight: 600, color: isFeat ? 'rgba(255,255,255,.6)' : 'var(--muted)' }}>{enabled}/{total}</span>
                  </div>
                  <div style={{ fontSize: 22, fontWeight: 700, marginTop: 18, letterSpacing: '-.01em' }}>{p.n}</div>
                  <div style={{ fontSize: 13, opacity: .75, marginTop: 4, lineHeight: 1.45 }}>{p.d}</div>
                  <div style={{ fontSize: 10.5, fontWeight: 700, letterSpacing: '.12em', color: isFeat ? 'rgba(255,255,255,.5)' : 'var(--muted)', marginTop: 22, marginBottom: 10 }}>FEATURES</div>
                  <ul style={{ margin: 0, padding: 0, listStyle: 'none', display: 'flex', flexDirection: 'column', gap: 8, flex: 1 }}>
                    {FEATURES.map((f, idx) => {
                      const active = p.on.includes(idx);
                      const onColor = isFeat ? 'var(--orange)' : 'var(--blue)';
                      const offColor = isFeat ? 'rgba(255,255,255,.25)' : 'rgba(15,17,21,.22)';
                      return (
                        <li key={f} style={{ display: 'flex', gap: 8, alignItems: 'center', fontSize: 13, color: active ? (isFeat ? '#fff' : 'var(--ink)') : (isFeat ? 'rgba(255,255,255,.4)' : 'rgba(15,17,21,.4)') }}>
                          <span style={{ color: active ? onColor : offColor, display: 'inline-flex', flexShrink: 0 }}>
                            {active ? <IconCheck s={14}/> : <IconX s={12}/>}
                          </span>
                          <span style={{ textDecoration: active ? 'none' : 'line-through', textDecorationColor: offColor }}>{f}</span>
                        </li>
                      );
                    })}
                  </ul>
                  <a href="https://wa.me/5511913077669" target="_blank" rel="noopener" className="btn btn-whats" style={{ width: '100%', justifyContent: 'center', marginTop: 22 }}>
                    <IconWhatsLogo s={16}/> Entrar em contato
                  </a>
                </div>
              </Reveal>
            );
          })}
        </div>
      </div>
    </section>
  );
};

// ── Testimonials ─────────────────────────────────────────────
const Testimonials = () => (
  <section id="clientes" style={{ background: 'var(--card)', borderTop: '1px solid var(--line)', borderBottom: '1px solid var(--line)' }}>
    <div className="container">
      <Reveal>
        <span className="eyebrow"><span className="dot"/> Quem já usa</span>
        <h2 className="title" style={{ margin: '16px 0 14px' }}>Lojas de verdade,<br/>operando agora.</h2>
      </Reveal>
      <div className="grid-md-1" style={{ marginTop: 36, display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 14 }}>
        {[
          { n: 'Bonjour Sucree', c: 'Guarujá - SP', plan: 'PLUS', pc: '#F59E0B', p: 118, r: 'R$ 2.212,00', q: 'Plantei o Plus no primeiro dia. O KDS acabou com ticket perdido.' },
          { n: 'Central do Açaí', c: 'Guarujá - SP', plan: 'PLUS', pc: '#F59E0B', p: 92, r: 'R$ 3.199,00', q: 'Saí do marketplace e hoje 70% dos pedidos vêm direto pelo meu link.' },
          { n: 'Batatou Bertioga', c: 'Bertioga - SP', plan: 'PLUS', pc: '#F59E0B', p: 3, r: 'R$ 30,00', q: 'Abri a segunda loja e o painel multi-loja ajudou a gerir as duas juntas.' },
        ].map((t, i) => (
          <Reveal key={t.n} delay={i * 80}>
            <div className="card" style={{ padding: 20 }}>
              <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 14 }}>
                <div style={{ display: 'flex', gap: 10, alignItems: 'center' }}>
                  <span style={{ width: 8, height: 8, borderRadius: 999, background: ['#EF4444','#8B5CF6','#10B981'][i] }}/>
                  <div>
                    <div style={{ fontWeight: 700, fontSize: 14 }}>{t.n}</div>
                    <div style={{ fontSize: 11, color: 'var(--muted)' }}>{t.c}</div>
                  </div>
                </div>
                <span style={{ background: t.pc, color: '#fff', fontSize: 9, fontWeight: 700, padding: '3px 8px', borderRadius: 4 }}>{t.plan}</span>
              </div>
              <p style={{ fontSize: 14, lineHeight: 1.5, color: 'var(--ink-2)', margin: 0 }}>"{t.q}"</p>
              <div style={{ marginTop: 14, paddingTop: 14, borderTop: '1px dashed var(--line)', display: 'flex', justifyContent: 'space-between' }}>
                <div><div style={{ fontSize: 10, color: 'var(--muted)' }}>PEDIDOS</div><div className="mono" style={{ fontWeight: 700 }}>{t.p}</div></div>
                <div style={{ textAlign: 'right' }}><div style={{ fontSize: 10, color: 'var(--muted)' }}>FATURAMENTO</div><div className="mono" style={{ fontWeight: 700 }}>{t.r}</div></div>
              </div>
            </div>
          </Reveal>
        ))}
      </div>
    </div>
  </section>
);

// ── Final CTA ────────────────────────────────────────────────
const FinalCTA = () => (
  <section style={{ padding: '60px 0 100px' }}>
    <div className="container">
      <Reveal>
        <div style={{ background: 'linear-gradient(135deg, #1E66F5 0%, #0F1115 100%)', borderRadius: 24, padding: 'clamp(40px, 6vw, 72px)', color: '#fff', position: 'relative', overflow: 'hidden' }}>
          <div aria-hidden style={{ position: 'absolute', right: -80, bottom: -80, width: 360, height: 360, background: 'radial-gradient(closest-side, rgba(245,158,11,.35), transparent 70%)' }} />
          <h2 className="title" style={{ maxWidth: 720 }}>Tudo pronto pra abrir<br/>— <span style={{ color: 'var(--orange)' }}>hoje mesmo</span>.</h2>
          <p style={{ marginTop: 14, fontSize: 17, opacity: .85, maxWidth: 560 }}>Criamos sua loja em 5 minutos, migramos seu cardápio e você já sai vendendo. 14 dias grátis, sem cartão.</p>
          <div style={{ marginTop: 28, display: 'flex', gap: 12, flexWrap: 'wrap' }}>
            <a href="https://wa.me/5511913077669" target="_blank" rel="noopener" className="btn btn-whats btn-lg"><IconWhatsLogo s={18}/> Entrar em contato <IconArrow s={16}/></a>
          </div>
        </div>
      </Reveal>
    </div>
  </section>
);

// ── Footer ───────────────────────────────────────────────────
const Footer = () => (
  <footer style={{ borderTop: '1px solid var(--line)', padding: '48px 0 32px' }}>
    <div className="container footer-wrap">
      <div className="footer-logo">
        <Logo size={28}/>
        <p style={{ fontSize: 13, color: 'var(--muted)', marginTop: 12, maxWidth: 280, lineHeight: 1.5 }}>O sistema operacional do seu restaurante. Feito no Brasil.</p>
      </div>
      <div className="footer-cols">
        {[
          { t: 'Produto', l: ['Catálogo', 'KDS', 'Caixa', 'Desempenho'] },
          { t: 'Empresa', l: ['Sobre', 'Blog', 'Parceiros'] },
          { t: 'Ajuda', l: ['Suporte', 'Docs', 'Status', 'cardapiocode.app'] },
        ].map(c => (
          <div key={c.t}>
            <div style={{ fontSize: 10, fontWeight: 700, color: 'var(--muted)', letterSpacing: '.1em', textTransform: 'uppercase', marginBottom: 12 }}>{c.t}</div>
            {c.l.map(x => <a key={x} href="#" style={{ display: 'block', fontSize: 13, padding: '4px 0', color: 'var(--ink-2)' }}>{x}</a>)}
          </div>
        ))}
      </div>
    </div>
    <div className="container" style={{ marginTop: 36, paddingTop: 20, borderTop: '1px solid var(--line)', display: 'flex', justifyContent: 'space-between', flexWrap: 'wrap', gap: 12 }}>
      <div style={{ fontSize: 12, color: 'var(--muted)' }}>© 2026 Cardápio Code · cardapiocode.app</div>
      <div style={{ fontSize: 12, color: 'var(--muted)' }}>Made in 🇧🇷 · LGPD compliant</div>
    </div>
  </footer>
);

// ── Tweaks ───────────────────────────────────────────────────
const Tweaks = ({ dark, setDark, open, setOpen }) => {
  useEffect(() => {
    const fn = (e) => {
      if (e.data?.type === '__activate_edit_mode') setOpen(true);
      if (e.data?.type === '__deactivate_edit_mode') setOpen(false);
    };
    window.addEventListener('message', fn);
    window.parent.postMessage({ type: '__edit_mode_available' }, '*');
    return () => window.removeEventListener('message', fn);
  }, []);
  if (!open) return null;
  return (
    <div className="tweak open">
      <div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 10 }}>
        <h4 style={{ margin: 0, fontWeight: 700 }}>Tweaks</h4>
        <button onClick={() => { setOpen(false); window.parent.postMessage({ type: '__edit_mode_dismissed' }, '*'); }}><IconX s={14}/></button>
      </div>
      <label style={{ display: 'flex', justifyContent: 'space-between', padding: '8px 0' }}>
        <span style={{ color: 'var(--muted)' }}>Tema</span>
        <div style={{ display: 'flex', gap: 4 }}>
          <button onClick={() => setDark(false)} style={{ padding: '4px 10px', borderRadius: 6, background: !dark ? 'var(--blue)' : 'var(--bg)', color: !dark ? '#fff' : 'var(--ink)', fontSize: 11 }}>Claro</button>
          <button onClick={() => setDark(true)} style={{ padding: '4px 10px', borderRadius: 6, background: dark ? 'var(--blue)' : 'var(--bg)', color: dark ? '#fff' : 'var(--ink)', fontSize: 11 }}>Escuro</button>
        </div>
      </label>
    </div>
  );
};

// ── Promo video section ──────────────────────────────────────
const PromoVideo = () => (
  <section id="video" style={{ background: 'var(--card)', borderTop: '1px solid var(--line)', borderBottom: '1px solid var(--line)' }}>
    <div className="container" style={{ textAlign: 'center' }}>
      <Reveal>
        <h2 className="title" style={{ margin: '16px 0 14px' }}>Veja em 60 segundos.</h2>
        <p className="lede" style={{ maxWidth: 560, margin: '0 auto' }}>Cardapio Code rodando do pedido ao caixa — cardápio online, KDS, motoboy e relatório numa volta só.</p>
      </Reveal>
      <Reveal delay={120}>
        <div className="video-wrap" style={{ marginTop: 40, position: 'relative', borderRadius: 20, overflow: 'hidden', background: '#0A0C10', aspectRatio: '16 / 9', boxShadow: 'var(--shadow-lg)', border: '1px solid var(--line)' }}>
          <iframe
            src="video.html"
            title="Cardapio Code — Vídeo Promo"
            allow="autoplay; fullscreen"
            loading="lazy"
            allowFullScreen
            style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', border: 0, display: 'block' }}
          />
          <button
            type="button"
            aria-label="Tela cheia"
            onClick={(e) => {
              const wrap = e.currentTarget.parentElement;
              if (document.fullscreenElement) {
                document.exitFullscreen();
              } else if (wrap.requestFullscreen) {
                wrap.requestFullscreen();
              } else if (wrap.webkitRequestFullscreen) {
                wrap.webkitRequestFullscreen();
              } else {
                // iOS Safari fallback: open the video in its own tab
                window.open('video.html', '_blank');
              }
            }}
            style={{
              position: 'absolute', bottom: 12, right: 12, zIndex: 2,
              background: 'rgba(0,0,0,.65)', color: '#fff',
              border: '1px solid rgba(255,255,255,.2)', borderRadius: 8,
              padding: '8px 12px', fontSize: 13, fontWeight: 600,
              display: 'inline-flex', alignItems: 'center', gap: 6,
              cursor: 'pointer', backdropFilter: 'blur(6px)'
            }}
          >
            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round">
              <path d="M8 3H5a2 2 0 0 0-2 2v3M21 8V5a2 2 0 0 0-2-2h-3M3 16v3a2 2 0 0 0 2 2h3M16 21h3a2 2 0 0 0 2-2v-3"/>
            </svg>
            Tela cheia
          </button>
        </div>
      </Reveal>
    </div>
  </section>
);

// ── App ──────────────────────────────────────────────────────
const App = () => {
  const [dark, setDark] = useState(false);
  const [tweakOpen, setTweakOpen] = useState(false);
  useEffect(() => { document.documentElement.classList.toggle('dark', dark); }, [dark]);
  useEffect(() => {
    const obs = new IntersectionObserver((entries) => {
      entries.forEach(e => { if (e.isIntersecting) e.target.classList.add('in'); });
    }, { threshold: .1 });
    document.querySelectorAll('.reveal').forEach(el => obs.observe(el));
    return () => obs.disconnect();
  }, []);
  return (
    <>
      <Header dark={dark} setDark={setDark} />
      <Hero />
      <PromoVideo />
      <Modules />
      <KDSSection />
      <RelatorySection />
      <StorefrontSection />
      <Plans />
      <Testimonials />
      <FinalCTA />
      <Footer />
      <Tweaks dark={dark} setDark={setDark} open={tweakOpen} setOpen={setTweakOpen} />
    </>
  );
};

ReactDOM.createRoot(document.getElementById('root')).render(<App />);
