@use 'ui-design-system/src/styles/semantic/index' as *;
.skyui-avatar {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background-color: $semantic-color-surface-secondary;
  color: $semantic-color-text-secondary;
  box-sizing: border-box;
  flex-shrink: 0;
  user-select: none;
  cursor: pointer;

  // Size variants based on semantic sizing tokens
  &--size-xs {
    width: 24px;
    height: 24px;
    
    .skyui-avatar__initials {
      font-size: calc(24px * 0.4);
      font-weight: 500;
    }
    
    .skyui-avatar__icon {
      font-size: calc(24px * 0.6);
    }
  }

  &--size-sm {
    width: 32px;
    height: 32px;
    
    .skyui-avatar__initials {
      font-size: calc(32px * 0.4);
      font-weight: 500;
    }
    
    .skyui-avatar__icon {
      font-size: calc(32px * 0.6);
    }
  }

  &--size-md {
    width: 40px;
    height: 40px;
    
    .skyui-avatar__initials {
      font-size: calc(40px * 0.4);
      font-weight: 500;
    }
    
    .skyui-avatar__icon {
      font-size: calc(40px * 0.6);
    }
  }

  &--size-lg {
    width: 48px;
    height: 48px;
    
    .skyui-avatar__initials {
      font-size: calc(48px * 0.4);
      font-weight: 600;
    }
    
    .skyui-avatar__icon {
      font-size: calc(48px * 0.6);
    }
  }

  &--size-xl {
    width: 64px;
    height: 64px;
    
    .skyui-avatar__initials {
      font-size: calc(64px * 0.35);
      font-weight: 600;
    }
    
    .skyui-avatar__icon {
      font-size: calc(64px * 0.5);
    }
  }

  &--size-xxl {
    width: 80px;
    height: 80px;
    
    .skyui-avatar__initials {
      font-size: calc(80px * 0.35);
      font-weight: 600;
    }
    
    .skyui-avatar__icon {
      font-size: calc(80px * 0.5);
    }
  }

  // Loading state
  &--loading {
    background-color: $semantic-color-surface-disabled;
    
    .skyui-avatar__loading {
      position: absolute;
      inset: 0;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .loading-spinner {
      width: 50%;
      height: 50%;
      border: 2px solid $semantic-color-border-subtle;
      border-top: 2px solid $semantic-color-brand-primary;
      border-radius: 50%;
      animation: spin 1s linear infinite;
    }
  }

  // Avatar image
  &__image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    overflow: hidden;
  }

  // Fallback container
  &__fallback {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: $semantic-color-container-primary;
    color: $semantic-color-on-container-primary;
    border-radius: 50%;
    overflow: hidden;
  }

  // Initials text
  &__initials {
    line-height: 1;
    text-align: center;
    letter-spacing: -0.02em;
  }

  // Icon
  &__icon {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  // Status indicator
  &__status {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 25%;
    height: 25%;
    min-width: 8px;
    min-height: 8px;
    border-radius: 50%;
    border: 2px solid $semantic-color-surface-primary;
    box-sizing: border-box;

    &--online {
      background-color: $semantic-color-success;
    }

    &--offline {
      background-color: $semantic-color-text-tertiary;
    }

    &--away {
      background-color: $semantic-color-warning;
    }

    &--busy {
      background-color: $semantic-color-danger;
    }
  }

  // Badge indicator positioning
  &__badge {
    position: absolute;
    top: -4px;
    right: -4px;
  }
}

// Animation for loading spinner
@keyframes spin {
  0% { 
    transform: rotate(0deg); 
  }
  100% { 
    transform: rotate(360deg); 
  }
}

// Focus and hover states for interactive avatars
.skyui-avatar {
  &[role="button"]:focus-visible,
  &[tabindex]:focus-visible {
    outline: 2px solid $semantic-color-brand-primary;
    outline-offset: 2px;
  }

  &[role="button"]:hover,
  &[tabindex]:hover {
    transform: scale(1.05);
    transition: transform $semantic-duration-fast $semantic-easing-standard;
  }
}

// High contrast mode support
@media (prefers-contrast: high) {
  .skyui-avatar {
    border: $semantic-border-width-1 solid $semantic-color-border-primary;
    
    &__status {
      border-width: $semantic-border-width-3;
    }
  }
}

// Reduced motion support
@media (prefers-reduced-motion: reduce) {
  .skyui-avatar {
    &[role="button"]:hover,
    &[tabindex]:hover {
      transition: none;
    }
    
    .loading-spinner {
      animation: none;
    }
  }
}