/**
 * Mega Menu Frontend Styles
 */

.wew-mega-menu-nav {
    display: flex;
    list-style: none;
    margin: 0;
    padding: 0;
    flex-wrap: nowrap; /* never wrap to next line — collapse is handled by .wew-mobile-active */
}

.wew-mega-menu-nav>li {
    position: relative;
}

.wew-mega-menu-nav>li>a {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    padding: 15px 20px;
    color: #333;
    transition: all 0.3s;
}

.wew-mm-arrow {
    font-size: 14px;
    width: 14px;
    height: 14px;
    line-height: 1;
    color: inherit;
    opacity: 0.7;
    transition: transform 0.3s ease;
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
}

.wew-mega-menu-nav>li:hover .wew-mm-arrow {
    transform: rotate(180deg);
}

/* Suppress any native theme arrows on the menu link to avoid duplicates */
.wew-mega-menu-nav>li>a::after,
.wew-mega-menu-nav>li>a::before {
    display: none !important;
    content: none !important;
}

/* Submenu Default - Refined to prevent leakage into Mega Menu */
.wew-mega-menu-nav>li>.sub-menu {
    position: absolute;
    top: 100%;
    left: 0;
    background: #fff;
    min-width: 200px;
    box-shadow: var(--wew-mm-shadow, 0 5px 20px rgba(0, 0, 0, 0.1));
    list-style: none;
    padding: 10px 0;
    margin: 0;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.3s ease;
    z-index: 1000;
}

.wew-mega-menu-nav>li:hover>.sub-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.wew-mega-menu-nav>li>.sub-menu li a {
    display: block;
    padding: 10px 20px;
    text-decoration: none;
    color: #666;
    transition: all 0.2s;
}

.wew-mega-menu-nav>li>.sub-menu li a:hover {
    background: #f8f9fa;
    color: #333;
}

/* Isolation for Elementor Content inside Mega Menu */
.wew-megamenu-container ul,
.wew-megamenu-container li,
.wew-megamenu-container a,
.wew-megamenu-container span {
    all: revert;
    box-sizing: border-box;
}

.wew-megamenu-container ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

/* Aggressive Reset to kill theme menu leakage */
.wew-megamenu-container li {
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    list-style: none !important;
    background: none !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    line-height: normal !important;
}

.wew-megamenu-container a {
    padding: 0 !important;
    margin: 0 !important;
    display: inline !important;
    /* Revert theme block display */
    width: auto !important;
    height: auto !important;
    line-height: normal !important;
    text-decoration: none !important;
    background: none !important;
}

/* Restore Elementor specific layouts after the reset */
.wew-megamenu-container .elementor-icon-list-item {
    display: flex !important;
    align-items: center !important;
}

.wew-megamenu-container .elementor-icon-list-item a {
    display: flex !important;
    align-items: center !important;
    width: 100% !important;
}

.wew-megamenu-container .elementor-icon-list-text {
    display: inline-block !important;
    line-height: 1.5 !important;
    /* Standard Elementor line-height */
}

/* Mega Menu Panel */
.wew-megamenu-container {
    display: none;
    position: absolute;
    top: 100%;
    background: #fff;
    /* Shadow moved to ::after to allow clipping without breaking the hover bridge */
    box-shadow: none !important;
    opacity: 0;
    transform: translateY(15px);
    transition: transform 0.3s cubic-bezier(0.165, 0.84, 0.44, 1), opacity 0.3s ease;
    z-index: 99999;
    padding: 30px;
    min-width: 400px;
}

/* Shadow layer that allows side-clipping */
.wew-megamenu-container::after {
    content: "";
    position: absolute;
    inset: 0;
    background: inherit;
    border-radius: inherit;
    box-shadow: var(--wew-mm-shadow, 0 10px 30px rgba(0, 0, 0, 0.15)) !important;
    z-index: -1;
    pointer-events: none;
    clip-path: var(--wew-mm-clip, inset(-500px -500px -500px -500px));
}

/* Bridge to prevent hover loss when there's a gap (due to Top distance) */
/* pointer-events: none here is intentional - the gap is handled by a JS timer instead */
.wew-megamenu-container::before {
    content: "";
    position: absolute;
    top: -120px;
    left: 0;
    right: 0;
    height: 120px;
    z-index: -1;
    pointer-events: none;
}

/* Submenu (standard WP) still uses pure-CSS hover on desktop.
   Megamenu panels (.wew-megamenu-container) are shown/hidden by JS only
   to avoid interference when multiple navs exist on the same page. */
.wew-mega-menu-nav li:hover > .sub-menu {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

/* Full Width Mega Menu */
.wew-mm-fullwidth {
    position: static !important;
}

.wew-mm-fullwidth>.wew-megamenu-container {
    left: auto;
    right: auto;
    width: 100%;
    max-width: none;
}

/* Relative Positioning */
.wew-mm-relative>.wew-megamenu-container {
    left: 50%;
    transform: translateX(-50%) translateY(15px);
}

.wew-mm-relative:hover>.wew-megamenu-container {
    transform: translateX(-50%) translateY(0);
}

/* Custom Width */
.wew-mm-customwidth>.wew-megamenu-container {
    left: 50%;
    transform: translateX(-50%) translateY(15px);
}

.wew-mm-customwidth:hover>.wew-megamenu-container {
    transform: translateX(-50%) translateY(0);
}

/* Hide standard submenu when megamenu is active on desktop/tablet.
   Use min-width: 769px so this rule does NOT apply on true mobile (< 768px),
   which is when .wew-mobile-active kicks in and we DO want the WP sub-menu. */
@media (min-width: 769px) {
    .wew-has-megamenu > .sub-menu {
        display: none !important;
    }
}

/* Responsive Logic - Mobile/Tablet */
/* The JS will handle adding a class like .wew-mobile-active based on breakpoint setting */

.wew-mega-menu-nav.wew-mobile-active {
    flex-direction: column;
}

.wew-mega-menu-nav.wew-mobile-active .sub-menu,
.wew-mega-menu-nav.wew-mobile-active .wew-megamenu-container {
    position: static !important;
    opacity: 1 !important;
    visibility: visible !important;
    transform: none !important;
    box-shadow: none !important;
    display: none;
    /* Managed by toggle in JS */
    width: 100% !important;
    padding: 15px !important;
}

/* On mobile, we HIDE the Elementor template and SHOW the WP sub-menu */
.wew-mega-menu-nav.wew-mobile-active .wew-megamenu-container {
    display: none !important;
}

.wew-mega-menu-nav.wew-mobile-active .wew-has-megamenu>.sub-menu {
    display: block;
    /* We want it to be toggleable by JS */
}

.wew-menu-toggle {
    display: none;
    background: none;
    border: none;
    padding: 10px;
    cursor: pointer;
}

.wew-mega-menu-nav.wew-mobile-active .wew-menu-toggle {
    display: block;
}