const revealItems=document.querySelectorAll('.reveal');
const io=new IntersectionObserver((entries)=>{entries.forEach(e=>{if(e.isIntersecting){e.target.classList.add('visible');io.unobserve(e.target)}})},{threshold:.12});
revealItems.forEach(el=>io.observe(el));
document.querySelectorAll('.accordion button').forEach(btn=>{btn.addEventListener('click',()=>{const panel=btn.nextElementSibling;panel.classList.toggle('open');btn.querySelector('span').textContent=panel.classList.contains('open')?'−':'+'})});
const form=document.querySelector('#leadForm');if(form){form.addEventListener('submit',async(e)=>{e.preventDefault();const btn=form.querySelector('button');const msg=form.querySelector('.form-message');const old=btn.textContent;btn.textContent='Отправка...';btn.disabled=true;try{const res=await fetch('send.php',{method:'POST',body:new FormData(form)});const data=await res.json();msg.textContent=data.message||'Заявка отправлена';msg.style.color=data.success?'#67e8a5':'#ff8a8a';if(data.success)form.reset()}catch(err){msg.textContent='Ошибка отправки. Позвоните нам напрямую.';msg.style.color='#ff8a8a'}finally{btn.textContent=old;btn.disabled=false}})}