/* ============================================================
   Xabia Agent — estilos del widget de chat
   ============================================================ */

/* --- CONTENEDOR PRINCIPAL --- */
.xabia-chatbox,
#xabia-chatbox {
    display: flex !important;
    flex-direction: column;
    width: 100%;
    height: 100%;
    min-height: 450px;
    max-height: 80vh;
    background: var(--xabia-bg, #ffffff);
    border: 1px solid #e1e1e1;
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.05);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    position: relative;
    overflow: hidden;
    margin: 0 auto;
    --xabia-magenta: #c2185b;
}

/* --- HISTORIAL DE MENSAJES --- */
.xabia-chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #fcfcfc;
    font-size: var(--xabia-font-size, 14px);
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Scrollbar fina */
.xabia-chat-history::-webkit-scrollbar { width: 6px; }
.xabia-chat-history::-webkit-scrollbar-track { background: transparent; }
.xabia-chat-history::-webkit-scrollbar-thumb { background-color: rgba(0,0,0,0.15); border-radius: 10px; }

/* --- BURBUJAS DE MENSAJE --- */
.xabia-msg {
    line-height: 1.5;
    animation: xFade 0.35s cubic-bezier(0.25, 1, 0.5, 1);
    word-wrap: break-word;
    max-width: 90%;
    padding: 10px 14px;
    border-radius: 15px;
    margin: 0;
}

.xabia-msg strong {
    color: var(--xabia-accent, #2271b1);
    font-weight: 700;
}

/* Mensaje del Usuario */
.xabia-msg.user {
    align-self: flex-end;
    background: var(--xabia-accent, #2271b1);
    color: #fff;
    border-bottom-right-radius: 2px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.xabia-msg.user a { color: #fff; text-decoration: underline; }

/* Mensaje del Bot */
.xabia-msg.bot {
    align-self: flex-start;
    background: #fff;
    color: #1d1d1f;
    border: 1px solid #eee;
    border-bottom-left-radius: 2px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

/* Conversión WooCommerce — acción principal (--xabia-magenta alineado con admin) */
.xabia-msg.bot .xabia-btn-cart {
    display: inline-block;
    margin-top: 8px;
    padding: 10px 16px;
    border: none;
    border-radius: 10px;
    font-size: 0.95em;
    font-weight: 600;
    cursor: pointer;
    background: var(--xabia-magenta, #c2185b);
    color: #fff;
    box-shadow: 0 2px 6px rgba(194, 24, 91, 0.35);
    transition: background 0.15s ease, transform 0.1s ease;
}

.xabia-msg.bot .xabia-btn-cart:hover:not(:disabled) {
    background: #ad1457;
    transform: translateY(-1px);
}

.xabia-msg.bot .xabia-btn-cart:disabled {
    opacity: 0.65;
    cursor: wait;
}

/* Reservas (inyectadas por addons) */
.xabia-msg.bot .xabia-btn-book,
.xabia-msg.bot a.xabia-btn-book {
    display: inline-block;
    margin-top: 8px;
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 0.95em;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    background: var(--xabia-accent, #2271b1);
    color: #fff;
    box-shadow: 0 2px 6px rgba(34, 113, 177, 0.35);
    transition: background 0.15s ease, transform 0.1s ease;
    border: none;
}
.xabia-msg.bot a.xabia-btn-book:hover {
    filter: brightness(1.05);
    transform: translateY(-1px);
}
.xabia-msg.bot .xabia-btn-book.xabia-book-amelia {
    display: inline-block;
    margin-top: 8px;
    padding: 10px 16px;
    border: none;
    border-radius: 10px;
    font-size: 0.95em;
    font-weight: 600;
    cursor: pointer;
    background: var(--xabia-accent, #2271b1);
    color: #fff;
    box-shadow: 0 2px 6px rgba(34, 113, 177, 0.35);
    transition: background 0.15s ease, transform 0.1s ease;
}
.xabia-msg.bot .xabia-btn-book.xabia-book-amelia:hover {
    filter: brightness(1.05);
    transform: translateY(-1px);
}

.xabia-msg.bot .xabia-msg-system {
    border-left: 3px solid var(--xabia-magenta, #c2185b);
}

/* Acciones en respuestas del bot (Llamar, Enlace, Mapa, Imagen) */
.xabia-msg.bot .xabia-action {
    display: inline-block;
    margin: 4px 6px 4px 0;
    padding: 6px 12px;
    border-radius: 8px;
    text-decoration: none;
    font-size: 0.9em;
    font-weight: 500;
}
.xabia-msg.bot .xabia-action-call {
    background: #0a0;
    color: #fff;
}
.xabia-msg.bot .xabia-action-url,
.xabia-msg.bot .xabia-action-map {
    background: var(--xabia-accent, #2271b1);
    color: #fff;
}
.xabia-msg.bot .xabia-action-img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 8px 0;
    display: block;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

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

/* --- INDICADOR DE ESCRITURA --- */
.xabia-typing-dots {
    display: flex;
    gap: 10px;
    padding: 10px 20px;
    align-items: center;
    height: 30px;
    background: transparent;
}
.xabia-typing-dots span {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    opacity: 0.45;
    transform: translateY(0) scale(0.78);
    animation: xThinkingWave 1.2s infinite cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform, opacity;
}
.xabia-typing-dots span:nth-child(1) {
    background: #73B5E6; /* Azul claro (marca) */
    animation-delay: 0s;
}
.xabia-typing-dots span:nth-child(2) {
    background: #B69FA1; /* Marrón grisáceo (marca) */
    animation-delay: 0.18s;
}
.xabia-typing-dots span:nth-child(3) {
    background: #F39250; /* Naranja (marca) */
    animation-delay: 0.36s;
}
@keyframes xThinkingWave {
    0%, 100% {
        transform: translateY(0) scale(0.78);
        opacity: 0.45;
    }
    35% {
        transform: translateY(-5px) scale(1);
        opacity: 1;
    }
    60% {
        transform: translateY(0) scale(0.9);
        opacity: 0.65;
    }
}

@media (prefers-reduced-motion: reduce) {
    .xabia-typing-dots span {
        animation: none;
        opacity: 0.9;
        transform: none;
    }
}

/* --- ÁREA DE ENTRADA (INPUT) --- */
.xabia-input-area {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-top: 1px solid #eee;
    background: #fff;
}

/* FIX CRÍTICO: width: auto y flex-grow para combatir al tema de WP */
.xabia-input-field {
    flex-grow: 1;
    width: auto; 
    border: 1px solid #d2d2d7;
    border-radius: 20px;
    padding: 10px 15px;
    outline: none;
    font-size: 15px;
    transition: border-color 0.2s;
    background: #fff;
    color: #333;
    margin: 0;
}

.xabia-input-field:focus {
    border-color: var(--xabia-accent, #2271b1);
    box-shadow: 0 0 0 3px rgba(0,0,0,0.05);
}

/* --- ICONOS --- */
.material-symbols-outlined {
    font-size: 22px;
    user-select: none;
    cursor: pointer;
    color: #86868b;
    transition: all 0.2s ease;
    flex-shrink: 0;
}
.material-symbols-outlined:hover { color: var(--xabia-accent, #2271b1); }

#x-mic.x-active,
.xabia-mic.xabia-mic-listening {
    color: #ff3b30 !important;
    animation: xPulseRed 1.5s infinite;
}
@keyframes xPulseRed { 0% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.1); opacity: 0.8; } 100% { transform: scale(1); opacity: 1; } }

/* --- BOTONES DE ACCIÓN --- */
.xabia-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-top: 8px;
    margin-right: 5px;
    padding: 6px 14px;
    background: var(--xabia-accent, #2271b1);
    color: #fff !important;
    border-radius: 20px;
    text-decoration: none !important;
    font-size: 12px;
    font-weight: 600;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: transform 0.2s;
}
.xabia-action-btn:hover { opacity: 0.9; transform: translateY(-1px); }

/* --- MODO TÓTEM: aviso de cierre por inactividad --- */
.xabia-totem-warning {
    padding: 10px 16px;
    background: #fff3cd;
    color: #856404;
    font-size: 13px;
    text-align: center;
    border-bottom: 1px solid #ffc107;
}