@use 'ui-design-system/src/styles/semantic/index' as *;

.ui-tabs-container {
  display: flex;
  position: relative;
  width: 100%;
  
  // Layout variants based on position
  &--position-top,
  &--position-bottom {
    flex-direction: column;
  }
  
  &--position-left,
  &--position-right {
    flex-direction: row;
  }
  
  &--position-bottom {
    flex-direction: column-reverse;
  }
  
  &--position-right {
    flex-direction: row-reverse;
  }
  
  // Tab Navigation
  &__nav {
    position: relative;
    display: flex;
    align-items: center;
    background: $semantic-color-surface;
    border-bottom: $semantic-border-width-1 solid $semantic-color-border-subtle;
    
    .ui-tabs-container--position-bottom & {
      border-bottom: none;
      border-top: $semantic-border-width-1 solid $semantic-color-border-subtle;
    }
    
    .ui-tabs-container--position-left & {
      border-bottom: none;
      border-right: $semantic-border-width-1 solid $semantic-color-border-subtle;
      flex-direction: column;
      align-items: stretch;
    }
    
    .ui-tabs-container--position-right & {
      border-bottom: none;
      border-left: $semantic-border-width-1 solid $semantic-color-border-subtle;
      flex-direction: column;
      align-items: stretch;
    }
  }
  
  &__nav-content {
    display: flex;
    flex: 1;
    overflow-x: auto;
    scrollbar-width: none;
    
    &::-webkit-scrollbar {
      display: none;
    }
    
    .ui-tabs-container--position-left &,
    .ui-tabs-container--position-right & {
      flex-direction: column;
      overflow-x: visible;
      overflow-y: auto;
    }
    
    .ui-tabs-container--scrollable & {
      scroll-behavior: smooth;
    }
    
    &--dragging {
      pointer-events: none;
      
      .ui-tabs-container__tab {
        pointer-events: auto;
      }
    }
  }
  
  // Individual Tab Button
  &__tab {
    display: flex;
    align-items: center;
    gap: $semantic-spacing-component-xs;
    position: relative;
    background: transparent;
    border: none;
    cursor: pointer;
    font-family: map-get($semantic-typography-button-medium, font-family);
    font-size: map-get($semantic-typography-button-medium, font-size);
    font-weight: map-get($semantic-typography-button-medium, font-weight);
    line-height: map-get($semantic-typography-button-medium, line-height);
    color: $semantic-color-text-secondary;
    transition: all $semantic-motion-duration-fast $semantic-motion-easing-ease;
    white-space: nowrap;
    user-select: none;
    
    // Size variants
    .ui-tabs-container--size-sm & {
      padding: $semantic-spacing-component-xs $semantic-spacing-component-sm;
      min-height: $semantic-sizing-button-height-sm;
      font-family: map-get($semantic-typography-button-small, font-family);
      font-size: map-get($semantic-typography-button-small, font-size);
      font-weight: map-get($semantic-typography-button-small, font-weight);
      line-height: map-get($semantic-typography-button-small, line-height);
    }
    
    .ui-tabs-container--size-md & {
      padding: $semantic-spacing-component-sm $semantic-spacing-component-md;
      min-height: $semantic-sizing-button-height-md;
    }
    
    .ui-tabs-container--size-lg & {
      padding: $semantic-spacing-component-md $semantic-spacing-component-lg;
      min-height: $semantic-sizing-button-height-lg;
      font-family: map-get($semantic-typography-button-large, font-family);
      font-size: map-get($semantic-typography-button-large, font-size);
      font-weight: map-get($semantic-typography-button-large, font-weight);
      line-height: map-get($semantic-typography-button-large, line-height);
    }
    
    // Variant styles
    .ui-tabs-container--variant-default & {
      border-bottom: 2px solid transparent;
      
      &--active {
        color: $semantic-color-primary;
        border-bottom-color: $semantic-color-primary;
      }
    }
    
    .ui-tabs-container--variant-filled & {
      border-radius: $semantic-border-radius-sm;
      margin: 0 $semantic-spacing-component-xs;
      
      &--active {
        background: $semantic-color-primary;
        color: $semantic-color-on-primary;
      }
    }
    
    .ui-tabs-container--variant-pills & {
      border-radius: $semantic-border-radius-full;
      margin: 0 $semantic-spacing-component-xs;
      
      &--active {
        background: $semantic-color-primary;
        color: $semantic-color-on-primary;
      }
    }
    
    .ui-tabs-container--variant-underlined & {
      border-radius: 0;
      border-bottom: 2px solid transparent;
      
      &--active {
        color: $semantic-color-primary;
        border-bottom-color: $semantic-color-primary;
        background: $semantic-color-surface-elevated;
      }
    }
    
    // Position-specific styles
    .ui-tabs-container--position-left &,
    .ui-tabs-container--position-right & {
      justify-content: flex-start;
      width: 100%;
      text-align: left;
      
      .ui-tabs-container--variant-default & {
        border-bottom: none;
        border-right: 2px solid transparent;
        
        &--active {
          border-right-color: $semantic-color-primary;
        }
      }
      
      .ui-tabs-container--position-right & {
        .ui-tabs-container--variant-default & {
          border-right: none;
          border-left: 2px solid transparent;
          
          &--active {
            border-left-color: $semantic-color-primary;
          }
        }
      }
    }
    
    // Interactive states
    &:hover:not(&--disabled):not(&--active) {
      color: $semantic-color-text-primary;
      background: $semantic-color-surface-secondary;
    }
    
    &:focus-visible {
      outline: 2px solid $semantic-color-focus;
      outline-offset: 2px;
    }
    
    &--active {
      color: $semantic-color-primary;
      font-weight: $semantic-typography-font-weight-semibold;
      
      .ui-tabs-container--variant-filled &,
      .ui-tabs-container--variant-pills & {
        background: $semantic-color-primary;
        color: $semantic-color-on-primary;
        
        &:hover {
          background: $semantic-color-primary;
        }
      }
    }
    
    &--disabled {
      color: $semantic-color-text-disabled;
      cursor: not-allowed;
      opacity: $semantic-opacity-disabled;
      
      &:hover {
        background: transparent;
        color: $semantic-color-text-disabled;
      }
    }
    
    // Draggable state
    &[draggable="true"]:not(&--disabled) {
      cursor: grab;
      
      &:active {
        cursor: grabbing;
      }
    }
  }
  
  // Tab elements
  &__tab-icon {
    display: flex;
    align-items: center;
    font-size: $semantic-sizing-icon-inline;
  }
  
  &__tab-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  
  &__tab-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: $semantic-sizing-touch-minimum;
    height: $semantic-sizing-touch-minimum;
    border: none;
    background: transparent;
    border-radius: $semantic-border-radius-sm;
    color: inherit;
    cursor: pointer;
    opacity: $semantic-opacity-subtle;
    transition: all $semantic-motion-duration-fast $semantic-motion-easing-ease;
    font-size: $semantic-typography-font-size-lg;
    line-height: 1;
    
    &:hover {
      opacity: 1;
      background: $semantic-color-surface-secondary;
      color: $semantic-color-danger;
    }
    
    &:focus-visible {
      outline: 2px solid $semantic-color-focus;
      outline-offset: 1px;
    }
  }
  
  // Scroll Controls
  &__scroll-controls {
    display: flex;
    gap: $semantic-spacing-component-xs;
    padding: 0 $semantic-spacing-component-sm;
    border-left: $semantic-border-width-1 solid $semantic-color-border-subtle;
    
    .ui-tabs-container--position-left &,
    .ui-tabs-container--position-right & {
      flex-direction: column;
      border-left: none;
      border-top: $semantic-border-width-1 solid $semantic-color-border-subtle;
      padding: $semantic-spacing-component-sm 0;
    }
  }
  
  &__scroll-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: $semantic-sizing-button-height-sm;
    height: $semantic-sizing-button-height-sm;
    border: $semantic-border-width-1 solid $semantic-color-border-primary;
    background: $semantic-color-surface;
    border-radius: $semantic-border-radius-sm;
    color: $semantic-color-text-primary;
    cursor: pointer;
    font-size: $semantic-typography-font-size-md;
    line-height: 1;
    transition: all $semantic-motion-duration-fast $semantic-motion-easing-ease;
    
    &:hover:not(:disabled) {
      background: $semantic-color-surface-secondary;
      border-color: $semantic-color-border-secondary;
    }
    
    &:focus-visible {
      outline: 2px solid $semantic-color-focus;
      outline-offset: 2px;
    }
    
    &:disabled {
      color: $semantic-color-text-disabled;
      border-color: $semantic-color-border-subtle;
      cursor: not-allowed;
      opacity: $semantic-opacity-disabled;
    }
  }
  
  // Content Area
  &__content {
    flex: 1;
    position: relative;
    min-height: 0;
  }
  
  &__panel {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    padding: $semantic-spacing-component-lg;
    background: $semantic-color-surface;
    opacity: 0;
    visibility: hidden;
    transition: opacity $semantic-motion-duration-fast $semantic-motion-easing-ease;
    overflow: auto;
    
    &--active {
      opacity: 1;
      visibility: visible;
      position: relative;
      top: auto;
      left: auto;
      right: auto;
      bottom: auto;
    }
  }
  
  // Responsive adjustments
  @media (max-width: $semantic-breakpoint-md - 1) {
    &__tab {
      .ui-tabs-container--size-lg & {
        padding: $semantic-spacing-component-sm $semantic-spacing-component-md;
        min-height: $semantic-sizing-button-height-md;
        font-family: map-get($semantic-typography-button-medium, font-family);
        font-size: map-get($semantic-typography-button-medium, font-size);
        font-weight: map-get($semantic-typography-button-medium, font-weight);
        line-height: map-get($semantic-typography-button-medium, line-height);
      }
    }
    
    &__panel {
      padding: $semantic-spacing-component-md;
    }
  }
  
  @media (max-width: $semantic-breakpoint-sm - 1) {
    &__tab {
      .ui-tabs-container--size-md &,
      .ui-tabs-container--size-lg & {
        padding: $semantic-spacing-component-xs $semantic-spacing-component-sm;
        min-height: $semantic-sizing-button-height-sm;
        font-family: map-get($semantic-typography-button-small, font-family);
        font-size: map-get($semantic-typography-button-small, font-size);
        font-weight: map-get($semantic-typography-button-small, font-weight);
        line-height: map-get($semantic-typography-button-small, line-height);
      }
    }
    
    &__panel {
      padding: $semantic-spacing-component-sm;
    }
    
    &__scroll-controls {
      padding: 0 $semantic-spacing-component-xs;
    }
  }
}