/* ============================================================
   Tema del sitio: modo oscuro y luz reducida.
   Las clases se aplican en <html> (no en <body>) para que el
   tema quede puesto antes de pintar y las variables se hereden
   a toda la página. Los colores oscuros concretos llegan desde
   tema.php, que los lee de .env.css.php.
   ============================================================ */

:root {
    --bg-primary: #f4faf6;
    --bg-secondary: #ffffff;
    --text-primary: #334155;
    --text-secondary: #475569;
    --border-color: #cde6d9;
    /* El sitio arranca en claro y el interruptor cambia a oscuro. */
    color-scheme: light;
}

.dark-mode-active {
    --bg-primary: var(--tema-oscuro-primario, #0f172a);
    --bg-secondary: var(--tema-oscuro-secundario, #1e293b);
    --text-primary: #cbd5e1;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    color-scheme: dark;
}

.reduced-lighting-active {
    --bg-primary: var(--tema-reducido-oscuro, #3f3f46);
    --bg-secondary: var(--tema-reducido-medio, #52525b);
    --text-primary: var(--tema-reducido-tenue, #71717a);
    --text-secondary: var(--tema-reducido-tenue, #71717a);
    --border-color: var(--tema-reducido-medio, #52525b);
    color-scheme: dark;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

/* El body trae utilidades de Tailwind (bg-sage-50, text-slate-700) que ganan
   por especificidad; estas reglas las dejan seguir a los tokens del tema. */
body.bg-sage-50 {
    background-color: var(--bg-primary);
}

body.text-slate-700 {
    color: var(--text-primary);
}

/* --- Superficies --- */
.dark-mode-active .bg-white,
.dark-mode-active .bg-white\/80,
.dark-mode-active .bg-sage-50,
.dark-mode-active .bg-sage-100,
.dark-mode-active .bg-sage-200,
.dark-mode-active .bg-slate-100,
.dark-mode-active .bg-slate-800 {
    background-color: var(--bg-secondary) !important;
}

.dark-mode-active .bg-em-100,
.dark-mode-active .bg-em-50\/40 {
    background-color: rgba(233, 106, 27, 0.16) !important;
}

/* Fondos con opacidad (bg-em-50/60, bg-sage-50/70...): Tailwind genera una
   clase distinta por cada fracción, así que se cubren todas de una vez. */
.dark-mode-active [class*="bg-em-50/"] {
    background-color: rgba(233, 106, 27, 0.15) !important;
}

.dark-mode-active [class*="bg-sage-50/"] {
    background-color: rgba(51, 65, 85, 0.45) !important;
}

/* Degradados claros: pasan a la superficie oscura. */
.dark-mode-active [class*="from-sage-50"],
.dark-mode-active [class*="from-white"],
.dark-mode-active .from-em-50 {
    background-image: none !important;
    background-color: var(--bg-secondary) !important;
}

/* El bloque de la cita usa un degradado cálido: en oscuro se tiñe de naranja. */
.dark-mode-active .from-em-50 {
    background-color: rgba(233, 106, 27, 0.14) !important;
}

/* --- Texto --- */
.dark-mode-active .text-slate-800,
.dark-mode-active .text-slate-700 {
    color: var(--text-primary) !important;
}

.dark-mode-active .text-slate-600,
.dark-mode-active .text-slate-500,
.dark-mode-active .text-slate-400 {
    color: var(--text-secondary) !important;
}

.dark-mode-active .text-sage-700,
.dark-mode-active .text-sage-400 {
    color: #a6d0ba !important;
}

.dark-mode-active .text-em-700,
.dark-mode-active .text-em-600 {
    color: #f4a269 !important;
}

/* --- Bordes --- */
.dark-mode-active .border-sage-200,
.dark-mode-active .border-sage-300,
.dark-mode-active .border-slate-300 {
    border-color: var(--border-color) !important;
}

.dark-mode-active .border-em-200,
.dark-mode-active .border-em-300 {
    border-color: rgba(244, 162, 105, 0.45) !important;
}

/* --- Controles de tema --- */
/* En oscuro, los botones flotantes necesitan algo más de contraste que la cabecera. */
.dark-mode-active [aria-label="Preferencias de visualización"] > button {
    background-color: #334155 !important;
    border-color: #475569 !important;
    color: #e2e8f0 !important;
}

/* El botón muestra el sol cuando el modo oscuro está activo. */
.dark-mode-active #icon-moon {
    display: none;
}

.dark-mode-active #icon-sun {
    display: block;
}

.reduced-lighting-active .bg-sage-50,
.reduced-lighting-active .text-slate-700 {
    opacity: 0.85;
}

.dark-mode-active button.bg-em-500,
.dark-mode-active a.bg-em-500 {
    background-color: var(--tema-acento-oscuro, #d65a10) !important;
}

/* --- Formularios y tablas en oscuro --- */

.dark-mode-active input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
.dark-mode-active select,
.dark-mode-active textarea {
    background-color: var(--bg-secondary) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary) !important;
}

.dark-mode-active input::placeholder,
.dark-mode-active textarea::placeholder {
    color: #94a3b8 !important;
}

.dark-mode-active table {
    border-color: var(--border-color);
}

.dark-mode-active thead,
.dark-mode-active .bg-sage-50 thead {
    background-color: rgba(51, 65, 85, 0.55) !important;
}

.dark-mode-active hr,
.dark-mode-active .divide-sage-100 > :not([hidden]) ~ :not([hidden]) {
    border-color: var(--border-color) !important;
}

.dark-mode-active code {
    background-color: rgba(51, 65, 85, 0.6) !important;
    color: #e2e8f0 !important;
}

.dark-mode-active .shadow-lg,
.dark-mode-active .shadow-md,
.dark-mode-active .shadow-sm {
    box-shadow: 0 10px 30px -18px rgba(0, 0, 0, 0.8) !important;
}
