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

// ==================== i18n HOOK ====================
// Subscribes to SMi18n language changes and re-renders the component.
function useLang() {
  const [lang, setLang] = useState(() => window.SMi18n?.lang || 'es');
  useEffect(() => {
    if (!window.SMi18n) return;
    return window.SMi18n.onChange(setLang);
  }, []);
  return {
    lang,
    t: (key) => window.SMi18n?.t(key) ?? key,
  };
}

// ==================== Cuba flag (SVG) ====================
const CubaFlag = (p) => (
  <svg viewBox="0 0 30 20" width="22" height="15" {...p} style={{borderRadius:3, boxShadow:'0 0 0 1px rgba(0,0,0,.08)', display:'block', ...(p.style||{})}}>
    <rect width="30" height="20" fill="#fff"/>
    <rect width="30" height="4" y="0" fill="#002A8F"/>
    <rect width="30" height="4" y="8" fill="#002A8F"/>
    <rect width="30" height="4" y="16" fill="#002A8F"/>
    <polygon points="0,0 12,10 0,20" fill="#CF142B"/>
    <polygon points="3,10 4.4,7.5 1.7,7.5 4.1,5.7 3.1,8.3 5.5,6.6 4.5,9.4 6.9,7.7 6,10.5 8.4,8.7 7.5,11.6 5,9.5 5.5,12.5 3.5,10.5" fill="#fff" transform="translate(0.5,0)"/>
    <circle cx="4.4" cy="10" r="1.6" fill="#fff"/>
  </svg>
);

// Cleaner star shape
const CubaFlagSimple = (p) => (
  <svg viewBox="0 0 30 20" width="22" height="15" {...p} style={{borderRadius:3, boxShadow:'0 0 0 1px rgba(0,0,0,.08)', display:'block', ...(p.style||{})}}>
    <rect width="30" height="20" fill="#fff"/>
    <rect y="0"  width="30" height="4" fill="#002A8F"/>
    <rect y="8"  width="30" height="4" fill="#002A8F"/>
    <rect y="16" width="30" height="4" fill="#002A8F"/>
    <polygon points="0,0 12,10 0,20" fill="#CF142B"/>
    <polygon points="4.2,7.2 4.85,9.2 6.95,9.2 5.25,10.4 5.9,12.4 4.2,11.15 2.5,12.4 3.15,10.4 1.45,9.2 3.55,9.2" fill="#fff"/>
  </svg>
);

// ==================== ICONS ====================
const Icon = {
  Bolt: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z"/></svg>,
  Shield: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></svg>,
  Globe: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><circle cx="12" cy="12" r="10"/><path d="M2 12h20M12 2a15 15 0 010 20M12 2a15 15 0 000 20"/></svg>,
  Check: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round" {...p}><polyline points="20 6 9 17 4 12"/></svg>,
  Arrow: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round" {...p}><line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/></svg>,
  Phone: (p) => <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M22 16.92v3a2 2 0 01-2.18 2 19.79 19.79 0 01-8.63-3.07 19.5 19.5 0 01-6-6 19.79 19.79 0 01-3.07-8.67A2 2 0 014.11 2h3a2 2 0 012 1.72 12.84 12.84 0 00.7 2.81 2 2 0 01-.45 2.11L8.09 9.91a16 16 0 006 6l1.27-1.27a2 2 0 012.11-.45 12.84 12.84 0 002.81.7A2 2 0 0122 16.92z"/></svg>,
  Wifi: (p) => <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M5 12.55a11 11 0 0114.08 0M1.42 9a16 16 0 0121.16 0M8.53 16.11a6 6 0 016.95 0M12 20h.01"/></svg>,
  Lock: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><rect x="3" y="11" width="18" height="11" rx="2"/><path d="M7 11V7a5 5 0 0110 0v4"/></svg>,
  Clock: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>,
  Plus: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round" {...p}><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>,
  Star: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" {...p}><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/></svg>,
  Send: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><line x1="22" y1="2" x2="11" y2="13"/><polygon points="22 2 15 22 11 13 2 9 22 2"/></svg>,
  Mail: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z"/><polyline points="22,6 12,13 2,6"/></svg>,
  Msg: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"/></svg>,
  Target: (p) => <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" {...p}><circle cx="12" cy="12" r="10"/><circle cx="12" cy="12" r="6"/><circle cx="12" cy="12" r="2"/></svg>,
  Heart: (p) => <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" {...p}><path d="M20.84 4.61a5.5 5.5 0 00-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 00-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 000-7.78z"/></svg>,
  Zap: (p) => <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z"/></svg>,
  FB: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M22 12a10 10 0 10-11.56 9.88v-6.99H7.9V12h2.54V9.8c0-2.5 1.49-3.88 3.77-3.88 1.09 0 2.24.2 2.24.2v2.46h-1.26c-1.24 0-1.63.77-1.63 1.56V12h2.77l-.44 2.89h-2.33v6.99A10 10 0 0022 12z"/></svg>,
  IG: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" {...p}><rect x="2" y="2" width="20" height="20" rx="5"/><path d="M16 11.37A4 4 0 1112.63 8 4 4 0 0116 11.37zM17.5 6.5h.01"/></svg>,
  WA: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M17.5 14.4c-.3-.1-1.6-.8-1.9-.9s-.4-.1-.6.1-.7.9-.8 1-.3.2-.6.1a7.5 7.5 0 01-2.3-1.4 8.3 8.3 0 01-1.6-2c-.2-.3 0-.4.1-.6l.4-.5.3-.4.1-.4v-.4c-.1-.1-.6-1.5-.8-2s-.5-.4-.6-.4h-.6a1.1 1.1 0 00-.8.4 3.3 3.3 0 00-1.1 2.5 5.9 5.9 0 001.2 3.1 13.3 13.3 0 005.1 4.5c.7.3 1.3.5 1.7.6a4.1 4.1 0 001.9.1 3.1 3.1 0 002-1.4 2.5 2.5 0 00.2-1.4c-.1-.1-.3-.2-.5-.3zM12 2a10 10 0 00-8.6 15.1L2 22l4.9-1.3A10 10 0 1012 2zm5.9 15.9a8.3 8.3 0 01-11.3.3l-.3-.2-2.9.8.8-2.8-.2-.3A8.3 8.3 0 1117.9 17.9z"/></svg>,
  Crown: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M2 20h20v2H2zm0-2l2-8 5 4 3-8 3 8 5-4 2 8z"/></svg>,
};

// ==================== NAV ====================
function Logo() {
  return (
    <a href="index.html" className="sm-nav__logo" style={{textDecoration:'none'}}>
      <img src="logo.svg" alt="SMCUBA" height="52" style={{display:'block', height:52, width:'auto'}} />
    </a>
  );
}

// Smart in-page scroll; falls through to href if element not found (different page).
function navScroll(id, type) {
  return (e) => {
    const el = document.getElementById(id);
    if (el) {
      e.preventDefault();
      el.scrollIntoView({ behavior: 'smooth' });
      if (type) window.dispatchEvent(new CustomEvent('sm:setType', { detail: type }));
    }
  };
}

function Nav({ mobile = false }) {
  const [hasSession, setHasSession] = useState(false);
  const [open, setOpen] = useState(false);
  const { t, lang } = useLang();

  useEffect(() => {
    let cancelled = false;
    if (window.SMAuth && window.SMAuth.session) {
      window.SMAuth.session().then(s => { if (!cancelled) setHasSession(!!s); });
    }
    const { data: sub } = (window.supabaseClient?.auth?.onAuthStateChange(
      (_e, sess) => { if (!cancelled) setHasSession(!!sess); }
    )) || { data: null };
    return () => { cancelled = true; sub?.subscription?.unsubscribe?.(); };
  }, []);

  const close = () => setOpen(false);
  const toggleLang = () => window.SMi18n?.setLang(lang === 'es' ? 'en' : 'es');

  const links = <>
    <a className="sm-nav__link sm-nav__link--active" href="index.html" onClick={close}>{t('nav.home')}</a>
    <a className="sm-nav__link" href="index.html#recargas"    onClick={e=>{navScroll('recargas','movil')(e); close();}}>{t('nav.movil')}</a>
    <a className="sm-nav__link" href="index.html#recargas"    onClick={e=>{navScroll('recargas','nauta')(e); close();}}>{t('nav.nauta')}</a>
    <a className="sm-nav__link" href="index.html#promociones" onClick={e=>{navScroll('promociones')(e);      close();}}>{t('nav.promos')}</a>
    <a className="sm-nav__link" href="index.html#faq"         onClick={e=>{navScroll('faq')(e);             close();}}>{t('nav.ayuda')}</a>
  </>;

  const cta = hasSession
    ? <a href="dashboard.html" className="sm-btn sm-btn--primary" onClick={close}>{t('nav.mi_cuenta')} <Icon.Arrow /></a>
    : <a href="login.html"     className="sm-btn sm-btn--primary" onClick={close}>{t('nav.iniciar')} <Icon.Arrow /></a>;

  return (
    <>
      <nav className="sm-nav">
        <Logo />
        <div className="sm-nav__links">{links}</div>
        <div className="sm-nav__actions">
          <button className="sm-lang-toggle" onClick={toggleLang} aria-label="Toggle language" title={lang === 'es' ? 'Switch to English' : 'Cambiar a Español'}>
            <span className={lang === 'es' ? 'sm-lang-toggle__opt--active' : 'sm-lang-toggle__opt'}>ES</span>
            <span className="sm-lang-toggle__sep">|</span>
            <span className={lang === 'en' ? 'sm-lang-toggle__opt--active' : 'sm-lang-toggle__opt'}>EN</span>
          </button>
          <div className="sm-nav__cta-wrap">{cta}</div>
          <button className="sm-nav__burger" aria-label={open ? t('nav.cerrar') : t('nav.menu')} onClick={()=>setOpen(o=>!o)}>
            {open
              ? <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
              : <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5"><line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="12" x2="21" y2="12"/><line x1="3" y1="18" x2="21" y2="18"/></svg>}
          </button>
        </div>
      </nav>
      {open && (
        <div className="sm-nav__drawer">
          <div className="sm-nav__drawer-links">{links}</div>
          <div style={{display:'flex', alignItems:'center', gap:12, justifyContent:'center', padding:'4px 0'}}>
            <button className="sm-lang-toggle" onClick={() => { toggleLang(); close(); }} aria-label="Toggle language">
              <span className={lang === 'es' ? 'sm-lang-toggle__opt--active' : 'sm-lang-toggle__opt'}>ES</span>
              <span className="sm-lang-toggle__sep">|</span>
              <span className={lang === 'en' ? 'sm-lang-toggle__opt--active' : 'sm-lang-toggle__opt'}>EN</span>
            </button>
          </div>
          <div className="sm-nav__drawer-cta">{cta}</div>
        </div>
      )}
    </>
  );
}

// ==================== DB OFFERS HOOKS ====================
// Simple module-level cache to avoid redundant DB calls.
let _dbOffersCache = null;
let _dbPromoCache  = null;

function useDbOffers() {
  const [offers, setOffers] = useState(null); // null = loading/fallback
  useEffect(() => {
    if (_dbOffersCache) { setOffers(_dbOffersCache); return; }
    if (!window.supabaseClient) return;
    window.supabaseClient
      .from('offers').select('*').eq('active', true).order('type').order('sort_order')
      .then(({ data }) => {
        if (!data || !data.length) return;
        const g = { movil: [], nauta: [] };
        data.forEach(o => {
          g[o.type]?.push({
            id:      o.id,
            amount:  o.name,
            desc:    (o.features || []).map(f => f.join(': ')).join(' · '),
            price:   parseFloat(o.price),
            was:     o.was_price  ? parseFloat(o.was_price)  : undefined,
            badge:   o.badge,
            cup:     o.cup_value  ? parseFloat(o.cup_value)  : 0,
            bonus:   o.bonus_cup  ? parseFloat(o.bonus_cup)  : 0,
            service: o.type,
          });
        });
        if (g.movil.length + g.nauta.length > 0) { _dbOffersCache = g; setOffers(g); }
      });
  }, []);
  return offers; // null = use fallback OFFERS constant
}

function useDbPromos() {
  const [promos, setPromos] = useState(null);
  useEffect(() => {
    if (_dbPromoCache) { setPromos(_dbPromoCache); return; }
    if (!window.supabaseClient) return;
    window.supabaseClient
      .from('offers').select('*').eq('active', true).eq('featured', true).order('sort_order')
      .then(({ data }) => {
        if (!data || !data.length) return;
        const list = data.map(o => ({
          type:     o.type === 'movil' ? 'Móvil' : 'Nauta',
          name:     o.name,
          features: (o.features || []).map(([k, v]) => [k, v]),
          now:      parseFloat(o.price),
          was:      o.was_price ? parseFloat(o.was_price) : null,
          tag:      o.badge,
          featured: o.featured,
        }));
        _dbPromoCache = list;
        setPromos(list);
      });
  }, []);
  return promos;
}

// ==================== HERO (with integrated Recarga Flash) ====================
const OFFERS = {
  movil: [
    { id: 'm1', amount: '80 minutos', desc: 'Duración 35 días · Llamadas nacionales', price: 5.99, was: 7.99, badge: 'Oferta' },
    { id: 'm2', amount: '40 minutos', desc: 'Duración 35 días · Llamadas nacionales', price: 3.99 },
    { id: 'm3', amount: '250 CUP', desc: 'Saldo principal · 30 días', price: 4.50 },
    { id: 'm4', amount: '500 CUP', desc: 'Saldo principal · 30 días', price: 8.99, badge: 'Popular' },
  ],
  nauta: [
    { id: 'n1', amount: 'Nauta Plus 15 días', desc: 'Internet ilimitado', price: 8.50, was: 14.00, badge: 'Oferta' },
    { id: 'n2', amount: 'Nauta 1 GB', desc: '30 días', price: 4.00 },
    { id: 'n3', amount: 'Nauta 5 GB', desc: '30 días', price: 12.00, badge: 'Mejor valor' },
    { id: 'n4', amount: 'Nauta 10 USD', desc: 'Saldo cuenta Nauta', price: 10.00 },
  ],
};

function FlashCard({ variant }) {
  const [type, setType] = useState('movil');
  const [selected, setSelected] = useState('m1');
  const [phone, setPhone] = useState('');
  const [flashErr, setFlashErr] = useState('');
  const dbOffers = useDbOffers();
  const activeOffers = dbOffers || OFFERS;
  const { t } = useLang();

  useEffect(() => {
    const first = activeOffers[type]?.[0]?.id || (type==='movil'?'m1':'n1');
    setSelected(first);
  }, [type, dbOffers]);

  // Listen for nav "Recargas Nauta / Móvil" click events
  useEffect(() => {
    const h = (e) => setType(e.detail);
    window.addEventListener('sm:setType', h);
    return () => window.removeEventListener('sm:setType', h);
  }, []);
  const list = (activeOffers[type] || []).slice(0, 4);

  return (
    <div className="sm-flash anim-rise" style={{animationDelay: '0.2s'}}>
      <div className="sm-flash__header">
        <h3 className="sm-flash__title">{t('flash.title')}</h3>
        <span className="sm-flash__live">
          <span className="sm-flash__live-dot"/> {t('flash.live')}
        </span>
      </div>

      <div className="sm-flash__toggle">
        <div className="sm-flash__toggle-indicator" style={{ left: type === 'movil' ? '4px' : 'calc(50% + 0px)' }}/>
        <button className={`sm-flash__toggle-btn ${type==='movil'?'sm-flash__toggle-btn--active':''}`} onClick={()=>setType('movil')}>
          <Icon.Phone width="16" height="16" /> {t('flash.movil')}
        </button>
        <button className={`sm-flash__toggle-btn ${type==='nauta'?'sm-flash__toggle-btn--active':''}`} onClick={()=>setType('nauta')}>
          <Icon.Wifi width="16" height="16" /> {t('flash.nauta')}
        </button>
      </div>

      <div className="sm-field">
        <label className="sm-field__label">{type === 'nauta' ? t('flash.nauta_lbl') : t('flash.phone_lbl')}</label>
        {type === 'nauta' ? (
          <div className="sm-phone">
            <input
              className="sm-phone__input"
              style={{paddingLeft:18}}
              placeholder="usuario"
              value={phone}
              onChange={e=>setPhone(e.target.value.replace(/\s/g,'').toLowerCase())}
              autoComplete="off"
            />
            <span className="sm-phone__prefix" style={{order:2, borderLeft:'1px solid var(--ink-100,#eee)', borderRight:'none', color:'var(--ink-700)'}}>@nauta.com.cu</span>
          </div>
        ) : (
          <div className="sm-phone">
            <span className="sm-phone__prefix"><CubaFlagSimple/> +53</span>
            <input
              className="sm-phone__input"
              placeholder="5XXXXXXX"
              inputMode="numeric"
              maxLength="8"
              value={phone}
              onChange={e=>setPhone(e.target.value.replace(/\D/g,'').slice(0,8))}
            />
          </div>
        )}
      </div>

      <div className="sm-field">
        <label className="sm-field__label">{t('flash.offer_lbl')}</label>
        <div className="sm-offers">
          {list.map(o => (
            <button key={o.id} className={`sm-offer ${selected===o.id?'sm-offer--selected':''}`} onClick={()=>setSelected(o.id)}>
              {o.badge && <span className="sm-offer__badge">{o.badge}</span>}
              <span className="sm-offer__amt">{o.amount}</span>
              <span className="sm-offer__desc">{o.desc}</span>
              <div className="sm-offer__price">
                <span className="sm-offer__price-now">${o.price.toFixed(2)}</span>
                {o.was && <span className="sm-offer__price-was">${o.was.toFixed(2)}</span>}
              </div>
            </button>
          ))}
        </div>
      </div>

      {flashErr && (
        <div style={{
          display:'flex', alignItems:'center', gap:10,
          background:'rgba(239,68,68,.1)', border:'1px solid rgba(239,68,68,.3)',
          borderRadius:12, padding:'10px 14px', fontSize:13, fontWeight:600,
          color:'#c62828', marginBottom:4
        }}>
          <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" style={{flexShrink:0}}>
            <circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/>
          </svg>
          {flashErr}
        </div>
      )}
      <button className="sm-btn sm-btn--primary sm-btn--lg sm-btn--block" onClick={() => {
        setFlashErr('');
        if (type === 'movil' && phone.length !== 8) {
          setFlashErr(t('flash.err_phone'));
          return;
        }
        if (type === 'nauta' && !/^[a-z0-9._-]+$/i.test(phone || '')) {
          setFlashErr(t('flash.err_nauta'));
          return;
        }
        const offer = (activeOffers[type] || []).find(o => o.id === selected) || activeOffers[type]?.[0];
        localStorage.setItem('sm_recarga', JSON.stringify({
          type,
          offerId:    selected,
          offerName:  offer?.amount || '',
          offerPrice: offer?.price  || 0,
          phone,
          recipient:  type === 'nauta' ? `${phone}@nauta.com.cu` : `+53${phone}`,
          savedAt:    Date.now(),
        }));
        window.location.href = 'login.html';
      }}>
        <Icon.Bolt /> {t('flash.cta')} <Icon.Arrow />
      </button>

      <div className="sm-flash__footer">
        <span className="sm-flash__footer-note"><Icon.Lock /> {t('flash.ssl')}</span>
        <span className="sm-flash__footer-note"><Icon.Clock /> {t('flash.fast')}</span>
      </div>
    </div>
  );
}

function HeroPhoto() {
  return (
    <div className="sm-hero__visual-wrap">
      <div className="sm-hero__photo">
        <div className="sm-hero__photo-placeholder">
          <span className="sm-hero__photo-tag">FOTO · PERSONA CUBANA CON MÓVIL</span>
        </div>
      </div>
      <div className="sm-hero__float-card sm-hero__float-card--tl">
        <div className="sm-hero__float-avatar">M</div>
        <div>
          <strong>María, La Habana</strong>
          <span>Recibió $5.99 hace 2 min</span>
        </div>
      </div>
      <div className="sm-hero__float-card sm-hero__float-card--br">
        <div className="sm-hero__float-avatar" style={{background:'linear-gradient(135deg, #4F3DF5, #8B7EFF)'}}>
          <Icon.Check />
        </div>
        <div>
          <strong>Entrega garantizada</strong>
          <span>En menos de 60 segundos</span>
        </div>
      </div>
    </div>
  );
}

function Hero({ variant, mobile = false }) {
  const { t } = useLang();
  return (
    <section className="sm-hero" id="recargas">
      <div className="sm-hero__inner">
        <div className="anim-rise">
          <span className="sm-hero__eyebrow"><span className="sm-hero__eyebrow-dot"/> {t('hero.eyebrow')}</span>
          <h1 className="sm-hero__title" dangerouslySetInnerHTML={{ __html: t('hero.title') }} />
          <p className="sm-hero__sub">{t('hero.sub')}</p>
          <div className="sm-hero__chips">
            <span className="sm-chip"><Icon.Clock /> {t('hero.chip1')}</span>
            <span className="sm-chip"><Icon.Shield /> {t('hero.chip2')}</span>
            <span className="sm-chip"><Icon.Globe /> {t('hero.chip3')}</span>
          </div>
        </div>
        {variant === 'photo' ? <HeroPhoto /> : <FlashCard variant={variant} />}
      </div>
    </section>
  );
}

// ==================== TRUST BAR ====================
function Counter({ to, suffix = '', prefix = '' }) {
  const [n, setN] = useState(0);
  const ref = useRef(null);
  useEffect(() => {
    let raf;
    const duration = 1400;
    const start = performance.now();
    const step = (t) => {
      const p = Math.min(1, (t - start) / duration);
      const eased = 1 - Math.pow(1 - p, 3);
      setN(Math.floor(to * eased));
      if (p < 1) raf = requestAnimationFrame(step);
      else setN(to);
    };
    raf = requestAnimationFrame(step);
    return () => cancelAnimationFrame(raf);
  }, [to]);
  return <span ref={ref}>{prefix}{n.toLocaleString()}{suffix}</span>;
}

function TrustBar() {
  const { t } = useLang();
  return (
    <section className="sm-trust">
      <div className="sm-trust__inner">
        <div className="sm-trust__stats">
          <div className="sm-trust__stat">
            <span className="sm-trust__stat-num"><Counter to={340} suffix="K+" /></span>
            <span className="sm-trust__stat-label">{t('trust.recargas')}</span>
          </div>
          <div className="sm-trust__divider" />
          <div className="sm-trust__stat">
            <span className="sm-trust__stat-num"><em>&lt; 1 min</em></span>
            <span className="sm-trust__stat-label">{t('trust.entrega')}</span>
          </div>
          <div className="sm-trust__divider" />
          <div className="sm-trust__stat">
            <span className="sm-trust__stat-num"><em>24/7</em></span>
            <span className="sm-trust__stat-label">{t('trust.soporte')}</span>
          </div>
        </div>
        <div/>
        <div className="sm-trust__rating">
          <div className="sm-trust__stars">
            <Icon.Star /><Icon.Star /><Icon.Star /><Icon.Star /><Icon.Star />
          </div>
          <div className="sm-trust__rating-text">
            <strong>4.9 / 5.0</strong>
            <small>de +3,200 {t('trust.resenas')}</small>
          </div>
        </div>
      </div>
    </section>
  );
}

// ==================== HOW IT WORKS ====================
function HowItWorks() {
  const { t } = useLang();
  const steps = [
    { n: '01', title: t('how.s1.title'), desc: t('how.s1.desc'), icon: <Icon.Target /> },
    { n: '02', title: t('how.s2.title'), desc: t('how.s2.desc'), icon: <Icon.Shield width="20" height="20" /> },
    { n: '03', title: t('how.s3.title'), desc: t('how.s3.desc'), icon: <Icon.Zap /> },
  ];
  return (
    <section className="sm-section">
      <div className="sm-section__header">
        <div className="sm-section__eyebrow">{t('how.eyebrow')}</div>
        <h2 className="sm-section__title" dangerouslySetInnerHTML={{ __html: t('how.title') }} />
        <p className="sm-section__sub">{t('how.sub')}</p>
      </div>
      <div className="sm-steps">
        {steps.map(s => (
          <div key={s.n} className="sm-step">
            <div className="sm-step__icon">{s.icon}</div>
            <div className="sm-step__num">{s.n}</div>
            <h3 className="sm-step__title">{s.title}</h3>
            <p className="sm-step__desc">{s.desc}</p>
          </div>
        ))}
      </div>
    </section>
  );
}

// ==================== PROMOS ====================
const FALLBACK_PROMOS = [
  { type: 'Móvil', name: 'Recarga 80 minutos', features: [['Duración', '35 días'], ['Incluye', '80 min nacionales'], ['Activación', 'Inmediata']], now: 5.99, was: 7.99, tag: 'Oferta', featured: false },
  { type: 'Nauta', name: 'Nauta Plus 15 días', features: [['Internet', 'Ilimitado'], ['Válido por', '15 días'], ['Tipo', 'Nauta Hogar']], now: 8.50, was: 14.00, tag: '-40%', featured: true },
  { type: 'Móvil', name: 'Recarga 500 CUP', features: [['Saldo', '500 CUP'], ['Duración', '30 días'], ['Bono', '+50 SMS']], now: 8.99, was: null, tag: 'Popular', featured: false },
];

function Promos() {
  const dbPromos = useDbPromos();
  const promos = dbPromos || FALLBACK_PROMOS;
  const { t } = useLang();
  return (
    <section className="sm-section" id="promociones">
      <div className="sm-section__header">
        <div className="sm-section__eyebrow">{t('promos.eyebrow')}</div>
        <h2 className="sm-section__title" dangerouslySetInnerHTML={{ __html: t('promos.title') }} />
        <p className="sm-section__sub">{t('promos.sub')}</p>
      </div>
      <div className="sm-promos">
        {promos.map((p, i) => (
          <div key={i} className={`sm-promo ${p.featured?'sm-promo--featured':''}`}>
            {p.tag && <span className="sm-promo__tag">{p.tag}</span>}
            <div className="sm-promo__type">{p.type}</div>
            <h3 className="sm-promo__name">{p.name}</h3>
            <ul className="sm-promo__features">
              {p.features.map(([k,v], j) => (
                <li key={j} className="sm-promo__feature">
                  <Icon.Check width="14" height="14" /> {k}: <strong>{v}</strong>
                </li>
              ))}
            </ul>
            <div className="sm-promo__price">
              <span className="sm-promo__price-now">${p.now.toFixed(2)}</span>
              {p.was && <span className="sm-promo__price-was">${p.was.toFixed(2)}</span>}
            </div>
            <button className="sm-promo__cta">{t('promos.cta')} <Icon.Arrow /></button>
          </div>
        ))}
      </div>
    </section>
  );
}

// ==================== FAQ ====================
function FAQ() {
  const [open, setOpen] = useState(0);
  const { t } = useLang();
  const items = [
    { q: t('faq.q1'), a: t('faq.a1') },
    { q: t('faq.q2'), a: t('faq.a2') },
    { q: t('faq.q3'), a: t('faq.a3') },
    { q: t('faq.q4'), a: t('faq.a4') },
    { q: t('faq.q5'), a: t('faq.a5') },
  ];
  return (
    <section className="sm-section" id="faq">
      <div className="sm-section__header">
        <div className="sm-section__eyebrow">{t('faq.eyebrow')}</div>
        <h2 className="sm-section__title" dangerouslySetInnerHTML={{ __html: t('faq.title') }} />
      </div>
      <div className="sm-faq">
        {items.map((it, i) => (
          <div key={i} className={`sm-faq__item ${open===i?'sm-faq__item--open':''}`}>
            <button className="sm-faq__q" onClick={()=>setOpen(open===i?-1:i)}>
              <span>{it.q}</span>
              <span className="sm-faq__icon"><Icon.Plus /></span>
            </button>
            <div className="sm-faq__a">{it.a}</div>
          </div>
        ))}
      </div>
    </section>
  );
}

// ==================== CONTACT ====================
function Contact() {
  return (
    <ContactSection />
  );
}

function ContactSection() {
  const [form, setForm] = useState({ first:'', last:'', email:'', phone:'', message:'' });
  const [fieldErrs, setFieldErrs] = useState({});
  const [token, setToken] = useState('');
  const [msg, setMsg] = useState('');
  const [sending, setSending] = useState(false);
  const turnstileRef = useRef(null);
  const { t } = useLang();

  useEffect(() => {
    let cancelled = false;
    const ensureScript = () => new Promise(resolve => {
      if (window.turnstile) return resolve();
      if (document.getElementById('cf-turnstile-script')) {
        const i = setInterval(()=>{ if (window.turnstile){ clearInterval(i); resolve(); } }, 100);
        return;
      }
      const s = document.createElement('script');
      s.id = 'cf-turnstile-script';
      s.src = 'https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit';
      s.async = true; s.defer = true;
      s.onload = () => resolve();
      document.head.appendChild(s);
    });
    ensureScript().then(() => {
      if (cancelled || !turnstileRef.current) return;
      const SITEKEY = window.SM_TURNSTILE_SITEKEY || '1x00000000000000000000AA';
      window.turnstile.render(turnstileRef.current, {
        sitekey: SITEKEY,
        callback: (tk) => setToken(tk),
        'expired-callback': () => setToken(''),
        'error-callback': () => setToken(''),
      });
    });
    return () => { cancelled = true; };
  }, []);

  const validate = () => {
    const e = {};
    if (!form.first.trim()) e.first = t('contact.val.first_req');
    else if (/\d/.test(form.first)) e.first = t('contact.val.first_num');
    else if (form.first.trim().length < 2) e.first = t('contact.val.first_min');
    if (!form.last.trim()) e.last = t('contact.val.last_req');
    else if (/\d/.test(form.last)) e.last = t('contact.val.last_num');
    else if (form.last.trim().length < 2) e.last = t('contact.val.last_min');
    if (!form.email.trim()) e.email = t('contact.val.email_req');
    else if (!/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(form.email.trim())) e.email = t('contact.val.email_inv');
    if (form.phone && !/^\+?[0-9 ()-]{6,20}$/.test(form.phone.trim())) e.phone = t('contact.val.phone_inv');
    if (!form.message.trim()) e.message = t('contact.val.msg_req');
    else if (form.message.trim().length < 10) e.message = `${t('contact.val.msg_min')} (${form.message.trim().length} ${t('contact.val.msg_written')}).`;
    return e;
  };

  const setField = (f) => (ev) => {
    const val = f === 'phone' ? ev.target.value.replace(/[^0-9+ ()-]/g,'') : ev.target.value;
    setForm(prev => ({...prev, [f]: val}));
    if (fieldErrs[f]) setFieldErrs(prev => ({...prev, [f]: ''}));
  };

  const onSubmit = async (e) => {
    e.preventDefault();
    setMsg('');
    const errs = validate();
    setFieldErrs(errs);
    if (Object.keys(errs).length > 0) return;
    if (!token) { setFieldErrs({_: t('contact.err_robot')}); return; }
    setSending(true);
    try {
      const { error } = await window.supabaseClient.from('support_tickets').insert({
        first_name: form.first.trim(),
        last_name:  form.last.trim(),
        email:      form.email.trim(),
        phone:      form.phone.trim() || null,
        message:    form.message.trim(),
        turnstile_token: token,
      });
      if (error) throw error;
      setMsg(t('contact.success_pre') + form.email.trim() + '.');
      setForm({ first:'', last:'', email:'', phone:'', message:'' });
      setFieldErrs({});
      if (window.turnstile) window.turnstile.reset();
      setToken('');
    } catch (ex) {
      setFieldErrs({_: t('contact.err_send')});
    } finally { setSending(false); }
  };

  const inp = (f, full) => `sm-contact__input${full?' sm-contact__input--full':''} sm-cfield__inp${fieldErrs[f]?' sm-cfield__inp--err':''}`;

  return (
    <section className="sm-section" style={{paddingTop: 0}}>
      <div className="sm-contact">
        <div>
          <h2 className="sm-contact__title" dangerouslySetInnerHTML={{ __html: t('contact.title') }} />
          <p className="sm-contact__desc">{t('contact.desc')}</p>
          <div className="sm-contact__meta">
            <div className="sm-contact__meta-item">
              <div className="sm-contact__meta-icon"><Icon.Mail /></div>
              <a href="mailto:support@smcuba.com" style={{color:'inherit', textDecoration:'none'}}>support@smcuba.com</a>
            </div>
            <div className="sm-contact__meta-item">
              <div className="sm-contact__meta-icon"><Icon.WA /></div>
              <span>WhatsApp · +1 (305) 555-0123</span>
            </div>
            <div className="sm-contact__meta-item">
              <div className="sm-contact__meta-icon"><Icon.Clock width="16" height="16" /></div>
              <span>{t('contact.support')}</span>
            </div>
          </div>
        </div>
        <form className="sm-contact__form" onSubmit={onSubmit} noValidate>

          <div className="sm-cfield">
            <label className="sm-cfield__label">{t('contact.first')}</label>
            <input className={inp('first')} placeholder={t('contact.first_ph')} value={form.first} onChange={setField('first')} />
            {fieldErrs.first && <span className="sm-cfield__err">{fieldErrs.first}</span>}
          </div>

          <div className="sm-cfield">
            <label className="sm-cfield__label">{t('contact.last')}</label>
            <input className={inp('last')} placeholder={t('contact.last_ph')} value={form.last} onChange={setField('last')} />
            {fieldErrs.last && <span className="sm-cfield__err">{fieldErrs.last}</span>}
          </div>

          <div className="sm-cfield sm-cfield--full">
            <label className="sm-cfield__label">{t('contact.email_lbl')}</label>
            <input className={inp('email', true)} type="email" placeholder="tu@correo.com" value={form.email} onChange={setField('email')} />
            {fieldErrs.email && <span className="sm-cfield__err">{fieldErrs.email}</span>}
          </div>

          <div className="sm-cfield sm-cfield--full">
            <label className="sm-cfield__label">{t('contact.phone_lbl')} <span style={{opacity:.6, fontWeight:400}}>{t('contact.phone_opt')}</span></label>
            <input className={inp('phone', true)} placeholder="+1 (305) 555-0123" inputMode="tel" value={form.phone} onChange={setField('phone')} />
            {fieldErrs.phone && <span className="sm-cfield__err">{fieldErrs.phone}</span>}
          </div>

          <div className="sm-cfield sm-cfield--full">
            <label className="sm-cfield__label" style={{display:'flex', justifyContent:'space-between', alignItems:'center'}}>
              <span>{t('contact.msg_lbl')}</span>
              <span style={{opacity:.5, fontWeight:400, fontSize:11}}>{form.message.length}/500</span>
            </label>
            <textarea className={`sm-contact__textarea sm-cfield__inp${fieldErrs.message?' sm-cfield__inp--err':''}`}
              placeholder={t('contact.msg_ph')}
              maxLength={500}
              value={form.message}
              onChange={setField('message')}
            />
            {fieldErrs.message && <span className="sm-cfield__err">{fieldErrs.message}</span>}
          </div>

          <div ref={turnstileRef} style={{gridColumn:'1 / -1', minHeight:65}}/>

          {fieldErrs._ && <div style={{gridColumn:'1 / -1', color:'#ffcdd2', background:'rgba(198,40,40,0.3)', padding:'10px 14px', borderRadius:10, fontSize:13}}>{fieldErrs._}</div>}
          {msg && <div style={{gridColumn:'1 / -1', color:'#c8e6c9', background:'rgba(46,125,50,0.3)', padding:'10px 14px', borderRadius:10, fontSize:13}}>{msg}</div>}

          <button className="sm-contact__submit" disabled={sending}>{sending ? t('contact.sending') : <>{t('contact.submit')} <Icon.Send/></>}</button>
        </form>
      </div>
    </section>
  );
}

// ==================== REVIEWS CAROUSEL ====================
const SEED_REVIEWS = [
  { id:'s1', rating:5, text:'Increíble servicio. Recargué el teléfono de mi mamá en Cuba y llegó en menos de 30 segundos. Sin complicaciones para nada.', author:'María G.', tag:'🇺🇸 Miami, FL' },
  { id:'s2', rating:5, text:'Llevo más de un año usando SMCUBA y nunca me ha fallado. El proceso es rapidísimo y el soporte responde enseguida.', author:'Roberto A.', tag:'🇪🇸 Madrid' },
  { id:'s3', rating:5, text:'Lo que más me gusta es la transparencia. El precio que ves es el que pagas, sin sorpresas. 100% recomendado.', author:'Yanira F.', tag:'🇲🇽 Ciudad de México' },
  { id:'s4', rating:5, text:'Perfecta para mandar recargas a la familia. Simple, rápida y confiable. Mi familia la recibe enseguida.', author:'Carlos P.', tag:'🇨🇦 Toronto' },
  { id:'s5', rating:5, text:'Servicio excelente, muy fácil de usar y las recargas llegan al instante. Lo recomiendo a todos mis amigos.', author:'Laura M.', tag:'🇮🇹 Roma' },
  { id:'s6', rating:5, text:'Primera vez que uso el servicio y quedé encantada. El teléfono de mi abuela recibió la recarga en segundos. ¡Gracias!', author:'Dianelys R.', tag:'🇩🇪 Berlín' },
];

// Gradient palette for avatars — cycles by index
const AVATAR_GRADIENTS = [
  'linear-gradient(135deg,#667eea,#764ba2)',
  'linear-gradient(135deg,#f093fb,#f5576c)',
  'linear-gradient(135deg,#4facfe,#00f2fe)',
  'linear-gradient(135deg,#43e97b,#38f9d7)',
  'linear-gradient(135deg,#fa709a,#fee140)',
  'linear-gradient(135deg,#a18cd1,#fbc2eb)',
];

function ReviewsCarousel() {
  const [reviews, setReviews] = useState(SEED_REVIEWS);
  const [page, setPage]       = useState(0);
  const [fading, setFading]   = useState(false);
  const timerRef              = useRef(null);
  const PER_PAGE              = 3;
  const { t } = useLang();

  // Load approved reviews from DB (public/anon access)
  useEffect(() => {
    const sb = window.supabaseClient;
    if (!sb) return;
    sb.from('reviews').select('id,rating,text,created_at')
      .eq('status','approved').order('created_at',{ascending:false}).limit(15)
      .then(({ data }) => {
        if (!data || !data.length) return;
        const dbRows = data.map((r, i) => ({
          id:     r.id,
          rating: r.rating,
          text:   r.text,
          author: t('rev.verified'),
          tag:    t('rev.purchase'),
        }));
        setReviews([...dbRows, ...SEED_REVIEWS]);
      }).catch(() => {});
  }, []);

  const pages = Math.max(1, Math.ceil(reviews.length / PER_PAGE));

  const goTo = (n, resetTimer = true) => {
    const next = ((n % pages) + pages) % pages;
    setFading(true);
    setTimeout(() => { setPage(next); setFading(false); }, 280);
    if (resetTimer) {
      clearInterval(timerRef.current);
      timerRef.current = setInterval(advance, 5000);
    }
  };

  const advance = () => goTo(page + 1, false);

  useEffect(() => {
    timerRef.current = setInterval(() => {
      setPage(p => {
        const next = (p + 1) % pages;
        setFading(true);
        setTimeout(() => setFading(false), 280);
        return next;
      });
    }, 5000);
    return () => clearInterval(timerRef.current);
  }, [pages]);

  const visible = Array.from({ length: PER_PAGE }, (_, i) =>
    reviews[(page * PER_PAGE + i) % reviews.length]
  );

  return (
    <section className="sm-section" style={{ background:'var(--cream-50)', paddingBottom:80 }}>
      <div className="sm-section__inner" style={{ maxWidth:1100, margin:'0 auto' }}>

        {/* Header */}
        <div style={{ textAlign:'center', marginBottom:48 }}>
          <div className="sm-section__eyebrow" style={{ justifyContent:'center', display:'flex' }}>
            {t('rev.eyebrow')}
          </div>
          <h2 className="sm-section__title" dangerouslySetInnerHTML={{ __html: t('rev.title') }} />
          <p className="sm-section__sub">{t('rev.sub')}</p>
        </div>

        {/* Cards */}
        <div className="sm-reviews-grid" style={{
          display:'grid', gridTemplateColumns:'repeat(3,1fr)', gap:20,
          opacity: fading ? 0 : 1,
          transform: fading ? 'translateY(6px)' : 'translateY(0)',
          transition:'opacity .28s ease, transform .28s ease',
        }}>
          {visible.map((r, i) => (
            <div key={(r?.id || i) + '-' + page} style={{
              background:'#fff', borderRadius:22, padding:'28px 24px 24px',
              boxShadow:'0 2px 20px rgba(0,0,0,.06)', border:'1px solid var(--cream-200)',
              display:'flex', flexDirection:'column', gap:16, position:'relative',
            }}>
              {/* Open-quote accent */}
              <div style={{
                position:'absolute', top:18, right:22,
                fontSize:64, lineHeight:1, color:'var(--cream-200)',
                fontFamily:'Georgia,serif', fontWeight:900, userSelect:'none',
              }}>"</div>

              {/* Stars */}
              <div style={{ color:'#f59e0b', fontSize:17, letterSpacing:3 }}>
                {'★'.repeat(r?.rating || 5)}
              </div>

              {/* Text */}
              <p style={{
                fontSize:14, lineHeight:1.7, color:'var(--ink-700)',
                margin:0, flex:1, position:'relative', zIndex:1,
              }}>
                {r?.text}
              </p>

              {/* Author row */}
              <div style={{
                display:'flex', alignItems:'center', gap:12,
                borderTop:'1px solid var(--cream-100)', paddingTop:16,
              }}>
                <div style={{
                  width:42, height:42, borderRadius:'50%', flexShrink:0,
                  background: AVATAR_GRADIENTS[i % AVATAR_GRADIENTS.length],
                  display:'flex', alignItems:'center', justifyContent:'center',
                  color:'#fff', fontWeight:800, fontSize:16,
                }}>
                  {r?.author?.[0]?.toUpperCase() || '✔'}
                </div>
                <div>
                  <div style={{ fontWeight:700, fontSize:14, color:'var(--ink-900)' }}>
                    {r?.author}
                  </div>
                  <div style={{ fontSize:12, color:'var(--ink-400)', marginTop:2 }}>
                    {r?.tag}
                  </div>
                </div>
              </div>
            </div>
          ))}
        </div>

        {/* Controls */}
        <div style={{ display:'flex', alignItems:'center', justifyContent:'center', gap:14, marginTop:36 }}>
          {/* Prev */}
          <button
            onClick={() => goTo(page - 1)}
            style={{
              width:38, height:38, borderRadius:'50%', border:'1.5px solid var(--cream-200)',
              background:'#fff', cursor:'pointer', fontSize:20, lineHeight:'36px',
              color:'var(--ink-500)', transition:'all .2s', display:'flex',
              alignItems:'center', justifyContent:'center',
            }}
            onMouseEnter={e => { e.currentTarget.style.borderColor='var(--brand-600)'; e.currentTarget.style.color='var(--brand-600)'; }}
            onMouseLeave={e => { e.currentTarget.style.borderColor='var(--cream-200)'; e.currentTarget.style.color='var(--ink-500)'; }}
          >‹</button>

          {/* Dots */}
          {Array.from({ length: pages }).map((_, i) => (
            <div
              key={i}
              onClick={() => goTo(i)}
              style={{
                height:8, borderRadius:4, cursor:'pointer',
                width: i === page ? 28 : 8,
                background: i === page ? 'var(--brand-600)' : 'var(--cream-200)',
                transition:'all .35s cubic-bezier(.22,1,.36,1)',
              }}
            />
          ))}

          {/* Next */}
          <button
            onClick={() => goTo(page + 1)}
            style={{
              width:38, height:38, borderRadius:'50%', border:'1.5px solid var(--cream-200)',
              background:'#fff', cursor:'pointer', fontSize:20, lineHeight:'36px',
              color:'var(--ink-500)', transition:'all .2s', display:'flex',
              alignItems:'center', justifyContent:'center',
            }}
            onMouseEnter={e => { e.currentTarget.style.borderColor='var(--brand-600)'; e.currentTarget.style.color='var(--brand-600)'; }}
            onMouseLeave={e => { e.currentTarget.style.borderColor='var(--cream-200)'; e.currentTarget.style.color='var(--ink-500)'; }}
          >›</button>
        </div>

      </div>
    </section>
  );
}

// ==================== FOOTER ====================
function Footer() {
  const { t } = useLang();
  return (
    <footer className="sm-footer">
      <div className="sm-footer__inner">
        <div className="sm-footer__brand">
          <div className="sm-footer__brand-logo" style={{display:'flex', alignItems:'center'}}>
            <img src="logo.svg" alt="SMCUBA" style={{height:48, width:'auto', filter:'brightness(0) invert(1)'}}/>
          </div>
          <p className="sm-footer__brand-desc">{t('footer.desc')}</p>
          <div className="sm-footer__social">
            <a href="https://www.facebook.com/smcubaoficial/" target="_blank" rel="noopener noreferrer" aria-label="Facebook"><Icon.FB /></a>
            <a href="https://www.instagram.com/smcubaoficial/" target="_blank" rel="noopener noreferrer" aria-label="Instagram"><Icon.IG /></a>
            <a href="https://wa.me/13055550123" target="_blank" rel="noopener noreferrer" aria-label="WhatsApp"><Icon.WA /></a>
          </div>
        </div>
        <div className="sm-footer__col">
          <h4>{t('footer.servicios')}</h4>
          <ul>
            <li><a href="index.html#recargas" onClick={navScroll('recargas','movil')}>{t('footer.movil')}</a></li>
            <li><a href="index.html#recargas" onClick={navScroll('recargas','nauta')}>{t('footer.nauta')}</a></li>
            <li><a href="index.html#recargas" onClick={navScroll('recargas','nauta')}>{t('footer.nauta_hogar')}</a></li>
            <li><a href="index.html#promociones" onClick={navScroll('promociones')}>{t('footer.promos')}</a></li>
          </ul>
        </div>
        <div className="sm-footer__col">
          <h4>{t('footer.empresa')}</h4>
          <ul>
            <li><a href="about-us.html">{t('footer.quienes')}</a></li>
            <li><a href="index.html#faq" onClick={navScroll('faq')}>{t('footer.faq')}</a></li>
            <li><a href="index.html#contacto" onClick={navScroll('contacto')}>{t('footer.contacto')}</a></li>
          </ul>
        </div>
        <div className="sm-footer__col">
          <h4>{t('footer.legal')}</h4>
          <ul>
            <li><a href="terms.html">{t('footer.terms')}</a></li>
            <li><a href="privacy.html">{t('footer.privacy')}</a></li>
          </ul>
        </div>
      </div>
      <div className="sm-footer__bottom">
        <span>{t('footer.copy')}</span>
        <div className="sm-footer__payments">
          <span style={{fontSize:11, color:'var(--ink-300)', marginRight:4}}>{t('footer.payments_label')}</span>
          <span className="sm-footer__payment-chip">VISA</span>
          <span className="sm-footer__payment-chip">MASTERCARD</span>
          <span className="sm-footer__payment-chip">PAYPAL</span>
          <span className="sm-footer__payment-chip">AMEX</span>
        </div>
      </div>
    </footer>
  );
}

// ==================== PAGES ====================
function LandingDesktop({ variant = 'flash' }) {
  return (
    <div className="sm-app">
      <Nav />
      <Hero variant={variant} />
      <TrustBar />
      <HowItWorks />
      <Promos />
      <ReviewsCarousel />
      <FAQ />
      <Contact />
      <Footer />
    </div>
  );
}

function LandingMobile() {
  return (
    <div className="sm-app sm-mobile">
      <Nav mobile />
      <Hero variant="flash" mobile />
      <TrustBar />
      <HowItWorks />
      <Promos />
      <ReviewsCarousel />
      <FAQ />
      <Contact />
      <Footer />
    </div>
  );
}

Object.assign(window, { LandingDesktop, LandingMobile, OFFERS, Nav, Logo, Icon, CubaFlag, CubaFlagSimple, useLang });
