/*
* Master Navigation CSS: v1.0.2 (State Synchronization Patch)
*/
@media (min-width: 992px) {

    /**
     * 1. VARIANT 1: MEGA MENU (.mega-menu)
     * Setup for ultra-wide screens (1920px capped)
     */
    .navbar .mega-menu {
        position: static !important;
    }

    .navbar .mega-menu .mega-menu-container {
        display: none !important;
        position: absolute !important;
        width: 1920px !important;    /* Hard cap for 4k/Ultrawide */
        max-width: 98vw !important;  /* Safe margin for smaller desktops */
        left: 50% !important;
        transform: translateX(-50%) !important;
        top: 100% !important;
        z-index: 1050 !important;    /* Supreme baseline z-index */
        background: #ffffff;
        border: 1px solid #e9ecef;
        border-top: 3px solid var(--bs-primary);
        box-shadow: 0 15px 30px rgba(0,0,0,0.1);
        opacity: 0;
        visibility: hidden;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    /* JavaScript Toggle Class */
    .mega-menu.is-open > .mega-menu-container {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
    }

    .mega-menu-container ul.row {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important; /* CRITICAL: Prevents column drop */
        width: 100% !important;
        margin: 0 !important;
        padding: 2.5rem 2rem !important;
        list-style: none !important;
    }

    .mega-menu-col {
        flex: 1 1 0% !important;
        min-width: 0 !important;
        padding: 0 30px !important;
    }

    /* Desktop Safety Net for Mega Menu Headers (Prevents mobile toggle logic on desktop) */
    .mega-mobile-collapse { display: block !important; }
    .mega-mobile-toggle { cursor: default; }
    .mega-mobile-toggle::after { display: none !important; }

    /**
     * 2. VARIANT 2: FLYOUT MENU (.has-flyout)
     * Setup for standard vertical 3rd-level expansion
     */
    .has-flyout {
        position: relative;
        z-index: 99 !important; /* Sits low when closed so it doesn't overlap mega menu */
        min-width: 240px;       /* Matches the dropdown-flyout width for a flush layout */
    }

    .has-flyout > .dropdown-flyout {
        position: absolute !important;
        top: 0 !important;
        left: 100% !important;
        display: none !important;
        min-width: 240px;
        z-index: 1010;
        background: #ffffff;
        border-top: 3px solid var(--bs-primary);
        box-shadow: 5px 5px 15px rgba(0,0,0,0.05);
        padding: 0.5rem 0;
        list-style: none;
    }

    /* Elevate Flyout and Bootstrap Dropdowns ONLY when actively clicked */
    .has-flyout.is-open,
    .navbar-nav .dropdown.show {
        z-index: 1060 !important; /* Jumps above the mega menu container */
    }

    .has-flyout.is-open > .dropdown-flyout {
        display: block !important;
    }

    /* Breakout z-index if flyout is nested inside a mega menu */
    .mega-menu .has-flyout.is-open {
        z-index: 1070 !important;
    }

    /**
     * 3. ICON LOGIC (Surgical Overrides)
     */

    /* Remove default Bootstrap triangle on Flyout items */
    .has-flyout > .dropdown-toggle::after {
        display: none !important;
        content: none !important;
        border: 0 !important;
    }

    /* Add custom Flyout chevron */
    .has-flyout > a.dropdown-item::after {
        display: inline-block !important;
        content: "›" !important;
        float: right;
        margin-left: 10px;
        font-weight: bold;
        font-size: 1.2rem;
        line-height: 1;
        color: inherit;
    }

    /* Maintain default arrow ONLY on top-level Mega Menu items */
    .mega-menu > a.dropdown-toggle::after {
        display: inline-block;
        margin-left: 0.255em;
        vertical-align: 0.255em;
        content: "";
        border-top: 0.3em solid;
        border-right: 0.3em solid transparent;
        border-bottom: 0;
        border-left: 0.3em solid transparent;
    }
}

/**
 * 4. SHARED STYLING (Headers & Typography)
 */
.mega-menu-col .dropdown-header {
    display: block;
    padding: 0 0 0.5rem 0;
    margin-bottom: 1rem;
    border-bottom: 1px solid #eee;
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--bs-primary);
    text-transform: uppercase;
}

/**
 * 5. MOBILE FALLBACK (Accordion Style & Mega Nested Accordions)
 */
@media (max-width: 991.98px) {
    /* Reset containers for vertical stacking */
    .mega-menu-container,
    .dropdown-flyout {
        position: static !important;
        display: none !important;
        width: 100% !important;
        padding-left: 1.5rem !important;
    }

    .mega-menu.is-open > .mega-menu-container,
    .has-flyout.is-open > .dropdown-flyout {
        display: block !important;
    }

    .mega-menu-container ul.row {
        flex-direction: column !important;
        display: block !important;
    }

    /* --- NEW: MOBILE MEGA MENU ACCORDIONS --- */

    /* Hide the column lists by default on mobile */
    .mega-mobile-collapse {
        display: none;
        padding-bottom: 1rem;
    }

    /* Style the heading to look like a clickable toggle */
    .mega-mobile-toggle {
        cursor: pointer;
        position: relative;
        padding: 0.75rem 0 !important;
        margin-bottom: 0 !important;
        border-bottom: 1px solid #eaeaea;
    }

    /* Add the Chevron icon (pointing down by default) */
    .mega-mobile-toggle::after {
        content: "›";
        position: absolute;
        right: 0;
        top: 50%;
        transform: translateY(-50%) rotate(90deg);
        transition: transform 0.2s ease;
        font-size: 1.5rem;
        line-height: 1;
    }

    /* Show the list when the 'is-expanded' class is added */
    .mega-menu-col.is-expanded .mega-mobile-collapse {
        display: block;
    }

    /* Rotate the chevron up when open */
    .mega-menu-col.is-expanded .mega-mobile-toggle::after {
        transform: translateY(-50%) rotate(-90deg);
    }
}

/* ==========================================================================
   ACTIVE / CURRENT SECTION HIGHLIGHTING (Top-Level Only)
   ========================================================================== */

/* 1. Highlight ONLY the Top-Level Parent (The Main Navbar) */
.navbar-nav > .current-menu-item > a.nav-link,
.navbar-nav > .current-menu-parent > a.nav-link,
.navbar-nav > .current-menu-ancestor > a.nav-link {
    color: var(--bs-primary) !important;
    font-weight: 700;
    position: relative;
}

/* 2. Add the stylish bottom-border to the top-level link */
.navbar-nav > .current-menu-item > a.nav-link::before,
.navbar-nav > .current-menu-parent > a.nav-link::before,
.navbar-nav > .current-menu-ancestor > a.nav-link::before {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0.5rem;  /* Aligns with standard Bootstrap link padding */
    right: 0.5rem;
    height: 3px;
    background-color: var(--bs-primary);
    border-radius: 3px 3px 0 0;
}

/* 3. actively suppress Bootstrap/WordPress highlights on nested anchor links */
.dropdown-menu .current-menu-item > a.dropdown-item,
.dropdown-menu .dropdown-item.active {
    color: #212529 !important; /* Forces standard text color (Bootstrap dark) */
    background-color: transparent !important; /* Kills any active background */
    font-weight: 400 !important; /* Forces normal font weight */
}