/* ==========================================================================
   Shared components: site header, navigation, theme toggle, footer.
   Navigation collapses below 60rem (keep in sync with NAV_DESKTOP_QUERY in
   js/main.js).
   ========================================================================== */

/* ---------- Brand (logo) ---------- */

.brand {
    display: inline-flex;
    align-items: center;
    min-height: 2.75rem;
    text-decoration: none;
}

.brand__logo {
    width: auto;
    height: 2.75rem;
    filter: var(--logo-filter);
}

@media (min-width: 60rem) {
    .site-header .brand__logo {
        height: 3.25rem;
    }
}

/* ---------- Header ---------- */

.site-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--color-header-bg);
    border-bottom: var(--border-width) solid var(--color-border);
}

/* DOM order is brand → menu toggle → nav → theme toggle, so the tab order
   matches what is seen: on phones the open menu panel sits beneath the
   top row, on desktop the links sit between the brand and theme toggle. */
.site-header__inner {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas:
        "brand menu theme"
        "nav nav nav";
    align-items: center;
    column-gap: var(--space-xs);
    min-height: var(--header-height);
    padding-block: var(--space-xs);
}

.site-header .brand { grid-area: brand; justify-self: start; }
.nav-toggle { grid-area: menu; }
.site-nav { grid-area: nav; }
.theme-toggle { grid-area: theme; }

.icon-button {
    display: inline-grid;
    place-items: center;
    width: 2.75rem;
    height: 2.75rem;
    padding: 0;
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text);
    cursor: pointer;
    transition: border-color var(--duration) var(--ease);
}

.icon-button:hover {
    border-color: var(--color-border-strong);
}

.icon-button svg {
    width: 1.25rem;
    height: 1.25rem;
}

/* Controls that need JavaScript are hidden without it. */
.no-js .theme-toggle,
.no-js .nav-toggle {
    display: none;
}

/* Theme toggle shows the icon of the theme it will switch to. */
.theme-toggle__sun {
    display: none;
}

.theme-toggle[aria-pressed="true"] .theme-toggle__sun {
    display: block;
}

.theme-toggle[aria-pressed="true"] .theme-toggle__moon {
    display: none;
}

/* Menu toggle icon swaps when open. */
.nav-toggle__close {
    display: none;
}

.nav-toggle[aria-expanded="true"] .nav-toggle__open {
    display: none;
}

.nav-toggle[aria-expanded="true"] .nav-toggle__close {
    display: block;
}

/* ---------- Primary navigation ---------- */

.site-nav__list {
    display: flex;
    flex-wrap: wrap;
    gap: 0 var(--space-xs);
    margin: 0;
    padding: 0 0 var(--space-xs);
    list-style: none;
}

.site-nav__link {
    position: relative;
    display: flex;
    align-items: center;
    min-height: 2.75rem;
    padding: 0 var(--space-sm);
    color: var(--color-heading);
    font-family: var(--font-display);
    font-size: 0.9375rem;
    font-weight: 700;
    letter-spacing: var(--tracking-caps);
    text-decoration: none;
    text-transform: uppercase;
}

.site-nav__link:hover {
    color: var(--color-accent-text);
}

/* Current section: orange text plus an orange bar (shape, not colour alone). */
.site-nav__link[aria-current="true"] {
    color: var(--color-accent-text);
}

.site-nav__link[aria-current="true"]::before {
    content: "";
    position: absolute;
    inset: 0 var(--space-sm) auto;
    height: 3px;
    background: var(--color-accent);
}

/* With JavaScript on small screens the list becomes a disclosure panel. */
@media (max-width: 59.99rem) {
    /* Without JavaScript the full link list makes the header too tall to stay
       sticky without covering anchor targets, so it scrolls with the page. */
    .no-js .site-header {
        position: static;
    }

    .js .site-nav {
        display: none;
    }

    .js .site-nav[data-open] {
        display: block;
    }

    .js .site-nav__list {
        flex-direction: column;
        padding-block: var(--space-xs) var(--space-md);
        border-top: var(--border-width) solid var(--color-border);
    }

    .js .site-nav__link[aria-current="true"]::before {
        inset: var(--space-xs) auto var(--space-xs) 0;
        width: 3px;
        height: auto;
    }
}

@media (min-width: 60rem) {
    .site-header__inner {
        grid-template-columns: auto minmax(0, 1fr) auto;
        grid-template-areas: "brand nav theme";
        column-gap: var(--space-lg);
    }

    .site-nav {
        justify-self: end;
        align-self: stretch;
        display: flex;
    }

    .site-nav__list {
        padding: 0;
    }

    .site-nav__link {
        height: 100%;
        padding-inline: var(--space-md);
    }

    .nav-toggle {
        display: none;
    }
}

@media (min-width: 72rem) {
    .site-nav__link {
        font-size: 1rem;
        padding-inline: 1.125rem;
    }
}

/* ---------- Footer ---------- */

.site-footer {
    padding-block: var(--space-2xl) var(--space-xl);
    background: var(--color-bg);
    border-top: var(--border-width) solid var(--color-border);
    font-size: var(--text-sm);
}

.site-footer__inner {
    display: grid;
    gap: var(--space-xl);
}

.site-footer__inner > * {
    min-width: 0;
}

.site-footer__email {
    overflow-wrap: anywhere;
}

.site-footer .brand__logo {
    height: 3rem;
}

.site-footer__nav ul {
    display: flex;
    flex-wrap: wrap;
    gap: 0 var(--space-lg);
    margin: 0;
    padding: 0;
    list-style: none;
}

.site-footer__nav a,
.site-footer__email {
    display: inline-flex;
    align-items: center;
    min-height: 2.75rem;
}

.site-footer__nav a {
    color: var(--color-heading);
    font-weight: 700;
    letter-spacing: var(--tracking-caps);
    text-decoration: none;
    text-transform: uppercase;
}

.site-footer__nav a:hover {
    color: var(--color-accent-text);
    text-decoration: underline;
}

.site-footer__heading {
    margin-bottom: var(--space-2xs);
    color: var(--color-text-muted);
    font-size: 0.8125rem;
    font-weight: 500;
    letter-spacing: var(--tracking-caps);
    text-transform: uppercase;
}

.site-footer__legal {
    padding-top: var(--space-lg);
    border-top: var(--border-width) solid var(--color-border);
    color: var(--color-text-muted);
}

@media (min-width: 48rem) {
    .site-footer__inner {
        grid-template-columns: auto minmax(0, 1fr) auto;
        align-items: center;
        column-gap: var(--space-2xl);
    }

    .site-footer__legal {
        grid-column: 1 / -1;
    }
}
