async function doLogin() { const email = document.getElementById('gateEmail').value.trim(); const err = document.getElementById('gateError'); const btn = document.getElementById('gateBtn'); if (!email || !email.includes('@')) { err.textContent = 'Informe um e-mail válido.'; err.classList.add('show'); return; } btn.textContent = 'Verificando…'; btn.disabled = true; try { const res = await fetch('/api/check-access.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email }) }); const data = await res.json(); if (data.ok) { document.getElementById('gate').style.display = 'none'; document.getElementById('app').style.display = 'flex'; render(); } else { const msgs = { not_found: 'E-mail não encontrado. Use o mesmo e-mail do cadastro.', inactive: 'Seu acesso está inativo. Entre em contato.', expired: 'Seu acesso expirou. Renove para continuar.', service_unavailable: 'Serviço temporariamente indisponível. Tente novamente.' }; err.textContent = msgs[data.reason] || 'Acesso negado.'; err.classList.add('show'); if (['not_found','expired'].includes(data.reason)) showCta(); } } catch(e) { err.textContent = 'Erro de conexão. Verifique sua internet.'; err.classList.add('show'); } btn.textContent = 'Acessar'; btn.disabled = false; }