/* 基础重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
}

html, body {
    height: 100%;
    background-color: #f5f7fa;
    overflow: hidden; /* 禁止页面整体滚动 */
}

/* 容器：flex垂直布局，确保对话框占满中间空间 */
.container {
    width: 100%;
    height: 100vh; /* 占满视口高度 */
    max-width: 1200px;
    margin: 0 auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.header {
    text-align: center;
    padding: 8px 0;
    border-bottom: 1px solid #eee;
}

.header h1 {
    color: #2c3e50;
    font-size: 22px;
    margin-bottom: 4px;
}

.header p {
    color: #666;
    font-size: 13px;
}

/* 连接状态 */
.connection-status {
    text-align: center;
    font-size: 13px;
    color: #666;
    height: 24px;
    line-height: 24px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.status-connected { color: #28a745; }
.status-connecting { color: #ffc107; }
.status-disconnected { color: #dc3545; }

.config-bar {
    background-color: white;
    border-radius: 8px;
    padding: 10px 15px;
    display: flex;
    align-items: center;
    gap: 25px;
    font-size: 13px;
    color: #666;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.config-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.config-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #4285f4;
    cursor: pointer;
}

/* 对话框容器 */
.chat-container {
    background-color: white;
    border-radius: 8px;
    padding: 15px;
    flex: 1; /* 占满剩余空间 */
    min-height: 0; /* 关键：允许flex子元素收缩 */
    overflow-y: auto; /* 内容溢出时可滚动 */
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

/* 滚动条美化 */
.chat-container::-webkit-scrollbar { width: 6px; }
.chat-container::-webkit-scrollbar-track { background: #f1f1f1; border-radius: 3px; }
.chat-container::-webkit-scrollbar-thumb { background-color: #ccc; border-radius: 3px; }

/* 对话框样式 视觉层次 */
.chat-item {
    max-width: 80%;
    padding: 12px 18px; /* 增加内边距，提升手感 */
    border-radius: 16px; /* 圆润边角 */
    line-height: 1.6;
    font-size: 14px;
    position: relative;
    word-wrap: break-word;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05); /* 轻微阴影，区分层级 */
}

/* 用户对话框：右对齐+蓝色调 */
.chat-item.user {
    align-self: flex-end;
    background-color: #e6f7ff;
    color: #1890ff;
    border-bottom-right-radius: 4px;
}

/* AI对话框：左对齐+浅灰色调 */
.chat-item.ai {
    align-self: flex-start;
    background-color: #f9fafb;
    color: #333;
    border-bottom-left-radius: 4px;
}

/* 角色图标容器 */
.chat-content-wrapper {
    display: flex;
    align-items: flex-start;
    gap: 10px; /* 图标与文本间距 */
}

/* 角色图标：放大+居中 */
.chat-avatar {
    font-size: 20px;
    margin-top: 2px;
    flex-shrink: 0; /* 防止图标被压缩 */
}

/* 加载提示 */
.ai-loading {
    color: #999;
    font-size: 12px;
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
    position: relative;
    z-index: 1;
}

.ai-loading span {
    animation: blink 1.2s infinite both; /* 加快动画速度 */
    width: 10px; /* 放大圆点 */
    height: 10px;
    border-radius: 50%;
    background: #999;
}

.ai-loading span:nth-child(2) { animation-delay: 0.2s; }
.ai-loading span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
    0% { opacity: 0.2; transform: scale(0.8); }
    20% { opacity: 1; transform: scale(1.2); }
    100% { opacity: 0.2; transform: scale(0.8); }
}

/* 音频按钮样式 */
.ai-audio-container {
    margin-top: 8px;
    display: block !important;
}

.ai-audio-btn {
    padding: 6px 12px;
    background-color: #f8f9fa;
    border: 1px solid #eee;
    border-radius: 8px;
    color: #444;
    font-size: 13px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: all 0.2s;
}

.ai-audio-btn:hover {
    background-color: #eee;
    border-color: #ddd;
}

.ai-audio-btn:disabled {
    background-color: #f9f9f9;
    color: #ccc;
    cursor: not-allowed;
    border-color: #f0f0f0;
}

.ai-audio-btn.playing {
    background-color: #e8f0fe;
    color: #4285f4;
    border-color: #d1e0fe;
}

.ai-audio-btn.buffering {
    background-color: #fff3cd;
    color: #856404;
    border-color: #ffeeba;
}

.ai-audio-btn.replay,
.ai-audio-btn.continue { /* 新增“继续播放”状态样式 */
    background-color: #e8f5e9;
    color: #2e7d32;
    border-color: #c8e6c9;
}

.ai-audio-btn.error {
    background-color: #fef2f2;
    color: #dc3545;
    border-color: #fecdd3;
}

/* 底部固定区域：避免滚动时被覆盖 */
#bottom-bar {
    background: #f5f7fa;
    padding-top: 10px;
}

/* 输入容器 */
.input-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.text-input-group, .audio-input-group {
    display: flex;
    gap: 10px;
}

/* 文本输入框 */
#textInput {
    flex: 1;
    padding: 12px 15px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    transition: all 0.2s;
    outline: none;
}

#textInput:focus {
    border-color: #4285f4;
    box-shadow: 0 0 0 3px rgba(66, 133, 244, 0.2); /* 增强聚焦效果 */
}

/* 按钮样式 */
button {
    padding: 11px 18px;
    background-color: #4285f4;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
    outline: none;
}

button:hover {
    background-color: #3367d6;
    transform: translateY(-1px); /* 轻微上浮，提升交互感 */
}

button:disabled {
    background-color: #ccc;
    cursor: not-allowed;
    transform: none; /* 禁用时取消上浮 */
}

/* 录音中按钮：添加脉冲动画 */
button.recording {
    background-color: #dc3545;
    animation: pulse 1s infinite;
}

button.recording:hover {
    background-color: #c82333;
}

/* 录音脉冲动画 */
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.chat-error {
    align-self: center;
    background-color: #f8d7da;
    color: #721c24;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    max-width: 60%;
    text-align: center;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

/* 小屏幕适配 */
@media (max-width: 768px) {
    .config-bar {
        gap: 15px;
        padding: 8px 12px;
        flex-wrap: wrap; /* 允许换行，避免挤压 */
    }
    .chat-item {
        max-width: 90%; /* 小屏幕增加对话框宽度 */
        padding: 10px 14px;
    }
    button {
        padding: 10px 15px;
        font-size: 13px;
    }
    .text-input-group, .audio-input-group {
        flex-direction: column; /* 小屏幕输入框和按钮垂直排列 */
    }
    .text-input-group button, .audio-input-group button {
        width: 100%; /* 按钮占满宽度 */
        justify-content: center;
    }
}
