/* Internal chat (LAMS Messages).
   Colours come from the Bootstrap theme variables so the page follows
   the template's light / dark / monochrome modes without extra work. */

.chat-app {
    display: flex;
    height: calc(100vh - 230px);
    min-height: 520px;
    border: 1px solid var(--bs-border-color);
    border-radius: .5rem;
    background: var(--bs-body-bg);
    overflow: hidden;
}

/* ── Conversation list ─────────────────────────────────────────────── */

.chat-sidebar {
    width: 320px;
    flex: 0 0 320px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--bs-border-color);
    min-width: 0;
}

.chat-sidebar-head {
    padding: .75rem;
    border-bottom: 1px solid var(--bs-border-color);
}

.chat-list {
    flex: 1;
    overflow-y: auto;
}

.chat-list-item {
    display: flex;
    gap: .65rem;
    align-items: center;
    padding: .65rem .75rem;
    cursor: pointer;
    border-bottom: 1px solid var(--bs-border-color-translucent);
    border-left: 3px solid transparent;
}

.chat-list-item:hover {
    background: var(--bs-secondary-bg);
}

.chat-list-item.active {
    background: rgba(var(--bs-primary-rgb), .10);
    border-left-color: var(--bs-primary);
}

.chat-list-body {
    flex: 1;
    min-width: 0;
}

.chat-list-name {
    font-weight: 600;
    font-size: .86rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-list-preview {
    font-size: .78rem;
    color: var(--bs-secondary-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-list-side {
    text-align: right;
    flex: 0 0 auto;
}

.chat-list-time {
    font-size: .68rem;
    color: var(--bs-secondary-color);
    white-space: nowrap;
}

.chat-unread {
    display: inline-block;
    min-width: 18px;
    padding: 0 5px;
    margin-top: .25rem;
    border-radius: 9px;
    background: var(--bs-danger);
    color: #fff;
    font-size: .68rem;
    line-height: 18px;
    text-align: center;
}

/* ── Avatars ───────────────────────────────────────────────────────── */

.chat-avatar {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: .8rem;
    color: #fff;
    background: var(--bs-primary);
    user-select: none;
}

.chat-avatar.sm {
    width: 28px;
    height: 28px;
    flex-basis: 28px;
    font-size: .68rem;
}

/* Deterministic per-person tint so people are recognisable at a glance. */
.chat-avatar.t0 { background: #4361ee; }
.chat-avatar.t1 { background: #2a9d8f; }
.chat-avatar.t2 { background: #e76f51; }
.chat-avatar.t3 { background: #7209b7; }
.chat-avatar.t4 { background: #0891b2; }
.chat-avatar.t5 { background: #b5179e; }

/* ── Thread ────────────────────────────────────────────────────────── */

.chat-thread {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-thread-head {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .65rem .9rem;
    border-bottom: 1px solid var(--bs-border-color);
}

.chat-thread-name {
    font-weight: 600;
    font-size: .95rem;
    line-height: 1.1;
}

.chat-thread-sub {
    font-size: .72rem;
    color: var(--bs-secondary-color);
}

.chat-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.1rem;
    background: var(--bs-tertiary-bg);
}

.chat-day {
    text-align: center;
    margin: .9rem 0 .7rem;
}

.chat-day span {
    background: var(--bs-secondary-bg);
    color: var(--bs-secondary-color);
    padding: .15rem .65rem;
    border-radius: 1rem;
    font-size: .7rem;
}

.chat-row {
    display: flex;
    gap: .5rem;
    margin-bottom: .55rem;
    align-items: flex-end;
}

.chat-row.mine {
    flex-direction: row-reverse;
}

.chat-bubble {
    max-width: min(560px, 74%);
    padding: .45rem .7rem;
    border-radius: .85rem;
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.chat-row.mine .chat-bubble {
    background: var(--bs-primary);
    border-color: transparent;
    color: #fff;
}

.chat-sender {
    font-size: .7rem;
    font-weight: 600;
    color: var(--bs-secondary-color);
    margin-bottom: .1rem;
}

.chat-text {
    font-size: .86rem;
    white-space: pre-wrap;
}

.chat-meta {
    font-size: .66rem;
    opacity: .75;
    margin-top: .15rem;
    text-align: right;
}

.chat-deleted {
    font-style: italic;
    opacity: .7;
    font-size: .82rem;
}

/* ── Groups ───────────────────────────────────────────── */

.chat-group-icon {
    font-size: 15px !important;
    vertical-align: -2px;
    margin-right: .2rem;
    opacity: .7;
}

/* Group notices ("Ama added Kwame") sit between messages, not in a bubble. */
.chat-notice {
    text-align: center;
    margin: .6rem 0;
}

.chat-notice span {
    display: inline-block;
    max-width: 80%;
    padding: .2rem .7rem;
    border-radius: 1rem;
    background: var(--bs-secondary-bg);
    color: var(--bs-secondary-color);
    font-size: .72rem;
}


/* ── Mentions ──────────────────────────────────────── */

.chat-mention {
    font-weight: 600;
    color: var(--bs-primary);
}

/* Your own name stands out from other people's, so a tag is hard to scroll past. */
.chat-mention.me {
    background: rgba(var(--bs-warning-rgb), .22);
    border-radius: .25rem;
    padding: 0 .15rem;
}

.chat-row.mine .chat-mention {
    color: #fff;
    text-decoration: underline;
}

/* The "@" picker, floating just above the composer. */
.chat-mention-popup {
    max-height: 210px;
    overflow-y: auto;
    margin-bottom: .4rem;
    border: 1px solid var(--bs-border-color);
    border-radius: .5rem;
    background: var(--bs-body-bg);
    box-shadow: 0 -4px 14px rgba(0, 0, 0, .10);
}

.chat-mention-option {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .35rem .6rem;
    font-size: .82rem;
    cursor: pointer;
}

.chat-mention-option:hover,
.chat-mention-option.active {
    background: rgba(var(--bs-primary-rgb), .12);
}

/* ── Message actions ─────────────────────────────── */

/* Kept out of the way until the row is hovered, so bubbles stay clean. */
.chat-msg-delete {
    opacity: 0;
    transition: opacity .12s ease-in-out;
}

.chat-row:hover .chat-msg-delete,
.chat-msg-delete:focus-visible {
    opacity: .65;
}

.chat-msg-delete:hover {
    opacity: 1 !important;
}

/* Touch screens have no hover, so the control is simply always visible. */
@media (hover: none) {
    .chat-msg-delete {
        opacity: .55;
    }
}

/* ── Attachments ───────────────────────────────────────────────────── */

.chat-attach-img {
    display: block;
    margin-top: .35rem;
    max-width: 240px;
    max-height: 240px;
    border-radius: .5rem;
    cursor: pointer;
}

.chat-file {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-top: .35rem;
    padding: .4rem .55rem;
    border-radius: .45rem;
    background: rgba(var(--bs-emphasis-color-rgb), .07);
    color: inherit;
    text-decoration: none;
    font-size: .8rem;
}

.chat-file:hover {
    background: rgba(var(--bs-emphasis-color-rgb), .13);
    color: inherit;
}

.chat-row.mine .chat-file {
    background: rgba(255, 255, 255, .18);
    color: #fff;
}

.chat-row.mine .chat-file:hover {
    background: rgba(255, 255, 255, .28);
}

.chat-file-size {
    font-size: .7rem;
    opacity: .75;
}

/* ── Composer ──────────────────────────────────────────────────────── */

.chat-composer {
    border-top: 1px solid var(--bs-border-color);
    padding: .55rem .75rem;
}

.chat-composer-row {
    display: flex;
    align-items: center;
    gap: .35rem;
}

.chat-staged {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    margin-bottom: .45rem;
}

.chat-typing {
    font-size: .72rem;
    color: var(--bs-secondary-color);
    padding: 0 1.1rem .35rem;
    font-style: italic;
}

.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    color: var(--bs-secondary-color);
    padding: 2rem;
    text-align: center;
}

/* ── Topbar dropdown ───────────────────────────────────────────────── */

.chat-drop-item {
    display: flex;
    gap: .6rem;
    align-items: center;
    padding: .55rem .85rem;
    text-decoration: none;
    color: inherit;
}

.chat-drop-item:hover {
    background: var(--bs-secondary-bg);
    color: inherit;
}

/* ── Small screens ─────────────────────────────────────────────────── */

@media (max-width: 767.98px) {
    .chat-app {
        flex-direction: column;
        height: auto;
    }

    .chat-sidebar {
        width: 100%;
        flex: 0 0 auto;
        max-height: 260px;
        border-right: 0;
        border-bottom: 1px solid var(--bs-border-color);
    }

    .chat-thread {
        min-height: 60vh;
    }

    .chat-bubble {
        max-width: 88%;
    }
}
