/* ==========================================================================
   Visually hidden utility (screen-reader only)
   ========================================================================== */

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ==========================================================================
   Main Nav — desktop bar
   ========================================================================== */

/* Outside :where() so host pages that embed the header (Aptify) can't override the layout with a generic nav rule */
.site-header > .main-nav {
    display: grid;
    grid-template-columns: 0.25fr 2fr auto;
}

:where(.main-nav) {
    background-color: var(--color-brand-navy);
    gap: 3.8rem;
    font-weight: 500;
    font-size: 1.9rem;
    padding-block: 2.5rem 2rem;
    width: 100%;
    position: relative;
    z-index: 5;
    margin-block-start: var(--top-nav-height);
    overflow-x: hidden;
    padding-inline: var(--mobile-padding);
    box-sizing: border-box;

    .center {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .main-nav-parent-links {
        width: 100%;
    }

    .login-button {
        padding: 1rem;
    }

    :where(ul, li) {
        list-style-type: none;
        margin: 0;
        padding: 0;
        display: inline-block;
    }

    :where(a) {
        color: var(--color-primary-white);
    }

    :where(a:hover, a:active) {
        color: var(--color-brand-orange);
        text-decoration: none;
    }

    /* Logo */

    .logo > svg {
        height: 7rem;
        margin-left: 2rem;
    }

    .logo > svg:nth-child(2) {
        display: none;
        width: 27rem;
    }

    .header-logo.mobile-logo,
    .footer-logo.mobile-logo {
        display: none;
    }

    > .left {
        display: flex;
        align-items: center;
    }

    > .right {
        display: flex;
        flex-flow: row nowrap;
        align-items: center;
        justify-content: flex-end;
        gap: 3rem;
        margin-left: -2.5rem;

        .button-holder {
            display: grid;
            align-items: center;
            font-size: 1.4rem;
        }
    }

    /* Desktop nav links */

    .nav-items {
        display: flex;
        flex-flow: row nowrap;
        gap: 6rem;
        justify-content: flex-end;
        align-items: center;
        overflow: visible;
        margin-bottom: 0;
        width: 100%;
        max-width: 120rem;
        margin-left: auto;

        a > span {
            color: var(--color-primary-white);
            font-size: 1.8rem;
            font-weight: 400;

            &:hover {
                color: var(--color-brand-orange);
            }
        }

        @supports selector(:has(+ *)) {
            a > span:hover,
            a:has(span:hover) + .nav-svg svg path {
                color: var(--color-brand-orange);
                fill: var(--color-brand-orange);
            }
        }

        li {
            display: flex;
            flex-flow: row wrap;
            justify-content: center;
            align-items: center;
            padding-left: 0;
            text-indent: 0;

            & > a {
                display: block;
            }

            /* CTA button — last nav item */
            &:last-child {
                text-indent: 0;
                /* Pull the button toward its left neighbor so its text keeps
                   the same rhythm as the plain links. */
                margin-left: -2rem;

                a {
                    border-radius: 0.5rem;
                    border: solid var(--color-brand-orange) 0.1rem;
                    background: var(--color-brand-orange);

                    transition: all 250ms ease-in-out;
                    min-width: fit-content;
                    display: block;
                    padding: 0.5rem 1.5rem;

                    &:focus-visible {
                        outline: solid var(--color-primary-white) 3px;
                        outline-offset: 0.5rem;
                    }

                    span {
                        color: var(--color-brand-navy);
                    }
                }

                a > span {
                    font-weight: 500;
                    min-width: fit-content;
                    font-size: 1.6rem;
                }

                .nav-svg {
                    display: none;
                }

                &:hover a {
                    background: var(--color-brand-pale-blue);
                    border: 1px solid var(--color-brand-pale-blue);
                    transition: all 250ms ease-in-out;

                    & > span {
                        color: var(--color-brand-navy) !important;
                    }
                }
            }
        }
    }

    /* Mobile menu button */

    .mobile-menu {
        display: flex;
        flex-flow: column wrap;
        align-items: center;
        justify-content: center;
        color: var(--color-primary-white);
        text-transform: uppercase;
        font-size: 1.2rem;
        padding-inline: 0.5rem;

        svg {
            margin-bottom: 0.5rem;
            width: 2.7rem;
            height: 1.8rem;
        }

        h3 {
            font-size: 1.2rem;
            color: var(--color-primary-white);
            margin-block: 0.5rem 0;
        }
    }

    /* Responsive */

    @media (max-width: 80em) {
        gap: 3rem;
        padding-inline: 2rem;

        .nav-items {
            gap: 5rem;
        }

        /* Pull the Join/Renew button and search icon left at this breakpoint
           (smaller offsets than desktop to suit the narrower gap). */
        .nav-items li:last-child {
            margin-left: -2rem;
        }

        .search {
            margin-left: 2.7rem;
            margin-right: -.5rem;
        }

        .header-logo.mobile-logo,
        .footer-logo.mobile-logo {
            display: inline-block !important;
        }

        .logo > svg {
            display: none;
        }

        .nav-items a > span {
            font-size: 1.6rem;
        }

        /* Separate rule needed outside :where() — logo swap at 80em uses mobile-logo class */
        .mobile-logo.header-logo {
            width: 12rem;
            height: 3rem;
        }
    }

    @media (max-width: 1024px) {
        justify-content: space-between;
        align-items: center;
        gap: 4rem;

        .nav-items {
            gap: 0;

            > *:not(.nav-cta) {
                display: none;
            }

            li:last-child {
                margin-right: 0;
            }

            a > span {
                margin-block: 0;
                padding-block: 0;
                font-size: 1.6rem;
            }
        }

        .logo > svg:nth-child(1) {
            display: none;
        }

        .logo > svg:nth-child(2) {
            display: inline-block;
        }

        .mobile-menu {
            display: flex !important;
            background: none;
            order: 2;
        }
    }

    @media (max-width: 450px) {
        gap: 2rem;
        padding-inline: 2rem;

        .logo > svg:nth-child(2) {
            width: 20rem;
        }
    }

    @media screen and (max-width: 414px) {
        .nav-items .nav-cta {
            display: none;
        }
    }
}
