/* ======== Mega Menu — Tab‑switch layout ========
 *
 * THEME ISOLATION STRATEGY
 * ~~~~~~~~~~~~~~~~~~~~~~~~
 * The mega‑menu dropdown lives inside a nav <li class="menu-item"> element,
 * so *every* theme that styles navigation descendants (e.g. Astra's
 * `.main-header-menu .menu-item > .menu-link`, `.ast-builder-menu-1
 * .main-header-menu .menu-item > .menu-link`, GeneratePress's
 * `.main-navigation a`, etc.) will leak padding / margin / color / line‑height
 * into our `<a>` tabs and child links.
 *
 * To win the cascade, all selectors that style elements *inside* the dropdown
 * are scoped to at least:
 *     li.cxb-mega-menu-item .cxb-mega-dropdown …
 * giving an effective specificity of 0,2,1 BEFORE the inner selector — high
 * enough to beat 0,4,0 Astra selectors once the inner class is added.
 *
 * Every property a theme is known to inject (padding, margin, color,
 * line-height, font-size, text-transform, letter-spacing, border, background,
 * box-shadow, text-decoration, display, width) is explicitly declared so that
 * no theme can leak through.
 * ============================================================================ */

li.cxb-mega-menu-item {
    position: relative !important;
}
li.cxb-mega-menu-item > a > .cxb-mega-link-arrow {
    display: inline-block;
    vertical-align: middle;
    margin-left: 4px;
    margin-right: 0;
    padding: 0;
    border: none;
    background: none;
    box-shadow: none;
    transition: transform .25s ease;
    position: relative;
    top: -1px;
    width: 14px;
    height: 14px;
    line-height: 1;
    color: currentColor;
}
li.cxb-mega-menu-item.cxb-mega-open > a > .cxb-mega-link-arrow {
    transform: rotate(180deg);
}

/* ---- Dropdown container ---- */
li.cxb-mega-menu-item > .cxb-mega-dropdown {
    display: none;
    position: absolute;
    left: 0;
    top: 100%;
    z-index: 2147483646;
    background: #fff;
    background-image: none;
    border-radius: 14px;
    box-shadow: 0 10px 40px rgba(0,0,0,.13), 0 2px 10px rgba(0,0,0,.06);
    box-sizing: border-box;
    width: 70vw;
    height: 70vh;
    min-width: 700px;
    max-width: 1300px;
    overflow: hidden;
    padding: 0;
    margin: 0;
    border: none;
    float: none;
    text-align: left;
    font-size: 14px;
    line-height: 1.5;
    letter-spacing: normal;
    text-transform: none;
    color: #333;
    visibility: visible;
    opacity: 1;
    transform: none;
    transition: none;
    pointer-events: auto;
}
li.cxb-mega-menu-item.cxb-mega-open > .cxb-mega-dropdown {
    display: block;
}
/* Override: force‑close after the close button is clicked (even while hovering) */
.cxb-mega-dropdown.cxb-mega-force-closed {
    display: none !important;
}

/* ---- Inner: left / right split ---- */
li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-inner {
    display: flex;
    flex-direction: row;
    width: 100%;
    height: 100%;
    padding: 0;
    margin: 0;
    border: none;
    background: transparent;
}

/* ---- Left panel: parent tabs (30%) ---- */
li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-tabs {
    width: 30%;
    flex: 0 0 30%;
    max-width: 300px;
    overflow-y: auto;
    overflow-x: hidden;
    border-right: 1px solid #f0f0f0;
    border-top: none;
    border-bottom: none;
    border-left: none;
    padding: 12px 0;
    margin: 0;
    background: #fafbfc;
    background-image: none;
    border-radius: 14px 0 0 14px;
    scrollbar-width: thin;
    scrollbar-color: #ddd transparent;
    list-style: none;
}
li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-tabs::-webkit-scrollbar { width: 4px; }
li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-tabs::-webkit-scrollbar-track { background: transparent; }
li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-tabs::-webkit-scrollbar-thumb { background: #ddd; border-radius: 2px; }

/* ---- Tab links (the parent category items in the left panel) ----
 * These are <a> elements — prime targets for theme nav selectors.
 * Specificity: 0,5,2 — beats Astra's heaviest 0,4,0 selectors.     */
li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-tabs a.cxb-mega-tab {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px 10px 20px;
    margin: 0;
    color: #333;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.5;
    letter-spacing: normal;
    text-decoration: none;
    text-transform: none;
    text-shadow: none;
    text-align: left;
    white-space: normal;
    word-wrap: break-word;
    background: transparent;
    background-image: none;
    border: none;
    border-left: 3px solid transparent;
    border-radius: 0;
    box-shadow: none;
    box-sizing: border-box;
    outline: none;
    transition: background .15s ease, color .15s ease;
    float: none;
    width: auto;
    min-height: 0;
    height: auto;
    position: static;
    opacity: 1;
    visibility: visible;
}
li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-tabs a.cxb-mega-tab:hover,
li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-tabs a.cxb-mega-tab.cxb-mega-tab-active {
    background: #fff;
    background-image: none;
    color: var(--cxb-primary-color, #0A7AFF);
    border-left-color: var(--cxb-primary-color, #0A7AFF);
    text-decoration: none;
    box-shadow: none;
}
li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-tabs a.cxb-mega-tab:visited {
    color: #333;
}
li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-tabs a.cxb-mega-tab:hover:visited,
li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-tabs a.cxb-mega-tab.cxb-mega-tab-active:visited {
    color: var(--cxb-primary-color, #0A7AFF);
}
li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-tab-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0;
    margin: 0;
    border: none;
}
li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-tab-arrow {
    flex: 0 0 16px;
    width: 16px;
    height: 16px;
    color: #bbb;
    transition: color .15s ease;
    padding: 0;
    margin: 0;
    border: none;
    background: none;
}
li.cxb-mega-menu-item .cxb-mega-dropdown a.cxb-mega-tab:hover .cxb-mega-tab-arrow,
li.cxb-mega-menu-item .cxb-mega-dropdown a.cxb-mega-tab.cxb-mega-tab-active .cxb-mega-tab-arrow {
    color: var(--cxb-primary-color, #0A7AFF);
}

/* ---- Right panel: children content (70%) ---- */
li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-content {
    width: 70%;
    flex: 1 1 70%;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px 28px;
    margin: 0;
    border: none;
    background: transparent;
    scrollbar-width: thin;
    scrollbar-color: #ddd transparent;
}
li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-content::-webkit-scrollbar { width: 4px; }
li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-content::-webkit-scrollbar-track { background: transparent; }
li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-content::-webkit-scrollbar-thumb { background: #ddd; border-radius: 2px; }

li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-panel {
    display: none;
}
li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-panel.cxb-mega-panel-active {
    display: block;
}

/* ---- Children grid: adaptive wrapping, max 200px per column ---- */
li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-children-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 200px));
    gap: 16px 12px;
    padding: 0;
    margin: 0;
    border: none;
    list-style: none;
}

/* ---- Text‑only child (also <a> — must beat theme nav selectors) ---- */
li.cxb-mega-menu-item .cxb-mega-dropdown.cxb-mega-text a.cxb-mega-child {
    display: block;
    max-width: 200px;
    padding: 8px 12px;
    margin: 0;
    border: none;
    border-radius: 8px;
    background: #f5f6f8;
    background-image: none;
    color: #444;
    font-family: inherit;
    font-size: 13px;
    font-weight: 400;
    line-height: 1.5;
    letter-spacing: normal;
    text-decoration: none;
    text-transform: none;
    text-shadow: none;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow: none;
    box-sizing: border-box;
    outline: none;
    transition: background .15s ease, color .15s ease;
    float: none;
    width: auto;
    height: auto;
    min-height: 0;
    position: static;
    opacity: 1;
    visibility: visible;
}
li.cxb-mega-menu-item .cxb-mega-dropdown.cxb-mega-text a.cxb-mega-child:hover {
    background: #e8edff;
    background-image: none;
    color: var(--cxb-primary-color, #0A7AFF);
    text-decoration: none;
    box-shadow: none;
}
li.cxb-mega-menu-item .cxb-mega-dropdown.cxb-mega-text a.cxb-mega-child:visited {
    color: #444;
}

/* ---- Image‑mode child ---- */
li.cxb-mega-menu-item .cxb-mega-dropdown.cxb-mega-image .cxb-mega-children-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 130px));
}
li.cxb-mega-menu-item .cxb-mega-dropdown.cxb-mega-image a.cxb-mega-child {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    max-width: 130px;
    padding: 10px 6px;
    margin: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    background-image: none;
    color: #444;
    font-family: inherit;
    font-size: 12px;
    font-weight: 400;
    line-height: 1.5;
    letter-spacing: normal;
    text-decoration: none;
    text-transform: none;
    text-shadow: none;
    box-shadow: none;
    box-sizing: border-box;
    outline: none;
    transition: background .15s ease;
    float: none;
    width: auto;
    height: auto;
    min-height: 0;
    position: static;
    opacity: 1;
    visibility: visible;
}
li.cxb-mega-menu-item .cxb-mega-dropdown.cxb-mega-image a.cxb-mega-child:visited {
    color: #444;
}
li.cxb-mega-menu-item .cxb-mega-dropdown.cxb-mega-image .cxb-mega-child-name {
    display: block;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0;
    margin: 0;
    border: none;
}
li.cxb-mega-menu-item .cxb-mega-dropdown.cxb-mega-image a.cxb-mega-child:hover {
    background: #f8f9fb;
    text-decoration: none;
}
li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-child-img {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    object-fit: cover;
    background: #f0f0f0;
    margin-bottom: 8px;
    margin-top: 0;
    margin-left: 0;
    margin-right: 0;
    padding: 0;
    border: none;
    box-shadow: none;
    transition: transform .2s ease, box-shadow .2s ease;
}
li.cxb-mega-menu-item .cxb-mega-dropdown a.cxb-mega-child:hover .cxb-mega-child-img {
    transform: scale(1.08);
    box-shadow: 0 4px 14px rgba(0,0,0,.12);
}
li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-child-name {
    line-height: 1.3;
    padding: 0;
    margin: 0;
    border: none;
}

/* ---- No children placeholder ---- */
li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-no-children {
    padding: 30px 0;
    margin: 0;
    text-align: center;
    color: #999;
    font-size: 14px;
    line-height: 1.5;
    border: none;
    background: transparent;
}
li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-no-children a {
    color: var(--cxb-primary-color, #0A7AFF);
    text-decoration: none;
    padding: 0;
    margin: 0;
    border: none;
    background: transparent;
    box-shadow: none;
    font-size: inherit;
    line-height: inherit;
}

/* ---- Back button (mobile only, hidden on desktop) ---- */
li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-panel-back {
    display: none;
}

/* ---- Close button on dropdown (desktop only) ----
 * <button> element — must beat theme button resets from Astra/Hello
 * Elementor/GeneratePress etc.                                        */
li.cxb-mega-menu-item .cxb-mega-dropdown button.cxb-mega-close {
    position: absolute;
    top: 10px;
    right: 12px;
    left: auto;
    bottom: auto;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    min-width: 0;
    min-height: 0;
    max-width: none;
    max-height: none;
    border: none;
    border-radius: 50%;
    background: #f0f1f3;
    background-image: none;
    color: #666;
    cursor: pointer;
    padding: 0;
    margin: 0;
    transition: background .15s ease, color .15s ease;
    outline: none;
    box-shadow: none;
    box-sizing: border-box;
    appearance: none;
    -webkit-appearance: none;
    font-size: 0;
    font-weight: 400;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    text-decoration: none;
    text-shadow: none;
    text-align: center;
    float: none;
    overflow: visible;
    vertical-align: middle;
    opacity: 1;
    visibility: visible;
}
li.cxb-mega-menu-item .cxb-mega-dropdown button.cxb-mega-close:hover {
    background: #e4e5e8;
    background-image: none;
    color: #333;
    border: none;
    box-shadow: none;
    text-decoration: none;
}
li.cxb-mega-menu-item .cxb-mega-dropdown button.cxb-mega-close:active {
    background: #d8d9dc;
    background-image: none;
    border: none;
    box-shadow: none;
}
li.cxb-mega-menu-item .cxb-mega-dropdown button.cxb-mega-close svg {
    display: block;
    width: 18px;
    height: 18px;
    margin: 0;
    padding: 0;
    border: none;
    color: inherit;
}

/* ---- Mobile ---- */
@media (max-width: 768px) {
    /* Desktop‑only elements: hidden on mobile */
    li.cxb-mega-menu-item > a > .cxb-mega-link-arrow,
    li.cxb-mega-menu-item .cxb-mega-dropdown button.cxb-mega-close {
        display: none !important;
    }

    li.cxb-mega-menu-item > .cxb-mega-dropdown {
        position: fixed;
        left: 3%;
        right: 3%;
        top: 10vh;
        transform: none;
        width: 94%;
        height: 75vh;
        min-width: auto;
        max-width: none;
        border-radius: 12px;
    }

    /* Mobile drill-down: initial state — tabs 100%, content hidden */
    li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-tabs {
        width: 100%;
        flex: 0 0 100%;
        max-width: none;
        padding: 8px 0;
        border-radius: 14px;
    }
    li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-content {
        width: 0;
        flex: 0 0 0;
        overflow: hidden;
        padding: 0;
    }

    /* Drilled-in state: tabs hidden, content 100% */
    li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-inner.cxb-mega-drilled .cxb-mega-tabs {
        width: 0;
        flex: 0 0 0;
        overflow: hidden;
        padding: 0;
    }
    li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-inner.cxb-mega-drilled .cxb-mega-content {
        width: 100%;
        flex: 0 0 100%;
        overflow-y: auto;
        padding: 0;
    }

    li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-tabs a.cxb-mega-tab {
        padding: 10px 14px 10px 16px;
        font-size: 14px;
    }
    li.cxb-mega-menu-item .cxb-mega-dropdown a.cxb-mega-tab[data-has-children="0"] .cxb-mega-tab-arrow {
        display: none;
    }

    /* Back button visible on mobile */
    li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-panel-back {
        display: flex;
        align-items: center;
        gap: 6px;
        padding: 12px 16px;
        margin: 0;
        font-size: 15px;
        font-weight: 600;
        color: var(--cxb-primary-color, #0A7AFF);
        border: none;
        border-bottom: 1px solid #f0f0f0;
        background: transparent;
        cursor: pointer;
        user-select: none;
        -webkit-user-select: none;
    }
    li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-panel-back svg {
        flex: 0 0 16px;
        color: var(--cxb-primary-color, #0A7AFF);
    }

    /* Vertical layout for children */
    li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-children-grid {
        display: flex;
        flex-direction: column;
        gap: 0;
    }
    li.cxb-mega-menu-item .cxb-mega-dropdown.cxb-mega-text a.cxb-mega-child {
        border-radius: 0;
        background: none;
        background-image: none;
        padding: 11px 16px;
        border: none;
        border-bottom: 1px solid #f5f5f5;
        max-width: none;
    }
    li.cxb-mega-menu-item .cxb-mega-dropdown.cxb-mega-text a.cxb-mega-child:last-child {
        border-bottom: none;
    }
    li.cxb-mega-menu-item .cxb-mega-dropdown.cxb-mega-text a.cxb-mega-child:hover {
        background: #f8f9fb;
    }

    /* Image mode: vertical rows */
    li.cxb-mega-menu-item .cxb-mega-dropdown.cxb-mega-image .cxb-mega-children-grid {
        grid-template-columns: none;
        display: flex;
        flex-direction: column;
        gap: 0;
    }
    li.cxb-mega-menu-item .cxb-mega-dropdown.cxb-mega-image a.cxb-mega-child {
        flex-direction: row;
        text-align: left;
        max-width: none;
        padding: 10px 16px;
        border: none;
        border-bottom: 1px solid #f5f5f5;
        border-radius: 0;
    }
    li.cxb-mega-menu-item .cxb-mega-dropdown.cxb-mega-image a.cxb-mega-child:last-child {
        border-bottom: none;
    }
    li.cxb-mega-menu-item .cxb-mega-dropdown .cxb-mega-child-img {
        width: 40px;
        height: 40px;
        margin-bottom: 0;
        margin-right: 10px;
        flex: 0 0 40px;
    }
}

/* ---- Mobile Modal (appended to <body>, immune to theme menu JS) ---- */
.cxb-mega-modal-backdrop {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,.45);
    z-index: 2147483644;
}
.cxb-mega-modal {
    position: fixed;
    left: 4%;
    right: 4%;
    top: 8vh;
    bottom: 8vh;
    width: 92%;
    z-index: 2147483645;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 10px 40px rgba(0,0,0,.18);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.cxb-mega-modal .cxb-mega-modal-close {
    position: absolute;
    top: 10px;
    right: 12px;
    left: auto;
    bottom: auto;
    z-index: 5;
    width: 32px;
    height: 32px;
    min-width: 0;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: none;
    background: #f0f0f0;
    background-image: none;
    color: #666;
    cursor: pointer;
    padding: 0;
    margin: 0;
    box-shadow: none;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    font-size: 0;
    line-height: 1;
}
.cxb-mega-modal .cxb-mega-modal-close:active {
    background: #ddd;
}

/* Parent list */
.cxb-mega-modal .cxb-mega-modal-parents {
    flex: 1;
    overflow-y: auto;
    padding: 14px 0;
    margin: 0;
    border: none;
    background: transparent;
    list-style: none;
    -webkit-overflow-scrolling: touch;
}
.cxb-mega-modal .cxb-mega-modal-parent-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 13px 18px;
    margin: 0;
    font-size: 15px;
    line-height: 1.5;
    color: #333;
    cursor: pointer;
    border: none;
    border-bottom: 1px solid #f3f3f3;
    background: transparent;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}
.cxb-mega-modal .cxb-mega-modal-parent-item:active {
    background: #f5f7fa;
}
.cxb-mega-modal .cxb-mega-modal-parent-item svg {
    flex: 0 0 16px;
    color: #bbb;
    padding: 0;
    margin: 0;
    border: none;
}
.cxb-mega-modal .cxb-mega-modal-parent-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0;
    margin: 0;
    border: none;
}

/* Children view */
.cxb-mega-modal .cxb-mega-modal-children {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.cxb-mega-modal .cxb-mega-modal-back {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 13px 16px;
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.5;
    color: var(--cxb-primary-color, #0A7AFF);
    border: none;
    border-bottom: 1px solid #f0f0f0;
    background: transparent;
    cursor: pointer;
    flex: 0 0 auto;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}
.cxb-mega-modal .cxb-mega-modal-back:active {
    background: #f5f7fa;
}
.cxb-mega-modal .cxb-mega-modal-back svg {
    flex: 0 0 16px;
    color: var(--cxb-primary-color, #0A7AFF);
    padding: 0;
    margin: 0;
    border: none;
}
.cxb-mega-modal .cxb-mega-modal-children-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px 0;
    margin: 0;
    border: none;
    background: transparent;
    list-style: none;
    -webkit-overflow-scrolling: touch;
}
.cxb-mega-modal .cxb-mega-modal-child-item {
    display: flex;
    align-items: center;
    padding: 12px 18px;
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
    color: #444;
    cursor: pointer;
    border: none;
    border-bottom: 1px solid #f5f5f5;
    background: transparent;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}
.cxb-mega-modal .cxb-mega-modal-child-item:last-child {
    border-bottom: none;
}
.cxb-mega-modal .cxb-mega-modal-child-item:active {
    background: #f5f7fa;
}
.cxb-mega-modal .cxb-mega-modal-child-img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    background: #f0f0f0;
    margin: 0 12px 0 0;
    padding: 0;
    border: none;
    box-shadow: none;
    flex: 0 0 40px;
}
.cxb-mega-modal .cxb-mega-modal-child-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0;
    margin: 0;
    border: none;
}
