/* ==========================================================================
   Header — two tiers:
     1. .stsed-header    the blue bar: branding + primary nav
     2. .stsed-subheader the white bar: secondary (resources) nav
   ========================================================================== */

.stsed-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var( --stsed-header-bg );
    color: var( --stsed-header-text );
}

.stsed-header__inner {
    display: flex;
    align-items: center;
    gap: var( --stsed-space-sm );
    min-height: 3.5rem;
}

/* --- Branding ----------------------------------------------------------- */

.stsed-branding {
    display: flex;
    align-items: center;
    flex: none;
    /* Sits flush against the bar's leading edge, like a home tile. */
    margin-inline-start: calc( var( --stsed-space-sm ) * -1 );
    padding-inline: var( --stsed-space-sm );
    align-self: stretch;
}

.stsed-branding__title {
    color: var( --stsed-header-text );
    font-weight: var( --stsed-weight-bold );
    font-size: var( --stsed-text-lg );
    line-height: var( --stsed-leading-tight );
    text-decoration: none;
}

.stsed-branding__title:hover,
.stsed-branding__title:focus-visible {
    color: var( --stsed-header-text );
    text-decoration: none;
    opacity: 0.85;
}

.stsed-branding .custom-logo-link {
    display: flex;
    align-items: center;
}

.stsed-branding .custom-logo {
    max-height: 2.5rem;
    width: auto;
}

/* --- Primary nav -------------------------------------------------------- */

.stsed-header__nav {
    flex: 1;
    min-width: 0;
}

.stsed-nav__list {
    display: flex;
    align-items: center;
    gap: var( --stsed-space-3xs );
    margin: 0;
    padding: 0;
    list-style: none;
}

.stsed-nav__list li {
    margin: 0;
    position: relative;
}

.stsed-nav--primary .stsed-nav__list > li > a {
    display: flex;
    align-items: center;
    padding: var( --stsed-space-2xs ) var( --stsed-space-sm );
    color: var( --stsed-header-text );
    font-weight: var( --stsed-weight-medium );
    border-radius: var( --stsed-radius-sm );
    text-decoration: none;
    white-space: nowrap;
    transition: background-color var( --stsed-transition );
}

.stsed-nav--primary .stsed-nav__list > li > a:hover,
.stsed-nav--primary .stsed-nav__list > li > a:focus-visible {
    background: var( --stsed-header-hover-bg );
    color: var( --stsed-header-text );
    text-decoration: none;
}

.stsed-nav--primary .stsed-nav__list > li.current-menu-item > a,
.stsed-nav--primary .stsed-nav__list > li.current-menu-ancestor > a {
    background: var( --stsed-header-active-bg );
}

/* Keep the focus ring visible against the blue bar. */
.stsed-header :focus-visible {
    outline-color: var( --stsed-grey-0 );
}

/* --- Secondary bar ------------------------------------------------------ */

.stsed-subheader {
    background: var( --stsed-subheader-bg );
    border-block-end: 1px solid var( --stsed-subheader-border );
}

.stsed-subheader__inner {
    display: flex;
    align-items: center;
    min-height: 2.75rem;
    overflow-x: auto;
    /* Horizontal scroll on narrow screens rather than wrapping to two rows. */
    scrollbar-width: none;
}

.stsed-subheader__inner::-webkit-scrollbar {
    display: none;
}

.stsed-nav--secondary .stsed-nav__list {
    gap: var( --stsed-space-2xs );
}

.stsed-nav--secondary .stsed-nav__list > li > a {
    display: flex;
    align-items: center;
    padding: var( --stsed-space-3xs ) var( --stsed-space-2xs );
    color: var( --stsed-subheader-text );
    font-size: var( --stsed-text-sm );
    font-weight: var( --stsed-weight-medium );
    border-radius: var( --stsed-radius-sm );
    white-space: nowrap;
    text-decoration: none;
}

.stsed-nav--secondary .stsed-nav__list > li > a:hover,
.stsed-nav--secondary .stsed-nav__list > li > a:focus-visible {
    background: var( --stsed-color-surface-sunken );
    color: var( --stsed-color-link-hover );
    text-decoration: none;
}

.stsed-nav--secondary .stsed-nav__list > li.current-menu-item > a {
    color: var( --stsed-color-text );
    font-weight: var( --stsed-weight-semibold );
}

/* --- Submenus ----------------------------------------------------------- */

.stsed-nav .sub-menu {
    position: absolute;
    top: 100%;
    inset-inline-start: 0;
    z-index: 10;
    min-width: 12rem;
    margin: 0;
    padding: var( --stsed-space-3xs );
    list-style: none;
    background: var( --stsed-color-surface );
    border: 1px solid var( --stsed-color-border );
    border-radius: var( --stsed-radius-md );
    box-shadow: var( --stsed-shadow-md );
    /* Hidden but focusable-in: opacity+visibility so it animates and so
       :focus-within can reveal it for keyboard users. */
    opacity: 0;
    visibility: hidden;
    transition: opacity var( --stsed-transition ), visibility var( --stsed-transition );
}

.stsed-nav .sub-menu li + li {
    margin: 0;
}

.stsed-nav .sub-menu a {
    display: block;
    padding: var( --stsed-space-3xs ) var( --stsed-space-2xs );
    color: var( --stsed-color-text );
    font-size: var( --stsed-text-sm );
    font-weight: var( --stsed-weight-normal );
    border-radius: var( --stsed-radius-sm );
    white-space: nowrap;
    text-decoration: none;
}

.stsed-nav .sub-menu a:hover,
.stsed-nav .sub-menu a:focus-visible {
    background: var( --stsed-color-surface-sunken );
    color: var( --stsed-color-link-hover );
    text-decoration: none;
}

.stsed-nav__list > li:hover > .sub-menu,
.stsed-nav__list > li:focus-within > .sub-menu {
    opacity: 1;
    visibility: visible;
}

/* --- Mobile toggle ------------------------------------------------------ */

.stsed-header__toggle {
    display: none;
    margin-inline-start: auto;
    padding: var( --stsed-space-2xs );
    color: var( --stsed-header-text );
    border-radius: var( --stsed-radius-sm );
}

.stsed-header__toggle:hover {
    background: var( --stsed-header-hover-bg );
}

.stsed-header__toggle-bars,
.stsed-header__toggle-bars::before,
.stsed-header__toggle-bars::after {
    display: block;
    width: 1.25rem;
    height: 2px;
    background: currentColor;
    border-radius: 1px;
    transition: transform var( --stsed-transition ), opacity var( --stsed-transition );
}

.stsed-header__toggle-bars {
    position: relative;
}

.stsed-header__toggle-bars::before,
.stsed-header__toggle-bars::after {
    content: "";
    position: absolute;
    inset-inline-start: 0;
}

.stsed-header__toggle-bars::before {
    top: -6px;
}

.stsed-header__toggle-bars::after {
    top: 6px;
}

.stsed-header__toggle[aria-expanded="true"] .stsed-header__toggle-bars {
    background: transparent;
}

.stsed-header__toggle[aria-expanded="true"] .stsed-header__toggle-bars::before {
    top: 0;
    transform: rotate( 45deg );
}

.stsed-header__toggle[aria-expanded="true"] .stsed-header__toggle-bars::after {
    top: 0;
    transform: rotate( -45deg );
}

@media ( max-width: 47.999em ) {
    .stsed-header__inner {
        flex-wrap: wrap;
    }

    .stsed-header__toggle {
        display: block;
    }

    .stsed-header__nav {
        flex-basis: 100%;
        display: none;
    }

    .stsed-header__nav.is-open {
        display: block;
    }

    .stsed-nav--primary .stsed-nav__list {
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        padding-block-end: var( --stsed-space-2xs );
    }

    .stsed-nav--primary .stsed-nav__list > li > a {
        padding-inline: var( --stsed-space-2xs );
    }

    /* Submenus can't hover on touch — show them inline, indented. */
    .stsed-nav--primary .sub-menu {
        position: static;
        opacity: 1;
        visibility: visible;
        background: none;
        border: 0;
        box-shadow: none;
        padding-inline-start: var( --stsed-space-sm );
    }

    .stsed-nav--primary .sub-menu a {
        color: var( --stsed-header-text );
    }

    .stsed-nav--primary .sub-menu a:hover,
    .stsed-nav--primary .sub-menu a:focus-visible {
        background: var( --stsed-header-hover-bg );
        color: var( --stsed-header-text );
    }
}
