// Use theme variables with namespace to avoid conflicts
@use 'variables' as vars;

// ============================================
// Hikari Avatar Component
// ============================================

.hi-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background-color: var(--hi-tertiary-bg, rgba(240, 240, 244, 0.5));
    color: var(--hi-text-secondary, var(--hi-text-secondary, rgba(80, 97, 109, 0.65)));
    font-weight: 600;
    transition:
        transform vars.$hikari-transition-fast,
        box-shadow vars.$hikari-transition-fast;
    position: relative;
    cursor: default;
    flex-shrink: 0;

    img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    &:hover {
        transform: scale(1.03);
        box-shadow: var(--hi-shadow-md, 0 4px 6px -1px rgba(0, 0, 0, 0.1));
    }
}

// Size variants
.hi-avatar-xs {
    width: 24px;
    height: 24px;
    font-size: 0.625rem;
}

.hi-avatar-sm {
    width: 32px;
    height: 32px;
    font-size: 0.75rem;
}

.hi-avatar-md {
    width: 40px;
    height: 40px;
    font-size: 0.875rem;
}

.hi-avatar-lg {
    width: 48px;
    height: 48px;
    font-size: 1rem;
}

.hi-avatar-xl {
    width: 64px;
    height: 64px;
    font-size: 1.25rem;
}

// Shape variants
.hi-avatar-circular {
    border-radius: 50%;
}

.hi-avatar-rounded {
    border-radius: vars.$hikari-radius-lg;
}

.hi-avatar-square {
    border-radius: vars.$hikari-radius-sm;
}

// Fallback content (text/initials)
.hi-avatar-fallback {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

// Icon placeholder
.hi-avatar-icon {
    color: var(--hi-text-secondary);
    opacity: 0.7;
    transition: opacity vars.$hikari-transition-fast;
}

.hi-avatar:hover .hi-avatar-icon {
    opacity: 1;
}

// Image element
.hi-avatar-img {
    display: block;
    width: 100%;
    height: 100%;
}

// Clickable / interactive avatar
.hi-avatar-clickable {
    cursor: pointer;

    &:hover {
        box-shadow:
            var(--hi-shadow-md, 0 4px 6px -1px rgba(0, 0, 0, 0.1)),
            0 0 0 2px var(--hi-color-primary, var(--hi-primary, #FFB3A7));
    }

    &:active {
        transform: scale(0.96);
    }

    &:focus-visible {
        outline: 2px solid var(--hi-color-primary, var(--hi-primary));
        outline-offset: 2px;
    }
}

// Status indicator dot (positioned at bottom-right)
.hi-avatar-status {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 30%;
    height: 30%;
    min-width: 8px;
    min-height: 8px;
    max-width: 14px;
    max-height: 14px;
    border-radius: 50%;
    border: 2px solid var(--hi-surface, #FAFAFA);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.hi-avatar-status-online {
    background-color: var(--hi-success, #0EB840);
}

.hi-avatar-status-offline {
    background-color: var(--hi-text-disabled, rgba(80, 97, 109, 0.35));
}

.hi-avatar-status-busy {
    background-color: var(--hi-danger, #FF4C00);
}

.hi-avatar-status-away {
    background-color: var(--hi-accent, #FFC773);
}

// Group / stack variant
.hi-avatar-group {
    display: inline-flex;
    align-items: center;

    .hi-avatar {
        border: 2px solid var(--hi-background, #ffffff);
        margin-left: -8px;

        &:first-child {
            margin-left: 0;
        }
    }
}

// Dark theme (Tairitsu)
[data-theme="tairitsu"] .hi-avatar {
    background-color: rgba(240, 240, 245, 0.08);
    color: var(--hi-text-secondary, #B3B8C7);

    &:hover {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    }
}

[data-theme="tairitsu"] .hi-avatar-icon {
    color: var(--hi-text-secondary, #B3B8C7);
    opacity: 0.5;
}

[data-theme="tairitsu"] .hi-avatar:hover .hi-avatar-icon {
    opacity: 0.7;
}

[data-theme="tairitsu"] .hi-avatar-status {
    border-color: var(--hi-background, #161823);
}

[data-theme="tairitsu"] .hi-avatar-group .hi-avatar {
    border-color: var(--hi-background, #161823);
}

// Reduced motion support
@media (prefers-reduced-motion: reduce) {
    .hi-avatar,
    .hi-avatar-clickable {
        transition: none;
    }

    .hi-avatar:hover,
    .hi-avatar-clickable:hover {
        transform: none;
    }

    .hi-avatar-clickable:active {
        transform: none;
    }
}
