// App principal + Tweaks

const DEFAULTS = /*EDITMODE-BEGIN*/{
  "heroVariant": "editorial",
  "primaryHue": 210,
  "showAnnouncement": true,
  "forceSpecial": "auto",
  "specialPosition": "above"
}/*EDITMODE-END*/;

function App() {
  const [t, setTweak] = useTweaks(DEFAULTS);
  useReveal();

  return (
    <AuthProvider>
      <AppShell t={t} setTweak={setTweak} />
    </AuthProvider>
  );
}

function AppShell({ t, setTweak }) {
  const auth = useAuth();
  const [apiSpecial, setApiSpecial] = useState(null);
  const [configLoaded, setConfigLoaded] = useState(false);
  const [siteConfig, setSiteConfig] = useState(() => window.SITE_CONFIG || {
    visible_categories: ['Brincos', 'Colares', 'Pulseiras', 'Chokers'],
    affiliates_enabled: true,
    testimonials: null,
  });

  useEffect(() => {
    // Importante: TODOS os setState têm que rodar no mesmo microtask
    // pra React 18 batchar e gerar um único render. setConfigLoaded em
    // .finally vira microtask separado → 2 renders → flash do padrão.
    fetch('/api/config')
      .then(r => r.ok ? r.json() : null)
      .then(data => {
        if (data?.banner_configs) window.CAPAS_CONFIG = data.banner_configs;
        if (data?.active_special) setApiSpecial(data.active_special);
        if (data) {
          const cfg = {
            visible_categories: Array.isArray(data.visible_categories) && data.visible_categories.length
              ? data.visible_categories
              : ['Brincos', 'Colares', 'Pulseiras', 'Chokers'],
            affiliates_enabled: data.affiliates_enabled !== false,
            testimonials: Array.isArray(data.testimonials) ? data.testimonials : null,
            hero:  data.hero  || null,
            promo: data.promo || null,
          };
          window.SITE_CONFIG = cfg;
          setSiteConfig(cfg);
          window.dispatchEvent(new CustomEvent('site-config-loaded', { detail: cfg }));
        }
        setConfigLoaded(true);
      })
      .catch(() => setConfigLoaded(true));
  }, []);

  // Resolve tema ativo: forceSpecial (dev) > apiSpecial (DB) > 'padrao' (default).
  // Importante: só renderiza banner depois que config carregou — evita flash do
  // tema padrão piscando antes do tema correto entrar em cena.
  const special = !configLoaded && t.forceSpecial === 'auto'
    ? null
    : (t.forceSpecial === 'auto'
        ? (apiSpecial || 'padrao')
        : (t.forceSpecial === 'none' ? null : t.forceSpecial));

  const capaTheme = special ? window.CAPAS?.[special] : null;
  const SpecialBanner = capaTheme?.Banner || null;
  const specialAccent = capaTheme?.accent;
  const specialGridLabel = capaTheme?.gridLabel;
  const specialGridTitle = capaTheme?.gridTitle;

  return (
    <CartProvider>
      <Nav
        onLogin={()=> auth.user ? location.href = '/account/' : auth.openLogin()}
        announcement={special || 'default'}
        visibleCategories={siteConfig.visible_categories}
      />
      {SpecialBanner && t.specialPosition === 'above' && <SpecialBanner />}
      {SpecialBanner && t.specialPosition === 'above' && special && (
        <SpecialProductsGrid
          special={special}
          accent={specialAccent}
          sectionLabel={specialGridLabel}
          sectionTitle={specialGridTitle}
        />
      )}
      <Hero variant={t.heroVariant} />
      {SpecialBanner && t.specialPosition === 'below' && <SpecialBanner />}
      {SpecialBanner && t.specialPosition === 'below' && special && (
        <SpecialProductsGrid
          special={special}
          accent={specialAccent}
          sectionLabel={specialGridLabel}
          sectionTitle={specialGridTitle}
        />
      )}
      <ProductsSection visibleCategories={siteConfig.visible_categories} />
      <Benefits />
      <Testimonials testimonials={siteConfig.testimonials} />
      <FaqSection />
      <ContactSection />
      <FinalCTA />
      <Footer />

      <WhatsAppFab />
      <ThemeToggleFab />
      <LoginModal open={auth.modalOpen} onClose={auth.closeLogin} message={auth.modalMsg} />

      <TweaksPanel title="Tweaks">
        <TweakSection label="Especiais Sazonais">
          <TweakRadio
            label="Forçar tema"
            value={t.forceSpecial}
            onChange={(v)=> setTweak('forceSpecial', v)}
            options={[
              { value: 'auto',      label: 'Auto (API)' },
              { value: 'none',      label: 'Nenhum' },
              { value: 'namorados', label: '💕 Namorados' },
              { value: 'maes',      label: '👩 Dia das Mães' },
            ]}
          />
          <TweakRadio
            label="Posição"
            value={t.specialPosition}
            onChange={(v)=> setTweak('specialPosition', v)}
            options={[
              { value: 'above', label: 'Acima do hero' },
              { value: 'below', label: 'Abaixo do hero' },
            ]}
          />
        </TweakSection>
        <TweakSection label="Hero">
          <TweakRadio
            label="Variação"
            value={t.heroVariant}
            onChange={(v)=> setTweak('heroVariant', v)}
            options={[
              { value: 'editorial', label: 'Editorial' },
              { value: 'gradient',  label: 'Gradiente' },
              { value: 'showcase',  label: 'Vitrine' },
            ]}
          />
        </TweakSection>
      </TweaksPanel>

      <ResponsiveCSS />
    </CartProvider>
  );
}

function ResponsiveCSS() {
  // injetar CSS responsivo via style — funciona melhor que media queries inline
  return (
    <style>{`
      @media (hover: hover) and (pointer: fine) {
        .card-actions-mobile { display: none !important; }
      }

      /* ===========================================================
         IDENTIDADE LUAR — assinatura visual da marca
         =========================================================== */
      /* Glow lunar suave usado em seções premium */
      .lunar-glow {
        position: absolute; pointer-events: none;
        border-radius: 50%;
        background: radial-gradient(circle at 35% 35%,
          rgba(255,255,255,0.55) 0%,
          rgba(212,175,106,0.18) 35%,
          rgba(103,232,249,0.08) 65%,
          transparent 75%);
        filter: blur(40px);
        opacity: 0.9;
        mix-blend-mode: screen;
      }
      [data-theme="dark"] .lunar-glow {
        background: radial-gradient(circle at 35% 35%,
          rgba(212,175,106,0.18) 0%,
          rgba(103,232,249,0.12) 45%,
          transparent 75%);
        opacity: 0.7;
      }

      /* Brilho prateado em CTAs premium (shimmer ao passar mouse) */
      .silver-shimmer { position: relative; overflow: hidden; isolation: isolate; }
      .silver-shimmer::after {
        content: '';
        position: absolute; top: 0; left: -150%;
        width: 70%; height: 100%;
        background: linear-gradient(110deg,
          transparent 0%,
          rgba(255,255,255,0.0) 30%,
          rgba(255,255,255,0.35) 50%,
          rgba(255,255,255,0.0) 70%,
          transparent 100%);
        transform: skewX(-18deg);
        transition: left .7s cubic-bezier(.2,.7,.2,1);
        pointer-events: none;
        z-index: 0;
      }
      .silver-shimmer:hover::after { left: 130%; }

      /* Crescente decorativo SVG (use como background-image) */
      .crescent-deco {
        position: absolute; pointer-events: none;
        opacity: 0.08;
      }
      [data-theme="dark"] .crescent-deco { opacity: 0.18; }

      /* Reveal refinado com stagger via attribute delay */
      .reveal[data-delay="1"].in { animation-delay: 0.05s; }
      .reveal[data-delay="2"].in { animation-delay: 0.12s; }
      .reveal[data-delay="3"].in { animation-delay: 0.19s; }
      .reveal[data-delay="4"].in { animation-delay: 0.26s; }
      .reveal[data-delay="5"].in { animation-delay: 0.33s; }

      /* Hover lift universal para cards (.product-card, .related-card, etc) */
      @media (hover: hover) {
        .product-card, .related-card { will-change: transform; }
      }

      /* Foco acessível premium em inputs/botões */
      :focus-visible {
        outline: 2px solid var(--accent, #d4af6a);
        outline-offset: 3px;
        border-radius: 4px;
      }
      [data-theme="dark"] :focus-visible {
        outline-color: #d4af6a;
      }

      /* Selection brand colors */
      ::selection { background: rgba(212,175,106,0.35); color: #0a1f3d; }
      [data-theme="dark"] ::selection { background: rgba(212,175,106,0.45); color: #ecfeff; }

      /* Suavidade global de transições */
      a, button, input, select, textarea, .product-card, .related-card {
        transition-property: color, background-color, border-color, box-shadow, transform, opacity;
        transition-duration: .2s;
        transition-timing-function: cubic-bezier(.2,.7,.2,1);
      }
      /* Mas não interfere onde já tem transition específico longo */
      .product-card { transition-duration: .35s; }

      /* ===== TABLET (601 – 900px) ===== */
      @media (min-width: 601px) and (max-width: 900px) {
        .container { width: 94vw; }
        .four-up { grid-template-columns: repeat(2, 1fr) !important; }
        .three-up { grid-template-columns: repeat(2, 1fr) !important; }
        .hero-3up { grid-template-columns: repeat(3, 1fr) !important; }
      }

      /* ===== MOBILE + small tablet (≤ 900px) ===== */
      @media (max-width: 900px) {
        .container { width: 94vw; }
        .hero-grid, .two-up, .footer-grid { grid-template-columns: 1fr !important; gap: 40px !important; }
        .four-up { grid-template-columns: repeat(2, 1fr) !important; }
        .three-up { grid-template-columns: 1fr !important; }
        .hero-3up { grid-template-columns: 1fr !important; }
        .login-grid { grid-template-columns: 1fr !important; }
        .nav-links { display: none !important; }
        .testi-grid { grid-template-columns: 1fr !important; gap: 14px !important; }
        section { padding-top: 70px !important; padding-bottom: 70px !important; }
      }
      @media (min-width: 901px) {
        .only-mobile { display: none !important; }
      }
      /* ===== MOBILE only (≤ 600px) ===== */
      @media (max-width: 600px) {
        .four-up { grid-template-columns: repeat(2, 1fr) !important; gap: 14px !important; }
        section { padding-top: 48px !important; padding-bottom: 48px !important; }
        .testi-card { padding: 20px !important; }
        h1.serif, h2.serif { letter-spacing: -0.02em !important; }
        /* Tighter eyebrows */
        .eyebrow { font-size: 10px !important; letter-spacing: 0.14em !important; }
        /* CTAs grandes (thumb zone): mín 48px */
        .btn { min-height: 48px !important; }
        .hero-grid .btn, .two-up .btn { font-size: 14px !important; }
        /* Hero: stack vertical com mais respiro */
        .hero-grid { gap: 32px !important; }
        .hero-collage { max-width: 460px; margin: 0 auto; }
        /* Product cards: padding mais apertado em mobile */
        .product-card { border-radius: 16px !important; }
        .product-card > div:last-child { padding: 14px 14px 16px !important; }
        /* Theme toggle smaller on mobile */
        .theme-fab { bottom: 90px !important; width: 42px !important; height: 42px !important; }
        /* Formulário de contato: 2 colunas → 1 coluna em mobile */
        .contact-2col { grid-template-columns: 1fr !important; }
        /* WhatsApp FAB: sobe pra não colidir com chrome do browser, mantém tamanho fixo */
        .whatsapp-fab {
          bottom: calc(80px + env(safe-area-inset-bottom, 0px)) !important;
          width: 52px !important;
          height: 52px !important;
          padding: 0 !important;
        }
        /* Esconde label de hover no WhatsApp em mobile — não tem hover em touch */
        .wa-label { display: none !important; }
        /* Modal login: esconde painel decorativo pra dar espaço ao form */
        .login-modal-visual { display: none !important; }
        /* Login grid: uma coluna com altura gerenciada */
        .login-grid {
          grid-template-columns: 1fr !important;
          max-height: calc(100dvh - 40px) !important;
          overflow-y: auto !important;
        }
      }
      /* ===== EXTRA SMALL (≤ 400px) ===== */
      @media (max-width: 400px) {
        .four-up { grid-template-columns: 1fr !important; }
        h1.serif { font-size: clamp(32px, 9vw, 44px) !important; }
      }

      /* ===== CTA buttons em cards ===== */
      .cta-row {
        display: flex !important;
        gap: 8px !important;
        align-items: stretch !important;
      }
      .cta-row > button,
      .cta-row > a {
        flex: 1 1 0 !important;
        min-width: 0 !important;
        white-space: nowrap !important;
      }
      /* Em cards muito apertados (2-col mobile entre 480-560px ou
         single-col abaixo de 360px), stack vertical pra não cortar texto */
      @media (max-width: 360px) {
        .cta-row { flex-direction: column !important; }
        .cta-row > button, .cta-row > a { width: 100% !important; }
      }
      @media (min-width: 401px) and (max-width: 520px) {
        /* 2-col grid, cards ~170px wide: reduz padding/icon pra caber */
        .cta-row > .cta-sacola svg { display: none !important; }
        .cta-row > button, .cta-row > a {
          font-size: 11px !important;
          padding: 0 6px !important;
        }
      }

      /* ===== LANDSCAPE PHONES (altura curta ≤ 480px) ===== */
      @media (max-height: 480px) and (max-width: 900px) {
        /* Esconde painel decorativo do login em landscape também */
        .login-modal-visual { display: none !important; }
        .login-grid {
          grid-template-columns: 1fr !important;
          max-height: calc(100dvh - 24px) !important;
          overflow-y: auto !important;
        }
        /* WhatsApp sobe pra não colidir com chrome em landscape */
        .whatsapp-fab { bottom: 16px !important; }
        .theme-fab    { bottom: 16px !important; }
      }

      /* ===== Dark mode — hero editorial ===== */
      [data-theme="dark"] .hero-editorial {
        background: radial-gradient(ellipse at top, #0a1622 0%, #0f1a26 60%) !important;
      }
      [data-theme="dark"] .hero-editorial .hero-title {
        color: #ecfeff !important;
      }
      [data-theme="dark"] .hero-editorial .hero-lede {
        color: #b8d6e6 !important;
      }
      [data-theme="dark"] .hero-editorial .hero-eyebrow {
        color: #d4af6a !important;
      }
      [data-theme="dark"] .hero-editorial .hero-badge {
        background: #14202d !important;
        border-color: rgba(212,175,106,0.4) !important;
        color: #d4af6a !important;
        box-shadow: 0 8px 24px -8px rgba(0,0,0,0.55) !important;
      }
      [data-theme="dark"] .hero-editorial .hero-cta-ghost {
        background: #14202d !important;
        color: #ecfeff !important;
        border-color: #2a4865 !important;
      }
      [data-theme="dark"] .hero-editorial .hero-cta-ghost:hover {
        background: #1a2540 !important;
        border-color: #d4af6a !important;
      }

      /* ===== Dark mode — product cards & special cards ===== */
      [data-theme="dark"] .product-card,
      [data-theme="dark"] .hero-editorial + section .product-card {
        background: #14202d !important;
        border-color: #2a4865 !important;
      }

      /* ===== Dark mode ===== */
      [data-theme="dark"] {
        /* Semantic tokens — dark */
        --bg:            #0a1622;
        --bg-elev:       #0f1a26;
        --bg-surface:    #14202d;
        --fg:            #ecfeff;
        --fg-muted:      #b8d6e6;
        --fg-subtle:     #7a99ab;
        --border:        #2a4865;
        --border-strong: #406a8a;
        --card:          #14202d;
        --card-fg:       #ecfeff;
        --primary:       #22d3ee;
        --primary-fg:    #0a1622;
        --accent:        #d4af6a;
        --accent-fg:     #ecfeff;
        --danger:        #ef4444;
        --success:       #10b981;
        --warning:       #f59e0b;
        --overlay:       rgba(0,0,0,0.7);

        /* Compat com tokens legados */
        --white: #14202d;
        --cream: #0f1a26;
        --blue-50: #1a2f44;
        --blue-100: #234260;
        --blue-200: #2e5275;
        --blue-300: #406a8a;
        --line: #2a4865;
        --ink: #ecfeff;
        --ink-2: #b8d6e6;
        --ink-3: #7a99ab;
        --navy: #ecfeff;
        --navy-2: #b8d6e6;
        --silver: #2a4865;
        --silver-soft: #1a2f44;
      }
      html, body { transition: background-color .3s ease, color .3s ease; }

      /* ===== Dark mode — overrides amplos ===== */
      [data-theme="dark"] section[style*="background: var(--cream)"],
      [data-theme="dark"] section[style*="background:var(--cream)"],
      [data-theme="dark"] section[style*="background: white"],
      [data-theme="dark"] section[style*="background:white"],
      [data-theme="dark"] section[style*="background: #ffffff"] {
        background: var(--bg) !important;
      }
      [data-theme="dark"] section[style*="background: linear-gradient(180deg, var(--blue-50)"] {
        background: linear-gradient(180deg, #0f1a26 0%, #0a1622 100%) !important;
      }

      /* Inputs/textareas/selects universal */
      [data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
      [data-theme="dark"] select,
      [data-theme="dark"] textarea {
        background: #0f1a26 !important;
        color: #ecfeff !important;
        border-color: #2a4865 !important;
      }
      [data-theme="dark"] input::placeholder,
      [data-theme="dark"] textarea::placeholder { color: #7a99ab !important; }
      [data-theme="dark"] select option { background: #14202d; color: #ecfeff; }

      /* Buttons hardcoded white */
      [data-theme="dark"] button[style*="background: white"],
      [data-theme="dark"] button[style*="background:white"] {
        background: #14202d !important;
        color: #ecfeff !important;
      }

      /* Links genéricos */
      [data-theme="dark"] a[style*="color: var(--blue-700)"],
      [data-theme="dark"] a[style*="color:var(--blue-700)"] {
        color: #67e8f9 !important;
      }
      [data-theme="dark"] body,
      [data-theme="dark"] html {
        background: #0a1622 !important;
        color: var(--ink);
      }
      /* Catch inline white & light backgrounds */
      [data-theme="dark"] [style*="background: white"],
      [data-theme="dark"] [style*="background:white"],
      [data-theme="dark"] [style*="background: '#fff'"],
      [data-theme="dark"] [style*="background: rgba(255, 255, 255"],
      [data-theme="dark"] [style*="background: rgba(255,255,255"],
      [data-theme="dark"] [style*="background: var(--cream)"],
      [data-theme="dark"] [style*="background:var(--cream)"],
      [data-theme="dark"] [style*="background: var(--white)"],
      [data-theme="dark"] [style*="background: var(--blue-50)"],
      [data-theme="dark"] [style*="background: #f0f9ff"],
      [data-theme="dark"] [style*="background: #fff"],
      [data-theme="dark"] [style*="background-color: white"] {
        background: #14202d !important;
      }
      /* Catch inline white card backgrounds with combined gradients (Valentine's etc) */
      [data-theme="dark"] [style*="linear-gradient(180deg, #eaf2fb"],
      [data-theme="dark"] [style*="linear-gradient(180deg, var(--cream)"] {
        background: linear-gradient(180deg, #0a1622 0%, #0f1a26 100%) !important;
      }
      /* Light text on dark surfaces */
      [data-theme="dark"] [style*="color: var(--ink)"],
      [data-theme="dark"] [style*="color: var(--blue-900)"],
      [data-theme="dark"] [style*="color: var(--blue-800)"],
      [data-theme="dark"] [style*="color:var(--ink)"] {
        color: #ecfeff !important;
      }
      [data-theme="dark"] [style*="color: var(--ink-2)"] { color: #b8d6e6 !important; }
      [data-theme="dark"] [style*="color: var(--ink-3)"] { color: #7a99ab !important; }
      [data-theme="dark"] [style*="border: 1px solid var(--line)"],
      [data-theme="dark"] [style*="border-bottom: 1px solid var(--line)"],
      [data-theme="dark"] [style*="border-top: 1px solid var(--line)"],
      [data-theme="dark"] [style*="border-right: 1px solid var(--line)"],
      [data-theme="dark"] [style*="border-left: 1px solid var(--line)"] {
        border-color: #2a4865 !important;
      }
      /* Soften nav sticky bg in dark */
      [data-theme="dark"] header[style*="rgba(255,255,255,0.85)"],
      [data-theme="dark"] header[style*="background: rgba(255, 255, 255, 0.85)"] {
        background: rgba(20,32,45,0.85) !important;
        backdrop-filter: saturate(160%) blur(14px);
      }
      [data-theme="dark"] header[style*="background: white"] {
        background: rgba(20,32,45,0.98) !important;
      }
      /* Soften shadows */
      [data-theme="dark"] [style*="box-shadow: 0 30px 60px -20px"],
      [data-theme="dark"] [style*="box-shadow: 0 20px 50px"],
      [data-theme="dark"] [style*="box-shadow: 0 16px 40px"],
      [data-theme="dark"] [style*="box-shadow: 0 14px 32px"] {
        box-shadow: 0 30px 60px -20px rgba(0,0,0,0.55) !important;
      }
      /* Inputs */
      [data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]),
      [data-theme="dark"] select,
      [data-theme="dark"] textarea {
        background: #14202d !important;
        color: #ecfeff !important;
        border-color: #2a4865 !important;
      }
      [data-theme="dark"] input::placeholder,
      [data-theme="dark"] textarea::placeholder { color: #7a99ab !important; }
      /* Selection */
      [data-theme="dark"] ::selection { background: var(--blue-700); color: white; }

      /* Theme toggle FAB */
      .theme-fab {
        position: fixed; bottom: 24px; left: 24px;
        z-index: 70;
        width: 48px; height: 48px; border-radius: 50%;
        background: white;
        color: var(--ink);
        border: 1px solid var(--line);
        display: inline-flex; align-items: center; justify-content: center;
        cursor: pointer;
        box-shadow: 0 12px 28px -8px rgba(8,51,68,0.25);
        transition: transform .2s ease, background .2s ease;
      }
      .theme-fab:hover { transform: translateY(-2px) rotate(-12deg); }
      [data-theme="dark"] .theme-fab {
        background: #14202d !important;
        border-color: #2a4865 !important;
        color: #fbbf24;
      }
      .theme-fab .sun { display: none; }
      .theme-fab .moon { display: block; }
      [data-theme="dark"] .theme-fab .sun { display: block; }
      [data-theme="dark"] .theme-fab .moon { display: none; }

      /* ===== Dia dos Namorados dark mode polish ===== */
      [data-theme="dark"] #namorados {
        background: linear-gradient(180deg, #0a1622 0%, #14202d 55%, #1f1622 100%) !important;
        border-bottom-color: #2a4865 !important;
      }
      /* Tone down decorative watercolor splashes on dark */
      [data-theme="dark"] #namorados > svg[style*="position: absolute"],
      [data-theme="dark"] #namorados > svg[style*="position:absolute"] {
        opacity: 0.3 !important;
        mix-blend-mode: screen;
      }
      /* Bracelet placeholder cream background */
      [data-theme="dark"] [style*="background: #f6f2ec"],
      [data-theme="dark"] [style*="background:#f6f2ec"] {
        background: #1a2540 !important;
      }
      /* The white halo radial behind featured products */
      [data-theme="dark"] [style*="radial-gradient(circle at 50% 50%, rgba(255,255,255,0.9)"] {
        background: radial-gradient(circle at 50% 50%, rgba(103,232,249,0.18) 0%, rgba(10,22,34,0) 70%) !important;
        opacity: 0.6;
      }
      /* The moon accent dot */
      [data-theme="dark"] [style*="radial-gradient(circle at 35% 30%, #ffffff, #c7dbf3 70%"] {
        background: radial-gradient(circle at 35% 30%, #67e8f9, #2e5275 70%, #14202d 100%) !important;
        color: #67e8f9 !important;
      }
      /* Countdown card */
      [data-theme="dark"] [style*="background: rgba(255,255,255,0.7)"][style*="backdropFilter"],
      [data-theme="dark"] [style*="background: rgba(255, 255, 255, 0.7)"] {
        background: rgba(20,32,45,0.7) !important;
        border-color: rgba(103,232,249,0.18) !important;
      }
      /* "Dia dos Namorados · 12.06" pill keeps coral text — make pill dark */
      [data-theme="dark"] #namorados [style*="background: white"][style*="border: 1px solid #fbe1e7"] {
        background: #1a1118 !important;
        border-color: #6b2a3a !important;
      }
      /* "Para presentear seu amor" heading — comes from var(--blue-900) which already maps */
      /* Hand-drawn blue hearts get muted in dark */
      [data-theme="dark"] #namorados svg[viewBox="0 0 100 100"] {
        opacity: 0.85;
      }
      /* Card surface for bracelet items in featured collage + grid */
      [data-theme="dark"] #namorados [style*="background: white"][style*="border-radius: 22"],
      [data-theme="dark"] #namorados [style*="background: white"][style*="border-radius: 18"] {
        background: #14202d !important;
        border-color: #2a4865 !important;
      }
      /* Dashed border separator in cards */
      [data-theme="dark"] #namorados [style*="border-top: 1px dashed var(--line)"] {
        border-color: #2a4865 !important;
      }
      /* "Namorados" pill on grid cards — keep white, just adjust shadow */
      [data-theme="dark"] #namorados [style*="background: white"][style*="color: '#e25c7c'"],
      [data-theme="dark"] #namorados [style*="background: white"][style*="color:#e25c7c"] {
        background: #1f1014 !important;
        color: #fda4af !important;
      }
      /* Strip / announcement bar coral-to-blue gradient — keep but slightly darker */
      [data-theme="dark"] [style*="linear-gradient(90deg, #e25c7c 0%, #c8466b 50%, #2d5b8a 100%)"] {
        background: linear-gradient(90deg, #be1d3f 0%, #8e2a47 50%, #1a3b6b 100%) !important;
      }
    `}</style>
  );
}

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

// ---- Theme toggle FAB ----
function ThemeToggleFab() {
  const [theme, setTheme] = useState(() => {
    try { return localStorage.getItem('lua_theme') || 'light'; } catch(e) { return 'light'; }
  });
  useEffect(() => {
    document.documentElement.dataset.theme = theme;
    try { localStorage.setItem('lua_theme', theme); } catch(e){}
  }, [theme]);
  return (
    <button
      className="theme-fab"
      aria-label={theme === 'dark' ? 'Modo claro' : 'Modo escuro'}
      onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}
    >
      <svg className="moon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
        <path d="M20 14A8 8 0 1 1 10 4a6 6 0 0 0 10 10z"/>
      </svg>
      <svg className="sun" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
        <circle cx="12" cy="12" r="4"/>
        <path d="M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M4.93 19.07l1.41-1.41M17.66 6.34l1.41-1.41"/>
      </svg>
    </button>
  );
}
