/* ============================================================================
   [IA] tema.css — TOKENS DEL TEMA DEL PORTAL (claro y oscuro) + interruptor
   FLUJO: clientesInicio.cfm carga clientes.css -> tema.css -> tema-oscuro.css
   REGLA: este archivo es el UNICO del portal con colores hexadecimales.
          El resto usa nombres CSS o var(--token).
          tema-oscuro.css NO contiene colores literales: solo var(--token),
          para que el bloque @media print devuelva todo a claro.
   BASE: mismos tokens que CRM2/css/tema.css (homologacion ERP <-> portal).
   ============================================================================ */

/* ===== TOKENS BASE (claro) ===== */
:root {
  /* marca */
  --primary: red;
  --primary-solid: red;          /* relleno solido (h1, boton activo) */
  --on-primary: white;           /* texto/icono sobre --primary */

  /* enlaces y acentos de texto */
  --link: red;
  --link-hover: red;
  --text-accent: steelblue;
  --text-ok: darkgreen;
  --text-warn: darkgoldenrod;
  --text-info: #4279a0;
  --text-err: #b2292c;

  /* superficies */
  --surface: white;              /* tarjetas, contenido, menu */
  --surface-2: whitesmoke;       /* encabezado de tabla, panel, hover suave */
  --surface-3: #fafafa;          /* fila par / cebra */
  --surface-hover: snow;         /* hover de fila */
  --surface-sunken: #f5f5f5;     /* h2, h3, bloques hundidos */
  --input-bg: white;
  --input-border: silver;
  --bg-page: #f4f6f9;            /* lienzo detras del layout */

  /* tabla */
  --table-text: darkslategray;
  --thead-bg: whitesmoke;
  --thead-text: dimgray;
  --row-alt: #fafafa;
  --row-hover: snow;

  /* mensajes semanticos (fondo / texto) */
  --ok-bg: #def2d6;   --ok-text: #5f7357;
  --warn-bg: #f8f3d6; --warn-text: #957540;
  --info-bg: #cce8f4; --info-text: #4279a0;
  --err-bg: #ebc8c4;  --err-text: #b2292c;

  /* acentos del dashboard estandar (.tixDash) homologado del ERP */
  --tix-red-txt: darkred;
  --tix-green-txt: darkgreen;
  --tix-blue-txt: darkblue;
  --tix-purple-txt: darkviolet;
  --tix-amber-txt: darkorange;
  --tix-purple-bg: lavender;

  /* resaltados de busqueda / seleccion */
  --mark-bg: yellow;   --mark-text: black;
  --soft-mark-bg: #ffffd6;
  --overlay-bg: rgba(0,0,0,0.4);

  /* estructura */
  --border-light: whitesmoke;
  --border-med: silver;
  --border-soft: lightgray;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  --radius-sm: 4px;
  --radius: 6px;
  --radius-lg: 10px;

  /* tipografia */
  --text-body: #161616;
  --text-muted: dimgray;
  --text-soft: gray;
  --text-faint: silver;
  --text-strong: #333;
  --text-brand: darkred;
  --red-tint: #fff0f0;
  --text-dim: #666;
  --font-family: "Roboto", sans-serif;
  --font-xs: 10px;
  --font-sm: 11px;
  --font-base: 13px;
  --font-lg: 15px;
  --h1-size: 14px;
  --h2-size: 13px;
  --h3-size: 12px;

  /* espaciado y movimiento */
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing: 12px;
  --spacing-lg: 16px;
  --spacing-xl: 24px;
  --transition: 0.2s ease;

  /* estados (heredado de clientes.css; se mantiene el nombre) */
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.1);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.1);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.1);
  --info: #06b6d4;
  --info-bg: rgba(6, 182, 212, 0.1);

  /* scrollbar (navegadores modernos) */
  --scroll-thumb: #c9ccd2;
  --scroll-track: #f0f1f4;

  /* chrome del navegador / PWA */
  --theme-color: #ffffff;

  /* toast (fondo oscuro fijo en ambos temas) */
  --toast-bg: #323232;
  --toast-text: white;
}

/* ===== TOKENS OSCUROS ===== */
html[data-tema="oscuro"] {
  color-scheme: dark;

  --primary: #d32020;            /* rojo de marca, oscurecido para AA */
  --primary-solid: #d32020;
  --on-primary: #ffffff;

  --link: #ff6b6b;               /* 6.27:1 sobre --surface */
  --link-hover: #ff8f8f;
  --text-accent: #8ab4f8;
  --text-ok: #4ade80;
  --text-warn: #f5c04a;
  --text-info: #7cc4f0;
  --text-err: #f87171;

  --surface: #171a21;
  --surface-2: #1f232b;
  --surface-3: #1b1f26;
  --surface-hover: #232833;
  --surface-sunken: #1f232b;
  --input-bg: #12151b;
  --input-border: #3a4150;
  --bg-page: #0f1115;

  --table-text: #c9d1d9;
  --thead-bg: #1f232b;
  --thead-text: #a8b0bd;
  --row-alt: #1b1f26;
  --row-hover: #2a3040;

  --ok-bg: #16301c;   --ok-text: #7ee2a8;
  --warn-bg: #332c14; --warn-text: #f5c04a;
  --info-bg: #16303d; --info-text: #7cc4f0;
  --err-bg: #3a1c1a;  --err-text: #f87171;

  --tix-red-txt: #ff8a8a;
  --tix-green-txt: #7ee2a8;
  --tix-blue-txt: #8ab4f8;
  --tix-purple-txt: #c8a2ff;
  --tix-amber-txt: #f5c04a;
  --tix-purple-bg: #241d33;

  --mark-bg: #5a4a00;  --mark-text: #fff3c4;
  --soft-mark-bg: #3a3512;
  --overlay-bg: rgba(0,0,0,0.6);

  --border-light: #2a2f3a;
  --border-med: #3a4150;
  --border-soft: #3a4150;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.45);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.5);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.6);

  --text-body: #c9d1d9;          /* gris tipo "code block": menos fatiga que blanco */
  --text-muted: #a8b0bd;
  --text-soft: #98a1ad;
  --text-faint: #7d8694;
  --text-strong: #c9d1d9;
  --text-brand: #ff8a8a;
  --red-tint: #3a1c1a;
  --text-dim: #a8b0bd;

  --success-bg: rgba(74, 222, 128, 0.12);
  --warning-bg: rgba(245, 192, 74, 0.12);
  --danger-bg: rgba(248, 113, 113, 0.12);
  --info-bg: rgba(124, 196, 240, 0.12);

  --scroll-thumb: #3a4150;
  --scroll-track: #12151b;

  --theme-color: #0f1115;

  --toast-bg: #232833;
  --toast-text: #c9d1d9;
}

/* ===== Interruptor luna / sol (barra superior) ===== */
.temaToggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  font-size: var(--font-sm);
  font-family: var(--font-family);
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.temaToggle:hover {
  background: var(--surface-2);
  color: var(--primary);
  border-color: var(--border-light);
}
.temaToggle .material-icons {
  font-size: 20px;
  transition: transform 0.25s ease, color 0.2s ease;
}
.temaToggle:active .material-icons {
  transform: scale(0.88);
}
html[data-tema="oscuro"] .temaToggle .material-icons {
  color: gold;
}
@media (prefers-reduced-motion: reduce) {
  .temaToggle .material-icons { transition: none; }
}
@media (max-width: 900px) {
  /* en movil solo el icono: la barra superior no tiene ancho para la etiqueta */
  .temaToggle .etiquetaTema { display: none; }
}

/* ===== Barra de desplazamiento ===== */
html[data-tema="oscuro"] * {
  scrollbar-color: var(--scroll-thumb) var(--scroll-track);
}
html[data-tema="oscuro"] ::-webkit-scrollbar {
  width: 10px; height: 10px;
}
html[data-tema="oscuro"] ::-webkit-scrollbar-track {
  background: var(--scroll-track);
}
html[data-tema="oscuro"] ::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 6px;
}

/* ===== Impresion: SIEMPRE en claro =====
   Al re-declarar los tokens base, todas las reglas de tema-oscuro.css
   (que solo usan var()) vuelven solas a su equivalente claro. */
@media print {
  html[data-tema="oscuro"] {
    color-scheme: light;
    --bg-page: #f4f6f9;
    --primary: red;
    --primary-solid: red;
    --on-primary: white;
    --link: red;
    --link-hover: red;
    --text-accent: steelblue;
    --text-ok: darkgreen;
    --text-warn: darkgoldenrod;
    --text-info: #4279a0;
    --text-err: #b2292c;
    --surface: white;
    --surface-2: whitesmoke;
    --surface-3: #fafafa;
    --surface-hover: snow;
    --surface-sunken: #f5f5f5;
    --input-bg: white;
    --input-border: silver;
    --table-text: darkslategray;
    --thead-bg: whitesmoke;
    --thead-text: dimgray;
    --row-alt: #fafafa;
    --row-hover: snow;
    --ok-bg: #def2d6;   --ok-text: #5f7357;
    --warn-bg: #f8f3d6; --warn-text: #957540;
    --info-bg: #cce8f4; --info-text: #4279a0;
    --err-bg: #ebc8c4;  --err-text: #b2292c;
    --tix-red-txt: darkred;
    --tix-green-txt: darkgreen;
    --tix-blue-txt: darkblue;
    --tix-purple-txt: darkviolet;
    --tix-amber-txt: darkorange;
    --tix-purple-bg: lavender;
    --mark-bg: yellow;  --mark-text: black;
    --soft-mark-bg: #ffffd6;
    --border-light: whitesmoke;
    --border-med: silver;
    --border-soft: lightgray;
    --text-body: #161616;
    --text-muted: dimgray;
    --text-soft: gray;
    --text-faint: silver;
    --text-strong: #333;
    --text-brand: darkred;
    --red-tint: #fff0f0;
    --text-dim: #666;
  }
  html[data-tema="oscuro"] body {
    background: white !important;
    color: black !important;
  }
  html[data-tema="oscuro"] .ui-icon { filter: none !important; }
}
