(function(){
  let shown=false; const modal=document.getElementById('exit-modal'); if(!modal) return;
  function show(){ if(shown) return; shown=true; modal.classList.add('show'); }
  document.addEventListener('mouseleave',(e)=>{ if(e.clientY<=0) show(); });
  document.getElementById('exit-close').addEventListener('click',()=>modal.classList.remove('show'));
  document.getElementById('exit-apply').addEventListener('click',()=>{
    const code=modal.dataset.code||'JANGANPERGI10'; const input=document.querySelector('input[name=coupon]'); if(input){ input.value=code; alert('Kod dimasukkan: '+code); }
    modal.classList.remove('show');
  });
})();