(function(){
    document.querySelectorAll('.epwf-accordion').forEach(function(accordion){
        var btns = accordion.querySelectorAll('.epwf-q');

        btns.forEach(function(btn){
            btn.addEventListener('click', function(){
                var isOpen   = btn.getAttribute('aria-expanded') === 'true';
                var panel    = document.getElementById(btn.getAttribute('aria-controls'));
                if(!panel) return;

                // Close all other items in this accordion
                btns.forEach(function(other){
                    if(other === btn) return;
                    other.setAttribute('aria-expanded','false');
                    var otherPanel = document.getElementById(other.getAttribute('aria-controls'));
                    if(otherPanel) otherPanel.setAttribute('hidden','');
                });

                // Toggle clicked item
                btn.setAttribute('aria-expanded', isOpen ? 'false' : 'true');
                if(isOpen){
                    panel.setAttribute('hidden','');
                } else {
                    panel.removeAttribute('hidden');
                }
            });
        });
    });
})();
