﻿// Tela de Login — split editorial com mockup vivo + form clean
// Estado: 'login' → 'splash' → 'app' (em app.jsx)

const { useState: useLoginState, useEffect: useLoginEffect } = React;

// Detecta o slug do cliente pelo subdomínio
// Ex: meldica.ezzacrm.com.br → "meldica" | localhost → "demo"
function getClienteSlug() {
  // 1. Parâmetro ?slug=xxx na URL (funciona em qualquer domínio)
  try {
    const urlSlug = new URLSearchParams(window.location.search).get('slug');
    if (urlSlug) return urlSlug.toLowerCase().trim();
  } catch (e) {}

  const host = window.location.hostname;

  // 2. localhost: verifica slug-override do campo de acesso
  if (host === 'localhost' || host === '127.0.0.1') {
    try {
      const override = sessionStorage.getItem('ezza-slug-override');
      if (override) { sessionStorage.removeItem('ezza-slug-override'); return override; }
    } catch (e) {}
    return '';
  }

  // 3. Subdomínio próprio: meldica.ezzacrm.com.br → "meldica"
  //    (exceto subdomínios reservados que NÃO são clientes)
  if (host.endsWith('.ezzacrm.com.br')) {
    const sub = host.split('.')[0];
    const reservados = ['hub', 'www', 'app', 'crm', 'painel'];
    if (!reservados.includes(sub)) return sub;
  }

  // 4. Genérico (hub/reservado/outro domínio) → vazio: login identifica a empresa pelo e-mail
  return '';
}

function LoginScreen({ onLogin }) {
  const [email, setEmail] = useLoginState('');
  const [password, setPassword] = useLoginState('');
  const [remember, setRemember] = useLoginState(true);
  const [showPwd, setShowPwd] = useLoginState(false);
  const [loading, setLoading] = useLoginState(false);
  const [erro, setErro] = useLoginState('');
  const [cliente, setCliente] = useLoginState(null);

  const clienteSlug = getClienteSlug();
  const [empresas, setEmpresas] = useLoginState(null); // lista quando o e-mail existe em +1 empresa

  // Carrega branding do cliente só quando há slug (subdomínio/atalho). No genérico, branding padrão Ezza.
  useLoginEffect(() => {
    if (!clienteSlug) return;
    fetch(`/api/clientes/${clienteSlug}`)
      .then(r => r.json())
      .then(data => { if (data.ok) setCliente(data.cliente); })
      .catch(() => {});
  }, []);

  // tenta logar; slugForce sobrepõe quando o usuário escolhe a empresa
  const doLogin = async (slugForce) => {
    setErro(''); setLoading(true);
    try {
      const body = { email, senha: password };
      const slug = slugForce || clienteSlug;
      if (slug) body.clienteSlug = slug;
      const res = await fetch('/auth/login', {
        method: 'POST', headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify(body),
      });
      const data = await res.json();
      if (data.needsChoice) { setEmpresas(data.empresas); setLoading(false); return; }
      if (!res.ok || !data.ok) { setErro(data.error || 'E-mail ou senha incorretos.'); setLoading(false); return; }
      localStorage.setItem('ezza_token', data.token);
      onLogin({ name: data.usuario.nome, email: data.usuario.email, token: data.token });
    } catch {
      setErro('Erro de conexão. Tente novamente.');
      setLoading(false);
    }
  };

  const submit = async (e) => {
    e?.preventDefault();
    if (!email || !password) { setErro('Preencha e-mail e senha.'); return; }
    doLogin();
  };

  const loginGoogle = () => {
    setErro('');
    if (!window.google?.accounts?.id) {
      setErro('Login Google não disponível. Recarregue a página.');
      return;
    }
    setLoading(true);
    window.google.accounts.id.initialize({
      client_id: window.GOOGLE_CLIENT_ID || '',
      callback: async ({ credential }) => {
        try {
          const gBody = { idToken: credential };
          if (clienteSlug) gBody.clienteSlug = clienteSlug;
          const res = await fetch('/auth/google', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify(gBody),
          });
          const data = await res.json();
          if (!res.ok) { setErro(data.error || 'Erro no login Google.'); setLoading(false); return; }
          localStorage.setItem('ezza_token', data.token);
          onLogin({ name: data.usuario.nome, email: data.usuario.email, token: data.token });
        } catch {
          setErro('Erro ao autenticar com Google.');
          setLoading(false);
        }
      },
    });
    window.google.accounts.id.prompt();
  };

  const nomeCliente = cliente?.nome || 'Ezza CRM';
  const rememberedAvatar = null;
  const rememberedName = '';

  return (
    <div className="login-root">
      {/* ─── lateral esquerda — editorial + mockup vivo ────────────── */}
      <aside className="login-left">
        <div className="ll-blob ll-blob-1" />
        <div className="ll-blob ll-blob-2" />
        <div className="ll-blob ll-blob-3" />

        <div className="ll-brand">
          <img src="assets/ezza-icon.svg" alt="" />
          <span>ezza<em>CRM</em></span>
        </div>

        <div className="ll-headline">
          <h1>
            Onde o<br/>
            <em>relacionamento</em><br/>
            vira receita.
          </h1>
          <p className="ll-sub">A plataforma de CRM que cresceu junto com 500+ times comerciais brasileiros.</p>
        </div>

        {/* mini mockup flutuante do dashboard */}
        <div className="ll-mockup">
          <div className="ll-mk-bar">
            <div className="ll-mk-dots">
              <span /><span /><span />
            </div>
            <div className="ll-mk-tab">Pipeline · Maio</div>
            <div className="ll-mk-bar-right">
              <div className="ll-mk-av-stack">
                {[1,2,3,4].map(i => <img key={i} src={`https://i.pravatar.cc/120?img=${i + 10}`} alt="" />)}
                <span>+5</span>
              </div>
            </div>
          </div>

          <div className="ll-mk-body">
            <div className="ll-mk-stats">
              <div className="ll-mk-stat">
                <div className="ll-mk-stat-lbl">Receita do mês</div>
                <div className="ll-mk-stat-val">R$ 1.98M</div>
                <div className="ll-mk-stat-delta">↑ +12%</div>
              </div>
              <div className="ll-mk-stat">
                <div className="ll-mk-stat-lbl">Negócios</div>
                <div className="ll-mk-stat-val">76</div>
                <div className="ll-mk-stat-delta">↑ +8</div>
              </div>
              <div className="ll-mk-stat ll-mk-stat-hl">
                <div className="ll-mk-stat-lbl">Taxa de conversão</div>
                <div className="ll-mk-stat-val">32,4%</div>
                <div className="ll-mk-stat-delta">↑ +5,8pp</div>
              </div>
            </div>

            <div className="ll-mk-funnel">
              {[
                { lbl: 'Qualificado', pct: 92, c: 'blue' },
                { lbl: 'Proposta',    pct: 67, c: 'yellow' },
                { lbl: 'Negociação',  pct: 48, c: 'pink' },
                { lbl: 'Fechado',     pct: 28, c: 'mint' },
              ].map((s, i) => (
                <div key={i} className="ll-mk-funnel-row" style={{ animationDelay: `${i * 0.15}s` }}>
                  <span className="ll-mk-funnel-lbl">{s.lbl}</span>
                  <div className="ll-mk-funnel-bar">
                    <div className={`ll-mk-funnel-fill ll-mk-fill-${s.c}`} style={{ width: `${s.pct}%` }} />
                  </div>
                </div>
              ))}
            </div>
          </div>

          {/* floating notif card */}
          <div className="ll-mk-notif">
            <div className="ll-mk-notif-ic">✓</div>
            <div>
              <div className="ll-mk-notif-t">Ana Beatriz fechou um negócio</div>
              <div className="ll-mk-notif-s">Tecnoluz Solar · R$ 482.300</div>
            </div>
          </div>
        </div>

        {/* social proof */}
        <div className="ll-stats">
          <div className="ll-stat-block">
            <div className="ll-stat-n">500+</div>
            <div className="ll-stat-l">empresas confiam<br/>na Ezza</div>
          </div>
          <div className="ll-divider-v" />
          <div className="ll-stat-block">
            <div className="ll-stat-n">R$ 4,2bi</div>
            <div className="ll-stat-l">em pipeline<br/>gerenciado</div>
          </div>
          <div className="ll-divider-v" />
          <div className="ll-stat-block">
            <div className="ll-stat-n">4,9<span style={{fontSize:18}}>★</span></div>
            <div className="ll-stat-l">no Capterra<br/>(312 reviews)</div>
          </div>
        </div>
      </aside>

      {/* ─── lateral direita — form ─────────────────────────────────── */}
      <main className="login-right">
        <div className="lr-shell">
          <div className="lr-eyebrow">
            {cliente ? `Bem-vindo a ${nomeCliente}` : 'Bem-vindo de volta'}
          </div>

          {erro && (
            <div style={{ background: 'oklch(0.96 0.03 18)', border: '1px solid oklch(0.88 0.06 18)', color: 'oklch(0.40 0.15 18)', borderRadius: 10, padding: '10px 14px', fontSize: 13, fontWeight: 500, marginBottom: 16 }}>
              {erro}
            </div>
          )}

          {empresas && (
            <div style={{ marginBottom: 16 }}>
              <div style={{ fontSize: 13, fontWeight: 600, marginBottom: 8 }}>Sua conta existe em mais de uma empresa. Escolha:</div>
              <div className="col" style={{ gap: 6 }}>
                {empresas.map(em => (
                  <button key={em.slug} type="button" className="lr-sso" style={{ justifyContent: 'space-between' }}
                    onClick={() => { setEmpresas(null); doLogin(em.slug); }}>
                    <span>{em.nome}</span><span>{ICN.arrowRight}</span>
                  </button>
                ))}
              </div>
            </div>
          )}

          <form className="lr-form" onSubmit={submit}>
            <label className="lr-field">
              <span>E-mail</span>
              <input type="email" value={email} onChange={(e) => setEmail(e.target.value)} placeholder="voce@empresa.com.br" autoComplete="email" />
            </label>

            <label className="lr-field">
              <span className="lr-field-row">
                <span>Senha</span>
                <button type="button" className="lr-forgot" onClick={() => onLogin({ name: rememberedName, email, hint: 'forgot' })}>
                  Esqueci a senha
                </button>
              </span>
              <span className="lr-pwd-wrap">
                <input type={showPwd ? 'text' : 'password'} value={password} onChange={(e) => setPassword(e.target.value)} placeholder="••••••••••" autoComplete="current-password" />
                <button type="button" className="lr-pwd-toggle" onClick={() => setShowPwd(s => !s)} title={showPwd ? 'Esconder' : 'Mostrar'}>
                  {showPwd ? ICN.eyeOff : ICN.eye}
                </button>
              </span>
            </label>

            <label className="lr-remember">
              <span className={`lr-check ${remember ? 'lr-check-on' : ''}`} onClick={() => setRemember(r => !r)}>
                {remember && ICN.check}
              </span>
              <span>Lembrar deste dispositivo por 30 dias</span>
            </label>

            <button type="submit" className={`lr-submit ${loading ? 'lr-submit-loading' : ''}`} disabled={loading}>
              {loading ? <span className="lr-loading-dots"><span/><span/><span/></span> : <>Entrar <span style={{marginLeft: 8}}>{ICN.arrowRight}</span></>}
            </button>

            <div className="lr-divider">
              <span>ou continue com</span>
            </div>

            <button type="button" className="lr-sso" onClick={loginGoogle} disabled={loading}>
              <GoogleGlyph />
              <span>Continuar com Google</span>
            </button>
          </form>

          <div className="lr-foot">
            <span>Novo na Ezza?</span>
            <button className="lr-link" onClick={() => onLogin({ name: 'Novo usuário', email, hint: 'signup' })}>Criar conta gratuita</button>
          </div>

          <div className="lr-legal">
            <span>v2.6.1</span>
            <span>·</span>
            <a href="#">Termos</a>
            <span>·</span>
            <a href="#">Privacidade</a>
            <span>·</span>
            <a href="#">Status</a>
          </div>
        </div>
      </main>

      <LoginStyles />
    </div>
  );
}

function GoogleGlyph() {
  return (
    <svg width="18" height="18" viewBox="0 0 18 18" aria-hidden="true">
      <path d="M17.64 9.2c0-.637-.057-1.251-.164-1.84H9v3.481h4.844a4.14 4.14 0 0 1-1.796 2.716v2.258h2.908c1.702-1.567 2.684-3.874 2.684-6.615z" fill="#4285F4"/>
      <path d="M9 18c2.43 0 4.467-.806 5.956-2.18l-2.908-2.259c-.806.54-1.837.86-3.048.86-2.344 0-4.328-1.584-5.036-3.711H.957v2.332A8.997 8.997 0 0 0 9 18z" fill="#34A853"/>
      <path d="M3.964 10.71A5.41 5.41 0 0 1 3.682 9c0-.593.102-1.17.282-1.71V4.958H.957A8.996 8.996 0 0 0 0 9c0 1.452.348 2.827.957 4.042l3.007-2.332z" fill="#FBBC05"/>
      <path d="M9 3.58c1.321 0 2.508.454 3.44 1.345l2.582-2.58C13.463.891 11.426 0 9 0A8.997 8.997 0 0 0 .957 4.958L3.964 7.29C4.672 5.163 6.656 3.58 9 3.58z" fill="#EA4335"/>
    </svg>
  );
}

// ────────────────────────────────────────────────────────────────────
// Splash screen — após login, transição pro app
// ────────────────────────────────────────────────────────────────────
function SplashScreen({ user, demo, onDone }) {
  const [stage, setStage] = useLoginState(0);
  const stages = demo ? [
    'Preparando dados de demonstração…',
    'Carregando workspace fictício…',
    'Tudo pronto. Boa exploração!',
  ] : [
    'Conectando à conta…',
    'Carregando seu workspace…',
    `Bem-vinda de volta, ${user?.name?.split(' ')[0] || 'Letícia'}.`,
  ];

  useLoginEffect(() => {
    const t1 = setTimeout(() => setStage(1), 700);
    const t2 = setTimeout(() => setStage(2), 1500);
    const t3 = setTimeout(() => onDone(), 2400);
    return () => { clearTimeout(t1); clearTimeout(t2); clearTimeout(t3); };
  }, []);

  return (
    <div className="splash-root">
      <div className="splash-blob splash-blob-1" />
      <div className="splash-blob splash-blob-2" />

      <div className="splash-card">
        <div className="splash-logo">
          <img src="assets/ezza-icon.svg" alt="" />
        </div>

        <img className="splash-av" src={demo ? 'assets/ezza-icon.svg' : 'https://i.pravatar.cc/160?img=47'} alt="" style={demo ? {objectFit: 'contain', padding: 16, background: 'oklch(0.96 0.012 250)'} : {}} />
        <div className="splash-name">{demo ? 'Modo demonstração' : (user?.name || 'Letícia Andrade')}</div>

        <div className="splash-progress">
          <div className="splash-progress-bar" />
        </div>

        <div className="splash-stages">
          {stages.map((s, i) => (
            <div key={i} className={`splash-stage ${stage >= i ? 'splash-stage-on' : ''} ${stage === i ? 'splash-stage-cur' : ''}`}>
              <span className="splash-stage-ic">
                {stage > i ? ICN.check : stage === i ? <span className="splash-spinner" /> : <span className="splash-dot" />}
              </span>
              <span>{s}</span>
            </div>
          ))}
        </div>
      </div>

      <SplashStyles />
    </div>
  );
}

// Styles ───────────────────────────────────────────────────────────────
function LoginStyles() {
  return (
    <style>{`
      .login-root {
        position: fixed; inset: 0;
        display: grid; grid-template-columns: 1.15fr 1fr;
        overflow: hidden;
        font-family: var(--font-ui);
      }

      /* ─── LEFT ─── */
      .login-left {
        position: relative;
        padding: 56px 64px;
        background:
          radial-gradient(700px 500px at 0% 0%, oklch(0.94 0.05 245) 0%, transparent 60%),
          radial-gradient(700px 500px at 100% 100%, oklch(0.94 0.05 320) 0%, transparent 55%),
          oklch(0.97 0.02 95);
        display: flex; flex-direction: column;
        overflow: hidden;
      }
      .ll-blob {
        position: absolute; border-radius: 50%;
        filter: blur(80px); opacity: 0.55;
        pointer-events: none;
        animation: ll-float 14s ease-in-out infinite;
      }
      .ll-blob-1 { width: 380px; height: 380px; background: var(--acc-pink); top: -80px; right: -80px; }
      .ll-blob-2 { width: 320px; height: 320px; background: var(--acc-lav); bottom: 100px; left: -60px; animation-delay: -4s; }
      .ll-blob-3 { width: 260px; height: 260px; background: var(--acc-blue); top: 40%; right: 20%; animation-delay: -8s; }
      @keyframes ll-float {
        0%, 100% { transform: translate(0, 0) scale(1); }
        50%      { transform: translate(20px, -20px) scale(1.08); }
      }

      .ll-brand {
        display: flex; align-items: center; gap: 12px;
        font-size: 18px; font-weight: 700; letter-spacing: -0.01em;
        color: var(--ink);
        position: relative; z-index: 2;
      }
      .ll-brand img { width: 32px; height: 32px; }
      .ll-brand em { font-family: var(--font-display); font-style: italic; font-weight: 400; }

      .ll-headline {
        margin-top: 48px;
        position: relative; z-index: 2;
        max-width: 540px;
      }
      .ll-headline h1 {
        font-family: var(--font-display);
        font-style: normal;
        font-weight: 400;
        font-size: 64px;
        line-height: 1.02;
        letter-spacing: -0.025em;
        margin: 0;
        color: var(--ink);
        animation: ll-rise 0.8s cubic-bezier(.2,.8,.2,1);
      }
      .ll-headline h1 em {
        font-style: italic;
        background: linear-gradient(95deg, oklch(0.55 0.16 250) 0%, oklch(0.62 0.18 25) 100%);
        -webkit-background-clip: text;
        background-clip: text;
        color: transparent;
      }
      .ll-sub {
        font-size: 15px;
        color: var(--ink-soft);
        line-height: 1.45;
        margin-top: 18px;
        max-width: 420px;
        animation: ll-rise 0.8s 0.15s cubic-bezier(.2,.8,.2,1) backwards;
      }
      @keyframes ll-rise {
        from { opacity: 0; transform: translateY(16px); }
        to   { opacity: 1; transform: translateY(0); }
      }

      /* mini mockup */
      .ll-mockup {
        position: relative; z-index: 2;
        margin-top: 40px;
        background: white;
        border-radius: 18px;
        box-shadow: 0 32px 80px -32px rgba(20,30,60,.28), 0 8px 20px -10px rgba(20,30,60,.12);
        overflow: hidden;
        transform: rotate(-1.5deg);
        animation: ll-mockup-rise 1s 0.3s cubic-bezier(.2,.8,.2,1) backwards;
        max-width: 600px;
      }
      @keyframes ll-mockup-rise {
        from { opacity: 0; transform: translateY(40px) rotate(-1.5deg); }
        to   { opacity: 1; transform: translateY(0) rotate(-1.5deg); }
      }
      .ll-mockup:hover { transform: rotate(-0.5deg) scale(1.01); transition: transform .4s; }

      .ll-mk-bar {
        display: flex; align-items: center; gap: 14px;
        padding: 10px 14px;
        background: oklch(0.97 0.01 250);
        border-bottom: 0.5px solid oklch(0.92 0.01 255);
      }
      .ll-mk-dots { display: flex; gap: 6px; }
      .ll-mk-dots span { width: 9px; height: 9px; border-radius: 50%; background: oklch(0.88 0.012 255); }
      .ll-mk-dots span:nth-child(1) { background: #ff5f57; }
      .ll-mk-dots span:nth-child(2) { background: #febc2e; }
      .ll-mk-dots span:nth-child(3) { background: #28c840; }
      .ll-mk-tab {
        font-size: 11px; font-weight: 600; color: var(--ink);
        padding: 4px 12px;
        background: white;
        border-radius: 99px;
        font-family: var(--font-display); font-style: italic;
        font-size: 13px;
      }
      .ll-mk-bar-right { margin-left: auto; }
      .ll-mk-av-stack { display: flex; align-items: center; }
      .ll-mk-av-stack img {
        width: 22px; height: 22px; border-radius: 50%;
        border: 2px solid white;
        margin-left: -8px;
      }
      .ll-mk-av-stack img:first-child { margin-left: 0; }
      .ll-mk-av-stack span {
        font-size: 9px; font-weight: 700;
        background: oklch(0.93 0.01 255);
        color: var(--ink-muted);
        padding: 0 6px;
        height: 22px; line-height: 22px;
        border-radius: 99px;
        margin-left: 4px;
      }

      .ll-mk-body { padding: 18px 22px 24px; }
      .ll-mk-stats {
        display: grid; grid-template-columns: 1fr 1fr 1.2fr;
        gap: 10px;
        margin-bottom: 18px;
      }
      .ll-mk-stat {
        padding: 12px;
        background: oklch(0.97 0.01 250);
        border-radius: 12px;
      }
      .ll-mk-stat-hl {
        background: linear-gradient(135deg, oklch(0.92 0.07 250) 0%, oklch(0.94 0.06 295) 100%);
      }
      .ll-mk-stat-lbl { font-size: 9.5px; font-weight: 600; color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.08em; }
      .ll-mk-stat-val { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; margin-top: 6px; font-family: var(--font-mono); }
      .ll-mk-stat-delta { font-size: 10px; font-weight: 700; color: oklch(0.45 0.13 155); margin-top: 2px; }

      .ll-mk-funnel { display: flex; flex-direction: column; gap: 7px; }
      .ll-mk-funnel-row {
        display: grid;
        grid-template-columns: 90px 1fr;
        align-items: center;
        gap: 12px;
        animation: ll-bar-grow 0.8s cubic-bezier(.2,.8,.2,1) backwards;
      }
      @keyframes ll-bar-grow {
        from { opacity: 0; transform: translateX(-10px); }
        to   { opacity: 1; transform: translateX(0); }
      }
      .ll-mk-funnel-lbl { font-size: 10.5px; font-weight: 600; color: var(--ink-soft); }
      .ll-mk-funnel-bar {
        height: 8px; background: oklch(0.95 0.01 250); border-radius: 99px; overflow: hidden;
      }
      .ll-mk-funnel-fill {
        height: 100%; border-radius: 99px;
        animation: ll-fill 1.4s 0.4s cubic-bezier(.2,.8,.2,1) backwards;
      }
      @keyframes ll-fill { from { width: 0 !important; } }
      .ll-mk-fill-blue { background: var(--acc-blue); }
      .ll-mk-fill-yellow { background: var(--acc-yellow); }
      .ll-mk-fill-pink { background: var(--acc-pink); }
      .ll-mk-fill-mint { background: var(--acc-mint); }

      /* floating notif */
      .ll-mk-notif {
        position: absolute; right: 16px; bottom: 40px;
        background: white;
        border-radius: 16px;
        box-shadow: 0 16px 36px -12px rgba(20,30,60,.25);
        padding: 12px 16px 12px 12px;
        display: flex; align-items: center; gap: 12px;
        max-width: 280px;
        transform: rotate(1.5deg);
        animation: ll-notif-pop 0.6s 1.2s cubic-bezier(.2,.8,.2,1) backwards;
      }
      @keyframes ll-notif-pop {
        from { opacity: 0; transform: translateY(20px) rotate(1.5deg) scale(0.85); }
        to   { opacity: 1; transform: translateY(0) rotate(1.5deg) scale(1); }
      }
      .ll-mk-notif-ic {
        width: 32px; height: 32px; border-radius: 50%;
        background: var(--acc-mint);
        color: oklch(0.40 0.14 160);
        display: grid; place-items: center;
        font-size: 14px; font-weight: 800;
        flex-shrink: 0;
        animation: ll-pulse 1.6s ease-in-out infinite;
      }
      @keyframes ll-pulse {
        0%, 100% { box-shadow: 0 0 0 0 oklch(0.65 0.13 155 / 0.4); }
        50%      { box-shadow: 0 0 0 8px oklch(0.65 0.13 155 / 0); }
      }
      .ll-mk-notif-t { font-size: 12.5px; font-weight: 600; letter-spacing: -0.005em; }
      .ll-mk-notif-s { font-size: 11px; color: var(--ink-muted); margin-top: 2px; }

      /* social proof */
      .ll-stats {
        margin-top: auto;
        padding-top: 36px;
        display: flex; align-items: flex-start; gap: 32px;
        position: relative; z-index: 2;
        flex-wrap: nowrap;
      }
      .ll-stat-block { min-width: 0; flex-shrink: 0; }
      .ll-stat-n {
        font-family: var(--font-display);
        font-style: italic;
        font-size: 30px;
        font-weight: 400;
        line-height: 1;
        letter-spacing: -0.015em;
        color: var(--ink);
        white-space: nowrap;
      }
      .ll-stat-l { font-size: 11px; color: var(--ink-muted); margin-top: 8px; line-height: 1.35; white-space: nowrap; }
      .ll-divider-v { width: 1px; height: 42px; background: oklch(0.78 0.012 255); flex-shrink: 0; margin-top: 4px; }

      /* ─── RIGHT ─── */
      .login-right {
        display: grid; place-items: center;
        padding: 56px;
        background: oklch(0.99 0.005 250);
        position: relative;
      }
      .lr-shell {
        width: 100%; max-width: 380px;
        animation: lr-rise 0.7s 0.1s cubic-bezier(.2,.8,.2,1) backwards;
      }
      @keyframes lr-rise {
        from { opacity: 0; transform: translateY(12px); }
        to   { opacity: 1; transform: translateY(0); }
      }

      .lr-eyebrow {
        font-family: var(--font-display);
        font-style: italic;
        font-size: 22px;
        color: var(--ink-soft);
        margin-bottom: 18px;
      }

      .lr-remembered {
        display: flex; align-items: center; gap: 12px;
        padding: 12px 14px 12px 12px;
        background: white;
        border: 0.5px solid oklch(0.92 0.012 255);
        border-radius: 16px;
        margin-bottom: 24px;
        box-shadow: 0 8px 24px -16px rgba(20,30,60,.12);
      }
      .lr-av-wrap { position: relative; flex-shrink: 0; width: 44px; height: 44px; }
      .lr-av-wrap img { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; display: block; }
      .lr-av-pulse {
        position: absolute; inset: -3px; border-radius: 50%;
        border: 2px solid var(--acc-blue-strong);
        animation: lr-pulse 2.4s cubic-bezier(.5,0,.5,1) infinite;
        pointer-events: none;
      }
      @keyframes lr-pulse {
        0%, 100% { transform: scale(1); opacity: 1; }
        50%      { transform: scale(1.18); opacity: 0; }
      }
      .lr-name { font-size: 14px; font-weight: 600; }
      .lr-name-sub { font-size: 11.5px; color: var(--ink-muted); margin-top: 2px; font-family: var(--font-mono); }
      .lr-switch {
        margin-left: auto;
        background: oklch(0.95 0.012 250);
        border: none;
        font-size: 11px; font-weight: 600;
        padding: 6px 10px;
        border-radius: 99px;
        color: var(--ink-soft);
        cursor: default;
        font-family: inherit;
      }
      .lr-switch:hover { background: oklch(0.92 0.012 250); }

      .lr-form { display: flex; flex-direction: column; gap: 14px; }
      .lr-field { display: flex; flex-direction: column; gap: 7px; }
      .lr-field > span:first-child { font-size: 11.5px; font-weight: 600; color: var(--ink-soft); letter-spacing: -0.005em; }
      .lr-field-row { display: flex; justify-content: space-between; align-items: center; }
      .lr-forgot {
        font-size: 11px; font-weight: 600;
        color: var(--acc-blue-strong);
        background: none; border: none;
        cursor: default;
        font-family: inherit;
        padding: 0;
      }
      .lr-forgot:hover { text-decoration: underline; }
      .lr-field input {
        font-family: inherit;
        font-size: 14px;
        font-weight: 500;
        padding: 13px 14px;
        background: white;
        border: 1px solid oklch(0.90 0.012 255);
        border-radius: 12px;
        color: var(--ink);
        letter-spacing: -0.005em;
        transition: border-color .15s, box-shadow .15s;
      }
      .lr-field input:focus {
        outline: none;
        border-color: var(--acc-blue-strong);
        box-shadow: 0 0 0 3px oklch(0.78 0.10 250 / 0.25);
      }
      .lr-pwd-wrap { position: relative; }
      .lr-pwd-wrap input { width: 100%; padding-right: 44px; }
      .lr-pwd-toggle {
        position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
        background: none; border: none;
        width: 32px; height: 32px;
        display: grid; place-items: center;
        color: var(--ink-muted);
        cursor: default;
        border-radius: 8px;
      }
      .lr-pwd-toggle:hover { background: oklch(0.95 0.012 250); }

      .lr-remember {
        display: flex; align-items: center; gap: 10px;
        font-size: 12.5px; color: var(--ink-soft);
        margin-top: 4px;
        cursor: default;
      }
      .lr-check {
        width: 18px; height: 18px; border-radius: 6px;
        border: 1.5px solid oklch(0.85 0.012 255);
        background: white;
        display: grid; place-items: center;
        color: white;
        flex-shrink: 0;
        transition: background .15s, border-color .15s;
      }
      .lr-check svg { width: 12px; height: 12px; stroke-width: 3; }
      .lr-check-on {
        background: var(--ink);
        border-color: var(--ink);
      }

      .lr-submit {
        margin-top: 8px;
        background: var(--ink);
        color: white;
        font-family: inherit;
        font-size: 14px; font-weight: 600;
        padding: 14px;
        border: none;
        border-radius: 12px;
        cursor: default;
        display: flex; align-items: center; justify-content: center;
        letter-spacing: -0.005em;
        transition: transform .12s, background .15s;
      }
      .lr-submit:hover { background: oklch(0.10 0.008 255); }
      .lr-submit:active { transform: scale(0.985); }
      .lr-submit:disabled { opacity: 0.7; }

      .lr-loading-dots { display: flex; gap: 5px; }
      .lr-loading-dots span {
        width: 6px; height: 6px; border-radius: 50%;
        background: white;
        animation: lr-dot 1.2s ease-in-out infinite;
      }
      .lr-loading-dots span:nth-child(2) { animation-delay: .15s; }
      .lr-loading-dots span:nth-child(3) { animation-delay: .3s; }
      @keyframes lr-dot {
        0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
        40% { opacity: 1; transform: scale(1.1); }
      }

      .lr-divider {
        position: relative;
        margin: 16px 0 6px;
        text-align: center;
      }
      .lr-divider::before {
        content: ''; position: absolute; left: 0; right: 0; top: 50%;
        height: 1px; background: oklch(0.92 0.012 255);
      }
      .lr-divider span {
        position: relative;
        background: oklch(0.99 0.005 250);
        padding: 0 12px;
        font-size: 11px;
        color: var(--ink-muted);
        text-transform: uppercase;
        letter-spacing: 0.12em;
        font-weight: 600;
      }

      .lr-sso {
        display: flex; align-items: center; justify-content: center; gap: 10px;
        font-family: inherit; font-size: 13.5px; font-weight: 600;
        padding: 13px;
        background: white;
        border: 1px solid oklch(0.90 0.012 255);
        border-radius: 12px;
        color: var(--ink);
        cursor: default;
        letter-spacing: -0.005em;
        transition: border-color .15s, background .15s;
      }
      .lr-sso:hover { border-color: oklch(0.82 0.012 255); background: oklch(0.98 0.005 250); }

      .lr-foot {
        display: flex; justify-content: center; gap: 6px;
        margin-top: 24px;
        font-size: 12.5px;
        color: var(--ink-muted);
      }
      .lr-link {
        background: none; border: none;
        color: var(--ink); font-weight: 600;
        cursor: default; font-family: inherit;
        font-size: inherit;
        padding: 0;
      }
      .lr-link:hover { text-decoration: underline; }

      .lr-legal {
        display: flex; justify-content: center; gap: 8px;
        font-size: 10.5px;
        color: var(--ink-faint);
        margin-top: 36px;
        font-family: var(--font-mono);
      }
      .lr-legal a { color: var(--ink-muted); text-decoration: none; }
      .lr-legal a:hover { color: var(--ink); }

      /* responsive */
      @media (max-width: 980px) {
        .login-root { grid-template-columns: 1fr; }
        .login-left { display: none; }
      }
    `}</style>
  );
}

function SplashStyles() {
  return (
    <style>{`
      .splash-root {
        position: fixed; inset: 0;
        display: grid; place-items: center;
        background:
          radial-gradient(800px 600px at 20% 20%, oklch(0.94 0.05 245) 0%, transparent 60%),
          radial-gradient(800px 600px at 80% 80%, oklch(0.94 0.06 320) 0%, transparent 55%),
          oklch(0.97 0.02 95);
        overflow: hidden;
        font-family: var(--font-ui);
      }
      .splash-blob {
        position: absolute; border-radius: 50%;
        filter: blur(100px); opacity: 0.55;
        animation: ll-float 10s ease-in-out infinite;
      }
      .splash-blob-1 { width: 420px; height: 420px; background: var(--acc-pink); top: -100px; left: -100px; }
      .splash-blob-2 { width: 380px; height: 380px; background: var(--acc-lav); bottom: -100px; right: -100px; animation-delay: -5s; }

      .splash-card {
        position: relative;
        background: white;
        border-radius: 28px;
        padding: 48px 56px;
        box-shadow: 0 40px 80px -32px rgba(20,30,60,.25);
        width: 420px;
        text-align: center;
        animation: splash-pop 0.5s cubic-bezier(.2,.8,.2,1);
      }
      @keyframes splash-pop {
        from { opacity: 0; transform: translateY(20px) scale(0.96); }
        to   { opacity: 1; transform: translateY(0) scale(1); }
      }

      .splash-logo {
        position: absolute; top: 24px; left: 24px;
      }
      .splash-logo img { width: 32px; height: 32px; }

      .splash-av {
        width: 80px; height: 80px; border-radius: 50%;
        margin: 0 auto 14px;
        display: block;
        border: 3px solid white;
        box-shadow: 0 0 0 2px var(--acc-blue), 0 16px 32px -14px rgba(20,30,60,.25);
        animation: splash-av-pulse 2s ease-in-out infinite;
      }
      @keyframes splash-av-pulse {
        0%, 100% { box-shadow: 0 0 0 2px var(--acc-blue), 0 16px 32px -14px rgba(20,30,60,.25); }
        50%      { box-shadow: 0 0 0 6px var(--acc-blue), 0 16px 32px -14px rgba(20,30,60,.25); }
      }
      .splash-name {
        font-family: var(--font-display);
        font-style: italic;
        font-size: 24px;
        color: var(--ink);
        margin-bottom: 24px;
        letter-spacing: -0.015em;
      }

      .splash-progress {
        height: 3px; background: oklch(0.94 0.012 250); border-radius: 99px; overflow: hidden;
        margin-bottom: 24px;
      }
      .splash-progress-bar {
        height: 100%;
        background: linear-gradient(90deg, var(--acc-blue-strong), oklch(0.62 0.18 25));
        border-radius: 99px;
        animation: splash-progress 2.4s linear forwards;
      }
      @keyframes splash-progress {
        from { width: 0%; }
        to   { width: 100%; }
      }

      .splash-stages { display: flex; flex-direction: column; gap: 10px; text-align: left; }
      .splash-stage {
        display: flex; align-items: center; gap: 12px;
        font-size: 13px; font-weight: 500;
        color: var(--ink-faint);
        transition: color .3s;
      }
      .splash-stage-on { color: var(--ink-soft); }
      .splash-stage-cur { color: var(--ink); font-weight: 600; }
      .splash-stage-ic {
        width: 18px; height: 18px;
        display: grid; place-items: center;
        flex-shrink: 0;
      }
      .splash-stage-ic svg { width: 14px; height: 14px; color: var(--ok); stroke-width: 3; }
      .splash-spinner {
        width: 12px; height: 12px;
        border-radius: 50%;
        border: 1.5px solid oklch(0.85 0.012 255);
        border-top-color: var(--ink);
        animation: splash-spin .8s linear infinite;
      }
      @keyframes splash-spin { to { transform: rotate(360deg); } }
      .splash-dot {
        width: 6px; height: 6px; border-radius: 50%;
        background: oklch(0.88 0.012 255);
      }
    `}</style>
  );
}

// Add eye / eyeOff icons (extend ICN if not present)
if (!window.ICN.eye) {
  window.ICN.eye = (
    <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><path d="M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7z"/><circle cx="12" cy="12" r="3"/></svg>
  );
  window.ICN.eyeOff = (
    <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><path d="M9.88 9.88a3 3 0 1 0 4.24 4.24"/><path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"/><path d="M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61"/><line x1="2" x2="22" y1="2" y2="22"/></svg>
  );
}

Object.assign(window, { LoginScreen, SplashScreen, EntryGate, DemoBanner, ThanksScreen, PricingScreen });

// ═════════════════════════════════════════════════════════════════
// ThanksScreen — tela de despedida para usuário pago
// ═════════════════════════════════════════════════════════════════

function ThanksScreen({ user, onDone }) {
  const [progress, setProgress] = useLoginState(0);

  useLoginEffect(() => {
    const t = setTimeout(() => onDone(), 3200);
    const t2 = setTimeout(() => setProgress(1), 100);
    return () => { clearTimeout(t); clearTimeout(t2); };
  }, []);

  const firstName = user?.name?.split(' ')[0] || 'Letícia';

  return (
    <div className="thanks-root">
      <div className="thanks-blob thanks-blob-1" />
      <div className="thanks-blob thanks-blob-2" />
      <div className="thanks-blob thanks-blob-3" />

      <div className="thanks-content">
        <div className="thanks-wave">👋</div>

        <h1 className="thanks-title">
          Até logo,<br/>
          <em>{firstName}</em>.
        </h1>

        <p className="thanks-sub">
          Foi um prazer ter você aqui hoje.<br/>
          Você fechou <strong>R$ 982k</strong> em maio — mande bem aí fora.
        </p>

        <div className="thanks-stats">
          <div className="thanks-stat">
            <div className="thanks-stat-n">23</div>
            <div className="thanks-stat-l">tarefas concluídas hoje</div>
          </div>
          <div className="thanks-stat-divider" />
          <div className="thanks-stat">
            <div className="thanks-stat-n">7</div>
            <div className="thanks-stat-l">negócios movidos</div>
          </div>
          <div className="thanks-stat-divider" />
          <div className="thanks-stat">
            <div className="thanks-stat-n">3h<span style={{fontSize:18, opacity:0.55}}>12min</span></div>
            <div className="thanks-stat-l">de foco sem interrupção</div>
          </div>
        </div>

        <div className="thanks-progress">
          <div className="thanks-progress-bar" style={{ width: progress ? '100%' : '0%' }} />
        </div>
        <div className="thanks-foot">Encerrando sua sessão com segurança…</div>
      </div>

      <style>{`
        .thanks-root {
          position: fixed; inset: 0;
          display: grid; place-items: center;
          font-family: var(--font-ui);
          overflow: hidden;
          background:
            radial-gradient(900px 700px at 30% 20%, oklch(0.94 0.05 245) 0%, transparent 60%),
            radial-gradient(900px 700px at 70% 80%, oklch(0.94 0.06 320) 0%, transparent 55%),
            oklch(0.97 0.02 95);
        }
        .thanks-blob {
          position: absolute; border-radius: 50%;
          filter: blur(100px); opacity: 0.45;
          animation: ll-float 14s ease-in-out infinite;
          pointer-events: none;
        }
        .thanks-blob-1 { width: 500px; height: 500px; background: var(--acc-pink); top: -120px; left: -120px; }
        .thanks-blob-2 { width: 460px; height: 460px; background: var(--acc-blue); top: 40%; right: -100px; animation-delay: -5s; }
        .thanks-blob-3 { width: 380px; height: 380px; background: var(--acc-mint); bottom: -120px; left: 30%; animation-delay: -9s; }
        .thanks-content {
          position: relative; z-index: 2;
          text-align: center;
          max-width: 580px;
          padding: 48px;
          animation: thanks-rise .7s cubic-bezier(.2,.8,.2,1);
        }
        @keyframes thanks-rise { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
        .thanks-wave { font-size: 64px; animation: thanks-wave 1.4s ease-in-out infinite; transform-origin: 70% 70%; margin-bottom: 8px; }
        @keyframes thanks-wave { 0%, 100% { transform: rotate(0deg); } 25% { transform: rotate(-18deg); } 75% { transform: rotate(14deg); } }
        .thanks-title { font-family: var(--font-display); font-size: 76px; line-height: 0.98; letter-spacing: -0.025em; font-weight: 400; color: var(--ink); margin: 0 0 24px; }
        .thanks-title em {
          font-style: italic;
          background: linear-gradient(95deg, oklch(0.55 0.16 250) 0%, oklch(0.62 0.18 25) 100%);
          -webkit-background-clip: text; background-clip: text; color: transparent;
        }
        .thanks-sub { font-size: 15px; color: var(--ink-soft); line-height: 1.55; margin: 0 0 40px; }
        .thanks-sub strong { color: var(--ink); font-weight: 700; }
        .thanks-stats { display: flex; align-items: center; justify-content: center; gap: 28px; margin-bottom: 48px; }
        .thanks-stat-n { font-family: var(--font-display); font-style: italic; font-size: 36px; line-height: 1; color: var(--ink); letter-spacing: -0.015em; }
        .thanks-stat-l { font-size: 11.5px; color: var(--ink-muted); margin-top: 8px; max-width: 130px; line-height: 1.35; }
        .thanks-stat-divider { width: 1px; height: 44px; background: oklch(0.82 0.012 255); }
        .thanks-progress { height: 3px; background: oklch(0.92 0.012 250); border-radius: 99px; overflow: hidden; margin: 0 auto 14px; max-width: 280px; }
        .thanks-progress-bar { height: 100%; background: linear-gradient(90deg, var(--acc-blue-strong), oklch(0.62 0.18 25)); border-radius: 99px; transition: width 3s cubic-bezier(.4,0,.2,1); }
        .thanks-foot { font-size: 11.5px; color: var(--ink-muted); font-family: var(--font-mono); }
      `}</style>
    </div>
  );
}

// ═════════════════════════════════════════════════════════════════
// PricingScreen — tela de planos para quem está saindo da demo
// ═════════════════════════════════════════════════════════════════

function PricingScreen({ onBack, onPick }) {
  const [billing, setBilling] = useLoginState('anual');
  const [picked, setPicked] = useLoginState(null);

  const plans = [
    { id: 'starter',  name: 'Starter',  eyebrow: 'Para times pequenos começando', price: { mensal: 297, anual: 247 }, color: 'lav',
      features: ['Até 3 usuários','1.000 leads','Pipeline completo','WhatsApp integrado','IA de qualificação','Suporte por e-mail'], cta: 'Começar agora', hint: '14 dias de teste grátis' },
    { id: 'pro',      name: 'Pro',      eyebrow: 'Mais escolhido por times de vendas', price: { mensal: 597, anual: 497 }, color: 'pink', highlight: true,
      features: ['Até 10 usuários','Leads ilimitados','Jornadas customizadas','Automações ilimitadas','WhatsApp + IA SDR','Relatórios avançados','Suporte prioritário'], cta: 'Assinar Pro', hint: 'Sem fidelidade' },
    { id: 'business', name: 'Enterprise', eyebrow: 'Para operações comerciais grandes', price: { mensal: 'sob consulta', anual: 'sob consulta' }, color: 'blue',
      features: ['Usuários ilimitados','White-label','SSO + auditoria LGPD','API + webhooks','CSM exclusivo','SLA 99,9%','Onboarding dedicado'], cta: 'Falar com vendas', hint: 'Custom' },
  ];

  return (
    <div className="prc-root">
      <div className="prc-blob prc-blob-1" />
      <div className="prc-blob prc-blob-2" />

      <header className="prc-header">
        <div className="prc-brand">
          <img src="assets/ezza-icon.svg" alt="" />
          <span>ezza<em>CRM</em></span>
        </div>
        <button className="prc-back" onClick={onBack}>
          {ICN.arrowLeft} Voltar à entrada
        </button>
      </header>

      <div className="prc-content">
        <div className="prc-eyebrow">PRONTA PARA O REAL?</div>
        <h1 className="prc-title">
          Pegue um <em>plano</em>.<br/>
          Comece a fechar.
        </h1>
        <p className="prc-sub">
          Você acabou de explorar a Ezza com dados fictícios — agora escolha o plano que faz sentido pra sua equipe e comece a usar com dados reais hoje.
        </p>

        <div className="prc-billing">
          <button className={`prc-bill-btn ${billing === 'mensal' ? 'prc-bill-on' : ''}`} onClick={() => setBilling('mensal')}>Cobrança mensal</button>
          <button className={`prc-bill-btn ${billing === 'anual' ? 'prc-bill-on' : ''}`} onClick={() => setBilling('anual')}>Anual <span className="prc-save">economize 23%</span></button>
        </div>

        <div className="prc-grid">
          {plans.map(p => (
            <div key={p.id} className={`prc-plan ${p.highlight ? 'prc-plan-hl' : ''} ${picked === p.id ? 'prc-plan-picked' : ''}`}>
              {p.highlight && <div className="prc-badge">⭐ Mais popular</div>}
              <div className="prc-plan-eyebrow">{p.eyebrow}</div>
              <div className="prc-plan-name">{p.name}</div>
              <div className="prc-price">
                {typeof p.price[billing] === 'number' ? (
                  <>
                    <span className="prc-price-currency">R$</span>
                    <span className="prc-price-n">{p.price[billing]}</span>
                    <span className="prc-price-unit">/workspace<br/>/mês</span>
                  </>
                ) : (
                  <span className="prc-price-custom">{p.price[billing]}</span>
                )}
              </div>
              {billing === 'anual' && typeof p.price.anual === 'number' && (
                <div className="prc-price-strike">de R$ {p.price.mensal}/mês</div>
              )}
              {!(billing === 'anual' && typeof p.price.anual === 'number') && (
                <div className="prc-price-strike" style={{visibility:'hidden'}}>—</div>
              )}
              <ul className="prc-features">
                {p.features.map((f, i) => (
                  <li key={i}><span className="prc-feat-check">{ICN.check}</span>{f}</li>
                ))}
              </ul>
              <button className={`prc-cta ${p.highlight ? 'prc-cta-hl' : ''}`} onClick={() => { setPicked(p.id); setTimeout(() => onPick(p.id), 600); }}>
                {picked === p.id ? <span className="prc-cta-loading"><span/><span/><span/></span> : <>{p.cta} {ICN.arrowRight}</>}
              </button>
              <div className="prc-hint">{p.hint}</div>
            </div>
          ))}
        </div>

        <div className="prc-faq">
          <div className="prc-faq-item"><strong>Posso trocar de plano depois?</strong><span>A qualquer momento, sem perder dados.</span></div>
          <div className="prc-faq-divider" />
          <div className="prc-faq-item"><strong>Os dados do demo migram?</strong><span>Não — você começa em um workspace limpo.</span></div>
          <div className="prc-faq-divider" />
          <div className="prc-faq-item"><strong>Aceitam Pix e boleto?</strong><span>Sim, além de cartão e fatura para Business.</span></div>
        </div>
      </div>

      <style>{`
        .prc-root {
          position: fixed; inset: 0; overflow-y: auto; font-family: var(--font-ui);
          background:
            radial-gradient(900px 600px at 20% 10%, oklch(0.94 0.05 245) 0%, transparent 60%),
            radial-gradient(900px 600px at 80% 50%, oklch(0.95 0.04 320) 0%, transparent 55%),
            oklch(0.97 0.02 95);
        }
        .prc-blob { position: absolute; border-radius: 50%; filter: blur(120px); opacity: 0.4; animation: ll-float 14s ease-in-out infinite; pointer-events: none; }
        .prc-blob-1 { width: 500px; height: 500px; background: var(--acc-pink); top: -100px; left: -100px; }
        .prc-blob-2 { width: 500px; height: 500px; background: var(--acc-lav); bottom: -100px; right: -100px; animation-delay: -7s; }
        .prc-header { position: relative; z-index: 5; display: flex; justify-content: space-between; align-items: center; padding: 28px 48px; }
        .prc-brand { display: flex; align-items: center; gap: 12px; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; color: var(--ink); }
        .prc-brand img { width: 32px; height: 32px; }
        .prc-brand em { font-family: var(--font-display); font-style: italic; font-weight: 400; }
        .prc-back { display: inline-flex; align-items: center; gap: 8px; background: white; border: 0.5px solid oklch(0.92 0.012 255); font-family: inherit; font-size: 12.5px; font-weight: 600; padding: 9px 16px 9px 12px; border-radius: 999px; color: var(--ink-soft); cursor: default; box-shadow: 0 4px 14px -8px rgba(20,30,60,.18); }
        .prc-back:hover { color: var(--ink); }
        .prc-back svg { width: 14px; height: 14px; }
        .prc-content { position: relative; z-index: 2; max-width: 1240px; margin: 0 auto; padding: 32px 48px 80px; }
        .prc-eyebrow { font-size: 11px; font-weight: 700; letter-spacing: 0.14em; color: var(--ink-muted); margin-bottom: 16px; }
        .prc-title { font-family: var(--font-display); font-size: 80px; line-height: 0.96; letter-spacing: -0.025em; font-weight: 400; color: var(--ink); margin: 0 0 24px; max-width: 800px; }
        .prc-title em { font-style: italic; background: linear-gradient(95deg, oklch(0.55 0.16 250) 0%, oklch(0.62 0.18 25) 100%); -webkit-background-clip: text; background-clip: text; color: transparent; padding-left: 0.07em; margin-left: -0.07em; padding-right: 0.05em; }
        .prc-sub { font-size: 16px; color: var(--ink-soft); line-height: 1.55; max-width: 640px; margin: 0 0 32px; }
        .prc-billing { display: inline-flex; background: white; border-radius: 999px; padding: 4px; margin-bottom: 48px; box-shadow: 0 8px 24px -12px rgba(20,30,60,.18); }
        .prc-bill-btn { font-family: inherit; font-size: 13px; font-weight: 600; padding: 9px 18px; background: transparent; border: none; border-radius: 999px; color: var(--ink-muted); cursor: default; display: inline-flex; align-items: center; gap: 8px; letter-spacing: -0.005em; transition: background .15s, color .15s; }
        .prc-bill-on { background: var(--ink); color: white; }
        .prc-save { font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: var(--acc-mint); color: oklch(0.34 0.12 160); }
        .prc-bill-on .prc-save { background: oklch(1 0 0 / 0.2); color: var(--acc-mint); }
        .prc-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-bottom: 56px; align-items: stretch; }
        .prc-plan { position: relative; background: white; border-radius: 24px; padding: 28px 28px 24px; border: 0.5px solid oklch(0.92 0.012 255); box-shadow: 0 16px 40px -20px rgba(20,30,60,.18); display: flex; flex-direction: column; transition: transform .25s, box-shadow .25s; }
        .prc-plan:hover { transform: translateY(-4px); box-shadow: 0 24px 56px -20px rgba(20,30,60,.25); }
        .prc-plan-hl { background: linear-gradient(180deg, oklch(0.20 0.012 255) 0%, oklch(0.16 0.008 255) 100%); color: white; border: none; transform: scale(1.02); box-shadow: 0 24px 56px -20px rgba(20,30,60,.4); }
        .prc-plan-hl:hover { transform: scale(1.02) translateY(-4px); }
        .prc-plan-picked { transform: scale(0.98); }
        .prc-plan-hl.prc-plan-picked { transform: scale(1.0); }
        .prc-badge { position: absolute; top: -12px; left: 50%; transform: translateX(-50%); background: linear-gradient(95deg, var(--acc-pink), var(--acc-yellow)); color: oklch(0.20 0.04 18); font-size: 11px; font-weight: 700; padding: 5px 14px; border-radius: 999px; letter-spacing: -0.005em; box-shadow: 0 8px 18px -8px rgba(20,30,60,.3); }
        .prc-plan-eyebrow { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-muted); margin-bottom: 10px; }
        .prc-plan-hl .prc-plan-eyebrow { color: oklch(0.78 0.012 255); }
        .prc-plan-name { font-family: var(--font-display); font-style: italic; font-size: 38px; line-height: 1; color: var(--ink); margin-bottom: 24px; }
        .prc-plan-hl .prc-plan-name { color: white; }
        .prc-price { display: flex; align-items: baseline; gap: 4px; min-height: 56px; }
        .prc-price-currency { font-size: 18px; font-weight: 700; color: var(--ink-soft); }
        .prc-plan-hl .prc-price-currency { color: oklch(0.85 0.012 255); }
        .prc-price-n { font-size: 56px; font-weight: 800; letter-spacing: -0.04em; color: var(--ink); line-height: 1; }
        .prc-plan-hl .prc-price-n { color: white; }
        .prc-price-unit { font-size: 11px; font-weight: 600; color: var(--ink-muted); line-height: 1.2; margin-left: 4px; }
        .prc-plan-hl .prc-price-unit { color: oklch(0.78 0.012 255); }
        .prc-price-custom { font-family: var(--font-display); font-style: italic; font-size: 32px; color: var(--ink); align-self: center; }
        .prc-plan-hl .prc-price-custom { color: white; }
        .prc-price-strike { font-size: 11px; color: var(--ink-faint); text-decoration: line-through; margin-top: 2px; margin-bottom: 18px; height: 16px; }
        .prc-plan-hl .prc-price-strike { color: oklch(0.62 0.012 255); }
        .prc-features { list-style: none; padding: 0; margin: 24px 0 28px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
        .prc-features li { display: flex; align-items: flex-start; gap: 10px; font-size: 13px; font-weight: 500; color: var(--ink-soft); line-height: 1.4; letter-spacing: -0.005em; }
        .prc-plan-hl .prc-features li { color: oklch(0.92 0.012 255); }
        .prc-feat-check { width: 18px; height: 18px; border-radius: 50%; background: var(--acc-mint); color: oklch(0.30 0.12 160); display: grid; place-items: center; flex-shrink: 0; margin-top: 1px; }
        .prc-feat-check svg { width: 11px; height: 11px; stroke-width: 3; }
        .prc-plan-hl .prc-feat-check { background: oklch(0.65 0.13 155); color: oklch(0.18 0.008 255); }
        .prc-cta { display: flex; align-items: center; justify-content: center; gap: 8px; background: oklch(0.95 0.012 250); color: var(--ink); border: none; font-family: inherit; font-size: 14px; font-weight: 600; padding: 14px; border-radius: 14px; cursor: default; letter-spacing: -0.005em; transition: background .15s, transform .12s; }
        .prc-cta:hover { background: oklch(0.92 0.012 250); }
        .prc-cta:active { transform: scale(0.985); }
        .prc-cta svg { width: 14px; height: 14px; }
        .prc-cta-hl { background: white; color: var(--ink); font-weight: 700; }
        .prc-cta-hl:hover { background: oklch(0.97 0.012 250); }
        .prc-cta-loading { display: flex; gap: 5px; }
        .prc-cta-loading span { width: 6px; height: 6px; border-radius: 50%; background: var(--ink); animation: lr-dot 1.2s ease-in-out infinite; }
        .prc-cta-loading span:nth-child(2) { animation-delay: .15s; }
        .prc-cta-loading span:nth-child(3) { animation-delay: .3s; }
        .prc-hint { text-align: center; font-size: 11px; color: var(--ink-muted); margin-top: 8px; font-family: var(--font-mono); }
        .prc-plan-hl .prc-hint { color: oklch(0.70 0.012 255); }
        .prc-faq { display: flex; align-items: stretch; justify-content: center; gap: 28px; padding: 24px 32px; background: white; border-radius: 18px; border: 0.5px solid oklch(0.92 0.012 255); box-shadow: 0 8px 24px -16px rgba(20,30,60,.12); max-width: 800px; margin: 0 auto; }
        .prc-faq-item { display: flex; flex-direction: column; flex: 1; text-align: center; }
        .prc-faq-item strong { font-size: 12.5px; font-weight: 600; color: var(--ink); margin-bottom: 4px; }
        .prc-faq-item span { font-size: 11.5px; color: var(--ink-muted); line-height: 1.4; }
        .prc-faq-divider { width: 1px; background: oklch(0.93 0.012 250); }
        @media (max-width: 980px) {
          .prc-grid { grid-template-columns: 1fr; }
          .prc-plan-hl { transform: none; }
          .prc-title { font-size: 56px; }
          .prc-faq { flex-direction: column; }
          .prc-faq-divider { display: none; }
        }
      `}</style>
    </div>
  );
}

// ════════════════════════════════════════════════════════════════════

function EntryGate({ onDemo, onLogin }) {
  const [hover, setHover] = useLoginState(null); // 'demo' | 'login' | null
  const [slug, setSlug] = useLoginState('');
  const [slugErro, setSlugErro] = useLoginState('');

  const acessarCRM = (e) => {
    e?.preventDefault();
    const s = slug.trim().toLowerCase().replace(/[^a-z0-9-]/g, '');
    if (!s) { setSlugErro('Digite o nome da sua empresa.'); return; }
    // Redireciona para o subdomínio do cliente
    const host = window.location.hostname;
    if (host === 'localhost' || host === '127.0.0.1') {
      // Em localhost: simula indo pro login com aquele slug
      sessionStorage.setItem('ezza-slug-override', s);
      onLogin();
    } else {
      window.location.href = `https://${s}.ezzacrm.com.br`;
    }
  };

  return (
    <div className="gate-root" onMouseLeave={() => setHover(null)}>
      <div className="gate-blob gate-blob-1" />
      <div className="gate-blob gate-blob-2" />

      {/* topo: logo + tag */}
      <header className="gate-header">
        <div className="gate-brand">
          <img src="assets/ezza-icon.svg" alt="" />
          <span>ezza<em>CRM</em></span>
        </div>
        <div className="gate-tag">
          <span className="gate-tag-dot" />
          Online · 500+ times ativos agora
        </div>
      </header>

      <div className={`gate-split gate-hover-${hover || 'none'}`}>
        {/* ESQUERDA — DEMO */}
        <button
          className="gate-half gate-demo"
          onMouseEnter={() => setHover('demo')}
          onClick={onDemo}
        >
          <div className="gate-half-bg">
            {/* avatares flutuantes */}
            {[
              { i: 10, x: '15%', y: '20%', d: 0 },
              { i: 22, x: '70%', y: '15%', d: 1.2 },
              { i: 33, x: '85%', y: '60%', d: 2.4 },
              { i: 44, x: '20%', y: '70%', d: 3.6 },
              { i: 55, x: '55%', y: '80%', d: 1.8 },
              { i: 12, x: '5%',  y: '45%', d: 0.6 },
            ].map((a, k) => (
              <img key={k}
                className="gate-fav"
                src={`https://i.pravatar.cc/120?img=${a.i}`}
                style={{ left: a.x, top: a.y, animationDelay: `${a.d}s` }}
                alt=""
              />
            ))}
          </div>

          <div className="gate-half-content">
            <div className="gate-half-eyebrow">NÃO TENHO CONTA</div>
            <div className="gate-half-title">
              Quero conhecer<br/>a Ezza <em>por dentro</em>.
            </div>
            <div className="gate-half-sub">
              Entre na demo com dados fictícios.<br/>
              Nada pra cadastrar, nada pra instalar.
            </div>

            <div className="gate-half-cta">
              <span>Iniciar demo gratuita</span>
              <span className="gate-arrow">{ICN.arrowRight}</span>
            </div>

            <div className="gate-half-meta">
              <span className="gate-meta-pill">~ 30 segundos</span>
              <span className="gate-meta-pill">Sem cartão</span>
              <span className="gate-meta-pill">12 telas · dados reais</span>
            </div>
          </div>
        </button>

        {/* divisor diagonal */}
        <div className="gate-slash">
          <span>ou</span>
        </div>

        {/* DIREITA — LOGIN */}
        <button
          className="gate-half gate-login"
          onMouseEnter={() => setHover('login')}
          onClick={onLogin}
        >
          <div className="gate-half-bg gate-login-bg">
            {/* mini cards flutuantes */}
            <div className="gate-card gate-card-1">
              <div className="gate-card-h">
                <div className="gate-card-dot gate-card-dot-pink" />
                <span>Tecnoluz Solar</span>
              </div>
              <div className="gate-card-v">R$ 482k</div>
            </div>
            <div className="gate-card gate-card-2">
              <div className="gate-card-h">
                <div className="gate-card-dot gate-card-dot-mint" />
                <span>Editora Pampa</span>
              </div>
              <div className="gate-card-v">R$ 128k</div>
            </div>
            <div className="gate-card gate-card-3">
              <div className="gate-card-h">
                <div className="gate-card-dot gate-card-dot-yellow" />
                <span>Café do Vale</span>
              </div>
              <div className="gate-card-v">R$ 64k</div>
            </div>
          </div>

          <div className="gate-half-content">
            <div className="gate-half-eyebrow">JÁ SOU CLIENTE</div>
            <div className="gate-half-title">
              Entrar na<br/>minha <em>conta</em>.
            </div>
            <div className="gate-half-sub">
              Acesse seu workspace com e-mail e senha,<br/>
              ou pelo SSO da sua empresa.
            </div>

            <div className="gate-half-cta gate-cta-dark">
              <span>Acessar conta</span>
              <span className="gate-arrow">{ICN.arrowRight}</span>
            </div>

            <div className="gate-half-meta">
              <span className="gate-meta-pill gate-meta-pill-light">E-mail + senha</span>
              <span className="gate-meta-pill gate-meta-pill-light">SSO Google</span>
              <span className="gate-meta-pill gate-meta-pill-light">2FA</span>
            </div>
          </div>
        </button>
      </div>

      {/* ── Barra "Acesse meu CRM" ── */}
      <form className="gate-access-bar" onSubmit={acessarCRM}>
        <div className="gate-access-label">Já é cliente?</div>
        <div className="gate-access-wrap">
          <span className="gate-access-pre">ezzacrm.com.br/</span>
          <input
            className="gate-access-input"
            type="text"
            placeholder="suaempresa"
            value={slug}
            onChange={e => { setSlug(e.target.value); setSlugErro(''); }}
            autoCapitalize="none"
            autoCorrect="off"
            spellCheck="false"
          />
          <button className="gate-access-btn" type="submit">
            Acessar {ICN.arrowRight}
          </button>
        </div>
        {slugErro && <div className="gate-access-erro">{slugErro}</div>}
      </form>

      <footer className="gate-foot">
        <span>v2.6.1</span>
        <span>·</span>
        <a href="#">Termos</a>
        <span>·</span>
        <a href="#">Privacidade</a>
        <span>·</span>
        <a href="#">Status</a>
      </footer>

      <GateStyles />
    </div>
  );
}

function GateStyles() {
  return (
    <style>{`
      .gate-root {
        position: fixed; inset: 0;
        font-family: var(--font-ui);
        overflow: hidden;
        background: oklch(0.97 0.015 95);
      }
      .gate-blob {
        position: absolute; border-radius: 50%;
        filter: blur(120px); opacity: 0.4;
        pointer-events: none;
        animation: ll-float 16s ease-in-out infinite;
      }
      .gate-blob-1 { width: 600px; height: 600px; background: var(--acc-pink); top: -200px; left: -100px; }
      .gate-blob-2 { width: 600px; height: 600px; background: var(--acc-blue); bottom: -200px; right: -100px; animation-delay: -8s; }

      .gate-header {
        position: absolute; top: 32px; left: 0; right: 0;
        display: flex; justify-content: space-between; align-items: center;
        padding: 0 48px;
        z-index: 10;
        pointer-events: none;
      }
      .gate-header > * { pointer-events: auto; }
      .gate-brand {
        display: flex; align-items: center; gap: 12px;
        font-size: 18px; font-weight: 700; letter-spacing: -0.01em;
        color: var(--ink);
      }
      .gate-brand img { width: 32px; height: 32px; }
      .gate-brand em { font-family: var(--font-display); font-style: italic; font-weight: 400; }
      .gate-tag {
        display: flex; align-items: center; gap: 8px;
        font-size: 11.5px; font-weight: 600; color: var(--ink-soft);
        background: white; padding: 7px 14px; border-radius: 999px;
        box-shadow: 0 4px 14px -8px rgba(20,30,60,.18);
      }
      .gate-tag-dot {
        width: 8px; height: 8px; border-radius: 50%;
        background: var(--ok);
        box-shadow: 0 0 0 0 var(--ok);
        animation: ll-pulse 1.8s ease-in-out infinite;
      }

      .gate-split {
        position: relative;
        width: 100%; height: 100%;
        display: grid; grid-template-columns: 1fr 1fr;
        transition: grid-template-columns .55s cubic-bezier(.2,.8,.2,1);
      }
      .gate-hover-demo  { grid-template-columns: 1.35fr 1fr; }
      .gate-hover-login { grid-template-columns: 1fr 1.35fr; }

      .gate-half {
        position: relative;
        border: none;
        cursor: default;
        font-family: inherit;
        text-align: left;
        overflow: hidden;
        padding: 0;
        transition: transform .4s cubic-bezier(.2,.8,.2,1);
      }
      .gate-half:focus-visible { outline: 3px solid var(--acc-blue-strong); outline-offset: -8px; }

      /* DEMO half */
      .gate-demo {
        background:
          radial-gradient(600px 400px at 30% 70%, oklch(0.94 0.06 95) 0%, transparent 60%),
          oklch(0.95 0.04 95);
      }
      .gate-demo:hover { background:
          radial-gradient(600px 400px at 30% 70%, oklch(0.93 0.08 95) 0%, transparent 60%),
          oklch(0.94 0.05 95); }

      /* LOGIN half */
      .gate-login {
        background:
          radial-gradient(600px 400px at 70% 30%, oklch(0.30 0.05 250) 0%, transparent 60%),
          oklch(0.20 0.012 255);
        color: white;
      }
      .gate-login:hover { background:
          radial-gradient(600px 400px at 70% 30%, oklch(0.34 0.07 250) 0%, transparent 60%),
          oklch(0.22 0.012 255); }

      .gate-half-bg {
        position: absolute; inset: 0;
        pointer-events: none;
        opacity: 0.85;
      }

      /* floating avatars (demo) */
      .gate-fav {
        position: absolute;
        width: 56px; height: 56px; border-radius: 50%;
        border: 3px solid white;
        box-shadow: 0 12px 28px -10px rgba(20,30,60,.25);
        object-fit: cover;
        animation: gate-float 6s ease-in-out infinite;
      }
      @keyframes gate-float {
        0%, 100% { transform: translateY(0) rotate(-2deg); }
        50%      { transform: translateY(-12px) rotate(2deg); }
      }

      /* floating cards (login) */
      .gate-card {
        position: absolute;
        background: oklch(0.28 0.012 255);
        border: 0.5px solid oklch(0.36 0.012 255);
        border-radius: 14px;
        padding: 12px 14px;
        min-width: 180px;
        box-shadow: 0 16px 36px -12px rgba(0,0,0,.4);
        animation: gate-float 7s ease-in-out infinite;
      }
      .gate-card-1 { top: 16%;  right: 8%; animation-delay: 0s; }
      .gate-card-2 { top: 50%;  right: 24%; animation-delay: -2.5s; }
      .gate-card-3 { top: 75%;  right: 12%; animation-delay: -4.5s; }
      .gate-card-h { display: flex; align-items: center; gap: 8px; font-size: 11px; font-weight: 600; color: oklch(0.85 0.012 255); }
      .gate-card-dot { width: 8px; height: 8px; border-radius: 50%; }
      .gate-card-dot-pink { background: var(--acc-pink); }
      .gate-card-dot-mint { background: var(--acc-mint); }
      .gate-card-dot-yellow { background: var(--acc-yellow); }
      .gate-card-v {
        font-family: var(--font-mono);
        font-size: 17px; font-weight: 700;
        letter-spacing: -0.02em;
        color: white;
        margin-top: 6px;
      }

      .gate-half-content {
        position: relative;
        z-index: 2;
        padding: 110px 56px;
        height: 100%;
        display: flex; flex-direction: column;
        justify-content: center;
        max-width: 520px;
      }
      .gate-demo .gate-half-content { margin-left: auto; align-items: flex-start; }
      .gate-login .gate-half-content { }

      .gate-half-eyebrow {
        font-size: 10.5px;
        font-weight: 700;
        letter-spacing: 0.14em;
        color: var(--ink-muted);
        margin-bottom: 24px;
      }
      .gate-login .gate-half-eyebrow { color: oklch(0.70 0.012 255); }

      .gate-half-title {
        font-family: var(--font-display);
        font-size: 52px;
        line-height: 1.05;
        letter-spacing: -0.025em;
        color: var(--ink);
        margin-bottom: 22px;
      }
      .gate-login .gate-half-title { color: white; }
      .gate-half-title em {
        font-style: italic;
        background: linear-gradient(95deg, oklch(0.55 0.16 250) 0%, oklch(0.62 0.18 25) 100%);
        -webkit-background-clip: text;
        background-clip: text;
        color: transparent;
      }
      .gate-login .gate-half-title em {
        background: linear-gradient(95deg, var(--acc-blue) 0%, var(--acc-pink) 100%);
        -webkit-background-clip: text;
        background-clip: text;
        color: transparent;
      }

      .gate-half-sub {
        font-size: 15px;
        color: var(--ink-soft);
        line-height: 1.5;
        margin-bottom: 36px;
      }
      .gate-login .gate-half-sub { color: oklch(0.78 0.012 255); }

      .gate-half-cta {
        display: inline-flex; align-items: center; gap: 14px;
        background: var(--ink);
        color: white;
        padding: 16px 22px;
        border-radius: 999px;
        font-size: 15px; font-weight: 600;
        letter-spacing: -0.005em;
        transition: gap .3s, transform .15s, box-shadow .3s;
        align-self: flex-start;
        box-shadow: 0 12px 28px -12px rgba(20,30,60,.4);
      }
      .gate-cta-dark {
        background: white;
        color: var(--ink);
      }
      .gate-half:hover .gate-half-cta { gap: 22px; box-shadow: 0 18px 36px -10px rgba(20,30,60,.5); }
      .gate-half:active .gate-half-cta { transform: scale(0.98); }
      .gate-arrow { display: inline-flex; transition: transform .3s; }
      .gate-half:hover .gate-arrow { transform: translateX(4px); }

      .gate-half-meta {
        display: flex; gap: 8px; flex-wrap: wrap;
        margin-top: 28px;
      }
      .gate-meta-pill {
        font-size: 10.5px; font-weight: 600;
        padding: 5px 10px;
        background: oklch(1 0 0 / 0.55);
        border-radius: 999px;
        color: var(--ink-soft);
        backdrop-filter: blur(6px);
      }
      .gate-meta-pill-light {
        background: oklch(1 0 0 / 0.08);
        color: oklch(0.82 0.012 255);
      }

      /* diagonal slash divider */
      .gate-slash {
        position: absolute; top: 0; bottom: 0;
        left: 50%; transform: translateX(-50%);
        width: 80px;
        display: grid; place-items: center;
        pointer-events: none;
        z-index: 3;
        transition: left .55s cubic-bezier(.2,.8,.2,1);
      }
      .gate-hover-demo  .gate-slash { left: 57.45%; }
      .gate-hover-login .gate-slash { left: 42.55%; }
      .gate-slash span {
        font-family: var(--font-display);
        font-style: italic;
        font-size: 22px;
        background: white;
        color: var(--ink-muted);
        width: 48px; height: 48px;
        display: grid; place-items: center;
        border-radius: 50%;
        box-shadow: 0 8px 20px -6px rgba(20,30,60,.25);
      }

      .gate-foot {
        position: absolute; bottom: 24px; left: 0; right: 0;
        display: flex; justify-content: center; gap: 10px;
        font-size: 11px;
        color: oklch(1 0 0 / 0.7);
        font-family: var(--font-mono);
        z-index: 10;
        mix-blend-mode: difference;
      }
      .gate-foot a { color: inherit; text-decoration: none; }

      /* ── Barra de acesso rápido ao CRM ── */
      .gate-access-bar {
        position: absolute;
        bottom: 64px; left: 50%; transform: translateX(-50%);
        z-index: 10;
        display: flex; flex-direction: column; align-items: center; gap: 6px;
        animation: lr-rise 0.6s 0.4s cubic-bezier(.2,.8,.2,1) backwards;
      }
      .gate-access-label {
        font-size: 11px; font-weight: 700; letter-spacing: 0.10em;
        text-transform: uppercase; color: oklch(0.55 0.012 255);
      }
      .gate-access-wrap {
        display: flex; align-items: center;
        background: white;
        border-radius: 14px;
        box-shadow: 0 12px 36px -12px rgba(20,30,60,.28), 0 0 0 1px oklch(0.92 0.012 255);
        overflow: hidden;
        height: 48px;
      }
      .gate-access-pre {
        padding: 0 0 0 16px;
        font-size: 13px; font-weight: 500;
        color: var(--ink-muted);
        white-space: nowrap;
        font-family: var(--font-mono);
        user-select: none;
      }
      .gate-access-input {
        border: none; outline: none;
        font-family: var(--font-mono);
        font-size: 13px; font-weight: 600;
        color: var(--ink);
        width: 140px;
        padding: 0 8px;
        background: transparent;
      }
      .gate-access-input::placeholder { color: oklch(0.78 0.01 255); font-weight: 400; }
      .gate-access-btn {
        height: 100%;
        padding: 0 18px;
        background: var(--ink);
        color: white;
        border: none;
        font-family: inherit; font-size: 13px; font-weight: 600;
        cursor: pointer;
        display: flex; align-items: center; gap: 7px;
        letter-spacing: -0.005em;
        transition: background .15s;
        white-space: nowrap;
        border-radius: 0 14px 14px 0;
      }
      .gate-access-btn svg { width: 14px; height: 14px; }
      .gate-access-btn:hover { background: oklch(0.18 0.01 255); }
      .gate-access-erro {
        font-size: 11.5px; color: oklch(0.50 0.16 18); font-weight: 500;
      }

      @media (max-width: 900px) {
        .gate-split { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
        .gate-hover-demo, .gate-hover-login { grid-template-columns: 1fr; }
        .gate-slash { display: none; }
        .gate-half-content { padding: 80px 32px; max-width: none; }
        .gate-half-title { font-size: 44px; }
      }
    `}</style>
  );
}

// ═════════════════════════════════════════════════════════════════
// DemoBanner — barra inferior fixa quando o app está em modo demo
// ═════════════════════════════════════════════════════════════════

function DemoBanner({ onExit, onSignup }) {
  return (
    <div className="demo-banner">
      <div className="demo-banner-tag">DEMO</div>
      <div className="demo-banner-text">
        <strong>Você está explorando a Ezza com dados fictícios.</strong>
        <span> Nada que você fizer aqui é salvo de verdade.</span>
      </div>
      <button className="demo-banner-cta" onClick={onSignup}>
        Criar conta gratuita {ICN.arrowRight}
      </button>
      <button className="demo-banner-exit" onClick={onExit} title="Sair da demo">
        {ICN.x || '×'}
      </button>

      <style>{`
        .demo-banner {
          position: fixed; bottom: 16px; left: 50%;
          transform: translateX(-50%);
          display: flex; align-items: center; gap: 14px;
          background: var(--ink);
          color: white;
          padding: 10px 12px 10px 16px;
          border-radius: 999px;
          box-shadow: 0 20px 48px -16px rgba(20,30,60,.55), 0 4px 12px -4px rgba(20,30,60,.3);
          z-index: 150;
          font-size: 13px;
          max-width: calc(100% - 32px);
          animation: demo-pop .5s cubic-bezier(.2,.8,.2,1);
        }
        @keyframes demo-pop {
          from { opacity: 0; transform: translateX(-50%) translateY(12px); }
          to   { opacity: 1; transform: translateX(-50%) translateY(0); }
        }
        .demo-banner-tag {
          font-size: 10px; font-weight: 800;
          letter-spacing: 0.12em;
          padding: 4px 10px;
          background: linear-gradient(95deg, var(--acc-pink), var(--acc-yellow));
          color: oklch(0.22 0.04 18);
          border-radius: 999px;
          flex-shrink: 0;
        }
        .demo-banner-text {
          font-weight: 500;
          letter-spacing: -0.005em;
          color: oklch(0.95 0.012 255);
        }
        .demo-banner-text strong { font-weight: 700; color: white; }
        .demo-banner-cta {
          display: inline-flex; align-items: center; gap: 6px;
          background: white;
          color: var(--ink);
          font-family: inherit;
          font-size: 12.5px;
          font-weight: 600;
          padding: 8px 14px 8px 16px;
          border: none;
          border-radius: 999px;
          cursor: default;
          letter-spacing: -0.005em;
          transition: gap .2s, transform .12s;
          flex-shrink: 0;
        }
        .demo-banner-cta:hover { gap: 10px; }
        .demo-banner-cta:active { transform: scale(0.97); }
        .demo-banner-cta svg { width: 14px; height: 14px; }
        .demo-banner-exit {
          width: 32px; height: 32px;
          border-radius: 50%;
          background: oklch(1 0 0 / 0.08);
          color: oklch(0.85 0.012 255);
          border: none;
          display: grid; place-items: center;
          cursor: default;
          flex-shrink: 0;
          transition: background .15s;
          font-family: inherit;
        }
        .demo-banner-exit:hover { background: oklch(1 0 0 / 0.15); color: white; }
        .demo-banner-exit svg { width: 14px; height: 14px; }
        @media (max-width: 720px) {
          .demo-banner-text { display: none; }
        }
      `}</style>
    </div>
  );
}

Object.assign(window, { LoginScreen, SplashScreen, EntryGate, DemoBanner });

