/* ════════════════════════════════════════════════════════════════
 * tokens.css · SGI Contenedores Patagonia
 * ─────────────────────────────────────────────────────────────────
 * UN SOLO ARCHIVO con tokens del sistema + globales/resets.
 * Este es el archivo MÁS IMPORTANTE — define la paleta, tipografía,
 * spacing, sombras, motion, y los resets que aplican a TODO el sistema.
 *
 * Cargado PRIMERO en index.html.
 * Después: components.css (componentes) + layouts.css (responsive).
 *
 * Estructura:
 *   1. :root          → tokens canónicos Grovex (paleta + escalas)
 *   2. :root          → aliases legacy (--s0/s1, --tx/t2, --navy/red, --corp-*)
 *   3. Globales       → reset, html/body, ::selection, focus rings
 *   4. Scrollbars     → estilos unificados navy-tinted
 *   5. Accesibilidad  → reduced-motion, safe-area iOS, tap-highlight
 *   6. Print          → optimizado para imprimir informes
 *
 * Convención: tokens nuevos consumen el ámbito Grovex (--navy-*, --slate-*,
 * --success-*, etc). Los aliases legacy son fallback para callsites viejos
 * que no se han migrado todavía.
 * ──────────────────────────────────────────────────────────────── */

/* ════════════════════════════════════════════════════════════════
   1. TOKENS CANÓNICOS · Grovex Design System
   ════════════════════════════════════════════════════════════════ */

:root {
  /* ── Brand · Navy (corporate) ──
     Paleta anclada en #0B2A52 (navy-700) — primary del SGI.
     Anchors curados; intermedios interpolados. */
  --navy-50: #eef2f8;
  --navy-100: #d6deec;
  --navy-200: #a7b6d1;
  --navy-300: #788fb6;
  --navy-400: #4a689b;
  --navy-500: #2a4a7e;
  --navy-600: #143c68;
  --navy-700: #0b2a52; /* ★ corporate primary + sidebar bg */
  --navy-800: #08203f;
  --navy-900: #05182f;
  --navy-950: #02101f;

  /* ── Brand · Red (CTA) ── */
  --red-50: #fef1f2;
  --red-100: #fde2e5;
  --red-200: #fab9c0;
  --red-300: #f58a95;
  --red-400: #ed5a6a;
  --red-500: #e11d2e; /* primary CTA */
  --red-600: #c8102e;
  --red-700: #a20d24;
  --red-800: #7a0a1b;
  --red-900: #520712;

  /* ── Neutrals · Slate (warm) ──
     Slate cálido: shift de ~+5R / -1G / -2B vs Tailwind original.
     Razón: el slate frío de Tailwind se siente clínico; este se lee
     más humano sin afectar contraste WCAG. */
  --slate-25: #fcfcfd;
  --slate-50: #f8f9fb;
  --slate-100: #f1f3f7;
  --slate-200: #e4e7ee;
  --slate-300: #cdd3dd;
  --slate-400: #98a0b0;
  --slate-500: #6a7283;
  --slate-600: #4d5364;
  --slate-700: #3b4456;
  --slate-800: #232838;
  --slate-900: #14192a;

  /* ── Semantic ── */
  --success-50: #ecfdf5;
  --success-100: #d1fae5;
  --success-200: #a7f3d0;
  --success-500: #10b981;
  --success-600: #059669;
  --success-700: #047857;

  --warning-50: #fffbeb;
  --warning-100: #fef3c7;
  --warning-200: #fde68a;
  --warning-500: #f59e0b;
  --warning-600: #d97706;
  --warning-700: #b45309;

  --danger-50: #fef2f2;
  --danger-100: #fee2e2;
  --danger-200: #fecaca;
  --danger-500: #ef4444;
  --danger-600: #dc2626;
  --danger-700: #b91c1c;

  --info-50: #eff6ff;
  --info-100: #dbeafe;
  --info-200: #bfdbfe;
  --info-500: #3b82f6;
  --info-600: #2563eb;
  --info-700: #1d4ed8;

  /* ── Semantic surface tokens ── */
  --bg: var(--slate-50);
  --surface: #ffffff;
  --surface-alt: var(--slate-50);
  --surface-sunken: var(--slate-100);

  --border: var(--slate-200);
  --border-strong: var(--slate-300);
  --border-subtle: var(--slate-100);

  --text-primary: var(--slate-900);
  --text-secondary: var(--slate-600);
  --text-muted: var(--slate-500);
  --text-disabled: var(--slate-400);
  --text-inverse: #ffffff;

  --link: var(--navy-600);

  /* ── Sidebar tokens ── */
  --sidebar-bg: var(--navy-700);
  --sidebar-bg-hover: var(--navy-600);
  --sidebar-active: var(--navy-800);
  --sidebar-text: #b8c4d8;
  --sidebar-text-muted: #6e7e9b;
  --sidebar-text-active: #ffffff;
  --sidebar-border: var(--navy-800);

  /* ── Type ── */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --font-features: "ss01", "cv11";

  /* Type scale · valores legacy (compactos para densidad de información).
     Las páginas Grovex (.gx-*) los reciben aquí también. */
  --text-2xs: 10px;
  --text-xs: 11px;
  --text-sm: 12px;
  --text-base: 13px;
  --text-md: 16px;
  --text-lg: 18px;
  --text-xl: 18px;
  --text-2xl: 22px;
  --text-3xl: 28px;
  --text-4xl: 36px;
  --text-5xl: 48px;

  --leading-tight: 1.2;
  --leading-snug: 1.35;
  --leading-normal: 1.5;
  --leading-relaxed: 1.65;

  --tracking-tight: -0.02em;
  --tracking-snug: -0.01em;
  --tracking-normal: 0;
  --tracking-wide: 0.02em;
  --tracking-caps: 0.06em;

  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  /* ── Spacing (4px base) ── */
  --space-0: 0;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* ── Radii ── */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-2xl: 20px;
  --radius-3xl: 20px;
  --radius-full: 999px;
  --radius-pill: 999px;

  /* ── Shadows · tintadas en navy para coherencia cromática ── */
  --shadow-xs: 0 1px 2px 0 rgba(11, 42, 82, 0.04);
  --shadow-sm: 0 1px 2px 0 rgba(11, 42, 82, 0.05), 0 1px 3px 0 rgba(11, 42, 82, 0.05);
  --shadow-md: 0 2px 4px -1px rgba(11, 42, 82, 0.06), 0 4px 8px -2px rgba(11, 42, 82, 0.06);
  --shadow-lg: 0 4px 6px -2px rgba(11, 42, 82, 0.05), 0 12px 20px -4px rgba(11, 42, 82, 0.1);
  --shadow-xl: 0 12px 16px -4px rgba(11, 42, 82, 0.08), 0 24px 40px -8px rgba(11, 42, 82, 0.14);
  --shadow-2xl: 0 12px 16px -4px rgba(11, 42, 82, 0.08), 0 24px 40px -8px rgba(11, 42, 82, 0.14);
  --shadow-focus: 0 0 0 3px rgba(11, 42, 82, 0.18);
  --shadow-focus-danger: 0 0 0 3px rgba(225, 29, 46, 0.18);

  /* ── Motion ── */
  --ease-standard: cubic-bezier(0.2, 0, 0, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --duration-instant: 0ms;
  --duration-fast: 120ms;
  --duration-base: 180ms;
  --duration-slow: 280ms;
  --duration-slower: 420ms;

  --transition-color:
    color var(--duration-fast) var(--ease-standard), background var(--duration-fast) var(--ease-standard),
    border-color var(--duration-fast) var(--ease-standard);
  --transition-shadow: box-shadow var(--duration-base) var(--ease-standard);
  --transition-transform: transform var(--duration-base) var(--ease-standard);

  /* ════════════════════════════════════════════════════════════════
     2. ALIASES LEGACY · 191 clases viejas + 3.803 inline styles
     ────────────────────────────────────────────────────────────────
     Cada uno apunta al token canónico Grovex equivalente. Cambiar
     la paleta acá reskina TODO el sistema sin tocar callsites.
     ════════════════════════════════════════════════════════════════ */

  /* Surfaces (s0=card, s1=row alterna, s2=input bg, s3=divider) */
  --s0: var(--surface);
  --s1: var(--surface-alt);
  --s2: var(--surface-sunken);
  --s3: var(--slate-200);

  /* Borders (b0=subtle, b1=default, b2=strong) */
  --b0: var(--border-subtle);
  --b1: var(--border);
  --b2: var(--border-strong);

  /* Inks (texto) */
  --tx: var(--text-primary);
  --t2: var(--text-secondary);
  --t3: var(--text-muted);
  --t3-legacy: #8a94a6;

  /* Brand: navy + blue */
  --navy: var(--navy-700);
  --navy2: var(--navy-900);
  --blue: var(--navy-500);
  --blueb: var(--navy-100);
  --bluet: var(--navy-700);

  /* Brand: red */
  --red: var(--red-500);
  --redb: var(--red-50);
  --redt: var(--red-700);

  /* Semantic colors */
  --green: var(--success-500);
  --greenb: var(--success-50);
  --greent: var(--success-700);

  --orange: var(--warning-500);
  --orangeb: var(--warning-50);
  --oranget: var(--warning-700);
  --amber: var(--warning-500);

  /* Corporate aliases */
  --corp-red: var(--red-500);
  --corp-redb: var(--red-50);
  --corp-redt: var(--red-700);
  --corp-navy: var(--navy-700);
  --corp-navyb: var(--navy-100);
  --corp-navyt: var(--navy-700);
  --corp-gold: var(--warning-500);
  --corp-goldb: var(--warning-50);
  --corp-goldt: var(--warning-700);

  /* Tokens huérfanos (purple/teal) usados por dashboards · mapeados
     al equivalente semántico Grovex */
  --tealb: var(--success-50);
  --tealt: var(--success-700);
  --purpleb: var(--info-50);
  --purplet: var(--info-700);

  /* Layout sidebar */
  --sb: 242px;
  --rl: 12px;

  /* Font weights legacy → alias canonical */
  --font-weight-normal: var(--weight-regular);
  --font-weight-medium: var(--weight-medium);
  --font-weight-semibold: var(--weight-semibold);
  --font-weight-bold: var(--weight-bold);

  /* Touch · Apple HIG / WCAG 2.5.5 */
  --tap-min: 44px;

  /* Iconos (escala consistente con stroke-width 1.5 estilo Lucide) */
  --icon-xs: 12px;
  --icon-sm: 14px;
  --icon-md: 16px;
  --icon-lg: 20px;
  --icon-xl: 24px;
  --icon-2xl: 28px;
  --icon-stroke: 1.5;

  /* Z-index (declarados para compat) */
  --z-base: 1;
  --z-sticky: 100;
  --z-drawer: 500;
  --z-overlay: 450;
  --z-modal: 600;
  --z-toast: 700;
  --z-tooltip: 800;

  /* Focus rings (alias del canonical) */
  --focus-ring: var(--shadow-focus);
  --focus-ring-error: var(--shadow-focus-danger);
  --focus-ring-danger: var(--shadow-focus-danger);
}

/* ════════════════════════════════════════════════════════════════
   3. RESET + GLOBALES (HTML/body/selección/focus base)
   ════════════════════════════════════════════════════════════════ */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* 16px base en mobile evita zoom auto en iOS al focusear inputs.
   En desktop bajamos a 13px para densidad de información. */
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}
@media (min-width: 1024px) {
  html {
    font-size: 13px;
  }
}

html,
body {
  font-family: var(--font-sans);
  line-height: var(--leading-normal);
  color: var(--tx);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: var(--bg);
  min-height: 100vh;
  text-rendering: optimizeLegibility;
  font-feature-settings: var(--font-features);
}

/* Selección de texto con color brand */
::selection {
  background: var(--navy-100);
  color: var(--navy-900);
}
input,
textarea {
  caret-color: var(--navy);
}

/* Focus visible accesible (WCAG AA) — solo navegación con teclado */
:focus {
  outline: none;
}
:focus-visible {
  outline: 2px solid var(--navy);
  outline-offset: 2px;
  border-radius: 4px;
}
button:focus-visible,
a:focus-visible,
[role="button"]:focus-visible {
  outline-offset: 3px;
}

/* Botones interactivos · cursor + tap highlight */
button,
[role="button"],
a,
[data-action] {
  -webkit-tap-highlight-color: transparent;
}
button:not(:disabled),
[role="button"],
[data-action] {
  cursor: pointer;
}
button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* Divs con data-action son botones funcionales · navegables por teclado */
[data-action]:not(button):not(a) {
  user-select: none;
}
[data-action]:not(button):not(a):focus-visible {
  outline: 2px solid var(--navy);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Imágenes responsive por defecto */
img {
  max-width: 100%;
  height: auto;
}

/* ════════════════════════════════════════════════════════════════
   4. SCROLLBARS · esquema unificado navy-tinted (default)
   ════════════════════════════════════════════════════════════════
   Aplica a todo el sistema. Sidebar y casos especiales (.tw, .sb-nav)
   tienen overrides en components.css. */

* {
  scrollbar-width: thin;
  scrollbar-color: rgba(1, 45, 85, 0.18) transparent;
}
*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background: rgba(1, 45, 85, 0.18);
  border-radius: var(--radius-pill);
  transition: background var(--duration-fast) var(--ease-out);
}
*::-webkit-scrollbar-thumb:hover {
  background: rgba(1, 45, 85, 0.35);
}
*::-webkit-scrollbar-corner {
  background: transparent;
}

/* ════════════════════════════════════════════════════════════════
   5. ACCESIBILIDAD · reduced-motion + safe-area iOS
   ════════════════════════════════════════════════════════════════ */

/* Respeta usuarios que prefieren menos movimiento (epilepsia, mareos) */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Safe-area en iOS (notch, gesture bar) */
@supports (padding: max(0px)) {
  body {
    padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
  }
  .topbar {
    padding-top: max(10px, env(safe-area-inset-top));
  }
}

/* ════════════════════════════════════════════════════════════════
   6. PRINT · optimización para imprimir informes
   ════════════════════════════════════════════════════════════════
   Oculta sidebar/topbar/UI · deja solo el contenido del informe.
   Activado por window.print() o atajo Cmd/Ctrl+P. */

@media print {
  body {
    background: #fff !important;
    color: #000 !important;
  }

  .sb,
  .topbar,
  .sb-ov,
  .btab,
  .topbar .tact,
  .gx-tabs,
  .alm-pills,
  .oa-pills,
  #TW,
  #MOD,
  #OFFLINE_BANNER,
  #NOTIF_BELL_CONTAINER,
  .sobt,
  .gx-btn,
  .btn:not(.print-show),
  .fbar,
  button[data-action] {
    display: none !important;
  }

  .main {
    margin: 0 !important;
    padding: 0 !important;
  }
  .content {
    padding: 0 !important;
    max-width: 100% !important;
  }

  /* Cards: sin sombras, bordes finos para impresión */
  .card,
  .gx-card {
    box-shadow: none !important;
    border: 1px solid #ccc !important;
    page-break-inside: avoid;
    break-inside: avoid;
    background: #fff !important;
  }
  .ch {
    background: #f5f5f5 !important;
    color: #000 !important;
  }

  /* Tablas optimizadas para tinta */
  table {
    font-size: 10pt;
  }
  table th {
    background: #eaeaea !important;
    color: #000 !important;
  }
  table tr {
    page-break-inside: avoid;
  }

  /* Badges legibles en blanco/negro */
  .bdg {
    border: 1px solid #888 !important;
    padding: 1px 6px !important;
  }

  /* A4 con márgenes razonables */
  @page {
    margin: 14mm 12mm;
    size: A4 portrait;
  }
}

/* NOTA: el informe "Mi informe" usa `printDoc()` de informes/shared.js
   que abre un popup con RPT_PRINT_CSS embebido. Por eso no necesita
   reglas @media print propias acá — el render de impresión es 100%
   independiente del CSS de la app principal y queda consistente con
   los otros informes (bodega, adquisiciones, productividad, etc). */

/* Cuando .printing-informe está en body, también esconder elementos
   en pantalla normal antes del diálogo (UX más limpia). */
body.printing-informe .sb,
body.printing-informe .topbar {
  opacity: 0;
}
