* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    /* Evita el parpadeo azul al tocar botones en el móvil */
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: #dadbd4;
    display: flex;
    justify-content: center;
    align-items: center;
    /* Asegura altura completa dinámica en móviles */
    height: 100vh;
    height: 100dvh; 
    overflow: hidden; /* Evita scrolls raros en el cuerpo de la página */
    transition: background-color 0.3s ease;
}

/* --- DISEÑO BASE: EN MÓVIL SE COMPORTA COMO APP COMPLETA --- */
.chat-container {
    width: 100vw;
    height: 100vh;
    height: 100dvh; /* Se adapta dinámicamente si sale el teclado o barras del navegador */
    background-color: #efeae2;
    display: flex;
    flex-direction: column;
    position: relative;
    transition: background-color 0.3s ease;
}

/* Encabezado fijo superior */
.chat-header {
    background-color: #008069;
    color: white;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    transition: background-color 0.3s ease;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 38px;
    height: 38px;
    background-color: transparent;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden; /* Mantiene la imagen perfectamente redonda */
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover; /* Evita que el logo se deforme */
}

.status h2 {
    font-size: 15px;
    font-weight: 500;
}

.status p {
    font-size: 11px;
    color: #d1ecf1;
}

.header-icons {
    display: flex;
    gap: 22px;
    font-size: 18px;
    color: white;
    align-items: center;
}

.header-icons i {
    cursor: pointer;
}

/* --- COMPONENTE MENÚ DESPLEGABLE (3 PUNTOS) --- */
.menu-container {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.dropdown-menu {
    display: none; /* Oculto por defecto */
    position: absolute;
    right: 0;
    top: calc(100% + 10px);
    background-color: white;
    min-width: 220px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    border-radius: 8px;
    z-index: 100;
    padding: 6px 0;
}

/* Clase activa que inyectaremos con JS */
.dropdown-menu.show {
    display: block;
}

/* Enlaces y botones del menú */
.dropdown-menu a, .dropdown-menu button {
    color: #3b4a54;
    padding: 12px 16px;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    background: none;
    border: none;
    font-size: 14.5px;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
}

.dropdown-menu a:hover, .dropdown-menu button:hover {
    background-color: #f5f6f6;
}

/* Iconos personalizados del menú (Calculadora y Crédito) */
.menu-icon {
    width: 18px;
    height: 18px;
    object-fit: contain;
}

/* Área de Mensajes con Scroll Independiente e Imagen de Fondo */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    /* Scroll suave para móviles */
    -webkit-overflow-scrolling: touch; 
    
    /* CONFIGURACIÓN DEL FONDO CLARO */
    background-image: url('../img/chat-claro.png');
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover; /* Se estira ordenadamente para cubrir el área del chat */
}

/* Estilo de burbujas */
.message {
    max-width: 80%; /* Un poco más anchas en móvil para aprovechar espacio */
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 14.5px;
    line-height: 1.4;
    position: relative;
    display: flex;
    flex-direction: column;
    box-shadow: 0 1px 0.5px rgba(0,0,0,0.13);
    word-break: break-word; /* Evita que textos largos rompan la burbuja */
}

/* Mensaje del Bot (Izquierda) */
.message.bot {
    background-color: #ffffff;
    align-self: flex-start;
    border-top-left-radius: 0;
}

/* Mensaje del Usuario (Derecha) */
.message.user {
    background-color: #d9fdd3;
    align-self: flex-end;
    border-top-right-radius: 0;
}

.message-time {
    font-size: 10px;
    color: #667781;
    align-self: flex-end;
    margin-top: 2px;
}

/* Barra inferior fija */
.chat-input-area {
    background-color: #f0f2f5;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 -1px 3px rgba(0,0,0,0.05);
    transition: background-color 0.3s ease;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 22px;
    color: #54656f;
    cursor: pointer;
    padding: 4px;
}

.input-form {
    flex: 1;
    display: flex;
    gap: 8px;
    align-items: center;
}

#userInput {
    flex: 1;
    border: none;
    padding: 10px 14px;
    border-radius: 20px; /* Bordes más redondeados estilo WhatsApp actual */
    font-size: 15px;
    outline: none;
    background-color: white;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.send-btn {
    background-color: #00a884;
    color: white;
    border: none;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 15px;
    cursor: pointer;
    flex-shrink: 0; /* Evita que se deforme el botón de enviar */
}


/* --- SECCIÓN: ESTILOS PARA MODO OSCURO (.dark-mode) --- */
body.dark-mode {
    background-color: #111b21;
}

body.dark-mode .chat-container {
    background-color: #0b141a;
}

body.dark-mode .chat-header {
    background-color: #202c33;
}

body.dark-mode .dropdown-menu {
    background-color: #233138;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

body.dark-mode .dropdown-menu a, 
body.dark-mode .dropdown-menu button {
    color: #e9edef;
}

body.dark-mode .dropdown-menu a:hover, 
body.dark-mode .dropdown-menu button:hover {
    background-color: #182229;
}

/* CONFIGURACIÓN DEL FONDO OSCURO */
body.dark-mode .chat-messages {
    background-image: url('../img/chat-oscuro.png');
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
}

body.dark-mode .message.bot {
    background-color: #202c33;
    color: #e9edef;
}

body.dark-mode .message.user {
    background-color: #005c4b; /* Verde oscuro oficial de WhatsApp Dark */
    color: #e9edef;
}

body.dark-mode .message-time {
    color: #8696a0;
}

body.dark-mode .chat-input-area {
    background-color: #202c33;
}

body.dark-mode .icon-btn {
    color: #aebac1;
}

body.dark-mode #userInput {
    background-color: #2a3942;
    color: #e9edef;
}

body.dark-mode #userInput::placeholder {
    color: #8696a0;
}


/* --- VISTA DE ESCRITORIO (PANTALLAS GRANDES) --- */
@media (min-width: 768px) {
    .chat-container {
        width: 100%;
        max-width: 450px;
        height: 85vh;
        height: 85dvh;
        border-radius: 12px;
        overflow: hidden;
        box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    }
    
    .message {
        max-width: 75%;
    }
}