:root {
    --toc-sticky-admin-bar: 0px;
}
@media screen and (min-width: 783px) {
    body.admin-bar {
        --toc-sticky-admin-bar: 32px;
    }
}
@media screen and (max-width: 782px) {
    body.admin-bar {
        --toc-sticky-admin-bar: 46px;
    }
}

/* ── Trigger button (hiển thị khi scroll past) ─────────────────────── */
.toc-sticky-trigger {
    position: fixed;
    top: calc(var(--toc-sticky-offset, 30px) + var(--toc-sticky-admin-bar, 0px));
    z-index: 9999;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 12px 8px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,.15);
    color: #333;
    text-decoration: none;
    
    /* Mặc định ẩn, sẽ được JS add class is-visible */
    opacity: 0;
    pointer-events: none;
    transform: scale(0.8);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.toc-sticky-trigger-icon { font-size: 1.2em; line-height: 1; margin-bottom: 6px; }
.toc-sticky-trigger-text { 
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 1px;
}

.toc-sticky-trigger.is-visible {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1);
}

.toc-sticky-trigger.toc-sticky-left  { left: 0; border-left: none; border-radius: 0 6px 6px 0; }
.toc-sticky-trigger.toc-sticky-right { right: 0; border-right: none; border-radius: 6px 0 0 6px; }

/* Ẩn trigger khi panel đang mở (ghi đè is-visible) */
.toc-sticky-trigger[aria-expanded="true"] { 
    opacity: 0 !important; 
    pointer-events: none !important; 
    transform: scale(0.8);
}

/* ── Sticky panel (Full height) ────────────────────────────────────────── */
.toc-sticky-panel {
    position: fixed;
    top: var(--toc-sticky-admin-bar, 0px);
    bottom: 0;
    z-index: 9998;
    width: 320px;
    max-width: 85vw; /* Không vượt quá màn hình mobile */
    height: calc(100vh - var(--toc-sticky-admin-bar, 0px));
    height: calc(100dvh - var(--toc-sticky-admin-bar, 0px)); /* Hỗ trợ mobile tốt hơn */
    background: #fff;
    border: none;
    box-shadow: 0 0 25px rgba(0,0,0,.15);
    display: flex; flex-direction: column;

    /* Swipe animation kết hợp mờ dần (fade out) */
    transform: translateX(-100%);
    opacity: 0;
    visibility: hidden;
    transition: transform 0.4s cubic-bezier(0.23, 1, 0.32, 1), opacity 0.3s ease, visibility 0s 0.4s;
}

.toc-sticky-panel.toc-sticky-right {
    left: auto;
    right: 0;
    transform: translateX(100%);   /* slide từ phải */
}
.toc-sticky-panel.toc-sticky-left { left: 0; }

/* Trạng thái MỞ */
.toc-sticky-panel.is-open {
    transform: translateX(0);
    opacity: 1;
    visibility: visible;
    transition: transform 0.4s cubic-bezier(0.23, 1, 0.32, 1), opacity 0.4s ease, visibility 0s 0s;
}

/* ── Header của panel ─────────────────────────────────────── */
.toc-sticky-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 15px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    flex-shrink: 0;
}
.toc-sticky-title { font-weight: 700; font-size: 1.1em; color: #333; }
.toc-sticky-close { 
    background: none; border: none; cursor: pointer; 
    font-size: 1.2em; padding: 5px; color: #666;
    transition: color 0.2s;
}
.toc-sticky-close:hover { color: #dc3545; }

/* ── Nav list (scrollable) ───────────────────────────────── */
.toc-sticky-panel nav {
    flex-grow: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 15px 0;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}
.toc-sticky-list { margin: 0; padding: 0 20px; list-style: none; }
.toc-sticky-list a { 
    display: block; padding: 6px 0; font-size: 0.95em; 
    color: #475569; text-decoration: none; 
    transition: color 0.2s;
}
.toc-sticky-list a:hover { color: #2563eb; }

/* Xóa ảnh hưởng của ToC+ gốc (ví dụ: style="display:none" do config "collapse by default" hoặc jQuery toggle) */
.toc-sticky-panel ul {
    display: block !important;
}

/* ── Scroll Spy active state ─────────────────────────────── */
.toc-sticky-list a.toc-spy-active {
    font-weight: 600;
    color: #2563eb;
    border-left: 3px solid #2563eb;
    padding-left: 12px;
    margin-left: -15px;
    background: #f8fafc;
}

/* ── Mobile: ẩn toàn bộ nếu option disable ──────────────── */
.toc-sticky-mobile-disabled .toc-sticky-panel,
.toc-sticky-mobile-disabled .toc-sticky-trigger {
    display: none !important;
}
