/* --- BOTÓN FLOTANTE (BURBUJA) --- */
.chatbot-toggler {
    position: fixed;
    bottom: 30px;
    right: 35px;
    outline: none;
    border: none;
    height: 60px;
    width: 60px;
    display: flex;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #8f793b; /* Color Madera */
    border: 3px solid white;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    transition: all 0.2s ease;
    z-index: 9999;
}

.chatbot-toggler:hover {
    transform: scale(1.1);
}

.chatbot-toggler img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

/* --- VENTANA PRINCIPAL DEL CHAT --- */
.chatbot {
    position: fixed;
    right: 35px;
    bottom: 100px;
    width: 350px;
    background: #fff;
    border-radius: 15px;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transform: scale(0.5);
    transform-origin: bottom right;
    box-shadow: 0 0 128px 0 rgba(0,0,0,0.1), 0 32px 64px -48px rgba(0,0,0,0.5);
    transition: all 0.1s ease;
    z-index: 9998;
    border: 2px solid #8f793b;
    display: flex;
    flex-direction: column; /* Importante para el layout flexible */
}

body.show-chatbot .chatbot {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1);
}

/* --- ENCABEZADO --- */
.chatbot header {
    background: #38761D;
    padding: 16px 0;
    position: relative;
    text-align: center;
    color: #fff;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.chatbot header h2 {
    font-size: 1.2rem;
    margin: 0;
}

.chatbot header .close-btn {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    font-size: 1.5rem;
    display: none; 
}

/* --- ÁREA DE MENSAJES --- */
.chatbox {
    overflow-y: auto;
    height: 350px; /* Altura desktop */
    padding: 15px 20px 20px; /* Reduje el padding inferior */
    background: #f4f6f8;
    flex: 1; /* Ocupa el espacio restante */
}

.chatbox .chat {
    display: flex;
    list-style: none;
    margin-bottom: 15px;
}

.chatbox .incoming span {
    width: 32px;
    height: 32px;
    background: #8f793b;
    color: #fff;
    align-self: flex-end;
    border-radius: 50%;
    text-align: center;
    line-height: 32px;
    margin: 0 10px 7px 0;
    font-size: 0.8rem;
    font-weight: bold;
}

.chatbox .outgoing {
    justify-content: flex-end;
    margin: 20px 0;
}

.chatbox .outgoing p {
    background: #38761D;
    color: #fff;
    border-radius: 10px 10px 0 10px;
    white-space: pre-wrap;
    padding: 12px 16px;
    max-width: 75%;
    font-size: 0.95rem;
}

.chatbox .incoming p {
    background: #fff;
    color: #333;
    border-radius: 10px 10px 10px 0;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    white-space: pre-wrap;
    padding: 12px 16px;
    max-width: 75%;
    font-size: 0.95rem;
}

/* --- ÁREA DE INPUT --- */
.chat-input {
    display: flex;
    gap: 5px;
    background: #fff;
    padding: 10px 20px;
    border-top: 1px solid #ddd;
    /* Eliminada posición absoluta para que fluya con flexbox */
}

.chat-input textarea {
    height: 45px;
    width: 100%;
    border: none;
    outline: none;
    resize: none;
    max-height: 180px;
    padding: 12px 0;
    font-family: 'Poppins', sans-serif;
    font-size: 0.95rem;
}

.chat-input span {
    align-self: flex-end;
    color: #38761D;
    cursor: pointer;
    height: 45px;
    display: flex;
    align-items: center;
    font-size: 1.3rem;
    transition: color 0.2s;
}

.chat-input span:hover {
    color: #8f793b;
}

/* --- RESPONSIVE MÓVIL --- */
@media (max-width: 490px) {
    .chatbot {
        right: 0;
        bottom: 0;
        height: 100%;
        border-radius: 0;
        width: 100%;
        border: none;
        display: flex;
        flex-direction: column;
    }
    
    .chatbot .chatbox {
        height: auto; /* Dejar que flexbox maneje la altura */
    }
    
    .chatbot header .close-btn {
        display: block; 
    }
}