/* --- BASES Y FUENTES --- */
body { font-family: 'Inter', sans-serif; }

/* --- CONTENEDOR PRINCIPAL (WIDGET) --- */
.widget-container {
    position: fixed; 
    bottom: 20px; 
    right: 20px; 
    z-index: 999999;
    display: flex; 
    flex-direction: column; 
    align-items: flex-end;
}

/* --- BOTÓN FLOTANTE (BURBUJA) --- */
#chatButton {
    width: 65px; 
    height: 65px; 
    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: #0006ff; 
    color: white;
    z-index: 1;
}
#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;
    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; }

#chatWindow.minimized .message-area,
#chatWindow.minimized .chb-inputbar {
    display: none !important;
}

#chatWindow.minimized {
    height: 60px !important;
    width: 300px !important;
    overflow: hidden;
}

/* --- CABECERA (HEADER) CON EFECTO GLASS --- */
.chb-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 16px;
    background: rgba(79, 70, 229, 0.95);
    backdrop-filter: blur(10px);        
    -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;
    cursor: move; 
    user-select: none;
}

.chb-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chb-header-avatar {
    position: relative;
    width: 50px;
    height: 50px;
}

.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;
}

/* Punto de estado con animación de pulso */
.chb-status-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 10px;
    height: 10px;
    background-color: #2ecc71;
    border: 2px solid #fff;
    border-radius: 50%;
    display: block;
}

.chb-status-dot::after {
    content: "";
    position: absolute;
    top: -4px;
    left: -4px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid #2ecc71;
    animation: chb-pulse 2s infinite;
    box-sizing: content-box;
}

@keyframes chb-pulse {
    0% { transform: scale(1); opacity: 1; }
    100% { transform: scale(2); opacity: 0; }
}

.chb-title {
    font-family: inherit;
    font-size: 18px;
    line-height: 0.8;
    margin: 0;
    font-weight: 700;
    color: white;
    text-transform: uppercase;
    padding: 1% 0;
}

.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: 50px; height: 50px; 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;
    word-break: break-word;
}

.bot-message {
    font-family: 'Inter', sans-serif;
    background-color: #f1f5f9;
    color: #1e293b;
    padding: .6rem .9rem;
    border-radius: .15rem .75rem .75rem .75rem;
    font-size: 15px;
    word-break: break-word;
}

/* --- 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 {
    width: 15%;
    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;
    display: flex;
    align-items: center;
    justify-content: center;
}
#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); } }

/* 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;
}

#chatWindow.maximized .bot-message, 
#chatWindow.maximized .user-message {
    max-width: 68ch;
    font-size: 1.05em;
    line-height: 1.55;
}

#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%);
}

/* RESPONSIVO MÓVIL */
@media (max-width: 500px) {
    #chatWindow {
        height: 100dvh !important; 
        height: -webkit-fill-available;
        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;
    }

    .chb-header {
        position: fixed;
        width: 100%;
        border-radius: 0px;
        top: 0;
        flex-shrink: 0;
        z-index: 1002;
        cursor: default;
    }

    .message-area {
        padding: 5rem 1rem 1rem;
        flex: 1 1 auto; 
        overflow-y: auto;
    }

    .chb-inputbar {
        position: sticky;
        bottom: 0;
        flex-shrink: 0;
        max-width: 100vw;
    }

    #userInput {
        max-width: 80%;
    }

    #sendButton {
        width: 20%;
    }
    
    #maximizeBtn {
        display: none!important;
    }
}

@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;  
    }
}