/* ============================================================
   TOC (Table of Contents) Sidebar
   Tái sử dụng: copy toc.css + toc.js vào project
   Yêu cầu: CSS variables --color-blue, --color-red, --color-white,
            --color-border, --color-muted, --shadow-blue
   Nếu không có variables, tự khai báo lại trong :root
============================================================ */

/* Fallback variables — chỉ áp dụng nếu host chưa khai báo */
.toc-sidebar {
    --toc-accent:  var(--color-blue,   #002147);
    --toc-red:     var(--color-red,    #BB133E);
    --toc-white:   var(--color-white,  #ffffff);
    --toc-border:  var(--color-border, #e0e0e0);
    --toc-muted:   var(--color-muted,  #6b7280);
    --toc-shadow:  var(--shadow-blue,  rgba(0,33,71,.15));
    --toc-text:    var(--color-text,   #2c3e50);
    --toc-bg:      var(--color-white,  #ffffff);
}

/* ===== WRAPPER ===== */
.toc-sidebar {
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 200;
    font-size: 0.875rem;
    font-family: inherit;
}

/* ===== TOGGLE BUTTON ===== */
.toc-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--toc-accent);
    color: var(--toc-white);
    border: none;
    padding: 0;
    border-radius: 0 8px 8px 0;
    cursor: pointer;
    box-shadow: 2px 0 12px var(--toc-shadow);
    transition: background .2s, box-shadow .2s;
    width: 30px;       /* width cố định = độ rộng button */
    height: 90px;
    overflow: visible;
}

.toc-toggle span {
    display: inline-block;
    transform: rotate(90deg);
    white-space: nowrap;
    font-weight: 700;
    font-size: 0.8rem;
    letter-spacing: .06em;
    line-height: 1;
    padding: 0 12px;   /* padding 2 đầu chữ sau khi xoay */
}

.toc-toggle:hover {
    background: var(--toc-red);
    box-shadow: 2px 0 16px rgba(187,19,62,.3);
}

/* ===== MENU PANEL ===== */
.toc-menu {
    position: absolute;
    left: 100%;
    top: 0;
    background: var(--toc-bg);
    width: 280px;
    max-height: 60vh;
    overflow-y: auto;
    border: 1px solid var(--toc-border);
    border-left: none;
    border-radius: 0 8px 8px 0;
    box-shadow: 4px 4px 20px var(--toc-shadow);
    padding: 16px;
    display: none;
    scrollbar-width: thin;
    scrollbar-color: var(--toc-border) transparent;
}

.toc-menu::-webkit-scrollbar       { width: 4px; }
.toc-menu::-webkit-scrollbar-track { background: transparent; }
.toc-menu::-webkit-scrollbar-thumb { background: var(--toc-border); border-radius: 2px; }

.toc-menu.open { display: block; }

/* ===== HEADING ===== */
.toc-menu .toc-title {
    margin: 0 0 12px;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--toc-muted);
    border-bottom: 1px solid var(--toc-border);
    padding-bottom: 8px;
}

/* ===== LIST ===== */
#toc-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

#toc-list li {
    margin: 4px 0;
}

#toc-list a {
    display: block;
    color: var(--toc-text);
    text-decoration: none;
    padding: 5px 8px 5px 0;
    border-left: 2px solid transparent;
    border-radius: 0 4px 4px 0;
    transition: color .15s, border-color .15s, background .15s, padding .15s;
    line-height: 1.4;
}

#toc-list a:hover {
    color: var(--toc-accent);
    border-left-color: var(--toc-accent);
    background: rgba(0,33,71,.04);
    padding-left: 6px;
}

#toc-list a.active {
    color: var(--toc-accent);
    border-left-color: var(--toc-red);
    background: rgba(0,33,71,.06);
    padding-left: 6px;
    font-weight: 600;
}

/* ===== LEVELS ===== */
.toc-level-1 { font-weight: 700; font-size: 0.875rem; }
.toc-level-2 { padding-left: 12px; font-weight: 500; font-size: 0.85rem; }
.toc-level-3 { padding-left: 24px; font-size: 0.8rem; color: var(--toc-muted); }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .toc-menu {
        width: 240px;
        font-size: 0.82rem;
        max-height: 50vh;
    }

    .toc-toggle {
        padding: 12px 7px;
        font-size: 0.75rem;
        min-height: 60px;
    }
}