/* ========================================
   Accessibility Enhancements
   ======================================== */

/* Skip Link */
.skip-link {
  position: absolute;
  top: -100px;
  left: 0;
  z-index: 10000;
  padding: var(--space-sm) var(--space-md);
  background: var(--color-primary);
  color: #ffffff;
  text-decoration: none;
  font-weight: 600;
  border-radius: 0 0 var(--radius-md) 0;
  transition: top var(--transition);
}

.skip-link:focus {
  top: 0;
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

/* Enhanced Focus States */
*:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Ensure all interactive elements are keyboard accessible */
button:not(:disabled),
a,
input:not([type="hidden"]):not(:disabled),
select:not(:disabled),
textarea:not(:disabled),
[tabindex]:not([tabindex="-1"]) {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

/* Enhanced Button Focus */
.btn:focus-visible,
button:focus-visible,
[role="button"]:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(31, 107, 255, 0.2);
}

/* Enhanced Link Focus */
a:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  text-decoration: underline;
}

/* Input Focus States */
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-color: var(--color-primary);
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
  :root {
    --color-border: rgba(255, 255, 255, 0.3);
    --color-border-hover: rgba(255, 255, 255, 0.5);
  }

  .btn {
    border-width: 2px;
  }

  .card {
    border-width: 2px;
  }
}

/* Reduced Motion */
@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;
  }

  .global-loading-spinner,
  .ui-skeleton,
  .ui-skeleton--animated {
    animation: none !important;
  }
}

/* Screen Reader Only Content */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.sr-only-focusable:focus {
  position: static;
  width: auto;
  height: auto;
  padding: var(--space-sm) var(--space-md);
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* Ensure proper heading hierarchy is maintained */
h1 {
  font-size: var(--text-4xl);
  font-weight: 700;
}

h2 {
  font-size: var(--text-3xl);
  font-weight: 600;
}

h3 {
  font-size: var(--text-2xl);
  font-weight: 600;
}

h4 {
  font-size: var(--text-xl);
  font-weight: 600;
}

h5 {
  font-size: var(--text-lg);
  font-weight: 600;
}

h6 {
  font-size: var(--text-base);
  font-weight: 600;
}

/* Landmark regions */
header[role="banner"],
nav[role="navigation"],
main[role="main"],
footer[role="contentinfo"],
aside[role="complementary"] {
  /* Semantic HTML landmarks */
}

/* Ensure sufficient color contrast for text */
.text-muted {
  color: var(--color-muted);
  /* Ensure minimum 4.5:1 contrast ratio */
}

/* Error states with icons + text */
.error-message {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  color: var(--color-error);
  font-size: var(--text-sm);
}

.error-message::before {
  content: "⚠";
  font-size: var(--text-base);
}

/* Success states */
.success-message {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  color: var(--color-success);
  font-size: var(--text-sm);
}

.success-message::before {
  content: "✓";
  font-size: var(--text-base);
}

/* Focus trap for modals */
.modal-open {
  overflow: hidden;
}

/* Live regions for dynamic content */
[role="status"],
[role="alert"],
[aria-live] {
  /* Live region announcements */
}

/* Ensure form labels are associated */
label[for] {
  cursor: pointer;
}

/* Loading states with proper ARIA */
[aria-busy="true"] {
  position: relative;
}

[aria-busy="true"]::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* Ensure images have proper sizing for screen readers */
img {
  max-width: 100%;
  height: auto;
}

img[alt=""] {
  /* Decorative images */
}

/* Ensure tables are accessible */
table {
  border-collapse: collapse;
}

th {
  font-weight: 600;
  text-align: left;
}

/* Ensure sufficient touch targets on mobile */
@media (max-width: 768px) {
  button,
  a,
  [role="button"],
  input[type="button"],
  input[type="submit"] {
    min-height: 44px;
    min-width: 44px;
  }
}
