* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased; /* 优化字体渲染 */
    -moz-osx-font-smoothing: grayscale; /* 优化字体渲染 */
    -webkit-text-size-adjust: 100%; /* 防止iOS Safari调整字体大小 */
    -ms-text-size-adjust: 100%; /* 防止IE调整字体大小 */
}
body {
    background-color: #f5f5f5;
    height: 100vh;
    height: -webkit-fill-available; /* 适配移动端浏览器地址栏 */
    height: -webkit-fill-available;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-top: env(safe-area-inset-top); /* 适配刘海屏 */
    padding-bottom: env(safe-area-inset-bottom); /* 适配底部安全区域 */
}

/* 加载动画容器 */
.loading-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #f5f5f5;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-top: 4px solid #27ae60;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

.loading-text {
    font-size: 16px;
    color: #666;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* 隐藏内容直到加载完成 */
.content-hidden {
    visibility: hidden;
}

/* 顶部导航栏 */
.chat-header {
    height: 48px;
    background-color: #f7f7f7;
    border-bottom: 1px solid #e5e5e5;
    display: flex;
    align-items: center;
    padding: 0 16px;
    position: relative;
    z-index: 10;
}
.back-btn {
    color: #333;
    font-size: 20px;
    margin-right: 12px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 返回按钮图片 */
.back-btn::before {
    content: "";
    background-image: url('../img/fanhui.png');
    background-size: contain;
    background-repeat: no-repeat;
    width: 15px;
    height: 15px;
    display: block;
}

.chat-title {
    font-size: 15px;
    font-weight: 500;
    text-align: center;
    color: #333;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.header-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-icon::before {
    content: "⋯";
    font-size: 20px;
}

.connection-status {
    font-size: 10px;
    padding: 2px 5px;
    border-radius: 3px;
}

.status-connected {
    color: #07c160;
    background-color: rgba(7, 193, 96, 0.1);
}

.status-disconnected {
    color: #ff4d4f;
    background-color: rgba(255, 77, 79, 0.1);
}

.status-connecting {
    color: #1890ff;
    background-color: rgba(24, 144, 255, 0.1);
}

/* 聊天内容区域 */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: calc(100vh - 120px);
    max-height: calc(100dvh - 120px);
    max-height: calc(var(--vh, 1vh) * 100 - 120px);
    padding-bottom: 70px;
    margin-bottom: 0;
    /* 添加平滑滚动 */
    scroll-behavior: smooth;
}

/* 当输入框获得焦点时，调整聊天容器 */
.input-area:focus-within + .chat-container,
.input-area:focus-within ~ .chat-container {
    max-height: calc(100vh - 200px);
    max-height: calc(100dvh - 200px);
    max-height: calc(var(--vh, 1vh) * 100 - 200px);
}

/* 底部输入区域 */
.input-area {
    background-color: #fff;
    border-top: 1px solid #e5e5e5;
    padding: 8px 16px;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 20;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    /* 添加过渡动画 */
    transition: transform 0.3s ease;
    /* 确保输入区域在视口中 */
    transform: translateZ(0);
    /* 当输入框获得焦点时，确保输入区域可见 */
    z-index: 100;
}

/* 当输入框获得焦点时，调整输入区域 */
.input-area:focus-within {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
}

/* WebView特殊处理 */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    body {
        position: fixed;
        width: 100%;
        height: 100%;
    }
    
    .input-area {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        z-index: 1000 !important;
    }
    
    .chat-container {
        padding-bottom: 70px !important;
    }
}

/* 消息气泡 */
.message {
    max-width: 80%;
    margin-bottom: 15px;
    display: flex;
    position: relative;
}

.message.received {
    align-self: flex-start;
}

/* 客户发送的消息样式 */
.message.sent {
    align-self: flex-end;
    flex-direction: row-reverse;
    margin-left: auto; /* 确保完全靠右 */
    margin-right: 0;
    width: auto; /* 不限制宽度，让内容决定 */
    max-width: 80%; /* 保持最大宽度限制 */
}

.message.sent .avatar {
    margin-right: 0;
    margin-left: 8px;
}

.message.sent .message-content {
    align-items: flex-end;
}

.message.sent .bubble {
    background-color: #95ec69;
    border-top-right-radius: 0;
}

.message.sent .message-time {
    text-align: right;
    margin-right: 5px;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 4px;
    background-color: #eee;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: #999;
    margin-right: 8px;
    flex-shrink: 0;
}

.message.sent .avatar {
    margin-right: 0;
    margin-left: 8px;
}

.message-content {
    display: flex;
    flex-direction: column;
    align-items: flex-start; /* 默认左对齐 */
}

.message.sent .message-content {
    align-items: flex-end; /* 客户消息内容右对齐 */
}

.bubble {
    position:relative;
  padding:8px 10px;border-radius:6px;font-size:14px;line-height:1.45;
  word-break:break-all;               /* 英文长单词强制换行 */
  white-space:normal;                 /* 允许换行 */
  max-width:100%;min-width:40px;
  background:#fff;
}
.message.received .bubble {
    background-color: #fff;
    border-top-left-radius: 0;
}

.message.sent .bubble {
    background-color: #95ec69;
    border-top-right-radius: 0;
}

/* 图片和视频消息样式（无气泡边框和背景） */
.media-message {
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0;
    max-width: fit-content; /* 媒体消息宽度由内容决定 */
}

.message.received .media-message {
    background: transparent;
    border: none;
}

.message.sent .media-message {
    background: transparent;
    border: none;
}

.message-time {
    font-size: 12px;
    color: #999;
    margin-top: 4px;
    width: fit-content; /* 时间宽度由内容决定 */
}

.message.received .message-time {
    text-align: left;
    margin-left: 5px;
}

.message.sent .message-time {
    text-align: right;
    margin-right: 5px;
}

/* 底部输入区域 */
.input-area {
    background-color: #fff;
    border-top: 1px solid #e5e5e5;
    padding: 8px 16px;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 20;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    /* 添加过渡动画 */
    transition: transform 0.3s ease;
    /* 确保输入区域在视口中 */
    transform: translateZ(0);
    /* 当输入框获得焦点时，确保输入区域可见 */
    z-index: 100;
}

/* 当输入框获得焦点时，调整输入区域 */
.input-area:focus-within {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
}

.input-row {
    display: flex;
    align-items: center;
}

.input-btn {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    font-size: 25px;
    cursor: pointer;
}

/* 笑脸图标 */
.smile-icon::before {
    content: "";
    background-image: url(../img/bq.png);
    background-size: contain;
    background-repeat: no-repeat;
    width: 30px;
    height: 30px;
    display: block;
}

.input-btn.active {
    color: #27ae60;
}

.input-box {
    flex: 1;
    background-color: #f0f0f0;
    border-radius: 18px;
    padding: 8px 14px;
    margin: 0 8px;
    min-height: 36px;
    max-height: 120px;
    overflow-y: auto;
    outline: none;
    border: none;
    resize: none;
}

.send-btn {
    background-color: #27ae60;
    color: #fff;
    border-radius: 4px;
    padding: 6px 14px;
    font-size: 14px;
    border: none;
    cursor: pointer;
    display: none;
}

.send-btn.active {
    display: block;
}

.plus-btn {
    font-size: 30px;
    color: #999;
    cursor: pointer;
    display: block;
}

.plus-btn.hidden {
    display: none;
}

/* 表情面板 */
.emoji-panel {
    position: absolute;
    bottom: 60px;
    left: 0;
    right: 0;
    background-color: #fff;
    border-top: 1px solid #e5e5e5;
    padding: 10px;
    display: none;
    flex-wrap: wrap;
    max-height: 200px;
    overflow-y: auto;
    z-index: 15;
}

.emoji-panel.active {
    display: flex;
}

.emoji-item {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    cursor: pointer;
    margin: 4px;
}

/* 功能面板 */
.function-panel {
    position: absolute;
    bottom: 60px;
    left: 0;
    right: 0;
    background-color: #fff;
    border-top: 1px solid #e5e5e5;
    padding: 15px;
    display: none;
    flex-wrap: wrap;
    z-index: 15;
}

.function-panel.active {
    display: flex;
}

.function-item {
    width: 25%;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 15px;
    cursor: pointer;
}

.function-icon {
    width: 50px;
    height: 50px;
    background-color: #f0f0f0;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: #27ae60;
    margin-bottom: 8px;
}

/* 图片图标 */
.picture-icon::before {
    content: "🖼";
}

/* 视频图标 */
.video-icon::before {
    content: "🎬";
}

/* 文件图标 */
.file-icon::before {
    content: "📁";
}

.function-name {
    font-size: 12px;
    color: #666;
}

/* 时间戳样式 */
.timestamp {
    text-align: center;
    color: #999;
    font-size: 12px;
    margin: 15px 0;
}

/* 连接状态提示 */
.connection-status {
    font-size: 10px;
    padding: 2px 5px;
    border-radius: 3px;
}

.status-connected {
    color: #07c160;
    background-color: rgba(7, 193, 96, 0.1);
}

.status-disconnected {
    color: #ff4d4f;
    background-color: rgba(255, 77, 79, 0.1);
}

.status-connecting {
    color: #1890ff;
    background-color: rgba(24, 144, 255, 0.1);
}

/* 媒体上传加载遮罩 */
.upload-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

/* 自动回复模板样式 */
#autoReplyTemplate {
    display: flex;
    align-items: flex-start;
    margin-bottom: 15px;
}

#autoReplyTemplate .avatar {
    width: 36px;
    height: 36px;
    border-radius: 4px;
    background-color: #eee;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: #999;
    margin-right: 8px;
    flex-shrink: 0;
    background-image: url('../img/kefu.png');
    background-size: cover;
}

#autoReplyTemplate .message-content {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

#autoReplyTemplate .bubble {
    position: relative;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 14px;
    line-height: 1.45;
    word-break: break-all;
    white-space: normal;
    max-width: 100%;
    min-width: 40px;
    background: #fff;
    border-top-left-radius: 0;
    /*box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);*/
    width: 100%;
}

#autoReplyTemplate .template-header {
    font-size: 14px;
    font-weight: 500;
    color: #333;
    margin-bottom: 8px;
    line-height: 1.2;
}

#autoReplyTemplate .template-items {
    display: flex;
    flex-direction: column;
    width: 100%;
}

#autoReplyTemplate .template-item {
    padding: 4px 0;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    color: #1890ff;
    text-align: left;
    line-height: 1.4;
    width: 100%;
}

#autoReplyTemplate .template-item:hover {
    background: none;
}

#autoReplyTemplate .template-item:not(:last-child) {
    border-bottom: 1px solid #f0f0f0;
}

#autoReplyTemplate .message-time {
    font-size: 12px;
    color: #999;
    margin-top: 4px;
    width: fit-content;
}

/* 圆形加载动画 */
.circular-loader {
    width: 30px;
    height: 30px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}