/**
 * Centrul Muzical — Menu Animations & Navigation Enhancements
 * File: assets/css/cm-menu.css
 * Theme: Astra Child (astra-child)
 *
 * Description:
 * Separate stylesheet dedicated to desktop & mobile menu animations,
 * in-place arrow rotation, full-site mobile backdrop overlay,
 * gradual accordion submenu height transitions, and focus outline fixes.
 *
 * Contents:
 * 1. Desktop Submenu Animations (Reveal, Slide, Scale, Hover States)
 * 2. Desktop Arrow In-Place Rotation (No Left Shift)
 * 3. Mobile Full-Site Backdrop Overlay (Excludes Logo & Toggle)
 * 4. Mobile Header Container (Slide & Fade + Bottom Separation Shadow)
 * 5. Mobile Navigation Menu Items (Staggered Intro Cascading)
 * 6. Mobile Submenus Gradual Accordion (Height, Opacity & Slide on Open/Close)
 * 7. Mobile Arrow In-Place Rotation (No Left Shift)
 * 8. Dropdown Toggle Button Fix (Removes Off-Center Dotted Outline & Border)
 * 9. Accessibility & Reduced Motion Support
 * 10. Elementor Editor Neutralization
 */

/* ==========================================================================
   1. DESKTOP SUBMENU ANIMATIONS (min-width: 922px)
   ========================================================================== */
@media (min-width: 922px) {
    /* Submenu Container: smooth reveal with subtle slide & scale */
    .ast-desktop .main-header-menu .sub-menu {
        display: block !important;
        visibility: hidden;
        opacity: 0;
        transform: translateY(12px) scale(0.98);
        pointer-events: none;
        transition: opacity 0.26s cubic-bezier(0.16, 1, 0.3, 1),
                    transform 0.26s cubic-bezier(0.16, 1, 0.3, 1),
                    visibility 0.26s cubic-bezier(0.16, 1, 0.3, 1) !important;
        box-shadow: 0 16px 36px -4px rgba(15, 23, 42, 0.12), 0 8px 16px -4px rgba(15, 23, 42, 0.08) !important;
        border: 1px solid #E2E8F0 !important;
        border-radius: 6px !important;
        padding: 6px 0 !important;
        background-color: #FFFFFF !important;
        will-change: opacity, transform;
    }

    /* Submenu Hit-Area Bridge (prevents mouse flicker when moving from item to dropdown) */
    .ast-desktop .main-header-menu .sub-menu::before {
        content: "";
        position: absolute;
        top: -12px;
        left: 0;
        right: 0;
        height: 12px;
    }

    /* Open State on Hover, Focus or Focus-Within */
    .ast-desktop .main-header-menu .menu-item-has-children:hover > .sub-menu,
    .ast-desktop .main-header-menu .menu-item-has-children.focus > .sub-menu,
    .ast-desktop .main-header-menu .menu-item-has-children:focus-within > .sub-menu {
        visibility: visible !important;
        opacity: 1 !important;
        transform: translateY(0) scale(1) !important;
        pointer-events: auto !important;
    }

    /* Submenu Links styling and hover interactions */
    .ast-desktop .main-header-menu .sub-menu .menu-item > .menu-link {
        padding: 10px 22px !important;
        transition: background-color 0.2s ease, color 0.2s ease, padding-left 0.2s cubic-bezier(0.16, 1, 0.3, 1) !important;
        font-family: Roboto, sans-serif !important;
        font-size: 0.94rem !important;
    }
    .ast-desktop .main-header-menu .sub-menu .menu-item > .menu-link:hover {
        background-color: #F8FAFC !important;
        color: #DCA54A !important;
        padding-left: 26px !important;
    }

    /* 2. Desktop Arrow In-Place Rotation (Strictly around its own geometric center, zero shift) */
    .ast-desktop .main-header-menu .menu-item-has-children > .menu-link .ast-header-navigation-arrow svg {
        display: inline-block !important;
        transform-origin: 50% 50% !important;
        transform-box: fill-box !important;
        transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1) !important;
    }
    .ast-desktop .main-header-menu .menu-item-has-children:hover > .menu-link .ast-header-navigation-arrow svg,
    .ast-desktop .main-header-menu .menu-item-has-children.focus > .menu-link .ast-header-navigation-arrow svg {
        transform: rotate(180deg) !important;
    }
}

/* ==========================================================================
   2. MOBILE HEADER & NAVIGATION ENHANCEMENTS (max-width: 921px)
   ========================================================================== */
@media (max-width: 921px) {
    /* 3. Mobile Full-Site Backdrop Overlay (excludes logo & menu toggle) */
    body::before {
        content: "";
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(15, 23, 42, 0.65);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 90;
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: opacity 0.32s cubic-bezier(0.16, 1, 0.3, 1),
                    visibility 0.32s cubic-bezier(0.16, 1, 0.3, 1);
    }
    body.ast-main-header-nav-open::before {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    /* Keep header bar, logo, and mobile menu cleanly above the overlay */
    #masthead {
        z-index: 99 !important;
    }
    .ast-mobile-header-wrap {
        position: relative;
        z-index: 100;
    }

    /* 4. Mobile Menu Container: Smooth opening and closing */
    .ast-mobile-header-wrap .ast-mobile-header-content {
        display: none;
        opacity: 0;
        transform: translateY(-10px);
        transition: display 0.32s allow-discrete,
                    opacity 0.32s cubic-bezier(0.16, 1, 0.3, 1),
                    transform 0.32s cubic-bezier(0.16, 1, 0.3, 1);
        /* Bottom box-shadow to cleanly separate white menu from page content */
        box-shadow: 0 14px 28px -4px rgba(15, 23, 42, 0.12), 0 8px 12px -4px rgba(15, 23, 42, 0.06) !important;
        border-bottom: 1px solid rgba(226, 232, 240, 0.8) !important;
        will-change: opacity, transform;
    }

    .ast-main-header-nav-open.ast-header-break-point .ast-mobile-header-wrap .ast-mobile-header-content {
        display: block;
        opacity: 1;
        transform: translateY(0);
    }

    @starting-style {
        .ast-main-header-nav-open.ast-header-break-point .ast-mobile-header-wrap .ast-mobile-header-content {
            opacity: 0;
            transform: translateY(-10px);
        }
    }

    /* Fallback keyframes for mobile menu open */
    @keyframes cmMobileMenuSlideDown {
        0% {
            opacity: 0;
            transform: translateY(-10px);
        }
        100% {
            opacity: 1;
            transform: translateY(0);
        }
    }
    .ast-main-header-nav-open.ast-header-break-point .ast-mobile-header-wrap .ast-mobile-header-content {
        animation: cmMobileMenuSlideDown 0.32s cubic-bezier(0.16, 1, 0.3, 1);
    }

    /* 5. Staggered entrance of mobile menu items */
    @keyframes cmMobileItemEnter {
        0% {
            opacity: 0;
            transform: translateY(-6px);
        }
        100% {
            opacity: 1;
            transform: translateY(0);
        }
    }
    .ast-main-header-nav-open .ast-mobile-header-content #ast-hf-mobile-menu > li {
        animation: cmMobileItemEnter 0.28s cubic-bezier(0.16, 1, 0.3, 1) both;
    }
    .ast-main-header-nav-open .ast-mobile-header-content #ast-hf-mobile-menu > li:nth-child(1) { animation-delay: 0.04s; }
    .ast-main-header-nav-open .ast-mobile-header-content #ast-hf-mobile-menu > li:nth-child(2) { animation-delay: 0.08s; }
    .ast-main-header-nav-open .ast-mobile-header-content #ast-hf-mobile-menu > li:nth-child(3) { animation-delay: 0.12s; }
    .ast-main-header-nav-open .ast-mobile-header-content #ast-hf-mobile-menu > li:nth-child(4) { animation-delay: 0.16s; }
    .ast-main-header-nav-open .ast-mobile-header-content .ast-header-button-1 {
        animation: cmMobileItemEnter 0.28s cubic-bezier(0.16, 1, 0.3, 1) both;
        animation-delay: 0.20s;
    }

    /* Mobile Hamburger Icon smooth rotation on open/close */
    .menu-toggle .mobile-menu-toggle-icon svg {
        transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease;
    }
    .menu-toggle.toggled .mobile-menu-toggle-icon .ast-close-svg {
        animation: cmSpinIn 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    }
    @keyframes cmSpinIn {
        0% { transform: rotate(-90deg) scale(0.8); opacity: 0; }
        100% { transform: rotate(0deg) scale(1); opacity: 1; }
    }

    /* ==========================================================================
       6. MOBILE SUBMENUS: GRADUAL ACCORDION HEIGHT & FADE (OPEN & CLOSE)
       ========================================================================== */
    /* Fix: Prevent parent menu item link from expanding/stretching to 100% height and covering first submenu item */
    .ast-header-break-point .main-header-menu > .menu-item > .menu-link {
        height: auto !important;
        min-height: unset !important;
        flex-grow: 0 !important;
        align-self: flex-start !important;
        width: 100% !important;
    }
    .ast-header-break-point .main-header-bar-navigation .menu-item-has-children {
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        position: relative !important;
    }
    .ast-header-break-point .main-header-bar-navigation .menu-item-has-children > a[href="#"],
    .ast-header-break-point .main-header-bar-navigation .menu-item-has-children > a[href=""] {
        cursor: pointer !important;
    }

    .ast-header-break-point .main-header-bar-navigation .menu-item-has-children > .sub-menu {
        display: block !important;
        max-height: 0;
        overflow: hidden;
        opacity: 0;
        transform: translateY(-8px);
        visibility: hidden;
        pointer-events: none;
        margin: 0 !important;
        padding-top: 0 !important;
        padding-bottom: 0 !important;
        transition: max-height 0.35s cubic-bezier(0.16, 1, 0.3, 1),
                    opacity 0.28s cubic-bezier(0.16, 1, 0.3, 1),
                    transform 0.28s cubic-bezier(0.16, 1, 0.3, 1),
                    visibility 0.35s ease,
                    padding 0.35s cubic-bezier(0.16, 1, 0.3, 1) !important;
        will-change: max-height, opacity, transform;
    }

    /* Expanded Submenu: expands height gradually and fades in */
    .ast-header-break-point .main-header-bar-navigation .menu-item-has-children.ast-submenu-expanded > .sub-menu {
        max-height: 350px;
        opacity: 1;
        transform: translateY(0);
        visibility: visible;
        pointer-events: auto;
        padding-top: 4px !important;
        padding-bottom: 8px !important;
    }

    /* Staggered entrance for items inside expanded submenu */
    @keyframes cmSubmenuItemFade {
        0% {
            opacity: 0;
            transform: translateX(-6px);
        }
        100% {
            opacity: 1;
            transform: translateX(0);
        }
    }
    .ast-header-break-point .main-header-bar-navigation .menu-item-has-children.ast-submenu-expanded > .sub-menu > li {
        animation: cmSubmenuItemFade 0.25s cubic-bezier(0.16, 1, 0.3, 1) both;
    }
    .ast-header-break-point .main-header-bar-navigation .menu-item-has-children.ast-submenu-expanded > .sub-menu > li:nth-child(1) { animation-delay: 0.03s; }
    .ast-header-break-point .main-header-bar-navigation .menu-item-has-children.ast-submenu-expanded > .sub-menu > li:nth-child(2) { animation-delay: 0.07s; }
    .ast-header-break-point .main-header-bar-navigation .menu-item-has-children.ast-submenu-expanded > .sub-menu > li:nth-child(3) { animation-delay: 0.11s; }
    .ast-header-break-point .main-header-bar-navigation .menu-item-has-children.ast-submenu-expanded > .sub-menu > li:nth-child(4) { animation-delay: 0.15s; }

    /* 7. Mobile Arrow In-Place Rotation (Strictly around its own geometric center, zero shift) */
    .ast-header-break-point .main-header-bar-navigation .menu-item-has-children > .ast-menu-toggle svg {
        display: inline-block !important;
        transform-origin: 50% 50% !important;
        transform-box: fill-box !important;
        transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1) !important;
    }
    .ast-header-break-point .main-header-bar-navigation .menu-item-has-children.ast-submenu-expanded > .ast-menu-toggle svg {
        transform: rotate(180deg) !important;
    }

    /* ==========================================================================
       8. DROPDOWN TOGGLE BUTTON FIX (Removes Useless Off-Center Dotted Outline/Border)
       ========================================================================== */
    .ast-header-break-point .main-header-bar-navigation .menu-item-has-children > .ast-menu-toggle,
    .ast-header-break-point .main-header-bar-navigation .menu-item-has-children > .ast-menu-toggle:focus,
    .ast-header-break-point .main-header-bar-navigation .menu-item-has-children > .ast-menu-toggle:hover,
    .ast-header-break-point .main-header-bar-navigation .menu-item-has-children > .ast-menu-toggle:active,
    .ast-header-break-point .main-header-bar-navigation .menu-item-has-children > .ast-menu-toggle:focus-visible,
    #ast-hf-mobile-menu .ast-menu-toggle,
    #ast-hf-mobile-menu .ast-menu-toggle:focus,
    #ast-hf-mobile-menu .ast-menu-toggle:hover,
    #ast-hf-mobile-menu .ast-menu-toggle:active,
    #ast-hf-mobile-menu .ast-menu-toggle:focus-visible {
        outline: none !important;
        border: none !important;
        border-color: transparent !important;
        box-shadow: none !important;
        background: transparent !important;
        -webkit-tap-highlight-color: transparent;
    }
}

/* ==========================================================================
   9. ACCESSIBILITY & REDUCED MOTION SUPPORT
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
    .ast-desktop .main-header-menu .sub-menu,
    .ast-mobile-header-wrap .ast-mobile-header-content,
    .ast-header-break-point .main-header-bar-navigation .menu-item-has-children > .sub-menu,
    .ast-header-break-point .main-header-bar-navigation .menu-item-has-children > .ast-menu-toggle svg,
    .ast-desktop .main-header-menu .menu-item-has-children > .menu-link .ast-header-navigation-arrow svg,
    body::before {
        transition: none !important;
        animation: none !important;
        transform: none !important;
    }
}

/* ==========================================================================
   10. ELEMENTOR EDITOR NEUTRALIZATION
   ========================================================================== */
body.elementor-editor-active .ast-desktop .main-header-menu .sub-menu,
body.elementor-editor-active .ast-mobile-header-wrap .ast-mobile-header-content,
body.elementor-editor-active .ast-header-break-point .main-header-bar-navigation .menu-item-has-children > .sub-menu,
body.elementor-editor-active::before {
    display: none !important;
    transition: none !important;
    animation: none !important;
}
