/* ===========================================
   components/sticky_toc.css
   页内目录组件（桌面侧栏 / 移动横滑 sticky chip）
   · 类名：.nd-sticky-toc / __title / __list / __item / __link
   · 模板：common/_sticky_toc.html（Information 母版同构 markup）
   · JS：information_toc.js
   · 禁止写 :root（令牌在 lp_tokens）
   · 移动 sticky top 只用固定令牌，禁止跟 --header-offset（地址栏/scroll 会抖）
=========================================== */

.nd-sticky-toc {
    position: sticky;
    top: calc(var(--header-topbar-height) + var(--header-height-nav) + var(--lp-spacing-md));
    background: var(--lp-surface);
    border-radius: var(--lp-radius);
    padding: var(--lp-spacing-lg);
    border: 1px solid var(--lp-border-light);
    min-width: 0;
    max-width: 100%;
}

.nd-sticky-toc__title {
    font-family: var(--lp-font);
    font-size: var(--lp-font-size-h4, 1.125rem);
    font-weight: var(--lp-font-weight-subhead, 500);
    color: var(--lp-text-primary);
    margin: 0 0 var(--lp-spacing-md);
    padding-bottom: var(--lp-spacing-sm);
    border-bottom: 1px solid var(--lp-border-light);
}

.nd-sticky-toc__list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.nd-sticky-toc__item {
    margin-bottom: var(--lp-spacing-xs);
}

.nd-sticky-toc__link {
    display: block;
    padding: var(--lp-spacing-sm) var(--lp-spacing-md);
    color: var(--lp-text-secondary);
    text-decoration: none;
    border-radius: 4px;
    font-size: var(--lp-font-size-nav, 0.875rem);
    font-family: var(--lp-font);
    font-weight: 400;
    line-height: 1.5;
    transition: background 0.2s ease, color 0.2s ease;
}

.nd-sticky-toc__link:hover {
    background: var(--lp-hover-bg);
    color: var(--lp-primary-color);
}

.nd-sticky-toc__link.active {
    background: var(--lp-primary-color);
    color: #fff;
    font-weight: 500;
}

@media (max-width: 768px) {
    .nd-sticky-toc {
        position: -webkit-sticky;
        position: sticky;
        top: calc(var(--header-height-nav) + var(--lp-breadcrumb-bar-height));
        z-index: 400;
        margin: 0;
        /* 上下对称：chip 距条顶 = 距条底（对齐服务器 Privacy） */
        padding: 12px 0;
        border-radius: 0;
        border: none;
        border-bottom: 1px solid var(--lp-border-light);
        box-shadow: none;
        background: var(--lp-surface);
        width: 100%;
        max-width: 100%;
        min-width: 0;
        /* 不用 overflow:hidden：真机 sticky 条易抖；裁切交给内部 list */
        /* 禁止 transform/filter：会生成含块，sticky 易「钉死视口」盖住 Footer */
        overflow: visible;
        overflow-anchor: none;
    }

    .nd-sticky-toc:not(:has(.nd-sticky-toc__item)) {
        display: none !important;
    }

    .nd-sticky-toc__title {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    .nd-sticky-toc__list {
        display: flex;
        flex-wrap: nowrap;
        gap: 8px;
        width: 100%;
        max-width: 100%;
        min-width: 0;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        /* 上下 0：条的对称空隙只来自 .nd-sticky-toc 的 padding */
        padding: 0 var(--lp-spacing-lg);
        scroll-padding-inline: var(--lp-spacing-lg);
        box-sizing: border-box;
        touch-action: pan-x;
        overscroll-behavior-x: contain;
        overscroll-behavior-y: none;
    }

    .nd-sticky-toc__list::-webkit-scrollbar {
        display: none;
    }

    .nd-sticky-toc__item {
        margin-bottom: 0;
        flex-shrink: 0;
    }

    .nd-sticky-toc__link {
        padding: 7px 12px;
        background: var(--lp-surface);
        border: 1px solid var(--lp-border-light);
        border-radius: 999px;
        font-size: var(--lp-font-size-nav, 0.875rem);
        /* 固定字重：active 时勿加粗，否则 chip 变宽 → 横条抖动 */
        font-weight: 500;
        white-space: nowrap;
        line-height: 1.3;
        touch-action: manipulation;
    }

    .nd-sticky-toc__link.active {
        background: var(--lp-primary-color);
        color: #fff;
        border-color: var(--lp-primary-color);
        box-shadow: none;
        font-weight: 500;
    }
}

@media (max-width: 480px) {
    .nd-sticky-toc__list {
        padding-left: var(--lp-spacing-md);
        padding-right: var(--lp-spacing-md);
        scroll-padding-inline: var(--lp-spacing-md);
    }
}
