// Module Tabs
//================================================== //

.tab-container.module-tabs {
  background-color: $module-tabs-bg-color;
  border-bottom: 1px solid $module-tabs-y-border-color;
  border-top: 1px solid $module-tabs-y-border-color;
  font-size: 0;
  height: 38px;
  overflow: hidden;

  &::after,
  &::before {
    background-color: transparent;
    content: '';
    display: inline-block;
    height: 40px;
    pointer-events: none;
    position: absolute;
    top: 0;
    width: 0;
    z-index: 20;
  }

  &::before {
    background-image:
      linear-gradient(to right,
        rgba($module-default-bg-color, 1),
        rgba($module-default-bg-color, 0));
  }

  &::after {
    background-image:
      linear-gradient(to right,
        rgba($module-default-bg-color, 0),
        rgba($module-default-bg-color, 1));
  }

  > * {
    display: inline-block;
    vertical-align: middle;
  }

  [class^='btn'] {
    background-color: $module-tabs-bg-color;
    border: 0;
    color: $module-tabs-inactive-text-color;
    font-size: $ids-size-font-sm;
    min-width: 0;

    > * {
      display: inline-block;
      vertical-align: middle;
    }

    .icon {
      color: $module-tabs-inactive-text-color;
    }

    span {
      color: inherit;
    }

    &:focus {
      box-shadow: none;
    }
  }

  .icon {
    &.app-header {
      left: -5px;
      position: relative;
      top: -8px;

      span:not(.audible) {
        background-color: $module-tabs-inactive-text-color;
      }
    }
  }

  .tab-list-container {
    display: inline-block;
    overflow-x: auto;
    overflow-y: hidden;
    position: relative;
    -ms-overflow-style: none;
    scrollbar-width: none;
    width: calc(100% - 1px);

    .tab-list {
      height: inherit;
      overflow: scroll;
      display: inline-block;
      white-space: nowrap;
      -ms-overflow-style: none;
      scrollbar-width: none;

      &.has-arrange-placeholder {
        .tab:hover {
          background-color: $module-tabs-bg-color;
        }
      }

      .tab {
        position: relative;
      }

      .tab {
        &.is-focused::before {
          content: '';
          position: absolute;
          inset: 0;
          border: 1px solid $ids-color-palette-azure-70;
          pointer-events: none;
          z-index: 1;
          display: block !important;
          height: auto;
        }

        &.application-menu-trigger {
          background-color: $module-tabs-bg-color;
          border-inline-end: 1px solid $module-tabs-y-border-color;
          position: fixed;
          max-height: 38px;
          min-height: 37px;
          z-index: 25;

          ~ .tab:nth-child(2) {
            margin-inline-start: 88px;
          }

          &.no-text ~ .tab:nth-child(2) {
            margin-inline-start: 42px;
          }

          &:hover {
            background-color: $module-tabs-hover-bg-color;
          }
        }
      }
    }
  }

  .tab-list-info {
    display: none;
  }

  .tab-list {
    height: 34px;
    overflow: hidden;
    width: calc(100% - 1px); // 1px for the vertical centerer

    &.has-arrange-placeholder {
      .tab:hover {
        background-color: $module-tabs-bg-color;
      }
    }
  }

  &.has-toolbar {
    .tab-list-container {
      + .toolbar {
        border-left: 1px solid $module-tabs-x-border-color;
        float: right;
        text-align: right;
        width: 314px;
      }
    }
  }

  .toolbar-searchfield-wrapper {
    .btn-icon.close {
      .icon.close {
        top: 0;
      }
    }

    &.has-focus.active.has-categories {
      .searchfield.no-animation {
        border-bottom-color: transparent;
        border-top-color: transparent;
      }
    }
  }

  .separator {
    display: none !important;
  }

  .tab {
    @include transition(background-color 500ms cubic-bezier(0.17, 0.04, 0.03, 0.94), border-color 500ms cubic-bezier(0.17, 0.04, 0.03, 0.94));

    color: $module-tabs-inactive-text-color;
    font-size: $ids-size-font-sm;
    overflow: hidden;
    text-align: center;
    z-index: 1;

    &.tab.application-menu-trigger .icon {
      color: $module-tabs-icon-normal-color;
      inset-block: -3px;
      inset-inline: 0;
    }

    &.tab.application-menu-trigger.no-text .icon {
      inset-block-start: 0;
      inset-inline: 1px;
      z-index: 1;
    }

    .icon {
      color: $module-tabs-inactive-text-color;
    }

    &:not(:first-child) {
      border-left: 1px solid $module-tabs-x-border-color;
    }

    &:not(.application-menu-trigger) {
      min-width: 135px;
    }

    a {
      font-size: $ids-size-font-sm;
      font-weight: $ids-number-font-weight-bold;
      margin: 0 auto;
      overflow: hidden;
      padding: 10px;
      text-overflow: ellipsis;
      white-space: nowrap;

      @media (max-width: ($breakpoint-slim - 25)) {
        width: 95px !important;
      }

      @media (min-width: ($breakpoint-phone + 60)) {
        padding: 10px;
      }

      > * {
        display: inline-block;
        vertical-align: middle;
      }

      > span:not(.icon) {
        font-weight: $ids-number-font-weight-bold;
        margin-inline-start: 4px;
        margin-top: -5px;
      }
    }

    &.arrange-dragging.is-touch {
      background-color: $module-tabs-bg-color;
    }

    &:hover {
      background-color: $module-tabs-hover-bg-color;
      color: $module-tabs-hover-text-color;

      &.arrange-dragging.is-touch {
        background-color: $module-tabs-hover-bg-color;
      }
    }

    &.is-selected {
      background-color: $module-tabs-active-bg-color;
      color: $module-tabs-active-text-color;

      > a {
        color: $module-tabs-active-text-color;
      }

      &.arrange-dragging.is-touch {
        background-color: $module-tabs-active-bg-color;
      }
    }

    // Individual Tab Disable
    &.is-disabled {
      background-color: $module-tabs-disabled-bg-color;
      color: $module-tabs-disabled-text-color;

      &:not(:first-child) {
        border-left: 1px solid $module-tabs-disabled-x-border-color;
      }

      &.is-selected {
        background-color: $module-tabs-disabled-bg-color;
        color: $module-tabs-disabled-text-color;
      }

      &:hover {
        background-color: $module-tabs-disabled-bg-color;
        color: $module-tabs-disabled-text-color;
      }
    }

    &.dismissible {
      .icon {
        @include css3(transform, translateY(-50%));

        height: 14px;
        position: absolute;
        right: 6px;
        top: 47%;
      }

      a {
        padding: 10px 35px 10px 10px;
      }

      svg.close {
        color: $module-tabs-inactive-text-color;

        &:hover {
          color: $module-tabs-hover-text-color;
        }
      }
    }

    &.application-menu-trigger {
      a {
        padding: 9px 10px 7px;
      }
    }
  }

  .add-tab-button {
    font-size: $ids-size-font-xl;
    font-weight: $ids-number-font-weight-base;
    height: 34px;
    padding-bottom: 5px;
    padding-top: 1px;
    width: 41px;

    span {
      font-size: $ids-size-font-xl;
      font-weight: $ids-number-font-weight-base;
    }
  }

  .tab-focus-indicator {
    border-radius: 2px;
    z-index: 26;
    position: fixed;

    &.is-selected:not(.is-visible) {
      border-color: transparent;
    }

    &.is-visible {
      border-color: $module-tabs-focus-border-color;
    }
  }

  .tab-more {
    width: 43px;
    height: 40px;

    &.is-focused::before {
      content: '';
      position: absolute;
      inset: 0;
      border: 1px solid $ids-color-palette-azure-70;
      pointer-events: none;
      z-index: 1;
      display: block !important;
      height: calc(100% - 6px);
      top: 1px;
    }
  }

  .tab-more,
  .add-tab-button {
    border-left: 1px solid $module-tabs-x-border-color;
    color: $module-tabs-inactive-text-color;
    font-size: $ids-size-font-sm;
    font-weight: $ids-number-font-weight-bold;
    padding: 6px 7px;
    text-align: center;
    z-index: 1;

    .icon {
      color: $module-tabs-inactive-text-color;
    }

    .more-text {
      font-size: $ids-size-font-sm;
      font-weight: $ids-number-font-weight-bold;

      .count {
        font-weight: $ids-number-font-weight-bold;
      }
    }

    &.is-selected {
      background-color: $module-tabs-active-bg-color;
      color: $module-tabs-active-text-color;

      .icon {
        color: $module-tabs-active-text-color;
      }
    }

    &:hover,
    &.is-open {
      background-color: $module-tabs-hover-bg-color;
      color: $module-tabs-hover-text-color;

      .icon {
        color: $module-tabs-hover-text-color;
      }
    }
  }

  .toolbar {
    margin-bottom: 0;
    overflow: hidden;

    .buttonset {
      height: 34px;
      text-align: right;

      > * {
        margin: 0 5px 0 0;
      }
    }

    .more,
    .more .btn-actions {
      height: 32px;
      margin-inline-start: 1px;
    }

    [class^='btn'],
    .btn-menu:not(.btn):not(.btn-primary):not(.btn-secondary):not(.btn-tertiary) {
      background-color: transparent;
      color: $module-tabs-icon-normal-color;
      height: 34px;

      &:not(.btn-menu) {
        border-color: transparent;
      }

      .icon {
        color: $module-tabs-icon-normal-color;
      }

      span {
        color: inherit;
      }

      &:focus,
      &.is-selected:focus {
        color: $module-tabs-icon-normal-color;

        .icon {
          color: $module-tabs-icon-normal-color;
        }

        &:not(.hide-focus) {
          border-color: transparent;
          box-shadow: none;
        }
      }

      &.is-open {
        span {
          color: inherit;
        }

        .icon {
          color: $module-tabs-icon-hover-color;
        }
      }
    }

    .btn-actions {
      min-height: 32px;
      min-width: 32px;
      width: 32px;
    }
  }

  .toolbar-searchfield-wrapper {
    color: $module-tabs-active-text-color;
    text-align: right;
    width: calc(100% - 5px) !important;

    @media (min-width: $breakpoint-tablet-reduced) {
      width: 274px !important;
    }

    .icon:not(.error) {
      color: $searchfield-icon-color;
    }

    .searchfield {
      background-color: rgba($searchfield-moduletabs-bg-color, 0);
      border-bottom-color: rgba($searchfield-moduletabs-border-color, 0);
      border-top-color: rgba($searchfield-moduletabs-bg-color, 0);
      color: $module-tabs-inactive-text-color;
      height: 40px;
    }

    [class^='btn'] {
      background-color: $searchfield-toolbar-bg-color;

      &.active,
      &.has-focus {
        border-color: $module-tabs-inactive-text-color;
      }
    }

    &.non-collapsible {
      .searchfield {
        background-color: $searchfield-toolbar-bg-color;
        color: $searchfield-text-color;

        @media (max-width: ($breakpoint-phone-to-tablet - 1)) {
          padding-right: 20px;
        }
      }
    }

    &.active {
      .searchfield {
        background-color: $searchfield-toolbar-bg-color;
      }

      .btn {
        border-color: transparent;
      }
    }

    &.has-focus {
      .searchfield {
        color: $searchfield-text-color;

        @media (max-width: ($breakpoint-phone-to-tablet - 1)) {
          padding-right: 34px;
        }
      }

      .icon:not(.error) {
        color: $searchfield-text-color;
      }
    }

    &.has-categories {
      width: 101px;
    }

    .btn:focus {
      border-color: transparent;
    }
  }

  > .toolbar-searchfield-wrapper.active {
    width: calc(100% - 1px);
  }

  // Change the display proposition from block to flex to fix positioning
  &.has-auxiliary {
    display: flex;
    flex-direction: row;

    .tab-list-container {
      display: flex;
      flex-direction: row;

      .tab-list {
        flex: 1;
      }

      .tab-more {
        position: static;
      }

      .add-tab-button {
        position: static;
      }
    }
    
    .tab-list-container + .buttonset {
      height: 40px;

      .btn {
        border-radius: 0;

        &:hover {
          background-color: $module-tabs-hover-bg-color;
          color: $module-tabs-hover-text-color;

          .icon {
            color: $module-tabs-hover-text-color;
          }
        }
      }
    }
  }

  &.has-add-button {
    .tab-list-container {
      .tab-list {
        width: calc(100% - 40px);
      }
    }

    &.has-more-button {
      .tab-list-container {
        .tab-list {
          width: calc(100% - 77px);
        }
      }
    }

    .add-tab-button {
      height: 34px;
      top: 0;

      span:first-child {
        position: relative;
        top: -7px;
      }

      .icon-add.icon {
        top: 2px;
      }
    }
  }

  &.has-app-menu {
    .tab-trigger.application-menu-trigger {
      background-color: $module-tabs-bg-color;
      border-inline-end: 1px solid $module-tabs-y-border-color;
      max-height: 40px;
      min-height: 40px;

      &:hover {
        background-color: $module-tabs-hover-bg-color;
      }
    }

    &.has-more-button {
      .tab-list-container {
        .tab-list {
          width: calc(100% - 37px);

          @media (min-width: ($breakpoint-slim - 25px)) {
            width: calc(100% - 37px);
          } 
        }
      }

      &.has-add-button {
        .tab-list-container {
          .tab-list {
            width: calc(100% - 77px);
  
            @media (min-width: ($breakpoint-slim - 25px)) {
              width: calc(100% - 77px);
            } 
          }
        }
      }
    }

    .tab-list-container {
      width: calc(100% - 78px);
    }

    &.has-toolbar {
      .tab-list-container {
        width: calc(100% - 399px);
      }
    }

    &.has-add-button {
      .tab-list-container {
        .tab-list {
          width: calc(100% - 40px);
        }
      }
    }

    .tab-trigger.no-text + .tab-list-container {
      width: calc(100% - 40px);

      @media (max-width: ($breakpoint-phone-to-tablet - 1)) {
        width: calc(100% - 45px);
      }

      @media (max-width: ($breakpoint-slim - 25)) {
        width: calc(100% - 100px);
      }
    }
  }

  .tab-more {
    display: inline-block;

    &.is-hidden {
      display: none;
    }
  }

  // Change state when the spillover button is necessary
  &.has-more-button {
    &.scrolled-right {
      &::before {
        left: 0;
        width: 40px;
      }

      &.has-app-menu {
        &::before {
          left: 80px;
          width: 40px;
        }

        &.no-text {
          &::before {
            left: 39px;
            width: 40px;
          }
        }
      }
    }

    &.scrolled-left {
      &::after {
        right: 37px;
        width: 40px;

        @media (max-width: $breakpoint-phone-to-tablet) {
          right: 43px;
        }
      }
    }

    .tab-list {
      .tab {
        &.dismissible {
          a {
            padding: 10px 35px 10px 10px;
            text-overflow: ellipsis;
            width: inherit;
          }
        }
      }
    }

    .tab-more {
      right: -4px;
      top: 0;

      .more-text {
        @media (min-width: $breakpoint-phone) {
          display: none;
        }
      }
    }

    &.has-toolbar {
      &.has-add-button {
        .toolbar {
          @media (max-width: $breakpoint-phone-to-tablet) {
            display: none;
          }
        }
      }
    }

    &.has-add-button {
      &.scrolled-left {
        &::after {
          @media (max-width: $breakpoint-phone-to-tablet) {
            right: 80px;
          }
        }
      }

      .tab-more {
        right: 41px;
        top: 0;
      }
    }
  }

  // Entire component is Disabled
  &.is-disabled {
    background-color: $module-tabs-disabled-bg-color;
    border-bottom: 1px solid $module-tabs-disabled-y-border-color;
    border-top: 1px solid $module-tabs-disabled-y-border-color;

    [class^='btn'] {
      background-color: $module-tabs-disabled-bg-color;
      color: $module-tabs-disabled-text-color;

      .icon {
        color: $module-tabs-disabled-text-color;
      }
    }

    .icon {
      color: $module-tabs-disabled-text-color;

      &.app-header {
        span:not(.audible) {
          background-color: $module-tabs-disabled-text-color;
        }
      }
    }

    &.has-toolbar {
      .tab-list-container {
        + .toolbar {
          border-left: 1px solid $module-tabs-disabled-x-border-color;
        }
      }
    }

    .tab {
      color: $module-tabs-disabled-text-color;

      &:not(:first-child) {
        border-left: 1px solid $module-tabs-disabled-x-border-color;
      }

      &.is-selected {
        background-color: $module-tabs-disabled-bg-color;
        color: $module-tabs-disabled-text-color;
      }

      &:hover,
      &.is-focused {
        background-color: $module-tabs-disabled-bg-color;
        color: $module-tabs-disabled-text-color;
      }
    }

    .tab-more {
      border-left: 1px solid $module-tabs-disabled-x-border-color;
      color: $module-tabs-disabled-text-color;

      .icon {
        color: $module-tabs-disabled-text-color;
      }

      &.is-selected {
        background-color: $module-tabs-disabled-bg-color;
        color: $module-tabs-disabled-text-color;

        .icon {
          color: $module-tabs-disabled-text-color;
        }
      }

      &:hover,
      &.is-focused,
      &.is-open {
        background-color: $module-tabs-disabled-bg-color;
        color: $module-tabs-disabled-text-color;

        .icon {
          color: $module-tabs-disabled-text-color;
        }
      }
    }

    .toolbar {
      [class^='btn'],
      .btn-menu:not(.btn):not(.btn-primary):not(.btn-secondary):not(.btn-tertiary) {
        color: $module-tabs-disabled-text-color;
        cursor: default !important;

        &:not(.btn-menu) {
          border-color: $module-tabs-disabled-text-color;
        }

        .icon {
          color: $module-tabs-disabled-text-color;
        }

        &:hover {
          color: $module-tabs-disabled-text-color;

          .icon {
            color: $module-tabs-disabled-text-color;
          }
        }

        &:focus,
        &.is-selected:focus {
          color: $module-tabs-disabled-text-color;

          .icon {
            color: $module-tabs-disabled-text-color;
          }

          &:not(.hide-focus) {
            border-color: transparent;
            box-shadow:
              0 0 0 2px transparent,
              0 0 0 1px $module-tabs-disabled-text-color;
          }
        }

        &.is-open {
          .icon {
            color: $module-tabs-disabled-text-color;
          }
        }
      }
    }

    .toolbar-searchfield-wrapper {
      .icon:not(.error) {
        color: $module-tabs-disabled-text-color;
      }

      .searchfield {
        background-color: rgba($searchfield-moduletabs-disabled-bg-color, 0);
        border-bottom-color: rgba($searchfield-moduletabs-disabled-bg-color, 0);
        border-top-color: rgba($searchfield-moduletabs-disabled-bg-color, 0);
        color: $module-tabs-disabled-text-color;
      }

      &.active {
        .searchfield {
          background-color: rgba($searchfield-moduletabs-disabled-bg-color, 1);
          border-bottom-color: rgba($searchfield-moduletabs-disabled-border-color, 1);
        }
      }

      &.has-focus {
        .searchfield {
          color: $module-tabs-disabled-text-color;
        }

        .icon:not(.error) {
          color: $module-tabs-disabled-text-color;
        }
      }
    }
  }

  .toolbar-searchfield-wrapper.has-categories {
    .searchfield-category-button {
      padding-right: 5px;
    }

    .searchfield {
      border: none;
      border-left: 1px solid $searchfield-toolbar-border-color;

      + .close {
        transform: translateY(50%);
        top: 2px;
      }
    }
  }

  // Overrides soho-personalization <style> injection
  // https://github.com/infor-design/enterprise/issues/6207
  &.is-personalizable {
    .toolbar-searchfield-wrapper {
      > svg.icon:not(.close) {
        fill: transparent !important;
      }
    }
  }
}

// Make the tab-panel-container stretch to the full height of the page-container
.page-container {
  .tab-container.module-tabs {
    + .tab-panel-container {
      height: calc(100% - 40px);
    }
  }
}

.masthead + .tab-container.module-tabs {
  border-top: 1px solid transparent;
}

// RTL Styles
html[dir='rtl'] {
  .tab-container.module-tabs .tab-more {
    width: 40px;
  }

  .tab-container.module-tabs {
    &.has-add-button {
      .add-tab-button {
        left: 0;
        right: auto;
      }
    }

    &.scrolled-left {
      &::after {
        width: 0;
      }

      &::before {
        width: 40px;
        left: 41px;
        top: 2px;
      }
    }

    &.scrolled-right {
      &::before {
        left: 40px;
      }
    }

    &.has-more-button {
      .tab-list {
        .tab {
          &.dismissible {
            a {
              padding: 7px 16px 7px 20px;
            }
          }
        }
      }
    }

   .searchfield-wrapper.has-close-icon-button.has-text .btn-icon.close {
    right: calc(300px - 25%);
   }

    &:not(:first-child) {
      border-right: 1px solid $module-tabs-x-border-color;
    }

    .toolbar-searchfield-wrapper {
      text-align: left;

      .searchfield {
        padding-left: 30px;
      }

      &.has-categories .searchfield {
        border: none;
        border-right: 1px solid $searchfield-toolbar-border-color;
      }
    }

    // Change state when the spillover button is necessary
    &.has-more-button {
      .tab-more {
        left: 0;
        right: auto;

        svg {
          margin-left: -3px;
          margin-top: -3px;
        }
      }

      &.has-add-button {
        .tab-more {
          left: 45px;
          right: auto;
        }

        .add-tab-button {
          left: 0;
          right: auto;
        }
      }
    }

    .icon.app-header {
      left: auto;
      right: -6px;
    }

    .tab.dismissible {
      padding-right: 0;

      .icon {
        left: 5px;
        right: auto;
      }
    }

    .tab-list .tab:hover.dismissible svg.icon.close {
      right: auto;
    }
  }
}

// IE always gets cut off without this.
.ie11 {
  .toolbar-searchfield-wrapper {
    padding-left: 1px;
  }
}

// Firefox has weird padding on the Add Tabs Button and Application Menu Triggers without this bit of code
.is-firefox {
  .tab-container.module-tabs {
    .add-tab-button {
      span:first-child {
        position: relative;
        top: -3px;
      }
    }

    .application-menu-trigger {
      a {
        padding-bottom: 8px;
        padding-top: 8px;
      }
    }

    .tab-list .tab:hover.dismissible svg.icon.close {
      right: 12px;
    }

  }

  .tab-container.module-tabs {
    .toolbar-searchfield-wrapper,
    .toolbar-searchfield-wrapper .searchfield {
      height: 34px;

      &.has-categories {
        height: 38px;
      }
    }
  }
}

@include respond-to(phone) {
  .tab-container.module-tabs {
    .tab.application-menu-trigger {
      min-width: 0;

      a > span:not(.icon) {
        margin-left: 0;
        visibility: hidden;
        width: 0;
      }
    }
  }

 .tab-container.module-tabs .tab-list-container .tab-list .tab.application-menu-trigger ~ .tab:nth-child(2) {
    margin-inline-start: 42px;
  }

  html[dir='rtl'] {
    .tab-container {
      &.module-tabs {
        .toolbar-searchfield-wrapper {
          .searchfield {
            padding-left: 60px;
          }
        }
      }
    }
  }
}

/**
 * targets toolbar searchfield close button inside of
 * a tab container, with variant wrapped in button
 */
.tab-container > .toolbar > .buttonset {
  > .searchfield-wrapper.toolbar-searchfield-wrapper > .btn-icon.close {
    height: 24px; // matches min-height declaration of button.close in input.scss
    top: 50% !important;
    transform: translateY(-50%);
    width: 24px;
  }
}

.layout-embedded {
  .container {
    > .page-container {
      padding: 0 !important;
    }
  }
}

// Classic Hacks
.theme-classic-light,
.theme-classic-dark,
.theme-classic-contrast {
  .tab-container.module-tabs{
    height: 36px;
  }

  .tab-container.module-tabs .tab-list-container .tab-list .tab.application-menu-trigger {
    max-height: 34px;
    min-height: 34px;
    width: 88px;
  }

  .header .toolbar [class^="btn"]:not(.btn-primary).application-menu-trigger {
    top: 0;
  }

  .tab-container.module-tabs .tab.dismissible .icon {
    top: 49%;
  }

  .tab-container.module-tabs .tab-more .icon {
    left: -2px;
    top: 2px;
  }

  .tab-container.module-tabs .tab-list-container .tab-list .tab.application-menu-trigger {
    width: 89px;
  }
}

@include respond-to(phone) {
  .theme-classic-light,
  .theme-classic-dark,
  .theme-classic-contrast {
    .tab-container.module-tabs .tab-list-container .tab-list .tab.application-menu-trigger {
        width: 43px;
    }
  }
}
