/* ============================================
   H2 TOC Sidebar v1.3.0 - Frontend Styles
   纯 CSS position:sticky,不会抖动
   ============================================ */

/* ===== 桌面端侧边栏目录 ===== */
.h2toc-sidebar {
    width: 100%;
    box-sizing: border-box;
}

/* ⭐ 核心:CSS sticky,父容器需要 height 或自动撑开 */
.h2toc-sidebar.h2toc-sticky-on {
    position: -webkit-sticky;
    position: sticky;
    top: var(--h2toc-sticky-top, 100px);
    align-self: flex-start;
    /* 限高,内容多时滚动 */
    max-height: calc(100vh - var(--h2toc-sticky-top, 100px) - 20px);
    overflow-y: auto;
    overflow-x: hidden;
    /* 滚动条美化 */
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.2) transparent;
    /* 防止 sticky 失效:强制 z-index */
    z-index: 5;
}

.h2toc-sidebar.h2toc-sticky-on::-webkit-scrollbar {
    width: 6px;
}
.h2toc-sidebar.h2toc-sticky-on::-webkit-scrollbar-track {
    background: transparent;
}
.h2toc-sidebar.h2toc-sticky-on::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.15);
    border-radius: 3px;
}

/* ⭐ 关键:让目录所在 column 的祖先链不要破坏 sticky
   Elementor 默认会给 .elementor-column 加 overflow:hidden,这会让 sticky 失效
   我们用更高优先级的选择器恢复 */
.elementor-column:has(.h2toc-sidebar.h2toc-sticky-on),
.elementor-widget-wrap:has(.h2toc-sidebar.h2toc-sticky-on) {
    overflow: visible !important;
}

.h2toc-sidebar-title {
    color: var(--h2toc-item-text, #fff);
    font-size: 18px;
    font-weight: 700;
    margin: 0 0 16px 0;
}

.h2toc-list {
    list-style: none !important;
    padding: 0 !important;
    margin: 0 !important;
}

.h2toc-list li {
    margin: 0 0 12px 0 !important;
    padding: 0 !important;
    list-style: none !important;
}

.h2toc-list li a {
    display: block;
    padding: 14px 24px;
    background: var(--h2toc-item-bg, #1a1a1a);
    color: var(--h2toc-item-text, #ffffff);
    border-radius: 28px;
    text-decoration: none;
    font-weight: 600;
    font-size: 15px;
    line-height: 1.4;
    transition: all 0.3s ease;
    border: none;
    box-shadow: none;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
    white-space: normal;
    box-sizing: border-box;
    max-width: 100%;
}

.h2toc-list li a:hover,
.h2toc-list li a:focus {
    background: var(--h2toc-item-hover-bg, #2a2a2a);
    color: var(--h2toc-item-text, #ffffff);
    text-decoration: none;
}

.h2toc-list li.is-active a {
    background: var(--h2toc-active-bg, #14b8a6);
    color: #ffffff;
    box-shadow: 0 0 20px rgba(20, 184, 166, 0.4);
}

/* ===== 移动端悬浮按钮 ===== */
.h2toc-mobile-trigger {
    display: none;
    align-items: center;
    gap: 8px;
    position: fixed;
    top: var(--h2toc-mobile-top, 70px);
    left: 16px;
    z-index: 9998;
    padding: 10px 18px;
    background: rgba(30, 30, 30, 0.95);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    color: #fff;
    border: none;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    max-width: calc(100% - 32px);
    font-family: inherit;
    transition: opacity 0.2s ease, transform 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.h2toc-mobile-trigger.is-visible {
    display: inline-flex;
}

.h2toc-mobile-trigger:active {
    transform: scale(0.97);
}

.h2toc-current-title {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.h2toc-arrow {
    font-size: 18px;
    line-height: 1;
    opacity: 0.8;
}

/* ===== 移动端全屏覆盖层 ===== */
.h2toc-mobile-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--h2toc-mobile-overlay-bg, #1a1a1a);
    z-index: 9999;
    transform: translateX(-100%);
    transition: transform 0.3s ease, visibility 0s linear 0.3s;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 24px;
    box-sizing: border-box;
    visibility: hidden;
    pointer-events: none;
}

.h2toc-mobile-overlay.is-open {
    transform: translateX(0);
    visibility: visible;
    pointer-events: auto;
    transition: transform 0.3s ease, visibility 0s linear 0s;
}

.h2toc-close {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 8px;
    margin: 0 0 16px -8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.h2toc-close:hover {
    background: rgba(255, 255, 255, 0.1);
}

.h2toc-mobile-title {
    color: #fff;
    font-size: 28px;
    font-weight: 700;
    margin: 0 0 24px 0;
    line-height: 1.2;
}

.h2toc-mobile-list {
    list-style: none !important;
    padding: 0 !important;
    margin: 0 !important;
}

.h2toc-mobile-list li {
    margin: 0 0 8px 0 !important;
    padding: 0 !important;
    list-style: none !important;
}

.h2toc-mobile-list li a {
    display: block;
    padding: 14px 20px;
    color: #fff;
    text-decoration: none;
    border-radius: 28px;
    font-size: 16px;
    font-weight: 500;
    line-height: 1.4;
    transition: background 0.2s ease;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
}

.h2toc-mobile-list li a:hover,
.h2toc-mobile-list li a:focus {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    text-decoration: none;
}

.h2toc-mobile-list li.is-active a {
    background: var(--h2toc-active-bg, #14b8a6);
    color: #fff;
    font-weight: 600;
}

body.h2toc-overlay-open {
    overflow: hidden;
}
