/**
 * xzWiki — 三栏式 Wiki 布局样式
 * Version: 001
 *
 * 在 knowhow-modified-v6 基础上追加。
 * 布局：原生 #left-sidebar-nav (fixed 240px) + 中间正文 + 右侧 TOC
 * 中间栏和 TOC 在 #site-container (margin-left:240px) 内 flex 排列。
 * 所有超长文字自动省略号，禁止横向滚动。
 */

/* ==================== Primary 容器调整 ==================== */
#primary.xzwiki-primary {
    padding-top: 0;
}
#primary.xzwiki-primary .ht-container {
    max-width: 1320px !important;
    padding: 0 16px;
    width: 100%;
}

/* ==================== 两栏容器（中间 + 右侧 TOC） ==================== */
#xzwiki-wrap.xzwiki-container {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 18px;
    padding: 5px 0 30px;
    min-height: 65vh;
    width: 100%;
}

/* ==================== 右侧 TOC ==================== */
.xzwiki-right {
    position: sticky;
    top: 12px;
    flex: 0 0 190px;
    width: 190px;
    max-height: calc(100vh - 30px);
    overflow-y: auto;
    overflow-x: hidden;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    padding: 10px;
}

/* 首页 FMHY 模式默认隐藏 TOC（但保留 DOM 结构） */
.xzwiki-right-homepage {
    display: none !important;
}

.xzwiki-sidebar-title {
    font-size: 12.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #777;
    padding: 0 0 6px;
    margin: 0 0 6px;
    border-bottom: 1px solid #eee;
}

.xzwiki-toc-empty {
    color: #999;
    font-size: 12px;
    margin: 0;
}

/* TOC 列表逐层嵌套 */
.xzwiki-toc-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.xzwiki-toc-sublist {
    list-style: none;
    margin: 0 0 0 10px;
    padding: 0;
}

.xzwiki-toc-h2 a {
    display: block;
    padding: 3px 5px;
    font-size: 12px;
    font-weight: 600;
    color: #334155;
    text-decoration: none;
    border-radius: 2px;
    transition: background 0.15s;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.xzwiki-toc-h2 a:hover {
    background: #f0f4ff;
    color: #2563eb;
}

.xzwiki-toc-h3 a {
    display: block;
    padding: 2px 5px;
    font-size: 11.5px;
    color: #4a5568;
    text-decoration: none;
    border-radius: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.xzwiki-toc-h3 a:hover {
    background: #f0f4ff;
    color: #2563eb;
}

.xzwiki-toc-h4 a {
    display: block;
    padding: 2px 5px;
    font-size: 11px;
    color: #718096;
    text-decoration: none;
    border-radius: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.xzwiki-toc-h4 a:hover {
    background: #f0f4ff;
    color: #2563eb;
}

.xzwiki-toc-active {
    background: #eef2ff !important;
    color: #1d4ed8 !important;
    font-weight: 600;
}

/* ==================== 中间栏 ==================== */
.xzwiki-content {
    flex: 1 1 0;
    min-width: 0;
    width: 100%;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    padding: 22px 30px;
    overflow-wrap: break-word;
}

.xzwiki-article-title {
    font-size: 24px;
    font-weight: 800;
    line-height: 1.3;
    margin: 10px 0 16px 0;
    color: #111;
    padding-bottom: 10px;
    border-bottom: 2px solid #e5e7eb;
}

/* 正文排版 */
.xzwiki-article-body h2 {
    font-size: 20px;
    font-weight: 700;
    margin: 26px 0 10px 0;
    padding-bottom: 6px;
    border-bottom: 1px solid #eee;
    color: #1e293b;
}

.xzwiki-article-body h3 {
    font-size: 17px;
    font-weight: 600;
    margin: 18px 0 8px 0;
    color: #334155;
}

.xzwiki-article-body h4 {
    font-size: 15px;
    font-weight: 600;
    margin: 14px 0 6px 0;
    color: #475569;
}

.xzwiki-article-body p {
    margin: 0 0 12px 0;
    line-height: 1.75;
}

.xzwiki-article-body a {
    color: #2563eb;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.xzwiki-article-body ul,
.xzwiki-article-body ol {
    margin: 0 0 12px 0;
    padding-left: 20px;
}

.xzwiki-article-body pre,
.xzwiki-article-body code {
    font-family: 'Fira Code', 'Consolas', 'Monaco', monospace;
    font-size: 13px;
}

.xzwiki-article-body pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 12px 16px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 12px 0;
}

.xzwiki-article-body code {
    background: #f1f5f9;
    padding: 2px 4px;
    border-radius: 3px;
}

.xzwiki-article-body pre code {
    background: transparent;
    padding: 0;
}

.xzwiki-article-body blockquote {
    margin: 12px 0;
    padding: 8px 16px;
    border-left: 4px solid #2563eb;
    background: #f8fafc;
    color: #475569;
}

.xzwiki-article-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
}

.xzwiki-article-body th,
.xzwiki-article-body td {
    border: 1px solid #e2e8f0;
    padding: 7px 10px;
    text-align: left;
}

.xzwiki-article-body th {
    background: #f8fafc;
    font-weight: 600;
}

.xzwiki-article-body img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
}

/* 加载 & 错误 */
.xzwiki-loading,
.xzwiki-error {
    padding: 30px 20px;
    text-align: center;
    color: #888;
    font-size: 14px;
}

.xzwiki-error {
    color: #dc2626;
}

/* ==================== 响应式 ==================== */
@media (max-width: 1024px) {
    .xzwiki-right {
        flex-basis: 160px;
        width: 160px;
    }
    .xzwiki-content {
        padding: 16px 20px;
    }
}

/* ==================== 移动端 ==================== */
@media (max-width: 768px) {
    #xzwiki-wrap.xzwiki-container {
        flex-direction: column;
    }

    /* 右侧 TOC 折叠为汉堡图标 */
    .xzwiki-right {
        position: fixed;
        top: auto;
        bottom: 0;
        right: 0;
        width: 100% !important;
        flex: none !important;
        max-height: 0 !important;
        overflow: hidden !important;
        border-radius: 12px 12px 0 0;
        z-index: 9995;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.12);
        transition: max-height 0.35s ease;
        order: 3;
        padding: 0;
        background: #fff;
    }

    .xzwiki-right.toc-open {
        max-height: 50vh !important;
        overflow-y: auto !important;
        padding: 12px 14px 20px;
    }

    .xzwiki-content {
        padding: 14px;
        padding-bottom: 50px; /* 给底部 TOC 触发按钮留空间 */
    }

    /* TOC 触发按钮（右下角三条横线） */
    .xzwiki-toc-toggle {
        display: flex !important;
        position: fixed;
        bottom: 70px;
        right: 12px;
        z-index: 99999;
        width: 28px;
        height: 28px;
        background: none !important;
        color: #6b7280;
        border: none;
        align-items: center;
        justify-content: center;
        font-size: 22px;
        cursor: pointer;
        padding: 0;
        pointer-events: auto;
        touch-action: manipulation;
        opacity: 0.65;
        transition: opacity 0.15s;
        box-shadow: none !important;
        border-radius: 0 !important;
    }
    .xzwiki-toc-toggle:active {
        opacity: 1;
    }
    .xzwiki-toc-toggle.toc-open {
        display: none;
    }
    .xzwiki-toc-toggle:hover {
        background: none !important;
        transform: none !important;
    }

    /* 桌面端隐藏 TOC 按钮 */
    .xzwiki-toc-toggle {
        display: none;
    }
}

/* ==================== 文章页 Wiki 模式 ==================== */
body.wiki-post .xzwiki-article-body .entry-meta,
body.wiki-post .xzwiki-article-body .post-meta {
    font-size: 13px;
    color: #6b7280;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #f0f0f5;
}

body.wiki-post .xzwiki-article-body .tags {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid #e5e7eb;
}

body.wiki-post .xzwiki-article-body .tags strong {
    font-size: 13px;
    color: #6b7280;
}

body.wiki-post .xzwiki-article-body .tags a {
    display: inline-block;
    padding: 2px 10px;
    margin: 2px 4px 2px 0;
    background: #f1f5f9;
    border-radius: 4px;
    font-size: 12px;
    color: #475569;
    text-decoration: none;
    transition: background 0.15s;
}

body.wiki-post .xzwiki-article-body .tags a:hover {
    background: #e2e8f0;
    color: #1e293b;
}

/* 文章页网址信息栏适配 */
body.wiki-post .website-info-bar {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 14px 18px;
    margin-bottom: 16px;
}

body.wiki-post .website-info-inner {
    display: flex;
    align-items: flex-start;
    gap: 14px;
}

body.wiki-post .website-thumb img {
    width: 56px;
    height: 56px;
    border-radius: 8px;
    object-fit: cover;
}

body.wiki-post .website-details {
    flex: 1;
    min-width: 0;
}

body.wiki-post .website-name {
    font-size: 15px;
    font-weight: 700;
    margin: 0 0 4px;
    color: #1e293b;
}

body.wiki-post .website-official-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    color: #fff;
    background: #2563eb;
    padding: 1px 6px;
    border-radius: 3px;
    vertical-align: middle;
    margin-left: 6px;
}

body.wiki-post .website-tags {
    margin-bottom: 4px;
}

body.wiki-post .website-tag {
    display: inline-block;
    font-size: 11px;
    color: #64748b;
    margin-right: 6px;
}

body.wiki-post .website-desc {
    font-size: 13px;
    color: #475569;
    margin: 4px 0;
    line-height: 1.5;
}

body.wiki-post .website-visit-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 14px;
    background: #2563eb;
    color: #fff;
    text-decoration: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    transition: background 0.15s;
    margin-top: 4px;
}

body.wiki-post .website-visit-btn:hover {
    background: #1d4ed8;
}

/* 文章页作者信息 & 相关文章适配 */
body.wiki-post .author-bio,
body.wiki-post .single-related-posts {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid #e5e7eb;
}

body.wiki-post .xzwiki-article-body .st-related-posts {
    margin-top: 24px;
}
