/* =========================================
   WP AI ASSISTANT - ESTILOS COMPLETOS (V12.0)
   ========================================= */

/* --- 1. CONTENEDOR PRINCIPAL (WRAPPER) --- */
#wpai-widget-container {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    position: fixed;
    bottom: 20px;
    z-index: 99999999; /* Máxima prioridad visual */
    display: flex;
    flex-direction: column-reverse; /* IMPORTANTE: Botón abajo, elementos arriba */
    gap: 15px; /* Espacio vertical entre elementos */
    align-items: flex-end; /* Alineación base a la derecha */
    
    /* TRUCO: Permite hacer clic en la página a través del contenedor vacío */
    pointer-events: none; 
}

/* Reactivar clics en los elementos interactivos */
#wpai-launcher, #wpai-window, #wpai-tooltip { 
    pointer-events: auto; 
}

/* --- 2. POSICIONAMIENTO --- */
.wpai-pos-right {
    right: 20px;
    left: auto;
    align-items: flex-end;
}

.wpai-pos-left {
    left: 20px;
    right: auto;
    align-items: flex-start;
}

/* --- 3. BOTÓN FLOTANTE (LAUNCHER) --- */
#wpai-launcher {
    width: 60px;
    height: 60px;
    background-color: var(--wpai-primary);
    color: var(--wpai-text);
    border-radius: 50%;
    box-shadow: 0 4px 14px rgba(0,0,0,0.25);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.2s, opacity 0.2s;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

#wpai-launcher:hover { transform: scale(1.05); }

#wpai-launcher span { 
    font-size: 30px; 
    line-height: 1; 
}

.wpai-launcher-img { 
    width: 100%; 
    height: 100%; 
    object-fit: cover; 
}

.wpai-notification-dot {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 12px;
    height: 12px;
    background: #ff3b30;
    border-radius: 50%;
    border: 2px solid #fff;
    z-index: 2;
    display: none;
}

/* Al abrir el chat, ocultamos el launcher */
#wpai-widget-container.wpai-open #wpai-launcher {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.5);
    height: 0; 
    margin: 0;
}

/* --- 4. GLOBO EMERGENTE (TOOLTIP) --- */
#wpai-tooltip {
    background: #fff;
    padding: 12px 16px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
    margin-bottom: 5px; 
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    font-weight: 500;
    color: #333;
    animation: wpai-bounce 0.5s ease-out;
    position: relative;
    max-width: 250px;
    line-height: 1.3;
}

/* Flechita del globo (apunta abajo) */
#wpai-tooltip::after {
    content: '';
    position: absolute;
    bottom: -6px;
    right: 24px; /* Posición para widget a la derecha */
    width: 12px;
    height: 12px;
    background: #fff;
    transform: rotate(45deg);
    box-shadow: 2px 2px 2px rgba(0,0,0,0.05);
}

/* Ajuste flecha para izquierda */
.wpai-pos-left #wpai-tooltip::after {
    right: auto;
    left: 24px;
}

#wpai-tooltip.wpai-hidden { display: none; }

#wpai-tooltip-close {
    font-size: 18px;
    cursor: pointer;
    color: #999;
    line-height: 1;
    font-weight: bold;
}
#wpai-tooltip-close:hover { color: #333; }

@keyframes wpai-bounce {
    0% { transform: translateY(10px); opacity: 0; }
    80% { transform: translateY(-3px); opacity: 1; }
    100% { transform: translateY(0); }
}

/* --- 5. VENTANA DEL CHAT --- */
#wpai-window {
    width: 360px;
    height: 550px;
    
    /* RESPONSIVE: Límites de pantalla */
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 100px);
    
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 5px 30px rgba(0,0,0,0.2);
    display: none; /* Oculto inicial */
    flex-direction: column;
    overflow: hidden;
    margin-bottom: 0;
    position: relative;
}

#wpai-widget-container.wpai-open #wpai-window {
    display: flex;
    animation: wpai-slide-up 0.3s cubic-bezier(0.25, 1, 0.5, 1);
}

@keyframes wpai-slide-up {
    from { opacity: 0; transform: translateY(20px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* --- 6. CABECERA (HEADER) --- */
.wpai-header {
    background: var(--wpai-primary);
    color: var(--wpai-text);
    padding: 12px 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0; /* NO ENCOGER */
    gap: 10px;
    z-index: 20; /* Encima del formulario */
}

/* Info Izquierda */
.wpai-header-info { 
    display: flex; align-items: center; gap: 10px; 
    flex: 1; min-width: 0; 
}

.wpai-avatar { 
    width: 34px; height: 34px; 
    background: rgba(255,255,255,0.2); 
    border-radius: 50%; 
    display: flex; justify-content: center; align-items: center;
    flex-shrink: 0; overflow: hidden;
}
.wpai-avatar img { width: 100%; height: 100%; object-fit: cover; }

.wpai-title-wrapper { display: flex; flex-direction: column; min-width: 0; }
.wpai-title-text { 
    font-weight: 700; font-size: 14px; 
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; 
}
.wpai-status-text { font-size: 10px; opacity: 0.8; }

/* Controles Derecha (Botones) */
.wpai-header-controls { 
    display: flex; align-items: center; gap: 5px; 
    flex: 0 0 auto; /* BLINDAJE: No desaparecer */
}

.wpai-header-controls button, .wpai-header-controls a {
    background: none; 
    border: none; 
    color: inherit; 
    cursor: pointer; 
    padding: 6px; 
    opacity: 0.8; 
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%; 
    transition: background 0.2s;
    text-decoration: none;
}
.wpai-header-controls button:hover, .wpai-header-controls a:hover { 
    opacity: 1; 
    background: rgba(255,255,255,0.15); 
}

#wpai-close-btn span { font-size: 20px; }
#wpai-reset-btn span { font-size: 18px; }

/* Botón WhatsApp SVG */
#wpai-wa-btn { 
    background: #25D366; 
    color: #fff; 
    opacity: 1; 
    box-shadow: 0 2px 5px rgba(0,0,0,0.2); 
    width: 40px; 
    height: 40px; 
    padding: 0; 
}
#wpai-wa-btn:hover { background: #1ebc59; transform: scale(1.1); }
#wpai-wa-btn svg { width: 50px; height: 50px; fill: #ffffff; }

/* --- 7. FORMULARIO DE LEADS (OVERLAY) --- */
#wpai-lead-form {
    position: absolute;
    top: 60px; /* Altura aprox del header */
    left: 0;
    width: 100%;
    height: calc(100% - 60px);
    background: #f9f9f9;
    z-index: 15; /* Encima de mensajes */
    padding: 25px 20px;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

#wpai-lead-form.wpai-hidden { display: none; }

.wpai-form-content h3 {
    font-size: 16px; margin: 0 0 20px 0;
    text-align: center; color: #333; line-height: 1.4;
}

#wpai-user-form { display: flex; flex-direction: column; gap: 12px; }

#wpai-user-form input {
    width: 100%; padding: 12px;
    border: 1px solid #ddd; border-radius: 8px;
    font-size: 14px; background: #fff;
    outline: none; transition: border-color 0.2s;
}
#wpai-user-form input:focus { border-color: var(--wpai-primary); }

#wpai-user-form button {
    background: var(--wpai-primary);
    color: var(--wpai-text);
    padding: 14px;
    border: none; border-radius: 8px;
    font-weight: 700; font-size: 15px;
    cursor: pointer; margin-top: 10px;
    transition: opacity 0.2s;
}
#wpai-user-form button:hover { opacity: 0.9; }

/* --- 8. ÁREA DE MENSAJES --- */
#wpai-messages-area {
    flex: 1;
    padding: 15px;
    background-color: #f9f9f9;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
#wpai-messages-area::-webkit-scrollbar { width: 6px; }
#wpai-messages-area::-webkit-scrollbar-thumb { background-color: rgba(0,0,0,0.1); border-radius: 3px; }

.wpai-message { 
    padding: 10px 14px; border-radius: 12px; 
    font-size: 14px; line-height: 1.4; 
    max-width: 85%; word-wrap: break-word; 
}

.wpai-bot-msg { background: #eef1f5; color: #333; align-self: flex-start; border-bottom-left-radius: 2px; }
.wpai-user-msg { background: var(--wpai-primary); color: var(--wpai-text); align-self: flex-end; border-bottom-right-radius: 2px; }

/* Listas Markdown y Enlaces */
.wpai-message ul { margin: 5px 0 5px 20px; padding: 0; list-style-type: disc; }
.wpai-message li { margin-bottom: 4px; }
.wpai-message a { text-decoration: underline; color: inherit; font-weight: bold; }
.wpai-bot-msg a { color: #0066cc; }
.wpai-user-msg a { color: #fff; }

/* --- 9. INPUT Y CONTROLES INFERIORES --- */
.wpai-input-wrapper { 
    background: #fff; 
    padding: 10px; 
    border-top: 1px solid #eee; 
    flex-shrink: 0; 
}

.wpai-input-area {
    display: flex; align-items: center; gap: 5px; 
    background: #fff; border: 1px solid #ddd; 
    border-radius: 24px; padding: 6px 6px 6px 15px;
}
.wpai-input-area:focus-within { border-color: var(--wpai-primary); }

#wpai-input { 
    flex: 1; border: none; background: transparent; 
    outline: none; font-size: 14px; 
    resize: none; max-height: 80px; padding: 4px 0; 
}

/* Botón Micrófono */
#wpai-mic-btn {
    background: transparent; border: none; color: #999;
    width: 32px; height: 32px; border-radius: 50%;
    cursor: pointer; display: flex; justify-content: center; align-items: center;
    transition: all 0.2s;
}
#wpai-mic-btn:hover { color: var(--wpai-primary); background: #f0f0f0; }
#wpai-mic-btn span { font-size: 18px; }

/* Estado Escuchando (Pulsación) */
#wpai-mic-btn.is-listening {
    color: #ff3b30; background: rgba(255, 59, 48, 0.1);
    animation: wpai-pulse 1.5s infinite;
}
@keyframes wpai-pulse {
    0% { box-shadow: 0 0 0 0 rgba(255, 59, 48, 0.4); }
    70% { box-shadow: 0 0 0 8px rgba(255, 59, 48, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 59, 48, 0); }
}

/* Botón Enviar */
#wpai-send-btn {
    background: var(--wpai-primary); border: none;
    width: 32px; height: 32px; border-radius: 50%;
    cursor: pointer; display: flex; 
    justify-content: center; align-items: center;
    flex-shrink: 0; padding: 0;
}
#wpai-send-btn:hover { filter: brightness(1.1); }

/* Icono Flecha Blanco (Dashicons) */
#wpai-send-btn span {
    font-family: 'dashicons' !important; font-size: 20px; 
    color: #ffffff !important; margin-left: 1px; margin-top: 2px; 
    display: block; line-height: 1;
}

/* Branding Footer (Más oscuro) */
.wpai-branding { 
    text-align: center; 
    font-size: 10px; 
    color: #555; 
    margin-top: 5px; 
    font-weight: 600;
}
.wpai-typing { padding: 12px !important; font-style: italic; color: #888; }

/* =========================================
   MEDIA QUERIES (RESPONSIVE MÓVIL)
   ========================================= */

/* Vertical */
@media (max-width: 480px) {
    #wpai-widget-container {
        bottom: 10px;
        right: 10px !important; left: auto !important; /* Siempre derecha en móvil */
        align-items: flex-end;
    }
    #wpai-window {
        width: calc(100vw - 20px);
        height: 80vh;
        max-width: none; max-height: none;
    }
    #wpai-tooltip { display: none; } /* Ocultar globo en móvil */
}

/* Horizontal (Landscape) */
@media (max-height: 500px) and (orientation: landscape) {
    #wpai-window {
        height: 100vh;
        width: 450px;
        max-height: none;
        border-radius: 12px 12px 0 0;
        bottom: 0;
    }
    #wpai-widget-container { bottom: 0; }
    #wpai-launcher { display: none; }
    
    #wpai-widget-container.wpai-open #wpai-window {
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
    }
}