@use "../../../../styles/utils" as *;
@use "./components/thread-event/index" as *;
@use "./components/thread-event-input/index" as *;

.thread-view {
    background-color: var(--c--contextuals--background--surface--tertiary);
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow-y: auto;

    &--empty {
        align-items: center;
        justify-content: center;
        text-align: center;
        height: 100%;
        background: var(--c--contextuals--background--surface--tertiary);

        & > div {
            font-size: var(--c--globals--font--sizes--h6);
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 1rem;

            & > * {
                margin-block: 0;
            }

            p {
                color: var(--c--contextuals--content--semantic--neutral--tertiary);
            }
        }
    }
}

.thread-view--talk .thread-message:not(.thread-message--sender) {
    margin-right: var(--c--globals--spacings--xxl);
}

.thread-view--talk .thread-message.thread-message--sender {
    margin-left: var(--c--globals--spacings--xxl);
}

@media screen and (max-width: breakpoint(mobile)) {
    .thread-view {
        position: fixed;
        top: var(--header-height);
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 900;
        height: auto;
    }

    .thread-view--talk .thread-message:not(.thread-message--sender),
    .thread-view--talk .thread-message.thread-message--sender {
        margin-inline: 0;
    }
}

.thread-view--loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.thread-view__labels-list {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    padding: var(--c--globals--spacings--base);
    padding-left: var(--c--globals--spacings--md);
    padding-top: 0;
}


.thread-view__messages-list {
    display: flex;
    flex-direction: column;
    gap: var(--c--globals--spacings--base);
    padding: var(--c--globals--spacings--base);
    flex: 1;
}

.thread-view__trashed-banner__content {
    display: flex;
    flex-direction: row;
    gap: var(--c--globals--spacings--base);
    justify-content: space-between;
}

.thread-view__trashed-banner__actions {
    display: flex;
    gap: var(--c--globals--spacings--sm);
}


.thread-view__header {
    padding-inline: var(--c--globals--spacings--md) var(--c--globals--spacings--base);
    padding-block: var(--c--globals--spacings--b) var(--c--globals--spacings--base);
    background: linear-gradient(to top, var(--c--globals--colors--black-000), var(--c--contextuals--background--surface--tertiary) 15px, var(--c--contextuals--background--surface--tertiary) 100%);
    z-index: 10;
    container-type: inline-size;
}

.thread-view__header__top {
    display: flow-root;

    .thread-action-bar__container {
        float: right;
        width: auto;
        margin-left: var(--c--globals--spacings--base);
        margin-bottom: var(--c--globals--spacings--4xs);
    }

    // Switch to a stacked layout before the title is squeezed down to a few
    // orphan letters on its first line. Using a container query (not a media
    // query) keeps the trigger in sync with the resizable thread panel width.
    @container (max-width: 35rem) {
        display: flex;
        flex-direction: column;
        gap: var(--c--globals--spacings--xs);

        .thread-action-bar__container {
            float: none;
            align-self: flex-end;
            margin-left: 0;
            margin-bottom: 0;
        }
    }
}

.thread-view__subject {
    font-weight: 700;
    font-size: var(--c--globals--font--sizes--h4);
    vertical-align: baseline;

    & > .thread-view__subject__star {
        font-size: var(--c--globals--font--sizes--h4);
        color: var(--c--contextuals--background--palette--yellow--secondary);
        transform: translate(-4px, 3px)
    }
}

.thread-view__sticky-container {
    position: sticky;
    top: 0;
    z-index: 2;
}

// Magnetic-focus highlight applied after deep-link navigation lands on a
// specific message or comment.
.thread-view__highlight {
    --thread-highlight-color: var(--c--contextuals--content--semantic--info--primary);
}

.thread-message.thread-view__highlight {
    animation: thread-view-highlight-focus 1700ms cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    z-index: 3;
}

// On a thread-event, the visible "bubble" is `__content` (the rounded
// background block that holds the text).
.thread-event.thread-view__highlight .thread-event__content {
    animation: thread-view-highlight-focus 1700ms cubic-bezier(0.34, 1.56, 0.64, 1);
    transform-origin: left center;
    position: relative;
    z-index: 3;
}

@keyframes thread-view-highlight-focus {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 transparent;
    }
    18% {
        transform: scale(1.014);
        box-shadow:
            0 22px 56px -14px color-mix(in srgb, var(--thread-highlight-color) 28%, transparent),
            0 0 0 2px var(--thread-highlight-color);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 transparent;
    }
}

.thread-view__messages-list--focusing > :not(.thread-view__highlight) {
    animation: thread-view-dim-cycle 1700ms both;
}

@keyframes thread-view-dim-cycle {
    0% {
        opacity: 1;
        filter: saturate(1);
        animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
    }
    18% {
        opacity: 0.42;
        filter: saturate(0.88);
        animation-timing-function: linear;
    }
    40% {
        opacity: 0.42;
        filter: saturate(0.88);
        animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
    }
    100% {
        opacity: 1;
        filter: saturate(1);
    }
}

@media (prefers-reduced-motion: reduce) {
    .thread-message.thread-view__highlight,
    .thread-event.thread-view__highlight .thread-event__content {
        animation: none;
        box-shadow: 0 0 0 2px var(--thread-highlight-color);
        transition: box-shadow 1.2s ease-out;
    }
    .thread-view__messages-list--focusing > :not(.thread-view__highlight) {
        animation: none;
        opacity: 1;
        filter: none;
    }
}
