/* ==========================================================================
   文章详情页 · 侧栏模块（文章结构 = 目录 / 相关文章）
   BAKESLA 四站共用（com / cn / my / id）· 2026-11-05
   --------------------------------------------------------------------------
   设计约束：
   1. 只作用于 .article-aside 与 .as-* 命名空间，不改动任何既有类
   2. 侧栏吸顶只依赖 position:sticky，父级不得有 overflow:hidden
   3. ≥992px 显示右侧栏（8/4 双栏）；<992px 侧栏改为静态，目录上移到正文顶部
   4. 品牌红 #ff3131 与白字对比度仅 3.65:1，故激活态用深红字 + 浅红底
   ========================================================================== */

/* ---------- 版式：8/4 双栏 ----------
   注意：com 站的 all.min.css 是经过 purge 的打包产物，里面**没有** .col-lg-8 与 .col-12，
   所以这里不复用 Bootstrap 栅格，改为自带宽度规则，四站行为一致。 */
.as-layout {
    display: flex;
    flex-wrap: wrap;
}

.as-layout > .as-main,
.as-layout > .as-side {
    flex: 0 0 auto;
    min-width: 0;
    width: 100%;
}

@media (min-width: 1200px) {
    .as-layout > .as-main {
        width: 66.666667%;
    }

    .as-layout > .as-main.as-main-full {
        width: 100%;
    }

    .as-layout > .as-side {
        width: 33.333333%;
    }
}

/* ---------- sticky 生效的必要修复 ----------
   本站主题给 body 设了 overflow-x:hidden（实际计算为 overflow:hidden auto）。
   这会让 body 成为「滚动容器」，而页面实际滚动的是视口，于是内部 position:sticky
   永远不会触发（实测：滚动 1500px 后侧栏 top 从 24px 变成 -988px）。
   改成 overflow-x:clip —— 横向裁切效果不变，但不会建立滚动容器，sticky 恢复。
   该文件只在「启用侧栏的文章页」加载，其它页面行为不受影响。 */
body {
    overflow-x: clip;
}

.article-aside {
    position: -webkit-sticky;
    position: sticky;
    top: 24px;
    max-height: calc(100vh - 48px);
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow: hidden;
    font-family: 'Inter', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
}

.as-card {
    position: relative;
    background: #fff;
    border: 1px solid #ececec;
    border-radius: 5px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.as-card-title {
    position: relative;
    margin: 0 0 12px;
    padding-left: 12px;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.4;
    letter-spacing: 0.01em;
    color: #1a1a1a;
}

.as-card-title::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    width: 3px;
    height: 15px;
    margin-top: -7.5px;
    background: #ff3131;
    border-radius: 2px;
}

/* ---------- ① 文章结构 ---------- */
/* 高度预算：目录可收缩并内部滚动，相关文章不收缩（始终完整可见） */
.as-card.as-toc {
    display: flex;
    flex-direction: column;
    flex: 0 1 auto;
    min-height: 0;
}

.as-toc-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
}

.as-toc-list::-webkit-scrollbar {
    width: 5px;
}

.as-toc-list::-webkit-scrollbar-thumb {
    background: #dcdcdc;
    border-radius: 3px;
}

.as-toc-link {
    display: block;
    padding: 7px 10px 7px 11px;
    border-left: 3px solid transparent;
    border-radius: 0 4px 4px 0;
    font-size: 13.5px;
    line-height: 1.55;
    color: #5c636a;
    text-decoration: none;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.as-toc-link span {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.as-toc-link:hover,
.as-toc-link:focus-visible {
    color: #1a1a1a;
    background: #f7f7f7;
    outline: none;
}

.as-toc-link.is-lv3 {
    padding-left: 24px;
    font-size: 13px;
}

.as-toc-link.is-active {
    color: #b91c1c;
    background: #fff3f3;
    border-left-color: #ff3131;
    font-weight: 600;
}

/* ---------- ② 相关文章 ---------- */
.as-card.as-related {
    flex: 0 0 auto;
    min-height: 0;
}

/* 兜底：视口很矮时相关文章自身内部滚动，绝不顶出屏幕 */
.as-related-list {
    max-height: 46vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
}

.as-related-list::-webkit-scrollbar {
    width: 5px;
}

.as-related-list::-webkit-scrollbar-thumb {
    background: #dcdcdc;
    border-radius: 3px;
}

.as-related-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.as-related-list li {
    border-bottom: 1px solid #f2f2f2;
}

.as-related-list li:last-child {
    border-bottom: 0;
}

.as-related-list a {
    display: block;
    padding: 9px 0;
    text-decoration: none;
}

.as-related-list li:first-child a {
    padding-top: 0;
}

.as-related-list li:last-child a {
    padding-bottom: 0;
}

.as-rel-title {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 13.5px;
    line-height: 1.55;
    color: #2b2b2b;
    transition: color 0.15s ease;
}

.as-related-list a:hover .as-rel-title,
.as-related-list a:focus-visible .as-rel-title {
    color: #ff3131;
}

.as-related-list a:focus-visible {
    outline: 2px solid #ff3131;
    outline-offset: 2px;
    border-radius: 2px;
}

.as-rel-meta {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    line-height: 1.4;
    color: #9aa0a6;
    font-variant-numeric: tabular-nums;
}

/* ---------- 正文内标题的锚点留白（供浏览器原生 #hash 跳转使用） ---------- */
.content-detail-box .content h2,
.content-detail-box .content h3 {
    scroll-margin-top: 96px;
}

/* 正文收窄后宽表格的横向滚动兜底（由 JS 包裹） */
.as-table-wrap {
    max-width: 100%;
    overflow-x: auto;
}

/* ---------- ③ 移动端目录（<details> 折叠块，位于正文上方） ---------- */
.as-mobile-toc {
    display: none;
}

@media screen and (max-width: 1199.98px) {
    .article-aside {
        position: static;
        max-height: none;
        margin-top: 20px;
    }

    /* 目录已上移到正文顶部，侧栏里只保留相关文章 */
    .as-card.as-toc {
        display: none;
    }

    .as-mobile-toc {
        display: block;
        margin-bottom: 16px;
        padding: 0 18px;
        background: #fff;
        border: 1px solid #ececec;
        border-radius: 5px;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    }

    .as-mobile-toc > summary {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 14px 0;
        font-size: 14px;
        font-weight: 700;
        color: #1a1a1a;
        cursor: pointer;
        list-style: none;
    }

    .as-mobile-toc > summary::-webkit-details-marker {
        display: none;
    }

    .as-mobile-toc[open] > summary {
        border-bottom: 1px solid #f2f2f2;
    }

    .as-mobile-toc .as-chev {
        flex: 0 0 auto;
        margin-left: 10px;
        transition: transform 0.2s ease;
    }

    .as-mobile-toc[open] .as-chev {
        transform: rotate(180deg);
    }

    .as-mobile-toc .as-toc-list {
        max-height: 46vh;
        padding: 4px 0 10px;
    }

    .as-card {
        padding: 18px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .as-toc-link,
    .as-rel-title,
    .as-mobile-toc .as-chev {
        transition: none;
    }
}

@media print {
    .article-aside,
    .as-mobile-toc {
        display: none !important;
    }
}
