/* Reset y variables locales dentro del scope */
.onus-wsp {
    position: fixed;
    z-index: 11;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.onus-wsp * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Posicionamiento */
.onus-wsp--right { bottom: 20px; right: 20px; align-items: flex-end; }
.onus-wsp--left { bottom: 20px; left: 20px; align-items: flex-start; }

/* Botón flotante */
.onus-wsp__trigger {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    /* border: none; */
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: transform 0.3s ease;
    background: #FFF;
    border: 2px solid #E5E5E5;
}

.onus-wsp__trigger:hover { transform: scale(1.05); }

.onus-wsp__icon-svg { width: 35px; height: 35px; fill: white; transition: opacity 0.3s; }
.onus-wsp__close-icon { 
    display: none; 
    color: red; 
    font-size: 30px; 
    line-height: 1;
}

/* Estado Abierto (Clase toggleada por JS) */
.onus-wsp.is-open .onus-wsp__trigger .onus-wsp__icon-svg { display: none; }
.onus-wsp.is-open .onus-wsp__trigger .onus-wsp__close-icon { display: block; transform: translateY(-3px);}

/* Indicador Online */
.onus-wsp__badge {
    position: absolute;
    top: 0;
    right: 0;
    width: 14px;
    height: 14px;
    background-color: #4ad504;
    border: 2px solid #fff;
    border-radius: 50%;
    animation: onusPulse 2s infinite;
}

@keyframes onusPulse {
    0% { box-shadow: 0 0 0 0 rgba(74, 213, 4, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(74, 213, 4, 0); }
    100% { box-shadow: 0 0 0 0 rgba(74, 213, 4, 0); }
}

/* Ventana de Chat */
.onus-wsp__window {
    position: absolute;
    width: 320px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 5px 25px rgba(0,0,0,0.15);
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.9);
    transform-origin: bottom right;
    transition: all 0.3s cubic-bezier(0.19, 1, 0.22, 1);
    display: flex;
    flex-direction: column;
    bottom: 40px;
  right: 40px;
}

.onus-wsp--left .onus-wsp__window { transform-origin: bottom left; }

.onus-wsp.is-open .onus-wsp__window {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Header */
.onus-wsp__header {
    padding: 16px;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    line-height: 1;
}
.onus-wsp__header-title { font-weight: 700; font-size: 16px; display: block; }
.onus-wsp__header-subtitle { font-size: 12px; opacity: 0.9; }
.onus-wsp__header-close { background: none; border: none; color: white; font-size: 24px; cursor: pointer; }

/* Cuerpo */
.onus-wsp__body {
    background: #e5ddd5; /* Fondo clásico tipo WSP */
    padding: 20px;
    height: 130px; /* Altura fija */
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: flex-start;
}

/* Mensajes */
.onus-wsp__message {
    background: white;
    padding: 10px 14px;
    border-radius: 0 12px 12px 12px;
    font-size: 14px;
    color: #333;
    max-width: 90%;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    opacity: 0; 
    transform: translateY(10px);
    transition: all 0.4s ease;
    display: none; /* Se maneja por JS */
}

.onus-wsp__message.is-visible {
    opacity: 1;
    transform: translateY(0);
    display: block;
}

/* Animación Typing */
.onus-wsp__typing {
    background: white;
    padding: 12px;
    border-radius: 12px;
    display: none; /* Se maneja por JS */
    gap: 4px;
    margin-bottom: 10px;
    width: fit-content;
}
.onus-wsp__dot {
    width: 6px;
    height: 6px;
    background: #b6b5ba;
    border-radius: 50%;
    animation: onusTyping 1.4s infinite ease-in-out both;
}
.onus-wsp__dot:nth-child(1) { animation-delay: -0.32s; }
.onus-wsp__dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes onusTyping {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Footer */
.onus-wsp__footer {
    padding: 15px;
    background: white;
    border-top: 1px solid #eee;
}

.onus-wsp__field-group { margin-bottom: 10px; }
.onus-wsp__label { font-size: 12px; color: #666; margin-bottom: 4px; display: block; }
.onus-wsp__select {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    background: white;
    cursor: pointer;
}

.onus-wsp__textarea {
    width: 100%;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 10px;
    font-family: inherit;
    font-size: 14px;
    resize: none;
    height: 60px;
    outline: none;
    margin-bottom: 10px;
}
.onus-wsp__textarea:focus { border-color: #25D366; }

.onus-wsp__btn-send {
    width: 100%;
    color: white;
    border: none;
    padding: 10px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: opacity 0.2s;
}
.onus-wsp__btn-send:hover { opacity: 0.9; }

/* Media Query para móviles (Desactivar hover automático) */
@media (hover: none) and (pointer: coarse) {
    .onus-wsp__trigger:hover { transform: none; }
}


/* --- RESPONSIVE FIXES --- */
@media (max-width: 768px) {

    /* 1. Desacoplamos la ventana del contenedor padre (.onus-wsp) */
    .onus-wsp__window {
        position: fixed; /* Rompe el flujo relativo al botón */
        bottom: 90px;    /* Lo elevamos para que no tape el botón flotante de abrir/cerrar */
        left: 50%;       /* Lo movemos al centro de la pantalla */
        right: auto;     /* Reseteamos cualquier herencia */
        
        /* Cálculo para centrado perfecto y ancho seguro */
        width: calc(100% - 32px); /* 100% menos 16px de margen a cada lado */
        max-width: 400px;         /* Evitamos que se vea gigante en tablets */
        
        /* Ajustamos el punto de origen de la animación al centro-abajo */
        transform-origin: center bottom;
        transform: translateX(-50%) translateY(20px) scale(0.9);
        
        /* Aseguramos que el z-index sea superior al navbar (como el de 'Tienda' en tu foto) */
        z-index: 10000; 
    }

    /* 2. Ajustamos la animación de apertura para mantener el centrado */
    .onus-wsp.is-open .onus-wsp__window {
        /* Mantenemos el translateX(-50%) para que siga centrado */
        transform: translateX(-50%) translateY(0) scale(1);
        opacity: 1;
        visibility: visible;
    }

    /* 3. Ajuste opcional: Si quieres que el botón flotante se mueva un poco o cambie */
    .onus-wsp__trigger {
        /* Nos aseguramos que el botón siga accesible y visible */
        z-index: 10001; 
    }
    
    /* 4. Fix para teclados móviles: Ajuste del textarea */
    /* Evita que el zoom automático de iOS rompa el diseño al hacer focus */
    .onus-wsp__textarea, 
    .onus-wsp__select {
        font-size: 16px; /* 16px evita el zoom automático en iPhone */
    }
}