/* =========================================================
   1. 防抖：消除长短页面切换时的“滚动条布局偏移”
   ========================================================= */
html {
    /* 现代标准：始终为滚动条预留出物理空间 */
    scrollbar-gutter: stable;
    /* 兜底防御：针对不支持 scrollbar-gutter 的老旧浏览器 */
    overflow-y: scroll;
}

/* =========================================================
   2. 全局变量与基础重置
   ========================================================= */
:root {
    /* JS 动态注入的 Footer 重叠高度计算值（勿动） */
    --zcnote-footer-overlap: 0px;

    /* 左侧边栏宽度控制阀（自由调节，推荐 12rem ~ 15rem，原版为22rem左右） */
    --zcnote-sidebar-width: 20rem;
}

/* 文本两端对齐与长词换行保护，提升技术文档阅读体验 */
.bd-article p, .bd-article li {
    text-align: justify;
    text-justify: inter-word;
    overflow-wrap: break-word;
    word-wrap: break-word;
}

/* 页面基准设定，打破外层包裹限制，为 Footer 绝对定位做准备 */
body {
    position: relative !important;
    min-height: 100vh;
    overflow-x: clip;
}

.bd-page-width {
    position: static !important;
}

/* =========================================================
   3. Footer 绝对覆盖图层
   ========================================================= */
.bd-footer {
    position: absolute !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    margin: 0 !important;
    z-index: 100 !important;
    background-color: var(--pst-color-background) !important;
    border-top: 1px solid var(--pst-color-border) !important;
}

/* =========================================================
   4. 大屏布局控制：侧边栏、Header对齐与零跳动滚动
   ========================================================= */
@media (min-width: 1200px) {

    /* --- 4.1 Header 顶部栏与左侧边栏像素级对齐 --- */
    .bd-header .navbar-header-items__start {
        width: var(--zcnote-sidebar-width) !important;
        flex: 0 0 var(--zcnote-sidebar-width) !important;
        max-width: var(--zcnote-sidebar-width) !important;
    }

    .bd-header .navbar-header-items {
        flex: 1 1 auto !important;
        width: auto !important;
        max-width: 100% !important;
    }

    .bd-header .navbar-header-items__start .navbar-brand {
        padding-left: 0.5rem !important;
    }

    /* --- 4.2 左侧边栏尺寸接管与折叠兼容 --- */
    .bd-sidebar-primary {
        width: var(--zcnote-sidebar-width);
        max-width: var(--zcnote-sidebar-width);
        flex: 0 0 auto; /* 放弃 Flex 霸权，听从 width 指挥 */

        /* 为 JS 触发的折叠动作注入 Material Design 标准丝滑缓冲动画 */
        transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                    max-width 0.25s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }

    /* 微调左侧边栏内部留白，向正文归还更多阅读空间 */
    #pst-primary-sidebar .sidebar-primary-item {
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
    }

    #pst-primary-sidebar .bd-toc-item {
        padding-right: 0.5rem !important;
    }

    /* --- 4.3 双侧边栏动态防跳动滚动计算 --- */
    #pst-primary-sidebar,
    #pst-secondary-sidebar {
        align-self: start !important;
        position: sticky !important;
        top: var(--pst-header-height) !important;

        /* 使用 dvh 兼容移动端浏览器地址栏的伸缩，并减去 Footer 遮挡 */
        height: calc(100dvh - var(--pst-header-height) - var(--zcnote-footer-overlap)) !important;
        max-height: calc(100dvh - var(--pst-header-height) - var(--zcnote-footer-overlap)) !important;

        /* 还原空间，防滚动条误触 */
        padding-bottom: 0 !important;
        margin-bottom: 0 !important;

        overflow-y: auto !important;
        scrollbar-width: thin;
    }
}

/* =========================================================
   5. Admonition (提示框) 极简定制 - 四边等宽彩色边框
   ========================================================= */
/* 基础容器：设置默认主色（Primary）边框，替代冗长的 :not() 兜底选择器 */
div.admonition {
    border: 1px solid var(--pst-color-primary) !important;
    border-radius: 0.25rem !important;
    box-shadow: none !important;
}

/* 颜色语义精准映射（利用 CSS 层叠性自动覆盖上方默认的 Primary 颜色） */
div.admonition.note,
div.admonition.info,
div.admonition.hint {
    border-color: var(--pst-color-info) !important;
}

div.admonition.tip,
div.admonition.success {
    border-color: var(--pst-color-success) !important;
}

div.admonition.warning,
div.admonition.attention,
div.admonition.important,
div.admonition.caution {
    border-color: var(--pst-color-warning) !important;
}

div.admonition.danger,
div.admonition.error {
    border-color: var(--pst-color-danger) !important;
}

div.admonition.seealso {
    border-color: var(--pst-color-secondary) !important;
}

/* =========================================================
   6. 修复：MathJax/Sphinx 公式垂直滚动条
   remove this when pydata fix it!!
   ========================================================= */
/* 1. 镇压 Sphinx 的外层容器 */
.bd-article div.math,
.bd-article div.math-wrapper,
div.math.notranslate {
    overflow-x: auto !important;
    overflow-y: hidden !important;
    padding-top: 0.5em !important;
    padding-bottom: 0.5em !important;
    min-height: min-content !important;
}

/* 2. 镇压 MathJax 3 的原生渲染容器 */
mjx-container[display="true"],
.MathJax_Display {
    overflow-y: hidden !important;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    outline: none !important; /* 防止内部轮廓线撑破容器 */
}

/* 3. 镇压 MathJax 最深层的数学节点 */
mjx-container[display="true"] > mjx-math,
mjx-container[display="true"] > mjx-math * {
    overflow-y: visible !important;
}
