/* Animaciones para actualizaciones incrementales */

/* Animaciones para contactos */
.contact-entering {
    animation: slideInLeft 0.3s ease-out;
}

.contact-updating {
    animation: pulse 0.5s ease-in-out;
    background-color: rgba(0, 168, 132, 0.1);
}

.new-message-received {
    animation: newMessageGlow 1s ease-in-out;
    border-left: 3px solid #00a884;
}

.contact-leaving {
    animation: slideOutRight 0.3s ease-in;
}

/* Animaciones para mensajes */
.message-entering {
    animation: slideInUp 0.3s ease-out;
}

.message-updating {
    animation: flash 0.3s ease-in-out;
}

/* Keyframes */
@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideOutRight {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(20px);
    }
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0% {
        background-color: rgba(0, 168, 132, 0.1);
    }
    50% {
        background-color: rgba(0, 168, 132, 0.2);
    }
    100% {
        background-color: rgba(0, 168, 132, 0.1);
    }
}

@keyframes flash {
    0% {
        background-color: transparent;
    }
    50% {
        background-color: rgba(0, 168, 132, 0.15);
    }
    100% {
        background-color: transparent;
    }
}

@keyframes newMessageGlow {
    0% {
        background-color: rgba(0, 168, 132, 0.2);
        border-left-color: #00a884;
    }
    50% {
        background-color: rgba(0, 168, 132, 0.3);
        border-left-color: #00d04a;
    }
    100% {
        background-color: transparent;
        border-left-color: transparent;
    }
}

/* Transiciones suaves para elementos que cambian */
.chat-item {
    transition: all 0.2s ease;
}

.chat-item:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.message {
    transition: all 0.2s ease;
}

/* Indicador de nuevos mensajes */
.unread-count {
    animation: bounceIn 0.3s ease-out;
}

.counter-updated {
    animation: counterPulse 0.6s ease-out;
}

@keyframes bounceIn {
    0% {
        opacity: 0;
        transform: scale(0.3);
    }
    50% {
        opacity: 1;
        transform: scale(1.1);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes counterPulse {
    0% {
        transform: scale(1);
        background-color: #00a884;
    }
    50% {
        transform: scale(1.2);
        background-color: #00d04a;
    }
    100% {
        transform: scale(1);
        background-color: #00a884;
    }
}

/* Animación para scroll suave */
.messages-list {
    scroll-behavior: smooth;
}

/* Efecto de typing indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    background-color: #f0f0f0;
    border-radius: 18px;
    margin: 5px 0;
    animation: fadeIn 0.3s ease-out;
}

.typing-dots {
    display: flex;
    gap: 3px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #999;
    animation: typingDot 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typingDot {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Animación para botón de actualización */
.action-btn.refreshing {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* Efecto de conexión realtime */
.realtime-indicator {
    position: relative;
    display: inline-block;
}

.realtime-indicator::after {
    content: '';
    position: absolute;
    top: -2px;
    right: -2px;
    width: 8px;
    height: 8px;
    background-color: #00d04a;
    border-radius: 50%;
    animation: realtimePulse 2s infinite;
}

@keyframes realtimePulse {
    0% {
        box-shadow: 0 0 0 0 rgba(0, 208, 74, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(0, 208, 74, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(0, 208, 74, 0);
    }
}

/* Optimizaciones de rendimiento */
.chat-item,
.message,
.contact-entering,
.contact-updating,
.message-entering,
.message-updating {
    will-change: transform, opacity;
}

/* Reducir animaciones en dispositivos de bajo rendimiento */
@media (prefers-reduced-motion: reduce) {
    .contact-entering,
    .contact-updating,
    .contact-leaving,
    .message-entering,
    .message-updating,
    .unread-count,
    .typing-indicator,
    .realtime-indicator::after {
        animation: none;
    }
    
    .chat-item,
    .message {
        transition: none;
    }
    
    .messages-list {
        scroll-behavior: auto;
    }
}
