(function(){function initMoronActividades(root){if(!root || root.dataset.maInit==='1') return;root.dataset.maInit='1';const q=root.querySelector('#q');const localidad=root.querySelector('#localidad');const tipo=root.querySelector('#tipo');const reset=root.querySelector('#reset');const sedes=Array.prototype.slice.call(root.querySelectorAll('.ma-sede'));const sections=Array.prototype.slice.call(root.querySelectorAll('.ma-localidad'));const count=root.querySelector('#count');const empty=root.querySelector('#empty');const norm=function(s){return (s || '') .toLowerCase() .normalize('NFD') .replace(/[\u0300-\u036f]/g,'') .trim()};function apply(){const tq=norm(q && q.value);const l=localidad ? localidad.value :'';const t=tipo ? tipo.value :'';let visibleSedes=0,visibleActs=0;sedes.forEach(function(card){const okL=!l || card.getAttribute('data-localidad')===l;const items=Array.prototype.slice.call(card.querySelectorAll('li'));let sedeTieneCoincidencias=false;items.forEach(function(li){const liText=norm(li.textContent);const categoria=li.getAttribute('data-categoria') || li.getAttribute('data-tipo') || '';const okQ=!tq || liText.indexOf(tq) !==-1;const okT=!t || categoria===t;const show=okL && okQ && okT;li.classList.toggle('ma-hidden',!show);if(show){sedeTieneCoincidencias=true;visibleActs++}});card.classList.toggle('ma-hidden',!sedeTieneCoincidencias);if(sedeTieneCoincidencias) visibleSedes++});sections.forEach(function(sec){const anyVisible=Array.prototype.slice.call(sec.querySelectorAll('.ma-sede')).some(function(el){return !el.classList.contains('ma-hidden')});sec.classList.toggle('ma-hidden',!anyVisible)});if(count){count.textContent=visibleActs + ' ' + (visibleActs===1 ? 'actividad':'actividades') + ' en ' + visibleSedes + ' ' + (visibleSedes===1 ? 'sede':'sedes')}if(empty){empty.classList.toggle('ma-hidden',visibleActs !==0)}}[q,localidad,tipo].filter(Boolean).forEach(function(el){el.addEventListener('input',apply,{passive:true});el.addEventListener('change',apply,{passive:true})});if(reset){reset.addEventListener('click',function(){if(q) q.value='';if(localidad) localidad.value='';if(tipo) tipo.value='';apply()})}apply()}function boot(context){var scope=context && context.querySelectorAll ? context:document;Array.prototype.slice.call(scope.querySelectorAll('#moron-actividades')).forEach(initMoronActividades)}// Carga inicial estándar if(document.readyState==='loading'){document.addEventListener('DOMContentLoaded',function(){boot(document)})}else{boot(document)}window.addEventListener('load',function(){boot(document)});// Elementor frontend hooks if(window.elementorFrontend && window.elementorFrontend.hooks){try{window.elementorFrontend.hooks.addAction('frontend/element_ready/global',function($scope){if($scope && $scope[0]) boot($scope[0])});window.elementorFrontend.hooks.addAction('frontend/element_ready/html.default',function($scope){if($scope && $scope[0]) boot($scope[0])}}// Observa bloques que Elementor / caché puedan inyectar tarde try{var mo=new MutationObserver(function(mutations){mutations.forEach(function(m){Array.prototype.slice.call(m.addedNodes || []).forEach(function(node){if(!node || node.nodeType !==1) return;if(node.id==='moron-actividades') initMoronActividades(node);else if(node.querySelectorAll) boot(node)})})});mo.observe(document.documentElement,{childList:true,subtree:true}// Reintentos cortos por si el HTML aparece después del JS var attempts=0;var timer=setInterval(function(){boot(document);attempts++;if(attempts>20) clearInterval(timer)},500)})();