/**
 * AI Chatbot Styles
 * Modern, clean chat interface
 */

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

/* Toggle Button */
.chatbot-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
    transition: all 0.3s ease;
    position: relative;
}

.chatbot-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.6);
}

.chatbot-toggle i {
    font-size: 28px;
}

.chatbot-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ef4444;
    color: white;
    border-radius: 12px;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: bold;
    min-width: 20px;
    text-align: center;
    display: none;
}

.chatbot-badge[style*="display: block"],
.chatbot-badge[style*="display: inline"] {
    display: block !important;
}

/* Chat Window */
.chatbot-window {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 380px;
    height: 600px;
    max-height: calc(100vh - 120px);
    background: var(--bg-primary, #ffffff);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    display: none !important;
    flex-direction: column;
    overflow: hidden;
    z-index: 9998;
}

.chatbot-window.open {
    display: flex !important;
    animation: slideUp 0.3s ease;
}

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

/* Chat Header */
.chatbot-header {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chatbot-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

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

.chatbot-title h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.chatbot-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    opacity: 0.9;
    margin-top: 2px;
}

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

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.chatbot-header-actions {
    display: flex;
    gap: 8px;
}

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

.chatbot-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Messages Area */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    background: var(--bg-secondary, #f9fafb);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

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

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

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

.chatbot-message {
    display: flex;
    gap: 8px;
    animation: messageIn 0.3s ease;
}

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

.chatbot-message.user {
    flex-direction: row-reverse;
}

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

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

.message-content {
    max-width: 70%;
}

.message-text {
    background: var(--bg-primary, white);
    padding: 12px 16px;
    border-radius: 12px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    word-wrap: break-word;
    word-break: break-word;
    line-height: 1.6;
    font-size: 14px;
    color: var(--text-primary, #1f2937);
    white-space: pre-wrap;
}

.chatbot-message-user .message-text {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
}

.message-bubble {
    background: var(--bg-primary, white);
    padding: 12px 16px;
    border-radius: 12px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    word-wrap: break-word;
    word-break: break-word;
    line-height: 1.6;
    font-size: 14px;
    color: var(--text-primary, #1f2937);
    white-space: pre-wrap;
}

.chatbot-message.user .message-bubble {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
}

.message-time {
    font-size: 11px;
    color: var(--text-secondary, #6b7280);
    margin-top: 4px;
    padding: 0 4px;
}

.chatbot-message.user .message-time {
    color: #9ca3af;
    text-align: right;
}

/* Quick Actions */
.chatbot-quick-actions {
    padding: 12px 16px;
    background: var(--bg-primary, #ffffff);
    border-top: 1px solid var(--border, #e5e7eb);
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.quick-action-btn {
    background: var(--bg-secondary, #f3f4f6);
    border: 1px solid var(--border, #e5e7eb);
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-primary, #1f2937);
}

.quick-action-btn:hover {
    background: #6366f1;
    color: white;
    border-color: #6366f1;
}

/* Input Container */
.chatbot-input-container {
    padding: 16px;
    background: var(--bg-primary, #ffffff);
    border-top: 1px solid var(--border, #e5e7eb);
    display: flex;
    gap: 8px;
    align-items: center;
}

.chatbot-input {
    flex: 1;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    background: var(--bg-secondary, #f9fafb);
    color: var(--text-primary, #1f2937);
}

.chatbot-input:focus {
    border-color: #6366f1;
    background: var(--bg-primary, white);
}

.chatbot-input::placeholder {
    color: #9ca3af;
}

.chatbot-attach-btn,
.chatbot-send-btn,
.chatbot-voice-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary, #6b7280);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chatbot-send-btn {
    background: #6366f1;
    color: white;
    width: 36px;
    height: 36px;
}

.chatbot-send-btn:hover {
    background: #4f46e5;
}

.chatbot-attach-btn:hover,
.chatbot-voice-btn:hover {
    background: var(--bg-secondary, #f3f4f6);
    color: var(--text-primary, #1f2937);
}

/* Typing Indicator */
.chatbot-typing-indicator {
    padding: 16px;
    display: flex;
    gap: 4px;
    align-items: center;
    background: var(--bg-secondary, #f9fafb);
}

.chatbot-typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary, #9ca3af);
    animation: typing 1.4s infinite;
}

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

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

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

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

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

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

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

/* Chart in message */
.message-chart {
    margin-top: 12px;
    padding: 12px;
    background: var(--bg-secondary, #f9fafb);
    border-radius: 8px;
}

/* Responsive */
@media (max-width: 480px) {
    .chatbot-window {
        width: calc(100vw - 40px);
        height: calc(100vh - 120px);
        bottom: 70px;
    }

    .chatbot-widget {
        right: 10px;
        bottom: 10px;
    }
}

/* Dark mode support */
[data-theme="dark"] .chatbot-window {
    background: var(--bg-primary);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .chatbot-messages {
    background: var(--bg-secondary);
}

[data-theme="dark"] .message-text {
    background: #374151;
    color: var(--text-primary);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

[data-theme="dark"] .message-bubble {
    background: #374151;
    color: var(--text-primary);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

[data-theme="dark"] .chatbot-input {
    background: #374151;
    border-color: #4b5563;
    color: var(--text-primary);
}

[data-theme="dark"] .chatbot-input:focus {
    background: #4b5563;
    border-color: #6366f1;
}

[data-theme="dark"] .chatbot-input::placeholder {
    color: #6b7280;
}

[data-theme="dark"] .quick-action-btn {
    background: #374151;
    border-color: #4b5563;
    color: var(--text-primary);
}

[data-theme="dark"] .message-text code,
[data-theme="dark"] .message-bubble code {
    background: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .chatbot-messages::-webkit-scrollbar-thumb {
    background: #4b5563;
}

[data-theme="dark"] .chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: #6b7280;
}

/* Also support prefers-color-scheme for automatic detection */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .chatbot-window {
        background: var(--bg-primary, #1f2937);
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    }

    :root:not([data-theme="light"]) .chatbot-messages {
        background: var(--bg-secondary, #111827);
    }

    :root:not([data-theme="light"]) .message-bubble {
        background: #374151;
        color: #f9fafb;
    }

    :root:not([data-theme="light"]) .chatbot-input {
        background: #374151;
        border-color: #4b5563;
        color: #f9fafb;
    }

    :root:not([data-theme="light"]) .chatbot-input:focus {
        background: #4b5563;
    }

    :root:not([data-theme="light"]) .quick-action-btn {
        background: #374151;
        border-color: #4b5563;
        color: #f9fafb;
    }
}

/* Minimized state */
.chatbot-window.minimized {
    height: 60px;
    overflow: hidden;
}

.chatbot-window.minimized .chatbot-messages,
.chatbot-window.minimized .chatbot-quick-actions,
.chatbot-window.minimized .chatbot-input-container,
.chatbot-window.minimized .chatbot-typing-indicator {
    display: none;
}
