/* Widget Container */
.chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 10000;
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Chat Toggle Button */
.chat-toggle {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(79, 70, 229, 0.3);
    transition: all 0.3s ease;
    color: white;
    font-size: 24px;
    position: relative;
}

/* NEW: Preview Message Bubble */
.preview-message {
    position: absolute;
    bottom: 80px;
    right: 0;
    background: white;
    padding: 12px 16px;
    border-radius: 20px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
    border: 1px solid #e5e7eb;
    max-width: 200px;
    opacity: 0;
    transform: translateY(10px) scale(0.9);
    transition: all 0.3s ease;
    cursor: pointer;
    z-index: 9999;
}

.preview-message.show {
    opacity: 1;
    transform: translateY(0) scale(1);
    animation: slideInPreview 0.5s ease-out;
}

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

.preview-message .preview-text {
    font-size: 14px;
    color: #374151;
    margin: 0;
    font-weight: 500;
}

.preview-message .preview-subtitle {
    font-size: 12px;
    color: #6b7280;
    margin: 4px 0 0 0;
}

.preview-message .preview-close {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.preview-message .preview-close:hover {
    background: #dc2626;
    transform: scale(1.1);
}

/* Pulse animation for chat button when preview is shown */
.chat-toggle.with-preview {
    animation: gentlePulse 2s infinite;
}

@keyframes gentlePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* Chat Container - Now Resizable */
.chat-container {
    width: 350px;
    height: 500px;
    min-width: 280px;
    min-height: 400px;
    max-width: 600px;
    max-height: 80vh;
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
    display: none;
    flex-direction: column;
    position: absolute;
    bottom: 80px;
    right: 0;
    overflow: hidden;
    border: 1px solid rgba(229, 231, 235, 0.8);
    resize: both;
}

.chat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 30px rgba(79, 70, 229, 0.4);
}

.chat-toggle.open {
    background: #ef4444;
}

.chat-container.open {
    display: flex;
    animation: slideUp 0.3s ease-out;
}

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

/* Chat Header */
.chat-header {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: white;
    padding: 16px;
    text-align: center;
    position: relative;
}

.chat-header h3 {
    margin: 0 0 4px 0;
    font-size: 16px;
    font-weight: 600;
}

.chat-header p {
    margin: 0;
    font-size: 12px;
    opacity: 0.9;
}

.chat-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    opacity: 0.8;
    padding: 4px;
}

.chat-close:hover {
    opacity: 1;
}

/* Messages Area */
.chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: #f8fafc;
}

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

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(79, 70, 229, 0.3);
    border-radius: 4px;
}

.message {
    margin-bottom: 12px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    animation: fadeIn 0.3s ease-out;
}

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

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

.message-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.message.bot .message-avatar {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: white;
}

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

.message-content {
    max-width: 250px;
    padding: 10px 12px;
    border-radius: 16px;
    font-size: 13px;
    line-height: 1.4;
    word-wrap: break-word;
}

.message.bot .message-content {
    background: white;
    color: #374151;
    border: 1px solid #e5e7eb;
}

.message.user .message-content {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: white;
}

/* Message Formatting */
.message-content strong {
    font-weight: 600;
    color: #1f2937;
}

.message.user .message-content strong {
    color: white;
}

.bullet-point {
    margin: 4px 0;
    line-height: 1.3;
}

/* Typing Indicator */
.typing-indicator {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: white;
    border-radius: 16px;
    border: 1px solid #e5e7eb;
    margin-bottom: 12px;
}

.typing-dots {
    display: flex;
    gap: 3px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: #9ca3af;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

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

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

/* Input Area */
.chat-input-container {
    padding: 12px;
    background: white;
    border-top: 1px solid #e5e7eb;
}

.input-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
    background: #f3f4f6;
    border-radius: 20px;
    padding: 6px;
}

.chat-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 8px 12px;
    font-size: 13px;
    outline: none;
    resize: none;
    max-height: 60px;
    font-family: inherit;
}

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

.send-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.2s ease;
}

.send-btn:hover {
    transform: scale(1.1);
}

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

/* Notification Badge */
.notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ef4444;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
    display: none;
    animation: bounce 1s infinite;
}

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

/* Quick Actions */
.quick-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.quick-btn {
    background: rgba(79, 70, 229, 0.1);
    color: #4f46e5;
    border: 1px solid rgba(79, 70, 229, 0.2);
    border-radius: 12px;
    padding: 4px 8px;
    font-size: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.quick-btn:hover {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: white;
    transform: translateY(-1px);
}

/* Mobile Responsiveness */
@media (max-width: 480px) {
    .chat-widget {
        bottom: 10px;
        right: 10px;
    }
    
    .chat-container {
        width: 320px;
        height: 450px;
        bottom: 70px;
        right: -10px;
    }
    
    .preview-message {
        max-width: 180px;
        bottom: 70px;
        right: -5px;
    }
    
    .chat-toggle {
        width: 55px;
        height: 55px;
        font-size: 20px;
    }
}

@media (max-width: 380px) {
    .chat-container {
        width: 300px;
        right: -5px;
    }
    
    .preview-message {
        max-width: 160px;
        right: 0;
    }
}

/* Accessibility */
.chat-toggle:focus,
.chat-close:focus,
.send-btn:focus,
.quick-btn:focus,
.preview-close:focus {
    outline: 2px solid #4f46e5;
    outline-offset: 2px;
}

.chat-input:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.3);
    border-radius: 8px;
}

.chunk-info {
    margin-top: 8px;
    padding: 8px;
    background: rgba(231, 76, 60, 0.1);
    border-radius: 4px;
    font-size: 0.85em;
}

.continue-hint {
    color: #666;
    font-style: italic;
}

.continuation-prompt {
    margin: 10px 0;
    text-align: center;
}

/* Course Selection Buttons */
.course-selection {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

.course-btn {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 8px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.course-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.additional-options {
    display: flex;
    gap: 6px;
    margin-top: 10px;
}

.option-btn {
    background: rgba(231, 76, 60, 0.1);
    color: #e74c3c;
    border: 1px solid rgba(231, 76, 60, 0.2);
    border-radius: 8px;
    padding: 4px 8px;
    font-size: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.option-btn:hover {
    background: #e74c3c;
    color: white;
}

/* Options Button */
.chat-options {
    position: absolute;
    top: 12px;
    right: 45px;
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    opacity: 0.8;
    padding: 4px;
    border-radius: 3px;
    transition: all 0.2s ease;
}

.chat-options:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

/* Options Menu */
.options-menu {
    display: none;
    position: absolute;
    top: 45px;
    right: 10px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
    border: 1px solid #e5e7eb;
    min-width: 200px;
    z-index: 1000;
}

.options-header {
    padding: 12px 16px 8px 16px;
    font-size: 14px;
    font-weight: 600;
    color: #6b7280;
    border-bottom: 1px solid #f3f4f6;
}

.option-item {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-size: 14px;
    color: #374151;
}

.option-item:hover {
    background-color: #f9fafb;
}

.option-item:last-child {
    border-radius: 0 0 12px 12px;
}

.option-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
}