/**
 * Accessibility Enhancements CSS
 * WCAG 2.1 AA compliant styles for improved accessibility
 * Version: 1.0.0
 */

/* =====================================
   FOCUS INDICATORS
   ===================================== */

/* Enhanced focus indicators for all interactive elements */
*:focus {
  outline: 2px solid #0066cc !important;
  outline-offset: 2px !important;
}

/* Custom focus for buttons */
button:focus,
.btn:focus,
.button:focus,
input[type="submit"]:focus,
input[type="button"]:focus {
  outline: 2px solid #0066cc !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 4px rgba(0, 102, 204, 0.2) !important;
}

/* Custom focus for form elements */
input:focus,
textarea:focus,
select:focus {
  outline: 2px solid #0066cc !important;
  outline-offset: 1px !important;
  box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1) !important;
  border-color: #0066cc !important;
}

/* Custom focus for links */
a:focus {
  outline: 2px solid #0066cc !important;
  outline-offset: 2px !important;
  background-color: rgba(0, 102, 204, 0.1) !important;
  border-radius: 2px;
}

/* Focus for custom components */
.card:focus,
.tutor-card:focus,
.course-card:focus {
  outline: 2px solid #0066cc !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 4px rgba(0, 102, 204, 0.2) !important;
}

/* =====================================
   SKIP LINKS
   ===================================== */

/* Accessibility Enhancements for Student Pages */

/* Skip to main content link */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: #D64026;
  color: white;
  padding: 8px 16px;
  text-decoration: none;
  z-index: 100;
  border-radius: 0 0 4px 0;
  font-weight: 600;
  transition: top 0.2s;
}

.skip-link:focus {
  top: 0;
  outline: 3px solid #fff;
  outline-offset: 2px;
  outline: 2px solid #ffffff !important;
}

/* =====================================
   SCREEN READER ONLY
   ===================================== */

.sr-only,
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* =====================================
   COLOR CONTRAST IMPROVEMENTS
   ===================================== */

/* Improve text contrast */
.text-muted,
.muted {
  color: #495057 !important; /* Was too light, now 4.5:1 contrast */
}

.text-secondary {
  color: #495057 !important;
}

/* Button contrast improvements */
.btn-secondary {
  background-color: #495057 !important;
  border-color: #495057 !important;
  color: #ffffff !important;
}

.btn-secondary:hover {
  background-color: #343a40 !important;
  border-color: #343a40 !important;
}

/* Link contrast improvements */
a {
  color: #0056b3 !important; /* Darker blue for better contrast */
}

a:hover {
  color: #003d82 !important;
}

/* Form placeholder text */
input::placeholder,
textarea::placeholder {
  color: #495057 !important; /* Improved contrast from default gray */
  opacity: 1 !important;
}

/* Disabled state improvements */
input:disabled,
textarea:disabled,
select:disabled,
button:disabled,
.btn:disabled {
  opacity: 0.7 !important;
  background-color: #e9ecef !important;
  color: #495057 !important;
  border-color: #ced4da !important;
}

/* =====================================
   ERROR AND SUCCESS STATES
   ===================================== */

/* Form validation states */
.has-error input,
.has-error textarea,
.has-error select,
input[aria-invalid="true"],
textarea[aria-invalid="true"],
select[aria-invalid="true"] {
  border-color: #dc3545 !important;
  box-shadow: 0 0 0 2px rgba(220, 53, 69, 0.2) !important;
}

.has-success input,
.has-success textarea,
.has-success select,
input.success,
textarea.success,
select.success {
  border-color: #28a745 !important;
  box-shadow: 0 0 0 2px rgba(40, 167, 69, 0.2) !important;
}

/* Error message styling */
.validation-error,
.feedback-error-inline,
.error-message {
  color: #721c24 !important; /* Darker red for better contrast */
  background-color: #f8d7da !important;
  border: 1px solid #f5c6cb !important;
  padding: 0.5rem !important;
  border-radius: 4px !important;
  margin-top: 0.25rem !important;
  font-size: 0.875rem !important;
  line-height: 1.4 !important;
}

/* Success message styling */
.feedback-success,
.success-message {
  color: #155724 !important;
  background-color: #d4edda !important;
  border: 1px solid #c3e6cb !important;
  padding: 0.5rem !important;
  border-radius: 4px !important;
  margin-top: 0.25rem !important;
  font-size: 0.875rem !important;
}

/* Warning message styling */
.feedback-warning,
.warning-message {
  color: #856404 !important;
  background-color: #fff3cd !important;
  border: 1px solid #ffeaa7 !important;
  padding: 0.5rem !important;
  border-radius: 4px !important;
  margin-top: 0.25rem !important;
  font-size: 0.875rem !important;
}

/* =====================================
   INTERACTIVE ELEMENT IMPROVEMENTS
   ===================================== */

/* Ensure minimum touch target size (44x44px) */
button,
.btn,
input[type="submit"],
input[type="button"],
input[type="checkbox"],
input[type="radio"],
select,
.touch-target {
  min-width: 44px !important;
  min-height: 44px !important;
}

/* Exception for inline checkboxes and radio buttons */
input[type="checkbox"],
input[type="radio"] {
  min-width: 20px !important;
  min-height: 20px !important;
  margin: 12px !important; /* Padding around to meet 44px target */
}

/* =====================================
   HIGH CONTRAST MODE SUPPORT
   ===================================== */

@media (prefers-contrast: high) {
  * {
    border-color: currentColor !important;
  }
  
  *:focus {
    outline: 3px solid !important;
    outline-offset: 2px !important;
  }
  
  button,
  .btn {
    border: 2px solid !important;
  }
  
  input,
  textarea,
  select {
    border: 2px solid !important;
  }
}

/* =====================================
   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;
    scroll-behavior: auto !important;
  }
  
  .skip-link {
    transition: none !important;
  }
}

/* =====================================
   MODAL AND DIALOG IMPROVEMENTS
   ===================================== */

/* Modal backdrop */
.modal-backdrop,
.overlay {
  background-color: rgba(0, 0, 0, 0.75) !important; /* Increased opacity for better contrast */
}

/* Modal content */
.modal,
.dialog,
[role="dialog"] {
  background-color: white !important;
  border: 2px solid #dee2e6 !important;
  border-radius: 8px !important;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5) !important;
}

/* Modal headers */
.modal-header {
  border-bottom: 1px solid #dee2e6 !important;
  padding: 1rem !important;
}

/* Modal close buttons */
.modal-close,
.close {
  background: none !important;
  border: 2px solid transparent !important;
  font-size: 1.5rem !important;
  font-weight: bold !important;
  color: #495057 !important;
  padding: 0.5rem !important;
  border-radius: 4px !important;
  min-width: 44px !important;
  min-height: 44px !important;
  left: 300px;
}

.modal-close:hover,
.close:hover {
  background-color: #f8f9fa !important;
  border-color: #dee2e6 !important;
}

/* =====================================
   TOAST NOTIFICATIONS
   ===================================== */

.toast-a11y {
  min-width: 300px !important;
  max-width: 400px !important;
}

.toast-a11y__close:focus {
  outline: 2px solid rgba(255, 255, 255, 0.8) !important;
  outline-offset: 2px !important;
}

/* =====================================
   FORM IMPROVEMENTS
   ===================================== */

/* Label improvements */
label {
  font-weight: 600 !important;
  color: #212529 !important;
  display: block !important;
}

/* Required field indicators */
label[for] input[required] + label::after,
label input[required]::after {
  content: " *" !important;
  color: #dc3545 !important;
  font-weight: bold !important;
}

/* Fieldset and legend improvements */
fieldset {
  border: 2px solid #dee2e6 !important;
  border-radius: 4px !important;
  padding: 1rem !important;
  margin-bottom: 1rem !important;
}

legend {
  font-weight: bold !important;
  color: #212529 !important;
  padding: 0 0.5rem !important;
}

/* =====================================
   TABLE IMPROVEMENTS
   ===================================== */

table {
  border-collapse: collapse !important;
  width: 100% !important;
}

th,
td {
  border: 1px solid #dee2e6 !important;
  padding: 0.75rem !important;
  text-align: left !important;
}

th {
  background-color: #f8f9fa !important;
  font-weight: bold !important;
  color: #495057 !important;
}

/* =====================================
   RESPONSIVE IMPROVEMENTS
   ===================================== */

@media (max-width: 768px) {
  /* Ensure touch targets are adequate on mobile */
  button,
  .btn,
  input,
  select,
  textarea {
    min-height: 48px !important;
    font-size: 16px !important; /* Prevent zoom on iOS */
  }
  
  /* Modal improvements for mobile */
  .modal,
  [role="dialog"] {
    margin: 1rem !important;
    width: calc(100% - 2rem) !important;
    max-height: calc(100vh - 2rem) !important;
    overflow-y: auto !important;
  }
}

/* =====================================
   BOOKTUTOR FILTER ACCESSIBILITY
   ===================================== */

/* Ensure filter controls have visible focus on long pages */
.filters-section input:focus-visible,
.filters-section select:focus-visible,
.filters-section button:focus-visible,
.filter-bar input:focus-visible,
.filter-bar select:focus-visible,
.filter-bar button:focus-visible {
  outline: 3px solid #D64026 !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 5px rgba(214, 64, 38, 0.15) !important;
  z-index: 1;
}

/* Tutor card keyboard navigation */
.tutor-card[tabindex]:focus-visible {
  outline: 3px solid #D64026 !important;
  outline-offset: 3px !important;
  box-shadow: 0 8px 24px rgba(214, 64, 38, 0.25) !important;
  transform: translateY(-2px);
  z-index: 10;
}

/* Tier navigation buttons */
.tier-nav-btn:focus-visible {
  outline: 3px solid #D64026 !important;
  outline-offset: 2px !important;
  box-shadow: 0 4px 12px rgba(214, 64, 38, 0.2) !important;
}

/* =====================================
   NOTIFICATION PANEL ACCESSIBILITY
   ===================================== */

/* Notification panel focus trap visual indicator */
#notificationPanel.active {
  /* Focus trap is managed by common/topbar.js trapFocus() */
  border: 2px solid rgba(214, 64, 38, 0.3) !important;
}

#notificationPanel .notification-item:focus-visible {
  outline: 2px solid #D64026 !important;
  outline-offset: -2px !important;
  background-color: rgba(214, 64, 38, 0.08) !important;
}

#notificationPanel button:focus-visible {
  outline: 2px solid #D64026 !important;
  outline-offset: 2px !important;
}

/* Close button accessibility */
#notificationPanel .close-btn:focus-visible,
#notificationPanel [aria-label*="Close"]:focus-visible {
  outline: 3px solid #D64026 !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 4px rgba(214, 64, 38, 0.15) !important;
}

/* =====================================
   KEYBOARD NAVIGATION DETECTION
   ===================================== */

/* Hide focus rings when using mouse, show when using keyboard */
body:not(.user-is-tabbing) button:focus,
body:not(.user-is-tabbing) a:focus,
body:not(.user-is-tabbing) input:not([type="text"]):not([type="email"]):not([type="password"]):focus {
  outline: none !important;
}

body.user-is-tabbing *:focus-visible {
  outline: 3px solid #D64026 !important;
  outline-offset: 2px !important;
}

/* =====================================
   ARIA-LIVE REGION ENHANCEMENTS
   ===================================== */

/* Ensure aria-live regions are properly announced */
[aria-live="polite"],
[aria-live="assertive"] {
  position: relative;
}

/* Visual feedback when aria-busy state changes (for development) */
[aria-busy="true"]::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.7);
  pointer-events: none;
  z-index: 1;
}

/* Ensure content updates are visible */
[aria-live] > * {
  position: relative;
  z-index: 2;
}

/* =====================================
   IMPROVED CONTRAST FOR TEXT ELEMENTS
   ===================================== */

/* Ensure secondary text meets AA contrast ratio */
.text-secondary,
.muted,
.text-muted,
.hint {
  color: #495057 !important; /* 4.5:1 contrast on white */
}

/* Ensure disabled text is still readable */
input:disabled,
button:disabled,
select:disabled,
textarea:disabled {
  color: #6c757d !important; /* 4.54:1 contrast */
}

/* =====================================
   FOCUS ORDER AND SKIP NAVIGATION
   ===================================== */

/* Ensure logical tab order */
[tabindex="-1"]:focus {
  outline: none !important;
}

[tabindex="0"]:focus-visible,
[tabindex="1"]:focus-visible {
  outline: 3px solid #D64026 !important;
  outline-offset: 2px !important;
}

/* Skip to main content improvements */
.skip-link {
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

.skip-link:focus {
  clip: auto;
  clip-path: none;
  height: auto;
  overflow: visible;
  position: fixed;
  top: 0;
  left: 0;
  width: auto;
  z-index: 10000;
  padding: 1rem 1.5rem;
  background: #D64026;
  color: white;
  font-weight: 600;
  text-decoration: none;
  border-radius: 0 0 8px 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* =====================================
   PREFERS COLOR SCHEME SUPPORT
   ===================================== */

@media (prefers-contrast: more) {
  /* Enhance focus indicators in high contrast */
  *:focus-visible {
    outline-width: 4px !important;
    outline-offset: 3px !important;
  }
  
  /* Ensure all interactive elements have visible borders */
  button,
  .btn,
  input,
  select,
  textarea,
  a {
    border: 2px solid currentColor !important;
  }
  
  /* Remove gradient backgrounds */
  .gradient-text,
  .gradient-bg {
    background: none !important;
    color: inherit !important;
    -webkit-background-clip: unset !important;
    -webkit-text-fill-color: currentColor !important;
  }
}
