/* ========================================
   Custom Table of Contents Styles
   ======================================== */

/* Wrapper */
.custom-toc-wrapper {
    position: relative;
}

/* Desktop: Hide mobile toggle */
.custom-toc-mobile-toggle {
    display: none;
}

/* Desktop Layout */
.custom-toc-container {
    display: flex;
    gap: 40px;
    align-items: flex-start;
}

.custom-toc-sidebar {
    flex: 0 0 280px;
    position: sticky;
    top: 120px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    order: -1; /* Places ToC on the left */
}

.custom-toc-content {
    flex: 1;
    min-width: 0;
}

/* ToC Navigation Styles */
.custom-toc {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 20px;
    font-size: 14px;
}

.custom-toc-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 15px;
    color: #212529;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.custom-toc ul.custom-toc-list {
    list-style: none;
    margin: 0 ;
    padding: 0;
}

.custom-toc-list li {
    margin: 0;
    padding: 0;
}

.custom-toc-list li a {
    display: block;
    padding: 8px 0;
    padding-left: 12px;
    padding-right: 12px;
    color: #495057;
    text-decoration: none;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    border-radius: 4px;
}

.custom-toc-list li a:hover {
    color: #007bff;
    padding-left: 16px;
    border-left-color: #007bff;
    background: rgba(0, 123, 255, 0.05);
}

.custom-toc-list li a.active {
    color: #007bff;
    font-weight: 700;
    border-left-color: #007bff;
    background: rgba(0, 123, 255, 0.1);
    padding-left: 16px;
}

/* .custom-toc-list li a.active::before {
    content: '▸ ';
    margin-right: 4px;
    font-weight: bold;
} */

/* Indentation for different heading levels */
.toc-level-2 {
    padding-left: 0;
}

.toc-level-3 {
    padding-left: 15px;
}

.toc-level-4 {
    padding-left: 30px;
}

.toc-level-5 {
    padding-left: 45px;
}

.toc-level-6 {
    padding-left: 60px;
}

/* Scrollbar styling for ToC */
.custom-toc-sidebar::-webkit-scrollbar {
    width: 6px;
}

.custom-toc-sidebar::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.custom-toc-sidebar::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

.custom-toc-sidebar::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Mobile overlay - hidden by default on desktop */
.custom-toc-mobile-overlay {
    display: none;
}

/* ========================================
   Mobile Styles
   ======================================== */

@media screen and (max-width: 768px) {
    /* Show mobile toggle */
    .custom-toc-mobile-toggle {
        display: block;
        position: fixed;
        bottom: 0;
        z-index: 999;
        background: #fff;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        margin-bottom: 10px;
        width: calc(100% - 30px);
        border-radius: 4px;
        border: 2px solid rgb(224, 225, 233);
    }
    
    .custom-toc-toggle-btn {
        width: 100%;
        padding: 5px 15px;
        background: #fff;
        color: #007bff;
        border: none;
        font-size: 16px;
        font-weight: 600;
        cursor: pointer;
        display: flex;
        align-items: center;
        gap: 10px;
        transition: background 0.2s ease;
    }
    
    .custom-toc-toggle-btn:hover {
        background: #0056b3;
    }
    
    .toc-toggle-icon {
        font-size: 20px;
    }
    
    /* Hide desktop sidebar ToC */
    .custom-toc-container {
        display: block;
    }
    
    .custom-toc-sidebar {
        display: none;
    }
    
    .custom-toc-content {
        width: 100%;
    }
    
    /* Mobile overlay menu */
    .custom-toc-mobile-overlay {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1000;
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }
    
    .custom-toc-mobile-overlay.active {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }
    
    .custom-toc-mobile-menu {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 60vh;
        background: #fff;
        overflow-y: auto;
        padding: 20px;
        padding-top: 20px;
        border-radius: 16px 16px 0 0;
        transform: translateY(100%);
        transition: transform 0.3s ease;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
    }
    
    .custom-toc-mobile-overlay.active .custom-toc-mobile-menu {
        transform: translateY(0);
    }
    

    
    .custom-toc-close-btn {
        position: absolute;
        top: 10px;
        right: 10px;
        background: transparent;
        border: none;
        font-size: 32px;
        color: #333;
        cursor: pointer;
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0;
        line-height: 1;
        z-index: 1;
    }
    
    .custom-toc-close-btn:hover {
        color: #007bff;
    }
    
    /* Adjust ToC in mobile menu */
    .custom-toc-mobile-menu .custom-toc {
        background: transparent;
        border: none;
        padding: 10px 0 0 0;
    }
    
    .custom-toc-mobile-menu .custom-toc-title {
        font-size: 18px;
        margin-bottom: 20px;
        text-align: center;
    }
    
    .custom-toc-mobile-menu .custom-toc-list li a {
        padding: 12px 0;
        padding-left: 12px;

        font-size: 15px;
    }
    
    .custom-toc-mobile-menu .custom-toc-list li a.active {
        background: rgba(0, 123, 255, 0.1);
        padding-left: 16px;
    }
}

/* Tablet adjustments */
@media screen and (min-width: 769px) and (max-width: 1024px) {
    .custom-toc-sidebar {
        flex: 0 0 220px;
    }
    
    .custom-toc {
        padding: 15px;
        font-size: 13px;
    }
    
    .custom-toc-title {
        font-size: 14px;
    }
}

/* Large desktop - move ToC to right side */
@media screen and (min-width: 1200px) {
    .custom-toc-sidebar {
        order: 1; /* Places ToC on the right */
    }
    
    .custom-toc-content {
        order: 0;
    }
}

/* Smooth scrolling for anchor links */
html {
    scroll-behavior: smooth;
}

/* Add some offset for fixed headers when jumping to anchors */
.custom-toc-content h2[id],
.custom-toc-content h3[id],
.custom-toc-content h4[id],
.custom-toc-content h5[id],
.custom-toc-content h6[id] {
    scroll-margin-top: 70px;
}

@media screen and (max-width: 768px) {
    .custom-toc-content h2[id],
    .custom-toc-content h3[id],
    .custom-toc-content h4[id],
    .custom-toc-content h5[id],
    .custom-toc-content h6[id] {
        scroll-margin-top: 80px;
    }
}

@media screen and (min-width: 768px) {
    body.has-custom-toc .tipi-m-8 {
        width: 100%;
        /* or width: 100%; depending on your needs */
    }
}

/* ========================================
   Body Class Helper
   ======================================== */

/*
   The body tag gets the class 'has-custom-toc' when ToC is enabled.
   Use this to adjust your theme's styles when ToC is active.
   
   Example usage:
   
   body.has-custom-toc .tipi-m-8 {
       max-width: 100%;
   }
*/
