/**
 * WCAG 2.1 Level AA Accessibility Enhancements
 * VitaLaw | Defences - AI-Powered Canadian Legal Research Platform
 *
 * This file implements comprehensive accessibility features:
 * - Keyboard navigation
 * - Focus indicators
 * - Skip links
 * - ARIA live regions
 * - Screen reader optimizations
 * - High contrast mode support
 */

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

.skip-links {
  position: absolute;
  top: -100px;
  left: 0;
  z-index: 10000;
  background: #f59e0b;
  padding: 0;
  margin: 0;
  list-style: none;
}

.skip-links a {
  position: absolute;
  left: -10000px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
  background: #f59e0b;
  color: #000;
  padding: 1rem 1.5rem;
  text-decoration: none;
  font-weight: 600;
  font-size: 1rem;
  border-radius: 0 0 8px 0;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.4);
  transition: all 0.2s ease;
}

.skip-links a:focus {
  position: static;
  width: auto;
  height: auto;
  left: 0;
  top: 0;
  outline: 3px solid #fbbf24;
  outline-offset: 2px;
}

.skip-links a:hover {
  background: #fbbf24;
  transform: translateY(2px);
}

/* ==========================================
   FOCUS INDICATORS (WCAG AA 3:1 contrast)
   ========================================== */

/* Global focus styles - visible and high contrast */
*:focus {
  outline: 3px solid #f59e0b;
  outline-offset: 2px;
  transition: outline 0.2s ease;
}

/* Enhanced focus for interactive elements */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus,
[role="button"]:focus,
[role="link"]:focus,
[role="tab"]:focus,
[role="menuitem"]:focus {
  outline: 3px solid #f59e0b;
  outline-offset: 3px;
  box-shadow: 0 0 0 5px rgba(245, 158, 11, 0.2);
}

/* Focus within - for containers */
.focus-within:focus-within {
  border-color: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.2);
}

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

*:focus-visible {
  outline: 3px solid #f59e0b;
  outline-offset: 2px;
}

/* ==========================================
   KEYBOARD NAVIGATION SUPPORT
   ========================================== */

/* Visual indicator for keyboard navigation mode */
body.keyboard-navigation *:focus {
  outline: 3px solid #f59e0b !important;
  outline-offset: 3px !important;
}

/* Tab focus ring for cards and interactive containers */
.case-card:focus,
.industry-card:focus,
.faq-toggle:focus {
  outline: 3px solid #f59e0b;
  outline-offset: 4px;
  transform: translateY(-4px);
  box-shadow: 0 12px 40px rgba(245, 158, 11, 0.25);
}

/* ==========================================
   ARIA LIVE REGIONS
   ========================================== */

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

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

/* Live region styling */
[aria-live="polite"],
[aria-live="assertive"] {
  position: relative;
}

/* Status messages */
.status-message {
  padding: 1rem 1.5rem;
  border-radius: 8px;
  margin: 1rem 0;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.status-message[role="status"] {
  background: rgba(59, 130, 246, 0.1);
  border: 2px solid rgba(59, 130, 246, 0.3);
  color: #3b82f6;
}

.status-message[role="alert"] {
  background: rgba(239, 68, 68, 0.1);
  border: 2px solid rgba(239, 68, 68, 0.3);
  color: #ef4444;
}

/* ==========================================
   FORM ACCESSIBILITY
   ========================================== */

/* Ensure labels are visible and associated */
label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
  color: #f5f5f5;
  cursor: pointer;
}

label[for] {
  cursor: pointer;
}

/* Required field indicator */
.required::after,
[aria-required="true"] label::after {
  content: " *";
  color: #ef4444;
  font-weight: bold;
  margin-left: 0.25rem;
}

/* Input focus states */
input:focus,
textarea:focus,
select:focus {
  border-color: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.2);
  outline: 3px solid #f59e0b;
  outline-offset: 2px;
}

/* Error states */
input[aria-invalid="true"],
textarea[aria-invalid="true"],
select[aria-invalid="true"] {
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
}

/* Error messages */
.error-message {
  color: #ef4444;
  font-size: 0.875rem;
  margin-top: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
}

.error-message::before {
  content: "⚠";
  font-size: 1.125rem;
}

/* Field descriptions */
.field-description {
  font-size: 0.875rem;
  color: #94a3b8;
  margin-top: 0.25rem;
}

/* ==========================================
   BUTTON ACCESSIBILITY
   ========================================== */

/* Minimum touch target size: 44x44px (WCAG 2.5.5) */
button,
a.btn,
[role="button"] {
  min-height: 44px;
  min-width: 44px;
  padding: 0.75rem 1.5rem;
}

/* Icon buttons */
.icon-btn {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
}

/* Disabled state with proper contrast */
button:disabled,
[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ==========================================
   MODAL/DIALOG ACCESSIBILITY
   ========================================== */

/* Focus trap container */
.focus-trap {
  position: relative;
}

/* Modal backdrop */
[role="dialog"],
[role="alertdialog"] {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 9999;
  background: #1a1a1a;
  border: 2px solid #f59e0b;
  border-radius: 16px;
  padding: 2rem;
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
}

/* Modal overlay */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(3px);
  z-index: 9998;
}

/* Close button in modals */
.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 2px solid #2e2e2e;
  border-radius: 50%;
  color: #f5f5f5;
  font-size: 1.5rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.modal-close:hover,
.modal-close:focus {
  background: #2e2e2e;
  border-color: #f59e0b;
  transform: rotate(90deg);
}

/* ==========================================
   NAVIGATION MENU ACCESSIBILITY
   ========================================== */

/* Ensure nav elements are keyboard accessible */
nav a,
nav button {
  position: relative;
  display: inline-block;
  padding: 0.75rem 1rem;
  min-height: 44px;
  display: flex;
  align-items: center;
}

/* Dropdown menus */
[role="menu"],
[role="menubar"] {
  list-style: none;
  padding: 0.5rem 0;
}

[role="menuitem"] {
  padding: 0.75rem 1.5rem;
  min-height: 44px;
  cursor: pointer;
  transition: all 0.2s ease;
}

[role="menuitem"]:hover,
[role="menuitem"]:focus {
  background: #2e2e2e;
  color: #f59e0b;
}

/* ==========================================
   TABLE ACCESSIBILITY
   ========================================== */

/* Ensure tables have proper structure */
table {
  border-collapse: collapse;
  width: 100%;
}

th,
td {
  padding: 1rem;
  text-align: left;
  border: 1px solid #2e2e2e;
}

th {
  background: #1a1a1a;
  font-weight: 600;
  color: #f5f5f5;
}

/* Caption for tables */
caption {
  padding: 1rem;
  font-size: 1.25rem;
  font-weight: 600;
  text-align: left;
  color: #f5f5f5;
}

/* ==========================================
   COLOR CONTRAST FIXES
   ========================================== */

/* Ensure all text meets WCAG AA 4.5:1 contrast */
.text-primary {
  color: #f5f5f5; /* 18:1 on #0a0a0a */
}

.text-secondary {
  color: #d4d4d4; /* 12:1 on #0a0a0a */
}

.text-muted {
  color: #94a3b8; /* 6.5:1 on #0a0a0a */
}

/* Links must have 3:1 contrast against background */
a {
  color: #f59e0b; /* 5.8:1 on #0a0a0a */
  text-decoration-thickness: 2px;
  text-underline-offset: 2px;
}

a:hover,
a:focus {
  color: #fbbf24; /* 7.2:1 on #0a0a0a */
  text-decoration: underline;
}

/* ==========================================
   LOADING STATES
   ========================================== */

/* Loading spinner with aria-busy */
[aria-busy="true"] {
  position: relative;
  pointer-events: none;
  opacity: 0.6;
}

[aria-busy="true"]::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  border: 3px solid #2e2e2e;
  border-top-color: #f59e0b;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ==========================================
   ACCORDION/EXPANDABLE SECTIONS
   ========================================== */

[aria-expanded="false"] .expand-indicator {
  transform: rotate(0deg);
}

[aria-expanded="true"] .expand-indicator {
  transform: rotate(180deg);
}

.expand-indicator {
  transition: transform 0.3s ease;
  display: inline-block;
}

/* ==========================================
   MOBILE ACCESSIBILITY
   ========================================== */

/* Touch targets on mobile */
@media (max-width: 768px) {
  button,
  a.btn,
  [role="button"],
  input,
  select,
  textarea {
    min-height: 48px;
    min-width: 48px;
    font-size: 16px; /* Prevent zoom on iOS */
  }

  /* Larger tap areas for mobile */
  .mobile-menu-link,
  .case-card,
  .faq-toggle {
    min-height: 48px;
  }
}

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

@media (prefers-contrast: high) {
  *:focus {
    outline-width: 4px;
    outline-offset: 4px;
  }

  button,
  a,
  input,
  select,
  textarea {
    border-width: 2px;
  }

  .border {
    border-width: 2px !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;
  }

  .fade-in,
  .slide-up,
  .card-hover,
  .animate-fade-in-up {
    animation: none !important;
    transition: none !important;
  }
}

/* ==========================================
   PRINT ACCESSIBILITY
   ========================================== */

@media print {
  .skip-links,
  .mobile-menu-overlay,
  .mobile-filter-drawer,
  [aria-hidden="true"] {
    display: none !important;
  }

  a[href]::after {
    content: " (" attr(href) ")";
  }

  *:focus {
    outline: none;
  }
}

/* ==========================================
   UTILITIES
   ========================================== */

/* Visually hidden but accessible to screen readers */
.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;
}

/* Focus within utility */
.has-focus-within:focus-within {
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.3);
  border-color: #f59e0b;
}

/* Keyboard-only focus (no mouse) */
.focus-keyboard:focus:not(:active) {
  outline: 3px solid #f59e0b;
  outline-offset: 3px;
}
