/**
 * WCAG 2.1 Accessibility Fixes for Performing Trobar
 * 
 * This stylesheet addresses critical accessibility issues identified in the audit.
 * Add this to your existing stylesheets or integrate the rules into your theme.
 */

/* ============================================================================
   1. FOCUS INDICATORS
   Ensures keyboard users can see where they are on the page
   WCAG 2.4.7 Focus Visible (Level AA)
   ========================================================================= */

/* Base focus styles for all interactive elements */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus,
[tabindex]:focus {
  outline: 2px solid #005fcc;
  outline-offset: 2px;
}

/* Enhanced focus for buttons and navigation */
.btn:focus,
.btn-search:focus,
.nav a:focus,
.menu a:focus {
  outline: 3px solid #005fcc;
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(0, 95, 204, 0.2);
}

/* Focus styles for form inputs */
input[type="text"]:focus,
input[type="search"]:focus,
select:focus {
  border-color: #005fcc;
  box-shadow: 0 0 0 3px rgba(0, 95, 204, 0.2);
}

/* Remove outline for mouse users (but keep for keyboard) */
a:focus:not(:focus-visible),
button:focus:not(:focus-visible) {
  outline: none;
}

a:focus-visible,
button:focus-visible {
  outline: 2px solid #005fcc;
  outline-offset: 2px;
}


/* ============================================================================
   2. SKIP NAVIGATION
   Makes skip links visible when focused
   WCAG 2.4.1 Bypass Blocks (Level A)
   ========================================================================= */

.element-invisible {
  position: absolute !important;
  clip: rect(1px, 1px, 1px, 1px);
  overflow: hidden;
  height: 1px;
  width: 1px;
  word-wrap: normal;
}

.element-invisible.element-focusable:focus,
.element-invisible.element-focusable:active {
  position: absolute;
  clip: auto;
  overflow: visible;
  height: auto;
  width: auto;
  z-index: 10000;
  
  /* Styling to make it prominent */
  top: 5px;
  left: 5px;
  padding: 10px 15px;
  background: #000;
  color: #fff;
  font-size: 16px;
  font-weight: bold;
  text-decoration: none;
  border-radius: 3px;
}


/* ============================================================================
   3. FORM ACCESSIBILITY
   Makes form labels visible and improves input visibility
   WCAG 1.3.1, 3.3.2 (Level A)
   ========================================================================= */

/* Make search form label visible */
#block-search-form label.element-invisible {
  /* Override to make visible */
  position: static;
  clip: auto;
  height: auto;
  width: auto;
  overflow: visible;
  
  /* Style the label */
  display: block;
  margin-bottom: 5px;
  font-weight: 600;
  color: #333;
}

/* Improve placeholder contrast */
input::placeholder,
textarea::placeholder {
  color: #666;
  opacity: 1;
}

/* Better contrast for disabled inputs */
input:disabled,
select:disabled,
textarea:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}


/* ============================================================================
   4. CONTRAST IMPROVEMENTS
   Ensures text meets WCAG AA contrast requirements (4.5:1 for normal text)
   WCAG 1.4.3 Contrast (Minimum) (Level AA)
   ========================================================================= */

/* Ensure link contrast */
a {
  color: #0056b3; /* Darker blue for better contrast */
}

a:hover,
a:focus {
  color: #003d82;
  text-decoration: underline;
}

/* Visited links */
a:visited {
  color: #551a8b;
}

/* Ensure text has sufficient contrast */
body {
  color: #212529; /* Dark gray, not pure black */
  background: #fff;
}

/* Secondary text with sufficient contrast */
.text-muted,
.submitted {
  color: #555; /* Minimum 4.5:1 contrast */
}


/* ============================================================================
   5. TABLE ACCESSIBILITY
   Improves table readability and accessibility
   WCAG 1.3.1 Info and Relationships (Level A)
   ========================================================================= */

/* Better table spacing and borders */
table {
  border-collapse: collapse;
  width: 100%;
}

th {
  text-align: left;
  font-weight: 600;
  background-color: #f5f5f5;
  padding: 12px 8px;
  border: 1px solid #ddd;
}

td {
  padding: 10px 8px;
  border: 1px solid #ddd;
}

/* Zebra striping for better readability */
tbody tr:nth-child(odd) {
  background-color: #fafafa;
}

tbody tr:hover,
tbody tr:focus-within {
  background-color: #f0f0f0;
}


/* ============================================================================
   6. RESPONSIVE TEXT
   Ensures text remains readable when zoomed
   WCAG 1.4.4 Resize Text (Level AA)
   ========================================================================= */

/* Use relative units for font sizes */
body {
  font-size: 16px; /* Base size */
  line-height: 1.5;
}

h1 {
  font-size: 2rem; /* 32px */
  line-height: 1.2;
}

h2 {
  font-size: 1.5rem; /* 24px */
  line-height: 1.3;
}

h3 {
  font-size: 1.25rem; /* 20px */
  line-height: 1.4;
}

/* Ensure text can scale up to 200% */
@media (max-width: 768px) {
  body {
    font-size: 18px;
  }
}


/* ============================================================================
   7. TOUCH TARGET SIZE
   Ensures interactive elements are large enough for touch
   WCAG 2.5.5 Target Size (Level AAA, but good practice)
   ========================================================================= */

/* Minimum 44x44px touch targets */
button,
.btn,
input[type="submit"],
input[type="button"],
input[type="image"],
a.btn {
  min-height: 44px;
  min-width: 44px;
  padding: 10px 15px;
}

/* Navigation links */
.nav a,
.menu a {
  display: block;
  padding: 12px 15px;
  min-height: 44px;
}


/* ============================================================================
   8. ERROR MESSAGING
   Styles for accessible form error messages
   WCAG 3.3.1 Error Identification (Level A)
   ========================================================================= */

.error,
.form-error,
[aria-invalid="true"] {
  border-color: #dc3545;
  border-width: 2px;
}

.error-message,
.form-error-message {
  color: #dc3545;
  font-weight: 600;
  margin-top: 5px;
  display: flex;
  align-items: center;
}

.error-message::before {
  content: "⚠ ";
  margin-right: 5px;
}

/* Success states */
.success,
[aria-invalid="false"] {
  border-color: #28a745;
}


/* ============================================================================
   9. SCREEN READER ONLY TEXT
   Utility class for content that should only be available to screen readers
   ========================================================================= */

.sr-only,
.visually-hidden {
  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,
.sr-only-focusable:active {
  position: static;
  width: auto;
  height: auto;
  overflow: visible;
  clip: auto;
  white-space: normal;
}


/* ============================================================================
   10. PRINT STYLES
   Ensures accessibility in print media
   ========================================================================= */

@media print {
  /* Show URLs for links */
  a[href]::after {
    content: " (" attr(href) ")";
  }
  
  /* Don't show skip links in print */
  .element-invisible {
    display: none;
  }
  
  /* Ensure good contrast in print */
  body {
    color: #000;
    background: #fff;
  }
}


/* ============================================================================
   11. HIGH CONTRAST MODE SUPPORT
   Respects user's high contrast preferences
   ========================================================================= */

@media (prefers-contrast: high) {
  body {
    color: #000;
    background: #fff;
  }
  
  a {
    color: #0000ee;
    text-decoration: underline;
  }
  
  button,
  .btn {
    border: 2px solid #000;
  }
}


/* ============================================================================
   12. REDUCED MOTION
   Respects user's motion preferences
   WCAG 2.3.3 Animation from Interactions (Level AAA)
   ========================================================================= */

@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;
  }
}
