/* 定积 Wiki 样式 */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: "思源黑体", "Source Han Sans", -apple-system, sans-serif;
    background: #f5f7fa;
    color: #2c3e50;
}

.wiki-container {
    display: flex;
    height: 100vh;
}

/* 侧边栏 */
.wiki-sidebar {
    width: 300px;
    background: linear-gradient(180deg, #1D3557 0%, #2E5C8A 100%);
    color: white;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
}

.wiki-header {
    padding: 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.wiki-header h1 {
    font-size: 1.4rem;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.wiki-search {
    display: flex;
    gap: 8px;
}

.wiki-search input {
    flex: 1;
    padding: 10px 12px;
    border: none;
    border-radius: 8px;
    background: rgba(255,255,255,0.15);
    color: white;
    font-size: 0.9rem;
}

.wiki-search input::placeholder {
    color: rgba(255,255,255,0.6);
}

.wiki-search button {
    padding: 10px 14px;
    border: none;
    border-radius: 8px;
    background: #E85D4E;
    color: white;
    cursor: pointer;
    transition: background 0.2s;
}

.wiki-search button:hover {
    background: #d44d3e;
}

/* RAG 搜索框 */
.rag-search-box {
    padding: 0 20px 15px;
    display: flex;
    gap: 8px;
}

.rag-search-box input {
    flex: 1;
    padding: 10px 12px;
    border: none;
    border-radius: 8px;
    background: rgba(255,255,255,0.1);
    color: white;
    font-size: 0.9rem;
    border: 1px solid rgba(255,255,255,0.2);
}

.rag-search-box input:focus {
    outline: none;
    border-color: #F4A261;
}

.rag-search-box button {
    padding: 10px 12px;
    border: none;
    border-radius: 8px;
    background: #F4A261;
    color: #1D3557;
    cursor: pointer;
}

/* 考研错因索引（error_analysis_index.json） */
.wiki-error-index {
    flex-shrink: 0;
    padding: 12px 16px 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    max-height: 240px;
    overflow-y: auto;
}

.wiki-error-index-head {
    margin-bottom: 8px;
}

.wiki-error-index-title {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
}

.wiki-error-index-sub {
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.55);
}

.wiki-error-index-hint {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.65);
    margin-bottom: 8px;
    line-height: 1.45;
}

.wiki-error-index-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.wiki-error-index-list li {
    margin-bottom: 6px;
}

.wiki-error-index-btn {
    width: 100%;
    text-align: left;
    padding: 8px 10px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 0.82rem;
    cursor: pointer;
    transition: background 0.2s;
}

.wiki-error-index-btn:hover {
    background: rgba(244, 162, 97, 0.38);
}

.wiki-error-index-muted {
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.5);
    padding: 4px 2px;
    display: block;
    line-height: 1.35;
}

/* 统计信息 */
.wiki-stats {
    padding: 15px 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
    display: flex;
    gap: 15px;
    font-size: 0.85rem;
    color: rgba(255,255,255,0.7);
}

/* 导航 */
.wiki-nav {
    flex: 1;
    overflow-y: auto;
    padding: 10px 0;
}

.nav-chapter {
    margin-bottom: 5px;
}

.chapter-title {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    cursor: pointer;
    transition: background 0.2s;
    font-weight: 500;
}

.chapter-title:hover {
    background: rgba(255,255,255,0.1);
}

.chapter-icon {
    margin-right: 10px;
    font-size: 1.1rem;
}

.chapter-title .count {
    margin-left: auto;
    font-size: 0.8rem;
    background: rgba(255,255,255,0.2);
    padding: 2px 8px;
    border-radius: 10px;
}

.toggle {
    font-size: 0.8rem;
    transition: transform 0.2s;
    margin-left: 5px;
}

.chapter-docs {
    padding-left: 20px;
    display: none;
}

.chapter-docs.show {
    display: block;
}

.doc-item {
    padding: 8px 20px 8px 35px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
    border-left: 3px solid transparent;
}

.doc-item:hover {
    background: rgba(255,255,255,0.1);
    border-left-color: #F4A261;
}

.empty-hint {
    padding: 8px 20px 8px 35px;
    font-size: 0.8rem;
    color: rgba(255,255,255,0.5);
    font-style: italic;
}

/* 主内容区 */
.wiki-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* 工具栏 */
.wiki-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 25px;
    background: white;
    border-bottom: 1px solid #e8e8e8;
}

.breadcrumb {
    color: #666;
    font-size: 0.95rem;
}

.breadcrumb span {
    color: #2E5C8A;
    font-weight: 500;
}

.toolbar-actions {
    display: flex;
    gap: 10px;
}

.toolbar-actions button {
    padding: 8px 16px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    background: white;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.toolbar-actions button:hover {
    background: #f5f5f5;
    border-color: #ccc;
}

/* 标签页 */
.wiki-tabs {
    display: flex;
    background: white;
    border-bottom: 1px solid #e8e8e8;
    padding: 0 25px;
}

.wiki-tabs .tab {
    padding: 12px 20px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 0.95rem;
    color: #666;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.wiki-tabs .tab:hover {
    color: #2E5C8A;
}

.wiki-tabs .tab.active {
    color: #2E5C8A;
    border-bottom-color: #2E5C8A;
}

/* 内容区包装器 */
.wiki-content-wrapper {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* 内容区 */
.wiki-content {
    flex: 1;
    padding: 30px 40px;
    overflow-y: auto;
    background: white;
}

.welcome-panel {
    text-align: center;
    padding: 40px 20px;
    color: #666;
}

.welcome-panel h2 {
    color: #1D3557;
    margin-bottom: 20px;
    font-size: 1.8rem;
}

.welcome-panel ul {
    list-style: none;
    margin: 20px 0;
}

.welcome-panel li {
    padding: 10px;
    font-size: 1.1rem;
}

.welcome-panel .hint {
    margin-top: 20px;
    color: #999;
    font-size: 0.95rem;
}

/* 统计卡片 */
.stats-cards {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 30px;
}

.stat-card-mini {
    background: linear-gradient(135deg, #2E5C8A, #1D3557);
    color: white;
    padding: 20px 30px;
    border-radius: 15px;
    cursor: pointer;
    transition: transform 0.2s;
    min-width: 100px;
}

.stat-card-mini:hover {
    transform: translateY(-3px);
}

.stat-card-mini .stat-icon {
    font-size: 1.5rem;
    display: block;
    margin-bottom: 8px;
}

.stat-card-mini .stat-num {
    font-size: 1.5rem;
    font-weight: bold;
}

.stat-card-mini .stat-label {
    font-size: 0.8rem;
    opacity: 0.8;
}

/* 目录面板 */
.toc-panel {
    width: 250px;
    background: #f8f9fa;
    border-left: 1px solid #e8e8e8;
    padding: 20px;
    overflow-y: auto;
}

.toc-panel h3 {
    margin-bottom: 15px;
    color: #1D3557;
    font-size: 1rem;
}

.toc-item {
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 6px;
    margin-bottom: 5px;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.toc-item:hover {
    background: rgba(46, 92, 138, 0.1);
}

.toc-level-1 { padding-left: 0; font-weight: 500; }
.toc-level-2 { padding-left: 15px; }
.toc-level-3 { padding-left: 30px; font-size: 0.85rem; }
.toc-level-4 { padding-left: 45px; font-size: 0.8rem; }

/* 问答面板 */
.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: white;
    border-left: 1px solid #e8e8e8;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.chat-message {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

.chat-message.user {
    flex-direction: row-reverse;
}

.chat-message .avatar {
    font-size: 1.5rem;
}

.chat-message .message-content {
    background: #f0f2f5;
    padding: 12px 16px;
    border-radius: 12px;
    max-width: 70%;
    line-height: 1.5;
}

.chat-message.bot .message-content {
    background: #e8f4f8;
}

.chat-message.user .message-content {
    background: #2E5C8A;
    color: white;
}

.chat-message .sources {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(0,0,0,0.1);
    font-size: 0.85rem;
    color: #666;
}

/* 证据引用（RAG 可追溯） */
.citations {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid rgba(0,0,0,0.08);
}

.citations-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 8px;
}

.citations-head .confidence {
    color: #2E5C8A;
    font-weight: 500;
}

.citation-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.citation-chip {
    border: 1px solid rgba(46, 92, 138, 0.25);
    background: rgba(46, 92, 138, 0.06);
    color: #2E5C8A;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 0.82rem;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
    text-align: left;
}

.citation-chip:hover {
    background: rgba(46, 92, 138, 0.12);
    border-color: rgba(46, 92, 138, 0.45);
}

.chat-input {
    display: flex;
    gap: 10px;
    padding: 15px 20px;
    border-top: 1px solid #e8e8e8;
}

.chat-input input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #ddd;
    border-radius: 25px;
    font-size: 0.95rem;
}

.chat-input input:focus {
    outline: none;
    border-color: #2E5C8A;
}

.chat-input button {
    padding: 10px 20px;
    background: #2E5C8A;
    color: white;
    border: none;
    border-radius: 25px;
    cursor: pointer;
}

/* Markdown 样式 */
.markdown-body {
    max-width: 800px;
    margin: 0 auto;
    line-height: 1.8;
    font-size: 1rem;
}

.markdown-body h1 {
    font-size: 1.8rem;
    color: #1D3557;
    margin: 30px 0 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #E85D4E;
}

.markdown-body h2 {
    font-size: 1.4rem;
    color: #2E5C8A;
    margin: 25px 0 15px;
}

.markdown-body h3 {
    font-size: 1.2rem;
    color: #2E5C8A;
    margin: 20px 0 10px;
}

.markdown-body p {
    margin: 15px 0;
    color: #444;
}

.markdown-body ul, .markdown-body ol {
    margin: 15px 0;
    padding-left: 25px;
}

.markdown-body li {
    margin: 8px 0;
}

.markdown-body code {
    background: #f4f4f4;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: "JetBrains Mono", monospace;
    font-size: 0.9em;
}

.markdown-body pre {
    background: #1D3557;
    color: #f8f8f2;
    padding: 15px 20px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 20px 0;
}

.markdown-body pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.markdown-body blockquote {
    border-left: 4px solid #2E5C8A;
    padding-left: 15px;
    margin: 20px 0;
    color: #666;
}

/* 警告框 */
.warning, .error, .success {
    padding: 12px 15px;
    border-radius: 8px;
    margin: 15px 0;
}

.warning {
    background: #FFF3E0;
    border-left: 4px solid #F4A261;
}

.error {
    background: #FFEBEE;
    border-left: 4px solid #E63946;
}

.success {
    background: #E8F5E9;
    border-left: 4px solid #2A9D8F;
}

/* 编辑器 */
.doc-editor {
    flex: 1;
    width: 100%;
    padding: 20px 40px;
    font-family: "JetBrains Mono", monospace;
    font-size: 0.95rem;
    border: none;
    resize: none;
    background: #fafafa;
    line-height: 1.6;
}

.doc-editor:focus {
    outline: none;
    background: white;
    box-shadow: inset 0 0 0 2px #2E5C8A;
}

/* 模态框 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 12px;
    width: 450px;
    max-width: 90%;
}

.modal-content h3 {
    margin-bottom: 20px;
    color: #1D3557;
}

.modal-content label {
    display: block;
    margin-bottom: 15px;
    color: #666;
}

.modal-content select, .modal-content input {
    width: 100%;
    padding: 10px;
    margin-top: 5px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.95rem;
}

/* 上传相关 */
.upload-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.upload-tab {
    flex: 1;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: white;
    cursor: pointer;
    text-align: center;
}

.upload-tab.active {
    background: #2E5C8A;
    color: white;
    border-color: #2E5C8A;
}

.file-input-label {
    display: block;
    padding: 20px;
    border: 2px dashed #ddd;
    border-radius: 8px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.file-input-label:hover {
    border-color: #2E5C8A;
    background: #f8f9fa;
}

.file-input-label input {
    display: none;
}

.upload-hint {
    font-size: 0.85rem;
    color: #999;
    margin-top: 10px;
}

.upload-progress {
    margin-top: 15px;
}

.progress-bar {
    height: 8px;
    background: #e8e8e8;
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #2E5C8A, #F4A261);
    transition: width 0.3s;
}

.upload-progress span {
    font-size: 0.85rem;
    color: #666;
    margin-top: 5px;
    display: block;
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.modal-actions button {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95rem;
}

.modal-actions button:first-child {
    background: #2E5C8A;
    color: white;
}

.modal-actions button:last-child {
    background: #f0f0f0;
    color: #666;
}

/* 搜索结果 */
.search-results {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 12px;
    width: 550px;
    max-height: 70vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    z-index: 1000;
    padding: 25px;
}

.search-results h3 {
    margin-bottom: 15px;
    color: #1D3557;
}

.result-item {
    padding: 15px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    transition: background 0.2s;
}

.result-item:hover {
    background: #f8f9fa;
}

.result-title {
    font-weight: 500;
    color: #2E5C8A;
    margin-bottom: 5px;
    display: flex;
    justify-content: space-between;
}

.result-title .score {
    font-size: 0.8rem;
    color: #F4A261;
    font-weight: normal;
}

.result-chapter {
    font-size: 0.85rem;
    color: #999;
    margin-bottom: 5px;
}

.result-snippet {
    font-size: 0.9rem;
    color: #666;
}

.search-results > button {
    width: 100%;
    padding: 12px;
    margin-top: 15px;
    background: #f0f0f0;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

/* KaTeX 公式 */
.math {
    font-family: "Latin Modern Math", serif;
}

/* 响应式 */
@media (max-width: 768px) {
    .wiki-sidebar {
        width: 220px;
    }
    
    .wiki-content {
        padding: 20px;
    }
    
    .toc-panel, .chat-panel {
        display: none !important;
    }
}