/**
 * Accessibility Styles - WCAG 2.1
 * 
 * Stili essenziali per l'accessibilità del sito
 * Compatibile con OneTap Accessibility e altri widget di accessibilità
 *
 * @package igrandiclassici
 * @since 1.0.0
 */

/* ============================================
   Compatibilità Widget Accessibilità
   ============================================ */
/* Questi stili sono progettati per NON interferire con:
   - OneTap Accessibility
   - UserWay
   - AccessiBe
   - Altri widget di accessibilità
   
   IMPORTANTE: Non usare !important su colori, font-size, line-height
   per permettere ai widget di sovrascrivere gli stili.
*/

/* ============================================
   Screen Reader Only
   ============================================ */
.sr-only,
.screen-reader-text {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Screen reader only che diventa visibile al focus (per skip links) */
.sr-only-focusable:focus,
.sr-only-focusable:active,
.screen-reader-text:focus,
.screen-reader-text:active {
  position: static;
  width: auto;
  height: auto;
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* ============================================
   Skip Links
   ============================================ */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: #000;
  color: #fff;
  padding: 8px 16px;
  z-index: 9000; /* Inferiore ai widget di accessibilità (tipicamente 99999+) */
  text-decoration: none;
  font-weight: 600;
  border-radius: 0 0 4px 0;
  transition: top 0.2s ease-in-out;
  opacity: 0;
}

.skip-link:focus {
  top: 0;
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.skip-link:hover {
  background: #333;
}

/* ============================================
   Focus Styles
   ============================================ */
/* Focus visibile per elementi interattivi (WCAG 2.1 SC 2.4.7) 
   NON usa !important per permettere ai widget di personalizzare */
a:focus,
button:focus,
input:focus,
textarea:focus,
select:focus,
[tabindex]:focus,
[role="button"]:focus,
[role="link"]:focus {
  outline: 2px solid #0066cc;
  outline-offset: 2px;
}

/* Focus per altri elementi - solo con tastiera */
*:focus-visible {
  outline: 2px solid #0066cc;
  outline-offset: 2px;
}

/* ============================================
   Form Accessibility
   ============================================ */
/* Campi obbligatori */
.required,
[required],
[aria-required="true"] {
  /* Aggiungi uno stile visivo per i campi obbligatori se necessario */
}

/* Messaggi di errore - Contrasto WCAG AA 4.5:1 */
.error-message,
[role="alert"] {
  color: #c62828; /* Contrasto 5.5:1 con bianco */
  font-size: 0.875rem;
  font-weight: 600; /* Maggiore visibilità */
  margin-top: 4px;
  display: block;
}

.error-message:empty {
  display: none;
}

/* Campo con errore - Contrasto 3:1 per bordi UI */
.form-field.has-error input,
.form-field.has-error textarea,
.form-field.has-error select {
  border: 2px solid #c62828; /* Contrasto 5.5:1, bordo più spesso */
  background-color: #fff5f5;
}

/* Messaggi di successo - Contrasto WCAG AA 4.5:1 */
.success-message {
  color: #1b5e20; /* Contrasto 7.4:1 con bianco */
  font-size: 0.875rem;
  font-weight: 600; /* Maggiore visibilità */
  margin-top: 4px;
  display: block;
}

/* Form notice */
.form-notice {
  background: #e3f2fd;
  padding: 12px;
  border-left: 4px solid #1976d2;
  margin-bottom: 20px;
}

/* ============================================
   Hidden Elements
   ============================================ */
/* Attributo HTML5 hidden - nasconde completamente l'elemento */
[hidden] {
  display: none !important;
}

/* aria-hidden="true" nasconde SOLO dagli screen reader, 
   ma l'elemento rimane visibile sullo schermo.
   NON aggiungere display: none perché vanificherebbe lo scopo.
   Usalo per icone decorative, contenuti duplicati, etc. */

/* ============================================
   ARIA Live Regions
   ============================================ */
[aria-live],
[role="status"],
[role="alert"] {
  /* Assicurati che le live regions abbiano spazio sufficiente */
  min-height: 1px;
}

/* ============================================
   High Contrast Mode Support
   ============================================ */
/* Supporto per modalità alto contrasto del sistema operativo
   Non interferisce con widget che applicano il loro alto contrasto */
@media (prefers-contrast: high) {
  *:focus {
    outline-width: 3px;
    outline-offset: 3px;
  }

  .skip-link:focus {
    outline-width: 3px;
  }
}

/* ============================================
   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;
  }

  /* Disabilita completamente animazioni critiche */
  [aria-busy="true"]::after {
    animation: none !important;
  }
}

/* ============================================
   Keyboard Navigation
   ============================================ */
/* Usa :focus-visible per mostrare focus solo con tastiera (supporto nativo browser)
   IMPORTANTE: Il focus è SEMPRE garantito, ma visibile solo quando appropriato.
   Non rimuovere mai outline senza alternativa (WCAG 2.1 SC 2.4.7) 
   
   Compatibilità widget: questi stili NON usano !important per permettere
   ai widget di accessibilità di personalizzare il focus */

/* Focus visibile con mouse click (browser moderni) */
*:focus:not(:focus-visible) {
  outline: none;
}

/* Focus sempre visibile con tastiera */
*:focus-visible {
  outline: 2px solid #0066cc;
  outline-offset: 2px;
}

/* ============================================
   Menu Toggle Accessibility
   ============================================ */
.menu-toggle[aria-expanded="true"] .icon-open {
  display: none;
}

.menu-toggle[aria-expanded="false"] .icon-close {
  display: none;
}

/* ============================================
   Tab Navigation
   ============================================ */
[role="tablist"] {
  display: flex;
  gap: 4px;
}

[role="tab"] {
  cursor: pointer;
  padding: 8px 16px;
  border: 2px solid #767676; /* Contrasto 3:1 per UI components */
  background: #f5f5f5;
  border-radius: 4px 4px 0 0;
}

[role="tab"][aria-selected="true"] {
  background: #fff;
  border-bottom-color: #fff;
  font-weight: 600;
}

[role="tab"]:focus {
  outline: 2px solid #0066cc;
  outline-offset: 2px;
  z-index: 1;
}

[role="tabpanel"] {
  padding: 20px;
  border: 2px solid #767676; /* Contrasto 3:1 per UI components */
  border-radius: 0 4px 4px 4px;
}

[role="tabpanel"][hidden] {
  display: none;
}

/* ============================================
   Breadcrumb Accessibility
   ============================================ */
.breadcrumb {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.breadcrumb li {
  display: inline-flex;
  align-items: center;
}

.breadcrumb li:not(:last-child)::after {
  content: "/";
  margin-left: 8px;
  color: #666;
}

.breadcrumb [aria-current="page"] {
  color: #333;
  font-weight: 600;
}

/* ============================================
   Pagination Accessibility
   ============================================ */
.pagination {
  display: flex;
  justify-content: center;
  gap: 8px;
  list-style: none;
  padding: 0;
}

.pagination a,
.pagination span {
  display: inline-block;
  padding: 8px 12px;
  border: 2px solid #767676; /* Contrasto 3:1 per UI components */
  border-radius: 4px;
  text-decoration: none;
  color: #212121; /* Contrasto testo */
}

.pagination .current {
  background: #0066cc;
  color: #fff;
  border-color: #0066cc;
  font-weight: 600;
}

.pagination a:hover,
.pagination a:focus {
  background: #e3f2fd;
  border-color: #0066cc;
}

/* ============================================
   Modal/Dialog Accessibility
   ============================================ */
[role="dialog"],
.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  z-index: 9999;
  max-width: 90vw;
  max-height: 90vh;
  overflow: auto;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 9998;
}

/* ============================================
   Tooltip Accessibility
   ============================================ */
[role="tooltip"] {
  position: absolute;
  background: #333;
  color: #fff;
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 0.875rem;
  z-index: 1000;
  max-width: 250px;
}

/* ============================================
   Loading States
   ============================================ */
[aria-busy="true"] {
  position: relative;
  pointer-events: none;
  opacity: 0.6;
}

[aria-busy="true"]::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  border: 4px solid #f3f3f3;
  border-top-color: #0066cc;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
  .skip-link,
  .menu-toggle,
  [aria-hidden="true"] {
    display: none !important;
  }

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

  abbr[title]::after {
    content: " (" attr(title) ")";
  }
}

/* ============================================
   Color Contrast Helpers
   ============================================ */
/* Assicurati che questi colori abbiano un contrasto sufficiente (WCAG AA: 4.5:1 per testo normale)
   NON usa !important per permettere ai widget di modificare i colori */
.text-on-light {
  color: #212121; /* Contrasto con bianco: 16.1:1 */
}

.text-on-dark {
  color: #ffffff; /* Contrasto con nero: 21:1 */
}

.link-color {
  color: #0066cc; /* Contrasto con bianco: 6.3:1 */
}

.link-color:hover,
.link-color:focus {
  color: #004499; /* Contrasto aumentato al focus */
}

/* ============================================
   Language Specific Helpers
   ============================================ */
[lang="it"] {
  /* Stili specifici per italiano se necessari */
}

[lang="en"] {
  /* Stili specifici per inglese se necessari */
}
