/* ===================================
   Chat Widget AAA - Animations & Styles
   =================================== */

/* Message animations */
@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes messageFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

@keyframes checkMark {
    0% {
        transform: scale(0);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
    }
}

@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-3px);
    }
}

/* Typing indicator animation */
.dot-typing {
    position: relative;
    left: -9999px;
    width: 8px;
    height: 8px;
    border-radius: 5px;
    background-color: #9880ff;
    color: #9880ff;
    box-shadow: 9984px 0 0 0 #9880ff, 9999px 0 0 0 #9880ff, 10014px 0 0 0 #9880ff;
    animation: dotTyping 1.5s infinite linear;
}

@keyframes dotTyping {
    0% {
        box-shadow: 9984px 0 0 0 #9880ff, 9999px 0 0 0 #9880ff, 10014px 0 0 0 #9880ff;
    }
    16.667% {
        box-shadow: 9984px -10px 0 0 #9880ff, 9999px 0 0 0 #9880ff, 10014px 0 0 0 #9880ff;
    }
    33.333% {
        box-shadow: 9984px 0 0 0 #9880ff, 9999px 0 0 0 #9880ff, 10014px 0 0 0 #9880ff;
    }
    50% {
        box-shadow: 9984px 0 0 0 #9880ff, 9999px -10px 0 0 #9880ff, 10014px 0 0 0 #9880ff;
    }
    66.667% {
        box-shadow: 9984px 0 0 0 #9880ff, 9999px 0 0 0 #9880ff, 10014px 0 0 0 #9880ff;
    }
    83.333% {
        box-shadow: 9984px 0 0 0 #9880ff, 9999px 0 0 0 #9880ff, 10014px -10px 0 0 #9880ff;
    }
    100% {
        box-shadow: 9984px 0 0 0 #9880ff, 9999px 0 0 0 #9880ff, 10014px 0 0 0 #9880ff;
    }
}

.stage {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    padding: 0 0 0 25px;
    overflow: hidden;
    height: 20px;
}

/* Message styles with animations */
.message {
    animation: messageSlideIn 0.3s ease-out;
    transition: all 0.2s ease;
}

.message:hover {
    transform: translateX(2px);
}

.message-content {
    transition: all 0.2s ease;
    position: relative;
}

/* Online status indicator */
.online-status {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.online-status .status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 5px;
    transition: all 0.3s ease;
}

.online-status .status-dot.online {
    background-color: #4CAF50;
    box-shadow: 0 0 0 0 rgba(76, 175, 80, 1);
    animation: statusPulse 2s infinite;
}

.online-status .status-dot.offline {
    background-color: #9E9E9E;
}

.online-status .status-dot.away {
    background-color: #FFC107;
    animation: statusPulse 2s infinite;
}

@keyframes statusPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.7);
    }
    70% {
        box-shadow: 0 0 0 8px rgba(76, 175, 80, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0);
    }
}

/* Read indicator animation */
.read-indicator {
    display: inline-block;
    margin-left: 5px;
    animation: checkMark 0.3s ease-out;
}

.read-indicator i {
    font-size: 14px;
    transition: color 0.3s ease;
}

/* Sending indicator */
.sending-indicator {
    opacity: 0.7;
    position: relative;
}

.sending-indicator .message-content {
    background-color: #f0f0f0 !important;
}

.sending-indicator .message-status {
    display: inline-flex !important;
    align-items: center;
    margin-left: 5px;
    color: #999;
    font-size: 11px;
}

.sending-indicator .message-status::before {
    content: '';
    display: inline-block;
    width: 10px;
    height: 10px;
    border: 2px solid #999;
    border-top-color: transparent;
    border-radius: 50%;
    margin-right: 4px;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.message-status {
    display: none;
    font-size: 11px;
    color: #999;
    margin-left: 5px;
}

.message-status.sent {
    display: inline-flex !important;
    align-items: center;
    color: #4CAF50;
}

.message-status.error {
    display: inline-flex !important;
    align-items: center;
    color: #f44336;
}

/* Chat window transitions */
.modal-popup-chat {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 9998;
}

.modal-popup-chat.d-block {
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Scroll indicator */
.scroll-indicator {
    position: absolute;
    bottom: 90px;
    right: 20px;
    width: 40px;
    height: 40px;
    background: rgba(25, 118, 210, 0.9);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    animation: bounce 2s infinite;
    z-index: 10;
    transition: all 0.3s ease;
}

.scroll-indicator:hover {
    background: rgba(25, 118, 210, 1);
    transform: scale(1.1);
}

.scroll-indicator i {
    color: white;
    font-size: 18px;
}

/* Unread badge animation */
.unread-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #f44336;
    color: white;
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: bold;
    animation: pulse 2s infinite;
}

/* Message input focus effect */
#message-input:focus {
    box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.1);
    border-color: #1976d2;
    transition: all 0.3s ease;
}

/* Attachment preview animations */
.message-attachment {
    animation: messageFadeIn 0.4s ease-out;
}

.message-attachment img {
    transition: transform 0.3s ease;
}

.message-attachment img:hover {
    transform: scale(1.05);
}

/* Notification popup */
.chat-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: white;
    padding: 15px 20px;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 10000;
    animation: slideInRight 0.3s ease-out;
    max-width: 300px;
    display: flex;
    align-items: center;
    gap: 10px;
}

@keyframes slideInRight {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.chat-notification.closing {
    animation: slideOutRight 0.3s ease-out forwards;
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(400px);
        opacity: 0;
    }
}

.chat-notification .avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.chat-notification .content {
    flex: 1;
}

.chat-notification .content .name {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 2px;
}

.chat-notification .content .message {
    font-size: 12px;
    color: #666;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Loading spinner */
.loading-spinner {
    animation: messageFadeIn 0.3s ease-out;
}

/* Smooth scroll */
#chatMessageWindow {
    scroll-behavior: smooth;
}

/* Hover effects for message list items */
.message-list-item,
.list-group-item.bg-transparent {
    transition: background-color 0.2s ease, transform 0.2s ease;
    cursor: pointer;
    border-radius: 8px !important;
    margin-bottom: 4px;
    padding: 12px 8px !important;
}

.message-list-item:hover,
.list-group-item.bg-transparent:hover {
    background-color: rgba(25, 118, 210, 0.05) !important;
    transform: translateX(3px);
}

.message-list-item:active,
.list-group-item.bg-transparent:active {
    background-color: rgba(25, 118, 210, 0.1) !important;
}

.list-group-item.bg-transparent figure.avatar {
    position: relative;
}

.list-group-item.bg-transparent figure.avatar::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid white;
    background-color: #9E9E9E;
}

.list-group-item.bg-transparent.online figure.avatar::after {
    background-color: #4CAF50;
    animation: statusPulse 2s infinite;
}

.list-group-item .truncate-text {
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block !important;
}

.message-error {
    opacity: 0.6;
}

.message-error .message-content {
    background-color: #ffebee !important;
    border-left: 3px solid #f44336;
}

/* Button hover effects */
.chat-send-button {
    transition: all 0.2s ease;
}

.chat-send-button:hover {
    transform: scale(1.05);
}

.chat-send-button:active {
    transform: scale(0.95);
}

/* New message indicator at bottom */
.new-message-indicator {
    position: absolute;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    background: #1976d2;
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    animation: bounce 2s infinite;
    z-index: 10;
    transition: all 0.3s ease;
}

.new-message-indicator:hover {
    background: #1565c0;
    transform: translateX(-50%) scale(1.05);
}

.attachment-indicator {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: #e3f2fd;
    border: 1px solid #90caf9;
    border-radius: 15px;
    padding: 4px 10px;
    font-size: 12px;
    color: #1976d2;
    margin-right: 8px;
    animation: messageFadeIn 0.3s ease-out;
}

.attachment-indicator i {
    font-size: 14px;
}

.attachment-indicator .feather-x {
    color: #666;
    margin-left: 3px;
}

.attachment-indicator .feather-x:hover {
    color: #f44336;
}
