/* Chatbot Styles */
.chatbot-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* Toggle Button */
.chatbot-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.3);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    color: white;
    font-size: 24px;
}

.chatbot-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.chatbot-toggle:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.5);
}

.chatbot-toggle.chatbot-open {
    transform: rotate(180deg);
}

/* Chat Window */
.chatbot-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 350px;
    height: 500px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chatbot-container.chatbot-open .chatbot-window {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* Header */
.chatbot-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: 16px 16px 0 0;
}

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

.chatbot-header-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chatbot-close,
.chatbot-maximize {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background-color 0.2s;
    font-size: 16px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chatbot-close:hover,
.chatbot-maximize:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.chatbot-close:focus,
.chatbot-maximize:focus {
    outline: none;
    background-color: rgba(255, 255, 255, 0.2);
}

/* Messages Area */
.chatbot-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    scroll-behavior: smooth;
    background: #f8f9fa;
}

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

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

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

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

/* Message Bubbles */
.chatbot-message {
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
    animation: messageSlideIn 0.3s ease-out;
}

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

.chatbot-message-content {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    line-height: 1.4;
    font-size: 14px;
    word-wrap: break-word;
}

.chatbot-message-user .chatbot-message-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.chatbot-message-bot .chatbot-message-content {
    background: white;
    color: #374151;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 4px;
}

.chatbot-message-error .chatbot-message-content {
    background: #fee2e2;
    color: #dc2626;
    border-color: #fecaca;
}

/* Timestamp */
.chatbot-message-timestamp {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 4px;
    padding: 0 4px;
}

.chatbot-message-user .chatbot-message-timestamp {
    text-align: right;
}

.chatbot-message-bot .chatbot-message-timestamp {
    text-align: left;
}

/* Typing Cursor */
.chatbot-cursor {
    display: inline-block;
    animation: blink 1s infinite;
    color: #667eea;
    font-weight: bold;
}

@keyframes blink {
    0%, 50% {
        opacity: 1;
    }
    51%, 100% {
        opacity: 0;
    }
}

/* Typing Indicator */
.chatbot-typing .chatbot-message-content {
    padding: 16px;
    background: white;
    border: 1px solid #e5e7eb;
}

.chatbot-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
}

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

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

.chatbot-typing-indicator 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;
    }
}

/* Input Area */
.chatbot-input-area {
    padding: 16px;
    border-top: 1px solid #e5e7eb;
    background: white;
    border-radius: 0 0 16px 16px;
}

.chatbot-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.chatbot-input-wrapper {
    flex: 1;
    position: relative;
}

.chatbot-input {
    width: 100%;
    min-height: 40px;
    max-height: 120px;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 20px;
    font-size: 14px;
    line-height: 1.4;
    resize: none;
    overflow-y: auto;
    background: white;
    transition: border-color 0.2s;
    font-family: inherit;
}

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

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

.chatbot-char-count {
    position: absolute;
    bottom: -18px;
    right: 0;
    font-size: 11px;
    color: #9ca3af;
}

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

.chatbot-send:hover {
    transform: scale(1.05);
}

.chatbot-send:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.3);
}

.chatbot-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* References */
.chatbot-references {
    margin-top: 12px;
    padding: 12px;
    background: #f8fafc;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.chatbot-references-title {
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chatbot-references-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chatbot-reference-link {
    display: inline-flex;
    align-items: center;
    font-size: 13px;
    color: #3b82f6;
    text-decoration: none;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
    line-height: 1.3;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chatbot-reference-link:hover {
    background: #dbeafe;
    color: #1d4ed8;
    text-decoration: underline;
}

.chatbot-reference-link:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}

.chatbot-reference-link::before {
    content: "🔗";
    margin-right: 6px;
    font-size: 11px;
}

/* Welcome Message */
.chatbot-welcome {
    text-align: center;
    color: #6b7280;
    font-size: 14px;
    margin: 20px 0;
    line-height: 1.5;
}

/* Responsive Design */
@media (max-width: 480px) {
    .chatbot-container {
        bottom: 10px;
        right: 10px;
    }

    .chatbot-window {
        width: calc(100vw - 40px);
        height: calc(100vh - 140px);
        max-height: 600px;
        right: -10px;
    }

    .chatbot-toggle {
        width: 56px;
        height: 56px;
        font-size: 22px;
    }

    .chatbot-window {
        bottom: 76px;
    }

    .chatbot-message-content {
        max-width: 85%;
        font-size: 15px;
    }

    .chatbot-input {
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

@media (max-width: 360px) {
    .chatbot-window {
        width: calc(100vw - 20px);
        right: -10px;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .chatbot-toggle {
        border: 2px solid white;
    }

    .chatbot-window {
        border: 2px solid #000;
    }

    .chatbot-message-content {
        border-width: 2px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .chatbot-toggle,
    .chatbot-window,
    .chatbot-message,
    .chatbot-send {
        transition: none;
        animation: none;
    }

    .chatbot-typing-indicator span {
        animation: none;
        opacity: 0.7;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .chatbot-window {
        background: #1f2937;
        border: 1px solid #374151;
    }

    .chatbot-messages {
        background: #111827;
    }

    .chatbot-message-bot .chatbot-message-content {
        background: #374151;
        color: #f3f4f6;
        border-color: #4b5563;
    }

    .chatbot-input-area {
        background: #1f2937;
        border-color: #374151;
    }

    .chatbot-input {
        background: #374151;
        border-color: #4b5563;
        color: #f3f4f6;
    }

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

    .chatbot-typing .chatbot-message-content {
        background: #374151;
        border-color: #4b5563;
    }

    .chatbot-welcome {
        color: #d1d5db;
    }

    .chatbot-references {
        background: #374151;
        border-color: #4b5563;
    }

    .chatbot-references-title {
        color: #9ca3af;
    }

    .chatbot-reference-link {
        color: #60a5fa;
    }

    .chatbot-reference-link:hover {
        background: #1e3a8a;
        color: #93c5fd;
    }
}

/* Maximized State */
.chatbot-container.chatbot-maximized .chatbot-window {
    position: fixed;
    top: 20px;
    left: 20px;
    right: 20px;
    bottom: 20px;
    width: auto;
    height: auto;
    max-width: none;
    max-height: none;
    z-index: 10000;
}

@media (max-width: 768px) {
    .chatbot-container.chatbot-maximized .chatbot-window {
        top: 10px;
        left: 10px;
        right: 10px;
        bottom: 10px;
    }
}

/* Code Block Styles */
.chatbot-code-block {
    margin: 12px 0;
    padding: 16px;
    border-radius: 6px;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    overflow-x: auto;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.4;
    white-space: pre-wrap;
}

.chatbot-code-block code {
    background: none;
    padding: 0;
    font-family: inherit;
    color: #212529;
}

/* Inline Code Styles */
.chatbot-inline-code {
    background: #f1f3f4;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Courier New', monospace;
    font-size: 0.9em;
    color: #d63384;
    border: 1px solid #e9ecef;
}

/* URL Link Styles */
.chatbot-url-link {
    color: #667eea;
    text-decoration: underline;
    transition: color 0.2s ease;
}

.chatbot-url-link:hover {
    color: #5a67d8;
    text-decoration: none;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .chatbot-code-block {
        font-size: 12px;
        padding: 12px;
    }
}