/* Header - Navigation bar, logo, search form, and header layout */

header {
    position: relative;
    z-index: 10;
}

body:has(.hero-image) > header {
    position: absolute;
    inset-block-start: 0;
    inset-inline: 0;
}

header li {
    display: inline-block;
}

.header-a svg {
    color: var(--color-primary);
}

.logo-svg {
    width: var(--space-xl);
    height: var(--space-xl);
    transform: rotate(-15deg);
}

.header {
    color: var(--color-foreground);
}

.header a:not(.button, .avatar, .menu-content a, .search-suggestions a) {
    color: var(--color-foreground);
    text-align: center;
    text-decoration: none;
    border-radius: 4px;
}

.header a.logo {
    font-size: 25px;
    color: var(--color-foreground);
    display: grid;
    place-items: center;
    min-inline-size: 3rem;
    min-block-size: 3rem;
    margin: 0;
    flex: 0 0 auto;
    filter: drop-shadow(0 0.35rem 0.75rem rgb(0 0 0 / 0.28));
    transition: transform 0.18s ease, filter 0.18s ease;
}

.header a.logo:hover {
    filter: drop-shadow(0 0.45rem 0.95rem rgb(0 0 0 / 0.4)) brightness(1.05);
}

.header a.logo:active {
    transform: scale(0.94);
}

.header a:not(.button, .avatar, .menu-content a):hover {
    color: var(--color-muted);
}

.header a:not(.button, .avatar, .menu-content a).active {
    color: var(--color-muted);
}

.header-a, .header-b {
    display: flex;
    align-items: center;
}

.header-a {
    justify-content: flex-start;
    gap: var(--space-md, 1rem);
}

.header-b {
    justify-content: flex-end;
    gap: var(--space-sm, 0.75rem);
}

.header-a svg, .header-b svg {
    vertical-align: middle;
}

nav.header {
    --hero-max-width: calc(2 * var(--grid-max-width));
    --feather-size: clamp(0px, (100vw - var(--hero-max-width)) * 0.5, 6rem);
    --header-control-height: clamp(2.4rem, 2.15rem + 0.65vw, 2.75rem);

    box-sizing: border-box;
    inline-size: min(100%, var(--hero-max-width));
    margin-inline: auto;
    padding-block: max(0.85rem, env(safe-area-inset-top)) 0.85rem;
    padding-inline: calc(var(--grid-gutter) + var(--feather-size));
    display: grid;
    /* Equal flexible side tracks keep the search box on the page's center line; each side still
       keeps room for its own content, so on narrow screens the search box simply takes what is left */
    grid-template-columns: minmax(max-content, 1fr) minmax(0, 24rem) minmax(max-content, 1fr);
    align-items: center;
    gap: clamp(0.5rem, 2vw, 0.85rem);
    background-color: transparent;
}

nav.header .logo {
    flex-shrink: 0;
    /* Stop the link stretching across its now-wider column */
    justify-self: start;
}

nav.header .logo-svg {
    height: 2.25rem;
    width: auto;
}

nav.header .header-avatar {
    --avatar-size: var(--header-control-height);
}

nav.header .header-b a.button {
    box-sizing: border-box;
    block-size: var(--header-control-height);
    min-block-size: var(--header-control-height);
    padding-block: 0;
    padding-inline: clamp(0.75rem, 1.8vw, 1.15rem);
    border-radius: 9999px;
    font-family: var(--font-family-san-serif);
    font-size: clamp(0.82rem, 0.76rem + 0.25vw, 0.95rem);
    white-space: nowrap;
}

/* House-green contribution CTA with dark text for contrast. */
nav.header .header-b a.button[href="/Account/Register"] {
    --button-bg: var(--color-primary);
    --button-color: var(--color-foreground);
    --button-hover-bg: var(--uchu-green-6);
    --button-hover-color: var(--color-foreground);
    --button-outline-color: var(--color-foreground);
}

.search-form {
    box-sizing: border-box;
    inline-size: min(100%, 24rem);
    justify-self: center;
    block-size: var(--header-control-height);
    min-block-size: var(--header-control-height);
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    border-radius: 9999px;
    background: rgb(255 255 255 / 0.75);
    border: 1px solid rgb(0 0 0 / 0.12);
    box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.6), 0 0.4rem 1.25rem rgb(0 0 0 / 0.14);
    backdrop-filter: blur(1.2rem) saturate(135%);
    transition: background-color 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.search-form:focus-within {
    background: rgb(255 255 255 / 0.92);
    border-color: var(--color-primary);
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.search-form .search-submit {
    inline-size: var(--header-control-height);
    block-size: 100%;
    display: grid;
    place-items: center;
    padding: 0;
    margin: 0;
    border: 0;
    border-radius: 9999px;
    background: transparent;
    color: rgb(28 29 35 / 0.7);
    cursor: pointer;

    &:hover,
    &:focus {
        background: transparent;
        border-color: transparent;
        color: var(--color-foreground);
        outline: none;
    }

    & svg {
        inline-size: 1.15rem;
        block-size: 1.15rem;
        fill: none;
        stroke: currentColor;
        stroke-linecap: round;
        stroke-width: 2;
    }
}

.search-form input[type="search"] {
    box-sizing: border-box;
    min-inline-size: 0;
    inline-size: 100%;
    block-size: 100%;
    padding: 0 1rem 0 0;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--color-foreground);
    font-family: var(--font-family-san-serif);
    font-size: 0.95rem;
}

/* Typeahead panel: Datastar patches #search-suggestions; search-dropdown.js adds data-dismissed on Escape or
   short input. Hidden whenever focus leaves the form, which also closes it on an outside click. */
.search-form {
    position: relative;
}

.search-suggestions {
    position: absolute;
    inset-block-start: calc(100% + 0.45rem);
    inset-inline: 0;
    z-index: 100;
    box-sizing: border-box;
    max-block-size: calc(100dvh - 6rem);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-block: 0.4rem 0;
    border-radius: 0.9rem;
    border: 1px solid #e6e4dd;
    background-color: var(--color-background);
    box-shadow:
        0 10px 28px rgb(0 0 0 / 0.12),
        0 2px 6px rgb(0 0 0 / 0.06);
    font-family: var(--font-family-san-serif);
}

.search-form:not(:focus-within) .search-suggestions,
.search-form[data-dismissed] .search-suggestions {
    display: none;
}

.search-suggestion {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: baseline;
    column-gap: 0.75rem;
    padding: 0.55rem 1rem;
    border-inline-start: 3px solid transparent;
    color: var(--color-foreground);
    text-decoration: none;
    line-height: 1.3;

    &:hover,
    &[aria-selected="true"] {
        background-color: #f5f3ee;
    }

    &[aria-selected="true"] {
        border-inline-start-color: var(--color-primary);
    }
}

.search-suggestion-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.95rem;
    font-weight: 500;
}

.search-suggestion-type {
    padding: 0.1rem 0.45rem;
    border-radius: 9999px;
    background: var(--color-surface);
    color: var(--color-muted);
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.search-suggestion-snippet {
    grid-column: 1 / -1;
    margin-block-start: 0.15rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--color-muted);
    font-size: 0.8rem;
}

.search-suggestions mark {
    padding-inline: 0.05em;
    border-radius: 2px;
    background: color-mix(in oklch, var(--color-primary) 30%, transparent);
    color: inherit;
    font-weight: 650;
}

.search-suggestions-empty {
    margin: 0;
    padding: 0.55rem 1rem 0.65rem;
    color: var(--color-muted);
    font-size: 0.9rem;
}

.search-suggestions-all {
    display: block;
    margin-block-start: 0.35rem;
    padding: 0.65rem 1rem;
    border-block-start: 1px solid #eceae3;
    color: var(--color-foreground);
    font-size: 0.85rem;
    text-decoration: none;

    &:hover {
        background-color: #f5f3ee;
    }
}

@media (max-width: 48rem) {
    nav.header .header-b a.button:not([data-button-variant="naked"]) {
        display: none;
    }

    nav.header .header-b a.button[data-button-variant="naked"] {
        --button-bg: var(--uchu-yin-8);
        --button-color: var(--uchu-yang);
        --button-border-color: var(--uchu-yin-8);
        --button-hover-bg: var(--uchu-green-6);
        --button-hover-color: #ffffff;
    }
}

@media (max-width: 40rem) {
    nav.header:has(.search-form:focus-within) .header-b {
        display: none;
    }

    nav.header:has(.search-form:focus-within) .search-form {
        grid-column: 2 / -1;
        inline-size: 100%;
        max-inline-size: none;
    }
}

/* Account menu uses the same panel, rows, dividers and dismissal layer as article menus. */
.account-menu-trigger {
    display: flex;
    align-items: center;
    padding: 0.25rem;
    border-radius: 9999px;
}

.account-menu-trigger:hover,
.account-menu[open] > .account-menu-trigger {
    background: var(--color-surface);
}

.account-menu .menu-content {
    box-sizing: border-box;
    min-inline-size: 0;
    inline-size: min(19rem, calc(100vw - 2rem));
    padding-block: 0.5rem;
    max-block-size: calc(100dvh - 6rem);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.account-menu-profile {
    min-inline-size: 0;
}

.account-menu-profile small {
    display: block;
    margin-block-start: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.8em;
}

.account-menu .menu-content a {
    min-block-size: 3.25rem;
    box-sizing: border-box;
    padding: 0.8rem 1.15rem;
    gap: 1rem;
    font-size: 1rem;
}

.account-menu .menu-content .menu-item-icon {
    inline-size: 1.5rem;
    block-size: 1.5rem;
    margin-inline: 0.25rem;
}

.account-menu .account-menu-avatar {
    --avatar-size: 2rem;
}

.account-menu-profile small {
    color: var(--color-muted);
}

.account-menu .menu-content .menu-divider {
    margin-inline: 0;
}
