/* ==========================================================================
   ACCESSIBILITY ENHANCEMENTS - WCAG 2.2 AA Compliance (PHASE 3B)
   Focus indicators, contrast verification, and screen reader optimizations
   ========================================================================== */

/* --- FOCUS INDICATORS (3px solid gold, exceeds 4.5:1 contrast) --- */
:focus-visible {
  outline: 3px solid var(--color-secondary);
  outline-offset: 3px;
  border-radius: 2px;
}

/* Remove default outline only when visible outline is applied */
*:focus-visible {
  outline: 3px solid var(--color-secondary);
  outline-offset: 3px;
}

/* Ensure all interactive elements have visible focus */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--color-secondary);
  outline-offset: 3px;
  border-radius: 2px;
}

/* Button focus states */
.btn:focus-visible,
.header-search-btn:focus-visible,
.menu-toggle:focus-visible {
  outline: 3px solid var(--color-secondary);
  outline-offset: 3px;
}

/* Navigation link focus */
.nav-menu a:focus-visible,
.dropdown a:focus-visible,
[role="menuitem"]:focus-visible {
  outline: 3px solid var(--color-secondary);
  outline-offset: 2px;
}

/* --- SKIP LINK (accessibility best practice) --- */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--color-primary);
  color: white;
  padding: 8px 16px;
  text-decoration: none;
  z-index: 10000;
  font-weight: 600;
}

.skip-link:focus-visible {
  top: 0;
  outline: 3px solid var(--color-secondary);
  outline-offset: 0;
}

/* --- COLOR CONTRAST VERIFICATION --- */
/* Navy var(--color-primary) on white: 12.6:1 (exceeds 4.5:1 requirement) */
/* Gold var(--color-secondary) on navy: 5.2:1 (exceeds 4.5:1 requirement) */
/* Gray text on white: 7.1:1 (exceeds 4.5:1 requirement) */

body {
  color: var(--color-text-dark); /* 7.1:1 on white */
}

/* Underline + navy ONLY for links inside running body text (prose / article
   / blog / faq answers). Navigation, header, footer, topbar and icon links
   keep their own component colors — a global rule here made them navy-on-navy
   (invisible) and put an unwanted underline under the nav items. */
.prose p a,
.prose li a,
.post-content a,
.blog-body a,
.faq-a a {
  color: var(--color-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.prose p a:hover,
.prose li a:hover,
.post-content a:hover,
.blog-body a:hover,
.faq-a a:hover {
  color: var(--color-secondary-dark);
  text-decoration: none;
}

/* Footer links - Gold on navy background */
.footer-links a {
  color: var(--color-secondary);
  text-decoration: none;
}

.footer-links a:hover {
  color: var(--color-secondary-hover);
  text-decoration: none;
}

/* Ensure sufficient contrast on all text */
.text-muted {
  color: var(--color-text-muted); /* 5.5:1 on white */
}

/* --- FORM ACCESSIBILITY --- */
label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  color: var(--color-primary);
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="search"],
textarea,
select {
  border: 2px solid var(--color-border-light);
  padding: 10px 12px;
  font-size: 16px; /* Prevents zoom on iOS */
  font-family: inherit;
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  border-color: var(--color-secondary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(200, 166, 70, 0.1);
}

/* Required field indicator — only on <label>, never on <input>.
   (::after does not render on replaced inputs, and it collided with the
   custom consent checkbox, printing a stray "*".) */
label.required::after,
label[data-required]::after {
  content: " *";
  color: var(--color-error);
}

/* Error messaging - linked via aria-describedby */
.form-error {
  color: var(--color-primary);
  font-size: 14px;
  margin-top: 4px;
  display: block;
}

input[aria-invalid="true"] {
  border-color: var(--color-primary);
}

input[aria-invalid="true"]:focus-visible {
  outline-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(196, 30, 58, 0.1);
}

/* --- BUTTON ACCESSIBILITY --- */
button,
input[type="button"],
input[type="submit"] {
  min-height: 48px; /* Mobile clickable target */
  min-width: 48px;
  padding: 12px 24px;
  font-size: 16px;
  cursor: pointer;
  border: none;
  border-radius: 4px;
  transition: all 0.3s ease;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* --- DROPDOWN & MENU ACCESSIBILITY --- */
[role="menuitem"] {
  display: block;
  padding: 12px 16px;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
}

[aria-expanded="true"] + .dropdown,
[aria-expanded="true"] + .mega-menu {
  display: block;
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* --- SCREEN READER ONLY TEXT --- */
.sr-only,
.screen-reader-text {
  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:focus-visible,
.screen-reader-text:focus-visible {
  position: static;
  width: auto;
  height: auto;
  overflow: visible;
  clip: auto;
  white-space: normal;
  padding: 8px 16px;
  background: var(--color-primary);
  color: white;
}

/* --- SEMANTIC HTML LANDMARKS --- */
[role="banner"] {
  /* Header/banner styles */
}

[role="main"] {
  /* Main content area */
}

[role="navigation"] {
  /* Navigation areas */
}

[role="contentinfo"] {
  /* Footer area */
}

/* --- LIVE REGION FOR NOTIFICATIONS --- */
[aria-live="polite"],
[aria-live="assertive"] {
  position: relative;
}

/* --- HEADING HIERARCHY --- */
h1 {
  font-size: 2.5rem;
  margin: 1.5rem 0 1rem 0;
}

h2 {
  font-size: 2rem;
  margin: 1.25rem 0 0.75rem 0;
}

h3 {
  font-size: 1.5rem;
  margin: 1rem 0 0.5rem 0;
}

h4 {
  font-size: 1.25rem;
  margin: 0.75rem 0 0.5rem 0;
}

h5 {
  font-size: 1.1rem;
  margin: 0.5rem 0 0.25rem 0;
}

h6 {
  font-size: 1rem;
  margin: 0.5rem 0 0.25rem 0;
}

/* Ensure proper heading structure */
h1 + h2,
h2 + h3,
h3 + h4 {
  margin-top: 0.5rem;
}

/* --- LINK ACCESSIBILITY ---
   Underlines are applied to body-text links only (see the .prose/.faq-a rules
   near the top of this file). A global a{underline} was putting an unwanted
   line under every nav item, topbar link and button. Keep the underline only
   on keyboard focus so focus is always clearly indicated. */
a:focus-visible {
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

/* Links that open in new window — hint kept for screen readers only (was
   visually printing "(opens in new window)" over social icons & app badges).
   Icon-only / button / logo links rely on their aria-label instead. */
a[target="_blank"]:not([aria-label]):not(.btn)::after {
  content: " (opens in new window)";
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --- IMAGE ACCESSIBILITY --- */
img {
  max-width: 100%;
  height: auto;
  /* All images must have meaningful alt text */
}

img[alt=""],
img:not([alt]) {
  /* Alert if missing alt text */
  border: 2px dashed orange;
}

/* Decorative images */
img[aria-hidden="true"] {
  /* Already marked as decorative */
}

/* --- TABLE ACCESSIBILITY --- */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
}

th {
  background: var(--color-primary);
  color: white;
  padding: 12px;
  text-align: left;
  font-weight: 600;
}

td {
  padding: 12px;
  border-bottom: 1px solid var(--color-border-light);
}

tbody tr:nth-child(odd) {
  background: var(--color-background);
}

/* --- LIST ACCESSIBILITY --- */
ol, ul {
  margin: 1rem 0;
  padding-left: 2rem;
}

ol li, ul li {
  margin: 0.5rem 0;
  line-height: 1.6;
}

/* --- ANIMATION & MOTION --- */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* --- TEXT SIZING --- */
/* Allow users to scale text up to 200% */
body {
  font-size: 16px;
  line-height: 1.6;
}

/* Ensure relative units for responsive text */
h1 { font-size: clamp(1.75rem, 5vw, 2.5rem); }
h2 { font-size: clamp(1.5rem, 4vw, 2rem); }
h3 { font-size: clamp(1.25rem, 3vw, 1.5rem); }

/* --- MOBILE TOUCH TARGETS --- */
button,
a,
input[type="checkbox"],
input[type="radio"],
[role="button"],
[role="link"] {
  min-height: 44px;
  min-width: 44px;
}

/* Adjust for padding */
.btn {
  padding: 12px 24px;
  min-height: 48px;
}

/* --- DARK MODE SUPPORT --- */
@media (prefers-color-scheme: dark) {
  body {
    background: var(--color-text-dark);
    color: var(--color-border-light);
  }

  a {
    color: var(--color-secondary);
  }

  a:visited {
    color: var(--color-secondary);
  }

  input,
  textarea,
  select {
    background: var(--color-text-dark);
    color: var(--color-border-light);
    border-color: var(--color-text-muted);
  }

  th {
    background: var(--color-primary);
  }

  tbody tr:nth-child(odd) {
    background: var(--color-text-dark);
  }
}

/* --- HIGH CONTRAST MODE --- */
@media (prefers-contrast: more) {
  body {
    color: var(--color-text-dark);
  }

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

  button {
    border: 2px solid currentColor;
  }

  input,
  textarea,
  select {
    border: 2px solid var(--color-text-dark);
  }
}

/* --- TRANSPARENCY REDUCTION --- */
@media (prefers-reduced-transparency: reduce) {
  * {
    background-attachment: fixed !important;
  }

  .hero-overlay,
  .overlay {
    opacity: 1 !important;
  }
}
