/* Backdrop for mobile ToC */
.toc-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4); 
    backdrop-filter: blur(2px); 
    z-index: 9997;
}

/* Global styles */
html {
    scroll-behavior: smooth;
}

h2 {
    position: relative;
}

.toc-header {
    font-weight: 700;
    color: #024430;
    text-align: center;
    border-bottom: 2px solid rgba(2, 68, 48, 0.15); 
    padding-bottom: 12px;
    margin-bottom: 16px;
    letter-spacing: -0.01em;
}

.toc-container {
    padding: 0;
    max-width: 800px;
}

/* Unified ToC styles */
.toc-mobile ul,
.toc-desktop ul {
    list-style: none;
    padding-left: 0;
    margin: 0;
    counter-reset: h2-counter;
}

.toc-desktop ul {
    margin-right: 10px; 
}

.toc-mobile ul li,
.toc-desktop ul li {
    margin: 6px 0;
    line-height: 1.45; 
}

/* Increment the counter on the list item */
.toc-mobile ul li.h2,
.toc-desktop ul li.h2 {
    counter-increment: h2-counter;
    padding-left: 0; 
}

/* ALIGNMENT FIX: Flexbox on the link itself */
.toc-mobile ul li a,
.toc-desktop ul li a {
    text-decoration: none;
    color: #333333; 
    word-break: break-word;
    white-space: normal;
    display: flex; /* Aligns the pseudo-number and text */
    align-items: flex-start;
    padding: 6px 10px; 
    border-radius: 6px;
    transition: all 0.25s ease-in-out; 
}

/* Put the number inside the link for perfect spacing */
.toc-mobile ul li a::before,
.toc-desktop ul li a::before {
    content: counter(h2-counter) ".";
    color: #024430; 
    font-weight: 700;
    opacity: 0.8;
    margin-right: 8px; /* This gives you exact control over the space */
    flex-shrink: 0; /* Prevents the number from squishing */
}

/* Hover and Active States */
.toc-mobile ul li a:hover,
.toc-desktop ul li a:hover {
    color: #024430;
    background-color: rgba(2, 68, 48, 0.06); 
}

.toc-mobile ul li a.active,
.toc-desktop ul li a.active {
    background-color: #024430;
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(2, 68, 48, 0.25); 
}

/* Keep number white when active */
.toc-mobile ul li a.active::before,
.toc-desktop ul li a.active::before {
    color: #ffffff;
    opacity: 1;
}

/* Mobile and Tablet ToC (max-width: 1023px) */
@media (max-width: 1023px) {
    /* Floating button */
    .toc-mobile-btn {
        position: fixed;
        right: 15px;
        top: calc(150px * 1);
        min-width: 60px;
        padding: 10px 16px; 
        background: #024430;
        color: white;
        border-radius: 30px;
        font-size: 14px;
        font-weight: bold;
        display: flex;
        align-items: center;
        justify-content: space-between;
        z-index: 10001;
        cursor: pointer;
        box-shadow: 0 4px 12px rgba(2, 68, 48, 0.35); 
        transition: background 0.3s, transform 0.2s, box-shadow 0.3s;
    }
    
    .toc-mobile .toc-header {
        position: sticky;
        top: 0;
        background: #E6F4EA;
        padding: 15px 15px 10px;
        margin: 0;
        z-index: 2;
    }

    .toc-mobile .toc-container {
        padding-top: 0;
    }
    
    .toc-mobile-btn:hover {
        background: #036a38;
        transform: translateY(-2px); 
        box-shadow: 0 6px 16px rgba(2, 68, 48, 0.4);
    }
    
    .toc-label {
        margin-right: 8px;
    }
    
    .toc-arrow {
        transition: transform 0.3s ease;
    }
    
    .toc-mobile.open + .toc-mobile-btn .toc-arrow {
        transform: rotate(180deg);
    }

    /* ToC sidebar */
    .toc-mobile {
        position: fixed;
        top: calc(150px + 55px);
        right: 5%;
        left: 5%;
        width: 90%;
        height: 90vh;
        background: #E6F4EA;
        border-radius: 12px;
        border: 1px solid rgba(2, 68, 48, 0.08); 
        padding: 0px 15px;
        overflow-y: auto;
        z-index: 10000;
        display: none;
        transform: translateY(-15px);
        opacity: 0;
        pointer-events: none;
        transition: transform 0.35s cubic-bezier(0.25, 0.8, 0.25, 1), opacity 0.35s ease;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15); 
    }
    
    .toc-mobile.open {
        display: block;
        transform: translateY(0);
        opacity: 1;
        pointer-events: auto;
        z-index: 10000;
    }

    .toc-header {
        font-size: 1.4em;
        padding-top: 15px;
    }

    .toc-container {
        padding: 0 15px;
    }

    /* Hide desktop ToC on mobile/tablet */
    .toc-desktop {
        display: none;
    }
}

/* Desktop ToC (min-width: 1024px) */
@media (min-width: 1024px) {
    /* Hide mobile ToC elements */
    .toc-mobile-btn, .toc-mobile, .toc-backdrop {
        display: none;
    }

    /* ToC sidebar */
    .toc-desktop {
        position: fixed;
        top: 150px;
        right: 4vw;
        width: 30vw;
        min-width: 300px;
        max-width: 600px;
        max-height: calc(100vh - 220px - 20px);
        background: #E6F4EA;
        border-radius: 12px;
        border: 1px solid rgba(2, 68, 48, 0.08); 
        padding: 0px 15px;
        overflow-y: auto;
        overscroll-behavior: contain;
        z-index: 10;
        box-shadow: 0 8px 24px rgba(2, 68, 48, 0.12); 
        scrollbar-width: none; /* Firefox */
        -ms-overflow-style: none; /* IE and Edge */
    }
    
    .toc-desktop::-webkit-scrollbar {
        display: none; /* Chrome, Safari, Edge */
    }
    
    .toc-desktop .toc-header {
        position: sticky;
        top: 0;
        background: #E6F4EA;
        z-index: 1;
        padding: 20px 15px 10px;
    }
    
    .toc-desktop .toc-desktop ul {
        margin-top: 30px;
        padding-bottom: 20px;
    }

    .toc-header {
        font-size: 1.6rem;
    }

    .toc-container {
        margin-right: calc(26vw + 40px);
        padding: 0 20px;
    }
}

/* Fine-tune for smaller desktops */
@media (min-width: 1024px) and (max-width: 1200px) {
    .toc-desktop {
        right: 20px;
        width: 300px;
    }
    .toc-container {
        margin-right: 340px;
    }
}

/* Fine-tune for larger screens */
@media (min-width: 1921px) {
    .toc-desktop {
        right: 10vw;
        width: 28vw;
        max-width: 700px;
    }
    .toc-container {
        margin-right: calc(28vw + 50px);
    }
}

/* Font size adjustments for ToC lists */
@media (min-width: 1024px) {
    #toc-list-desktop .h2,
    #toc-list-desktop h2 {
        font-size: 1.15em !important;
    }
}

@media (max-width: 1023px) {
    #toc-list-mobile h2,
    #toc-list-mobile .h2 {
        font-size: 1.15em !important;
    }
}

aside#secondary {
    display: none;
}

@media screen and (min-width: 1024px) {
    .has-sidebar .content-container {
        display: grid;
        grid-template-columns: 5fr 2fr;
        grid-gap: var(--global-xl-spacing);
        justify-content: center;
    }
}

/* Floating button logic for whatsapp button for laptops and small desktops */
@media (min-width: 1023px) and (max-width: 1200px) {
    .floating {
        position: fixed;
        width: 60px;
        height: 60px;
        background-color: #25d366;
        color: #fff;
        border-radius: 50px;
        text-align: center;
        font-size: 30px;
        box-shadow: 0 4px 10px rgba(37, 211, 102, 0.4); 
        z-index: 1000;
        left: 10px;
        top: 94%;
        transform: translate(0, -50%);
        cursor: pointer;
        transition: transform 0.2s, box-shadow 0.2s;
    }
    .floating:hover {
        transform: translate(0, -50%) scale(1.05);
        box-shadow: 0 6px 14px rgba(37, 211, 102, 0.5);
    }
}

@media (min-width: 1200px) {
    .has-sidebar .content-container {
        display: grid;
        grid-template-columns: 5fr 2.5fr !important;
        grid-gap: var(--global-xl-spacing);
        justify-content: center;
    }
}