/* ==========================================================================
   Contenedor Principal y Estructura
   ========================================================================== */
#sfb-widget {
    position: fixed !important;
    bottom: 20px;
    right: 20px;
    width: 320px;
    height: auto; 
    max-height: 550px; 
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    background: #ffffff;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    overflow: hidden !important; 
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

/* Estado Abierto/Cerrado */
#sfb-widget:not(.open) {
    max-height: 52px; 
    width: 250px;
    cursor: pointer;
}

/* ==========================================================================
   Encabezado
   ========================================================================== */
.sfb-header {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 12px 15px;
    background: #0073aa; 
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    position: relative;
    z-index: 10002;
}

.sfb-header-info {
    display: flex;
    align-items: center;
    overflow: hidden;
    flex: 1;
}

.sfb-bot-name-text {
    font-weight: bold;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* CORRECCIÓN: Asegura que el icono de limpieza sea visible y no se oculte */
#sfb-clear-chat {
    display: inline-block;
    filter: brightness(0) invert(1); /* Hace que el emoji sea blanco si es necesario */
    margin-right: 5px;
}

#sfb-online-status {
    font-size: 10px;
    color: #2ecc71;
    margin-left: 8px;
    display: none;
    animation: blink 2s infinite;
}

@keyframes blink {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

/* ==========================================================================
   Área de Chat y Mensajes
   ========================================================================== */
.sfb-chat {
    padding: 15px;
    min-height: 100px; 
    max-height: 400px; 
    height: auto;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    background-color: #f4f7f6;
    position: relative;
}

#sfb-widget.open {
    height: auto;
    max-height: 550px;
}

.sfb-bot, .sfb-user {
    padding: 10px 14px;
    margin-bottom: 12px;
    max-width: 85%;
    font-size: 14px;
    line-height: 1.5;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.sfb-bot {
    align-self: flex-start;
    background: #ffffff;
    color: #333;
    border-radius: 14px 14px 14px 4px;
    border: 1px solid #e0e0e0;
}

.sfb-agent-msg {
    border-left: 4px solid #2ecc71 !important;
    background: #f0fff4;
}

.sfb-user {
    align-self: flex-end;
    background: #0073aa; 
    color: #ffffff;
    border-radius: 14px 14px 4px 14px;
    word-wrap: break-word;
}

/* ==========================================================================
   Popup de Salida (CORREGIDO A MODAL WEB COMPLETO)
   ========================================================================== */
#sfb-exit-popup {
    display: none; /* Se activa como flex desde JS */
    position: fixed !important;
    top: 0;
    left: 0;
    width: 100vw !important;
    height: 100vh !important;
    background: rgba(0, 0, 0, 0.6) !important; /* Fondo oscuro */
    backdrop-filter: blur(5px); /* Efecto difuminado */
    z-index: 999999 !important; /* Por encima de todo */
    align-items: center;
    justify-content: center;
}

.sfb-popup-content {
    background: #ffffff;
    width: 90%;
    max-width: 400px;
    padding: 30px;
    border-radius: 15px;
    position: relative;
    box-shadow: 0 20px 40px rgba(0,0,0,0.4);
    text-align: center;
    animation: modalShow 0.3s ease-out;
}

@keyframes modalShow {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.sfb-popup-content h3 {
    margin: 10px 0;
    color: #333;
    font-size: 22px;
    font-weight: bold;
}

.sfb-popup-content p {
    font-size: 15px;
    color: #555;
    margin-bottom: 20px;
    line-height: 1.4;
}

#sfb-custom-leads-form input,
#sfb-custom-leads-form textarea {
    width: 100%;
    padding: 12px;
    margin-bottom: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    box-sizing: border-box;
    background: #f9f9f9;
}

/* CORRECCIÓN: Botón ajustado a color azul para el modo "Enviar" */
#sfb-submit-lead-btn {
    width: 100%;
    padding: 15px;
    border: none;
    border-radius: 8px;
    background: #0073aa !important; /* Cambiado de rojo a azul */
    color: white !important;
    font-weight: bold;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.2s;
}

#sfb-submit-lead-btn:hover {
    background: #005f8d !important;
}

#sfb-close-popup {
    position: absolute;
    right: 15px;
    top: 10px;
    font-size: 28px;
    color: #aaa;
    cursor: pointer;
    line-height: 1;
}

#sfb-close-popup:hover {
    color: #333;
}

/* ==========================================================================
   Input y Footer
   ========================================================================== */
.sfb-input-container {
    display: flex;
    padding: 12px;
    background: #fff;
    border-top: 1px solid #eee;
    align-items: center;
}

#sfb-input {
    flex: 1;
    border: 1px solid #ddd;
    padding: 8px 15px;
    border-radius: 20px;
    outline: none;
    font-size: 14px;
}

#sfb-send-btn {
    border: none;
    background: #0073aa;
    color: #fff;
    margin-left: 8px;
    padding: 8px 16px;
    cursor: pointer;
    border-radius: 20px;
    font-weight: bold;
}

/* Chips */
.sfb-chip {
    display: inline-block;
    background: #ffffff;
    color: #0073aa;
    padding: 6px 12px;
    border-radius: 15px;
    font-size: 12px;
    margin: 4px 2px; 
    cursor: pointer;
    border: 1px solid #0073aa;
}

/* Scrollbar */
.sfb-chat::-webkit-scrollbar { width: 4px; }
.sfb-chat::-webkit-scrollbar-thumb { background: #ccc; border-radius: 10px; }

/* Forzar que el selector de países esté por encima de todo */
.iti--allow-dropdown .iti__country-list {
    z-index: 9999999 !important;
}

/* Ajustar el fondo del popup para que cubra todo correctamente */
#sfb-exit-popup {
    z-index: 9999998 !important;
}

/* Evitar que el texto del input se amontone con la bandera */
#lead_whatsapp_visual {
    padding-left: 50px !important;
}