.tabs {
  box-shadow: none;
}

// Tabs
.tabs-wrapper,
.horizontal-tabs ul.horizontal-tabs-list {
  padding: 0 var(--gin-spacing-xs);
  margin-inline: calc(var(--gin-spacing-xs) * -1);

  @include mq(small) {
    padding: 0;
  }
}

// Vertical tabs
.tabs-wrapper:not(.is-horizontal) {
  .tabs {
    .gin--dark-mode & {
      border-color: #8E929C;
    }

    &__tab {
      .gin--dark-mode & {
        background-color: var(--gin-bg-item-hover);
        border-color: #8E929C;
      }
    }
  }
}

.vertical-tabs {
  &__items {
    z-index: inherit;
  }
}

.gin--dark-mode {
  .tabs {
    border-color: var(--gin-border-color-layer2);

    .tabs__tab,
    .tabs__tab.is-active {
      border-color: var(--gin-border-color-layer2);
      background-color: transparent;
    }
  }
}

.tabs__link,
.claro-details__summary,
.horizontal-tabs ul.horizontal-tabs-list li.horizontal-tab-button a {
  color: var(--gin-color-text);
  font-size: var(--gin-font-size);
  font-weight: var(--gin-font-weight-semibold);
  padding-block: calc(var(--gin-spacing-l) - var(--gin-spacing-xxs));

  strong {
    font-weight: inherit;
  }
}

.tabs__link.is-active,
.claro-details__summary[aria-expanded=true],
.horizontal-tabs ul.horizontal-tabs-list li.horizontal-tab-button.selected a {
  font-weight: var(--gin-font-weight-semibold);
}

.is-horizontal .tabs__link,
.horizontal-tabs ul.horizontal-tabs-list li.horizontal-tab-button a {
  &:hover,
  &:focus {
    color: var(--gin-color-primary);
    background: var(--gin-bg-item-hover);
  }
}

.claro-details {
  color: var(--gin-color-text);
  border: 1px solid var(--gin-border-color);
  border-radius: var(--gin-border-m);
  box-shadow: none;
}

.claro-details__summary {
  &::after {
    border-radius: var(--gin-border-m);
  }

  &:hover {
    color: var(--gin-color-primary);
    background-color: var(--gin-bg-item-hover);
  }
}

.is-horizontal .tabs--primary,
.is-horizontal .tabs--secondary,
.horizontal-tabs ul.horizontal-tabs-list {
  position: relative;

  @include mq(small) {
    width: 100%;
    padding-block: .3125rem var(--gin-spacing-l);
    padding-inline: var(--gin-spacing-xs);
    margin-block-end: calc(var(--gin-spacing-xl) * -1);
    overflow-x: auto;

    .gin--edit-form & {
      padding-block-start: .4rem;
    }
  }

  &::after {
    pointer-events: none;
    content: "";
    position: absolute;
    inset-block-end: 0;
    inset-inline-start: 0;
    display: block;
    width: 100%;
    max-width: calc(100% + var(--gin-spacing-xs));
    border-block-end: 1px solid var(--gin-border-color);

    @media (prefers-reduced-motion: no-preference) {
      transition: var(--gin-transition);
    }

    @include mq(small) {
      inset-inline-start: var(--gin-spacing-xs);
      inset-block-end: var(--gin-spacing-l);
      max-width: calc(100% - var(--gin-spacing-m));
    }
  }

  .tabs__tab,
  .horizontal-tab-button {
    position: relative;

    &:focus-within {
      &::after {
        content: "";
        width: calc(100% + var(--gin-spacing-xs));
        height: 4px;
        background: var(--gin-bg-app);
        display: block;
        position: absolute;
        inset-block-end: calc(var(--gin-spacing-xxs) * -1);
        inset-inline-start: calc(var(--gin-spacing-xxs) * -1);
        z-index: 3;
      }
    }
  }

  .horizontal-tab-button {
    &:focus-within {
      &::after {
        background: var(--gin-bg-layer);
      }
    }
  }
}

.horizontal-tabs ul.horizontal-tabs-list {
  &::before {
    z-index: 1;
    background: var(--gin-bg-layer);
  }

  &::after {
    inset-inline-start: var(--gin-spacing-xs);
    max-width: calc(100% - var(--gin-spacing-m));
  }
}

.is-horizontal .tabs--primary,
.is-horizontal .tabs--secondary {
  @include mq(small) {
    margin-inline: 0;
  }
}

.tabs--primary {
  @include mq(small) {
    margin-block-end: 0;
  }
}

.is-horizontal .tabs--primary {
  @include mq(small) {
    &::after {
      border-block-end: 0 none;

      .gin--high-contrast-mode & {
        border-block-end: 1px solid;
      }
    }
  }

  .tabs__tab {
    @include mq($to: small) {
      background-color: var(--gin-bg-layer);
      border-block-end: 1px solid var(--gin-border-color-layer2);

      &[data-original-order="0"] {
        border-block-end: none;
      }
    }

    @include mq(small) {
      &:focus-within::after {
        display: none;
      }
    }
  }

  .tabs__link {
    min-height: var(--gin-spacing-xxl);
    height: 100%;

    @include mq(small) {
      font-size: var(--gin-font-size);
      padding-block: calc(var(--gin-spacing-xs) - 2px);
      padding-inline: var(--gin-spacing-s);
      margin-inline-end: 0.25em;
      min-height: 2rem;
      border-radius: 2rem;
    }

    &.is-active {
      @include mq(small) {
        color: var(--gin-color-primary-active);
        background: var(--gin-color-primary-light);
      }

      &::before {
        display: none;
      }
    }
  }
}

.tabs__trigger {
  svg {
    stroke: var(--gin-color-primary);
  }
}

.is-horizontal .tabs--secondary {
  @include mq(small) {
    margin-block-start: var(--gin-spacing-m);

    &::before {
      width: 100%;
    }
  }

  .tabs__link {
    min-height: 2.5rem;
    padding-block: var(--gin-spacing-xs) var(--gin-spacing-m);
    padding-inline: var(--gin-spacing-m);
    font-size: var(--gin-font-size-s);
    border-radius: var(--gin-border-m) var(--gin-border-m) 0 0;
  }
}

// Horizontal Tabs in Claro style
.horizontal-tabs {
  position: static !important;
  display: flex;
  flex-wrap: wrap;
  width: 100%;
  border: 0 none;
  margin-block-start: calc(var(--gin-spacing-m) * -1);

  ul.horizontal-tabs-list {
    background: none;
    border-inline-end: 0 none;
    border-block-end: 0 none;
    overflow: hidden;

    &:after {
      @include mq(small) {
        inset-inline-start: var(--gin-spacing-xs);
        max-width: calc(100% - var(--gin-spacing-m));
      }
    }

    li.horizontal-tab-button {
      background: none;
      border-inline-end: 0 none;
      border-block-end: 0 none;

      a {
        padding-block: var(--gin-spacing-xs) var(--gin-spacing-m);
        padding-inline: var(--gin-spacing-m);
        font-size: var(--gin-font-size-s);
        border-radius: var(--gin-border-m) var(--gin-border-m) 0 0;

        &::before {
          content: '';
          display: block;
          position: absolute;
        }
      }

      &.selected a {
        color: var(--gin-color-primary);

        &::before {
          z-index: 1;
          border-inline: none;
          border-block-end: 3px solid var(--gin-color-primary);
          inset-block-start: auto;
          inset-block-end: 0;
          inset-inline-start: 0;
          inset-inline-end: 0;
          height: 3px;
          width: 100%;
        }
      }
    }
  }

  // Nested horizontal tabs.
  .horizontal-tabs {
    margin-block-start: var(--gin-spacing-m);
  }

  .horizontal-tabs-panes,
  [data-horizontal-tabs-panes] {
    width: 100%;
  }

  .horizontal-tabs-pane {
    padding: 0;
    box-shadow: none;

    > .details-wrapper {
      margin: 0;

      > .claro-details__description {
        margin-block-start: var(--gin-spacing-m);
      }
    }
  }

  .paragraphs-subform .horizontal-tabs-panes {
    margin-block-start: var(--gin-spacing-s);
  }
}

.claro-details__description {
  max-width: var(--gin-max-line-length);
}

// Icon
.claro-details__summary::before,
.claro-details[open] > .claro-details__summary::before {
  inset-inline-start: 1.125rem;
  background: var(--gin-color-text);
  mask-image: icon('handle');
  mask-repeat: no-repeat;
  mask-position: center center;
  mask-size: 100% 100%;

  @media (forced-colors: active) {
    background-color: buttonBorder;
  }
}

.claro-details__summary::before {
  @media (forced-colors: active) {
    transform: rotate(90deg);
  }
}

.claro-details[open] > .claro-details__summary::before {
  @media (forced-colors: active) {
    transform: rotate(270deg);
    margin-block-start: -6px;
  }
}

.claro-details__summary:hover::before,
.claro-details__summary:hover:focus::before,
.claro-details[open] > .claro-details__summary:hover::before,
.claro-details[open] > .claro-details__summary:focus::before,
.claro-details[open] > .claro-details__summary--accordion::before,
.claro-details[open] > .claro-details__summary--accordion-item::before,
.claro-details[open] > .claro-details__summary--vertical-tabs-item::before {
  background: var(--gin-color-primary);

  @media (forced-colors: active) {
    background-color: linkText;
  }
}

.claro-details {
  &__description {
    color: var(--gin-color-text-light);
  }
}

.claro-details__wrapper--accordion,
.claro-details__wrapper--accordion-item,
.claro-details__wrapper--vertical-tabs-item {
  border-block-start: 1px solid var(--gin-border-color);
  background: var(--gin-bg-app);
}

.gin--dark-mode {
  .claro-details,
  .claro-details__summary--accordion,
  .claro-details__summary--accordion-item,
  .claro-details__summary--vertical-tabs-item {
    background-color: transparent;
  }

  .claro-details {
    border-color: var(--gin-border-color);
  }

  .vertical-tabs {
    &__items {
      background: none;
      border: 0 none;
    }

    &__menu-item.is-selected .vertical-tabs__menu-link {
      background: var(--gin-bg-app);
      border-color: transparent;
    }

    &__menu-link {
      color: var(--gin-color-text);
    }

    &__menu-link-summary {
      color: var(--gin-color-text-light);
    }

    .claro-details__wrapper {
      background: var(--gin-bg-app);
    }
  }
}

.vertical-tabs {
  &__items {
    border-radius: var(--gin-border-m);

    @include mq(large) {
      border-start-start-radius: 0;
    }

    .vertical-tabs__item {
      border-radius: 0;

      @include mq(1360px) {
        border-start-end-radius: var(--gin-border-m);
        border-end-end-radius: var(--gin-border-m);
        border-end-start-radius: var(--gin-border-m);

        ~ .vertical-tabs__item {
          border-start-start-radius: var(--gin-border-m);
        }
      }

      .claro-details__summary {
        @include mq(large) {
          padding-inline-start: var(--gin-spacing-xxl);

          &::before {
            inset-inline-start: var(--gin-spacing-m);
          }
        }
      }

      > .claro-details__wrapper {
        display: inline-block;
        width: 100%;
      }
    }
  }

  &__menu-item-title {
    font-weight: var(--gin-font-weight-bold);
  }

  &__menu-item {
    &::before,
    &::after {
      border-color: var(--gin-border-color);
    }
  }

  &__menu-link,
  &__menu-item.is-selected &__menu-link {
    &:hover {
      color: var(--gin-color-primary);

      &::before {
        background: var(--gin-bg-item-hover);
      }
    }
  }
}

[open] > .claro-details__summary--vertical-tabs-item:not(:focus):not(:active)::after,
[open] > .claro-details__summary--accordion-item:not(:focus):not(:active)::after {
  border-inline-start-width: 5px;
}

@media screen and (min-width: 85em) {
  html.js .vertical-tabs__item {
    overflow: visible;
    float: inline-start;
    width: 100%;
  }
}
