/**
 * Accessibility Enhancements for GENNOOR Platform
 * WCAG 2.1 AA Compliance
 */

/* ============================================
   Skip Links
   ============================================ */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--navy-primary, #0a1628);
  color: white;
  padding: 8px 16px;
  text-decoration: none;
  font-weight: 600;
  z-index: 10000;
  border-radius: 0 0 4px 0;
  transition: top 0.3s ease;
}

.skip-link:focus {
  top: 0;
  outline: 3px solid var(--blue-primary, #2563eb);
  outline-offset: 2px;
}

/* ============================================
   Focus Indicators (Enhanced)
   ============================================ */
*:focus {
  outline: 2px solid var(--blue-primary, #2563eb);
  outline-offset: 2px;
}

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

*:focus-visible {
  outline: 3px solid var(--blue-primary, #2563eb);
  outline-offset: 3px;
}

/* Enhanced button focus states */
button:focus-visible,
.btn:focus-visible,
a.btn:focus-visible {
  outline: 3px solid var(--blue-primary, #2563eb);
  outline-offset: 3px;
  box-shadow: 0 0 0 5px rgba(37, 99, 235, 0.2);
}

/* ============================================
   High Contrast Mode Support
   ============================================ */
@media (prefers-contrast: high) {
  :root {
    --navy-primary: #000000;
    --navy-light: #1a1a1a;
    --text-color: #ffffff;
  }
  
  .btn {
    border: 2px solid currentColor;
  }
  
  a {
    text-decoration: underline;
  }
}

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

/* ============================================
   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: inherit;
  margin: inherit;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* ============================================
   Color Contrast Improvements
   ============================================ */

/* Ensure minimum 4.5:1 contrast ratio for normal text */
.text-muted,
.text-secondary {
  color: #64748b; /* Updated for better contrast */
}

/* Links should have sufficient contrast */
a:not(.btn) {
  color: #1d4ed8; /* Darker blue for better contrast */
  text-decoration: underline;
  text-decoration-color: rgba(29, 78, 216, 0.3);
  text-underline-offset: 2px;
}

a:not(.btn):hover {
  color: #1e40af;
  text-decoration-color: rgba(30, 64, 175, 0.6);
}

a:not(.btn):focus {
  color: #1e3a8a;
  text-decoration-color: rgba(30, 58, 138, 1);
}

/* ============================================
   Form Accessibility
   ============================================ */

/* Required field indicators */
.required::after {
  content: " *";
  color: #dc2626;
  font-weight: bold;
}

/* Error states */
.form-error,
.input-error {
  border-color: #dc2626 !important;
  background-color: #fef2f2;
}

.error-message {
  color: #991b1b;
  font-size: 0.875rem;
  margin-top: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.error-message::before {
  content: "⚠";
  font-weight: bold;
}

/* Success states */
.form-success,
.input-success {
  border-color: #16a34a !important;
  background-color: #f0fdf4;
}

.success-message {
  color: #166534;
  font-size: 0.875rem;
  margin-top: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.success-message::before {
  content: "✓";
  font-weight: bold;
}

/* Form labels */
label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--navy-primary, #0a1628);
}

/* Input focus states */
input:focus,
textarea:focus,
select:focus {
  outline: 2px solid var(--blue-primary, #2563eb);
  outline-offset: 2px;
  border-color: var(--blue-primary, #2563eb);
}

/* ============================================
   Keyboard Navigation
   ============================================ */

/* Tab navigation visibility */
.tab-focus-visible:focus {
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.5);
}

/* Mobile menu keyboard support */
.nav-toggle:focus {
  outline: 3px solid var(--blue-primary, #2563eb);
  outline-offset: 3px;
}

/* Card focus states */
.card:focus-within {
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.3);
  transform: translateY(-2px);
}

/* ============================================
   Touch Target Sizes (WCAG AAA)
   ============================================ */

/* Ensure minimum 44x44px touch targets */
button,
.btn,
a.btn,
input[type="submit"],
input[type="button"],
input[type="reset"] {
  min-height: 44px;
  min-width: 44px;
  padding: 12px 24px;
}

/* Mobile touch targets */
@media (max-width: 768px) {
  .nav-link {
    min-height: 48px;
    padding: 14px 20px;
  }
  
  .card,
  .course-card {
    min-height: 48px;
  }
}

/* ============================================
   ARIA Live Regions
   ============================================ */
.live-region {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* ============================================
   Loading States
   ============================================ */
.loading {
  position: relative;
  pointer-events: none;
  opacity: 0.6;
}

.loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid var(--blue-primary, #2563eb);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spinner 0.8s linear infinite;
}

@keyframes spinner {
  to { transform: rotate(360deg); }
}

/* Respect prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  .loading::after {
    animation: none;
    border-top-color: var(--blue-primary, #2563eb);
  }
}

/* ============================================
   Text Spacing (WCAG 1.4.12)
   ============================================ */
.text-spacing-enhanced {
  line-height: 1.5 !important;
  letter-spacing: 0.12em !important;
  word-spacing: 0.16em !important;
}

p {
  line-height: 1.6;
  margin-bottom: 1rem;
}

/* ============================================
   Responsive Typography
   ============================================ */
@media (max-width: 768px) {
  /* Ensure text is readable on mobile */
  body {
    font-size: 16px; /* Prevent zoom on iOS */
  }
  
  h1 {
    font-size: 2rem;
    line-height: 1.2;
  }
  
  h2 {
    font-size: 1.5rem;
    line-height: 1.3;
  }
  
  h3 {
    font-size: 1.25rem;
    line-height: 1.4;
  }
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
  .skip-link,
  .nav-toggle,
  .back-to-top,
  button,
  .btn {
    display: none;
  }
  
  a {
    text-decoration: underline;
  }
  
  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: #666;
  }
}

/* ============================================
   Dark Mode Support (Accessibility)
   ============================================ */
@media (prefers-color-scheme: dark) {
  :root {
    --navy-primary: #1a2332;
    --navy-light: #2d3e50;
    --text-color: #e2e8f0;
    --bg-color: #0f172a;
  }
  
  body {
    background-color: var(--bg-color);
    color: var(--text-color);
  }
  
  a:not(.btn) {
    color: #60a5fa;
  }
  
  .card {
    background-color: var(--navy-light);
    border-color: #475569;
  }
}

/* ============================================
   Utility Classes
   ============================================ */

/* Hidden but accessible */
.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-width: 0 !important;
}

/* Not focusable */
.no-focus:focus {
  outline: none;
  box-shadow: none;
}

/* Ensure images don't break layout */
img {
  max-width: 100%;
  height: auto;
}

/* Alt text styling when image fails to load */
img::before {
  content: attr(alt);
  display: block;
  padding: 1rem;
  background-color: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  color: #475569;
  font-size: 0.875rem;
  text-align: center;
}
