/**
 * KAZ Global JavaScript
 * Responsive Header and Mobile Navigation Toggle
 */
document.addEventListener('DOMContentLoaded', function () {
    const hamburger = document.getElementById('kazMobileHamburger');
    const closeBtn = document.getElementById('kazMobileClose');
    const overlay = document.getElementById('kazMobileOverlay');
    const overlayLinks = document.querySelectorAll('.kaz-mobile-nav-link');

    // Open mobile overlay
    if (hamburger && overlay) {
        hamburger.addEventListener('click', function () {
            overlay.classList.add('active');
            document.body.style.overflow = 'hidden'; // Prevent scrolling parent window
        });
    }

    // Close mobile overlay
    if (closeBtn && overlay) {
        closeBtn.addEventListener('click', function () {
            overlay.classList.remove('active');
            document.body.style.overflow = '';
        });
    }

    // Close menu when clicking on any navigation link
    overlayLinks.forEach(link => {
        link.addEventListener('click', function () {
            overlay.classList.remove('active');
            document.body.style.overflow = '';
        });
    });

    // Close menu when clicking outside of the active container (on the dark backdrop)
    if (overlay) {
        overlay.addEventListener('click', function (e) {
            if (e.target === overlay) {
                overlay.classList.remove('active');
                document.body.style.overflow = '';
            }
        });
    }
});
