/* ─── WooCommerce AI Chat Widget v3 ─── */

#woo-ai-chat-widget {
    --chat-primary: #1a1a2e;
    --chat-accent: #e94560;
    --chat-accent-hover: #d63851;
    --chat-bg: #ffffff;
    --chat-user-bg: #1a1a2e;
    --chat-user-text: #ffffff;
    --chat-bot-bg: #f0f0f5;
    --chat-bot-text: #1a1a2e;
    --chat-border: #e0e0e8;
    --chat-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    --chat-success: #22c55e;

    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

/* ─── Botón flotante ─── */

#woo-ai-chat-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: var(--chat-accent);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(233, 69, 96, 0.4);
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

#woo-ai-chat-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(233, 69, 96, 0.5);
}

/* ─── Ventana del chat — DESKTOP: 1/3 de la pantalla ─── */

#woo-ai-chat-window {
    --chat-primary: #1a1a2e;
    --chat-accent: #e94560;
    --chat-accent-hover: #d63851;
    --chat-bg: #ffffff;
    --chat-user-bg: #1a1a2e;
    --chat-user-text: #ffffff;
    --chat-bot-bg: #f0f0f5;
    --chat-bot-text: #1a1a2e;
    --chat-border: #e0e0e8;
    --chat-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    --chat-success: #22c55e;

    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 33.33vw;
    height: 100%;
    background: var(--chat-bg);
    box-shadow: var(--chat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-left: 1px solid var(--chat-border);
    animation: woo-chat-slide-in 0.3s ease;
    z-index: 100000;
    border-radius: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

@keyframes woo-chat-slide-in {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ─── Header ─── */

#woo-ai-chat-header {
    background: var(--chat-primary);
    color: #fff;
    padding: 18px 24px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-shrink: 0;
    position: relative;
}

#woo-ai-chat-close {
    position: absolute;
    top: 14px;
    right: 16px;
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background 0.2s;
}

#woo-ai-chat-close:hover {
    color: #fff;
    background: rgba(255,255,255,0.15);
}

#woo-ai-chat-title { font-weight: 700; font-size: 17px; }

#woo-ai-chat-status {
    font-size: 12px;
    opacity: 0.75;
    display: flex;
    align-items: center;
    gap: 6px;
}

#woo-ai-chat-status::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    display: inline-block;
}

/* ─── Mensajes ─── */

#woo-ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

#woo-ai-chat-messages::-webkit-scrollbar { width: 5px; }
#woo-ai-chat-messages::-webkit-scrollbar-thumb { background: var(--chat-border); border-radius: 4px; }

.woo-ai-msg {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    word-wrap: break-word;
    white-space: pre-wrap;
    animation: woo-msg-appear 0.2s ease;
    font-size: 14px;
}

@keyframes woo-msg-appear {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.woo-ai-msg.bot {
    background: var(--chat-bot-bg);
    color: var(--chat-bot-text);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.woo-ai-msg.user {
    background: var(--chat-user-bg);
    color: var(--chat-user-text);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.woo-ai-msg a {
    color: var(--chat-accent);
    text-decoration: underline;
}

/* ─── Typing ─── */

.woo-ai-typing {
    display: flex;
    gap: 5px;
    padding: 12px 16px;
    align-self: flex-start;
    background: var(--chat-bot-bg);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
}

.woo-ai-typing span {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: woo-typing-bounce 1.2s infinite;
}

.woo-ai-typing span:nth-child(2) { animation-delay: 0.15s; }
.woo-ai-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes woo-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ─── Tarjetas de producto ─── */

.woo-ai-products-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 4px 0 8px 0;
    align-self: flex-start;
    width: 100%;
    animation: woo-msg-appear 0.3s ease;
}

.woo-ai-product-card {
    background: #fff;
    border: 1px solid var(--chat-border);
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.woo-ai-product-card:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

/* Imagen */

.woo-ai-product-img-link {
    display: block;
    width: 100%;
    aspect-ratio: 1;
    overflow: hidden;
    background: #f5f5f7;
}

.woo-ai-product-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease;
}

.woo-ai-product-img[src=""],
.woo-ai-product-img:not([src]) {
    display: none;
}

.woo-ai-product-card:hover .woo-ai-product-img {
    transform: scale(1.05);
}

/* Info */

.woo-ai-product-info {
    padding: 10px 12px 4px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
}

.woo-ai-product-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--chat-primary);
    text-decoration: none;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.35;
}

.woo-ai-product-name:hover {
    color: var(--chat-accent);
}

.woo-ai-product-price {
    font-size: 16px;
    font-weight: 700;
    color: var(--chat-accent);
}

/* Botones */

.woo-ai-product-actions {
    padding: 8px 12px 12px;
    display: flex;
    gap: 6px;
    align-items: center;
}

.woo-ai-btn-cart {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 8px 10px;
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    color: #fff;
    background: var(--chat-accent);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s;
    white-space: nowrap;
}

.woo-ai-btn-cart:hover {
    background: var(--chat-accent-hover);
    transform: scale(1.03);
}

.woo-ai-btn-cart:disabled {
    opacity: 0.7;
    cursor: wait;
    transform: none;
}

.woo-ai-btn-cart.woo-ai-btn-added {
    background: var(--chat-success);
}

.woo-ai-btn-view {
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    color: var(--chat-primary);
    background: var(--chat-bot-bg);
    border: 1px solid var(--chat-border);
    border-radius: 8px;
    text-decoration: none;
    text-align: center;
    transition: background 0.2s;
    white-space: nowrap;
}

.woo-ai-btn-view:hover {
    background: var(--chat-border);
}

.woo-ai-no-stock {
    flex: 1;
    font-size: 12px;
    font-weight: 600;
    color: #ef4444;
    text-align: center;
    padding: 8px;
}

/* Spinner */

.woo-ai-spin {
    animation: woo-ai-spin-anim 1s linear infinite;
}

@keyframes woo-ai-spin-anim {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ─── Input ─── */

#woo-ai-chat-input-area {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    border-top: 1px solid var(--chat-border);
    background: var(--chat-bg);
    flex-shrink: 0;
}

#woo-ai-chat-input {
    flex: 1;
    border: 1px solid var(--chat-border);
    border-radius: 24px;
    padding: 12px 18px;
    font-size: 14px;
    outline: none;
    font-family: inherit;
    transition: border-color 0.2s;
}

#woo-ai-chat-input:focus {
    border-color: var(--chat-accent);
}

#woo-ai-chat-send {
    width: 44px;
    height: 44px;
    border: none;
    background: var(--chat-accent);
    color: #fff;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.15s;
}

#woo-ai-chat-send:hover {
    background: var(--chat-accent-hover);
    transform: scale(1.05);
}

#woo-ai-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ─── MOBILE: pantalla completa ─── */

@media (max-width: 768px) {
    #woo-ai-chat-widget {
        bottom: 16px;
        right: 16px;
    }

    #woo-ai-chat-window {
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        border-left: none;
        border-radius: 0;
        animation: woo-chat-slide-up-mobile 0.3s ease;
    }

    @keyframes woo-chat-slide-up-mobile {
        from { opacity: 0; transform: translateY(100%); }
        to { opacity: 1; transform: translateY(0); }
    }

    .woo-ai-products-container {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    #woo-ai-chat-input-area {
        padding-bottom: env(safe-area-inset-bottom, 14px);
    }
}

/* ─── Pantallas grandes: máximo 500px de ancho ─── */

@media (min-width: 1600px) {
    #woo-ai-chat-window {
        width: 500px;
    }
}
