/* ===== 全局重置与基础样式 ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --sidebar-width: 280px;
    --sidebar-bg: #f8f9fa;
    --sidebar-border: #e1e4e8;
    --content-bg: #ffffff;
    --text-primary: #24292e;
    --text-secondary: #586069;
    --text-muted: #959da5;
    --link-color: #0366d6;
    --hover-bg: #e8eaed;
    --active-bg: #dbeafe;
    --active-border: #3b82f6;
    --code-bg: #f6f8fa;
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

html, body {
    height: 100%;
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--content-bg);
}

body {
    display: flex;
    overflow: hidden;
}

/* ===== 侧边栏 ===== */
#sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: margin-left 0.3s ease;
    z-index: 100;
}

#sidebar.collapsed {
    margin-left: calc(-1 * var(--sidebar-width));
}

.sidebar-header {
    display: flex;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--sidebar-border);
    gap: 10px;
}

#sidebar-toggle {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px 8px;
    border-radius: 4px;
}

#sidebar-toggle:hover {
    background: var(--hover-bg);
}

.site-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-search {
    padding: 12px 16px;
    border-bottom: 1px solid var(--sidebar-border);
}

#search-input {
    width: 100%;
    padding: 6px 12px;
    border: 1px solid var(--sidebar-border);
    border-radius: 6px;
    font-size: 13px;
    outline: none;
    background: white;
}

#search-input:focus {
    border-color: var(--active-border);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* ===== 目录树 ===== */
.file-tree {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.file-tree .loading {
    padding: 16px;
    color: var(--text-muted);
    text-align: center;
    font-size: 13px;
}

.tree-item {
    display: flex;
    align-items: center;
    padding: 4px 16px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    text-decoration: none;
    user-select: none;
    transition: background 0.15s;
}

.tree-item:hover {
    background: var(--hover-bg);
}

.tree-item.active {
    background: var(--active-bg);
    color: var(--link-color);
    border-right: 3px solid var(--active-border);
    font-weight: 500;
}

.tree-item .icon {
    width: 18px;
    margin-right: 6px;
    text-align: center;
    flex-shrink: 0;
    font-size: 12px;
}

.tree-item .name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tree-children {
    display: none;
}

.tree-children.open {
    display: block;
}

.tree-children .tree-item {
    padding-left: 32px;
}

.tree-children .tree-children .tree-item {
    padding-left: 48px;
}

.tree-children .tree-children .tree-children .tree-item {
    padding-left: 64px;
}

.tree-folder-icon {
    display: inline-block;
    transition: transform 0.2s;
}

.tree-folder-icon.expanded {
    transform: rotate(90deg);
}

/* ===== 主内容区 ===== */
#content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    min-width: 0;
}

#breadcrumb {
    padding: 12px 24px;
    border-bottom: 1px solid var(--sidebar-border);
    font-size: 13px;
    color: var(--text-secondary);
    background: var(--sidebar-bg);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
}

.breadcrumb-item {
    color: var(--text-muted);
}

.breadcrumb-item a {
    color: var(--link-color);
    text-decoration: none;
}

.breadcrumb-item a:hover {
    text-decoration: underline;
}

.breadcrumb-sep {
    color: var(--text-muted);
    margin: 0 2px;
}

#article {
    flex: 1;
    overflow-y: auto;
    padding: 32px 48px;
    max-width: 100%;
}

/* ===== 欢迎页 ===== */
.welcome {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-secondary);
}

.welcome h2 {
    font-size: 24px;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.welcome p {
    font-size: 15px;
    margin-bottom: 8px;
}

/* ===== Markdown 内容样式 ===== */
.markdown-body {
    max-width: 900px;
    line-height: 1.7;
}

/* Markdown 内的代码块高亮样式（与独立代码文件共用 .code-block） */
.markdown-body .code-block {
    margin: 16px 0;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--sidebar-border);
}

.markdown-body .code-block .code-header {
    padding: 6px 12px;
    background: #f1f3f5;
    border-bottom: 1px solid var(--sidebar-border);
    font-size: 12px;
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
    margin-top: 24px;
    margin-bottom: 12px;
    font-weight: 600;
    line-height: 1.3;
}

.markdown-body h1 { font-size: 2em; border-bottom: 1px solid var(--sidebar-border); padding-bottom: 8px; }
.markdown-body h2 { font-size: 1.5em; border-bottom: 1px solid var(--sidebar-border); padding-bottom: 6px; }
.markdown-body h3 { font-size: 1.25em; }
.markdown-body h4 { font-size: 1em; }

.markdown-body p {
    margin-bottom: 16px;
}

.markdown-body a {
    color: var(--link-color);
    text-decoration: none;
}

.markdown-body a:hover {
    text-decoration: underline;
}

.markdown-body img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    margin: 12px 0;
}

.markdown-body blockquote {
    margin: 16px 0;
    padding: 8px 16px;
    border-left: 4px solid var(--active-border);
    background: var(--code-bg);
    color: var(--text-secondary);
}

.markdown-body pre {
    margin: 16px 0;
    padding: 16px;
    background: var(--code-bg);
    border-radius: 6px;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.5;
}

.markdown-body code {
    font-family: var(--font-mono);
    font-size: 0.9em;
    padding: 2px 6px;
    background: var(--code-bg);
    border-radius: 3px;
}

.markdown-body pre code {
    padding: 0;
    background: none;
}

.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
}

.markdown-body th,
.markdown-body td {
    padding: 8px 12px;
    border: 1px solid var(--sidebar-border);
    text-align: left;
}

.markdown-body th {
    background: var(--code-bg);
    font-weight: 600;
}

.markdown-body ul,
.markdown-body ol {
    margin: 12px 0;
    padding-left: 24px;
}

.markdown-body li {
    margin-bottom: 4px;
}

.markdown-body hr {
    border: none;
    border-top: 1px solid var(--sidebar-border);
    margin: 24px 0;
}

/* ===== Landing 首页样式 ===== */
body.landing-page {
    display: block;
    overflow-y: auto;
    background: #f0f2f5;
}

.landing-container {
    max-width: 960px;
    margin: 0 auto;
    padding: 48px 24px;
}

.landing-header {
    text-align: center;
    margin-bottom: 40px;
}

.landing-header h1 {
    font-size: 32px;
    font-weight: 700;
    color: #1a1a2e;
    margin-bottom: 8px;
}

.landing-subtitle {
    font-size: 16px;
    color: #666;
}

.tutorial-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.tutorial-card {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 24px;
    background: white;
    border-radius: 12px;
    border: 1px solid #e1e4e8;
    text-decoration: none;
    color: inherit;
    transition: all 0.2s ease;
}

.tutorial-card:hover {
    border-color: #3b82f6;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
    transform: translateY(-2px);
}

.card-icon {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0f4ff;
    border-radius: 10px;
    color: #3b82f6;
}

.card-content {
    flex: 1;
    min-width: 0;
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    color: #1a1a2e;
    margin-bottom: 6px;
}

.card-desc {
    font-size: 13px;
    color: #666;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ===== 代码高亮样式（chroma with classes） ===== */
.code-block {
    margin: 16px 0;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--sidebar-border);
}

.code-header {
    padding: 6px 12px;
    background: #f1f3f5;
    border-bottom: 1px solid var(--sidebar-border);
    font-size: 12px;
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

.code-block pre {
    margin: 0;
    padding: 12px;
    background: #f6f8fa;
    overflow-x: auto;
    font-size: 13px;
    line-height: 1.5;
}

.code-block table {
    border-collapse: collapse;
    width: 100%;
    margin: 0;
}

.code-block td {
    border: none;
    padding: 0;
}

.code-block .lnt {
    padding: 0 8px;
    color: #999;
    background: #f0f2f4;
    text-align: right;
    user-select: none;
    min-width: 3em;
}

.code-block .ln {
    padding: 0 8px;
    color: #999;
    background: #f0f2f4;
    text-align: right;
    user-select: none;
}

/* chroma 语法 token 颜色 */
.code-block .chroma { background: #f6f8fa; color: #24292e; }
.code-block .chroma .lntable { border-spacing: 0; padding: 0; margin: 0; border: 0; width: auto; overflow: auto; display: block; }
.code-block .chroma .lntd { vertical-align: top; padding: 0; margin: 0; border: 0; }

/* 关键字 */
.code-block .chroma .k  { color: #d73a49; } /* Keyword */
.code-block .chroma .kc { color: #005cc5; } /* KeywordConstant */
.code-block .chroma .kd { color: #d73a49; } /* KeywordDeclaration */
.code-block .chroma .kn { color: #d73a49; } /* KeywordNamespace */
.code-block .chroma .kp { color: #d73a49; } /* KeywordPseudo */
.code-block .chroma .kr { color: #d73a49; } /* KeywordReserved */
.code-block .chroma .kt { color: #6f42c1; } /* KeywordType */

/* 名称 */
.code-block .chroma .n  { color: #24292e; } /* Name */
.code-block .chroma .nb { color: #005cc5; } /* NameBuiltin */
.code-block .chroma .bp { color: #005cc5; } /* NameBuiltinPseudo */
.code-block .chroma .nc { color: #6f42c1; } /* NameClass */
.code-block .chroma .no { color: #005cc5; } /* NameConstant */
.code-block .chroma .nd { color: #e36209; } /* NameDecorator */
.code-block .chroma .ni { color: #e36209; } /* NameEntity */
.code-block .chroma .ne { color: #d73a49; } /* NameException */
.code-block .chroma .nf { color: #6f42c1; } /* NameFunction */
.code-block .chroma .nl { color: #005cc5; } /* NameLabel */
.code-block .chroma .nn { color: #6f42c1; } /* NameNamespace */
.code-block .chroma .nt { color: #22863a; } /* NameTag */
.code-block .chroma .nv { color: #e36209; } /* NameVariable */

/* 字符串 */
.code-block .chroma .s  { color: #032f62; } /* LiteralString */
.code-block .chroma .sa { color: #032f62; }
.code-block .chroma .sb { color: #032f62; }
.code-block .chroma .sc { color: #032f62; }
.code-block .chroma .sd { color: #032f62; }
.code-block .chroma .s2 { color: #032f62; }
.code-block .chroma .se { color: #032f62; }
.code-block .chroma .sh { color: #032f62; }
.code-block .chroma .si { color: #032f62; }
.code-block .chroma .sx { color: #032f62; }
.code-block .chroma .sr { color: #032f62; }
.code-block .chroma .s1 { color: #032f62; }
.code-block .chroma .ss { color: #005cc5; }

/* 数字 */
.code-block .chroma .m  { color: #005cc5; } /* LiteralNumber */
.code-block .chroma .mb { color: #005cc5; }
.code-block .chroma .mf { color: #005cc5; }
.code-block .chroma .mh { color: #005cc5; }
.code-block .chroma .mi { color: #005cc5; }
.code-block .chroma .il { color: #005cc5; }
.code-block .chroma .mo { color: #005cc5; }

/* 操作符 */
.code-block .chroma .o  { color: #d73a49; } /* Operator */
.code-block .chroma .ow { color: #d73a49; } /* OperatorWord */

/* 注释 */
.code-block .chroma .c  { color: #6a737d; font-style: italic; } /* Comment */
.code-block .chroma .ch { color: #6a737d; font-style: italic; }
.code-block .chroma .cm { color: #6a737d; font-style: italic; }
.code-block .chroma .cp { color: #d73a49; }
.code-block .chroma .cs { color: #6a737d; font-weight: bold; font-style: italic; }

/* Generic */
.code-block .chroma .g  { color: #24292e; }
.code-block .chroma .gd { color: #b31d28; background: #ffeef0; }
.code-block .chroma .ge { color: #24292e; font-style: italic; }
.code-block .chroma .gr { color: #b31d28; }
.code-block .chroma .gh { color: #005cc5; font-weight: bold; }
.code-block .chroma .gi { color: #22863a; background: #f0fff4; }
.code-block .chroma .go { color: #24292e; }
.code-block .chroma .gp { color: #735c0f; }
.code-block .chroma .gs { color: #24292e; font-weight: bold; }
.code-block .chroma .gu { color: #005cc5; }
.code-block .chroma .gt { color: #b31d28; }

/* ===== 目录列表视图（loadDir 渲染） ===== */
.dir-listing {
    max-width: 900px;
}

.dir-listing h2 {
    font-size: 20px;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--sidebar-border);
}

.dir-items {
    list-style: none;
    padding: 0;
}

.dir-item {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    border-radius: 6px;
    transition: background 0.15s;
}

.dir-item:hover {
    background: var(--hover-bg);
}

.dir-icon {
    width: 24px;
    margin-right: 10px;
    text-align: center;
    flex-shrink: 0;
    font-size: 14px;
}

.dir-item a {
    color: var(--link-color);
    text-decoration: none;
    font-size: 14px;
}

.dir-item a:hover {
    text-decoration: underline;
}

.dir-item.dir a {
    font-weight: 500;
}

/* ===== 纯文本展示 ===== */
.plain-text {
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.5;
    padding: 16px;
    background: var(--code-bg);
    border-radius: 6px;
    overflow-x: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* ===== 移动端遮罩 ===== */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 99;
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
    #sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
    }

    #sidebar.collapsed {
        margin-left: calc(-1 * var(--sidebar-width));
        box-shadow: none;
    }

    .sidebar-overlay.visible {
        display: block;
    }

    #article {
        padding: 20px 16px;
    }
}

/* ===== 滚动条美化 ===== */
.file-tree::-webkit-scrollbar,
#article::-webkit-scrollbar {
    width: 6px;
}

.file-tree::-webkit-scrollbar-thumb,
#article::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.file-tree::-webkit-scrollbar-thumb:hover,
#article::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

/* ===== 搜索高亮 ===== */
.tree-item.search-match .name {
    color: var(--link-color);
    font-weight: 500;
}

.tree-item.search-hidden {
    display: none;
}

/* ===== 认证区域 ===== */
.auth-area {
    max-width: 400px;
    margin: 0 auto 32px;
}

.auth-box {
    display: flex;
    gap: 8px;
}

/* ===== 管理页面通用样式 ===== */
.back-link {
    color: var(--link-color);
    text-decoration: none;
    font-size: 14px;
}
.back-link:hover { text-decoration: underline; }

.admin-link {
    display: inline-block;
    margin-top: 12px;
    padding: 6px 16px;
    background: #f0f4ff;
    color: #3b82f6;
    text-decoration: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}
.admin-link:hover {
    background: #3b82f6;
    color: #fff;
}

.section-title {
    font-size: 18px;
    font-weight: 600;
    color: #1a1a2e;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid #e1e4e8;
}

.tutorial-manage-area,
.change-pwd-area {
    margin-bottom: 32px;
}

/* ===== 登录卡片 ===== */
.login-card {
    max-width: 420px;
    margin: 40px auto;
    background: #fff;
    border-radius: 12px;
    border: 1px solid #e1e4e8;
    padding: 32px;
}

.login-title {
    font-size: 20px;
    font-weight: 600;
    color: #1a1a2e;
    margin-bottom: 24px;
    text-align: center;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.login-status {
    font-size: 13px;
    text-align: center;
    min-height: 18px;
}
.login-status.error { color: #d73a49; }
.login-status.success { color: #1a7f37; }

.login-hint {
    margin-top: 16px;
    font-size: 12px;
    color: #959da5;
    text-align: center;
}

/* ===== 表单组件 ===== */
.form-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-row label {
    font-size: 13px;
    font-weight: 500;
    color: #24292e;
}

.form-input {
    padding: 10px 14px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    background: #fff;
    transition: border-color 0.2s;
}

.form-input:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.btn-primary {
    padding: 10px 20px;
    background: #3b82f6;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: #2563eb;
}

.btn-full {
    width: 100%;
}

/* ===== 修改密码区域 ===== */
.change-pwd-box {
    max-width: 420px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.change-pwd-status {
    font-size: 13px;
    min-height: 18px;
}
.change-pwd-status.error { color: #d73a49; }
.change-pwd-status.success { color: #1a7f37; }

/* ===== 首页：上传区域 ===== */
.upload-area {
    margin-bottom: 32px;
}

.upload-box {
    border: 2px dashed #c7d0db;
    border-radius: 12px;
    padding: 28px 24px;
    text-align: center;
    cursor: pointer;
    background: #fff;
    transition: all 0.2s ease;
}

.upload-box:hover,
.upload-box.drag {
    border-color: #3b82f6;
    background: #f6f9ff;
}

.upload-box.drag {
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.12);
}

.upload-icon {
    color: #3b82f6;
    margin-bottom: 8px;
}

.upload-text {
    font-size: 15px;
    color: #24292e;
    font-weight: 500;
    margin-bottom: 4px;
}

.upload-hint {
    font-size: 12px;
    color: #959da5;
}

.upload-status {
    margin-top: 12px;
    font-size: 13px;
    text-align: center;
    min-height: 18px;
}

.upload-status.info { color: #0366d6; }
.upload-status.success { color: #1a7f37; }
.upload-status.error { color: #d73a49; }

/* ===== 状态栏 ===== */
.auth-bar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    margin-bottom: 24px;
    padding: 8px 16px;
    background: #f0f4ff;
    border-radius: 8px;
}

.auth-status-text {
    font-size: 13px;
    color: #3b82f6;
    font-weight: 500;
}

.logout-btn {
    padding: 4px 12px;
    background: transparent;
    color: #666;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.logout-btn:hover {
    background: #f3f4f6;
    color: #333;
}

/* ===== 首页：卡片包裹与删除按钮 ===== */
.tutorial-card-wrap {
    position: relative;
}

.tutorial-card-wrap .tutorial-card {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 24px;
    background: white;
    border-radius: 12px;
    border: 1px solid #e1e4e8;
    text-decoration: none;
    color: inherit;
    transition: all 0.2s ease;
}

.tutorial-card-wrap .tutorial-card:hover {
    border-color: #3b82f6;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
    transform: translateY(-2px);
}

.delete-btn {
    position: absolute;
    top: 8px;
    right: 10px;
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.04);
    color: #959da5;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    z-index: 2;
}

.delete-btn:hover {
    background: #d73a49;
    color: #fff;
}

/* ===== 首页：空状态 ===== */
.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 48px 20px;
    color: #959da5;
}

.empty-state svg {
    color: #c7d0db;
    margin-bottom: 12px;
}

.empty-state p {
    font-size: 15px;
}

