/* ==========================================================================
   聊天室样式（2026-11-17 重做）
   —— 群聊大厅形态：桌面右下浮窗（可展开全屏）/ 移动端全屏 sheet / /chat 独立页
   —— 结构见 Views/Shared/_ChatRoom.cshtml，JS 见 base.chat.js + base.js
   —— 注意：独立 .css 不经 Razor 编译，@keyframes / @media 只能写单 @
   ========================================================================== */

/* ---------- 容器 ---------- */
.chat-container {
    position: fixed;
    /* 2026-11-17: 24 → 56。右下工具栏（.wrap-right，right:5 宽 28）原来被浮窗整个压住，
       往左让一个身位后工具栏仍可点。 */
    right: 56px;
    bottom: 24px;
    width: 384px;
    height: min(560px, calc(100vh - 48px));
    /* 需高于 #header(998) 与右下工具栏(1050)，否则首屏点不动 */
    z-index: 1200;
    opacity: 0;
    pointer-events: none;
    transform: translateY(14px) scale(0.98);
    transform-origin: bottom right;
    transition: opacity 0.22s ease,
                transform 0.22s cubic-bezier(0.4, 0, 0.2, 1),
                width 0.28s cubic-bezier(0.4, 0, 0.2, 1),
                height 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-container.chat-active {
    opacity: 1;
    pointer-events: auto;
    transform: none;
}

/* 桌面展开：宽高一起放大，仍贴着右下角（展开时回到 24，避免右侧留一条空带） */
.chat-container.chat-expanded {
    right: 24px;
    width: min(960px, calc(100vw - 48px));
    height: calc(100vh - 48px);
}

/* /chat 独立页：直接全屏、常显，不依赖 .chat-active */
.chat-container[data-chat-mode="page"] {
    inset: 0;
    width: 100%;
    height: 100dvh;
    max-height: none;
    opacity: 1;
    pointer-events: auto;
    transform: none;
    transition: none;
}

/* ---------- 面板 ---------- */
.chat-panel {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #ffffff;
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 18px;
    box-shadow: 0 24px 64px rgba(15, 23, 42, 0.18), 0 2px 8px rgba(15, 23, 42, 0.06);
}

.chat-container[data-chat-mode="page"] .chat-panel {
    border: none;
    border-radius: 0;
    box-shadow: none;
}

/* ---------- 头部 ---------- */
.chat-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    height: 58px;
    padding: 0 12px 0 16px;
    border-bottom: 1px solid #eef2f7;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(12px);
}

.chat-header-main {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.chat-header-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 11px;
    background: linear-gradient(135deg, #165dff 0%, #3b82f6 60%, #22d3ee 100%);
    color: #ffffff;
    font-size: 15px;
    flex-shrink: 0;
}

.chat-header-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.25;
}

.chat-title {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: #0f172a;
    letter-spacing: 0.2px;
}

.chat-subtitle {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 0;
    border: none;
    background: none;
    font-size: 12px;
    color: #64748b;
    cursor: pointer;
    font-family: inherit;
    line-height: 1.4;
}

.chat-subtitle:hover { color: #165dff; }

.chat-online-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15);
    flex-shrink: 0;
}

.chat-online-count { font-weight: 600; color: #0f172a; }

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

.chat-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    border-radius: 9px;
    background: transparent;
    color: #64748b;
    font-size: 13px;
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.16s, color 0.16s;
}

.chat-icon-btn:hover { background: #f1f5f9; color: #0f172a; }

/* ---------- 在线成员浮层 ---------- */
.chat-members {
    position: absolute;
    top: 58px;
    left: 0;
    right: 0;
    z-index: 6;
    max-height: 52%;
    overflow-y: auto;
    padding: 8px 10px 10px;
    background: rgba(255, 255, 255, 0.98);
    border-bottom: 1px solid #eef2f7;
    box-shadow: 0 16px 28px rgba(15, 23, 42, 0.08);
}

.chat-members-head {
    padding: 4px 6px 8px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #94a3b8;
}

.chat-contacts-list { display: flex; flex-direction: column; gap: 2px; }

.chat-contact-item {
    display: flex;
    align-items: center;
    padding: 6px;
    border-radius: 9px;
    cursor: default;
    transition: background-color 0.15s;
}

.chat-contact-item:hover { background: #f8fafc; }

.chat-contact-content {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
}

.chat-contact-avatar {
    position: relative;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: #e2e8f0;
}

.chat-avatar-img { width: 100%; height: 100%; object-fit: cover; display: block; }

.chat-contact-info { min-width: 0; }

.chat-contact-name {
    margin: 0;
    font-size: 13px;
    font-weight: 500;
    color: #334155;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-members-empty {
    padding: 10px 6px;
    font-size: 13px;
    color: #94a3b8;
}

/* ---------- 消息区 ---------- */
.chat-messages-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px 16px 8px;
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    overscroll-behavior: contain;
}

.chat-scrollbar-hide { -ms-overflow-style: none; scrollbar-width: none; }
.chat-scrollbar-hide::-webkit-scrollbar { display: none; }

.chat-content-auto { content-visibility: auto; }

.chat-date-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 6px 0 16px;
}

.chat-date-label {
    padding: 3px 10px;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.16);
    font-size: 11px;
    color: #64748b;
}

/* 系统消息（加入/离开）：居中的浅色小字，不和聊天气泡混在一起 */
.chat-system-line {
    display: flex;
    justify-content: center;
    margin: 10px 0 14px;
}

.chat-system-line > span {
    padding: 3px 10px;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.14);
    font-size: 11px;
    line-height: 1.6;
    color: #94a3b8;
    text-align: center;
}

/* 消息区空态 */
.chat-empty {
    padding: 36px 16px 0;
    text-align: center;
    font-size: 12px;
    color: #a3adba;
    user-select: none;
}

.chat-message {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    margin-bottom: 14px;
}

.chat-sent { flex-direction: row-reverse; }

.chat-message-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: #e2e8f0;
}

.chat-message-content {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    max-width: calc(100% - 46px);
    min-width: 0;
}

.chat-sent .chat-message-content { align-items: flex-end; }

.chat-message-username {
    margin-bottom: 4px;
    font-size: 11px;
    color: #94a3b8;
}

.chat-message-bubble {
    max-width: 100%;
    padding: 8px 12px;
    border-radius: 4px 14px 14px 14px;
    background: #ffffff;
    border: 1px solid #eef2f7;
    font-size: 14px;
    line-height: 1.55;
    color: #1e293b;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.chat-message-bubble p { margin: 0; }
.chat-message-bubble p + p { margin-top: 6px; }

.chat-sent .chat-message-bubble {
    border-radius: 14px 4px 14px 14px;
    border-color: transparent;
    background: linear-gradient(135deg, #165dff 0%, #3b82f6 100%);
    color: #ffffff;
}

.chat-message-time {
    margin-top: 4px;
    font-size: 11px;
    color: #a3adba;
}

.chat-message-appear { animation: fadeIn 0.3s ease forwards; }

/* 媒体消息 */
.chat-media-image,
.chat-media-video { max-width: 240px; }

.chat-msg-image,
.chat-msg-video {
    display: block;
    max-width: 100%;
    border-radius: 10px;
    cursor: pointer;
    background: #e2e8f0;
}

.chat-msg-video { cursor: default; }

.chat-media-caption {
    margin: 6px 0 0;
    font-size: 13px;
    color: inherit;
}

.chat-media-file {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    min-width: 180px;
    border-radius: 10px;
    background: rgba(241, 245, 249, 0.9);
    cursor: pointer;
}

.chat-sent .chat-media-file { background: rgba(255, 255, 255, 0.18); }

.chat-file-icon { color: #165dff; flex-shrink: 0; display: flex; }
.chat-sent .chat-file-icon { color: #ffffff; }

.chat-file-info { min-width: 0; }

.chat-file-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 190px;
}

.chat-file-size { font-size: 11px; opacity: 0.7; margin-top: 2px; }

/* ---------- 输入区 ---------- */
.chat-input-area {
    flex-shrink: 0;
    padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
    border-top: 1px solid #eef2f7;
    background: #ffffff;
}

.chat-input-tools {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-bottom: 6px;
}

.chat-tool-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #64748b;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.16s, color 0.16s;
}

.chat-tool-btn:hover { background: #f1f5f9; color: #165dff; }

.chat-message-input-container {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 46px;
    padding: 0 6px 0 12px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #f8fafc;
    transition: border-color 0.16s, box-shadow 0.16s, background-color 0.16s;
}

.chat-message-input-container:focus-within {
    border-color: #165dff;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(22, 93, 255, 0.12);
}

.chat-message-input {
    flex: 1;
    min-width: 0;
    height: 100%;
    border: none;
    outline: none;
    background: transparent;
    font-size: 16px;              /* 16px 起，避免 iOS 聚焦时自动放大页面 */
    color: #0f172a;
    font-family: inherit;
}

.chat-message-input::placeholder { color: #9aa4b2; }

.chat-send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, #165dff 0%, #3b82f6 100%);
    color: #ffffff;
    font-size: 13px;
    cursor: pointer;
    flex-shrink: 0;
    box-shadow: 0 6px 14px rgba(22, 93, 255, 0.28);
    transition: transform 0.16s, box-shadow 0.16s, opacity 0.16s;
}

.chat-send-btn:hover { transform: translateY(-1px); box-shadow: 0 8px 18px rgba(22, 93, 255, 0.34); }
.chat-send-btn:active { transform: translateY(1px); opacity: 0.85; }

/* 附件预览 */
.chat-attachment-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    padding: 8px 10px;
    border-radius: 10px;
    background: #f8fafc;
    border: 1px dashed #cbd5e1;
}

.chat-attachment-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    padding-right: 18px;
    font-size: 12px;
    color: #475569;
    max-width: 100%;
}

.chat-attachment-thumb {
    width: 34px;
    height: 34px;
    border-radius: 6px;
    object-fit: cover;
    background: #e2e8f0;
}

.chat-attachment-file-icon { font-size: 16px; }

.chat-attachment-name {
    max-width: 160px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-attachment-size { color: #94a3b8; }

.chat-attachment-remove {
    position: absolute;
    top: -6px;
    right: 0;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #94a3b8;
    color: #ffffff;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
}

/* 表情面板 */
.chat-emoji-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    max-height: 148px;
    overflow-y: auto;
    margin-bottom: 8px;
    padding: 8px;
    border: 1px solid #eef2f7;
    border-radius: 12px;
    background: #ffffff;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.1);
}

.chat-emoji-item {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    font-size: 18px;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.12s, transform 0.12s;
}

.chat-emoji-item:hover { background: #f1f5f9; transform: scale(1.08); }

/* ---------- 动画 ---------- */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-3px); opacity: 1; }
}

/* ---------- 深色模式 ---------- */
[color-scheme=dark] .chat-panel { background: #111a2b; border-color: rgba(148, 163, 184, 0.16); }
[color-scheme=dark] .chat-header { background: rgba(17, 26, 43, 0.92); border-bottom-color: rgba(148, 163, 184, 0.14); }
[color-scheme=dark] .chat-title { color: #e2e8f0; }
[color-scheme=dark] .chat-subtitle { color: #94a3b8; }
[color-scheme=dark] .chat-online-count { color: #e2e8f0; }
[color-scheme=dark] .chat-icon-btn { color: #94a3b8; }
[color-scheme=dark] .chat-icon-btn:hover { background: rgba(148, 163, 184, 0.14); color: #e2e8f0; }
[color-scheme=dark] .chat-members { background: rgba(17, 26, 43, 0.98); border-bottom-color: rgba(148, 163, 184, 0.14); }
[color-scheme=dark] .chat-contact-item:hover { background: rgba(148, 163, 184, 0.1); }
[color-scheme=dark] .chat-contact-name { color: #cbd5e1; }
[color-scheme=dark] .chat-messages-container { background: linear-gradient(180deg, #0d1626 0%, #111a2b 100%); }
[color-scheme=dark] .chat-date-label { background: rgba(148, 163, 184, 0.16); color: #94a3b8; }
[color-scheme=dark] .chat-message-bubble { background: #1b2942; border-color: rgba(148, 163, 184, 0.14); color: #dbe4f0; }
[color-scheme=dark] .chat-sent .chat-message-bubble { background: linear-gradient(135deg, #1d4ed8 0%, #2563eb 100%); color: #ffffff; }
[color-scheme=dark] .chat-media-file { background: rgba(148, 163, 184, 0.12); }
[color-scheme=dark] .chat-input-area { background: #111a2b; border-top-color: rgba(148, 163, 184, 0.14); }
[color-scheme=dark] .chat-tool-btn { color: #94a3b8; }
[color-scheme=dark] .chat-tool-btn:hover { background: rgba(148, 163, 184, 0.14); color: #93c5fd; }
[color-scheme=dark] .chat-message-input-container { background: #0d1626; border-color: rgba(148, 163, 184, 0.18); }
[color-scheme=dark] .chat-message-input { color: #e2e8f0; }
[color-scheme=dark] .chat-attachment-preview { background: #0d1626; border-color: rgba(148, 163, 184, 0.24); }
[color-scheme=dark] .chat-emoji-panel { background: #1b2942; border-color: rgba(148, 163, 184, 0.14); }
[color-scheme=dark] .chat-emoji-item:hover { background: rgba(148, 163, 184, 0.16); }
[color-scheme=dark] .chat-system-line > span { background: rgba(148, 163, 184, 0.14); color: #8e9aab; }
[color-scheme=dark] .chat-empty { color: #6f7b8b; }

/* ---------- 移动端：全屏 sheet ---------- */
@media (max-width: 768px) {
    .chat-container {
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100dvh;
        max-height: none;
        transform: translateY(100%);
        transform-origin: bottom center;
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
    }

    .chat-container.chat-active { transform: translateY(0); }

    /* 移动端不需要展开按钮，展开态等同全屏 */
    .chat-container.chat-expanded { right: 0; bottom: 0; width: 100%; height: 100dvh; }

    .chat-panel {
        border: none;
        border-radius: 0;
        box-shadow: none;
    }

    .chat-header { height: 54px; padding-left: 14px; }

    .chat-messages-container { padding: 14px 14px 6px; }

    .chat-input-area { padding-left: 10px; padding-right: 10px; }

    .chat-send-btn { width: 32px; height: 32px; }

    .chat-message-bubble { font-size: 15px; }
}

/* /chat 页与展开态在桌面端：内容居中收窄，长行不跨满屏 */
@media (min-width: 769px) {
    .chat-container[data-chat-mode="page"] .chat-header { height: 62px; padding-left: 24px; }
    .chat-container[data-chat-mode="page"] .chat-messages-container { padding: 20px max(24px, calc(50% - 460px)); }
    .chat-container[data-chat-mode="page"] .chat-input-area { padding-left: max(24px, calc(50% - 460px)); padding-right: max(24px, calc(50% - 460px)); }

    /* 展开到 960 宽后消息区会拉成一条长行，收窄到约 720px 的阅读列 */
    .chat-container.chat-expanded .chat-messages-container { padding-left: max(20px, calc(50% - 360px)); padding-right: max(20px, calc(50% - 360px)); }
    .chat-container.chat-expanded .chat-input-area { padding-left: max(20px, calc(50% - 360px)); padding-right: max(20px, calc(50% - 360px)); }
}
