/* ============================================================================
 * base.css — Reset, tipografía base y prevención de gestos nativos
 * ----------------------------------------------------------------------------
 * Incluye:
 *  - Reset universal (box-sizing, márgenes, paddings)
 *  - Tipografía base y legibilidad
 *  - Prevención de pull-to-refresh y swipe lateral del historial
 *  - Eliminación de tap-highlight de iOS
 *  - Estilos de focus para accesibilidad (navegación por teclado)
 *  - Scroll táctil sin interrupciones
 *  - Bloqueo de zoom en inputs (16px mínimo)
 * ============================================================================ */

/* --- Reset universal (estilo moderno de Joshua Comeau + mejoras propias) --- */
*, *::before, *::after { box-sizing: border-box; }
*, *::before, *::after { margin: 0; padding: 0; }

html {
  font-family: var(--font-family-aplicada, 'Roboto', system-ui, sans-serif);
  font-size: var(--font-size-aplicada, 100%);
  line-height: var(--line-height-base, 1.5);
  /* Prevenir "overscroll-behavior" para evitar pull-to-refresh */
  overscroll-behavior-y: none;
  /* Bloquear el gesto horizontal de "swipe back/forward" del navegador */
  overscroll-behavior-x: none;
  /* En iOS Safari, prevenir el "bounce" */
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  /* Suavizar scroll */
  scroll-behavior: smooth;
  /* Prevenir selección accidental de texto al hacer gestos largos en iOS */
  -webkit-touch-callout: none;
  user-select: none;
  /* Pero permitir selección dentro de inputs y textos largos editables */
}

/* Permitir selección en inputs, textareas y áreas explícitamente marcadas */
input, textarea, [contenteditable="true"], .seleccionable {
  user-select: text;
  -webkit-user-select: text;
  -webkit-touch-callout: default;
}

body {
  font-family: inherit;
  font-size: 1rem;
  line-height: inherit;
  color: var(--color-texto);
  background-color: var(--color-fondo);
  /* Bloquear pull-to-refresh: overscroll-behavior en body */
  overscroll-behavior-y: contain;
  /* Bloquear swipe lateral del navegador */
  overscroll-behavior-x: contain;
  /* Prevenir el zoom en iOS al pulsar inputs: el body no debe hacer zoom */
  touch-action: manipulation;
  /* Eliminar huecos de scroll en iOS */
  -webkit-overflow-scrolling: touch;
  /* Soporte para muescas de iPhone X+ */
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0)
           env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
  min-height: 100vh;
  min-height: 100dvh; /* dynamic viewport height (más fiable en móvil) */
}

/* Headings y tipografía básica */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.25;
  color: var(--color-texto);
}
h1 { font-size: var(--font-size-xxl, 1.5rem); }
h2 { font-size: var(--font-size-xl, 1.25rem); }
h3 { font-size: var(--font-size-lg, 1.125rem); }

p { line-height: var(--line-height-base); }

a {
  color: var(--color-acento);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

/* Listas */
ul, ol { list-style: none; }

/* Tablas (por si se usan) */
table { border-collapse: collapse; width: 100%; }

/* --- Inputs: 16px mínimo para evitar zoom en iOS --- */
input[type="text"], input[type="email"], input[type="search"],
input[type="password"], input[type="number"], input[type="tel"],
input[type="url"], input[type="date"], input[type="time"],
textarea, select {
  font-family: inherit;
  font-size: 16px; /* Innegociable: evitar zoom automático iOS */
  line-height: 1.4;
  color: var(--color-texto-input);
  background-color: var(--color-fondo-input);
  border: 1px solid var(--color-borde-input);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  width: 100%;
  outline: none;
  transition: border-color var(--transicion-rapida), box-shadow var(--transicion-rapida);
}
input[type="text"]:focus, input[type="email"]:focus, input[type="search"]:focus,
input[type="password"]:focus, input[type="number"]:focus, input[type="tel"]:focus,
input[type="url"]:focus, input[type="date"]:focus, input[type="time"]:focus,
textarea:focus, select:focus {
  border-color: var(--color-acento);
  box-shadow: 0 0 0 3px var(--color-acento-claro);
}

/* Placeholders con suficiente contraste (accesibilidad) */
::placeholder {
  color: var(--color-texto-3);
  opacity: 1;
}

/* Botones base (sin estilo por defecto del navegador) */
button {
  font-family: inherit;
  font-size: 1rem;
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  /* Eliminar tap highlight */
  -webkit-tap-highlight-color: transparent;
}

/* --- Focus visible para accesibilidad (tabulación) --- */
:focus-visible {
  outline: 3px solid var(--color-acento);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
/* Quitar outline para ratón, mantenerlo solo para teclado */
:focus:not(:focus-visible) { outline: none; }

/* --- Scrollbar personalizada (en navegadores que lo soportan) --- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--color-fondo-3);
}
::-webkit-scrollbar-thumb {
  background: var(--color-borde);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--color-texto-3);
}

/* --- Prevenir scroll horizontal general --- */
html, body {
  max-width: 100%;
  overflow-x: hidden;
}

/* --- Imágenes responsive --- */
img, svg, video, canvas {
  max-width: 100%;
  height: auto;
  display: block;
}

/* --- Aspecto del modo de alto contraste del sistema (forzar borders visibles) --- */
@media (prefers-contrast: more) {
  :root, [data-tema] {
    --color-borde: currentColor;
    --color-borde-input: currentColor;
  }
}

/* --- Reducir movimiento para usuarios sensibles (accesibilidad) --- */
@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;
  }
}

/* --- Ocultar visualmente pero mantener accesible para screen readers --- */
.solo-lectura {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --- Atributo hidden fiable (algunos navegadores lo dibujan mal) --- */
[hidden] { display: none !important; }

/* --- Selección de texto (customizada al color del tema) --- */
::selection {
  background-color: var(--color-acento-claro);
  color: var(--color-texto);
}
