/* ======================================================================
   Cumplanza — Base / componentes compartidos
   Requiere tokens.css cargado antes. Reset + tipografía + botones +
   formularios + tarjetas + badges + accesibilidad (foco, reduced-motion).
   ====================================================================== */

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

html {
  font-size: 100%;               /* 16px — respeta el zoom de fuente del usuario */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------- Tipografía ---------- */
h1, h2, h3, h4 { font-family: var(--font-display); line-height: var(--lh-tight); color: var(--ink); font-weight: 600; }
h1 { font-size: var(--fs-2xl); letter-spacing: -0.01em; }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-md); }
p  { line-height: var(--lh-relaxed); }

a {
  color: var(--brand-700);
  text-decoration: none;
  text-underline-offset: 2px;
  transition: color var(--t-fast);
}
a:hover { color: var(--brand-600); text-decoration: underline; }

.mono  { font-family: var(--font-mono); }
.muted { color: var(--muted); }

/* Siglas con expansión (LA/FT/FPADM, PEP…): subrayado discreto + cursor de ayuda,
   hereda el color del texto que las rodea (sirve sobre fondo claro u oscuro). */
abbr[title] {
  text-decoration: underline dotted;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
  cursor: help;
}
.overline {
  font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase;
  letter-spacing: var(--ls-wide); color: var(--muted);
}

/* ---------- Accesibilidad: foco visible ---------- */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}
/* Solo quitamos el outline cuando el navegador soporta :focus-visible
   (evita dejar a usuarios de teclado sin pista). */
:where(button, [role="button"]):focus:not(:focus-visible) { outline: none; }

/* Lectores de pantalla: contenido visualmente oculto pero accesible */
.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;
}
.skip-link {
  position: absolute; left: var(--sp-3); top: -64px; z-index: var(--z-toast);
  background: var(--brand-900); color: #fff; padding: var(--sp-2) var(--sp-4);
  border-radius: var(--r-sm); transition: top var(--t);
}
.skip-link:focus { top: var(--sp-3); color: #fff; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  font-family: var(--font-sans); font-size: var(--fs-base); font-weight: 600;
  line-height: 1; padding: 0.7rem 1.15rem; min-height: 42px;
  border: 1px solid transparent; border-radius: var(--r-sm);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background var(--t), border-color var(--t), color var(--t), box-shadow var(--t), transform var(--t-fast);
}
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--brand-700); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-600); color: #fff; }

.btn-accent { background: var(--accent-600); color: #fff; }
.btn-accent:hover:not(:disabled) { background: var(--accent-700); color: #fff; }

.btn-outline { background: var(--surface); color: var(--ink); border-color: var(--line-2); }
.btn-outline:hover:not(:disabled) { background: var(--bg); border-color: var(--brand-600); color: var(--brand-700); }

.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-ghost:hover:not(:disabled) { background: var(--brand-050); color: var(--brand-700); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #93180f; color: #fff; }

.btn-sm { min-height: 34px; padding: 0.45rem 0.8rem; font-size: var(--fs-sm); }
.btn-lg { min-height: 50px; padding: 0.9rem 1.6rem; font-size: var(--fs-md); }
.btn-block { width: 100%; }

/* ---------- Formularios ---------- */
.field { display: flex; flex-direction: column; gap: var(--sp-2); margin-bottom: var(--sp-4); }
.field > label, .label {
  font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2);
}
.input, input[type="text"], input[type="email"], input[type="password"],
input[type="search"], input[type="number"], select, textarea {
  width: 100%; font-family: inherit; font-size: var(--fs-base); color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-2);
  border-radius: var(--r-sm); padding: 0.65rem 0.8rem;
  transition: border-color var(--t), box-shadow var(--t);
}
.input::placeholder, input::placeholder { color: #9aa2af; }
.input:focus, input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand-600); box-shadow: var(--focus-ring);
}
.input[aria-invalid="true"], input[aria-invalid="true"] {
  border-color: var(--danger); box-shadow: 0 0 0 3px rgba(180,35,24,.18);
}
.field-hint { font-size: var(--fs-xs); color: var(--muted); }
.field-error { font-size: var(--fs-sm); color: var(--danger); font-weight: 600; }

/* Input con botón embebido (ej: mostrar/ocultar contraseña) */
.input-group { position: relative; display: flex; align-items: center; }
.input-group input { padding-right: 3rem; }
.input-affix {
  position: absolute; right: 0.35rem; border: none; background: transparent;
  color: var(--muted); cursor: pointer; padding: 0.4rem 0.5rem;
  border-radius: var(--r-sm); font-size: var(--fs-sm); font-weight: 600;
}
.input-affix:hover { color: var(--brand-700); background: var(--brand-050); }

/* ---------- Tarjeta ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--sh-sm); padding: var(--sp-6);
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: .02em;
  padding: 3px 10px; border-radius: var(--r-pill); white-space: nowrap;
  border: 1px solid transparent;
}
.badge-ok     { background: var(--ok-bg);     color: var(--ok);     border-color: var(--ok-line); }
.badge-warn   { background: var(--warn-bg);   color: var(--warn);   border-color: var(--warn-line); }
.badge-danger { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-line); }
.badge-info   { background: var(--info-bg);   color: var(--info);   border-color: var(--info-line); }
.badge-muted  { background: var(--bg);        color: var(--muted);  border-color: var(--line-2); }

/* ---------- Mensajes inline (reemplazo de alert()) ---------- */
.alert {
  display: flex; gap: var(--sp-3); align-items: flex-start;
  padding: var(--sp-3) var(--sp-4); border-radius: var(--r-sm);
  font-size: var(--fs-sm); border: 1px solid transparent;
}
.alert-danger { background: var(--danger-bg); color: #7a160f; border-color: var(--danger-line); }
.alert-warn   { background: var(--warn-bg);   color: #7a2e08; border-color: var(--warn-line); }
.alert-ok     { background: var(--ok-bg);     color: #054f31; border-color: var(--ok-line); }
.alert-info   { background: var(--info-bg);   color: #0b3d91; border-color: var(--info-line); }

/* ---------- Toast (notificaciones no bloqueantes) ---------- */
.toast-region {
  position: fixed; right: var(--sp-4); bottom: var(--sp-4); z-index: var(--z-toast);
  display: flex; flex-direction: column; gap: var(--sp-2); max-width: min(380px, 92vw);
}
.toast {
  background: var(--brand-900); color: #fff; border-radius: var(--r-sm);
  box-shadow: var(--sh-lg); padding: var(--sp-3) var(--sp-4); font-size: var(--fs-sm);
  display: flex; gap: var(--sp-3); align-items: flex-start;
  border-left: 4px solid var(--accent-600);
  animation: toast-in var(--t);
}
.toast-ok     { border-left-color: var(--ok); }
.toast-danger { border-left-color: var(--danger); }
.toast-warn   { border-left-color: var(--warn); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Spinner ---------- */
.spinner {
  width: 20px; height: 20px; border: 2.5px solid rgba(255,255,255,.25);
  border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Utilidades ---------- */
.hidden { display: none !important; }
.stack  { display: flex; flex-direction: column; gap: var(--sp-3); }
.row    { display: flex; gap: var(--sp-3); align-items: center; }
.grow   { flex: 1; min-width: 0; }

/* ---------- Movimiento reducido ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important; animation-iteration-count: 1 !important;
    transition-duration: .001ms !important; scroll-behavior: auto !important;
  }
}
