/**
 * Petmarket AI Chat - Estilos
 */

/* ==========================================================================
   Toggle Button (junto a la lupa) — clase, no ID, porque hay multiples forms
   ========================================================================== */

.pmai-chat-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: auto;
    padding: 0;
    margin: 0;
    border: none;
    background: #222;
    cursor: pointer;
    color: #ccc;
    transition: color 0.2s, background 0.2s;
    position: relative;
    vertical-align: top;
    flex-shrink: 0;
    border-left: 1px solid rgba(255, 255, 255, 0.15);
    border-top-right-radius: 30px;
    border-bottom-right-radius: 30px;
}

.pmai-chat-toggle:hover {
    color: #fff;
    background: #ed6436;
}

.pmai-chat-toggle.active {
    color: #fff;
    background: linear-gradient(135deg, #ed6436, #f59e0b);
}

.pmai-chat-toggle svg {
    width: 20px;
    height: 20px;
    pointer-events: none;
}

/* Quitar border-radius derecho del boton de busqueda cuando toggle existe */
.bwp-header .header-search-form .search-from #searchsubmit2,
.bwp-header .header-search-form .search-from #searchsubmit,
.search-from #searchsubmit2 {
    border-top-right-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
}

/* ==========================================================================
   Form activo (borde gradiente)
   ========================================================================== */

.search-from.pmai-chat-active {
    box-shadow: 0 0 0 2px #ed6436;
}

/* ==========================================================================
   Chat Panel
   ========================================================================== */

#pmai-chat-panel {
    position: absolute;
    z-index: 9999;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column;
    overflow: hidden;
    max-height: 500px;
    min-height: 300px;
}

#pmai-chat-panel.pmai-chat-open {
    display: flex;
}

/* ==========================================================================
   Chat Header
   ========================================================================== */

.pmai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: linear-gradient(135deg, #ed6436, #f59e0b);
    color: #fff;
    flex-shrink: 0;
}

.pmai-chat-header-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 14px;
}

.pmai-chat-header-title svg {
    flex-shrink: 0;
}

#pmai-chat-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    transition: background 0.2s;
}

#pmai-chat-close:hover {
    background: rgba(255, 255, 255, 0.35);
}

/* ==========================================================================
   Messages Area
   ========================================================================== */

.pmai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
}

/* Scrollbar estilizada */
.pmai-chat-messages::-webkit-scrollbar {
    width: 4px;
}

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

.pmai-chat-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 2px;
}

/* Mensaje burbuja base */
.pmai-chat-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13px;
    line-height: 1.5;
    word-wrap: break-word;
}

/* Usuario */
.pmai-chat-msg.pmai-msg-user {
    align-self: flex-end;
    background: #ed6436;
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* Asistente */
.pmai-chat-msg.pmai-msg-assistant {
    align-self: flex-start;
    background: #f5f5f5;
    color: #333;
    border-bottom-left-radius: 4px;
}

/* Error */
.pmai-chat-msg.pmai-msg-error {
    align-self: flex-start;
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
    border-bottom-left-radius: 4px;
    font-size: 12px;
}

/* ==========================================================================
   Typing Indicator
   ========================================================================== */

.pmai-typing {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: #f5f5f5;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
}

.pmai-typing-dot {
    width: 7px;
    height: 7px;
    background: #999;
    border-radius: 50%;
    animation: pmai-bounce 1.4s infinite ease-in-out;
}

.pmai-typing-dot:nth-child(1) { animation-delay: 0s; }
.pmai-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.pmai-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes pmai-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* ==========================================================================
   Product Cards
   ========================================================================== */

.pmai-chat-products {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.pmai-product-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: #fff;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
    cursor: pointer;
}

.pmai-product-card:hover {
    border-color: #ed6436;
    box-shadow: 0 2px 8px rgba(237, 100, 54, 0.15);
}

.pmai-product-card-img {
    width: 56px;
    height: 56px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
    background: #f5f5f5;
}

.pmai-product-card-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.pmai-product-card-name {
    font-size: 12px;
    font-weight: 600;
    color: #333;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.pmai-product-card-reason {
    font-size: 11px;
    color: #777;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.pmai-product-card-price {
    font-size: 12px;
    font-weight: 700;
    color: #ed6436;
}

.pmai-product-card-price del {
    color: #999;
    font-weight: 400;
    font-size: 11px;
}

.pmai-product-card-price ins {
    text-decoration: none;
}

.pmai-product-card-arrow {
    flex-shrink: 0;
    color: #ccc;
    font-size: 12px;
    transition: color 0.2s;
}

.pmai-product-card:hover .pmai-product-card-arrow {
    color: #ed6436;
}

/* ==========================================================================
   Follow-up Button
   ========================================================================== */

.pmai-follow-up {
    display: inline-block;
    margin-top: 8px;
    padding: 6px 14px;
    background: #fff;
    border: 1px solid #ed6436;
    border-radius: 20px;
    color: #ed6436;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.pmai-follow-up:hover {
    background: #ed6436;
    color: #fff;
}

/* ==========================================================================
   Suggestion Chips
   ========================================================================== */

.pmai-chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 16px;
    border-top: 1px solid #f0f0f0;
    flex-shrink: 0;
}

.pmai-chat-suggestions.pmai-hidden {
    display: none;
}

.pmai-suggestion-chip {
    display: inline-block;
    padding: 5px 12px;
    background: #f8f8f8;
    border: 1px solid #e5e5e5;
    border-radius: 20px;
    font-size: 12px;
    color: #555;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
    white-space: nowrap;
}

.pmai-suggestion-chip:hover {
    background: #ed6436;
    border-color: #ed6436;
    color: #fff;
}

/* ==========================================================================
   Input Area
   ========================================================================== */

.pmai-chat-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: #fafafa;
    border-top: 1px solid #eee;
    flex-shrink: 0;
}

#pmai-chat-input {
    flex: 1;
    height: 38px;
    padding: 0 14px;
    border: 1px solid #ddd;
    border-radius: 20px;
    font-size: 13px;
    outline: none;
    background: #fff;
    transition: border-color 0.2s;
}

#pmai-chat-input:focus {
    border-color: #ed6436;
}

#pmai-chat-input::placeholder {
    color: #aaa;
}

#pmai-chat-send {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: #ed6436;
    color: #fff;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    flex-shrink: 0;
}

#pmai-chat-send:hover {
    background: #d4532a;
}

#pmai-chat-send:active {
    transform: scale(0.95);
}

#pmai-chat-send:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* ==========================================================================
   Mobile FAB
   ========================================================================== */

#pmai-chat-fab {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #ed6436, #f59e0b);
    color: #fff;
    box-shadow: 0 4px 16px rgba(237, 100, 54, 0.4);
    cursor: pointer;
    z-index: 9998;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

#pmai-chat-fab:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(237, 100, 54, 0.5);
}

#pmai-chat-fab.pmai-fab-hidden {
    display: none !important;
}

/* ==========================================================================
   Mobile Overlay
   ========================================================================== */

#pmai-chat-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9998;
}

#pmai-chat-overlay.pmai-overlay-show {
    display: block;
}

/* ==========================================================================
   Welcome message
   ========================================================================== */

.pmai-chat-welcome {
    text-align: center;
    padding: 20px 16px 8px;
    color: #888;
    font-size: 13px;
}

.pmai-chat-welcome svg {
    display: block;
    margin: 0 auto 8px;
    color: #ed6436;
}

/* ==========================================================================
   Desktop (>=992px)
   ========================================================================== */

@media (min-width: 992px) {
    #pmai-chat-panel {
        width: 100%;
        min-width: 400px;
        max-width: 600px;
    }

    #pmai-chat-fab {
        display: none !important;
    }
}

/* ==========================================================================
   Mobile (<=991px)
   ========================================================================== */

@media (max-width: 991px) {
    /* Ocultar toggle en mobile - se usa el FAB */
    .pmai-chat-toggle {
        display: none !important;
    }

    /* Restaurar border-radius del boton de busqueda en mobile */
    .bwp-header .header-search-form .search-from #searchsubmit2,
    .bwp-header .header-search-form .search-from #searchsubmit,
    .search-from #searchsubmit2 {
        border-top-right-radius: 30px !important;
        border-bottom-right-radius: 30px !important;
    }

    /* FAB visible */
    #pmai-chat-fab {
        display: flex;
    }

    /* Panel como bottom drawer */
    #pmai-chat-panel {
        position: fixed !important;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto !important;
        width: 100% !important;
        max-width: 100% !important;
        max-height: 75vh;
        min-height: 50vh;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.2);
        z-index: 10000;
    }

    #pmai-chat-panel.pmai-chat-open {
        animation: pmai-slide-up 0.25s ease-out;
    }

    @keyframes pmai-slide-up {
        from { transform: translateY(100%); }
        to   { transform: translateY(0); }
    }

    /* Ocultar FAB cuando chat esta abierto */
    #pmai-chat-panel.pmai-chat-open ~ #pmai-chat-fab {
        display: none !important;
    }
}
