/* Sticky and scrollable sidebar */

/* Ensure the container has enough height */
.container {
    min-height: 100vh;
    /* Full viewport height */
}

/* Sticky and scrollable sidebar on medium screens and up */
@media (min-width: 768px) {
    .sidebar {
        position: sticky;
        /* Sticks to the top while scrolling */
        top: 0;
        /* Aligns to the top of the parent container */
        height: 100vh;
        /* Full viewport height */
        overflow-y: auto;
        /* Scrollbar appears if content overflows */
        z-index: 100;
        /* Keeps sidebar above other content */
    }
}

/* End sticky and scrollable sidebar */

/* TOC Container */
ul.toc {
    padding: 1em 0 1.75em;
    /* Add padding to top */
    font-size: 0.85em;
    /* Light right border */
}

/* Reset list styling for all ul elements */
ul.toc,
ul.toc ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

/* Style list items */
ul.toc li a {
    display: block;
    padding: 0.4em 0.8em;
    /* Adjusted padding */
    text-decoration: none;
    color: var(--toc-text);
    transition: background 0.2s ease, padding-left 0.2s ease, border-left 0.2s ease;
    /* Smooth transitions */
    padding-left: 0.8em;
    /* Initial padding */
    border-left: 3px solid transparent;
    /* Add transparent border for hover */
    border-bottom: 1px solid rgba(0, 0, 0, 0.03);
    /* Add a very subtle bottom border to each list item */
}

/* Indent nested levels for hierarchy */
ul.toc ul {
    margin-left: 1.2em !important;
    margin-top: 0.3em;
}

/* Hover effect */
ul.toc a:hover {
    /* Use theme-aware variable so dark mode works correctly */
    background: var(--card-hover-bg, #f9f9f9);
    padding-left: 1em;
    /* Slight padding increase on hover */
    border-left: 3px solid var(--bs-primary, #0071eb);
}

/* Second-level items numbering */
ul.toc>li>ul>li>a {
    padding-left: 1.5em;
}

/* Third-level items numbering */
ul.toc>li>ul>li>ul>li>a {
    padding-left: 2.0em;
}

/* Accessibility: Focus styles - improved for keyboard navigation */
ul.toc a:focus {
    outline: 2px solid #0071eb;
    outline-offset: -2px;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);
    position: relative;
    z-index: 1;
    /* Ensure the focus outline is visible */
}

.spec-footer {
    font-size: 0.7em;
    text-align: center;
}

/* Add a subtle visual cue for active/selected item */
ul.toc li a.active,
ul.toc li a[aria-current="page"],
ul.toc li a[aria-current="true"] {
    border-left: 3px solid var(--bs-primary, #0071eb);
    /* Highlight active item */
    font-weight: 500;
    /* Make active item slightly bolder */
    background: var(--card-hover-bg, #f0f0f0);
    /* Theme-aware background for active item */
}

/* Remove bottom border from last list item */
ul.toc li:last-child a {
    border-bottom: none;
}

/* Collapsible menu styles - Docusaurus inspired */
#toc ul li {
    position: relative;
}

/* Fixed position for the list item to allow absolute positioning of the toggle */
#toc ul li.has-children {
    position: relative;
}

/* Collapse toggle button styles - enhanced for accessibility */
.collapse-toggle {
    position: absolute;
    top: 0.35em;
    right: 0;
    width: 28px;
    height: 28px;
    background: transparent;
    border: 1px solid transparent;
    /* Border for focus state */
    border-radius: 3px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
    z-index: 2;
}

.collapse-toggle:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

/* Improved focus styles for keyboard navigation */
.collapse-toggle:focus {
    outline: 2px solid #0071eb;
    outline-offset: 1px;
    border-color: #0071eb;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);
}

/* Arrow icon for the toggle */
.collapse-toggle::after {
    content: "";
    border-style: solid;
    border-width: 0.15em 0.15em 0 0;
    display: inline-block;
    height: 0.5em;
    width: 0.5em;
    position: relative;
    transform: rotate(135deg);
    transition: transform 0.2s ease;
}

/* Rotate arrow when collapsed */
.collapse-toggle.collapsed::after {
    transform: rotate(45deg);
}

/* Hide submenu when collapsed - with screen reader considerations */
#toc ul li.has-children>ul {
    max-height: 1000px;
    /* Arbitrary large value */
    overflow: hidden;
    transition: max-height 0.3s ease-in-out, opacity 0.3s ease-in-out;
    opacity: 1;
}

#toc ul li.has-children.collapsed>ul {
    max-height: 0;
    overflow: hidden;
    opacity: 0.6;
    /* Better visual cue that content is hidden */
}

/* Skip to content - accessibility enhancement */
.screen-reader-text {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* But make it visible on focus - for keyboard users */
.screen-reader-text:focus,
.visually-hidden-focusable.screen-reader-text:focus {
    position: fixed;
    top: 0;
    left: 0;
    width: auto;
    height: auto;
    clip: auto;
    clip-path: none;
    margin: 0;
    overflow: visible;
    white-space: normal;
    display: block;
    padding: 15px 23px 14px;
    background-color: #fff;
    color: #0071EB;
    z-index: 100000;
    font-size: 1em;
    font-weight: bold;
    text-decoration: none;
    line-height: normal;
    box-shadow: 0 0 2px 2px rgba(0, 0, 0, 0.2);
}