/* Chat Widget - Complete Professional Implementation */

/* Base Chat Widget Container */
.chat-widget {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 999999;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    user-select: none;
}

/* Chat Toggle Button */
.chat-toggle {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: white;
    font-size: 1.5rem;
    box-shadow: 0 4px 20px rgba(37, 99, 235, 0.4), 0 0 0 0 rgba(37, 99, 235, 0.3);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    border: 3px solid white;
    animation: chatPulse 3s infinite;
    outline: none;
}

.chat-toggle:hover {
    transform: scale(1.05) translateY(-2px);
    box-shadow: 0 8px 30px rgba(37, 99, 235, 0.5), 0 0 0 8px rgba(37, 99, 235, 0.1);
}

.chat-toggle:focus {
    box-shadow: 0 8px 30px rgba(37, 99, 235, 0.5), 0 0 0 4px rgba(37, 99, 235, 0.3);
}

.chat-toggle.active {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    transform: scale(0.95);
    animation: none;
}

/* Icon Animations */
.chat-icon, .close-icon {
    transition: all 0.3s ease;
    position: absolute;
}

.close-icon {
    font-size: 1.3rem;
}

/* Chat Notification Badge */
.chat-notification {
    position: absolute;
    top: -8px;
    right: -8px;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
    animation: bounce 2s infinite;
    border: 2px solid white;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
}

/* Chat Window */
.chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 550px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 999998;
    overflow: hidden;
}

.chat-window.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Chat Header */
.chat-header {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: white;
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    position: relative;
}

.chat-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.3);
    position: relative;
}

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

.avatar-fallback {
    display: none;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.2);
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: white;
}

.chat-info {
    flex: 1;
}

.chat-info h4 {
    margin: 0 0 0.25rem 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: white !important;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    font-size: 0.85rem;
    color: white !important;
    opacity: 1;
}

.status-text {
    color: white !important;
    font-weight: 500;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
    animation: statusPulse 2s infinite;
}

.status-dot.offline {
    background: #ef4444;
    animation: none;
}

.chat-minimize {
    background: none;
    border: none;
    color: white;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: background-color 0.2s ease;
    outline: none;
}

.chat-minimize:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Messages Container */
.chat-messages {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    background: linear-gradient(180deg, #f8fafc 0%, #ffffff 100%);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Message Styling */
.welcome-message, .message-group {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.user-message .message-avatar {
    background: linear-gradient(135deg, #10b981, #059669);
    order: 2;
}

.message-content-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.user-message .message-content-wrapper {
    align-items: flex-end;
}

.message-content {
    background: white;
    padding: 1rem 1.25rem;
    border-radius: 18px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(0, 0, 0, 0.05);
    max-width: 280px;
    word-wrap: break-word;
}

.message-content.welcome {
    background: linear-gradient(135deg, #eff6ff, #dbeafe);
    border: 1px solid #bfdbfe;
}

.user-message .message-content {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: white;
    border: 1px solid #1d4ed8;
}

.message-content p {
    margin: 0 0 0.5rem 0;
    line-height: 1.5;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-time {
    font-size: 0.75rem;
    color: #6b7280;
    margin-top: 0.25rem;
}

.user-message .message-time {
    text-align: right;
}

/* Quick Options */
.quick-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.quick-option {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    color: #374151;
    outline: none;
}

.quick-option:hover {
    background: #f3f4f6;
    border-color: #d1d5db;
    transform: translateY(-1px);
}

.quick-option:active {
    transform: translateY(0);
}

/* Typing Indicator */
.chat-typing {
    padding: 1rem 1.5rem;
    background: white;
    border-top: 1px solid #f3f4f6;
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.typing-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.8rem;
}

.typing-content {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.typing-dots {
    display: flex;
    gap: 0.25rem;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #6b7280;
    animation: typingPulse 1.5s ease-in-out infinite;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

.typing-text {
    font-size: 0.85rem;
    color: #6b7280;
    font-style: italic;
}

/* Input Area - Enhanced for Better Usability */
.chat-input-area {
    background: white;
    border-top: 1px solid #f3f4f6;
    padding: 1.25rem 1.5rem 1.5rem;
}

.chat-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.input-wrapper {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: #f8fafc;
    border: 2px solid #e5e7eb;
    border-radius: 28px;
    padding: 0.75rem 1.25rem;
    transition: all 0.2s ease;
    min-height: 48px;
}

.input-wrapper:focus-within {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
    background: #ffffff;
}

#chatMessageInput {
    flex: 1;
    border: none;
    background: none;
    outline: none;
    font-size: 1rem;
    color: #374151;
    line-height: 1.5;
    min-height: 24px;
    padding: 0.25rem 0;
}

#chatMessageInput::placeholder {
    color: #9ca3af;
    font-size: 0.95rem;
}

#chatSendBtn {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    outline: none;
    flex-shrink: 0;
    font-size: 0.9rem;
}

#chatSendBtn:enabled:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

#chatSendBtn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #9ca3af;
}

.input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: #9ca3af;
    padding-top: 0.5rem;
}

.powered-by {
    font-size: 0.7rem;
    color: #9ca3af;
}

.char-counter {
    font-size: 0.7rem;
    color: #9ca3af;
}

/* Scrollbar Styling */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* Animations */
@keyframes chatPulse {
    0%, 100% { 
        box-shadow: 0 4px 20px rgba(37, 99, 235, 0.4), 0 0 0 0 rgba(37, 99, 235, 0.3);
    }
    50% { 
        box-shadow: 0 4px 20px rgba(37, 99, 235, 0.4), 0 0 0 8px rgba(37, 99, 235, 0.15);
    }
}

@keyframes bounce {
    0%, 20%, 53%, 80%, 100% { 
        transform: translate3d(0,0,0); 
    }
    40%, 43% { 
        transform: translate3d(0, -8px, 0); 
    }
    70% { 
        transform: translate3d(0, -4px, 0); 
    }
    90% { 
        transform: translate3d(0, -2px, 0); 
    }
}

@keyframes statusPulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(1.1);
    }
}

@keyframes typingPulse {
    0%, 60%, 100% {
        transform: scale(1);
        opacity: 0.5;
    }
    30% {
        transform: scale(1.2);
        opacity: 1;
    }
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .chat-widget {
        bottom: 1rem;
        right: 1rem;
    }
    
    .chat-toggle {
        width: 56px;
        height: 56px;
        font-size: 1.3rem;
    }
    
    .chat-window {
        width: calc(100vw - 2rem);
        height: calc(100vh - 8rem);
        max-width: none;
        right: -1rem;
        bottom: 72px;
        border-radius: 12px;
    }
    
    .chat-messages {
        padding: 1rem;
    }
    
    .message-content {
        max-width: calc(100vw - 8rem);
    }
    
    .quick-options {
        grid-template-columns: 1fr;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .chat-toggle {
        border-width: 2px;
    }
    
    .chat-window {
        border: 2px solid #000;
    }
    
    .message-content {
        border-width: 2px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .chat-toggle,
    .chat-window,
    .message-content,
    .quick-option,
    #chatSendBtn {
        animation: none;
        transition: none;
    }
    
    .typing-dots span {
        animation: none;
    }
    
    .status-dot {
        animation: none;
    }
}

/* ===== ONLY ADDITION: Fix user message text color ===== */
.message-content.user,
.message-content.user p,
.message-content.user * {
    background: linear-gradient(135deg, #2563eb, #1d4ed8) !important;
    color: white !important;
    border: 1px solid #1d4ed8;
}