/**
 * UpdraftDocs Accessibility Styles
 * WCAG 2.1 Level AA Compliance
 */

/* ===== Focus Indicators ===== */
/* Ensure all interactive elements have visible focus */

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

a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus,
summary:focus,
[tabindex]:focus {
  outline: 3px solid #ffbf47;
  outline-offset: 2px;
}

/* Focus within for containers */
*:focus-within {
  outline: none; /* Let child handle focus */
}

/* High contrast focus for dark backgrounds */
.cost-risk-badge:focus,
.complexity-badge:focus,
.update-type-badge:focus {
  outline-color: #ffffff;
  outline-width: 2px;
}

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

/* ===== Keyboard Navigation Helpers ===== */
.keyboard-only-focus:not(:focus-visible) {
  outline: none;
}

/* Show focus only for keyboard users */
@supports selector(:focus-visible) {
  *:focus {
    outline: none;
  }

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

/* ===== Color Contrast ===== */
/* Ensure WCAG AA contrast ratio of 4.5:1 for normal text, 3:1 for large text */

/* Update secondary text for better contrast */
.resource-description,
.concept-description,
.example-description {
  color: #212529; /* AA compliant */
}

.property-optional {
  color: #495057; /* AA compliant */
}

/* Dark mode contrast */
@media (prefers-color-scheme: dark) {
  .resource-description,
  .concept-description,
  .example-description {
    color: #e9ecef;
  }

  .property-optional {
    color: #adb5bd;
  }
}

/* ===== RTL Language Support ===== */
/* Enhanced support for Hebrew and Arabic */

html[dir="rtl"] {
  direction: rtl;
}

html[dir="rtl"] .book-menu {
  right: 0;
  left: auto;
}

html[dir="rtl"] .book-page {
  margin-right: 16rem;
  margin-left: 0;
}

html[dir="rtl"] .book-toc {
  left: 0;
  right: auto;
}

html[dir="rtl"] .property-table {
  direction: rtl;
}

html[dir="rtl"] .tab-navigation {
  direction: rtl;
}

html[dir="rtl"] .cost-risk-badge,
html[dir="rtl"] .complexity-badge,
html[dir="rtl"] .update-type-badge {
  direction: rtl;
}

/* Mirror icons for RTL */
html[dir="rtl"] .toggle-icon,
html[dir="rtl"] .sort-icon,
html[dir="rtl"] .search-icon {
  transform: scaleX(-1);
}

/* ===== Reduced Motion Support ===== */
/* Respect user's 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;
  }

  .nested-type-toggle,
  .tab-button,
  .code-block-copy {
    transition: none !important;
  }
}

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

@media (prefers-contrast: high) {
  .cost-risk-badge,
  .complexity-badge,
  .update-type-badge {
    border: 2px solid currentColor;
  }

  .property-table {
    border: 2px solid currentColor;
  }

  .property-table th,
  .property-table td {
    border: 1px solid currentColor;
  }

  .tab-button.active {
    border: 3px solid currentColor;
  }
}

/* ===== Semantic HTML Improvements ===== */
/* Ensure proper heading hierarchy */

main h1 {
  font-size: 2.5rem;
  line-height: 1.2;
  margin-bottom: 1.5rem;
}

main h2 {
  font-size: 2rem;
  line-height: 1.3;
  margin-top: 2rem;
  margin-bottom: 1rem;
}

main h3 {
  font-size: 1.5rem;
  line-height: 1.4;
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
}

main h4 {
  font-size: 1.25rem;
  line-height: 1.4;
  margin-top: 1rem;
  margin-bottom: 0.5rem;
}

/* ===== Touch Target Sizes ===== */
/* WCAG 2.1 Success Criterion 2.5.5 - Minimum 44x44px */

button,
a,
input[type="checkbox"],
input[type="radio"],
select,
.tab-button,
.code-block-copy,
.skip-link {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Exception for inline links in text */
p a,
li a {
  min-width: auto;
  min-height: auto;
  display: inline;
}

/* ===== Error States ===== */
/* Clear visual and semantic error indicators */

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

.error-message {
  color: #dc3545;
  font-weight: 600;
  margin-top: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

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

/* ===== Live Regions for Dynamic Content ===== */
[aria-live="polite"],
[aria-live="assertive"] {
  position: relative;
}

.status-message {
  padding: 1rem;
  margin: 1rem 0;
  border-radius: 0.25rem;
  background-color: #e7f3ff;
  border-left: 4px solid #0066cc;
}

/* ===== Link Underlines ===== */
/* Ensure links are distinguishable from text */

a {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

a:hover {
  text-decoration-thickness: 2px;
}

/* Exception for navigation links */
nav a,
.book-menu a,
.tab-button {
  text-decoration: none;
}

nav a:hover,
.book-menu a:hover {
  text-decoration: underline;
}

/* ===== Language Indicator ===== */
[lang]:not([lang=""]):not([lang="en"]) {
  font-style: normal;
}

/* Indicate language changes for screen readers */
[lang]:not([lang=""])::before {
  content: "";
  speak: literal-punctuation;
}

/* ===== Form Labels ===== */
/* Ensure all form inputs have associated labels */

input:not([type="hidden"]):not([aria-label]):not([aria-labelledby]),
select:not([aria-label]):not([aria-labelledby]),
textarea:not([aria-label]):not([aria-labelledby]) {
  /* Development warning - should have label */
  outline: 2px dashed orange !important;
}

/* ===== Table Headers ===== */
/* Ensure tables have proper headers */

table:not([role="presentation"]) th {
  font-weight: 600;
  text-align: left;
}

table:not([role="presentation"]) th[scope="col"] {
  vertical-align: bottom;
}

table:not([role="presentation"]) th[scope="row"] {
  text-align: left;
}

/* ===== Accessible Tooltips ===== */
[title] {
  position: relative;
}

/* Ensure title attributes are accessible */
[title]:hover::after,
[title]:focus::after {
  content: attr(title);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.5rem;
  background-color: #212529;
  color: white;
  font-size: 0.875rem;
  white-space: nowrap;
  border-radius: 0.25rem;
  z-index: 1000;
  pointer-events: none;
}

/* ===== Print Styles ===== */
@media print {
  .skip-navigation,
  .book-menu,
  .book-toc,
  .book-header,
  .book-footer,
  .code-block-copy {
    display: none !important;
  }

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

  .property-table {
    page-break-inside: avoid;
  }
}
