:root {
    --primary: #F65835;      /* APP主题橙红色 */
    --send-bubble: #FDDED6;  /* 发送气泡粉橙 */
    --send-text: #313131;
    --recv-bubble: #FFFFFF;
    --recv-border: #B6B5B5;
    --bg-color: #F6F6F6;
    /* iOS安全区域 */
    --safe-top: env(safe-area-inset-top);
    --safe-bottom: env(safe-area-inset-bottom);
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; }
body { font-family: -apple-system, 'PingFang SC', 'Helvetica Neue', sans-serif; background: var(--bg-color); touch-action: manipulation; }

#app {
    max-width: 500px;
    margin: 0 auto;
    /* 使用动态视口高度，兼容更多手机浏览器 */
    height: 100vh;
    height: 100dvh;
    height: var(--app-height, 100dvh);
    display: flex;
    flex-direction: column;
    background: var(--bg-color);
}

/* 标题栏 - 白色背景，与系统状态栏融合 */
.header {
    padding: 12px 16px;
    padding-top: calc(12px + var(--safe-top));
    background: #FFFFFF;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    position: relative;
}
.header .title {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 17px;
    font-weight: 600;
    color: #333;
}
.header .status {
    font-size: 12px;
    color: #52c41a;
    display: flex;
    align-items: center;
    gap: 4px;
}
.header .status::before {
    content: '';
    width: 6px;
    height: 6px;
    background: #52c41a;
    border-radius: 50%;
}

.message-list { flex: 1; overflow-y: auto; padding: 16px; }
.message { display: flex; margin-bottom: 16px; align-items: flex-end; }
.message.self { flex-direction: row-reverse; }

/* 消息气泡 - 仿APP样式 */
.message .bubble {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: 20px;
    font-size: 15px;
    line-height: 1.5;
    position: relative;
}

/* 接收消息 - 白色背景+边框+左下小尾巴 */
.message.other .bubble {
    background: var(--recv-bubble);
    border: 1px solid var(--recv-border);
    color: #313131;
    border-bottom-left-radius: 4px;
    margin-left: 8px;
}

/* 客服头像 */
.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: linear-gradient(135deg, #FF6B4A 0%, #FF8F70 100%);
}

/* 发送消息 - 粉橙背景+右下小尾巴 */
.message.self .bubble {
    background: var(--send-bubble);
    color: var(--send-text);
    border-bottom-right-radius: 4px;
    margin-right: 8px;
}

/* 图片消息 */
.msg-img { max-width: 200px; max-height: 200px; border-radius: 10px; cursor: pointer; }

/* 链接消息 */
.link-msg {
    cursor: pointer;
    background: linear-gradient(to right, #FFFAF8, #FFF5F2) !important;
}
.link-msg:hover {
    background: linear-gradient(to right, #FFF5F2, #FFEBE6) !important;
}
.link-title {
    font-weight: 500;
    color: var(--primary);
    margin-bottom: 4px;
}
.link-desc {
    font-size: 13px;
    color: #666;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 200px;
}

/* 富文本链接 */
.msg-link {
    color: var(--primary);
    text-decoration: none;
    cursor: pointer;
}
.msg-link:hover {
    text-decoration: underline;
}

/* 视频消息 */
.video-wrap { position: relative; display: inline-block; }
.video-cover { width: 150px; height: 100px; object-fit: cover; border-radius: 10px; }
.play-icon { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); font-size: 36px; color: #fff; text-shadow: 0 2px 4px rgba(0,0,0,0.3); }

/* 输入区 - 悬浮卡片样式 */
.input-area {
    display: flex;
    padding: 8px 12px;
    margin: 8px 12px;
    margin-bottom: calc(12px + var(--safe-bottom));
    background: #FFFFFF;
    border-radius: 24px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    align-items: center;
}

/* 图片按钮 - 简洁灰色 */
.img-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: #666;
    cursor: pointer;
    margin-right: 6px;
    flex-shrink: 0;
    background: transparent;
}
.img-btn:active { background: #f0f0f0; }
#messageInput {
    flex: 1;
    min-width: 0;
    padding: 8px 4px;
    border: none;
    font-size: 15px;
    outline: none;
    background: transparent;
}
#messageInput::placeholder { color: #999; }

/* 发送按钮 - 铉铉风格蓝色圆角 */
#sendBtn {
    margin-left: 8px;
    padding: 6px 16px;
    background: #1677ff;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
}
#sendBtn:active { background: #0958d9; }

/* 快捷消息区域 */
.quick-msg {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
    background: var(--bg-color);
}
.quick-msg:empty { display: none; }
.quick-msg-btn {
    padding: 5px 12px;
    background: transparent;
    border: 1px solid #1677ff;
    border-radius: 4px;
    font-size: 13px;
    color: #1677ff;
    cursor: pointer;
    white-space: nowrap;
}
.quick-msg-btn:active { background: rgba(22, 119, 255, 0.1); }

/* 视频消息容器 */
.video-msg {
    position: relative;
    display: inline-block;
    cursor: pointer;
}
.video-msg .video-cover {
    width: 200px;
    height: 150px;
    object-fit: cover;
    border-radius: 10px;
}
/* 视频占位背景 */
.video-msg .video-cover-placeholder {
    width: 200px;
    height: 150px;
    background: #000;
    border-radius: 10px;
    position: relative;
}
/* 占位背景上的三角形播放图标 */
.video-msg .video-cover-placeholder::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-40%, -50%);
    width: 0;
    height: 0;
    border-left: 30px solid #fff;
    border-top: 20px solid transparent;
    border-bottom: 20px solid transparent;
}
.video-msg .play-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 40px;
    color: #fff;
    text-shadow: 0 2px 8px rgba(0,0,0,0.5);
    pointer-events: none;
}

/* 视频播放弹窗 */
.video-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.video-wrapper {
    position: relative;
    max-width: 90%;
    max-height: 90%;
}
.video-wrapper video {
    max-width: 100%;
    max-height: 80vh;
    border-radius: 8px;
}
.close-btn {
    position: absolute;
    top: -40px;
    right: 0;
    color: #fff;
    font-size: 32px;
    cursor: pointer;
}
.close-btn:hover { color: #ccc; }

/* 加载动画 */
.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 视频加载层内容 */
.loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}
.loading-progress {
    color: #fff;
    font-size: 18px;
    font-weight: 500;
}
.loading-cancel-btn {
    padding: 10px 30px;
    background: transparent;
    border: 2px solid #fff;
    border-radius: 25px;
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s;
}
.loading-cancel-btn:hover {
    background: rgba(255,255,255,0.1);
}
.loading-cancel-btn:active {
    background: rgba(255,255,255,0.2);
}

/* 图片预览弹窗 */
.image-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.image-modal .image-wrapper {
    position: relative;
    max-width: 90%;
    max-height: 90%;
}
.image-modal img {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 4px;
}

/* 小屏幕适配 */
@media (max-width: 360px) {
    .header { padding: 12px; padding-top: calc(12px + var(--safe-top)); }
    .header .title { font-size: 16px; }
    .message .bubble { font-size: 14px; padding: 8px 12px; }
    .msg-img { max-width: 150px; max-height: 150px; }
    #messageInput { padding: 8px 12px; font-size: 14px; }
    #sendBtn { padding: 8px 16px; font-size: 14px; }
    .quick-msg-btn { padding: 5px 10px; font-size: 12px; }
}

/* 横屏适配 */
@media (orientation: landscape) and (max-height: 500px) {
    .message-list { padding: 8px; }
    .message { margin-bottom: 8px; }
    .header { padding: 8px 16px; padding-top: calc(8px + var(--safe-top)); }
    .input-area { padding: 8px 12px; padding-bottom: calc(8px + var(--safe-bottom)); }
}
