/* ============================================
   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: 999999;
    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) {
    /* FIXED: Removed pointer-events:none - was breaking hamburger menu on some devices */
    .navbar {
        /* Allow normal pointer events */
    }

    .navbar-container {
        pointer-events: auto;
    }

    .navbar-toggle {
        display: flex;
        pointer-events: auto !important; /* Hamburger must be tappable */
        cursor: pointer;
        z-index: 10010; /* Ensure it's above everything */
        width: 48px !important;
        height: 48px !important;
        min-width: 48px;
        min-height: 48px;
        padding: 10px !important;
        background: rgba(255,255,255,0.9) !important;
        border-radius: 8px;
        margin-right: -10px;
    }

    .navbar-menu {
        display: flex !important; /* CRITICAL: Must be flex to show items */
        position: fixed;
        top: 0;
        right: -75%;
        width: 70%; /* Narrower - shows 30% of page behind */
        max-width: 280px;
        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: 9999999; /* Above popup overlay */
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
        pointer-events: auto !important; /* Force touch events on mobile */
        visibility: visible !important; /* Ensure visible */
    }

    .navbar-menu.active {
        right: 0;
        transform: translateX(0);
    }

    .navbar-menu li {
        width: 100%;
        border-bottom: 1px solid rgba(0, 0, 0, 0.06);
        opacity: 1 !important; /* Always visible - menu slides, not items */
        transform: none !important; /* No transform - menu handles animation */
        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;
    }

    /* Animate list items when menu is active */
    .navbar-menu.active li {
        opacity: 1;
        transform: translateX(0);
    }

    .navbar-menu.active li:nth-child(1) { transition-delay: 0.05s; }
    .navbar-menu.active li:nth-child(2) { transition-delay: 0.1s; }
    .navbar-menu.active li:nth-child(3) { transition-delay: 0.15s; }
    .navbar-menu.active li:nth-child(4) { transition-delay: 0.2s; }
    .navbar-menu.active li:nth-child(5) { transition-delay: 0.25s; }
    .navbar-menu.active li:nth-child(6) { transition-delay: 0.3s; }
    .navbar-menu.active li:nth-child(7) { transition-delay: 0.35s; }
    .navbar-menu.active li:nth-child(8) { transition-delay: 0.4s; }

    .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;
        /* FIXED: Ensure CTA button is visible in mobile menu */
        background: #00a651 !important;
        color: white !important;
        display: block !important;
        padding: 16px 24px !important;
        font-weight: 700 !important;
        box-shadow: 0 4px 12px rgba(0, 166, 81, 0.3) !important;
    }

    /* 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;
        /* Removed position: fixed which can cause layout issues */
    }
}

/* ============================================
   SMALLER DESKTOP ADJUSTMENTS (FIX FOR CHROME)
   ============================================ */
@media (max-width: 1280px) and (min-width: 1025px) {
    .navbar-menu {
        gap: 1rem;
    }

    .navbar-menu a {
        font-size: 0.9rem;
        padding: 0.65rem 0.75rem;
    }
}

/* ============================================
   TABLET ADJUSTMENTS
   ============================================ */
@media (max-width: 1024px) and (min-width: 769px) {
    .navbar-menu {
        gap: 1rem;
    }

    .navbar-menu a {
        font-size: 0.88rem;
        padding: 0.5rem 0.6rem;
    }

    .navbar-container {
        padding: 1rem 1.5rem;
    }

    .navbar-cta {
        padding: 0.55rem 1.2rem !important;
    }
}

/* ============================================
   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;
    }
}

/* ============================================
   DROPDOWN MENU STYLES
   ============================================ */
.navbar-menu .dropdown {
    position: relative;
}

.navbar-menu .dropdown-toggle::after {
    content: " ▼";
    font-size: 0.7em;
    margin-left: 4px;
    transition: transform 0.3s ease;
}

.navbar-menu .dropdown:hover .dropdown-toggle::after {
    transform: rotate(180deg);
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 240px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10001;
    padding: 8px 0;
    margin-top: 8px;
    list-style: none;
}

.dropdown:hover .dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-menu li {
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.dropdown-menu li:last-child {
    border-bottom: none;
}

.dropdown-menu a {
    display: block;
    padding: 12px 20px;
    color: #333;
    white-space: nowrap;
    text-decoration: none;
}

.dropdown-menu a:hover {
    background: rgba(0, 166, 81, 0.08);
    color: #00a651;
}

/* Mobile dropdown - accordion style */
@media (max-width: 768px) {
    .navbar-menu .dropdown-toggle::after {
        float: right;
    }

    .dropdown-menu {
        position: static;
        opacity: 1;
        visibility: visible;
        transform: none;
        box-shadow: none;
        background: transparent;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
        padding: 0;
        margin: 0;
    }

    .dropdown.active .dropdown-menu {
        max-height: 500px;
    }

    .dropdown-menu a {
        padding-left: 40px;
        font-size: 0.9rem;
    }
}

/* ============================================
   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;
    }
}
