/**
 * Accessibility Styles for WCAG 2.1 Level AA Compliance
 * Renew Risk Platform
 */

/* ============================================
   Screen Reader Only Content
   ============================================ */
.sr-only,
.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;
}

/* ============================================
   Skip Links
   ============================================ */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: #000;
  color: #fff;
  padding: 8px 16px;
  text-decoration: none;
  z-index: 10000;
  font-weight: 600;
  border-radius: 0 0 4px 0;
}

.skip-link:focus {
  top: 0;
  outline: 3px solid #17807A;
  outline-offset: 2px;
}

/* ============================================
   Enhanced Focus Indicators
   WCAG 2.1 compliant - 4.52:1 contrast ratio
   ============================================ */
*:focus {
  outline: 3px solid #17807A;
  outline-offset: 2px;
}

/* Focus visible only for keyboard users */
:focus:not(:focus-visible) {
  outline: none;
}

:focus-visible {
  outline: 3px solid #17807A;
  outline-offset: 2px;
}

/* Button focus states */
.btn:focus,
.btn:focus-visible {
  outline: 3px solid #17807A;
  outline-offset: 2px;
  box-shadow: 0 0 0 0.2rem rgba(23, 128, 122, 0.25);
}

/* Input focus states */
input:focus,
textarea:focus,
select:focus {
  outline: 3px solid #17807A;
  outline-offset: 0;
  border-color: #17807A;
  box-shadow: 0 0 0 0.2rem rgba(23, 128, 122, 0.25);
}

/* Link focus states */
a:focus {
  outline: 3px solid #17807A;
  outline-offset: 2px;
  text-decoration: underline;
}

/* ============================================
   Required Field Indicators
   ============================================ */
.required-indicator {
  color: #dc3545;
  font-weight: bold;
  margin-left: 0.25rem;
}

.form-label.required::after {
  content: " *";
  color: #dc3545;
  font-weight: bold;
}

/* ============================================
   Error States
   ============================================ */
.form-control[aria-invalid="true"],
input[aria-invalid="true"],
textarea[aria-invalid="true"],
select[aria-invalid="true"] {
  border-color: #dc3545;
  padding-right: calc(1.5em + 0.75rem);
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='12' height='12' fill='none' stroke='%23dc3545'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23dc3545' stroke='none'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right calc(0.375em + 0.1875rem) center;
  background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

.error-message {
  color: #dc3545;
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

/* ============================================
   High Contrast Mode Support
   ============================================ */
@media (prefers-contrast: high) {
  .btn {
    border: 2px solid currentColor;
  }

  a {
    text-decoration: underline;
  }

  .navbar {
    border-bottom: 3px solid #fff;
  }
}

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

/* ============================================
   Color Blindness / Accessibility Enhancements
   ============================================ */

/* Add icons to color-coded elements for better accessibility */
.alert-success::before {
  content: "✓ ";
  font-weight: bold;
}

.alert-danger::before,
.alert-error::before {
  content: "⚠ ";
  font-weight: bold;
}

.alert-warning::before {
  content: "⚠ ";
  font-weight: bold;
}

.alert-info::before {
  content: "ℹ ";
  font-weight: bold;
}

/* ============================================
   Keyboard Navigation Helpers
   ============================================ */

/* Show outline on keyboard navigation */
.keyboard-nav *:focus {
  outline: 3px solid #20B2AA;
  outline-offset: 2px;
}

/* Remove outline on mouse navigation */
.mouse-nav *:focus {
  outline: none;
}

/* ============================================
   Improved Link Visibility
   ============================================ */
a {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

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

/* Navigation links don't need underline */
.navbar a,
.nav-tabs a,
.btn {
  text-decoration: none;
}

/* ============================================
   Modal Accessibility
   ============================================ */
.modal[aria-modal="true"] {
  /* Prevent background scroll when modal is open */
  position: fixed;
}

/* Ensure modal backdrop is announced */
.modal-backdrop {
  background-color: rgba(0, 0, 0, 0.5);
}

/* ============================================
   Table Accessibility
   ============================================ */
table caption {
  caption-side: top;
  color: #212529;
  font-weight: 600;
  padding: 0.75rem;
  text-align: left;
}

/* Zebra striping for better readability */
.table-striped tbody tr:nth-of-type(odd) {
  background-color: rgba(0, 0, 0, 0.02);
}

/* ============================================
   Loading States
   ============================================ */
[aria-busy="true"] {
  cursor: wait;
  opacity: 0.6;
}

/* ============================================
   Touch Target Size (Minimum 44x44px for WCAG)
   ============================================ */
button,
.btn,
a {
  min-height: 44px;
  min-width: 44px;
}

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

/* Checkbox/radio - let Shiny/Bootstrap handle styling, just ensure clickable area via label */
/* The label provides the touch target, not the input itself */

/* ============================================
   Improved Contrast for Disabled Elements
   ============================================ */
button:disabled,
.btn:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
