/*
*
* @copyright Copyright (c) Open-Xchange GmbH, Germany <info@open-xchange.com>
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.

* You should have received a copy of the GNU Affero General Public License
* along with OX App Suite. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*
* Any use of the work other than as authorized under this license or copyright law is prohibited.
*
*/

/* was 35, but we need 45 for proper Japanese */
@thumbIndexWidth: 45px;
@photo-size: 120px;

/* VGrid elements */

.contact-grid-container {

    &.abs { left: @thumbIndexWidth; }

    @photoSize: 48px;
    @paddingLeft: @photoSize + 32;
    @checkboxWidth: 32px;
    @paddingLabel: 32px;

    .vgrid-cell {

        &.contact {

            height: 4.5rem;
            padding: 6px 16px 0 @paddingLeft;
            line-height: 16px;
            border-bottom: 1px solid rgba(0, 0, 0, 0.05);

            .contact-photo {
                position: absolute;
                left: 16px;
                top: 12px;
                width: @photoSize;
                height: @photoSize;
                svg {
                    width: 100%; // fix for safari
                }
            }

            .private_flag {
                float: right;
                color: #aaa;
                font-size: 17px;
                margin-left: 3px;
                line-height: 24px;
            }

            .fullname {
                font-weight: 500;
                font-size: 15px;
                line-height: 24px;
                margin-bottom: -3px;
                .last_name { font-weight: bold; }
                // we use display: flex so that we an ellipsis on first and last name
                display: flex;
                // since we have "LAST, FIRST" or "FIRST LAST" margin-left works better
                // due to the comma. however we need to skip the first element
                > *:not(:first-child) { margin-left: 4px; }
            }

            .presence {
                position: absolute;
                top: 42px;
                left: 48px;
                &.offline { display: none; }
            }

            .description {
                font-weight: normal;
            }
        }

        &.vgrid-label {
            font-size: 24px;
            line-height: 1em;
            text-align: left;
            font-weight: bold;
            color: #333;
            padding: (@paddingLabel - 5) 0 (16px + 4) @paddingLabel;
            background-image: none;
            background-color: #fff;
            border-top: 0 none;
            border-bottom: 1px solid #aaa;
            /* overflow and nowrap for longer labels (e.g. Japanese) */
            white-space: nowrap;
            overflow: visible;
        }
    }

    &.editable .vgrid-cell.contact {
        padding-left: @paddingLeft + @checkboxWidth;
        .contact-photo { left: @checkboxWidth + 16; }
    }

    &.editable .vgrid-cell.vgrid-label  {
        padding-left: @checkboxWidth + @paddingLabel;
    }

    &.invisible-labels .vgrid-label {
        visibility: hidden;
        overflow: hidden;
        height: 0;
        padding: 0;
        border: 0;
    }
}

// Tabs

.contact-grid-index {
    width: @thumbIndexWidth;
    overflow: hidden;
    .user-select(none);
    list-style: none;
    padding:0;

    .thumb-index {
        font-size: 11px;
        line-height: 20px;
        padding: 0 4px;
        font-weight: bold;
        text-align: center;
        white-space: nowrap;
        cursor: pointer;
        margin: 0;

        &:hover, &.focussed {
            color: @white;
            background-color: @link-color;
        }

        &.thumb-index-disabled, &.thumb-index-disabled:hover {
            color: #949494;
            font-weight: normal;
            cursor: default;
        }
    }

    @media (min-height: 800px) {
        .thumb-index {
            line-height: 24px;
        }
    }
}

// Detail view

.contact-detail-edit  { width: 100%; }

// css react to listview resize. less padding for really small views
.scrollable-pane.small-width .contact-detail {
    .dl-horizontal {
        @small-width: 120px;
        dt { width: @small-width; }
        dd { margin-left: @small-width + 32px; }
    }
}

.contact-detail {

    width: 100%;

    .private-flag {
        color: @hc-gray;
        margin-left: 8px;
    }

    .inline-toolbar:first-child {
        margin-top: 0;
        margin-bottom: 16px;
    }

    .attachments-container {
        min-height: 3em;
        .dropdown {
            display: inline-block;
            position: static;
            margin-right: 16px;
            &.open { position: relative; }
        }
    }

    .attachment-item {
        color: #333;
        word-break: break-all;
    }

    .dl-horizontal {
        margin-bottom: 32px;
        dt, dd, .contact-summary .presence { line-height: 24px; }
        &.contact-header { margin-bottom: 22px } // fixes baselining between contact-header and details
    }

    @media (min-width: 768px) {
        @width: max(@photo-size, 200px);
        .dl-horizontal {
            dt { width: @width; }
            dd { margin-left: @width + 32px; }
        }
    }

    dd.note {
        line-height: 16px;
        padding-top: 4px;
        margin-bottom: 4px;
    }


    &.view section.contains-dropdown dd {
        overflow: visible;
    }

    &.view dd:not(.contact-summary), &.view address {
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /*.block {

        margin: 0 0 32px 0;

        dl {
            margin-bottom: 0;

            dt {
                font-size:13px;
                width: 192px;
                text-align: right;
                color: #333;
                line-height: 24px;
                margin-top: -2px;
                margin-bottom: 2px;
            }

            dd {
                margin-left: 216px;
                word-break: break-all;
            }
        }
    }*/

    address {
        color: #333;
        white-space: pre;
        margin-bottom: 4px;
        padding-top: 4px;
        line-height: 16px;
    }

    .member {
        height: 48px;
        clear: both;
        margin-bottom: 1em;
    }

    .member-picture {
        float: left;
        margin-right: 14px;
        .picture(48px, 48px);
    }

    .member-name {
        font-weight: bold;
        padding-top: 4px;
    }
}

/* general blueprint for attachments */
.contact-detail, .contact-edit {

    .attachment-list { margin-top: 2px; }

    .attachment-list .attachment {

        width: 100%;
        position: relative;
        margin-bottom: 4px;
        padding-right: 2.5rem;

        .file {
            padding: 8px 12px;
            background: #f5f5f5;
            border-radius: 4px;
        }

        .filename {
        }

        .filesize {
            color: #707070;
        }

        .remove {
            position: absolute;
            top: 0;
            right: 0;
            bottom:  0;
            width: 2em;
            i.fa {
                position: absolute;
                top: 50%;
                left: 0;
                //left: 58px;
                right: 0;
                margin-top: -0.5em;
                text-align: center;
            }
        }
    }
}

/* general blueprint for contact photo */
.contact-photo {
    /* default size */
    width: 40px;
    height: 40px;
    /* photo as background image */
    background-color: rgba(0, 0, 0, 0.05);
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center center;
    /* shape is circle */
    border-radius: 50%;
    /* for initials */
    color: rgba(0, 0, 0, 0.60);
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* shared between contact detail and edit view */

.contact-header {

    min-height: @photo-size;
    margin-bottom: 40px;

    .contact-photo {
        width: @photo-size;
        height: @photo-size;
        font-size: 24px;
        float: right;
    }

    .contact-summary {
        min-height: @photo-size;
        height: 100%;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    h1 {
        font-size: 24px;
        // to stop descenders(Unterlängen) from being cut of
        line-height: 32px;
        font-weight: normal;
        margin: -1px 0 4px 0;
        overflow: hidden;
        text-overflow: ellipsis;
        .first_name, .last_name {
            .ellipsis();
        }
    }

    h2 {
        font-size: 14px;
        line-height: 16px;
        font-weight: normal;
        color: #707070;
        margin: 0;
    }

    h2.business {
        font-weight: 500;
        color: #333;
    }

    .presence {
        margin-top: 4px;
        .icon {
            position: relative;
            top: -1px;
        }
        &.offline {
            .icon { border: 2px solid white; }
        }
        &.online .availability { color: #438601; }
        &.busy .availability { color: @presence-color-busy; }
    }
}

.distribution-list {

    .contact-header {
        height: auto;
        min-height: auto;
        margin-bottom: 32px;
        padding-top: 2px;
    }

    // placement of all currently available options to adjust baselining
    article {
        .list-count {
            padding-top: 6px;
        }

        .member-list.list-unstyled {
            padding-top: 4px;
        }
    }

}

// smartphone
@media (max-width: @smartphone-breakpoint), (max-device-width: @smartphone-breakpoint) {

    .contact-header {

        height: 64px;
        margin-bottom: 16px;

        h1 {
            font-size: 20px;
            line-height: 24px;
        }

        .contact-photo {
            width: 64px;
            height: 64px;
            font-size: 24px;
            float: left;
            margin-right: 16px;
        }
    }

    .contact-detail {
        .dl-horizontal {
            dt, dd { line-height: 20px; }
            dd { margin-bottom: 8px; }
        }
    }

    .io-ox-contacts-window, .io-ox-halo, .io-ox-sidepopup, .io-ox-search-window {

        .editable .vgrid-cell.contact {
            padding-left: 112px;
        }

        .vgrid.top-toolbar .vgrid-scrollpane {
            top: 0;
            bottom: 40px;
        }

        .contact-detail {

            .comment {
                margin-bottom: 16px;
            }

            .participant-wrapper { margin: 12px 8px; }

            .member-list, .breadcrumb-view { padding: 0; }

            .io-ox-inline-links:first-child {
                margin: 0;
                padding: 15px 0;
                span.io-ox-action-link.dropdown { float: right; }
            }
        }

        .io-ox-pagecontroller.page.default-content-padding {
            padding: 0;
            .scrollable-pane { padding: 16px 16px 0 16px; }
        }
    }

    .contact-grid-container.abs {
        left: 0;
        right: @thumbIndexWidth;
    }

    .contact-grid-index {
        left: auto;
        right: 0;
        width: @thumbIndexWidth;
        padding: 10px 0;

        display: flex;
        flex-direction: column;
        justify-content: space-between;

        .thumb-index {
            font-size: 11px;
            line-height: 12px;
            padding: 0 5px 0 5px;
            margin: 0 1px 0 1px;
        }
    }
}

//io.ox/contacts/listview, io.ox/contacts/common-extensions
.contact-item {

    .fullname {
        .ellipsis();
        font-weight: bold;
        color: rgb(51, 51, 51);
    }

    .bright {
        .ellipsis();
        color: rgb(136, 136, 136);
        font-weight: 300;
    }
}

.department {
    color: #767676;
}

.io-ox-contact-print-dialog {
    iframe {
        width: 200px;
        height: 270px;
        border: 1px solid #ccc;
        box-shadow: 0px 3px 20px #ccc;
    }
}
