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

.ui-tooltip-wrapper {
  position: relative;
  display: inline-block;
}

.ui-tooltip-trigger {
  display: inherit;
  width: inherit;
  height: inherit;
}

.ui-tooltip {
  position: absolute;
  z-index: $semantic-z-index-tooltip;
  background: $semantic-color-surface-elevated;
  border: $semantic-border-width-1 solid $semantic-color-border-subtle;
  border-radius: $semantic-border-radius-md;
  box-shadow: $semantic-shadow-elevation-3;
  pointer-events: none;
  opacity: 1;
  transform: scale(1);
  animation: tooltip-fade-in $semantic-motion-duration-fast $semantic-easing-standard;
  
  // Size variants
  &--sm {
    max-width: 200px;
    
    .ui-tooltip__content {
      padding: $semantic-spacing-component-xs;
      font-size: $semantic-typography-font-size-xs;
    }
  }
  
  &--md {
    max-width: 250px;
    
    .ui-tooltip__content {
      padding: $semantic-spacing-component-sm;
      font-size: $semantic-typography-font-size-sm;
    }
  }
  
  &--lg {
    max-width: 300px;
    
    .ui-tooltip__content {
      padding: $semantic-spacing-component-md;
      font-size: $semantic-typography-font-size-sm;
    }
  }
  
  // Position variants
  &--top {
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-8px);
    margin-bottom: $semantic-spacing-component-xs;
    
    .ui-tooltip__arrow {
      top: 100%;
      left: 50%;
      transform: translateX(-50%);
      border-top-color: $semantic-color-surface-elevated;
      border-bottom: none;
    }
  }
  
  &--bottom {
    top: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(8px);
    margin-top: $semantic-spacing-component-xs;
    
    .ui-tooltip__arrow {
      bottom: 100%;
      left: 50%;
      transform: translateX(-50%);
      border-bottom-color: $semantic-color-surface-elevated;
      border-top: none;
    }
  }
  
  &--left {
    right: 100%;
    top: 50%;
    transform: translateY(-50%) translateX(-8px);
    margin-right: $semantic-spacing-component-xs;
    
    .ui-tooltip__arrow {
      left: 100%;
      top: 50%;
      transform: translateY(-50%);
      border-left-color: $semantic-color-surface-elevated;
      border-right: none;
    }
  }
  
  &--right {
    left: 100%;
    top: 50%;
    transform: translateY(-50%) translateX(8px);
    margin-left: $semantic-spacing-component-xs;
    
    .ui-tooltip__arrow {
      right: 100%;
      top: 50%;
      transform: translateY(-50%);
      border-right-color: $semantic-color-surface-elevated;
      border-left: none;
    }
  }
  
  &__content {
    color: $semantic-color-text-primary;
    line-height: 1.4;
    word-wrap: break-word;
    text-align: center;
  }
  
  &__arrow {
    position: absolute;
    width: 0;
    height: 0;
    border: 6px solid transparent;
    
    // Default arrow styling
    border-top: 6px solid $semantic-color-surface-elevated;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
  }
  
  // Dark mode support
  :host-context(.dark-theme) & {
    background: $semantic-color-surface-secondary;
    border-color: $semantic-color-border-primary;
    
    .ui-tooltip__content {
      color: $semantic-color-text-primary;
    }
    
    .ui-tooltip__arrow {
      border-top-color: $semantic-color-surface-secondary;
      
      &::after {
        border-top-color: $semantic-color-surface-secondary;
      }
    }
    
    &--bottom .ui-tooltip__arrow {
      border-bottom-color: $semantic-color-surface-secondary;
      border-top: none;
    }
    
    &--left .ui-tooltip__arrow {
      border-left-color: $semantic-color-surface-secondary;
      border-right: none;
    }
    
    &--right .ui-tooltip__arrow {
      border-right-color: $semantic-color-surface-secondary;
      border-left: none;
    }
  }
  
  // Responsive adjustments
  @media (max-width: $semantic-breakpoint-sm - 1) {
    &--sm { max-width: 150px; }
    &--md { max-width: 200px; }
    &--lg { max-width: 250px; }
    
    .ui-tooltip__content {
      padding: $semantic-spacing-component-xs;
      font-size: $semantic-typography-font-size-xs;
    }
  }
}

// Animation keyframes
@keyframes tooltip-fade-in {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}