/* --- 1. CONTENEDOR PRINCIPAL Y SOMBRAS --- */
#divWrap {
    border: 1px solid #D0E2FF;
   /* box-shadow: 10px 5px 5px rgba(0,0,0,0.1) !important;*/
}

body.bubblesButtonsInsideThemeInverted #divWrap #divMainContainer #divYFlow #divYFlowChating .messages > div {
    background: linear-gradient(to bottom, #FFFF, #E4EEFF) !important;
}

/* --- 2. CABECERA, BOTONES Y FOOTER (DEGRADADO UNIFICADO) --- */
body.withHeader #divHeader,
body.withCloseButtons #divButtons {
    background: #FFFFFF !important; /* Color sólido de respaldo */
    border: none !important;
}

/* Sombra específica para el Header (hacia abajo)
body.withHeader #divHeader {
 box-shadow: 0px 1px 5px grey !important;
}*/

body.withFooter #divFooter {
    border-top: none !important;
}

/* --- 3. BARRA DE NAVEGACIÓN --- */
.navbar-default {
    border-color: transparent !important;
    background-image: none !important;
    background-color: transparent !important
}

/* --- 4. ZONA DE ESCRITURA --- */
#divWrap #divMainContainer #divYFlow #divYFlowChating .compose {
    background-color: #E4EEFF;

}

#divWrap #divMainContainer #divYFlow #divYFlowChating .compose .pm {
    border-right: 1px solid #ccc !important
}
/* --- 5. Estilo para todos los globos de mensaje --- */
body.bubblesButtonsInsideThemeInverted  #divWrap #divMainContainer #divYFlow #divYFlowChating .messages > div div.message{
    border-radius: 20px !important; 
   /* box-shadow: 0px 1px 5px #ccc !important */
}

/* --- 6. Estilo específico para mensajes del cliente --- */
body.bubblesButtonsInsideThemeInverted  #divWrap #divMainContainer #divYFlow #divYFlowChating .messages > div div.message.client {
    border-radius: 20px !important
}

/* --- 6. Botones --- */
body.bubblesButtonsInsideThemeInverted  #divWrap #divMainContainer #divYFlow #divYFlowChating .messages > div div.message.yflow.yflow.attach.template.button .buttons {
    display: flex !important; 
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 5px !important
}

body.bubblesButtonsInsideThemeInverted  #divWrap #divMainContainer #divYFlow #divYFlowChating .messages > div div.message.yflow.yflow.attach.template.button .buttons .button {
    border-radius: 50px !important
}

body.bubblesButtonsInsideThemeInverted  #divWrap #divMainContainer #divYFlow #divYFlowChating .messages > div div.message.yflow.yflow.attach.template.button .buttons .button:hover {
    box-shadow: 0px 1px 5px #ccc !important
}

body.withHeader.withLogo #divHeader{
    height: 50px;
}

/* --- 7. Margen en el navbar para que quede centrado --- */
body.withLogo #divHeader div.navbar-header img.navbar-brand {
    margin: 5px !important
}

body.withHeader #divHeader div.navbar-header img {
    height: 40px !important
}

#divWrap .btn-primary {
    box-shadow: 0px 1px 5px rgba(0, 0, 0, 0.2) !important;
    border: none !important
}
body.bubblesButtonsInsideThemeInverted #divWrap #divMainContainer #divYFlow #divYFlowChating .messages > div div.message.yflow,
body.bubblesButtonsInsideThemeInverted #divWrap #divMainContainer #divYFlow #divYFlowChating .messages > div div.message.client .msgtext,
body.bubblesButtonsInsideThemeInverted #divWrap #divMainContainer #divYFlow #divYFlowChating .messages > div div.message.agent,
body.bubblesButtonsInsideThemeInverted #divWrap #divMainContainer #divYFlow #divYFlowChating .messages > div div.message.supervisor {
    padding: 14px !important
}
/* --- 8. Margen a la hora de envío del mensaje --- */
body.bubblesButtonsInsideThemeInverted #divWrap #divMainContainer #divYFlow #divYFlowChating .messages > div div.message.yflow .time,
body.bubblesButtonsInsideThemeInverted #divWrap #divMainContainer #divYFlow #divYFlowChating .messages > div div.message.agent .time,
body.bubblesButtonsInsideThemeInverted #divWrap #divMainContainer #divYFlow #divYFlowChating .messages > div div.message.supervisor .time,
body.bubblesButtonsInsideThemeInverted #divWrap #divMainContainer #divYFlow #divYFlowChating .messages > div div.message.client .time
 {
    right: -35px !important;
}

body.bubblesButtonsInsideThemeInverted #divWrap #divMainContainer #divYFlow #divYFlowChating .messages > div div.message.yflow .msgtext{
    padding: 0px;
}

/* Contenedor principal del header ajustado para flujo flexible */
body.withLogo #divHeader div.navbar-header {
    display: flex !important;
    flex-direction: column !important; /* Alinea los textos verticalmente */
    justify-content: center !important;
    align-items: flex-start !important; /* Alinea al inicio a la derecha del logo */
    padding-left: 50px!important; /* Espacio exacto para que el logo no pise el texto */
    height: 50px !important;
    width: 100% !important;
    white-space: nowrap !important; /* Evita que el texto se rompa en varias líneas */
}

/* Ajuste del Logo para que no interfiera con el texto */
body.withLogo #divHeader div.navbar-header img.navbar-brand {
    position: absolute !important;
    left: 10px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    margin: 0 !important;
    height: 35px !important;
    width: auto !important;
}

/* Inyección del título principal de forma responsiva */
body.withLogo #divHeader div.navbar-header::before {
    content: "Webchat AT&T México";
    font-weight: bold;
    color: #003366;
    font-size: 14px;
    display: block;
    line-height: 1.2;
}

/* Inyección del subtítulo (Horario de atención) */
body.withLogo #divHeader div.navbar-header::after {
    content: "Servicio de atención a clientes";
    font-size: 11px;
    color: #666;
    display: block;
    line-height: 1.2;
}

body.bubblesButtonsInsideThemeInverted #divWrap #divMainContainer #divYFlow #divYFlowChating .messages > div:not(.client) {
    padding-left: 45px !important;
    position: relative;
    display: flex;
    flex-direction: column;
    /* justify-content: flex-end; <-- ELIMINADO: esto bloqueaba el scroll */
    scrollbar-width: none !important
}

/* 2. Posicionamos el avatar */
body.bubblesButtonsInsideThemeInverted #divWrap #divMainContainer #divYFlow #divYFlowChating .messages > div:not(.client) div.message.yflow::before {
    content: "";
    position: absolute;
    left: -40px; /* Lo mueve hacia afuera del globo a la izquierda */
    bottom: 0;   /* Alineado a la base del mensaje */
    width: 39px;
    height: 39px;
    background-image: url('https://iili.io/qKTqa99.png'); /* URL de tu icono */
    background-size: 90%;
    background-position: center;
    background-repeat: no-repeat;
    border-radius: 50%;
    display: block;
}

body.bubblesButtonsInsideThemeInverted #divWrap #divMainContainer #divYFlow #divYFlowChating .messages > div div.message.client:not(.generic){
    margin-right: 45px !important;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

body.bubblesButtonsInsideThemeInverted #divWrap #divMainContainer #divYFlow #divYFlowChating .messages > div div.message.client:not(.generic)::before{
    content: "";
    position: absolute;
    right: -40px; /* Lo mueve hacia afuera del globo a la derecha */
    bottom: 0;   /* Alineado a la base del mensaje */
    width: 30px;
    height: 30px;
    background-image: url('https://iili.io/qKhjWan.png'); /* URL de tu icono */
    background-size: 90%;
    background-position: center;
    background-repeat: no-repeat;
    border-radius: 50%;
    display: block;
}


/* --- Estilo de Cápsula para el Input --- */
#divWrap #divMainContainer #divYFlow #divYFlowChating .compose .composer .form-group {
    border-radius: 25px !important;       /* Esto le da la forma de círculo/píldora */
    margin: 2px 10px !important;          /* Despega el input de los bordes laterales y el botón */
    padding: 0 15px !important;           /* Espacio interno para que el texto no toque los bordes curvos */
    height: 40px !important;              /* Altura fija para mantener la estética */
    display: flex !important;
    align-items: center !important;
    flex-grow: 1 !important;              /* Permite que crezca si hay espacio */
    width: auto !important;               /* Evita que fuerce el 100% ignorando márgenes */
    background-color: #FFFF !important;
}

/* Reset del textarea interno para que sea invisible dentro de la cápsula */
#divWrap #divMainContainer #divYFlow #divYFlowChating .compose .composer .form-group textarea {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 8px 0 !important;
    margin: 0 !important;
    resize: none !important;
    line-height: 20px !important;
}

/* Seleccionamos el div que envuelve al botón */
#divWrap #divMainContainer #divYFlow #divYFlowChating .compose .composer .send > div {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    height: 100% !important;
    padding: 0 10px !important; /* Espacio para que no toque el borde derecho */
}

#divWrap #divMainContainer #divYFlow #divYFlowChating .compose .composer .send .btn-default {
    border: 1px solid black !important;  /* Borde sólido */
    border-radius: 20% !important;         /* Círculo perfecto */
    width: 40px !important;                /* Ancho fijo */
    height: 40px !important;               /* Alto fijo */
    padding: 0 !important;                 /* Quitamos el padding de bootstrap */
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-shadow: none !important;
    outline: none !important;
}

#divWrap #divMainContainer #divYFlow #divYFlowChating .compose .composer .send .btn-default svg path {
    fill: #0097D7 !important;
    fill-opacity: 1 !important;
}
#divWrap #divMainContainer #divYFlow #divYFlowChating .compose{
    border-top: none !important;
    margin-top: 0px !important;
}
body.withFooter{
    padding-bottom: 0px !important;
}

#divWrap #divMainContainer #divYFlow #divYFlowChating .compose .composer .send > div .btn{
    background-color: #0097D7;
}
.btn-default{
    background-color: transparent !important
}
body.withFooter #divFooter .powered{
    display: none;
}

/* 1. Obligamos al body y al contenedor principal a no crecer más que la pantalla */
html, body, #divWrap {
    height: 100% !important;
    height: 100vh !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important; /* Evita el scroll doble del navegador */
}

/* 2. Convertimos el contenedor en un Flexbox Vertical */
#divWrap {
    display: flex !important;
    flex-direction: column !important;
}

/* 3. El contenedor central debe ocupar todo el espacio sobrante */
#divMainContainer, #divYFlow, #divYFlowChating {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important; /* Clave para que el contenido no lo desborde */
    height: auto !important;
}

/* 4. EL SCROLL: Este es el único lugar donde debe haber scroll */
#divYFlowChating .messages {
    flex: 1 !important;
    overflow-y: auto !important; /* Habilita el scroll vertical */
    overflow-x: hidden !important;
    display: block !important;
    height: 100% !important;
}

/* 5. LA BARRA DE ESCRITURA: La anclamos abajo */
#divWrap #divMainContainer #divYFlow #divYFlowChating .compose {
    flex-shrink: 0 !important; /* Evita que el chat la "apriete" y la desaparezca */
    height: auto !important;
    min-height: 60px !important;
    background-color: #E4EEFF !important;
    border-top: 1px solid #D0E2FF !important;
    z-index: 999 !important;
    align-items: center;
}

/* Ajuste preventivo para el header */
#divHeader {
    flex-shrink: 0 !important; /* El header no se encoge */
}

/* Aplicamos esto a la cadena de contenedores para que "acepten" tener scroll */
#divMainContainer, 
#divYFlow, 
#divYFlowChating {
    flex: 1 !important;
    min-height: 0 !important; /* OBLIGATORIO para que el hijo pueda scrollear */
    display: flex !important;
    flex-direction: column !important;
}

/* 2. El contenedor que REALMENTE tiene los mensajes */
#divYFlowChating .messages {
    flex: 1 !important;
    overflow-y: auto !important; /* Activa el scroll vertical */
    overflow-x: hidden !important;
    height: auto !important; /* No fuerces 100% aquí, deja que flex lo maneje */
    display: block !important;
    -webkit-overflow-scrolling: touch !important; /* Para que en iPhone sea suave */
}

/* Eliminamos cualquier bloqueo de scroll que venga por defecto */
#divYFlow, #divYFlowChating, .messages-wrapper {
    overflow: visible !important; 
}

/* Y solo se lo activamos al contenedor final de mensajes */
#divYFlowChating .messages {
    overflow-y: auto !important;
}

#divYFlowChating .messages::-webkit-scrollbar {
    width: 6px !important;
    display: block !important;
}

#divYFlowChating .messages::-webkit-scrollbar-thumb {
    background-color: #0097D7 !important; /* Color de AT&T para la barrita */
    border-radius: 10px !important;
}

/* 1. El contenedor del chat debe ser el marco de referencia */
#divYFlowChating {
    position: relative !important;
    height: 100% !important;
    width: 100% !important;
    overflow: hidden !important;
}

/* --- FIX FUNCIONAL DE SCROLL --- */

/* 1. Limitamos la altura de toda la cadena para que NO exceda la pantalla */
html, body, #divWrap, #divMainContainer, #divYFlow, #divYFlowChating {
    height: 100vh !important;
    max-height: 100vh !important;
    overflow: hidden !important; 
    display: flex !important;
    flex-direction: column !important;
}

/* 2. El área de mensajes debe ser la ÚNICA que gestione el scroll */
#divYFlowChating .messages {
    flex: 1 1 auto !important; /* Toma todo el espacio y permite encogerse */
    overflow-y: auto !important; /* ACTIVA EL SCROLL DEL MOUSE */
    overflow-x: hidden !important;
    
    /* Forzamos que el mouse sea capturado aquí */
    pointer-events: all !important; 
    touch-action: pan-y !important;
    
    /* Esto es vital: si no tiene altura, flex: 1 a veces no basta */
    height: 100% !important; 
}

/* 3. Evitamos que el Footer o el Header "empujen" el chat fuera de rango */
#divHeader, .compose {
    flex-shrink: 0 !important; /* Prohibido que se achiquen o se estiren de más */
}

/* Matamos cualquier capa invisible que esté bloqueando el mouse */
#divHeader, .compose, #divFooter {
    z-index: 20 !important;
}

#divYFlowChating .messages {
    z-index: 10 !important;
    position: relative !important;
}

/* Si el software usa un "wrapper" interno, lo obligamos a cooperar */
.messages-wrapper, #divYFlow {
    pointer-events: none !important; /* Deja pasar el click/scroll... */
}

#divYFlowChating .messages, .compose, #divHeader {
    pointer-events: auto !important; /* ...pero estos SÍ lo capturan */
}

body.bubblesButtonsInsideThemeInverted #divWrap #divMainContainer #divYFlow #divYFlowChating .messages > div div.message.yflow.continuation.first {
    margin-top: 50px;
}

#divYFlow:not([style*="display: none"]) ~ #divLogged {
    display: none !important;
}

#divYFlow[style*="display: none"] ~ #divLogged {
    display: block !important;
}

#divWrap #divMainContainer #divYFlow #divYFlowChating.withSystemMessage .systemmessage {
    display: none;
}

/* --- FIX ESPECÍFICO PARA MÓVILES --- */
@media (max-width: 768px) {
    html, body, #divWrap {
        /* Evita que el contenido se vaya debajo de la barra de URL del celular */
        height: 100dvh !important; 
        height: -webkit-fill-available !important;
        position: fixed !important; /* Evita rebotes extraños en iOS */
        width: 100% !important;
        overflow: hidden !important;
    }

    /* Aseguramos que el contenedor de mensajes no empuje al footer */
    #divMainContainer {
        height: calc(100dvh - 110px) !important; /* Header (~50px) + Compose (~60px) */
    }

    /* La barra de escritura (Compose) debe estar siempre al frente */
    #divWrap #divMainContainer #divYFlow #divYFlowChating .compose {
        position: sticky !important;
        bottom: 0 !important;
        flex-shrink: 0 !important;
        z-index: 9999 !important;
        background-color: #E4EEFF !important; /* Tu color de fondo */
    }
}