﻿.chat.hidden {
    display: none;
}

.chat {
    position: absolute;
    inset: 0;
    z-index: 120;
    background: #000;
    color: #fff;
    font-family: Arial, sans-serif;
    overflow: hidden;
}

.chat-wrap {
    width: 100%;
    height: 100%;
    display: flex;
    overflow: hidden;
}

/* left */
.chat-left {
    width: 20%;
    height: 100%;
    box-sizing: border-box;
    border-right: 1px solid rgba(255,255,255,.12);
    background: var(--btn_bg_s);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    font-size: 12px;
}

.chat-left-fixed {
    padding: 10px 5px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-left-divider {
    height: 1px;
    background: rgba(255,255,255,.10);
}

.chat-left-title {
    padding: 10px 10px 6px 10px;
    font-size: 12px;
    opacity: .75;
}

.chat-pm-list {
    flex: 1;
    height: 100%;
    overflow: hidden; /* 实际滚动交给 loop.js 设置 */
}

/* tabs/buttons */
.chat-tab-btn {
    width: 100%;
    height: 38px;
    border: 1px solid rgba(255,255,255,.18);
    background: rgba(255,255,255,.06);
    color: #fff;
    border-radius: 10px;
    text-align: center;
    padding: 0 0px;
    box-sizing: border-box;
}

    .chat-tab-btn.is-active {
        border-color: rgb(255 255 255 / 80%);
        background: rgb(255 255 255 / 25%);
    }

.chat-pm-btn {
    width: 100%;
    height: 40px;
    border: 1px solid rgba(255,255,255,.12);
    background: rgba(255,255,255,.04);
    color: #fff;
    border-radius: 10px;
    padding: 0 0px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

    .chat-pm-btn.is-active {
        border-color: rgba(255,255,255,.42);
        background: rgba(255,255,255,.14);
    }

.chat-pm-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-pm-badge {
    font-size: 11px;
    opacity: .65;
}

/* right */
.chat-right {
    width: 80%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--btn_bg_s);
}

.chat-topbar {
    flex: 0 0 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    box-sizing: border-box;
    border-bottom: 1px solid rgba(255,255,255,.12);
    background: linear-gradient(180deg, rgba(0,0,0,.65), rgba(0,0,0,0));
}

.chat-title {
    font-size: 14px;
    font-weight: 700;
}

.chat-close {
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 10px;
    background: rgba(255,255,255,.08);
    position: relative;
}

    .chat-close::before,
    .chat-close::after {
        content: "";
        position: absolute;
        left: 50%;
        top: 50%;
        width: 18px;
        height: 2px;
        background: rgba(255,255,255,.85);
        transform-origin: center;
    }

    .chat-close::before {
        transform: translate(-50%, -50%) rotate(45deg);
    }

    .chat-close::after {
        transform: translate(-50%, -50%) rotate(-45deg);
    }

.chat-mid {
    flex: 1;
    overflow: hidden; /* 实际滚动交给 chat-msg-list */
}

.chat-msg-list {
    height: 100%;
    overflow: hidden; /* loop.js 会设置 overflow-y */
}

    /* 覆盖 loop.js 固定比例，允许聊天条目自适应高度 */
    .chat-msg-list .loop-item-inner,
    .chat-pm-list .loop-item-inner {
        aspect-ratio: auto !important;
        display: block !important;
        align-items: stretch !important;
        justify-content: flex-start !important;
        padding: 0 !important;
    }

/* message item */
.chat-msg-row {
    width: 100%;
    display: flex;
    gap: 5px;
    align-items: flex-start;
}

    .chat-msg-row.is-me {
        flex-direction: row-reverse;
    }

.chat-msg-avatar {
    width: 46px;
    height: 46px;
    position: relative;
    flex: 0 0 46px;
}

.chat-msg-avatar-img {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 34px;
    height: 34px;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    object-fit: cover;
}

.chat-msg-avatar-frame {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 46px;
    height: 46px;
    transform: translate(-50%, -50%);
    pointer-events: none;
    object-fit: contain;
}

.chat-msg-main {
    min-width: 0;
    max-width: 78%;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-msg-head {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.chat-msg-name {
    font-size: 12px;
    font-weight: 700;
    opacity: .95;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-msg-title-icon {
    width: 18px;
    height: 18px;
    object-fit: contain;
    flex: 0 0 18px;
}

.chat-msg-bubble {
    padding: 0px 10px;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,.14);
    background: rgba(255,255,255,.06);
    word-break: break-word;
    white-space: pre-wrap;
    line-height: 1.2;
    font-size: 13px;
}

.chat-msg-row.is-me .chat-msg-bubble {
    background: rgba(80,160,255,.20);
    border-color: rgba(80,160,255,.30);
}

.chat-msg-text {
    font-size: 13px;
}

.chat-msg-meta {
    font-size: 11px;
    opacity: .65;
    margin-top: 4px;
}

/* bottom */
.chat-bottom {
    flex: 0 0 56px;
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 8px 10px;
    box-sizing: border-box;
    border-top: 1px solid rgba(255,255,255,.12);
    background: #00000021;
    overflow: hidden;
}

.chat-input {
    flex: 1;
    height: 40px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,.18);
    background: rgba(255,255,255,.06);
    color: #fff;
    padding: 0 10px;
    box-sizing: border-box;
    outline: none;
}

.chat-send {
    width: 76px;
    height: 40px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,.18);
    background: rgba(255,255,255,.10);
    color: #fff;
}

    .chat-send[disabled] {
        opacity: .5;
        pointer-events: none;
    }

/* 关键：flex 容器里允许子元素真正变成可滚动区域（否则容易滚动穿透/露黑边） */
.chat-left,
.chat-right,
.chat-mid {
    min-height: 0;
}

/* 左侧私聊列表：滚动只发生在列表容器内 */
.chat-pm-list {
    flex: 1;
    height: 100%;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    touch-action: pan-y;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

/* 右侧消息列表：滚动只发生在列表容器内（避免拖出 body 黑底） */
.chat-msg-list {
    height: 100%;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    touch-action: pan-y;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

/* 外层只负责裁剪，不参与滚动（防止底部/外层跟着动、露黑边） */
.chat,
.chat-wrap,
.chat-left,
.chat-right,
.chat-mid {
    overflow: hidden;
    overscroll-behavior: contain;
}

/* ===== chat bottom overrides: 输入框更短 + 发送按钮固定不被压缩 ===== */
.chat-bottom {
    gap: 10px;
}

.chat-input {
    flex: 1 1 auto;
    min-width: 0; /* 允许输入框被压缩，避免挤压发送按钮 */
}

.chat-send {
    flex: 0 0 68px; /* 固定宽度 */
    min-width: 68px;
    flex-shrink: 0; /* 禁止被压缩 */
    white-space: nowrap;
}
/* 私聊按钮：只显示 4 个字，不显示省略号 */
.chat-pm-name {
    overflow: visible;
    text-overflow: clip;
    white-space: nowrap;
}

/* 不再有右侧 badge 时，让内容居中更自然（如需左对齐可改为 flex-start） */
.chat-pm-btn {
    justify-content: center;
}

/* 让 head 和 bubble 都不要被 column flex 默认的 stretch 拉满宽度 */
.chat-msg-main {
    align-items: flex-start; /* 别人：左对齐 + 子项不拉伸 */
}

.chat-msg-row.is-me .chat-msg-main {
    align-items: flex-end; /* 自己：右对齐 + 子项不拉伸 */
}

/* 气泡宽度跟随文字内容（到达最大宽度后再换行） */
.chat-msg-bubble {
    display: inline-block;
    width: fit-content;
    max-width: 100%;
    min-width: 60px;
}