//
// Top navigation bar
// --------------------------------------------------

@mainmenu-mode-tile-height: 78px;
@mainmenu-mode-inline-height: 60px;
@mainmenu-mode-collapse-height: 45px;

@mainmenu-icon-dimension: 30px;
@mainmenu-tile-dimension: 65px;
@mainmenu-tile-label-height: 20px;
@mainmenu-tile-label-width: 100px;

body.mainmenu-open {
    overflow: hidden;
}

.mainmenu-item-link() {
    display: inline-block;
    font-size: @font-size-base;
    color: inherit;
    outline: none;
    text-shadow: 0 0 2px black;

    &:hover {
        background-color: transparent;
    }

    &:active, &:focus {
        text-decoration: none;
        color: @color-mainmenu-inactive;
    }

    i {
        line-height: 1;
        font-size: 30px;
        vertical-align: middle;
    }
}

.mainmenu-item-link-active() {
    // background: @color-mainmenu-active-bg;
    // .border-radius(3px);
    // .box-shadow(inset 0 -2px 0 rgba(0,0,0,.25));
}

.mainmenu-set-height(@height) {
    height: @height;

    ul.mainmenu-toolbar {
        li.mainmenu-preview {
            a {
                height: @height;
                line-height: @height;
            }
        }

        li.mainmenu-account {
            > a {
                height: @height;
                line-height: @height;
            }
        }
    }

    ul li .mainmenu-accountmenu {
        top: @height + 10;
    }
}

.mainmenu-tooltip {
    .tooltip-inner {
        font-size: @font-size-base - 1;
        padding: 6px 16px;
    }
}

nav#layout-mainmenu {
    background-color: @color-mainmenu;
    padding: 0 0 0 20px;
    line-height: 0;
    white-space: nowrap;
    vertical-align: top;

    a {
        text-decoration: none;
        &:focus {
            background: transparent;
        }
    }

    ul {
        margin: 0;
        padding: 0;
        list-style: none;
        float: left;
        white-space: nowrap;
        overflow: hidden;

        li {
            color: @color-mainmenu-inactive;
            display: inline-block;
            vertical-align: top;
            position: relative;
            margin-right: 30px;

            a {
                .mainmenu-item-link();
                padding: 14px 0 10px;

                img.svg-icon {
                    height: 30px;
                    width: 30px;
                    margin-right: 10px;
                    position: relative;
                    top: 0;
                }
            }

            &.active a {
                // font-weight: bold;
            }
        }

        &.nav {
            display: inline-block;
        }
    }

    .toolbar-item {
        padding-right: 0;

        &:before, &:after {
            margin-top: 0;
        }

        &:before {
            left: -12px;
        }

        &:after {
            right: -12px;
        }

        &.scroll-active-before:before {
            color: @color-mainmenu-active;
        }

        &.scroll-active-after:after {
            color: @color-mainmenu-active;
        }
    }

    //
    // Toolbar
    //

    ul.mainmenu-toolbar {
        li.mainmenu-preview {
            margin: 0 0 0 21px;

            i {
                font-size: 20px;
            }

            a {
                position: relative;
                padding: 0 10px;
                top: -1px;
            }
        }

        li.mainmenu-account {
            margin-right: 0;

            > a {
                padding: 0 15px 0 10px;
                font-size: @font-size-base - 1;
                position: relative;
            }

            &.highlight > a {
                z-index: @zindex-popover;
            }

            img.account-avatar {
                width: 45px;
            }

            .account-name {
                //font-weight: bold;
                margin-right: 15px;
            }

            ul {
                line-height: 23px;
            }
        }
    }

    //
    // Fading animation (disabled)
    //

    &:hover {
        ul.mainmenu-nav li {
            //.transition(opacity .15s ease);
            //.opacity(1);
        }
    }

    ul.mainmenu-nav li {
        //.opacity(.65);
        //.transition(opacity 5s ease);
        //.transition-delay(5s);

        &.active {
            //.opacity(1);
        }
    }
}

//
// SVG support
//

html.svg {
    nav#layout-mainmenu,
    .mainmenu-collapsed {
        img.svg-icon {
            display: inline-block;
        }
    }
}

//
// User account menu
//

nav#layout-mainmenu ul li .mainmenu-accountmenu {
    position: fixed;
    top: 0; // See mode for this value
    right: @padding-standard;
    background: @color-accountmenu-bg;
    z-index: @zindex-popover;
    display: none;
    .box-shadow(@overlay-box-shadow);
    border-radius: @border-radius-base;

    &.active {
        display: block;
    }

    &:after {
        .triangle(up, 17px, 7px, @color-accountmenu-bg);
        right: 9px;
        top: -7px;
        position: absolute;
    }

    ul {
        float: none;
        display: block;
        overflow: visible;
    }

    li {
        padding: 0;
        margin: 0;
        font-weight: normal;
        text-align: left;
        display: block;

        a {
            display: block;
            padding: (@padding-standard * 0.5) (@padding-standard * 1.5);
            text-align: left;
            font-size: @font-size-base;
            color: @color-accountmenu-text;
            text-shadow: none;

            &:hover, &:focus {
                background: @highlight-hover-bg;
                color: @highlight-hover-text;
                text-shadow: 0 -1px 0 @highlight-hover-text-shadow;
            }

            &:active {
                background: @highlight-active-bg;
                color: @highlight-active-text;
                text-shadow: 0 -1px 0 @highlight-active-text-shadow;
            }
        }

        &:first-child a {
            &:hover, &:focus, &:active {
                &:after {
                    .triangle(up, 17px, 7px, @highlight-hover-bg);
                    position: absolute;
                    right: 9px;
                    top: -7px;
                    z-index: 102;
                }
            }
            &:active {
                &:after {
                    .triangle(up, 17px, 7px, @highlight-active-bg);
                }
            }
        }
    }

    li.divider {
        height: 1px;
        width: 100%;
        background-color: @color-accountmenu-divider;
    }
}

//
// Navbar (Inline mode)
//

nav#layout-mainmenu.navbar-mode-inline {
    .mainmenu-set-height(@mainmenu-mode-inline-height);

    ul.mainmenu-nav {
        li {
            margin: 5px 0;

            a {
                padding: 10px 15px;

                .nav-icon {
                    position: relative;
                    top: -1px;
                    margin-right: 5px;
                    width: @mainmenu-icon-dimension;
                    height: @mainmenu-icon-dimension;
                    i, img { margin: 0; }
                }
                .nav-label {
                    line-height: @mainmenu-icon-dimension;
                }
            }

            &:first-child {
                margin-left: -13px;
            }

            &:last-child {
                margin-right: 0;
            }
        }

        li.active {
            .mainmenu-item-link-active();

            // &:first-child {
            //     margin-left: 0;
            // }
        }

    }
}

//
// Navbar (Tiles mode)
//

nav#layout-mainmenu.navbar-mode-tile {
    .mainmenu-set-height(@mainmenu-mode-tile-height);
    .mainmenu-navbar-tiles();
}

.mainmenu-navbar-tiles() {
    ul.mainmenu-nav {
        li a {
            position: relative;
            width: @mainmenu-tile-dimension;
            height: @mainmenu-tile-dimension;

            // Offset from bottom
            @tile-bottom-offset: 4;

            .nav-icon {
                text-align: center;
                display: block;
                position: absolute;
                top: 50%;
                left: 50%;
                margin-left: -(@mainmenu-icon-dimension / 2);
                margin-top: -((@mainmenu-tile-dimension - @mainmenu-tile-label-height) / 2) - @tile-bottom-offset;
                width: @mainmenu-icon-dimension;
                height: @mainmenu-icon-dimension;
                i, img { margin: 0; }
            }

            .nav-label {
                display: block;
                width: @mainmenu-tile-label-width;
                height: @mainmenu-tile-label-height;
                line-height: @mainmenu-tile-label-height;
                position: absolute;
                bottom: @tile-bottom-offset + 0px;
                left: 50%;
                padding: 0 5px;
                margin-left: -(@mainmenu-tile-label-width / 2);
                overflow: hidden;
                text-overflow: ellipsis;
                text-align: center;
            }
        }

        li {
            padding: 0 15px;
            margin: 7px 0 0;

            &:first-child {
                margin-left: -7px;
            }

            &:hover {
                .nav-label {
                    width: auto;
                    min-width: @mainmenu-tile-label-width;
                    text-overflow: all;
                    overflow: visible;
                    z-index: 2;
                }
            }

        }

        li.active {
            .mainmenu-item-link-active();

            a {
                // font-weight: bold;
            }

            &:first-child {
                margin-left: 0;
            }
        }
    }
}

//
// Mobile (Collapsed mode)
//

nav#layout-mainmenu {
    .menu-toggle {
        height: @mainmenu-mode-collapse-height;
        line-height: @mainmenu-mode-collapse-height;
        font-size: @font-size-base + 2;
        display: none;

        .menu-toggle-icon {
            background: #333;
            display: inline-block;
            height: @mainmenu-mode-collapse-height;
            line-height: @mainmenu-mode-collapse-height;
            width: @mainmenu-mode-collapse-height;
            text-align: center;

            i {
                line-height: 1;
                font-size: 30px;
                vertical-align: middle;
            }
        }

        .menu-toggle-title {
            margin-left: 10px;
        }
    }
}

nav#layout-mainmenu.navbar-mode-collapse {
    .mainmenu-navbar-collapse();
}

@media (max-width: @menu-breakpoint-max) {
    nav#layout-mainmenu.navbar {
        .mainmenu-navbar-collapse();
    }
}

// This logic is implemented in the october.navbar.js script,
// it prevents the collapse mode from working beyond the min
// breakpoint. Leaving this code just in case, remove later.
// -SG
@media (min-width: @menu-breakpoint-min) {
    // #layout-canvas { position: static !important; }
    // .mainmenu-collapsed { display: none !important; }
}

.mainmenu-navbar-collapse() {
    padding-left: 0;

    .mainmenu-set-height(@mainmenu-mode-collapse-height);

    ul.mainmenu-toolbar li.mainmenu-account > a {
        padding-right: 0;
    }

    ul li .mainmenu-accountmenu:after {
        right: 13px;
    }

    ul.nav { display: none; }

    .menu-toggle {
        display: inline-block;
        color: @color-mainmenu-active !important;
        // font-weight: bold;
    }
}

.mainmenu-collapsed {
    position: absolute;
    height: 100%;
    top: 0;
    left: 0;
    margin: 0;
    background: @color-mainmenu-collapsed;

    > div {
        display: block;
        height: 100%;

        .mainmenu-navbar-tiles();

        ul.mainmenu-nav li:first-child {
            margin-left: 0;
        }

        ul {
            margin: 0;
            padding: 5px 0 15px 15px;
            overflow: hidden;
        }

        ul li {
            color: @color-mainmenu-inactive;
            display: inline-block;
            vertical-align: top;
            position: relative;
            margin-right: 30px;
        }

        ul li a {
            .mainmenu-item-link();

            img.svg-icon {
                height: 30px;
                width: 30px;
                position: relative;
                top: 0;
            }
        }
    }

    .vertical-scroll-marker(@color-mainmenu-inactive);
}

body.mainmenu-open .mainmenu-collapsed ul {
    position: absolute;
    left: 0;
    top: 10px;
    bottom: 10px;
}

//
// Misc
//

nav#layout-mainmenu.navbar ul li:hover,
.mainmenu-collapsed li:hover {
    a {
        &:active, &:focus {
            color: @color-mainmenu-active !important;
        }
    }
}

.touch .mainmenu-collapsed li a:hover {
    color: @color-mainmenu-inactive;
}

nav#layout-mainmenu.navbar ul li,
.mainmenu-collapsed li {

    // a:active, a:focus {
    //     .nav-label {
    //         text-shadow: 1px 1px 15px white, -1px -1px 15px white;
    //     }
    // }

    // Used by account menu
    &.highlight > a {
        color: @color-mainmenu-active !important;
    }

    &.active {
        color: @color-mainmenu-active !important;

        a {
            color: @color-mainmenu-active !important;

            .nav-label {
               text-shadow: none;
            }
        }
    }

    &:hover {
        color: @color-mainmenu-active;
        background: transparent;
    }
}

body.drag {
    nav#layout-mainmenu.navbar ul.nav li,
    .mainmenu-collapsed ul li {
        &:hover {
            color: @color-mainmenu-inactive;
        }

        a:active, a:focus {
            .nav-label {
                text-shadow: none;
            }
        }
    }
}
