/* ===================================
   ACCESSIBILITY ENHANCEMENTS
   =================================== */

/* Focus Indicators */
*:focus {
  outline: none;
}

*:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Enhanced Focus for Interactive Elements */
button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(229, 9, 20, 0.1);
}

/* Focus Within for Containers */
.video-card:focus-within {
  outline: 2px solid var(--accent-primary);
  outline-offset: 4px;
  border-radius: 12px;
}

/* Skip Links */
.skip-link {
  position: absolute;
  top: -100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent-primary);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 0 0 8px 8px;
  font-weight: 600;
  text-decoration: none;
  z-index: 10000;
  transition: top 0.3s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.skip-link:focus {
  top: 0;
}

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

.sr-only-focusable:focus {
  position: static;
  width: auto;
  height: auto;
  padding: inherit;
  margin: inherit;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

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

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
  :root {
    --bg-primary: #000000;
    --bg-secondary: #0a0a0a;
    --bg-tertiary: #141414;
    --bg-card: #1a1a1a;
    --text-primary: #ffffff;
    --text-secondary: #ffffff;
    --text-tertiary: #cccccc;
    --border-subtle: rgba(255, 255, 255, 0.3);
  }

  button,
  .btn,
  a {
    border: 2px solid currentColor;
  }

  .video-card {
    border: 2px solid var(--border-subtle);
  }
}

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

  .skeleton,
  .spinner,
  .loading-overlay {
    animation: none !important;
  }
}

/* Keyboard Navigation Indicators */
body.using-keyboard *:focus {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

body.using-mouse *:focus {
  outline: none;
}

/* Enhanced Button States for Accessibility */
button:disabled,
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  position: relative;
}

button:disabled::after,
.btn:disabled::after {
  content: attr(aria-label);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.9);
  color: white;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.85rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  margin-bottom: 8px;
}

button:disabled:hover::after,
.btn:disabled:hover::after {
  opacity: 1;
}

/* Form Field Accessibility */
input:invalid,
textarea:invalid,
select:invalid {
  border-color: #ef4444;
}

input:invalid:focus,
textarea:invalid:focus,
select:invalid:focus {
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.form-error {
  color: #ef4444;
  font-size: 0.85rem;
  margin-top: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.form-error-icon {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* Required Field Indicator */
.required::after {
  content: '*';
  color: var(--accent-primary);
  margin-left: 0.25rem;
}

/* Tooltip for Accessibility */
[data-tooltip] {
  position: relative;
}

[data-tooltip]::before {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.9);
  color: white;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.85rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  margin-bottom: 8px;
  z-index: 1000;
}

[data-tooltip]:hover::before,
[data-tooltip]:focus::before {
  opacity: 1;
}

/* Accessible Modal */
.modal[aria-hidden="true"] {
  display: none;
}

.modal[aria-hidden="false"] {
  display: flex;
}

/* Focus Trap for Modals */
.modal-open {
  overflow: hidden;
}

/* Accessible Tabs */
[role="tablist"] {
  display: flex;
  gap: 0.5rem;
}

[role="tab"] {
  position: relative;
}

[role="tab"][aria-selected="true"] {
  color: white;
  background: var(--accent-primary);
}

[role="tab"][aria-selected="false"] {
  color: var(--text-tertiary);
}

[role="tabpanel"][aria-hidden="true"] {
  display: none;
}

[role="tabpanel"][aria-hidden="false"] {
  display: block;
}

/* Accessible Dropdown */
[aria-expanded="false"] + [role="menu"],
[aria-expanded="false"] + [role="listbox"] {
  display: none;
}

[aria-expanded="true"] + [role="menu"],
[aria-expanded="true"] + [role="listbox"] {
  display: block;
}

/* Color Contrast Helpers */
.text-contrast-high {
  color: var(--text-primary);
  font-weight: 600;
}

.bg-contrast-high {
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
}

/* Touch Target Size (Minimum 44x44px) */
button,
.btn,
a,
input[type="checkbox"],
input[type="radio"] {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Exception for text links */
a:not(.btn) {
  min-width: auto;
  min-height: auto;
}

/* Accessible Loading States */
[aria-busy="true"] {
  position: relative;
  pointer-events: none;
}

[aria-busy="true"]::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Status Messages */
[role="status"],
[role="alert"] {
  padding: 1rem;
  border-radius: 8px;
  margin: 1rem 0;
}

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

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

/* Accessible Progress Bar */
[role="progressbar"] {
  position: relative;
  height: 8px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  overflow: hidden;
}

[role="progressbar"]::after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  background: var(--accent-primary);
  width: var(--progress, 0%);
  transition: width 0.3s ease;
}

/* Accessible Slider */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  background: var(--accent-primary);
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid white;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  background: var(--accent-primary);
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid white;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

input[type="range"]:focus::-webkit-slider-thumb {
  box-shadow: 0 0 0 4px rgba(229, 9, 20, 0.2);
}

input[type="range"]:focus::-moz-range-thumb {
  box-shadow: 0 0 0 4px rgba(229, 9, 20, 0.2);
}

/* Accessible Checkbox and Radio */
input[type="checkbox"],
input[type="radio"] {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-subtle);
  border-radius: 4px;
  cursor: pointer;
  position: relative;
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-tertiary);
}

input[type="radio"] {
  border-radius: 50%;
}

input[type="checkbox"]:checked,
input[type="radio"]:checked {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
}

input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 2px;
  width: 6px;
  height: 10px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

input[type="radio"]:checked::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 8px;
  height: 8px;
  background: white;
  border-radius: 50%;
}

/* Dark Mode Preference */
@media (prefers-color-scheme: light) {
  /* Users who prefer light mode can be accommodated here */
  /* Currently the app is dark-themed by default */
}

/* Print Styles for Accessibility */
@media print {
  * {
    background: white !important;
    color: black !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }

  a,
  a:visited {
    text-decoration: underline;
  }

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

  .no-print,
  header,
  footer,
  .back-to-top,
  .modal,
  .toast-container {
    display: none !important;
  }
}

/* Responsive Text Sizing */
@media (max-width: 768px) {
  html {
    font-size: 16px;
  }

  /* Ensure touch targets remain accessible */
  button,
  .btn,
  a.btn {
    min-width: 44px;
    min-height: 44px;
  }
}

/* Forced Colors Mode (Windows High Contrast) */
@media (forced-colors: active) {
  * {
    forced-color-adjust: auto;
  }

  button,
  .btn {
    border: 1px solid ButtonText;
  }

  .video-card {
    border: 1px solid CanvasText;
  }
}
