/* ==========================================
   CHATBOT WIDGET WITH ANIMATED AVATAR
   ========================================== */

/* Chatbot Toggle Button (Floating Avatar) */
.chatbot-widget {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 9999;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.chatbot-avatar-button {
    position: relative;
    cursor: pointer;
    transition: transform 0.3s ease;
}

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

.avatar-container {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    overflow: hidden;
    border: 4px solid #00d4ff;
    box-shadow: 0 8px 30px rgba(0, 212, 255, 0.4);
    animation: avatarIdle 3s ease-in-out infinite;
}

@keyframes avatarIdle {

    0%,
    100% {
        transform: translateY(0px);
    }

    50% {
        transform: translateY(-8px);
    }
}

.avatar-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center top;
}

.avatar-status-indicator {
    position: absolute;
    bottom: 5px;
    right: 5px;
    width: 16px;
    height: 16px;
    background: #10b981;
    border-radius: 50%;
    border: 3px solid white;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.2);
        opacity: 0.8;
    }
}

.avatar-wave-hand {
    position: absolute;
    top: -10px;
    right: -10px;
    font-size: 2rem;
    animation: wave 1.5s ease-in-out infinite;
    transform-origin: 70% 70%;
}

@keyframes wave {

    0%,
    100% {
        transform: rotate(0deg);
    }

    10%,
    30% {
        transform: rotate(14deg);
    }

    20%,
    40% {
        transform: rotate(-8deg);
    }

    50%,
    60% {
        transform: rotate(14deg);
    }

    70% {
        transform: rotate(-4deg);
    }

    80% {
        transform: rotate(10deg);
    }
}

.avatar-greeting-bubble {
    position: absolute;
    bottom: 100%;
    right: 0;
    margin-bottom: 15px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    backdrop-filter: blur(20px);
    padding: 0.8rem 1.2rem;
    border-radius: 15px;
    color: var(--text-primary);
    font-weight: 600;
    white-space: nowrap;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
    animation: bubbleBounce 2s ease-in-out infinite;
}

.avatar-greeting-bubble::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 20px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid var(--card-border);
}

@keyframes bubbleBounce {

    0%,
    100% {
        transform: translateY(0px);
    }

    50% {
        transform: translateY(-5px);
    }
}

/* Chatbot Window */
.chatbot-window {
    position: absolute;
    bottom: 20px;
    right: 0;
    /* Align with right edge of the widget */
    width: 400px;
    min-width: 300px;
    max-width: calc(100vw - 2rem);
    height: 600px;
    min-height: 400px;
    max-height: calc(100vh - 150px);
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    display: none;
    flex-direction: column;
    overflow: hidden;
    resize: both;
    /* Enable resizing */
    animation: slideUpFade 0.3s ease;
}

.chatbot-window.active {
    display: flex;
}

@keyframes slideUpFade {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Chatbot Header */
.chatbot-header {
    display: flex;
    align-items: center;
    padding: 1.2rem;
    background: linear-gradient(135deg, #00d4ff, #7b2ff7);
    color: white;
    cursor: grab;
    /* Indicate draggability */
}

.chatbot-header:active {
    cursor: grabbing;
}

.chatbot-header-avatar {
    position: relative;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid white;
    margin-right: 1rem;
}

.chatbot-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center top;
}

.status-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 10px;
    height: 10px;
    background: #10b981;
    border-radius: 50%;
    border: 2px solid white;
}

.chatbot-header-info {
    flex: 1;
}

.chatbot-header-info h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
}

.status-text {
    margin: 0;
    font-size: 0.85rem;
    opacity: 0.9;
}

.chatbot-header-actions {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.chatbot-close,
.chatbot-export-btn {
    background: transparent;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.chatbot-close:hover,
.chatbot-export-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Message bubble wrapper (bot messages) */
.message-bubble-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 75%;
}

/* Streaming text cursor effect */
.stream-text::after {
    content: '▍';
    animation: blink 1s step-end infinite;
    color: #00d4ff;
    font-size: 0.8em;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

/* Message Footer: sources + feedback */
.message-meta-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.5rem;
    align-items: center;
}

/* Source Verification Badges (Proposal 1) */
.source-verification {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.2rem;
}

.verification-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.8rem;
    border-radius: 15px;
    font-size: 0.75rem;
    font-weight: 600;
    width: fit-content;
    user-select: none;
    transition: background 0.2s ease;
}

.badge-verified {
    background: rgba(16, 185, 129, 0.15);
    border: 1px solid rgba(16, 185, 129, 0.4);
    color: #10b981;
    cursor: pointer;
    /* Indicates it can be clicked to show sources */
}

.badge-verified:hover {
    background: rgba(16, 185, 129, 0.25);
}

.badge-genai {
    background: rgba(139, 92, 246, 0.15);
    border: 1px solid rgba(139, 92, 246, 0.4);
    color: #8b5cf6;
    cursor: help;
    /* Indicates tooltip on hover */
}

/* M1: Source citation chips */
.source-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.source-chip {
    display: inline-flex;
    align-items: center;
    background: rgba(0, 212, 255, 0.1);
    border: 1px solid rgba(0, 212, 255, 0.3);
    border-radius: 12px;
    padding: 0.2rem 0.6rem;
    font-size: 0.72rem;
    color: var(--text-secondary);
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: default;
}

/* H2: Feedback buttons */
.feedback-row {
    display: flex;
    gap: 0.3rem;
    margin-left: auto;
}

.feedback-btn {
    background: transparent;
    border: 1px solid var(--card-border);
    border-radius: 50%;
    width: 28px;
    height: 28px;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    line-height: 1;
}

.feedback-btn:hover {
    background: rgba(0, 212, 255, 0.1);
    border-color: #00d4ff;
    transform: scale(1.15);
}

/* M2: Typing indicator label */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.8rem 1rem;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 15px 15px 15px 5px;
}

.typing-label {
    font-size: 0.82rem;
    color: var(--text-secondary);
    font-style: italic;
    margin-right: 0.2rem;
}


/* Messages Container */
.chatbot-messages {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    background: rgba(var(--bg-primary), 0.3);
}

.message {
    display: flex;
    gap: 0.8rem;
    margin-bottom: 1.5rem;
    animation: messageSlideIn 0.3s ease;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-avatar {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center top;
}

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

.bot-message .message-content {
    background: var(--bg-primary);
    border: 1px solid var(--card-border);
    padding: 0.9rem 1.2rem;
    border-radius: 15px 15px 15px 5px;
}

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

.user-message .message-content {
    background: linear-gradient(135deg, #00d4ff, #7b2ff7);
    color: white;
    padding: 0.9rem 1.2rem;
    border-radius: 15px 15px 5px 15px;
}

.message-content p {
    margin: 0;
    color: inherit;
    line-height: 1.5;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 0.3rem;
    padding: 1rem;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite;
}

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

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

@keyframes typingBounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
    }

    30% {
        transform: translateY(-10px);
    }
}

/* Quick Actions */
.chatbot-quick-actions {
    padding: 1rem;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    background: var(--bg-secondary);
    border-top: 1px solid var(--card-border);
}

.quick-action-btn {
    padding: 0.6rem 1rem;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.quick-action-btn:hover {
    background: rgba(0, 212, 255, 0.1);
    border-color: #00d4ff;
    transform: translateY(-2px);
}

/* Input Area */
.chatbot-input-area {
    display: flex;
    padding: 1rem;
    gap: 0.8rem;
    border-top: 1px solid var(--card-border);
    background: var(--card-bg);
}

.chatbot-input {
    flex: 1;
    padding: 0.8rem 1rem;
    background: var(--bg-primary);
    border: 1px solid var(--card-border);
    border-radius: 25px;
    color: var(--text-primary);
    outline: none;
}

.chatbot-input:focus {
    border-color: #00d4ff;
    background: rgba(0, 212, 255, 0.05);
}

.chatbot-send-btn {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: linear-gradient(135deg, #00d4ff, #7b2ff7);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
}

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

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

/* Responsive */
@media (max-width: 768px) {
    .chatbot-window {
        width: calc(100vw - 2rem);
        height: calc(100vh - 120px);
        bottom: 110px;
        right: 0;
        /* Reset on mobile so it takes full width */
    }

    .chatbot-widget {
        bottom: 1rem;
        right: 1rem;
    }
}
/* New UI Enhancements */
.chatbot-image-preview-container {
    transition: all 0.3s ease;
}
.chatbot-remove-img-btn {
    position: absolute;
    top: -8px; 
    right: -8px; 
    background: #ef4444; 
    color: white; 
    border: none; 
    border-radius: 50%; 
    width: 24px; 
    height: 24px; 
    cursor: pointer; 
    display: flex; 
    align-items: center; 
    justify-content: center;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), background 0.2s;
    box-shadow: 0 2px 5px rgba(239, 68, 68, 0.4);
}
.chatbot-remove-img-btn:hover {
    transform: scale(1.15) rotate(90deg);
    background: #dc2626;
}
.chatbot-image-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: rgba(0,0,0,0.1);
    border-radius: 0 0 8px 8px;
    overflow: hidden;
}
.chatbot-image-progress-bar {
    width: 0%;
    height: 100%;
    background: #00d4ff;
    transition: width 0.3s ease;
}

/* User Message Bubble Gradient Fix */
.user-message .message-content {
    background: linear-gradient(135deg, #e07a5f, #f4a261) !important;
    color: white !important;
    box-shadow: 0 4px 15px rgba(224, 122, 95, 0.2);
}

/* Markdown Rendering Styles */
.message-content h1, .message-content h2, .message-content h3 {
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
    font-size: 1.1em;
}
.message-content p {
    margin-bottom: 0.5rem;
}
.message-content p:last-child {
    margin-bottom: 0;
}
.message-content ul, .message-content ol {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}
.message-content li {
    margin-bottom: 0.2rem;
}
.message-content pre {
    background: rgba(0,0,0,0.05);
    padding: 0.8rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.5rem 0;
}
.message-content code {
    background: rgba(0,0,0,0.05);
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}

