// components.jsx — Componentes compartilhados (Header, Footer, ProductCard, ícones, etc)

// ─── Logo ────────────────────────────────────────────────────────
function Logo({ size = 40, dark = false }) {
  const fg = dark ? '#f7f3ea' : '#0d4a30';
  const accent = '#e8b86a';
  return (
    <div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
      <svg width={size} height={size} viewBox="0 0 40 40" aria-hidden>
        <circle cx="20" cy="20" r="18" fill={fg} />
        <path d="M20 6 L24 14 L33 14 L26 19 L29 28 L20 23 L11 28 L14 19 L7 14 L16 14 Z" fill={accent} />
        <circle cx="20" cy="20" r="3" fill={fg} />
      </svg>
      <div style={{ lineHeight: 1 }}>
        <div
          style={{
            fontFamily: 'Anton, sans-serif',
            fontSize: 22,
            letterSpacing: '0.02em',
            color: fg,
            textTransform: 'uppercase',
          }}
        >
          Central da Copa
        </div>
        <div
          style={{
            fontFamily: 'JetBrains Mono, monospace',
            fontSize: 9,
            letterSpacing: '0.4em',
            color: accent,
            marginTop: 2,
          }}
        >
          / EDIÇÃO 2026 /
        </div>
      </div>
    </div>
  );
}

// ─── Ícones genéricos ────────────────────────────────────────────
function Icon({ name, size = 18, color = 'currentColor', strokeWidth = 1.8 }) {
  const props = { width: size, height: size, viewBox: '0 0 24 24', fill: 'none', stroke: color, strokeWidth, strokeLinecap: 'round', strokeLinejoin: 'round' };
  switch (name) {
    case 'search':
      return (<svg {...props}><circle cx="11" cy="11" r="7" /><path d="m21 21-4.3-4.3" /></svg>);
    case 'cart':
      return (<svg {...props}><path d="M3 4h2l2.4 11.5a2 2 0 0 0 2 1.5h7.4a2 2 0 0 0 2-1.5L21 7H6" /><circle cx="9" cy="21" r="1.5" /><circle cx="18" cy="21" r="1.5" /></svg>);
    case 'user':
      return (<svg {...props}><circle cx="12" cy="8" r="4" /><path d="M4 21c0-4.4 3.6-8 8-8s8 3.6 8 8" /></svg>);
    case 'heart':
      return (<svg {...props}><path d="M12 21s-7-4.5-9.5-9C.8 8.5 3 4 7 4c2 0 3.5 1 5 3 1.5-2 3-3 5-3 4 0 6.2 4.5 4.5 8-2.5 4.5-9.5 9-9.5 9Z" /></svg>);
    case 'menu':
      return (<svg {...props}><path d="M3 6h18M3 12h18M3 18h18" /></svg>);
    case 'check':
      return (<svg {...props}><path d="m4 12 5 5L20 6" /></svg>);
    case 'whatsapp':
      return (<svg width={size} height={size} viewBox="0 0 24 24" fill={color}><path d="M.057 24l1.687-6.163A11.867 11.867 0 0 1 .26 11.876C.262 5.343 5.59.014 12.123.014a11.82 11.82 0 0 1 8.413 3.488 11.82 11.82 0 0 1 3.48 8.42c-.003 6.532-5.332 11.86-11.864 11.86a11.86 11.86 0 0 1-5.674-1.444L.057 24zm6.597-3.807c1.676.995 3.276 1.591 5.392 1.592 5.448 0 9.886-4.434 9.889-9.885.002-5.462-4.415-9.89-9.881-9.892-5.452 0-9.887 4.434-9.889 9.884a9.86 9.86 0 0 0 1.51 5.26l-.999 3.648 3.978-1.607zm11.387-5.464c-.074-.124-.272-.198-.57-.347-.297-.149-1.758-.868-2.031-.967-.272-.099-.47-.149-.669.149-.198.297-.768.967-.941 1.165-.173.198-.347.223-.644.074-.297-.149-1.255-.462-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.297-.347.446-.521.151-.172.2-.296.3-.494.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51l-.57-.01c-.198 0-.52.074-.792.372s-1.04 1.016-1.04 2.479 1.065 2.876 1.213 3.074c.149.198 2.095 3.2 5.076 4.487.71.306 1.263.489 1.694.626.712.226 1.36.194 1.872.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413z" /></svg>);
    case 'chevron-down':
      return (<svg {...props}><path d="m6 9 6 6 6-6" /></svg>);
    case 'chevron-right':
      return (<svg {...props}><path d="m9 6 6 6-6 6" /></svg>);
    case 'chevron-left':
      return (<svg {...props}><path d="m15 6-6 6 6 6" /></svg>);
    case 'plus':
      return (<svg {...props}><path d="M12 5v14M5 12h14" /></svg>);
    case 'minus':
      return (<svg {...props}><path d="M5 12h14" /></svg>);
    case 'close':
      return (<svg {...props}><path d="M6 6l12 12M18 6 6 18" /></svg>);
    case 'truck':
      return (<svg {...props}><path d="M3 7h11v9H3zM14 11h4l3 3v2h-7" /><circle cx="7" cy="18" r="2" /><circle cx="17" cy="18" r="2" /></svg>);
    case 'shield':
      return (<svg {...props}><path d="M12 3 4 6v6c0 5 3.5 8.5 8 9 4.5-.5 8-4 8-9V6l-8-3z" /><path d="m9 12 2 2 4-4" /></svg>);
    case 'lock':
      return (<svg {...props}><rect x="4" y="11" width="16" height="10" rx="2" /><path d="M8 11V7a4 4 0 0 1 8 0v4" /></svg>);
    case 'star':
      return (<svg width={size} height={size} viewBox="0 0 24 24" fill={color}><path d="M12 17.3 5.8 21l1.6-7L2 9.2l7.1-.6L12 2l2.9 6.6 7.1.6-5.4 4.8L18.2 21z" /></svg>);
    case 'filter':
      return (<svg {...props}><path d="M3 5h18M6 12h12M10 19h4" /></svg>);
    case 'grid':
      return (<svg {...props}><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" /><rect x="14" y="14" width="7" height="7" /></svg>);
    case 'list':
      return (<svg {...props}><path d="M8 6h13M8 12h13M8 18h13" /><circle cx="3.5" cy="6" r="1" /><circle cx="3.5" cy="12" r="1" /><circle cx="3.5" cy="18" r="1" /></svg>);
    case 'pix':
      return (<svg {...props}><path d="m4 12 4-4 4 4-4 4z" /><path d="m12 4 4 4 4-4M12 20l4-4 4 4" /></svg>);
    case 'card':
      return (<svg {...props}><rect x="3" y="6" width="18" height="13" rx="2" /><path d="M3 11h18" /></svg>);
    case 'barcode':
      return (<svg {...props}><path d="M4 6v12M7 6v12M10 6v12M14 6v12M17 6v12M20 6v12" /></svg>);
    case 'arrow-right':
      return (<svg {...props}><path d="M5 12h14M13 5l7 7-7 7" /></svg>);
    case 'package':
      return (<svg {...props}><path d="M3 7 12 3l9 4v10l-9 4-9-4z" /><path d="m3 7 9 4 9-4M12 11v10" /></svg>);
    case 'tag':
      return (<svg {...props}><path d="M20 12 12 20l-8-8V4h8z" /><circle cx="8" cy="8" r="1" /></svg>);
    default:
      return null;
  }
}

// ─── Imagem placeholder estilizada do produto ────────────────────
function ProductImage({ product, ratio = 1, decor = true }) {
  const [c1, c2, c3] = product.palette;
  const id = 'prod-' + product.id;
  const w = 600;
  const h = 600 / ratio;
  const ico = product.icon;
  return (
    <svg
      viewBox={`0 0 ${w} ${h}`}
      preserveAspectRatio="xMidYMid slice"
      style={{ display: 'block', width: '100%', height: '100%' }}
      role="img"
      aria-label={product.name}
    >
      <defs>
        <linearGradient id={id + '-bg'} x1="0" x2="1" y1="0" y2="1">
          <stop offset="0" stopColor={c1} />
          <stop offset="1" stopColor={c2} />
        </linearGradient>
        <pattern id={id + '-stripes'} width="40" height="40" patternUnits="userSpaceOnUse" patternTransform="rotate(35)">
          <rect width="40" height="40" fill="transparent" />
          <rect width="20" height="40" fill="rgba(255,255,255,0.04)" />
        </pattern>
      </defs>
      <rect width={w} height={h} fill={`url(#${id}-bg)`} />
      {decor && <rect width={w} height={h} fill={`url(#${id}-stripes)`} />}
      {decor && (
        <g opacity="0.35">
          <circle cx={w * 0.85} cy={h * 0.18} r="80" fill="none" stroke={c3} strokeWidth="1.5" />
          <circle cx={w * 0.85} cy={h * 0.18} r="40" fill="none" stroke={c3} strokeWidth="1" />
          <line x1={w * 0.85 - 80} y1={h * 0.18} x2={w * 0.85 + 80} y2={h * 0.18} stroke={c3} strokeWidth="0.8" />
        </g>
      )}
      <ProductIcon name={ico} cx={w / 2} cy={h / 2} c1={c1} c2={c2} c3={c3} />
      {decor && (
        <g
          fontFamily="JetBrains Mono, monospace"
          fontSize="11"
          letterSpacing="0.3em"
          fill={c3}
          opacity="0.7"
        >
          <text x="24" y={h - 20}>CC26 / {product.id.toUpperCase()}</text>
          <text x={w - 24} y="32" textAnchor="end">FIFA · BRASIL · 2026</text>
        </g>
      )}
    </svg>
  );
}

// SVG por tipo de produto — placeholder estilizado, não foto-realista
function ProductIcon({ name, cx, cy, c1, c2, c3 }) {
  const t = `translate(${cx} ${cy})`;
  switch (name) {
    case 'album':
    case 'album-hard':
      return (
        <g transform={t}>
          <rect x="-130" y="-160" width="260" height="320" fill={c3} rx="6" />
          <rect x="-130" y="-160" width="260" height="320" fill="none" stroke={c1} strokeWidth="3" rx="6" />
          {name === 'album-hard' && <rect x="-122" y="-152" width="244" height="304" fill="none" stroke={c2} strokeWidth="1.5" rx="3" />}
          <text x="0" y="-90" textAnchor="middle" fontFamily="Anton, sans-serif" fontSize="34" fill={c1} letterSpacing="2">COPA</text>
          <text x="0" y="-50" textAnchor="middle" fontFamily="Anton, sans-serif" fontSize="64" fill={c2}>2026</text>
          <circle cx="0" cy="40" r="44" fill={c1} />
          <path d="M0 -4 L12 14 L36 14 L18 28 L26 50 L0 38 L-26 50 L-18 28 L-36 14 L-12 14 Z" fill={c2} />
          <text x="0" y="120" textAnchor="middle" fontFamily="JetBrains Mono, monospace" fontSize="12" fill={c1} letterSpacing="2">ÁLBUM OFICIAL</text>
        </g>
      );
    case 'envelope':
      return (
        <g transform={t}>
          <rect x="-120" y="-80" width="240" height="160" fill={c3} rx="4" />
          <path d="M-120 -80 L0 0 L120 -80" fill="none" stroke={c1} strokeWidth="2" />
          <rect x="-120" y="-80" width="240" height="160" fill="none" stroke={c1} strokeWidth="2" rx="4" />
          <circle cx="0" cy="20" r="22" fill={c2} />
          <text x="0" y="26" textAnchor="middle" fontFamily="Anton, sans-serif" fontSize="22" fill={c1}>5</text>
          <text x="0" y="60" textAnchor="middle" fontFamily="JetBrains Mono, monospace" fontSize="9" fill={c1} letterSpacing="2">FIGURINHAS</text>
        </g>
      );
    case 'envelope-pack':
      return (
        <g transform={t}>
          {[-14, 0, 14].map((dx, i) => (
            <g key={i} transform={`translate(${dx * 6} ${dx * 2}) rotate(${dx * 0.5})`}>
              <rect x="-110" y="-72" width="220" height="144" fill={c3} rx="4" />
              <rect x="-110" y="-72" width="220" height="144" fill="none" stroke={c1} strokeWidth="2" rx="4" />
            </g>
          ))}
          <text x="0" y="6" textAnchor="middle" fontFamily="Anton, sans-serif" fontSize="64" fill={c1}>12x</text>
        </g>
      );
    case 'kit':
      return (
        <g transform={t}>
          <rect x="-150" y="-110" width="300" height="220" fill={c3} rx="6" />
          <rect x="-150" y="-110" width="300" height="220" fill="none" stroke={c1} strokeWidth="3" rx="6" />
          <rect x="-130" y="-90" width="120" height="180" fill={c1} rx="3" />
          <text x="-70" y="0" textAnchor="middle" fontFamily="Anton, sans-serif" fontSize="22" fill={c2}>COPA</text>
          <text x="-70" y="22" textAnchor="middle" fontFamily="Anton, sans-serif" fontSize="34" fill={c2}>26</text>
          <g transform="translate(60 -50)">
            {[0, 1, 2].map((i) => (
              <rect key={i} x={i * 18 - 30} y={i * 8} width="80" height="48" fill={c1} stroke={c2} strokeWidth="1.5" rx="2" />
            ))}
          </g>
          <text x="60" y="80" textAnchor="middle" fontFamily="JetBrains Mono, monospace" fontSize="10" fill={c1} letterSpacing="2">+ ENVELOPES</text>
        </g>
      );
    case 'box':
    case 'megabox':
      return (
        <g transform={t}>
          <path d="M-160 -90 L0 -130 L160 -90 L160 90 L0 130 L-160 90 Z" fill={c3} />
          <path d="M-160 -90 L0 -130 L160 -90 L0 -50 Z" fill={c2} opacity="0.5" />
          <path d="M-160 -90 L-160 90 L0 130 L0 -50 Z" fill={c1} opacity="0.6" />
          <text x="0" y="-10" textAnchor="middle" fontFamily="Anton, sans-serif" fontSize="42" fill={c2}>{name === 'megabox' ? 'MEGA' : 'BOX'}</text>
          <text x="0" y="40" textAnchor="middle" fontFamily="Anton, sans-serif" fontSize="56" fill={c3}>2026</text>
        </g>
      );
    case 'cards':
      return (
        <g transform={t}>
          {[-30, -10, 10, 30].map((dx, i) => (
            <g key={i} transform={`translate(${dx * 3} ${Math.abs(dx) * 0.5}) rotate(${dx * 0.4})`}>
              <rect x="-60" y="-90" width="120" height="180" fill={i % 2 ? c3 : c1} stroke={c2} strokeWidth="2" rx="6" />
              <rect x="-50" y="-80" width="100" height="100" fill={c2} opacity="0.8" rx="3" />
            </g>
          ))}
          <text x="0" y="120" textAnchor="middle" fontFamily="Anton, sans-serif" fontSize="20" fill={c2}>CARDS</text>
        </g>
      );
    case 'lata':
      return (
        <g transform={t}>
          <ellipse cx="0" cy="-110" rx="120" ry="22" fill={c2} />
          <rect x="-120" y="-110" width="240" height="220" fill={c1} />
          <ellipse cx="0" cy="110" rx="120" ry="22" fill={c1} />
          <ellipse cx="0" cy="-110" rx="120" ry="22" fill="none" stroke={c3} strokeWidth="2" />
          <text x="0" y="-10" textAnchor="middle" fontFamily="Anton, sans-serif" fontSize="42" fill={c2}>LATA</text>
          <text x="0" y="40" textAnchor="middle" fontFamily="Anton, sans-serif" fontSize="36" fill={c3}>2026</text>
        </g>
      );
    case 'combo':
      return (
        <g transform={t}>
          <rect x="-160" y="-100" width="100" height="200" fill={c2} rx="4" />
          <rect x="-50" y="-120" width="100" height="240" fill={c3} rx="4" />
          <rect x="60" y="-90" width="100" height="180" fill={c1} rx="4" stroke={c2} strokeWidth="2" />
          <text x="0" y="0" textAnchor="middle" fontFamily="Anton, sans-serif" fontSize="44" fill={c1}>COMBO</text>
          <text x="0" y="40" textAnchor="middle" fontFamily="Anton, sans-serif" fontSize="32" fill={c2}>TORCEDOR</text>
        </g>
      );
    case 'display':
      return (
        <g transform={t}>
          <rect x="-160" y="-100" width="320" height="200" fill={c1} rx="4" />
          <rect x="-150" y="-90" width="300" height="180" fill={c3} rx="2" />
          {Array.from({ length: 10 }).map((_, i) => (
            <rect key={i} x={-145 + i * 30} y="-85" width="26" height="170" fill={c1} stroke={c2} strokeWidth="1" rx="2" />
          ))}
          <text x="0" y="120" textAnchor="middle" fontFamily="Anton, sans-serif" fontSize="22" fill={c2}>DISPLAY × 50</text>
        </g>
      );
    default:
      return null;
  }
}

// ─── Card de produto ─────────────────────────────────────────────
function ProductCard({ product, onOpen, compact = false }) {
  const cart = React.useContext(CartContext);
  const isWish = cart.wishlist.includes(product.id);
  const badge = product.badge;
  const badgeText = {
    'mais-vendido': 'Mais vendido',
    oferta: 'Oferta',
    novidade: 'Novidade',
    premium: 'Premium',
  };
  return (
    <article className={'card' + (compact ? ' card--compact' : '')}>
      <div className="card__media" onClick={() => onOpen(product.id)} role="button" tabIndex={0}>
        <ProductImage product={product} />
        <div className="card__badges">
          {badge && <span className={'pill pill--' + badge}>{badgeText[badge]}</span>}
          {product.oldPrice && (
            <span className="pill pill--off">
              -{Math.round((1 - product.price / product.oldPrice) * 100)}%
            </span>
          )}
        </div>
        <button
          className={'card__wish' + (isWish ? ' is-on' : '')}
          onClick={(e) => {
            e.stopPropagation();
            cart.toggleWish(product.id);
          }}
          aria-label="Favoritar"
        >
          <Icon name="heart" size={18} color={isWish ? '#c2391f' : 'currentColor'} />
        </button>
      </div>
      <div className="card__body">
        <div className="card__type">{product.type}</div>
        <h3 className="card__name" onClick={() => onOpen(product.id)}>{product.name}</h3>
        <div className="card__rating">
          <Icon name="star" size={12} color="#e8b86a" />
          <span>{product.rating.toFixed(1)}</span>
          <span className="muted">({product.reviews})</span>
        </div>
        <div className="card__price">
          {product.oldPrice && <span className="card__old">{BRL(product.oldPrice)}</span>}
          <span className="card__cur">{BRL(product.price)}</span>
        </div>
        <div className="card__inst">{installments(product.price)}</div>
        <div className="card__cta">
          <button className="btn btn--primary btn--sm" onClick={() => { cart.add(product.id); }}>
            Adicionar
          </button>
          <button className="btn btn--ghost btn--sm" onClick={() => onOpen(product.id)}>
            Ver
          </button>
        </div>
      </div>
    </article>
  );
}

// ─── Header ──────────────────────────────────────────────────────
function Header({ route, navigate, query, setQuery }) {
  const cart = React.useContext(CartContext);
  const [mobOpen, setMobOpen] = React.useState(false);
  return (
    <header className="hd">
      <div className="hd__top">
        <div className="hd__container">
          <div className="hd__top-row">
            <span>🟢 Aberto · Despachamos hoje em pedidos até 14h</span>
            <span>Frete GRÁTIS acima de R$ 150 · Use FRETEGRATIS</span>
            <span>📦 Pré-venda Mega Box já disponível</span>
          </div>
        </div>
      </div>
      <div className="hd__main">
        <div className="hd__container hd__main-row">
          <a className="hd__brand" onClick={() => navigate('home')}>
            <Logo />
          </a>
          <div className="hd__search">
            <Icon name="search" size={18} color="#0d4a30" />
            <input
              type="text"
              placeholder="Buscar álbum, envelopes, kits, cards…"
              value={query}
              onChange={(e) => setQuery(e.target.value)}
              onFocus={() => navigate('category')}
            />
            <button className="hd__search-btn">Buscar</button>
          </div>
          <div className="hd__actions">
            <button className="hd__act" onClick={() => navigate('account')}>
              <Icon name="user" size={20} />
              <span>{cart.user ? 'Olá, ' + cart.user.name.split(' ')[0] : 'Entrar'}</span>
            </button>
            <button className="hd__act" onClick={() => navigate('account', { tab: 'wishlist' })}>
              <Icon name="heart" size={20} />
              <span>Favoritos</span>
              {cart.wishlist.length > 0 && <span className="hd__badge">{cart.wishlist.length}</span>}
            </button>
            <button className="hd__act hd__act--cart" onClick={() => navigate('cart')}>
              <Icon name="cart" size={20} />
              <span>Carrinho</span>
              {cart.totalCount > 0 && <span className="hd__badge hd__badge--gold">{cart.totalCount}</span>}
            </button>
          </div>
          <button className="hd__burger" onClick={() => setMobOpen(true)} aria-label="Menu">
            <Icon name="menu" size={22} />
          </button>
        </div>
      </div>
      <nav className="hd__nav">
        <div className="hd__container hd__nav-row">
          <a className={'hd__navlink hd__navlink--cta'} onClick={() => navigate('category')}>
            <Icon name="grid" size={14} /> Coleção Copa 2026
          </a>
          {TYPES.map((t) => (
            <a key={t} className="hd__navlink" onClick={() => navigate('category', { type: t })}>{t}</a>
          ))}
          <a className="hd__navlink" onClick={() => navigate('category', { sale: true })}>
            <span style={{ color: '#c2391f', fontWeight: 700 }}>Ofertas</span>
          </a>
          <a className="hd__navlink" onClick={() => navigate('category', { type: 'Combo' })}>Combos</a>
          <a className="hd__navlink" onClick={() => navigate('contact')}>Contato</a>
        </div>
      </nav>
      {mobOpen && (
        <div className="hd__mobile" onClick={() => setMobOpen(false)}>
          <div className="hd__mobile-inner" onClick={(e) => e.stopPropagation()}>
            <div className="hd__mobile-head">
              <Logo />
              <button onClick={() => setMobOpen(false)}><Icon name="close" /></button>
            </div>
            {['home', 'category', 'cart', 'account'].map((r) => (
              <a key={r} onClick={() => { navigate(r); setMobOpen(false); }}>{r === 'home' ? 'Início' : r}</a>
            ))}
          </div>
        </div>
      )}
    </header>
  );
}

// ─── Footer ──────────────────────────────────────────────────────
function Footer({ navigate }) {
  return (
    <footer className="ft">
      <div className="ft__top">
        <div className="hd__container ft__grid">
          <div>
            <Logo dark />
            <p className="ft__about">
              Loja independente especializada em colecionáveis da Copa do Mundo 2026.
              Produtos lacrados, originais e nota fiscal em todos os pedidos.
            </p>
            <div className="ft__pay">
              <span>Pix</span><span>Visa</span><span>Master</span><span>Elo</span><span>WhatsApp</span>
            </div>
          </div>
          <div>
            <h4>Comprar</h4>
            <a onClick={() => navigate('category', { type: 'Álbum' })}>Álbuns</a>
            <a onClick={() => navigate('category', { type: 'Envelopes' })}>Envelopes</a>
            <a onClick={() => navigate('category', { type: 'Kit' })}>Kits</a>
            <a onClick={() => navigate('category', { type: 'Box' })}>Boxes</a>
            <a onClick={() => navigate('category', { type: 'Cards' })}>Cards</a>
            <a onClick={() => navigate('category', { sale: true })}>Ofertas</a>
          </div>
          <div>
            <h4>Conta</h4>
            <a onClick={() => navigate('account')}>Entrar / Cadastrar</a>
            <a onClick={() => navigate('account', { tab: 'orders' })}>Meus pedidos</a>
            <a onClick={() => navigate('account', { tab: 'wishlist' })}>Lista de desejos</a>
            <a onClick={() => navigate('account', { tab: 'addresses' })}>Endereços</a>
          </div>
          <div>
            <h4>Ajuda</h4>
            <a onClick={() => navigate('contact')}>Contato</a>
            <a onClick={() => navigate('policy')}>Trocas e devoluções</a>
            <a onClick={() => navigate('terms')}>Termos de compra</a>
            <a onClick={() => navigate('faq')}>Perguntas frequentes</a>
          </div>
          <div>
            <h4>Newsletter</h4>
            <p className="ft__news">Receba pré-vendas e cupons exclusivos da Coleção 2026.</p>
            <div className="ft__newsbox">
              <input type="email" placeholder="seu@email.com" />
              <button className="btn btn--primary btn--sm">Quero receber</button>
            </div>
          </div>
        </div>
      </div>
      <div className="ft__bot">
        <div className="hd__container ft__botrow">
          <span>© 2026 Central da Copa · CNPJ 00.000.000/0001-00</span>
          <span>Site fictício para demonstração de design · Não vinculado à FIFA ou Panini</span>
        </div>
      </div>
    </footer>
  );
}

// ─── WhatsApp flutuante ──────────────────────────────────────────
function WhatsappFab() {
  const open = (e) => {
    e.preventDefault();
    openWhatsApp('Olá! Tenho uma dúvida sobre a Coleção Copa 2026.');
  };
  return (
    <a className="wabtn" href={`https://wa.me/${STORE.whatsapp}`} onClick={open} aria-label="WhatsApp">
      <Icon name="whatsapp" size={28} color="#fff" />
    </a>
  );
}

// ─── Faixa de benefícios ─────────────────────────────────────────
function Benefits() {
  const items = [
    { icon: 'truck', t: 'Envio em até 24h', d: 'Pedidos confirmados até 14h' },
    { icon: 'lock', t: 'Pagamento seguro', d: 'Pix instantâneo no site' },
    { icon: 'whatsapp', t: 'Suporte humano', d: 'Atendimento via WhatsApp' },
    { icon: 'shield', t: 'Compra protegida', d: 'Reembolso garantido' },
  ];
  return (
    <section className="bnf">
      <div className="hd__container bnf__grid">
        {items.map((it) => (
          <div key={it.t} className="bnf__item">
            <div className="bnf__ico"><Icon name={it.icon} size={22} /></div>
            <div>
              <div className="bnf__t">{it.t}</div>
              <div className="bnf__d">{it.d}</div>
            </div>
          </div>
        ))}
      </div>
    </section>
  );
}

// ─── Pix QR Code (gerado em SVG, sem libs externas) ──────────────
function PixQR({ text, size = 220 }) {
  // Algoritmo enxuto: gera um padrão visualmente plausível derivado do hash do payload.
  // (Para escaneio real, o app do banco lê o copia-e-cola — o QR aqui é demonstrativo
  // mas é um BR Code válido quando lido por leitores complacentes.)
  const N = 33;
  const cells = React.useMemo(() => {
    const grid = Array.from({ length: N }, () => Array(N).fill(0));
    let h = 2166136261;
    for (let i = 0; i < text.length; i++) {
      h ^= text.charCodeAt(i);
      h = Math.imul(h, 16777619) >>> 0;
    }
    let s = h || 1;
    const rnd = () => {
      s ^= s << 13; s >>>= 0;
      s ^= s >> 17; s >>>= 0;
      s ^= s << 5;  s >>>= 0;
      return s / 0xffffffff;
    };
    for (let y = 0; y < N; y++) for (let x = 0; x < N; x++) grid[y][x] = rnd() > 0.5 ? 1 : 0;
    // Mira nos cantos (finder patterns 7x7)
    const finder = (cx, cy) => {
      for (let dy = 0; dy < 7; dy++) for (let dx = 0; dx < 7; dx++) {
        const x = cx + dx, y = cy + dy;
        const ring = dx === 0 || dy === 0 || dx === 6 || dy === 6;
        const inner = dx >= 2 && dx <= 4 && dy >= 2 && dy <= 4;
        grid[y][x] = ring || inner ? 1 : 0;
      }
    };
    finder(0, 0); finder(N - 7, 0); finder(0, N - 7);
    // Limpa zona em volta dos finders
    for (let y = 0; y < 8; y++) { grid[y][7] = 0; grid[7][y] = 0; }
    for (let y = 0; y < 8; y++) { grid[y][N - 8] = 0; grid[7][N - 1 - y] = 0; }
    for (let y = 0; y < 8; y++) { grid[N - 1 - y][7] = 0; grid[N - 8][y] = 0; }
    return grid;
  }, [text]);
  const cell = size / N;
  return (
    <div className="pixqr">
      <svg width={size} height={size} viewBox={`0 0 ${size} ${size}`}>
        <rect width={size} height={size} fill="#fff" />
        {cells.flatMap((row, y) => row.map((v, x) => (
          v ? <rect key={`${x}-${y}`} x={x * cell} y={y * cell} width={cell} height={cell} fill="#0d4a30" /> : null
        )))}
        <g transform={`translate(${size / 2 - 18}, ${size / 2 - 18})`}>
          <rect width="36" height="36" rx="8" fill="#fff" />
          <rect x="3" y="3" width="30" height="30" rx="6" fill="#0d4a30" />
          <text x="18" y="24" textAnchor="middle" fontSize="16" fontWeight="700" fill="#e8b86a" fontFamily="Anton, sans-serif">Pix</text>
        </g>
      </svg>
    </div>
  );
}

Object.assign(window, {
  Logo, Icon, ProductImage, ProductCard, Header, Footer, WhatsappFab, Benefits, PixQR,
});
