<!-- Main Navigation Bar -->
<div
  id="main-nav"
  class="fixed top-9 left-0 w-full bg-surface/95 backdrop-blur-xl z-40
         transition-all duration-300 shadow-sm"
>
  <div class="max-w-7xl mx-auto px-4">
    <div class="flex items-center justify-between h-20">

      <!-- Logo -->
      <a href="<?= base_url('/') ?>" class="block">
        <img
          src="<?= base_url('assets/images/logo.svg') ?>"
          alt="Mount Kenya Treks & Safaris"
          class="h-10 sm:h-12 max-w-[180px] object-contain
                 transition-transform duration-300 hover:scale-105"
        >
      </a>

      <!-- Desktop Navigation -->
      <nav class="hidden lg:flex items-center gap-1">

        <!-- Active example -->
        <a href="<?= base_url('/') ?>"
           class="px-4 py-2 text-[11px] font-bold uppercase tracking-[0.15em]
                  rounded-xl transition-all duration-300
                  text-secondary bg-primary/5">
          Home
        </a>

        <a href="#routes"
           class="px-4 py-2 text-[11px] font-bold uppercase tracking-[0.15em]
                  rounded-xl transition-all duration-300
                  text-navy hover:text-secondary hover:bg-primary/5">
          Routes
        </a>

        <a href="<?= base_url('tours') ?>"
           class="px-4 py-2 text-[11px] font-bold uppercase tracking-[0.15em]
                  rounded-xl transition-all duration-300
                  text-navy hover:text-secondary hover:bg-primary/5">
          Tours
        </a>

        <a href="<?= base_url('blog') ?>"
           class="px-4 py-2 text-[11px] font-bold uppercase tracking-[0.15em]
                  rounded-xl transition-all duration-300
                  text-navy hover:text-secondary hover:bg-primary/5">
          Blog
        </a>
      </nav>

      <!-- Book Now -->
      <a
        href="<?= base_url('booking') ?>"
        class="whitespace-nowrap font-bold uppercase tracking-widest
               rounded-full shadow-md hover:shadow-lg
               transition-all duration-300
               focus:outline-none focus:ring-2 focus:ring-secondary/50
               lg:ml-6 lg:px-6 lg:py-3 lg:text-[11px]
               px-4 py-2 text-[10px]
               bg-gradient-to-r from-secondary to-accent
               text-surface hover:scale-[1.02]"
      >
        Book Now
      </a>

      <!-- Mobile Menu Button -->
      <button
        id="mobile-menu-button"
        class="lg:hidden flex flex-col justify-center items-center
               w-8 h-8 ml-4 rounded-md transition"
      >
        <span class="block w-6 h-0.5 bg-navy mb-1 transition-all duration-300"></span>
        <span class="block w-6 h-0.5 bg-navy mb-1 transition-all duration-300"></span>
        <span class="block w-6 h-0.5 bg-navy transition-all duration-300"></span>
      </button>

    </div>
  </div>
</div>

<!-- Mobile Menu -->
<div
  id="mobile-menu"
  class="fixed top-[116px] left-0 w-full h-[calc(100vh-116px)]
         bg-surface z-30 shadow-2xl
         transform -translate-x-full transition-transform duration-300
         lg:hidden overflow-y-auto"
>
  <div class="max-w-7xl mx-auto px-6 py-8">

    <ul class="space-y-3">
      <li>
        <a href="<?= base_url('/') ?>"
           class="block px-4 py-3 text-xl font-bold rounded-xl
                  text-secondary bg-primary/5">
          Home
        </a>
      </li>

      <li>
        <a href="<?= base_url('routes') ?>"
           class="block px-4 py-3 text-xl font-bold rounded-xl
                  text-navy hover:text-secondary hover:bg-primary/5 transition">
          Routes
        </a>
      </li>

      <li>
        <a href="<?= base_url('tours') ?>"
           class="block px-4 py-3 text-xl font-bold rounded-xl
                  text-navy hover:text-secondary hover:bg-primary/5 transition">
          Tours
        </a>
      </li>

      <li>
        <a href="<?= base_url('blog') ?>"
           class="block px-4 py-3 text-xl font-bold rounded-xl
                  text-navy hover:text-secondary hover:bg-primary/5 transition">
          Blog
        </a>
      </li>
    </ul>

    <!-- Mobile Book Now -->
    <div class="mt-8 pt-6 border-t border-border">
      <a
        href="<?= base_url('booking') ?>"
        class="block w-full py-3 text-center
               bg-gradient-to-r from-secondary to-accent
               text-surface font-bold text-sm rounded-xl"
      >
        Book Now
      </a>
    </div>

  </div>
</div>

<script>
(function () {
  const mobileBtn = document.getElementById('mobile-menu-button');
  const mobileMenu = document.getElementById('mobile-menu');
  const mainNav = document.getElementById('main-nav');
  const safetyBar = document.getElementById('safety-bar');
  const links = document.querySelectorAll('nav a, .mobile-menu a');
  let lastScrollY = window.scrollY;

  // Active link handling
  const path = window.location.pathname;
  document.querySelectorAll('a[href]').forEach(link => {
    const href = link.getAttribute('href');
    if (!href) return;

    const isActive =
      (href === '/' && path === '/') ||
      (href !== '/' && path.startsWith(href));

    if (isActive) {
      link.classList.add('text-secondary', 'bg-primary/5');
    }
  });

  // Mobile toggle
  mobileBtn.addEventListener('click', () => {
    mobileMenu.classList.toggle('-translate-x-full');
    mobileBtn.classList.toggle('bg-navy/10');
  });

  // Outside click close
  document.addEventListener('click', (e) => {
    if (
      !mobileMenu.contains(e.target) &&
      !mobileBtn.contains(e.target) &&
      !mobileMenu.classList.contains('-translate-x-full')
    ) {
      mobileMenu.classList.add('-translate-x-full');
      mobileBtn.classList.remove('bg-navy/10');
    }
  });

  // Scroll hide/show
  window.addEventListener('scroll', () => {
    const y = window.scrollY;
    const hide = y > lastScrollY && y > 80;
    mainNav.classList.toggle('-translate-y-full', hide);
    safetyBar?.classList.toggle('-translate-y-full', hide);
    lastScrollY = y;
  });

  // Reset on resize
  window.addEventListener('resize', () => {
    if (window.innerWidth >= 1024) {
      mobileMenu.classList.add('-translate-x-full');
      mobileBtn.classList.remove('bg-navy/10');
    }
  });
})();
</script>
