/**
 * Cabinet de Avocat - JavaScript principal
 */
(function() {
    'use strict';

    // Header scroll effect
    const header = document.getElementById('header');
    let lastScroll = 0;

    window.addEventListener('scroll', function() {
        const currentScroll = window.pageYOffset;

        if (currentScroll > 50) {
            header.classList.add('header-scrolled');
        } else {
            header.classList.remove('header-scrolled');
        }

        lastScroll = currentScroll;
    });

    // Mobile menu toggle
    const menuToggle = document.getElementById('menuToggle');
    const nav = document.getElementById('nav');

    if (menuToggle) {
        menuToggle.addEventListener('click', function() {
            this.classList.toggle('active');
            nav.classList.toggle('nav-open');
            document.body.classList.toggle('menu-open');
        });
    }

    // Close mobile menu on link click
    document.querySelectorAll('.nav-link').forEach(function(link) {
        link.addEventListener('click', function() {
            if (nav.classList.contains('nav-open')) {
                menuToggle.classList.remove('active');
                nav.classList.remove('nav-open');
                document.body.classList.remove('menu-open');
            }
        });
    });

    // Smooth scroll to top on page load
    window.scrollTo(0, 0);

    // Animate elements on scroll
    const observerOptions = {
        threshold: 0.1,
        rootMargin: '0px 0px -50px 0px'
    };

    const observer = new IntersectionObserver(function(entries) {
        entries.forEach(function(entry) {
            if (entry.isIntersecting) {
                entry.target.classList.add('visible');
                observer.unobserve(entry.target);
            }
        });
    }, observerOptions);

    document.querySelectorAll('.card, .service-category, .article-card, .process-step, .timeline-item, .principle').forEach(function(el) {
        el.classList.add('animate-in');
        observer.observe(el);
    });

})();
