(function(){
var sidebar=document.querySelector('.faq-sidebar');
if(sidebar){
sidebar.addEventListener('click',function(e){
var btn=e.target.closest('.faq-cat-link');
if(!btn)return;
var links=document.querySelectorAll('.faq-cat-link');
for(var i=0;i<links.length;i++)links[i].classList.remove('active');
btn.classList.add('active');
var catName=btn.getAttribute('data-cat');
switchFaqCat(catName);
var sel=document.getElementById('faq-mobile-select');
if(sel)sel.value=catName;
});
}
var mobileSelect=document.getElementById('faq-mobile-select');
if(mobileSelect){
mobileSelect.addEventListener('change',function(){
var catName=this.value;
switchFaqCat(catName);
var links=document.querySelectorAll('.faq-cat-link');
for(var i=0;i<links.length;i++){
links[i].classList.toggle('active',links[i].getAttribute('data-cat')===catName);
}
});
}
function switchFaqCat(catName){
var contents=document.querySelectorAll('.faq-cat-content');
for(var j=0;j<contents.length;j++){
contents[j].style.display=(contents[j].getAttribute('data-cat')===catName)?'':'none';
}
}
document.addEventListener('click',function(e){
var btn=e.target.closest('[data-action="toggle-fq"]');
if(!btn)return;
var item=btn.parentElement;
var wasOpen=item.classList.contains('open');
var answerWrap=item.querySelector('.fq-answer-wrap');
if(wasOpen){
answerWrap.style.maxHeight='0';
answerWrap.style.paddingBottom='0';
item.classList.remove('open');
}else{
var siblings=item.parentElement.querySelectorAll('.fq-item.open');
for(var i=0;i<siblings.length;i++){
var sw=siblings[i].querySelector('.fq-answer-wrap');
if(sw){sw.style.maxHeight='0';sw.style.paddingBottom='0';}
siblings[i].classList.remove('open');
}
item.classList.add('open');
answerWrap.style.maxHeight=answerWrap.scrollHeight+'px';
answerWrap.style.paddingBottom='18px';
}
});
})();
