/**
 * 文章目录小工具样式
 * 侧边栏目录卡片 + 顶部阅读进度条
 * 兼容浅色/暗色模式（跟随主题 CSS 变量）
 */

/* ============================================================
 * 侧边栏目录卡片
 * ============================================================ */
.article-toc {
    font-size: 14px;
}

/* 字数统计 + 阅读时长 */
.article-toc-meta {
    padding: 6px 10px;
    margin-bottom: 10px;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.03);
    color: var(--muted-color, #666);
    font-size: 13px;
    line-height: 1.6;
}
.article-toc-meta b {
    color: var(--theme-color, #007bff);
    font-weight: 600;
}

/* 目录列表 */
.article-toc-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 420px;
    overflow-y: auto;
}

.article-toc-item {
    line-height: 1.5;
    margin: 0;
}

.article-toc-item a {
    display: block;
    padding: 5px 10px;
    border-left: 3px solid transparent;
    color: var(--muted-color, #666);
    text-decoration: none;
    border-radius: 0 4px 4px 0;
    transition: color .2s, background-color .2s, border-color .2s;
    word-break: break-word;
}

/* H3 ~ H6 逐级缩进（H2 为基准层，不缩进） */
.article-toc-item.article-toc-h3 a {
    padding-left: 24px;
    font-size: 13px;
}
.article-toc-item.article-toc-h4 a {
    padding-left: 38px;
    font-size: 12.5px;
}
.article-toc-item.article-toc-h5 a {
    padding-left: 52px;
    font-size: 12.5px;
}
.article-toc-item.article-toc-h6 a {
    padding-left: 66px;
    font-size: 12px;
}

.article-toc-item a:hover {
    color: var(--theme-color, #007bff);
    background: rgba(0, 0, 0, 0.03);
    border-left-color: var(--theme-color, #007bff);
}

/* 当前阅读章节高亮 */
.article-toc-item.is-active a {
    color: var(--theme-color, #007bff);
    background: rgba(0, 0, 0, 0.05);
    border-left-color: var(--theme-color, #007bff);
    font-weight: 600;
}

/* 目录卡片自身滚动条（轻量） */
.article-toc-list::-webkit-scrollbar {
    width: 4px;
}
.article-toc-list::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 2px;
}
.article-toc-list::-webkit-scrollbar-track {
    background: transparent;
}

/* ============================================================
 * 阅读进度条（小工具内，字数统计下方）
 * 炫丽彩色：蓝→黄→红→绿四色渐变 + 斜条纹流动 + 百分比
 * 参考人生倒计时小工具的配色与动画
 * ============================================================ */
.article-toc-progress {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 2px 10px 10px;
}

.article-toc-progress-track {
    position: relative;
    flex: 1;
    height: 12px;
    background: rgba(0, 0, 0, 0.06);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* 彩色填充条：蓝→黄→红→绿渐变 + 斜条纹流动 */
.article-toc-progress-fill {
    position: relative;
    display: block;
    height: 100%;
    width: 0;
    border-radius: 10px;
    background-color: #3a7afe;
    /* 斜条纹（仿人生倒计时）+ 渐变 叠加 */
    background-image:
        linear-gradient(
            135deg,
            rgba(255, 255, 255, 0.30) 25%,
            transparent 25%,
            transparent 50%,
            rgba(255, 255, 255, 0.30) 50%,
            rgba(255, 255, 255, 0.30) 75%,
            transparent 75%,
            transparent 100%
        ),
        linear-gradient(
            90deg,
            #3a7afe 0%,
            #4aa8ff 25%,
            #f5a623 50%,
            #f1404b 75%,
            #67c23a 100%
        );
    background-size: 24px 24px, 100% 100%;
    animation: article-toc-stripes 0.8s linear infinite;
    box-shadow: 0 0 6px rgba(0, 0, 0, 0.15);
}

/* 进度条末端光晕（跟随 fill 宽度，出现在末端） */
.article-toc-progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    right: -1px;
    height: 100%;
    width: 7px;
    background: rgba(255, 255, 255, 0.95);
    filter: blur(2px);
    opacity: 0.9;
    border-radius: 0 10px 10px 0;
}

@keyframes article-toc-stripes {
    from { background-position: 0 0, 0 0; }
    to   { background-position: 24px 0, 0 0; }
}

/* 百分比数值 */
.article-toc-progress-pct {
    font-size: 12px;
    font-weight: 700;
    color: #3a7afe;
    min-width: 40px;
    text-align: right;
    font-variant-numeric: tabular-nums;
    background: linear-gradient(90deg, #3a7afe, #f1404b);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: #3a7afe;
    text-shadow: none;
}

/* ============================================================
 * 侧栏吸顶：滚动时目录卡片始终可见
 * ------------------------------------------------------------
 * 父主题用 theia-sticky-sidebar 接管 .sidebar-tools：把整列包进
 * .theiaStickySidebar 并按滚动方向整体平移。侧栏总高度超过一屏时，
 * 向上滚动这一列会被推走，目录卡片跟着离开视口。
 *
 * 因此目录卡片改为「自己吸顶」：
 *   - JS 给目录所在侧栏加 .io-toc-sticky-host（并下发 --io-toc-top /
 *     --io-toc-host-h 两个变量），给卡片加 .io-toc-sticky-card；
 *   - 这里让 theia 的包裹层回到普通文档流（!important 可压过内联样式），
 *     并把侧栏列撑到与正文等高，使 sticky 有足够滑动行程；
 *   - --io-toc-top 由 JS 按固定头部实测高度下发，改头部样式也不会被压住。
 * 侧栏在 <992px 是隐藏的（d-none d-lg-block），故规则只在桌面端生效。
 * ============================================================ */
@media (min-width: 992px) {
    /* 让 theia 的包裹层回到普通文档流（内联的 fixed/absolute + transform 失效），
       并把它拉高：包裹层是卡片直接的 containing block，若侧栏只有目录一个小工具，
       它原本的高度刚好等于卡片高度，sticky 行程为 0 等于没生效 */
    .io-toc-sticky-host .theiaStickySidebar {
        position: static !important;
        top: auto !important;
        left: auto !important;
        width: auto !important;
        transform: none !important;
        min-height: var(--io-toc-host-h, auto) !important;
    }

    /* 侧栏列与正文等高：sticky 只能在父容器范围内滑动 */
    .io-toc-sticky-host {
        min-height: var(--io-toc-host-h, auto) !important;
    }

    .io-toc-sticky-host .io-toc-sticky-card {
        position: -webkit-sticky;
        position: sticky;
        top: var(--io-toc-top, 88px);
        z-index: 6;
    }
}

/* ============================================================
 * 暗色模式适配（主题给 html/body 加 .dark 类 或 prefers-color-scheme）
 * ============================================================ */
.dark .article-toc-meta,
[data-bs-theme="dark"] .article-toc-meta {
    background: rgba(255, 255, 255, 0.06);
    color: #aaa;
}
.dark .article-toc-item a,
[data-bs-theme="dark"] .article-toc-item a {
    color: #aaa;
}
.dark .article-toc-item a:hover,
[data-bs-theme="dark"] .article-toc-item a:hover {
    background: rgba(255, 255, 255, 0.05);
}
.dark .article-toc-item.is-active a,
[data-bs-theme="dark"] .article-toc-item.is-active a {
    background: rgba(255, 255, 255, 0.08);
}
.dark .article-toc-list::-webkit-scrollbar-thumb,
[data-bs-theme="dark"] .article-toc-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
}
/* 暗色模式：进度条轨道加深，条纹高亮降低防过曝 */
.dark .article-toc-progress-track,
[data-bs-theme="dark"] .article-toc-progress-track {
    background: rgba(255, 255, 255, 0.1);
}
.dark .article-toc-progress-fill,
[data-bs-theme="dark"] .article-toc-progress-fill {
    background-image:
        linear-gradient(
            135deg,
            rgba(255, 255, 255, 0.18) 25%,
            transparent 25%,
            transparent 50%,
            rgba(255, 255, 255, 0.18) 50%,
            rgba(255, 255, 255, 0.18) 75%,
            transparent 75%,
            transparent 100%
        ),
        linear-gradient(
            90deg,
            #3a7afe 0%,
            #4aa8ff 25%,
            #f5a623 50%,
            #f1404b 75%,
            #67c23a 100%
        );
}

@media (prefers-color-scheme: dark) {
    .article-toc-meta { background: rgba(255, 255, 255, 0.06); color: #aaa; }
    .article-toc-item a { color: #aaa; }
    .article-toc-item a:hover { background: rgba(255, 255, 255, 0.05); }
    .article-toc-item.is-active a { background: rgba(255, 255, 255, 0.08); }
    .article-toc-list::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.2); }
    .article-toc-progress-track { background: rgba(255, 255, 255, 0.1); }
    .article-toc-progress-fill {
        background-image:
            linear-gradient(
                135deg,
                rgba(255, 255, 255, 0.18) 25%,
                transparent 25%,
                transparent 50%,
                rgba(255, 255, 255, 0.18) 50%,
                rgba(255, 255, 255, 0.18) 75%,
                transparent 75%,
                transparent 100%
            ),
            linear-gradient(
                90deg,
                #3a7afe 0%,
                #4aa8ff 25%,
                #f5a623 50%,
                #f1404b 75%,
                #67c23a 100%
            );
    }
}
