class NavManager {
  constructor() {
    this.topNav = document.getElementById('topNav');
    this.toggle = document.getElementById('navToggle');
    this.menu = document.getElementById('mobileMenu');
    this.menuOpen = false;
    this.init();
  }

  init() {
    if (this.topNav) {
      window.addEventListener('scroll', () => {
        this.topNav.classList.toggle('scrolled', scrollY > 60);
      }, { passive: true });
    }
    if (this.toggle && this.menu) {
      this.toggle.addEventListener('click', () => this.menuOpen ? this.close() : this.open());
      this.menu.querySelectorAll('.mobile-menu-link').forEach(l => l.addEventListener('click', () => this.close()));
      document.addEventListener('keydown', e => { if (e.key === 'Escape') this.close(); });
      window.addEventListener('resize', () => { if (innerWidth > 1024) this.close(); });
    }
  }

  open() {
    this.menuOpen = true;
    this.toggle.classList.add('active');
    this.toggle.setAttribute('aria-expanded', 'true');
    this.menu.classList.add('open');
    document.body.classList.add('menu-open');
  }

  close() {
    if (!this.menuOpen) return;
    this.menuOpen = false;
    this.toggle.classList.remove('active');
    this.toggle.setAttribute('aria-expanded', 'false');
    this.menu.classList.remove('open');
    document.body.classList.remove('menu-open');
  }
}
