/* Use the active theme palette; keep the track transparent instead of native white. */
body.dm-theme {
    --sidebar-scroll-thumb: var(--dm-accent-start, #9d4edd);
    --sidebar-scroll-hover: var(--dm-accent-end, #00d4e6);
}
body.sl-theme {
    --sidebar-scroll-thumb: var(--sl-accent, var(--sl-lime, #b8ee48));
    --sidebar-scroll-hover: var(--sl-text, #ffffff);
}
body.ul-theme {
    --sidebar-scroll-thumb: var(--ul-lime, #b8ee48);
    --sidebar-scroll-hover: var(--ul-green, #51a91f);
}
body.pyragy-theme {
    --sidebar-scroll-thumb: var(--py-cyan-core, #00b8d9);
    --sidebar-scroll-hover: var(--py-cyan, #2ee6ff);
}
body #sidebar.side-bar {
    --sidebar-scroll-thumb: #00b8c8;
    --sidebar-scroll-hover: #00ffff;
}
body.pw-theme {
    --sidebar-scroll-radius: 0;
}

/* Keep navigation and bottom actions reachable on short screens.
   Loaded after each theme so legacy overflow/hidden-scrollbar rules cannot clip them. */
body.dm-theme #site_header.header.dm-header,
body #site_header.header.pyragy-header,
body #site_header.header:not(.dm-header):not(.pyragy-header),
body #sidebar.side-bar {
    box-sizing: border-box;
    min-height: 0 !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior-y: contain;
    scrollbar-width: thin !important;
    scrollbar-color: var(--sidebar-scroll-thumb, #04b4e0) transparent !important;
    -ms-overflow-style: auto !important;
    -webkit-overflow-scrolling: touch;
}

body #site_header.header::-webkit-scrollbar,
body #sidebar.side-bar::-webkit-scrollbar {
    display: block !important;
    width: 8px !important;
}
body #site_header.header::-webkit-scrollbar-thumb,
body #sidebar.side-bar::-webkit-scrollbar-thumb {
    background: var(--sidebar-scroll-thumb, #04b4e0);
    border: 2px solid transparent;
    background-clip: padding-box;
    border-radius: var(--sidebar-scroll-radius, 8px);
}

body #site_header.header::-webkit-scrollbar-track,
body #site_header.header::-webkit-scrollbar-corner,
body #sidebar.side-bar::-webkit-scrollbar-track,
body #sidebar.side-bar::-webkit-scrollbar-corner {
    background: transparent;
}
body #site_header.header:hover,
body #site_header.header:focus-within,
body #sidebar.side-bar:hover,
body #sidebar.side-bar:focus-within {
    scrollbar-color: var(--sidebar-scroll-hover, #50d4f0) transparent !important;
}
body #site_header.header::-webkit-scrollbar-thumb:hover,
body #sidebar.side-bar::-webkit-scrollbar-thumb:hover {
    background-color: var(--sidebar-scroll-hover, #50d4f0);
}

/* Scroll the entire stack, not a clipped inner flex box. */
body.dm-theme #site_header.header.dm-header .dm-sidebar-stack {
    flex: 0 0 auto !important;
    height: auto !important;
    min-height: min-content !important;
    max-height: none !important;
    overflow: visible !important;
}
body.dm-theme #site_header.header.dm-header .dm-sidebar-stack > *,
body #sidebar.side-bar > * {
    flex-shrink: 0 !important;
}

@media (min-width: 1025px) {
    /* The parent row already excludes the global footer height. */
    body.dm-theme #site_header.header.dm-header {
        align-self: stretch !important;
        height: auto !important;
        max-height: var(--sidebar-available-height, 100vh) !important;
    }
    body #site_header.header.pyragy-header {
        max-height: calc(100vh - 64px) !important;
        max-height: var(--sidebar-available-height, calc(100dvh - 64px)) !important;
    }
    body #site_header.header:not(.dm-header):not(.pyragy-header) {
        max-height: var(--sidebar-available-height, 100vh) !important;
    }
    /* BreezyCV keeps its floating navigation outside the profile column. */
    body #site_header.header:not(.dm-header):not(.pyragy-header) > .main-menu {
        max-height: var(--sidebar-available-height, 80vh);
        overflow-y: auto;
        scrollbar-width: thin;
        scrollbar-color: var(--sidebar-scroll-thumb, #04b4e0) transparent;
        box-sizing: border-box;
    }
}

@media (max-width: 1024px) {
    body #site_header.header,
    body.dm-theme #site_header.header.dm-header:not(.mobile-menu-hide),
    body.pyragy-theme #site_header.header.pyragy-header:not(.mobile-menu-hide) {
        height: 100vh !important;
        height: 100dvh !important;
        min-height: 0 !important;
        max-height: 100vh !important;
        max-height: 100dvh !important;
        overflow-y: auto !important;
        scrollbar-width: thin !important;
    }
    body #site_header.header::-webkit-scrollbar,
    body.dm-theme #site_header.header.dm-header:not(.mobile-menu-hide)::-webkit-scrollbar {
        display: block !important;
        width: 8px !important;
    }
}

body #sidebar.side-bar {
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
}

/* BreezyCV's absolute footer must participate in the scrollable content. */
body #site_header.header .copyrights.breezycv-site-footer {
    position: static;
    width: auto;
    margin-top: 30px;
}

/* Respect the operating system's high contrast palette. */
@media (forced-colors: active) {
    body #site_header.header,
    body #site_header.header:hover,
    body #site_header.header:focus-within,
    body #sidebar.side-bar,
    body #sidebar.side-bar:hover,
    body #sidebar.side-bar:focus-within {
        scrollbar-color: auto !important;
    }
}
