/* ---------- 全局重置 & 基础 ---------- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --primary-light: #eff6ff;
    --border-color: #e5e7eb;
    --bg-sidebar: #f8fafc;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --sidebar-width: 300px;
}

body {
    background: #f1f5f9;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.6;
    color: var(--text-main);
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
}

/* ---------- 布局容器 ---------- */
.blog-wrapper {
    display: flex;
    min-height: 100vh;
    max-width: 1440px;
    margin: 0 auto;
    background: #ffffff;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.03);
}

/* ---------- 左侧边栏 ---------- */
.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    padding: 1.25rem 1rem 2rem 1rem;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    height: 100vh;
    position: sticky;
    top: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
}

/* 折叠状态（桌面端） */
body.sidebar-collapsed .sidebar {
    width: 0;
    padding-left: 0;
    padding-right: 0;
    border-right-color: transparent;
    overflow: hidden;
}

/* ---------- Tab 样式按钮 ---------- */
.sidebar-tab-bar {
    display: flex;
    align-items: center;
    margin-bottom: 1.2rem;
}

.top-tab-header {
    display: none;
    margin-bottom: 1.5rem;
}

.tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.9rem;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-main);
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    transition: all 0.2s ease;
}

.tab-btn:hover {
    background: #ffffff;
    border-color: #cbd5e1;
    color: var(--primary-color);
}

.tab-btn.active {
    background: var(--primary-color);
    color: #ffffff;
    border-color: var(--primary-color);
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}

.tab-btn .tab-icon {
    font-size: 1rem;
}

/* 折叠时，顶部按钮在主区显示 */
body.sidebar-collapsed .top-tab-header {
    display: flex;
}

/* ---------- 简介区域 ---------- */
.intro {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.intro h2 {
    font-size: 1.15rem;
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 0.3rem;
}

.intro p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ---------- 目录区域优化 ---------- */
.toc {
    flex: 1;
}

.toc h3 {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.toc-tree, .toc-subfolder {
    list-style: none;
    padding-left: 0;
}

.toc-folder {
    margin-bottom: 0.25rem;
}

.toc-folder-title {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.88rem;
    font-weight: 600;
    color: #334155;
    padding: 0.45rem 0.6rem;
    border-radius: 6px;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.toc-folder-title:hover {
    background-color: #f1f5f9;
    color: #0f172a;
}

.toc-subfolder {
    border-left: 1.5px solid #e2e8f0;
    margin-left: 0.8rem;
    padding-left: 0.4rem;
    transition: all 0.2s ease;
}

.toc-article a {
    display: flex;
    align-items: center;
    font-size: 0.85rem;
    color: #475569;
    text-decoration: none;
    padding: 0.4rem 0.6rem;
    margin: 0.1rem 0;
    border-radius: 6px;
    transition: all 0.15s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.toc-article a:hover {
    background-color: #f1f5f9;
    color: var(--primary-color);
}

/* 当前高亮文章 */
.toc-article a.active {
    background-color: var(--primary-light);
    color: var(--primary-color);
    font-weight: 600;
}

/* 折叠/展开箭头 */
.folder-toggle {
    font-size: 0.65rem;
    color: #94a3b8;
    width: 1rem;
    display: inline-flex;
    justify-content: center;
    transition: transform 0.2s ease;
}

.toc-folder-title.collapsed .folder-toggle {
    transform: rotate(-90deg);
}

/* ---------- 右侧主内容区域 ---------- */
.main-content {
    flex: 1;
    padding: 2.5rem 3rem;
    background: #ffffff;
    overflow-y: auto;
    min-height: 100vh;
    min-width: 0;
}

.main-content h1 {
    font-size: 1.75rem;
    font-weight: 700;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
    margin-bottom: 1.25rem;
    color: #0f172a;
}

.main-content p {
    margin-bottom: 1rem;
    color: #334155;
}

/* ---------- 移动端遮罩层 ---------- */
.sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.4);
    z-index: 90;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    backdrop-filter: blur(4px);
}

/* ---------- 状态控制 ---------- */
.toc-loading {
    font-size: 0.85rem;
    color: var(--text-muted);
    padding: 0.5rem 0;
}

/* ---------- 响应式 (大屏/小屏适配) ---------- */
@media (max-width: 768px) {
    .top-tab-header {
        display: flex;
    }

    /* 移动端 sidebar 转为抽屉风格 */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: 82vw;
        max-width: 320px;
        transform: translateX(0);
        box-shadow: 10px 0 25px rgba(0, 0, 0, 0.1);
        border-right: none;
        transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    }

    body.sidebar-collapsed .sidebar {
        width: 82vw;
        max-width: 320px;
        padding: 1.25rem 1rem 2rem 1rem;
        transform: translateX(-100%);
    }

    body:not(.sidebar-collapsed) .sidebar-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    .main-content {
        padding: 1.25rem 1.25rem 2rem 1.25rem;
    }
}