/* 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[data-theme="dark"]` (lo pone theme_toggle.js antes de pintar). 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[data-theme="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[data-theme="dark"] .bg-white,
    html[data-theme="dark"] .hover\:bg-white:hover { background-color: rgb(var(--c-card)); }
    html[data-theme="dark"] .bg-white\/95 { background-color: rgb(var(--c-card) / .95); }
    html[data-theme="dark"] .bg-slate-50,
    html[data-theme="dark"] .bg-gray-50,
    html[data-theme="dark"] .hover\:bg-slate-50:hover,
    html[data-theme="dark"] .hover\:bg-gray-50:hover { background-color: rgb(var(--c-subtle)); }
    html[data-theme="dark"] .bg-slate-100,
    html[data-theme="dark"] .bg-gray-100,
    html[data-theme="dark"] .hover\:bg-slate-100:hover,
    html[data-theme="dark"] .hover\:bg-gray-100:hover { background-color: rgb(var(--c-muted-bg)); }
    html[data-theme="dark"] .bg-slate-200 { background-color: rgb(var(--c-stroke-strong)); }

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

    html[data-theme="dark"] .border-slate-100,
    html[data-theme="dark"] .border-slate-200,
    html[data-theme="dark"] .border-gray-200,
    html[data-theme="dark"] .divide-slate-100 > * + * { border-color: rgb(var(--c-stroke)); }
    html[data-theme="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[data-theme="dark"] .bg-red-50,
    html[data-theme="dark"] .hover\:bg-red-50:hover { background-color: rgba(239, 68, 68, .1); }
    html[data-theme="dark"] .bg-amber-50 { background-color: rgba(245, 158, 11, .1); }
    html[data-theme="dark"] .bg-amber-100 { background-color: rgba(245, 158, 11, .16); }
    html[data-theme="dark"] .bg-emerald-50 { background-color: rgba(16, 185, 129, .1); }
    html[data-theme="dark"] .bg-emerald-100,
    html[data-theme="dark"] .bg-green-100 { background-color: rgba(16, 185, 129, .16); }
    html[data-theme="dark"] .bg-blue-50 { background-color: rgba(59, 130, 246, .12); }
    html[data-theme="dark"] .bg-violet-50 { background-color: rgba(139, 92, 246, .12); }
    html[data-theme="dark"] .bg-violet-100 { background-color: rgba(139, 92, 246, .18); }

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

    html[data-theme="dark"] .border-red-200,
    html[data-theme="dark"] .ring-red-200 { border-color: rgba(248, 113, 113, .35); --tw-ring-color: rgba(248, 113, 113, .35); }
    html[data-theme="dark"] .border-amber-200,
    html[data-theme="dark"] .ring-amber-200 { border-color: rgba(251, 191, 36, .3); --tw-ring-color: rgba(251, 191, 36, .3); }
    html[data-theme="dark"] .border-emerald-200 { border-color: rgba(52, 211, 153, .3); }
    html[data-theme="dark"] .border-blue-200,
    html[data-theme="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[data-theme="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[data-theme="dark"] .rs-btn:hover,
    html[data-theme="dark"] .rs-day.rs-preview { background: rgb(var(--c-subtle)); }
    html[data-theme="dark"] .rs-day.rs-out,
    html[data-theme="dark"] .rs-day:disabled,
    html[data-theme="dark"] .rs-sep { color: rgb(var(--c-txt-light) / .5); }
    html[data-theme="dark"] .rs-preset,
    html[data-theme="dark"] .rs-pbtn-clear { color: rgb(var(--c-txt-2)); }

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

    /* Tom Select (CDN, sin modo oscuro propio). */
    html[data-theme="dark"] .ts-control,
    html[data-theme="dark"] .ts-wrapper.single.input-active .ts-control,
    html[data-theme="dark"] .ts-dropdown,
    html[data-theme="dark"] .ts-dropdown .optgroup-header { background: rgb(var(--c-card)); color: rgb(var(--c-txt)); }
    html[data-theme="dark"] .ts-control,
    html[data-theme="dark"] .ts-dropdown { border-color: rgb(var(--c-stroke-strong)); }
    html[data-theme="dark"] .ts-control > input { color: rgb(var(--c-txt)); }
    html[data-theme="dark"] .ts-control > input::placeholder,
    html[data-theme="dark"] .ts-dropdown .no-results,
    html[data-theme="dark"] .ts-dropdown .create { color: rgb(var(--c-txt-light)); }
    html[data-theme="dark"] .ts-dropdown .active { background: rgb(var(--c-active)); color: rgb(var(--c-txt)); }
    html[data-theme="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[data-theme="dark"] .ts-wrapper.disabled .ts-control { background: rgb(var(--c-subtle)); }
}

/* ===== Componentes (de FACTU base.html) ===== */
body { font-family: 'Geist', system-ui, sans-serif; background: rgb(var(--c-body)); color: rgb(var(--c-txt)); }
input[type="text"],input[type="email"],input[type="password"],input[type="number"],
input[type="url"],input[type="tel"],input[type="search"],textarea {
    width:100%;border-radius:0.5625rem;border:1px solid rgb(var(--c-stroke-strong));
    background-color:rgb(var(--c-card));padding:0.5rem 0.75rem;color:rgb(var(--c-txt));
    outline:none;font-size:0.875rem;transition:all .15s;height:2.5rem;
}
input::placeholder, textarea::placeholder { color:rgb(var(--c-txt-light)); }
input:focus,select:focus,textarea:focus { border-color:rgb(var(--c-primary));box-shadow:0 0 0 3px rgb(var(--c-primary) / .12); }
.btn { display:inline-flex;align-items:center;gap:0.5rem;padding:0.5rem 1rem;border-radius:0.5625rem;font-size:0.875rem;font-weight:500;transition:all .15s;cursor:pointer;border:1px solid transparent; }
.btn-primary { background-color:rgb(var(--c-primary));color:#fff;font-weight:600; }
.btn-primary:hover { background-color:rgb(var(--c-primary-dark)); }
.btn-secondary { background-color:rgb(var(--c-card));color:rgb(var(--c-txt));border-color:rgb(var(--c-stroke-strong)); }
.btn-secondary:hover { background-color:rgb(var(--c-subtle)); }
.btn-ghost { background-color:transparent;color:rgb(var(--c-txt-muted)); }
.btn-ghost:hover { background-color:rgb(var(--c-muted-bg));color:rgb(var(--c-txt)); }
.btn-sm { padding:0.25rem 0.75rem;font-size:0.8125rem; }
.badge { display:inline-flex;align-items:center;padding:0.1875rem 0.625rem;border-radius:9999px;font-size:0.75rem;font-weight:600;white-space:nowrap; }
.badge-success { background:var(--tone-green-bg);color:var(--tone-green-fg); }
.badge-danger { background:var(--tone-red-bg);color:var(--tone-red-fg); }
.badge-gray { background:var(--tone-gray-bg);color:var(--tone-gray-fg); }
.badge-warning { background:var(--tone-amber-bg);color:var(--tone-amber-fg); }
.badge-info { background:var(--tone-blue-bg);color:var(--tone-blue-fg); }
.sit-1 { background:var(--tone-green-bg);color:var(--tone-green-fg); }
.sit-2 { background:var(--tone-amber-bg);color:var(--tone-amber-fg); }
.sit-3 { background:var(--tone-amber-bg);color:var(--tone-amber-fg);box-shadow:inset 0 0 0 1px currentColor; }
.sit-4 { background:var(--tone-red-bg);color:var(--tone-red-fg); }
.sit-5, .sit-6 { background:var(--tone-red-bg);color:var(--tone-red-fg);box-shadow:inset 0 0 0 1px currentColor; }
.bcra-historia { font-size:0.75rem; }
.bcra-historia th, .bcra-historia td { text-align:center;padding:2px 4px;white-space:nowrap; }
.bcra-historia td span { display:block;padding:1px 4px;border-radius:0.25rem; }
.bcra-historia .entidad { max-width:12rem;overflow:hidden;text-overflow:ellipsis; }
.btn-danger { background-color:rgb(var(--c-danger));color:#fff;font-weight:600; }
.btn-danger:hover { background-color:rgb(var(--c-danger) / .9); }
select:not([multiple]) {
    width:100%;height:2.5rem;border-radius:0.5625rem;border:1px solid rgb(var(--c-stroke-strong));
    background-color:rgb(var(--c-card));padding:0 0.75rem;color:rgb(var(--c-txt));font-size:0.875rem;outline:none;
}
select[multiple] { width:100%;border-radius:0.5625rem;border:1px solid rgb(var(--c-stroke-strong));background-color:rgb(var(--c-card));color:rgb(var(--c-txt));font-size:0.875rem;padding:0.25rem; }
input[type="date"] {
    width:100%;height:2.5rem;border-radius:0.5625rem;border:1px solid rgb(var(--c-stroke-strong));
    background-color:rgb(var(--c-card));padding:0 0.75rem;color:rgb(var(--c-txt));font-size:0.875rem;
}
.card { background:rgb(var(--c-card));border:1px solid rgb(var(--c-stroke));border-radius:0.875rem; }
.card-title { font-size:1rem;font-weight:600;color:rgb(var(--c-txt));line-height:1.5;letter-spacing:-0.01em; }
.table-container { overflow-x:auto; }
.table-container table { width:100%;border-collapse:collapse;font-size:0.875rem; }
.table-container th { text-align:left;padding:0.625rem 1rem;font-size:0.75rem;font-weight:600;text-transform:uppercase;letter-spacing:0.05em;color:rgb(var(--c-txt-muted));border-bottom:1px solid rgb(var(--c-stroke)); }
.table-container td { padding:0.625rem 1rem;border-bottom:1px solid rgb(var(--c-stroke));color:rgb(var(--c-txt)); }
.table-container tr:hover td { background:rgb(var(--c-subtle)); }
/* Menú superior */
.topbar { background:rgb(var(--c-card));border-bottom:1px solid rgb(var(--c-stroke)); }
.nav-link { display:inline-flex;align-items:center;gap:0.375rem;padding:0.5rem 0.75rem;border-radius:0.5625rem;font-size:0.875rem;font-weight:500;color:rgb(var(--c-txt-2));cursor:pointer;list-style:none; }
.nav-link:hover, .nav-link.active { background:rgb(var(--c-muted-bg));color:rgb(var(--c-txt)); }
.nav-dd { position:relative; }
.nav-dd > summary::-webkit-details-marker { display:none; }
.nav-dd-panel { position:absolute;left:0;top:calc(100% + 4px);min-width:12rem;z-index:50;padding:0.375rem;background:rgb(var(--c-card));border:1px solid rgb(var(--c-stroke));border-radius:0.75rem;box-shadow:var(--shadow-pop); }
.nav-dd-panel.right { left:auto;right:0; }
.nav-dd-item { display:block;width:100%;text-align:left;padding:0.5rem 0.75rem;border-radius:0.5rem;font-size:0.875rem;color:rgb(var(--c-txt-2));background:none;border:0;cursor:pointer; }
.nav-dd-item:hover { background:rgb(var(--c-muted-bg));color:rgb(var(--c-txt)); }
