const $=(s,p=document)=>p.querySelector(s);const $$=(s,p=document)=>[...p.querySelectorAll(s)];
addEventListener('scroll',()=>document.body.classList.toggle('scrolled',scrollY>40));
const obs=new IntersectionObserver(es=>es.forEach(e=>{if(e.isIntersecting){e.target.classList.add('visible');obs.unobserve(e.target)}}),{threshold:.14});
$$('[data-reveal]').forEach(e=>obs.observe(e));
$$('.faq-item').forEach(item=>$('.faq-q',item).onclick=()=>{ $$('.faq-item').filter(i=>i!==item).forEach(i=>i.classList.remove('open')); item.classList.toggle('open')});
$$('a[href^="#"]').forEach(a=>a.onclick=e=>{const t=$(a.getAttribute('href'));if(t){e.preventDefault();t.scrollIntoView({behavior:'smooth'})}});
const f=$('#leadForm');if(f)f.onsubmit=async e=>{e.preventDefault();const m=$('.form-message'),b=f.querySelector('button');const old=b.textContent;b.textContent='Отправка...';b.disabled=1;try{const r=await fetch('send.php',{method:'POST',body:new FormData(f)});const d=await r.json();m.textContent=d.message||'Заявка отправлена.';m.className='form-message '+(d.success?'ok':'bad');if(d.success)f.reset()}catch(_){m.textContent='Не удалось отправить. Напишите в WhatsApp.';m.className='form-message bad'}b.textContent=old;b.disabled=0};
