/* ── Secondary sidebar (right-side TOC) ────────────────────────────── */
/* Hidden by default and enabled only when JS marks body.toc-has-content */
.md-sidebar--secondary.md-sidebar,
.md-nav--secondary {
    display: none;
}

/* Desktop behavior: keep native Material layout */
@media (min-width: 76.25em) {
    body.toc-visible.toc-has-content .md-sidebar--secondary.md-sidebar,
    body.toc-visible.toc-has-content .md-nav--secondary {
        display: block;
    }

    body.toc-visible.toc-has-content .md-sidebar--secondary .md-sidebar__scrollwrap {
        height: 85vh !important;
        overflow-y: auto !important;
    }

    body.toc-visible.toc-has-content .md-sidebar--secondary .md-sidebar__inner {
        background: rgba(0, 0, 0, 0.03);
        border-radius: 4px;
    }

    [data-md-color-scheme="slate"] body.toc-visible.toc-has-content .md-sidebar--secondary .md-sidebar__inner {
        background: rgba(255, 255, 255, 0.04);
    }

    body.toc-visible.toc-has-content .md-grid {
        max-width: 95%;
    }
}

/* Active TOC link highlighting */
body.toc-visible.toc-has-content .md-nav--secondary .md-nav__link--active {
    font-weight: 600;
    border-left: 3px solid var(--heading-accent, #3c678a);
    padding-left: 0.5em;
}

/* TOC search box (under md-nav__title) */
body.toc-has-content .md-sidebar--secondary .toc-search {
    margin: 0.6rem 0.2rem 0.45rem;
}

body.toc-has-content .md-sidebar--secondary .toc-search__input {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--md-default-fg-color--lightest);
    border-radius: 0.25rem;
    padding: 0.35rem 0.55rem;
    background: var(--md-default-bg-color);
    color: var(--md-default-fg-color);
    font-size: 0.62rem;
    line-height: 1.25;
}

body.toc-has-content .md-sidebar--secondary .toc-search__input::placeholder {
    color: var(--md-default-fg-color--light);
}

body.toc-has-content .md-sidebar--secondary .toc-search__input:focus {
    border-color: var(--md-accent-fg-color);
    outline: none;
}

body.toc-search-active .md-sidebar--secondary .md-nav__link.toc-search-hit {
    color: var(--md-accent-fg-color);
    font-weight: 600;
}

/* ── Heading permalink anchors (GitHub octicon-link style) ── */
.md-typeset .headerlink {
    visibility: hidden;
    opacity: 0.55;
    margin-left: 0.3em;
    text-decoration: none;
    transition: visibility 0.15s, opacity 0.15s;
    vertical-align: middle;
}
.md-typeset h1:hover .headerlink,
.md-typeset h2:hover .headerlink,
.md-typeset h3:hover .headerlink,
.md-typeset h4:hover .headerlink,
.md-typeset h5:hover .headerlink,
.md-typeset h6:hover .headerlink,
.md-typeset .headerlink:hover,
.md-typeset .headerlink:focus {
    visibility: visible;
    opacity: 0.85;
}

/* ── TOC hamburger toggle button in the header bar ── */
.toc-toggle-btn {
    background: transparent;
    border: none;
    color: currentColor;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    width: 2.4rem;
    height: 2.4rem;
    padding: 0;
    border-radius: 0.2rem;
    transition: background 0.2s, opacity 0.2s;
    opacity: 0.7;
    position: relative;
    vertical-align: middle;
}
.toc-toggle-btn:hover {
    opacity: 1;
    background: rgba(127,127,127,0.12);
}
.toc-toggle-btn.active {
    opacity: 1;
}
.toc-toggle-btn svg {
    width: 1.2rem;
    height: 1.2rem;
}
/* Button is shown only when page has a generated TOC */
body.toc-has-content .toc-toggle-btn {
    display: inline-flex;
}

/* Mobile behavior: TOC as a right drawer overlay */
@media (max-width: 76.1875em) {
    .md-sidebar--secondary.md-sidebar {
        display: block;
        position: fixed;
        top: 0;
        right: 0;
        width: min(82vw, 20rem);
        height: 100dvh;
        margin: 0;
        padding-right: 0 !important;
        z-index: 16;
        background: var(--md-default-bg-color);
        border-left: 1px solid var(--md-default-fg-color--lightest);
        box-shadow: none;
        transform: translateX(100%);
        transition: transform 0.2s ease;
        pointer-events: none;
    }

    .md-sidebar--secondary .md-sidebar__inner {
        height: 100%;
        padding-right: 0 !important;
        background: transparent;
        border-radius: 0;
    }

    .md-sidebar--secondary .md-sidebar__scrollwrap {
        height: 100% !important;
        max-height: none !important;
        min-height: 0;
        padding-right: 0 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    .md-sidebar--secondary .md-nav--secondary {
        padding-right: 0 !important;
    }

    body.toc-visible.toc-mobile-open.toc-has-content .md-sidebar--secondary.md-sidebar {
        transform: translateX(0);
        pointer-events: auto;
    }

    body.toc-visible.toc-mobile-open.toc-has-content .md-nav--secondary {
        display: block;
    }

    .md-sidebar--secondary .md-nav--secondary .md-nav__list {
        margin: 0;
        padding-left: 0;
    }

    .md-sidebar--secondary .md-nav--secondary .md-nav__link {
        display: block;
        width: 100%;
    }

    .md-sidebar--secondary .md-nav--secondary > .md-nav__list > .md-nav__item > .md-nav__link {
        padding-left: 0.1rem;
    }

    .md-sidebar--secondary .md-nav--secondary .md-nav__list .md-nav__list {
        margin-left: 0.9rem;
        padding-left: 0.7rem;
        border-left: 1px solid var(--md-default-fg-color--lightest);
    }

    .md-sidebar--secondary .md-nav--secondary .md-nav__list .md-nav__list .md-nav__list {
        margin-left: 0.75rem;
        padding-left: 0.55rem;
    }

    .toc-mobile-backdrop {
        position: fixed;
        inset: 0;
        z-index: 15;
        background: rgba(0, 0, 0, 0.42);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
    }

    body.toc-visible.toc-mobile-open.toc-has-content .toc-mobile-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    body.toc-visible.toc-mobile-open.toc-has-content {
        overflow: hidden;
    }

    /* Prevent any layout expansion on mobile when TOC is missing/hidden */
    .md-main__inner,
    .md-content {
        margin-right: 0 !important;
    }

    body.toc-visible.toc-has-content .md-grid {
        max-width: 100%;
    }
}

/* ── Code block language label (.filename): hidden by default ── */
/* Use same specificity as theme rule (.highlight span.filename) and !important
   to override its display:flow-root. */
.highlight span.filename {
    display: none !important;
}
.highlight span.filename.filename--visible {
    display: flow-root !important;  /* restore theme value when shown */
}
/* When .filename is hidden the theme's .filename+pre margin/radius reset
   no longer applies, so restore normal pre border-radius */
.highlight span.filename:not(.filename--visible) + pre {
    margin-top: 1em;
    border-top-left-radius: 0.1rem;
    border-top-right-radius: 0.1rem;
}

/* Language toggle button — positioned like the copy-to-clipboard btn */
.lang-toggle-btn {
    position: absolute;
    top: 0.45em;
    right: 2.8em;  /* leave room for the copy button to the right */
    z-index: 2;
    background: transparent;
    border: none;
    color: var(--md-default-fg-color--lightest, rgba(0,0,0,0.26));
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5em;
    height: 1.5em;
    padding: 0;
    border-radius: 0.15em;
    transition: color 0.2s, background 0.2s;
    opacity: 0.6;
}
.lang-toggle-btn:hover {
    opacity: 1;
    color: var(--md-accent-fg-color, #526cfe);
    background: rgba(127,127,127,0.08);
}
.lang-toggle-btn.active {
    opacity: 1;
    color: var(--md-accent-fg-color, #526cfe);
}
.lang-toggle-btn svg {
    width: 1.1em;
    height: 1.1em;
    fill: currentColor;
}

/* General styles for navigation and typeset */
.md-nav {
    font-size: 14px;
    line-height: 1.4;
}

.md-nav__link {
    display: inline-flex;
}

.md-typeset {
    font-size: .7rem;
    line-height: 1.5;
}

/* Adjust spacing for paragraphs and line breaks */
.md-typeset p {
    margin: 0.5em 0;
}

/* Hide double line breaks in markdown source (e.g. between list items) */
.md-typeset p br + br {
    display: none;
}

.md-typeset h1,
.md-typeset h2,
.md-typeset h3,
.md-typeset h4,
.md-typeset h5 {
    color: var(--heading-color);
    letter-spacing: 0.01em;
}

.md-typeset h1 {
    padding-bottom: 0.2rem;
    border-bottom: 1px solid var(--heading-rule);
}

.md-typeset h2,
.md-typeset h3,
.md-typeset h4,
.md-typeset h5 {
    font-weight: 500;
    margin-top: 1.4em;
    margin-bottom: 0.65em;
    padding-bottom: 0.12rem;
    border-bottom: 1px dashed var(--heading-accent);
}

.md-typeset code,
.md-typeset pre {
    color: var(--code-color);
}

.text-center {
    text-align: center !important;
}

.md-typeset table:not([class]) th {
    color: var(--table-foreground);
    background-color: var(--table-background);
}

[data-md-color-primary="blue-grey"] {
    --md-primary-fg-color: #436584;
}

[data-md-color-scheme="default"] {
    --code-color: #0891b2;        /* teal — matches colorscheme-modern.css .part1 */
    --table-foreground: var(--md-default-bg-color); /* table header backgrounds */
    --table-background: var(--md-default-fg-color--light); /* table header (text) */
    --heading-color: #203146;
    --heading-accent: #3c678a;
    --heading-rule: rgba(60, 103, 138, 0.32);
}

[data-md-color-scheme="slate"] {
    --code-color: #06b6d4;        /* bright cyan — readable on dark slate */
    --md-typeset-a-color: #7c90ff; /* links */
    --table-foreground: #a3acdf; /* table header (text) */
    --table-background: #272e53; /* table header backgrounds */
    --heading-color: #dfe7ff;
    --heading-accent: #6a85d8;
    --heading-rule: rgba(106, 133, 216, 0.45);
}

/* Final mobile override: disable theme max-height clamps and keep scrolling */
@media (max-width: 76.1875em) {
    body.toc-visible.toc-mobile-open.toc-has-content .md-sidebar--secondary .md-sidebar__inner,
    body.toc-visible.toc-mobile-open.toc-has-content .md-sidebar--secondary .md-sidebar__scrollwrap,
    body.toc-visible.toc-mobile-open.toc-has-content .md-sidebar--secondary .md-nav--secondary {
        max-height: none !important;
    }

    body.toc-visible.toc-mobile-open.toc-has-content .md-sidebar--secondary .md-sidebar__scrollwrap,
    body.toc-visible.toc-mobile-open.toc-has-content .md-sidebar--secondary .md-nav--secondary {
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }
}
