/* ========== Accessibility Enhancements - Unikode Design System ========== */
/* Enhanced focus indicators, ARIA support, and accessibility utilities */

/* ========== Enhanced Focus Indicators ========== */

/* Global focus visible styles */
:focus-visible {
  outline: 2px solid var(--color-text);
  outline-offset: 3px;
  border-radius: 2px;
}

/* High contrast focus for interactive elements */
a:focus-visible,
button:focus-visible,
[role="button"]:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--color-text);
  outline-offset: 2px;
  box-shadow: 0 0 0 6px rgba(255, 255, 255, 0.15);
}

/* Light theme focus adjustments */
[data-theme="light"] :focus-visible {
  outline-color: var(--color-text);
  box-shadow: 0 0 0 6px rgba(0, 0, 0, 0.1);
}

/* Focus within for form groups */
.form-group:focus-within {
  outline: 2px solid var(--color-text-secondary);
  outline-offset: 4px;
  border-radius: var(--radius-component);
}

/* Card focus state */
.card:focus-within {
  outline: 2px solid var(--color-text-secondary);
  outline-offset: 2px;
}

/* Navigation link focus */
.nav-links a:focus-visible {
  outline-offset: 4px;
  text-decoration: underline;
}

/* Button focus improvements */
.btn:focus-visible {
  outline: 3px solid currentColor;
  outline-offset: 3px;
}

/* Domain tab focus */
.domain-tab:focus-visible {
  outline: 2px solid var(--color-text);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.3);
}

/* ========== Skip Links ========== */

.skip-link {
  position: fixed;
  top: -100px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  padding: var(--space-3) var(--space-6);
  background: var(--color-text);
  color: var(--color-bg);
  text-decoration: none;
  font-weight: 600;
  border-radius: var(--radius-full);
  transition: top var(--duration-short-4) var(--easing-standard);
}

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

/* ========== Screen Reader Utilities ========== */

/* Visually hidden but accessible to screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Show on focus (for skip links, etc.) */
.sr-only-focusable:focus,
.sr-only-focusable:active {
  position: static;
  width: auto;
  height: auto;
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* ========== ARIA Live Region Styles ========== */

[aria-live] {
  /* Ensure live regions are not visually hidden unless intended */
}

.live-region {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.live-region-visible {
  position: relative;
  left: auto;
  width: auto;
  height: auto;
  overflow: visible;
  padding: var(--space-3);
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: var(--radius-component);
  margin-top: var(--space-2);
}

/* Status message styles */
.status-message {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-component);
  font-size: var(--text-body-md);
}

.status-message[role="status"] {
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.3);
  color: var(--color-text);
}

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

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

/* Show keyboard navigation mode */
.keyboard-nav :focus {
  outline: 3px solid var(--color-text);
  outline-offset: 3px;
}

/* Hide outlines for mouse users */
.mouse-nav :focus:not(:focus-visible) {
  outline: none;
}

/* ========== High Contrast Mode Support ========== */

@media (prefers-contrast: high) {
  :root {
    --color-border: #ffffff;
    --color-border-strong: #ffffff;
  }

  .btn {
    border: 2px solid currentColor;
  }

  .card {
    border: 2px solid var(--color-text);
  }

  a {
    text-decoration: underline;
  }
}

/* ========== Forced Colors Mode (Windows High Contrast) ========== */

@media (forced-colors: active) {
  .btn {
    border: 2px solid ButtonText;
  }

  .card {
    border: 2px solid CanvasText;
  }

  :focus-visible {
    outline: 3px solid Highlight;
    outline-offset: 2px;
  }

  .nav-links a:hover {
    forced-color-adjust: none;
    background: Highlight;
    color: HighlightText;
  }
}

/* ========== Motion Preferences ========== */

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

  .parallax {
    transform: none !important;
  }
}

/* Allow essential motion only */
@media (prefers-reduced-motion: no-preference) {
  /* Full animations enabled */
}

/* ========== Touch Target Sizes ========== */

/* Ensure minimum 44x44px touch targets */
@media (pointer: coarse) {
  .btn,
  .nav-links a,
  .domain-tab,
  .theme-toggle,
  .nav-hamburger {
    min-height: 44px;
    min-width: 44px;
  }

  /* Increase spacing between touch targets */
  .nav-links {
    gap: var(--space-4);
  }

  .domain-tabs {
    gap: var(--space-3);
  }
}

/* ========== Text Spacing Override Support ========== */

/* Support for user text spacing preferences (WCAG 1.4.12) */
html {
  /* Allow text spacing to be overridden */
  word-spacing: normal;
  letter-spacing: normal;
}

/* Ensure content reflows with increased spacing */
p, li, dd, dt, th, td {
  line-height: 1.5;
}

/* ========== Focus Trap Indicator ========== */

[data-focus-trap="true"] {
  position: relative;
}

[data-focus-trap="true"]::before {
  content: '';
  position: absolute;
  inset: -4px;
  border: 2px dashed var(--color-text-tertiary);
  border-radius: var(--radius-component);
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--duration-short-4) var(--easing-standard);
}

[data-focus-trap="true"]:focus-within::before {
  opacity: 1;
}

/* ========== Error State Accessibility ========== */

.error,
[aria-invalid="true"] {
  border-color: #ef4444 !important;
}

.error-message {
  color: #ef4444;
  font-size: var(--text-body-sm);
  margin-top: var(--space-1);
}

/* Light theme error colors */
[data-theme="light"] .error-message {
  color: #dc2626;
}

/* ========== Loading State Accessibility ========== */

[aria-busy="true"] {
  cursor: wait;
  opacity: 0.7;
}

.loading-indicator {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.loading-indicator::before {
  content: '';
  width: 16px;
  height: 16px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  will-change: transform; /* GPU compositing hint */
}

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

@media (prefers-reduced-motion: reduce) {
  .loading-indicator::before {
    animation: none;
    border: 2px solid currentColor;
    opacity: 0.5;
  }
}
