/**
 * Community Chat Widget Styles
 * Integrated chat system for blogs, courses, and pages
 */

/* ============================
   CHAT WIDGET CONTAINER
   ============================ */
.community-chat-widget {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
    margin-top: 2rem;
    box-shadow: 0 4px 24px rgba(0,0,0,0.08);
}

/* ============================
   CHAT HEADER
   ============================ */
.chat-widget-header {
    background: linear-gradient(135deg, var(--brand) 0%, #6366f1 100%);
    color: #fff;
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.chat-header-icon {
    width: 44px;
    height: 44px;
    background: rgba(255,255,255,0.2);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.chat-header-info h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
}

.chat-header-info p {
    margin: 0;
    font-size: 0.8rem;
    opacity: 0.9;
}

.chat-online-badge {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    background: rgba(255,255,255,0.15);
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
}

.chat-online-badge .online-dot {
    width: 8px;
    height: 8px;
    background: #22c55e;
    border-radius: 50%;
    animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.2); }
}

/* ============================
   CHAT MESSAGES AREA
   ============================ */
.chat-messages-area {
    height: 400px;
    overflow-y: auto;
    padding: 1rem 1.5rem;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.chat-messages-area::-webkit-scrollbar {
    width: 6px;
}

.chat-messages-area::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages-area::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

/* Empty State */
.chat-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--muted);
    padding: 2rem;
}

.chat-empty-state .empty-icon {
    width: 80px;
    height: 80px;
    background: var(--card);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    color: var(--brand);
    margin-bottom: 1rem;
    border: 2px dashed var(--border);
}

.chat-empty-state h4 {
    margin: 0 0 0.5rem;
    color: var(--text);
    font-size: 1.1rem;
}

.chat-empty-state p {
    margin: 0;
    font-size: 0.9rem;
    max-width: 280px;
}

.quick-prompts {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    margin-top: 1.25rem;
}

.quick-prompt-btn {
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.quick-prompt-btn:hover {
    background: var(--brand);
    color: #fff;
    border-color: var(--brand);
    transform: translateY(-1px);
}

/* ============================
   MESSAGE BUBBLES
   ============================ */
.chat-message {
    display: flex;
    gap: 0.75rem;
    max-width: 85%;
    animation: messageSlideIn 0.3s ease;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.user-message {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-message.ai-message,
.chat-message.human-message {
    align-self: flex-start;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: 600;
    flex-shrink: 0;
}

.chat-message.user-message .message-avatar {
    background: var(--brand);
    color: #fff;
}

.chat-message.ai-message .message-avatar {
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    color: #fff;
}

.chat-message.human-message .message-avatar {
    background: #22c55e;
    color: #fff;
}

.message-content {
    flex: 1;
}

.message-bubble {
    padding: 0.875rem 1rem;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.5;
}

.chat-message.user-message .message-bubble {
    background: var(--brand);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-message.ai-message .message-bubble,
.chat-message.human-message .message-bubble {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.message-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.35rem;
    font-size: 0.75rem;
    color: var(--muted);
}

.chat-message.user-message .message-meta {
    justify-content: flex-end;
}

.message-sender {
    font-weight: 600;
}

.ai-badge {
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    color: #fff;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
}

.volunteer-badge {
    background: #22c55e;
    color: #fff;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
}

/* AI Thinking Animation */
.chat-message.ai-thinking .message-bubble {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.thinking-dots {
    display: flex;
    gap: 4px;
}

.thinking-dots span {
    width: 8px;
    height: 8px;
    background: var(--brand);
    border-radius: 50%;
    animation: thinkingBounce 1.4s infinite ease-in-out;
}

.thinking-dots span:nth-child(1) { animation-delay: 0s; }
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes thinkingBounce {
    0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

/* Message Actions */
.message-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.message-action-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    transition: all 0.2s ease;
}

.message-action-btn:hover {
    background: var(--brand);
    color: #fff;
    border-color: var(--brand);
}

.message-action-btn.voted {
    background: var(--brand);
    color: #fff;
    border-color: var(--brand);
}

/* ============================
   CHAT INPUT AREA
   ============================ */
.chat-input-area {
    padding: 1rem 1.5rem;
    background: var(--card);
    border-top: 1px solid var(--border);
}

.chat-context-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: rgba(99, 102, 241, 0.1);
    border-radius: 8px;
    font-size: 0.8rem;
    color: var(--brand);
}

.chat-context-bar i {
    font-size: 0.9rem;
}

.context-truncate {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-input-wrapper {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

.chat-input-container {
    flex: 1;
    position: relative;
}

.chat-input {
    width: 100%;
    padding: 0.875rem 1rem;
    padding-right: 90px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 24px;
    color: var(--text);
    font-size: 0.9rem;
    resize: none;
    min-height: 48px;
    max-height: 120px;
    line-height: 1.4;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-input:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.chat-input::placeholder {
    color: var(--muted);
}

.chat-input-actions {
    position: absolute;
    right: 8px;
    bottom: 8px;
    display: flex;
    gap: 0.35rem;
}

.input-action-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.input-action-btn:hover {
    color: var(--brand);
    background: rgba(99, 102, 241, 0.1);
}

.chat-send-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: var(--brand);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chat-send-btn:hover {
    background: #4f46e5;
    transform: scale(1.05);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ============================
   ASK AI TOGGLE
   ============================ */
.ask-ai-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
    margin-bottom: 0.5rem;
}

.ask-ai-toggle label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text);
    cursor: pointer;
}

.ai-toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
}

.ai-toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.ai-toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--border);
    border-radius: 24px;
    transition: 0.3s ease;
}

.ai-toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: 0.3s ease;
}

.ai-toggle-switch input:checked + .ai-toggle-slider {
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
}

.ai-toggle-switch input:checked + .ai-toggle-slider:before {
    transform: translateX(20px);
}

.ai-toggle-label {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.ai-toggle-label i {
    color: #8b5cf6;
}

/* ============================
   LOGIN PROMPT
   ============================ */
.chat-login-prompt {
    padding: 2rem;
    text-align: center;
    background: var(--bg);
}

.chat-login-prompt p {
    margin: 0 0 1rem;
    color: var(--muted);
}

.chat-login-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--brand);
    color: #fff;
    padding: 0.75rem 1.5rem;
    border-radius: 24px;
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s ease;
}

.chat-login-btn:hover {
    background: #4f46e5;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

/* ============================
   CONTEXT MODAL
   ============================ */
.context-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.context-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.context-modal {
    background: var(--card);
    border-radius: 16px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow: hidden;
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.context-modal-overlay.active .context-modal {
    transform: translateY(0);
}

.context-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.context-modal-header h4 {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.context-modal-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.context-modal-close:hover {
    background: var(--bg);
    color: var(--text);
}

.context-modal-body {
    padding: 1.5rem;
    max-height: 60vh;
    overflow-y: auto;
}

.context-section {
    margin-bottom: 1.5rem;
}

.context-section:last-child {
    margin-bottom: 0;
}

.context-section h5 {
    font-size: 0.85rem;
    color: var(--muted);
    margin: 0 0 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.context-section p,
.context-section ul {
    margin: 0;
    font-size: 0.9rem;
    color: var(--text);
}

.context-section ul {
    list-style: none;
    padding: 0;
}

.context-section ul li {
    padding: 0.5rem 0;
    padding-left: 0;
    position: relative;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.context-section ul li:last-child {
    border-bottom: none;
}

.context-toc-list .toc-num {
    color: var(--brand);
    font-weight: 600;
    min-width: 24px;
}

.context-summary {
    font-size: 0.85rem;
    line-height: 1.6;
    color: var(--muted);
    background: var(--bg);
    padding: 0.75rem;
    border-radius: 8px;
}

.context-section ul li::before {
    content: "•";
    position: absolute;
    left: 0;
    color: var(--brand);
}

/* ============================
   FLOATING CHAT BUTTON
   ============================ */
.chat-float-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand) 0%, #6366f1 100%);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
    z-index: 999;
    transition: all 0.3s ease;
}

.chat-float-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 24px rgba(99, 102, 241, 0.5);
}

.chat-float-btn .unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 20px;
    height: 20px;
    background: #ef4444;
    border-radius: 50%;
    font-size: 0.7rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================
   RESPONSIVE
   ============================ */
@media (max-width: 768px) {
    .community-chat-widget {
        border-radius: 0;
        margin: 1rem -1rem 0;
        width: calc(100% + 2rem);
    }
    
    .chat-widget-header {
        padding: 1rem;
    }
    
    .chat-header-icon {
        width: 38px;
        height: 38px;
        font-size: 1rem;
    }
    
    .chat-online-badge {
        display: none;
    }
    
    .chat-messages-area {
        height: 350px;
        padding: 1rem;
    }
    
    .chat-message {
        max-width: 90%;
    }
    
    .chat-input-area {
        padding: 0.875rem 1rem;
    }
    
    .chat-input {
        padding-right: 50px;
    }
    
    .chat-input-actions {
        display: none;
    }
    
    .quick-prompts {
        flex-direction: column;
    }
    
    .quick-prompt-btn {
        width: 100%;
    }
}
