/* ========================================
   教程文档系统 - 前台样式
   ======================================== */

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

:root {
    --primary: #3451b2;
    --primary-light: #f0f2ff;
    --bg: #f6f6f7;
    --white: #ffffff;
    --text: #213547;
    --text-soft: #3c5a73;
    --text-muted: #8e8e8e;
    --border: #e2e2e3;
    --radius: 4px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.04);
    --shadow: 0 2px 6px rgba(0,0,0,.06);
    --transition: .15s ease;
    --sidebar-width: 260px;
    --header-height: 52px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.65;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: #1e3ea5; }

img { max-width: 100%; height: auto; }

/* --- Header --- */
.header {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 100;
    height: var(--header-height);
}

.header-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    letter-spacing: -.01em;
}
.logo svg { flex-shrink: 0; }

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-actions .btn {
    padding: 6px 14px;
    background: var(--text);
    color: #fff;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    border: none;
    cursor: pointer;
}
.header-actions .btn:hover { background: #000; color: #fff; }

/* --- Search --- */
.search-box {
    display: flex;
    align-items: center;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0 10px;
    height: 34px;
}
.search-box:focus-within { border-color: var(--primary); }

.search-box input {
    border: none;
    background: transparent;
    outline: none;
    padding: 0 6px;
    font-size: 13px;
    color: var(--text);
    width: 180px;
}
.search-box input::placeholder { color: var(--text-muted); }
.search-box button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: var(--text-muted);
    line-height: 0;
}
.search-box button:hover { color: var(--primary); }
.search-box button svg { display: block; }

/* --- Header User --- */
.header-user {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: 8px;
    padding-left: 16px;
    border-left: 1px solid var(--border);
}
.header-user-name {
    font-size: 13px;
    color: var(--text-soft);
}
.header-logout {
    font-size: 12px;
    color: var(--text-muted);
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    transition: all var(--transition);
}
.header-logout:hover {
    color: #dc2626;
    border-color: #fca5a5;
    background: #fef2f2;
}
.header-login-btn {
    font-size: 13px;
    color: #3451b2;
    padding: 6px 16px;
    border: 1px solid #3451b2;
    border-radius: 6px;
    margin-left: 8px;
    transition: all var(--transition);
    white-space: nowrap;
}
.header-login-btn:hover {
    background: #3451b2;
    color: #fff;
}

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

/* --- Sidebar --- */
.doc-sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--white);
    border-right: 1px solid var(--border);
    position: fixed;
    top: var(--header-height);
    bottom: 0;
    left: 0;
    overflow-y: auto;
    padding: 12px 0;
}
.doc-sidebar::-webkit-scrollbar { width: 4px; }
.doc-sidebar::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }
.doc-sidebar::-webkit-scrollbar-track { background: transparent; }

.sidebar-section-title {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .04em;
    color: var(--text-muted);
    padding: 10px 20px 6px;
}

.sidebar-all-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 20px;
    font-size: 13px;
    color: var(--text);
    font-weight: 500;
    border-right: 2px solid transparent;
}
.sidebar-all-link:hover { color: var(--primary); }
.sidebar-all-link.active {
    color: var(--primary);
    background: var(--primary-light);
    border-right-color: var(--primary);
}

/* Category group */
.cat-group { margin-bottom: 1px; }

.cat-group-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 20px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    user-select: none;
    border-right: 2px solid transparent;
}
.cat-group-header:hover { background: #f9f9f9; }
.cat-group-header .arrow {
    display: inline-block;
    width: 14px;
    font-size: 9px;
    color: var(--text-muted);
    flex-shrink: 0;
    text-align: center;
    transition: transform .2s;
    line-height: 1;
}
.cat-group-header.expanded .arrow { transform: rotate(90deg); }

.cat-group-articles {
    list-style: none;
    overflow: hidden;
    max-height: 0;
    transition: max-height .25s ease;
}
.cat-group-articles.expanded { max-height: 2000px; }

.cat-group-articles li a {
    display: block;
    padding: 6px 20px 6px 42px;
    font-size: 13px;
    color: var(--text-soft);
    border-right: 2px solid transparent;
    line-height: 1.45;
}
.cat-group-articles li a:hover { color: var(--primary); background: #f9f9f9; }
.cat-group-articles li a.active {
    color: var(--primary);
    background: var(--primary-light);
    border-right-color: var(--primary);
    font-weight: 500;
}

/* --- Main Content --- */
.doc-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 28px 36px;
    min-width: 0;
}

.doc-main-header { margin-bottom: 20px; }
.doc-main-header h1 {
    font-size: 22px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}
.doc-main-header .subtitle {
    font-size: 14px;
    color: var(--text-soft);
}

/* --- Article List --- */
.article-list-section { margin-bottom: 24px; }
.article-list-section h2 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.article-list { list-style: none; }
.article-list li { margin-bottom: 4px; }
.article-list li a {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 11px 16px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.article-list li a:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.article-list .article-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.article-list .article-icon svg { width: 16px; height: 16px; color: var(--text-muted); }
.article-list .article-info { flex: 1; min-width: 0; }
.article-list .article-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 2px;
}
.article-list .article-desc {
    font-size: 12px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.article-list .article-meta {
    font-size: 12px;
    color: var(--text-muted);
    flex-shrink: 0;
    margin-top: 2px;
}

/* --- Article View --- */
.article-breadcrumb {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.article-breadcrumb a { color: var(--text-soft); }
.article-breadcrumb a:hover { color: var(--primary); }
.article-breadcrumb .sep { color: #ccc; }

.article {
    background: var(--white);
    border-radius: var(--radius);
    padding: 32px 36px;
    border: 1px solid var(--border);
    scroll-margin-top: 80px;
}

.article-header {
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.article h1 {
    font-size: 22px;
    font-weight: 600;
    line-height: 1.4;
    margin-bottom: 8px;
    color: #111;
}

.article-meta {
    display: flex;
    gap: 16px;
    font-size: 13px;
    color: var(--text-muted);
    flex-wrap: wrap;
}

.article-cat-label {
    display: inline-block;
    font-size: 12px;
    color: var(--primary);
    font-weight: 500;
    margin-bottom: 8px;
    border-left: 3px solid var(--primary);
    padding-left: 8px;
}

.article-tags { margin-top: 10px; display: flex; gap: 6px; flex-wrap: wrap; }
.article-tags .tag {
    background: var(--bg);
    color: var(--text-soft);
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 12px;
    border: 1px solid var(--border);
}

/* --- Article Content --- */
.article-content {
    font-size: 14px;
    line-height: 1.75;
    color: #374151;
}

.article-content h2 {
    font-size: 18px;
    font-weight: 600;
    margin: 28px 0 12px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
    color: #111;
}
.article-content h3 {
    font-size: 15px;
    font-weight: 600;
    margin: 22px 0 8px;
    color: var(--text);
}
.article-content p { margin-bottom: 12px; }
.article-content ul, .article-content ol { margin: 8px 0 12px 22px; }
.article-content li { margin-bottom: 4px; }

.article-content pre {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 16px 18px;
    border-radius: var(--radius);
    overflow-x: auto;
    margin: 12px 0;
    font-size: 13px;
    line-height: 1.55;
}
.article-content code {
    background: #f1f5f9;
    color: #c7254e;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 13px;
    font-family: "SF Mono", "Fira Code", "Consolas", monospace;
}
.article-content pre code {
    background: transparent;
    color: inherit;
    padding: 0;
    border-radius: 0;
}
.article-content blockquote {
    border-left: 3px solid var(--primary);
    background: var(--primary-light);
    padding: 10px 16px;
    margin: 12px 0;
    border-radius: 0 4px 4px 0;
    color: var(--text-soft);
    font-size: 13px;
}
.article-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 13px;
}
.article-content th, .article-content td {
    border: 1px solid var(--border);
    padding: 8px 12px;
    text-align: left;
}
.article-content th { background: var(--bg); font-weight: 600; }
.article-content img { border-radius: var(--radius); margin: 12px 0; }

/* --- Video & iframe --- */
.article-content video,
.article-content iframe {
    max-width: 100%;
    border-radius: var(--radius);
    margin: 16px 0;
    display: block;
}
.article-content iframe { border: none; aspect-ratio: 16/9; height: auto; }

/* --- Link Card --- */
.article-content .link-card {
    display: flex;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    margin: 16px 0;
    text-decoration: none;
    color: inherit;
    transition: box-shadow 0.2s, border-color 0.2s;
    max-width: 500px;
}
.article-content .link-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow);
}
.article-content .link-card-img {
    width: 120px;
    height: 80px;
    object-fit: cover;
    flex-shrink: 0;
    margin: 0;
    border-radius: 0;
}
.article-content .link-card-body {
    padding: 12px 16px;
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.article-content .link-card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}
.article-content .link-card-desc {
    font-size: 12px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* --- Link Button --- */
.article-content .link-btn {
    display: inline-block;
    padding: 8px 24px;
    background: var(--primary);
    color: #fff !important;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    margin: 12px 0;
    transition: background 0.2s;
}
.article-content .link-btn:hover { background: #1e3ea5; color: #fff; }

/* 强制按钮链接文字在任何状态下都是白色，避免被全局 a 颜色覆盖 */
.article-content a.link-btn,
.article-content a.link-btn:link,
.article-content a.link-btn:visited,
.article-content a.link-btn:hover,
.article-content a.link-btn:active,
.article-content a.link-btn:focus {
    color: #fff !important;
}

/* --- Link Text --- */
.article-content .link-text {
    color: var(--primary);
    text-decoration: underline;
    text-underline-offset: 2px;
    font-size: 14px;
}
.article-content .link-text:hover { color: #1e3ea5; }

/* 文章内普通链接（来自 Quill 编辑器原生链接） */
.article-content a {
    color: var(--primary);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.article-content a:hover { color: #1e3ea5; }

/* --- Image Link --- */
.article-content a > img { border-radius: var(--radius); margin: 12px 0; }

/* --- Stacked Articles --- */
.article-stacked {
    margin-top: 28px;
    scroll-margin-top: 80px;
}

/* --- Article Nav --- */
.article-nav {
    display: flex;
    gap: 12px;
    margin-top: 32px;
}
.article-nav > a,
.article-nav > span {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 14px 18px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--white);
}
.article-nav > a:hover {
    border-color: var(--primary);
}
.article-nav .nav-prev { text-align: left; }
.article-nav .nav-next { text-align: right; align-items: flex-end; }
.article-nav .nav-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.article-nav .nav-title { font-size: 13px; color: var(--text); font-weight: 600; }
.article-nav > a:hover .nav-title { color: var(--primary); }
.article-nav .nav-disabled { opacity: .4; cursor: default; }

/* --- End Hint --- */
.article-end-hint {
    text-align: center;
    padding: 36px 20px;
    margin-top: 20px;
    color: var(--text-muted);
}
.article-end-hint p {
    font-size: 13px;
    margin-bottom: 12px;
}
.article-end-hint .btn-back-home {
    display: inline-block;
    padding: 7px 16px;
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    background: var(--white);
}
.article-end-hint .btn-back-home:hover { border-color: var(--primary); color: var(--primary); }

/* --- Search Results --- */
.search-results-bar {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    padding: 14px 20px;
    margin: -28px -36px 20px;
}
.search-results-bar h2 { font-size: 16px; font-weight: 600; }
.search-results-bar .count { color: var(--text-muted); font-size: 13px; font-weight: 400; }

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: 48px 20px;
}
.empty-state h3 { font-size: 16px; color: var(--text); margin-bottom: 6px; }
.empty-state p { font-size: 14px; color: var(--text-muted); }

/* --- Footer --- */
.footer {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
    font-size: 12px;
    border-top: 1px solid var(--border);
}

/* --- Mobile --- */
.sidebar-toggle { display: none; }
@media (max-width: 768px) {
    .sidebar-toggle {
        display: flex;
        align-items: center;
        gap: 6px;
        padding: 8px 16px;
        font-size: 13px;
        background: var(--white);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        cursor: pointer;
        color: var(--text);
        margin: 0 0 12px;
    }
    .doc-sidebar {
        position: fixed;
        z-index: 99;
        transform: translateX(-100%);
        transition: transform .25s;
        box-shadow: 0 4px 20px rgba(0,0,0,.1);
    }
    .doc-sidebar.mobile-open { transform: translateX(0); }
    .doc-main { margin-left: 0; padding: 16px; }
    .article { padding: 18px; }
    .article h1 { font-size: 19px; }
    .search-box input { width: 100px; }
    .header-user { padding-left: 10px; margin-left: 4px; gap: 6px; }
    .header-user-name { font-size: 12px; }
    .doc-layout { padding-top: 50px; }
    .header-inner { height: 48px; }
    .header { height: 48px; }
}
