/* 
 * 帮助中心优化版 CSS - 独立滚动容器设计
 * 优化左侧导航栏的可访问性和滚动体验
 */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    background: #f5f7fa;
    color: #333;
    overflow-x: hidden; /* 防止水平滚动 */
}

/* 搜索栏 */
.search-bar {
    background: white;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    position: sticky;
    top: 60px; /* 考虑导航栏高度 */
    z-index: 100;
}

.search-container {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    gap: 15px;
}

.search-input {
    flex: 1;
    padding: 12px 20px;
    border: 2px solid #e1e8ed;
    border-radius: 25px;
    font-size: 15px;
    transition: all 0.3s;
}

.search-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.search-btn {
    padding: 12px 30px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 25px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.search-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}

/* 主容器 - 使用 Flexbox 布局 */
.main-container {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    gap: 30px;
    padding: 20px;
    height: calc(100vh - 160px); /* 减去导航栏和搜索栏的高度 */
}

/* 左侧边栏 - 独立滚动容器 */
.sidebar {
    width: 300px;
    min-width: 300px; /* 防止收缩 */
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    overflow: hidden; /* 确保子元素不会溢出 */
}

.sidebar-header {
    padding: 20px 20px 15px;
    border-bottom: 1px solid #f0f0f0;
    flex-shrink: 0; /* 防止头部被压缩 */
}

.sidebar h3 {
    font-size: 18px;
    color: #2c3e50;
    margin: 0;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto; /* 独立垂直滚动 */
    overflow-x: hidden; /* 防止水平滚动 */
    padding: 15px 20px 20px;
}

/* 自定义滚动条样式 */
.sidebar-content::-webkit-scrollbar {
    width: 6px;
}

.sidebar-content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.sidebar-content::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.sidebar-content::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

.category-group {
    margin-bottom: 25px;
}

.category-title {
    font-size: 14px;
    font-weight: 600;
    color: #667eea;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 2px solid #f0f0f0;
    position: sticky;
    top: 0;
    background: white;
    z-index: 10;
}

.article-list {
    list-style: none;
}

.article-item {
    padding: 10px;
    margin-bottom: 5px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
    color: #555;
    word-wrap: break-word; /* 防止长文本溢出 */
    line-height: 1.4;
}

.article-item:hover {
    background: #f8f9fa;
    color: #667eea;
    transform: translateX(5px);
}

.article-item.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    transform: translateX(5px);
}

/* 内容区域 - 独立滚动容器 */
.content-area {
    flex: 1;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.content-scrollable {
    flex: 1;
    overflow-y: auto; /* 独立垂直滚动 */
    overflow-x: hidden; /* 防止水平滚动 */
    padding: 40px;
}

/* 内容区域滚动条样式 */
.content-scrollable::-webkit-scrollbar {
    width: 8px;
}

.content-scrollable::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.content-scrollable::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.content-scrollable::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

.article-header {
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid #f0f0f0;
}

.article-title {
    font-size: 32px;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 10px;
    line-height: 1.2;
}

.article-meta {
    display: flex;
    gap: 20px;
    font-size: 14px;
    color: #7f8c8d;
    flex-wrap: wrap;
}

.article-category {
    display: inline-block;
    padding: 5px 15px;
    background: #667eea;
    color: white;
    border-radius: 15px;
    font-size: 12px;
}

/* Markdown 内容样式 */
.article-content {
    line-height: 1.8;
    color: #333;
}

.article-content h1 {
    font-size: 28px;
    margin: 30px 0 15px;
    color: #2c3e50;
}

.article-content h2 {
    font-size: 24px;
    margin: 25px 0 12px;
    color: #34495e;
}

.article-content h3 {
    font-size: 20px;
    margin: 20px 0 10px;
    color: #34495e;
}

.article-content p {
    margin-bottom: 15px;
}

.article-content ul, .article-content ol {
    margin-left: 25px;
    margin-bottom: 15px;
}

.article-content li {
    margin-bottom: 8px;
}

/* 代码块容器样式 */
.article-content pre {
    background: #1e1e1e;
    padding: 20px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 20px 0;
}

/* 内联代码样式（非代码块中的 code，浅色主题） */
/* 注意：这个规则必须在 pre code 之前，以便 pre code 可以覆盖它 */
.article-content p code,
.article-content li code,
.article-content h1 code,
.article-content h2 code,
.article-content h3 code,
.article-content h4 code,
.article-content td code,
.article-content blockquote code {
    background: #f6f8fa !important;
    padding: 2px 6px !important;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 14px !important;
    color: #e83e8c !important;
}

/* 代码块内的 code 样式（深色主题，用于语法高亮） */
/* ⚠️ 这个规则必须在内联代码规则之后，以确保更高的优先级 */
/* 因为代码块可能在 <li> 中，导致 .article-content li code 也匹配 */
.article-content pre code {
    background: none !important;
    color: #e1e8ed !important;
    padding: 0 !important;
    font-size: 14px;
    border-radius: 0;
}

.article-content blockquote {
    border-left: 4px solid #667eea;
    padding-left: 20px;
    margin: 20px 0;
    color: #7f8c8d;
    font-style: italic;
}

.article-content a {
    color: #667eea;
    text-decoration: none;
}

.article-content a:hover {
    text-decoration: underline;
}

.article-content img {
    max-width: 100%;
    border-radius: 8px;
    margin: 20px 0;
}

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

.article-content th, .article-content td {
    padding: 12px;
    border: 1px solid #e1e8ed;
    text-align: left;
}

.article-content th {
    background: #f8f9fa;
    font-weight: 600;
}

/* 视频嵌入 */
.video-container {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 */
    height: 0;
    overflow: hidden;
    margin: 25px 0;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.video-container iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
}

/* 空状态 */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #7f8c8d;
}

.empty-state-icon {
    font-size: 64px;
    margin-bottom: 20px;
}

.empty-state h3 {
    font-size: 20px;
    margin-bottom: 10px;
}

/* 加载状态 */
.loading {
    text-align: center;
    padding: 40px;
    color: #7f8c8d;
}

.spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* 响应式设计 */
@media (max-width: 1200px) {
    .main-container {
        max-width: 100%;
        padding: 15px;
    }
    
    .sidebar {
        width: 280px;
        min-width: 280px;
    }
    
    .content-scrollable {
        padding: 30px;
    }
}

@media (max-width: 968px) {
    .main-container {
        flex-direction: column;
        height: auto;
        gap: 20px;
    }
    
    .sidebar {
        width: 100%;
        min-width: auto;
        height: 300px; /* 固定高度，保持独立滚动 */
        order: 2; /* 移到内容下方 */
    }
    
    .content-area {
        order: 1;
        height: 70vh; /* 移动端内容区域高度 */
    }
    
    .content-scrollable {
        padding: 25px;
    }
    
    .article-title {
        font-size: 24px;
    }
    
    .search-container {
        flex-direction: column;
        gap: 10px;
    }
    
    .search-input, .search-btn {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .main-container {
        padding: 10px;
    }
    
    .sidebar {
        height: 250px;
    }
    
    .content-area {
        height: 60vh;
    }
    
    .content-scrollable {
        padding: 20px;
    }
    
    .article-title {
        font-size: 20px;
    }
    
    .article-meta {
        flex-direction: column;
        gap: 10px;
    }
}

/* 可访问性增强 */
@media (prefers-reduced-motion: reduce) {
    .article-item,
    .search-btn {
        transition: none;
    }
    
    .spinner {
        animation: none;
    }
}

/* 高对比度模式支持 */
@media (prefers-contrast: high) {
    .sidebar {
        border: 2px solid #333;
    }
    
    .content-area {
        border: 2px solid #333;
    }
    
    .article-item:hover {
        background: #000;
        color: #fff;
    }
}

/* 焦点可见性 */
.article-item:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

.search-input:focus,
.search-btn:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* 打印样式 */
@media print {
    .sidebar,
    .search-bar {
        display: none;
    }
    
    .main-container {
        display: block;
        height: auto;
    }
    
    .content-area {
        box-shadow: none;
        border: 1px solid #ccc;
    }
}


/* ============================================
   锚点导航样式
   ============================================ */

.anchor-navigation {
    position: fixed;
    right: 20px;
    top: 100px;
    width: 220px;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    background: #1e1e1e;
    border: 1px solid #333;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 1000;
    transition: opacity 0.3s ease;
}

.anchor-navigation.hidden {
    opacity: 0;
    pointer-events: none;
}

.anchor-nav-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid #333;
}

.anchor-nav-title {
    font-size: 14px;
    font-weight: 600;
    color: #fff;
}

.anchor-nav-toggle {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    font-size: 18px;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease;
}

.anchor-nav-toggle:hover {
    color: #fff;
}

.anchor-nav-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.anchor-nav-item {
    margin: 5px 0;
}

.anchor-nav-link {
    display: block;
    padding: 6px 10px;
    color: #aaa;
    text-decoration: none;
    font-size: 13px;
    border-radius: 4px;
    transition: all 0.2s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.anchor-nav-link:hover {
    background: #2a2a2a;
    color: #fff;
}

.anchor-nav-link.active {
    background: #0d6efd;
    color: #fff;
}

/* 二级标题样式 */
.anchor-nav-item.level-2 .anchor-nav-link {
    font-weight: 600;
    padding-left: 10px;
}

/* 三级标题样式 */
.anchor-nav-item.level-3 .anchor-nav-link {
    padding-left: 25px;
    font-size: 12px;
}

/* 滚动条样式 */
.anchor-navigation::-webkit-scrollbar {
    width: 6px;
}

.anchor-navigation::-webkit-scrollbar-track {
    background: #1e1e1e;
    border-radius: 3px;
}

.anchor-navigation::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 3px;
}

.anchor-navigation::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* 响应式：小屏幕隐藏锚点导航 */
@media (max-width: 1400px) {
    .anchor-navigation {
        display: none;
    }
}
