.page-container { justify-content: flex-start; }

:root {
    /* 1. Define the exact height we want the TOC header to be */
    --mobile-toc-height: 60px; 
}

/* --- Desktop TOC --- */
.toc { 
    width: 320px; 
    flex-shrink: 0; 
    position: sticky; 
    top: var(--header-height); /* Offset exactly by the desktop header height */
    max-height: calc(100vh - var(--header-height) ); /* Prevent scrolling past the screen bottom */
    overflow-y: auto; 
    background: var(--surface-color); 
    border-right: 1px solid var(--border-color); 
    padding: 20px; 
    box-sizing: border-box; 
}
.toc-toggle-checkbox, .toc-toggle-label { display: none; }
.toc ul { list-style-type: none; padding-left: 20px; margin: 4px 0; }
.toc > .toc-wrapper > ul { padding-left: 0; } 
.toc li { position: relative; margin-bottom: 6px; }
.toc a { text-decoration: none; color: var(--text-color); opacity: 0.8; font-size: 0.9em; display: block; padding: 2px 0; transition: color 0.2s, opacity 0.2s; }
.toc a:hover { color: var(--primary-brand); opacity: 1; }
.has-children > a { padding-left: 20px; }
.collapse-btn { position: absolute; left: 0; top: 6px; cursor: pointer; font-size: 0.8em; color: var(--text-color); opacity: 0.6; user-select: none; width: 20px; text-align: center; z-index: 2; transition: transform 0.2s; background: transparent; border: none; padding: 0; outline: none; }
li.collapsed > ul { display: none; }
li.collapsed > .collapse-btn { transform: rotate(-90deg); }

/* --- Mobile TOC --- */
@media (max-width: 900px) {
    .toc { 
        width: 100%; 
        position: sticky; 
        top: 70px; /* Offset exactly by the mobile header height */
        z-index: 100; 
        padding: 0; 
        border-right: none; 
        border-bottom: 1px solid var(--border-color); 
        box-shadow: 0 2px 5px rgba(0,0,0,0.05); 
        background: var(--bg-color); 
    }
    .toc-wrapper { display: none; padding: 20px; max-height: 60vh; overflow-y: auto; background: var(--surface-color); border-bottom: 1px solid var(--border-color); }
    .toc-toggle-label {
        height: var(--mobile-toc-height);
        display: flex;
        align-items: center;
        box-sizing: border-box;
        gap: 10px;
        padding: 0 20px;
        background: var(--surface-color);
        color: var(--text-color);
        font-weight: bold;
        cursor: pointer;
        user-select: none;
        margin: 0;
    }
    .toc-toggle-checkbox:checked ~ .toc-wrapper { display: block; }
    

    html {
        /* Adjust this value based on your actual mobile header + TOC height */
        scroll-padding-top: var(--mobile-toc-height, 60px); 
    }          

}