(function(){'use strict';document.addEventListener('DOMContentLoaded',init);function init(){initThemeToggle();initMobileSidebar();initLanguageDropdown();initStickyHeader();}
function initThemeToggle(){var toggle=document.querySelector('.ap-theme-toggle');if(!toggle)return;toggle.addEventListener('click',function(){var html=document.documentElement;var isLight=html.classList.contains('light-theme');if(isLight){html.classList.remove('light-theme');localStorage.setItem('ap-theme','dark');}else{html.classList.add('light-theme');localStorage.setItem('ap-theme','light');}});}
function initMobileSidebar(){const hamburger=document.querySelector('.ap-hamburger');const sidebar=document.querySelector('.ap-sidebar');const overlay=document.querySelector('.ap-sidebar-overlay');const closeBtn=document.querySelector('.ap-sidebar__close');if(!hamburger||!sidebar)return;function openSidebar(){sidebar.classList.add('is-open');overlay&&overlay.classList.add('is-visible');hamburger.classList.add('is-open');hamburger.setAttribute('aria-expanded','true');document.body.style.overflow='hidden';const firstLink=sidebar.querySelector('a, button');if(firstLink)firstLink.focus();}
function closeSidebar(){sidebar.classList.remove('is-open');overlay&&overlay.classList.remove('is-visible');hamburger.classList.remove('is-open');hamburger.setAttribute('aria-expanded','false');document.body.style.overflow='';hamburger.focus();}
hamburger.addEventListener('click',function(){const isOpen=sidebar.classList.contains('is-open');isOpen?closeSidebar():openSidebar();});closeBtn&&closeBtn.addEventListener('click',closeSidebar);overlay&&overlay.addEventListener('click',closeSidebar);document.addEventListener('keydown',function(e){if(e.key==='Escape'&&sidebar.classList.contains('is-open')){closeSidebar();}});}
function initLanguageDropdown(){const langWidget=document.querySelector('.ap-lang');if(!langWidget)return;const trigger=langWidget.querySelector('.ap-lang__trigger');if(!trigger)return;trigger.addEventListener('click',function(e){e.stopPropagation();langWidget.classList.toggle('is-open');});document.addEventListener('click',function(e){if(!langWidget.contains(e.target)){langWidget.classList.remove('is-open');}});document.addEventListener('keydown',function(e){if(e.key==='Escape'){langWidget.classList.remove('is-open');}});}
function initStickyHeader(){const header=document.querySelector('.ap-header');if(!header)return;let ticking=false;window.addEventListener('scroll',function(){if(!ticking){window.requestAnimationFrame(function(){header.classList.toggle('is-scrolled',window.scrollY>10);ticking=false;});ticking=true;}},{passive:true});}})();