/* ── AI Chatbot Widget ─────────────────────── */
#ai-chatbot-widget { --chatbot-color: #6366f1; --chatbot-color-light: color-mix(in srgb, var(--chatbot-color) 12%, transparent); }

/* Bubble */
.chatbot-bubble {
    position: fixed;
    bottom: 24px;
    z-index: 9998;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--chatbot-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    transition: transform 0.2s, box-shadow 0.2s;
}
.chatbot-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(0,0,0,0.25);
}
.chatbot-bubble.right { right: 24px; }
.chatbot-bubble.left { left: 24px; }
.chatbot-bubble::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: var(--chatbot-color);
    animation: cb-pulse 2s ease-out infinite;
    z-index: -1;
}
@keyframes cb-pulse {
    0% { transform: scale(1); opacity: 0.4; }
    100% { transform: scale(1.7); opacity: 0; }
}

/* Badge */
.chatbot-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    background: #ef4444;
    color: white;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    padding: 0 4px;
}

/* Panel */
.chatbot-panel {
    position: fixed;
    bottom: 96px;
    z-index: 9999;
    width: 380px;
    max-height: 540px;
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 12px 48px rgba(0,0,0,0.15), 0 0 0 1px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.chatbot-panel.right { right: 24px; }
.chatbot-panel.left { left: 24px; }

/* Header */
.chatbot-header {
    background: var(--chatbot-color);
    color: white;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.chatbot-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}
.chatbot-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}
.chatbot-header-name {
    font-weight: 600;
    font-size: 15px;
    line-height: 1.2;
}
.chatbot-header-status {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
}
.chatbot-close {
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    transition: background 0.15s;
}
.chatbot-close:hover { background: rgba(255,255,255,0.25); }

/* Messages */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 180px;
    max-height: 340px;
    scroll-behavior: smooth;
}
.chatbot-messages::-webkit-scrollbar { width: 4px; }
.chatbot-messages::-webkit-scrollbar-track { background: transparent; }
.chatbot-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 2px; }

.chatbot-msg-wrap {
    display: flex;
    flex-direction: column;
}

/* Bubbles */
.chatbot-msg {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 13.5px;
    line-height: 1.55;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.chatbot-msg.user {
    align-self: flex-end;
    background: var(--chatbot-color);
    color: white;
    border-bottom-right-radius: 6px;
}
.chatbot-msg.assistant {
    align-self: flex-start;
    background: #f3f4f6;
    color: #1f2937;
    border-bottom-left-radius: 6px;
}

/* Typing */
.chatbot-typing {
    align-self: flex-start;
    display: flex;
    gap: 5px;
    padding: 12px 16px;
    background: #f3f4f6;
    border-radius: 18px;
    border-bottom-left-radius: 6px;
}
.chatbot-typing span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #9ca3af;
    animation: cb-dot 1.4s ease-in-out infinite;
}
.chatbot-typing span:nth-child(2) { animation-delay: 0.15s; }
.chatbot-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes cb-dot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-8px); opacity: 1; }
}

/* Tools wrap */
.chatbot-tools-wrap {
    align-self: flex-start;
    max-width: 90%;
}

/* Product cards */
.chatbot-products {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}
.chatbot-product-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 10px 12px;
    display: flex;
    gap: 10px;
    align-items: center;
    transition: border-color 0.15s;
}
.chatbot-product-card:hover {
    border-color: var(--chatbot-color);
}
.chatbot-product-img {
    width: 52px;
    height: 52px;
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
    background: #f9fafb;
}
.chatbot-product-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.chatbot-product-info {
    flex: 1;
    min-width: 0;
}
.chatbot-product-name {
    font-weight: 600;
    font-size: 12.5px;
    color: #1f2937;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}
.chatbot-product-prices {
    margin-top: 2px;
}
.chatbot-product-price {
    font-size: 13px;
    font-weight: 700;
    color: var(--chatbot-color);
}
.chatbot-product-original {
    font-size: 11px;
    text-decoration: line-through;
    color: #9ca3af;
    margin-left: 4px;
}
.chatbot-product-desc {
    font-size: 11px;
    color: #6b7280;
    margin-top: 2px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.chatbot-product-btn {
    flex-shrink: 0;
    padding: 7px 14px;
    background: var(--chatbot-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: opacity 0.15s;
}
.chatbot-product-btn:hover { opacity: 0.85; }

/* WhatsApp */
.chatbot-wa-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    background: #25d366;
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: opacity 0.15s;
    box-shadow: 0 2px 8px rgba(37,211,102,0.3);
}
.chatbot-wa-btn:hover { opacity: 0.9; color: white; }

/* Contact saved */
.chatbot-contact-saved {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: #dcfce7;
    color: #166534;
    border-radius: 10px;
    font-size: 12.5px;
    font-weight: 500;
    margin-top: 6px;
}

/* Cart added */
.chatbot-cart-added {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 10px;
    background: #eff6ff;
    color: #1e40af;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 500;
    margin-top: 6px;
}

/* Input */
.chatbot-input {
    padding: 12px 14px;
    border-top: 1px solid #f3f4f6;
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    background: #fafafa;
}
.chatbot-input input {
    flex: 1;
    border: 1px solid #e5e7eb;
    border-radius: 24px;
    padding: 10px 18px;
    font-size: 13.5px;
    outline: none;
    background: white;
    transition: border-color 0.15s;
}
.chatbot-input input:focus {
    border-color: var(--chatbot-color);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--chatbot-color) 15%, transparent);
}
.chatbot-input input:disabled {
    background: #f9fafb;
    color: #9ca3af;
}
.chatbot-input button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--chatbot-color);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.15s, transform 0.1s;
}
.chatbot-input button:hover:not(:disabled) { opacity: 0.85; transform: scale(1.05); }
.chatbot-input button:disabled { opacity: 0.4; cursor: not-allowed; }

/* Powered by */
.chatbot-powered {
    text-align: center;
    font-size: 10px;
    color: #9ca3af;
    padding: 4px;
    background: #fafafa;
    border-top: 1px solid #f3f4f6;
}

/* Cloak */
[x-cloak] { display: none !important; }

/* Mobile */
@media (max-width: 640px) {
    .chatbot-bubble { bottom: 16px; }
    .chatbot-bubble.right { right: 16px; }
    .chatbot-bubble.left { left: 16px; }
    .chatbot-panel {
        width: calc(100% - 16px);
        left: 8px !important;
        right: 8px !important;
        bottom: 88px;
        max-height: calc(100dvh - 100px);
        border-radius: 16px;
    }
    .chatbot-messages {
        max-height: calc(100dvh - 240px);
    }
}
