@import '_variables.scss';
@import '_mixins.scss';


:root {
  --toc-dock-offset: 100px;
  --toc-dock-width: 100%;
  --toc-menu-dock-width: 100%;
  --toc-breakpoint: 1024px;
}

body.narrow-menu-open {
  height: calc(var(--all-height-available) - 10px);
  overflow: hidden;
}


// ----------- TOC widget

.webien-toc-widget-toc {
  width: var(--toc-dock-width);

  >.inner {
    opacity: 0;

    &.ready {
      opacity: 1;
      transition: opacity 0.3s ease;
    }
  }

  .chapters {
    display: flex;
    flex-direction: column;
    //background-color: $gray-lighter;
  }

  button {
    @include normalize-button;
    display: block;
    width: 100%;
    padding: 10px;
    background-color: transparent;
    border-bottom: 1px solid $gray-light;
    border-radius: 0;
    white-space: normal;
    text-align: left;
    transition: none;

    &:focus-visible {
      outline: 2px solid $black;
    }

    &.active {
      background-color: $gray-light;
    }

    @include hover {
      background-color: $gray-lighter;
    }

    &.level-1 {
      padding-left: 10px;
    }
    &.level-2 {
      padding-left: 25px;
      font-size: 80%;
    }
    &.level-3 {
      padding-left: 40px;
      font-size: 80%;
    }
    &.level-4 {
      padding-left: 55px;
      font-size: 80%;
    }
    &.level-5 {
      padding-left: 70px;
      font-size: 80%;
    }
    &.level-6 {
      font-size: 80%;
      padding-left: 85px;
    }

  }


  // ----------- Narrow view

  .narrow-view-btns {
    flex-direction: column;
    gap: 16px;
    position: fixed;
    bottom: 20%;
    right: 0;
    align-items: flex-end;
    display: flex;
    z-index: 10;

    button {
      @include normalize-button;
      width: 50px;
      height: 50px;
      border-radius: 0;
      border-top-left-radius: 5px;
      border-bottom-left-radius: 5px;
      background-color: $gray;
      display: grid;
      place-items: center;
      z-index: 10;

      svg {
        width: 28px;
        height: 28px;

        * {
          fill: currentColor !important;
        }

      }
      i {
        color: currentColor;
      }

      &:active,
      &:focus {
        background-color: $gray;
      }

      @include hover {
        background-color: $black;
      }

    }

    // Written with PHP in view.php instead
    /*
    @media (min-width: var(--toc-breakpoint)) {
      display: none;
    }
     */

  }


  .narrow-view {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: translateX(100%);
    pointer-events: none;
    z-index: -1;

    &.active {
      transform: translateX(0);
      pointer-events: all;
      z-index: 9999999;

      .bkg {
        opacity: 1;
      }

      .inner {
        transform: translateX(0);
        overflow: auto;
      }
    }

    .bkg {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      backdrop-filter: blur(5px);
      background-color: rgba($black, 0.3);
      opacity: 0;
      transition: opacity 0.2s ease;
    }

    .inner {
      box-shadow: -2px 0px 10px rgba($black, 0.2);
      position: absolute;
      top: 0;
      right: 0;
      width: 85vw;
      max-width: 300px;
      z-index: 1;
      height: 100%;
      background-color: $white;
      transform: translateX(100%);
      transition: transform 0.2s ease-out;
      transition-delay: 0.1s;

    }

  }


  .standard-view {
    display: none;
  }

  /*
  @media (min-width: var(--toc-breakpoint)) {
    .standard-view {
      display: block;
    }
    .narrow-view {
      display: none;
    }
  }

   */

}


.elementor-widget-theme-post-content {
  .chapter-heading {
    scroll-margin-top: var(--toc-dock-offset);
    cursor: pointer;
    position: relative;


    // Anchor icon
    .anchor {
      display: inline-block;
      margin-left: 10px;
      width: 50px;
      background-repeat: no-repeat;
      background-position: left center;
      background-size: 0.8em;
      opacity: 0;
      transition: opacity 0.2s ease;
    }


    @include hover {
      .anchor {
        opacity: 0.8;;
      }
    }
  }
}


// ----------- Menu widget

.webien-toc-widget-menu {
  width: var(--toc-menu-dock-width);

  >.inner {
    opacity: 0;

    &.ready {
      opacity: 1;
      transition: opacity 0.3s ease;
    }
  }

  .menu-item {

    .inner {
      display: flex;
      align-items: stretch;
    }

    .toggle-childs {
      @include normalize-button;
      padding: 3px 10px;
      background-color: transparent;
      border: none;
      cursor: pointer;
      transition: none;
      display: grid;
      place-items: center;
      border-radius: 0;

      &:focus,
      &:active {
        background-color: transparent;
      }

      @include hover {
        background-color: $gray-lighter;
      }

      svg {
        width: 20px;
        height: auto;
        transition: transform 0.3s ease-out;
        transform: rotate(0deg);

        * {
          fill: currentColor !important;
        }
      }

      i {
        transition: transform 0.3s ease-out;
      }

      &.open {
        svg, i {
          transform: rotate(180deg);
        }
      }

    }

    a {
      //color: inherit;
      padding: 3px 10px;
      display: flex;
      align-items: center;
      flex-grow: 1;


      &.current-menu-item,
      &:focus,
      &:active {
        background-color: inherit;
      }


      @include hover {
        background-color: rgba($black, 0.05);
      }


    }


    .sub-menu {
      display: none;

      &.open {
        display: flex;
        flex-direction: column;
      }


      a {
        padding-left: 20px;
      }
    }

  }

  // ----------- External menu

  .external-menu {
    margin-top: 30px;
    padding-top: 30px;
    border-top: 1px solid $gray-light;

  }


}




.sticky-wrapper {
  position: relative;
  width: 100%;

  .stuck {
    position: fixed;
    top: 100px;
    max-height: 100vh;
    transition: top 0.5s ease;
  }

}