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

.ui-toast {
  // Core Structure
  display: flex;
  position: relative;
  align-items: flex-start;
  width: 100%;
  max-width: 400px;
  
  // Layout & Spacing
  padding: $semantic-spacing-component-md;
  gap: $semantic-spacing-component-sm;
  
  // Visual Design
  background: $semantic-color-surface-elevated;
  border: $semantic-border-width-1 solid $semantic-color-border-primary;
  border-radius: $semantic-border-card-radius;
  box-shadow: $semantic-shadow-elevation-3;
  
  // 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;
  
  // Transitions
  transition: all $semantic-motion-duration-normal $semantic-motion-easing-ease;
  
  // Size Variants
  &--sm {
    padding: $semantic-spacing-component-sm;
    gap: $semantic-spacing-component-xs;
    max-width: 320px;
    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 {
    // Default styles already applied above
  }
  
  &--lg {
    padding: $semantic-spacing-component-lg;
    gap: $semantic-spacing-component-md;
    max-width: 480px;
    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;
    border-left-width: 4px;
    
    .ui-toast__icon {
      color: $semantic-color-primary;
    }
    
    .ui-toast__title {
      color: $semantic-color-primary;
    }
  }
  
  &--success {
    border-color: $semantic-color-success;
    border-left-width: 4px;
    
    .ui-toast__icon {
      color: $semantic-color-success;
    }
    
    .ui-toast__title {
      color: $semantic-color-success;
    }
  }
  
  &--warning {
    border-color: $semantic-color-warning;
    border-left-width: 4px;
    
    .ui-toast__icon {
      color: $semantic-color-warning;
    }
    
    .ui-toast__title {
      color: $semantic-color-warning;
    }
  }
  
  &--danger {
    border-color: $semantic-color-danger;
    border-left-width: 4px;
    
    .ui-toast__icon {
      color: $semantic-color-danger;
    }
    
    .ui-toast__title {
      color: $semantic-color-danger;
    }
  }
  
  &--info {
    border-color: $semantic-color-info;
    border-left-width: 4px;
    
    .ui-toast__icon {
      color: $semantic-color-info;
    }
    
    .ui-toast__title {
      color: $semantic-color-info;
    }
  }
  
  // BEM Elements
  &__icon {
    flex-shrink: 0;
    color: $semantic-color-text-secondary;
    font-size: $semantic-sizing-icon-inline;
    margin-top: 2px; // Slight optical alignment
  }
  
  &__content {
    flex: 1;
    min-width: 0; // Prevents flex overflow
  }
  
  &__title {
    margin: 0 0 $semantic-spacing-content-line-tight 0;
    font-family: map-get($semantic-typography-label, font-family);
    font-size: map-get($semantic-typography-label, font-size);
    font-weight: map-get($semantic-typography-label, font-weight);
    line-height: map-get($semantic-typography-label, line-height);
    color: $semantic-color-text-primary;
    
    &--bold {
      font-weight: $semantic-typography-font-weight-semibold;
    }
  }
  
  &__message {
    margin: 0;
    color: $semantic-color-text-secondary;
  }
  
  &__actions {
    margin-top: $semantic-spacing-component-sm;
    display: flex;
    gap: $semantic-spacing-component-xs;
    flex-wrap: wrap;
  }
  
  &__dismiss {
    position: absolute;
    top: $semantic-spacing-component-xs;
    right: $semantic-spacing-component-xs;
    background: transparent;
    border: none;
    color: $semantic-color-text-tertiary;
    cursor: pointer;
    padding: $semantic-spacing-component-xs;
    border-radius: $semantic-border-radius-sm;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: $semantic-sizing-touch-minimum;
    min-height: $semantic-sizing-touch-minimum;
    
    &:hover {
      background: $semantic-color-surface-secondary;
      color: $semantic-color-text-secondary;
    }
    
    &:focus-visible {
      outline: 2px solid $semantic-color-focus;
      outline-offset: 2px;
    }
    
    &:active {
      background: $semantic-color-surface-primary;
    }
  }
  
  // State Variants
  &--dismissible {
    padding-right: calc($semantic-spacing-component-lg + $semantic-sizing-touch-minimum);
  }
  
  // Toast-specific positioning and animations
  &--entering {
    animation: toast-slide-in $semantic-motion-duration-normal $semantic-motion-easing-ease forwards;
  }
  
  &--exiting {
    animation: toast-slide-out $semantic-motion-duration-normal $semantic-motion-easing-ease forwards;
  }
  
  // Progress bar for auto-dismiss
  &__progress {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: $semantic-color-surface-secondary;
    border-radius: 0 0 $semantic-border-card-radius $semantic-border-card-radius;
    overflow: hidden;
    
    &-bar {
      height: 100%;
      background: currentColor;
      width: 100%;
      transform-origin: left;
      animation: toast-progress var(--duration) linear forwards;
    }
  }
  
  &--with-progress {
    padding-bottom: calc($semantic-spacing-component-md + 3px);
  }
  
  // Responsive Design
  @media (max-width: $semantic-breakpoint-sm - 1) {
    padding: $semantic-spacing-component-sm;
    gap: $semantic-spacing-component-xs;
    max-width: 100%;
    
    &--lg {
      padding: $semantic-spacing-component-md;
    }
    
    &__title {
      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);
    }
    
    &__message {
      font-family: map-get($semantic-typography-caption, font-family);
      font-size: map-get($semantic-typography-caption, font-size);
      font-weight: map-get($semantic-typography-caption, font-weight);
      line-height: map-get($semantic-typography-caption, line-height);
    }
    
    &--dismissible {
      padding-right: calc($semantic-spacing-component-md + $semantic-sizing-touch-minimum);
    }
  }
}

// Keyframe animations
@keyframes toast-slide-in {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes toast-slide-out {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(100%);
  }
}

@keyframes toast-progress {
  from {
    transform: scaleX(1);
  }
  to {
    transform: scaleX(0);
  }
}