/*
 * ADS Menu — layout only.
 * All colors, font sizes and weights come from the settings page
 * (inline CSS generated in ads-menu-plugin.php).
 * Breakpoint: desktop >= 1081px, mobile <= 1080px. Keep these two media queries written exactly like this:
 * a custom breakpoint from the settings is applied by replacing them (ADS_Menu_Plugin::get_layout_css()).
 */

/* WordPress admin bar height (logged-in users) so the mobile panel and close button sit below it */
body.admin-bar .ads-menu-header {
    --ads-menu-adminbar: 32px;
}

@media screen and (max-width: 782px) {
    body.admin-bar .ads-menu-header {
        --ads-menu-adminbar: 46px;
    }
}

/* BASE */
.ads-menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
}

.ads-menu-header .site-logo {
    display: flex;
    max-width: 160px;
    position: relative;
}

.ads-menu-header .site-logo a {
    width: 100%;
    display: inline-flex;
}

.ads-menu-header .site-logo a img {
    width: 100%;
    max-width: 100%;
    height: auto;
}

/* Submenu arrow icon */
.ads-menu-header .ads-menu-chevron {
    display: inline-flex;
    width: 1em;
    height: 1em;
    line-height: 1;
}

.ads-menu-header .ads-menu-chevron svg {
    display: block;
    width: 100%;
    height: 100%;
}

/* DESKTOP MENU */
@media only screen and (min-width: 1081px) {
    .ads-menu-header .header-menu {
        padding: 0 !important;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .ads-menu-header .header-menu li {
        position: relative;
        list-style: none;
    }

    .ads-menu-header .header-menu li.mobile-only {
        display: none;
    }

    .ads-menu-header .header-menu li span {
        display: none;
    }

    .ads-menu-header .header-menu li a {
        padding: 10px 12px;
        display: block;
        text-decoration: none;
        position: relative;
        transition: color 0.25s ease, background-color 0.25s ease;
    }

    .ads-menu-header .header-menu li.menu-item-has-children {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .ads-menu-header .header-menu li.menu-item-has-children > a {
        padding-right: 25px;
    }

    .ads-menu-header .header-menu li.menu-item-has-children > span {
        display: flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        width: 10px;
        height: 10px;
        right: 8px;
    }

    .ads-menu-header .header-menu li.menu-item-has-children > span i {
        font-size: 10px;
        transition: 0.3s;
    }

    .ads-menu-header .header-menu li.menu-item-has-children > span.active i,
    .ads-menu-header .header-menu li.menu-item-has-children:hover > span i {
        transform: rotate(-180deg);
    }

    .ads-menu-header .header-menu > li > .sub-menu,
    .ads-menu-header .header-menu > li > .sub-menu > li > .sub-menu {
        position: absolute;
        top: 100%;
        right: 0;
        padding: 0;
        opacity: 0;
        visibility: hidden;
        transition: 0.2s;
        display: flex;
        flex-direction: column;
        z-index: 99;
        width: max-content;
        min-width: 0;
        max-width: 320px;
        white-space: normal;
        box-shadow: 2px 2px 10px 0 rgba(0, 0, 0, 0.2);
    }

    .ads-menu-header .header-menu > li > .sub-menu > li > .sub-menu {
        right: auto;
        left: 100%;
        top: 0;
    }

    .ads-menu-header .header-menu > li > .sub-menu li {
        order: 2;
        font-weight: 400;
    }

    .ads-menu-header .header-menu > li > .sub-menu li a {
        white-space: pre-line;
        display: block;
        width: 100%;
    }

    .ads-menu-header .header-menu > li:hover > .sub-menu,
    .ads-menu-header .header-menu > li > .sub-menu > li:hover > .sub-menu {
        opacity: 1;
        visibility: visible;
    }
}

/* HAMBURGER BUTTON */
.ads-menu-header .cmn-toggle-switch {
    display: none;
    position: relative;
    overflow: hidden;
    margin: 0;
    padding: 0;
    width: 50px;
    min-width: 50px;
    height: 50px;
    font-size: 0;
    text-indent: -9999px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    box-shadow: none;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: 1s;
    z-index: 9999;
    align-items: center;
}

.ads-menu-header .cmn-toggle-switch:focus {
    outline: none;
}

.ads-menu-header .cmn-toggle-switch:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

.ads-menu-header .cmn-toggle-switch span {
    display: block;
    position: absolute;
    left: 15%;
    right: 15%;
    height: 2px;
    transition: background 0s 0.3s;
}

.ads-menu-header .cmn-toggle-switch span::before,
.ads-menu-header .cmn-toggle-switch span::after {
    position: absolute;
    display: block;
    left: 0;
    width: 100%;
    height: 2px;
    content: "";
    transition-duration: 0.3s, 0.3s;
    transition-delay: 0.3s, 0s;
}

.ads-menu-header .cmn-toggle-switch span::before {
    top: -10px;
    transition-property: top, transform;
}

.ads-menu-header .cmn-toggle-switch span::after {
    bottom: -10px;
    transition-property: bottom, transform;
}

/* Close button: top corner of the open panel, below the admin bar */
.ads-menu-header .cmn-toggle-switch.active {
    position: fixed;
    top: calc(30px + var(--ads-menu-adminbar, 0px));
    right: 30px;
    left: auto;
    transition: 0.3s;
}

/* Left panel narrower than the screen: keep the button inside the panel's right edge */
.ads-menu-header.ads-menu--from-left.ads-menu--auto .cmn-toggle-switch.active {
    right: auto;
    left: calc(min(var(--ads-menu-panel-width, 360px), 100vw) - 50px - 20px);
}

.ads-menu-header .cmn-toggle-switch.active span::before {
    top: 0;
    transform: rotate(45deg);
    transition-delay: 0s, 0.3s;
}

.ads-menu-header .cmn-toggle-switch.active span::after {
    bottom: 0;
    transform: rotate(-45deg);
    transition-delay: 0s, 0.3s;
}

/* MOBILE MENU */
@media only screen and (max-width: 1080px) {
    .ads-menu-header .cmn-toggle-switch {
        display: flex;
    }

    .ads-menu-header .site-logo {
        max-width: 140px;
    }

    .ads-menu-header .navigation-wrap {
        margin: 0 0 0 auto;
    }

    /*
     * Panel. Direction: .ads-menu--from-top | --from-right | --from-left
     * Size: .ads-menu--fullscreen | --auto (fits the menu height)
     */
    .ads-menu-header .header-menu {
        position: fixed;
        top: 0;
        right: auto;
        bottom: auto;
        left: 0;
        box-sizing: border-box;
        width: 100%;
        height: 100%;
        max-height: 100%;
        margin: 0;
        z-index: 9998;
        overflow-y: auto;
        overscroll-behavior: contain;
        display: flex;
        align-items: flex-start;
        justify-content: flex-start;
        flex-direction: column;
        flex-wrap: nowrap;
        box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.215) !important;
        padding: calc(100px + var(--ads-menu-adminbar, 0px)) 25px 25px 25px !important;
        transform: translateY(-100%);
        visibility: hidden;
        transition: transform 0.35s ease, visibility 0s linear 0.35s;
    }

    .ads-menu-header.ads-menu--from-right .header-menu {
        left: auto;
        right: 0;
        transform: translateX(100%);
    }

    .ads-menu-header.ads-menu--from-left .header-menu {
        transform: translateX(-100%);
    }

    .ads-menu-header.move .header-menu {
        transform: none;
        visibility: visible;
        transition: transform 0.35s ease, visibility 0s;
    }

    /* Fit menu height */
    .ads-menu-header.ads-menu--auto .header-menu {
        height: auto;
    }

    .ads-menu-header.ads-menu--auto.ads-menu--from-right .header-menu,
    .ads-menu-header.ads-menu--auto.ads-menu--from-left .header-menu {
        width: var(--ads-menu-panel-width, 360px);
        max-width: 100%;
    }

    /* Page dimming behind a panel that doesn't cover the screen */
    .ads-menu-header.ads-menu--auto::after {
        content: "";
        position: fixed;
        inset: 0;
        z-index: 9997;
        background: var(--ads-menu-overlay, rgba(0, 0, 0, 0.5));
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: opacity 0.35s ease, visibility 0s linear 0.35s;
    }

    .ads-menu-header.ads-menu--auto.move::after {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
        transition: opacity 0.35s ease, visibility 0s;
    }

    .ads-menu-header .header-menu li {
        position: relative;
        display: inline-flex;
        width: auto;
    }

    .ads-menu-header .header-menu li.mobile-only {
        display: inline-block;
    }

    .ads-menu-header .header-menu li a {
        padding: 10px;
        display: inline-block;
        width: auto;
    }

    .ads-menu-header .header-menu li .current-menu-item {
        background: none;
    }

    .ads-menu-header .header-menu li .current-menu-item > a {
        margin-bottom: 10px;
    }

    .ads-menu-header .header-menu > li {
        padding: 5px 10px;
        margin-bottom: 5px;
    }

    .ads-menu-header .header-menu li span {
        display: none;
    }

    .ads-menu-header .header-menu li.menu-item-has-children {
        width: 100%;
        justify-content: space-between;
        align-items: center;
        flex-wrap: wrap;
    }

    .ads-menu-header .header-menu li.menu-item-has-children > a {
        pointer-events: all;
    }

    .ads-menu-header .header-menu li.menu-item-has-children > span {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 34px;
        height: 34px;
        z-index: 99;
        cursor: pointer;
        transition: 0.3s;
    }

    .ads-menu-header .header-menu li.menu-item-has-children > span i {
        font-size: 18px;
        transition: 0.3s;
    }

    .ads-menu-header .header-menu li.menu-item-has-children > span.active i {
        transform: rotate(180deg);
    }

    /* All levels collapsed by default; menu-script.js animates height between 0 and the content height */
    .ads-menu-header .header-menu .sub-menu {
        display: block;
        box-sizing: border-box;
        width: 100%;
        height: 0;
        overflow: hidden;
        position: relative;
        border: none;
        border-radius: 0;
        padding: 0 20px;
        margin: 0;
        background-image: none;
        list-style: none;
        box-shadow: none;
        z-index: 10;
        opacity: 0;
        visibility: hidden;
        transition: height 0.35s ease, opacity 0.25s ease, visibility 0s linear 0.35s;
    }

    .ads-menu-header .header-menu .sub-menu.is-open {
        opacity: 1;
        visibility: visible;
        transition: height 0.35s ease, opacity 0.25s ease 0.05s, visibility 0s;
    }

    /* Vertical spacing lives on the items so the measured height is exact */
    .ads-menu-header .header-menu .sub-menu > li:first-child {
        margin-top: 5px;
    }

    .ads-menu-header .header-menu .sub-menu > li:last-child {
        margin-bottom: 5px;
    }

    .ads-menu-header .header-menu > li .sub-menu {
        padding-left: 20px !important;
    }

    .ads-menu-header .header-menu > li > .sub-menu li {
        width: 100%;
    }

    .ads-menu-header .header-menu > li > .sub-menu li > a {
        border: none;
        font-weight: 300;
        width: auto;
        display: inline-block;
    }

    .ads-menu-header .header-menu > li .sub-menu > li.current-menu-item a {
        font-weight: 700;
    }

    .ads-menu-header .header-menu .site-logo {
        display: none !important;
    }

    body.menu-open {
        overflow: hidden;
    }
}

@media (prefers-reduced-motion: reduce) {
    .ads-menu-header .header-menu,
    .ads-menu-header::after,
    .ads-menu-header .header-menu .sub-menu,
    .ads-menu-header .header-menu li > span,
    .ads-menu-header .header-menu li > span i {
        transition: none !important;
    }
}
