@use '../main';
@use '../global/scss/themes/all';
@use '../global/scss/tools' as nsw;

$content-width: 768px;
$nav-width: 300px;
$header-height: 151px;

.nsw-palette {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr 1fr;
  gap: 0 0;
  grid-template-areas:
    '. . . . . . . . . . . .'
    '. . . . . . . . . . . .'
    '. . . . . . . . . . . .'
    '. . . . . . . . . . . .';

  font-size: var(--nsw-font-size-xxs-desktop);
  color: var(--nsw-text-light);
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;

  > div {
    padding: nsw.rem(8px);
    white-space: normal;
    overflow-wrap: normal; 
  }
}

.nsw-theme-grid {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0;
  background: #f0f0f0;

  @include nsw.breakpoint(nsw.$nsw-desktop-breakpoint) {
    flex-direction: row;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 2rem;
  }

  &-container,
  &-side-stack {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.25rem;
    width: 100%;

    @include nsw.breakpoint(nsw.$nsw-desktop-breakpoint) {
      grid-auto-flow: column;
      grid-template-rows: repeat(4, auto);
      grid-auto-columns: 80px;
      gap: 0;
      /* overflow-x: auto; */
      width: auto;
      max-width: 100%;
    }
  }

  &-swatch {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    font-size: 10px;
    font-weight: 500;
    padding: 0.25rem;
    box-sizing: border-box;
    text-align: left;
    height: 80px;

    @include nsw.breakpoint(nsw.$nsw-desktop-breakpoint) {
      height: 120px;
      width: 80px;
      font-size: 12px;
      padding: 0.5rem;
    }

    span {
      line-height: 1.2;
    }
  }
}

.nsw-docs {
  :not(pre) code {
    padding: nsw.rem(3px);
    background: var(--nsw-grey-04);
    border-radius: var(--nsw-border-radius);
  }

  // fix to offset height of fixed nav to trick anchor links' positioning

  :target::before {

    @include nsw.breakpoint(nsw.$nsw-desktop-breakpoint) {
      content: '';
      display: block;
      height: nsw.rem($header-height);
      margin: nsw.rem(-$header-height) 0 0;
    }
  }

  &--light {
    .nsw-docs__main {
      background-color: var(--nsw-white);
    }
  }

  &__header {
    @include nsw.breakpoint(nsw.$nsw-desktop-breakpoint) {
      height: nsw.rem($header-height);
    }

    &-wrapper {
      @include nsw.breakpoint(nsw.$nsw-desktop-breakpoint) {
        @include nsw.z-index('upper');
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        background-color: var(--nsw-white);
      }
    }

    .nsw-container,
    .nsw-header__container {
      margin: 0;
    }

    @include nsw.breakpoint(nsw.$nsw-desktop-breakpoint) {
      .nsw-container,
      .nsw-header__container {
        max-width: nsw.rem($content-width + $nav-width + 172px);
      }

      .nsw-header__container .nsw-header__inner {
        justify-content: space-between;
        align-items: center;
      }
    }
  }

  &__wrapper {
    @include nsw.breakpoint(nsw.$nsw-desktop-breakpoint) {
      display: flex;
    }
  }

  &__nav {
    @include nsw.breakpoint(nsw.$nsw-desktop-breakpoint) {
      min-width: nsw.rem($nav-width);
      max-width: nsw.rem($nav-width);
    }

    &-wrapper {
      @include nsw.breakpoint(nsw.$nsw-desktop-breakpoint) {
        @include nsw.z-index('upper');
        position: fixed;
        top: nsw.rem($header-height);
        bottom: 0;
        left: 0;
        width: nsw.rem($nav-width);
        overflow-y: auto;
        border-right: 1px solid var(--nsw-grey-04);
        background-color: var(--nsw-white);
        padding: nsw.rem(16px);
      }
    }

    /* stylelint-disable max-nesting-depth */

    .nsw-main-nav__sub-nav a {
      .nsw-brand {
        margin-right: nsw.rem(-8px);
      }
    }

    @include nsw.breakpoint(nsw.$nsw-desktop-breakpoint) {
      .nsw-main-nav {
        background-color: transparent;

        li {
          border-top: 1px solid var(--nsw-grey-04);
        }

        a {
          font-weight: var(--nsw-font-normal);

          &.active {
            font-weight: var(--nsw-font-bold);
          }

          &.current-section {
            font-weight: var(--nsw-font-bold);
            border-left: 2px solid var(--nsw-brand-accent);

            &:hover {
              background-color: var(--nsw-hover);
            }
          }

          &.current {
            background-color: var(--nsw-off-white);
          }
        }

        &__list {
          max-width: none;
          margin: 0;
          flex-direction: column;
          cursor: pointer;

          > li {
            &:first-child {
              border-top: 0;
            }
          }

          > li > a {      
            @include nsw.breakpoint(nsw.$nsw-desktop-breakpoint) {      
              &.active {
                box-shadow: none;
              }
            }
          }
        }

        &__sub-nav {
          position: relative;
          top: auto;
          left: auto;
          max-width: none;
          margin: 0;
          padding: 0;
          box-shadow: none;
          display: none;

          &.active {
            display: block;
            transform: none;
            left: auto;
          }

          &.current-section {
            border-left: 2px solid var(--nsw-brand-accent);
          }

          ul {
            margin: 0;
            flex-direction: column;
          }

          li {
            width: auto;
            margin: 0;
            border-bottom: 0;
          }

          a {
            padding-left: nsw.rem(24px);
            color: var(--nsw-text-dark);
          }
        }
      }
    }

    /* stylelint-enable max-nesting-depth */

  }

  &__main {
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: var(--nsw-off-white);

    .nsw-docs__example {
      padding: nsw.rem(16px);
      background-color: var(--nsw-white);
    }

    &--narrow,
    &--menu {
      .nsw-docs__demo {
        max-width: nsw.rem($content-width + 32px);

        @include nsw.breakpoint(nsw.$nsw-desktop-breakpoint) {
          max-width: nsw.rem($content-width + 104px);
        }
      }
    }

    &--wide {
      .nsw-docs__demo {
        max-width: calc(var(--nsw-container-width) + #{nsw.rem(32px)});

        @include nsw.breakpoint(nsw.$nsw-desktop-breakpoint) {
          max-width: calc(var(--nsw-container-width) + #{nsw.rem(104px)});
        }
      }
    }

    &--menu {
      .nsw-docs__component {
        max-width: nsw.rem(336px);
      }
    }
  }

  &__container {
    max-width: nsw.rem($content-width + 32px);

    @include nsw.breakpoint(nsw.$nsw-desktop-breakpoint) {
      max-width: nsw.rem($content-width + 104px);
    }
  }

  &__intro {
    background-color: var(--nsw-white);

    .nsw-docs__container {
      padding: nsw.rem(24px) nsw.rem(16px);

      @include nsw.breakpoint(nsw.$nsw-desktop-breakpoint) {
        padding: nsw.rem(48px) nsw.rem(52px);
      }
    }

    &--tabs {
      margin-bottom: nsw.rem(-48px);

      .nsw-docs__container {
        padding-bottom: nsw.rem(78px);

        @include nsw.breakpoint(nsw.$nsw-desktop-breakpoint) {
          padding-bottom: nsw.rem(88px);
        }
      }
    }
  }

  &__tabs {
    flex-grow: 1;
  }

  &__content {
    padding: nsw.rem(24px) nsw.rem(16px);
    flex-grow: 1;

    @include nsw.breakpoint(nsw.$nsw-desktop-breakpoint) {
      padding: nsw.rem(48px) nsw.rem(16px) nsw.rem(48px) nsw.rem(52px);
    }
  }

  &__example {
    &--hidden {
      display: none;
    }

    &.nsw-docs__example--dark {
      background-color: var(--nsw-grey-01);
    }
    
    &.nsw-docs__example--light {
      background-color: var(--nsw-grey-04);
    }

    &.nsw-docs__example--brand-dark {
      background-color: var(--nsw-brand-dark);
    }

    &.nsw-docs__example--brand-light {
      background-color: var(--nsw-brand-light);
    }
  }

  &__iframe {
    width: 100%;
    height: 500px;
    background-color: var(--nsw-white);
  }

  &__demo {
    > h3 {
      padding: nsw.rem(16px) 0;

      &:first-child {
        padding-top: 0;
      }

      + p {
        margin-top: nsw.rem(-12px);
        padding-bottom: nsw.rem(16px);
      }

      + h4 {
        padding-top: 0;
      }
    }

    > h4 {
      padding: nsw.rem(16px) 0;
    }
  }

  &__component {
    &::after {
      content: '';
      clear: both;
      display: table;
    }
  }

  &__external {
    padding-top: nsw.rem(8px);
  }

  &__list {
    padding: 0;
    list-style-type: none;

    &--4 {
      column-gap: nsw.rem(36px);
      column-count: 2;

      @include nsw.breakpoint(nsw.$nsw-desktop-breakpoint) {
        column-count: 4;
      }
    }

    &--3 {
      column-gap: nsw.rem(36px);
      column-count: 2;

      @include nsw.breakpoint(nsw.$nsw-desktop-breakpoint) {
        column-count: 3;
      }
    }

    &--2 {
      @include nsw.breakpoint(nsw.$nsw-desktop-breakpoint) {
        column-gap: nsw.rem(36px);
        column-count: 2;
      }
    }

    li {
      margin: 0;
    }

    a {
      position: relative;
      display: inline-block;
      margin: nsw.rem(4px) 0;
    }

    .nsw-brand {
      position: absolute;
      right: nsw.rem(-24px);
    }
  }

  &__box {
    background-color: var(--nsw-grey-03);
    min-height: nsw.rem(56);

    &--large {
      min-height: nsw.rem(150);
    }
  }

  &__section {
    &--white,
    &--light,
    &--dark {
      padding: nsw.rem(8px);
      margin: nsw.rem(8px) nsw.rem(-8px) 0 nsw.rem(-8px);
    }

    &--dark {
      background-color: var(--nsw-grey-01);
    }

    &--light {
      background-color: var(--nsw-grey-04);
    }

    &--spaced {
      @include nsw.component-spacing();
    }
  }

  &__swatch {
    margin: 0 auto;
    background-color: var(--nsw-brand-dark);
    width: nsw.rem(40px);
    height: nsw.rem(40px);
    border-radius: 100%;
  }

  &__loader {
    @include nsw.z-index('upper');
    height: 100%;
    max-height: 100vh;
    overflow-y: auto;
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    background-color: rgba(var(--nsw-white-rgb), 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
  }

  &__guideline {
    img {
      width: 100%;
    }

    &--do,
    &--dont,
    &--heading {
      text-align: center;
      font-weight: var(--nsw-font-bold);
      padding: nsw.rem(8px) 0;

      @include nsw.font-size('md');
    }
    
    &--do {
      color: var(--nsw-palette-green-02);
      background-color: var(--nsw-palette-green-04);
    }
    
    &--dont {
      color: var(--nsw-palette-red-02);
      background-color: var(--nsw-palette-red-04);
    }

    &--heading {
      color: var(--nsw-text-dark);
      background-color: var(--nsw-grey-03);
    }
  }

  .nsw-in-page-alert + h1 {
    margin-top: nsw.rem(24px);

    @include nsw.breakpoint(nsw.$nsw-desktop-breakpoint) {
      margin-top: nsw.rem(48px);
    }
  }

  .nsw-card {
    .nsw-brand {
      margin-left: nsw.rem(8px);
    }
  }
}

.nsw-docs-code {
  position: relative;

  > button {
    margin-top: nsw.rem(24px);
    padding: nsw.rem(2px);
    cursor: pointer;

    &.active {
      .nsw-material-icons {
        transform: rotate(180deg);
      }
    }
  }

  &__content {
    position: relative;
    display: none;
    margin-top: nsw.rem(24px);
    max-width: nsw.rem(872px);

    &.active {
      display: block;
    }

    pre {
      margin: 0;
    }

    .hljs {
      padding: nsw.rem(16px);
      overflow: visible;
      background-color: transparent;
    }

    > button {
      position: absolute;
      top: nsw.rem(16px);
      right: nsw.rem(16px);
    }
  }

  &__copy {
    padding: 0;
    border: 0;
    width: 1px;
    height: 1px;
    opacity: 0;
    position: absolute;
    display: none;
  }

  &__wrapper {
    min-height: nsw.rem(68px);
    max-width: nsw.rem(872px);
    max-height: nsw.rem(400px);
    overflow: auto;
    background-color: var(--nsw-white);
  }
}

.nsw-docs-tabs {
  >.nsw-tabs__list-wrapper {
    background-color: transparent;
    padding: 0 nsw.rem(16px);

    @include nsw.breakpoint(nsw.$nsw-desktop-breakpoint) {
      padding: 0 nsw.rem(52px);
    }
  }

  >.nsw-tabs__content {
    padding: 0;
    border-bottom: 0;
    border-color: var(--nsw-white);

    &:focus {
      outline: none;
    }

    .nsw-docs__container,
    .nsw-docs__demo {
      padding: nsw.rem(24px) nsw.rem(16px);

      @include nsw.breakpoint(nsw.$nsw-desktop-breakpoint) {
        padding: nsw.rem(48px) nsw.rem(52px);
      }
    }
  }

  .nsw-docs__external {
    padding: 0 0 nsw.rem(24px) 0;
  }
}

.nsw-docs-footer {
  .nsw-container {
    margin: 0;
    padding: 0 nsw.rem(16px);

    @include nsw.breakpoint(nsw.$nsw-desktop-breakpoint) {
      padding: 0 nsw.rem(52px);
    }
  }

  .nsw-footer__lower {
    padding: nsw.rem(16px) 0;
  }
}

.nsw-docs__version {
  font-weight: var(--nsw-font-normal);
  padding: nsw.rem(2px) nsw.rem(16px);
  border: solid 1px var(--nsw-brand-dark);
  border-radius: nsw.rem(24px);
  color: var(--nsw-brand-dark);
  text-decoration: none;
  display: inline-block;
  margin-left: nsw.rem(16px);
  
  @include nsw.font-size('xs');
}

.nsw-docs__element {
  height: 100%;
}

.nsw-autocomplete {
  .nsw-material-icons {
    font-size: 2.25rem;
  }

  &__item {
    cursor: pointer;
    transition: 0.2s;
    padding-left: 0;
    margin-top: 0;

    &.nsw-autocomplete__no-results {
      padding: 0.5rem 0.75rem;

      @include nsw.media-breakpoint-up(md) {
        padding: 0.75rem 1.125rem;
      }
    }

    > *:first-child,
    > *:last-child {
      margin-top: 0;
    }

    a {
      display: block;
      width: 100%;
      margin: 0;
      padding: 0.5rem 0.75rem;
      font-weight: 400;
      color: var(--nsw-text-dark);

      @include nsw.media-breakpoint-up(md) {
        padding: 0.75rem 1.125rem;
      }
    }
  }

  &__results {
    position: absolute;
    z-index: 5;
    width: 100%;
    left: 0;
    top: calc(100% + 3px);
    transform: translateY(4px);
    background-color: var(--nsw-white);
    box-shadow: var(--nsw-box-shadow);
    border-radius: 0.25em;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0s 0.3s, transform 0.3s cubic-bezier(0.55, 0.055, 0.675, 0.19);
    overflow: hidden;
  }

  &.active {
    .nsw-autocomplete__results {
      opacity: 1;
      visibility: visible;
      transition: opacity 0.3s, transform 0.3s cubic-bezier(0.215, 0.61, 0.355, 1);
      transform: translateY(0);
    }
  }

  &__list {
    list-style: none;
    padding-left: 0;
    max-height: 250px;
    overflow: auto;
  }
}

.nsw-color-swatches-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px); /* stylelint-disable-line property-no-vendor-prefix */
}

.nsw-color-swatches {
  border: 0;
  width: 100%;
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
  align-items: center;
  gap: 0.5rem;
  margin: 16px 0;

  &__palette-selector {
    width: auto;
    white-space: nowrap;
    flex: 0 0 auto; 
  }

  &__list {
    list-style: none;
    margin-top: 0;
    padding: 0;
    display: flex;
    gap: 0.375rem;
    align-items: center;
  }

  &__option {
    &:focus-visible {
      outline: 2px solid var(--nsw-brand-dark);
      outline-offset: 2px;
    }
  }
  
  &__swatch {
    position: relative;
    display: block;
    height: 32px;
    width: 32px;
    border-radius: 50%;
    cursor: pointer;

    &::before {
      content: '';
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 100%;
      height: 100%;
      border: 1px solid rgba(var(--nsw-brand-dark-rgb), 0.1);
      border-radius: inherit;
      pointer-events: none;
      transition: 0.2s;
    }

    &:hover::before {
      border-color: rgba(var(--nsw-brand-dark-rgb), 0.3);
    }
  }

  &__item {
    margin-top: 0;

    &--selected {
      .nsw-color-swatches__swatch::before {
        border-color: rgba(var(--nsw-brand-dark-rgb), 0.8);
        width: calc(100% + 6px);
        height: calc(100% + 6px);
      }
    }
  }

  &__data {
    code {
      background: var(--nsw-grey-04);
      border-radius: var(--nsw-border-radius);
      padding: 0.1875rem;
    }
  }
}

.material-icons-loading .nsw-docs__nav .nsw-material-icons {
  visibility: hidden;
}

.material-icons-loaded .nsw-docs__nav .nsw-material-icons {
  visibility: visible;
}
