/* Sidebar */
#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 16em;
    height: 100vh;
    overflow-y: auto;
    background: #f8f9fa;
    border-right: 1px solid #e1e4e8;
    padding: 1em 0;
    box-sizing: border-box;
    z-index: 100;
}

#sidebar-title {
    font-weight: 700;
    font-size: 0.95em;
    padding: 0 1em 0.8em;
    border-bottom: 1px solid #e1e4e8;
    margin-bottom: 0.5em;
    color: #1a1a1a;
}

#sidebar-nav {
    list-style: none;
    margin: 0;
    padding: 0;
}

#sidebar-nav > li {
    border-top: 1px solid #e9ecef;
}

#sidebar-nav > li:first-child {
    border-top: none;
}

#sidebar-nav > li > a {
    display: block;
    padding: 0.45em 1em;
    color: #333;
    text-decoration: none;
    font-size: 0.85em;
    font-weight: 500;
    line-height: 1.4;
    border-left: 3px solid transparent;
}

#sidebar-nav > li > a:hover {
    color: #0366d6;
    background: #eef2f7;
}

#sidebar-nav > li > a.active {
    color: #0366d6;
    border-left-color: #0366d6;
    background: #e8f0fe;
    font-weight: 600;
}

/* Subsections: hidden by default, shown when parent is expanded */
.sidebar-subsections {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease;
}

#sidebar-nav li.expanded > .sidebar-subsections {
    max-height: 50em;
}

.sidebar-subsections li a {
    display: block;
    padding: 0.2em 1em 0.2em 2.2em;
    color: #777;
    text-decoration: none;
    font-size: 0.75em;
    line-height: 1.4;
    border-left: 3px solid transparent;
}

.sidebar-subsections li a:hover {
    color: #0366d6;
    background: #eef2f7;
}

.sidebar-subsections li a.active {
    color: #0366d6;
    border-left-color: #0366d6;
    background: #e8f0fe;
    font-weight: 600;
}

#sidebar-toggle {
    display: none;
    position: fixed;
    top: 0.5em;
    left: 0.5em;
    z-index: 200;
    background: #f8f9fa;
    border: 1px solid #e1e4e8;
    border-radius: 4px;
    padding: 0.3em 0.6em;
    font-size: 1.2em;
    cursor: pointer;
}

/* Content area */
#content {
    margin-left: 16em;
    max-width: 48em;
    padding: 2em 2em 2em 3em;
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    color: #333;
}

h1, h2, h3, h4, h5, h6 {
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    color: #1a1a1a;
}

h1 { font-size: 1.8em; border-bottom: 2px solid #ddd; padding-bottom: 0.3em; }
h2 { font-size: 1.4em; border-bottom: 1px solid #eee; padding-bottom: 0.2em; }

a { color: #0366d6; }

code {
    background: #f4f4f4;
    padding: 0.15em 0.3em;
    border-radius: 3px;
    font-size: 0.9em;
}

pre {
    background: #f6f8fa;
    padding: 1em;
    border-radius: 6px;
    overflow-x: auto;
    border: 1px solid #e1e4e8;
}

pre code {
    background: none;
    padding: 0;
}

blockquote {
    border-left: 4px solid #ddd;
    margin-left: 0;
    padding-left: 1em;
    color: #666;
}

table {
    border-collapse: collapse;
    width: 100%;
    margin: 1em 0;
}

th, td {
    border: 1px solid #ddd;
    padding: 0.5em 0.75em;
    text-align: left;
}

th { background: #f6f8fa; }

hr { border: none; border-top: 1px solid #ddd; margin: 2em 0; }

/* Inline detailed TOC */
#full-toc {
    background: #f8f9fa;
    border: 1px solid #e1e4e8;
    border-radius: 6px;
    padding: 1em 1.5em;
    margin-bottom: 2em;
}

#full-toc summary {
    cursor: pointer;
    user-select: none;
}

#TOC ul { list-style: none; padding-left: 1.2em; }
#TOC > ul { padding-left: 0; }

.download-link {
    display: inline-block;
    background: #0366d6;
    color: #fff !important;
    padding: 0.5em 1.2em;
    border-radius: 6px;
    text-decoration: none;
    font-weight: 500;
    margin-bottom: 1.5em;
    margin-right: 0.5em;
}

.download-link:hover { background: #0250a3; }

/* Heading anchor links (permalink on hover) */
.heading-anchor {
    visibility: hidden;
    text-decoration: none;
    color: #aaa;
    margin-left: 0.3em;
    font-weight: 400;
}

h1:hover .heading-anchor,
h2:hover .heading-anchor,
h3:hover .heading-anchor,
h4:hover .heading-anchor,
h5:hover .heading-anchor,
h6:hover .heading-anchor {
    visibility: visible;
}

.heading-anchor:hover {
    color: #0366d6;
}

/* Hide anchors when copied into TOC/sidebar */
#sidebar .heading-anchor,
#TOC .heading-anchor,
#full-toc .heading-anchor {
    display: none;
}

header { margin-bottom: 1em; }

.author { margin: 0.3em 0; }
.author-name { font-weight: 600; }
.author-affiliation { font-style: italic; color: #555; }
.author-email { font-size: 0.9em; }

/* Responsive: collapse sidebar on narrow screens */
@media (max-width: 60em) {
    #sidebar {
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }
    #sidebar.open {
        transform: translateX(0);
        box-shadow: 2px 0 8px rgba(0,0,0,0.15);
    }
    #sidebar-toggle {
        display: block;
    }
    #content {
        margin-left: 0;
        padding: 2em 1em;
        padding-top: 3em;
    }
}
