/**
 * Accessibility Enhancements
 * Improves keyboard navigation, screen reader support, and WCAG compliance
 */

/* Skip to main content link - visible only on focus */
.visually-hidden-focusable:not(:focus):not(:focus-within) {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.visually-hidden-focusable:focus {
  clip: auto !important;
  width: auto !important;
  height: auto !important;
  overflow: visible !important;
  white-space: normal !important;
  z-index: 10000;
  text-decoration: none;
}

/* Focus indicators - ensure visible for keyboard navigation */
a:focus,
button:focus,
input:focus,
textarea:focus,
select:focus,
[tabindex]:focus {
  outline: 3px solid #FF6B35;
  outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .card {
    border: 2px solid currentColor;
  }
  
  .btn {
    border: 2px solid currentColor;
  }
}

/* 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;
  }
}

/* Screen reader only content */
.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;
}

/* Ensure sufficient color contrast */
.text-muted {
  color: #6c757d !important;
}

/* Ensure interactive elements have adequate touch target size (min 44x44px)
   NOTE: To avoid oversized checkboxes across the whole project, we scope the
   larger checkbox targets only to the Custom Tour form. */
.btn,
.nav-link,
.form-select {
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Large checkboxes only inside Custom Tour form */
.custom-tour-form .form-check-input {
  min-height: 44px;
  min-width: 44px;
  width: 1.5rem;
  height: 1.5rem;
}

/* Improve link visibility */
a:not(.btn):not(.nav-link) {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

a:not(.btn):not(.nav-link):hover {
  text-decoration-thickness: 2px;
}

/* Error state indicators with icons for color-blind users */
.is-invalid {
  border-color: #dc3545 !important;
  padding-right: calc(1.5em + 0.75rem);
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='12' height='12' fill='none' stroke='%23dc3545'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23dc3545' stroke='none'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right calc(0.375em + 0.1875rem) center;
  background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

/* Loading state accessibility */
.btn.loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

.btn.loading::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  top: 50%;
  left: 50%;
  margin-left: -8px;
  margin-top: -8px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spinner-border 0.75s linear infinite;
}

@keyframes spinner-border {
  to { transform: rotate(360deg); }
}

/* Ensure form labels are associated and visible */
label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
}

/* Required field indicator */
label .required,
label .text-danger {
  color: #dc3545;
  font-weight: bold;
}

/* Improve table accessibility on mobile */
@media (max-width: 768px) {
  table {
    font-size: 0.875rem;
  }
  
  th, td {
    padding: 0.5rem !important;
  }
}

/* Focus visible polyfill for better keyboard navigation */
:focus-visible {
  outline: 3px solid #FF6B35;
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}
