/*
 * SPDX-FileCopyrightText: 2025 OPTIMETA and KOMET projects <https://projects.tib.eu/komet>
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

/*
 * Accessibility Enhancements for OPTIMAP
 * Implements WCAG 2.1 AA compliance features
 * - High contrast theme
 * - Focus indicators
 * - Screen reader utilities
 */

/* ==========================================================================
   Screen Reader Only Utility 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;
}

.sr-only-focusable:active,
.sr-only-focusable:focus {
  position: static;
  width: auto;
  height: auto;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* ==========================================================================
   Focus Indicators (WCAG 2.4.7)
   High contrast, visible focus indicators for all interactive elements
   Only shown when high contrast mode is enabled
   ========================================================================== */

/* Focus indicators only in high contrast mode */
body.high-contrast *:focus {
  outline: 3px solid #FF6B35 !important;
  outline-offset: 2px;
}

body.high-contrast a:focus,
body.high-contrast button:focus,
body.high-contrast input:focus,
body.high-contrast select:focus,
body.high-contrast textarea:focus,
body.high-contrast [tabindex]:focus {
  outline: 3px solid #FF6B35 !important;
  outline-offset: 2px;
}

/* Focus indicators for dark backgrounds (navbar, footer) in high contrast mode */
body.high-contrast .navbar *:focus,
body.high-contrast .footer *:focus,
body.high-contrast .bg-primary *:focus {
  outline: 3px solid #FFD700 !important; /* Gold for better visibility on dark */
  outline-offset: 2px;
}

/* Focus for Bootstrap buttons in high contrast mode */
body.high-contrast .btn:focus,
body.high-contrast .btn:active:focus {
  outline: 3px solid #FF6B35 !important;
  outline-offset: 2px;
  box-shadow: 0 0 0 0.2rem rgba(255, 107, 53, 0.25) !important;
}

body.high-contrast .btn-primary:focus,
body.high-contrast .btn-primary:active:focus {
  box-shadow: 0 0 0 0.2rem rgba(21, 143, 155, 0.5) !important;
}

/* Focus for dropdown items in high contrast mode */
body.high-contrast .dropdown-item:focus {
  outline: 2px solid #FF6B35 !important;
  outline-offset: -2px;
  background-color: #f8f9fa;
}

/* Focus for form controls in high contrast mode */
body.high-contrast .form-control:focus {
  border-color: #FF6B35;
  box-shadow: 0 0 0 0.2rem rgba(255, 107, 53, 0.25);
  outline: 2px solid #FF6B35;
}

/* ==========================================================================
   Skip Link (WCAG 2.4.1)
   ========================================================================== */

.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: #000;
  color: #fff;
  padding: 8px 12px;
  z-index: 10000;
  text-decoration: none;
  font-weight: bold;
}

.skip-link:focus {
  top: 0;
}

body.high-contrast .skip-link:focus {
  outline: 3px solid #FFD700;
  outline-offset: 0;
}

/* ==========================================================================
   High Contrast Theme
   Activated via JavaScript toggle, saved in localStorage
   ========================================================================== */

body.high-contrast {
  /* Enhanced contrast colors */
  background-color: #000000 !important;
  color: #FFFFFF !important;
}

body.high-contrast .navbar {
  background-color: #000000 !important;
  border-bottom: 3px solid #FFFFFF;
}

body.high-contrast .footer-copyright {
  background-color: #000000 !important;
  border-top: 3px solid #FFFFFF;
}

body.high-contrast .bg-primary {
  background-color: #000000 !important;
  color: #FFFF00 !important; /* Yellow for maximum contrast */
}

body.high-contrast a {
  color: #00FFFF !important; /* Cyan for links */
  text-decoration: underline;
  font-weight: bold;
}

body.high-contrast a:hover,
body.high-contrast a:focus {
  color: #FFFF00 !important; /* Yellow on hover */
  text-decoration: underline;
  background-color: #000080; /* Dark blue background */
}

body.high-contrast .btn-primary {
  background-color: #FFFF00 !important;
  color: #000000 !important;
  border: 3px solid #FFFFFF !important;
  font-weight: bold;
}

body.high-contrast .btn-primary:hover,
body.high-contrast .btn-primary:focus {
  background-color: #FFFFFF !important;
  color: #000000 !important;
  border: 3px solid #FFFF00 !important;
}

body.high-contrast .btn-secondary {
  background-color: #808080 !important;
  color: #FFFFFF !important;
  border: 3px solid #FFFFFF !important;
}

body.high-contrast .btn-danger {
  background-color: #FF0000 !important;
  color: #FFFFFF !important;
  border: 3px solid #FFFFFF !important;
}

body.high-contrast .card {
  background-color: #1A1A1A !important;
  border: 2px solid #FFFFFF !important;
  color: #FFFFFF !important;
}

body.high-contrast .card-header {
  background-color: #000000 !important;
  border-bottom: 2px solid #FFFFFF !important;
  color: #FFFF00 !important;
}

body.high-contrast .alert {
  border: 3px solid #FFFFFF !important;
  font-weight: bold;
}

body.high-contrast .alert-primary {
  background-color: #000080 !important;
  color: #FFFF00 !important;
}

body.high-contrast .alert-success {
  background-color: #006400 !important;
  color: #00FF00 !important;
}

body.high-contrast .alert-danger {
  background-color: #8B0000 !important;
  color: #FF6347 !important;
}

body.high-contrast .form-control {
  background-color: #FFFFFF !important;
  color: #000000 !important;
  border: 2px solid #000000 !important;
}

body.high-contrast .form-control:focus {
  outline: 3px solid #FFFF00 !important;
  border-color: #FFFF00 !important;
}

body.high-contrast .dropdown-menu {
  background-color: #1A1A1A !important;
  border: 2px solid #FFFFFF !important;
}

body.high-contrast .dropdown-item {
  color: #FFFFFF !important;
}

body.high-contrast .dropdown-item:hover,
body.high-contrast .dropdown-item:focus {
  background-color: #000080 !important;
  color: #FFFF00 !important;
}

body.high-contrast .dropdown-divider {
  border-top: 2px solid #FFFFFF !important;
}

/* High contrast for map elements */
body.high-contrast #map {
  border: 3px solid #FFFFFF !important;
}

body.high-contrast .leaflet-popup-content-wrapper {
  background-color: #1A1A1A !important;
  color: #FFFFFF !important;
  border: 3px solid #FFFFFF !important;
}

body.high-contrast .leaflet-popup-content-wrapper a {
  color: #00FFFF !important;
}

body.high-contrast .leaflet-popup-tip {
  background-color: #1A1A1A !important;
  border: 2px solid #FFFFFF !important;
}

/* High contrast focus indicators for Leaflet map controls */
body.high-contrast .leaflet-bar a:focus,
body.high-contrast .leaflet-control a:focus,
body.high-contrast .leaflet-control button:focus {
  outline: 3px solid #FFD700 !important;
  outline-offset: 2px;
}

body.high-contrast .leaflet-container a.leaflet-popup-close-button:focus {
  outline: 3px solid #FFD700 !important;
  outline-offset: 2px;
}

body.high-contrast .leaflet-control-attribution a:focus {
  outline: 3px solid #FFD700 !important;
  outline-offset: 2px;
}

/* High contrast for tables */
body.high-contrast table {
  border: 2px solid #FFFFFF !important;
}

body.high-contrast th {
  background-color: #000000 !important;
  color: #FFFF00 !important;
  border: 2px solid #FFFFFF !important;
}

body.high-contrast td {
  border: 1px solid #FFFFFF !important;
}

/* ==========================================================================
   Accessibility Toggle Button
   ========================================================================== */

#accessibility-toggle {
  position: fixed;
  bottom: 15px;
  right: 15px;
  z-index: 9999;
  background-color: #158F9B;
  color: #FFFFFF;
  border: 2px solid #FFFFFF;
  border-radius: 50%;
  width: 42px;
  height: 42px;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

#accessibility-toggle:hover {
  background-color: #0A6870;
  transform: scale(1.05);
}

body.high-contrast #accessibility-toggle:focus {
  outline: 3px solid #FFD700;
  outline-offset: 3px;
}

body.high-contrast #accessibility-toggle {
  background-color: #FFFF00;
  color: #000000;
  border: 3px solid #FFFFFF;
}

body.high-contrast #accessibility-toggle:hover {
  background-color: #FFFFFF;
  color: #000000;
}

/* Tooltip for accessibility toggle */
#accessibility-toggle[data-tooltip]:before {
  content: attr(data-tooltip);
  position: absolute;
  right: 100%;
  margin-right: 10px;
  padding: 8px 12px;
  background-color: #000;
  color: #fff;
  white-space: nowrap;
  border-radius: 4px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

#accessibility-toggle:hover[data-tooltip]:before,
#accessibility-toggle:focus[data-tooltip]:before {
  opacity: 1;
}

/* ==========================================================================
   ARIA Live Regions
   ========================================================================== */

#announcer,
#map-announcer {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ==========================================================================
   Improved Link Visibility
   ========================================================================== */

/* External link indicators should be more visible.
   Skip links that already render their own external-link icon (templates and
   JS-built popups frequently include an explicit <i class="fa-external-link-alt">),
   otherwise we'd stack two icons on the same link. */
a[target="_blank"]:not(:has(.fa-external-link-alt))::after,
a[rel*="external"]:not(:has(.fa-external-link-alt))::after {
  content: " \f08e"; /* FontAwesome 6 arrow-up-right-from-square icon */
  font-family: "Font Awesome 6 Free";
  font-weight: 900;
  font-size: 0.8em;
  margin-left: 0.2em;
  opacity: 0.7;
}

/* High contrast external link indicators */
body.high-contrast a[target="_blank"]:not(:has(.fa-external-link-alt))::after,
body.high-contrast a[rel*="external"]:not(:has(.fa-external-link-alt))::after {
  opacity: 1;
  color: inherit;
}

/* ==========================================================================
   Improved Button States
   ========================================================================== */

/* Make disabled state more obvious */
button:disabled,
.btn:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  outline: 2px dashed #999;
}

body.high-contrast button:disabled,
body.high-contrast .btn:disabled,
body.high-contrast input:disabled {
  background-color: #4D4D4D !important;
  color: #999999 !important;
  border: 2px dashed #FFFFFF !important;
}

/* ==========================================================================
   Reduced Motion (prefers-reduced-motion)
   ========================================================================== */

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

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
  .skip-link,
  #accessibility-toggle,
  .navbar,
  .footer,
  #map-announcer,
  #announcer {
    display: none !important;
  }

  a[href]::after {
    content: " (" attr(href) ")";
  }
}
