.o-header {
  position: sticky;
  width: 100%;
  top: 0;
  box-shadow: 0 0.4rem 1rem 0 rgba(0, 0, 0, 0.1);
  background-color: var(--bg-default);
  z-index: 5;
  height: 6rem;
  padding-left: calc((100vw - 100%) / 2);
  border-bottom: var(--border);

  @media print {
    display: none;
  }
}

.o-header__wrapper {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0;

  @media (min-width: #{$breakpoint-md}) {
    justify-content: unset;
  }
}

.o-header__curtain:has(~ .o-header__nav--open) {
  background-color: rgba(0, 0, 0, 0.8);
  inset: 0;
  position: fixed;
  z-index: 2;
}

.o-header__nav {
  align-items: center;
  display: flex;
  justify-content: flex-end;

  @media (min-width: #{$breakpoint-md}) {
    display: block;
  }
}

.o-header__nav nav {
  width: 100%;
  display: none;

  @media (min-width: #{$breakpoint-md}) {
    display: block;
  }

  hr {
    display: none;
  }
}

.o-header__logo {
  display: flex;
  margin: 0.6rem 0;
  position: relative;
  text-decoration: none;
  border-radius: var(--border-radius-m);

  &:hover,
  &:focus {
    background-color: var(--bg-neutral);
  }

  svg {
    width: 14.5rem;
    height: 3.6rem;
    padding: 0.6rem;
    align-self: center;
    aspect-ratio: 145 / 36;
  }
}

.o-header__nav > nav > menu {
  display: flex;
  justify-content: space-between;
  margin: 0;
}

menu > li > menu {
  display: flex;
  flex-direction: row;
  padding-inline-start: 0;
}

.o-header__item > .o-dropdown__button {
  font-weight: bold;
  line-height: 1;

  @media (max-width: #{$breakpoint-md}) {
    flex-direction: row-reverse;
  }
}

.o-header__skip-link {
  opacity: 0;
  position: absolute;
  left: 0;
  padding: 1rem;
  margin: 0.9rem;
  pointer-events: none;
  background-color: var(--bg-neutral);
  border-radius: var(--border-radius-s);
  color: var(--bg-default);
  z-index: 100;

  &:focus {
    opacity: 1;
    pointer-events: auto;
  }
}

.o-dropdown__menu > .o-header__item {
  display: flex;

  a {
    font-weight: 400;
    white-space: nowrap;
    min-width: max-content;

    @media (max-width: #{$breakpoint-md}) {
      flex-direction: row-reverse;
    }
  }

  &--current a {
    font-weight: 700;
    color: var(--link-hovered);
  }
}

.o-header__item {
  list-style: none;
  display: flex;
  align-items: center;

  @media (max-width: #{$breakpoint-md}) {
    display: block;

    &.o-dropdown {
      display: flex;
      flex-direction: column;
      align-items: end;
    }

    .o-dropdown__menu {
      box-shadow: none;
      position: static;
      margin-bottom: 1rem;
      border-radius: 0;
      border: none;
    }
  }

  ul {
    display: flex;
    margin: 0;
  }

  .o-dropdown__button[aria-expanded="true"] + .o-dropdown__menu {
    display: grid;
    justify-items: flex-end;

    @media (min-width: #{$breakpoint-md}) {
      padding: 1rem;
      justify-items: flex-start;

      display: grid;
      grid-auto-flow: row;
      grid-template-rows: auto;
      grid-template-columns: 1fr 1fr 1fr;
      column-gap: 1rem;

      @media (max-width: #{$breakpoint-lg}) {
        grid-template-columns: 1fr 1fr;
      }
    }
  }
}

.o-header__item a {
  display: inline-flex;
  gap: 0.4em;
  padding: 1rem;
  text-decoration: none;
  color: var(--color-body);
  font-weight: 700;
  align-items: center;
  white-space: nowrap;
  line-height: 1;

  &:hover,
  &:focus {
    text-decoration: underline;
    color: var(--link-hovered);
  }
}

.o-nav__menu-button,
.o-nav__close-button {
  display: inline-flex;
  padding: 1rem;
  border: none;
  background: none;
  width: fit-content;
  text-align: right;
  font-weight: 700;
  color: var(--color-body);

  height: fit-content;
  text-decoration: none;

  &:hover,
  &:focus {
    :not(.material-symbols-rounded) {
      text-decoration: underline;
    }
    color: var(--link-hovered);
  }
}

.o-nav__close-button,
.o-nav__menu-button {
  display: flex;

  @media (min-width: #{$breakpoint-md}) {
    display: none;
  }

  > .material-symbols-rounded {
    margin-left: 0.8rem;
    align-self: center;
    text-decoration: none;
  }
}

.o-header__nav--open nav {
  @media (max-width: #{$breakpoint-md}) {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    position: fixed;
    top: 0;
    right: 0;
    width: 70%;
    height: 100%;
    z-index: 4;
    background-color: var(--bg-default);
    padding: 1rem;
    overflow-y: scroll;
    border-left: var(--border);

    > menu {
      margin-top: 4rem;
    }

    ul,
    menu {
      flex-direction: column;
      align-items: flex-end;
      padding-left: 0;
    }

    .o-header__item {
      height: fit-content;
    }

    hr {
      display: block;
      width: 100vw;
      margin: 0;
      margin-right: -1rem;
      border-top: 2px solid grey;
    }
  }
}

body:has(.o-header__nav--open) {
  overflow: hidden;
}

.a-theme-toggle {
  padding: 1rem;
  border: none;
  background: transparent;
  width: fit-content;
  color: var(--color-body);
  transition: color 0.3s ease;
  height: fit-content;

  &:hover {
    color: var(--link-hovered);
  }

  &--desktop {
    display: none;

    @media (min-width: #{$breakpoint-md}) {
      display: inline-flex;
    }
  }

  &--mobile {
    display: inline-flex;

    @media (min-width: #{$breakpoint-md}) {
      display: none;
    }
  }
}

#li-header-news {
  @media (min-width: #{$breakpoint-md}) and (max-width: #{$breakpoint-lg}) {
    display: none;
  }
}
