/* ==========================================
   TRADE GENIE - PREMIUM AI UI
   ========================================== */

:root {
    --ai-primary: #6366f1;
    --ai-secondary: #8b5cf6;
    --ai-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --ai-bg: #ffffff;
    --ai-text: #1e293b;
    --ai-text-muted: #64748b;
    --ai-border: #e2e8f0;
}

/* ===== FLOATING BUTTON ===== */
.ai-chat-button {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    height: 85px;
    padding: 0 5px;
    border-radius: 24px;
    background: var(--ai-gradient);
    border: none;
    box-shadow: 0 10px 25px rgba(99, 102, 241, 0.4), inset 0 0 15px rgba(255, 255, 255, 0.2);
    cursor: pointer;
    z-index: 999;
    display: none; /* Hidden by default - shown via JS if logged in */
    align-items: center;
    justify-content: flex-end; /* Keep icon on the right */
    gap: 0;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    animation: ai-pulse 3s infinite;
    max-width: 85px; /* Increased initial width */
    overflow: hidden;
    white-space: nowrap;
}

.ai-chat-button:hover {
    max-width: 300px;
    padding-left: 25px;
    padding-right: 10px;
    gap: 12px;
}

.ai-chat-label {
    opacity: 0;
    color: white;
    font-weight: 700;
    font-size: 1rem;
    transition: all 0.3s ease;
    transform: translateX(10px);
}

.ai-chat-button:hover .ai-chat-label {
    opacity: 1;
    transform: translateX(0);
}

.ai-chat-button .ai-icon {
    width: 70px;
    height: 70px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-chat-button:hover {
    transform: scale(1.1) translateY(-5px) rotate(5deg);
    box-shadow: 0 15px 35px rgba(99, 102, 241, 0.6);
}

.ai-chat-button .ai-icon {
    color: white;
    font-size: 1.5rem;
    font-weight: 800;
}

@keyframes ai-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.4);
    }

    70% {
        box-shadow: 0 0 0 15px rgba(99, 102, 241, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0);
    }
}

/* ===== MODAL WRAPPER (Aligned to Bottom Right) ===== */
.ai-chat-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    background: transparent; /* Remove the full-screen backdrop for better UX */
    padding: 1.5rem;
    pointer-events: none; /* Let clicks pass through to background when backdrop is transparent */
}

.ai-chat-modal.active {
    display: block;
}

/* ===== CHAT CONTAINER (PRO CARD) ===== */
.ai-chat-container {
    position: absolute;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 100%;
    max-width: 420px;
    height: 600px;
    background: var(--ai-bg);
    border: 1px solid var(--ai-border);
    border-radius: 24px;
    box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    pointer-events: auto; /* Re-enable pointer events for the container */
    transform-origin: bottom right;
    transform: scale(0.9) translateY(20px);
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.ai-chat-modal.active .ai-chat-container {
    transform: scale(1) translateY(0);
    opacity: 1;
}

/* Header */
.ai-chat-header {
    padding: 1.25rem 1.75rem;
    background: #f8fafc;
    border-bottom: 1px solid var(--ai-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.ai-chat-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    background: var(--ai-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.close-chat-btn {
    background: #f1f5f9;
    border: 1px solid var(--ai-border);
    width: 34px;
    height: 34px;
    border-radius: 10px;
    color: var(--ai-text-muted);
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-chat-btn:hover {
    background: #fee2e2;
    border-color: #fecaca;
    color: #ef4444;
}

/* Messages Area */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    scroll-behavior: smooth;
}



/* Bubble Styling */
.ai-chat-message {
    display: flex;
    gap: 1rem;
    max-width: 85%;
}

.ai-chat-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.ai-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
}

.ai-message-avatar.ai {
    background: var(--ai-gradient);
    color: white;
}

.ai-message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: inherit;
}

.ai-message-avatar.ai img {
    /* remove background show-through when image loads */
    background: transparent;
}

.ai-message-avatar.user {
    background: #334155;
    color: white;
}

.ai-message-content {
    padding: 0.75rem 1rem;
    border-radius: 16px;
    font-size: 0.95rem;
    line-height: 1.4;
    position: relative;
}

.ai-chat-message.ai .ai-message-content {
    background: #f1f5f9;
    border: 1px solid var(--ai-border);
    color: var(--ai-text);
    border-top-left-radius: 4px;
}

.ai-chat-message.user .ai-message-content {
    background: var(--ai-gradient);
    color: white;
    border-top-right-radius: 5px;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.15);
}

/* Typing */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 5px 0;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: #64748b;
    border-radius: 50%;
    animation: ai-dot-bounce 1.4s infinite ease-in-out;
}

@keyframes ai-dot-bounce {

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

    40% {
        transform: scale(1.0);
    }
}

/* Input Area */
.ai-chat-input-container {
    padding: 1.25rem 1.75rem;
    background: #f8fafc;
    border-top: 1px solid var(--ai-border);
    display: flex;
    gap: 0.75rem;
}

.ai-chat-input {
    flex: 1;
    background: #ffffff;
    border: 1px solid var(--ai-border);
    border-radius: 12px;
    padding: 0.75rem 1.25rem;
    color: var(--ai-text);
    font-family: inherit;
    transition: all 0.3s;
}

.ai-chat-input:focus {
    outline: none;
    border-color: var(--ai-primary);
    background: rgba(255, 255, 255, 0.08);
}

.ai-send-chat-btn {
    width: 45px;
    height: 45px;
    background: var(--ai-gradient);
    border: none;
    border-radius: 12px;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s;
}

.ai-send-chat-btn:hover {
    transform: scale(1.05);
    filter: brightness(1.1);
}

/* Scrollbar */
.ai-chat-messages::-webkit-scrollbar {
    width: 5px;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: #e2e8f0;
    border-radius: 10px;
}

/* Business Card (Mini) */
.chat-business-card {
    background: #ffffff;
    border: 1px solid var(--ai-border);
    border-radius: 20px;
    overflow: hidden;
    margin: 10px 0;
    max-width: 320px;
    transition: all 0.3s;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.chat-business-card:hover {
    transform: translateY(-3px);
    border-color: var(--ai-primary);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.card-image {
    width: 100%;
    height: 140px;
    object-fit: cover;
}

.card-details {
    padding: 1.25rem;
}

.card-details h4 {
    margin: 0 0 5px;
    color: #1e293b; /* Dark Slate (Black) */
    font-size: 1.1rem;
    font-weight: 700;
}

.card-details p {
    font-size: 0.85rem;
    color: #64748b; /* Muted Slate */
    margin: 0 0 12px;
    line-height: 1.4;
}

.card-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card-meta .category-tag {
    font-size: 0.75rem;
    padding: 2px 8px;
    background: #f1f5f9;
    color: var(--ai-primary);
    border-radius: 6px;
    font-weight: 600;
}

@keyframes ai-fade-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@media (max-width: 500px) {
    .ai-chat-container {
        height: 100%;
        border-radius: 0;
        max-width: 100%;
    }

    .ai-chat-modal {
        padding: 0;
    }
}