
.page-container-with-sidebar {
    --sidebar-icon-mobile: #aa2205;
}

.sidebar-table {
    width: 280px;
    padding: 0 0 30px; /* top right/left bottom */
    margin-right: 40px;
    background-color: inherit;
    box-shadow: 0px 0 12px 4px rgba(0,0,0,0.5); /* horizontal-offset vertical-offset blur-radius spread-radius color */
    border-radius: 8px;
    
    position: sticky; /* sticky must be used with top: 0 */
    top: 0;
    z-index: 10;
    transition: all 0.3s ease;
}

.sidebar-table a {
    font-weight: bold;
    padding: 10px 0;
    margin: 5px 0;
    color: var(--main-title);
    text-decoration: none;
    border-radius: 5px;
    transition: background 0.2s;
}

.sidebar-table a:hover {
    background-color: var(--title-background-hover);
}

.sidebar-table .active {
    background-color: #007BFF;
    color: white;
}

.sidebar-item.level-1 > a {
    padding-left: 10px;
    /* background: var(--title-background);*/
}
.sidebar-item.level-2 > a {
    padding-left: 25px;
    /*background: var(--title2-background);*/
}
.sidebar-item.level-3 > a {
    padding-left: 40px;
    /*background: var(--title3-background);*/
}
.sidebar-item.level-4 > a {
    padding-left: 55px;
    /*background: var(--title4-background);*/
}

.sidebar-link {
    display:flex;
    align-items:center;
    gap: 6px;
    width: 100%;
    box-sizing: border-box;
}

.sidebar-link.active {
    background: var(--title-background-hover);
}

.sidebar-number {
    flex: 0 0 auto;
    color: #666;
}

.sidebar-name {
    flex: 1;
}

.sidebar-expand-icon {
    flex: 0 0 auto;
    font-size: 0.8em;
    margin-right: 10px;
}





.sidebar-mobile-toggle {
    display: none;
}

.sidebar-close {
    display: none;
}

.sidebar-mobile-overlay {
    display: none;
}


@media (max-width: 768px) {

    /* Floating button */
    .sidebar-mobile-toggle {
        display: flex;
        position: fixed;
        left: 0;
        top: 50%;
        z-index: 1001;
        
        color: white;
        font-size: 0.9rem;
        font-weight: 600;
        padding: 4px;
        min-height: 80px;
        align-items: center;
        justify-content: center;
        border: none;
        border-radius: 0 12px 12px 0;
        background: var(--sidebar-icon-mobile);
        box-shadow: 0 3px 12px rgba(0, 0, 0, 0.35);
        
        cursor: grab;
        touch-action: none;
        user-select: none;
        transition: opacity 0.2s ease;
    }
    
    .sidebar-mobile-toggle:active {
        cursor: grabbing;
    }

    .sidebar-mobile-toggle.mobile-hidden {
        opacity: 0;
        pointer-events: none;
    }

    .sidebar-mobile-toggle .contents-label {
        writing-mode: vertical-rl;
        transform: rotate(180deg);
        letter-spacing: 0.04em;
    }

    html[lang^="zh"] .sidebar-mobile-toggle .contents-label {
        writing-mode: vertical-tb;
        transform: none;
        white-space: nowrap;
    }
    
    .sidebar-mobile-toggle .contents-icon {
        font-size: 1rem;
        margin-bottom: 4px;
    }
    /* Sidebar is hidden by default on phone */
    .sidebar-table {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        box-sizing: border-box;
        width: min(250px, 85vw);
        height: 100vh;
        margin: 0 !important;
        padding: 50px 10px 100px;
        overflow-x: hidden;
        overflow-y: auto;
        background: var(--background, white);
        border-radius: 0;
        box-shadow: -5px 0 20px rgba(0, 0, 0, 0.35);
        z-index: 1002;

        /*
         * Start outside the screen.
         */
        transform: translateX(-110%);
        transition: transform 0.3s ease;
    }


    /* Sidebar opened */
    .sidebar-table.mobile-open {
        transform: translateX(0);
    }


    /* Close button inside sidebar */
    .sidebar-close {
        display: flex;
        position: fixed;
        font-size: 28px;
        line-height: 1;
        left: calc(min(250px, 85vw) - 50px);
        bottom: 20px;
        width: 36px;
        height: 36px;
        padding: 0;
        align-items: center;
        justify-content: center;
        border: none;
        border-radius: 50%;
        background: transparent;
        color: var(--main-title, #333);
        background-color: var(--title-background-hover);
        cursor: pointer;
        z-index: 1004;
        
        /* Hidden while sidebar is closed */
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition:
            opacity 0.2s ease,
            visibility 0.2s ease,
            transform 0.2s ease;
    }

    .sidebar-close.mobile-visible {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    .sidebar-close:hover {
        background: var(--title-background-hover);
        transform: scale(1.08);
    }


    /* Dark transparent layer behind sidebar */
    .sidebar-mobile-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.35);
        opacity: 0;
        visibility: hidden;
        z-index: 1000;
        transition:
            opacity 0.3s ease,
            visibility 0.3s ease;
    }


    /* Overlay visible when sidebar is open */
    .sidebar-mobile-overlay.mobile-open {
        opacity: 1;
        visibility: visible;
    }


    /* Hide floating button while sidebar is open */
    .sidebar-mobile-toggle.mobile-hidden {
        opacity: 0;
        pointer-events: none;
    }


    /*
     * Your existing level indentation remains.
     * Slightly reduce it on small screens if desired.
     */
    .sidebar-item.level-1 > a {
        padding-left: 10px;
    }

    .sidebar-item.level-2 > a {
        padding-left: 25px;
    }

    .sidebar-item.level-3 > a {
        padding-left: 40px;
    }

    .sidebar-item.level-4 > a {
        padding-left: 55px;
    }
}