/* =============================================================
   base.css — Reset, tipografía, utilidades y accesibilidad.
   Móvil primero. Solo tokens de tokens.css, nunca colores sueltos.
   ============================================================= */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; scroll-padding-top: var(--space-6); }

body {
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  font-weight: var(--fw-regular);
  color: var(--text);
  background-color: var(--bg);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  transition: background-color var(--transition), color var(--transition);
}

h1, h2, h3, h4 { font-weight: var(--fw-bold); line-height: 1.2; color: var(--text); letter-spacing: -0.01em; text-wrap: balance; }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-md); }
h3 { font-size: var(--fs-base); }
p { text-wrap: pretty; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
button { font-family: inherit; font-size: inherit; cursor: pointer; border: none; background: none; color: inherit; }
img, svg { max-width: 100%; display: block; }
input, select, textarea { font-family: inherit; font-size: var(--fs-base); color: inherit; }
ul, ol { list-style: none; }
code, kbd, pre { font-family: var(--font-mono); font-size: 0.9em; }
kbd {
  display: inline-block; min-width: 1.6em; padding: 0 5px;
  border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 6px;
  background: var(--surface); color: var(--text-secondary); text-align: center; font-size: var(--fs-xs);
}
hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-4) 0; }
table { border-collapse: collapse; width: 100%; }

/* El atributo hidden gana a cualquier display de un componente */
[hidden] { display: none !important; }

/* ---- Utilidades ---- */
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-success { color: var(--success-text); }
.text-danger { color: var(--danger-text); }
.text-warning { color: var(--warning-text); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: var(--fs-sm); }
.text-xs { font-size: var(--fs-xs); }
.fw-bold { font-weight: var(--fw-bold); }
.nowrap { white-space: nowrap; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.break-anywhere { overflow-wrap: anywhere; }
.pre-wrap { white-space: pre-wrap; overflow-wrap: anywhere; }
.mono { font-family: var(--font-mono); font-size: 0.92em; }
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.grow { flex: 1 1 auto; min-width: 0; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.stack > * + * { margin-top: var(--space-3); }
.stack-lg > * + * { margin-top: var(--space-5); }
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.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); }
.full-width { width: 100%; }

/* Solo para lectores de pantalla */
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* Saltar al contenido: visible solo con el foco */
.skip-link {
  position: fixed; top: calc(var(--safe-top) + var(--space-2)); left: var(--space-2); z-index: var(--z-toast);
  display: inline-flex; align-items: center; min-height: 44px;
  padding: var(--space-2) var(--space-4); border-radius: var(--radius-sm);
  background: var(--primary-solid); color: var(--on-primary); font-weight: var(--fw-bold);
  transform: translateY(-200%); transition: transform var(--transition-fast);
}
.skip-link:focus { transform: none; text-decoration: none; }

/* ---- Esqueleto de carga ---- */
.skeleton {
  display: block;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ---- Spinner ---- */
.spinner {
  width: 18px; height: 18px;
  border: 2.5px solid color-mix(in srgb, currentColor 30%, transparent);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
  flex-shrink: 0;
}
.spinner.lg { width: 32px; height: 32px; border-width: 3px; color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Animaciones de entrada ---- */
@keyframes fadeInUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise-in { from { opacity: 0; transform: translateY(12px); } }
.animate-in { animation: fadeInUp 0.4s var(--ease-out) both; }

/* ---- Accesibilidad ---- */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
::selection { background: var(--primary-solid); color: var(--on-primary); }

@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;
  }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}

/* ---- Barra de desplazamiento discreta ---- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--radius-full); }
::-webkit-scrollbar-track { background: transparent; }
