/* =====================================================================
   MEDINT · Design System
   ---------------------------------------------------------------------
   Capa ADITIVA sobre style.css. No reemplaza nada: extiende los design
   tokens (incluye modo oscuro) y agrega componentes reutilizables.

   Como style.css ya usa var(--surface), var(--text), etc., al redefinir
   esos tokens bajo [data-theme="dark"] TODA la UI existente hereda el
   modo oscuro automáticamente.

   Índice:
     1. Design tokens (light)
     2. Design tokens (dark)
     3. Base / accesibilidad
     4. Botones (variantes, tamaños, loading, icon)
     5. Badges / chips / pills
     6. Alertas / banners
     7. Cards / stat cards
     8. Empty states
     9. Skeletons / spinners (estados de carga)
    10. Avatares
    11. Modal / dialog
    12. Form fields
    13. Switch / segmented control (incl. theme toggle)
    14. Tooltip / progress / pagination
    15. Utilidades
   ===================================================================== */

/* ============================ 1. TOKENS (LIGHT) ===================== */
:root {
  /* Marca + estados (se completan los que faltaban: --warning, *-rgb) */
  --primary-rgb: 37, 99, 235;
  --success-rgb: 16, 185, 129;
  --danger-rgb: 239, 68, 68;
  --warning: #f59e0b;
  --warning-rgb: 245, 158, 11;
  --info: #0ea5e9;
  --info-rgb: 14, 165, 233;

  /* Superficies / elevación */
  --surface-2: #f1f5f9;        /* superficie elevada (headers de tabla, hovers) */
  --surface-hover: #f1f5f9;
  --on-primary: #ffffff;       /* texto sobre fondo primario */
  --text-strong: #0b1220;

  /* Tints suaves para fondos de estado */
  --primary-soft: rgba(37, 99, 235, 0.10);
  --success-soft: rgba(16, 185, 129, 0.12);
  --danger-soft: rgba(239, 68, 68, 0.10);
  --warning-soft: rgba(245, 158, 11, 0.14);
  --info-soft: rgba(14, 165, 233, 0.12);

  /* Foco accesible */
  --ring: 0 0 0 3px rgba(var(--primary-rgb), 0.35);

  /* Escala de espaciado (4px base) */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-8: 3rem;

  /* Radios */
  --radius-sm: 0.5rem;
  --radius-lg: 1rem;
  --radius-full: 999px;

  /* Sombras */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.10), 0 2px 4px -2px rgba(0, 0, 0, 0.10);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.12), 0 8px 10px -6px rgba(0, 0, 0, 0.10);

  /* Movimiento */
  --transition: 0.2s ease;

  color-scheme: light;
}

/* ============================ 2. TOKENS (DARK) ====================== */
html[data-theme="dark"] {
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --primary-rgb: 59, 130, 246;
  --accent: #38bdf8;

  --background: #0f172a;
  --surface: #1e293b;
  --surface-2: #243044;
  --surface-hover: #334155;
  --text: #e2e8f0;
  --text-strong: #f8fafc;
  --text-light: #94a3b8;
  --border: #334155;

  --success: #34d399;  --success-rgb: 52, 211, 153;
  --danger: #f87171;   --danger-rgb: 248, 113, 113;
  --warning: #fbbf24;  --warning-rgb: 251, 191, 36;
  --info: #38bdf8;     --info-rgb: 56, 189, 248;

  --primary-soft: rgba(59, 130, 246, 0.16);
  --success-soft: rgba(52, 211, 153, 0.16);
  --danger-soft: rgba(248, 113, 113, 0.16);
  --warning-soft: rgba(251, 191, 36, 0.16);
  --info-soft: rgba(56, 189, 248, 0.16);

  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -2px rgba(0, 0, 0, 0.5);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -2px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.6), 0 8px 10px -6px rgba(0, 0, 0, 0.5);

  color-scheme: dark;
}

/* El body de style.css fija una imagen con overlay claro: la oscurecemos. */
html[data-theme="dark"] body {
  background-image:
    linear-gradient(rgba(15, 23, 42, 0.94), rgba(15, 23, 42, 0.94)),
    url('../img/med_abstract_bg.png');
}

/* Navbar tiene fondo blanco translúcido hardcodeado: override en oscuro. */
html[data-theme="dark"] .navbar {
  background: rgba(15, 23, 42, 0.82);
  border-bottom-color: var(--border);
}

/* Logo: variante clara (texto oscuro) en tema claro, variante con texto blanco en oscuro. */
.brand-logo--dark { display: none; }
html[data-theme="dark"] .brand-logo--light { display: none; }
html[data-theme="dark"] .brand-logo--dark { display: inline-block; }

/* Dashboard: las tablas de alerta traen thead/filas con colores claros fijos
   (crema/amarillo) en estilos inline. En modo oscuro los neutralizamos de una
   sola vez para que sean legibles, sin tener que tocar cada tabla. */
html[data-theme="dark"] .dashboard table thead { background: var(--surface-2) !important; }
html[data-theme="dark"] .dashboard table thead th { color: var(--text) !important; }
html[data-theme="dark"] .dashboard table tbody tr[style*="background"] { background: rgba(248, 113, 113, 0.10) !important; }
/* Bordes claros de las cards de alerta -> borde neutro del tema */
html[data-theme="dark"] .dashboard .card[style*="border"] { border-color: var(--border) !important; }
/* Botones "Renovar" con fondo blanco fijo dentro del dashboard */
html[data-theme="dark"] .dashboard a.btn[style*="background: white"],
html[data-theme="dark"] .dashboard a.btn[style*="background:#fff"] { background: var(--surface-2) !important; color: var(--text) !important; }

/* Red de seguridad global: cualquier fondo blanco fijo en estilos inline
   (background: white / #fff / #ffffff) pasa a superficie del tema en oscuro.
   Es inequívoco (blanco -> oscuro siempre es correcto en dark mode) y cubre
   de una vez muchas pantallas con islas blancas. */
html[data-theme="dark"] [style*="background: white"],
html[data-theme="dark"] [style*="background:white"],
html[data-theme="dark"] [style*="background-color: white"],
html[data-theme="dark"] [style*="background-color:white"],
html[data-theme="dark"] [style*="background: #fff;"],
html[data-theme="dark"] [style*="background:#fff;"],
html[data-theme="dark"] [style*="background: #fff "],
html[data-theme="dark"] [style*="background: #ffffff"],
html[data-theme="dark"] [style*="background:#ffffff"] {
  background-color: var(--surface) !important;
}

/* select2 (plugin jQuery): su CSS trae fondos blancos fijos. Dark-safe. */
html[data-theme="dark"] .select2-container--default .select2-selection--single,
html[data-theme="dark"] .select2-container--default .select2-selection--multiple,
html[data-theme="dark"] .select2-dropdown,
html[data-theme="dark"] .select2-search__field {
  background-color: var(--surface) !important;
  border-color: var(--border) !important;
  color: var(--text) !important;
}
html[data-theme="dark"] .select2-selection__rendered,
html[data-theme="dark"] .select2-results__option { color: var(--text) !important; }
html[data-theme="dark"] .select2-results__option { background-color: var(--surface) !important; }
html[data-theme="dark"] .select2-results__option--highlighted { background-color: var(--primary) !important; color: #fff !important; }
html[data-theme="dark"] .select2-selection__choice { background-color: var(--surface-2) !important; border-color: var(--border) !important; color: var(--text) !important; }

/* Asistente flotante (chat) definido en base.html con fondos claros fijos. */
html[data-theme="dark"] .assistant-messages { background: var(--background) !important; }
html[data-theme="dark"] .msg-bot { background: var(--surface) !important; color: var(--text) !important; }
html[data-theme="dark"] .closest-card { background: var(--surface) !important; }

/* ============================ 3. BASE / A11Y ======================== */
/* Foco visible y consistente sólo para navegación por teclado. */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible,
.btn:focus-visible {
  outline: 2px solid transparent;
  box-shadow: var(--ring);
  border-radius: var(--radius-sm);
}

/* Sólo lectores de pantalla */
.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;
}

/* Respeta usuarios con movimiento reducido */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================ 4. BOTONES =========================== */
/* Variantes nuevas que complementan .btn / .btn-primary de style.css */
.btn-secondary {
  background-color: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background-color: var(--surface-hover); transform: translateY(-1px); }

.btn-success { background-color: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(0.95); transform: translateY(-1px); }

.btn-danger { background-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.95); transform: translateY(-1px); }

.btn-warning { background-color: var(--warning); color: #0b1220; }
.btn-warning:hover { filter: brightness(0.97); transform: translateY(-1px); }

.btn-ghost { background: transparent; color: var(--text); border: 1px solid transparent; }
.btn-ghost:hover { background: var(--surface-hover); }

.btn-outline-primary {
  background: transparent; color: var(--primary);
  border: 1px solid var(--primary);
}
.btn-outline-primary:hover { background: var(--primary-soft); }

/* Tamaños */
.btn-sm { padding: 0.45rem 0.9rem; font-size: 0.85rem; border-radius: var(--radius-sm); }
.btn-lg { padding: 0.95rem 1.8rem; font-size: 1.1rem; }
.btn-block { width: 100%; }

/* Botón sólo-ícono */
.btn-icon {
  width: 2.5rem; height: 2.5rem; padding: 0;
  border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-icon.btn-sm { width: 2rem; height: 2rem; }

/* Estado deshabilitado uniforme para cualquier .btn */
.btn:disabled,
.btn[disabled],
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none !important;
  pointer-events: none;
}

/* Estado de carga: <button class="btn is-loading"> muestra spinner y oculta texto */
.btn.is-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 1.1em; height: 1.1em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  /* recupera el color real del texto para el spinner */
  color: var(--on-primary);
  animation: ds-spin 0.6s linear infinite;
}
.btn-secondary.is-loading::after,
.btn-ghost.is-loading::after,
.btn-outline-primary.is-loading::after { color: var(--primary); }

/* ============================ 5. BADGES / CHIPS ===================== */
.badge {
  display: inline-flex; align-items: center; gap: 0.35em;
  padding: 0.25rem 0.6rem;
  font-size: 0.78rem; font-weight: 600; line-height: 1.2;
  border-radius: var(--radius-full);
  background: var(--surface-2); color: var(--text);
  white-space: nowrap;
}
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: #92600a; }
html[data-theme="dark"] .badge-warning { color: var(--warning); }
.badge-info    { background: var(--info-soft);    color: var(--info); }
.badge-neutral { background: var(--surface-2); color: var(--text-light); }

/* Punto de estado opcional dentro del badge */
.badge .dot { width: 0.5em; height: 0.5em; border-radius: 50%; background: currentColor; }

/* Chip removible (filtros activos, tags) */
.chip {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.3rem 0.7rem;
  border-radius: var(--radius-full);
  background: var(--surface-2); color: var(--text);
  font-size: 0.85rem; border: 1px solid var(--border);
}
.chip button {
  background: none; border: none; cursor: pointer;
  color: var(--text-light); font-size: 1rem; line-height: 1; padding: 0;
}
.chip button:hover { color: var(--danger); }

/* ============================ 6. ALERTAS ============================ */
.alert {
  display: flex; gap: 0.75rem; align-items: flex-start;
  padding: 1rem 1.15rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  margin-bottom: 1rem;
}
.alert .alert-icon { font-size: 1.15rem; line-height: 1.4; flex-shrink: 0; }
.alert .alert-body { flex: 1; min-width: 0; }
.alert .alert-title { font-weight: 600; margin-bottom: 0.15rem; }
.alert-primary { background: var(--primary-soft); border-color: transparent; }
.alert-success { background: var(--success-soft); border-color: transparent; }
.alert-danger  { background: var(--danger-soft);  border-color: transparent; }
.alert-warning { background: var(--warning-soft); border-color: transparent; }
.alert-info    { background: var(--info-soft);    border-color: transparent; }

/* ============================ 7. CARDS ============================= */
/* .card ya existe en style.css. Agregamos piezas y variantes. */
.card-hover { transition: transform var(--transition), box-shadow var(--transition); }
.card-hover:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }

.card-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin-bottom: 1rem;
  padding-bottom: 1rem; border-bottom: 1px solid var(--border);
}
.card-title { font-size: 1.15rem; font-weight: 600; margin: 0; }
.card-footer {
  margin-top: 1rem; padding-top: 1rem;
  border-top: 1px solid var(--border);
  display: flex; gap: 0.5rem; justify-content: flex-end;
}

/* Stat card (KPIs del dashboard) */
.stat-card {
  display: flex; align-items: center; gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-sm);
}
.stat-card__icon {
  width: 3rem; height: 3rem; flex-shrink: 0;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
  background: var(--primary-soft); color: var(--primary);
}
.stat-card__label { font-size: 0.82rem; color: var(--text-light); font-weight: 500; }
.stat-card__value { font-size: 1.7rem; font-weight: 700; line-height: 1.1; color: var(--text-strong); }
.stat-card__trend { font-size: 0.8rem; font-weight: 600; }
.stat-card__trend.up { color: var(--success); }
.stat-card__trend.down { color: var(--danger); }

/* ============================ 8. EMPTY STATES ====================== */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-light);
}
.empty-state__icon {
  font-size: 3rem; margin-bottom: 1rem; opacity: 0.6; line-height: 1;
}
.empty-state__title { font-size: 1.15rem; font-weight: 600; color: var(--text); margin-bottom: 0.4rem; }
.empty-state__text { font-size: 0.95rem; max-width: 28rem; margin: 0 auto 1.25rem; }

/* ============================ 9. CARGA ============================= */
@keyframes ds-spin { to { transform: rotate(360deg); } }
@keyframes ds-shimmer { 100% { transform: translateX(100%); } }

.spinner {
  display: inline-block;
  width: 1.25rem; height: 1.25rem;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: ds-spin 0.6s linear infinite;
}
.spinner-lg { width: 2.5rem; height: 2.5rem; border-width: 3px; }

/* Overlay de carga para una sección/card */
.loading-overlay {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0.75rem; padding: 2.5rem; color: var(--text-light);
}

/* Skeleton */
.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}
.skeleton::after {
  content: "";
  position: absolute; inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.35), transparent);
  animation: ds-shimmer 1.4s infinite;
}
html[data-theme="dark"] .skeleton::after {
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.06), transparent);
}
.skeleton-text { height: 0.8rem; margin-bottom: 0.5rem; }
.skeleton-text.w-50 { width: 50%; }
.skeleton-text.w-75 { width: 75%; }
.skeleton-title { height: 1.4rem; width: 40%; margin-bottom: 1rem; }
.skeleton-avatar { width: 3rem; height: 3rem; border-radius: 50%; }
.skeleton-block { height: 8rem; }

/* ============================ 10. AVATARES ========================= */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.5rem; height: 2.5rem;
  border-radius: 50%;
  background: var(--primary-soft); color: var(--primary);
  font-weight: 600; font-size: 0.9rem;
  overflow: hidden; flex-shrink: 0;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 2rem; height: 2rem; font-size: 0.78rem; }
.avatar-lg { width: 3.5rem; height: 3.5rem; font-size: 1.2rem; }

/* ============================ 11. MODAL =========================== */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(2, 6, 23, 0.55);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem; z-index: 10050;
  opacity: 0; visibility: hidden;
  transition: opacity var(--transition), visibility var(--transition);
}
.modal-backdrop.open { opacity: 1; visibility: visible; }
.modal {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 32rem;
  max-height: 90vh; overflow-y: auto;
  transform: translateY(12px) scale(0.98);
  transition: transform var(--transition);
}
.modal-backdrop.open .modal { transform: translateY(0) scale(1); }
.modal-sm { max-width: 24rem; }
.modal-lg { max-width: 48rem; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 1.2rem; }
.modal-body { padding: 1.5rem; }
.modal-footer {
  display: flex; gap: 0.6rem; justify-content: flex-end;
  padding: 1rem 1.5rem; border-top: 1px solid var(--border);
}
.modal-close {
  background: none; border: none; cursor: pointer;
  font-size: 1.4rem; line-height: 1; color: var(--text-light);
  width: 2rem; height: 2rem; border-radius: var(--radius-sm);
}
.modal-close:hover { background: var(--surface-hover); color: var(--text); }

/* ============================ 12. FORM FIELDS ===================== */
.field { margin-bottom: 1.25rem; }
.field-label {
  display: block; margin-bottom: 0.4rem;
  font-weight: 500; font-size: 0.9rem; color: var(--text);
}
.field-label .req { color: var(--danger); margin-left: 0.15rem; }
.field-hint { font-size: 0.8rem; color: var(--text-light); margin-top: 0.35rem; }
.field-error { font-size: 0.82rem; color: var(--danger); margin-top: 0.35rem; }
.form-control.is-invalid { border-color: var(--danger); }
.form-control.is-invalid:focus { box-shadow: 0 0 0 3px var(--danger-soft); }
/* Grupo con ícono/addon a la izquierda */
.input-group { position: relative; display: flex; align-items: center; }
.input-group .input-icon {
  position: absolute; left: 0.85rem; color: var(--text-light); pointer-events: none;
}
.input-group .form-control { padding-left: 2.4rem; }

/* Asegura que inputs/selects/textarea adopten tokens en oscuro */
.form-control, select.form-control, textarea.form-control {
  background-color: var(--surface);
  color: var(--text);
}
.form-control::placeholder { color: var(--text-light); opacity: 0.8; }

/* ============================ 13. SWITCH / SEGMENTED ============== */
.switch { position: relative; display: inline-flex; align-items: center; cursor: pointer; gap: 0.6rem; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  width: 2.6rem; height: 1.5rem; border-radius: var(--radius-full);
  background: var(--border); transition: background var(--transition); flex-shrink: 0;
}
.switch .thumb {
  position: absolute; left: 0.18rem; top: 50%; transform: translateY(-50%);
  width: 1.14rem; height: 1.14rem; border-radius: 50%;
  background: #fff; box-shadow: var(--shadow-sm); transition: left var(--transition);
}
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track + .thumb { left: 1.28rem; }
.switch input:focus-visible + .track { box-shadow: var(--ring); }

/* Control segmentado (tabs/toggle de vistas) */
.segmented {
  display: inline-flex; padding: 0.25rem; gap: 0.25rem;
  background: var(--surface-2); border-radius: var(--radius);
  border: 1px solid var(--border);
}
.segmented button {
  border: none; background: none; cursor: pointer;
  padding: 0.45rem 0.9rem; border-radius: calc(var(--radius) - 4px);
  font-size: 0.88rem; font-weight: 500; color: var(--text-light);
  transition: all var(--transition);
}
.segmented button[aria-pressed="true"],
.segmented button.active {
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm);
}

/* Theme toggle (botón en navbar) */
.theme-toggle {
  background: none; border: 1px solid var(--border);
  color: var(--text); cursor: pointer;
  width: 2.4rem; height: 2.4rem; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.05rem; transition: all var(--transition);
}
.theme-toggle:hover { background: var(--surface-hover); }
.theme-toggle .icon-moon { display: none; }
.theme-toggle .icon-sun { display: inline; }
html[data-theme="dark"] .theme-toggle .icon-moon { display: inline; }
html[data-theme="dark"] .theme-toggle .icon-sun { display: none; }

/* ============================ 14. TOOLTIP / PROGRESS / PAGING ===== */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute; bottom: calc(100% + 0.4rem); left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: var(--text-strong); color: var(--surface);
  padding: 0.35rem 0.6rem; border-radius: var(--radius-sm);
  font-size: 0.78rem; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: all var(--transition); z-index: 50;
}
[data-tooltip]:hover::after { opacity: 1; transform: translateX(-50%) translateY(0); }

.progress { height: 0.6rem; background: var(--surface-2); border-radius: var(--radius-full); overflow: hidden; }
.progress__bar { height: 100%; background: var(--primary); border-radius: inherit; transition: width 0.4s ease; }

.pagination { display: flex; gap: 0.3rem; align-items: center; flex-wrap: wrap; justify-content: center; }
.pagination a, .pagination span {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 2.25rem; height: 2.25rem; padding: 0 0.6rem;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); text-decoration: none;
  font-size: 0.9rem; transition: all var(--transition);
}
.pagination a:hover { background: var(--surface-hover); border-color: var(--primary); }
.pagination .active { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.pagination .disabled { opacity: 0.45; pointer-events: none; }

/* ============================ 15. UTILIDADES ====================== */
.stack { display: flex; flex-direction: column; }
.stack-2 { gap: var(--space-2); } .stack-3 { gap: var(--space-3); } .stack-4 { gap: var(--space-4); }
.cluster { display: flex; flex-wrap: wrap; align-items: center; }
.cluster-2 { gap: var(--space-2); } .cluster-3 { gap: var(--space-3); }
.between { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.text-muted { color: var(--text-light); }
.text-center { text-align: center; }
.w-full { width: 100%; }

/* Grid responsivo auto-fit (KPIs, tarjetas). Sin media queries: se adapta solo. */
.grid-auto {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 16rem), 1fr));
  gap: 1.5rem;
}
.grid-auto-sm {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 12rem), 1fr));
  gap: 1rem;
}

/* ───────────────────────────────────────────────────────────────
   Auditoría Médica (Asistente IA) — modo oscuro
   La tarjeta trae el fondo y los colores en estilos INLINE desde la
   plantilla (fondo blanco, título violeta oscuro, texto #333), y además
   el HTML que genera la IA puede traer sus propios colores inline. Los
   estilos inline le ganan a las clases, por eso hace falta !important
   para que en modo oscuro se lea. Se aplica en la ficha del paciente y
   en el historial clínico compartido del profesional.
   ─────────────────────────────────────────────────────────────── */
html[data-theme="dark"] .ai-summary-card {
  background: var(--surface) !important;
  border-left-color: #a78bfa !important;
}
html[data-theme="dark"] .ai-summary-card h3 {
  color: #c4b5fd !important;
}
html[data-theme="dark"] #ai-summary-content,
html[data-theme="dark"] #ai-summary-content * {
  color: var(--text) !important;
}
