:root {
    --color-primary: #00796b;
    --color-primary-hover: #004d40;
    --color-accent: #3b82f6;
    --color-background: #f4f4f4;
    --color-surface: #fff;
    --color-text: #333;
    --color-text-secondary: #777;
    --box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    --border-radius-card: 12px;
    --border-radius-input: 25px;
    --border-color-light: #e0e0e0;

    /* Variables de Fuente Base */
    --font-size-base: 16px;
    --font-scale: 1.0;
}

/* 🌙 Variables del Modo Oscuro/Noche 🌙 */
body.dark-mode {
    --color-primary: #4db6ac;
    --color-primary-hover: #26a69a;
    --color-accent: #6ea8ff;
    --color-background: #121212;
    --color-surface: #1e1e1e;
    --color-text: #e0e0e0;
    --color-text-secondary: #aaaaaa;
    --box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    --border-color-light: #333333;

    /* Estilos específicos para modo oscuro */
    background-color: var(--color-background);
    color: var(--color-text);
}

/* ⚠️ Corrección para Elementos que usan colores fijos en Modo Oscuro ⚠️ */

/* Advertencia de Seguridad */
body.dark-mode .warning {
    background-color: #551a17;
    color: #ffbaba;
}

/* Lista de Fuentes (Necesita contraste) */
body.dark-mode #sourcesList,
body.dark-mode textarea#pregunta,
body.dark-mode #response-container {
    background-color: var(--color-surface);
    border-color: var(--border-color-light);
    color: var(--color-text); /* Asegura el color del texto */
}


/* --- RESET Y BASE --- */
html { box-sizing: border-box; }
*, *::before, *::after { box-sizing: inherit; }

body {
    font-family: 'Roboto', sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--color-background);
    color: var(--color-text);
    display: block;
    min-height: 90vh;
    font-size: calc(var(--font-size-base) * var(--font-scale));
    /* El modo oscuro lo controla JS añadiendo la clase 'dark-mode' */
}

.warning {
    background-color: #ffcccc;
    color: #d9534f;
    text-align: center;
/*    padding: 10px; */
    font-weight: bold;
}
.container {
    padding: 20px 10px 0;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    display: block;
}

/* --- SECCIÓN DE CABECERA (FLOAT/FLOTACIÓN) --- */
header {
    margin-bottom: 5px;
    width: 100%;
    overflow: hidden;
}

.imagen-flotante {
    float: left;
    margin-right: 0;
    max-width: 75px;
    height: auto;
    background-color: transparent !important;
}

.header-text-wrapper {
    overflow: hidden;
    text-align: center;
    padding-top: 10px;
}

h1 {
    color: var(--color-primary);
    font-weight: 700;
    margin-top: 0;
    margin-bottom: 5px;
}

h4 {
    margin-top: 5px;
    margin-bottom: 0;
    font-size: 1em;
    text-align: center;
}
/* -------------------------------------------------------------------------- */
/* AJUSTES DE LOOK & FEEL (L&F) - Top Right */
/* -------------------------------------------------------------------------- */
.controls-container {
    top: auto;
    right: 20px;
    float: right;
    margin-top: 5px; 
    margin-bottom: 5px;
    display: block;
    /* Capa superior para que sean siempre clicables */
    z-index: 100;
}

.icon-button {
    display: inline-block;
    /* Simula el 'gap' (espacio) entre elementos */
    margin-left: 5px;
    background: transparent;
    color: var(--color-text);
    border: none;
    border-radius: 4px;
    padding: 3px 6px;
    cursor: pointer;
    font-size: 1.1em;
    transition: background 0.3s, border-color 0.3s;
}
/* Estilo para las imágenes dentro de los botones de icono */
.icon-img {
    height: 16px; /* Ajusta este tamaño si es necesario */
    width: 16px;
    vertical-align: middle;
}
.icon-button:hover {
    /* CORREGIDO: Usando variables existentes */
    background: var(--border-color-light);
}

/* Estilos específicos para las letras 'A' de la fuente */
.font-small-btn {
    font-size: 0.8em;
    padding: 3px 6px;
}
.font-standard-btn {
    font-size: 1.0em;
    padding: 5px 8px;
}
.font-large-btn {
    font-size: 1.2em;
    padding: 7px 10px;
}

/* Separador (opcional) */
.separator {
    display: inline-block;
    color: var(--color-text-secondary);
    margin: 0 2px;
}

/* Ajuste para el modo oscuro */
.dark-mode .icon-button {
/* ESTA LÍNEA SE ELIMINA PARA MANTENER LA TRANSPARENCIA: */
/*    border: solid var(--border-color-light); */
}
/* --- AJUSTE DE COLOR PARA ICONOS EN MODO OSCURO --- */

body.dark-mode .icon-img {
    /* Invierte los colores (negro a blanco) para que el icono se vea sobre el fondo oscuro. */
    filter: invert(1);
}
/* --- AJUSTE DE COLOR PARA IMAGEN EN MODO OSCURO --- */
body.dark-mode .imagen-flotante {
    /* Invierte los colores (negro a blanco) para que el logo se vea sobre el fondo oscuro. */
    filter: invert(1);
}

/* --- SECCIÓN DE CONTROLES SUPERIORES (APILADOS, NO EN TABLA) --- */
.top-controls-container {
    /* Mantenemos display: table para el contenedor para que actúe como una única fila inicial */
    display: table;
    width: 100%;
    max-width: 1200px;
    /* Usamos tu espaciado original */
    border-spacing: 5px; 
    padding-left: 5px; 
    padding-right: 5px;
    margin: 5px auto 5px auto; 
}

/* Estilo para los bloques <details> (Celdas de tabla) */
.detail-block {
    /* CRUCIAL: Se comportan como celdas */
    display: table-cell; 
    width: 33.33%;
    /* Estilos de apariencia */
    background-color: var(--color-surface);
    border: 1px solid var(--border-color-light);
    border-radius: var(--border-radius-card);
    padding: 8px 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
    font-size: calc(1rem * var(--font-scale));
}

/* Para que la summary (el resumen) del details abierto ocupe todo el ancho */
.detail-block[open] {
    /* ANULA LA CÉLULA DE TABLA para que pueda ocupar el 100% de ancho */
    display: block; 
    width: 100%;
    margin-bottom: 15px;
    padding: 15px;
}

/* ⚠️ CRÍTICO: OCULTA LOS BLOQUES HERMANOS CUANDO UNO ESTÁ ABIERTO */
.top-controls-container:has(details[open]) .detail-block:not([open]) {
    /* Si el contenedor tiene un 'details[open]', entonces Oculta los que no están abiertos. */
    display: none !important; 
}

/* --- SECCIÓN DE CHAT --- */
.chat-container {
    width: 100%;
    max-width: 1200px;
    background-color: var(--color-surface);
    border-radius: var(--border-radius-card);
    box-shadow: var(--box-shadow);
    display: block;
    padding: 20px;
    padding-bottom: 5px;
}

.chat-label {
    display: block;
    color: var(--color-text-secondary);
    font-weight: bold;
    padding: 0 0 2px 0;
    text-align: left;
    margin-top: 0px;
}

textarea#pregunta {
    width: 100%;
    min-height: 60px;
    line-height: 1.2;
    border: 1px solid var(--border-color-light);
    padding: 5px 10px 10px 10px;
    border-radius: var(--border-radius-card);
    resize: vertical;
    font-size: 16px;
    transition: none;
    box-sizing: content-box;
    font-size: calc(1rem * var(--font-scale));
}

#response-container {
    width: 100%;
    min-height: 75px;
    background-color: var(--color-surface);
    white-space: pre-wrap;
    word-wrap: break-word;
    line-height: 1.6;
    border: 1px solid var(--border-color-light);
    padding: 0 10px 5px 10px;
    border-radius: var(--border-radius-card);
    transition: all 0.3s ease;
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.04);
    margin: 0;
    font-size: calc(1rem * var(--font-scale));
}

button#enviar {
    background-color: var(--color-primary);
    color: white;
    border: none;
    border-radius: 20px;
    padding: 8px 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    position: static;
    right: auto;
    bottom: auto;
    display: block;
    width: 120px;
    margin: 5px auto 0px auto;
    transition: background-color 0.3s ease, transform 0.1s ease;
}

button#enviar[disabled],
button#enviar:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: var(--color-primary);
    transform: none;
    box-shadow: none;
}
#sourcesList {
    border: 1px solid #ccc;
    padding: 10px;
    margin-top: 5px;
    background-color: #f9f9f9;
    font-size: 0.9em;
    max-height: 300px;
    overflow-y: auto;
}
#info-version {
    font-size: 0.75em;
    color: #777;
    margin-top: 10px;
}
footer {
    width: 100%;
    max-width: 1200px;
    margin: 0px auto 0 auto;
    padding: 5px 20px;
    text-align: center;
}
.disclaimer {
    font-size: 0.8em;
    color: var(--color-text-secondary);
    padding: 0;
    margin: 0;
    line-height: 1.4;
}

/* ---------------------------------------------------- */
/* CONTROL DE TAMAÑO DE FUENTE (L&F) */
/* ---------------------------------------------------- */

body.font-small {
    --font-scale: 0.85; /* 85% */
}
body.font-large {
    --font-scale: 1.2; /* 120% */
}

/* --- INDICADOR DE CARGA (SPINNER) --- */
#loading-indicator {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.25); /* Fondo oscuro semitransparente */
    display: none; /* Inicialmente oculto por JS */
    justify-content: center; /* Centrado horizontal (usando Flexbox si el padre es Flex) */
    align-items: center; /* Centrado vertical (usando Flexbox si el padre es Flex) */
    z-index: 9999;
}

.spinner {
    border: 4px solid var(--border-color-light); /* Borde claro */
    border-top: 4px solid var(--color-primary); /* Borde principal (color que gira) */
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.typing-cursor {
    display: inline-block;
    width: 8px; /* Or whatever width you prefer */
    height: 1.2em; /* Match line height */
    background-color: #333; /* Or your text color */
    animation: blink-caret 0.75s step-end infinite;
    vertical-align: middle; /* Align with text */
    margin-left: 2px;
}

@keyframes blink-caret {
    from, to { background-color: transparent }
    50% { background-color: #333; } /* Blinking color */
}

.suggestion-button {
    text-align: left; /* Alinea el texto a la izquierda */
    width: 100%;       /* Opcional: Hace que el botón ocupe todo el ancho disponible para que la alineación sea más evidente */
    padding: 0px;     /* Opcional: Añade un poco de relleno para que el texto no esté pegado a los bordes */
    margin-bottom: 1px; /* Opcional: Un pequeño margen entre botones */
    /* Otros estilos que ya puedas tener para los botones */
    background-color: #f0f0f0;
    border: 1px solid #ccc;
    cursor: pointer;
    font-size: 16px;
    border-radius: 5px;
}


/* --- MEDIA QUERIES --- */
@media (max-width: 600px) {
    /* Ajuste de controles de L&F para móvil (posición) */
    .controls-container {
        right: 10px;
        top: 5px;
        gap: 5px;
    }
    .warning {
        font-size: 0.8em;
/*        padding: 5px;*/
    }
    /* Header: Flotación desactivada y se usa Flexbox */
    header {
        /* REVERTIDO: Usar display: block en móvil para apilar elementos */
        display: block !important;
        margin: 0;
        overflow: auto; /* Para contener flotaciones internas */
        /* CRÍTICO: Centra los elementos que son inline-block */
        text-align: center;
    }
    .header-text-wrapper {
        padding: 0;
        margin: 0;
        /* CRÍTICO: Permite que el texto se alinee con la imagen */
        display: inline-block; 
        /* Alinea el texto a la izquierda DENTRO de su contenedor */
        text-align: left; 
        /* Alineación vertical */
        vertical-align: middle;
        width: auto; 
        max-width: calc(100% - 60px); /* Deja espacio para el logo (50px) y un margen (10px) */
    }
    .imagen-flotante {
        float: none;
        max-width: 50px;
        height: auto;
        margin-right: 0px;
        /* CRÍTICO: Permite que la imagen se alinee con el texto */
        display: inline-block; 
        /* Alineación vertical */
        vertical-align: middle;
    }
   h1 {
        font-size: 1.2em;
        margin: 0;
        line-height: 1.0;
    } 
    /* Opcional: ajustar h4 si también parece grande */
    h4 {
        font-size: 0.8em;
        margin-top: 5px;
        margin-bottom: 2px;
        line-height: 1.0;
    }
    /* Controles Superiores: Vuelven a apilarse de forma vertical */
    .top-controls-container {
        display: block; 
        border-spacing: 0;
        padding: 0;
    }
    .detail-block {
        display: block;
        width: 100%;
        margin-bottom: 5px;
    }
    .detail-block summary {
        font-size: 0.9em;
        line-height: 1.3;
        padding: 0;
    }
    footer {
        padding: 5px;
        margin-top: 5px;
    }
}

/* ============================================
   ESTILOS PARA NUEVOS CONTROLES DE CONSULTA
   Añadir al final de styles.css
   ============================================ */

.query-controls {
    margin-bottom: 15px;
    padding: 15px;
    background-color: var(--color-surface);
    border: 1px solid var(--border-color-light);
    border-radius: var(--border-radius-card);
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-start;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 200px;
    flex: 1;
}

.control-label {
    font-weight: 600;
    font-size: 0.9em;
    color: var(--color-text-secondary);
}

.control-select,
.control-input {
    padding: 8px 12px;
    border: 1px solid var(--border-color-light);
    border-radius: 8px;
    font-size: 1em;
    background-color: var(--color-surface);
    color: var(--color-text);
    transition: border-color 0.3s ease;
}

.control-select:focus,
.control-input:focus {
    outline: none;
    border-color: var(--color-primary);
}

.control-select {
    cursor: pointer;
}

.control-input {
    font-family: 'Roboto', monospace;
}

.control-input.invalid {
    border-color: #ef5350;
    background-color: #ffebee;
}

.error-message {
    color: #ef5350;
    font-size: 0.85em;
    margin-top: 3px;
}

/* Ajustes para modo oscuro */
body.dark-mode .control-select,
body.dark-mode .control-input {
    background-color: var(--color-surface);
    border-color: var(--border-color-light);
    color: var(--color-text);
}

body.dark-mode .control-input.invalid {
    background-color: #3d1f1f;
    border-color: #c62828;
}

/* Responsive para móvil */
@media (max-width: 600px) {
    .query-controls {
        flex-direction: column;
        padding: 10px;
        gap: 10px;
    }
    
    .control-group {
        min-width: 100%;
    }
}

/* ============================================
   🆕 AJUSTE DEL LOADING INDICATOR
   Centrado y flotante sobre el botón Enviar
   ============================================ */

#loading-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 60px;
    background-color: rgba(255, 255, 255, 0.98);
    border: 2px solid var(--color-primary);
    border-radius: 12px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    pointer-events: none;
}

body.dark-mode #loading-indicator {
    background-color: rgba(30, 30, 30, 0.98);
    border-color: var(--color-primary);
}

.spinner {
    border: 3px solid var(--border-color-light);
    border-top: 3px solid var(--color-primary);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    animation: spin 0.8s linear infinite;
}

/* --- PANEL DE AJUSTES IA --- */
.settings-panel {
    position: absolute;
    top: 45px;
    right: 0;
    width: 280px;
    background-color: var(--color-surface);
    border: 1px solid var(--border-color-light);
    border-radius: var(--border-radius-card);
    box-shadow: var(--box-shadow);
    padding: 15px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.settings-panel.hidden { display: none; }

.settings-panel h4 {
    margin: 0 0 5px 0;
    color: var(--color-primary);
    text-align: left;
    border-bottom: 1px solid var(--border-color-light);
    padding-bottom: 5px;
}

.setting-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    text-align: left;
}

.setting-item label {
    font-size: 0.85em;
    font-weight: bold;
    color: var(--color-text-secondary);
}

.setting-item select, 
.setting-item input[type="number"] {
    padding: 6px;
    border-radius: 6px;
    border: 1px solid var(--border-color-light);
    background: var(--color-background);
    color: var(--color-text);
}

.setting-info {
    font-size: 0.75em;
    color: var(--color-text-secondary);
    border-top: 1px dashed var(--border-color-light);
    padding-top: 8px;
    text-align: left;
}
