/*
 * SSPFBA site header and navigation menus: NavbarComponent, NavOverlayMenu, NavMegaMenu and the
 * language and account controls of the header. Registered by those components through
 * getStyleSheets(), so it loads after Bootstrap and before the stylesheet of the application, which
 * can override any rule. Moved from the stylesheet of the application without changes.
 */

:root {
    /* --- SSPFBA: dark overlay/panel background colour --- */
    --sspf-dark-surface: #282a35;
}

/*
 * Site Header + Full-Screen Overlay Mega-Menu
 *
 * Architecture:
 *   - <header> is sticky (z-index 1020) with solid background.
 *   - Overlay panels are children of <body>, NOT of <header>.
 *     This puts them in the root stacking context where header (1020) > overlay (1015).
 *   - Nav items stretch to fill the full header height via align-items:stretch
 *     at every flex level. The selected item's dark background (var(--sspf-dark-surface)) therefore
 *     covers the full header height, connecting seamlessly with the overlay below.
 *   - The overlay uses top:var(--header-height) so it starts just below the header.
 *     The header paints on top of it (higher z-index), leaving only the area below
 *     the header visible, with the selected nav item's dark background as the bridge.
 */

/* ── Header ─────────────────────────────────────────────────────── */
.site-header {
    position: sticky;
    top: 0;
    z-index: 1020;
    /* background-color comes from header { background-color: var(--bs-body-bg) } above */
}

.site-header-bar {
    display: flex;
    align-items: stretch;   /* KEY: all children fill the full header height */
    padding-top: 0;
    padding-bottom: 0;
}

.site-logo {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.site-logo img {
    height: 54px;
    width: auto;
}

/* ── Hamburger toggle (mobile only) ──────────────────────────────── */
.site-toggle {
    display: none;          /* hidden on desktop */
    align-items: center;
    background: none;
    border: none;
    padding: 0 1rem;
    cursor: pointer;
    color: inherit;
}

.site-toggle:focus-visible {
    outline: 2px solid var(--bs-primary);
    outline-offset: -2px;
}

.site-toggle i {
    font-size: 1.75rem;
}

/* ── Nav ─────────────────────────────────────────────────────────── */
.site-nav {
    flex: 1;
    display: flex;
    min-height: 5rem;
    align-items: stretch;
}

.site-nav ul {
    display: flex;
    align-items: stretch;   /* stretch li elements */
    justify-content: center;
    list-style: none;
    margin: 0;
    padding: 0;
    width: 100%;
}

.site-nav-item {
    display: flex;
    align-items: stretch;   /* stretch the link inside */
}

.site-nav-link {
    display: flex;
    align-items: center;    /* center text vertically within the stretched space */
    padding: 0 1.25rem;
    font-weight: 700;
    font-size: 1.2rem;
    white-space: nowrap;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    transition: background-color 0.15s ease;
}

.site-nav-link:hover {
    background-color: rgba(0, 0, 0, 0.15);
    color: inherit;
    text-decoration: none;
}

.site-nav-link::after {
    content: '';
    display: inline-block;
    margin-left: 0.4rem;
    width: 0;
    height: 0;
    border-left: 0.3em solid transparent;
    border-right: 0.3em solid transparent;
    border-top: 0.4em solid currentColor;
    transition: transform 0.2s ease;
}

.site-nav-item.is-open .site-nav-link::after {
    transform: rotate(180deg);
}

/* Active state: dark background bridges with the overlay below (NavOverlayMenu only) */
.site-nav-item[data-overlay].is-open .site-nav-link {
    background-color: var(--sspf-dark-surface);
    color: #c8c8d8;
}

.site-nav-item[data-overlay].is-open .site-nav-link:hover {
    background-color: var(--sspf-dark-surface);
    color: #e0e0e0;
}

/* Mega menu items use same colour as hover when open (no dark bridge needed) */
.site-nav-item.dropdown.is-open .site-nav-link {
    background-color: rgba(0, 0, 0, 0.15);
    color: inherit;
}

.site-nav-separator {
    display: flex;
    align-items: center;
    padding: 0 0.25rem;
    color: rgba(0, 0, 0, 0.25);
    font-weight: 300;
    pointer-events: none;
    user-select: none;
}

.site-nav-separator::before {
    content: '|';
}

/* ── Controls (language + auth) ──────────────────────────────────── */
.site-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

/* ── Mobile (<992px) ─────────────────────────────────────────────── */
@media (max-width: 991.98px) {

    .site-logo {
        padding-left: 0;
    }

    .site-header-bar {
        flex-wrap: wrap;
        align-items: center; /* center in the header row on mobile */
        padding-left: 0;
        padding-right: 0;
        padding-top: 0.25rem;
        padding-bottom: 0.25rem;
    }

    .site-toggle {
        display: flex;       /* show hamburger */
    }

    .site-controls {
        margin-left: auto;   /* push to the right, next to toggle */
        padding-right: 1rem;
    }

    /* Force locale text visible on xs — Bootstrap's d-none hides it below 576px. */
    .site-controls .dropdown-toggle span {
        display: inline !important;
    }

    /* Nav becomes a full-width row below the header bar */
    .site-nav {
        order: 4;
        flex: 0 0 100%;
        flex-direction: column;
        display: none;       /* collapsed by default */
        border-top: 1px solid var(--bs-border-color);
        background-color: var(--bs-body-bg);
        min-height: 4rem;
    }

    .site-nav.is-open {
        display: flex;
    }

    .site-nav ul {
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
    }

    .site-nav-item {
        flex-direction: column;
        align-items: stretch;
    }

    .site-nav-link,
    .site-nav-link:hover {
        padding: 0.75rem 1.25rem;
        border-bottom: 1px solid var(--bs-border-color);
    }

    .site-nav-item:last-child .site-nav-link,
    .site-nav-item:last-child .site-nav-link:hover {
        border-bottom: none;
    }

    /* Dark overlay bridge effect on mobile too */
    .site-nav-item[data-overlay].is-open .site-nav-link {
        background-color: var(--sspf-dark-surface);
        color: #c8c8d8;
    }
}

/* ── Full-screen overlay panel ───────────────────────────────────── */

/* Panels live as children of <body>, not inside <header>.
   In the root stacking context, z-index 1015 < header 1020.        */
.mega-overlay {
    position: fixed;
    top: var(--header-height, 84px); left: 0; right: 0; bottom: 0;
    z-index: 1015;
    display: none;
    flex-direction: column;
    background-color: var(--sspf-dark-surface);
    color: #e0e0e0;
    overflow: hidden;
}

.mega-overlay.is-open {
    display: flex;
}

.mega-overlay-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid #3a3c4a;
    flex-shrink: 0;
}

.mega-overlay-filter {
    flex: 1;
    max-width: 420px;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    border: 1px solid #555;
    background-color: #3a3c4a;
    color: #e0e0e0;
}

.mega-overlay-filter::placeholder { color: #999; }
.mega-overlay-filter:focus { outline: none; border-color: #888; }

.mega-overlay-close {
    margin-left: auto;
    background: none;
    border: none;
    color: #e0e0e0;
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
}

.mega-overlay-close:hover { color: #fff; }

.mega-overlay-body {
    display: grid;
    flex: 1;
    overflow-y: auto;
    padding: 2rem 3rem;
    column-gap: 2rem;
    row-gap: 2rem;
    align-content: start;
}

.mega-overlay--cols-2 .mega-overlay-body { grid-template-columns: repeat(2, 1fr); }
.mega-overlay--cols-3 .mega-overlay-body { grid-template-columns: repeat(3, 1fr); }
.mega-overlay--cols-4 .mega-overlay-body { grid-template-columns: repeat(4, 1fr); }

.mega-overlay-col {
    box-sizing: border-box;
    min-width: 0; /* required for text-overflow:ellipsis to work inside grid tracks */
}

/* Level 1 — Section (any element + optional hub-page link) */
.mega-category {
    display: block;
    font-family: var(--bs-body-font-family);
    font-weight: 700;
    font-size: 1.25rem;
    color: #ffe407c7;
    padding: 0;
    margin-top: 1rem;
    margin-bottom: 0;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mega-category:first-child { margin-top: 0; }

.mega-category a {
    display: block;
    color: inherit;
    text-decoration: none;
}

.mega-category a:hover {
    color: #ffe407;
    text-decoration: none;
}

/* Level 2 — Entry (navigable leaf or subsection label) */
.mega-section {
    display: block;
    font-family: var(--bs-body-font-family);
    font-size: 1.125rem;
    color: #ddd;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 300;
    padding: 0.2rem 0;
    text-decoration: none;
}

a.mega-section {
    text-decoration: underline dashed #bbb;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
}

.mega-section a {
    display: block;
    color: inherit;
    text-decoration: none;
}

.mega-section:hover, .mega-section:focus {
    background-color: rgba(255, 255, 255, 0.08);
    color: #fff;
    text-decoration-color: #fff;
}

.mega-section:hover a, .mega-section:focus a {
    color: inherit;
}

/* Level 3 — Items: compact inline links under a MenuEntry */
.mega-items {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    padding: 0.1rem 0 0.2rem;
}

.mega-item {
    font-size: 0.875rem;
    font-weight: 300;
    color: #bbb;
    text-decoration: underline dashed #bbb;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
    white-space: nowrap;
}

.mega-item:hover {
    color: #fff;
    text-decoration-color: #fff;
}

/* ::after pipe separator rendered as display:inline-block so it sits outside
   the text-decoration flow of the <a> and is not underlined. */
.mega-item:not(:last-child)::after {
    content: '|';
    display: inline-block;
    color: #bbb;
    margin-left: 0.3rem;
    margin-right: 0.3rem;
    text-decoration: none;
}

body.mega-overlay-active { overflow: hidden; }

/* ── Language selector dropdown ──────────────────────────────────── */
.flag-icon {
    width: 20px;
    height: 15px;
    margin-right: 0.5rem;
    border-radius: 2px;
}

/* The global  a, li a  rule above adds text-decoration:underline dashed to
   all anchors. Reset it for Bootstrap dropdown items in the header.   */
.site-controls .dropdown-item {
    text-decoration: none;
}

.site-controls .dropdown-item:hover,
.site-controls .dropdown-item:focus {
    text-decoration: none;
}

/* Two-column grid for the language list.
   The grid goes on the inner div, NOT on .dropdown-menu itself —
   Bootstrap controls display:none/block on .dropdown-menu and
   overriding it here would cause the menu to appear on page load. */
.site-controls .dropdown-menu {
    min-width: 220px;
    padding: 0.5rem;
}

.site-controls .dropdown-menu-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0;
}

.site-controls .dropdown-menu-grid li {
    list-style: none;
}

/* ── Bootstrap Dropdown Mega Menu (NavMegaMenu) ───────────────────── */
.dropdown-menu.mega-menu {
    padding: 1em;
    border-radius: 0;
    border-color: #ddd;
    top: 100%;
    position: absolute;
    box-shadow: 0 3px 6px rgba(0, 0, 0, .23);
    display: none;
}

/* Hover trigger (desktop) */
.dropdown:hover .dropdown-menu.mega-menu {
    display: grid;
    gap: 1rem;
}

/* Click/tap trigger via Bootstrap .show (touch devices + JS coordination) */
.dropdown-menu.mega-menu.show {
    display: grid;
    gap: 1rem;
}

.dropdown-menu.mega-menu.mega-menu--cols-2 { grid-template-columns: repeat(2, 1fr); }
.dropdown-menu.mega-menu.mega-menu--cols-3 { grid-template-columns: repeat(3, 1fr); }
.dropdown-menu.mega-menu.mega-menu--cols-4 { grid-template-columns: repeat(4, 1fr); }

/* Override Bootstrap's smaller default font-size for dropdown headers */
.dropdown-menu.mega-menu .dropdown-header {
    font-size: 1.1rem;
    font-weight: bold;
    color: #444;
}

.dropdown-menu.mega-menu .dropdown-item {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 300;
}

/* ── Navigation responsive breakpoints ───────────────────────────── */

/* lg (992–1199px): 4 cols → 2 */
@media (max-width: 1199.98px) {
    .mega-overlay--cols-4 .mega-overlay-body { grid-template-columns: repeat(2, 1fr); }
}

/* md (768–991px): overlay 3 cols → 2; mega-menu scrollable */
@media (max-width: 991.98px) {
    .mega-overlay--cols-3 .mega-overlay-body { grid-template-columns: repeat(2, 1fr); }

    .dropdown-menu.mega-menu {
        max-height: 70vh;
        overflow-y: auto;
    }
}

/* sm / mobile (<768px): overlay 1 col centered; mega-menu single column */
@media (max-width: 767.98px) {
    .mega-overlay-header {
        padding: 0.75rem 1rem;
    }

    .mega-overlay-body {
        grid-template-columns: minmax(0, 540px) !important;
        justify-content: center;
        padding: 1rem 2rem;
    }

    .dropdown-menu.mega-menu {
        width: 80%;
        max-height: 70vh;
        overflow-y: auto;
    }

    .dropdown-menu.mega-menu.mega-menu--cols-2,
    .dropdown-menu.mega-menu.mega-menu--cols-3,
    .dropdown-menu.mega-menu.mega-menu--cols-4 {
        grid-template-columns: 1fr;
    }
}

/* ── Small screens (<576px) ─────────────────────────────────────── */
@media (max-width: 575.98px) {
    /* Site header: smaller logo, hamburger icon and control buttons. */
    .site-logo img {
        height: 40px;
    }

    .site-toggle i {
        font-size: 1.5rem;
    }

    .site-controls .btn,
    .site-controls .nav-link {
        font-size: 0.9rem;
    }

    /* Collapsed mobile nav: the three main items shown when hamburger is open. */
    .site-nav-link {
        font-size: 1.075rem;
    }

    /* Full-page overlay menu: tighter padding and smaller type. */
    .mega-overlay-body {
        padding: 0.75rem 1rem;
    }

    .mega-category {
        font-size: 1.075rem;
    }

    .mega-section {
        font-size: 1rem;
    }

    .mega-item {
        font-size: 0.875rem;
    }
}
