/**
 * a11y-base.css — WCAG 2.1 AA Focus Visibility & Accessibility Base Styles
 *
 * Overrides the global `input:focus { outline-color: transparent }` from layout.css
 * Adopts the evMap widget's darkviolet dotted outline pattern for portal-wide consistency.
 */

/* ---- Focus Indicators ---- */

/* Override shared layout.css suppression (input:focus { outline-color: transparent }) */
input:focus,
select:focus,
textarea:focus,
button:focus,
a:focus,
[tabindex]:focus,
[role="tab"]:focus {
  outline-color: darkviolet;
  outline-style: dotted;
  outline-width: 2px;
  outline-offset: 2px;
}

/* Modern browsers: only show focus ring on keyboard navigation, not mouse clicks */
@supports selector(:focus-visible) {
  input:focus,
  select:focus,
  textarea:focus,
  button:focus,
  a:focus,
  [tabindex]:focus,
  [role="tab"]:focus {
    outline: none;
  }

  input:focus-visible,
  select:focus-visible,
  textarea:focus-visible,
  button:focus-visible,
  a:focus-visible,
  [tabindex]:focus-visible,
  [role="tab"]:focus-visible {
    outline-color: darkviolet;
    outline-style: dotted;
    outline-width: 2px;
    outline-offset: 2px;
  }
}

/* Ensure role="button" elements have same focus style */
[role="button"]:focus {
  outline-color: darkviolet;
  outline-style: dotted;
  outline-width: 2px;
  outline-offset: 2px;
}

@supports selector(:focus-visible) {
  [role="button"]:focus {
    outline: none;
  }
  [role="button"]:focus-visible {
    outline-color: darkviolet;
    outline-style: dotted;
    outline-width: 2px;
    outline-offset: 2px;
  }
}

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

/* ---- Unstyled Button for Semantic HTML ---- */
/* Used when replacing <div role="button"> with proper <button> elements */
.btn-unstyled {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  text-align: inherit;
  display: inline;
  width: auto;
}

.btn-unstyled:hover {
  background: none;
  border: none;
}

/* Maintain focus outline from general rules above */

/* ---- Skip Links ---- */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  z-index: 100000;
  padding: 8px 16px;
  background: #000;
  color: #fff;
  text-decoration: none;
  border-radius: 0 0 4px 0;
  font-weight: bold;
  transition: top 0.1s ease-in;
  visibility: hidden;
}

.skip-link:focus,
.skip-link:focus-visible {
  top: 0;
  outline: 2px solid #fff;
  outline-offset: 2px;
  visibility: visible;
}

/* Ensure main landmark can receive focus programmatically */
main[tabindex="-1"]:focus {
  outline: none;
}

/* Prevent skip link from scrolling header out of view (accounts for fixed header height) */
main[tabindex="-1"] {
  scroll-margin-top: 70px;
}

/* ---- Form Accessibility Styles ---- */
/* Heading resets to not break UI afte rusing h* instead of spans */
h1, h2, h3, h4, h5, h6 {
  margin-top: 0 !important;
  margin-bottom: 0 !important;
}
/* Required field indicator */
.required-indicator,
abbr.required-indicator {
  color: #d32f2f;
  text-decoration: none;
  font-weight: bold;
  margin-left: 2px;
}

/* Help text */
.help-text {
  display: block;
  margin-top: 4px;
  font-size: 0.875rem;
  color: #666;
}

/* Error text */
.error-text {
  display: block;
  margin-top: 4px;
  font-size: 0.875rem;
  color: #d32f2f;
  font-weight: bold;
}

.error-text:empty {
  display: none;
}

/* Invalid field styling */
.form-control.is-invalid {
  border-color: #d32f2f;
  border-width: 2px;
}

.form-control.is-invalid:focus {
  outline-color: #d32f2f;
  box-shadow: 0 0 0 3px rgba(211, 47, 47, 0.25);
}

/* Form group spacing */
.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
}

/* Fieldset styling */
fieldset {
  border: none;
  padding: 0;
  margin: 0 0 1.5rem 0;
}

fieldset legend {
  font-weight: bold;
  margin-bottom: 1rem;
  padding: 0;
}

/* File upload custom styling */
input[type="file"].sr-only + label {
  cursor: pointer;
  display: inline-block;
}

input[type="file"].sr-only:focus + label {
  outline: 2px dotted darkviolet;
  outline-offset: 2px;
}

/* ---- Color Contrast Enhancements (WCAG 2.1 AA Compliance) ---- */

/* Override Bootstrap's .text-muted for better contrast */
/* Bootstrap default: #777 (4.54:1 on white) - borderline */
/* Enhanced: #595959 (7:1 on white) - passes AAA */
.text-muted {
  color: #595959 !important;
}

/* Link colors - ensure 4.5:1 minimum on white background */
a {
  color: #0056b3; /* 7:1 ratio on white */
}

a:hover,
a:focus {
  color: #003d82; /* 10:1 ratio on white */
}

/* Visited links */
a:visited {
  color: #6f42c1; /* 5.5:1 ratio on white */
}

/* Button text contrast enhancements */
.btn-primary {
  background-color: #0056b3 !important;
  border-color: #004085 !important;
  color: #ffffff !important; /* 12:1 ratio */
}

.btn-secondary {
  background-color: #5a6268 !important;
  border-color: #545b62 !important;
  color: #ffffff !important; /* 9:1 ratio */
}

/* Badge/label contrast */
.badge-success {
  background-color: #1e7e34 !important; /* 4.5:1 on white for large text */
  color: #ffffff !important;
}

.badge-warning {
  background-color: #856404 !important; /* 7:1 on white */
  color: #ffffff !important;
}

.badge-danger {
  background-color: #bd2130 !important; /* 5.5:1 on white */
  color: #ffffff !important;
}

/* Placeholder text contrast (minimum 4.5:1) */
::placeholder {
  color: #6c757d;
  opacity: 1;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .text-muted {
    color: #000000 !important;
  }

  a {
    color: #0000EE !important;
    text-decoration: underline;
  }

  a:visited {
    color: #551A8B !important;
  }

  .btn {
    border-width: 2px !important;
  }
}

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