/* =========================================
   WHATSAPP-STYLE AI CHAT UI (Blue Theme)
   ========================================= */

/* Modal Content Base */
.ai-chat-content {
    background-color: #f0f2f5;
    /* Light grey/blue background similar to WhatsApp */
    border-radius: 16px;
    overflow: hidden;
    position: relative;
}

/* Chat Header - WhatsApp style but Blue */
.ai-chat-header {
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    padding: 12px 16px;
    color: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    z-index: 10;
}

.ai-chat-header h2 {
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
}

/* Close Button - Standard Popup Position */
.ai-chat-close-btn {
    position: absolute;
    top: 14px;
    right: 14px;
    background: white;
    border: 1px solid #e2e8f0;
    color: #64748b;
    cursor: pointer;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 200;
    /* Ensure above header actions */
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    font-size: 16px;
}

.ai-chat-close-btn:hover {
    background: #f1f5f9;
    color: #ef4444;
    border-color: #ef4444;
    transform: rotate(90deg);
}

/* Header Actions Container */
.ai-chat-header-actions {
    position: absolute;
    top: 12px;
    right: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 100;
}

/* Unified Header Button Style (Glassmorphism) */
.ai-chat-header-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    cursor: pointer;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-size: 14px;
    backdrop-filter: blur(4px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.ai-chat-header-btn:hover {
    background: white;
    color: #2563eb;
    /* Blue text */
    transform: translateY(-2px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    border-color: white;
}

/* Specific hover color for Trash (optional, but nice) */
.ai-chat-header-btn[title*="Nueva"] :hover {
    color: #ef4444;
}

.ai-chat-header .ai-chat-credits {
    font-size: 0.8rem;
    opacity: 0.9;
    color: #eff6ff;
}

/* Messages Area - The "Wallpaper" */
.ai-chat-messages {
    background-color: #e5e7eb;
    /* Slightly darker to make bubbles pop */
    background-image:
        radial-gradient(circle at 2px 2px, rgba(59, 130, 246, 0.05) 1px, transparent 0);
    background-size: 24px 24px;
    padding: 20px 15px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Message Bubbles - Modern WhatsApp Look */
.ai-message-bubble {
    max-width: 80%;
    position: relative;
    padding: 6px 12px;
    font-size: 0.95rem;
    line-height: 1.4;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    animation: bubblePop 0.2s ease-out;
}

@keyframes bubblePop {
    from {
        transform: scale(0.95);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* USER Bubble (Right / Light Blue) */
.ai-message-bubble.user {
    align-self: flex-end;
    background-color: transparent !important;
    box-shadow: none !important;
}

.ai-message-bubble.user .ai-message-content {
    background: #dbeafe !important;
    color: #1e293b !important;
    border-radius: 12px 12px 0 12px;
    padding: 8px 12px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* ASSISTANT Bubble (Left / White) */
.ai-message-bubble.assistant {
    align-self: flex-start;
    background-color: transparent !important;
    box-shadow: none !important;
}

.ai-message-bubble.assistant .ai-message-content {
    background-color: #ffffff !important;
    color: #1e293b !important;
    border-radius: 12px 12px 12px 0;
    padding: 8px 12px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    border: 1px solid #e2e8f0;
}

/* Message Content - Markdown Support */
.ai-message-content {
    word-wrap: break-word;
}

.ai-message-content p {
    margin: 2px 0;
}

.ai-message-content h1,
.ai-message-content h2,
.ai-message-content h3 {
    margin: 8px 0 4px 0;
    line-height: 1.2;
}

.ai-message-content ul,
.ai-message-content ol {
    margin: 4px 0;
    padding-left: 20px;
}

.ai-message-content li {
    margin: 2px 0;
}

.ai-message-content strong {
    font-weight: 700;
    color: inherit;
}

/* Markdown specific colors in assistant bubbles */
.ai-message-bubble.assistant .ai-message-content code {
    background: #f1f5f9;
    color: #2563eb;
    padding: 2px 4px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
}

.ai-message-bubble.assistant .ai-message-content pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 10px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}

/* Input Area - Pill Style */
.ai-chat-input-area {
    background: #f0f2f5;
    padding: 10px 15px;
    border-top: 1px solid #e2e8f0;
}

.ai-chat-input-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    background: white;
    padding: 5px 15px;
    border-radius: 25px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.ai-chat-input {
    border: none !important;
    background: transparent;
    padding: 10px 0;
    font-size: 0.95rem;
    max-height: 100px;
    box-shadow: none !important;
}

.ai-chat-input:focus {
    outline: none !important;
}

.ai-chat-send-btn {
    background: transparent !important;
    color: #3b82f6 !important;
    border: none !important;
    padding: 5px !important;
    font-size: 1.2rem !important;
    cursor: pointer;
    transition: transform 0.2s;
    box-shadow: none !important;
}

.ai-chat-send-btn span {
    display: none;
    /* Hide text, use icon only */
}

.ai-chat-send-btn:hover {
    transform: scale(1.1);
    color: #2563eb !important;
}

/* Manual Generation Button - Modern Pill */
.ai-chat-manual-gen-btn {
    background: #ffffff !important;
    color: #3b82f6 !important;
    border: 1px solid #3b82f6 !important;
    border-radius: 20px !important;
    padding: 6px 16px !important;
    font-size: 0.85rem !important;
    margin-bottom: 10px !important;
    margin-left: auto;
    margin-right: auto;
    display: flex;
    width: fit-content;
    box-shadow: 0 2px 5px rgba(59, 130, 246, 0.1) !important;
}

.ai-chat-manual-gen-btn:hover {
    background: #eff6ff !important;
    transform: translateY(-1px);
}

/* Diagram Action Card - Lilac Success */
.diagram-action-card {
    background: #f5f3ff;
    border: 1.5px solid #8b5cf6;
    border-radius: 12px;
    padding: 12px;
    margin: 10px 0;
    text-align: center;
}

.btn-generate-diagram {
    background: #8b5cf6 !important;
    color: white !important;
    border-radius: 8px !important;
    padding: 8px 16px !important;
    font-weight: 600 !important;
    margin-top: 8px !important;
}

/* Responsive */
@media (max-width: 600px) {
    .ai-chat-content {
        width: 100%;
        height: 100vh;
        border-radius: 0;
    }
}

/* Select-to-Quote Floating Button */
.ai-chat-quote-btn {
    position: absolute;
    background: white;
    color: #3b82f6;
    border: 1px solid #3b82f6;
    border-radius: 20px;
    padding: 6px 12px;
    font-size: 0.85rem;
    font-weight: 600;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 5px;
    animation: popIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: auto;
}

.ai-chat-quote-btn:hover {
    background: #eff6ff;
    transform: translateY(-2px);
    box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
}

.ai-chat-quote-btn i {
    font-size: 0.8rem;
}

@keyframes popIn {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(10px);
    }

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