/**
 * AI对话区样式模块
 * 包含：对话容器、消息气泡、输入区、快捷按钮、动画效果
 */

/* ==================== 对话容器 ==================== */

/* 对话容器 */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: #ffffff;
}

/* 消息列表 */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* 空状态 */
.chat-empty {
    text-align: center;
    padding: 80px 20px;
    color: #909399;
}

.chat-empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.chat-empty p {
    font-size: 16px;
    margin-bottom: 8px;
}

.chat-empty-hint {
    font-size: 13px;
    color: #c0c4cc;
}

/* ==================== 消息气泡 ==================== */

/* 消息气泡 */
.chat-message {
    display: flex;
    margin-bottom: 16px;
    animation: messageSlideIn 0.3s ease-out;
    flex-wrap: nowrap;  /* 🆕 强制不换行 */
    align-items: flex-start;  /* 🆕 顶部对齐 */
}

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

.chat-message.user {
    justify-content: flex-end;
}

.chat-message.ai {
    justify-content: flex-start;
}

/* 🆕 迭代2：系统消息（带附件时居中显示） */
.chat-message.system {
    justify-content: center;
}

/* 🆕 系统消息的附件卡片居中显示，头像隐藏 */
.chat-message.system .message-avatar {
    display: none;  /* 系统消息不显示头像 */
}

/* 🔧 修复：无头像的消息（如执行结果） */
.chat-message.no-avatar {
    padding-left: 0;  /* 移除左侧间距 */
}

.chat-message.no-avatar .message-content {
    margin-left: 0;  /* 内容不留头像位置 */
}

.chat-message.system .message-content {
    max-width: 90%;  /* 限制最大宽度 */
}

/* 消息头像 */
.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.chat-message.user .message-avatar {
    order: 2;
    margin-left: 12px;
    background-color: #409eff;
}

.chat-message.ai .message-avatar {
    margin-right: 12px;
    background-color: #67c23a;
}

.chat-message.system .message-avatar {
    margin-right: 12px;
    background-color: #909399;
}

/* 消息内容 */
.message-content {
    max-width: 70%;
    display: flex;
    flex-direction: column;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: 12px;
    word-wrap: break-word;
    white-space: pre-wrap;
    line-height: 1.6;
}

/* 🆕 阶段4.1：执行结果表格气泡无padding，避免双滚动条 */
.message-bubble:has(.execution-table-standalone) {
    padding: 0;
    overflow: visible;
    max-height: none;  /* 🆕 移除高度限制 */
}

.message-bubble:has(.execution-header-standalone) {
    padding: 0;
}

/* 🆕 让包含表格的消息内容宽度更大 */
.chat-message.ai:has(.execution-table-standalone) .message-content {
    max-width: 90%;
}

.chat-message.user .message-bubble {
    background-color: #409eff;
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.chat-message.ai .message-bubble {
    background-color: #f4f4f5;
    color: #303133;
    border-bottom-left-radius: 4px;
}

.chat-message.system .message-bubble {
    background-color: #e9ecef;
    color: #606266;
    border-bottom-left-radius: 4px;
    font-size: 14px;
}

.message-time {
    font-size: 12px;
    color: #c0c4cc;
    margin-top: 4px;
    padding: 0 4px;
}

.chat-message.user .message-time {
    text-align: right;
}

/* ==================== AI 思考动画 ==================== */

.message-typing {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    padding: 12px 16px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #c0c4cc;
    animation: typingAnimation 1.4s infinite;
}

.typing-dot:nth-child(1) {
    animation-delay: 0s;
}

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

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

@keyframes typingAnimation {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* ==================== 快捷提示区 ==================== */

.chat-shortcuts {
    padding: 12px 20px;
    background-color: #fafbfc;
    border-top: 1px solid #e4e7ed;
    display: flex;
    align-items: center;
    gap: 12px;
}

.shortcuts-label {
    font-size: 13px;
    color: #909399;
    white-space: nowrap;
}

.shortcuts-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.shortcut-btn {
    padding: 6px 12px;
    background-color: #ffffff;
    border: 1px solid #dcdfe6;
    border-radius: 16px;
    font-size: 13px;
    color: #606266;
    cursor: pointer;
    transition: all 0.3s;
    white-space: nowrap;
}

.shortcut-btn:hover {
    background-color: #ecf5ff;
    border-color: #409eff;
    color: #409eff;
}

/* ==================== 输入区 ==================== */

/* 输入区容器 */
.chat-input-container {
    border-top: 1px solid #e4e7ed;
    background-color: #ffffff;
    padding: 16px 20px;
}

/* 🆕 输入框上方的文件预览卡片 */
.input-file-preview {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background-color: #ecf5ff;
    border: 1px solid #b3d8ff;
    border-radius: 8px;
    margin-bottom: 12px;
    transition: all 0.3s;
}

.input-file-preview:hover {
    background-color: #d9ecff;
}

.input-file-icon {
    font-size: 24px;
    flex-shrink: 0;
}

.input-file-info {
    flex: 1;
    min-width: 0;
}

.input-file-name {
    font-size: 14px;
    font-weight: 600;
    color: #303133;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.input-file-size {
    font-size: 12px;
    color: #909399;
    margin-top: 2px;
}

.input-file-remove {
    width: 28px;
    height: 28px;
    border: none;
    background-color: rgba(0, 0, 0, 0.05);
    border-radius: 50%;
    font-size: 20px;
    line-height: 1;
    color: #606266;
    cursor: pointer;
    transition: all 0.3s;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.input-file-remove:hover {
    background-color: #f56c6c;
    color: #ffffff;
}

.chat-input-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.btn-icon {
    width: 32px;
    height: 32px;
    border: none;
    background-color: transparent;
    border-radius: 4px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background-color: #f5f7fa;
}

.chat-input-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    padding: 14px 16px;  /* 🔧 增加内边距 */
    min-height: 48px;  /* 🔧 增加最小高度 */
    border: 2px solid #409eff;  /* 🔧 更粗的边框，蓝色更显眼 */
    border-radius: 10px;  /* 🔧 稍大的圆角 */
    font-size: 15px;  /* 🔧 稍大的字体 */
    font-family: inherit;
    resize: none;
    max-height: 140px;  /* 🔧 增加最大高度 */
    overflow-y: auto;
    transition: all 0.3s;  /* 🔧 所有属性过渡 */
    line-height: 1.6;
    background-color: #ffffff;
    box-shadow: 0 2px 8px rgba(64, 158, 255, 0.15);  /* 🔧 添加蓝色阴影 */
}

.chat-input:focus {
    outline: none;
    border-color: #66b1ff;  /* 🔧 聚焦时更亮的蓝色 */
    box-shadow: 0 4px 12px rgba(64, 158, 255, 0.3);  /* 🔧 聚焦时加强阴影 */
    transform: translateY(-1px);  /* 🔧 轻微抬起效果 */
}

.chat-input:disabled {
    background-color: #f5f7fa;
    cursor: not-allowed;
    border-color: #dcdfe6;
    box-shadow: none;
}

.btn-send {
    padding: 10px 20px;
    background-color: #409eff;
    color: #ffffff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.btn-send:hover:not(:disabled) {
    background-color: #66b1ff;
}

.btn-send:disabled {
    background-color: #c0c4cc;
    cursor: not-allowed;
    opacity: 0.6;
}

.send-icon {
    font-size: 16px;
}

/* 🆕 阶段6：停止按钮样式 */
.btn-stop {
    background-color: #f56c6c !important;  /* 红色背景 */
}

.btn-stop:hover:not(:disabled) {
    background-color: #f78989 !important;  /* 浅红色悬停 */
}

/* ==================== 🆕 迭代2：消息中的附件卡片 ==================== */

/* 附件卡片基础样式 */
.message-attachment-card {
    border: 1px solid #e4e7ed;
    border-radius: 8px;
    background-color: #fafbfc;
    margin-bottom: 8px;
    overflow: hidden;
    transition: all 0.3s;
}

.message-attachment-card:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* 🆕 迭代2修复：上传通知标题 */
.attachment-upload-notice {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #ffffff;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    letter-spacing: 0.5px;
}

/* 附件头部 */
.attachment-header {
    display: flex;
    align-items: center;
    padding: 12px;
    background-color: #f5f7fa;
    border-bottom: 1px solid #e4e7ed;
}

.attachment-icon {
    font-size: 24px;
    margin-right: 12px;
}

.attachment-info {
    flex: 1;
}

.attachment-name {
    font-size: 14px;
    font-weight: 600;
    color: #303133;
    margin-bottom: 4px;
    word-break: break-all;
}

.attachment-meta {
    font-size: 12px;
    color: #909399;
}

/* 完整预览模式 */
.message-attachment-card.full-preview {
    max-width: 100%;
}

/* 表格预览容器 */
.attachment-table-wrapper {
    padding: 0px 12px 12px 12px;  /* 🔧 修复：顶部padding改为0，减少表头距离 */
    max-height: 400px;
    overflow: auto;
}

.attachment-preview-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.attachment-preview-table th {
    background-color: #f5f7fa;
    color: #606266;
    font-weight: 600;
    padding: 8px 12px;
    text-align: left;
    border: 1px solid #e4e7ed;
    white-space: nowrap;
    /* 🔧 修复：移除sticky定位，避免滚动时遮住数据 */
    position: static;  /* 确保不固定 */
}

.attachment-preview-table td {
    padding: 8px 12px;
    border: 1px solid #e4e7ed;
    color: #606266;
    white-space: nowrap;
}

.attachment-preview-table tbody tr:nth-child(even) {
    background-color: #fafbfc;
}

.attachment-preview-table tbody tr:hover {
    background-color: #ecf5ff;
}

/* 更多数据提示 */
.attachment-more-hint {
    text-align: center;
    padding: 8px;
    color: #909399;
    font-size: 12px;
    font-style: italic;
}

/* 缓存提示 */
.attachment-cache-hint {
    padding: 12px;
    text-align: center;
    color: #e6a23c;
    font-size: 13px;
    background-color: #fdf6ec;
    border-top: 1px solid #f5dab1;
}

/* 🆕 阶段3：简化引用模式优化 */
.message-attachment-card.simple-ref {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    background-color: #ecf5ff;
    border-color: #b3d8ff;
    gap: 12px;
    max-width: 450px;
}

.attachment-icon-small {
    font-size: 24px;
    flex-shrink: 0;
}

.attachment-info-small {
    flex: 1;
    min-width: 0;
}

.attachment-name-small {
    font-size: 14px;
    color: #303133;
    font-weight: 600;
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attachment-size-small {
    font-size: 12px;
    color: #909399;
}

.attachment-actions-small {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.btn-attachment-action {
    width: 32px;
    height: 32px;
    border: none;
    background-color: rgba(255, 255, 255, 0.8);
    border-radius: 6px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-attachment-action:hover {
    background-color: #ffffff;
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.btn-attachment-action:active {
    transform: translateY(0);
}

.attachment-status {
    font-size: 12px;
    color: #67c23a;
    margin-left: 4px;
}

/* ==================== 🆕 阶段1：代码折叠区域样式 ==================== */

/* 执行结果容器 */
.execution-result-container {
    margin-top: 12px;
}

.execution-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    padding: 8px 12px;
    background-color: #f5f7fa;
    border-radius: 6px;
}

.execution-status {
    font-weight: 600;
    font-size: 14px;
}

.execution-status.success {
    color: #67c23a;
}

.execution-status.error {
    color: #f56c6c;
}

.execution-intent {
    flex: 1;
    color: #606266;
    font-size: 14px;
}

.execution-time {
    font-size: 12px;
    color: #909399;
}

.execution-content {
    margin-bottom: 16px;
}

.execution-error {
    padding: 12px;
    background-color: #fef0f0;
    border: 1px solid #fde2e2;
    border-radius: 6px;
    color: #f56c6c;
    margin-bottom: 16px;
    font-size: 13px;
}

.execution-error strong {
    color: #c45656;
}

/* 🆕 阶段1（调整）：收藏工具按钮区域（代码已隐藏） */
.ai-code-actions {
    margin-top: 12px;
    padding: 12px;
    background-color: #f5f7fa;
    border-radius: 6px;
    text-align: right;
}

.btn-save-tool {
    padding: 8px 16px;
    font-size: 13px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 500;
    background: linear-gradient(135deg, #e6a23c 0%, #f0b86e 100%);
    color: #ffffff;
    box-shadow: 0 2px 4px rgba(230, 162, 60, 0.3);
}

.btn-save-tool:hover {
    background: linear-gradient(135deg, #ebb563 0%, #f4c78a 100%);
    box-shadow: 0 4px 8px rgba(230, 162, 60, 0.4);
    transform: translateY(-1px);
}

.btn-save-tool:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(230, 162, 60, 0.3);
}

/* ==================== 🆕 阶段2：新对话欢迎语样式（已废弃） ==================== */
/* 🔧 用户反馈：删除静态欢迎框体，只保留AI流式欢迎消息 */
/*
.welcome-message {
    max-width: 600px;
    margin: 60px auto;
    text-align: center;
    padding: 40px 30px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 16px;
    box-shadow: 0 8px 24px rgba(102, 126, 234, 0.25);
    animation: welcomeFadeIn 0.6s ease-out;
}

@keyframes welcomeFadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.welcome-icon {
    font-size: 64px;
    margin-bottom: 20px;
    animation: welcomeWave 2s ease-in-out infinite;
}

@keyframes welcomeWave {
    0%, 100% {
        transform: rotate(0deg);
    }
    10%, 30% {
        transform: rotate(14deg);
    }
    20%, 40% {
        transform: rotate(-8deg);
    }
    50% {
        transform: rotate(10deg);
    }
    60% {
        transform: rotate(-4deg);
    }
    70% {
        transform: rotate(6deg);
    }
    80% {
        transform: rotate(0deg);
    }
}

.welcome-title {
    font-size: 28px;
    font-weight: 700;
    color: #ffffff;
    margin-bottom: 30px;
    letter-spacing: 0.5px;
}

.welcome-features {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 30px;
}

.welcome-feature {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background-color: rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    backdrop-filter: blur(10px);
    transition: all 0.3s;
}

.welcome-feature:hover {
    background-color: rgba(255, 255, 255, 0.25);
    transform: translateY(-2px);
}

.feature-icon {
    font-size: 24px;
    flex-shrink: 0;
}

.feature-text {
    font-size: 14px;
    color: #ffffff;
    font-weight: 500;
    text-align: left;
}

.welcome-hint {
    font-size: 16px;
    color: rgba(255, 255, 255, 0.95);
    margin: 0;
    font-weight: 500;
    padding: 16px;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    backdrop-filter: blur(10px);
}
*/

/* ==================== 🆕 阶段5：AI思考过程展示 ==================== */

.ai-thinking-process {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 16px;
    padding: 20px;
    margin: 16px 0;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.3);
    animation: slideIn 0.3s ease-out;
}

.ai-thinking-process.fade-out {
    animation: fadeOut 0.3s ease-out;
}

.thinking-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.thinking-icon {
    font-size: 28px;
    animation: rotate 2s linear infinite;
}

.thinking-title {
    font-size: 16px;
    font-weight: 600;
    color: #ffffff;
}

.thinking-stages {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.thinking-stage {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    transition: all 0.3s ease;
}

.thinking-stage.active {
    background-color: rgba(255, 255, 255, 0.2);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.thinking-stage.completed {
    background-color: rgba(255, 255, 255, 0.15);
}

.stage-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.stage-text {
    flex: 1;
    font-size: 14px;
    color: #ffffff;
    font-weight: 500;
}

.stage-status {
    font-size: 16px;
    flex-shrink: 0;
}

.thinking-stage.active .stage-status {
    animation: pulse 1.5s ease-in-out infinite;
}

.stage-time {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.8);
    font-weight: 600;
    min-width: 50px;
    text-align: right;
}

.thinking-footer {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    text-align: center;
}

.thinking-total {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 600;
}

#thinkingTotalTime {
    font-size: 18px;
    color: #ffffff;
    font-weight: 700;
}

/* 思考过程动画 */
@keyframes rotate {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(1.1);
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.95);
    }
}

