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

// Tokens available globally via main application styles

.ui-button {
  // Reset and base styles
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: $semantic-border-radius-md;
  cursor: pointer;
  text-decoration: none;
  outline: none;
  position: relative;
  overflow: hidden;
  
  // Typography
  font-family: $semantic-typography-font-family-sans;
  font-weight: $semantic-typography-font-weight-medium;
  text-align: center;
  text-transform: none;
  letter-spacing: $semantic-typography-letter-spacing-normal;
  white-space: nowrap;
  
  // Interaction states
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  box-sizing: border-box;
  
  // Transitions
  transition: all 200ms cubic-bezier(0.4, 0, 0.2, 1);
  
  // Size variants
  &--small {
    height: $semantic-spacing-9; // 2.25rem
    padding: 0 $semantic-spacing-3; // 0.75rem
    font-size: $semantic-typography-font-size-sm;
    line-height: $semantic-typography-line-height-tight;
    min-width: $semantic-spacing-16; // 4rem
  }
  
  &--medium {
    height: $semantic-spacing-11; // 2.75rem
    padding: 0 $semantic-spacing-4; // 1rem
    font-size: $semantic-typography-font-size-md;
    line-height: $semantic-typography-line-height-normal;
    min-width: $semantic-spacing-20; // 5rem
  }
  
  &--large {
    height: $semantic-spacing-12; // 3rem + a bit
    padding: 0 $semantic-spacing-6; // 1.5rem
    font-size: $semantic-typography-font-size-lg;
    line-height: $semantic-typography-line-height-normal;
    min-width: $semantic-spacing-24; // 6rem
  }
  
  // Filled variant (primary)
  &--filled {
    background-color: $semantic-color-interactive-primary;
    color: $semantic-color-on-brand-primary;
    
    &:hover:not(:disabled) {
      background-color: $semantic-color-brand-primary;
      transform: translateY(-1px);
      box-shadow: $semantic-shadow-button-hover;
    }
    
    &:active:not(:disabled) {
      transform: scale(0.98);
      box-shadow: $semantic-shadow-button-active;
    }
    
    &:focus-visible {
      outline: 2px solid $semantic-color-brand-primary;
      outline-offset: 2px;
    }
  }
  
  // Tonal variant
  &--tonal {
    background-color: $semantic-color-container-primary;
    color: $semantic-color-on-container-primary;
    
    &:hover:not(:disabled) {
      background-color: $semantic-color-container-primary;
      transform: translateY(-1px);
      box-shadow: $semantic-shadow-button-hover;
      filter: brightness(0.95);
    }
    
    &:active:not(:disabled) {
      transform: scale(0.98);
    }
    
    &:focus-visible {
      outline: 2px solid $semantic-color-brand-primary;
      outline-offset: 2px;
    }
  }
  
  // Outlined variant
  &--outlined {
    background-color: transparent;
    color: $semantic-color-interactive-primary;
    border: $semantic-border-width-1 solid $semantic-color-border-primary;
    
    &:hover:not(:disabled) {
      background-color: $semantic-color-container-primary;
      border-color: $semantic-color-interactive-primary;
      transform: translateY(-1px);
    }
    
    &:active:not(:disabled) {
      background-color: $semantic-color-container-primary;
      transform: scale(0.98);
      filter: brightness(0.9);
    }
    
    &:focus-visible {
      outline: 2px solid $semantic-color-brand-primary;
      outline-offset: 2px;
    }
  }
  
  // States
  &--disabled {
    opacity: 0.38;
    cursor: not-allowed;
    pointer-events: none;
  }
  
  &--loading {
    cursor: wait;
    
    .button-content {
      opacity: 0;
    }
  }
  
  &--full-width {
    width: 100%;
  }

  // Icon styles
  .button-content {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .button-icon {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;

    &--left {
      margin-right: $semantic-spacing-2; // 0.5rem
    }

    &--right {
      margin-left: $semantic-spacing-2; // 0.5rem
    }
  }

  // Size-specific icon adjustments
  &--small .button-icon {
    font-size: $semantic-typography-font-size-xs;
    
    &--left {
      margin-right: $semantic-spacing-1-5; // 0.375rem
    }
    
    &--right {
      margin-left: $semantic-spacing-1-5; // 0.375rem
    }
  }

  &--medium .button-icon {
    font-size: $semantic-typography-font-size-sm;
    
    &--left {
      margin-right: $semantic-spacing-2; // 0.5rem
    }
    
    &--right {
      margin-left: $semantic-spacing-2; // 0.5rem
    }
  }

  &--large .button-icon {
    font-size: $semantic-typography-font-size-md;
    
    &--left {
      margin-right: $semantic-spacing-2-5; // 0.625rem
    }
    
    &--right {
      margin-left: $semantic-spacing-2-5; // 0.625rem
    }
  }
  
  // Loader styles
  .button-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
  
  .button-spinner {
    width: $semantic-spacing-4; // 1rem
    height: $semantic-spacing-4; // 1rem
    border: 2px solid currentColor;
    border-top: 2px solid transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    opacity: 0.7;
  }
  
  @keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
  }
  
  // Ripple effect
  &::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.3) 0%, transparent 70%);
    transform: scale(0);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s ease, opacity 0.3s ease;
  }
  
  &:active:not(:disabled)::after {
    transform: scale(1);
    opacity: 1;
    transition: none;
  }
}