html {
    scroll-behavior: smooth;
}

section>:first-child,
article>:first-child {
    /* Add margin to the titles of sections and articles to prevent the header from covering it when scrolling to them on mini-toc link click */
    scroll-margin-top: calc(var(--header-height) + 1.85rem);
}

.header-container {
    color: var(--pico-color);
    /* Prevent tabs or long content from making header wider than viewport */
    overflow-x: clip;
    margin-bottom: var(--header-margin-bottom);
    height: var(--header-height);
    position: sticky;
    z-index: 3;
    top: 0;
    width: 100%;
    left: 0;
    background: transparent;
    border-bottom: none;
}

.header {
    display: grid;
    grid-template-columns: minmax(120px, 1fr) minmax(0, 600px) minmax(120px, 1fr);
    align-items: center;
    gap: 2rem;
    margin: 1rem 2rem;

    .header-mobile-top {
        background: var(--elements-background);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border-radius: 6px;
        border: none;
        padding: 0 1rem;
        height: 2.5rem;
    }
}

.header .logo-container {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    background-color: var(--main-background-color);
    width: fit-content;
    border-radius: 6px;
    height: 40px;
    padding-left: 1rem;
    padding-right: 1rem;
    margin-left: -1rem;
}

.header .header-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 2rem;
}

.brand-logo {
    flex-shrink: 0;
    min-width: 24px;
}

.brand-logo img {
    height: 28px;
    display: block;
}

.brand-logo.logo-black {
    display: block;
}

.brand-logo.logo-white {
    display: none;
}

.theme-toggle__expand {
    margin-top: 0.20rem;
    width: 20px;
    height: 20px;
    fill: var(--pico-muted-color);
    stroke: var(--pico-muted-color);
}

@media (prefers-color-scheme: dark) {
    .brand-logo.logo-black {
        display: none;
    }

    .brand-logo.logo-white {
        display: block;
    }
}

[data-theme=dark] .brand-logo.logo-white {
    display: block;
}

[data-theme=light] .brand-logo.logo-black {
    display: block;
}

[data-theme=light] .brand-logo.logo-white {
    display: none;
}

[data-theme=dark] .brand-logo.logo-black {
    display: none;
}



/* New search input structure */
.search-container {
    position: relative;
    background: transparent;
    display: flex;
    align-items: center;

    @media print {
        display: none;
    }
}

/* Search toggle button (shown on mobile, hidden on desktop) */
.search-toggle-button {
    display: none;
    position: relative;
    right: 0;
    background: var(--elements-background);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 6px;
    border: none;
    color: var(--pico-muted-color, inherit);
    cursor: pointer;
    padding: 0.625rem;
    height: 2.5rem;
    width: 2.5rem;
}

.search-toggle-button:hover {
    background: rgba(127, 127, 127, 0.08);
}

/* Search input wrapper - hidden by default, expands on mobile */
.search-input-wrapper {
    display: flex;
    width: 100%;
    position: relative;
}

/* Close button in search wrapper */
.search-close-button {
    position: absolute;
    right: 0.4rem;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--pico-muted-color, inherit);
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0.25rem;
    border-radius: 6px;
    z-index: 10;
}

.search-close-button:hover {
    background: rgba(127, 127, 127, 0.08);
}

input.search-input {
    display: flex;
    align-items: center;
    margin: 0;
    padding-right: 4rem;
    height: 2.5rem;
    background: var(--elements-background);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 6px;
    border: none;
    box-shadow: var(--pico-dropdown-box-shadow);
}

.search-input::placeholder {
    color: var(--pico-muted-color, #6b7280);
    margin-top: 0;
}

.search-submit-button {
    position: absolute;
    right: 0.4rem;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--pico-muted-color, inherit);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.25rem;
    border-radius: 6px;
}

.search-submit-button:hover {
    background: rgba(127, 127, 127, 0.08);
}

/* Remove old input-field-based styling no longer used by header search */
.input-field {
    position: static;
}

.input-field input[type="text"] {
    padding-left: initial;
}

.input-field label {
    position: static;
    transform: none;
}

.header details.dropdown {
    margin-bottom: 0;
    height: 2.5rem;
}

.header details.dropdown>summary {
    margin-bottom: 0;
    height: 2.5rem;
    padding-top: 0;
    display: flex;
    align-items: center;
    padding-bottom: 0;
    background: transparent;
    border: none;
}

.header details.dropdown.auth-links>summary {
    border: none;
    padding: 0;
    margin: 0;
}

.header details.dropdown.auth-links>summary:focus {
    box-shadow: none;
}

.header details.dropdown.auth-links>summary::after {
    display: none;
}

.header details.dropdown>summary>svg {
    width: 2rem;

}

.auth-links.dropdown::after {
    display: none;
}

.header-mobile-top {
    display: flex;
    align-items: center;
    gap: 2rem;
}

details.dropdown>summary:not([role]) svg,
.header-mobile-top label {
    transition: all 0.5s ease;
}

details.dropdown>summary:not([role]) svg:hover,
.header-mobile-top label:hover {
    filter: brightness(1.5);
}


.header details.dropdown.sections-dropdown {
    background: transparent;
    border-radius: 6px;
    border: none;
    outline: none;
    /* Don't create containing block - remove backdrop-filter from parent */
}

.header details.dropdown.sections-dropdown ul {
    position: absolute;
    right: 0;
    width: max-content;
    max-width: 100vw;
    top: 100%;
    z-index: 1000;
    margin-top: 0.5rem;
    overflow: scroll;
    max-height: calc(100vh - var(--header-height));
}

.header details.dropdown.sections-dropdown ul>li {
    max-width: 100vw;
}

.header details.dropdown.sections-dropdown>summary {
    margin: 0;
    padding: 0;
    border: none;
}

.header details.dropdown.sections-dropdown>summary::after {
    transition: all 0.5s ease;
}

.header details.sections-dropdown>summary:hover::after {
    filter: brightness(1.5);
}

.header details.dropdown.sections-dropdown>summary:focus,
.header details.dropdown.sections-dropdown>summary:focus-visible {
    outline: none;
    box-shadow: none;
    border: none;
}


@media (prefers-color-scheme: dark) {
    .header details.sections-dropdown>summary::after {
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke-width='3' stroke='%23a1a1aa' %3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5'/%3E%3C/svg%3E");
    }
}

/* Responsive header tweaks */
@media (max-width: 900px) {
    .brand-logo {
        margin-top: 0;
    }

    .header-container {
        position: relative;
        --header-margin-bottom: 4rem;
    }

    .header {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        gap: 2rem;
        margin-bottom: 0;
        margin-left: 1rem;
        margin-right: 1rem;
    }

    .header .logo-container {
        justify-content: flex-start;
        width: fit-content;
    }

    .header .header-right .header-mobile-top {
        position: relative;
        right: auto;
        top: auto;
        gap: 1.5rem;
    }

    .header-mobile-top {
        @media print {
            display: none;
        }
    }

    .tabs {
        gap: 0.125rem;
    }

    .tab {
        height: 2rem;
        padding: 0 0.5rem;
    }

    .header-mobile-top {
        position: absolute;
        right: 1rem;
        top: 1rem;
    }

    .search-container {
        width: 100%;
    }

    /* Center sections dropdown on mobile */
    .header details.dropdown.sections-dropdown ul {
        position: fixed;
        top: calc(var(--header-height) + 1rem);
        width: calc(100vw - 2rem);
        max-width: 500px;
    }

}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 1175px) {

    /* Adjust grid layout for tablets to prevent dropdown overlap with search */
    .header {
        grid-template-columns: minmax(80px, 1fr) minmax(0, 450px) minmax(100px, 1fr);
        gap: 1.5rem;
    }

    /* Adjust dropdown positioning on tablets to prevent overlap with search */
    .header details.dropdown.sections-dropdown ul {
        right: 0;
        left: auto;
    }

    .header details.dropdown.sections-dropdown>summary {
        border: none;
        box-shadow: none;
        background: transparent;
        margin: 0;
        padding: 0;
    }

    .header details.sections-dropdown>summary>span {
        display: none;
    }

    /* Add hamburger menu icon to sections dropdown */
    .header details.sections-dropdown>summary::after {
        content: "";
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke-width='1.5' stroke='currentColor' class='size-6'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5'/%3E%3C/svg%3E");
        width: 20px;
        height: 20px;
        display: inline-block;
        margin-left: 0.5rem;
        background-repeat: no-repeat;
        background-position: center;
        background-size: contain;
    }

    @media (prefers-color-scheme: dark) {
        .header details.sections-dropdown>summary::after {
            background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke-width='1.5' stroke='%23a1a1aa' class='size-6'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5'/%3E%3C/svg%3E");
        }
    }
}