/* ============================================================
   Knowledge Base - Wiki.js inspired front-end theme
   ============================================================ */

:root {
    --accent: #1976d2;
    --accent-dark: #145ea8;
    --accent-soft: #e8f1fb;
    --ink: #26323d;
    --ink-soft: #46596b;
    --muted: #7b8d9e;
    --line: #e3e8ef;
    --line-soft: #eef1f5;
    --bg: #ffffff;
    --bg-soft: #f6f8fa;
    --radius: 10px;
    --header-h: 60px;
    --sidebar-w: 288px;
    --toc-w: 240px;
    --shadow: 0 1px 3px rgba(32, 48, 64, .08), 0 6px 24px rgba(32, 48, 64, .06);
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    margin: 0;
    font-family: var(--sans);
    font-size: 15.5px;
    line-height: 1.65;
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

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

img { max-width: 100%; }

.skip-link {
    position: absolute; left: -9999px; top: 0;
    background: var(--accent); color: #fff; padding: 8px 14px; z-index: 1000;
}
.skip-link:focus { left: 8px; top: 8px; border-radius: 6px; }

/* ------------------------------- header -------------------------------- */

.site-header {
    position: sticky; top: 0; z-index: 100;
    background: rgba(255, 255, 255, .92);
    backdrop-filter: saturate(180%) blur(8px);
    border-bottom: 1px solid var(--line);
}

.header-inner {
    max-width: 1440px; margin: 0 auto;
    height: var(--header-h);
    display: flex; align-items: center; gap: 18px;
    padding: 0 22px;
}

.brand {
    display: flex; align-items: center; gap: 9px;
    font-weight: 700; font-size: 17px; color: var(--ink);
    white-space: nowrap; flex: 0 0 auto;
}
.brand svg { color: var(--accent); }

.header-search {
    flex: 1 1 auto; max-width: 520px; min-width: 0;
    display: flex; align-items: center; gap: 8px;
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 12px;
    transition: border-color .15s, box-shadow .15s, background .15s;
}
.header-search:focus-within {
    background: #fff;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(25, 118, 210, .12);
}
.header-search svg { color: var(--muted); flex: none; }
.header-search input {
    flex: 1; border: 0; background: transparent; outline: none;
    padding: 9px 0; font: inherit; color: var(--ink);
}

.header-nav { display: flex; align-items: center; gap: 4px; }
.header-nav > a, .nav-dropdown > a {
    padding: 7px 12px; border-radius: 7px;
    color: var(--ink-soft); font-weight: 500; font-size: 14.5px;
    display: inline-flex; align-items: center; gap: 5px;
}
.header-nav a:hover { background: var(--bg-soft); color: var(--accent); }

.nav-dropdown { position: relative; }
.nav-menu {
    position: absolute; top: calc(100% + 6px); left: 0;
    min-width: 190px; background: #fff;
    border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 6px;
    display: none; flex-direction: column;
}
.nav-dropdown:hover .nav-menu, .nav-dropdown:focus-within .nav-menu { display: flex; }
.nav-menu a { padding: 8px 12px; border-radius: 6px; color: var(--ink-soft); font-size: 14px; }
.nav-menu a:hover { background: var(--accent-soft); color: var(--accent); }
.caret { font-size: 10px; color: var(--muted); }

.header-user { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.header-user img { border-radius: 50%; }
.user-name { display: inline-flex; align-items: center; gap: 6px; color: var(--ink) !important; font-weight: 600; font-size: 14px; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    padding: 8px 16px; border-radius: 8px;
    border: 1px solid var(--line); background: #fff;
    color: var(--ink); font: inherit; font-weight: 600; font-size: 14px;
    cursor: pointer; white-space: nowrap;
    transition: background .15s, border-color .15s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }
.btn.ghost { border-color: transparent; }
.btn.ghost:hover { background: var(--bg-soft); }
.btn.block { width: 100%; }

/* ----------------------------- 点击涟漪特效 ----------------------------- */

.btn, .page-btn, .category-card, .pn-card, .chip {
    -webkit-tap-highlight-color: transparent;
}
.btn, .page-btn, .pn-card, .category-card { position: relative; overflow: hidden; }
.ripple {
    position: absolute;
    border-radius: 50%;
    transform: scale(0);
    pointer-events: none;
    background: var(--ripple-color, rgba(25, 118, 210, .26));
    animation: kb-ripple .6s ease-out forwards;
    z-index: 0;
}
.btn.primary { --ripple-color: rgba(255, 255, 255, .55); }
/* 涟漪位于背景之上、文字之下 */
.btn > :not(.ripple), .page-btn > :not(.ripple),
.pn-card > :not(.ripple), .category-card > :not(.ripple) { position: relative; z-index: 1; }
@keyframes kb-ripple {
    0% { transform: scale(0); opacity: .55; }
    60% { opacity: .32; }
    100% { transform: scale(2.6); opacity: 0; }
}
@media (hover: hover) {
    .btn:active { transform: scale(.97); }
    .category-card:active, .pn-card:active { transform: scale(.985); }
}
@media (prefers-reduced-motion: reduce) {
    .ripple { animation: none; opacity: 0; }
    .btn:active, .category-card:active, .pn-card:active { transform: none; }
}
@keyframes kb-sheen {
    from { left: -80%; }
    to { left: 130%; }
}

.sidebar-toggle {
    display: none; background: none; border: 0; cursor: pointer;
    width: 40px; height: 40px; padding: 9px; border-radius: 8px;
    flex: 0 0 auto;
    flex-direction: column; justify-content: center; gap: 4px;
}
.sidebar-toggle span { display: block; width: 100%; height: 2px; background: var(--ink); border-radius: 2px; }
.sidebar-toggle:hover { background: var(--bg-soft); }

/* -------------------------------- shell -------------------------------- */

.app-shell {
    max-width: 1440px; margin: 0 auto;
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    gap: 0;
    min-height: calc(100vh - var(--header-h));
}
.app-shell.layout-contained { --content-max: 880px; }
.app-shell.layout-wide { --content-max: 1080px; }

.sidebar {
    border-right: 1px solid var(--line);
    background: #fafbfc;
    padding: 24px 14px 40px;
    position: sticky; top: var(--header-h);
    align-self: start;
    height: calc(100vh - var(--header-h));
    overflow-y: auto;
}
.sb-section { margin-bottom: 22px; }
.sb-section h4 {
    margin: 0 10px 8px;
    font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
    color: var(--muted); font-weight: 700;
}
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar a { color: var(--ink-soft); font-size: 14.5px; }
.sidebar a:hover { color: var(--accent); }

.sb-flat li a { display: block; padding: 6px 10px; border-radius: 6px; }
.sb-flat li a:hover { background: var(--accent-soft); }

.sb-tree details summary { list-style: none; cursor: pointer; }
.sb-tree details summary::-webkit-details-marker { display: none; }
.sb-tree .twisty {
    display: inline-block; width: 16px; color: var(--muted);
    font-size: 10px; transition: transform .15s;
}
.sb-tree details[open] > summary .twisty { transform: rotate(90deg); }
.twisty-placeholder { display: inline-block; width: 16px; }

.sb-category > details > summary, .sb-category > .sb-leaf {
    display: flex; align-items: center; padding: 3px 0;
}
.sb-cat-link { font-weight: 600 !important; padding: 4px 8px 4px 2px !important; flex: 1; border-radius: 6px; }
.sb-category.active > details > summary .sb-cat-link,
.sb-category.active > .sb-leaf .sb-cat-link { color: var(--accent); }

.sb-children { padding-left: 17px; border-left: 1px solid var(--line); margin: 2px 0 4px 11px; }
.sb-children > li > a { display: block; padding: 4px 10px; border-radius: 6px; }
.sb-children > li > a:hover { background: var(--accent-soft); }
.sb-children > li.active > a {
    background: var(--accent-soft); color: var(--accent); font-weight: 600;
}

.main { min-width: 0; padding: 26px 40px 0; display: flex; flex-direction: column; }

.breadcrumbs {
    font-size: 13px; color: var(--muted);
    margin-bottom: 14px; display: flex; flex-wrap: wrap; gap: 6px;
}
.breadcrumbs a { color: var(--muted); }
.breadcrumbs a:hover { color: var(--accent); }
.breadcrumbs .current { color: var(--ink-soft); font-weight: 500; }
.breadcrumbs .sep { color: #b6c2cd; }

.content-wrap {
    width: 100%; max-width: calc(var(--content-max) + var(--toc-w) + 48px);
    margin: 0 auto;
    display: grid; grid-template-columns: minmax(0, 1fr);
}
.content-wrap.with-toc { grid-template-columns: minmax(0, 1fr) var(--toc-w); gap: 40px; }
.content-body { min-width: 0; max-width: var(--content-max); }

.toc-rail { position: relative; }
.toc-inner {
    position: sticky; top: calc(var(--header-h) + 20px);
    font-size: 13px; padding-bottom: 30px;
}
.toc-inner h4 {
    margin: 0 0 8px; font-size: 11px; text-transform: uppercase;
    letter-spacing: .08em; color: var(--muted);
}
.toc-inner ul { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); }
.toc-inner li a { display: block; padding: 4px 12px; color: var(--muted); border-left: 2px solid transparent; margin-left: -2px; }
.toc-inner li a:hover { color: var(--accent); }
.toc-level-3 { padding-left: 12px; }

/* ------------------------------- flash --------------------------------- */

.flash {
    padding: 11px 16px; border-radius: 8px; margin-bottom: 18px;
    font-size: 14px; border: 1px solid transparent;
}
.flash.success { background: #e7f5ec; border-color: #c3e3cc; color: #1d6b35; }
.flash.error { background: #fdecea; border-color: #f5c6c2; color: #8c241c; }
.flash.info { background: var(--accent-soft); border-color: #c9dff5; color: #15497e; }

/* -------------------------------- home --------------------------------- */

.home-hero {
    text-align: center;
    padding: 56px 20px 44px;
    background:
        radial-gradient(900px 260px at 50% -60px, rgba(25, 118, 210, .10), transparent 70%);
    border-bottom: 1px solid var(--line-soft);
    margin: -26px -40px 28px;
}
.home-hero h1 { font-size: 38px; margin: 0 0 10px; letter-spacing: -.5px; }
.hero-sub { color: var(--ink-soft); font-size: 17px; margin: 0 0 26px; }
.hero-search {
    max-width: 640px; margin: 0 auto;
    display: flex; align-items: center; gap: 10px;
    background: #fff; border: 1px solid var(--line);
    border-radius: 10px; padding: 6px 8px 6px 16px;
    box-shadow: var(--shadow);
}
.hero-search svg { color: var(--muted); }
.hero-search input { flex: 1; border: 0; outline: none; font: inherit; padding: 10px 0; }
.hero-meta { color: var(--muted); font-size: 13px; margin-top: 14px; }

.home-section { margin-bottom: 34px; }
.section-title {
    font-size: 20px; margin: 0 0 16px; padding-bottom: 8px;
    border-bottom: 1px solid var(--line-soft);
}

.category-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 14px;
}
.category-card {
    display: flex; gap: 12px; padding: 16px;
    border: 1px solid var(--line); border-radius: var(--radius);
    background: #fff; color: var(--ink);
    transition: border-color .15s, transform .15s, box-shadow .15s;
}
.category-card:hover {
    border-color: var(--accent); transform: translateY(-1px);
    box-shadow: var(--shadow); color: var(--ink);
}
.cat-icon { font-size: 22px; line-height: 1.3; }
.cat-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cat-body strong { font-size: 15px; }
.cat-body small { color: var(--muted); font-size: 12.5px; }
.cat-body em { color: var(--muted); font-style: normal; font-size: 13px; margin-top: 2px; }
.category-grid.compact { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }

.home-columns {
    display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 36px;
    align-items: start;
}
.home-side { position: sticky; top: calc(var(--header-h) + 20px); }

.article-list { list-style: none; margin: 0; padding: 0; }
.article-list li {
    padding: 16px 0; border-bottom: 1px solid var(--line-soft);
}
.article-list li:last-child { border-bottom: 0; }
.article-list h3 { margin: 0 0 4px; font-size: 17px; }
.article-list h3 a { color: var(--ink); }
.article-list h3 a:hover { color: var(--accent); }
.article-excerpt { margin: 0 0 8px; color: var(--ink-soft); font-size: 14px; }
.article-meta {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    font-size: 12.5px; color: var(--muted);
}
.meta-sep { color: #c3cdd7; }
.chip {
    display: inline-block; padding: 1px 10px; border-radius: 999px;
    background: var(--accent-soft); color: var(--accent) !important;
    font-size: 12px; font-weight: 600;
}
.chip:hover { background: #d7e8f9; }

.popular-list { list-style: none; margin: 0; padding: 0; counter-reset: pop; }
.popular-list li { display: grid; grid-template-columns: 26px 1fr; gap: 4px 10px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.popular-list li:last-child { border-bottom: 0; }
.popular-list .rank {
    grid-row: span 2; width: 24px; height: 24px; border-radius: 50%;
    background: var(--bg-soft); color: var(--muted);
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700;
}
.popular-list a { color: var(--ink); font-weight: 600; font-size: 14px; }
.popular-list small { color: var(--muted); font-size: 12px; }

.empty-note { color: var(--muted); font-size: 14px; }

/* ------------------------------ article -------------------------------- */

.doc-header { margin-bottom: 26px; }
.doc-header h1 { font-size: 34px; line-height: 1.25; margin: 8px 0 12px; letter-spacing: -.5px; }
.doc-meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.doc-meta .avatar { border-radius: 50%; }
.doc-meta .author { color: var(--ink-soft); font-weight: 600; }

.badge {
    display: inline-block; padding: 3px 11px; border-radius: 999px;
    font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
}
.badge.draft { background: #fff4e0; color: #a3640a; }

.tag-row { margin: 34px 0 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.tag {
    background: var(--bg-soft); border: 1px solid var(--line);
    padding: 3px 12px; border-radius: 999px; font-size: 13px; color: var(--ink-soft);
}

.prev-next {
    display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
    margin: 38px 0;
}
.pn-card {
    display: flex; flex-direction: column; gap: 3px;
    border: 1px solid var(--line); border-radius: var(--radius);
    padding: 14px 18px; color: var(--ink);
}
.pn-card:hover { border-color: var(--accent); color: var(--ink); }
.pn-card span { font-size: 12.5px; color: var(--muted); }
.pn-card strong { font-size: 14.5px; font-weight: 600; }
.pn-card.next { text-align: right; }

/* ----------------------------- markdown -------------------------------- */

.markdown-body { font-size: 15.5px; word-wrap: break-word; }
.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5 {
    line-height: 1.3; margin: 1.7em 0 .7em; font-weight: 700;
    scroll-margin-top: calc(var(--header-h) + 16px);
}
.markdown-body h1 { font-size: 1.9em; }
.markdown-body h2 {
    font-size: 1.45em; padding-bottom: .35em;
    border-bottom: 1px solid var(--line-soft);
}
.markdown-body h3 { font-size: 1.2em; }
.markdown-body h4 { font-size: 1.05em; }
.markdown-body p { margin: 0 0 1em; }
.markdown-body a { text-decoration: underline; text-decoration-color: rgba(25, 118, 210, .35); text-underline-offset: 2px; }

.heading-anchor {
    color: var(--muted); text-decoration: none; opacity: 0;
    margin-left: 6px; font-weight: 400;
}
.markdown-body h1:hover .heading-anchor,
.markdown-body h2:hover .heading-anchor,
.markdown-body h3:hover .heading-anchor,
.markdown-body h4:hover .heading-anchor { opacity: .7; }

.markdown-body ul, .markdown-body ol { margin: 0 0 1em; padding-left: 1.6em; }
.markdown-body li { margin: .3em 0; }
.markdown-body li > ul, .markdown-body li > ol { margin: .3em 0; }
.markdown-body .task { display: flex; align-items: center; gap: 8px; list-style: none; margin-left: -1.2em; }
.markdown-body .task input { margin: 0; accent-color: var(--accent); }

.markdown-body blockquote {
    margin: 0 0 1em; padding: 10px 18px;
    border-left: 4px solid var(--accent);
    background: var(--bg-soft);
    border-radius: 0 8px 8px 0;
    color: var(--ink-soft);
}
.markdown-body blockquote p:last-child { margin-bottom: 0; }

.markdown-body code {
    font-family: var(--mono); font-size: .88em;
    background: var(--bg-soft); border: 1px solid var(--line-soft);
    padding: .15em .4em; border-radius: 5px;
}
.markdown-body pre {
    background: #1e2530; color: #e6edf3;
    padding: 16px 18px; border-radius: var(--radius);
    overflow-x: auto; margin: 0 0 1.2em;
    font-size: 13.5px; line-height: 1.55;
}
.markdown-body pre code {
    background: none; border: 0; padding: 0;
    color: inherit; font-size: inherit;
}

.markdown-body .table-wrap { overflow-x: auto; margin: 0 0 1.2em; }
.markdown-body table {
    border-collapse: collapse; width: 100%;
    font-size: 14px; display: table;
}
.markdown-body th, .markdown-body td {
    border: 1px solid var(--line);
    padding: 8px 13px; text-align: left;
}
.markdown-body th { background: var(--bg-soft); font-weight: 600; }
.markdown-body tr:nth-child(even) td { background: #fcfdfe; }

.markdown-body img { border-radius: 8px; border: 1px solid var(--line-soft); }
.markdown-body hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }

/* --------------------------- category/search --------------------------- */

.category-head, .search-head { margin-bottom: 8px; }
.category-head h1, .search-head h1 { margin: 0 0 6px; font-size: 30px; }
.category-desc { color: var(--ink-soft); margin: 0 0 6px; }
.result-count { color: var(--muted); font-size: 14px; margin: 0 0 18px; }
.subcategories { margin: 8px 0 26px; }

.article-list.detailed li { padding: 20px 0; }

.search-results { list-style: none; margin: 0; padding: 0; }
.search-results li { padding: 20px 0; border-bottom: 1px solid var(--line-soft); }
.search-results h3 { margin: 6px 0; font-size: 18px; }
.search-results p { margin: 0 0 8px; color: var(--ink-soft); font-size: 14px; }
.search-results mark { background: #fff3a8; padding: 0 2px; border-radius: 3px; }

.inline-search { display: flex; gap: 10px; margin-top: 16px; max-width: 460px; }
.inline-search input {
    flex: 1; padding: 10px 14px; border: 1px solid var(--line);
    border-radius: 8px; font: inherit;
}

.empty-state {
    text-align: center; padding: 60px 20px;
    border: 1px dashed var(--line); border-radius: var(--radius);
    background: #fcfdfe; margin: 20px 0;
}
.empty-state h3 { margin: 0 0 6px; }
.empty-state p { color: var(--muted); margin: 0 0 8px; }

/* ----------------------------- pagination ------------------------------ */

.pagination {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; margin: 30px 0 20px; flex-wrap: wrap;
}
.page-info { color: var(--muted); font-size: 13px; }
.page-links { display: flex; gap: 4px; flex-wrap: wrap; }
.page-btn {
    min-width: 34px; padding: 6px 11px; text-align: center;
    border: 1px solid var(--line); border-radius: 7px;
    font-size: 13.5px; color: var(--ink-soft); background: #fff;
}
.page-btn:hover { border-color: var(--accent); color: var(--accent); }
.page-btn.current { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.page-btn.disabled { opacity: .45; pointer-events: none; }

/* ------------------------------- auth ---------------------------------- */

.auth-wrap { display: flex; justify-content: center; padding: 40px 0 60px; }
.auth-card {
    width: 100%; max-width: 420px;
    background: #fff; border: 1px solid var(--line);
    border-radius: 14px; padding: 34px;
    box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0 0 4px; font-size: 24px; }
.auth-sub { color: var(--muted); margin: 0 0 22px; font-size: 14px; }
.auth-form label, .stack-form label {
    display: flex; flex-direction: column; gap: 6px;
    font-size: 13px; font-weight: 600; color: var(--ink-soft);
    margin-bottom: 16px;
}
.auth-form small, .stack-form small { font-weight: 400; color: var(--muted); }
.auth-form input, .stack-form input, .stack-form textarea {
    padding: 10px 13px; border: 1px solid var(--line);
    border-radius: 8px; font: inherit; color: var(--ink);
}
.auth-form input:focus, .stack-form input:focus, .stack-form textarea:focus {
    outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(25, 118, 210, .12);
}
.auth-links {
    display: flex; justify-content: space-between; gap: 10px;
    margin-top: 18px; font-size: 13.5px; flex-wrap: wrap;
}

/* ------------------------------ profile -------------------------------- */

.profile-wrap { max-width: 880px; margin: 0 auto 60px; }
.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; align-items: start; }
.panel-card {
    background: #fff; border: 1px solid var(--line);
    border-radius: var(--radius); padding: 24px;
}
.panel-card h2 { margin: 0 0 18px; font-size: 18px; }
.profile-id { display: flex; gap: 14px; margin-bottom: 20px; }
.profile-id .avatar-lg { border-radius: 50%; }
.profile-id > div { display: flex; flex-direction: column; gap: 2px; }
.profile-id small { color: var(--muted); font-size: 12.5px; }
.role-badge {
    align-self: flex-start;
    font-size: 11px; font-weight: 700; text-transform: uppercase;
    padding: 2px 9px; border-radius: 999px; letter-spacing: .05em;
}
.role-admin { background: #fde7ef; color: #ad3a68; }
.role-editor { background: var(--accent-soft); color: var(--accent); }
.role-viewer { background: #eef1f5; color: #5b6b7b; }
.stack-form textarea { resize: vertical; }

/* ------------------------------- error --------------------------------- */

.error-page { text-align: center; padding: 70px 20px; }
.error-code {
    font-size: 90px; font-weight: 800; line-height: 1;
    background: linear-gradient(135deg, var(--accent), #7aa7e0);
    -webkit-background-clip: text; background-clip: text; color: transparent;
}
.error-page h1 { font-size: 26px; margin: 10px 0; }
.error-page p { color: var(--ink-soft); }
.error-actions { display: flex; gap: 12px; justify-content: center; margin-top: 22px; }

/* ------------------------------ footer --------------------------------- */

.site-footer {
    margin-top: auto;
    border-top: 1px solid var(--line-soft);
    padding: 22px 0 28px; margin-top: 50px;
    display: flex; flex-direction: column; gap: 8px;
}
.footer-nav { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13.5px; }
.footer-nav a { color: var(--ink-soft); }
.footer-text { margin: 0; color: var(--muted); font-size: 13px; }

.page-scrim {
    position: fixed; inset: 0; background: rgba(20, 30, 42, .4);
    z-index: 90; display: none;
}

/* Right-hand sidebar option (Appearance setting) */
body.sb-right .app-shell {
    grid-template-columns: minmax(0, 1fr) var(--sidebar-w);
}
body.sb-right .sidebar { order: 2; border-right: 0; border-left: 1px solid var(--line); }
body.sb-right .main { order: 1; }

/* ----------------------------- responsive ------------------------------ */

@media (max-width: 1180px) {
    .home-columns { grid-template-columns: 1fr; }
    .home-side { position: static; }
    .content-wrap.with-toc { grid-template-columns: minmax(0, 1fr); }
    .toc-rail { display: none; }
}

@media (max-width: 1023px) {
    .sidebar-toggle { display: inline-flex; }
    .app-shell { grid-template-columns: minmax(0, 1fr); }
    .sidebar {
        position: fixed; top: 0; left: 0; bottom: 0;
        height: 100vh; z-index: 95;
        width: var(--sidebar-w); max-width: 82vw;
        transform: translateX(-105%);
        transition: transform .2s ease;
        box-shadow: 0 0 40px rgba(20, 30, 42, .25);
    }
    body.sb-right .sidebar {
        left: auto; right: 0;
        transform: translateX(105%);
        border-left: 1px solid var(--line);
        border-right: 0;
    }
    body.nav-open .sidebar { transform: translateX(0); }
    body.nav-open .page-scrim { display: block; }
    .main { padding: 20px 20px 0; }
    .home-hero { margin: -20px -20px 24px; }
    .header-nav { display: none; }
    .profile-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
    .header-inner { gap: 8px; padding: 0 12px; }
    .header-user .btn.ghost { display: none; }
    .home-hero h1 { font-size: 28px; }
    .doc-header h1 { font-size: 26px; }
    .prev-next { grid-template-columns: 1fr; }
    .category-grid { grid-template-columns: 1fr; }
}

/* 小屏顶栏防溢出：搜索框弹性收缩，品牌文字省略 */
@media (max-width: 560px) {
    .header-inner { gap: 6px; padding: 0 10px; }
    .brand span { max-width: 84px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .header-search { flex: 1 1 auto; min-width: 0; max-width: none; }
    .header-search input { min-width: 0; }
    .header-user { gap: 6px; margin-left: 0; flex: 0 0 auto; }
    .header-user .user-name { display: none; }
}

/* ==================== 响应式增强（小屏/触屏/表格） ==================== */

/* 笔记本区间（1024–1280px）：侧栏与留白微调，避免布局偏挤 */
@media (min-width: 1024px) and (max-width: 1280px) {
    :root { --sidebar-w: 260px; --toc-w: 220px; }
    .main { padding: 24px 28px 0; }
    .header-inner { padding: 0 18px; }
}

/* 流式字号，随视口平滑缩放 */
html { font-size: clamp(14px, 0.6vw + 13px, 16.5px); }
.home-hero h1 { font-size: clamp(26px, 5vw, 38px); }
.category-head h1, .search-head h1 { font-size: clamp(24px, 4vw, 30px); }
.doc-header h1 { font-size: clamp(22px, 4vw, 32px); }

@media (max-width: 1023px) {
    /* 玻璃模板悬浮头部在移动端回到全宽，避免占位过多 */
    body.tpl-aurora .site-header,
    body.tpl-midnight .site-header,
    body.tpl-sakura .site-header { top: 0; padding: 0; }
    body.tpl-aurora .header-inner,
    body.tpl-midnight .header-inner,
    body.tpl-sakura .header-inner {
        height: var(--header-h); border-radius: 0;
        border-left: 0; border-right: 0; border-top: 0;
    }
    /* 抽屉式侧栏恢复直角全高，避免圆角露出缝隙 */
    body.tpl-aurora .sidebar,
    body.tpl-midnight .sidebar,
    body.tpl-sakura .sidebar {
        border-radius: 0 20px 20px 0;
        top: 0; max-height: none;
    }
    body.sb-right.tpl-aurora .sidebar,
    body.sb-right.tpl-midnight .sidebar,
    body.sb-right.tpl-sakura .sidebar { border-radius: 20px 0 0 20px; }
}

@media (max-width: 768px) {
    .main { padding: 18px 16px 0; }
    .home-hero { padding: 34px 18px; margin-bottom: 24px; }
    .hero-search { flex-direction: column; gap: 10px; background: transparent; border: 0; padding: 0; }
    .hero-search input { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 11px 14px; width: 100%; }
    .hero-search .btn { width: 100%; }
    .hero-meta { font-size: 12.5px; }
    .doc-header { margin-bottom: 22px; }
    .doc-meta { flex-wrap: wrap; gap: 6px 10px; }
    .content-wrap { gap: 0; }
    .pagination { justify-content: center; }
    .page-info { width: 100%; text-align: center; }
    .inline-search { flex-direction: column; }
    .inline-search input, .inline-search .btn { width: 100%; }
    .auth-wrap { padding: 20px 0 40px; }
    .auth-card { padding: 24px 20px; }
    .profile-id { flex-direction: column; text-align: left; }
    .error-page { padding: 40px 16px; }
    .error-code { font-size: 64px; }
    .error-actions { flex-direction: column; }
    .error-actions .btn { width: 100%; }
    .site-footer { text-align: center; align-items: center; }

    /* 宽表格横向滚动，不挤压布局 */
    .markdown-body table {
        display: block; overflow-x: auto; white-space: nowrap;
        border-radius: 10px; -webkit-overflow-scrolling: touch;
    }
    .markdown-body table thead, .markdown-body table tbody { display: table; min-width: 100%; width: auto; }
    .markdown-body pre { font-size: 13px; }
}

@media (max-width: 480px) {
    .brand { font-size: 15px; }
    .brand svg { width: 22px; height: 22px; }
    .header-search { max-width: none; }
    .header-user img { width: 28px; height: 28px; }
    .header-user .user-name { display: none; }
    .home-hero { padding: 28px 16px; }
    .category-card { padding: 16px; gap: 12px; }
    .cat-icon { font-size: 20px; }
    .tag-pill, .tag-row .tag-pill { font-size: 12.5px; }
    .pn-card { padding: 14px; }
    .markdown-body { font-size: 14.5px; }
    .markdown-body pre { padding: 14px; }
}

/* 玻璃模板的文章/卡片内边距在小屏收敛 */
@media (max-width: 768px) {
    body.tpl-aurora .doc-article,
    body.tpl-midnight .doc-article { padding: 24px 20px 20px; border-radius: 20px; }
    body.tpl-sakura .doc-article { padding: 26px 20px 22px; border-radius: 24px; }
    body.tpl-aurora .home-hero,
    body.tpl-sakura .home-hero { border-radius: 22px; }
    body.tpl-midnight .home-hero { border-radius: 22px; }
    body.tpl-aurora .sidebar,
    body.tpl-midnight .sidebar,
    body.tpl-sakura .sidebar { backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }
}

/* 触屏设备增大可点击区域 */
@media (pointer: coarse) {
    .header-nav > a, .nav-dropdown > a { min-height: 40px; }
    .sb-cat-link, .sb-article a { min-height: 40px; display: flex; align-items: center; }
    .btn { min-height: 40px; }
    .page-btn { min-width: 40px; min-height: 40px; }
}

/* ================= 首页全宽显示与板块间距（仅首页生效） ================= */

.page-home .app-shell { max-width: none; }
.page-home .content-wrap,
.page-home .content-body { max-width: none; }
.page-home .hero-sub { margin-bottom: 4px; }
.page-home .home-hero .hero-meta { margin-top: 20px; }

@media (min-width: 1024px) {
    .page-home .home-hero { padding: clamp(44px, 4.5vw, 72px) 24px clamp(34px, 3.4vw, 52px); }
    .page-home .home-section { margin-bottom: clamp(28px, 3vw, 44px); }
}

@media (min-width: 1181px) {
    .page-home .home-columns {
        gap: clamp(28px, 3vw, 48px);
        grid-template-columns: minmax(0, 1fr) clamp(280px, 22vw, 360px);
    }
}

@media (min-width: 1600px) {
    .page-home .category-grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 18px; }
}

/* ==================== 文章内容组件（按钮 / 提示条） ==================== */

.markdown-body .md-button-row { margin: 1.1em 0; }
.markdown-body .md-button {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 20px; border-radius: 8px;
    background: var(--md-btn, var(--accent)); color: #fff;
    font-weight: 600; text-decoration: none;
    box-shadow: 0 2px 6px rgba(15,23,42,.16);
    transition: transform .12s, box-shadow .12s, filter .12s;
}
.markdown-body .md-button:hover {
    color: #fff; filter: brightness(1.06); transform: translateY(-1px);
    box-shadow: 0 5px 14px rgba(15,23,42,.2);
}
.markdown-body .md-button:active { transform: translateY(0); }
.markdown-body .md-button-plain { cursor: default; }

.markdown-body .md-alert {
    margin: 1.1em 0; padding: 12px 16px;
    --md-alert-bg: #eef4fb; --md-alert-border: #c9dff5; --md-alert-accent: #1976d2; --md-alert-text: #15497e;
    border: 1px solid var(--md-alert-border);
    border-left: 4px solid var(--md-alert-accent);
    border-radius: 10px;
    background: var(--md-alert-bg); color: var(--md-alert-text);
}
.markdown-body .md-alert-success { --md-alert-bg: #e7f5ec; --md-alert-border: #c3e3cc; --md-alert-accent: #2e7d32; --md-alert-text: #1d6b35; }
.markdown-body .md-alert-warning { --md-alert-bg: #fff7e6; --md-alert-border: #f0d9a6; --md-alert-accent: #d97706; --md-alert-text: #92400e; }
.markdown-body .md-alert-error { --md-alert-bg: #fdecea; --md-alert-border: #f5c6c2; --md-alert-accent: #dc2626; --md-alert-text: #8c241c; }
.markdown-body .md-alert-head { display: flex; align-items: center; gap: 7px; font-weight: 700; margin-bottom: 5px; }
.markdown-body .md-alert-icon { color: var(--md-alert-accent); }
.markdown-body .md-alert-body p { margin-bottom: .5em; }
.markdown-body .md-alert-body > :last-child { margin-bottom: 0; }

/* 前台 flash 提示条补齐 warning 类型 */
.flash.warning { background: #fff7e6; border-color: #f0d9a6; color: #92400e; }
