/**
 * Don Poncho Chat - Estilos de producción
 */

/* Container — z-index 150 ≈ por encima del install-prompt (100) y del WhatsApp float (80),
   PERO por debajo del modal (200) para que al abrir un producto el chat no lo tape.
   Antes era 9999 y tapaba el botón "Agregar al carrito". */
#dpChatContainer {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 150;
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* Cuando el carrito flotante está visible, el chat-toggle sube para no encimarse.
   El JS agrega .cart-visible al container igual que al whatsapp-float. */
#dpChatContainer.cart-visible {
    bottom: calc(90px + env(safe-area-inset-bottom, 0));
}
@media (min-width: 481px) {
    #dpChatContainer.cart-visible { bottom: calc(100px + env(safe-area-inset-bottom, 0)); }
}

/* Toggle button */
.chat-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: linear-gradient(135deg, #FF6B35 0%, #ff8c5a 100%);
    color: white;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(255, 107, 53, 0.4);
    transition: all 0.3s ease;
    font-family: inherit;
    font-weight: 600;
    font-size: 0.95rem;
}

.chat-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(255, 107, 53, 0.5);
}

.chat-toggle.hidden {
    display: none;
}

.chat-toggle-icon {
    font-size: 1.2rem;
}

/* Widget */
.chat-widget {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 380px;
    height: 550px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideIn 0.3s ease-out;
}

.chat-widget.hidden {
    display: none;
}

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

/* Header */
.chat-header {
    background: linear-gradient(135deg, #FF6B35 0%, #ff8c5a 100%);
    color: white;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar {
    width: 44px;
    height: 44px;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    flex-shrink: 0;
}

.chat-header-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.chat-title {
    font-weight: 600;
    font-size: 1.1rem;
}

.chat-status {
    font-size: 0.75rem;
    opacity: 0.9;
}

.chat-close {
    background: rgba(255,255,255,0.2);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.5rem;
    line-height: 1;
    transition: background 0.2s;
}

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

/* Messages area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f8f9fa;
}

.chat-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 0.95rem;
    line-height: 1.4;
    animation: messageIn 0.3s ease-out;
}

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

.chat-message.bot {
    background: white;
    color: #333;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.chat-message.user {
    background: linear-gradient(135deg, #FF6B35 0%, #ff8c5a 100%);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.chat-message.bot .message-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.message-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #FF6B35;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    color: white;
    font-weight: 700;
}

.message-name {
    font-weight: 600;
    font-size: 0.8rem;
    color: #FF6B35;
}

.message-content {
    white-space: pre-wrap;
    word-wrap: break-word;
}

.message-content strong {
    font-weight: 600;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: white;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #ccc;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        background: #ccc;
    }
    30% {
        transform: translateY(-6px);
        background: #FF6B35;
    }
}

/* Suggestions */
.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 16px;
    background: #f8f9fa;
    border-top: 1px solid #eee;
}

.chat-suggestions:empty {
    display: none;
}

.suggestion-chip {
    padding: 8px 14px;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    color: #333;
}

.suggestion-chip:hover {
    background: #FF6B35;
    color: white;
    border-color: #FF6B35;
    transform: translateY(-1px);
}

/* Input area */
.chat-input-container {
    display: flex;
    gap: 10px;
    padding: 16px;
    background: white;
    border-top: 1px solid #eee;
}

#chatInput {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #e0e0e0;
    border-radius: 24px;
    font-size: 0.95rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#chatInput:focus {
    border-color: #FF6B35;
    box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.1);
}

#chatSend {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, #FF6B35 0%, #ff8c5a 100%);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: transform 0.2s, box-shadow 0.2s;
    flex-shrink: 0;
}

#chatSend:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(255, 107, 53, 0.3);
}

#chatSend:active {
    transform: scale(0.95);
}

/* Estados de Don Poncho */
.chat-avatar[data-state="saludando"] {
    animation: bounce 0.5s ease;
}

.chat-avatar[data-state="pensando"] {
    animation: pulse 1.5s infinite;
}

.chat-avatar[data-state="emocionado"] {
    animation: bounce 0.3s ease 3;
}

.chat-avatar[data-state="recomendando"] {
    animation: pulse 0.8s ease;
}

.chat-avatar[data-state="celebrando"] {
    animation: celebrate 0.5s ease;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes celebrate {
    0% { transform: scale(1) rotate(0deg); }
    25% { transform: scale(1.1) rotate(-5deg); }
    50% { transform: scale(1.1) rotate(5deg); }
    75% { transform: scale(1.1) rotate(-5deg); }
    100% { transform: scale(1) rotate(0deg); }
}

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

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #ccc;
}

/* Ajuste cuando hay carrito flotante */
#dpChatContainer.cart-visible {
    bottom: 90px;
}

#dpChatContainer.cart-visible .chat-toggle {
    /* Ajuste adicional si es necesario */
}

/* Responsive — móvil: chat-toggle 100% compacto (solo icono tipo FAB).
   El texto "Chat con IA" hacía que la pastilla fuera horizontal-larga y se
   empalmaba con el carrito flotante que ocupa todo el ancho. */
@media (max-width: 480px) {
    #dpChatContainer {
        bottom: 16px;
        right: 16px;
        /* left sin definir → anclado a la derecha */
    }

    #dpChatContainer.cart-visible {
        bottom: calc(90px + env(safe-area-inset-bottom, 0));
    }

    /* Widget expandido: ocupa casi toda la pantalla */
    .chat-widget {
        position: fixed;
        bottom: 16px;
        left: 12px;
        right: 12px;
        width: auto;
        max-width: none;
        height: calc(100vh - 32px);
        max-height: 600px;
        border-radius: 14px;
    }

    /* Chat cerrado: FAB circular solo-icon. Sin texto → no se empalma con cart. */
    .chat-toggle {
        width: 56px;
        height: 56px;
        padding: 0;
        border-radius: 50%;
        justify-content: center;
        box-shadow: 0 4px 14px rgba(255,107,53,0.45);
    }

    /* Ocultar cualquier texto en el toggle (si el HTML lo incluye) */
    .chat-toggle-text { display: none; }

    .chat-toggle-icon { font-size: 1.5rem; }
}
