@import '@financial-times/o3-foundation/css/professional.css';

[data-o-header-subnav-dropdown-parent] {
  cursor: default;
  display: inline-block;
  position: relative;
}

.o-header__subnav-dropdown {
  position: fixed;
  transform: translate(-50%, -50%);
  border: 1px solid var(--o3-color-palette-black-10, #E6D9CE);
  background: var(--o3-color-palette-white, #FFF);
  box-shadow: 0 var(--o3-spacing-5xs) var(--o3-spacing-5xs) 0 rgba(0, 0, 0, 0.25);
  z-index: var(--o3-z-message-service-popover, 9999);
  width: 177px;
  padding: var(--o3-spacing-xs) 72px var(--o3-spacing-l) var(--o3-spacing-m);
  display: none;
}

.o-header__subnav-dropdown-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.o-header__subnav-dropdown-item {
  &:not(:last-child) {
    margin-bottom: var(--o3-spacing-l);
  }
}

.o-header__subnav-dropdown-link {
  display: block;
  width: 177px;
  height: 20px;
  color: var(--o3-color-palette-black, #000);
  line-height: var(--o3-type-body-base-line-height);
  font-weight: var(--o3-type-body-base-font-weight);
  font-family: var(--o3-type-body-base-font-family);
  font-size: var(--o3-type-body-base-font-size);
  text-decoration: none;
  transition: text-decoration 0.2s ease;

  @media (hover: hover) and (pointer: fine) {
    &:hover {
      text-decoration: underline;
      color: var(--o3-color-palette-black, #000);
    }
  }
}

[data-o-header-subnav-dropdown-button] {
  background-color: inherit;
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  line-height: inherit;
  &:focus-visible {
    box-shadow: var(--o3-focus-use-case-outline-color);
  }
  cursor: default !important; // On desktop the hover action will open the modal with click doing nothing additional. Therefore the pointer is misleading.
}

@media (hover: none) {
  [data-o-header-subnav-dropdown-parent] {
    -webkit-tap-highlight-color: transparent;
  }

  /*
  * iOS: fix clipping of fixed-position dropdown inside horizontally scrollable subnav.
  * This will cause the subnav items to spill out horitontally so the override is
  * limited to iOS to prevent android widening the layout when items overflow.
  */
  @supports (-webkit-touch-callout: none) {
    .o-header__subnav:has([data-o-header-subnav-dropdown-button][aria-expanded='true']) .o-header__subnav-wrap-outside,
    .o-header__subnav:has([data-o-header-subnav-dropdown-button][aria-expanded='true']) .o-header__subnav-wrap-inside {
      overflow: visible;
    }
  }

  .o-header__subnav-dropdown {
    position: fixed;
    top: var(--o3-spacing-3xs);
    left: var(--o3-spacing-3xs);
    right: var(--o3-spacing-3xs);
    bottom: var(--o3-spacing-3xs);
    width: auto;
    max-width: none;
    height: auto;
    transform: none;
    padding: 0;
    overflow-y: auto;
    box-shadow: 0 var(--o3-spacing-5xs) var(--o3-spacing-s) 0 rgba(0, 0, 0, 0.3);
  }

  .o-header__subnav-dropdown-title,
  .o-header__subnav-dropdown-link {
    font-size: var(--o3-spacing-2xs);
    color: var(--o3-color-palette-black, #000);
    font-family: var(--o3-type-heading-3-font-family);
    line-height: var(--o3-type-heading-3-line-height);
  }

  .o-header__subnav-dropdown-title {
    display: block;
    margin: 64px var(--o3-spacing-xs) 0 var(--o3-spacing-l);
    padding-bottom: var(--o3-spacing-2xs);
    border-bottom: 6px solid var(--o3-color-palette-black, #000);
    padding-left: 2px;
    font-weight: var(--o3-font-weight-semibold);
  }

  .o-header__subnav-dropdown-close {
    display: block;
    position: absolute;
    top: var(--o3-spacing-xs);
    right: var(--o3-spacing-xs);
    width: var(--o3-spacing-xs);
    height: var(--o3-spacing-xs);
    border: none;
    background: transparent;
    padding: 0;
    z-index: 1;
    cursor: pointer;
    
    &-icon {
      display: inline-block;
      width: 100%;
      height: 100%;
      background-color: var(--o3-color-palette-black);
      mask-image: var(--o3-icon-cross);
      mask-repeat: no-repeat;
      mask-size: contain;
    }
  }

  .o-header__subnav-dropdown-list {
    margin: 0 var(--o3-spacing-xs) var(--o3-spacing-xs) var(--o3-spacing-l);
    padding-top: var(--o3-spacing-xs);
    padding-left: 2px;
  }
  
  .o-header__subnav-dropdown-link {
    height: 20px;
    width: 100%;
    display: flex;
    align-items: center;
    padding: 0;
    font-weight: var(--o3-font-weight-regular);
    &:active,
    &:focus,
    &:focus-visible {
      text-decoration: underline;
      color: var(--o3-color-palette-black, #000);
    }
  }
}

@media (hover: hover) and (pointer: fine) {
  .o-header__subnav-dropdown-title,
  .o-header__subnav-dropdown-close {
    display: none;
  }
}
