@import (once) "./dropdown.less";
@import (once) "./colortheme.less";
@import (once) "./browser.less";
@import (once) "./ckeditor-fix.less";
@import (once) "./avatar.less";
@import (once) "./toolbar-history.less";
@import (once) "./icon-colors.less";
@import (once) "./tools.less";


.toolbar_main () {

    @toolbar_line-height: 32px;
    @toolbar_top-height: 64px;
    @toolbar_button-font: @colortheme_app-font;

    .dropdown_main();
    .ckeditor_fix();
    .history_main();
    .iconColors_main();

    .cp-toolbar-container {
        display: flex;
    }

    .cp-toolbar-userlist-drawer {
        font: @colortheme_app-font-size @colortheme_font;
        min-width: 175px;
        width: 175px;
        display: block;
        overflow-y: auto;
        overflow-x: hidden;
        padding: 10px;
        box-sizing: border-box;
        .cp-toolbar-userlist-drawer-close {
            position: absolute;
            margin-top: -10px;
            margin-left: 149px;
            font-size: 15px;
            opacity: 0.5;
            cursor: pointer;
            text-shadow: unset;
            &:hover {
                opacity: 1;
            }
        }
        h2 {
            color: inherit;
            text-align: center;
            padding: 5px 0px;
            margin: 5px 0px;
            font: inherit;
            font-weight: bold;
            white-space: normal;
            line-height: auto;
        }
        text-align:baseline;
        .cp-toolbar-userlist-viewer {
            font-style: italic;
            padding: 5px;
            background: rgba(0,0,0,0.1);
            margin: 2px 0;
        }

        & > p {
            font: @colortheme_app-font-size @colortheme_font;
            margin: 0;
            padding: 0;
            display: block;
        }

        .cp-toolbar-userlist-others {
            display: flex;
            flex-flow: column;
            margin: 10px 0;
            margin-bottom: 20px;
            &>span {
                padding: 5px;
                margin: 2px 0;
                background: rgba(0,0,0,0.1);
                .avatar_main(30px);
                .cp-avatar-default, media-tag {
                    margin-right: 5px;
                }
            }
        }
        .cp-toolbar-userlist-friend {
            display: inline-block;
            width: 20px;
        }
    }

    .addToolbarColors (@color, @bg-color) {
        .cp-toolbar-userlist-drawer {
            background-color: @bgcolor;
            color: @color;
            .cp-toolbar-userlist-drawer-close {
                color: @color;
            }
            h2 {
                background-color: darken(@bgcolor, 10%);
                color: @color;
            }
            .cp-toolbar-userlist-friend {
                &:hover {
                    color: darken(@color, 15%);
                }
            }
        }
        .cp-toolbar {
            background-color: @bgcolor;
            color: @color;
            .cp-toolbar-spinner {
                font-size: @colortheme_app-font-size;
                color: @color;
            }
            .cp-toolbar-limit {
                text-shadow: -1px 0 @color, 0 1px @color, 1px 0 @color, 0 -1px @color;
            }
            .cp-toolbar-leftside, .cp-toolbar-rightside {
                background-color: lighten(@bgcolor, 8%);
                button:hover, button.cp-toolbar-button-active {
                    background-color: @bgcolor;
                }
            }
            .cp-toolbar-title-hoverable:hover {
                .cp-toolbar-title-editable, .cp-toolbar-title-edit {
                    cursor: text;
                    border: 1px solid darken(@bgcolor, 15%);
                    background: darken(@bgcolor, 10%);
                    transition: all 0.15s;
                    color: @color;
                }
                .cp-toolbar-title-editable {
                    cursor: text;
                }
            }
            .cp-toolbar-title-save {
                border: 1px solid darken(@bgcolor, 15%);
                background: darken(@bgcolor, 10%);
                color: @color;
                &:hover {
                    background: darken(@bgcolor, 5%);
                }
            }
            input {
                border: 1px solid darken(@bgcolor, 15%);
                background: darken(@bgcolor, 10%);
                color: @color;
            }
            .cp-dropdown-content.cp-dropdown-left a {
                color: black;
            }
        }
    }

    &.cp-app-pad {
        @bgcolor: @colortheme_pad-bg;
        @color: @colortheme_pad-color;
        .addToolbarColors(@color, @bgcolor);
    }
    &.cp-app-code {
        @bgcolor: @colortheme_code-bg;
        @color: @colortheme_code-color;
        .addToolbarColors(@color, @bgcolor);
    }
    &.cp-app-slide {
        @bgcolor: @colortheme_slide-bg;
        @color: @colortheme_slide-color;
        .addToolbarColors(@color, @bgcolor);
    }
    &.cp-app-poll {
        @bgcolor: @colortheme_poll-bg;
        @color: @colortheme_poll-color;
        .addToolbarColors(@color, @bgcolor);
    }
    &.cp-app-whiteboard {
        @bgcolor: @colortheme_whiteboard-bg;
        @color: @colortheme_whiteboard-color;
        .addToolbarColors(@color, @bgcolor);
    }
    &.cp-app-drive {
        @bgcolor: @colortheme_drive-bg;
        @color: @colortheme_drive-color;
        .addToolbarColors(@color, @bgcolor);
    }
    &.cp-app-file {
        @bgcolor: @colortheme_file-bg;
        @color: @colortheme_file-color;
        .addToolbarColors(@color, @bgcolor);
    }
    &.cp-app-contacts {
        @bgcolor: @colortheme_friends-bg;
        @color: @colortheme_friends-color;
        .addToolbarColors(@color, @bgcolor);
    }
    &.cp-app-settings {
        @bgcolor: @colortheme_settings-bg;
        @color: @colortheme_settings-color;
        .addToolbarColors(@color, @bgcolor);
    }
    &.cp-app-profile {
        @bgcolor: @colortheme_profile-bg;
        @color: @colortheme_profile-color;
        .addToolbarColors(@color, @bgcolor);
    }
    &.cp-app-todo {
        @bgcolor: @colortheme_todo-bg;
        @color: @colortheme_todo-color;
        .addToolbarColors(@color, @bgcolor);
    }


    /* TODO: move to the slide LESS page */
    .cp-app-slide {
        @media screen and (max-width: @browser_media-medium-screen) {
            .cp-toolbar-leftside {
                flex-flow: row wrap;
                width: 175px;
                height: auto;
                .cp-toolbar-spinner { order: 0; }
            }
            .cp-toolbar-rightside {
                height: 2*@toolbar_line-height;
            }
        }
        @media screen and (max-width: 320px) {
            .cp-toolbar-leftside {
                flex-flow: row wrap;
                width: 175px;
                height: auto;
                padding-top: @toolbar_line-height;
                .cp-toolbar-spinner { order: 0; }
            }
            .cp-toolbar-rightside {
                height: auto;
            }
        }
    }

    .cp-toolbar {
        * {
            outline-width: 0;
            &:focus {
                outline-width: 0;
            }
        }

        @toolbar-green: #5cb85c;

        box-sizing: border-box;
        padding: 0px;

        //background-color: #BBBBFF;
        background-color: @colortheme_default-bg;
        color: @colortheme_default-color;



        .fa {
            font: normal normal normal 14px/1 FontAwesome;
            font-family: FontAwesome;
        }

        .tools_unselectable();

        font: @toolbar_button-font;
        width: 100%;
        z-index: 10000; // cp-toolbar

        .cp-dropdown-container {
            //height: 100%;
            //display: inline-block;
            button {
                height: 100%;
                border-radius: 0;
                margin: 0;
                background: transparent;
            }
        }

        button {
            transition: all 0.15s;
            .tools_unselectable();
            &.cp-toolbar-hidden {
                display: none;
            }
            .cp-toolbar-drawer-element {
                display: none;
            }
            // Bootstrap 4 colors (btn-secondary)
            border: 1px solid transparent;
            color: inherit;
            font: @toolbar_button-font;
            * {
                color: inherit;
                font: @toolbar_button-font;
            }
        }
        .cp-toolbar-rightside button, .cp-toolbar-leftside button {
            background: transparent;
            &:hover {
                background-color: rgba(50,50,50,0.3);
            }
        }

        .cp-toolbar-limit {
            box-sizing: border-box;
            height: 26px;
            width: 26px;
            display: inline-block;
            padding: 3px;
            margin: 0px 3px 0 6px;
            vertical-align: middle;
            line-height: @toolbar_top-height;
            span {
                color: red;
                cursor: pointer;
                margin: auto;
                font-size: 20px;
            }
        }

        div {
            white-space: normal;
        }

        button, select {
            height: @toolbar_line-height;
            box-sizing: border-box;
            padding: 3px 10px;
            margin: 0;

        }

        .cp-toolbar-rightside-button {
            float: right;
            cursor: pointer;
        }

        select {
            border: 0px;
            margin-left: 5px;
            margin-right: 5px;
            padding-left: 5px;
            border: 1px solid #A6A6A6;
            border-bottom-color: #979797;
            vertical-align: top;
            box-sizing: content-box;
            option {
                height: 24px;
            }
        }

        &.cp-toolbar-notitle {
            .cp-toolbar-top-filler {
                flex: 1;
            }
        }
        &:not(.cp-toolbar-notitle) {
            .cp-toolbar-top {
                @media screen and (max-width: @browser_media-medium-screen) {
                    flex-wrap: wrap;
                    height: auto;
                    .cp-toolbar-top-filler {
                        flex: 1;
                    }
                    .cp-toolbar-title {
                        flex: auto;
                        width: 100%;
                        order: 10;
                        height: @toolbar_line-height;
                        line-height: initial;
                        margin: 0;
                        .cp-toolbar-title-hoverable {
                            width: 100%;
                        }
                        .cp-toolbar-title-editable {
                            max-width: ~"calc(100vw - 26px)";
                            display: inline-block;
                            overflow: hidden;
                            text-overflow: ellipsis;
                            font-size: @colortheme_app-font-size;
                            height: @toolbar_line-height;
                            box-sizing: border-box;
                            line-height: 20px;
                        }
                        .cp-toolbar-title-edit, .cp-toolbar-title-save {
                            box-sizing: border-box;
                            height: @toolbar_line-height;
                            line-height: @colortheme_app-font-size;
                            display: inline-block;

                            .fa {
                                font-size: @colortheme_app-font-size;
                            }
                        }
                        input {
                            height: @toolbar_line-height;
                            font-size: @colortheme_app-font-size;
                            flex: 1;
                            max-width: none;
                        }
                    }
                }
            }
        }
    }

    .cp-toolbar-top {
        display: flex;
        flex-flow: row;
        height: @toolbar_top-height;
        position: relative;
        .cp-toolbar-top-filler {
            height: 100%;
            display: inline-block;
            order: 4;
            //flex: 1;
        }
        .cp-toolbar-title {
            flex: 1;
            overflow: hidden;
            text-overflow: ellipsis;
            order: 3;
            height: 100%;
            display: inline-flex;
            align-items: center;
            line-height: @toolbar_top-height;
            margin: 0 10px;
            .cp-toolbar-title-value {
                border: 1px solid transparent;
                padding: 5px;
                font-size: 25px;
                vertical-align: middle;
                line-height: 25px;
                white-space: nowrap;
            }
            .cp-toolbar-title-value-page {
                border: 1px solid transparent;
                padding: 0 5px;
                line-height: 48px;
            }
            .cp-toolbar-title-edit, .cp-toolbar-title-save {
                display: flex;
                align-items: center;
                font-size: 20px;
                vertical-align: middle;
                line-height: 20px;
                .fa {
                    font-size: 20px;
                }
            }
            .cp-toolbar-title-readonly {
                margin-left: 10px;
                font-size: 25px;
                font-style: italic;
                white-space: nowrap;
            }
            .cp-toolbar-title-hoverable {
                display: inline-flex;
                overflow: hidden;
            }
            .cp-toolbar-title-edit {
                cursor: pointer;
                border: 1px solid transparent;
                padding: 5px;
                border-collapse: collapse;
                span {
                    cursor: pointer;
                }
            }
            .cp-toolbar-title-save {
                cursor: pointer;
                padding: 5px;
                border-collapse: collapse;
                span {
                    cursor: pointer;
                }
            }
            .cp-toolbar-title-editable {
                overflow: hidden;
                text-overflow: ellipsis;
                border-collapse: collapse;
            }
            input {
                max-width: ~"calc(100% - 40px)";
                flex: 1;
                font-size: 1.5em;
                vertical-align: middle;
                box-sizing: border-box;
                cursor: auto;
                width: 300px;
                font-size: 20px;
                padding: 5px 5px;
                height: 40px;
            }
        }
        .cp-toolbar-link, .cp-toolbar-new {
            font-size: 48px;
            line-height: 64px;
            width: @toolbar_top-height;
            height: @toolbar_top-height;
            padding: 0;
            box-sizing: border-box;
            display: inline-block;

            color: white;
            a {
                color: white;
            }
            transition: all 0.15s;
        }
        .cp-toolbar-new {
            background-color: rgba(0,0,0,0.2);
            &:hover {
                background-color: rgba(0,0,0,0.3);
            }
            text-align: center;
            font-size: 32px;
            margin-left: 10px;
            &> button {
                display: flex;
                align-items: center;
                justify-content: center;
                width: 64px;
                height: 64px !important; // Allows us to have a nice square outline when focused
                font-size: 1em;
                color: inherit;
                height: auto;
                padding: 0px;
                margin: 0;
                &::before {
                    width: 100%;
                    text-align: center;
                    padding-top: 4px;
                }
                &:hover {
                    background-color: initial;
                    border-color: transparent;
                }
                span {
                    vertical-align: top;
                    font-size: 1em;
                    text-decoration: none;
                    color: inherit;
                }
            }
        }
        .cp-toolbar-link {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            background-color: rgba(0,0,0,0.4);
            &:hover {
                background-color: rgba(0,0,0,0.5);
            }
            order: 1;
            .fa {
                margin: 0;
            }
            a.cp-toolbar-link-logo {
                cursor: pointer;
                display: inline-flex;
                text-decoration: none;
                height: auto;
                padding: 10px;

                img {
                    cursor: pointer;
                    height: 100%;
                    width: 100%;
                }
            }
        }
        .cp-toolbar-user {
            height: 100%;
            display: inline-flex;
            order: 5;
            line-height: @toolbar_top-height;
            color: white;
            .cp-toolbar-new { order: 2; }
            .cp-toolbar-user-dropdown { order: 3; }
            .cp-toolbar-backup { order: 4; } // TODO drive migration to secure iframe
            &> * {
                display: inline-block;
                height: 100%;
                vertical-align: top;
            }
            .cp-toolbar-user-dropdown {
                z-index: 10000; //Z cp-toolbar-user-dropdown
                //margin-left: 20px;
                height: 64px;
                width: 64px;
                padding: 0px;
                box-sizing: border-box;
                text-align: center;
                background-color: rgba(0,0,0,0.3);
                transition: all 0.15s;
                &:hover {
                    background-color: rgba(0,0,0,0.4);
                }
                .cp-dropdown-content {
                    margin: 0;
                }
                button {
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    height: 64px;
                    width: 64px;
                    padding: 0;
                    span {
                        text-align: center;
                        width: 100%;
                        cursor: default;
                        font-size: 32px;
                    }
                    &.cp-avatar {
                        .avatar_main(48px);
                        &.cp-userlist-clickable {
                            cursor: pointer;
                            &:hover {
                                background-color: rgba(0,0,0,0.3);
                            }
                        }
                        .cp-toolbar-userlist-rightcol {
                            order: 10;
                            flex: 1;
                            overflow: hidden;
                            text-overflow: ellipsis;
                            white-space: nowrap;
                            display: flex;
                            flex-flow: column;
                            .cp-toolbar-userlist-name {
                                flex: 1;
                                overflow: hidden;
                                text-overflow: ellipsis;
                                white-space: nowrap;
                            }
                            .cp-toolbar-userlist-friend {
                                padding: 0;
                            }
                        }
                        media-tag {
                            margin: 8px;
                        }
                        border: 0;
                    }
                }
            }
            p.cp-toolbar-account {
                &> span {
                    font-weight: bold;
                    span {
                        font-weight: normal;
                    }
                }
            }
            .cp-toolbar-backup {
                margin: 0;
                border-radius: 0;
                background: transparent;
                &:hover {
                    background-color: rgba(0,0,0,0.2);
                }
            }
        }
    }

    .cp-toolbar-leftside {
        //height: @toolbar_line-height;
        &:empty {
            height: 0;
        }
        float: left;
        display: inline-flex;
        align-items: center;
        //margin-bottom: -1px;
        .cp-toolbar-users {
            pre {
                /* needed for ckeditor */
                white-space: pre;
                margin: 5px 0px;
            }
        }
        button {
            margin: 0px;
            border-radius: 0;
            height: 100%;
        }
        .cp-dropdown-content {
            margin-top: -1px;
        }

        & > span {
            height: @toolbar_line-height;
        }

        #cp-toolbar-userlist-drawer-open { order: 1; }
        .cp-toolbar-share-button { order: 2; }
        .cp-toolbar-spinner { order: 3; }

        #cp-toolbar-userlist-drawer-open button {
            width: 125px;
            text-align: center;
        }
        .cp-toolbar-share-button button {
            width: 50px;
            text-align: center;
        }
    }
    .cp-toolbar-rightside {
        min-height: @toolbar_line-height;
        overflow: hidden;
        &:empty {
            min-height: 0;
            height: 0;
        }
        text-align: right;
        /*&> button {
            height: 100%;
            margin: 0;
            border-radius: 0;
            padding: 0 10px;
        }*/
        .cp-toolbar-drawer-content:empty ~ .cp-toolbar-drawer-button {
            display: none;
        }
        .cp-toolbar-drawer-content {
            box-shadow: 0px 1px 5px 0px rgba(0, 0, 0, 0.2);
            position: absolute;
            right:0px;
            margin-top: @toolbar_line-height;
            min-width: 50px;
            background: @colortheme_dropdown-bg;
            display: flex;
            flex-flow: column;
            z-index:10000; //Z cp-toolbar-drawer-content
            color: black;
            .fa {
                font-size: 17px;
            }
            &> span {
                box-sizing: border-box;
                min-width: 150px;
                height: @toolbar_line-height;
                border-radius: 0;
                border: 0;
            }
            button {
                padding: 5px 16px;
                text-align: left;
                margin: 0;
                border-radius: 0;
                border: 0;
                width: 100%;
                line-height: 1em;
                .cp-toolbar-drawer-element {
                    margin-left: 10px;
                    display: inline;
                    vertical-align: top;
                }
                &:hover {
                    background-color: @colortheme_dropdown-bg-hover !important;
                    color: @colortheme_dropdown-color;
                }
            }
        }
    }
    .cp-toolbar-spinner {
        line-height: @toolbar_line-height;
        padding: 0 20px;
        &> span.fa {
            height: 20px;
            width: 20px;
            //margin: 8px;
            line-height: 20px;
            font-size: 20px;
            text-align: center;
        }
    }
    .cp-toolbar-readonly {
        margin-right: 5px;
        font-weight: bold;
        text-transform: uppercase;
    }
    .cp-toolbar-share {
        a {
            .fa {
                margin-right: 5px;
            }
        }
    }

}

