const chatModal = document.getElementById('chatModal');
document.getElementById('openChatBtn').addEventListener('click', (e)=>{ e.preventDefault(); chatModal.classList.add('open'); });
document.getElementById('closeChatBtn').addEventListener('click', ()=> chatModal.classList.remove('open'));
document.getElementById('demoBtn').addEventListener('click', ()=>{
const feed = document.getElementById('feed'); const msg = document.createElement('div');
msg.className='bubble bot'; msg.textContent='Demo: creăm o factură, trimitem clientului, confirmă în 24 secunde.';
feed.appendChild(msg); feed.scrollTop = feed.scrollHeight;
});
document.getElementById('contactBtn').addEventListener('click', ()=>{
const feed = document.getElementById('feed'); const msg = document.createElement('div');
msg.className='bubble bot'; msg.innerHTML='Contact: <a href="mailto:contact@softaga.com">contact@softaga.com</a>';
feed.appendChild(msg); feed.scrollTop = feed.scrollHeight;
});
const form = document.getElementById('signup');
const msg = document.getElementById('msg');
const ctaBtn = document.getElementById('ctaBtn');
form.addEventListener('submit', async (ev)=>{
ev.preventDefault();
msg.style.color='var(--muted)'; msg.textContent='Se procesează…';
ctaBtn.disabled=true;
try{
const fd = new FormData(form);
const res = await fetch('', { method:'POST', body:fd });
const contentType = res.headers.get('content-type') || '';
let data = null;
if (contentType.includes('application/json')) data = await res.json();
else {
const txt = await res.text();
try { data = JSON.parse(txt); }
catch(e){ throw new Error('Serverul a răspuns cu HTML. Verifică dacă fișierul e salvat ca index.php și că rulează PHP.'); }
}
if(!res.ok || !data.success){ throw new Error(data.message || 'Eroare la server'); }
msg.style.color='var(--confirm)'; msg.textContent=data.message || 'Mulțumim!';
animateLogoPress(true); confetti(); form.reset(); closeModal();
}catch(e){
msg.style.color='#FF445D'; msg.textContent=e.message || 'Nu am putut salva. Încearcă din nou.';
} finally {
setTimeout(()=>{ ctaBtn.disabled=false; }, 900);
}
});
document.getElementById('year').textContent=(new Date()).getFullYear();
</script>
</body>
</html>