/* motor-base.css — BOLETIX Motor Público
   Reset global, tipografía base y sistema de variables CSS.
   Separado del sitio de marketing (boletix-base.css).
   Sin valores hex directos — todos los colores se mapean a variables
   que branding.js sobreescribe dinámicamente desde Firestore.
   ─────────────────────────────────────────────────────────────────── */

/* ═══════════════════════════════════════════
   VARIABLES DEL SISTEMA
   Los valores por defecto son los de BOLETIX.
   branding.js sobreescribe: --color-primary,
   --color-primary-dark, --color-primary-light,
   --color-secondary, --color-accent, --font-family,
   --color-bg, --color-text (en dark mode)
   ═══════════════════════════════════════════ */
:root {
  /* — Colores de marca (sobreescritos por branding.js) — */
  --color-primary:        #6C4CF7;
  --color-primary-dark:   #5538D4;
  --color-primary-light:  #8B6CF9;
  --color-secondary:      #1A1A2E;
  --color-accent:         #FFD700;

  /* — Fondos y superficies — */
  --color-bg:             #FFFFFF;
  --color-surface:        #F8F9FA;
  --color-surface-2:      #EAECEF;
  --color-border:         #E2E8F0;

  /* — Texto — */
  --color-text:           #111827;
  --color-text-muted:     #6B7280;
  --color-text-inverse:   #FFFFFF;

  /* — Estados funcionales — */
  --color-success:        #10B981;
  --color-success-bg:     #ECFDF5;
  --color-warning:        #F59E0B;
  --color-warning-bg:     #FFFBEB;
  --color-danger:         #EF4444;
  --color-danger-bg:      #FEF2F2;
  --color-info:           #3B82F6;
  --color-info-bg:        #EFF6FF;

  /* — Tipografía (sobreescrita por branding.js) — */
  --font-family:          'Inter', system-ui, -apple-system, sans-serif;
  --font-size-base:       1rem;
  --font-size-xs:         0.75rem;
  --font-size-sm:         0.875rem;
  --font-size-lg:         1.125rem;
  --font-size-xl:         1.25rem;
  --font-size-2xl:        1.5rem;
  --font-size-3xl:        1.875rem;
  --font-size-4xl:        2.25rem;
  --font-weight-normal:   400;
  --font-weight-medium:   500;
  --font-weight-semibold: 600;
  --font-weight-bold:     700;
  --line-height-base:     1.5;
  --line-height-tight:    1.25;
  --line-height-relaxed:  1.75;

  /* — Espaciado — */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;

  /* — Radios — */
  --radius-sm:   0.25rem;
  --radius-md:   0.5rem;
  --radius-lg:   0.75rem;
  --radius-xl:   1rem;
  --radius-2xl:  1.5rem;
  --radius-full: 9999px;

  /* — Sombras — */
  --shadow-sm:  0 1px 2px rgba(0,0,0,0.05);
  --shadow-md:  0 4px 6px rgba(0,0,0,0.07), 0 1px 3px rgba(0,0,0,0.06);
  --shadow-lg:  0 10px 15px rgba(0,0,0,0.07), 0 4px 6px rgba(0,0,0,0.05);
  --shadow-xl:  0 20px 25px rgba(0,0,0,0.08), 0 8px 10px rgba(0,0,0,0.04);

  /* — Transiciones — */
  --transition-fast: 100ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 350ms ease;

  /* — Curvas de easing con más "punch" que las nativas del navegador —
     usar en animaciones de entrada/scroll-reveal, no en transiciones simples
     de hover/color (esas se quedan con --transition-*). */
  --ease-out:    cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);

  /* — Layout — */
  --container-max: 1200px;
  --container-pad: clamp(1rem, 4vw, 2rem);
  --header-height: 84px;

  /* — Z-index — */
  --z-dropdown: 100;
  --z-sticky:   200;
  --z-overlay:  300;
  --z-modal:    400;
  --z-toast:    500;
}

/* Modo oscuro — activado por branding.js si darkModeDefault == true */
.dark-mode {
  --color-bg:         #0F172A;
  --color-surface:    #1E293B;
  --color-surface-2:  #334155;
  --color-border:     #334155;
  --color-text:       #F1F5F9;
  --color-text-muted: #94A3B8;
}

/* ═══════════════════════════════════════════
   RESET MÍNIMO
   ═══════════════════════════════════════════ */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* Sin user-scalable=no — zoom habilitado (WCAG) */
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
  color: var(--color-text);
  background-color: var(--color-bg);
  min-height: 100dvh;
  overflow-x: hidden;
  /* Previene scroll horizontal en mobile */
  max-width: 100vw;
}

img,
video {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Una regla de autor (esta) siempre le gana en la cascada a la regla por
   defecto del navegador para [hidden] (display:none), sin importar
   especificidad — el origen (autor > user-agent) se evalúa antes que la
   especificidad. Sin esto, cualquier <img hidden> (ej. el logo de
   maintenance.html/404.html/root.html cuando el tenant no tiene logo
   configurado) se renderiza igual, mostrando el ícono de imagen rota. */
img[hidden],
video[hidden] {
  display: none;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

ul,
ol {
  list-style: none;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ═══════════════════════════════════════════
   LAYOUT
   ═══════════════════════════════════════════ */
.container {
  width: 100%;
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: var(--container-pad);
}

/* Offset del header fijo */
.motor-page {
  padding-top: var(--header-height);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Cualquier sección con id (ej: #sorteos) que sea destino de un link ancla
   (<a href="#sorteos">) necesita este margen — si no, el header fijo tapa
   la parte superior de la sección al saltar ahí y parece que "no pasa nada".
   Regla genérica: cubre cualquier ancla futura en cualquier página pública,
   sin tener que acordarse de agregarla sección por sección. */
section[id] {
  scroll-margin-top: calc(var(--header-height) + var(--space-4));
}

/* ═══════════════════════════════════════════
   TIPOGRAFÍA
   ═══════════════════════════════════════════ */
h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
  color: var(--color-text);
}

p {
  line-height: var(--line-height-relaxed);
}

/* Clases de tamaño */
.text-xs    { font-size: var(--font-size-xs); }
.text-sm    { font-size: var(--font-size-sm); }
.text-lg    { font-size: var(--font-size-lg); }
.text-xl    { font-size: var(--font-size-xl); }
.text-2xl   { font-size: var(--font-size-2xl); }
.text-3xl   { font-size: var(--font-size-3xl); }

/* Clases de peso */
.font-medium   { font-weight: var(--font-weight-medium); }
.font-semibold { font-weight: var(--font-weight-semibold); }
.font-bold     { font-weight: var(--font-weight-bold); }

/* Color */
.text-muted   { color: var(--color-text-muted); }
.text-primary { color: var(--color-primary); }
.text-success { color: var(--color-success); }
.text-danger  { color: var(--color-danger); }
.text-warning { color: var(--color-warning); }

/* Alineación */
.text-center { text-align: center; }
.text-right  { text-align: right; }

/* ═══════════════════════════════════════════
   UTILIDADES FLEXBOX / DISPLAY
   ═══════════════════════════════════════════ */
.flex             { display: flex; }
.flex-col         { flex-direction: column; }
.flex-wrap        { flex-wrap: wrap; }
.items-center     { align-items: center; }
.items-start      { align-items: flex-start; }
.justify-center   { justify-content: center; }
.justify-between  { justify-content: space-between; }
.justify-end      { justify-content: flex-end; }
.gap-1            { gap: var(--space-1); }
.gap-2            { gap: var(--space-2); }
.gap-3            { gap: var(--space-3); }
.gap-4            { gap: var(--space-4); }
.gap-6            { gap: var(--space-6); }
.flex-1           { flex: 1; }
.flex-shrink-0    { flex-shrink: 0; }

/* Espaciado */
.mt-2  { margin-top: var(--space-2); }
.mt-4  { margin-top: var(--space-4); }
.mt-6  { margin-top: var(--space-6); }
.mb-2  { margin-bottom: var(--space-2); }
.mb-4  { margin-bottom: var(--space-4); }
.mb-6  { margin-bottom: var(--space-6); }
.p-4   { padding: var(--space-4); }
.p-6   { padding: var(--space-6); }

.w-full { width: 100%; }

.hidden  { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ═══════════════════════════════════════════
   SKELETON LOADER
   ═══════════════════════════════════════════ */
@keyframes skeleton-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

.skeleton {
  background-color: var(--color-surface-2);
  border-radius: var(--radius-md);
  animation: skeleton-pulse 1.5s ease infinite;
}

/* ═══════════════════════════════════════════
   SPINNER
   ═══════════════════════════════════════════ */
@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner {
  display: inline-block;
  flex-shrink: 0;
  width: 1.5rem;
  height: 1.5rem;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.spinner--lg {
  width: 2.5rem;
  height: 2.5rem;
  border-width: 3px;
}

/* ═══════════════════════════════════════════
   6.3 ACCESIBILIDAD Y UX
   WCAG AA: contraste mínimo 4.5:1 en texto normal,
   3:1 en texto grande y elementos UI.
   Focus visible en todos los interactivos.
   Reducción de movimiento.
   ═══════════════════════════════════════════ */

/* Elimina outline por defecto solo cuando hay estilos propios */
:focus { outline: none; }

/* Focus visible accesible: anillo claro sobre cualquier fondo */
:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

/* Inputs: el anillo de focus ya viene de motor-components;
   garantizamos que no quede invisible en dark-mode */
.form-input:focus-visible,
.form-select:focus-visible,
.form-textarea:focus-visible {
  outline: none; /* usa box-shadow definido en motor-components */
}

/* Botones: focus adicional para navegación por teclado */
.btn:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 3px;
}

/* Reducción de movimiento — respeta preferencia del SO */
@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;
  }

  /* Excepciones: spinners deben seguir girando (son funcionales, no decorativos) */
  .spinner {
    animation-duration: 0.7s !important;
  }
}

/* Contraste de texto sobre fondos de superficie:
   --color-text-muted (#6B7280) sobre #FFFFFF = 4.62:1 ✓ AA
   En dark-mode (#94A3B8 sobre #0F172A) = 6.14:1 ✓ AA
   Tokens ya cumplen — no requieren ajuste. */

/* Imágenes: alt obligatorio en imágenes dinámicas se aplica en JS.
   Aquí prevenimos imágenes rotas visibles sin alt. */
img:not([alt]) {
  /* Indicador visual para detectar imágenes sin alt en desarrollo */
  outline: 2px dashed var(--color-danger);
}

/* Área de toque mínima: 44×44px en elementos interactivos pequeños.
   Aplica a botones que puedan quedar por debajo del mínimo. */
.btn--sm {
  min-height: 44px;
  min-width: 44px;
}

/* Chips de boleto con remove: área de toque mínima */
.ticket-chip__remove {
  min-width: 20px;
  min-height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Links de navegación: área de toque suficiente */
.motor-header__nav a,
.motor-footer__nav a {
  padding-block: var(--space-2);
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

/* Botones de filtro del grid: área de toque */
.grid-filter-btn,
.grid-ending-btn {
  min-height: 44px;
  min-width: 44px;
}

/* Paginación: área de toque */
.pagination__btn {
  min-width: 44px;
  min-height: 44px;
}

/* Cerrar modal: área de toque */
.modal__close {
  min-width: 44px;
  min-height: 44px;
}

/* Texto de error en formularios: contraste suficiente.
   --color-danger #EF4444 sobre #FFFFFF = 4.06:1 — falla AA normal.
   Corregimos a un rojo oscuro que pase 4.5:1. */
:root {
  --color-danger-text: #C0392B; /* 5.08:1 sobre #FFF ✓ */
}

.form-error {
  color: var(--color-danger-text);
}

/* Hints: --color-text-muted ya pasa 4.62:1 sobre fondo blanco ✓ */

/* Skip link: acceso directo al contenido principal para teclado */
.skip-link {
  position: absolute;
  top: -9999px;
  left: var(--space-4);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  padding: var(--space-3) var(--space-6);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  z-index: 10000;
  text-decoration: none;
}

.skip-link:focus-visible {
  top: 0;
  outline: none;
}

/* Tablas y grids: indicador visible del ítem actual */
[aria-current="page"] {
  font-weight: var(--font-weight-semibold);
}

/* Texto seleccionado: asegurar contraste */
::selection {
  background: color-mix(in srgb, var(--color-primary) 25%, transparent);
  color: var(--color-text);
}

.motor-loading {
  position: fixed;
  inset: 0;
  background: var(--color-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity var(--transition-slow);
}

.motor-loading.fade-out {
  opacity: 0;
  pointer-events: none;
}
