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

:root {
    --sidebar-width: 280px;
    --toc-width: 240px;
    --header-height: 56px;
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-sidebar: #f1f5f9;
    --bg-code: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --accent-color: #3b82f6;
    --accent-hover: #2563eb;
    --accent-light: #eff6ff;
    --danger-color: #ef4444;
    --success-color: #22c55e;
    --radius: 8px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
    --transition: 0.2s ease;
}

/* Dark theme */
[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-sidebar: #1e293b;
    --bg-code: #1e293b;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: #334155;
    --accent-color: #60a5fa;
    --accent-hover: #3b82f6;
    --accent-light: #1e3a5f;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.3);
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans SC', sans-serif;
    color: var(--text-primary);
    background: var(--bg-secondary);
    line-height: 1.7;
    overflow-x: hidden;
}

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

a:hover {
    color: var(--accent-hover);
}

/* ===== Header ===== */
.site-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: rgba(255,255,255,0.95);
    border-bottom: 1px solid var(--border-color);
    z-index: 100;
    backdrop-filter: blur(8px);
}

[data-theme="dark"] .site-header {
    background: rgba(15,23,42,0.95);
}

.header-inner {
    max-width: 1400px;
    margin: 0 auto;
    height: 100%;
    display: flex;
    align-items: center;
}

.site-header .logo {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.site-header .logo svg {
    width: 24px;
    height: 24px;
    color: var(--accent-color);
}

.site-header .logo-img {
    height: 28px;
    max-width: 120px;
    object-fit: contain;
}

.site-header .logo-text {
    font-size: 16px;
    font-weight: 800;
    letter-spacing: 0.05em;
    color: var(--accent-color);
}

/* Header navigation links */
.header-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 20px;
}

.header-nav-link {
    padding: 6px 12px;
    font-size: 14px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius);
    transition: all var(--transition);
    white-space: nowrap;
}

.header-nav-link:hover {
    color: var(--text-primary);
    background: var(--bg-secondary);
}

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

/* Theme toggle button */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: none;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--text-secondary);
    transition: all var(--transition);
    flex-shrink: 0;
}

.theme-toggle:hover {
    color: var(--accent-color);
    border-color: var(--accent-color);
    background: var(--accent-light);
}

.theme-toggle svg {
    width: 18px;
    height: 18px;
}

/* Light mode: show sun (click to go dark), hide moon */
.theme-toggle .sun-icon {
    display: block;
}

.theme-toggle .moon-icon {
    display: none;
}

/* Dark mode: show moon (click to go light), hide sun */
[data-theme="dark"] .theme-toggle .sun-icon {
    display: none;
}

[data-theme="dark"] .theme-toggle .moon-icon {
    display: block;
}

/* Search box */
.search-box {
    position: relative;
    width: 260px;
}

.search-box input {
    width: 100%;
    height: 36px;
    padding: 0 12px 0 36px;
    border: 1px solid var(--border-color);
    border-radius: 18px;
    font-size: 14px;
    outline: none;
    transition: all var(--transition);
    background: var(--bg-secondary);
}

.search-box input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
    background: var(--bg-primary);
}

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

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 8px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    max-height: 400px;
    overflow-y: auto;
    display: none;
    z-index: 200;
}

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

.search-result-item {
    display: block;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-color);
    transition: background var(--transition);
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background: var(--accent-light);
}

.search-result-item .result-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.search-result-item .result-snippet {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.search-result-item .result-path {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Sidebar toggle */
.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: var(--text-secondary);
    border-radius: var(--radius);
    transition: background var(--transition);
}

.sidebar-toggle:hover {
    background: var(--bg-secondary);
}

.sidebar-toggle svg {
    width: 20px;
    height: 20px;
}

/* ===== Layout ===== */
.layout {
    display: flex;
    margin: 0 auto;
    max-width: 1400px;
    padding-top: var(--header-height);
    min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: calc(100vh - var(--header-height));
    position: sticky;
    top: var(--header-height);
    flex-shrink: 0;
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px 0;
    transition: transform 0.3s ease;
}

.sidebar::-webkit-scrollbar {
    width: 4px;
}

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

.sidebar-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 8px 20px 8px;
}

/* Tree */
.tree-list {
    list-style: none;
    padding: 0;
}

.tree-item {
    list-style: none;
}

.tree-item .tree-item {
    padding-left: 16px;
}

.tree-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 20px;
    font-size: 14px;
    color: var(--text-secondary);
    transition: all var(--transition);
    border-left: 3px solid transparent;
    cursor: pointer;
}

.tree-link:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.tree-link.active {
    background: var(--accent-light);
    color: var(--accent-color);
    border-left-color: var(--accent-color);
    font-weight: 500;
}

.tree-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    cursor: pointer;
    flex-shrink: 0;
    margin-left: auto;
    position: relative;
}

.tree-toggle::before {
    content: '';
    width: 5px;
    height: 5px;
    border-right: 1.5px solid #7f8c99;
    border-bottom: 1.5px solid #7f8c99;
    transform: rotate(45deg);
    transition: transform 0.2s ease;
}

.tree-toggle.expanded::before {
    transform: rotate(-135deg);
}

.tree-toggle.hidden {
    visibility: hidden;
}


.tree-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tree-children {
    list-style: none;
    padding: 0;
    overflow: hidden;
}

.tree-children.collapsed {
    display: none;
}

/* ===== Main Content ===== */
.content-area {
    flex: 1;
    min-width: 0;
    display: flex;
}

.main-content {
    flex: 1;
    padding: 32px 40px 80px;
    min-width: 0;
    overflow-x: hidden;
}

/* Welcome page */
.welcome-page {
    text-align: center;
    padding: 80px 20px;
}

.welcome-page h1 {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 12px;
}

.welcome-page p {
    color: var(--text-secondary);
    font-size: 16px;
    margin-bottom: 24px;
}

.welcome-page .empty-hint {
    color: var(--text-muted);
    font-size: 14px;
}

/* Error page */
.error-page {
    text-align: center;
    padding: 80px 20px;
}

.error-page .error-code {
    font-size: 64px;
    font-weight: 800;
    color: var(--border-color);
    margin-bottom: 16px;
}

.error-page h1 {
    font-size: 24px;
    margin-bottom: 8px;
}

.error-page p {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.error-page a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    background: var(--accent-color);
    color: white;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
}

.error-page a:hover {
    background: var(--accent-hover);
    color: white;
}

/* Directory listing */
.directory-page h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 24px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border-color);
}

/* Breadcrumb */
.breadcrumb {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 20px;
    word-break: break-all;
}

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

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

/* Section title */
.dir-section-title {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin: 20px 0 8px;
}

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

.doc-list-item {
    border-bottom: 1px solid var(--border-color);
}

.doc-list-item a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 0;
    font-size: 16px;
    color: var(--text-primary);
    transition: color var(--transition);
}

.doc-list-item a:hover {
    color: var(--accent-color);
}

.doc-list-item .doc-icon {
    color: var(--accent-color);
    flex-shrink: 0;
    width: 20px;
    height: 20px;
}

.doc-list-item .doc-info {
    flex: 1;
}

.doc-list-item .doc-title {
    font-weight: 500;
}

.doc-list-item .doc-path {
    font-size: 12px;
    color: var(--text-muted);
}

/* ===== Markdown Content ===== */
.md-content {
    font-size: 16px;
    line-height: 1.8;
    color: var(--text-primary);
}

.md-content h1, .md-content h2, .md-content h3,
.md-content h4, .md-content h5, .md-content h6 {
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    font-weight: 600;
    line-height: 1.4;
    color: var(--text-primary);
}

.md-content h1 {
    font-size: 2em;
    padding-bottom: 0.3em;
    border-bottom: 1px solid var(--border-color);
}

.md-content h2 {
    font-size: 1.5em;
    padding-bottom: 0.25em;
    border-bottom: 1px solid var(--border-color);
}

.md-content h3 { font-size: 1.25em; }
.md-content h4 { font-size: 1.1em; }

.md-content p {
    margin-bottom: 1em;
}

.md-content a {
    color: var(--accent-color);
    text-decoration: underline;
    text-decoration-color: rgba(59,130,246,0.3);
    text-underline-offset: 2px;
}

.md-content a:hover {
    text-decoration-color: var(--accent-color);
}

.md-content strong {
    font-weight: 600;
}

.md-content ul, .md-content ol {
    margin-bottom: 1em;
    padding-left: 2em;
}

.md-content li {
    margin-bottom: 0.25em;
}

.md-content li > ul, .md-content li > ol {
    margin-top: 0.25em;
    margin-bottom: 0;
}

.md-content blockquote {
    margin: 1em 0;
    padding: 12px 20px;
    border-left: 4px solid var(--accent-color);
    background: var(--accent-light);
    color: var(--text-secondary);
    border-radius: 0 var(--radius) var(--radius) 0;
}

.md-content blockquote p:last-child {
    margin-bottom: 0;
}

.md-content code {
    font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;
    font-size: 0.875em;
    padding: 2px 6px;
    background: var(--bg-code);
    border-radius: 4px;
    color: #e11d48;
}

.md-content pre {
    margin: 1em 0;
    padding: 16px;
    background: #1e293b;
    border-radius: var(--radius);
    overflow-x: auto;
    border: 1px solid #334155;
}

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

/* Copy button for code blocks */
.md-content pre {
    position: relative;
}

.copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    font-size: 12px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans SC', sans-serif;
    color: #94a3b8;
    background: #334155;
    border: 1px solid #475569;
    border-radius: 4px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease, color 0.2s ease, background 0.2s ease;
    line-height: 1.4;
    z-index: 1;
}

.md-content pre:hover .copy-btn {
    opacity: 1;
}

.copy-btn:hover {
    color: #e2e8f0;
    background: #475569;
}

.copy-btn.copied {
    color: #4ade80;
    background: #1e3a5f;
    border-color: #22c55e;
}

/* Always show copy button on small screens (touch devices) */
@media (max-width: 900px) {
    .copy-btn {
        opacity: 1;
    }
}

.md-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1em 0;
    font-size: 14px;
}

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

.md-content th {
    background: var(--bg-secondary);
    font-weight: 600;
}

.md-content tr:nth-child(even) {
    background: var(--bg-secondary);
}

.md-content img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
    margin: 1em 0;
}

.md-content hr {
    margin: 2em 0;
    border: none;
    border-top: 1px solid var(--border-color);
}

.md-content input[type="checkbox"] {
    margin-right: 6px;
}

/* ===== Right TOC (Table of Contents) ===== */
.toc-panel {
    width: var(--toc-width);
    min-width: var(--toc-width);
    height: calc(100vh - var(--header-height));
    position: sticky;
    top: var(--header-height);
    overflow-y: auto;
    padding: 24px 16px 40px 20px;
    border-left: 1px solid var(--border-color);
    background: var(--bg-primary);
    transition: opacity 0.3s ease;
}

.toc-panel::-webkit-scrollbar {
    width: 3px;
}

.toc-panel::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

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

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

.toc-item {
    margin-bottom: 2px;
}

.toc-link {
    display: block;
    padding: 4px 0 4px 12px;
    font-size: 13px;
    color: var(--text-muted);
    text-decoration: none;
    border-left: 2px solid transparent;
    transition: all var(--transition);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
    line-height: 1.5;
}

.toc-link:hover {
    color: var(--text-primary);
    background: var(--bg-secondary);
}

.toc-link.active {
    color: var(--accent-color);
    border-left-color: var(--accent-color);
    font-weight: 500;
}

.toc-link[data-level="3"] {
    padding-left: 24px;
    font-size: 12px;
}

.toc-link[data-level="4"] {
    padding-left: 36px;
    font-size: 12px;
}

.toc-link[data-level="5"],
.toc-link[data-level="6"] {
    padding-left: 44px;
    font-size: 12px;
}

.toc-empty {
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
    padding: 20px 0;
}

/* ===== Loading ===== */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px;
    color: var(--text-muted);
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 12px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== Footer ===== */
/* ===== Back to Top ===== */
.back-to-top {
    position: fixed;
    bottom: 32px;
    right: 32px;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    opacity: 0;
    visibility: hidden;
    transform: translateY(12px);
    transition: all 0.2s ease;
    z-index: 999;
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.back-to-top:hover {
    background: var(--bg-secondary);
    border-color: var(--accent-color);
    color: var(--accent-color);
}

.back-to-top svg {
    width: 20px;
    height: 20px;
}

.content-footer {
    margin-top: 48px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
}

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

@media (max-width: 900px) {
    .layout {
        flex-direction: column;
    }

    .content-area {
        margin-left: 0;
        display: block;
    }

    .main-content {
        padding: 24px 20px 80px;
    }

    .sidebar {
        position: fixed;
        top: var(--header-height);
        left: 0;
        height: calc(100vh - var(--header-height));
        transform: translateX(-100%);
        z-index: 90;
        box-shadow: var(--shadow-md);
    }

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

    .sidebar-toggle {
        display: block;
    }

    .search-box {
        width: 180px;
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        top: var(--header-height);
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.3);
        z-index: 80;
    }

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

@media (max-width: 680px) {
    .search-box {
        display: none;
    }

    .main-content {
        padding: 16px 16px 80px;
    }

    .md-content pre {
        padding: 12px;
        font-size: 13px;
    }
}
