/* ================================================
   LM Soluciones — AI Chat Widget v4.0
   Premium Sales Assistant UI
   ================================================ */

#ai-chat-widget-container {
    position: fixed;
    bottom: 24px;
    left: 24px;
    right: auto;
    z-index: 9999;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    pointer-events: none;
}

#ai-chat-widget-launcher, #ai-chat-window {
    pointer-events: auto;
}

/* === LAUNCHER BUTTON === */
#ai-chat-widget-launcher {
    width: 68px;
    height: 68px;
    background: linear-gradient(135deg, #0061ff 0%, #00d4ff 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 6px 24px rgba(0,97,255,0.45), 0 0 0 0 rgba(0,97,255,0.4);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    overflow: hidden;
    animation: pulse-ring 2.5s infinite;
    position: relative;
}

#ai-chat-widget-launcher::after {
    content: '💬';
    position: absolute;
    bottom: -2px;
    right: -2px;
    background: #ff4444;
    color: white;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    animation: bounce-badge 1.5s ease-in-out infinite;
}

#ai-chat-widget-launcher img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

#ai-chat-widget-launcher:hover {
    transform: scale(1.12);
    box-shadow: 0 8px 30px rgba(0,97,255,0.55);
}

@keyframes pulse-ring {
    0% { box-shadow: 0 6px 24px rgba(0,97,255,0.45), 0 0 0 0 rgba(0,97,255,0.35); }
    50% { box-shadow: 0 6px 24px rgba(0,97,255,0.45), 0 0 0 12px rgba(0,97,255,0); }
    100% { box-shadow: 0 6px 24px rgba(0,97,255,0.45), 0 0 0 0 rgba(0,97,255,0); }
}

@keyframes bounce-badge {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* === CHAT WINDOW === */
#ai-chat-window {
    position: absolute;
    bottom: 80px;
    left: 0;
    width: 440px;
    height: 600px;
    background: #f8f9fb;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2), 0 0 0 1px rgba(0,0,0,0.05);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#ai-chat-window.active {
    display: flex;
}

@keyframes slideUp {
    from { transform: translateY(30px) scale(0.95); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

/* === HEADER === */
.chat-header {
    background: linear-gradient(135deg, #0046c7 0%, #0061ff 50%, #00a3ff 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 700;
    font-size: 15px;
    letter-spacing: -0.2px;
}

.chat-header .title {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-header .header-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.4);
    object-fit: cover;
}

.chat-header .status-dot {
    width: 8px;
    height: 8px;
    background: #00ff88;
    border-radius: 50%;
    display: inline-block;
    animation: blink 2s ease-in-out infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.close-chat {
    cursor: pointer;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
    font-size: 16px;
}

.close-chat:hover {
    background: rgba(255,255,255,0.2);
}

/* === MESSAGES AREA === */
.chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;/* Product Cards v6.0 */
.product-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    overflow: hidden;
    margin: 10px 0;
    transition: transform 0.2s, box-shadow 0.2s;
    max-width: 260px;
    display: flex;
    flex-direction: column;
}

.product-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.3);
    border-color: #00ff88;
}

.product-card-img {
    width: 100%;
    height: 140px;
    object-fit: contain;
    background: #fff;
    padding: 10px;
}

.product-card-body {
    padding: 12px;
}

.product-card-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: #fff;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.product-card-sku {
    font-size: 0.75rem;
    color: #888;
    margin-bottom: 8px;
}

.product-card-price {
    font-size: 1.1rem;
    font-weight: 700;
    color: #00ff88;
    margin-bottom: 12px;
}

.product-card-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 8px;
}

.product-card-btn-view {
    padding: 8px;
    border: 1px solid #00ff88;
    border-radius: 6px;
    background: transparent;
    color: #00ff88;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.product-card-btn-view:hover {
    background: #00ff88;
    color: #000;
}

.product-card-btn-cart {
    padding: 8px;
    border: none;
    border-radius: 6px;
    background: #00ff88;
    color: #000;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.2s;
}

.product-card-btn-cart:hover {
    opacity: 0.9;
}
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.15);
    border-radius: 4px;
}

/* === MESSAGE BUBBLES === */
.message {
    max-width: 92%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.55;
    word-break: break-word;
    animation: fadeInMsg 0.3s ease;
}

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

.message.user {
    align-self: flex-end;
    background: linear-gradient(135deg, #0061ff, #0046c7);
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,97,255,0.25);
}

.message.ai {
    align-self: flex-start;
    background: white;
    color: #1e293b;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    border: 1px solid #e8ecf1;
    max-width: 98%;
    overflow-x: auto;
}

/* === RICH CONTENT IN AI MESSAGES === */
.message.ai strong, .message.ai b {
    color: #0061ff;
    font-weight: 700;
}

.message.ai ul {
    margin: 8px 0;
    padding-left: 18px;
}

.message.ai li {
    margin-bottom: 6px;
}

.message.ai code {
    background: #eef2ff;
    color: #0046c7;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.message.ai a.product-link {
    display: inline-block;
    background: linear-gradient(135deg, #0061ff, #0046c7);
    color: white !important;
    text-decoration: none;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    margin: 4px 4px 4px 0;
    transition: all 0.2s;
    box-shadow: 0 2px 6px rgba(0,97,255,0.25);
}

.message.ai a.product-link:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,97,255,0.35);
}

/* Product cards in AI messages */
.message.ai .product-card {
    background: #f0f5ff;
    border: 1px solid #d4e0ff;
    border-radius: 12px;
    padding: 12px;
    margin: 8px 0;
}

.message.ai .product-card .product-name {
    font-weight: 700;
    color: #1e293b;
    font-size: 13px;
    margin-bottom: 4px;
}

.message.ai .product-card .product-meta {
    font-size: 12px;
    color: #64748b;
}

.message.ai .product-card .product-price {
    font-size: 16px;
    font-weight: 800;
    color: #0061ff;
    margin: 6px 0;
}

.message.ai .product-card .product-stock {
    font-size: 11px;
    color: #16a34a;
    font-weight: 600;
}

/* Tables in responses */
.message.ai table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 12px;
    display: block;
    overflow-x: auto;
    white-space: nowrap;
}

.message.ai table th {
    background: #0061ff;
    color: white;
    padding: 8px 10px;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    white-space: nowrap;
}

.message.ai table td {
    padding: 8px 10px;
    border-bottom: 1px solid #e8ecf1;
    white-space: normal;
    min-width: 80px;
}

.message.ai table tr:nth-child(even) {
    background: #f0f5ff;
}

/* === TYPING INDICATOR === */
.typing-indicator {
    padding: 8px 16px;
    font-size: 12px;
    color: #0061ff;
    display: none;
    font-weight: 600;
    animation: fadeInMsg 0.3s ease;
}

/* === INPUT AREA === */
.chat-input-area {
    padding: 14px 16px;
    border-top: 1px solid #e8ecf1;
    display: flex;
    gap: 10px;
    background: white;
}

.chat-input-area input {
    flex: 1;
    border: 2px solid #e2e8f0;
    border-radius: 24px;
    padding: 10px 18px;
    outline: none;
    font-size: 14px;
    transition: border-color 0.2s;
    font-family: 'Inter', sans-serif;
}

.chat-input-area input:focus {
    border-color: #0061ff;
    box-shadow: 0 0 0 3px rgba(0,97,255,0.1);
}

.chat-input-area input:disabled {
    background: #f1f5f9;
    opacity: 0.7;
}

.send-btn {
    background: linear-gradient(135deg, #0061ff, #0046c7);
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 12px rgba(0,97,255,0.35);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* === RESPONSIVE === */
@media (max-width: 520px) {
    #ai-chat-window {
        width: calc(100vw - 20px);
        height: calc(100vh - 120px);
        bottom: 80px;
        left: 10px;
        right: 10px;
        border-radius: 16px;
    }
    
    #ai-chat-widget-container {
        left: 16px;
        bottom: 16px;
    }
}
