/* Chat Bubble Floating Widget */

#chatBubble {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: white;
    border: 3px solid #667eea;
    overflow: hidden;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transition: transform 0.3s, box-shadow 0.3s;
    z-index: 9999;
    animation: pulse 2s infinite;
}

#chatBubble img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

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

/* Encouragement Speech Bubble */
#chatEncouragement {
    position: fixed;
    bottom: 30px;
    right: 100px;
    background: white;
    border-radius: 16px;
    padding: 12px 16px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    z-index: 9998;
    max-width: 250px;
    opacity: 0;
    transform: translateX(20px);
    transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    pointer-events: none;
    cursor: pointer;
}

#chatEncouragement.show {
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
}

#chatEncouragement:hover {
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.25);
    transform: scale(1.02);
}

#chatEncouragement::after {
    content: '';
    position: absolute;
    right: -8px;
    bottom: 20px;
    width: 0;
    height: 0;
    border-left: 10px solid white;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
}

.encouragement-content {
    color: #333;
    font-size: 0.9rem;
    line-height: 1.4;
    margin: 0;
    transition: opacity 0.3s ease;
}

.encouragement-highlight {
    color: #667eea;
    font-weight: bold;
}

.encouragement-close {
    position: absolute;
    top: 4px;
    right: 6px;
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    font-size: 1.2rem;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
    transition: color 0.2s;
}

.encouragement-close:hover {
    color: #667eea;
}

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

#chatWindow {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 380px;
    height: 550px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    z-index: 10000;
    transform: scale(0);
    transform-origin: bottom right;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

#chatWindow.large {
    width: 500px;
    height: 700px;
}

#chatWindow.open {
    transform: scale(1);
    opacity: 1;
}

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

.chat-header-buttons {
    display: flex;
    gap: 0.5rem;
}

.chat-window-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: bold;
    font-size: 1.1rem;
}

.chat-window-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid white;
    overflow: hidden;
}

.chat-window-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-window-name {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.chat-window-name-main {
    font-size: 1.1rem;
    font-weight: bold;
}

.chat-window-name-subtitle {
    font-size: 0.75rem;
    opacity: 0.9;
    font-weight: normal;
}

.chat-close-btn,
.chat-resize-btn,
.chat-clear-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-close-btn {
    font-size: 1.2rem;
}

.chat-resize-btn {
    font-size: 1.1rem;
}

.chat-clear-btn {
    font-size: 1rem;
}

.chat-close-btn:hover,
.chat-resize-btn:hover,
.chat-clear-btn:hover {
    background: rgba(255,255,255,0.3);
}

.chat-window-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: #f8f9fa;
    overscroll-behavior: contain;  /* Prevent scroll chaining to parent */
}

.chat-message {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    animation: slideIn 0.3s ease-out;
}

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

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

.chat-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
    overflow: hidden;
}

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

.chat-message.user .chat-message-avatar {
    background: #667eea;
}

.chat-message.bot .chat-message-avatar {
    background: white;
    border: 2px solid #764ba2;
}

.chat-message-content {
    background: white;
    padding: 0.75rem;
    border-radius: 12px;
    max-width: 70%;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.chat-message.user .chat-message-content {
    background: #667eea;
    color: white;
}

.chat-message-content p {
    margin: 0 0 0.5rem 0;
    line-height: 1.4;
}

.chat-message-content p:last-child {
    margin-bottom: 0;
}

/* Message Feedback Buttons */
.message-feedback {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-top: 0.75rem;
    padding-top: 0.5rem;
    border-top: 1px solid #e0e0e0;
}

.feedback-label {
    font-size: 0.85rem;
    color: #666;
    margin-right: 0.25rem;
}

.feedback-btn {
    background: #f0f0f0;
    border: 2px solid transparent;
    border-radius: 6px;
    padding: 0.4rem 0.8rem;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.feedback-btn:hover {
    background: #e0e0e0;
    transform: scale(1.1);
}

.feedback-btn.active {
    border-color: #667eea;
    background: #f0f4ff;
}

.feedback-like.active {
    border-color: #10b981;
    background: #ecfdf5;
}

.feedback-dislike.active {
    border-color: #ef4444;
    background: #fef2f2;
}

.articles-list {
    margin-top: 0.75rem;
    padding-top: 0.5rem;
    border-top: 1px solid #e0e0e0;
}

.article-bubble-card {
    background: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 0.75rem;
    margin-top: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.article-bubble-card:hover {
    border-color: #667eea;
    transform: translateX(4px);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.15);
}

.article-bubble-card h4 {
    margin: 0 0 0.5rem 0;
    font-size: 0.9rem;
    line-height: 1.3;
    color: #333;
}

.article-source {
    margin: 0.25rem 0;
    font-size: 0.8rem;
    color: #666;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.article-date {
    margin: 0.25rem 0 0 0;
    font-size: 0.75rem;
    color: #999;
}

.bias-badge {
    display: inline-block;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: bold;
    color: white;
}

.chat-window-typing {
    padding: 0.5rem 1rem;
    display: flex;
    gap: 0.3rem;
    align-items: center;
    background: #f8f9fa;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #667eea;
    animation: typingDot 1.4s infinite;
}

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

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

@keyframes typingDot {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-10px); }
}

.chat-window-input {
    padding: 1rem;
    background: white;
    border-radius: 0;
    display: flex;
    gap: 0.5rem;
    border-top: 1px solid #e0e0e0;
}

#chatWindowInput {
    flex: 1;
    padding: 0.75rem;
    border: 2px solid #e0e0e0;
    border-radius: 20px;
    outline: none;
    font-size: 0.9rem;
    transition: border-color 0.3s;
}

#chatWindowInput:focus {
    border-color: #667eea;
}

#chatWindowSend {
    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: transform 0.2s;
}

#chatWindowSend:hover:not(:disabled) {
    transform: scale(1.1);
}

#chatWindowSend:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    #chatWindow {
        width: calc(100% - 40px);
        height: calc(100% - 40px);
        bottom: 20px;
        right: 20px;
        left: 20px;
        max-width: 400px;
        margin: 0 auto;
    }

    #chatWindow.large {
        width: calc(100% - 20px);
        height: calc(100% - 20px);
        bottom: 10px;
        right: 10px;
        left: 10px;
    }

    #chatBubble {
        bottom: 15px;
        right: 15px;
        width: 56px;
        height: 56px;
        font-size: 26px;
    }

    #chatEncouragement {
        bottom: 20px;
        right: 85px;
        max-width: 200px;
        font-size: 0.85rem;
        padding: 10px 14px;
    }

    #chatEncouragement::after {
        right: -6px;
        bottom: 15px;
        border-left-width: 8px;
    }
}

/* Chat Window Footer - "Powered by" text */
.chat-window-footer {
    padding: 0.6rem 1rem;
    text-align: center;
    font-size: 0.75rem;
    color: #999;
    background: #f8f9fa;
    border-top: 1px solid #e0e0e0;
    border-radius: 0 0 16px 16px;
}

.chat-window-footer a {
    color: #667eea;
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s;
}

.chat-window-footer a:hover {
    color: #764ba2;
    text-decoration: underline;
}
