/* =========================================
   Table of Contents – Modern Style
   ========================================= */
.toc-wrapper {
    margin: 0 0 28px;
    font-size: 14px;
    line-height: 1.6;
}

/* ---- Container ---- */
.toc-container {
    border: 2px solid var(--theme-color, #4a90e2);
    border-radius: 10px;
    overflow: hidden;
    background: #fafafa;
    box-shadow: 0 2px 12px rgba(0,0,0,.07);
    transition: box-shadow .25s ease;
    max-width: 100%;
}
.toc-container:hover {
    box-shadow: 0 4px 20px rgba(0,0,0,.12);
}

/* ---- Header ---- */
.toc-container .toc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    background: var(--theme-color, #4a90e2);
    cursor: pointer;
    user-select: none;
    gap: 10px;
}
.toc-container .toc-header .toc-title {
    display: flex;
    align-items: center;
    gap: 9px;
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    letter-spacing: .3px;
    flex: 1;
}
.toc-container .toc-header .toc-title i {
    font-size: 15px;
    opacity: .9;
}
.toc-container .toc-header .toc-toggle {
    background: rgba(255,255,255,.2);
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .2s, transform .3s ease;
    outline: none;
    padding: 0;
}
.toc-container .toc-header .toc-toggle:hover {
    background: rgba(255,255,255,.35);
}
.toc-container.toc-collapsed .toc-header .toc-toggle {
    transform: rotate(180deg);
}

/* ---- Progress bar ---- */
.toc-progress-bar {
    height: 3px;
    background: #e8e8e8;
    width: 100%;
}
.toc-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--theme-color, #4a90e2);
    transition: width .1s linear;
    border-radius: 0 3px 3px 0;
}

/* ---- Body / nav ---- */
.toc-container .toc-body {
    overflow: hidden;
    max-height: 1200px;
    transition: max-height .35s ease, opacity .25s ease;
    opacity: 1;
}
.toc-container.toc-collapsed .toc-body {
    max-height: 0;
    opacity: 0;
}

/* ---- List ---- */
.toc-container nav {
    padding: 12px 18px 16px;
}
.toc-container ol,
.toc-container ul {
    margin: 0;
    padding-left: 20px;
    list-style: none;
    counter-reset: toc-counter;
}
.toc-container > .toc-body > nav > ol,
.toc-container > .toc-body > nav > ul {
    padding-left: 0;
}

/* Numbered style */
.toc-numbered ol,
.toc-numbered ul {
    counter-reset: toc-counter;
}
.toc-numbered li {
    counter-increment: toc-counter;
}
.toc-numbered li > a::before {
    content: counters(toc-counter, ".") ". ";
    color: var(--theme-color, #4a90e2);
    font-weight: 700;
    font-size: 12px;
    min-width: 22px;
    display: inline-block;
}

/* ---- List Items ---- */
.toc-container li {
    margin: 2px 0;
    position: relative;
}
.toc-container li ol,
.toc-container li ul {
    padding-left: 16px;
    margin-top: 2px;
}

/* ---- Links ---- */
.toc-container li a {
    display: flex;
    align-items: flex-start;
    padding: 5px 10px 5px 8px;
    border-radius: 6px;
    color: #333;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: background .2s, color .2s, padding-left .2s;
    border-left: 3px solid transparent;
    line-height: 1.5;
    gap: 4px;
    word-break: break-word;
}
.toc-container li a:hover {
    background: rgba(74,144,226,.09);
    color: var(--theme-color, #4a90e2);
    padding-left: 12px;
}

/* Active link (current section) */
.toc-container li a.toc-active {
    background: rgba(74,144,226,.13);
    color: var(--theme-color, #4a90e2);
    font-weight: 700;
    padding-left: 12px;
}

/* Nested link adjustments */
.toc-container li li a {
    font-size: 12.5px;
    font-weight: 400;
    color: #555;
}
.toc-container li li li a {
    font-size: 12px;
    color: #777;
}

/* ---- Mobile ---- */
@media (max-width: 767px) {
    .toc-container li a {
        font-size: 12.5px;
        padding: 5px 8px 5px 6px;
    }
    .toc-container nav {
        padding: 10px 12px 14px;
    }
    .toc-container .toc-header {
        padding: 10px 14px;
    }
    /* WD-109: vùng chạm tối thiểu 40px trên điện thoại */
    .toc-container .toc-header .toc-toggle {
        width: 40px;
        height: 40px;
    }
    .toc-container li a {
        padding-top: 9px;
        padding-bottom: 9px;
    }
}

/* =========================================
   Floating TOC – nút bên phải + panel danh sách
   ========================================= */
.toc-floating {
    position: fixed;
    right: 16px;
    top: 50%;
    z-index: 1040;
    transform: translate(calc(100% + 24px), -50%);
    transition: transform .3s ease;
    font-size: 14px;
    line-height: 1.6;
}
.toc-floating.toc-floating-show {
    transform: translate(0, -50%);
}
.toc-floating-btn {
    width: 46px;
    height: 46px;
    border: none;
    border-radius: 50%;
    background: var(--theme-color, #4a90e2);
    color: #fff;
    font-size: 17px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    box-shadow: 0 4px 16px rgba(0,0,0,.2);
    transition: transform .2s ease, box-shadow .2s ease, opacity .2s ease;
}
.toc-floating-btn:hover {
    transform: scale(1.06);
    box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.toc-floating-open .toc-floating-btn {
    opacity: 0;
    pointer-events: none;
}
.toc-floating-panel {
    position: absolute;
    right: 0;
    top: 50%;
    width: 320px;
    max-width: calc(100vw - 32px);
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0,0,0,.18);
    opacity: 0;
    visibility: hidden;
    transform: translate(16px, -50%);
    transition: opacity .25s ease, transform .25s ease, visibility .25s;
}
.toc-floating-open .toc-floating-panel {
    opacity: 1;
    visibility: visible;
    transform: translate(0, -50%);
}
.toc-floating-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 16px;
    background: var(--theme-color, #4a90e2);
    color: #fff;
    flex-shrink: 0;
}
.toc-floating-title {
    display: flex;
    align-items: center;
    gap: 9px;
    font-weight: 700;
    font-size: 14px;
}
.toc-floating-close {
    background: rgba(255,255,255,.2);
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
}
.toc-floating-close:hover {
    background: rgba(255,255,255,.35);
}
.toc-floating-body {
    position: relative;
    overflow-y: auto;
    padding: 10px 14px 14px;
}
.toc-floating-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1039;
    background: rgba(0,0,0,.25);
    opacity: 0;
    visibility: hidden;
    transition: opacity .25s ease, visibility .25s;
}
.toc-floating-backdrop.toc-floating-open {
    opacity: 1;
    visibility: visible;
}

/* List trong panel dùng chung kiểu với khung mục lục */
.toc-floating ol,
.toc-floating ul {
    margin: 0;
    padding-left: 16px;
    list-style: none;
    counter-reset: toc-counter;
}
.toc-floating-body > ol,
.toc-floating-body > ul {
    padding-left: 0;
}
.toc-floating li {
    margin: 2px 0;
}
.toc-floating li a {
    display: flex;
    align-items: flex-start;
    padding: 5px 10px 5px 8px;
    border-radius: 6px;
    color: #333;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    line-height: 1.5;
    gap: 4px;
    word-break: break-word;
    transition: background .2s, color .2s;
}
.toc-floating li a:hover {
    background: rgba(74,144,226,.09);
    color: var(--theme-color, #4a90e2);
}
.toc-floating li a.toc-active {
    background: rgba(74,144,226,.13);
    color: var(--theme-color, #4a90e2);
    font-weight: 700;
}
.toc-floating li li a {
    font-size: 12.5px;
    font-weight: 400;
    color: #555;
}

@media (max-width: 767px) {
    .toc-floating {
        right: 12px;
        top: auto;
        bottom: 90px;
        transform: translateX(calc(100% + 24px));
    }
    .toc-floating.toc-floating-show {
        transform: none;
    }
    .toc-floating-btn {
        width: 42px;
        height: 42px;
        font-size: 16px;
    }
    .toc-floating-panel {
        top: auto;
        bottom: 0;
        width: calc(100vw - 24px);
        max-height: 65vh;
        transform: translateY(16px);
    }
    .toc-floating-open .toc-floating-panel {
        transform: none;
    }
}