/* ===== Reset & Base ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --sidebar-width: 280px;
    --header-height: 56px;
    --color-primary: #3f51b5;
    --color-primary-light: #e8eaf6;
    --color-bg: #fff;
    --color-bg-gray: #f5f7fa;
    --color-text: #333;
    --color-text-light: #666;
    --color-text-muted: #999;
    --color-border: #e8e8e8;
    --color-link: #3f51b5;
    --color-code-bg: #f6f8fa;
    --color-sidebar-bg: #fafbfc;
    --color-sidebar-hover: #eef1f6;
    --color-sidebar-active: #e8eaf6;
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
    --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.7;
}

a {
    color: var(--color-link);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ===== Header ===== */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    padding: 0 20px;
    z-index: 100;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 18px;
    font-weight: 700;
    color: var(--color-text);
    min-width: calc(var(--sidebar-width) - 40px);
}

.header-logo svg {
    width: 28px;
    height: 28px;
    fill: var(--color-primary);
}

.header-search {
    flex: 1;
    max-width: 480px;
    position: relative;
}

.header-search input {
    width: 100%;
    height: 36px;
    padding: 0 16px 0 38px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 14px;
    background: var(--color-bg-gray);
    outline: none;
    transition: all 0.2s;
}

.header-search input:focus {
    border-color: var(--color-primary);
    background: var(--color-bg);
    box-shadow: 0 0 0 3px rgba(63, 81, 181, 0.1);
}

.header-search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-text-muted);
}

.header-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-right a {
    color: var(--color-text-light);
    font-size: 14px;
    padding: 6px 12px;
    border-radius: 4px;
    transition: background 0.2s;
}

.header-right a:hover {
    background: var(--color-bg-gray);
    text-decoration: none;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: var(--color-text);
}

/* ===== Layout ===== */
.layout {
    display: flex;
    padding-top: var(--header-height);
    min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--color-sidebar-bg);
    border-right: 1px solid var(--color-border);
    overflow-y: auto;
    padding: 16px 0;
    z-index: 50;
    transition: transform 0.3s ease;
}

.sidebar-section {
    margin-bottom: 8px;
}

.sidebar-section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 20px;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    user-select: none;
}

.sidebar-section-title:hover {
    color: var(--color-text-light);
}

.sidebar-section-title svg {
    width: 14px;
    height: 14px;
    transition: transform 0.2s;
}

.sidebar-section.collapsed .sidebar-section-title svg {
    transform: rotate(-90deg);
}

.sidebar-section.collapsed .sidebar-links {
    display: none;
}

.sidebar-links {
    list-style: none;
}

.sidebar-link {
    display: block;
    padding: 6px 20px 6px 36px;
    font-size: 14px;
    color: var(--color-text-light);
    border-left: 3px solid transparent;
    transition: all 0.15s;
}

.sidebar-link:hover {
    color: var(--color-text);
    background: var(--color-sidebar-hover);
    text-decoration: none;
}

.sidebar-link.active {
    color: var(--color-primary);
    background: var(--color-sidebar-active);
    border-left-color: var(--color-primary);
    font-weight: 500;
}

.sidebar-subsection {
    list-style: none;
}

.sidebar-subsection-title {
    display: block;
    padding: 8px 20px 4px 36px;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-muted);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 40;
}

/* ===== Content ===== */
.content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 32px 48px 64px;
    max-width: 900px;
    min-width: 0;
}

/* Breadcrumb */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--color-text-muted);
    margin-bottom: 16px;
}

.breadcrumb a {
    color: var(--color-text-muted);
}

.breadcrumb a:hover {
    color: var(--color-primary);
}

.breadcrumb-sep {
    color: var(--color-border);
}

/* Article */
.article h1 {
    font-size: 32px;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 8px;
    color: var(--color-text);
}

.article-meta {
    font-size: 13px;
    color: var(--color-text-muted);
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--color-border);
}

.article h2 {
    font-size: 24px;
    font-weight: 600;
    margin-top: 40px;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--color-border);
}

.article h3 {
    font-size: 20px;
    font-weight: 600;
    margin-top: 32px;
    margin-bottom: 12px;
}

.article h4 {
    font-size: 17px;
    font-weight: 600;
    margin-top: 24px;
    margin-bottom: 8px;
}

.article p {
    margin-bottom: 16px;
}

.article ul, .article ol {
    margin-bottom: 16px;
    padding-left: 24px;
}

.article li {
    margin-bottom: 6px;
}

.article code {
    font-family: var(--font-mono);
    font-size: 0.9em;
    background: var(--color-code-bg);
    padding: 2px 6px;
    border-radius: 4px;
    color: #e53935;
}

.article pre {
    background: #1e1e1e;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    overflow-x: auto;
}

.article pre code {
    background: none;
    color: #d4d4d4;
    padding: 0;
    font-size: 14px;
    line-height: 1.6;
}

.article blockquote {
    border-left: 4px solid var(--color-primary);
    background: var(--color-primary-light);
    padding: 12px 20px;
    margin-bottom: 16px;
    border-radius: 0 4px 4px 0;
}

.article blockquote p {
    margin-bottom: 0;
}

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

.article th, .article td {
    border: 1px solid var(--color-border);
    padding: 10px 14px;
    text-align: left;
}

.article th {
    background: var(--color-bg-gray);
    font-weight: 600;
}

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

.article hr {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: 32px 0;
}

/* Tip/Warning boxes */
.tip-box {
    padding: 16px 20px;
    border-radius: 6px;
    margin-bottom: 20px;
    font-size: 14px;
}

.tip-box.info {
    background: #e3f2fd;
    border-left: 4px solid #2196f3;
}

.tip-box.warning {
    background: #fff3e0;
    border-left: 4px solid #ff9800;
}

.tip-box.success {
    background: #e8f5e9;
    border-left: 4px solid #4caf50;
}

.tip-box-title {
    font-weight: 600;
    margin-bottom: 4px;
}

/* Error page */
.error-page {
    text-align: center;
    padding: 80px 20px;
    max-width: 480px;
    margin: 0 auto;
}

.error-page-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 24px;
    background: var(--color-bg-gray);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.error-page-icon svg {
    width: 40px;
    height: 40px;
    color: var(--color-text-muted);
}

.error-page h2 {
    font-size: 64px;
    font-weight: 700;
    color: var(--color-primary);
    border: none;
    margin-bottom: 8px;
    line-height: 1;
}

.error-page-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 8px;
}

.error-page-desc {
    font-size: 15px;
    color: var(--color-text-light);
    margin-bottom: 16px;
}

.error-page-hint {
    font-size: 13px;
    color: var(--color-text-muted);
    margin-bottom: 32px;
}

.error-page-hint code {
    background: var(--color-code-bg);
    padding: 2px 8px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 12px;
}

.error-page-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.error-btn {
    display: inline-block;
    padding: 10px 24px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s;
}

.error-btn-primary {
    background: var(--color-primary);
    color: #fff;
}

.error-btn-primary:hover {
    background: #303f9f;
}

.error-btn-secondary {
    background: var(--color-bg-gray);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.error-btn-secondary:hover {
    background: var(--color-border);
}

/* ===== TOC (Table of Contents) ===== */
.toc {
    position: fixed;
    right: 24px;
    top: calc(var(--header-height) + 32px);
    width: 200px;
    font-size: 13px;
}

.toc-title {
    font-weight: 600;
    color: var(--color-text-muted);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 12px;
}

.toc-list {
    list-style: none;
    border-left: 2px solid var(--color-border);
}

.toc-list a {
    display: block;
    padding: 4px 12px;
    color: var(--color-text-muted);
    border-left: 2px solid transparent;
    margin-left: -2px;
    transition: all 0.15s;
}

.toc-list a:hover {
    color: var(--color-text);
    text-decoration: none;
}

.toc-list a.active {
    color: var(--color-primary);
    border-left-color: var(--color-primary);
}

.toc-list .toc-h3 {
    padding-left: 24px;
}

/* ===== Pagination ===== */
.pagination {
    display: flex;
    justify-content: space-between;
    margin-top: 48px;
    padding-top: 24px;
    border-top: 1px solid var(--color-border);
}

.pagination a {
    display: flex;
    flex-direction: column;
    padding: 12px 16px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    max-width: 45%;
    transition: all 0.2s;
}

.pagination a:hover {
    border-color: var(--color-primary);
    background: var(--color-primary-light);
    text-decoration: none;
}

.pagination-label {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-bottom: 4px;
}

.pagination-title {
    font-size: 15px;
    font-weight: 500;
    color: var(--color-primary);
}

.pagination .next {
    text-align: right;
    margin-left: auto;
}

/* ===== Search Results ===== */
.search-results {
    display: none;
}

.search-results.active {
    display: block;
}

.search-results-page {
    padding: 0;
}

.search-results-page h2 {
    margin-bottom: 8px;
}

.search-result-item {
    padding: 16px 0;
    border-bottom: 1px solid var(--color-border);
}

.search-result-item h3 {
    font-size: 16px;
    margin-bottom: 4px;
    margin-top: 0;
    padding-bottom: 0;
    border: none;
}

.search-result-item .search-path {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-bottom: 6px;
}

.search-result-item .search-snippet {
    font-size: 14px;
    color: var(--color-text-light);
    line-height: 1.6;
}

.search-result-item .search-snippet mark {
    background: #fff176;
    padding: 1px 2px;
    border-radius: 2px;
}

/* ===== Footer ===== */
.footer {
    margin-left: var(--sidebar-width);
    padding: 24px 48px;
    border-top: 1px solid var(--color-border);
    font-size: 13px;
    color: var(--color-text-muted);
    text-align: center;
}

/* ===== Responsive ===== */
@media (max-width: 1200px) {
    .toc {
        display: none;
    }
}

@media (max-width: 768px) {
    .menu-toggle {
        display: block;
    }

    .header-logo {
        min-width: auto;
    }

    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.open {
        display: block;
    }

    .content {
        margin-left: 0;
        padding: 24px 20px 48px;
    }

    .footer {
        margin-left: 0;
        padding: 24px 20px;
    }

    .article h1 {
        font-size: 26px;
    }

    .pagination {
        flex-direction: column;
        gap: 12px;
    }

    .pagination a {
        max-width: 100%;
    }
}

/* ===== Scrollbar ===== */
.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-muted);
}
