(function(){
  const body=document.body;
  const toggle=document.querySelector('[data-front-menu-toggle]');
  const nav=document.getElementById('front-nav');
  const overlay=document.querySelector('[data-front-menu-overlay]');
  const closeFrontMenu=()=>{body.classList.remove('front-menu-open'); if(toggle) toggle.setAttribute('aria-expanded','false');};
  if(toggle && nav){
    toggle.addEventListener('click',()=>{const open=!body.classList.contains('front-menu-open');body.classList.toggle('front-menu-open',open);toggle.setAttribute('aria-expanded',open?'true':'false');});
    nav.querySelectorAll('a').forEach(a=>a.addEventListener('click',closeFrontMenu));
  }
  if(overlay) overlay.addEventListener('click',closeFrontMenu);
  const preloader=document.querySelector('[data-preloader]');
  const showLoader=()=>{ if(preloader){ preloader.classList.add('is-active'); preloader.setAttribute('aria-hidden','false'); } };
  const hideLoader=()=>{ if(preloader){ preloader.classList.remove('is-active'); preloader.setAttribute('aria-hidden','true'); } };
  window.addEventListener('pageshow',hideLoader);
  document.querySelectorAll('form').forEach(form=>form.addEventListener('submit',()=>showLoader()));
  document.addEventListener('click',(event)=>{const link=event.target.closest('a'); if(!link) return; const href=link.getAttribute('href')||''; if(!href || href.startsWith('#') || href.startsWith('mailto:') || href.startsWith('tel:') || link.target==='_blank' || link.hasAttribute('download')) return; showLoader();});
})();
