/* ============================================
   TBM NAVIGATION - PROFESSIONAL REFACTORED
   Fixed: z-index, scroll visibility, mobile menu
   ============================================ */

/* ============================================
   NAVIGATION CONTAINER - ALWAYS ON TOP
   ============================================ */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    z-index: 9999;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(0, 166, 81, 0.1);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.navbar.scrolled {
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    border-bottom-color: rgba(0, 166, 81, 0.15);
}

/* iOS Safe Area Support */
.navbar {
    padding-top: max(env(safe-area-inset-top), 0px);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* ============================================
   NAVIGATION INNER CONTAINER
   ============================================ */
.navbar-container {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    position: relative;
    min-height: 60px;
}

/* ============================================
   LOGO / BRAND
   ============================================ */
.navbar-logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1a1a1a;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: color 0.3s ease;
    z-index: 10003; /* Above mobile menu */
    position: relative;
}

.navbar-logo:hover {
    color: #00a651;
}

.navbar-logo-text {
    letter-spacing: -0.5px;
}

/* Remove emoji-based logo if present */
.navbar-logo::before {
    content: none;
}

/* ============================================
   NAVIGATION MENU - DESKTOP
   ============================================ */
.navbar-menu {
    display: flex;
    align-items: center;
    gap: 2rem;
    list-style: none;
    margin: 0;
    padding: 0;
}

.navbar-menu li {
    position: relative;
}

.navbar-menu a {
    color: #333;
    text-decoration: none;
    font-weight: 500;
    font-size: 0.95rem;
    padding: 0.75rem 0.875rem;
    min-height: 48px; /* Touch target accessibility */
    display: inline-flex;
    align-items: center;
    border-radius: 6px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
}

.navbar-menu a:hover {
    color: #00a651;
    background: rgba(0, 166, 81, 0.05);
}

.navbar-menu a.active {
    color: #00a651;
    background: rgba(0, 166, 81, 0.08);
}

/* ============================================
   CTA BUTTON IN NAV
   ============================================ */
.navbar-cta {
    background: #00a651;
    color: white !important;
    padding: 0.65rem 1.5rem !important;
    border-radius: 8px;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0, 166, 81, 0.2);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.navbar-cta:hover {
    background: #008a43 !important;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 166, 81, 0.3);
}

/* ============================================
   HAMBURGER MENU - MOBILE
   ============================================ */
.navbar-toggle {
    display: none;
    flex-direction: column;
    justify-content: space-around;
    width: 28px;
    height: 28px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    z-index: 10003; /* Above everything for closing menu */
    position: relative;
    pointer-events: all;
    touch-action: manipulation;
}

.navbar-toggle span {
    width: 28px;
    height: 3px;
    background: #333;
    border-radius: 10px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    transform-origin: center;
}

.navbar-toggle.active span {
    background: #1a1a1a;
}

.navbar-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(8px, 8px);
}

.navbar-toggle.active span:nth-child(2) {
    opacity: 0;
    transform: translateX(-20px);
}

.navbar-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(8px, -8px);
}

/* ============================================
   MOBILE MENU - FIXED Z-INDEX AND VISIBILITY
   ============================================ */
@media (max-width: 768px) {
    /* CRITICAL FIX: Navbar should not block menu */
    .navbar {
        pointer-events: none !important; /* Don't block menu taps */
    }

    .navbar-container {
        pointer-events: auto; /* Only container items are tappable */
    }

    .navbar-toggle {
        display: flex;
        pointer-events: auto !important; /* Hamburger must be tappable */
    }

    .navbar-menu {
        position: fixed;
        top: 0;
        right: -100%;
        width: min(320px, 85vw);
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height for mobile */
        background: white;
        flex-direction: column;
        align-items: flex-start;
        gap: 0;
        padding: 90px 2rem 2rem;
        box-shadow: -5px 0 25px rgba(0, 0, 0, 0.15);
        transition: right 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
        overflow-y: auto;
        overflow-x: hidden;
        z-index: 10005; /* FIXED: Way above backdrop for mobile touch */
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
        pointer-events: auto !important; /* Force touch events on mobile */
    }

    .navbar-menu.active {
        right: 0;
    }

    .navbar-menu li {
        width: 100%;
        border-bottom: 1px solid rgba(0, 0, 0, 0.06);
        opacity: 0;
        transform: translateX(20px);
        animation: slideIn 0.3s forwards;
        pointer-events: all; /* Ensure list items are tappable */
        -webkit-tap-highlight-color: rgba(0, 166, 81, 0.1); /* iOS tap feedback */
        z-index: 10009; /* Above backdrop */
        position: relative;
    }

    .navbar-menu.active li:nth-child(1) { animation-delay: 0.1s; }
    .navbar-menu.active li:nth-child(2) { animation-delay: 0.15s; }
    .navbar-menu.active li:nth-child(3) { animation-delay: 0.2s; }
    .navbar-menu.active li:nth-child(4) { animation-delay: 0.25s; }
    .navbar-menu.active li:nth-child(5) { animation-delay: 0.3s; }
    .navbar-menu.active li:nth-child(6) { animation-delay: 0.35s; }

    @keyframes slideIn {
        to {
            opacity: 1;
            transform: translateX(0);
        }
    }

    .navbar-menu a {
        display: block;
        width: 100%;
        padding: 1rem 0.75rem;
        font-size: 1.05rem;
        border-radius: 0;
        position: relative; /* Create new stacking context */
        z-index: 10010 !important; /* FIXED: Above everything to ensure clicks work */
        pointer-events: auto !important; /* Force touch events */
        -webkit-user-select: none; /* Prevent iOS text selection */
        user-select: none;
        touch-action: manipulation; /* Improve touch responsiveness */
        cursor: pointer !important;
        -webkit-tap-highlight-color: rgba(0, 166, 81, 0.3); /* iOS tap feedback */
        background: transparent;
        border: none;
    }

    /* Extra fix: ensure li elements don't block clicks */
    .navbar-menu li a {
        pointer-events: all !important;
        z-index: 10011 !important;
    }

    .navbar-cta {
        margin-top: 1rem;
        text-align: center;
        border-radius: 8px;
    }

    /* Mobile Menu Backdrop - FIXED Z-INDEX */
    .mobile-menu-backdrop {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
        z-index: 9998; /* BELOW menu (10005) so it doesn't block clicks */
    }

    .mobile-menu-backdrop.active {
        opacity: 1;
        pointer-events: all; /* Clickable to close menu */
    }

    /* Adjust container padding for mobile */
    .navbar-container {
        padding: 1rem 1.5rem;
        min-height: 56px;
    }

    /* Prevent body scroll when menu is open */
    body.menu-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
    }
}

/* ============================================
   TABLET ADJUSTMENTS
   ============================================ */
@media (max-width: 1024px) and (min-width: 769px) {
    .navbar-menu {
        gap: 1.5rem;
    }

    .navbar-menu a {
        font-size: 0.9rem;
        padding: 0.5rem 0.6rem;
    }

    .navbar-container {
        padding: 1rem 1.5rem;
    }
}

/* ============================================
   SMALL MOBILE ADJUSTMENTS
   ============================================ */
@media (max-width: 480px) {
    .navbar-container {
        padding: 0.75rem 1rem;
        min-height: 52px;
    }

    .navbar-logo {
        font-size: 1.25rem;
    }

    .navbar-menu {
        width: 100%;
        right: -100%;
        padding: 80px 1.5rem 2rem;
    }
}

/* ============================================
   SCROLL BEHAVIOR - ENSURE MENU FULLY VISIBLE
   ============================================ */
body {
    padding-top: 70px; /* Account for fixed navbar */
}

@media (max-width: 768px) {
    body {
        padding-top: 60px;
    }
}

/* Smooth scroll with offset for fixed nav */
html {
    scroll-padding-top: 85px;
    scroll-behavior: smooth;
}

/* Prevent content from jumping behind nav */
section {
    scroll-margin-top: 85px;
}

/* ============================================
   ACCESSIBILITY IMPROVEMENTS
   ============================================ */
.navbar-toggle:focus,
.navbar-toggle:focus-visible {
    outline: 2px solid #00a651;
    outline-offset: 4px;
    border-radius: 4px;
}

.navbar-menu a:focus,
.navbar-menu a:focus-visible {
    outline: 2px solid #00a651;
    outline-offset: 2px;
}

/* Skip to main content link for screen readers */
.skip-to-main {
    position: absolute;
    top: -100px;
    left: 0;
    background: #00a651;
    color: white;
    padding: 0.75rem 1.5rem;
    text-decoration: none;
    z-index: 10002;
    border-radius: 0 0 8px 0;
    transition: top 0.3s ease;
}

.skip-to-main:focus {
    top: 0;
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    .navbar {
        position: relative;
        box-shadow: none;
        background: white;
    }

    .navbar-toggle {
        display: none;
    }

    .navbar-menu {
        display: flex;
        position: static;
        width: auto;
        height: auto;
        flex-direction: row;
        padding: 0;
    }

    .mobile-menu-backdrop {
        display: none;
    }
}

/* ============================================
   PERFORMANCE OPTIMIZATIONS
   ============================================ */
.navbar,
.navbar-menu,
.navbar-toggle span {
    will-change: transform;
}

@media (prefers-reduced-motion: reduce) {
    .navbar,
    .navbar-menu,
    .navbar-toggle span,
    .navbar-menu a {
        transition: none;
        animation: none;
    }
}
