/* --- BASES Y FUENTES --- */
body { font-family: 'Inter', sans-serif; }

/* --- CONTENEDOR PRINCIPAL (WIDGET) --- */
.widget-container {
    position: fixed; 
    bottom: 20px; 
    right: 20px; 
    z-index: 10000;
    display: flex; 
    flex-direction: column; 
    align-items: flex-end;
}

/* --- BOTÓN FLOTANTE (BURBUJA) --- */
#chatButton {
    width: 56px; 
    height: 56px; 
    border-radius: 50%;
    display: flex; 
    justify-content: center; 
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.2);
    transition: transform .3s ease, background-color .3s ease;
    background: #4f46e5; 
    color: white;
    z-index: 1; /* Corregido a 1 para que sea visible */
}
#chatButton:hover { transform: scale(1.05); }

/* --- VENTANA DE CHAT --- */
#chatWindow {
    background-color: white; 
    border-radius: 1rem;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.2);
    width: 420px; 
    height: 500px;
    margin-bottom: 10px; 
    display: none; 
    flex-direction: column; 
    overflow: hidden; /* Mantiene el header y footer en su sitio */
    transform: scale(0.9); 
    opacity: 0;
    transition: transform .3s ease-out, opacity .3s ease-out, width 0.3s ease, height 0.3s ease;
}
#chatWindow.open { display: flex; transform: scale(1); opacity: 1; }

/* Cuando está minimizado, ocultamos el contenido pero dejamos el header */
#chatWindow.minimized .message-area,
#chatWindow.minimized .chb-inputbar {
    display: none !important;
}

#chatWindow.minimized {
    height: 60px !important; /* Altura del header */
    width: 300px !important; /* Un poco más angosto al estar minimizado */
}

/* --- CABECERA (HEADER) CON EFECTO GLASS --- */
.chb-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: rgba(79, 70, 229, 0.95); /* Azul con transparencia */
    backdrop-filter: blur(10px);        /* Desenfoque */
    -webkit-backdrop-filter: blur(10px);
    color: white;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    position: sticky;
    top: 0;
    z-index: 100;
    flex-shrink: 0; /* No se aplasta */
}

.chb-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chb-header-avatar {
    position: relative;
    width: 35px;
    height: 35px;
}

.chb-header-avatar img, 
.chb-avatar-placeholder {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chb-status-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 10px;
    height: 10px;
    background: #46b450;
    border: 2px solid #4f46e5;
    border-radius: 50%;
}

.chb-title {
    font-size: 14px;
    margin: 0;
    font-weight: 700;
    color: white;
    text-transform: uppercase;
}

.chb-header-controls {
    display: flex;
    column-gap: 10px;
}

#chatHeader .cab-btn-chtb {
    background: #00000030;
    border: none;
    color: white;
    cursor: pointer;
    padding: 5px;
    display: flex;
    opacity: 0.8;
    transition: opacity 0.2s;
    box-shadow: 0 2px 0px #222222b8;
    border-radius: 6px;
}
#chatHeader .cab-btn-chtb:hover {
    opacity: 1;
    background: #00000040;
    transform: scale(1.1);
    transition: transform 0.5s ease-out;
}

/* --- ÁREA DE MENSAJES --- */
.message-area {
    flex-grow: 1; 
    padding: 1rem; 
    overflow-y: auto; 
    display: flex; 
    flex-direction: column; 
    gap: 1rem;
    background: #fff;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    scrollbar-color: rgb(191 191 244) rgb(237, 242, 250);
}

#chatWindow .message-content a { color: #1700ff!important; }
#chatWindow .message-content a:hover { color: #00006e!important; text-decoration: underline; }

.message-wrapper { display: flex; align-items: flex-start; max-width: 90%; }
.bot-wrapper { align-self: flex-start; }
.user-wrapper { align-self: flex-end; flex-direction: row-reverse; }

.avatar-container { width: 32px; height: 32px; flex-shrink: 0; }
.bot-wrapper .avatar-container { margin-right: 8px; }
.user-wrapper .avatar-container { margin-left: 8px; }

.user-message {
    background-color: #4f46e5; 
    color: white;
    padding: .6rem .9rem; 
    border-radius: .75rem .75rem .15rem .75rem;
    font-size: 14px;
}

.bot-message {
    background-color: #f1f5f9; 
    color: #1e293b;
    padding: .6rem .9rem; 
    border-radius: .15rem .75rem .75rem .75rem;
    font-size: 14px;
}

/* --- INPUT BAR (FOOTER) FIXED --- */
.chb-inputbar { 
    padding: 12px; 
    border-top: 1px solid #e5e7eb; 
    display: flex; 
    gap: 8px; 
    background: rgba(241, 245, 249, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    position: sticky;
    bottom: 0;
    z-index: 100;
    flex-shrink: 0;
}

.chb-input {
    flex-grow: 1;
    padding: 10px!important;
    border: 1px solid #d1d5db!important;
    border-radius: 10px!important;
    outline: none;
    font-size: 16px;
    color: #000!important;
}

#sendButton {
    background: #4f46e5;
    color: #fff;
    border: 2px solid #4f46e5;
    border-radius: 9px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.7);
    line-height: 0;
    cursor: pointer;
    transition: transform 0.2s;
}
#sendButton:hover { background: #3831a5; transform: scale(1.1); }

/* --- ANIMACIONES --- */
.loading-dot {
    width: 6px; height: 6px; background-color: #4f46e5; border-radius: 50%;
    display: inline-block; margin: 0 1px; animation: bounce .5s infinite alternate;
}
@keyframes bounce { 0% { transform: translateY(0); } 100% { transform: translateY(-4px); } }

/* Header arrastrable */
.chb-header { cursor: move; user-select: none; }

/* Estado Maximizado */
#chatWindow.maximized {
    position: relative;
    width: 96vw!important;
    height: 95vh !important;
    top: 4em !important;
    left: auto!important;
    right: auto !important;
    bottom: auto !important;
    transform: none !important;
    background-color: #f8fafc;
    box-shadow: 0 0 0 50em #fff;
}

/* --- AJUSTES DE TEXTO EN MAXIMIZADO --- */
#chatWindow.maximized .bot-message, 
#chatWindow.maximized .user-message {
    max-width: 68ch; /* Tu excelente elección */
    font-size: 1.1em; /* Un poquito más grande para aprovechar el espacio */
    line-height: 1.6; /* Más aire entre líneas para textos largos */
}

/* Hacemos que el área de mensajes se vea más como un documento */
#chatWindow.maximized .message-area {
    padding:2rem 12%;
    background: #F0F1F0;
    background: linear-gradient(90deg, rgba(240, 241, 240, 1) 10%, rgba(255, 255, 255, 1) 10%, rgba(255, 255, 255, 1) 90%, rgba(240, 241, 240, 1) 90%);
}

/* Estado Minimizado (solo en Desktop para que no flote raro) */
#chatWindow.minimized {
    height: 60px !important;
    overflow: hidden;
}

@media (max-width: 500px) {
    #chatWindow {
        /* En lugar de 100vh, usamos dvh para que se ajuste dinámicamente */
        height: 100dvh !important; 
        height: -webkit-fill-available; /* Truco extra para navegadores iOS */
        width: 100vw;
        max-width:430px;
        border-radius:0px;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        display: none; 
        flex-direction: column;
        z-index: 10001;
    }

    /* Aseguramos que el header nunca se mueva del tope físico */
    .chb-header {
        position: fixed;
        width: 100%;
        border-radius:0px;
        top: 0;
        flex-shrink: 0;
        z-index: 1002;
    }

    /* El área de mensajes debe ser flexible para absorber el empuje del teclado */
    .message-area {
        padding: 5rem 1rem 1rem;
        flex: 1 1 auto; 
        overflow-y: auto;
    }

    /* El input bar también debe ser sticky al fondo del teclado */
    .chb-inputbar {
        position: sticky;
        bottom: 0;
        flex-shrink: 0;
    }
    
    /* Ocultar botones de arrastre minimizado y maximizado en móvil (No son prácticos ahí) */
    #maximizeBtn {
    display: none!important;
    }
    .chb-header { cursor: default; }
    }

@media only screen and (orientation: landscape) and (max-width:980px){
#chatWindow.open {
    max-height: 95vh;
    transform:translateY(20vh)!important;
    z-index: 9;
}
#chatWindow.maximized {
  top:0.3em!important  
}
}
