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

.ui-tree-view {
  // Core Structure
  display: block;
  position: relative;
  
  // Layout & Spacing
  padding: $semantic-spacing-component-sm;
  
  // Visual Design
  background: $semantic-color-surface-primary;
  border: $semantic-border-width-1 solid $semantic-color-border-subtle;
  border-radius: $semantic-border-card-radius;
  
  // Typography
  font-family: map-get($semantic-typography-body-medium, font-family);
  font-size: map-get($semantic-typography-body-medium, font-size);
  font-weight: map-get($semantic-typography-body-medium, font-weight);
  line-height: map-get($semantic-typography-body-medium, line-height);
  color: $semantic-color-text-primary;
  
  // Size Variants
  &--sm {
    padding: $semantic-spacing-component-xs;
    font-family: map-get($semantic-typography-body-small, font-family);
    font-size: map-get($semantic-typography-body-small, font-size);
    font-weight: map-get($semantic-typography-body-small, font-weight);
    line-height: map-get($semantic-typography-body-small, line-height);
  }
  
  &--md {
    padding: $semantic-spacing-component-sm;
    // Typography already set above for medium
  }
  
  &--lg {
    padding: $semantic-spacing-component-md;
    font-family: map-get($semantic-typography-body-large, font-family);
    font-size: map-get($semantic-typography-body-large, font-size);
    font-weight: map-get($semantic-typography-body-large, font-weight);
    line-height: map-get($semantic-typography-body-large, line-height);
  }
  
  // Color Variants
  &--primary {
    border-color: $semantic-color-primary;
    
    .ui-tree-view__node--selected {
      background: $semantic-color-primary;
      color: $semantic-color-on-primary;
    }
  }
  
  &--secondary {
    border-color: $semantic-color-secondary;
    
    .ui-tree-view__node--selected {
      background: $semantic-color-secondary;
      color: $semantic-color-on-secondary;
    }
  }
  
  // Tree Node
  &__node {
    display: flex;
    align-items: center;
    padding: $semantic-spacing-content-line-tight;
    margin-bottom: 2px;
    cursor: pointer;
    border-radius: $semantic-border-radius-sm;
    transition: all $semantic-motion-duration-fast $semantic-motion-easing-ease;
    
    // Node states
    &:hover {
      background: $semantic-color-surface-secondary;
    }
    
    &--selected {
      background: $semantic-color-surface-elevated;
      color: $semantic-color-text-primary;
      font-weight: $semantic-typography-font-weight-medium;
    }
    
    &--disabled {
      opacity: $semantic-opacity-disabled;
      cursor: not-allowed;
      pointer-events: none;
    }
    
    &:focus-visible {
      outline: 2px solid $semantic-color-focus;
      outline-offset: 2px;
    }
  }
  
  // Tree Node Content
  &__node-content {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0; // Allow text truncation
  }
  
  // Expand/Collapse Button
  &__expand-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: $semantic-sizing-touch-minimum;
    height: $semantic-sizing-touch-minimum;
    margin-right: $semantic-spacing-component-xs;
    border: none;
    background: transparent;
    border-radius: $semantic-border-radius-sm;
    cursor: pointer;
    transition: all $semantic-motion-duration-fast $semantic-motion-easing-ease;
    
    &:hover {
      background: $semantic-color-surface-secondary;
    }
    
    &:focus-visible {
      outline: 2px solid $semantic-color-focus;
      outline-offset: 2px;
    }
    
    &--expanded {
      transform: rotate(90deg);
    }
    
    &--leaf {
      cursor: default;
      color: $semantic-color-text-secondary;
      font-size: $semantic-typography-font-size-lg;
      
      &:hover {
        background: transparent;
      }
    }
  }
  
  // Node Icon
  &__node-icon {
    width: $semantic-sizing-icon-inline;
    height: $semantic-sizing-icon-inline;
    margin-right: $semantic-spacing-component-xs;
    color: $semantic-color-text-secondary;
    
    .ui-tree-view__node--selected & {
      color: inherit;
    }
  }
  
  // Node Label
  &__node-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  
  // Children Container
  &__children {
    margin-left: $semantic-spacing-layout-section-sm;
    border-left: $semantic-border-width-1 solid $semantic-color-border-subtle;
    padding-left: $semantic-spacing-component-sm;
    
    &--hidden {
      display: none;
    }
  }
  
  // Loading State
  &__loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: $semantic-spacing-component-md;
    color: $semantic-color-text-secondary;
  }
  
  // Empty State
  &__empty {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: $semantic-spacing-component-lg;
    color: $semantic-color-text-secondary;
    font-style: italic;
  }
  
  // Root level adjustments
  & > .ui-tree-view__node {
    &:first-child {
      margin-top: 0;
    }
    
    &:last-child {
      margin-bottom: 0;
    }
  }
  
  // Responsive Design
  @media (max-width: ($semantic-breakpoint-md - 1)) {
    padding: $semantic-spacing-component-xs;
    
    .ui-tree-view__children {
      margin-left: $semantic-spacing-component-md;
      padding-left: $semantic-spacing-component-xs;
    }
  }
  
  @media (max-width: ($semantic-breakpoint-sm - 1)) {
    font-family: map-get($semantic-typography-body-small, font-family);
    font-size: map-get($semantic-typography-body-small, font-size);
    font-weight: map-get($semantic-typography-body-small, font-weight);
    line-height: map-get($semantic-typography-body-small, line-height);
    
    .ui-tree-view__node {
      padding: $semantic-spacing-content-line-tight $semantic-spacing-component-xs;
    }
  }
}