/**
 * MLT Menu.
 *
 * Every value a site is likely to change is a custom property, set on
 * .mlt-menu. To retheme on one site, redeclare the ones you need in the
 * theme's own stylesheet:
 *
 *   .mlt-menu {
 *     --mlt-menu-link: #0f2a3c;
 *     --mlt-menu-link-hover: #4f9d3a;
 *     --mlt-menu-cta-bg: #4f9d3a;
 *   }
 *
 * Layout and structure are deliberately not variables.
 */

.mlt-menu {
  /* typography */
  --mlt-menu-font-size: 1rem;
  --mlt-menu-font-weight: 600;
  --mlt-menu-sub-font-size: 0.95rem;

  /* spacing */
  --mlt-menu-gap: 0.35rem;
  --mlt-menu-link-padding-y: 0.65rem;
  --mlt-menu-link-padding-x: 0.75rem;
  --mlt-menu-radius: 6px;

  /* top level colours */
  --mlt-menu-link: #16324a;
  --mlt-menu-link-hover: #0b6bb5;
  --mlt-menu-link-active: #0b6bb5;
  --mlt-menu-link-hover-bg: rgba(0, 0, 0, 0.05);
  --mlt-menu-underline: currentColor;

  /* dropdown */
  --mlt-menu-sub-bg: #ffffff;
  --mlt-menu-sub-link: #16324a;
  --mlt-menu-sub-link-hover: #0b6bb5;
  --mlt-menu-sub-link-hover-bg: rgba(0, 0, 0, 0.05);
  --mlt-menu-sub-border: rgba(0, 0, 0, 0.1);
  --mlt-menu-sub-shadow: 0 10px 30px rgba(0, 0, 0, 0.14);
  --mlt-menu-sub-width: 15rem;

  /* call to action */
  --mlt-menu-cta-bg: #0b6bb5;
  --mlt-menu-cta-bg-hover: #08558f;
  /* Derives the hover shade from whatever background is set, so the block's
     button colour setting only needs one value. Falls back to the line above
     in browsers without color-mix. */
  --mlt-menu-cta-bg-hover: color-mix(in srgb, var(--mlt-menu-cta-bg) 88%, #000);
  --mlt-menu-cta-text: #ffffff;

  /* drawer */
  --mlt-menu-drawer-bg: #ffffff;
  --mlt-menu-drawer-link: #16324a;
  --mlt-menu-drawer-border: rgba(0, 0, 0, 0.1);
  --mlt-menu-drawer-width: min(22rem, 86vw);
  --mlt-menu-backdrop: rgba(0, 0, 0, 0.45);

  /* toggle */
  --mlt-menu-toggle-color: #16324a;

  position: relative;
  display: block;
}

/* Light links, for dark or coloured header backgrounds. */
.mlt-menu--light-text {
  --mlt-menu-link: #ffffff;
  --mlt-menu-link-hover: #ffffff;
  --mlt-menu-link-active: #ffffff;
  --mlt-menu-link-hover-bg: rgba(255, 255, 255, 0.16);
  --mlt-menu-sub-bg: #16324a;
  --mlt-menu-sub-link: #ffffff;
  --mlt-menu-sub-link-hover: #ffffff;
  --mlt-menu-sub-link-hover-bg: rgba(255, 255, 255, 0.14);
  --mlt-menu-sub-border: rgba(255, 255, 255, 0.18);
  --mlt-menu-sub-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  --mlt-menu-cta-bg: #ffffff;
  --mlt-menu-cta-bg-hover: rgba(255, 255, 255, 0.85);
  --mlt-menu-cta-bg-hover: color-mix(in srgb, var(--mlt-menu-cta-bg) 88%, #000);
  --mlt-menu-cta-text: #16324a;
  --mlt-menu-toggle-color: #ffffff;
}

/* ---------------------------------------------------------------- bar ---- */

.mlt-menu__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--mlt-menu-gap);
  margin: 0;
  padding: 0;
  list-style: none;
}

.mlt-menu__item {
  position: relative;
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  align-items: center;
}

.mlt-menu__link {
  display: inline-block;
  padding: var(--mlt-menu-link-padding-y) var(--mlt-menu-link-padding-x);
  color: var(--mlt-menu-link);
  font-size: var(--mlt-menu-font-size);
  font-weight: var(--mlt-menu-font-weight);
  line-height: 1.2;
  text-decoration: none;
  border-radius: var(--mlt-menu-radius);
  transition: color 0.15s ease, background-color 0.15s ease;
}

.mlt-menu__link:hover,
.mlt-menu__link:focus-visible {
  color: var(--mlt-menu-link-hover);
  background-color: var(--mlt-menu-link-hover-bg);
  text-decoration: none;
}

.mlt-menu__item.is-active-trail > .mlt-menu__link {
  color: var(--mlt-menu-link-active);
}

/* Parent items keep the link clickable and put the chevron in its own button,
   so a parent that is also a real page still works. */
.mlt-menu__item--parent > .mlt-menu__link {
  padding-right: 0.25rem;
}

.mlt-menu__sub-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--mlt-menu-link-padding-y) 0.5rem var(--mlt-menu-link-padding-y) 0.15rem;
  margin: 0;
  border: 0;
  background: none;
  color: var(--mlt-menu-link);
  cursor: pointer;
  border-radius: var(--mlt-menu-radius);
  line-height: 1;
}

.mlt-menu__sub-toggle:hover,
.mlt-menu__sub-toggle:focus-visible {
  color: var(--mlt-menu-link-hover);
}

.mlt-menu__chevron {
  transition: transform 0.18s ease;
}

.mlt-menu__item.is-open > .mlt-menu__sub-toggle .mlt-menu__chevron {
  transform: rotate(180deg);
}

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

.mlt-menu__sub {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 950;
  min-width: var(--mlt-menu-sub-width);
  margin: 0;
  padding: 0.4rem;
  list-style: none;
  background: var(--mlt-menu-sub-bg);
  border: 1px solid var(--mlt-menu-sub-border);
  border-radius: var(--mlt-menu-radius);
  box-shadow: var(--mlt-menu-sub-shadow);
  opacity: 0;
  visibility: hidden;
  transform: translateY(6px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
}

.mlt-menu__item.is-open > .mlt-menu__sub {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* Flipped when the dropdown would run off the right edge. */
.mlt-menu__sub--flip {
  left: auto;
  right: 0;
}

.mlt-menu__sub-item {
  margin: 0;
  padding: 0;
  list-style: none;
}

.mlt-menu__sub-link {
  display: block;
  padding: 0.55rem 0.75rem;
  color: var(--mlt-menu-sub-link);
  font-size: var(--mlt-menu-sub-font-size);
  font-weight: 500;
  line-height: 1.3;
  text-decoration: none;
  border-radius: calc(var(--mlt-menu-radius) - 2px);
}

.mlt-menu__sub-link:hover,
.mlt-menu__sub-link:focus-visible {
  color: var(--mlt-menu-sub-link-hover);
  background-color: var(--mlt-menu-sub-link-hover-bg);
  text-decoration: none;
}

.mlt-menu__sub-item.is-active-trail > .mlt-menu__sub-link {
  color: var(--mlt-menu-sub-link-hover);
}

/* ---------------------------------------------------------------- cta ---- */

.mlt-menu__item--cta > .mlt-menu__link,
.mlt-menu__drawer-item--cta > .mlt-menu__drawer-row > .mlt-menu__drawer-link {
  background-color: var(--mlt-menu-cta-bg);
  color: var(--mlt-menu-cta-text);
  padding-left: 1.15rem;
  padding-right: 1.15rem;
}

.mlt-menu__item--cta > .mlt-menu__link:hover,
.mlt-menu__item--cta > .mlt-menu__link:focus-visible,
.mlt-menu__drawer-item--cta > .mlt-menu__drawer-row > .mlt-menu__drawer-link:hover {
  background-color: var(--mlt-menu-cta-bg-hover);
  color: var(--mlt-menu-cta-text);
}

/* ------------------------------------------------------------- toggle ---- */

.mlt-menu__toggle {
  display: none;
  align-items: center;
  gap: 0.5rem;
  width: -moz-fit-content;
  width: fit-content;
  margin-left: auto;
  margin-right: 0;
  padding: 0.6rem 0.75rem;
  border: 0;
  background: none;
  color: var(--mlt-menu-toggle-color);
  font-size: 1rem;
  font-weight: var(--mlt-menu-font-weight);
  cursor: pointer;
  border-radius: var(--mlt-menu-radius);
}

.mlt-menu__burger {
  display: inline-block;
  width: 22px;
  height: 16px;
  position: relative;
}

.mlt-menu__burger span {
  position: absolute;
  left: 0;
  width: 100%;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
}

.mlt-menu__burger span:nth-child(1) { top: 0; }
.mlt-menu__burger span:nth-child(2) { top: 7px; }
.mlt-menu__burger span:nth-child(3) { top: 14px; }

/* --------------------------------------------------- left or right side --- */

/* The button and the drawer are set independently, so the button can sit on
   one side and the panel come in from the other. */

.mlt-menu--toggle-right .mlt-menu__toggle {
  margin-left: auto;
  margin-right: 0;
}

.mlt-menu--toggle-left .mlt-menu__toggle {
  margin-left: 0;
  margin-right: auto;
}

.mlt-menu--drawer-right .mlt-menu__drawer {
  left: auto;
  right: 0;
  transform: translateX(100%);
}

.mlt-menu--drawer-left .mlt-menu__drawer {
  right: auto;
  left: 0;
  transform: translateX(-100%);
}

.mlt-menu--drawer-right .mlt-menu__drawer.is-open,
.mlt-menu--drawer-left .mlt-menu__drawer.is-open {
  transform: translateX(0);
}

/* Close button goes to the outer edge of whichever side the drawer is on. */
.mlt-menu--drawer-right .mlt-menu__drawer-head {
  justify-content: flex-end;
}

.mlt-menu--drawer-left .mlt-menu__drawer-head {
  justify-content: flex-start;
}

/* ------------------------------------------------- light or dark drawer --- */

/* The drawer has its own light/dark choice, separate from the bar, because a
   site can easily have a dark header and a light page behind it. */
.mlt-menu--drawer-dark {
  --mlt-menu-drawer-bg: #12222e;
  --mlt-menu-drawer-link: #f2f6f8;
  --mlt-menu-drawer-border: rgba(255, 255, 255, 0.14);
  --mlt-menu-backdrop: rgba(0, 0, 0, 0.62);
}

.mlt-menu--drawer-dark .mlt-menu__drawer-sub-link {
  opacity: 0.78;
}

/* ------------------------------------------------------------- drawer ---- */

.mlt-menu__backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--mlt-menu-backdrop);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.mlt-menu__backdrop.is-open {
  opacity: 1;
}

.mlt-menu__drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 1001;
  width: var(--mlt-menu-drawer-width);
  padding: 1rem 1rem 2rem;
  background: var(--mlt-menu-drawer-bg);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}

.mlt-menu__drawer.is-open {
  transform: translateX(0);
}

.mlt-menu__drawer-head {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.5rem;
}

.mlt-menu__close {
  padding: 0.5rem;
  border: 0;
  background: none;
  color: var(--mlt-menu-drawer-link);
  cursor: pointer;
  line-height: 1;
}

.mlt-menu__drawer-list,
.mlt-menu__drawer-sub {
  margin: 0;
  padding: 0;
  list-style: none;
}

.mlt-menu__drawer-item {
  border-bottom: 1px solid var(--mlt-menu-drawer-border);
}

.mlt-menu__drawer-row {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
}

.mlt-menu__drawer-link {
  flex: 1;
  display: block;
  padding: 0.9rem 0.25rem;
  color: var(--mlt-menu-drawer-link);
  font-size: 1.05rem;
  font-weight: var(--mlt-menu-font-weight);
  text-decoration: none;
}

.mlt-menu__drawer-item--cta {
  border-bottom: 0;
  margin-top: 1rem;
}

.mlt-menu__drawer-item--cta > .mlt-menu__drawer-row > .mlt-menu__drawer-link {
  border-radius: var(--mlt-menu-radius);
  text-align: center;
  padding: 0.9rem 1rem;
}

.mlt-menu__drawer-sub-toggle {
  flex: 0 0 auto;
  width: 3rem;
  border: 0;
  background: none;
  color: var(--mlt-menu-drawer-link);
  cursor: pointer;
}

.mlt-menu__drawer-item.is-open > .mlt-menu__drawer-row .mlt-menu__chevron {
  transform: rotate(180deg);
}

.mlt-menu__drawer-sub {
  padding: 0 0 0.6rem 0.75rem;
}

.mlt-menu__drawer-sub-link {
  display: block;
  padding: 0.6rem 0.25rem;
  color: var(--mlt-menu-drawer-link);
  font-size: 1rem;
  font-weight: 400;
  text-decoration: none;
  opacity: 0.85;
}

.mlt-menu__drawer-sub-item.is-active-trail > .mlt-menu__drawer-sub-link,
.mlt-menu__drawer-item.is-active-trail > .mlt-menu__drawer-row > .mlt-menu__drawer-link {
  color: var(--mlt-menu-link-hover);
  opacity: 1;
}

/* Stops the page behind the drawer scrolling on iOS. */
body.mlt-menu-drawer-open {
  overflow: hidden;
}

/* ------------------------------------------------ admin contextual links -- */

/* Keeps Drupal's edit pencil above the nav for logged-in editors, including
   when the theme makes its own header sticky. Only affects this block. */
.block-mlt-menu > .contextual,
.block-mlt-menu-block > .contextual {
  z-index: 1100;
}

/* ------------------------------------------------------------ a11y ------- */

.mlt-menu :focus-visible {
  outline: 3px solid currentColor;
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .mlt-menu__sub,
  .mlt-menu__drawer,
  .mlt-menu__backdrop,
  .mlt-menu__chevron,
  .mlt-menu__link {
    transition: none;
  }
}
