/* ================================================================
   base.css — Variables de tema, reset y tipografía
   Todas las variables son sobreescribibles desde tenant.css
   ================================================================ */

:root {
  /* --- Marca principal (tenant personaliza estas) --- */
  --brand-primary:      #1a4d8f;
  --brand-primary-dk:   #123669;
  --brand-primary-lt:   #e8f0fb;
  --brand-accent:       #2e7dd1;
  --brand-accent-lt:    #d0e4f7;

  /* --- Superficies --- */
  --bg-app:             #f0f3f8;
  --bg-surface:         #ffffff;
  --bg-sidebar:         #ffffff;
  --bg-card:            #ffffff;
  --bg-nav:             #1a4d8f;
  --bg-hover:           #f4f7fc;
  --bg-selected:        #e8f0fb;
  --bg-overlay:         rgba(15, 20, 45, 0.38);

  /* --- Texto --- */
  --text-primary:       #1a1f36;
  --text-secondary:     #4a5568;
  --text-muted:         #8898aa;
  --text-on-brand:      #ffffff;
  /* El texto sobre la barra (`--bg-nav`), que en oscuro no es el primario. */
  --text-on-nav:        #ffffff;
  --text-on-brand-dim:  rgba(255,255,255,0.65);

  /* --- Bordes --- */
  --border:             #9eaac0;
  --border-focus:       #2e7dd1;
  --border-strong:      #b0bdd4;
  /* La línea entre filas de una tabla: más suave que un borde en claro. */
  --border-fila:        #f0f2f7;

  /* --- Estados de trabajo (semáforo) --- */
  --status-lab:         #16a34a;
  --status-lab-bg:      #dcfce7;
  --status-proof:       #d97706;
  --status-proof-bg:    #fef3c7;
  --status-done:        #dc2626;
  --status-done-bg:     #fee2e2;
  --status-paused:      #6b7280;
  --status-paused-bg:   #f3f4f6;
  /* Afuera: un paso en manos de un técnico externo (no es un estado guardado). */
  --status-out:         #2563eb;
  --status-out-bg:      #dbeafe;
  /* La mesa de salida: salió a prueba o se terminó y todavía no se entregó. */
  --status-salida:      #ea580c;
  --status-salida-bg:   #ffedd5;

  /* --- Semánticos --- */
  --color-success:      #16a34a;
  --color-success-bg:   #dcfce7;
  --color-warning:      #d97706;
  --color-warning-bg:   #fef3c7;
  --color-danger:       #dc2626;
  --color-danger-bg:    #fee2e2;
  --color-info:         #2e7dd1;
  --color-info-bg:      #dbeafe;

  /* --- Tipografía --- */
  /* Las series de las gráficas (modules/estadisticas). La primera es la marca. */
  --chart-1:            var(--brand-primary);
  --chart-2:            #e07b39;
  --chart-3:            #2a9d8f;
  --chart-4:            #c0392b;
  --chart-5:            #8e6bbf;
  --chart-6:            #d4a72c;
  --chart-7:            #5d8aa8;
  --chart-8:            #7f8c8d;

  --font-ui:            'DM Sans', system-ui, sans-serif;
  --font-mono:          'DM Mono', 'Fira Mono', monospace;

  /* --- Forma y espacio --- */
  --radius-xs:          3px;
  --radius-sm:          5px;
  --radius-md:          8px;
  --radius-lg:          12px;
  --radius-xl:          16px;
  --radius-full:        9999px;

  /* --- Dimensiones del shell --- */
  --sidebar-w:          240px;
  --nav-h:              52px;

  /* --- Sombras --- */
  --shadow-xs:          0 1px 2px rgba(0,0,0,0.06);
  --shadow-sm:          0 1px 4px rgba(0,0,0,0.08);
  --shadow-md:          0 4px 16px rgba(0,0,0,0.10);
  --shadow-lg:          0 8px 32px rgba(0,0,0,0.14);
  --shadow-xl:          0 20px 60px rgba(0,0,0,0.18);

  /* --- Transiciones --- */
  --transition-fast:    0.12s ease;
  --transition-base:    0.18s ease;

  /* --- Z-index layers --- */
  --z-dropdown:         200;
  --z-sidebar:          100;
  --z-navbar:           300;
  --z-modal:            800;
  --z-toast:            1000;
  --z-tooltip:          900;

  /* --- Logo del tenant --- */
  --tenant-logo:        none;
  --tenant-name:        'AlGest';

  /* --- El encabezado de las tablas --- */
  --bg-thead:           #f7f9fc;

  /* Cuánto pesan los tintes suaves (`color-mix(… calc(8% * var(--tinte)) …)`):
     un 8 % de color sobre blanco se ve; sobre un fondo casi negro, no. */
  --tinte:              1;
  /* El mapa de calor de Estadísticas: hasta dónde se llena y el texto de
     las celdas llenas. */
  --calor-rango:        80%;
  --calor-texto:        var(--text-on-brand);

  color-scheme: light;
}

/* ----------------------------------------------------------------
   MODO OSCURO

   Lo elige cada usuario en Mi perfil y viaja con su login
   (`User.modo_oscuro`): `core/tema.js` pone `data-tema="oscuro"` en
   <html>. Sólo se redefinen tokens: todo lo que pinta con `var(--…)`
   cambia solo. El color del laboratorio sigue mandando en la barra;
   lo que se deriva de él para fondos claros (`--brand-primary-lt`,
   `--bg-selected`) lo recalcula `tema.js` hacia el oscuro.

   Quedan blancos a propósito el cuerpo de un mail (`.bz-cuerpo`, el
   HTML de otro está pensado sobre blanco) y la Lista de Aranceles,
   que es una hoja para imprimir.
   ---------------------------------------------------------------- */
:root[data-tema="oscuro"] {
  color-scheme: dark;

  /* Medidos contra las tarjetas (#19202a) y lo resaltado: el texto, 4,5:1
     como mínimo; lo seleccionado, que se distinga del fondo (1,35:1). Sobre
     el primario va texto oscuro (`--text-on-brand`). Con color del
     laboratorio los calcula `core/tema.js` (`derivadoOscuro`). */
  --brand-primary:      #72a4e4;
  --brand-primary-dk:   #4a86d4;
  --brand-primary-lt:   #223654;
  --brand-accent:       #8db8ec;
  --brand-accent-lt:    #223654;
  --text-on-brand:      #1a1f36;
  --text-on-nav:        #ffffff;

  --bg-app:             #0f141b;
  --bg-surface:         #171d26;
  --bg-sidebar:         #141a22;
  --bg-card:            #19202a;
  --bg-nav:             #1a3f70;
  --bg-hover:           #283240;
  --bg-selected:        #223654;
  --bg-overlay:         rgba(0, 0, 0, 0.6);
  --bg-thead:           #1e2631;
  --tinte:              2;
  --calor-rango:        42%;
  --calor-texto:        var(--text-primary);

  --text-primary:       #e4e8ef;
  --text-secondary:     #b3bccb;
  --text-muted:         #97a3b6;

  --border:             #4a5669;
  --border-focus:       #8db8ec;
  --border-strong:      #5f6c80;
  /* En oscuro, la línea entre filas es un borde como los demás: el #f0f2f7
     del modo claro quedaba como una raya blanca en cada fila. */
  --border-fila:        var(--border);

  --status-lab:         #34d27a;
  --status-lab-bg:      #17402a;
  --status-proof:       #f2a33a;
  --status-proof-bg:    #4a3514;
  --status-done:        #f68080;
  --status-done-bg:     #562222;
  --status-paused:      #a7b0be;
  --status-paused-bg:   #2f3742;
  --status-out:         #6cb0fb;
  --status-out-bg:      #1d3659;
  --status-salida:      #fb923c;
  --status-salida-bg:   #55300f;

  --color-success:      #34d27a;
  --color-success-bg:   #17402a;
  --color-warning:      #f2a33a;
  --color-warning-bg:   #4a3514;
  --color-danger:       #f68080;
  --color-danger-bg:    #562222;
  --color-info:         #6cb0fb;
  --color-info-bg:      #1d3659;

  --shadow-xs:          0 1px 2px rgba(0,0,0,0.4);
  --shadow-sm:          0 1px 4px rgba(0,0,0,0.45);
  --shadow-md:          0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg:          0 8px 32px rgba(0,0,0,0.55);
  --shadow-xl:          0 20px 60px rgba(0,0,0,0.6);
}

/* ----------------------------------------------------------------
   RESET
   ---------------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body { height: 100%; }

body {
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-app);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
img { max-width: 100%; display: block; }

/* ----------------------------------------------------------------
   TIPOGRAFÍA BASE
   ---------------------------------------------------------------- */
h1, h2, h3, h4, h5 { font-weight: 600; line-height: 1.2; color: var(--text-primary); }
h1 { font-size: 24px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }

p { color: var(--text-secondary); line-height: 1.65; }

code, pre {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
}

/* ----------------------------------------------------------------
   SCROLLBAR
   ---------------------------------------------------------------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ----------------------------------------------------------------
   LOADING SCREEN
   ---------------------------------------------------------------- */
.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 14px;
  color: var(--text-muted);
  font-size: 13px;
}
.loading-spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--brand-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ----------------------------------------------------------------
   ANIMACIONES UTILITARIAS
   ---------------------------------------------------------------- */
@keyframes fadeIn   { from { opacity: 0 }                        to { opacity: 1 } }
@keyframes slideUp  { from { opacity: 0; transform: translateY(14px) } to { opacity: 1; transform: translateY(0) } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-14px) } to { opacity: 1; transform: translateY(0) } }
@keyframes slideInR { from { opacity: 0; transform: translateX(20px) } to { opacity: 1; transform: translateX(0) } }
@keyframes fadeOut  { to   { opacity: 0; pointer-events: none } }

.anim-fade-in  { animation: fadeIn  var(--transition-base) both; }
/* Quien pidió menos movimiento en el sistema (o un equipo que lo dice): sin
   animaciones ni transiciones. Los modales y los menús aparecen de una. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important; animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
:root[data-sin-animaciones] *, :root[data-sin-animaciones] *::before, :root[data-sin-animaciones] *::after {
  animation-duration: 0.001ms !important; animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
}
.anim-slide-up { animation: slideUp var(--transition-base) both; }
