/* ============================================
   聊天页面样式
   ============================================ */

/* 聊天页面容器（与 -chat.php 的 JS 设置对应）*/
#root {
    overflow: hidden;
    height: 100dvh;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    overflow: hidden;
    box-sizing: border-box;
}

body {
    overflow: hidden;
    height: 100dvh;
    margin: 0;
    padding: 0;
    background: #fff;
}

html, body {
    width: 100%;
    touch-action: manipulation;
    -webkit-overflow-scrolling: auto;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    background: #ffffff;
    border-bottom: 1px solid #f0f0f0;
    position: sticky;
    top: 0;
    z-index: 10;
}

.chat-title {
    font-size: 18px;
    font-weight: 600;
    color: #000;
    margin: 0;
}

.chat-header-right {
    color: #666;
    font-size: 20px;
}

/* 聊天列表容器：独立滚动 */
.chat-list-container {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: #ffffff;
    padding-bottom: 54px;
}

.chat-list {
    padding: 0;
}

/* 聊天列表项 */
.chat-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    transition: background-color 0.15s ease;
    border-bottom: 1px solid #f5f5f5;
}

.chat-item:active {
    background-color: #f8f8f8;
}

.chat-item-avatar {
    position: relative;
    margin-right: 12px;
    flex-shrink: 0;
}

.chat-item-avatar img {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    background: #f0f0f0;
}

.chat-badge-group {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 18px;
    height: 18px;
    background: #07c160;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #ffffff;
    font-size: 10px;
    color: #fff;
}

.chat-item-info {
    flex: 1;
    min-width: 0;
}

.chat-item-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

.chat-item-name {
    font-size: 16px;
    font-weight: 500;
    color: #1a1a1a;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-item-time {
    font-size: 12px;
    color: #999;
    flex-shrink: 0;
    margin-left: 8px;
}

.chat-item-unread {
    background: #ff4d4f;
    color: #fff;
    font-size: 11px;
    min-width: 18px;
    height: 18px;
    line-height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    text-align: center;
    font-weight: 500;
    display: inline-block;
}

.chat-item-bottom {
    display: flex;
    align-items: center;
}

.chat-item-message {
    font-size: 14px;
    color: #888;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 空状态 */
.chat-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    color: #999;
}

.chat-empty i {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

/* ============================================
   聊天详情页样式
   ============================================ */

/* 详情页头部 */
.chat-detail-header {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    background: #ffffff;
    border-bottom: 1px solid #f0f0f0;
    position: sticky;
    top: 0;
    z-index: 9999;
    gap: 8px;
}

/* 简化版顶部：透明背景，背景图顶到最顶部，返回+昵称+占位对称 */
.chat-detail-header-simple {
    background: #ffffff;
    border-bottom: 1px solid #f0f0f0;
    padding: 12px;
}

/* 详情页返回按钮 */
.chat-back-embedded {
    color: #333333 !important;
    background: transparent !important;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border: none !important;
    box-shadow: none;
    width: 36px !important;
    height: 36px !important;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chat-back-embedded i {
    color: #333 !important;
    font-size: 18px !important;
    font-weight: 400 !important;
    text-shadow: none;
}
.chat-back-embedded:active {
    background: #f0f0f0 !important;
}

/* 详情页标题区（头像 + 昵称 + 认证 + ID）*/
.chat-detail-title-area {
    flex: 1;
    display: flex;
    justify-content: center;
    min-width: 0;
    cursor: pointer;
}
.chat-detail-avatar-s {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}
.chat-detail-name-only {
    font-size: 16px;
    font-weight: 600;
    color: #333333;
    letter-spacing: 0.2px;
    text-align: center;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.3;
}
.chat-detail-userid {
    font-size: 11px;
    color: #999;
    margin-top: 2px;
    line-height: 1.2;
}
.chat-detail-verify {
    color: #4CAF50;
    font-size: 12px;
}

.chat-back {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #333;
    font-size: 18px;
    cursor: pointer;
    flex-shrink: 0;
    border-radius: 50%;
    transition: background-color 0.15s;
}

.chat-back:active {
    background: #f0f0f0;
}

.chat-detail-more {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #333;
    font-size: 18px;
    cursor: pointer;
    flex-shrink: 0;
    border-radius: 50%;
}
.chat-detail-more:active { background: #f0f0f0; }

/* 加密提示条 */
.chat-encrypt-tip {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    background: #f5f5f5;
    color: #999;
    font-size: 12px;
    border-bottom: 1px solid #eee;
}
.chat-encrypt-tip i { color: #4CAF50; }
.chat-encrypt-on {
    margin-left: auto;
    color: #666;
    font-size: 12px;
}

.chat-security-tip {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    background: #f8f8f8;
    color: #888;
    font-size: 12px;
    border-bottom: 1px solid #f0f0f0;
}
.chat-security-tip i { color: #07c160; }
.chat-security-status { color: #07c160; }

/* 消息区域 */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    background: transparent;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}

.chat-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: #999;
}
.chat-empty-icon {
    width: 80px; height: 80px;
    border-radius: 50%;
    background: #e8e8e8;
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 16px;
}
.chat-empty-icon i { font-size: 32px; color: #bbb; }
.chat-empty-text { font-size: 14px; color: #aaa; }

/* 消息气泡 */
.chat-message {
    display: flex;
    margin-bottom: 16px;
    align-items: flex-end;
}
.chat-message.own { flex-direction: row-reverse; }

.chat-message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}
.chat-message.own .chat-message-avatar { margin-left: 8px; }
.chat-message:not(.own) .chat-message-avatar { margin-right: 8px; }

/* 文本气泡：限制约10个中文字就换行 */
.chat-message-bubble {
    max-width: 180px;            /* 内容宽度≈10字*15px + 左右padding28px */
    width: fit-content;          /* 内容自适应，空内容不撑大 */
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 15px;
    line-height: 1.5;
    word-break: normal;         /* 中文正常断词，不拆单字 */
    overflow-wrap: anywhere;    /* 长单词/链接兜底断行 */
    white-space: pre-wrap;      /* 保留用户手动换行 */
}
.chat-message:not(.own) .chat-message-bubble {
    background: #ffffff;
    color: #1a1a1a;
    border-top-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.chat-message.own .chat-message-bubble {
    background: #95ec69;
    color: #1a1a1a;
    border-top-right-radius: 4px;
}

/* 消息内层wrapper：消息主体 + 昵称。文字消息保持紧凑，图片消息更宽避免裁切 */
.chat-msg-body {
    display: flex;
    flex-direction: column;
    max-width: 100%;
    min-width: 0;
}
.chat-msg-body.msg-text { max-width: 180px; }
.chat-msg-body.msg-image { max-width: 240px; } /* 保证图片200px+余量，不被裁切 */
.chat-msg-body.msg-video { max-width: 280px; }
.chat-message.own .chat-msg-body  { align-items: flex-end; }
.chat-message:not(.own) .chat-msg-body { align-items: flex-start; }

/* 视频气泡：覆盖默认气泡样式，去除绿色背景/边框 */
.chat-video-bubble {
    padding: 0 !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    max-width: 260px;
    overflow: hidden;
}
.chat-video-bubble video {
    max-width: 260px;
    max-height: 320px;
    display: block;
    border: none;
    border-radius: 10px;
    background: #000;
    outline: none;
    padding: 0;
    margin: 0;
}

/* 机器人/系统消息样式：type=system 或 sender_is_bot */
.chat-message.bot-message {
    align-items: flex-start;
}
.chat-message.bot-message .chat-message-avatar {
    border: 2px solid #6C5CE7;
    box-shadow: 0 0 0 2px rgba(108,92,231,0.1);
}
.chat-message.bot-message .chat-message-bubble {
    max-width: 220px;               /* 机器人消息稍宽，便于展示多行列 */
    background: linear-gradient(135deg, #f8f7ff 0%, #ffffff 100%);
    color: #1a1a1a;
    border: 1px solid #e7e3ff;
    border-top-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(108,92,231,0.06);
    font-size: 14px;
    white-space: pre-wrap;
    word-break: normal;
    overflow-wrap: anywhere;
}
/* 中奖高亮 */
.chat-message.bot-message .bubble-win {
    color: #d92b1c;
    font-weight: 600;
}
.chat-message.bot-message .bubble-lose {
    color: #888;
}

/* 骰子动画容器：高速翻转（体感GIF） */
.dice-anim-wrap {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 12px;
    padding: 12px 8px 8px;
    border-radius: 14px;
    background: linear-gradient(135deg, #fef9e7 0%, #fff 100%);
    border: 1px dashed #ffd591;
}
.dice-anim-die {
    font-size: 40px;
    line-height: 1;
    width: 52px;
    height: 52px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: #fff;
    box-shadow:
        inset 0 -2px 0 rgba(0,0,0,0.08),
        0 4px 10px rgba(0,0,0,0.12);
    transform: translateY(0) rotate(0deg);
    transition: transform .08s linear;
    will-change: transform;
}
/* 摇动中：轻微上下抖动 + 微旋转 */
.dice-anim-wrap:not(.dice-anim-done) .dice-anim-die {
    animation: dice-shake 0.4s infinite alternate ease-in-out;
}
@keyframes dice-shake {
    0%   { transform: translateY(-3px) rotate(-6deg); }
    50%  { transform: translateY(2px)  rotate(5deg);  }
    100% { transform: translateY(-2px) rotate(-4deg); }
}
/* 落定：骰子最终点数高亮 */
.dice-anim-die.dice-anim-lock {
    background: linear-gradient(145deg, #fff 0%, #fff6da 100%);
    border: 2px solid #f5c355;
    box-shadow:
        0 0 0 3px rgba(255, 220, 130, 0.25),
        0 6px 14px rgba(245, 195, 85, 0.25);
    transform: translateY(-1px) scale(1.08);
    transition: transform .18s ease-out;
}

/* 图片消息气泡：让图片完整显示不被裁切 */
.chat-image-bubble {
    max-width: 100% !important;
    width: auto !important;
    padding: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    border: none !important;
}

/* 消息时间戳 */
.chat-message-time {
    display: block;
    text-align: center;
    margin: 16px 0;
    font-size: 12px;
    color: #999;
}

/* 底部输入区域 */
.chat-input-bar {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    background: #f7f7f7;
    border-top: 1px solid #e0e0e0;
    gap: 8px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    flex-wrap: wrap;
}

.chat-input-voice {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #ffffff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    font-size: 16px;
    cursor: pointer;
    flex-shrink: 0;
}

.chat-input-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    background: #ffffff;
    border-radius: 8px;
    padding: 0 12px;
    gap: 4px;
    height: 40px;
    min-width: 0;
}

.chat-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 15px;
    background: transparent;
    min-width: 0;
}

.chat-input-actions {
    display: flex;
    align-items: center;
    gap: 0;
    flex-shrink: 0;
}

.chat-input-send {
    display: none;
    flex-shrink: 0;
    background: #07c160;
    color: #ffffff;
    border: none;
    border-radius: 6px;
    padding: 0 14px;
    height: 30px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.15s;
}
.chat-input-send:active { background: #06ad56; }

.chat-input-emoji,
.chat-input-image,
.chat-input-more {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    font-size: 18px;
    cursor: pointer;
    flex-shrink: 0;
    border-radius: 50%;
    transition: background-color 0.15s;
}
.chat-input-emoji:hover,
.chat-input-image:hover,
.chat-input-more:hover {
    background: #f0f0f0;
}

/* 表情面板 */
.chat-emoji-panel {
    width: 100%;
    background: #ffffff;
    border-top: 1px solid #e8e8e8;
    padding: 12px;
    box-sizing: border-box;
}
.chat-emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
}
.chat-emoji-item {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 40px;
    font-size: 24px;
    cursor: pointer;
    border-radius: 6px;
    transition: background-color 0.15s;
    user-select: none;
}
.chat-emoji-item:active { background: #f0f0f0; }

/* 更多功能面板 */
.chat-more-panel {
    width: 100%;
    background: #ffffff;
    border-top: 1px solid #e8e8e8;
    padding: 16px 12px;
    box-sizing: border-box;
}
.chat-more-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px 8px;
}
.chat-more-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 8px 4px;
    border-radius: 8px;
    transition: background-color 0.15s;
}
.chat-more-item:active { background: #f5f5f5; }
.chat-more-icon {
    width: 52px; height: 52px;
    border-radius: 12px;
    background: #f5f5f5;
    display: flex; align-items: center; justify-content: center;
    color: #333; font-size: 22px;
}
.chat-more-item span { font-size: 12px; color: #666; }

/* 图片消息气泡 */
.chat-image-bubble { padding: 4px !important; }

/* 桌面端（与其他页面一致，居中 768px 宽度，禁止横向滚动）*/
@media (min-width: 768px) {
    #root {
        max-width: 768px;
        margin: 0 auto;
        height: 100vh;
        overflow: hidden;
        box-shadow: 0 0 40px rgba(0,0,0,0.04);
        border-left: 1px solid #f0f0f0;
        border-right: 1px solid #f0f0f0;
    }
    #app { height: 100vh; }
    body { height: 100vh; }
    .chat-detail-page #root,
    .chat-detail-page body { height: 100vh !important; }
}

/* 响应式（小屏） */
@media (max-width: 480px) {
    .chat-item-avatar img { width: 44px; height: 44px; }
    .chat-item-name { font-size: 15px; }
    .chat-item-message { font-size: 13px; }
    .chat-item-time { font-size: 11px; }
    .chat-detail-header { padding: 8px 10px; }
    .chat-detail-name-only { font-size: 15px; }
}

