/* ===== 全局基础 ===== */
* { box-sizing: border-box; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* ===== 滚动条 ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ===== 导航按钮 ===== */
.nav-btn {
    color: #9ca3af;
    text-align: left;
}
.nav-btn:hover {
    background: rgba(255,255,255,0.04);
    color: #e5e7eb;
}
.nav-btn.active {
    background: linear-gradient(135deg, rgba(99,102,241,0.15), rgba(139,92,246,0.1));
    color: #fff;
    border: 1px solid rgba(99,102,241,0.3);
}
.nav-btn.active svg { color: #818cf8; }

/* ===== Tab 切换 ===== */
.tab-panel { animation: fadeIn 0.25s ease; }
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== 拖拽区域 ===== */
#dropZone.dragover {
    border-color: #6366f1 !important;
    background: rgba(99,102,241,0.1) !important;
}

/* ===== Markdown 回答样式 ===== */
#answerContent h1, #answerContent h2, #answerContent h3 {
    color: #e5e7eb; font-weight: 600; margin: 1em 0 0.5em;
}
#answerContent h1 { font-size: 1.3em; }
#answerContent h2 { font-size: 1.15em; }
#answerContent h3 { font-size: 1.05em; }
#answerContent p { margin: 0.6em 0; line-height: 1.8; }
#answerContent ul, #answerContent ol { margin: 0.5em 0; padding-left: 1.5em; }
#answerContent li { margin: 0.3em 0; line-height: 1.7; }
#answerContent code {
    background: rgba(255,255,255,0.08);
    padding: 2px 6px; border-radius: 4px;
    font-size: 0.9em; color: #a5b4fc;
}
#answerContent pre {
    background: rgba(0,0,0,0.3);
    padding: 12px 16px; border-radius: 8px;
    overflow-x: auto; margin: 0.8em 0;
}
#answerContent pre code { background: none; padding: 0; color: #d1d5db; }
#answerContent blockquote {
    border-left: 3px solid #6366f1;
    padding-left: 12px; margin: 0.8em 0;
    color: #9ca3af;
}
#answerContent table {
    border-collapse: collapse; margin: 0.8em 0; width: 100%;
}
#answerContent th, #answerContent td {
    border: 1px solid rgba(255,255,255,0.1);
    padding: 8px 12px; text-align: left;
}
#answerContent th { background: rgba(255,255,255,0.05); }
#answerContent a { color: #818cf8; text-decoration: underline; }
#answerContent strong { color: #fff; }

/* ===== 多轮对话线程 ===== */
.conversation-turn { border-bottom: 1px solid rgba(255,255,255,0.05); padding-bottom: 16px; }
.conversation-turn:last-child { border-bottom: none; padding-bottom: 0; }
.ai-answer h1, .ai-answer h2, .ai-answer h3 {
    color: #e5e7eb; font-weight: 600; margin: 0.8em 0 0.4em;
}
.ai-answer h1 { font-size: 1.25em; }
.ai-answer h2 { font-size: 1.1em; }
.ai-answer h3 { font-size: 1em; }
.ai-answer p { margin: 0.5em 0; line-height: 1.7; }
.ai-answer ul, .ai-answer ol { margin: 0.4em 0; padding-left: 1.4em; }
.ai-answer li { margin: 0.2em 0; }
.ai-answer code { background: rgba(255,255,255,0.08); padding: 2px 6px; border-radius: 4px; font-size: 0.9em; color: #a5b4fc; }
.ai-answer pre { background: rgba(0,0,0,0.3); padding: 10px 14px; border-radius: 8px; overflow-x: auto; margin: 0.6em 0; }
.ai-answer pre code { background: none; padding: 0; color: #d1d5db; }
.ai-answer blockquote { border-left: 3px solid #6366f1; padding-left: 10px; margin: 0.6em 0; color: #9ca3af; }
.ai-answer strong { color: #fff; }

/* ===== 文档卡片 ===== */
.doc-card {
    background: rgba(30,27,75,0.4);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 16px;
    padding: 20px;
    transition: all 0.2s;
}
.doc-card:hover {
    border-color: rgba(99,102,241,0.3);
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(0,0,0,0.3);
}

/* ===== 历史记录项 ===== */
.history-item {
    background: rgba(30,27,75,0.3);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 12px;
    padding: 10px 12px;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 8px;
}
.history-item:hover {
    border-color: rgba(99,102,241,0.3);
    background: rgba(99,102,241,0.05);
}

/* ===== Toast ===== */
#toastInner {
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.1);
}
.toast-success { background: rgba(16,185,129,0.9); color: #fff; }
.toast-error { background: rgba(239,68,68,0.9); color: #fff; }
.toast-info { background: rgba(99,102,241,0.9); color: #fff; }

/* ===== 图谱容器 ===== */
#graphContainer {
    background:
        radial-gradient(circle at 30% 30%, rgba(99,102,241,0.05) 0%, transparent 50%),
        radial-gradient(circle at 70% 70%, rgba(139,92,246,0.05) 0%, transparent 50%);
}

/* ===== 上传结果卡片 ===== */
.result-card {
    background: rgba(30,27,75,0.5);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 16px;
    padding: 20px;
}
.result-card.success { border-left: 4px solid #10b981; }
.result-card.error { border-left: 4px solid #ef4444; }

/* ===== 标签 ===== */
.tag {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
}
.tag-blue { background: rgba(96,165,250,0.15); color: #60a5fa; }
.tag-purple { background: rgba(167,139,250,0.15); color: #a78bfa; }
.tag-green { background: rgba(52,211,153,0.15); color: #34d399; }
.tag-yellow { background: rgba(245,158,11,0.15); color: #f59e0b; }
.tag-red { background: rgba(239,68,68,0.15); color: #ef4444; }
.tag-gray { background: rgba(156,163,175,0.15); color: #9ca3af; }

/* ===== 文本截断 ===== */
.line-clamp-1 {
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ===== 历史记录项 ===== */
.history-item {
    padding: 10px 12px;
    background: rgba(30,27,75,0.4);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s;
}
.history-item:hover {
    background: rgba(99,102,241,0.08);
    border-color: rgba(99,102,241,0.25);
}

/* ===== 来源弹窗 ===== */
#sourceModal {
    animation: fadeIn 0.2s ease;
}
#sourceModal > div {
    animation: slideUp 0.25s ease;
}
@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== Toast ===== */
.toast-success { background: rgba(16,185,129,0.15); border: 1px solid rgba(16,185,129,0.3); color: #34d399; }
.toast-error { background: rgba(239,68,68,0.15); border: 1px solid rgba(239,68,68,0.3); color: #f87171; }
.toast-info { background: rgba(99,102,241,0.15); border: 1px solid rgba(99,102,241,0.3); color: #818cf8; }

/* ===== 豆包风格聊天布局 ===== */
.chat-layout {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 120px);
}
.chat-messages {
    scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }

/* 消息容器 */
.msg-row {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    max-width: 64rem;
    margin-left: auto;
    margin-right: auto;
}
.msg-row.user { flex-direction: row-reverse; }

.msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: #fff;
}
.msg-row.user .msg-avatar { background: #4b5563; }
.msg-row.ai .msg-avatar { background: linear-gradient(135deg, #6366f1, #8b5cf6); }

.msg-bubble {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.7;
    word-break: break-word;
}
.msg-row.user .msg-bubble {
    background: linear-gradient(135deg, #4f46e5, #6366f1);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.msg-row.ai .msg-bubble {
    background: transparent;
    border: none;
    color: #e5e7eb;
    padding: 0;
    border-radius: 0;
}

/* AI 回答内的 Markdown 样式 */
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 {
    color: #f3f4f6; font-weight: 600; margin: 0.8em 0 0.4em;
}
.msg-bubble h1 { font-size: 1.2em; }
.msg-bubble h2 { font-size: 1.1em; }
.msg-bubble h3 { font-size: 1em; }
.msg-bubble p { margin: 0.5em 0; }
.msg-bubble ul, .msg-bubble ol { margin: 0.4em 0; padding-left: 1.4em; }
.msg-bubble li { margin: 0.2em 0; }
.msg-bubble code {
    background: rgba(255,255,255,0.1); padding: 2px 6px; border-radius: 4px;
    font-size: 0.9em; color: #a5b4fc;
}
.msg-bubble pre {
    background: rgba(0,0,0,0.4); padding: 10px 14px; border-radius: 8px;
    overflow-x: auto; margin: 0.6em 0;
}
.msg-bubble pre code { background: none; padding: 0; color: #d1d5db; }
.msg-bubble blockquote {
    border-left: 3px solid #6366f1; padding-left: 10px; margin: 0.6em 0; color: #9ca3af;
}
.msg-bubble strong { color: #fff; }
.msg-bubble a { color: #818cf8; text-decoration: underline; }
.msg-bubble table { border-collapse: collapse; margin: 0.6em 0; width: 100%; }
.msg-bubble th, .msg-bubble td { border: 1px solid rgba(255,255,255,0.1); padding: 6px 10px; }
.msg-bubble th { background: rgba(255,255,255,0.05); }

/* 引用来源（AI 消息下方，横向排列） */
.msg-sources {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid rgba(255,255,255,0.06);
}
.sources-header {
    font-size: 12px;
    color: #6b7280;
    margin-bottom: 8px;
    font-weight: 500;
}

/* AI 思考过程（有思考内容时才展示，可折叠） */
.msg-thinking {
    margin-bottom: 10px;
    border: 1px solid rgba(129,140,248,0.18);
    background: rgba(129,140,248,0.06);
    border-radius: 8px;
    overflow: hidden;
}
.thinking-head {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 12px;
    color: #a5b4fc;
    user-select: none;
    -webkit-user-select: none;
}
.thinking-head:hover { background: rgba(129,140,248,0.08); }
.thinking-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #a78bfa;
    animation: pulse-dot 1.5s infinite;
    flex-shrink: 0;
}
.thinking-label {
    flex: 1;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
}
.thinking-badge {
    font-style: normal;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    padding: 2px 5px;
    border-radius: 4px;
    background: linear-gradient(135deg, #7c3aed, #a78bfa);
    color: #fff;
}
.thinking-toggle { color: #6b7280; }
.thinking-body {
    border-top: 1px solid rgba(255,255,255,0.06);
    padding: 6px 10px 8px;
    max-height: 240px;
    overflow-y: auto;
}
.thinking-text {
    font-size: 12px;
    line-height: 1.7;
    color: #9ca3af;
    white-space: pre-wrap;
    word-break: break-word;
}
.sources-scroll {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
    scroll-behavior: smooth;
    user-select: none;
    -webkit-user-select: none;
}
.sources-scroll::-webkit-scrollbar { height: 4px; }
.sources-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }
.source-card {
    background: rgba(99,102,241,0.06);
    border: 1px solid rgba(99,102,241,0.12);
    border-radius: 8px;
    padding: 8px 10px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    flex-shrink: 0;
    width: 220px;
    min-width: 220px;
}
.source-card:hover {
    background: rgba(99,102,241,0.12);
    border-color: rgba(99,102,241,0.25);
}
.source-card-head {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}
.source-num {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    background: rgba(99,102,241,0.2);
    color: #818cf8;
    font-size: 10px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.source-name {
    font-size: 12px;
    color: #c7d2fe;
    font-weight: 500;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.source-chunk {
    font-size: 10px;
    color: #6b7280;
    margin-bottom: 4px;
}
.source-hierarchy {
    font-size: 10px;
    color: #a78bfa;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.source-preview {
    font-size: 11px;
    color: #9ca3af;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin: 0;
}
.source-deleted {
    opacity: 0.5;
    background: rgba(107,114,128,0.06) !important;
    border-color: rgba(107,114,128,0.15) !important;
    cursor: not-allowed !important;
}
.source-deleted:hover {
    background: rgba(107,114,128,0.06) !important;
    border-color: rgba(107,114,128,0.15) !important;
}
.source-deleted-tag {
    font-size: 10px;
    color: #ef4444;
    background: rgba(239,68,68,0.1);
    padding: 1px 5px;
    border-radius: 3px;
    flex-shrink: 0;
}

/* AI 回答状态指示器 */
.msg-status {
    margin-top: 8px;
    font-size: 11px;
    color: #6b7280;
    display: flex;
    align-items: center;
    gap: 5px;
}
.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #f59e0b;
    animation: pulse-dot 1.5s infinite;
}
.status-dot.status-done {
    background: #10b981;
    animation: none;
}
.status-dot.status-error {
    background: #ef4444;
    animation: none;
}
@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* 输入框自动高度 */
#questionInput {
    overflow-y: auto;
    transition: height 0.1s;
}

/* ===== 加载动画 ===== */
.spinner-sm {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid rgba(251, 191, 36, 0.3);
    border-top-color: #fbbf24;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
.spinner-md {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(251, 191, 36, 0.3);
    border-top-color: #fbbf24;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== 内联删除确认 ===== */
.inline-delete-confirm {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    white-space: nowrap;
}
.inline-delete-confirm button {
    font-size: 13px;
    padding: 5px 14px;
    border-radius: 6px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s;
    line-height: 1.4;
    font-weight: 600;
    min-width: 44px;
    text-align: center;
}
.inline-delete-confirm .idc-yes {
    color: #f87171;
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.2);
}
.inline-delete-confirm .idc-yes:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
}
.inline-delete-confirm .idc-no {
    color: #9ca3af;
    background: rgba(255, 255, 255, 0.05);
}
.inline-delete-confirm .idc-no:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #d1d5db;
}

/* ===== 消息操作按钮（复制/停止） ===== */
.msg-actions {
    display: flex;
    gap: 6px;
    margin-top: 6px;
}
.msg-actions button {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 4px;
    background: rgba(255,255,255,0.05);
    color: #9ca3af;
    border: 1px solid rgba(255,255,255,0.08);
    cursor: pointer;
    transition: all 0.15s;
}
.msg-actions button:hover {
    background: rgba(255,255,255,0.1);
    color: #d1d5db;
}
.msg-stop-btn { color: #f87171 !important; }
.msg-stop-btn:hover { background: rgba(239,68,68,0.1) !important; color: #fca5a5 !important; }

/* ===== 拖拽上传高亮 ===== */
#dropZone.dragover {
    border-color: #6366f1 !important;
    background: rgba(99,102,241,0.08) !important;
}

/* ===== 来源内联展开 ===== */
.source-full {
    margin-top: 8px;
    padding: 8px 10px;
    background: rgba(0,0,0,0.2);
    border-radius: 6px;
    font-size: 11px;
    color: #9ca3af;
    line-height: 1.6;
    max-height: 200px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ===== 历史记录操作按钮 ===== */
.history-actions {
    display: flex;
    align-items: center;
    gap: 2px;
}
.history-actions button {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.15s;
}
.history-actions button:hover {
    background: rgba(255,255,255,0.08);
}

/* 打字光标 */
.typing-cursor::after {
    content: '▋';
    display: inline-block;
    animation: blink 1s infinite;
    color: #818cf8;
    margin-left: 2px;
}
@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}
