/* =========================================
   Mega Menu & Responsive Nav Styles
   ========================================= */

/* 1. Desktop Mega Menu */
.nav-item {
    position: static;
    /* Important for full-width mega menu if needed, or relative for scoped */
}

/* Make nav-links relative to contain the mega menu */
.nav-links {
    position: relative;
    display: flex;
    align-items: center;
    gap: 2rem;
}

.mega-menu {
    position: absolute;
    top: 100%;
    left: 0;
    width: 800px;
    /* Fixed width as per user request/image implication */
    background: white;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    border-radius: 8px;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.2s ease;
    display: flex;
    /* Sidebar + Content Layout */
    overflow: hidden;
    margin-top: 10px;
    /* Spacing */
}

/* Show Mega Menu on Hover */
.nav-item:hover .mega-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Sidebar (Left) */
.mega-sidebar {
    width: 30%;
    background: #f8fafc;
    border-right: 1px solid var(--border);
    padding: 1rem 0;
}

.mega-sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 1.5rem;
    color: var(--text-main);
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.2s;
}

.mega-sidebar-item:hover,
.mega-sidebar-item.active {
    background: white;
    color: var(--primary-deep);
    font-weight: 500;
    border-right: 2px solid var(--primary);
    /* Highlight active */
    margin-right: -1px;
    /* Cover border */
}

.mega-sidebar-item i {
    width: 20px;
    text-align: center;
    color: var(--text-muted);
}

.mega-sidebar-item.active i {
    color: var(--primary);
}

/* Content (Right) */
.mega-content {
    width: 70%;
    padding: 2rem;
}

.mega-subcontent {
    display: none;
    animation: fadeIn 0.2s ease;
}

.mega-subcontent.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.mega-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.mega-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.mega-list a {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.mega-list a:hover {
    color: var(--primary-deep);
    padding-left: 5px;
}

.mega-list .view-all {
    font-weight: 600;
    color: var(--primary-deep);
    margin-bottom: 0.5rem;
    display: inline-block;
}

/* Mobile Toggle Button */
.mobile-toggle,
.mobile-dropdown-toggle,
.mobile-header {
    display: none;
}

/* 2. Responsive / Mobile Styles */
@media (max-width: 992px) {

    /* Hide Desktop Nav Links by default */
    .nav-links {
        position: fixed;
        top: 0;
        left: -100%;
        /* Slide out */
        width: 300px;
        height: 100vh;
        background: white;
        flex-direction: column;
        align-items: flex-start;
        padding: 0;
        gap: 0;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
        transition: left 0.3s ease;
        z-index: 1002;
        /* Ensure above header (1001) and overlay (999) */
        overflow-y: auto;
        overscroll-behavior: contain;
        padding-bottom: 80px;
        /* Ensure bottom items are reachable */
    }

    .nav-links.active {
        left: 0;
    }

    /* Mobile Header inside menu */
    .mobile-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        padding: 1.5rem;
        border-bottom: 1px solid var(--border);
        background: var(--primary-deep);
        color: white;
    }

    .logo-text {
        font-weight: 700;
        font-size: 1.2rem;
    }

    .close-menu {
        background: none;
        border: none;
        color: white;
        font-size: 1.2rem;
        cursor: pointer;
    }

    /* Mobile Nav Items */
    .nav-item {
        width: 100%;
        border-bottom: 1px solid var(--border);
        position: relative;
        /* Reset for accordion */
    }

    .nav-link-wrapper {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        padding: 1rem 1.5rem;
    }

    .nav-link {
        color: var(--text-main);
        font-weight: 500;
        flex: 1;
    }

    .mobile-dropdown-toggle {
        display: block;
        background: none;
        border: none;
        padding: 5px;
        font-size: 1rem;
        color: var(--text-muted);
        cursor: pointer;
    }

    /* Reset Mega Menu for Mobile (Accordion) */
    .mega-menu {
        position: static;
        width: 100%;
        box-shadow: none;
        border: none;
        display: none;
        /* Hidden by default */
        opacity: 1;
        visibility: visible;
        transform: none;
        flex-direction: column;
        margin: 0;
        background: #f8fafc;
    }

    .nav-item.active .mega-menu {
        display: block;
    }

    .mega-sidebar {
        width: 100%;
        border-right: none;
        padding: 0;
    }

    /* Simplify Mobile Sidebar Items */
    .mega-sidebar-item {
        padding: 12px 2rem;
        background: transparent;
        border-bottom: 1px solid #eee;
    }

    .mega-sidebar-item:hover,
    .mega-sidebar-item.active {
        background: transparent;
        color: var(--primary);
        border-right: none;
    }

    .mega-sidebar-item i.ml-auto {
        display: none;
        /* Hide chevron on mobile sidebar items to simplify */
    }

    /* Hide Content panel on mobile? Or show below? 
       For this complexity, let's keep it simple: 
       On mobile, just showing the Level 2 links (Sidebar items) is often enough. 
       If we want to show Level 3, it becomes a 3-level accordion. 
       Let's stick to showing Level 2 links as the final destination for mobile to save space, 
       OR make the sidebar items just links. 
       
       Current code: Sidebar items are <a> links. So they work.
       We will HIDE the .mega-content on mobile to avoid deep nesting complexity for now.
    */
    .mega-content {
        display: none;
    }

    /* Mobile Toggle Button (Visible) */
    .mobile-toggle {
        display: block;
        background: none;
        border: none;
        font-size: 1.5rem;
        color: var(--primary-deep);
        cursor: pointer;
        /* Removed order: -1 to keep it on the right */
    }

    /* Overlay */
    .nav-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        display: none;
    }

    .nav-overlay.active {
        display: block;
    }
}