/* Chat Widget Styles */
:root {
    --chat-primary: #1e40af;
    --chat-primary-hover: #1d4ed8;
    --chat-secondary: #f8fafc;
    --chat-accent: #FFB72B;
    --chat-text: #1e293b;
    --chat-text-light: #64748b;
    --chat-border: #e2e8f0;
    --chat-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    --chat-shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.2);
    --chat-radius: 16px;
    --chat-radius-sm: 12px;
    --chat-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Chat Widget Container */
.chat-widget {
    position: fixed !important;
    bottom: 24px !important;
    right: 24px !important;
    left: auto !important;
    top: auto !important;
    z-index: 99999 !important;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* Chat Toggle Button */
.chat-toggle {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-hover) 100%);
    border: none;
    border-radius: 50%;
    box-shadow: var(--chat-shadow);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chat-transition);
    position: relative;
    overflow: hidden;
    pointer-events: auto;
    user-select: none;
}

.chat-toggle:hover {
    transform: translateY(-2px);
    box-shadow: var(--chat-shadow-lg);
    background: linear-gradient(135deg, var(--chat-primary-hover) 0%, #2563eb 100%);
}

.chat-toggle:active {
    transform: translateY(0);
}

.chat-toggle-icon {
    width: 28px;
    height: 28px;
    color: white;
    transition: var(--chat-transition);
}

.chat-toggle.active .chat-toggle-icon.chat-icon {
    opacity: 0;
    transform: rotate(90deg);
}

.chat-toggle.active .chat-toggle-icon.close-icon {
    opacity: 1;
    transform: rotate(0deg);
}

.chat-toggle-icon.close-icon {
    position: absolute;
    opacity: 0;
    transform: rotate(-90deg);
}

/* Chat Notification Badge */
.chat-notification {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 20px;
    height: 20px;
    background: #ef4444;
    border: 2px solid white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: white;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Chat Window */
.chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 520px;
    background: white;
    border-radius: var(--chat-radius);
    box-shadow: var(--chat-shadow-lg);
    border: 1px solid var(--chat-border);
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: var(--chat-transition);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.chat-window.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Chat Header */
.chat-header {
    background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-hover) 100%);
    color: white;
    padding: 20px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
    overflow: hidden;
}

.chat-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="20" cy="20" r="2" fill="white" opacity="0.1"/><circle cx="80" cy="40" r="1.5" fill="white" opacity="0.1"/><circle cx="40" cy="80" r="1" fill="white" opacity="0.1"/></svg>');
    animation: float 20s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(10px); }
}

.chat-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    position: relative;
    z-index: 1;
}

.chat-header-info {
    flex: 1;
    position: relative;
    z-index: 1;
}

.chat-header-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0 0 4px 0;
}

.chat-header-status {
    font-size: 13px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-indicator {
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.status-indicator.offline {
    background: #6b7280;
    animation: none;
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    padding: 20px 24px;
    overflow-y: auto;
    background: #f8fafc;
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Message Styles */
.message {
    margin-bottom: 16px;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    animation: messageSlideIn 0.4s ease-out;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--chat-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: var(--chat-accent);
    color: var(--chat-text);
}

.message-content {
    max-width: 75%;
    background: white;
    padding: 12px 16px;
    border-radius: var(--chat-radius-sm);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    position: relative;
    word-wrap: break-word;
    line-height: 1.5;
}

.message.user .message-content {
    background: var(--chat-primary);
    color: white;
}

.message-content::before {
    content: '';
    position: absolute;
    bottom: 0;
    width: 0;
    height: 0;
    border: 8px solid transparent;
}

.message:not(.user) .message-content::before {
    left: -8px;
    border-right-color: white;
    border-left: none;
}

.message.user .message-content::before {
    right: -8px;
    border-left-color: var(--chat-primary);
    border-right: none;
}

.message-text {
    font-size: 14px;
    margin: 0;
}

.message-text a {
    color: inherit;
    text-decoration: underline;
    opacity: 0.9;
}

.message.user .message-text a {
    color: rgba(255, 255, 255, 0.9);
}

.message-time {
    font-size: 11px;
    opacity: 0.6;
    margin-top: 4px;
    text-align: right;
}

.message:not(.user) .message-time {
    text-align: left;
}

/* Typing Indicator */
.typing-indicator {
    margin: 16px 0;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    opacity: 0;
    transform: translateY(10px);
    transition: var(--chat-transition);
}

.typing-indicator.active {
    opacity: 1;
    transform: translateY(0);
}

.typing-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--chat-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 14px;
    font-weight: 600;
}

.typing-content {
    background: white;
    padding: 12px 16px;
    border-radius: var(--chat-radius-sm);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    position: relative;
}

.typing-content::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: -8px;
    width: 0;
    height: 0;
    border: 8px solid transparent;
    border-right-color: white;
    border-left: none;
}

.typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--chat-text-light);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
.typing-dot:nth-child(3) { animation-delay: 0; }

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Chat Input */
.chat-input-container {
    padding: 20px 24px;
    background: white;
    border-top: 1px solid var(--chat-border);
}

.chat-input-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    background: var(--chat-secondary);
    border: 2px solid var(--chat-border);
    border-radius: 20px;
    padding: 12px 16px;
    font-size: 14px;
    line-height: 1.4;
    resize: none;
    max-height: 100px;
    min-height: 44px;
    transition: var(--chat-transition);
    font-family: inherit;
}

.chat-input:focus {
    outline: none;
    border-color: var(--chat-primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.1);
}

.chat-input::placeholder {
    color: var(--chat-text-light);
}

.chat-send-btn {
    width: 44px;
    height: 44px;
    background: var(--chat-primary);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chat-transition);
    flex-shrink: 0;
}

.chat-send-btn:hover:not(:disabled) {
    background: var(--chat-primary-hover);
    transform: translateY(-1px);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-send-icon {
    width: 18px;
    height: 18px;
}

/* Connection Status */
.connection-status {
    padding: 8px 16px;
    background: #fef3c7;
    color: #92400e;
    font-size: 12px;
    text-align: center;
    border-bottom: 1px solid var(--chat-border);
    display: none;
}

.connection-status.offline {
    background: #fee2e2;
    color: #991b1b;
    display: block;
}

.connection-status.reconnecting {
    background: #dbeafe;
    color: #1d4ed8;
    display: block;
}

/* Welcome Message */
.welcome-message {
    text-align: center;
    padding: 20px;
    color: var(--chat-text-light);
}

.welcome-message h3 {
    margin: 0 0 8px 0;
    color: var(--chat-text);
    font-size: 16px;
}

.welcome-message p {
    margin: 0;
    font-size: 14px;
    line-height: 1.4;
}

/* Responsive Design */
@media (max-width: 480px) {
    .chat-widget {
        bottom: 16px;
        right: 16px;
    }
    
    .chat-window {
        width: calc(100vw - 32px);
        height: calc(100vh - 120px);
        max-height: 600px;
    }
    
    .chat-toggle {
        width: 56px;
        height: 56px;
    }
    
    .chat-toggle-icon {
        width: 24px;
        height: 24px;
    }
}

@media (max-width: 320px) {
    .chat-window {
        width: calc(100vw - 16px);
        right: -8px;
    }
    
    .message-content {
        max-width: 85%;
    }
}

/* Animations for enhanced UX */
.chat-widget.initializing .chat-toggle {
    animation: breathe 2s ease-in-out infinite;
}

@keyframes breathe {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* Accessibility */
.chat-toggle:focus,
.chat-send-btn:focus,
.chat-input:focus {
    outline: 2px solid var(--chat-accent);
    outline-offset: 2px;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .chat-window {
        background: #1e293b;
        border-color: #374151;
    }
    
    .chat-messages {
        background: #0f172a;
    }
    
    .message-content {
        background: #334155;
        color: #e2e8f0;
    }
    
    .message.user .message-content {
        background: var(--chat-primary);
        color: white;
    }
    
    .typing-content {
        background: #334155;
    }
    
    .chat-input-container {
        background: #1e293b;
        border-color: #374151;
    }
    
    .chat-input {
        background: #0f172a;
        border-color: #374151;
        color: #e2e8f0;
    }
    
    .chat-input:focus {
        background: #1e293b;
    }
    
    .welcome-message {
        color: #94a3b8;
    }
    
    .welcome-message h3 {
        color: #e2e8f0;
    }
}
