/* 基础：避免横向意外溢出，盒模型统一 */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    overflow-x: hidden;
    min-height: 100vh;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

/* 仅首页：锁定视口高度，禁止整页滚动；滚动只在侧栏 / 右侧正文框内 */
html.page-blog-home {
    height: 100%;
    overflow: hidden;
}

body.page-blog-home {
    height: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* 首页：Grid 左列跨两行（头像上沿 = 右侧导航栏上沿），右列上行导航、下行正文 */
.blog-container {
    flex: 1 1 0;
    min-height: 0;
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    max-width: 100%;
    overflow: hidden;
}

.sidebar {
    grid-column: 1;
    grid-row: 1 / -1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: #f8f9fa;
    /* 顶对齐导航栏：上内边距为 0，头像区域上沿与 .main-header 上沿同高 */
    padding: 0 16px 16px 20px;
    border-right: 1px solid #dee2e6;
    box-shadow: 2px 0 5px rgba(0,0,0,0.1);
}

.blog-main-column {
    grid-column: 2;
    grid-row: 2;
    min-height: 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.blog-container > .main-header {
    grid-column: 2;
    grid-row: 1;
    align-self: stretch;
}

/* 左侧「文件列表」独立滚动区（头像/简介固定在上） */
.sidebar-list-scroll {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.28) rgba(0, 0, 0, 0.06);
    margin: 0 -4px 0 0;
    padding-right: 4px;
}

.sidebar-list-scroll::-webkit-scrollbar {
    width: 10px;
}

.sidebar-list-scroll::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.18);
    border-radius: 6px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

.sidebar-list-scroll::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.04);
    border-radius: 6px;
}

.main-content {
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 20px;
    background-color: #ffffff;
}

.profile {
    /* 供 .profile-desc 使用 cqi 随侧栏宽度缩放字号 */
    container-type: inline-size;
    container-name: profile;
    flex-shrink: 0;
    text-align: center;
    margin-bottom: 16px;
    padding: 20px;
    background-color: #ffffff;
    border-radius: 10px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

/* 与右侧导航栏同一行顶对齐：上内边距为 0，头像上沿与 .main-header 上沿一致 */
.profile.profile--nav-row {
    padding-top: 0;
    margin-top: 0;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}

.profile h3 {
    color: #2c3e50;
    margin-bottom: 10px;
    font-weight: 600;
}

.profile-desc {
    color: #666;
    /* 单行不折行；默认用 vw 缩放，避免极窄时溢出 */
    font-size: clamp(0.55rem, 0.22rem + 1.35vw, 0.85rem);
    line-height: 1.45;
    margin: 0;
    padding: 10px;
    border-top: 1px solid #eee;
    margin-top: 10px;
    font-family: 'Segoe UI', 'Microsoft YaHei', Arial, sans-serif;
    font-weight: 500;
    letter-spacing: 0.04em;
    white-space: nowrap;
    overflow: hidden;
    max-width: 100%;
    word-break: keep-all;
    word-wrap: normal;
    overflow-wrap: normal;
    text-align: center;
}

/* 支持容器查询时：按 .profile 实际宽度缩放，比 vw 更贴合侧栏 */
@supports (font-size: 1cqi) {
    .profile-desc {
        font-size: clamp(0.52rem, calc(0.3rem + 3.5cqi), 0.85rem);
    }
}

.avatar {
    width: 150px;
    height: 150px;
    border-radius: 50%;
    margin-bottom: 15px;
    border: 3px solid #ffffff;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    transition: transform 0.3s ease;
}

.avatar:hover {
    transform: scale(1.05);
}

.blog-list {
    list-style: none;
    padding: 0;
}

.blog-list li.blog-list-item {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 15px;
    border-bottom: 1px solid #dee2e6;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.3s ease;
    border-radius: 5px;
    margin-bottom: 5px;
}

/* 文件类型角标（MD / DOC / PDF） */
.blog-list-kind {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.9rem;
    min-height: 1.45rem;
    padding: 0.15rem 0.35rem;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    line-height: 1;
    border-radius: 4px;
    margin-top: 0.1rem;
    user-select: none;
}

.blog-list-kind--md {
    background: #e0f2f1;
    color: #00695c;
    border: 1px solid #b2dfdb;
}

.blog-list-kind--docx {
    background: #e3f2fd;
    color: #0d47a1;
    border: 1px solid #90caf9;
}

.blog-list-kind--pdf {
    background: #ffebee;
    color: #b71c1c;
    border: 1px solid #ef9a9a;
}

.blog-list-kind--unknown {
    background: #f5f5f5;
    color: #616161;
    border: 1px solid #e0e0e0;
}

.blog-list-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.blog-list-name {
    font-size: 0.95rem;
    line-height: 1.35;
    word-break: break-word;
    overflow-wrap: anywhere;
    color: #2c3e50;
}

.blog-list-time {
    display: block;
    font-size: 0.72rem;
    color: #6c757d;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}

.blog-list li:hover {
    background-color: #e9ecef;
    transform: translateX(5px);
}

@media (hover: none) {
    .blog-list li:hover {
        transform: none;
    }

    .blog-list li:active {
        background-color: #e2e6ea;
    }
}

/* 右侧正文：单独滚动区域（与左侧列表互不抢滚动条） */
#blog-content.blog-content-scroll {
    flex: 1 1 0;
    min-height: 0;
    /* auto：仅溢出时出现滚动条；Windows 可配合下方 webkit 样式看到滚动条 */
    overflow-y: auto;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* 避免滚轮穿透到整页（部分浏览器） */
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.28) rgba(0, 0, 0, 0.06);
    padding: 20px;
    background-color: #ffffff;
    border-radius: 10px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    line-height: 1.6;
    max-width: 100%;
}

/* WebKit 滚动条略细，避免占满视觉 */
#blog-content.blog-content-scroll::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

#blog-content.blog-content-scroll::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.18);
    border-radius: 6px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

#blog-content.blog-content-scroll::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.04);
    border-radius: 6px;
}

.blog-content-placeholder {
    margin: 0;
    padding: 0.5rem 0;
    font-size: 0.95rem;
}

.blog-content-title {
    font-size: 1.5rem;
    color: #2c3e50;
    margin-bottom: 0.75rem;
}

/* Markdown / Word 富文本渲染区域 */
.blog-article.rich-text-body {
    max-width: 52rem;
    font-size: 1rem;
    color: #333;
}

.blog-article.rich-text-body img {
    max-width: 100%;
    height: auto;
}

.blog-article.rich-text-body h1,
.blog-article.rich-text-body h2,
.blog-article.rich-text-body h3,
.blog-article.rich-text-body h4 {
    margin-top: 1.25rem;
    margin-bottom: 0.75rem;
    font-weight: 600;
    color: #1a1a1a;
}

.blog-article.rich-text-body p {
    margin-bottom: 1rem;
}

.blog-article.rich-text-body ul,
.blog-article.rich-text-body ol {
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}

.blog-article.rich-text-body blockquote {
    border-left: 4px solid #cfd8dc;
    margin: 1rem 0;
    padding: 0.5rem 1rem;
    color: #555;
    background: #f8f9fa;
}

.blog-article.rich-text-body pre {
    background: #f4f4f4;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 1rem;
    overflow-x: auto;
    font-size: 0.9rem;
}

.blog-article.rich-text-body code {
    font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
    font-size: 0.92em;
    background: #f0f0f0;
    padding: 0.15em 0.4em;
    border-radius: 4px;
}

.blog-article.rich-text-body pre code {
    background: transparent;
    padding: 0;
}

.blog-article.rich-text-body hr {
    margin: 1.5rem 0;
    border: 0;
    border-top: 1px solid #dee2e6;
}

.blog-article.rich-text-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
}

.blog-article.rich-text-body th,
.blog-article.rich-text-body td {
    border: 1px solid #dee2e6;
    padding: 0.5rem 0.75rem;
    text-align: left;
}

.blog-article.rich-text-body th {
    background: #f8f9fa;
}

/* PyMuPDF 导出的 PDF HTML：允许横向滚动、图片不撑破布局 */
.blog-article .pdf-native-html {
    overflow-x: auto;
    max-width: 100%;
    font-size: 14px;
    line-height: 1.5;
}

.blog-article .pdf-native-html img {
    max-width: 100%;
    height: auto;
}

.blog-plain {
    white-space: pre-wrap;
    word-break: break-word;
}

.btn-primary {
    width: 100%;
    padding: 10px;
    border-radius: 5px;
    transition: all 0.3s ease;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.main-header {
    width: 100%;
    background: linear-gradient(90deg, #e0eafc 0%, #cfdef3 100%);
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    padding: 18px 0 10px 0;
    margin-bottom: 0.5rem;
}

body.page-blog-home .main-header {
    flex-shrink: 0;
    margin-bottom: 0;
}

/* 顶栏：Flex — 左占位 | 标题 | 右侧区（公众号+二维码靠导航栏最右） */
.main-header-inner {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px 16px;
    padding-left: 12px;
    padding-right: 12px;
    max-width: 100%;
    box-sizing: border-box;
}

.header-side-left,
.header-side-right {
    flex: 1 1 0;
    min-width: 0;
}

.header-side-right {
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

.blog-title {
    flex: 0 1 auto;
    text-align: center;
    max-width: min(72vw, 28rem);
    min-width: 0;
    font-size: 2.1rem;
    color: #2c3e50;
    font-weight: 700;
    letter-spacing: 0.12em;
    margin: 0;
    font-family: 'Segoe UI', 'Microsoft YaHei', Arial, sans-serif;
    padding-left: 0;
    padding-right: 0;
    word-break: break-word;
}

.header-wechat {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex-shrink: 0;
    text-align: center;
}

.header-wechat-label {
    font-size: 0.8rem;
    color: #34495e;
    font-weight: 600;
    white-space: nowrap;
    letter-spacing: 0.06em;
}

.header-wechat-qrcode {
    display: block;
    width: 88px;
    height: auto;
    max-height: 88px;
    object-fit: contain;
    border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
    background: #fff;
}

/* ——— 移动端专用元素：桌面默认隐藏 ——— */
.mobile-list-btn  { display: none; }
.mobile-profile   { display: none; }
.mobile-hint      { display: none; }

/* ——— 移动端 / 窄屏 ——— */
@media screen and (max-width: 767.98px) {

    /* 顶栏内边距收紧 */
    .main-header-inner {
        gap: 8px 10px;
        padding-left: 8px;
        padding-right: 8px;
    }

    /* 移动端切换按钮 */
    .mobile-list-btn {
        display: inline-flex;
        align-items: center;
        gap: 5px;
        padding: 6px 12px;
        background: rgba(255, 255, 255, 0.75);
        border: 1px solid rgba(44, 62, 80, 0.2);
        border-radius: 20px;
        font-size: 0.82rem;
        font-weight: 600;
        color: #2c3e50;
        cursor: pointer;
        white-space: nowrap;
        transition: background 0.15s ease;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-list-btn:active,
    .mobile-list-btn.is-open {
        background: rgba(255, 255, 255, 0.95);
        border-color: rgba(44, 62, 80, 0.4);
    }

    .mobile-list-btn-icon {
        font-size: 1rem;
        line-height: 1;
    }

    /*
     * Grid：单列两行（header + main）。
     * sidebar 脱离 grid 流，用 position:fixed 左侧抽屉实现。
     */
    .blog-container {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
        flex: 1 1 0;
        min-height: 0;
        overflow: hidden;
    }

    .blog-container > .main-header {
        grid-column: 1;
        grid-row: 1;
        position: relative;
        z-index: 300;
    }

    .blog-main-column {
        grid-column: 1;
        grid-row: 2;
        flex: 1 1 0;
        min-height: 0;
    }

    /*
     * 侧栏：固定左侧抽屉，默认 translateX(-100%) 隐藏在屏幕外。
     * 添加 sidebar--open 类后向右滑入可见区域。
     */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(82vw, 300px);
        z-index: 250;
        transform: translateX(-100%);
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        border-right: 1px solid #dee2e6;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.18);
        padding: 16px 14px 20px;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        background-color: #f8f9fa;
    }

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

    /* 抽屉内头像适当缩小 */
    .sidebar .avatar {
        width: 80px;
        height: 80px;
    }

    .sidebar .profile {
        padding: 12px 10px;
        margin-bottom: 10px;
    }

    /* 遮罩层（JS 动态创建） */
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        z-index: 200;
        background: rgba(0, 0, 0, 0.4);
    }

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

    /* 移动端内容区：显示头像初始卡片 */
    .mobile-profile {
        display: block;
        margin-bottom: 12px;
    }

    .mobile-profile .avatar {
        width: 100px;
        height: 100px;
    }

    .mobile-hint  { display: block; }
    .desktop-hint { display: none; }

    .main-content {
        flex: 1 1 0;
        min-height: 0;
        padding: 12px;
    }

    #blog-content.blog-content-scroll {
        padding: 14px;
    }

    .blog-title {
        font-size: clamp(1.1rem, 5vw, 1.6rem);
        letter-spacing: 0.06em;
        line-height: 1.3;
    }

    .blog-content-title {
        font-size: 1.2rem;
        word-break: break-word;
    }

    .blog-list li.blog-list-item {
        min-height: 44px;
        align-items: flex-start;
        padding: 10px 12px;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.06);
    }

    .blog-list-name {
        font-size: 0.9rem;
    }

    .blog-list-time {
        font-size: 0.68rem;
    }

    .blog-list li:hover {
        transform: none;
    }

    .blog-article.rich-text-body {
        font-size: 0.95rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }

    .blog-article.rich-text-body pre {
        font-size: 0.82rem;
    }

    .blog-article.rich-text-body table {
        min-width: min(100%, max-content);
    }
}

/* 超窄屏（小手机） */
@media screen and (max-width: 380px) {
    .blog-title {
        font-size: 1.1rem;
    }
}