/* ==========================================================================
   Accessibility Enhancements
   Home Sweet Maine - WCAG 2.1 AA Compliance + User Preferences
   ========================================================================== */

/* --------------------------------------------------------------------------
   Skip Link - Allows keyboard users to skip navigation
   -------------------------------------------------------------------------- */
.skip-link {
  position: absolute;
  top: -100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-accent, #2c5545);
  color: white;
  padding: 12px 24px;
  border-radius: var(--radius-sm, 6px);
  z-index: 10000;
  font-weight: 600;
  text-decoration: none;
  transition: top 0.3s;
}

.skip-link:focus {
  top: 12px;
  outline: 3px solid white;
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Focus Visible - Global focus indicators
   -------------------------------------------------------------------------- */
*:focus-visible {
  outline: 3px solid var(--color-accent, #2c5545);
  outline-offset: 2px;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--color-accent, #2c5545);
  outline-offset: 2px;
}

/* Remove outline for mouse users */
*:focus:not(:focus-visible) {
  outline: none;
}

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

/* --------------------------------------------------------------------------
   Accessibility Toggle Button
   -------------------------------------------------------------------------- */
.a11y-toggle {
  position: fixed;
  bottom: 24px;
  left: 24px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #1b1b1e;
  border: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  z-index: 998;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.a11y-toggle:hover {
  background: #4cbae8;
  transform: scale(1.05);
}

.a11y-toggle:focus-visible {
  outline: 3px solid #4cbae8;
  outline-offset: 3px;
}

.a11y-toggle svg {
  width: 24px;
  height: 24px;
  fill: #ffffff;
}

/* --------------------------------------------------------------------------
   Accessibility Widget Panel
   -------------------------------------------------------------------------- */
.a11y-widget {
  position: fixed;
  bottom: 84px;
  left: 24px;
  width: 320px;
  background: var(--color-surface, #ffffff);
  border-radius: var(--radius-lg, 16px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
  z-index: 9998;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px) scale(0.95);
  transition: all 0.3s ease;
  overflow: hidden;
}

.a11y-widget.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.a11y-widget-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border-light, #f0f0f0);
  background: var(--color-bg, #faf9f7);
}

.a11y-widget-header h2 {
  font-family: var(--font-display, 'Cormorant Garamond', Georgia, serif);
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  color: var(--color-text, #1a1a1a);
}

.a11y-widget-close {
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  color: var(--color-text-muted, #6b6b6b);
  border-radius: var(--radius-sm, 6px);
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.a11y-widget-close:hover {
  background: var(--color-surface, #ffffff);
  color: var(--color-text, #1a1a1a);
}

.a11y-widget-close svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

.a11y-widget-body {
  padding: 16px 20px;
}

.a11y-option {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--color-border-light, #f0f0f0);
}

.a11y-option:last-child {
  border-bottom: none;
}

.a11y-option-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text, #1a1a1a);
}

/* Text Size Controls */
.a11y-text-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.a11y-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 10px;
  background: var(--color-bg, #faf9f7);
  border: 1px solid var(--color-border, #e5e5e5);
  border-radius: var(--radius-sm, 6px);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--color-text, #1a1a1a);
}

.a11y-btn:hover {
  background: var(--color-accent-light, #e8f0ec);
  border-color: var(--color-accent, #2c5545);
}

.a11y-btn svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

.a11y-text-value {
  min-width: 44px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-accent, #2c5545);
}

.a11y-btn--reset {
  background: transparent;
  border: none;
  color: var(--color-text-muted, #6b6b6b);
  font-size: 12px;
  padding: 6px 8px;
}

.a11y-btn--reset:hover {
  color: var(--color-accent, #2c5545);
  background: transparent;
}

/* Toggle Switch */
.a11y-toggle-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

.a11y-toggle-track {
  display: block;
  width: 44px;
  height: 24px;
  background: var(--color-border, #e5e5e5);
  border-radius: 12px;
  position: relative;
  transition: background 0.2s;
}

.a11y-toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s;
}

.a11y-toggle-btn.active .a11y-toggle-track {
  background: var(--color-accent, #2c5545);
}

.a11y-toggle-btn.active .a11y-toggle-thumb {
  transform: translateX(20px);
}

.a11y-toggle-btn:focus-visible .a11y-toggle-track {
  outline: 3px solid var(--color-accent, #2c5545);
  outline-offset: 2px;
}

.a11y-widget-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--color-border-light, #f0f0f0);
  background: var(--color-bg, #faf9f7);
}

.a11y-btn--reset-all {
  width: 100%;
  justify-content: center;
  padding: 10px;
  background: transparent;
  color: var(--color-text-muted, #6b6b6b);
}

.a11y-btn--reset-all:hover {
  background: var(--color-accent-light, #e8f0ec);
  color: var(--color-accent, #2c5545);
}

/* --------------------------------------------------------------------------
   Reading Guide - Horizontal bar that follows cursor
   -------------------------------------------------------------------------- */
.a11y-reading-guide {
  position: fixed;
  left: 0;
  right: 0;
  height: 40px;
  background: linear-gradient(
    transparent 0%,
    rgba(44, 85, 69, 0.08) 20%,
    rgba(44, 85, 69, 0.08) 80%,
    transparent 100%
  );
  pointer-events: none;
  z-index: 9997;
  display: none;
}

/* --------------------------------------------------------------------------
   High Contrast Mode
   -------------------------------------------------------------------------- */
.a11y-high-contrast {
  --color-bg: #000000;
  --color-surface: #1a1a1a;
  --color-text: #ffffff;
  --color-text-muted: #cccccc;
  --color-accent: #00ff88;
  --color-accent-hover: #00cc6a;
  --color-accent-light: #003320;
  --color-border: #444444;
  --color-border-light: #333333;
}

.a11y-high-contrast body {
  background: #000000;
}

.a11y-high-contrast a {
  color: #00ff88;
  text-decoration: underline;
}

.a11y-high-contrast img {
  filter: contrast(1.1);
}

.a11y-high-contrast .property-card,
.a11y-high-contrast .carousel-card,
.a11y-high-contrast .search-hero,
.a11y-high-contrast .nav-container,
.a11y-high-contrast header,
.a11y-high-contrast footer {
  background: #1a1a1a;
  border-color: #444444;
}

.a11y-high-contrast button,
.a11y-high-contrast .btn,
.a11y-high-contrast .action-btn {
  border: 2px solid currentColor;
}

/* --------------------------------------------------------------------------
   Dyslexia-Friendly Font
   -------------------------------------------------------------------------- */
@font-face {
  font-family: 'OpenDyslexic';
  src: url('https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/woff/OpenDyslexic-Regular.woff') format('woff');
  font-weight: normal;
  font-display: swap;
}

@font-face {
  font-family: 'OpenDyslexic';
  src: url('https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/woff/OpenDyslexic-Bold.woff') format('woff');
  font-weight: bold;
  font-display: swap;
}

.a11y-dyslexia-font,
.a11y-dyslexia-font * {
  font-family: 'OpenDyslexic', -apple-system, BlinkMacSystemFont, sans-serif !important;
  letter-spacing: 0.05em;
  word-spacing: 0.15em;
  line-height: 1.8;
}

.a11y-dyslexia-font h1,
.a11y-dyslexia-font h2,
.a11y-dyslexia-font h3,
.a11y-dyslexia-font h4,
.a11y-dyslexia-font h5,
.a11y-dyslexia-font h6 {
  letter-spacing: 0.02em;
}

/* --------------------------------------------------------------------------
   Reduce Motion - Disables animations
   -------------------------------------------------------------------------- */
.a11y-reduce-motion,
.a11y-reduce-motion *,
.a11y-reduce-motion *::before,
.a11y-reduce-motion *::after {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
  scroll-behavior: auto !important;
}

/* Also respect system preference */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* --------------------------------------------------------------------------
   WCAG Enhancements
   -------------------------------------------------------------------------- */

/* Minimum touch target size (44x44px) for mobile */
@media (pointer: coarse) {
  button,
  a,
  input[type="checkbox"],
  input[type="radio"],
  .nav-toggle,
  .action-btn,
  [role="button"] {
    min-height: 44px;
    min-width: 44px;
  }
}

/* Required field indicator */
label.required::after,
.required-label::after {
  content: ' *';
  color: #dc2626;
}

/* Error state for form inputs */
input:user-invalid,
textarea:user-invalid,
select:user-invalid {
  border-color: #dc2626;
}

input:user-invalid:focus,
textarea:user-invalid:focus,
select:user-invalid:focus {
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.2);
}

/* Link underlines for accessibility (not just color differentiation) */
main a:not(.btn):not(.action-btn):not(.property-card):not(.carousel-card):not([class*="nav"]) {
  text-decoration: underline;
  text-decoration-color: currentColor;
  text-underline-offset: 2px;
}

main a:not(.btn):not(.action-btn):not(.property-card):not(.carousel-card):not([class*="nav"]):hover {
  text-decoration-thickness: 2px;
}

/* --------------------------------------------------------------------------
   Mobile Adjustments
   -------------------------------------------------------------------------- */
@media (max-width: 900px) {
  .a11y-toggle {
    bottom: 16px;
    left: 16px;
    width: 44px;
    height: 44px;
  }

  .a11y-widget {
    bottom: auto;
    top: 50%;
    left: 50%;
    right: auto;
    transform: translate(-50%, -50%) scale(0.95);
    width: calc(100% - 32px);
    max-width: 320px;
    max-height: 80vh;
    overflow-y: auto;
  }

  .a11y-widget.active {
    transform: translate(-50%, -50%) scale(1);
  }

  /* Add backdrop on mobile */
  .a11y-widget::before {
    content: '';
    position: fixed;
    top: -100vh;
    left: -100vw;
    right: -100vw;
    bottom: -100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: -1;
    opacity: 0;
    transition: opacity 0.3s;
  }

  .a11y-widget.active::before {
    opacity: 1;
  }
}

/* Adjust for pages with mobile CTA bar */
body.has-mobile-cta .a11y-toggle {
  bottom: 176px;
}

/* --------------------------------------------------------------------------
   Print Styles - Hide accessibility UI
   -------------------------------------------------------------------------- */
@media print {
  .a11y-toggle,
  .a11y-widget,
  .a11y-reading-guide,
  .skip-link {
    display: none !important;
  }
}
