// Menu item variables
$main-menu-item-padding-x: 6px;
$main-menu-item-padding-y: 15px;

$main-menu-item-margin-x: 8px;
$main-menu-item-margin-y: 0;

$main-menu-item-font-size: 14px;

$main-submenu-item-padding-x: 8px;
$main-submenu-item-padding-y: 10px;

$main-menu-submenu-width: 20em;

$main-menu-side-menu-width: 300px;

@mixin menu-color-invert {
    color: var(--theme-menu-item-color-hover);
    background: var(--theme-menu-item-color);
}

// General main menu
.menu-bar {
    background: var(--theme-menu-bg);
    position: relative;
    margin: 0;
    padding: 0;
    left: 0;
    right: 0;
    z-index: 999;
    transition: margin-top 0.2s ease;
}

// hides header on scroll
.hide-header {
    .menu-bar {
        margin-top: -49px;
        transition: margin-top 0.2s ease;
    }

}

// menu item container
.menu-bar .main_menu__inner {
    max-width: $max-container-width-xl;
    margin: 0 auto;
    overflow: hidden;
    display: flex;
    padding: 0 $nav-link-padding-x;
    max-height: 49px;

    &.menu-bar-expand {
        height: auto;
    }
}

// main menu inner container when in full width mode
.full-width-mode .menu-bar .main_menu__inner {
    max-width: 100%;
}

// Main menu list (top level)
.menu-bar .main_menu__list {
    display: flex;
    flex-wrap: wrap;
    margin: 0;
    padding: 0;
    list-style: none;
    border-top: 0;
    border-right: 0;
}

//Main menu generic list items - (top level & sub items)
.menu-bar .main_menu__list {
    li {
        position: relative;
        list-style: none;
        margin-bottom: 1px;

        > a {
            text-decoration: none;
            display: block;
            color: var(--theme-menu-item-color);
            padding: $main-menu-item-padding-x $main-menu-item-padding-y;
            margin: $main-menu-item-margin-x $main-menu-item-margin-y;
            font-size: $main-menu-item-font-size;
            border-radius: $border-radius;

            &[href="javascript:void(0);"] {
                cursor: default;
            }

            &:hover {
                @include menu-color-invert;
                opacity: 1;
            }

        }
    }
}

// Main menu list items - adds an arrow to top level items which have sub items
.menu-bar .main_menu__list li.has-sub > a:after {
    content: "";
    margin-left: 8px;
    width: 7px;
    height: 7px;
    display: inline-block;
    transform: rotate(45deg);
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    margin-bottom: 3px;
}

// Main menu - submenu (1st level)
.menu-bar .main_menu__list {
    > li > ul {
        z-index: 30;
        position: fixed;
        left: auto;
        width: $main-menu-submenu-width;
        box-shadow: $dropdown-box-shadow;
        padding: $dropdown-padding-y $dropdown-padding-x;
        max-height: calc(90vh - 113px);
        overflow: auto;
        background: #fff;
        visibility: hidden;
        opacity: 0;
        transition: all 0.3s ease 0.1s;

        // submenu (2nd level) list item link
        li > a {
            padding: $main-submenu-item-padding-x $main-submenu-item-padding-y;
            color: $gray-800;
            margin: 0;
            font-size: $main-menu-item-font-size;
            overflow-wrap: break-word;
            word-wrap: break-word;

            &:hover {
                background: $dropdown-link-hover-bg;
                color: $gray-900;
            }

        }

    }
}

// Main menu items - submenus on topbar mode and all items on sidemenu
.menu-bar .main_menu__list > li > ul,
.desktop-sideview .menu-bar .main_menu__list  {
    // Submenu list toggle
    li.has-sub {
        // Submenu list toggle - link
        > a {
            margin: 0 0 0 32px;
            // Submenu list toggle - hides desktop arrow
            &:after {
                display: none;
            }
        }
        // Submenu list toggle - opens child list
        .desktop-toggle {
            position: absolute;
            left: 0;
            margin: 5px;
            padding: 0;
            width: 28px;
            height: 28px;
            border-radius: 10rem;
            background: $dropdown-link-hover-bg;
            border: none;


            &:hover {
                opacity: 1;
            }

            &:focus {
                outline: none;
            }

            // Arrow for sub-sub menu items
            &::after {
                content: "";
                position: absolute;
                top: 1px;
                left: 1px;
                border-right: 2px solid $gray-800;
                border-top: 2px solid $gray-800;
                width: 8px;
                height: 8px;
                transform: rotate(45deg);
                margin: 9px 8px;
                transition: .4s;
            }
        }

        // Submenu list - item with sub menu link
        > a {
            margin: 0 0 0 37px;
            // Submenu list toggle - hides desktop arrow
            &:after {
                display: none;
            }
        }

        // submenu with submenu list
        > ul {
            display: block;
            clear: both;
            position: relative;
            left: 0;
            top: 0;
            max-height: 0;
            width: auto;
            overflow: hidden;
            opacity: 0;
            box-shadow: none;
            @include transition(.2s);
        }
    }
}

// Main menu items - sub submenu styling - open
.menu-bar .main_menu__list  ul .has-sub.open-sub-menu,
.desktop-sideview .menu-bar .main_menu__list .has-sub.open-sub-menu {
    > .desktop-toggle::after  {
        transform: rotate(135deg);
        transition: .4s;
        left: 2px;
    }
    > ul {
        @include transition(.3s);
        opacity: 1;
        max-height: 250rem;
        padding-left: 10px;
    }
}

// Main menu items - submenu styling - show on hover
.menu-bar .main_menu__list {
    > li:hover > ul {
        opacity: 1;
        visibility: visible;
        transition: 0.3s;
    }
}

// Overflow menu styling - when open
.toggle:checked ~ .main_menu__inner {
    height: auto;
    max-height: 600px;
    transition: max-height 0.1s ease-out;
}

// Overflow menu toggle/button
.main_menu__toggle {
    flex-shrink: 0;
    margin-right: $nav-link-padding-x;
}

// Overflow menu button/toggle styling
.main_menu__link {
    display: none;
    @include menu-color-invert;
    position: relative;
    padding: $main-menu-item-padding-x $main-menu-item-padding-y;
    min-width: 80px;
    text-align: center;
    font-size: $main-menu-item-font-size;
    text-decoration: none;
    cursor: pointer;
    margin: $main-menu-item-margin-x $main-menu-item-margin-y;
    border-radius: $border-radius;
}

// Shows overflow menu button/toggle - on hover
.main_menu__link:hover {
    opacity: 0.8;
}

// Shows overflow menu button when screen is at smaller sizes
.main_menu__link.show {
    display: block;
}

// adds arrow to overflow menu toggle/button
.main_menu__link:after {
    content: "";
    margin-left: 8px;
    width: 7px;
    height: 7px;
    display: inline-block;
    transform: rotate(45deg);
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    margin-bottom: 3px;
    transition: .4s;
}

// Rotates arrow 180deg when overflow menu is open
.main_menu__toggle .main_menu__link.after:after {
    transform: rotate( 225deg );
    margin-bottom: 0px;
    transition: .4s;
}

// Hides overflow menu checkbox which is used for the workings of the overflow menu but not displayed
.toggle {
    position: absolute;
    z-index: -1;
    opacity: 0;
}

// behat testing banner
.behat_config_status {
    background-color: red;
    color: white;
    text-align: center;
    font-weight: bold;
    padding: 10px;
}

// Styling for sidebar style menu
@media only screen and (min-width: 768px) {

    .desktop-sideview {
        // Opaque black overlay styling and placement
        .back-close {
            position: fixed;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 0.4);
            z-index: 80;
            visibility: hidden;
            opacity: 0;
            @include transition($transition-speed);
            @include backface(hidden);
        }
        // Opaque black overlay when open
        .back-close.in {
            visibility: visible;
            opacity: 1;
            @include transition($transition-speed);
            @include backface(hidden);
        }
    }

    // hides navigation toggle when not in deskt
    .navbar-header .nav-toggle  {
        display: none;
    }


    // Makes container full width of page
    .desktop-sideview .claro-nav-container {
        width: 100%;
        max-width: 100%;
    }

    // creates sidebar toggle
    .desktop-sideview {
        .navbar-header .nav-toggle {
            background: transparent ;
            position: relative;
            margin: 4px 15px;
            height: 40px;
            width: 40px;
            z-index: 999;
            @include transition($transition-speed);
            @include backface(hidden);
            outline: none;
            display: block;

            .nav-toggle-bar {
                background: var(--theme-navbar-icon-color);
                position: absolute;
                height: 3px;
                width: 30px;
                left: 5px;
                @include transition($transition-speed);
                @include backface(hidden);
                border-radius: 4px;
            }
            .nav-toggle-bar:nth-child(2) {
                top: 9px;
                width: 25px;
            }
            .nav-toggle-bar:nth-child(3) {
                top: 18px;
                width: 28px;
            }
            .nav-toggle-bar:nth-child(4) {
                top: 27px;
                width: 19px;
            }
        }

        .navbar-header .nav-toggle:hover  .nav-toggle-bar  {
            width: 28px;
        }

        // create sidebar toggle when open
        .navbar-header .nav-toggle.in {
            .nav-toggle-bar {
                top: 18px;
                @include transition($transition-speed);
                @include backface(hidden);
                width: 28px;
            }
            .nav-toggle-bar:nth-child(2) {
                @include transform(rotate(-45deg)) ;
            }
            .nav-toggle-bar:nth-child(3) {
                visibility: hidden;
                opacity: 0;
            }
            .nav-toggle-bar:nth-child(4) {
                @include transform(rotate(45deg)) ;
            }
        }
    }

    // Side menu styling and placement
    .desktop-sideview {
        .menu-bar {
            width: $main-menu-side-menu-width;
            bottom: 0;
            left: 0;
            margin-left: -$main-menu-side-menu-width - 20px;
            @include transition(0.4s);
            @include transform(translate(0,0));
            box-shadow: $dropdown-box-shadow;
            overflow: auto;
            position: fixed;
            bottom: 0;
            top: 67px;
        }
    }

    // Side menu styling and placement when open
    .desktop-sideview .menu-bar.open {
        margin: 0;
        @include transition(0.4s);
    }

    // Side menu inner styling - overwrites overflow menu limits
    .desktop-sideview {
        .menu-bar .main_menu__inner {
            max-height: 100%;
            width: 100%;
            overflow: auto;
            height: auto;
        }

        // Side menu inner styling - hides overflow button
        .main_menu__toggle {
            display: none;
        }
    }

    // Side menu menu bar styling
    .desktop-sideview {
        .menu-bar .main_menu__list {
            display: block;
            width: 100%;
        }
    }

    // Side menu ul styling - overwrites all navbar ul styling
    .desktop-sideview {
        .menu-bar .main_menu__list ul {
            visibility: visible;
            opacity: 1;
            background: transparent;
            padding-top: 0;
            padding-bottom: 0;
        }
    }

    // Side menu li styling - overwrites all navbar li link and desktop toggle styling
    .desktop-sideview {
        .menu-bar .main_menu__inner .main_menu__list li > {
            a, .desktop-toggle {
                margin-top: 3px;
                margin-bottom: 3px;
            }

            a {
                color: var(--theme-menu-item-color);
                &:hover {
                    @include menu-color-invert;
                }
            }

        }
    }
}
