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

:root {
    --primary: #4A90D9;
    --primary-light: #6BA5E7;
    --bg: #EDEDED;
    --white: #FFFFFF;
    --text: #333333;
    --text-secondary: #999999;
    --bubble-agent: #FFFFFF;
    --bubble-user: #95EC69;
    --border: #E5E5E5;
    --danger: #FF4D4F;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --radius: 8px;
    --radius-lg: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
}

.chat-container {
    width: 100%;
    max-width: 500px;
    height: 100vh;
    max-height: 100vh;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* 顶部Header */
.chat-header {
    background: var(--primary);
    color: #fff;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

.chat-header .avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255,255,255,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

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

.chat-header .name {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.2;
}

.chat-header .status {
    font-size: 12px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-header .status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #5FDF6B;
    display: inline-block;
}

/* 滚动公告 — 水平marquee */
.announcement-bar {
    background: rgb(187, 214, 250, 1);
    /*border-bottom: 1px solid var(--border);*/
    padding: 8px 16px;
    flex-shrink: 0;
    overflow: hidden;
    position: relative;
    height: 36px;
    display: flex;
    align-items: center;
}

.announcement-bar .icon {
    font-size: 14px;
    z-index: 1;
    /*background: #FAFAFA;*/
    padding-right: 8px;
    flex-shrink: 0;
}

.announcement-scroll {
    overflow: hidden;
    flex: 1;
    white-space: nowrap;
    position: relative;
}

.announcement-track {
    display: inline-block;
    white-space: nowrap;
    animation: marquee 20s linear infinite;
    padding-left: 100%;
}

.announcement-item {
    display: inline;
    font-size: 13px;
    color: var(--text);
    margin-right: 60px;
}

@keyframes marquee {
    0%   { transform: translateX(0); }
    100% { transform: translateX(-100%); }
}

/* 消息区域 */
.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

.messages-area::-webkit-scrollbar {
    width: 4px;
}

.messages-area::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 2px;
}

/* 安全提示卡片 — 始终置顶，随消息滚动 */
.chat-notice {
    background: #fff;
    /*border: 1px solid #FFE4C4;*/
    border-radius: 10px;
    padding: 12px 14px;
    flex-shrink: 0;
}

.notice-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 12px;
    color: #8B6914;
    line-height: 1.6;
}

.notice-row + .notice-row {
    margin-top: 6px;
}

.notice-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 6px;
}

.notice-dot-red {
    background: #FF4D4F;
}

.notice-dot-orange {
    background: #FAAD14;
}

/* 时间标签 */
.time-divider {
    text-align: center;
    margin: 8px 0;
}

.time-divider span {
    font-size: 12px;
    color: #B2B2B2;
    background: var(--bg);
    padding: 2px 10px;
    border-radius: 3px;
}

/* 消息行 */
.message-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    max-width: 90%;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message-row.agent {
    align-self: flex-start;
}

.message-row.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-row .msg-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    flex-shrink: 0;
    overflow: hidden;
}
.msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.message-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 15px;
    line-height: 1.5;
    word-break: break-word;
    position: relative;
}

.message-row.agent .message-bubble {
    background: #FFFFFF;
    color: #333;
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

.message-row.user .message-bubble {
    background: #4A90D9;
    color: #FFFFFF;
}

/* 图片消息 */
.message-image {
    max-width: 240px;
    max-height: 240px;
    border-radius: 6px;
    cursor: pointer;
    display: block;
    transition: opacity 0.2s;
}

.message-image:hover {
    opacity: 0.9;
}

/* 视频消息 */
.message-video {
    max-width: 240px;
    border-radius: 6px;
    display: block;
    pointer-events: auto;
}

.message-video video {
    width: 100%;
    border-radius: 6px;
}

/* 消息体 — 头像右侧的垂直列 */
.msg-body {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    min-width: 0;
    flex: 1;
}

/* 坐席昵称 */
.msg-nickname {
    font-size: 11px;
    color: #999;
    line-height: 1.2;
}

/* 气泡+时间同一行 */
.msg-line {
    display: flex;
    align-items: flex-end;
    gap: 6px;
}

/* 用户消息：时间在气泡左边 */
.message-row.user .msg-line {
    flex-direction: row-reverse;
}

/* 时间戳 */
.msg-time {
    font-size: 11px;
    color: #999;
    padding-bottom: 6px;
    white-space: nowrap;
    flex-shrink: 0;
}

/* 输入区域 */
.input-area {
    background: #F7F7F7;
    border-top: 1px solid var(--border);
    padding: 8px 12px;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
}

.input-area .btn-icon {
    width: 36px;
    height: 36px;
    border: none;
    background: none;
    font-size: 22px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: #666;
    transition: background 0.15s;
    flex-shrink: 0;
}

.input-area .btn-icon:active {
    background: rgba(0,0,0,0.06);
}

.input-area .text-input {
    flex: 1;
    border: none;
    outline: none;
    background: #fff;
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 15px;
    line-height: 1.4;
    max-height: 100px;
    resize: none;
    min-height: 36px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.input-area .send-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--primary);
    color: #fff;
    font-size: 18px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}

.input-area .send-btn:active {
    background: var(--primary-light);
}

.input-area .send-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* 图片预览 Modal */
.image-preview {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.9);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.image-preview img {
    max-width: 95%;
    max-height: 95%;
    object-fit: contain;
}

/* 上传提示 */
.upload-toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,0.7);
    color: #fff;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 999;
    pointer-events: none;
    animation: toastIn 0.3s ease;
}

@keyframes toastIn {
    from { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
    to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* 桌面端适配 */
@media (min-width: 501px) {
    .chat-container {
        max-height: 90vh;
        border-radius: var(--radius-lg);
        box-shadow: 0 4px 30px rgba(0,0,0,0.12);
        margin: 20px;
    }
}

/* 移动端全屏 */
@media (max-width: 500px) {
    .chat-container {
        border-radius: 0;
        height: 100vh;
    }
    .messages-area {
        padding: 10px 12px;
    }
    .input-area {
        padding: 6px 10px;
        padding-bottom: max(6px, env(safe-area-inset-bottom));
    }
}
