/* ========================================
   ACCESSIBILITY STYLES - WCAG 2.1 AA Compliance
   ======================================== */

/* Focus Management */
*:focus {
  outline: 2px solid var(--color-info);
  outline-offset: 2px;
}

/* Ensure focus is visible on all interactive elements */
a:focus, button:focus, input:focus, select:focus, textarea:focus,
[tabindex]:not([tabindex="-1"]):focus {
  outline: 2px solid var(--color-info);
  outline-offset: 2px;
}

/* High contrast focus for high contrast theme */
.high-contrast-theme *:focus {
  outline: 3px solid #000000;
  outline-offset: 2px;
}

/* 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: 0;
}

.sr-only-focusable:active,
.sr-only-focusable:focus {
  position: static;
  width: auto;
  height: auto;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* Skip Links */
.skip-link {
  position: absolute;
  top: -40px;
  left: 10px;
  background: var(--color-info);
  color: white;
  padding: var(--space-2) var(--space-3);
  z-index: 10000;
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  transition: top 0.3s;
}

.skip-link:focus {
  top: 10px;
}

/* ARIA Live Regions */
[role="region"][aria-live] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Landmark Regions */
[role="banner"], [role="navigation"], [role="main"], 
[role="complementary"], [role="contentinfo"], [role="region"] {
  outline: none;
}

/* Ensure sufficient color contrast */
/* All text colors already meet AA contrast requirements with backgrounds */

/* Touch Target Sizes */
button, a.button, .btn, input[type="button"], input[type="submit"],
[role="button"], [tabindex]:not([tabindex="-1"]) {
  min-height: 44px;
  min-width: 44px;
}

/* For smaller visual buttons with larger hit areas */
.btn-sm {
  position: relative;
}

.btn-sm::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .animate-pulse {
    animation: none;
  }
  
  .transition {
    transition: none;
  }
  
  .smooth-scroll {
    scroll-behavior: auto;
  }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
  :root {
    --color-border: #000000;
    --color-bg: #ffffff;
    --color-bg-elevated: #ffffff;
    --color-text: #000000;
    --color-text-secondary: #000000;
  }
  
  * {
    border-width: 2px !important;
  }
}

/* Inverted Colors Support */
@media (prefers-contrast: custom) and (prefers-color-scheme: dark) {
  :root {
    --color-bg: #000000;
    --color-text: #ffffff;
  }
}

/* ARIA Attributes Styling */
[aria-busy="true"] {
  cursor: progress;
}

[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.5;
}

[aria-hidden="false"][hidden] {
  display: initial;
}

[aria-hidden="false"][hidden]:not(:focus) {
  clip: rect(0, 0, 0, 0);
  position: absolute;
}

/* Link Styles for Accessibility */
a {
  color: var(--color-info);
  text-decoration: underline;
}

a:hover {
  color: var(--color-info);
  text-decoration-thickness: 2px;
}

a:visited {
  color: #8b5cf6; /* Purple for visited links */
}

a:focus {
  outline: 2px solid var(--color-info);
  outline-offset: 2px;
}

/* Form Accessibility */
fieldset {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}

legend {
  font-weight: var(--font-semibold);
  padding: 0 var(--space-2);
}

.form-group {
  margin-bottom: var(--space-4);
}

.form-label {
  display: block;
  margin-bottom: var(--space-2);
  font-weight: var(--font-medium);
  color: var(--color-text);
}

/* Error states */
.form-error {
  color: var(--color-danger);
  border-color: var(--color-danger);
}

.error-message {
  color: var(--color-danger);
  font-size: var(--text-sm);
  margin-top: var(--space-2);
}

/* Required fields */
.form-label.required::after {
  content: " *";
  color: var(--color-danger);
}

/* Descriptions for screen readers */
.form-description {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  margin-top: var(--space-1);
}

/* Tab Panel Accessibility */
[role="tablist"] {
  display: flex;
}

[role="tab"] {
  padding: var(--space-2) var(--space-4);
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-bottom: none;
  cursor: pointer;
}

[role="tab"][aria-selected="true"] {
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-bg);
  margin-bottom: -1px;
}

[role="tabpanel"] {
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-top: none;
}

[role="tabpanel"][aria-hidden="true"] {
  display: none;
}