@use "00-base/configure" as *;

.ma__sticky-toc {
  margin-bottom: 30px;
  //position: relative // can't have position relative here or the links won't stick for the height of page-content
  font-size: $fonts-medium;

  @media ($bp-small-min) {
    margin-bottom: 60px;
    padding-top: 30px;
    font-size: $fonts-small;
  }

  @media print {
    display: none;
  }

  &__inner {

    @media ($bp-small-min) {
      padding-bottom: 35px;
    }
  }

  &__container {

    @include ma-container;
  }

  &__title {

    @include ma-heading-colored;
    margin-bottom: 0;
    position: relative;
    top: -30px;

    .main-content--two .page-content & {
      margin-bottom: 0;
    }

    &:after {
      display: none;
    }

    @media ($bp-x-small-max) {
      display: none;
    }

    @media ($bp-x-small-min) {
      margin-bottom: 15px;
    }
  }

  &__links {

    @include clearfix;
    position: relative;
    transition: top .3s;
    padding-left: 2rem;
    width: 100%;
    z-index: $z-sticky-content;

    &:before {
      content: "false"; // hook for JS to do the mobile sticky
      display: none;
    }

    @media ($bp-x-small-max) {
      left: 0;
      padding-left: 0;

      &:before {
        content: "true"; // hook for JS to do the mobile sticky
      }

      &[data-sticky='middle'] {
        position: fixed;
          top: 40px;

        .translated-rtl &,
        .translated-ltr & {
          top: 80px;
        }
      }

      &[data-sticky='bottom'] {
        position: absolute;
          top: auto; // height of one line of text
          bottom: -30px; // compensate for bottom margin
      }
    }

    &.is-open span {// popup state + symbol
      transform: rotate(135deg);
    }
  }

  &__toggle-link {

    @include ma-button-reset;
    font-size: $fonts-4xlarge;
    line-height: .65em;
    overflow: hidden;
    position: absolute;
    right: 10px;
    width: 100%;
    height: 100%;
    max-height: 45px;

    z-index: 1;

    span {
      position: absolute;
      top: 10px;
      right: 10px;
      transition: transform .2s ease;
      transform-origin: center center;
    }



    @media ($bp-x-small-min) {
      display: none;
    }
  }

  &__link {
    line-height: 1.2;
    padding-bottom: .35em;
    padding-left: 35px;
    position: relative;

    a {

      @include ma-link-underline;

      @media ($bp-x-small-min) {
        line-height: 1.5;
      }

      svg {
        height: 22px;
        position: absolute;
        left: 0;
        top: 4px;
        transform: rotate(90deg);
        width: 22px;
      }
    }

    @media ($bp-x-small-max) {
      display: none;
      line-height: 1.2;
      padding: 10px 35px 10px 15px;

      &.is-active {
        display: block;

        a {
          border: none;
        }
      }

      .is-open & {
        display: block;
      }

      .is-open & + & {
        border-top-width: 1px;
        border-top-style: solid;
      }
    }
  }
}

//theme

.ma__sticky-toc {

  &__inner {

    @media ($bp-x-small-min) {
      background-color: $c-bg-section;
    }
  }

  &__title {
    background-image: linear-gradient(-60deg, transparent, transparent 35px, $c-primary-alt 35px);
    color: $c-white;
    font-weight: $fonts-bold;
  }

  &__links {

    @media ($bp-x-small-max) {
      background-color: $c-bg-section;
    }
  }

  &__link {

    &:hover {
      cursor: pointer;
    }

    a {

    & > svg {
      fill: $c-primary-alt;

      @media ($bp-x-small-max) {
        display: none;
      }

      :hover {
        border-bottom: none;
      }
    }
  }

    &:hover a {
      border-bottom-color: rgba($c-font-link,.5);
    }

    &:nth-child(n+12) {
      display:  none;

      .open & {
        display: block;
      }

      .is-open & {
        display: block;
      }
    }

    @media ($bp-x-small-max) {

      a {
        font-weight: $fonts-normal;
      }

      &.is-active a {
        color: $c-font-base;
        font-weight: $fonts-bold;
      }

      &.is-active:hover a {
        color: $c-font-base;
        border-bottom-color: transparent;
      }

      & + & {
        border-top-color: $c-bd-divider;
      }

    }
  }

  &__toggle-link {
    color: $c-primary-alt;
  }

  &__footer {
    border-top: 1px solid $c-bd-divider;
    padding: 20px;
    width: 95%;
    margin: 0 auto;

    @media ($bp-x-small-max) {
      display: none;
    }

    button {
      position: relative;
      color: $c-primary;
      font-weight: $fonts-bold;
      background-color: transparent;
      border: none;
      padding: 3px 20px 1px;
      border-bottom: 3px solid transparent;
      transition: border 0.4s ease;

      &::after {
        content: "";
        position: absolute;
        top: 50%;
        transform: translateY(-50%) rotate(45deg);
        right: 0;
        display: inline-block;
        border-right: 4px solid rgba($c-primary, 0.3);
        border-bottom: 4px solid rgba($c-primary, 0.3);
        height: 10px;
        width: 10px;
        transition: all .2s;
        vertical-align: middle;
      }

      &.open::after {
        transform: translateY(-50%) rotate(225deg);
      }
    }
  }

  .ma__sticky-toc__stuck {
    display: none;
    height: 0;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
    transition: height 0.1s ease-out;
    width: 100%;
    background-color: $c-bg-subtle;
    z-index: $z-sticky-content;

    @media ($bp-header-toggle-max) {
       // Sticky toc is over the nav bar.
       $z-sticky-content: 101;
       z-index: $z-sticky-content;
    }
  }
}

.ma__sticky-toc.stuck {

  .ma__sticky-toc__stuck {
    display: block;
    padding-top: 15px;
    height: 75px;
    transition: height 0.2s ease-in;

    @media ($bp-header-toggle-min) {
      height: 70px;
      padding-top: 10px;
    }
  }
}

.ma__sticky-toc__stuck--inner-wrapper {

  @include ma-container;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.ma__sticky-toc__tools {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  margin-left: auto;
  width: 100%;
  max-width: 320px;

  .ma__sticky-toc__sticky-top {
    padding-right: 30px;
    margin-right: 30px;
    border-right: 1px solid $c-bd-divider;

    button {
      border: 4px solid rgba($c-primary, .5);
      height: 47px;
      position: relative;

      svg {
        fill: rgba($c-primary, 0.5);
        transform: rotate(-90deg);
        width: 11px;
        height: 12px;
        margin-bottom: 5px;

        use > svg {// For the bug in Firefox 55>
          transform: rotate(0deg);
        }
      }

      span {
        display: block;
        text-transform: uppercase;
        font-size: $fonts-3xsmall;
        font-weight: $fonts-bold;
        color: $c-primary;
        letter-spacing: $letter-spacing-large;
        margin-top: -4px;
      }
    }
  }

  .ma__sticky-toc__sticky-toggle {
    width: 100%;

    button {

      @include ma-button("","solid",$c-primary);
      font-size: $fonts-medium;
      padding: 10px 0;
      width: 100%;
    }
  }
}

.ma__sticky-toc__secondary-label {
  font-weight: $fonts-bold;
  line-height: 1.2;
  padding: 10px 35px 10px 15px;
  border: 1px solid $c-bd-divider;
  border-width: 1px 0 1px 0;

  @media ($bp-x-small-min) {
    display: none;
  }

  .secondary-label-close {
    display: none;
    position: relative;
    width: 35px;
    height: 35px;
    background-color: $c-primary;
    color: $c-white;

    .sticky-nav-open & {
      display: block;
    }

    span {
      display: block;
      font-size: $fonts-2xlarge;
      font-weight: 200;
      left: 50%;
      line-height: 0;
      position: absolute;
      top: 45%;
      transform: translate(-50%, -50%);
    }
  }
}

.ma__sticky-toc__current-section {

  @include ma-h6;
  width: calc(100% - 365px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: $fonts-bold;
  color: $c-black;
  margin-bottom: 0;
  display: none;

  @media ($bp-medium-min) {
    display: block;
  }
}

.ma__sticky-toc__stuck-menu {
  position: fixed;
  right: -600px;
  width: 100%;
  height: 100%;
  max-width: 550px;
  top: 0;
  z-index: 99;
  background-color: $c-white;
  transition: right 0.3s ease-out;

  overflow: auto;

  @media ($bp-medium-min) {
   padding-top: 35px;
  }

  @media ($bp-header-toggle-min) {
    top: 0;
    padding-top: 75px;
  }

  .ma__sticky-toc__secondary-label {
    display: flex;
    z-index: 99;
    position: fixed;

    align-items: center;
    justify-content: space-between;
    border: 0;
    font-size: $fonts-medium;
    font-weight: $fonts-normal;
    letter-spacing: $letter-spacing-large;
    text-transform: uppercase;
    color: $c-gray-dark;
    background-color: $c-white;
    height: 65px;
    padding: 10px 20px;
    width: 100%;
    max-width: 550px;

    @media ($bp-medium-min) {
      right: -600px;
    }

    &::after {
      content: '';
      position: absolute;
      width: calc(100% - 40px);
      height: 1px;
      bottom: 0;
      background-color: $c-gray-dark;
    }
  }

  .ma__sticky-toc__link {
    display: block;
    padding-right: 20px;
    padding-left: 60px;
    margin: 0; // 20px;

    a {
      font-weight: $fonts-bold;
      font-size: $fonts-medium;
      display: flex;

      svg {
        display: block;
        margin-top: 7px;
        margin-left: 20px;
        z-index: -3;

        @media ($bp-x-small-min) {
          margin: 0 0 0 20px;
        }
      }
    }
  }

  &.sticky-nav-open {
    right: 0;
    z-index: 10000;

    .ma__sticky-toc__secondary-label {

      @media ($bp-medium-min) {
        top:0;
        right: 0;
        transition: right 0.3s ease-out;
        position: fixed;
        z-index: 9999;
      }

      @media ($bp-medium-max) {

        // Fix the toc label covering top 2 toc links.

        & + .ma__sticky-toc__link {
          margin-top: 75px;
        }
      }
    }
  }
}

.sticky-toc-jump-target {

  &::before {
    display: block;
    content: '';
    margin-top: -120px;
    height: 120px;
    visibility: hidden;
    pointer-events: none;

    @media ($bp-header-toggle-min) {
      margin-top: -70px;
      height: 70px;
    }
  }
}

.ma__sticky-toc__overlay {
  display: none;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-color: rgba($c-black, 0.3);
  pointer-events: none;
  z-index: 99;
}

body.stuck {

  .ma__floating-action {
    display: none;
  }
}

html.stickyTOC {
 overflow-y: scroll;
}
