add_action('wp_footer', function () {
    ?>
    <script>
    document.addEventListener('click', function (e) {
        // 1. Find the toggle button using the new class
        var btn = e.target.closest('.eco-menu-toggle');
        if (!btn) return;

        // 2. Target the panel immediately following the button
        var panel = btn.nextElementSibling; 
        var isExpanded = btn.getAttribute('aria-expanded') === 'true';

        // 3. Toggle accessibility state
        btn.setAttribute('aria-expanded', !isExpanded);
        
        // 4. Toggle visibility and the icon (+ / −)
        if (panel && panel.classList.contains('eco-menu-panel')) {
            panel.style.display = isExpanded ? 'none' : 'block';
            
            var icon = btn.querySelector('.eco-menu-icon');
            if (icon) {
                icon.textContent = isExpanded ? '+' : '−';
            }
        }
    });
    </script>
    <?php
});