/* 聊天区域包装器和调整器 */
.chat-container-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0; /* 关键CSS属性，解决flex子项无法正确缩小的问题 */
}

/* 聊天区域容器添加可调整样式 */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0; /* 同样关键 */
}

/* 聊天区域宽度调整器 */
.chat-resizer {
    display: none; /* 移除内部调整器，使用面板调整器代替 */
}

/* 拖动中样式 */
.chat-container.resizing {
    transition: none;
}

/* 聊天区域样式 */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-height: 0; /* 确保可以滚动而不溢出 */
}

/* 调整基础消息容器 */
.message {
    display: flex;
    gap: 12px;
    max-width: 80%;
    position: relative; /* 添加相对定位便于调整 */
    transition: max-width 0.3s; /* 平滑过渡效果 */
}

/* AI助手消息 - 保持左对齐 */
.message.assistant {
    align-self: flex-start;
    margin-right: 15%; /* 给用户消息留出空间 */
}

/* 用户消息 - 修改为正确的右对齐布局 */
.message.user {
    align-self: flex-end;
    margin-left: 15%; /* 给AI消息留出空间 */
    flex-direction: row-reverse; /* 正确反转头像和气泡位置 */
}

/* 添加尺寸调节器 */
.message::after {
    content: "";
    position: absolute;
    width: 6px;
    height: 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.2s;
}

.message.assistant::after {
    right: -8px;
    bottom: 10px;
    cursor: e-resize;
}

.message.user::after {
    left: -8px;
    bottom: 10px;
    cursor: w-resize;
}

.message:hover::after {
    opacity: 1;
}

/* 消息气泡样式调整 */
.message-content {
    background-color: var(--bg-card) !important; /* 确保使用卡片背景色 */
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 0.95rem;
    line-height: 1.5;
    flex: 1; /* 允许气泡伸缩 */
    max-width: 100%; /* 最大宽度限制 */
    word-wrap: break-word; /* 确保长文本换行 */
    position: relative;
    z-index: 1;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15); /* 添加阴影增加立体感 */
}

/* 重新定义气泡圆角，确保视觉上与头像连接 */
.message.assistant .message-content {
    border-top-left-radius: 0;
    background: linear-gradient(145deg, rgba(10, 26, 40, 0.8), rgba(10, 22, 35, 0.95)) !important;
    border-left: 1px solid rgba(10, 200, 185, 0.3);
}

.message.user .message-content {
    border-top-left-radius: 12px; /* 恢复左上圆角 */
    border-top-right-radius: 0; /* 移除右上圆角，与头像连接 */
    background: linear-gradient(145deg, rgba(10, 26, 40, 0.7), rgba(0, 90, 180, 0.1)) !important;
    border-right: 1px solid rgba(0, 151, 245, 0.3);
}

.message-content p {
    margin-bottom: 8px;
    line-height: 1.6; /* 增加行高使公式显示更协调 */
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content ul {
    padding-left: 20px;
    margin: 8px 0;
}

/* Markdown样式 */
.message-content h1, .message-content h2, .message-content h3, 
.message-content h4, .message-content h5, .message-content h6 {
    margin-top: 16px;
    margin-bottom: 8px;
    color: var(--color-primary);
}

.message-content h1 { font-size: 1.5em; }
.message-content h2 { font-size: 1.3em; }
.message-content h3 { font-size: 1.2em; }


.message-content code {
    background-color: rgba(10, 20, 40, 0.3);
    padding: 2px 5px;
    border-radius: 3px;
    font-family: monospace;
    font-size: 0.9em;
    color: #e0e0e0;
}

.message-content pre code {
    background-color: transparent;
    padding: 0;
}

.message-content blockquote {
    border-left: 3px solid var(--color-secondary);
    padding-left: 10px;
    margin-left: 5px;
    color: var(--color-text-secondary);
}

.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
}

.message-content th, .message-content td {
    border: 1px solid rgba(30, 58, 95, 0.5);
    padding: 8px;
    text-align: left;
}

.message-content th {
    background-color: rgba(10, 25, 40, 0.6);
}

.message-content tr:nth-child(odd) {
    background-color: rgba(10, 25, 40, 0.2);
}

.message-content img {
    max-width: 100%;
    border-radius: 4px;
}

.chat-input {
    display: flex;
    padding: 15px;
    background-color: var(--bg-panel);
    border-top: 1px solid var(--color-border);
    gap: 10px;
    flex-shrink: 0; /* 防止输入区域被压缩 */
}

.chat-input textarea {
    flex: 1;
    background-color: var(--bg-card);
    border: 1px solid var(--color-border);
    border-radius: 20px;
    color: var(--color-text);
    padding: 12px 16px;
    font-family: var(--font-main);
    font-size: 0.95rem;
    height: auto;
    min-height: 44px;
    max-height: 120px;
    resize: none;
    overflow-y: auto;
    transition: all 0.3s;
}

.chat-input textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 10px rgba(10, 200, 185, 0.2);
}

/* AI助手容器 */
.ai-assistant {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* 确保聊天区域能够随浏览器大小变化 */
.card.full-height {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* 动态打字效果 */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background-color: var(--color-primary);
    border-radius: 50%;
    opacity: 0.7;
}

.typing-dot:nth-child(1) {
    animation: typingBounce 1.4s infinite 0s;
}
.typing-dot:nth-child(2) {
    animation: typingBounce 1.4s infinite 0.2s;
}
.typing-dot:nth-child(3) {
    animation: typingBounce 1.4s infinite 0.4s;
}

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-6px);
        opacity: 1;
    }
}



/* 确保头像正确显示 */
.message-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex-shrink: 0; /* 防止头像被压缩 */
    background-color: rgba(20, 35, 60, 0.5); /* 更深色透明背景 */
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.15);
    position: relative;
    z-index: 2;
}

.message-avatar i {
    color: rgba(255, 255, 255, 0.9); /* 图标更亮 */
    font-size: 20px;
    text-shadow: 0 0 5px rgba(0, 229, 255, 0.5); /* 添加发光效果 */
}

.message.user .message-avatar {
    margin-left: 0; /* 移除原有的错误间距 */
    margin-right: 10px; /* 添加正确的间距 */
}

.message.assistant .message-avatar {
    margin-right: 10px; /* 保持助手头像正确的间距 */
}



/* 更显眼的错误消息样式 */
.message.system-error {
    width: 90%;
    max-width: 90%;
    margin: 15px auto;
    background: rgba(255, 69, 58, 0.2) !important; /* 更亮的红色背景 */
    border: 1px solid rgba(255, 69, 58, 0.5); /* 添加红色边框 */
    border-radius: 6px;
    padding: 12px 16px;
    text-align: center;
    box-shadow: 0 3px 15px rgba(255, 69, 58, 0.25); /* 更强的阴影效果 */
    animation: errorPulse 2s infinite;
    display: block;
}

.message.system-error .message-content {
    background: none !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    color: rgba(255, 255, 255, 1); /* 更高对比度的文本 */
}

.message.system-error i {
    color: rgba(255, 90, 90, 1); /* 更亮的图标颜色 */
    vertical-align: middle;
    margin-right: 8px;
    font-size: 18px; /* 稍大的图标 */
    text-shadow: 0 0 8px rgba(255, 90, 90, 0.8); /* 图标光晕效果 */
}

/* 更快的错误信息闪烁动画 */
@keyframes errorPulse {
    0% { opacity: 0.85; background: rgba(255, 69, 58, 0.15); }
    50% { opacity: 1; background: rgba(255, 69, 58, 0.25); }
    100% { opacity: 0.85; background: rgba(255, 69, 58, 0.15); }
}

/* mathpix-markdown-it 相关样式 */
.message-content .mathpix-render {
    line-height: 1.6;
}

.message-content .math-inline {
    display: inline-block;
    vertical-align: middle;
}

.message-content .math-display {
    display: block;
    text-align: center;
    margin: 12px 0;
    overflow-x: auto;
}

/* 流式内容区域样式 */
.streaming-content {
    width: 100%;
}

/* 公式容器 */
.message-content .katex-container {
    margin: 10px 0;
    overflow-x: auto;
    text-align: center;
}

/* 暗色主题下的公式样式调整 */
.message-content .katex {
    color: #e0e0e0;
    font-size: 1.05em;
}

/* 打字指示器动画 */
.typing-indicator {
    display: flex;
    gap: 4px;
    margin: 10px 0;
    padding: 4px 0;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--color-primary, #0ac8b9);
    animation: typingBounce 1.5s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.3s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.6s;
}

@keyframes typingBounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40% { transform: translateY(-6px); opacity: 1; }
}

/* 在 chat.css 中添加 */
.formula-pending {
    background-color: rgba(10, 200, 185, 0.1);
    border: 1px dashed rgba(10, 200, 185, 0.3);
    border-radius: 3px;
    padding: 2px 5px;
    color: rgba(255, 255, 255, 0.6);
}

.formula-rendering {
    animation: pulse-bg 1.5s infinite;
}

@keyframes pulse-bg {
    0%, 100% { background-color: rgba(10, 200, 185, 0.1); }
    50% { background-color: rgba(10, 200, 185, 0.2); }
}

/* 在 chat.css 文件末尾添加以下内容 */

/* AI助手特定样式 - 从JS移动到CSS */
.message-content pre {
    background-color: #1e1e1e;
    border-radius: 6px;
    padding: 15px;
    margin: 15px 0;
    overflow-x: auto;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    position: relative;
    border-left: 3px solid var(--color-primary, #0ac8b9);
    font-family: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', 'Consolas', monospace !important;
}


/* API状态指示器 */
.api-status-indicator {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    border-radius: 4px;
    margin: 0 0 10px;
    background-color: rgba(10, 20, 40, 0.5);
    transition: all 0.3s ease;
    cursor: pointer;
}

.api-status-indicator .status-icon {
    margin-right: 10px;
}

.api-status-indicator .status-text {
    font-size: 0.85em;
    opacity: 0.9;
}

.api-status-indicator.api-status-online {
    background-color: rgba(0, 180, 100, 0.2);
    border-left: 3px solid rgba(0, 180, 100, 0.7);
}

.api-status-indicator.api-status-offline {
    background-color: rgba(200, 30, 30, 0.2);
    border-left: 3px solid rgba(200, 30, 30, 0.7);
}

.api-status-indicator.api-status-restarting {
    background-color: rgba(200, 150, 10, 0.2);
    border-left: 3px solid rgba(200, 150, 10, 0.7);
}

.api-status-hidden {
    opacity: 0.5;
    transform: translateY(-100%);
    height: 0;
    padding: 0;
    margin: 0;
    overflow: hidden;
}

/* 错误消息样式 */
.error-message {
    background-color: rgba(255, 60, 60, 0.1);
    border-left: 3px solid #ff3c3c;
    padding: 12px;
    margin: 10px 0;
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.error-message i {
    color: #ff3c3c;
    font-size: 24px;
    margin-bottom: 8px;
}

.error-message p {
    margin: 5px 0;
    text-align: center;
    color: #f0f0f0;
}

.btn-retry {
    margin-top: 10px;
    background-color: #444;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 6px 14px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-retry:hover {
    background-color: #666;
}

/* 重试消息样式 */
.retry-message {
    color: #ffa500;
    font-style: italic;
    margin: 8px 0;
    font-size: 0.9em;
}

/* API错误样式 */
.chat-api-error {
    background-color: rgba(255, 60, 60, 0.1);
    border-left: 3px solid #ff3c3c;
    padding: 12px;
    margin: 10px 0;
    border-radius: 4px;
    display: flex;
    align-items: center;
}

.chat-api-error .error-icon i {
    color: #ff3c3c;
    font-size: 20px;
    margin-right: 10px;
}

.chat-api-error .error-message {
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    flex: 1;
}

.chat-api-error .retry-button {
    background-color: #444;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 0.85em;
    margin-left: 10px;
}

.chat-api-error .retry-button:hover {
    background-color: #666;
}

/* 适配不同设备的代码字体 */
@media screen and (max-width: 768px) {
    .message-content pre code {
        font-size: 12px;
    }
}