* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #000000 0%, #1a1a1a 50%, #000000 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    /* A11Y: Se establece un tamaño base y altura de línea para mejor legibilidad. */
    font-size: 16px; 
    line-height: 1.5;
    transition: background 0.3s; /* Para la transición del modo alto contraste */
}

/* A11Y: Indicador de foco claro para todos los elementos interactivos que se navegan con teclado (Tab) */
*:focus {
    outline: 3px solid #007bff; /* Color azul brillante para alta visibilidad */
    outline-offset: 2px;
    border-radius: 4px;
}

.container {
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(246, 223, 8, 0.3);
    max-width: 800px;
    width: 100%;
    overflow: hidden;
    border: 3px solid #f6df08;
    /* Agregado para layout en móvil */
    display: flex;
    flex-direction: column;
}

.header {
    background: linear-gradient(135deg, #f6df08 0%, #e6cf00 100%);
    color: #000000;
    padding: 30px;
    text-align: center;
    /* A11Y: Necesario para posicionar el botón de accesibilidad */
    position: relative; 
    transition: background 0.3s, color 0.3s;
}

.header h1 {
    font-size: 28px;
    margin-bottom: 10px;
    font-weight: 700;
}

.header p {
    font-size: 14px;
    opacity: 0.8;
    font-weight: 500;
}

.chat-container {
    /* Altura por defecto para escritorio, se ajustará en móvil */
    height: 500px; 
    overflow-y: auto;
    padding: 30px;
    background: #f9f9f9;
    flex: 1; /* Agregado para que ocupe el espacio restante */
    min-height: 0; /* Necesario para que flexbox funcione correctamente con overflow */
}

.message {
    margin-bottom: 20px;
    display: flex;
    gap: 12px;
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 18px;
    flex-shrink: 0;
    border: 2px solid #000000;
}

.message.user .message-avatar {
    background: #000000;
    color: #f6df08;
}

.message.bot .message-avatar {
    background: #f6df08;
    color: #000000;
}

.message-content {
    max-width: 70%;
    padding: 15px 20px;
    border-radius: 18px;
    line-height: 1.6;
    font-size: 15px;
    /* Se permite que el texto se ajuste si es muy largo en móvil */
    word-wrap: break-word; 
}

.message.user .message-content {
    background: #000000;
    color: #f6df08;
    border-bottom-right-radius: 4px;
    border: 2px solid #000000;
}

.message.bot .message-content {
    background: white;
    color: #000000;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    border: 2px solid #f6df08;
}

.confidence {
    font-size: 12px;
    color: #666666;
    margin-top: 8px;
    font-style: italic;
    font-weight: 500;
}

.input-container {
    padding: 20px 30px;
    background: white;
    border-top: 3px solid #f6df08;
    display: flex;
    gap: 12px;
    flex-shrink: 0; /* Asegura que no se encoja */
}

#userInput {
    flex: 1;
    padding: 15px 20px;
    border: 2px solid #f6df08;
    border-radius: 25px;
    font-size: 15px;
    outline: none;
    transition: all 0.3s;
    background: white;
}

/* A11Y: Se anula el outline:focus global aquí para usar box-shadow. */
#userInput:focus {
    border-color: #f6df08;
    box-shadow: 0 0 0 3px rgba(246, 223, 8, 0.5); 
    outline: none; /* Anula el outline global */
}

#sendBtn {
    background: linear-gradient(135deg, #f6df08 0%, #e6cf00 100%);
    color: #000000;
    border: 2px solid #000000;
    padding: 15px 30px;
    border-radius: 25px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* A11Y: Se anula el outline:focus global aquí y se usa box-shadow para el foco. */
#sendBtn:focus {
    outline: none; 
    box-shadow: 0 0 0 3px #007bff; 
}

#sendBtn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(246, 223, 8, 0.6);
    background: #f6df08;
}

#sendBtn:active {
    transform: translateY(0);
}

#sendBtn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.loading {
    display: flex;
    gap: 5px;
    padding: 10px;
}

.loading span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #f6df08;
    animation: bounce 1.4s infinite ease-in-out both;
    border: 1px solid #000000;
}

.loading span:nth-child(1) {
    animation-delay: -0.32s;
}

.loading span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1);
    }
}

.welcome-message {
    text-align: center;
    color: #333333;
    padding: 40px 20px;
}

.welcome-message h2 {
    color: #000000;
    margin-bottom: 15px;
    font-size: 26px;
    font-weight: 700;
}

.welcome-message p {
    font-size: 16px;
    line-height: 1.6;
    color: #555555;
}

.error-message {
    background: #ffebee;
    color: #c62828;
    padding: 15px 20px;
    border-radius: 12px;
    margin: 20px;
    text-align: center;
    font-weight: 600;
    border: 2px solid #ef5350;
}

/* Scrollbar personalizada */
.chat-container::-webkit-scrollbar {
    width: 10px;
}

.chat-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.chat-container::-webkit-scrollbar-thumb {
    background: #f6df08;
    border-radius: 10px;
    border: 2px solid #000000;
}

.chat-container::-webkit-scrollbar-thumb:hover {
    background: #e6cf00;
}

/* Responsive (Dispositivos pequeños) */
@media (max-width: 600px) {
    body {
        /* Eliminar padding para que el chat ocupe todo el ancho */
        padding: 0; 
        /* Usar `display: flex` y `flex-direction: column` para el layout principal en móvil */
        align-items: flex-start; 
        justify-content: flex-start;
    }

    .container {
        border-radius: 0;
        /* Ocupar toda la altura de la ventana */
        height: 100vh; 
        max-width: 100%;
        width: 100%;
        /* Eliminar bordes superior/inferior/derecho para una apariencia de aplicación nativa */
        border: none;
        border-left: 3px solid #f6df08;
        border-right: 3px solid #f6df08;
    }

    .header {
        padding: 20px 15px; /* Reducir padding horizontal */
    }

    .header h1 {
        font-size: 22px;
    }

    .header p {
        font-size: 13px;
    }

    .chat-container {
        /* Ya tiene flex: 1, pero aseguramos la altura mínima de 0 */
        height: auto; 
        padding: 20px 15px;
    }

    .message-content {
        /* Permitir que el mensaje sea más ancho en pantallas pequeñas */
        max-width: 85%; 
        font-size: 14px;
        padding: 12px 16px;
    }

    .message-avatar {
        width: 35px;
        height: 35px;
        font-size: 16px;
    }

    .input-container {
        padding: 15px;
        /* Reducir el gap para ahorrar espacio */
        gap: 8px; 
    }

    #userInput {
        padding: 12px 16px;
        font-size: 14px;
        border-radius: 20px; /* Reducir ligeramente el border-radius */
    }

    #sendBtn {
        padding: 12px 20px; /* Reducir padding para ahorrar espacio */
        font-size: 13px;
        border-radius: 20px; /* Reducir ligeramente el border-radius */
    }

    .welcome-message {
        padding: 30px 15px;
    }

    .welcome-message h2 {
        font-size: 20px;
    }

    .welcome-message p {
        font-size: 14px;
    }
}

/* A11Y: Se asegura que los botones de sugerencia también tengan un foco claro. */
.chat-message-buttons button:focus {
    outline: 3px solid #f6df08; 
    outline-offset: 2px;
    box-shadow: none;
}

/* A11Y: Estilos para el nuevo botón de alternancia de alto contraste */
.accessibility-toggle-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: rgba(0, 0, 0, 0.1);
    color: #000000;
    border: 2px solid #000000;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    font-size: 1.2rem;
    transition: background 0.3s, border-color 0.3s, color 0.3s;
}

.accessibility-toggle-btn:hover {
    background: rgba(0, 0, 0, 0.2);
}

/* ======================================= */
/* A11Y: ESTILOS PARA MODO DE ALTO CONTRASTE */
/* ======================================= */

body.high-contrast {
    background: #000000 !important;
}

body.high-contrast .container {
    background: #000000 !important;
    border: 3px solid #f6ff00 !important; /* Amarillo fluorescente para alto contraste */
    box-shadow: none !important;
}

body.high-contrast .header {
    background: #1a1a1a !important;
    color: #f6ff00 !important;
}

body.high-contrast .accessibility-toggle-btn {
    background: #f6ff00 !important;
    border-color: #ffffff !important;
    color: #000000 !important;
}

body.high-contrast .chat-container {
    background: #000000 !important;
}

body.high-contrast .welcome-message {
    background-color: #000000 !important; 
    border-left: 5px solid #ffffff !important;
    color: #ffffff !important; 
}

body.high-contrast .welcome-message h2,
body.high-contrast .welcome-message p {
    color: #f6ff00 !important;
}

/* Ajuste de contraste para burbujas de mensaje */
body.high-contrast .message-bubble {
    font-weight: bold;
}

body.high-contrast .user-message .message-bubble {
    background-color: #004c99 !important; /* Azul oscuro sobre negro */
    color: #ffffff !important;
}

body.high-contrast .bot-message .message-bubble {
    background-color: #000000 !important; 
    color: #ffffff !important;
    border: 1px solid #f6ff00 !important;
}

body.high-contrast .input-container {
    background-color: #000000 !important;
    border-top: 1px solid #f6ff00 !important;
}

body.high-contrast #userInput {
    background: #1a1a1a !important;
    color: #ffffff !important;
    border-color: #f6ff00 !important;
}

body.high-contrast #sendBtn {
    background: #f6ff00 !important;
    color: #000000 !important;
}

/* Foco en modo de alto contraste: se cambia a blanco */
body.high-contrast #sendBtn:focus,
body.high-contrast #userInput:focus {
    box-shadow: 0 0 0 3px #ffffff !important; 
    outline: none !important;
}

body.high-contrast .chat-message-buttons button {
    background: #000000 !important;
    color: #f6ff00 !important;
    border: 1px solid #f6ff00 !important;
}

body.high-contrast .chat-message-buttons button:hover,
body.high-contrast .chat-message-buttons button:focus {
    background: #f6ff00 !important;
    color: #000000 !important;
    outline: 3px solid #ffffff !important; 
}

/* Ajuste de Media Query para el botón de toggle en móvil */
@media (max-width: 600px) {
    .header {
        /* A11Y: Asegurar que el botón de toggle se ajuste bien */
        padding-right: 60px; 
    }

    .accessibility-toggle-btn {
        top: 10px;
        right: 10px;
        width: 35px;
        height: 35px;
        font-size: 1rem;
    }
}

/* A11Y: Se asegura que el form ocupe todo el espacio y contenga los elementos (ya estaba) */
/* Se añade 'gap: 10px' para el espaciado entre el input y el botón. */
#chatForm {
    display: flex;
    gap: 10px;
    width: 100%; /* Asegura que ocupe el 100% del .input-container */
}

/* ======================================= */
/* A11Y: ESTILOS PARA MODO DE ALTO CONTRASTE */
/* ======================================= */

body.high-contrast {
    background: #000000 !important;
}

body.high-contrast .container {
    /* Aquí se anula el background: white */
    background: #000000 !important; 
    border: 3px solid #f6ff00 !important; /* Amarillo fluorescente para alto contraste */
    box-shadow: none !important;
}

body.high-contrast .header {
    background: #1a1a1a !important;
    color: #f6ff00 !important;
}

body.high-contrast .accessibility-toggle-btn {
    background: #f6ff00 !important;
    border-color: #ffffff !important;
    color: #000000 !important;
}

body.high-contrast .chat-container {
    /* Aquí se anula el background: #f9f9f9; */
    background: #000000 !important;
}

body.high-contrast .welcome-message {
    background-color: #000000 !important; 
    border-left: 5px solid #ffffff !important;
    color: #ffffff !important; 
}

body.high-contrast .welcome-message h2,
body.high-contrast .welcome-message p {
    color: #f6ff00 !important;
}

/* Ajuste de contraste para burbujas de mensaje */
body.high-contrast .message-bubble {
    font-weight: bold;
}

body.high-contrast .user-message .message-content {
    background-color: #004c99 !important; /* Azul oscuro sobre negro */
    color: #ffffff !important;
    border: 2px solid #ffffff !important;
}

body.high-contrast .message.bot .message-content {
    background: #000000 !important; 
    color: #f6ff00 !important;
    border: 2px solid #f6ff00 !important;
    box-shadow: none !important;
}

body.high-contrast .message-avatar {
    border: 2px solid #ffffff !important;
}

body.high-contrast .message.user .message-avatar {
    background: #ffffff !important;
    color: #000000 !important;
}

body.high-contrast .message.bot .message-avatar {
    background: #f6ff00 !important;
    color: #000000 !important;
}

body.high-contrast .input-container {
    background-color: #000000 !important;
    border-top: 1px solid #f6ff00 !important;
}

body.high-contrast #userInput {
    background: #1a1a1a !important;
    color: #ffffff !important;
    border-color: #f6ff00 !important;
}

body.high-contrast #sendBtn {
    background: #f6ff00 !important;
    color: #000000 !important;
}

/* Foco en modo de alto contraste: se cambia a blanco */
body.high-contrast #sendBtn:focus,
body.high-contrast #userInput:focus {
    box-shadow: 0 0 0 3px #ffffff !important; 
    outline: none !important;
}

body.high-contrast .chat-message-buttons button {
    background: #000000 !important;
    color: #f6ff00 !important;
    border: 1px solid #f6ff00 !important;
}

body.high-contrast .chat-message-buttons button:hover,
body.high-contrast .chat-message-buttons button:focus {
    background: #f6ff00 !important;
    color: #000000 !important;
    outline: 3px solid #ffffff !important; 
}

/* Ajuste de Scrollbar en modo alto contraste */
body.high-contrast .chat-container::-webkit-scrollbar-track {
    background: #1a1a1a !important;
}

body.high-contrast .chat-container::-webkit-scrollbar-thumb {
    background: #f6ff00 !important;
    border: 2px solid #ffffff !important;
}

/* Ajuste de Media Query para el botón de toggle en móvil */
@media (max-width: 600px) {
    .header {
        /* A11Y: Asegurar que el botón de toggle se ajuste bien */
        padding-right: 60px; 
    }

    .accessibility-toggle-btn {
        top: 10px;
        right: 10px;
        width: 35px;
        height: 35px;
        font-size: 1rem;
    }
}