/* ============================
   访客端聊天界面样式 - 自适应PC/移动
   ============================ */

/* --- 基础重置 --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif; font-size: 15px; color: #333; background: #f0f2f5; -webkit-tap-highlight-color: transparent; }

/* --- 聊天容器 --- */
.chat-container {
    display: flex; flex-direction: column;
    height: 100%; max-width: 800px; margin: 0 auto;
    background: #fff;
    box-shadow: 0 0 30px rgba(0,0,0,0.08);
}

/* --- 顶部标题栏 --- */
.chat-header {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px;
    background: linear-gradient(135deg, #1a73e8, #1557b0);
    color: #fff;
    flex-shrink: 0;
    min-height: 56px;
}
.chat-header-icon {
    width: 40px; height: 40px; border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-name { font-size: 17px; font-weight: 600; }
.chat-header-status { font-size: 12px; opacity: 0.85; margin-top: 2px; }

/* --- 消息列表区 --- */
.chat-messages {
    flex: 1; overflow-y: auto;
    padding: 16px;
    display: flex; flex-direction: column; gap: 12px;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    background: #f7f8fa;
}
.chat-loading {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 40px 0; color: #999; font-size: 13px;
}
.loading-dots { display: flex; gap: 5px; margin-bottom: 8px; }
.loading-dots span {
    width: 8px; height: 8px; border-radius: 50%; background: #ccc;
    animation: dotBounce 1.4s infinite ease-in-out both;
}
.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }
.loading-dots span:nth-child(3) { animation-delay: 0s; }
@keyframes dotBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* --- 消息气泡通用 --- */
.msg-wrapper {
    display: flex; gap: 8px; max-width: 85%;
    animation: msgIn 0.25s ease-out;
}
@keyframes msgIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* 访客消息（右侧） */
.msg-visitor { align-self: flex-end; flex-direction: row-reverse; }
.msg-visitor .msg-bubble {
    background: linear-gradient(135deg, #1a73e8, #1557b0);
    color: #fff;
    border-radius: 16px 4px 16px 16px;
}
.msg-visitor .msg-time { text-align: right; }

/* 管理员消息（左侧） */
.msg-admin { align-self: flex-start; }
.msg-admin .msg-bubble {
    background: #fff;
    color: #333;
    border-radius: 4px 16px 16px 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    border: 1px solid #e8eaed;
}
.msg-admin .msg-time { text-align: left; }

/* 消息气泡 */
.msg-bubble {
    padding: 10px 14px;
    font-size: 15px; line-height: 1.6;
    word-break: break-word;
    overflow-wrap: break-word;
    position: relative;
}

/* 消息时间 */
.msg-time {
    font-size: 11px; color: #999;
    margin-top: 4px; padding: 0 4px;
}

/* 系统消息（居中） */
.msg-system {
    align-self: center; max-width: 90%; text-align: center;
}
.msg-system .msg-bubble {
    background: transparent; color: #999;
    font-size: 12px; padding: 4px 12px;
    border-radius: 8px;
}

/* --- 图片消息 --- */
.msg-image { max-width: 240px; border-radius: 12px; cursor: pointer; display: block; }
.msg-visitor .msg-image { border-radius: 12px 4px 12px 12px; }
.msg-admin .msg-image { border-radius: 4px 12px 12px 12px; }

/* --- 视频消息 --- */
.msg-video-wrap { position: relative; }
.msg-video { max-width: 260px; border-radius: 12px; cursor: pointer; display: block; }
.msg-video-play {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%,-50%);
    width: 48px; height: 48px; border-radius: 50%;
    background: rgba(0,0,0,0.5); color: #fff;
    display: flex; align-items: center; justify-content: center;
    pointer-events: none;
}

/* --- 底部输入区 --- */
.chat-input-area {
    flex-shrink: 0; position: relative;
    background: #fff; border-top: 1px solid #e8eaed;
}
.chat-toolbar {
    display: flex; align-items: center; gap: 2px;
    padding: 6px 12px 0;
}
.tool-btn {
    width: 36px; height: 36px; border: none; background: none;
    cursor: pointer; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.2s;
}
.tool-btn:hover { background: #f0f2f5; }
.chat-input-row {
    display: flex; align-items: flex-end; gap: 8px;
    padding: 8px 12px;
}
.chat-input {
    flex: 1; border: 1px solid #e0e0e0; border-radius: 20px;
    padding: 10px 16px; font-size: 15px; outline: none;
    resize: none; max-height: 120px; line-height: 1.4;
    font-family: inherit; background: #f7f8fa;
    transition: border-color 0.2s;
}
.chat-input:focus { border-color: #1a73e8; background: #fff; }
.chat-send {
    width: 42px; height: 42px; border: none; border-radius: 50%;
    background: #1a73e8; color: #fff; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; transition: background 0.2s, transform 0.15s;
}
.chat-send:hover { background: #1557b0; }
.chat-send:active { transform: scale(0.92); }

/* --- 表情面板 --- */
.emoji-panel {
    position: absolute; bottom: 100%; left: 12px;
    width: 320px; max-width: calc(100vw - 24px);
    max-height: 260px; overflow-y: auto;
    background: #fff; border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    z-index: 100;
}
.emoji-item {
    width: 100%; aspect-ratio: 1;
    border: none; background: none;
    font-size: 22px; cursor: pointer;
    border-radius: 6px; display: flex;
    align-items: center; justify-content: center;
    transition: background 0.15s;
}
.emoji-item:hover { background: #f0f2f5; }

/* --- 图片预览遮罩 --- */
.image-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.9); z-index: 9999;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
}
.image-overlay img {
    max-width: 90vw; max-height: 90vh;
    border-radius: 8px; object-fit: contain;
}

/* ===== 移动端适配 ===== */
@media (max-width: 768px) {
    .chat-container {
        max-width: 100%; height: 100vh;
        box-shadow: none; border-radius: 0;
    }
    .chat-header { padding: 10px 12px; min-height: 50px; }
    .chat-header-icon { width: 34px; height: 34px; }
    .chat-header-name { font-size: 15px; }
    .chat-messages { padding: 12px 10px; gap: 10px; }
    .msg-wrapper { max-width: 90%; }
    .msg-bubble { font-size: 15px; padding: 8px 12px; }
    .msg-image { max-width: 180px; }
    .msg-video { max-width: 200px; }
    .chat-input-row { padding: 6px 8px; }
    .chat-input { padding: 8px 12px; font-size: 14px; }
    .emoji-panel {
        width: calc(100vw - 16px); left: 8px;
        grid-template-columns: repeat(8, 1fr);
    }
}

@media (max-width: 480px) {
    .chat-messages { padding: 8px 6px; gap: 8px; }
    .msg-wrapper { max-width: 92%; }
    .msg-bubble { font-size: 14px; padding: 7px 10px; border-radius: 14px 4px 14px 14px; }
    .msg-admin .msg-bubble { border-radius: 4px 14px 14px 14px; }
    .msg-image { max-width: 150px; border-radius: 10px; }
    .msg-video { max-width: 170px; }
    .tool-btn { width: 32px; height: 32px; }
    .chat-send { width: 38px; height: 38px; }
    .emoji-panel { grid-template-columns: repeat(7, 1fr); max-height: 220px; }
}
