/* Tema: los colores del backoffice en claro y en oscuro.
 *
 * Los de la marca (los que usa Tailwind: `bg-card`, `text-txt`, `border-stroke`,
 * `bg-primary`…) son variables en canales RGB, así siguen andando los
 * modificadores de opacidad (`bg-primary/10`). Los componentes de base.html
 * (`.card`, `.btn`, `.badge`, inputs, tablas) también salen de acá.
 *
 * El oscuro se activa con `html.dark` (lo pone base.html antes de pintar, según
 * lo que eligió el usuario en el rail). Más abajo, las utilidades de Tailwind
 * con color fijo (`bg-white`, `text-slate-500`, `bg-amber-50`…) que aparecen en
 * las plantillas, pasadas a oscuro: así una pantalla escrita con esas clases se
 * ve bien sin tocarla. Una pantalla nueva tiene que usar los colores de la marca.
 */

:root {
    --c-body: 245 246 248;
    --c-card: 255 255 255;
    --c-subtle: 248 249 251;
    --c-muted-bg: 241 243 246;
    --c-stroke: 230 232 236;
    --c-stroke-strong: 218 222 228;
    --c-txt: 15 23 42;
    --c-txt-2: 51 65 85;
    --c-txt-muted: 100 116 139;
    --c-txt-light: 148 163 184;
    --c-primary: 37 99 235;
    --c-primary-dark: 29 78 216;
    --c-primary-light: 219 234 254;
    --c-success: 16 185 129;
    --c-success-light: 209 250 229;
    --c-danger: 239 68 68;
    --c-danger-light: 254 226 226;
    --c-warning: 245 158 11;
    --c-warning-light: 254 243 199;
    --c-sidebar: 15 23 42;
    --c-sidebar-hover: 30 41 59;
    /* Logo del rail («chajá»): el rail es oscuro en los dos temas, no cambian. */
    --c-marca-letra: 251 251 248;
    --c-marca-cresta: 200 242 62;
    --c-panel: 251 251 252;
    --c-active: 232 238 251;

    /* Pills y avisos: fondo y texto de cada tono. */
    --tone-green-bg: #dcfce7;  --tone-green-fg: #166534;
    --tone-red-bg: #fee2e2;    --tone-red-fg: #b91c1c;
    --tone-amber-bg: #fef3c7;  --tone-amber-fg: #92400e;
    --tone-blue-bg: #dbeafe;   --tone-blue-fg: #1d4ed8;
    --tone-gray-bg: #f1f3f6;   --tone-gray-fg: #475569;

    --shadow-pop: 0 10px 15px -3px rgba(15, 23, 42, .08), 0 4px 6px -4px rgba(15, 23, 42, .06);
    color-scheme: light;
}

/* Sólo en pantalla: al imprimir quedan los valores claros de :root (papel blanco). */
@media screen {
html.dark {
    --c-body: 11 15 23;
    --c-card: 18 24 35;
    --c-subtle: 22 29 41;
    --c-muted-bg: 26 33 48;
    --c-stroke: 31 38 51;
    --c-stroke-strong: 42 50 66;
    --c-txt: 230 233 239;
    --c-txt-2: 195 202 214;
    --c-txt-muted: 138 147 163;
    --c-txt-light: 107 116 133;
    --c-primary: 59 130 246;
    --c-primary-dark: 96 165 250;
    --c-primary-light: 23 37 84;
    --c-success: 52 211 153;
    --c-success-light: 6 47 34;
    --c-danger: 248 113 113;
    --c-danger-light: 69 10 10;
    --c-warning: 251 191 36;
    --c-warning-light: 66 32 6;
    --c-sidebar: 6 9 15;
    --c-sidebar-hover: 30 41 59;
    --c-panel: 14 19 28;
    --c-active: 28 39 64;

    --tone-green-bg: rgba(34, 197, 94, .15);   --tone-green-fg: #4ade80;
    --tone-red-bg: rgba(239, 68, 68, .16);     --tone-red-fg: #f87171;
    --tone-amber-bg: rgba(245, 158, 11, .15);  --tone-amber-fg: #fbbf24;
    --tone-blue-bg: rgba(59, 130, 246, .18);   --tone-blue-fg: #93c5fd;
    --tone-gray-bg: rgb(26 33 48);             --tone-gray-fg: #c3cad6;

    --shadow-pop: 0 12px 28px rgba(0, 0, 0, .45);
    color-scheme: dark;
}
}

/* ===== Oscuro: utilidades de Tailwind con color fijo =====
 * Sólo en pantalla: al imprimir, el papel es blanco. */
@media screen {
    html.dark .bg-white,
    html.dark .hover\:bg-white:hover { background-color: rgb(var(--c-card)); }
    html.dark .bg-white\/95 { background-color: rgb(var(--c-card) / .95); }
    html.dark .bg-slate-50,
    html.dark .bg-gray-50,
    html.dark .hover\:bg-slate-50:hover,
    html.dark .hover\:bg-gray-50:hover { background-color: rgb(var(--c-subtle)); }
    html.dark .bg-slate-100,
    html.dark .bg-gray-100,
    html.dark .hover\:bg-slate-100:hover,
    html.dark .hover\:bg-gray-100:hover { background-color: rgb(var(--c-muted-bg)); }
    html.dark .bg-slate-200 { background-color: rgb(var(--c-stroke-strong)); }

    html.dark .text-black,
    html.dark .text-slate-900,
    html.dark .text-slate-800,
    html.dark .hover\:text-slate-800:hover { color: rgb(var(--c-txt)); }
    html.dark .text-slate-700,
    html.dark .text-slate-600 { color: rgb(var(--c-txt-2)); }
    html.dark .text-slate-500,
    html.dark .text-gray-500 { color: rgb(var(--c-txt-muted)); }
    html.dark .text-slate-400,
    html.dark .text-gray-400 { color: rgb(var(--c-txt-light)); }

    html.dark .border-slate-100,
    html.dark .border-slate-200,
    html.dark .border-gray-200,
    html.dark .divide-slate-100 > * + * { border-color: rgb(var(--c-stroke)); }
    html.dark .border-slate-300 { border-color: rgb(var(--c-stroke-strong)); }

    /* Tonos: los fondos pastel pasan a un tinte translúcido y el texto se aclara. */
    html.dark .bg-red-50,
    html.dark .hover\:bg-red-50:hover { background-color: rgba(239, 68, 68, .1); }
    html.dark .bg-amber-50 { background-color: rgba(245, 158, 11, .1); }
    html.dark .bg-amber-100 { background-color: rgba(245, 158, 11, .16); }
    html.dark .bg-emerald-50 { background-color: rgba(16, 185, 129, .1); }
    html.dark .bg-emerald-100,
    html.dark .bg-green-100 { background-color: rgba(16, 185, 129, .16); }
    html.dark .bg-blue-50 { background-color: rgba(59, 130, 246, .12); }
    html.dark .bg-violet-50 { background-color: rgba(139, 92, 246, .12); }
    html.dark .bg-violet-100 { background-color: rgba(139, 92, 246, .18); }

    html.dark .text-red-600,
    html.dark .text-red-700,
    html.dark .text-red-800,
    html.dark .text-red-900 { color: #f87171; }
    html.dark .text-amber-600,
    html.dark .text-amber-700,
    html.dark .text-amber-800,
    html.dark .text-amber-900,
    html.dark .text-orange-700,
    html.dark .text-yellow-600 { color: #fbbf24; }
    html.dark .text-emerald-600,
    html.dark .text-emerald-700,
    html.dark .text-emerald-800,
    html.dark .text-emerald-900,
    html.dark .text-green-600,
    html.dark .text-green-700,
    html.dark .text-green-800 { color: #34d399; }
    html.dark .text-blue-600,
    html.dark .text-blue-700,
    html.dark .text-blue-800,
    html.dark .text-sky-700 { color: #93c5fd; }
    html.dark .text-violet-600,
    html.dark .text-violet-700 { color: #c4b5fd; }

    html.dark .border-red-200,
    html.dark .ring-red-200 { border-color: rgba(248, 113, 113, .35); --tw-ring-color: rgba(248, 113, 113, .35); }
    html.dark .border-amber-200,
    html.dark .ring-amber-200 { border-color: rgba(251, 191, 36, .3); --tw-ring-color: rgba(251, 191, 36, .3); }
    html.dark .border-emerald-200 { border-color: rgba(52, 211, 153, .3); }
    html.dark .border-blue-200,
    html.dark .border-sky-200 { border-color: rgba(147, 197, 253, .3); }

    /* Selector de rango de fechas (range_selector.css): todo sale de sus variables. */
    html.dark .rs {
        --rs-accent-soft: rgba(59, 130, 246, .16);
        --rs-accent-text: #93c5fd;
        --rs-border: rgb(var(--c-stroke-strong));
        --rs-text: rgb(var(--c-txt));
        --rs-muted: rgb(var(--c-txt-light));
        --rs-subtle: rgb(var(--c-txt-muted));
        --rs-hover: rgb(var(--c-muted-bg));
        --rs-bg: rgb(var(--c-card));
    }
    html.dark .rs-btn:hover,
    html.dark .rs-day.rs-preview { background: rgb(var(--c-subtle)); }
    html.dark .rs-day.rs-out,
    html.dark .rs-day:disabled,
    html.dark .rs-sep { color: rgb(var(--c-txt-light) / .5); }
    html.dark .rs-preset,
    html.dark .rs-pbtn-clear { color: rgb(var(--c-txt-2)); }

    /* Centro de ayuda (help_panel.css). */
    html.dark .help-panel,
    html.dark .help-close-btn,
    html.dark .help-card,
    html.dark .help-chat-hints button,
    html.dark .help-chat-compose,
    html.dark .help-search:focus-within { background: rgb(var(--c-card)); }
    html.dark .help-search,
    html.dark .help-msg-bot code,
    html.dark .help-icon-btn:hover,
    html.dark .help-close-btn:hover { background: rgb(var(--c-muted-bg)); }
    html.dark .help-card-link:hover,
    html.dark .help-chat-hints button:hover { background: rgb(var(--c-subtle)); border-color: #93c5fd; }
    html.dark .help-panel,
    html.dark .help-search input,
    html.dark .help-msg-bot,
    html.dark .help-chat-hints button,
    html.dark .help-chat-compose textarea,
    html.dark .help-icon-btn:hover,
    html.dark .help-close-btn:hover,
    html.dark .help-tabs button:hover,
    html.dark .help-chat-foot button:hover { color: rgb(var(--c-txt)); }
    html.dark .help-close-btn { color: rgb(var(--c-txt-2)); }
    html.dark .help-tabs button[aria-selected="true"] { color: var(--tone-blue-fg); }
    html.dark .help-panel,
    html.dark .help-tabs,
    html.dark .help-panel-head { border-color: rgb(var(--c-stroke)); }
    html.dark .help-panel-head { background: rgb(var(--c-card)); }
    html.dark .help-contexto { background: var(--tone-blue-bg); border-color: transparent; }
    html.dark .help-msg-bot a { background: var(--tone-blue-bg); color: var(--tone-blue-fg); border-color: transparent; }
    html.dark .help-msg-tools span { background: rgb(var(--c-muted-bg)); color: rgb(var(--c-txt-muted)); }
    html.dark .help-card-icon { background: var(--tone-blue-bg); color: var(--tone-blue-fg); }
    html.dark .help-card-icon.is-screen { background: var(--tone-green-bg); color: var(--tone-green-fg); }
    html.dark .help-close-btn,
    html.dark .help-card,
    html.dark .help-chat-hints button,
    html.dark .help-chat-compose,
    html.dark .help-search { border-color: rgb(var(--c-stroke-strong)); }

    /* Tom Select (CDN, sin modo oscuro propio). */
    html.dark .ts-control,
    html.dark .ts-wrapper.single.input-active .ts-control,
    html.dark .ts-dropdown,
    html.dark .ts-dropdown .optgroup-header { background: rgb(var(--c-card)); color: rgb(var(--c-txt)); }
    html.dark .ts-control,
    html.dark .ts-dropdown { border-color: rgb(var(--c-stroke-strong)); }
    html.dark .ts-control > input { color: rgb(var(--c-txt)); }
    html.dark .ts-control > input::placeholder,
    html.dark .ts-dropdown .no-results,
    html.dark .ts-dropdown .create { color: rgb(var(--c-txt-light)); }
    html.dark .ts-dropdown .active { background: rgb(var(--c-active)); color: rgb(var(--c-txt)); }
    html.dark .ts-wrapper.multi .ts-control > div { background: rgb(var(--c-muted-bg)); color: rgb(var(--c-txt)); border-color: rgb(var(--c-stroke-strong)); }
    html.dark .ts-wrapper.disabled .ts-control { background: rgb(var(--c-subtle)); }
}
