/* ===================================
   ACCESIBILIDAD Y PREFERENCIAS DE USUARIO
   =================================== */

/* Respetar preferencias de movimiento reducido */
@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;
  }
  
  /* Mantener transiciones esenciales para UX */
  .focus\:ring-2:focus,
  .focus\:ring-blue-400:focus,
  .focus\:ring-offset-2:focus {
    transition: box-shadow 0.15s ease-in-out;
  }
}

/* Respetar preferencias de contraste alto */
@media (prefers-contrast: high) {
  .nav-link:hover,
  .nav-link:focus {
    background-color: rgba(255, 255, 255, 0.2);
    outline: 2px solid currentColor;
  }
  
  button:focus,
  a:focus {
    outline: 3px solid currentColor;
    outline-offset: 2px;
  }
}

/* Clases de utilidad para screen readers */
.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;
}

.sr-only-focusable:focus {
  position: static;
  width: auto;
  height: auto;
  padding: inherit;
  margin: inherit;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* Mejoras de foco para navegación por teclado */
.focus-visible:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* Skip links para navegación por teclado */
.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: #000;
  color: #fff;
  padding: 8px;
  text-decoration: none;
  border-radius: 4px;
  z-index: 1000;
}

.skip-link:focus {
  top: 6px;
}

/* Indicadores de estado para elementos interactivos */
[aria-expanded="true"] .fa-bars::before {
  content: "\f00d"; /* fa-times */
}

/* Indicador de página actual desactivado */
/* [aria-current="page"] {
  position: relative;
}

[aria-current="page"]::after {
  content: "";
  position: absolute;
  bottom: -2px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 2px;
  background-color: currentColor;
  border-radius: 1px;
} */

/* Mejoras para formularios */
.form-error {
  color: #dc2626;
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

.form-error::before {
  content: "⚠ ";
  font-weight: bold;
}

input:invalid,
textarea:invalid,
select:invalid {
  border-color: #dc2626;
  box-shadow: 0 0 0 1px #dc2626;
}

input:valid,
textarea:valid,
select:valid {
  border-color: #059669;
}

/* Mejoras para botones */
button:disabled,
[role="button"][aria-disabled="true"] {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}

/* Indicadores de carga accesibles */
.loading {
  position: relative;
}

.loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 20px;
  height: 20px;
  border: 2px solid transparent;
  border-top: 2px solid currentColor;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

/* Respetar preferencias de movimiento reducido para animaciones */
@media (prefers-reduced-motion: reduce) {
  .loading::after {
    animation: none;
    content: "⏳";
    border: none;
    font-size: 16px;
  }
}

/* Mejoras para tablas responsivas */
@media (max-width: 768px) {
  .table-responsive {
    overflow-x: auto;
  }
  
  .table-responsive:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
  }
}

/* Mejoras para modales */
.modal[aria-hidden="false"] {
  display: flex !important;
}

.modal[aria-hidden="true"] {
  display: none !important;
}

/* Focus trap para modales */
.modal-content {
  position: relative;
}

.modal-content::before,
.modal-content::after {
  content: "";
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* Mejoras para calendarios */
.calendar-day[aria-selected="true"] {
  background-color: #3b82f6;
  color: white;
  font-weight: bold;
}

.calendar-day[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.calendar-day:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
  z-index: 1;
}

/* Mejoras para tooltips */
[data-tooltip] {
  position: relative;
}

[data-tooltip]:hover::after,
[data-tooltip]:focus::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.875rem;
  white-space: nowrap;
  z-index: 1000;
  margin-bottom: 4px;
}

/* Respetar preferencias de transparencia */
@media (prefers-reduced-transparency: reduce) {
  .backdrop-blur-md,
  .backdrop-blur-lg {
    background-color: rgba(59, 130, 246, 0.95);
  }
}

/* Mejoras para impresión */
@media print {
  .no-print,
  nav,
  .fixed,
  .sticky {
    display: none !important;
  }
  
  a[href^="http"]:after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: #666;
  }
  
  .print-break {
    page-break-before: always;
  }
}