/* Focus ring WCAG rinforzato e stabile anche con CSS legacy che azzera outline */
.wcag-mode *:focus,
.wcag-mode *:focus-visible {
  outline: 3px solid #ffbf00 !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 4px rgba(255, 191, 0, 0.35) !important;
  background-clip: padding-box;
}

body.wcag-mode a:focus,
body.wcag-mode a:focus-visible,
body.wcag-mode button:focus,
body.wcag-mode button:focus-visible,
body.wcag-mode input:focus,
body.wcag-mode input:focus-visible,
body.wcag-mode select:focus,
body.wcag-mode select:focus-visible,
body.wcag-mode textarea:focus,
body.wcag-mode textarea:focus-visible,
body.wcag-mode [role="button"]:focus,
body.wcag-mode [role="button"]:focus-visible,
body.wcag-mode [role="checkbox"]:focus,
body.wcag-mode [role="checkbox"]:focus-visible,
body.wcag-mode [tabindex]:focus,
body.wcag-mode [tabindex]:focus-visible {
  outline: 3px solid #ffbf00 !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 4px rgba(255, 191, 0, 0.35) !important;
}

/* Controlli calendario e pulsanti circolari: ring piu leggibile su sfondi grafici */
body.wcag-mode .monthly-prev:focus,
body.wcag-mode .monthly-prev:focus-visible,
body.wcag-mode .monthly-next:focus,
body.wcag-mode .monthly-next:focus-visible,
body.wcag-mode .btn_general_circle:focus,
body.wcag-mode .btn_general_circle:focus-visible {
  outline: 3px solid #ffbf00 !important;
  outline-offset: 3px !important;
  box-shadow: 0 0 0 5px rgba(255, 191, 0, 0.45) !important;
}

/* Il file viene caricato solo in modalità WCAG: possiamo proteggere anche il root */
html,
body.wcag-mode {
  overflow-x: hidden !important;
  overflow-y: auto !important;
  height: auto !important;
}

.wcag-mode #header_content,
.wcag-mode #section_content,
.wcag-mode .headerhome,
.wcag-mode .jumbotron,
.wcag-mode .containercalendar,
.wcag-mode .monthly-day-wrap,
.wcag-mode .monthly-event-list {
  max-width: 100% !important;
}

.wcag-mode .sr-only-wcag {
  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;
  border: 0 !important;
}

.wcag-mode .slot_bar,
.wcag-mode .slot_bar_occupato,
.wcag-mode .slot_bar_prenotazione {
  min-height: 44px;
}

.wcag-mode .slot_bar[role="checkbox"] {
  cursor: pointer;
}

.wcag-mode .slot_bar[aria-checked="true"] {
  box-shadow: 0 0 0 3px #1a73e8 inset;
}

body.wcag-high-contrast .btn-general,
body.wcag-high-contrast .btn.btn-primary,
body.wcag-high-contrast .btnprenota,
body.wcag-high-contrast .slot_bar {
  background: #0b3d91 !important;
  color: #ffffff !important;
  border-color: #0b3d91 !important;
}

body.wcag-high-contrast .slot_bar_occupato,
body.wcag-high-contrast .slot_bar_prenotazione {
  background: #5a5a5a !important;
  color: #ffffff !important;
}

body.wcag-high-contrast a,
body.wcag-high-contrast .powered_link {
  color: #ffffff !important;
  text-decoration: underline !important;
}

body.wcag-high-contrast .inputform::placeholder,
body.wcag-high-contrast input::placeholder {
  color: #2f2f2f !important;
  opacity: 1 !important;
}

/* Toggle UI: "CONTRASTO ELEVATO" (solo frontend) */
.wcag-mode .booking-contrast-toggle{
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 1000000;
  padding: 10px 12px;
  border-radius: 10px;
  border: 2px solid #111827;
  background: #ffffff;
  color: #111827;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.4px;
  cursor: pointer;
}
.wcag-mode .booking-contrast-toggle.is-on{
  background: #111827;
  color: #ffffff;
}
.wcag-mode .booking-contrast-toggle:focus,
.wcag-mode .booking-contrast-toggle:focus-visible{
  outline: 3px solid #ffbf00 !important;
  outline-offset: 2px !important;
}
@media (max-width: 768px) {
  .wcag-mode .booking-contrast-toggle{
    top: auto;
    /* evita overlap con footer fisso mobile */
    bottom: calc(5vh + 8px);
    right: 10px;
    font-size: 13px;
    padding: 10px 10px;
    z-index: 1000002;
  }
}

/* High contrast theme: sovrascrive brand nel frontend pubblico */
body.wcag-high-contrast,
body.wcag-high-contrast #section_content,
body.wcag-high-contrast .container,
body.wcag-high-contrast .card,
body.wcag-high-contrast .card-body,
body.wcag-high-contrast .italydiv,
body.wcag-high-contrast .monthly,
body.wcag-high-contrast .monthly-header,
body.wcag-high-contrast .monthly-day-wrap,
body.wcag-high-contrast .monthly-event-list{
  background: #111111 !important;
  color: #ffffff !important;
}
body.wcag-high-contrast input,
body.wcag-high-contrast textarea,
body.wcag-high-contrast select{
  background: #1b1b1b !important;
  color: #ffffff !important;
  border-color: #ffffff !important;
}
body.wcag-high-contrast input[type="text"],
body.wcag-high-contrast input[type="email"],
body.wcag-high-contrast input[type="tel"],
body.wcag-high-contrast input[type="number"],
body.wcag-high-contrast input[type="date"],
body.wcag-high-contrast input[type="password"],
body.wcag-high-contrast .inputform{
  background: #ffffff !important;
  color: #111111 !important;
  border: 2px solid #111111 !important;
}
body.wcag-high-contrast .inputform::placeholder,
body.wcag-high-contrast input::placeholder{
  color: #4b5563 !important;
  opacity: 1 !important;
}
body.wcag-high-contrast label,
body.wcag-high-contrast .label,
body.wcag-high-contrast .acconsentolabel,
body.wcag-high-contrast .text-muted{
  color: #ffffff !important;
}

/* Form prenotazione: contenitori e micro UI */
body.wcag-high-contrast #contenuto_form,
body.wcag-high-contrast .content_dx,
body.wcag-high-contrast .content_sx{
  background: transparent !important;
  color: #ffffff !important;
}
body.wcag-high-contrast .box_captcha{
  background: #111111 !important;
  border: 1px solid #ffffff !important;
  padding: 8px !important;
  border-radius: 8px !important;
}
body.wcag-high-contrast #captcha_image_reload{
  fill: #ffffff !important;
}

/* CTA prenota */
body.wcag-high-contrast .btnprenota,
body.wcag-high-contrast #btnprenota{
  background: #ffffff !important;
  color: #111111 !important;
  border: 2px solid #111111 !important;
}

/* Slot list e paginazione (calendario old "calendario.php") */
body.wcag-high-contrast .slot_bar,
body.wcag-high-contrast .slot_bar_occupato,
body.wcag-high-contrast .slot_bar_prenotazione{
  border: 1px solid #ffffff !important;
}
body.wcag-high-contrast .list_sedi li span,
body.wcag-high-contrast .btn-info,
body.wcag-high-contrast .btn.btn-secondary,
body.wcag-high-contrast .btn.btn-primary{
  background: #2b2b2b !important;
  color: #ffffff !important;
  border-color: #ffffff !important;
}
body.wcag-high-contrast .powered_link,
body.wcag-high-contrast a{
  color: #ffffff !important;
  text-decoration: underline !important;
}

/* Header/Footer: evita barre brand blu in high contrast */
body.wcag-high-contrast #header_content,
body.wcag-high-contrast #footer_content,
body.wcag-high-contrast .cookie-bar,
body.wcag-high-contrast .cookie-bar-button{
  background: #111111 !important;
  color: #ffffff !important;
}
body.wcag-high-contrast #footer_content{
  border-top: 1px solid #ffffff !important;
}

/* Modali (index servizi + popup) */
body.wcag-high-contrast .modal-content,
body.wcag-high-contrast .modal-header,
body.wcag-high-contrast .modal-body,
body.wcag-high-contrast .modal-footer,
body.wcag-high-contrast .shadow{
  background: #111111 !important;
  color: #ffffff !important;
  border-color: #ffffff !important;
}
body.wcag-high-contrast .modal-title{
  color: #ffffff !important;
}
body.wcag-high-contrast .modal-backdrop.in,
body.wcag-high-contrast .modal-backdrop{
  opacity: 0.85 !important;
}
body.wcag-high-contrast .btn.btn-danger,
body.wcag-high-contrast .btn.btn-default,
body.wcag-high-contrast .btn.btn-secondary{
  background: #2b2b2b !important;
  color: #ffffff !important;
  border-color: #ffffff !important;
}

/* Calendario (monthly) in high contrast: griglie leggibili */
body.wcag-high-contrast .monthly-header,
body.wcag-high-contrast .monthly-header-title,
body.wcag-high-contrast .monthly-header-title-date{
  background: #111111 !important;
  color: #ffffff !important;
}
body.wcag-high-contrast .monthly-prev,
body.wcag-high-contrast .monthly-next{
  background: #2b2b2b !important;
  color: #ffffff !important;
  border-color: #ffffff !important;
}

/* Calendario: neutralizza azzurri inline (bg2/coltxt1) */
body.wcag-high-contrast a.monthly-prev.prev,
body.wcag-high-contrast a.monthly-next.next,
body.wcag-high-contrast .btn_general_circle,
body.wcag-high-contrast .btn-general,
body.wcag-high-contrast .disponibleslot{
  background-color: #2b2b2b !important;
  background: #2b2b2b !important;
  color: #ffffff !important;
  border-color: #ffffff !important;
}
body.wcag-high-contrast a.monthly-cal{
  background: #2b2b2b !important;
  color: #ffffff !important;
  border: 1px solid #ffffff !important;
}
body.wcag-high-contrast a.monthly-prev.prev:hover,
body.wcag-high-contrast a.monthly-next.next:hover,
body.wcag-high-contrast .btn_general_circle:hover,
body.wcag-high-contrast .btn-general:hover{
  background-color: #000000 !important;
  background: #000000 !important;
  color: #ffffff !important;
}

/* Form prenotazione (calendarform): slot e checkbox custom */
body.wcag-high-contrast .slot_bar{
  background-color: #2b2b2b !important;
  color: #ffffff !important;
}
body.wcag-high-contrast .slot_bar:hover{
  background-color: #000000 !important;
  color: #ffffff !important;
}
body.wcag-high-contrast #selectable .ui-selected{
  background: #000000 !important;
  color: #ffffff !important;
}
body.wcag-high-contrast .checkmark{
  border-color: #111111 !important;
}
body.wcag-high-contrast .container input:checked ~ .checkmark{
  background-color: #111111 !important;
}

/* Header box del form e titolo blu */
body.wcag-high-contrast .header_box,
body.wcag-high-contrast .header_box span,
body.wcag-high-contrast .description,
body.wcag-high-contrast .description *{
  background: #111111 !important;
  color: #ffffff !important;
}
/* Titoli/righe servizio nel calendario: neutralizza eventuali colori brand inline */
body.wcag-high-contrast .monthly-header-title-date,
body.wcag-high-contrast .monthly-header-title-date *,
body.wcag-high-contrast .monthly-header-title-date a,
body.wcag-high-contrast .header_box a,
body.wcag-high-contrast .description a{
  color: #ffffff !important;
}
/* Copre nodi con style inline colorati dal JS legacy */
body.wcag-high-contrast .header_box [style],
body.wcag-high-contrast .description [style],
body.wcag-high-contrast .header_box [style*="color"],
body.wcag-high-contrast .description [style*="color"]{
  color: #ffffff !important;
}
body.wcag-high-contrast .header_box svg,
body.wcag-high-contrast .description svg{
  fill: #ffffff !important;
  stroke: #ffffff !important;
}
/* Form consenso privacy (area chiara): etichette sempre leggibili */
body.wcag-high-contrast .booking-privacy-consent .acconsentolabel,
body.wcag-high-contrast .booking-privacy-consent .acconsentolabel a,
body.wcag-high-contrast .booking-privacy-consent .booking-privacy-consent-action,
body.wcag-high-contrast .booking-privacy-consent .booking-privacy-consent-action .acconsentolabel{
  color: #111111 !important;
  text-decoration: underline !important;
}
/* Fallback hard: in alcune view legacy il wrapper .booking-privacy-consent non c'e */
body.wcag-high-contrast a.booking-privacy-consent-action,
body.wcag-high-contrast a.booking-privacy-consent-action:link,
body.wcag-high-contrast a.booking-privacy-consent-action:visited,
body.wcag-high-contrast a.booking-privacy-consent-action:hover,
body.wcag-high-contrast a.booking-privacy-consent-action:focus,
body.wcag-high-contrast a.booking-privacy-consent-action > .acconsentolabel,
body.wcag-high-contrast a.booking-privacy-consent-action > .acconsentolabel[style],
body.wcag-high-contrast .acconsentolabel[style*="color"]{
  color: #111111 !important;
  text-decoration: underline !important;
}
body.wcag-high-contrast .monthly-day-title-wrap,
body.wcag-high-contrast .monthly-day-title-wrap *{
  background: #111111 !important;
  color: #ffffff !important;
}
body.wcag-high-contrast .monthly-day{
  background: #2b2b2b !important;
  color: #ffffff !important;
  border-color: #ffffff !important;
}
/* Numeri giorni: niente azzurro residuo */
body.wcag-high-contrast .monthly-day .monthly-day-number,
body.wcag-high-contrast .monthly-day .monthly-day-number a,
body.wcag-high-contrast .monthly-day-title-wrap div,
body.wcag-high-contrast .monthly-day-title-wrap a{
  color: #ffffff !important;
}
/* Frecce prev/next day nel titolo mese (SVG con fill inline legacy) */
body.wcag-high-contrast #prevday svg,
body.wcag-high-contrast #nextday svg,
body.wcag-high-contrast #prevday svg *,
body.wcag-high-contrast #nextday svg *{
  fill: #ffffff !important;
  stroke: #ffffff !important;
}
/* Riga "numero posti": niente azzurro, palette HC coerente */
body.wcag-high-contrast .numeroposti{
  background: #111111 !important;
  color: #ffffff !important;
  border: 1px solid #ffffff !important;
}
/* Titolo calendario legacy */
body.wcag-high-contrast h3.title_cal_calendar,
body.wcag-high-contrast .title_cal_calendar{
  color: #ffffff !important;
}
body.wcag-high-contrast .monthly-day-event > .disponibleslot,
body.wcag-high-contrast .monthly-day-event > .disponibleslot:hover{
  background-color: #2b2b2b !important;
  background: #2b2b2b !important;
  border: 1px solid #ffffff !important;
  color: #ffffff !important;
}
body.wcag-high-contrast .monthly-day-event > .disponibleslot img{
  filter: grayscale(1) contrast(2) brightness(2);
}
body.wcag-high-contrast .monthly-day .monthly-event-indicator,
body.wcag-high-contrast .monthly-day .monthly-event-indicator span{
  background-color: #2b2b2b !important;
  background: #2b2b2b !important;
  color: #ffffff !important;
  border-color: #ffffff !important;
}
/* fallback forte: alcuni eventi hanno background inline dal plugin */
body.wcag-high-contrast .monthly-day-event > div:not(.monthly-day-number){
  background-color: #2b2b2b !important;
  background: #2b2b2b !important;
  color: #ffffff !important;
  border-color: #ffffff !important;
}
body.wcag-high-contrast .monthly-day.not_selectable,
body.wcag-high-contrast .monthly-day.monthly-day-past{
  background: #3a3a3a !important;
  color: #d1d5db !important;
}
body.wcag-high-contrast .monthly-day.pick,
body.wcag-high-contrast .monthly-day:hover{
  background: #000000 !important;
  color: #ffffff !important;
  outline: 3px solid #ffbf00 !important;
  outline-offset: -3px !important;
}

/* Index: campo ricerca (evita ripetizione icona lente) */
body.wcag-high-contrast input#pac-input,
body.wcag-high-contrast input#cercasedeservizio,
body.wcag-high-contrast input#cercaservizi{
  background-image: none !important;
  background-repeat: no-repeat !important;
  padding-left: 12px !important;
  padding-right: 12px !important;
}

/* Modale: X chiusura ben visibile */
body.wcag-high-contrast .modal-header .close,
body.wcag-high-contrast button.close{
  color: #ffffff !important;
  opacity: 1 !important;
  text-shadow: none !important;
  font-size: 30px !important;
}
body.wcag-high-contrast .modal-header .close:hover,
body.wcag-high-contrast .modal-header .close:focus{
  color: #ffbf00 !important;
}

/* Slot list pager (calendarform) e frecce */
body.wcag-high-contrast #arrowL,
body.wcag-high-contrast #arrowR{
  background: #2b2b2b !important;
  border: 1px solid #ffffff !important;
  fill: #ffffff !important;
}
body.wcag-high-contrast li.page,
body.wcag-high-contrast li.pageNumbers,
body.wcag-high-contrast li.pageNumbers a{
  background: #2b2b2b !important;
  color: #ffffff !important;
  border-color: #ffffff !important;
}

/* SweetAlert2 (notifiche errori) */
body.wcag-high-contrast .swal2-popup{
  background: #111111 !important;
  color: #ffffff !important;
  border: 2px solid #ffffff !important;
}
body.wcag-high-contrast .swal2-title,
body.wcag-high-contrast .swal2-html-container{
  color: #ffffff !important;
}
body.wcag-high-contrast .swal2-confirm,
body.wcag-high-contrast .swal2-cancel{
  background: #ffffff !important;
  color: #111111 !important;
  border: 2px solid #111111 !important;
}

/* Home button: forza icona visibile anche con CSS legacy */
body.wcag-high-contrast a.btn_general_circle{
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Cpath fill='%23ffffff' d='M8 30L32 10l24 20v24a2 2 0 0 1-2 2H40V40H24v16H10a2 2 0 0 1-2-2V30z'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: center center !important;
  background-size: 28px 28px !important;
}

@media (max-width: 768px) {
  .wcag-mode .container,
  .wcag-mode .row,
  .wcag-mode .content_sx,
  .wcag-mode .content_dx,
  .wcag-mode .monthly,
  .wcag-mode .monthly-event-list,
  .wcag-mode .containercalendar {
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }

  .wcag-mode #section_content .container,
  .wcag-mode #section_content .row {
    padding-left: 0 !important;
    padding-right: 0 !important;
  }

  .wcag-mode .headerhome .container,
  .wcag-mode .monthly-header,
  .wcag-mode .monthly-day-wrap {
    left: 0 !important;
    right: 0 !important;
  }

  /* Neutralizza offset negativi legacy che causano overflow orizzontale */
  .wcag-mode .monthly-cal::before {
    right: 0 !important;
    margin-right: 0 !important;
  }

  .wcag-mode .monthly-header-title a:last-of-type {
    box-sizing: border-box !important;
    width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }

  .wcag-mode .logomobile,
  .wcag-mode .logomobirow {
    max-width: 90% !important;
    width: auto !important;
    height: auto !important;
    margin: 0 auto !important;
    display: block !important;
  }

  .wcag-mode #place-list,
  .wcag-mode .index-list-scroll {
    width: 100% !important;
    max-width: 100% !important;
  }

  /* Mobile (WCAG on): monthly-cal sempre a sinistra, per non essere coperto dal toggle */
  .wcag-mode a.monthly-cal{
    display: block !important;
    position: fixed !important;
    left: 10px !important;
    top: auto !important;
    right: auto !important;
    bottom: calc(5vh + 8px) !important;
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    border-radius: 999px !important;
    z-index: 1000002 !important;
    text-decoration: none !important;
  }
  .wcag-mode a.monthly-cal::before{
    position: static !important;
    top: auto !important;
    right: auto !important;
    margin: 0 !important;
    width: 100% !important;
    height: 100% !important;
    display: block !important;
    background-position: center center !important;
    background-size: 26px 26px !important;
  }

  /* Mobile HC: ripristina controllo "chiudi" come FAB a sinistra,
     per non sovrapporsi al bottone CONTRASTO ELEVATO (a destra). */
  body.wcag-high-contrast a.monthly-cal{
    display: block !important;
    position: fixed !important;
    left: 10px !important;
    top: auto !important;
    right: auto !important;
    bottom: calc(5vh + 8px) !important;
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    border-radius: 999px !important;
    background: #111111 !important;
    border: 2px solid #ffffff !important;
    z-index: 1000002 !important;
    text-decoration: none !important;
  }
  body.wcag-high-contrast a.monthly-cal::before{
    content: "\00d7" !important;
    background: none !important;
    position: static !important;
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    color: #ffffff !important;
    font-size: 30px !important;
    line-height: 1 !important;
    font-weight: 700 !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .wcag-mode * {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
