(function(){
  var key='uneed_cookies_uneed_cabeleireiros';
  var banner=document.getElementById('cookie-banner');
  function save(value){localStorage.setItem(key,JSON.stringify({value:value,ts:Date.now()})); if(banner)banner.hidden=true; if(value==='accept')loadTracking();}
  function loadTracking(){
    var cfg=window.UNEED_TRACKING||{};
    if(cfg.ga4Id&&cfg.ga4Id.indexOf('X')===-1){var s=document.createElement('script');s.async=true;s.src='https://www.googletagmanager.com/gtag/js?id='+cfg.ga4Id;document.head.appendChild(s);window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments)}window.gtag=gtag;gtag('js',new Date());gtag('config',cfg.ga4Id);}
  }
  window.uneedCookieSettings=function(){if(banner)banner.hidden=false;};
  document.addEventListener('click',function(e){var b=e.target.closest('[data-cookie]'); if(!b)return; e.preventDefault(); var v=b.getAttribute('data-cookie'); if(v==='settings'){save('essential');} else {save(v);}});
  document.addEventListener('click',function(e){if(e.target.closest('.js-cookie-settings')){e.preventDefault();window.uneedCookieSettings();}});
  try{var stored=JSON.parse(localStorage.getItem(key)||'null'); if(!stored&&banner)banner.hidden=false; if(stored&&stored.value==='accept')loadTracking();}catch(e){if(banner)banner.hidden=false;}
})();
