/* ==========================================================================
   Header: layout of the landing header, compact header of secondary pages and the
   language dropdown. Loaded on every page right after base.css (tokens, buttons).
   ========================================================================== */

/* ---------- Layout ---------- */

/* < 960 px: row 1 logo · CTA · language, row 2 links. The <nav> stays a real box: it spans
   the whole grid as a subgrid, so its CTA and links land in the parent's rows and columns.
   Row 2 is at least one tap target tall so that, without subgrid, the nav's own row
   (links + CTA) fits below row 1 instead of overlapping the logo.
   Defence in depth: the declarations below also keep the layout intact in engines that drop the
   subgrid value without matching the @supports fallback; minmax(44px, auto) also keeps a 44px tap target. */
.site-header__inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  grid-template-rows: auto minmax(44px, auto);
  grid-template-areas:
    'logo cta lang'
    'links links links';
  align-items: center;
  gap: var(--space-2) var(--space-3);
  padding-block: var(--space-3);
}

.logo {
  position: relative;
  z-index: 1; /* above the nav box, which overlaps the logo cell on mobile */
  grid-area: logo;
  color: var(--color-text);
  font-family: var(--font-display);
  font-size: 1.375rem;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: 0.02em;
  text-decoration: none;
}

.logo:hover {
  color: var(--color-text);
}

.logo__accent {
  color: var(--color-accent);
  font-style: italic;
  font-weight: 500;
  white-space: nowrap;
}

.site-header__inner > .site-nav {
  display: grid;
  grid-row: 1 / -1;
  grid-column: 1 / -1;
  grid-template-rows: subgrid;
  grid-template-columns: subgrid;
  align-items: center;
  /* Used only when the subgrid declarations are dropped (no support): the nav then lays out
     its own single row — links (shrinking, scrollable) · CTA — pinned to its bottom edge,
     i.e. parent row 2. In subgrid mode auto-tracks and content alignment are ignored. */
  grid-auto-columns: minmax(0, 1fr) auto;
  align-self: stretch;
  align-content: end;
  column-gap: var(--space-3);
}

.site-nav__links {
  display: flex;
  /* Rows by area name: resolve to parent rows with subgrid, and to one shared implicit row
     without it. Columns by number: full width / column 2 with subgrid, side by side without. */
  grid-row: links;
  grid-column: 1 / -1;
  gap: var(--space-5);
  overflow-x: auto;
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  scrollbar-width: none;
}

.site-nav .button--small {
  grid-row: cta;
  grid-column: 2;
  justify-self: end;
  padding-inline: var(--space-4);
  font-size: 0.875rem;
  white-space: nowrap;
}

.site-nav__link {
  padding-block: var(--space-2);
  color: var(--color-text);
  text-decoration: none;
}

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

/* Keep focus rings inside the scrollable mobile links row and the dropdown panel. */
.site-nav__link:focus-visible,
.lang-menu__link:focus-visible {
  outline-offset: -3px;
}

/* Explicit fallback for engines without subgrid (e.g. iOS 15 in-app browsers): row 1 logo ·
   language, row 2 the nav as a flex row — links left (scrollable), CTA right. */
@supports not (grid-template-columns: subgrid) {
  @media (max-width: 959.98px) {
    .site-header__inner {
      grid-template-columns: minmax(0, 1fr) auto;
      grid-template-areas:
        'logo lang'
        'nav nav';
    }

    .site-header__inner > .site-nav {
      display: flex;
      grid-area: nav;
      align-items: center;
      justify-content: space-between;
      gap: var(--space-3);
      min-width: 0;
    }

    .site-nav__links {
      flex: 1 1 auto;
      min-width: 0;
    }

    .site-nav .button--small {
      flex: none;
    }
  }
}

/* Narrow phones: logo on one line; smaller logo, gaps and CTA padding so that
   logo · CTA · language fit in row 1 down to 360 px without overlap. */
@media (max-width: 479.98px) {
  .site-header__inner {
    column-gap: var(--space-2);
  }

  .logo {
    font-size: clamp(1rem, 4.4vw, 1.25rem);
    letter-spacing: 0.01em;
    white-space: nowrap;
  }

  .site-nav .button--small {
    padding-inline: var(--space-3);
  }
}

@media (min-width: 768px) {
  .logo {
    font-size: 1.75rem;
  }
}

/* Desktop: logo left; links · CTA · dropdown packed into one right-aligned group. */
@media (min-width: 960px) {
  .site-header__inner {
    display: flex;
    gap: var(--space-5);
    padding-block: var(--space-5);
  }

  .site-header__inner > .site-nav {
    display: flex;
    align-items: center;
    gap: var(--space-6);
    margin-inline-start: auto;
  }

  .site-nav__links {
    gap: var(--space-6);
    overflow: visible;
    font-size: 0.9375rem;
  }

  .site-nav .button--small {
    padding-inline: var(--space-5);
    font-size: 0.9375rem;
  }
}

/* Compact header (privacy policy, 404): logo left, dropdown right, one row at every width. */
.site-header--compact .site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ---------- Language dropdown ---------- */

/* Native <details>: the toggle shows globe · code · chevron, the panel drops below it,
   aligned to its right edge. JS (language-switcher.js) only adds Esc / outside-press / focus-out close. */
.lang-menu {
  position: relative;
  z-index: 2; /* above the nav box, which overlaps the language cell on mobile */
  grid-area: lang;
}

.lang-menu__toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-height: 44px;
  padding-inline: var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  color: var(--color-text);
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  list-style: none;
  cursor: pointer;
  user-select: none;
  transition:
    border-color var(--transition),
    color var(--transition);
}

.lang-menu__toggle::-webkit-details-marker {
  display: none;
}

.lang-menu__toggle:hover,
.lang-menu[open] > .lang-menu__toggle {
  border-color: var(--color-line-strong);
  color: var(--color-accent);
}

.lang-menu__icon {
  flex: none;
}

.lang-menu__chevron {
  flex: none;
  transition: transform var(--transition);
}

.lang-menu[open] .lang-menu__chevron {
  transform: rotate(180deg);
}

.lang-menu__list {
  position: absolute;
  top: calc(100% + var(--space-1));
  right: 0;
  z-index: 20;
  min-width: 11rem;
  margin: 0;
  padding: var(--space-1);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-sm);
  background: var(--color-card);
  box-shadow: var(--shadow-float);
  list-style: none;
}

.lang-menu__link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-height: 44px;
  padding-inline: var(--space-3);
  border-radius: calc(var(--radius-sm) - 2px);
  color: var(--color-text);
  font-size: var(--text-base);
  font-weight: 500;
  text-decoration: none;
}

.lang-menu__link:hover {
  background: var(--color-band);
  color: var(--color-accent);
}

/* Current language: accent colour, bold and a check mark. */
.lang-menu__link[aria-current='page'] {
  color: var(--color-accent);
  font-weight: 700;
}

.lang-menu__link[aria-current='page']::after {
  content: '';
  width: 6px;
  height: 11px;
  margin-inline-end: var(--space-1);
  border: solid currentColor;
  border-width: 0 2px 2px 0;
  transform: translateY(-2px) rotate(45deg);
}

@media (min-width: 960px) {
  .lang-menu__toggle {
    font-size: 0.9375rem;
  }
}
