/*
 * HFTKernel 5.7.8 header layout.
 * Load after the theme styles. Header layout and its anchor clearance only;
 * standalone language controls and both theme palettes keep their own styles.
 */

.site-header .nav-wrap {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    column-gap: 24px;
    row-gap: 0;
    min-height: 84px;
    padding-block: 12px;
}

.site-header .brand {
    grid-column: 1;
    grid-row: 1;
    justify-self: start;
    min-width: 44px;
    min-height: 44px;
}

/* Its children occupy the header grid on desktop and the common mobile panel. */
.site-header .header-panel { display: contents; }

/* Reset the former fixed drawer, including its 880px/1160px overrides. */
.site-header .header-panel > .nav {
    position: static;
    inset: auto;
    grid-column: 2;
    grid-row: 1;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: stretch;
    justify-content: center;
    gap: 4px;
    width: 100%;
    min-width: 0;
    max-width: none;
    max-height: none;
    overflow: visible;
    margin: 0;
    padding: 0;
    border: 0;
    color: var(--hk-text-secondary);
    background: transparent;
    box-shadow: none;
    font-size: 14px;
    font-weight: 650;
    line-height: 1.35;
}

.site-header .nav > a:not(.btn) {
    position: relative;
    display: flex;
    flex: 0 1 auto;
    align-items: center;
    justify-content: center;
    min-width: min-content;
    min-height: 44px;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--hk-text-secondary);
    text-align: center;
    text-decoration: none;
    white-space: normal;
}

.site-header .nav > a:not(.btn):hover,
.site-header .nav > a:not(.btn):focus-visible {
    color: var(--hk-text);
    background: var(--hk-surface-hover);
}

.site-header .nav > a[aria-current="page"]:not(.btn),
.site-header .nav > a.active:not(.btn) {
    color: var(--hk-accent);
    background: var(--hk-accent-subtle);
}

/* An absolute marker keeps active links the same size as their neighbours. */
.site-header .nav > a[aria-current="page"]:not(.btn)::after,
.site-header .nav > a.active:not(.btn)::after {
    position: absolute;
    inset: auto 12px 4px;
    display: block;
    width: auto;
    height: 2px;
    margin: 0;
    border-radius: 999px;
    background: var(--hk-accent);
    content: "";
}

.site-header .nav-actions {
    grid-column: 3;
    grid-row: 1;
    justify-self: end;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    min-width: 0;
    margin: 0;
    padding-left: 20px;
    border-left: 1px solid var(--hk-border);
    color: var(--hk-text-secondary);
    font-size: 14px;
    line-height: 1.35;
}

.site-header .header-theme {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

/* The adjacent icon/code identify desktop utilities; their full labels remain
   available to assistive technology and are displayed on the smaller layouts. */
.site-header .header-control-label,
.site-header .language-trigger__label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    margin: -1px;
    padding: 0;
    border: 0;
    clip-path: inset(50%);
    white-space: nowrap;
}

.site-header .theme-switch {
    gap: 2px;
    margin: 0;
    padding: 3px;
    background: var(--hk-bg-alt);
}

.site-header .theme-switch .theme-option {
    min-width: 44px;
    min-height: 44px;
    padding: 10px 11px;
    font-size: 14px;
    font-weight: 650;
    line-height: 1.2;
}

.site-header .nav-actions .theme-option > span { display: inline; }

/* Utilities are quieter than the primary navigation in both palettes. */
.site-header .theme-switch .theme-option[aria-pressed="true"] {
    color: var(--hk-text);
    background: var(--hk-surface-hover);
    border-color: var(--hk-border-strong);
}

.site-header .theme-switch .theme-option:disabled {
    opacity: .6;
    cursor: default;
}

.site-header .header-language {
    position: relative;
    flex: 0 0 auto;
    min-width: 0;
}

.site-header .language-trigger {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 44px;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--hk-border);
    border-radius: 10px;
    color: var(--hk-text-secondary);
    background: transparent;
    font-size: 14px;
    font-weight: 650;
    line-height: 1.35;
    list-style: none;
    cursor: pointer;
}

.site-header .language-trigger::-webkit-details-marker { display: none; }
.site-header .language-trigger::marker { content: ""; }

.site-header .language-trigger:hover,
.site-header .header-language[open] > .language-trigger {
    color: var(--hk-text);
    background: var(--hk-surface-hover);
    border-color: var(--hk-border-strong);
}

.site-header .language-trigger__icon,
.site-header .language-trigger__chevron,
.site-header .language-check,
.site-header .nav-toggle > svg {
    display: block;
    flex: 0 0 auto;
    fill: none;
    stroke: currentColor;
}

.site-header .language-trigger__code { white-space: nowrap; }
.site-header .header-language[open] .language-trigger__chevron { transform: rotate(180deg); }

.site-header .header-language > .language-switcher {
    position: absolute;
    z-index: 80;
    top: calc(100% + 10px);
    right: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 2px;
    width: 280px;
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 110px);
    max-height: min(440px, calc(100dvh - 110px));
    overflow-y: auto;
    margin: 0;
    padding: 8px;
    border: 1px solid var(--hk-border);
    border-radius: 12px;
    color: var(--hk-text-secondary);
    background: var(--hk-surface);
    box-shadow: var(--hk-shadow);
    font-size: 14px;
    font-weight: 500;
    letter-spacing: normal;
    line-height: 1.35;
    white-space: normal;
}

.site-header .header-language:not([open]) > .language-switcher { display: none; }

.site-header .header-language .language-switcher > a {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) 18px;
    align-items: center;
    gap: 10px;
    min-width: 0;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid transparent;
    border-radius: 7px;
    color: var(--hk-text-secondary);
    text-decoration: none;
}

.site-header .header-language .language-switcher > a:hover,
.site-header .header-language .language-switcher > a:focus-visible {
    color: var(--hk-text);
    background: var(--hk-surface-hover);
}

.site-header .header-language .language-switcher > a.is-active {
    color: var(--hk-text);
    background: var(--hk-accent-subtle);
    border-color: var(--hk-border);
}

.site-header .language-code { font-weight: 750; }
.site-header .language-name { min-width: 0; }
.site-header .language-check { visibility: hidden; }
.site-header .language-switcher__item.is-active .language-check { visibility: visible; }

.site-header .nav-toggle {
    display: none;
    grid-column: 2;
    grid-row: 1;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: auto;
    min-width: 44px;
    height: auto;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--hk-border);
    border-radius: 10px;
    color: var(--hk-text-secondary);
    background: var(--hk-surface);
    font-size: 14px;
    font-weight: 650;
    line-height: 1.35;
    cursor: pointer;
}

.site-header .nav-toggle:hover,
.site-header .nav-toggle[aria-expanded="true"] {
    color: var(--hk-text);
    background: var(--hk-surface-hover);
    border-color: var(--hk-border-strong);
}

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

.site-header :is(.nav > a, .theme-option, .language-trigger, .language-switcher__item, .nav-toggle):focus-visible {
    outline: 2px solid var(--hk-accent);
    outline-offset: 3px;
    box-shadow: none;
}

/* Keep destination headings visible beneath the taller sticky header. */
.site-header ~ main { --hk-navigation-offset: 100px; }
.site-header ~ main[id],
.site-header ~ main > section[id],
.site-header ~ main .jt-section,
.site-header ~ main .jt-source-list details,
.site-header ~ main .release-entry {
    scroll-margin-top: var(--hk-navigation-offset);
}

/* Two clear rows keep all six translated links visible at laptop/tablet sizes. */
@media (min-width: 761px) and (max-width: 1279px) {
    .site-header ~ main { --hk-navigation-offset: 168px; }
    .site-header ~ main .parameter-category,
    .site-header ~ main .parameter-card {
        scroll-margin-top: var(--hk-navigation-offset);
    }

    .site-header .nav-wrap {
        grid-template-columns: auto minmax(0, 1fr);
        min-height: 0;
        padding-block: 0;
    }

    .site-header .nav-actions {
        grid-column: 2;
        min-height: 76px;
        padding-block: 12px;
    }

    .site-header .header-panel > .nav {
        grid-column: 1 / -1;
        grid-row: 2;
        justify-content: space-between;
        min-height: 56px;
        padding-block: 6px;
        border-top: 1px solid var(--hk-border);
    }
}

@media (max-width: 1279px) {
    .site-header .header-control-label,
    .site-header .language-trigger__label {
        position: static;
        width: auto;
        height: auto;
        overflow: visible;
        margin: 0;
        clip-path: none;
        white-space: normal;
    }

    .site-header .header-control-label {
        color: var(--hk-text-secondary);
        font-size: 14px;
        font-weight: 500;
        line-height: 1.35;
    }
}

/* Mobile uses one disclosure for navigation and utilities. Without a working
   controller the panel stays expanded and no unusable toggle is displayed. */
@media (max-width: 760px) {
    .site-header ~ main { --hk-navigation-offset: 88px; }
    .site-header:not([data-nav-ready]) { position: relative; }

    .site-header .nav-wrap {
        grid-template-columns: minmax(0, 1fr) auto;
        column-gap: 16px;
        min-height: 72px;
        padding-block: 0;
    }

    .site-header .brand { min-height: 72px; }

    .site-header[data-nav-ready] .nav-toggle { display: inline-flex; }

    .site-header .header-panel {
        grid-column: 1 / -1;
        grid-row: 2;
        display: flex;
        flex-direction: column;
        gap: 16px;
        width: 100%;
        min-width: 0;
        max-height: none;
        overflow: visible;
        padding: 12px 0 20px;
        border-top: 1px solid var(--hk-border);
    }

    .site-header[data-nav-ready] .header-panel:not(.is-open) { display: none; }

    .site-header[data-nav-ready] .header-panel.is-open {
        max-height: calc(100vh - 72px);
        max-height: calc(100dvh - 72px);
        overflow-y: auto;
        overscroll-behavior: contain;
        scrollbar-gutter: stable;
    }

    .site-header .header-panel > .nav {
        grid-column: auto;
        grid-row: auto;
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        gap: 4px;
        min-height: 0;
        padding: 0;
        border: 0;
    }

    .site-header .nav > a:not(.btn) {
        flex: 0 0 auto;
        justify-content: flex-start;
        min-width: 0;
        padding: 12px;
        text-align: left;
        overflow-wrap: anywhere;
    }

    .site-header .nav > a[aria-current="page"]:not(.btn)::after,
    .site-header .nav > a.active:not(.btn)::after {
        inset: 10px auto 10px 0;
        width: 3px;
        height: auto;
    }

    .site-header .nav-actions {
        grid-column: auto;
        grid-row: auto;
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
        min-height: 0;
        padding: 16px 0 0;
        border-top: 1px solid var(--hk-border);
        border-left: 0;
    }

    .site-header .header-theme {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: 8px;
    }

    .site-header .theme-switch { display: flex; width: 100%; }
    .site-header .theme-switch .theme-option { flex: 1 1 0; }

    .site-header .header-language { width: 100%; }
    .site-header .language-trigger { justify-content: flex-start; }
    .site-header .language-trigger__code { margin-left: auto; }

    /* Expansion participates in panel flow, so all seven links remain reachable. */
    .site-header .header-language > .language-switcher {
        position: static;
        width: 100%;
        max-width: none;
        max-height: none;
        overflow: visible;
        margin-top: 8px;
        background: var(--hk-bg-alt);
        box-shadow: none;
    }
}
