/**
 * Accessibility Styles
 * Enhanced focus indicators, screen reader support, and accessibility utilities
 */

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

/* Skip Link */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  z-index: 10000;
  padding: 8px 16px;
  background: var(--color-charcoal);
  color: var(--color-white);
  text-decoration: none;
  font-weight: 600;
  border-radius: 0 0 4px 0;
  transition: top 0.2s ease;
}

.skip-link:focus {
  top: 0;
  outline: 3px solid var(--highlight-color);
  outline-offset: 2px;
}

/* Enhanced Focus Indicators */
*:focus-visible {
  outline: 2px solid var(--highlight-color);
  outline-offset: 2px;
  border-radius: 2px;
}

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

/* Focus styles for interactive elements */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--highlight-color);
  outline-offset: 2px;
}

/* High contrast focus for dark mode */
[data-theme="dark"] *:focus-visible {
  outline-color: var(--accent);
  outline-width: 3px;
}

/* Focus within for containers */
.focus-within-ring:focus-within {
  outline: 2px solid var(--highlight-color);
  outline-offset: 4px;
  border-radius: 4px;
}

/* Keyboard Navigation Indicator */
body.keyboard-navigation *:focus {
  outline: 2px solid var(--highlight-color);
  outline-offset: 2px;
}

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

.reduced-motion *,
.reduced-motion *::before,
.reduced-motion *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
  scroll-behavior: auto !important;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
  * {
    border-color: currentColor !important;
  }
  
  a,
  button {
    text-decoration: underline;
  }
  
  img {
    border: 2px solid currentColor;
  }
}

/* Touch Target Sizes (Mobile) */
@media (max-width: 768px) {
  a,
  button,
  input,
  select,
  textarea,
  [role="button"] {
    min-height: 44px;
    min-width: 44px;
  }
  
  /* Ensure tap targets are large enough */
  .nav-link,
  .btn,
  .work-card,
  .side-project-card {
    min-height: 44px;
  }
}

/* ARIA Live Region */
#sr-announcer {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* Focus Trap Indicator */
.focus-trap-active {
  position: relative;
}

.focus-trap-active::before {
  content: '';
  position: absolute;
  inset: -4px;
  border: 2px dashed var(--highlight-color);
  border-radius: 4px;
  pointer-events: none;
}

/* Loading States for Screen Readers */
[aria-busy="true"]::before {
  content: 'Loading';
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* Error States */
[aria-invalid="true"] {
  border-color: #dc2626;
  border-width: 2px;
}

[aria-invalid="true"]:focus {
  outline-color: #dc2626;
}

/* Required Field Indicator */
[aria-required="true"]::after {
  content: ' *';
  color: #dc2626;
  font-weight: bold;
}

/* Disabled State */
[aria-disabled="true"],
:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}

/* Hidden but Accessible */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Landmark Regions */
main {
  outline: none;
}

main:focus {
  outline: none;
}

/* Navigation Focus Styles */
.nav-menu a:focus-visible,
.nav-menu button:focus-visible {
  background-color: var(--highlight-color);
  color: var(--color-white);
  outline: 2px solid var(--color-white);
  outline-offset: -2px;
}

/* Dropdown Focus Styles */
.nav-dropdown a:focus-visible {
  background-color: rgba(var(--highlight-color-rgb, 0, 0, 0), 0.1);
  outline: 2px solid var(--highlight-color);
}

/* Button Focus Styles */
.btn:focus-visible,
.btn-cta:focus-visible {
  outline: 3px solid var(--highlight-color);
  outline-offset: 3px;
}

/* Card Focus Styles */
.work-card:focus-visible,
.side-project-card:focus-visible {
  outline: 3px solid var(--highlight-color);
  outline-offset: 4px;
  transform: scale(1.02);
}

/* Form Focus Styles */
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  border-color: var(--highlight-color);
  box-shadow: 0 0 0 3px rgba(var(--highlight-color-rgb, 0, 0, 0), 0.1);
}

/* Print Styles for Accessibility */
@media print {
  a[href]::after {
    content: " (" attr(href) ")";
  }
  
  .skip-link,
  .nav-toggle,
  .theme-toggle {
    display: none;
  }
  
  * {
    background: white !important;
    color: black !important;
    box-shadow: none !important;
  }
}

/* Dark Mode Focus Adjustments */
[data-theme="dark"] *:focus-visible {
  outline-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent), 0 0 8px rgba(196, 215, 255, 0.3);
}

/* Mobile Navigation Focus */
@media (max-width: 1024px) {
  .nav-menu.is-open a:focus-visible {
    background-color: var(--surface-2);
    color: var(--color-text);
  }
}

/* Ensure sufficient color contrast */
.work-card-overlay,
.testimonial-card-body {
  background: rgba(255, 255, 255, 0.95);
}

[data-theme="dark"] .work-card-overlay,
[data-theme="dark"] .testimonial-card-body {
  background: rgba(15, 22, 41, 0.95);
}

/* Text alternatives for decorative images */
img[alt=""],
img[role="presentation"] {
  /* Ensure decorative images are properly marked */
}

/* Link purpose clarity */
a:not([aria-label]):not([aria-labelledby]) {
  /* Ensure links have clear purpose */
}

/* Error messages */
.error-message {
  color: #dc2626;
  font-weight: 600;
  margin-top: 4px;
}

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

/* Success messages */
.success-message {
  color: #16a34a;
  font-weight: 600;
  margin-top: 4px;
}

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

/* Loading spinner accessibility */
.spinner[aria-label] {
  /* Spinner should have aria-label */
}

.spinner[aria-busy="true"] {
  /* Indicate busy state */
}

