/* ====================================================================
   AC WP HAMBURGER MENU - TIGHTLY SCOPED STYLES
   Version: 2.0 - Critical Bug Fixes
   
   IMPORTANT: All styles are scoped to .ac-wp-ham-container to prevent
   conflicts with other site elements and GSAP timelines.
   ==================================================================== */

/* ========================================
   CONTAINER & TOGGLE BUTTON
   ======================================== */

.ac-wp-ham-container {
    position: relative;
    display: inline-block;
    z-index: 9999;
    /* Removed global overflow: visible - only apply where needed */
}

.ac-wp-ham-container .ac-wp-ham-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 12px;
    border-radius: 8px;
    background-color: rgba(255, 255, 255, 0.95);
    /* backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px); */
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
    position: relative;
    z-index: 10001;
}

.ac-wp-ham-container .ac-wp-ham-toggle:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.15);
    background-color: rgba(255, 255, 255, 1);
}

.ac-wp-ham-container .ac-wp-ham-toggle:focus {
    outline: 2px solid #5522dd;
    outline-offset: 2px;
}

.ac-wp-ham-container .ac-wp-ham-toggle:active {
    transform: translateY(0);
}

/* ========================================
   HAMBURGER ICON
   ======================================== */

.ac-wp-ham-container .ac-wp-ham-icon {
    display: block;
    width: 24px;
    height: 18px;
    position: relative;
}

.ac-wp-ham-container .ac-wp-ham-line {
    display: block;
    width: 100%;
    height: 2px;
    background-color: #5522dd;
    border-radius: 1px;
    position: absolute;
    left: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.ac-wp-ham-container .ac-wp-ham-line:nth-child(1) {
    top: 0;
}

.ac-wp-ham-container .ac-wp-ham-line:nth-child(2) {
    top: 8px;
}

.ac-wp-ham-container .ac-wp-ham-line:nth-child(3) {
    top: 16px;
}

/* Hamburger Animation to X */
.ac-wp-ham-container .ac-wp-ham-toggle[aria-expanded="true"] .ac-wp-ham-line:nth-child(1) {
    top: 8px;
    transform: rotate(45deg);
}

.ac-wp-ham-container .ac-wp-ham-toggle[aria-expanded="true"] .ac-wp-ham-line:nth-child(2) {
    opacity: 0;
    transform: scale(0);
}

.ac-wp-ham-container .ac-wp-ham-toggle[aria-expanded="true"] .ac-wp-ham-line:nth-child(3) {
    top: 8px;
    transform: rotate(-45deg);
}

/* ========================================
   MENU CONTAINER
   ======================================== */

.ac-wp-ham-container .ac-wp-ham-menu {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 8px;
    min-width: 280px;
    max-width: 90vw;
    background: rgba(255, 255, 255, 0.95);
    /* backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px); */
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px) scale(0.95);
    transform-origin: top left;
    z-index: 10000;
    /* Controlled overflow for submenu visibility */
    overflow: visible;
    /* CSS transitions for smooth animations */
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.ac-wp-ham-container .ac-wp-ham-menu.ac-wp-ham-menu-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* ========================================
   MENU INNER CONTAINER
   ======================================== */

.ac-wp-ham-container .ac-wp-ham-menu-inner {
    padding: 8px 0;
    max-height: 70vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
    /* CRITICAL: Allow submenus to extend outside - scoped to plugin only */
    overflow: visible !important;
}

/* ========================================
   NAVIGATION LIST
   ======================================== */

.ac-wp-ham-container .ac-wp-ham-nav-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.ac-wp-ham-container .ac-wp-ham-nav-list li {
    margin: 0;
    padding: 0;
    position: relative;
}

.ac-wp-ham-container .ac-wp-ham-nav-list li.menu-item-has-children {
    position: relative;
    /* Allow submenus to extend outside parent - scoped */
    overflow: visible;
}

.ac-wp-ham-container .ac-wp-ham-nav-list li.ac-wp-ham-submenu-open > a {
    background-color: rgba(85, 34, 221, 0.1);
    color: #5522dd;
}

.ac-wp-ham-container .ac-wp-ham-nav-list a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    color: #333;
    text-decoration: none;
    font-size: 16px;
    font-weight: 500;
    line-height: 1.4;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.ac-wp-ham-container .ac-wp-ham-nav-list a:hover,
.ac-wp-ham-container .ac-wp-ham-nav-list a:focus {
    background-color: rgba(85, 34, 221, 0.1);
    color: #5522dd;
    outline: none;
}

.ac-wp-ham-container .ac-wp-ham-nav-list li:last-child a {
    border-bottom: none;
}

/* ========================================
   SUBMENU ARROW
   ======================================== */

.ac-wp-ham-container .ac-wp-ham-submenu-arrow {
    font-size: 18px;
    color: #666;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    margin-left: 8px;
}

.ac-wp-ham-container .ac-wp-ham-nav-list a:hover .ac-wp-ham-submenu-arrow {
    color: #5522dd;
    transform: translateX(2px);
}

/* ========================================
   SUBMENU STYLES - BULLETPROOF & SCOPED
   ======================================== */

.ac-wp-ham-container .ac-wp-ham-submenu {
    list-style: none;
    margin: 0;
    padding: 12px 0;
    position: absolute;
    top: 0;
    left: 100%;
    margin-left: 10px;
    min-width: 220px;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    border: 1px solid #e0e0e0;
    z-index: 10001;
    /* DEFAULT STATE: COMPLETELY HIDDEN */
    display: none;
    /* Smooth transitions for submenu animations */
    opacity: 0;
    transform: translateY(-10px) scale(0.95);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ACTIVE STATE: COMPLETELY VISIBLE - BULLETPROOF */
.ac-wp-ham-container .ac-wp-ham-submenu.ac-wp-ham-submenu-active {
    display: block !important;
    opacity: 1 !important;
    transform: translateY(0) scale(1) !important;
}

/* Position submenus to the left if they would overflow */
.ac-wp-ham-container .ac-wp-ham-submenu.ac-wp-ham-submenu-left {
    left: auto;
    right: 100%;
    margin-left: 0;
    margin-right: 10px;
}

.ac-wp-ham-container .ac-wp-ham-submenu a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    color: #333;
    text-decoration: none;
    font-size: 16px;
    font-weight: 500;
    line-height: 1.4;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.ac-wp-ham-container .ac-wp-ham-submenu a:hover,
.ac-wp-ham-container .ac-wp-ham-submenu a:focus {
    background-color: rgba(85, 34, 221, 0.1);
    color: #5522dd;
    outline: none;
}

.ac-wp-ham-container .ac-wp-ham-submenu li:last-child a {
    border-bottom: none;
}

/* ========================================
   NESTED SUBMENU SUPPORT - UNLIMITED DEPTH
   ======================================== */

.ac-wp-ham-container .ac-wp-ham-submenu .menu-item-has-children {
    position: relative;
    /* Scoped overflow for nested submenus */
    overflow: visible;
}

/* Level 1+ nested submenus */
.ac-wp-ham-container .ac-wp-ham-submenu .ac-wp-ham-submenu {
    top: 0;
    left: 100%;
    margin-left: 5px;
    min-width: 200px;
}

/* Left positioning for nested submenus when they would overflow */
.ac-wp-ham-container .ac-wp-ham-submenu .ac-wp-ham-submenu.ac-wp-ham-submenu-left {
    left: auto;
    right: 100%;
    margin-left: 0;
    margin-right: 5px;
}

/* Level 2+ nested submenus */
.ac-wp-ham-container .ac-wp-ham-submenu .ac-wp-ham-submenu .ac-wp-ham-submenu {
    min-width: 180px;
}

.ac-wp-ham-container .ac-wp-ham-submenu .ac-wp-ham-submenu .ac-wp-ham-submenu a {
    font-size: 14px;
}

/* Level 3+ nested submenus */
.ac-wp-ham-container .ac-wp-ham-submenu .ac-wp-ham-submenu .ac-wp-ham-submenu .ac-wp-ham-submenu {
    min-width: 160px;
}

.ac-wp-ham-container .ac-wp-ham-submenu .ac-wp-ham-submenu .ac-wp-ham-submenu .ac-wp-ham-submenu a {
    font-size: 13px;
}

/* ========================================
   VIEWPORT EDGE DETECTION
   ======================================== */

.ac-wp-ham-container.ac-wp-ham-near-right-edge .ac-wp-ham-menu {
    left: auto;
    right: 0;
    transform-origin: top right;
}

.ac-wp-ham-container.ac-wp-ham-near-bottom-edge .ac-wp-ham-menu {
    top: auto;
    bottom: 100%;
    margin-top: 0;
    margin-bottom: 8px;
    transform-origin: bottom left;
}

.ac-wp-ham-container.ac-wp-ham-near-right-edge.ac-wp-ham-near-bottom-edge .ac-wp-ham-menu {
    transform-origin: bottom right;
}

/* ========================================
   CSS ANIMATION STATES - SMOOTH TRANSITIONS
   ======================================== */

.ac-wp-ham-container .ac-wp-ham-nav-list li {
    opacity: 0;
    transform: translateX(-30px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transition-delay: 0s; /* Will be overridden for stagger effect */
}

/* CSS stagger effect for menu items */
.ac-wp-ham-container .ac-wp-ham-nav-list li:nth-child(1) { transition-delay: 0.05s; }
.ac-wp-ham-container .ac-wp-ham-nav-list li:nth-child(2) { transition-delay: 0.1s; }
.ac-wp-ham-container .ac-wp-ham-nav-list li:nth-child(3) { transition-delay: 0.15s; }
.ac-wp-ham-container .ac-wp-ham-nav-list li:nth-child(4) { transition-delay: 0.2s; }
.ac-wp-ham-container .ac-wp-ham-nav-list li:nth-child(5) { transition-delay: 0.25s; }
.ac-wp-ham-container .ac-wp-ham-nav-list li:nth-child(6) { transition-delay: 0.3s; }
.ac-wp-ham-container .ac-wp-ham-nav-list li:nth-child(7) { transition-delay: 0.35s; }
.ac-wp-ham-container .ac-wp-ham-nav-list li:nth-child(8) { transition-delay: 0.4s; }
.ac-wp-ham-container .ac-wp-ham-nav-list li:nth-child(n+9) { transition-delay: 0.45s; }

/* CRITICAL: Make menu items visible when menu is open */
.ac-wp-ham-container .ac-wp-ham-menu.ac-wp-ham-menu-open .ac-wp-ham-nav-list li {
    opacity: 1 !important;
    transform: translateX(0) !important;
}

/* CRITICAL: Make submenu items visible when submenu is active */
.ac-wp-ham-container .ac-wp-ham-submenu.ac-wp-ham-submenu-active li {
    opacity: 1 !important;
    transform: translateX(0) !important;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========================================
   MOBILE RESPONSIVE STYLES
   ======================================== */

@media (max-width: 768px) {
    /* MOBILE: Increase menu size and remove height constraints */
    .ac-wp-ham-container .ac-wp-ham-menu {
        min-width: 300px;
        max-width: 90vw;
        width: 90vw;
    }
    
    /* MOBILE: Remove height restriction to prevent overflow */
    .ac-wp-ham-container .ac-wp-ham-menu-inner {
        max-height: none !important;
        height: auto !important;
        overflow-y: visible !important;
    }
    
    /* MOBILE: Normalize all font sizes and ensure left alignment */
    .ac-wp-ham-container .ac-wp-ham-nav-list a {
        padding: 16px 20px !important;
        font-size: 16px !important;
        text-align: left !important;
        justify-content: flex-start !important;
        align-items: center !important;
        line-height: 1.4 !important;
    }
    
    /* MOBILE: Make submenus inline instead of overlay */
    .ac-wp-ham-container .ac-wp-ham-submenu {
        position: static !important;
        left: auto !important;
        right: auto !important;
        margin: 0 !important;
        min-width: auto !important;
        width: 100% !important;
        background: #f8f9fa !important;
        border-radius: 0 !important;
        border: none !important;
        border-top: 1px solid #e9ecef !important;
        border-bottom: 1px solid #e9ecef !important;
        box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.1), inset 0 -3px 6px rgba(0, 0, 0, 0.1) !important;
        padding: 8px 0 !important;
        margin-top: 4px !important;
        margin-bottom: 4px !important;
    }
    
    /* MOBILE: Normalize submenu font sizes */
    .ac-wp-ham-container .ac-wp-ham-submenu a {
        padding: 14px 30px !important;
        font-size: 16px !important;
        background: transparent !important;
        border-bottom: 1px solid rgba(0, 0, 0, 0.05) !important;
        text-align: left !important;
        justify-content: flex-start !important;
        line-height: 1.4 !important;
    }
    
    .ac-wp-ham-container .ac-wp-ham-submenu a:hover,
    .ac-wp-ham-container .ac-wp-ham-submenu a:focus {
        background-color: rgba(85, 34, 221, 0.08) !important;
    }
    
    /* MOBILE: ALL nested submenus - CONSISTENT STYLING */
    .ac-wp-ham-container .ac-wp-ham-submenu .ac-wp-ham-submenu,
    .ac-wp-ham-container .ac-wp-ham-submenu .ac-wp-ham-submenu .ac-wp-ham-submenu,
    .ac-wp-ham-container .ac-wp-ham-submenu .ac-wp-ham-submenu .ac-wp-ham-submenu .ac-wp-ham-submenu {
        background: #f8f9fa !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        border-radius: 0 !important;
        box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.1), inset 0 -3px 6px rgba(0, 0, 0, 0.1) !important;
    }
    
    /* MOBILE: Level 2 nested submenu links */
    .ac-wp-ham-container .ac-wp-ham-submenu .ac-wp-ham-submenu a {
        padding: 14px 40px !important;
        font-size: 16px !important;
        text-align: left !important;
        line-height: 1.4 !important;
    }
    
    /* MOBILE: Level 3 nested submenu links */
    .ac-wp-ham-container .ac-wp-ham-submenu .ac-wp-ham-submenu .ac-wp-ham-submenu a {
        padding: 14px 50px !important;
        font-size: 16px !important;
        text-align: left !important;
        line-height: 1.4 !important;
    }
    
    /* MOBILE: Level 4+ nested submenu links */
    .ac-wp-ham-container .ac-wp-ham-submenu .ac-wp-ham-submenu .ac-wp-ham-submenu .ac-wp-ham-submenu a {
        padding: 14px 60px !important;
        font-size: 16px !important;
        text-align: left !important;
        line-height: 1.4 !important;
    }
    
    /* MOBILE: Remove left positioning classes */
    .ac-wp-ham-container .ac-wp-ham-submenu.ac-wp-ham-submenu-left {
        left: auto !important;
        right: auto !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
    
    /* MOBILE: Ensure arrows are right-aligned */
    .ac-wp-ham-container .ac-wp-ham-submenu-arrow {
        margin-left: auto !important;
    }
}

@media (max-width: 480px) {
    /* MOBILE SMALL: Maintain menu width but slightly smaller */
    .ac-wp-ham-container .ac-wp-ham-menu {
        min-width: 280px;
        max-width: 95vw;
        width: 95vw;
    }
    
    /* MOBILE SMALL: Keep consistent font sizes and alignment */
    .ac-wp-ham-container .ac-wp-ham-nav-list a {
        padding: 14px 18px !important;
        font-size: 16px !important;
        text-align: left !important;
    }
    
    /* MOBILE SMALL: Consistent submenu styling */
    .ac-wp-ham-container .ac-wp-ham-submenu a {
        padding: 12px 28px !important;
        font-size: 16px !important;
        text-align: left !important;
    }
    
    /* MOBILE SMALL: Adjust nested indentation slightly */
    .ac-wp-ham-container .ac-wp-ham-submenu .ac-wp-ham-submenu a {
        padding: 10px 35px !important;
    }
    
    .ac-wp-ham-container .ac-wp-ham-submenu .ac-wp-ham-submenu .ac-wp-ham-submenu a {
        padding: 8px 42px !important;
    }
}

/* ========================================
   ACCESSIBILITY & PERFORMANCE
   ======================================== */

/* Focus management for keyboard navigation */
.ac-wp-ham-container .ac-wp-ham-menu[aria-hidden="true"] {
    pointer-events: none;
}

.ac-wp-ham-container .ac-wp-ham-menu[aria-hidden="false"] {
    pointer-events: auto;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .ac-wp-ham-container .ac-wp-ham-toggle,
    .ac-wp-ham-container .ac-wp-ham-line,
    .ac-wp-ham-container .ac-wp-ham-menu,
    .ac-wp-ham-container .ac-wp-ham-nav-list a,
    .ac-wp-ham-container .ac-wp-ham-submenu-arrow,
    .ac-wp-ham-container .ac-wp-ham-submenu {
        transition: none !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .ac-wp-ham-container .ac-wp-ham-toggle {
        background-color: white;
        border: 2px solid black;
    }
    
    .ac-wp-ham-container .ac-wp-ham-menu {
        background: white;
        border: 2px solid black;
    }
    
    .ac-wp-ham-container .ac-wp-ham-nav-list a {
        border-bottom: 1px solid black;
    }
}

.scrolled-top:not(.scrolled-top:hover) .ac-wp-ham-container .textpurple {
    color: white!important
}

.scrolled-top:not(.scrolled-top:hover) .ac-wp-ham-container .ac-wp-ham-line {
    background-color: white!important
}