/* ===== chat.css — 商城内置聊天系统样式 ===== */
/* 命名空间：#chat-app，避免与商城样式冲突 */

#chat-app * { box-sizing: border-box; margin: 0; padding: 0; }

#chat-app {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    height: 100dvh;
    width: 100vw;
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
    font-size: 14px;
    color: #333;
    background: #f5f5f5;
    overflow: hidden;
    overscroll-behavior: none;
}
#chat-app .emoji-icon {
    display: inline-block;
    font-style: normal;
    line-height: 1;
    vertical-align: middle;
}

/* ===== 页面容器 ===== */
#chat-app .chat-page {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #f5f5f5;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    z-index: 1;
}
#chat-app .chat-page.hidden-left { transform: translateX(-30%); opacity: 0; pointer-events: none; }
#chat-app .chat-page.hidden-right { transform: translateX(100%); pointer-events: none; }
#chat-app .chat-page.active { transform: translateX(0); z-index: 10; }

/* ===== 顶部导航栏 ===== */
#chat-app .chat-header {
    flex-shrink: 0;
    height: 48px;
    background: #fff;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    padding: 0 12px;
    position: relative;
    z-index: 100;
}
#chat-app .chat-header .header-title {
    flex: 1;
    text-align: center;
    font-size: 17px;
    font-weight: 600;
    color: #333;
}
#chat-app .chat-header .header-btn {
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    color: #333;
    font-size: 18px;
    cursor: pointer;
    border: none;
    background: none;
}
#chat-app .chat-header .header-btn:active { opacity: 0.6; }

/* ===== 底部Tab栏 ===== */
#chat-app .chat-tabbar {
    flex-shrink: 0;
    height: 56px;
    background: #fff;
    border-top: 1px solid #eee;
    display: flex;
    padding-bottom: env(safe-area-inset-bottom);
}
#chat-app .chat-tabbar .tab-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #999;
    font-size: 11px;
    cursor: pointer;
    gap: 2px;
}
#chat-app .chat-tabbar .tab-item .tab-text { font-size: 15px; font-weight: 500; }
#chat-app .chat-tabbar .tab-item.active { color: #ff4d4f; }
#chat-app .chat-tabbar .tab-item .tab-badge {
    position: absolute;
    top: 4px;
    margin-left: 14px;
    min-width: 16px;
    height: 16px;
    line-height: 16px;
    padding: 0 4px;
    background: #ff4d4f;
    color: #fff;
    font-size: 10px;
    border-radius: 8px;
    text-align: center;
}

/* ===== 会话列表 ===== */
#chat-app .chat-conversation-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: #fff;
}
#chat-app .conversation-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    position: relative;
}
#chat-app .conversation-item:active { background: #f9f9f9; }
#chat-app .conversation-avatar {
    width: 48px; height: 48px;
    border-radius: 50%;
    background: #e8e8e8;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-size: 18px;
    font-weight: 600;
    position: relative;
    overflow: hidden;
}
#chat-app .conversation-avatar img { width: 100%; height: 100%; object-fit: cover; }
#chat-app .conversation-avatar .online-dot {
    position: absolute;
    bottom: 0; right: 0;
    width: 12px; height: 12px;
    background: #52c41a;
    border: 2px solid #fff;
    border-radius: 50%;
}
#chat-app .conversation-avatar .online-dot.offline { background: #bfbfbf; }
#chat-app .conversation-info {
    flex: 1;
    margin-left: 12px;
    min-width: 0;
}
#chat-app .conversation-info .row-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}
#chat-app .conversation-name {
    font-size: 16px;
    font-weight: 500;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}
#chat-app .conversation-id {
    font-size: 12px;
    font-weight: 400;
    color: #999;
    margin-left: 6px;
}
#chat-app .conversation-time {
    font-size: 12px;
    color: #999;
    flex-shrink: 0;
}
#chat-app .conversation-preview {
    font-size: 13px;
    color: #999;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#chat-app .conversation-unread {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    min-width: 20px;
    height: 20px;
    line-height: 20px;
    padding: 0 6px;
    background: #ff4d4f;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    border-radius: 10px;
    text-align: center;
}
#chat-app .conversation-unread.dot {
    min-width: 10px;
    width: 10px;
    height: 10px;
    padding: 0;
    border-radius: 50%;
    line-height: 0;
    top: 16px;
    transform: none;
}

/* ===== 空状态 ===== */
#chat-app .empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #999;
    padding: 60px 20px;
}
#chat-app .empty-state .empty-icon { font-size: 56px; margin-bottom: 16px; opacity: 0.6; }
#chat-app .empty-state p { font-size: 14px; margin-bottom: 20px; }
#chat-app .empty-state .btn {
    padding: 8px 24px;
    background: #ff4d4f;
    color: #fff;
    border: none;
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
}

/* ===== 聊天窗口 ===== */
#chat-app .chat-window {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #f5f5f5;
    overflow: hidden;
}
#chat-app .chat-messages {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px 12px 8px;
}
#chat-app .chat-messages::-webkit-scrollbar { width: 0; }

/* 时间分隔 */
#chat-app .msg-time-divider {
    text-align: center;
    margin: 12px 0;
}
#chat-app .msg-time-divider span {
    display: inline-block;
    padding: 2px 10px;
    background: #e0e0e0;
    color: #fff;
    font-size: 11px;
    border-radius: 10px;
}

/* 消息气泡 */
#chat-app .msg-row {
    display: flex;
    margin-bottom: 10px;
    align-items: flex-end;
}
#chat-app .msg-row.self { justify-content: flex-end; }
#chat-app .msg-row.other { justify-content: flex-start; }

#chat-app .msg-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: #e8e8e8;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    overflow: hidden;
}
#chat-app .msg-row.self .msg-avatar { margin-left: 8px; order: 2; }
#chat-app .msg-row.other .msg-avatar { margin-right: 8px; order: 1; }
#chat-app .msg-avatar img { width: 100%; height: 100%; object-fit: cover; }

#chat-app .msg-bubble {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: 18px;
    word-wrap: break-word;
    word-break: break-all;
    line-height: 1.5;
    font-size: 15px;
    position: relative;
}
#chat-app .msg-row.self .msg-bubble {
    background: #ff4d4f;
    color: #fff;
    border-bottom-right-radius: 4px;
    order: 1;
}
#chat-app .msg-row.other .msg-bubble {
    background: #fff;
    color: #333;
    border-bottom-left-radius: 4px;
    order: 2;
}

/* 图片消息 */
#chat-app .msg-bubble.msg-image {
    padding: 0;
    background: transparent;
    border-radius: 12px;
    overflow: hidden;
}
#chat-app .msg-bubble.msg-image img {
    display: block;
    max-width: 200px;
    max-height: 300px;
    border-radius: 12px;
    cursor: pointer;
}

/* 文件消息 */
#chat-app .msg-bubble.msg-file {
    padding: 12px 14px;
    min-width: 180px;
    display: flex;
    align-items: center;
    gap: 10px;
}
#chat-app .msg-bubble.msg-file .file-icon {
    width: 40px; height: 40px;
    background: #ff4d4f;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-size: 18px;
    flex-shrink: 0;
}
#chat-app .msg-row.other .msg-bubble.msg-file .file-icon { background: #ff7875; }
#chat-app .msg-bubble.msg-file .file-info { flex: 1; min-width: 0; }
#chat-app .msg-bubble.msg-file .file-name {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#chat-app .msg-bubble.msg-file .file-size {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 2px;
}

/* 消息状态 */
#chat-app .msg-status {
    font-size: 11px;
    color: #bfbfbf;
    margin-top: 2px;
    text-align: right;
}
#chat-app .msg-status.sending { color: #ff7875; }
#chat-app .msg-status.failed { color: #ff4d4f; }

/* 正在加载更多 */
#chat-app .load-more-hint {
    text-align: center;
    padding: 8px;
    color: #bfbfbf;
    font-size: 12px;
}

/* ===== 输入区 ===== */
#chat-app .chat-input-area {
    flex-shrink: 0;
    background: #fff;
    border-top: 1px solid #eee;
    padding: 8px 10px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
#chat-app .chat-input-area .input-btn {
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    color: #666;
    font-size: 20px;
    cursor: pointer;
    border: none;
    background: none;
    flex-shrink: 0;
}
#chat-app .chat-input-area .input-btn:active { opacity: 0.6; }
#chat-app .chat-input-area .input-text {
    flex: 1;
    min-height: 36px;
    max-height: 100px;
    padding: 8px 12px;
    background: #f5f5f5;
    border: none;
    border-radius: 18px;
    font-size: 15px;
    resize: none;
    outline: none;
    line-height: 1.4;
    font-family: inherit;
}
#chat-app .chat-input-area .send-btn {
    height: 36px;
    padding: 0 16px;
    background: #ff4d4f;
    color: #fff;
    border: none;
    border-radius: 18px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    flex-shrink: 0;
}
#chat-app .chat-input-area .send-btn:disabled {
    background: #ffccc7;
    cursor: not-allowed;
}
#chat-app .chat-input-area .send-btn:active:not(:disabled) { opacity: 0.8; }

/* 展开的功能面板 */
#chat-app .chat-extra-panel {
    flex-shrink: 0;
    background: #f7f7f7;
    padding: 16px;
    display: none;
    gap: 16px;
    border-top: 1px solid #eee;
}
#chat-app .chat-extra-panel.show { display: flex; }
#chat-app .chat-extra-panel .extra-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}
#chat-app .chat-extra-panel .extra-item:active { opacity: 0.6; }
#chat-app .chat-extra-panel .extra-icon {
    width: 56px; height: 56px;
    background: #fff;
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    color: #ff4d4f;
    font-size: 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
#chat-app .chat-extra-panel .extra-label {
    font-size: 12px;
    color: #666;
}

/* ===== 商家资料页 ===== */
#chat-app .profile-page {
    background: #f5f5f5;
}
#chat-app .profile-header {
    background: #fff;
    padding: 24px 16px;
    text-align: center;
}
#chat-app .profile-avatar {
    width: 80px; height: 80px;
    border-radius: 50%;
    background: #e8e8e8;
    margin: 0 auto 12px;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-size: 32px;
    font-weight: 600;
    overflow: hidden;
}
#chat-app .profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
#chat-app .profile-name {
    font-size: 20px;
    font-weight: 600;
    color: #333;
    margin-bottom: 4px;
}
#chat-app .profile-status {
    font-size: 13px;
    color: #52c41a;
}
#chat-app .profile-status.offline { color: #bfbfbf; }

#chat-app .profile-actions {
    margin-top: 20px;
    display: flex;
    justify-content: center;
    gap: 24px;
}
#chat-app .profile-action-btn {
    width: 56px; height: 56px;
    border-radius: 50%;
    background: #fff;
    border: 1px solid #eee;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    cursor: pointer;
    color: #ff4d4f;
    font-size: 20px;
}
#chat-app .profile-action-btn span {
    font-size: 11px;
    color: #666;
    font-weight: normal;
}
#chat-app .profile-action-btn:active { opacity: 0.7; }

#chat-app .profile-info-list {
    margin-top: 12px;
    background: #fff;
}
#chat-app .profile-info-row {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid #f0f0f0;
    font-size: 14px;
}
#chat-app .profile-info-row:last-child { border-bottom: none; }
#chat-app .profile-info-row .info-label {
    color: #999;
    width: 80px;
    flex-shrink: 0;
}
#chat-app .profile-info-row .info-value {
    flex: 1;
    color: #333;
    text-align: right;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
#chat-app .profile-info-row .info-arrow {
    color: #ccc;
    margin-left: 8px;
    font-size: 12px;
}

/* ===== 图片预览 lightbox ===== */
#chat-app .lightbox {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.95);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
}
#chat-app .lightbox.show { display: flex; }
#chat-app .lightbox img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}
#chat-app .lightbox .lightbox-close {
    position: absolute;
    top: 16px; right: 16px;
    width: 40px; height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    color: #fff;
    font-size: 20px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    z-index: 1;
}

/* ===== 视频通话模态框 ===== */
#chat-app .video-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #1a1a1a;
    z-index: 10000;
    display: none;
    flex-direction: column;
}
#chat-app .video-modal.show { display: flex; }
#chat-app .video-modal .video-remote {
    flex: 1;
    background: #2a2a2a;
    display: flex; align-items: center; justify-content: center;
    position: relative;
    overflow: hidden;
}
#chat-app .video-modal .video-remote video {
    width: 100%; height: 100%;
    object-fit: cover;
}
#chat-app .video-modal .video-local {
    position: absolute;
    top: 80px; right: 16px;
    width: 100px; height: 140px;
    background: #333;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid rgba(255,255,255,0.3);
    z-index: 10;
}
#chat-app .video-modal .video-local video {
    width: 100%; height: 100%;
    object-fit: cover;
}
#chat-app .video-modal .video-info {
    position: absolute;
    top: 48px; left: 0; right: 0;
    text-align: center;
    color: #fff;
    z-index: 10;
}
#chat-app .video-modal .video-info .v-name {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 4px;
}
#chat-app .video-modal .video-info .v-status {
    font-size: 13px;
    opacity: 0.8;
}
#chat-app .video-modal .video-controls {
    flex-shrink: 0;
    height: 100px;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 32px;
    padding-bottom: env(safe-area-inset-bottom);
}
#chat-app .video-modal .ctrl-btn {
    width: 56px; height: 56px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    color: #fff;
    font-size: 22px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    border: none;
}
#chat-app .video-modal .ctrl-btn.hangup {
    background: #ff4d4f;
    width: 64px; height: 64px;
    font-size: 26px;
}
#chat-app .video-modal .ctrl-btn:active { opacity: 0.7; }
#chat-app .video-modal .ctrl-btn.active {
    background: #ff4d4f;
}

/* ===== Toast 提示 ===== */
#chat-app .chat-toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,0.75);
    color: #fff;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 20000;
    max-width: 80%;
    text-align: center;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}
#chat-app .chat-toast.show { opacity: 1; }

/* ===== 连接状态条 ===== */
#chat-app .connection-status {
    position: absolute;
    top: 48px; left: 0; right: 0;
    padding: 6px 12px;
    background: #fff7e6;
    color: #d46b08;
    font-size: 12px;
    text-align: center;
    z-index: 50;
    transform: translateY(-100%);
    transition: transform 0.3s;
}
#chat-app .connection-status.show { transform: translateY(0); }

/* ===== 加载动画 ===== */
#chat-app .loading-spinner {
    display: inline-block;
    width: 20px; height: 20px;
    border: 2px solid #f0f0f0;
    border-top-color: #ff4d4f;
    border-radius: 50%;
    animation: chat-spin 0.8s linear infinite;
}
@keyframes chat-spin {
    to { transform: rotate(360deg); }
}

/* ===== 下拉刷新 ===== */
#chat-app .pull-refresh {
    height: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    font-size: 13px;
    transition: height 0.2s;
}
#chat-app .pull-refresh.show { height: 40px; }
