/* css/toc-style.css */
.toc-container {
    background: #fff;
    border: 1px solid #e0e0e0;
    margin: 20px 0;
    padding: 0 15px;
    width: 100%;
    transition: all 0.3s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    box-sizing: border-box;
}

.toc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 0;
    padding: 0;
    height: 40px;
    border-bottom: 1px solid #e0e0e0;
}

.toc-header span {
    font-size: 15px;
    font-weight: 600;
    color: #333;
    display: flex;
    align-items: center;
    line-height: 1;
}

.toc-header span:before {
    content: "≡";
    margin-right: 8px;
    font-size: 18px;
    line-height: 1;
}

.toc-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0 5px;
    color: #666;
    font-size: 12px;
    line-height: 1;
    display: flex;
    align-items: center;
}

.toc-content {
    max-height: 500px;
    overflow-y: auto;
    transition: all 0.3s ease;
    padding: 15px 0 5px;
}

/* Thu gọn mặc định */
.toc-container.collapsed .toc-content {
    max-height: 0;
    padding: 0;
    overflow: hidden;
}

/* Style cho H2 và H3 */
.toc-h2 {
    margin: 8px 0;
    padding: 5px 0;
    background: #f8f9fa;
    border-radius: 4px;
}

.toc-h3 {
    margin: 4px 0;
    padding: 5px 0 5px 28px;
    background: #fff;
}

.toc-h2 a, .toc-h3 a {
    color: #444;
    text-decoration: none;
    display: block;
    font-size: 15px;
    line-height: 1.4;
    padding: 5px 10px;
}

.toc-h2 a {
    font-weight: 500;
}

.toc-h3 a {
    font-weight: normal;
    color: #666;
}

.toc-number {
    display: inline-block;
    min-width: 25px;
    margin-right: 8px;
    color: #666;
}

/* Fixed position styles */
.toc-container.sticky {
    position: fixed;
    right: 20px;
    max-width: 300px;
    z-index: 999999;
    top: 50%;
    transform: translateY(-50%);
}

/* Minimized state */
.toc-container.sticky.minimized {
    position: fixed;
    right: 0;
    width: 40px;
    height: 40px;
    min-width: 40px;
    padding: 0;
    margin: 0;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-right: none;
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
    box-shadow: -2px 0 5px rgba(0,0,0,0.1);
    cursor: pointer;
    opacity: 0.9;
    z-index: 999999;
    overflow: hidden;
    top: 50%;
    transform: translateY(-50%);
}

.toc-container.sticky.minimized .toc-header {
    height: 100%;
    width: 100%;
    border: none;
    padding: 0;
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
}

.toc-container.sticky.minimized .toc-header span {
    font-size: 0;
    margin: 0;
}

.toc-container.sticky.minimized .toc-header span:before {
    content: "≡";
    font-size: 24px;
    margin: 0;
}

.toc-container.sticky.minimized .toc-toggle,
.toc-container.sticky.minimized .toc-content {
    display: none;
}

/* Mobile styles */
/* Chỉ cập nhật phần mobile styles trong file css/toc-style.css */

@media screen and (max-width: 768px) {
    .toc-container {
        padding: 0 15px;
    }

    .toc-header {
        height: 35px;
        flex-shrink: 0;
    }

    .toc-container.sticky {
        position: fixed;
        top: 50% !important;
        transform: translateY(-50%) !important;
        right: 20px;
        max-width: 85%;
        max-height: 80vh;
        margin: 0;
        background: #fff;
        border: 1px solid #e0e0e0;
        border-right: none;
        border-top-left-radius: 4px;
        border-bottom-left-radius: 4px;
        box-shadow: -2px 0 5px rgba(0,0,0,0.1);
        display: flex;
        flex-direction: column;
        overflow: hidden; /* Quan trọng: chỉ ẩn overflow ở container */
    }

    .toc-content {
        flex: 1;
        padding: 10px 0;
        overflow-y: scroll; /* Thay đổi từ auto sang scroll */
        -webkit-overflow-scrolling: touch;
        max-height: calc(80vh - 35px); /* Chiều cao tối đa = 80vh trừ đi chiều cao header */
        overscroll-behavior: contain; /* Ngăn scroll lan ra ngoài */
        touch-action: pan-y; /* Chỉ cho phép scroll dọc */
    }

    /* Custom scrollbar */
    .toc-content::-webkit-scrollbar {
        width: 4px;
    }

    .toc-content::-webkit-scrollbar-track {
        background: transparent;
    }

    .toc-content::-webkit-scrollbar-thumb {
        background-color: rgba(0, 0, 0, 0.2);
        border-radius: 4px;
    }

    .toc-h2 {
        margin: 5px 0;
        background: #f8f9fa;
    }

    .toc-h3 {
        padding-left: 20px;
        background: #fff;
    }

    .toc-h2 a, .toc-h3 a {
        padding: 10px; /* Tăng padding cho dễ bấm */
        font-size: 14px;
    }

    .toc-container.sticky.minimized {
        width: 35px;
        height: 35px;
        min-width: 35px;
        max-height: 35px;
        overflow: hidden;
    }

    /* Cải thiện touch targets */
    .toc-h2 a, .toc-h3 a {
        padding: 12px 10px;
        touch-action: pan-y;
    }
}

/* Animation */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.toc-container.sticky:not(.minimized) {
    animation: fadeIn 0.3s ease;
}
/* Thêm vào cuối file toc-style.css */

.toc-h2.active > a,
.toc-h3.active > a {
    background-color: rgba(72, 187, 120, 0.1); /* Màu xanh lá nhạt */
    color: #48bb78; /* Màu xanh lá đậm */
    border-radius: 4px;
}

.toc-h2.active > a .toc-number,
.toc-h3.active > a .toc-number {
    color: #48bb78;
}