/**
 * Auto Menu V3 - Clean & Modern Styles
 * @version 3.0
 */

/* ===== BASE NAVIGATION ===== */
.apc-nav {
    position: relative;
    width: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    z-index: 9999;
    clear: both;
    display: block;
    box-sizing: border-box;
}

/* === AGGRESSIVE FIX FOR THEME HEADER OVERLAP === */
/* This ensures menu always appears on its own line below theme headers */

/* Force menu to be block-level and full width */
.apc-nav,
nav.apc-nav,
div.apc-nav {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    clear: both !important;
    float: none !important;
}

/* When inside any header container, ensure proper stacking */
header .apc-nav,
.site-header .apc-nav,
#masthead .apc-nav,
.main-header .apc-nav,
.header-wrapper .apc-nav,
.header-inner .apc-nav {
    display: block !important;
    width: 100% !important;
    clear: both !important;
    float: none !important;
    position: relative !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
}

/* Handle flexbox headers - force menu to new line */
header[class*="header"] .apc-nav,
[class*="site-header"] .apc-nav,
[class*="main-header"] .apc-nav {
    flex: 0 0 100% !important;
    max-width: 100% !important;
    order: 999 !important;
}

/* Ensure menu lists also take full width */
.apc-list-simple,
.apc-list-mega {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
}

/* Fix for theme header integration - ensure menu is full width */
header .apc-nav,
.site-header .apc-nav,
.apc-shell-header .apc-nav,
.apc-brand-header .apc-nav,
.apc-premium-header .apc-nav {
    width: 100%;
    display: block;
    clear: both;
}

/* When menu is inside a header with logo, make it full width below */
.apc-shell-header,
.apc-brand-header,
.apc-premium-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
}

.apc-shell-header .apc-nav,
.apc-brand-header .apc-nav,
.apc-premium-header .apc-nav {
    flex: 0 0 100%;
    order: 3;
    margin-top: 10px;
}

/* Fix for when menu appears in theme header - prevent overlap */
.apc-nav::before,
.apc-nav::after {
    content: '';
    display: table;
    clear: both;
}

/* ===== MOBILE TOGGLE ===== */
.apc-menu-toggle {
    display: none;
    width: 100%;
    padding: 15px 20px;
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    align-items: center;
    justify-content: space-between;
}

.apc-bars {
    width: 20px;
    height: 2px;
    background: white;
    position: relative;
}

.apc-bars::before,
.apc-bars::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 2px;
    background: white;
    left: 0;
}

.apc-bars::before { top: -6px; }
.apc-bars::after { top: 6px; }

.apc-menu-toggle[aria-expanded="true"] .apc-bars {
    background: transparent;
}

.apc-menu-toggle[aria-expanded="true"] .apc-bars::before {
    transform: rotate(45deg);
    top: 0;
}

.apc-menu-toggle[aria-expanded="true"] .apc-bars::after {
    transform: rotate(-45deg);
    top: 0;
}

/* ===== SIMPLE MENU ===== */
.apc-list-simple {
    display: flex;
    list-style: none;
    margin: 0;
    padding: 0;
    justify-content: center;
    flex-wrap: wrap;
}

/* Ensure menu displays below any logo/branding */
.apc-nav + .apc-nav,
header + .apc-nav,
.site-header + .apc-nav {
    margin-top: 0;
}

/* When menu is inside a container with logo, stack vertically on small screens */
@media (max-width: 1024px) {
    .apc-shell-header .apc-list-simple,
    .apc-brand-header .apc-list-simple {
        justify-content: flex-start;
    }
}

.apc-list-simple li {
    position: relative;
}

.apc-link {
    display: block;
    padding: 15px 20px;
    color: white;
    text-decoration: none;
    font-weight: 500;
    transition: background 0.2s ease;
    white-space: nowrap;
}

.apc-link:hover,
.apc-link:focus {
    background: rgba(255,255,255,0.15);
}

.apc-arrow {
    font-size: 10px;
    margin-left: 5px;
    opacity: 0.7;
}

/* Dropdown */
.apc-has-dropdown .apc-link {
    padding-right: 35px;
}

.apc-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 220px;
    background: white;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    border-radius: 0 0 8px 8px;
    list-style: none;
    margin: 0;
    padding: 8px 0;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    z-index: 1000;
}

.apc-has-dropdown:hover .apc-dropdown,
.apc-has-dropdown:focus-within .apc-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.apc-dropdown-link {
    display: block;
    padding: 10px 20px;
    color: #333;
    text-decoration: none;
    font-size: 14px;
    transition: all 0.2s ease;
}

.apc-dropdown-link:hover {
    background: #f8f9fa;
    color: #667eea;
    padding-left: 25px;
}

.apc-dropdown-link.apc-more {
    color: #667eea;
    font-weight: 600;
}

/* ===== MEGA MENU ===== */
.apc-list-mega {
    display: flex;
    list-style: none;
    margin: 0 auto;
    padding: 0;
    justify-content: center;
    max-width: 1400px;
}

.apc-list-mega .apc-item {
    position: relative;
}

.apc-list-mega .apc-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 18px 22px;
    font-size: 15px;
}

.apc-list-mega .apc-home {
    font-weight: 700;
}

.apc-star {
    color: #ffd700;
    font-size: 12px;
}

.apc-pillar .apc-link {
    font-weight: 600;
}

/* Mega Dropdown */
.apc-mega {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-10px);
    width: 500px;
    max-width: 90vw;
    background: white;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    border-radius: 0 0 12px 12px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 1000;
    padding: 20px;
}

.apc-has-mega:hover .apc-mega,
.apc-has-mega:focus-within .apc-mega {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.apc-mega::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-bottom: 8px solid white;
}

.apc-mega-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 12px;
    border-bottom: 2px solid #f0f0f0;
}

.apc-mega-header strong {
    font-size: 16px;
    color: #333;
}

.apc-count {
    font-size: 12px;
    color: #666;
    background: #f0f0f0;
    padding: 4px 10px;
    border-radius: 12px;
}

.apc-mega-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.apc-mega-link {
    display: block;
    padding: 10px 12px;
    color: #555;
    text-decoration: none;
    font-size: 14px;
    border-radius: 6px;
    transition: all 0.2s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.apc-mega-link:hover {
    background: #f8f9fa;
    color: #667eea;
}

.apc-mega-footer {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #f0f0f0;
    text-align: center;
    font-size: 13px;
    color: #999;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .apc-menu-toggle {
        display: flex;
    }
    
    .apc-list-simple,
    .apc-list-mega {
        display: none;
        flex-direction: column;
        max-height: 70vh;
        overflow-y: auto;
    }
    
    .apc-list-simple.active,
    .apc-list-mega.active {
        display: flex;
    }
    
    .apc-list-simple li,
    .apc-list-mega .apc-item {
        width: 100%;
    }
    
    .apc-link {
        padding: 15px 20px;
        border-bottom: 1px solid rgba(255,255,255,0.1);
    }
    
    .apc-dropdown,
    .apc-mega {
        position: static;
        width: 100%;
        max-width: 100%;
        transform: none;
        opacity: 1;
        visibility: visible;
        display: none;
        box-shadow: none;
        background: rgba(0,0,0,0.2);
        border-radius: 0;
    }
    
    .apc-dropdown.active,
    .apc-mega.active {
        display: block;
    }
    
    .apc-mega::before {
        display: none;
    }
    
    .apc-mega-header {
        border-bottom-color: rgba(255,255,255,0.2);
    }
    
    .apc-mega-header strong {
        color: white;
    }
    
    .apc-count {
        background: rgba(255,255,255,0.2);
        color: rgba(255,255,255,0.9);
    }
    
    .apc-mega-list {
        grid-template-columns: 1fr;
    }
    
    .apc-mega-link {
        color: rgba(255,255,255,0.9);
        padding: 12px 15px;
    }
    
    .apc-mega-link:hover {
        background: rgba(255,255,255,0.1);
        color: white;
    }
    
    .apc-mega-footer {
        color: rgba(255,255,255,0.7);
        border-top-color: rgba(255,255,255,0.1);
    }
}

/* ===== ACCESSIBILITY ===== */
.apc-nav a:focus {
    outline: 2px solid white;
    outline-offset: -2px;
}

@media (prefers-reduced-motion: reduce) {
    .apc-nav * {
        transition: none !important;
    }
}

/* ===== PRINT ===== */
@media print {
    .apc-nav {
        display: none;
    }
}

/* ===== FIX FOR THEME HEADER OVERLAP ===== */

/* Ensure menu clears any floats and displays on its own line */
.apc-nav {
    clear: both;
    display: block;
    width: 100%;
}

/* When menu is the first child, ensure no overlap with theme header */
body > .apc-nav:first-child {
    position: relative;
    margin-top: 0;
}

/* Push content below menu to prevent overlap with fixed headers */
.apc-nav ~ .site-content,
.apc-nav ~ #content,
.apc-nav ~ main,
.apc-nav ~ .content-area {
    position: relative;
}

/* Ensure any logo in the same container as menu doesn't overlap */
.apc-brand-header,
.apc-shell-header {
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

.apc-brand-header .apc-brand-logo,
.apc-shell-header .apc-brand-logo {
    display: block;
    padding: 20px;
    text-align: center;
    background: white;
}

.apc-brand-header .apc-nav,
.apc-shell-header .apc-nav {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
}

/* Fix for when theme has logo and menu in header area */
.site-header .apc-nav,
header .apc-nav,
#header .apc-nav,
.header-wrapper .apc-nav {
    position: relative;
    display: block;
    width: 100%;
    clear: both;
}

/* When theme uses flex for header, menu should be full width */
header[class*="header"] .apc-nav,
[class*="site-header"] .apc-nav,
[class*="main-header"] .apc-nav {
    flex: 0 0 100%;
    max-width: 100%;
}

/* Ensure dropdowns appear above theme elements */
.apc-dropdown,
.apc-mega {
    z-index: 99999;
}

/* Fix for 09wi theme and similar themes */
.custom-header + .apc-nav,
#masthead + .apc-nav,
.header-inner + .apc-nav {
    margin-top: 0;
}

/* Prevent theme logo from overlapping menu bar */
.apc-nav::before {
    content: '';
    display: table;
    clear: both;
}

/* When menu is displayed after a logo, ensure proper spacing */
img + .apc-nav,
.logo + .apc-nav,
.site-logo + .apc-nav,
.brand + .apc-nav {
    margin-top: 0;
}

/* Ensure proper stacking context */
.apc-nav {
    transform: translateZ(0);
    will-change: transform;
}

/* ===== ADDITIONAL FIX FOR THEME HEADER OVERLAP ===== */

/* When menu appears inside theme header, ensure it stacks below logo */
header .apc-nav,
.site-header .apc-nav,
#masthead .apc-nav,
.header-inner .apc-nav {
    display: block !important;
    width: 100% !important;
    clear: both !important;
    position: relative !important;
    margin-top: 10px !important;
}

/* Ensure menu list doesn't wrap weirdly with theme elements */
header .apc-list-simple,
.site-header .apc-list-simple,
header .apc-list-mega,
.site-header .apc-list-mega {
    display: flex !important;
    justify-content: center !important;
    width: 100% !important;
}

/* Push menu to its own line when following any branding elements */
.custom-logo-link + .apc-nav,
.site-title + .apc-nav,
.site-branding + .apc-nav,
.branding + .apc-nav,
.header-logo + .apc-nav,
.site-identity + .apc-nav {
    display: block !important;
    width: 100% !important;
    margin-top: 0 !important;
}

/* When menu is at the very top, ensure proper display */
body > .apc-nav,
#page > .apc-nav:first-child,
#wrapper > .apc-nav:first-child {
    position: relative;
    top: auto;
    left: auto;
}

/* Ensure menu doesn't get constrained by theme header flex layout */
header > .apc-nav,
.site-header > .apc-nav,
.main-header > .apc-nav,
.header-main > .apc-nav,
.header-container > .apc-nav {
    flex: none !important;
    align-self: stretch !important;
}

/* Handle themes with inline-block header items */
.site-branding,
.custom-logo-link,
.site-title,
.site-description {
    vertical-align: middle;
}

/* When theme has logo + nav in same row, menu should break to new line */
.apc-nav {
    flex-basis: 100% !important;
}

/* Specific fix for themes with flex row headers */
@media (min-width: 769px) {
    header,
    .site-header,
    #masthead,
    .main-header {
        flex-wrap: wrap !important;
    }
    
    header .apc-nav,
    .site-header .apc-nav,
    #masthead .apc-nav {
        order: 99 !important;
    }
}

/* Ensure menu doesn't overlap sticky/fixed theme headers */
.site-header.sticky .apc-nav,
.site-header.fixed .apc-nav,
header.sticky .apc-nav,
header.fixed .apc-nav {
    position: relative !important;
}

/* Handle specific theme structures - 09wi and similar */
.apc-nav {
    isolation: isolate;
}

/* Ensure proper spacing between theme header and menu */
.apc-nav:first-of-type {
    margin-top: 0;
}

/* When menu appears after any block element, ensure no float issues */
.apc-nav {
    float: none !important;
}
