///
/// This file regroups the frontend general design rules and portal design
/// rules.
///

// ======  Variables =========
$o-theme-navbar-logo-height: $nav-link-height !default;

// Portal toolbar (filters, search bar)
$o-portal-mobile-toolbar: true; // Enable/Disable custom design
$o-portal-mobile-toolbar-border: $border-color;
$o-portal-mobile-toolbar-bg: $gray-200;

// Portal Tables
$o-portal-table-th-pt: map-get($spacers, 2) !default; // bts4 pt-2
$o-portal-table-th-pb: map-get($spacers, 2) !default; // bts4 pb-2
$o-portal-table-td-pt: map-get($spacers, 1) !default; // bts4 pt-1
$o-portal-table-td-pb: map-get($spacers, 1) !default; // bts4 pb-1

// Portal custom bg color
$o-portal-bg-color: desaturate($gray-200, 100%);

// Check if portal uses default colors
$o-portal-use-default-colors: $body-bg == $o-portal-default-body-bg;

// Frontend general
#wrapwrap {
    position: relative;
    display: flex;
    flex-flow: column nowrap;
    width: 100%;
    min-height: 100%;

    > * {
        flex: 0 0 auto;
    }
    > main {
        flex: 1 0 auto;
    }
}

header {
    .navbar-brand {
        flex: 0 0 auto;
        max-width: 75%;

        &.logo {
            padding-top: 0;
            padding-bottom: 0;

            img {
                // object-fit does not work on IE but is only used as a fallback
                object-fit: contain;
                display: block;
                width: auto;
                height: $o-theme-navbar-logo-height;

                @include media-breakpoint-down(sm) {
                    height: auto;
                    max-height: min($o-theme-navbar-logo-height, 5rem);
                }
            }
        }
    }
    .nav-link {
        white-space: nowrap;
    }
}
.navbar {
    margin-bottom: 0;

    ul.nav > li {
        &.divider {
            display: none;
            border-right: 1px solid $nav-divider-color;
        }

        &.active + .divider {
            visibility: hidden;
        }
    }
    .nav.navbar-nav.float-right {
        @include media-breakpoint-down(sm) {
            float: none!important;
        }
    }
}
@include media-breakpoint-up(md) {
    .navbar-expand-md ul.nav > li.divider {
        display: list-item;
    }
}
ul.flex-column > li > a {
    padding: 2px 15px;
}

// Link without text but an icon
a, .btn-link {
    &.fa:hover {
        text-decoration: $o-theme-btn-icon-hover-decoration;
    }
}

// Odoo options classes
.jumbotron {
    margin-bottom: 0;
}

// Typography
ul {
    list-style-type: disc;
}
ul ul {
    list-style-type: circle;
}
ul ul ul {
    list-style-type: square;
}
ul ul ul ul {
    list-style-type: disc;
}
ul ul ul ul ul {
    list-style-type: circle;
}
ul ul ul ul ul ul {
    list-style-type: square;
}
ul ul ul ul ul ul ul {
    list-style-type: disc;
}
ol {
    list-style-type: decimal;
}
ol ol {
    list-style-type: lower-alpha;
}
ol ol ol {
    list-style-type: lower-greek;
}
ol ol ol ol {
    list-style-type: decimal;
}
ol ol ol ol ol {
    list-style-type: lower-alpha;
}
ol ol ol ol ol ol {
    list-style-type: lower-greek;
}
ol ol ol ol ol ol ol {
    list-style-type: decimal;
}
li > p {
    margin: 0;
}

// Bootstrap hacks
%o-double-container-no-padding {
    padding-right: 0;
    padding-left: 0;
}
.container {
    .container, .container-fluid {
        @extend %o-double-container-no-padding;
    }
}
.container-fluid .container-fluid {
    @extend %o-double-container-no-padding;
}
#wrap {
    > .container, > .container-fluid {
        // BS3 used to do this on all containers so that margins and floats are
        // cleared inside containers. As lots of current odoo layouts may rely
        // on this for some alignments, this is restored (at least for a while)
        // here only for main containers of the frontend.
        &::before, &::after {
            content: "";
            display: table;
            clear: both;
        }
    }
}
[class^="col-lg-"] {
    min-height: 24px;
}
.input-group {
    flex-flow: row nowrap;
}
.list-group-item:not([class*="list-group-item-"]):not(.active) {
    color: color-yiq($list-group-bg);
}

%o-portal-breadcrumbs {
    background-color: inherit;
}

// Replaces old BS3 page-header class
%o-page-header {
    margin-bottom: $headings-margin-bottom * 2;
    padding-bottom: $headings-margin-bottom;
    border-bottom-width: $border-width;
    border-bottom-style: solid;
    border-bottom-color: $border-color;
    line-height: 2.1rem;
}
.o_page_header {
    @extend %o-page-header;
}

// Images spacing
img, .media_iframe_video, .o_image {
    &.float-right {
        margin-left: $grid-gutter-width / 2;
    }
    &.float-left {
        margin-right: $grid-gutter-width / 2;
    }
}
img.o_we_custom_image {
    // Images added with the editor are .img-fluid by default but should
    // still behave like inline content.
    display: inline-block;
}

// Others
::-moz-selection {
    background: rgba(150, 150, 220, 0.3);
}
::selection {
    background: rgba(150, 150, 220, 0.3);
}
.oe_search_box {
    padding-right: 23px;
}

// Kept for (up to) saas-12 compatibility
.para_large {
    font-size: 120%;
}
.jumbotron .para_large p {
    font-size: 150%;
}
.readable {
    font-size: 120%;
    max-width: 700px;
    margin-left: auto;
    margin-right: auto;

    .container {
        padding-left: 0;
        padding-right: 0;
        width: auto;
    }
}

//  Background (kept for 8.0 compatibility) (! some are still used by website_blog)
.oe_dark {
    background-color: rgba(200, 200, 200, 0.14);
}
.oe_black {
    background-color: rgba(0, 0, 0, 0.9);
    color: white;
}
.oe_green {
    background-color: #169C78;
    color: white;
    .text-muted {
        color: #ddd !important;
    }
}
.oe_blue_light {
    background-color: #41b6ab;
    color: white;
    .text-muted {
        color: #ddd !important;
    }
}
.oe_blue {
    background-color: #34495e;
    color: white;
}
.oe_orange {
    background-color: #f05442;
    color: white;
    .text-muted {
        color: #ddd !important;
    }
}
.oe_purple {
    background-color: #b163a3;
    color: white;
    .text-muted {
        color: #ddd !important;
    }
}
.oe_red {
    background-color: #9C1b31;
    color: white;
    .text-muted {
        color: #ddd !important;
    }
}
.oe_none {
    background-color: #FFFFFF;
}
.oe_yellow {
    background-color: #A2A51B;
}
.oe_green {
    background-color: #149F2C;
}

// Portal specific
// ===  Page custom bg ===
// To be applied to all portal pages if bg-color is white (default).
@if ($o-portal-use-default-colors) {
    #wrapwrap.o_portal {
        @include o-bg-color($o-portal-bg-color);
    }
}

.o_portal {
    .breadcrumb {
        @extend %o-portal-breadcrumbs;
    }

    > tbody.o_portal_report_tbody {
        vertical-align: middle;
    }
}

.o_portal_wrap {
    .o_portal_my_home > .o_page_header > a:hover {
        text-decoration: none;
    }

    .o_portal_navbar {
        .breadcrumb {
            padding-left: 0;
            padding-right: 0;
            @extend %o-portal-breadcrumbs;
        }

        @if ($o-portal-use-default-colors) {
            background-color: white!important;
        }
    }

    .o_portal_my_doc_table {
        th {
            padding-top: $o-portal-table-th-pt;
            padding-bottom: $o-portal-table-th-pb;
        }

        td {
            padding-top: $o-portal-table-td-pt;
            padding-bottom: $o-portal-table-td-pb;

        }

        tr:last-child td {
            padding-bottom: $o-portal-table-td-pb * 1.5;
        }

        td, th {
            vertical-align: middle;
            white-space: nowrap;
        }
    }

    address {
        span[itemprop="name"] {
            margin-bottom: 0.3em;
        }

        div[itemprop="address"] > div {
            position: relative;

            span[itemprop="streetAddress"] {
                line-height: 1.2;
                margin-bottom: 0.3em;
            }

            .fa {
                @include o-position-absolute(0, $left: 0);
                line-height: $line-height-base;

                + span, + div {
                    display: block;
                    // FontAwesome '.fa-fw' fixed-with + margin
                    padding-left: 1.28571429em + 0.5em;
                }
            }
        }
    }

    .o_my_sidebar div[itemprop="address"] > div {
        margin-top: 0.5em;
    }

    @if ($o-portal-mobile-toolbar) {
        #o_portal_navbar_content {
            @include media-breakpoint-down(md) {
                margin: $navbar-padding-y (-$navbar-padding-x) 0;
                padding: $navbar-padding-y $navbar-padding-x ;
                border-top: $border-width solid $o-portal-mobile-toolbar-border;
                background-color: $o-portal-mobile-toolbar-bg;
            }
        }
    }

    table.table tr {
        word-wrap: break-word;
    }
}

.oe_attachments .o_image_small {
    height: 40px;
    width: 50px;
}

form label {
    font-weight: $font-weight-bold;
    &.label-optional {
        font-weight: $font-weight-normal;
    }
}

.o_portal_contact_img {
    width: 2.3em;
    height: 2.3em;
    object-fit: cover;
}

.o_portal_sidebar {
    #sidebar_content.card {
        border-left: 0;
        border-bottom: 0;

        > div.card-body {
            border-left: $border-width solid $border-color;
        }

        > ul > li {
            border-left: $border-width solid $border-color;
            margin-bottom: -1px;
        }

        > div.card-footer {
            border-left: $border-width solid $border-color;
            border-bottom: $border-width solid $border-color;
        }
    }

    .o_portal_html_view {
        overflow: hidden;
        background: white;
        position: relative;

        .o_portal_html_loader {
            @include o-position-absolute(45%, 0, auto, 0);
        }

        iframe {
            position: relative;
        }
    }
}

// ------------------------------------------------------------
// Frontend Discuss widget
// ------------------------------------------------------------

// Readonly display
.o_portal_chatter {
    padding: 10px;

    .o_portal_chatter_avatar {
        width: 45px;
        height: 45px;
        margin-right: 1rem;
    }

    .o_portal_chatter_header {
        margin-bottom: 15px;
    }

    .o_portal_chatter_composer {
        margin-bottom: 15px;
    }

    .o_portal_chatter_messages {
        margin-bottom: 15px;

        .o_portal_chatter_message_title {
            p {
                font-size:85%;
                color:$o-main-color-muted;
                margin: 0px;
            }
        }
    }

    .o_portal_chatter_pager {
        text-align: center;
    }


}

// Readonly / Composer mix display
.o_portal_chatter,
.o_portal_chatter_composer {
    .o_portal_chatter_attachment {
        .o_portal_chatter_attachment_name {
            word-wrap: break-word;
        }

        .o_portal_chatter_attachment_delete {
            @include o-position-absolute($top: 0, $right: 0);
            opacity: 0;
        }

        &:hover .o_portal_chatter_attachment_delete {
            opacity: 1;
        }
    }

    .o_portal_message_internal_off {
        .btn-danger {
            display: none;
        }
    }

    .o_portal_message_internal_on {
        .btn-success {
            display: none;
        }
    }
}
