/**
 * @file
 * Navigation in header.
 */

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

.header-nav {
  position: fixed;
  z-index: 5; /* appear above overlay */
  inset-block-start: 0;
  inset-inline-end: 0;
  visibility: hidden;
  overflow: auto;
  /* Ensure that header nav not use additional space and force
     system branding block text to unnecessarily wrap. */
  flex-basis: 0;
  flex-grow: 1; /* Necessary for IE11. */
  width: 100%;
  max-width: var(--mobile-nav-width);
  height: 100%;
  padding-block: 0 var(--sp);
  padding-inline-start: var(--sp);
  padding-inline-end: var(--sp);
  transform: translateX(101%); /* LTR */
  border-block-start: solid var(--color--white) var(--sp3); /* Create room for the "close" button. */
  background-color: var(--color--white);
  box-shadow: 0 0 72px rgba(0, 0, 0, 0.1);

  &.is-active {
    visibility: visible;
  }

  @supports (flex-basis: max-content) {
    flex-basis: max-content;
  }

  @media (--sm) {
    border-top-width: var(--sp5);
  }

  @media (--md) {
    padding-block-end: var(--sp3);
    padding-inline-start: var(--sp3);
    border-top-width: var(--sp7);
  }

  @media (--lg) {
    grid-column: 5 / 14;
  }
}

/*
 * Only apply transition styles when JS is loaded. This
 * works around https://bugs.chromium.org/p/chromium/issues/detail?id=332189
 */
html.js .header-nav {
  transition: visibility 0.2s, transform 0.2s;
}

/* Toolbar is fixed, and tray is vertical. */
body.toolbar-vertical .header-nav {
  border-top-width: calc(var(--toolbar-height) + var(--sp3));

  @media (--sm) {
    border-top-width: calc(var(--toolbar-height) + var(--sp5));
  }
}

/* Toolbar is fixed, and tray is vertical or toolbar is horizontal and tray is closed. */
body.toolbar-vertical .header-nav,
body.toolbar-horizontal.toolbar-fixed .header-nav {
  @media (--md) {
    border-top-width: calc(var(--toolbar-height) + var(--sp7));
  }
}

/* Toolbar is horizontal fixed, and tray is open. */
body.toolbar-horizontal.toolbar-fixed.toolbar-tray-open .header-nav {
  @media (--md) {
    border-top-width: calc(var(--toolbar-height) + var(--toolbar-tray-height) + var(--sp7));
  }
}

body:not(.is-always-mobile-nav) .header-nav {
  @media (--nav) {
    position: static;
    display: flex;
    visibility: visible;
    overflow: visible;
    grid-column: 5 / 15;
    align-items: center;
    justify-content: flex-end;
    max-width: none;
    height: var(--header-height-wide-when-fixed);
    margin-block-start: auto;
    padding-block: 0;
    padding-inline-start: 0;
    padding-inline-end: 0;
    transition: transform 0.2s;
    transform: none;
    border-block-start: 0;
    box-shadow: none;
  }
}

body.is-always-mobile-nav {
  /* Toolbar is fixed, and tray is vertical or toolbar is horizontal and tray is closed. */
  &.toolbar-vertical .header-nav,
  &.toolbar-horizontal.toolbar-fixed .header-nav {
    @media (--nav) {
      border-top-width: calc(var(--toolbar-height) + var(--sp11));
    }
  }

  /* Toolbar is horizontal fixed, and tray is open. */
  &.toolbar-horizontal.toolbar-fixed.toolbar-tray-open .header-nav {
    @media (--nav) {
      border-top-width: calc(var(--toolbar-height) + var(--toolbar-tray-height) + var(--sp11));
    }
  }

  & .header-nav {
    @media (--nav) {
      inset-inline: 100vw auto;
      overflow: auto;
      max-width: calc((7 * (var(--grid-col-width--nav) + var(--grid-gap--nav))));
      padding-inline-end: var(--sp);
      transition: transform 0.2s, visibility 0.2s;
      border-top-width: var(--sp11);

      &.is-active {
        transform: translateX(-100%); /* LTR */
      }
    }

    @media (--grid-max) {
      max-width: calc(100vw - (var(--max-width) + var(--content-left)) + ((7 * (var(--grid-col-width--max) + var(--grid-gap--max)))));
      padding-inline-end: calc(100vw - (var(--max-width) + var(--content-left) - var(--sp)));
    }
  }
}

/* Necessary to override specificity of LTR and RTL compiled selectors. */
[dir] .header-nav.is-active {
  transform: translateX(0);
}

[dir="rtl"] {
  & body.is-always-mobile-nav .header-nav.is-active {
    @media (--nav) {
      transform: translateX(100%);
    }
  }

  & .header-nav {
    transform: translateX(-101%);
  }
}
