/**
 * @file
 * Nav Primary.
 */

@import "../../base/variables.pcss.css";

.primary-nav__menu {
  flex-wrap: wrap;
  list-style: none;
}

.primary-nav__menu-item {
  margin-block-end: var(--sp0-5);

  &:last-child {
    margin-block-end: 0;
  }

  &.primary-nav__menu-item--has-children {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;

    & .primary-nav__menu-link--link,
    & .primary-nav__menu-link--nolink {
      /* Ensure that long text doesn't make the mobile expand button wrap. */
      flex-basis: calc(100% - var(--sp3));
    }
  }
}

.primary-nav__menu-link {
  flex-grow: 1;
  text-decoration: none;
  color: var(--color--gray-0);
  font-size: 28px;
  font-weight: bold;
  line-height: var(--sp2);

  &:hover {
    color: inherit;
  }

  &:focus {
    outline: auto 2px var(--color--blue-50);
    outline-offset: 2px;
  }
}

.primary-nav__menu-link--nolink {
  padding-block: var(--sp0-5);
  padding-inline-start: 0;
  padding-inline-end: 0;
  color: var(--color--gray-20);
  font-weight: normal;
}

.primary-nav__menu-link--button {
  position: relative;
  padding-block: 0;
  padding-inline-start: 0;
  padding-inline-end: 0;
  cursor: pointer;
  text-align: start;
  border: 0;
  background: transparent;

  /* Plus icon for mobile navigation. */
  &.primary-nav__menu-link--has-children {
    padding-inline-end: var(--sp3); /* Ensure text does not overlap icon. */

    &:before,
    &:after {
      position: absolute;
      inset-inline-end: 9px;
      inset-block-start: calc(var(--sp0-5) + 17px); /* Visually align button with menu link text. */
      width: 18px;
      height: 0;
      content: "";
      /* Intentionally not using CSS logical properties. */
      border-top: solid 3px var(--color--blue-50);
    }

    &:after {
      transition: opacity 0.2s;
      transform: rotate(90deg);
    }

    &[aria-expanded="true"]:after {
      opacity: 0;
    }
  }
}

.primary-nav__menu-link-inner {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding-block: var(--sp0-5);
  padding-inline-start: 0;
  padding-inline-end: 0;

  &:after {
    position: absolute;
    inset-block-end: 0;
    inset-inline-start: 0;
    width: 100%;
    height: 0;
    content: "";
    transition: transform 0.2s;
    transform: scaleX(0);
    transform-origin: left;
    /* Intentionally not using CSS logical properties. */
    border-top: solid 5px var(--color--blue-50);
  }

  &:after {
    @nest .primary-nav__menu-link:hover & {
      transform: scaleX(1);
    }
  }
}

/*
  Top level specific styles.
*/
.primary-nav__menu--level-1 {
  margin-block: 0;
  margin-inline-start: 0;
  margin-inline-end: 0;
  padding-block: 0;
  padding-inline-start: 0;
  padding-inline-end: 0;
}

.primary-nav__menu-link--level-1 {
  position: relative;
  display: flex;
  letter-spacing: -1px;
}

/*
  Secondary menu specific styles.
*/
.primary-nav__menu--level-2 {
  visibility: hidden;
  overflow: hidden;
  flex-basis: 100%;
  max-height: 0;
  margin-block: 0;
  margin-inline-start: calc(-1 * var(--sp));
  padding-inline-start: var(--sp2-5);
  transition: opacity 0.2s, visibility 0.2s, max-height 0.2s;
  opacity: 0;
  border-inline-start: solid var(--sp) var(--color--blue-50);

  &.is-active-menu-parent {
    visibility: visible;
    max-height: none;
    margin-block-start: var(--sp1-5);
    opacity: 1;
  }

  @media (--md) {
    margin-inline-start: calc(-1 * var(--sp3));
    padding-inline-start: var(--sp3);
  }
}

/*
 * Olivero doesn't officially support nested tertiary submenus, but this
 * ensures that it doesn't break all the way.
 *
 * @see https://www.drupal.org/project/drupal/issues/3221399
 */
.primary-nav__menu--level-2 .primary-nav__menu-item--has-children {
  display: block;
}

.primary-nav__menu-link--level-2 {
  font-size: 16px;
  font-weight: normal;
  line-height: var(--sp);
}

html:not(.js) {
  & .primary-nav__menu--level-2 {
    visibility: visible;
    max-height: none;
    opacity: 1;
  }
}

[dir="rtl"] {
  & .primary-nav__menu-link-inner {
    &:after {
      transform-origin: right;
    }
  }
}
