// Import Bootstrap breakpoint functions
@import "../../../../vendor/twbs/bootstrap/scss/functions";
@import "../../../../vendor/twbs/bootstrap/scss/variables";
@import "../../../../vendor/twbs/bootstrap/scss/mixins/breakpoints";

$bgColorDefault: var(--hh-background-color-secondary);
$colorUnread: var(--bs-info);

$radius: 10px;
$radiusMiddle: 7px;
$radiusSmall: 4px;
$radiusRound: 50%;
$radiusNone: 0;

:root {
    --hh-mail-offset-top: 0px;
    --hh-mail-top-conversation-height: 0px;
}
@include media-breakpoint-down(lg) {
    :root {
        --hh-mail-top-conversation-height: 60px;
    }
}
@include media-breakpoint-down(md) {
    :root {
        --hh-mail-top-conversation-height: 50px;
    }
}

@mixin semiBold(){
    font-weight: 600
}

#dropdown-messages {
    .dropdown-header {
        color: #000;
        margin-bottom: 12px;
        @include semiBold;
    }

    &.dropdown-menu {
        li {
            a {
                font-size: inherit !important;
            }
        }
    }

    .text-break {
        font-weight: 200;
    }
}

.modal-body {
    #createmessage-message {
        .ProseMirror {
            min-height: 100px !important;
        }
    }
}

#mail-conversation-create-button, #create-message-button {
    .fa {
        margin: 0;
    }
}

#conversation-tags-root {
    border-bottom: 1px solid #eee;

    .my-tags-label {
        padding-right: 10px;
    }
}

.conversation-edit-button {
    border-bottom-right-radius: $radiusNone;
    border-top-right-radius: $radiusNone;
}

.conversation-scroll-down-button {
    position: absolute;
    z-index: 1;
    cursor: pointer;
    bottom: 58px;
    right: 25px;
    width: 38px;
    height: 38px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 1px 1px 2px #999;

    .fa {
        font-size: 26px;
        margin: 7px 0 0 11px;
    }
}

.conversation-entry-list {
    height: 100%;
}

.conversation-entry-content {
    display: table;
    float: left;
    background-color: $bgColorDefault;
    border-radius: $radius;
    padding: 10px;
    max-width: 70%;

    pre {
        max-width: 485px;
    }

    &.own {
        background: var(--hh-background-color-highlight);
    }

    .markdown-render {
        float: left;
        width: 100%;
        min-width: 230px;
    }
}

.conversation-blocked-recipient {
    -webkit-filter: grayscale(100%);
    filter: grayscale(100%);
}

#mail-conversation-root {
    hr {
        border-top: 1px solid #eee;
    }

    .ProsemirrorEditor.focusMenu {
        .ProseMirror-menubar {
            margin-top: -0;
        }
    }

    > .panel {
        display: flex;
        flex-direction: column;
        height: calc(100vh - 15px - var(--hh-fixed-header-height) - var(--hh-fixed-footer-height) - var(--hh-mobile-app-safe-area-inset-bottom, env(safe-area-inset-bottom)) - var(--hh-mail-top-conversation-height)); // 15px of the .panel margin-bottom

        > .conversation-entry-container {
            flex: 1;
            overflow: auto;
        }

        .content_create .richtext-create-input-group>.mb-3 [data-ui-markdown] {
            max-height: calc(50vh - var(--hh-fixed-header-height) - var(--hh-fixed-footer-height) - var(--hh-mobile-app-safe-area-inset-bottom, env(safe-area-inset-bottom)) - var(--hh-mail-top-conversation-height));
            overflow-y: auto;
        }
    }
}

#mail-conversation-header {
    padding: 6px 10px;
    border-bottom: 1px solid var(--hh-background3);
    border-bottom-left-radius: $radiusNone;
    border-bottom-right-radius: $radiusNone;

    h1 {
        @include semiBold;
        font-size: 16px;
        display: inline-block;
    }

    @include media-breakpoint-up(sm) {
        padding: 18px;
        h1 {
            font-size: 18px;
        }
    }

    small {
        display: block;
        font-size: 11px;
        font-weight: normal;

        a {
            color: var(--hh-text-color-main);
        }
    }

    @media (max-height: 500px) {
        h1 {
            margin-bottom: 0;
        }
        small {
            display: none;
        }
    }
}

#conversation-settings-button {
    padding: 6px;
    font-size: 12px;
    cursor: pointer;
}

#mail-filter-root {
    margin-top: 5px;
}

.mail-inbox-messages {
    .hh-list,
    .messagePreviewEntry,
    .mail-link {
        overflow-x: hidden;
    }

    .panel-heading {
        > a {
            @include semiBold;
        }

        #mail-filter-root > a {
            font-weight: normal;
        }
    }

    .text-break {
        min-width: 0;

        h4 {
            @include semiBold;
            font-size: 16px;
            display: flex;
            gap: 8px;

            time {
                font-size: 11px !important;
                font-weight: normal;
                flex: 0 0 auto;
                margin-left: auto;
                text-align: right;
            }
        }

        h5 {
            font-size: 14px;
            line-height: 16px;
            font-weight: 500 !important;
            color: var(--hh-text-color-highlight) !important;
            display: flex;
            justify-content: space-between;
            margin: 7px 0;

            span:first-child {
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
            }
        }

        .mail-last-entry {
            font-size: 14px;
            font-weight: 500;
            color: var(--hh-text-color-secondary);
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
    }
}

.mail-message-form {
    width: 100%;
    padding: 10px;
    box-shadow: none;
    border: none;
    margin-bottom: 0 !important;

    > panel-body {
        margin: 0 10px;
    }

    .content-create-input-group {
        position: relative;
    }

    .humhub-ui-richtext {
        border-radius: $radius;
    }

    @include media-breakpoint-up(md) {
        // Display the buttons on the bottom right of the richtext editor
        .humhub-ui-richtext {
            padding-right: 115px;
        }

        .richtext-create-buttons {
            position: absolute;
            right: 24px;
            bottom: 24px;
            z-index: 500;
        }
    }

    .reply-button {
        margin-left: 0 !important;
    }

    .form-text {
        margin: 0;
    }

    .alert {
        margin-bottom: 0;
    }
}

.mail-conversation-entry {
    margin-top: 3px;
    position: relative;

    .conversation-menu {
        visibility: hidden; // Visible on .mail-conversation-entry:hover
        padding-left: 35px;

        .conversation-menu-item {
            margin-bottom: 10px;
            margin-left: 5px;

            a {
                cursor: pointer;
            }
        }

        .time {
            color: inherit;
            text-transform: none;
        }

        .badge {
            background-color: $bgColorDefault;
            border-radius: $radius;
            color: inherit;
        }

        .conversation-edit-button {
            background-color: $bgColorDefault;
            border-radius: $radiusRound;
            color: inherit;

            &:hover {
                background-color: $bgColorDefault;
                color: inherit;
            }
        }
    }

    &:hover {
        .conversation-menu {
            visibility: visible;
        }
    }

    .author-image {
        .img-user {
            max-width: 100%;
        }
    }

    .author-label {
        font-size: 10px;
        @include semiBold;
    }

    &.hideUserInfo {
        .author-label {
            display: none;
        }

        .author-image {
            a {
                visibility: hidden;
                margin-top: 0;
            }
        }
    }

    .conversation-entry-time {
        float: right;
        font-size: 10px;
        color: var(--hh-text-color-main);

        > span {
            font-style: italic;
        }
    }
}

.conversation-entry-badge {
    padding: 10px 0 8px;
    text-align: center;

    span {
        display: inline-block;
        box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.3);
        border-radius: $radiusMiddle;
        padding: 5px 20px;
    }

    &.conversation-date-badge span {
        text-transform: uppercase;
    }
}

#inbox {
    max-height: calc(100vh - var(--hh-fixed-header-height) - var(--hh-fixed-footer-height) - var(--hh-mobile-app-safe-area-inset-bottom, env(safe-area-inset-bottom)) - var(--hh-mail-offset-top));
    overflow: auto;
    border-radius: $radiusSmall;
}

.messagePreviewEntry {
    cursor: pointer;

    time {
        font-size: 10px;
        color: var(--hh-text-color-secondary);
    }

    .new-message-badge {
        display: none;
    }

    &.unread {
        .new-message-badge {
            display: block;
        }

        time {
            color: $colorUnread;
        }

        .mail-last-entry {
            color: var(--hh-text-color-highlight);
        }
    }
}

.message-tag-filter-group {
    .select2-selection {
        border-bottom-right-radius: $radiusNone;
    }

    .manage-tags-link {
        @include semiBold;
        font-size: 0.8em;
        border: 1px solid #ededed;
        border-top: 0;
        border-bottom-left-radius: $radiusSmall;
        border-bottom-right-radius: $radiusSmall;
        padding: 2px 5px;
    }
}

.new-message-badge {
    float: right;
    min-width: 14px;
    height: 14px;
    border-radius: 50%;
    background: $colorUnread;
    margin-left: 2px;
}

.inbox-entry-title {
    @include semiBold;
}

.field-replyform-message {
    margin: 0;
}

.device-ios-mobile {
    #createmessage-message.ProsemirrorEditor.fullscreen,
    .mail-message-form .ProsemirrorEditor.fullscreen {
        top: var(--hh-fixed-header-height);
        height: calc(100vh - var(--hh-fixed-header-height) - var(--hh-mobile-app-safe-area-inset-bottom, env(safe-area-inset-bottom)));
        height: calc(100dvh - var(--hh-fixed-header-height) - var(--hh-mobile-app-safe-area-inset-bottom, env(safe-area-inset-bottom)));

        .ProseMirror-menubar-wrapper {
            display: flex;
            flex-direction: column;
            height: 100%;
        }

        .ProseMirror-menubar {
            position: sticky !important;
            top: 0 !important;
            z-index: 1;
        }

        .ProseMirror {
            flex: 1 1 auto;
            height: auto;
            min-height: 0;
        }
    }
}

@include media-breakpoint-down(lg) {
    #inbox {
        max-height: 500px !important;
    }
}

@include media-breakpoint-down(md) {
    #dropdown-messages {
        width: 300px !important;
    }

    .arrow {
        margin-left: -101px !important;
    }

    #inbox {
        max-height: none !important;
    }

    .mail-conversation-single-message {
        #inbox {
            max-height: none !important;
        }

        .inbox-wrapper {
            display: none;
        }
    }

    .conversation-entry-content {
        pre {
            max-width: 245px;
            padding: 0;
        }
    }
}
