/*
 * Messages / live chat (ULTRA-5 → SOCIAL WhatsApp-style rebuild).
 *
 * A full-height chat: sticky header, scrolling bubble log, and a composer bar with
 * emoji + GIF pickers and media attach. Tokens only, theme-aware (dark + light).
 * Bubble classes (gtx-msg*) are shared with the live-append JS, so their names are
 * load-bearing — keep them in sync with pages/messages/thread.phtml.
 */

.gtx-chat {
    display: flex;
    flex-direction: column;
    /* Fill the shell content area (viewport minus top navbar + content padding). */
    height: calc(100vh - 60px - var(--gtx-s6) - var(--gtx-s8));
    min-height: 32rem;
    border: 1px solid var(--gtx-line);
    border-radius: var(--gtx-r-l);
    background: var(--gtx-surface);
    overflow: hidden;
    position: relative;
}

/* --- Header --- */
.gtx-chat__head {
    display: flex;
    align-items: center;
    gap: var(--gtx-s3);
    padding: var(--gtx-s3) var(--gtx-s4);
    background: var(--gtx-chrome);
    border-bottom: 1px solid var(--gtx-line);
    flex: 0 0 auto;
}

.gtx-chat__back {
    display: inline-flex;
    align-items: center;
    color: var(--gtx-text-dim);
    text-decoration: none;
}

.gtx-chat__back:hover {
    color: var(--gtx-text);
}

/* The shared back chevron points left. */
.gtx-chat__back-icon {
    transform: rotate(180deg);
}

.gtx-chat__who {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.gtx-chat__name {
    font-weight: 700;
    color: var(--gtx-text);
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gtx-chat__status {
    font-size: var(--gtx-fs-meta);
    color: var(--gtx-text-dim);
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.gtx-chat__status::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: var(--gtx-r-full);
    background: var(--gtx-text-mute, var(--gtx-text-dim));
    flex: 0 0 auto;
}

.gtx-chat__status.is-on::before {
    background: var(--gtx-ok, #34d399);
}

.gtx-chat__status.is-error::before {
    background: var(--gtx-danger, #f87171);
}

/* --- Call strip --- */
.gtx-chat__call {
    display: flex;
    align-items: center;
    gap: var(--gtx-s2);
    padding: var(--gtx-s2) var(--gtx-s4);
    background: var(--gtx-accent-soft);
    border-bottom: 1px solid var(--gtx-line);
    flex: 0 0 auto;
}

/* --- Message log --- */
.gtx-chat__log {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--gtx-s2);
    padding: var(--gtx-s4);
    background:
        radial-gradient(60% 60% at 100% 0%, var(--gtx-accent-soft) 0%, transparent 60%),
        var(--gtx-bg);
}

.gtx-chat__empty {
    margin: auto;
    color: var(--gtx-text-dim);
}

/* --- Bubbles --- */
.gtx-msg {
    max-width: min(78%, 34rem);
    padding: var(--gtx-s2) var(--gtx-s3);
    border-radius: 14px;
    border: 1px solid var(--gtx-line);
    background: var(--gtx-surface-2);
    box-shadow: var(--gtx-shadow-1, 0 1px 2px rgba(0, 0, 0, 0.15));
}

.gtx-msg--mine {
    align-self: flex-end;
    background: var(--gtx-accent-fill);
    border-color: transparent;
    color: var(--gtx-on-accent);
    border-bottom-right-radius: 4px;
}

.gtx-msg--theirs {
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.gtx-msg__body {
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.45;
}

.gtx-msg__media {
    max-width: 100%;
    margin-top: var(--gtx-s1);
}

.gtx-msg__img,
.gtx-msg__video {
    display: block;
    max-width: 100%;
    max-height: 20rem;
    height: auto;
    border-radius: var(--gtx-r-s);
    border: 1px solid var(--gtx-line);
}

.gtx-msg__meta {
    margin-top: 2px;
    font-size: 10px;
    opacity: 0.7;
    text-align: right;
}

.gtx-msg--theirs .gtx-msg__meta {
    text-align: left;
}

/* --- Composer --- */
.gtx-composer {
    display: flex;
    align-items: flex-end;
    gap: var(--gtx-s2);
    padding: var(--gtx-s2) var(--gtx-s3);
    background: var(--gtx-chrome);
    border-top: 1px solid var(--gtx-line);
    flex: 0 0 auto;
}

.gtx-composer__btn {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid transparent;
    border-radius: var(--gtx-r-full);
    background: transparent;
    color: var(--gtx-text-dim);
    font-size: var(--gtx-fs-h3);
    line-height: 1;
    cursor: pointer;
    transition: color var(--gtx-t-fast) var(--gtx-ease), background-color var(--gtx-t-fast) var(--gtx-ease);
}

.gtx-composer__btn:hover {
    color: var(--gtx-text);
    background: var(--gtx-surface-hover);
}

.gtx-composer__btn--gif {
    font-size: var(--gtx-fs-meta);
    font-weight: 800;
    letter-spacing: 0.03em;
    width: auto;
    padding: 0 var(--gtx-s2);
}

.gtx-composer__btn svg {
    width: 20px;
    height: 20px;
}

.gtx-composer__input {
    flex: 1 1 auto;
    min-width: 0;
    resize: none;
    max-height: 140px;
    padding: var(--gtx-s2) var(--gtx-s3);
    border: 1px solid var(--gtx-line);
    border-radius: 20px;
    background: var(--gtx-surface-2, var(--gtx-surface));
    color: var(--gtx-text);
    font: inherit;
    line-height: 1.4;
}

.gtx-composer__input:focus {
    outline: none;
    border-color: var(--gtx-accent);
}

.gtx-composer__send {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: var(--gtx-r-full);
    background: var(--gtx-accent-fill);
    color: var(--gtx-on-accent);
    cursor: pointer;
    transition: background-color var(--gtx-t-fast) var(--gtx-ease);
}

.gtx-composer__send:hover {
    background: var(--gtx-accent-fill-hover);
}

.gtx-composer__send svg {
    width: 20px;
    height: 20px;
}

.gtx-composer__file {
    padding: 0 var(--gtx-s4) var(--gtx-s2);
    background: var(--gtx-chrome);
    color: var(--gtx-text-dim);
    font-size: var(--gtx-fs-meta);
    text-align: center;
}

/* --- Emoji / GIF picker panels --- */
.gtx-picker {
    position: absolute;
    left: var(--gtx-s3);
    right: var(--gtx-s3);
    bottom: 66px;
    z-index: var(--gtx-z-dropdown);
    max-height: 300px;
    display: flex;
    flex-direction: column;
    padding: var(--gtx-s3);
    background: var(--gtx-surface-2, var(--gtx-surface));
    border: 1px solid var(--gtx-line);
    border-radius: var(--gtx-r-m);
    box-shadow: var(--gtx-shadow-overlay);
}

.gtx-picker__grid {
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(2.2rem, 1fr));
    gap: 2px;
}

.gtx-picker__emoji {
    border: 0;
    background: transparent;
    font-size: 1.35rem;
    line-height: 1;
    padding: 4px;
    border-radius: var(--gtx-r-s);
    cursor: pointer;
}

.gtx-picker__emoji:hover {
    background: var(--gtx-surface-hover);
}

.gtx-picker__search {
    margin-bottom: var(--gtx-s2);
    flex: 0 0 auto;
}

.gtx-picker__gifs {
    overflow-y: auto;
    columns: 3;
    column-gap: var(--gtx-s2);
}

.gtx-picker__gif {
    width: 100%;
    margin-bottom: var(--gtx-s2);
    border-radius: var(--gtx-r-s);
    cursor: pointer;
    display: block;
    break-inside: avoid;
    border: 1px solid var(--gtx-line);
}

.gtx-picker__gif:hover {
    outline: 2px solid var(--gtx-accent);
}

.gtx-picker__msg {
    color: var(--gtx-text-dim);
    text-align: center;
    padding: var(--gtx-s4);
}

.gtx-picker__attr {
    flex: 0 0 auto;
    padding-top: var(--gtx-s1);
    color: var(--gtx-text-mute, var(--gtx-text-dim));
    font-size: 10px;
    text-align: right;
}

@media (max-width: 599px) {
    .gtx-picker__gifs {
        columns: 2;
    }
}

/* ===== TecXCord Wave C1: grouping, mentions, reactions, typing =============== */

/* The bubble is a positioning context for the hover "＋" react control. */
.gtx-msg {
    position: relative;
}

/* Discord-style grouping: a message from the same author within the window stacks
   tight under the previous one — pull it up over the log's row gap and soften its
   joined corner. The timestamp is hidden until the row is hovered (per-group time). */
.gtx-msg--grouped {
    margin-top: calc(-1 * var(--gtx-s2) + 2px);
}

.gtx-msg--grouped.gtx-msg--mine {
    border-top-right-radius: 4px;
}

.gtx-msg--grouped.gtx-msg--theirs {
    border-top-left-radius: 4px;
}

.gtx-msg--grouped .gtx-msg__meta {
    visibility: hidden;
}

.gtx-msg--grouped:hover .gtx-msg__meta {
    visibility: visible;
}

/* @mention token inside a message body. */
.gtx-mention {
    padding: 0 3px;
    border-radius: var(--gtx-r-s);
    font-weight: 600;
    color: var(--gtx-accent, #6ea8fe);
    background: var(--gtx-accent-soft);
}

.gtx-msg--mine .gtx-mention {
    color: inherit;
    background: rgba(255, 255, 255, 0.22);
}

/* --- Reaction bar --- */
.gtx-msg__reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.gtx-msg--mine .gtx-msg__reactions {
    justify-content: flex-end;
}

.gtx-reaction {
    margin-top: 5px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 1px 7px;
    border: 1px solid var(--gtx-line);
    border-radius: var(--gtx-r-full);
    background: var(--gtx-surface-2, var(--gtx-surface));
    color: var(--gtx-text);
    font-size: var(--gtx-fs-meta);
    line-height: 1.5;
    cursor: pointer;
    transition: border-color var(--gtx-t-fast) var(--gtx-ease), background-color var(--gtx-t-fast) var(--gtx-ease);
}

.gtx-reaction:hover {
    border-color: var(--gtx-accent);
}

.gtx-reaction.is-mine {
    border-color: var(--gtx-accent);
    background: var(--gtx-accent-soft);
}

.gtx-reaction__emoji {
    font-size: 0.95rem;
    line-height: 1;
}

.gtx-reaction__count {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

/* The hover "＋" add control — pinned to the bubble's top-right, revealed on hover. */
.gtx-react-add {
    position: absolute;
    top: -12px;
    right: 6px;
    opacity: 0;
    transition: opacity var(--gtx-t-fast) var(--gtx-ease);
}

.gtx-msg:hover .gtx-react-add,
.gtx-react-add:focus-within {
    opacity: 1;
}

.gtx-react-add__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border: 1px solid var(--gtx-line);
    border-radius: var(--gtx-r-full);
    background: var(--gtx-surface-2, var(--gtx-surface));
    color: var(--gtx-text-dim);
    font-size: 0.85rem;
    line-height: 1;
    cursor: pointer;
}

.gtx-react-add__btn:hover {
    color: var(--gtx-text);
    border-color: var(--gtx-accent);
}

.gtx-react-add__pop {
    position: absolute;
    right: 0;
    bottom: 28px;
    z-index: var(--gtx-z-dropdown);
    display: flex;
    gap: 2px;
    padding: 4px;
    background: var(--gtx-surface-2, var(--gtx-surface));
    border: 1px solid var(--gtx-line);
    border-radius: var(--gtx-r-m);
    box-shadow: var(--gtx-shadow-overlay);
}

.gtx-react-add__emoji {
    border: 0;
    background: transparent;
    font-size: 1.2rem;
    line-height: 1;
    padding: 3px;
    border-radius: var(--gtx-r-s);
    cursor: pointer;
}

.gtx-react-add__emoji:hover {
    background: var(--gtx-surface-hover);
}

/* --- Typing indicator (ephemeral) --- */
.gtx-chat__typing {
    flex: 0 0 auto;
    min-height: 1.15rem;
    padding: 0 var(--gtx-s4) 2px;
    background: var(--gtx-bg);
    color: var(--gtx-text-dim);
    font-size: var(--gtx-fs-meta);
    font-style: italic;
    opacity: 0;
    transition: opacity var(--gtx-t-fast) var(--gtx-ease);
}

.gtx-chat__typing.is-active {
    opacity: 1;
}

/* --- Mention autocomplete --- */
.gtx-mention-ac {
    position: absolute;
    left: var(--gtx-s3);
    bottom: 66px;
    z-index: var(--gtx-z-dropdown);
    min-width: 12rem;
    max-width: min(20rem, 80%);
    max-height: 14rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding: 4px;
    background: var(--gtx-surface-2, var(--gtx-surface));
    border: 1px solid var(--gtx-line);
    border-radius: var(--gtx-r-m);
    box-shadow: var(--gtx-shadow-overlay);
}

.gtx-mention-ac__item {
    display: flex;
    align-items: baseline;
    gap: var(--gtx-s2);
    padding: var(--gtx-s2);
    border: 0;
    border-radius: var(--gtx-r-s);
    background: transparent;
    color: var(--gtx-text);
    text-align: left;
    cursor: pointer;
}

.gtx-mention-ac__item.is-active,
.gtx-mention-ac__item:hover {
    background: var(--gtx-surface-hover);
}

.gtx-mention-ac__user {
    font-weight: 600;
    color: var(--gtx-accent, #6ea8fe);
}

.gtx-mention-ac__label {
    font-size: var(--gtx-fs-meta);
    color: var(--gtx-text-dim);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
