/**
 * Chat Widget Styles
 * Persistent floating chat interface that follows users across pages
 */

/* Chat Widget Container */
.chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Chat Toggle Button */
.chat-toggle {
    position: relative;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
    transition: all 0.3s ease;
    user-select: none;
}

.chat-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(102, 126, 234, 0.5);
}

.chat-toggle .chat-icon {
    color: white;
    font-size: 24px;
    transition: transform 0.3s ease;
}

.chat-widget.chat-open .chat-toggle .chat-icon {
    transform: rotate(180deg);
}

/* Chat Notification Badge */
.chat-notification {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4757;
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    animation: pulse 2s infinite;
}

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

.notification-bounce {
    animation: bounce 1s ease-in-out;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-10px); }
    60% { transform: translateY(-5px); }
}

/* Chat Window */
.chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 350px;
    height: 500px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    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);
    overflow: hidden;
}

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

.chat-window.chat-minimized {
    height: 60px;
    overflow: hidden;
}

/* Chat Header */
.chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 12px 12px 0 0;
    flex-shrink: 0;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar {
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.chat-title h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.chat-status {
    font-size: 12px;
    opacity: 0.8;
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-status::before {
    content: '';
    width: 8px;
    height: 8px;
    background: #2ed573;
    border-radius: 50%;
    display: inline-block;
}

.chat-status.offline::before {
    background: #ff4757;
}

.chat-controls {
    display: flex;
    gap: 8px;
}

.chat-controls button {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.chat-controls button:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #f8f9fa;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

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

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

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

/* Chat Message */
.chat-message {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: messageSlideIn 0.3s ease-out;
}

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

.user-message {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.bot-message {
    align-self: flex-start;
}

.message-avatar {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 14px;
    flex-shrink: 0;
}

.message-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message-text {
    background: white;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.user-message .message-text {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 6px;
}

.bot-message .message-text {
    border-bottom-left-radius: 6px;
}

.error-message .message-text {
    background: #ffe6e6;
    color: #d63031;
    border: 1px solid #ff7675;
}

.message-time {
    font-size: 11px;
    color: #999;
    padding: 0 4px;
}

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

/* Message Formatting */
.message-text strong {
    font-weight: 600;
}

.message-text em {
    font-style: italic;
}

.message-text code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 13px;
}

.user-message .message-text code {
    background: rgba(255, 255, 255, 0.2);
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px 16px 20px;
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.typing-dots {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: white;
    border-radius: 18px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

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

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

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

.typing-text {
    font-size: 12px;
    color: #999;
    font-style: italic;
}

/* Chat Input */
.chat-input-container {
    background: white;
    border-top: 1px solid #eee;
    padding: 16px 20px;
    flex-shrink: 0;
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: #f8f9fa;
    border-radius: 24px;
    padding: 8px 8px 8px 16px;
    border: 1px solid #e9ecef;
    transition: border-color 0.2s ease;
}

.chat-input-wrapper:focus-within {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.chat-input {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    outline: none;
    font-size: 14px;
    line-height: 1.4;
    padding: 8px 0;
    font-family: inherit;
    max-height: 120px;
}

.chat-input::placeholder {
    color: #999;
}

.chat-send {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chat-send:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.chat-send:active {
    transform: scale(0.95);
}

.chat-input-footer {
    margin-top: 8px;
    text-align: center;
}

.chat-input-footer small {
    color: #999;
    font-size: 11px;
}

/* Responsive Design */
@media (max-width: 768px) {
    .chat-widget {
        bottom: 15px;
        right: 15px;
    }
    
    .chat-window {
        width: calc(100vw - 30px);
        max-width: 350px;
        height: 450px;
        bottom: 75px;
        right: -15px;
    }
    
    .chat-toggle {
        width: 55px;
        height: 55px;
    }
    
    .chat-toggle .chat-icon {
        font-size: 22px;
    }
}

@media (max-width: 480px) {
    .chat-window {
        width: calc(100vw - 20px);
        height: 400px;
        bottom: 70px;
        right: -10px;
    }
    
    .chat-messages {
        padding: 16px;
        gap: 12px;
    }
    
    .chat-input-container {
        padding: 12px 16px;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .chat-window {
        background: #2c3e50;
        color: white;
    }
    
    .chat-messages {
        background: #34495e;
    }
    
    .message-text {
        background: #3c5a78;
        color: white;
    }
    
    .bot-message .message-text {
        background: #3c5a78;
    }
    
    .typing-dots {
        background: #3c5a78;
    }
    
    .chat-input-container {
        background: #2c3e50;
        border-top-color: #4a5f7a;
    }
    
    .chat-input-wrapper {
        background: #34495e;
        border-color: #4a5f7a;
    }
    
    .chat-input {
        color: white;
    }
    
    .chat-input::placeholder {
        color: #bdc3c7;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .chat-toggle {
        border: 2px solid #000;
    }
    
    .chat-window {
        border: 2px solid #000;
    }
    
    .message-text {
        border: 1px solid #000;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .chat-toggle,
    .chat-window,
    .chat-message,
    .typing-indicator {
        animation: none;
        transition: none;
    }
    
    .chat-notification {
        animation: none;
    }
    
    .typing-dots span {
        animation: none;
    }
}

/* Focus Styles for Accessibility */
.chat-toggle:focus,
.chat-controls button:focus,
.chat-send:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

.chat-input:focus {
    outline: none; /* Handled by wrapper focus-within */
}

/* Print Styles */
@media print {
    .chat-widget {
        display: none;
    }
}
