/* Accessibility Enhancements - M2AI Real Estate */
/* WCAG 2.1 Level AA/AAA Compliant Styles */

:root {
  /* WCAG AA/AAA Compliant Text Colors */
  /* All colors tested for contrast ratio on white backgrounds */
  --text-primary: #0f172a;        /* 16.8:1 - Highest contrast */
  --text-secondary: #334155;      /* 10.4:1 - Subheadlines */
  --text-tertiary: #475569;       /* 7.4:1 - Supporting text */
  --text-muted: #64748b;          /* 5.0:1 - Metadata (AA minimum) */

  /* Link Colors - WCAG Compliant */
  --link-primary: #1d4ed8;        /* 7.7:1 on white */
  --link-hover: #1e40af;          /* 9.2:1 on white */
  --link-visited: #7c3aed;        /* 6.3:1 on white */

  /* Status/Feedback Colors */
  --color-error: #dc2626;         /* 5.9:1 - Error states */
  --color-success: #047857;       /* 5.2:1 - Success states */
  --color-warning: #d97706;       /* 4.7:1 - Warning states */
  --color-info: #0369a1;          /* 6.8:1 - Info states */

  /* Background Colors */
  --bg-white: #ffffff;
  --bg-gray-50: #f8fafc;
  --bg-gray-100: #f1f5f9;
  --bg-error: #fef2f2;
  --bg-success: #f0fdf4;
  --bg-warning: #fffbeb;

  /* Border Colors */
  --border-default: #cbd5e1;
  --border-focus: #2563eb;
  --border-error: #dc2626;
}

/* Replace All Low-Contrast Text Colors */
.subheadline,
.hero-subheading,
.section-subtitle {
  color: var(--text-secondary) !important;
}

.trust-item,
.badge-text,
.mini-quote,
.intro-text,
.mission-text,
.why-text,
.cta-text {
  color: var(--text-secondary) !important;
}

.case-study-author,
.stat-label,
.form-intro p,
.mini-author,
.service-desc {
  color: var(--text-tertiary) !important;
}

/* Ensure All Body Text Meets Minimum Contrast */
body, p, li, td, th {
  color: var(--text-primary);
}

/* Link Accessibility */
a {
  color: var(--link-primary);
  text-decoration-thickness: 0.125em;
  text-underline-offset: 0.2em;
}

a:hover {
  color: var(--link-hover);
  text-decoration-thickness: 0.15em;
}

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

a:focus-visible {
  outline: 3px solid var(--border-focus);
  outline-offset: 3px;
  border-radius: 4px;
}

/* Universal Focus Indicator - WCAG 2.1 Requirement */
*:focus-visible {
  outline: 3px solid var(--border-focus);
  outline-offset: 3px;
  border-radius: 4px;
}

/* Remove Default Outline, Replace with Better One */
*:focus {
  outline: none;
}

/* Button Focus States */
.cta-button:focus-visible,
.primary-cta:focus-visible,
.secondary-cta:focus-visible,
.form-button:focus-visible,
button:focus-visible {
  outline: 4px solid var(--border-focus);
  outline-offset: 4px;
  border-color: #fff;
}

/* Input Focus States */
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Navigation Link Focus */
.nav-link-default:focus-visible,
.nav-link-current:focus-visible {
  outline: 3px solid var(--border-focus);
  outline-offset: 4px;
  border-radius: 6px;
}

/* Skip to Main Content Link - Keyboard Navigation */
.skip-to-main {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 999999;
  padding: 1rem 1.5rem;
  background: var(--link-hover);
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  font-size: 1rem;
  border-radius: 0 0 8px 0;
}

.skip-to-main:focus {
  left: 0;
  top: 0;
  outline: 3px solid #fff;
  outline-offset: -3px;
}

/* Screen Reader Only Class */
.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;
}

/* Visually Hidden but Available to Screen Readers */
.visually-hidden {
  position: absolute !important;
  height: 1px;
  width: 1px;
  overflow: hidden;
  clip: rect(1px, 1px, 1px, 1px);
  white-space: nowrap;
}

/* Form Error States - High Visibility */
.form-input.error,
.form-select.error,
.form-textarea.error,
input.error,
select.error,
textarea.error {
  border-color: var(--color-error) !important;
  background-color: var(--bg-error);
  border-width: 2px;
}

.error-message {
  color: var(--color-error);
  font-size: 0.875rem;
  font-weight: 600;
  margin-top: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.error-message::before {
  content: '⚠';
  font-size: 1rem;
  flex-shrink: 0;
}

/* Success States */
.success-message,
.form-success {
  color: var(--color-success);
  background-color: var(--bg-success);
  border: 2px solid var(--color-success);
  padding: 1rem;
  border-radius: 8px;
  font-weight: 600;
}

/* Required Field Indicator */
.form-label::after,
label.required::after {
  content: ' *';
  color: var(--color-error);
  font-weight: 700;
  margin-left: 0.125rem;
}

.form-label.optional::after,
label.optional::after {
  content: ' (optional)';
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.875rem;
  margin-left: 0.25rem;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
  :root {
    --text-primary: #000000;
    --text-secondary: #000000;
    --border-default: #000000;
  }

  .cta-button,
  .primary-cta,
  .secondary-cta {
    border: 3px solid currentColor !important;
  }

  .case-study-card,
  .service-card,
  .stat-card {
    border: 2px solid #000 !important;
  }

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

/* Reduced Motion for Users Who Prefer It */
@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;
  }

  /* Keep essential animations but make them instant */
  .pulse-glow {
    animation: none !important;
  }
}

/* Forced Colors Mode (Windows High Contrast) */
@media (forced-colors: active) {
  .cta-button,
  .primary-cta {
    border: 2px solid ButtonText;
  }

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

/* Focus-Visible Polyfill for Older Browsers */
.js-focus-visible :focus:not(.focus-visible) {
  outline: none;
}

/* Touch Target Size - WCAG 2.1 Level AAA */
/* Minimum 44x44px touch targets */
.cta-button,
.primary-cta,
.secondary-cta,
.nav-link-default,
.nav-link-current,
button,
a.button,
input[type="submit"],
input[type="button"] {
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Mobile Touch Targets - Even Larger */
@media (max-width: 768px) {
  .cta-button,
  .primary-cta,
  .secondary-cta,
  .form-button,
  button[type="submit"] {
    min-height: 48px;
    padding: 1rem 1.5rem;
  }

  .nav-link-default,
  .nav-link-current {
    min-height: 48px;
    padding: 0.75rem 1rem;
  }
}

/* Keyboard Navigation Helpers */
.keyboard-navigation-active *:focus {
  outline: 3px solid var(--border-focus) !important;
  outline-offset: 3px !important;
}

/* ARIA Live Region Styling */
[role="alert"],
[role="status"],
[aria-live] {
  padding: 1rem;
  border-radius: 8px;
  margin: 1rem 0;
}

[role="alert"] {
  background: var(--bg-error);
  color: var(--color-error);
  border: 2px solid var(--color-error);
}

[role="status"] {
  background: var(--bg-success);
  color: var(--color-success);
  border: 2px solid var(--color-success);
}

/* Ensure Sufficient Color Contrast for Badges */
.trust-badge,
.case-study-badge,
.service-badge {
  background: #ea580c !important;
  color: #ffffff !important;
  border: 1px solid #dc2626;
}

/* Make Non-Interactive Elements Clearly Static */
.trust-badge {
  cursor: default !important;
  user-select: none;
}

.trust-badge:hover {
  transform: none !important;
  background: #ea580c !important;
}

.badge-icon {
  pointer-events: none;
  user-select: none;
}

/* Improve Form Label Association */
label {
  cursor: pointer;
}

label:hover {
  color: var(--text-primary);
}

/* Disabled State Clarity */
button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  opacity: 0.6;
  cursor: not-allowed !important;
  background-color: var(--bg-gray-100) !important;
  color: var(--text-muted) !important;
}

/* Print Styles for Accessibility */
@media print {
  * {
    background: white !important;
    color: black !important;
  }

  a {
    text-decoration: underline !important;
  }

  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
  }
}
