/* =============================================
   WCAG 2.1 AA Accessibility Enhancements
   Gopnik Wallet — Iteration 6
   ============================================= */

/* ── Focus Indicators ──────────────────────────────────────────────────
   All interactive elements must have visible focus indicators.
   Using a high-contrast outline that works on both dark and light themes.
   Minimum 3:1 contrast ratio against adjacent background.
*/

*:focus-visible {
  outline: 2px solid #c4b5fd !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.3) !important;
  border-radius: 4px;
}

/* Remove default outline for mouse users, keep for keyboard */
*:focus:not(:focus-visible) {
  outline: none !important;
  box-shadow: none !important;
}

/* Button focus */
button:focus-visible,
.btn:focus-visible,
a.btn:focus-visible,
[role="button"]:focus-visible {
  outline: 2px solid #c4b5fd !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.3) !important;
}

/* Form control focus */
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible {
  outline: 2px solid #8b5cf6 !important;
  outline-offset: 0 !important;
  border-color: #8b5cf6 !important;
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.25) !important;
}

/* Link focus */
a:focus-visible {
  outline: 2px solid #c4b5fd !important;
  outline-offset: 2px !important;
  text-decoration: underline;
}

/* Dropdown items */
.dropdown-item:focus-visible,
.nav-link:focus-visible {
  outline: 2px solid #c4b5fd !important;
  outline-offset: -2px !important;
  background-color: rgba(139, 92, 246, 0.15) !important;
}


/* ── Colour Contrast ───────────────────────────────────────────────────
   Ensure text meets WCAG 2.1 AA contrast ratios:
   - 4.5:1 for normal text (< 18pt or < 14pt bold)
   - 3:1 for large text (>= 18pt or >= 14pt bold)

   Override any low-contrast text with accessible alternatives.
*/

/* Muted text: #8b89b8 on #080a2e → ~4.1:1 — bump to ensure 4.5:1 */
.text-muted,
[style*="color:#8b89b8"],
[style*="color: #8b89b8"] {
  color: #9e9cd0 !important;
}

/* Success text needs 4.5:1 on dark backgrounds */
.text-success,
.trade-buy {
  color: #34d399 !important;
}

/* Danger text */
.text-danger,
.trade-sell {
  color: #f87171 !important;
}

/* Warning text */
.text-warning {
  color: #fbbf24 !important;
}


/* ── Skip Navigation ───────────────────────────────────────────────────
   Enhanced skip link styling (already in base.html but improved here)
*/

.visually-hidden-focusable:focus {
  position: fixed !important;
  top: 8px !important;
  left: 8px !important;
  z-index: 100000 !important;
  padding: 12px 24px !important;
  background: #8b5cf6 !important;
  color: #fff !important;
  font-weight: 700 !important;
  font-size: 0.95rem !important;
  text-decoration: none !important;
  border-radius: 8px !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5) !important;
}


/* ── Reduced Motion ────────────────────────────────────────────────────
   Respect prefers-reduced-motion to avoid triggering vestibular disorders.
*/

@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;
  }
}


/* ── Touch Targets ─────────────────────────────────────────────────────
   Ensure minimum 44x44px touch targets for interactive elements.
*/

button,
a.btn,
.btn,
[role="button"],
.nav-link,
.dropdown-item,
.feed-action-btn,
.feed-tab,
.filter-tab,
.chart-btn {
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Navigation items slightly smaller is acceptable at 36px in dense navbars */
.navbar .nav-link,
.navbar .dropdown-item {
  min-height: 36px;
  padding-top: 8px;
  padding-bottom: 8px;
}


/* ── ARIA Live Region Styling ──────────────────────────────────────────
   Toast notifications and WebSocket updates use aria-live regions.
*/

[aria-live="polite"],
[aria-live="assertive"] {
  /* Ensure live regions are not hidden from screen readers */
  clip: auto !important;
}

/* Status banner for connection loss */
#connectionBanner[role="alert"] {
  font-weight: 700;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}


/* ── High Contrast Mode ────────────────────────────────────────────────
   Additional styles for forced-colors (Windows High Contrast).
*/

@media (forced-colors: active) {
  button,
  .btn,
  input,
  select,
  textarea {
    border: 1px solid ButtonText;
  }

  a {
    color: LinkText;
  }

  *:focus-visible {
    outline: 2px solid Highlight !important;
  }
}


/* ── Selection ─────────────────────────────────────────────────────────
   Custom selection colours with accessible contrast.
*/

::selection {
  background: rgba(139, 92, 246, 0.4);
  color: #f0f1ff;
}
