/* Desktop menu bar + mega menu panel (includes/mega-menu.php, js/mega-menu/mega-menu.js).
   Figma: Ballers, nodes 5607:6955 / 5607:6956. Desktop only (960px+); the mobile burger menu
   (js/update.js, css/layout.css) is not affected.
   !important: the header builder's menu typography/colour settings are more specific. */

@media (min-width: 960px) {

    /* ================================================================ menu bar */

    #header-sub .mfn-header-menu > li {
        position: relative;
    }

    /* Blue background of the hovered / open item, the full height of the bar
       (js measures the bar: --mega-bar-top / --mega-bar-h). */
    #header-sub .mfn-header-menu > li::before {
        content: "";
        position: absolute;
        top: var(--mega-bar-top, 0);
        left: -12px;
        right: -12px;
        height: var(--mega-bar-h, 100%);
        background: #258cd1;
        opacity: 0;
        transition: opacity .15s ease;
        pointer-events: none;
        z-index: 0;
    }

    #header-sub .mfn-header-menu > li:hover::before,
    #header-sub .mfn-header-menu > li.is-mega-open::before {
        opacity: 1;
    }

    /* Active (the page being viewed is this item, or under it): a blue line along the bottom of
       the bar, so it reads differently from hover / open (full blue background). */
    #header-sub .mfn-header-menu > li::after {
        content: "";
        position: absolute;
        top: calc(var(--mega-bar-top, 0px) + var(--mega-bar-h, 100%) - 3px);
        left: -12px;
        right: -12px;
        height: 3px;
        background: #258cd1;
        opacity: 0;
        pointer-events: none;
        z-index: 0;
    }

    /* .is-bar-measured (js): only once the bar is measured, so the line does not show under
       the text for a moment while the page loads. */
    #header-sub .mfn-header-menu > li.current-menu-item.is-bar-measured::after,
    #header-sub .mfn-header-menu > li.current-menu-parent.is-bar-measured::after,
    #header-sub .mfn-header-menu > li.current-menu-ancestor.is-bar-measured::after,
    #header-sub .mfn-header-menu > li.asitek-mega-current.is-bar-measured::after {
        opacity: 1;
    }

    /* "Pakkumised" (class menu-item-red) keeps its red button (css/layout.css), no blue */
    #header-sub .mfn-header-menu > li.menu-item-red::before,
    #header-sub .mfn-header-menu > li.menu-item-red::after {
        display: none;
    }

    #header-sub .mfn-header-menu > li > .mfn-menu-link {
        position: relative;
        z-index: 1;
    }

    /* Inter 16px, white, normal case */
    #header-sub .mfn-header-menu > li > .mfn-menu-link .menu-label,
    .mfn-header-mainmenu > li.mfn-menu-li > .mfn-menu-link .menu-label {
        font-family: "Inter", sans-serif !important;
        font-size: 16px !important;
        font-weight: 400 !important;
        line-height: normal !important;
        letter-spacing: 0 !important;
        text-transform: none !important;
    }

    #header-sub .mfn-header-menu > li > .mfn-menu-link,
    #header-sub .mfn-header-menu > li > .mfn-menu-link .menu-label,
    #header-sub .mfn-header-menu > li:hover > .mfn-menu-link .menu-label,
    #header-sub .mfn-header-menu > li.current-menu-item > .mfn-menu-link .menu-label {
        color: #fff !important;
    }

    /* Chevron (Figma asset): down when closed, up on hover / open */
    /* The image is centred on the chevron's visual middle, so flipping it does not shift it. */
    #header-sub .mfn-header-menu > li > .mfn-menu-link .mfn-menu-subicon {
        display: inline-flex;
        flex: 0 0 auto;
        width: 10.24px;
        height: 10.24px;
        margin-left: 9px;
        background: url("../../images/mega-menu/chevron.svg?v=4") center / 10.24px 10.24px no-repeat;
        transform: perspective(40px) rotateX(0deg) rotate(-45deg) scaleY(-1);
        transition: transform .35s cubic-bezier(.4, 0, .2, 1);
    }

    #header-sub .mfn-header-menu > li > .mfn-menu-link .mfn-menu-subicon i {
        display: none !important;
    }

    /* Flips over in 3D (around the horizontal axis): down → up */
    #header-sub .mfn-header-menu > li:hover > .mfn-menu-link .mfn-menu-subicon,
    #header-sub .mfn-header-menu > li.is-mega-open > .mfn-menu-link .mfn-menu-subicon {
        transform: perspective(40px) rotateX(180deg) rotate(-45deg) scaleY(-1);
    }


    /* ================================================================ regular dropdowns (e.g. Teenused) */
    /* Same card style as the mega panel: under the bar (js: --mega-sub-top), left edge on the
       item's blue background, rows separated by thin lines. */

    #header-sub .mfn-header-menu > li:not(.cat-dropdown) > .mfn-submenu {
        top: var(--mega-sub-top, 100%) !important;
        left: -12px !important;
        width: max-content !important;
        min-width: 260px !important;
        max-width: 380px;
        margin: 0 !important;
        padding: 10px 0 14px !important;
        background: #fff !important;
        border: 0 !important;
        border-radius: 0 0 16px 16px !important;
        box-shadow: 0 4px 29px rgba(0, 0, 0, .25) !important;
        z-index: 300;
    }

    /* Hover bridge over the gap between the item and the dropdown */
    #header-sub .mfn-header-menu > li:not(.cat-dropdown) > .mfn-submenu::before {
        content: "";
        position: absolute;
        left: 0;
        right: 0;
        bottom: 100%;
        height: var(--mega-sub-gap, 0px);
    }

    #header-sub .mfn-header-menu > li:not(.cat-dropdown) > .mfn-submenu > li {
        width: auto !important;
        margin: 0 24px !important;
        padding: 0 !important;
        border: 0 !important;
        background: transparent !important;
    }

    #header-sub .mfn-header-menu > li:not(.cat-dropdown) > .mfn-submenu > li + li {
        border-top: 1px solid rgba(195, 195, 195, .3) !important;
    }

    #header-sub .mfn-header-menu > li:not(.cat-dropdown) > .mfn-submenu > li > .mfn-menu-link {
        display: flex !important;
        align-items: center;
        justify-content: space-between !important;
        gap: 24px;
        padding: 12px 0 !important;
        border: 0 !important;
        background: transparent !important;
    }

    #header-sub .mfn-header-menu > li:not(.cat-dropdown) > .mfn-submenu > li > .mfn-menu-link .menu-label {
        color: #333 !important;
        font-family: "Inter", sans-serif !important;
        font-size: 16px !important;
        font-weight: 400 !important;
        line-height: normal !important;
        letter-spacing: 0 !important;
        text-transform: none !important;
        white-space: nowrap;
        transition: color .15s ease;
    }

    #header-sub .mfn-header-menu > li:not(.cat-dropdown) > .mfn-submenu > li > .mfn-menu-link:hover .menu-label,
    #header-sub .mfn-header-menu > li:not(.cat-dropdown) > .mfn-submenu > li.current-menu-item > .mfn-menu-link .menu-label {
        color: #258cd1 !important;
    }

    #header-sub .mfn-header-menu > li:not(.cat-dropdown) > .mfn-submenu > li.current-menu-item > .mfn-menu-link .menu-label {
        font-weight: 600 !important;
    }

    /* Arrow (Figma asset) slides in on hover */
    #header-sub .mfn-header-menu > li:not(.cat-dropdown) > .mfn-submenu > li > .mfn-menu-link::after {
        content: "";
        flex: 0 0 22px;
        width: 22px;
        height: 22px;
        background: url("../../images/mega-menu/arrow.svg?v=3") center / 15.5589px 15.5589px no-repeat;
        transform: rotate(-135deg) scaleY(-1);
        opacity: 0;
        translate: -4px 0;
        transition: opacity .15s ease, translate .2s ease;
    }

    #header-sub .mfn-header-menu > li:not(.cat-dropdown) > .mfn-submenu > li > .mfn-menu-link:hover::after {
        opacity: 1;
        translate: 0 0;
    }

    /* Theme's own submenu arrows/helpers */
    #header-sub .mfn-header-menu > li:not(.cat-dropdown) > .mfn-submenu .menu-sub,
    #header-sub .mfn-header-menu > li:not(.cat-dropdown) > .mfn-submenu .menu-item-helper {
        display: none !important;
    }

    /* The generated category submenu stays in the markup for the mobile menu; on desktop the
       panel below replaces it. */
    .asitek-mega-desktop > .mfn-submenu {
        display: none !important;
    }

    /* ================================================================ panel */

    .asitek-mega-panel {
        display: none;
        position: absolute;
        top: 100%;
        left: -12px;
        z-index: 300;
        width: 837px;
        max-width: calc(100vw - 40px);
        box-sizing: border-box;
        /* The white card is the active level (below): the panel itself is transparent, so after
           switching to a shorter level it can stay as tall as before (js), keeping the mouse "inside"
           without showing an empty card. */
        background: transparent;
        color: #333;
        font-family: "Inter", sans-serif;
        font-size: 16px;
        font-weight: 400;
        line-height: normal;
        letter-spacing: 0;
        text-align: left;
        text-transform: none;
        white-space: normal;
        cursor: auto;
    }

    .asitek-mega-desktop.is-mega-open > .asitek-mega-panel {
        display: block;
    }

    /* Hover bridge over the gap between the menu item and the panel (js sets --mega-gap) */
    .asitek-mega-panel::before {
        content: "";
        position: absolute;
        left: 0;
        right: 0;
        bottom: 100%;
        height: var(--mega-gap, 0px);
    }

    .asitek-mega-panel *,
    .asitek-mega-panel *::before,
    .asitek-mega-panel *::after {
        box-sizing: border-box;
    }

    /* One view per category level; only the active one is shown */
    .asitek-mega-panel .asitek-mega-view {
        display: none;
        flex-direction: column;
        min-height: 450px;
        background: #fff;
        border-radius: 0 0 16px 16px;
        box-shadow: 0 4px 29px rgba(0, 0, 0, .25);
    }

    .asitek-mega-panel .asitek-mega-view.is-active {
        display: flex;
    }

    /* The contents slide in, the card stays put */
    .asitek-mega-panel .asitek-mega-view.is-active > * {
        animation: asitek-mega-in .18s ease;
    }

    @keyframes asitek-mega-in {
        from { opacity: 0; transform: translateX(8px); }
        to   { opacity: 1; transform: none; }
    }

    /* ---------------------------------------------------------------- head */

    .asitek-mega-panel .asitek-mega-head {
        padding: 17px 61px 15px 55px;
        border-bottom: 1px solid rgba(195, 195, 195, .3);
    }

    /* "← parent": plain text link look (the theme styles every <button> as a filled button) */
    .asitek-mega-panel button.asitek-mega-back,
    .asitek-mega-panel button.asitek-mega-back:hover,
    .asitek-mega-panel button.asitek-mega-back:focus,
    .asitek-mega-panel button.asitek-mega-back:active {
        display: inline-flex !important;
        align-items: center;
        gap: 4px;
        width: auto !important;
        min-width: 0 !important;
        height: auto !important;
        min-height: 0 !important;
        margin: 0 0 4px -4px !important;
        padding: 0 !important;
        border: 0 !important;
        border-radius: 0 !important;
        background: none !important;
        box-shadow: none !important;
        color: #258acd !important;
        font: 600 12px/normal "Inter", sans-serif !important;
        letter-spacing: 0 !important;
        text-transform: none !important;
        text-decoration: none !important;
        cursor: pointer;
        transition: color .15s ease;
    }

    .asitek-mega-panel button.asitek-mega-back:hover {
        color: #1b6fa8 !important;
    }

    .asitek-mega-panel button.asitek-mega-back:focus-visible {
        outline: 2px solid rgba(37, 140, 209, .4) !important;
        outline-offset: 2px;
    }

    /* Back / "Kõik" arrows: the same Figma arrow as the rows, turned ← and → */
    .asitek-mega-panel .asitek-mega-icon {
        display: inline-block;
        flex: 0 0 auto;
        background: url("../../images/mega-menu/arrow.svg?v=3") center / contain no-repeat;
        translate: 0 0;
        transition: translate .2s ease;
    }

    .asitek-mega-panel .asitek-mega-back .asitek-mega-icon {
        width: 14px;
        height: 14px;
        background-size: 10px 10px;
        transform: rotate(45deg) scaleY(-1);
    }

    .asitek-mega-panel button.asitek-mega-back:hover .asitek-mega-icon {
        translate: -3px 0;
    }

    .asitek-mega-panel .asitek-mega-title-row {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 16px;
    }

    .asitek-mega-panel .asitek-mega-title {
        margin: 0;
        padding: 10px 0;
        color: #333;
        font: 700 18px/normal "Inter", sans-serif;
    }


    /* "Kõik {category} →": the level's category page, plain bold link */
    .asitek-mega-panel a.asitek-mega-all {
        display: inline-flex;
        flex: 0 0 auto;
        align-items: center;
        gap: 6px;
        padding: 8px 0;
        background: none;
        color: #258cd1;
        font: 600 15px/normal "Inter", sans-serif;
        text-decoration: none;
        white-space: nowrap;
        transition: color .15s ease;
    }

    .asitek-mega-panel a.asitek-mega-all:hover,
    .asitek-mega-panel a.asitek-mega-all:focus-visible {
        color: #1b6fa8;
        outline: none;
    }

    .asitek-mega-panel a.asitek-mega-all .asitek-mega-icon {
        width: 22px;
        height: 22px;
        background-size: 15.5589px 15.5589px;
        transform: rotate(-135deg) scaleY(-1);
    }

    .asitek-mega-panel a.asitek-mega-all:hover .asitek-mega-icon,
    .asitek-mega-panel a.asitek-mega-all:focus-visible .asitek-mega-icon {
        translate: 4px 0;
    }

    /* ---------------------------------------------------------------- rows: 2 columns */

    .asitek-mega-panel .asitek-mega-body {
        display: flex;
        flex: 1 0 auto;
        align-items: flex-start;
        gap: 111px;
        padding: 20px 61px 32px 55px;
    }

    .asitek-mega-panel ul.asitek-mega-col {
        display: block;
        flex: 0 0 303px;
        width: 303px;
        margin: 0;
        padding: 0;
        list-style: none;
        position: static;
        background: none;
        box-shadow: none;
    }

    .asitek-mega-panel ul.asitek-mega-col > li {
        display: block;
        position: static;
        width: auto;
        margin: 0;
        padding: 0;
        list-style: none;
    }

    /* Line between rows: #c3c3c3 at 30% */
    .asitek-mega-panel ul.asitek-mega-col > li + li {
        border-top: 1px solid rgba(195, 195, 195, .3);
    }

    .asitek-mega-panel a.asitek-mega-row {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        padding: 8.5px 0;
        color: #333;
        font: 400 16px/normal "Inter", sans-serif;
        text-decoration: none;
        transition: color .15s ease;
    }

    .asitek-mega-panel a.asitek-mega-row:hover,
    .asitek-mega-panel a.asitek-mega-row.is-current {
        color: #258cd1;
    }

    /* Active (the category being viewed, or one above it): also semibold; hover is colour only */
    .asitek-mega-panel a.asitek-mega-row.is-current {
        font-weight: 600;
    }

    .asitek-mega-panel .asitek-mega-arrow {
        flex: 0 0 22px;
        width: 22px;
        height: 22px;
    }

    /* Arrow (Figma asset) only on rows that open further subcategories */
    .asitek-mega-panel a.asitek-mega-row.has-sub .asitek-mega-arrow {
        background: url("../../images/mega-menu/arrow.svg?v=3") center / 15.5589px 15.5589px no-repeat;
        transform: rotate(-135deg) scaleY(-1);
        translate: 0 0;
        transition: translate .2s ease;
    }

    .asitek-mega-panel a.asitek-mega-row.has-sub:hover .asitek-mega-arrow {
        translate: 3px 0;
    }


    @media (prefers-reduced-motion: reduce) {
        .asitek-mega-panel .asitek-mega-view.is-active > * {
            animation: none;
        }

        .asitek-mega-panel a.asitek-mega-row.has-sub .asitek-mega-arrow,
        .asitek-mega-panel .asitek-mega-icon,
        #header-sub .mfn-header-menu > li > .mfn-menu-link .mfn-menu-subicon {
            transition: none;
        }
    }
}

/* ================================================================ mobile drill-down menu (below 960px) */
/* Same chevron as the desktop bar (instead of the "›" / "‹" text characters of css/layout.css):
   navy, pointing right on items with a submenu; white, pointing left in the round back button. */

@media (max-width: 959px) {
    /* Room for the chevron, so long labels do not run into it */
    .mfn-header-tmpl .menu-item-has-children > .mfn-menu-link {
        padding-right: 48px !important;
    }

    .mfn-header-tmpl .menu-item-has-children > .mfn-menu-link::after {
        content: "" !important;
        position: absolute;
        right: 20px;
        top: 50%;
        width: 12px;
        height: 12px;
        background: url("../../images/mega-menu/chevron-dark.svg?v=1") center / 12px 12px no-repeat;
        transform: translateY(-50%) rotate(-135deg) scaleY(-1);
    }

    /* Hide the "‹" character, draw the chevron instead */
    .mfn-header-tmpl .menu-breadcrumb .breadcrumb-back-button {
        position: relative;
        color: transparent !important;
        font-size: 0 !important;
    }

    .mfn-header-tmpl .menu-breadcrumb .breadcrumb-back-button::before {
        content: "";
        width: 14px;
        height: 14px;
        background: url("../../images/mega-menu/chevron.svg?v=4") center / 14px 14px no-repeat;
        transform: rotate(45deg) scaleY(-1);
    }
}
