html, body {
    margin: 0;
    padding: 0;
}

.toc {
    background: #dcf5de;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    padding: 10px;
    margin: 10px 0;
    border-radius: 8px;
    max-width: 300px;
    transition: all 0.3s ease;
}

.toc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding: 10px;
}

.toc-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
    color: #333;
}

.toc-toggle-arrow {
    margin-left: 10px;
    width: 0;
    height: 0;
    min-width: 12px;
    min-height: 12px;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid #333;
    border-bottom: none;
    transition: transform 0.3s ease;
}

.toc.collapsed .toc-toggle-arrow {
    transform: rotate(180deg);
}

.toc-list {
    list-style: none;
    padding: 0;
    margin: 0;
    transition: max-height 0.3s ease, opacity 0.3s ease;
}

.toc-list li {
    margin: 8px 0;
    position: relative;
}

.toc-list a {
    color: #0073aa;
    text-decoration: none;
    display: inline-block;
    padding-left: 15px;
    font-size: 1rem;
    line-height: 1.5;
    transition: color 0.2s ease;
}

.toc-list a:hover {
    color: #d32f2f;
}

.toc-active-indicator {
    display: none;
    width: 0;
    height: 0;
    border-left: 6px solid #d32f2f;
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
}

.toc-list a.active .toc-active-indicator {
    display: inline-block;
}

/* Tablet and Desktop (min-width: 1025px) */
@media (min-width: 1025px) {
    .toc {
        position: sticky;
        top: 100px; /* Default, overridden by JS */
        max-width: 250px;
        margin: 0;
        transition: top 0.3s ease; /* Smooth transition */
        z-index: 900; /* Below header (z-index: 1000) */
    }

    .toc-list {
        max-height: none;
        opacity: 1;
        display: block;
        transition: max-height 0.3s ease, opacity 0.3s ease;
    }

    .toc.collapsed .toc-list {
        max-height: 0;
        opacity: 0;
        overflow: hidden;
    }
}

/* Mobile (max-width: 767px) */
@media (max-width: 767px) {
    .toc-spacer {
        height: 0; /* Fallback; will be set dynamically by JS */
    }

    .toc {
        position: relative;
        margin: 0;
        padding: 0;
        border-bottom: 1px solid #e0e0e0;
        border-radius: 0;
        max-width: 100%;
        background: #f2fced;
        z-index: 999; /* Below #custom-header (1000) but above content */
    }

    .toc-header {
        padding: 12px 15px;
    }

    .toc-title {
        font-size: 1rem;
    }

    .toc-list {
        max-height: 0;
        opacity: 0;
        overflow: hidden;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: #fff;
        border: 1px solid #e0e0e0;
        border-top: none;
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
        z-index: 999; /* Match TOC z-index */
    }

    .toc:not(.collapsed) .toc-list {
        background: #dcf5de;
        max-height: 500px; /* Adjust based on content */
        opacity: 1;
        padding: 10px 15px;
    }

    .toc-list li {
        margin: 6px 0;
    }

    /* Force TOC above Omnisend embed */
    .toc,
    .toc-list {
        z-index: 999 !important; /* Higher than Omnisend (0) but below header (1000) */
    }

    /* Lower Omnisend embed form layers */
    [id^="omnisend-embedded-v2"],
    [id^="omnisend-form-"],
    [class*="omnisend-form"],
    [class*="omnisend-reset"] {
        z-index: 0 !important;
    }
}