/* ============================================
   ACCESSIBILITY WIDGET - WIDGET STESSO
   ============================================ */

#aw-widget,
#aw-widget * {
    box-sizing: border-box;
}

#aw-widget {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2147483647; /* massimo possibile, sempre sopra */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    color: #222;
    direction: ltr;
}

/* Pulsante toggle - ancorato a destra, a metà schermo */
#aw-widget .aw-toggle {
    position: relative;
    width: 56px;
    height: 56px;
    border-radius: 8px 0 0 8px;
    background: #0066cc;
    color: #ffffff;
    border: none;
    cursor: pointer;
    box-shadow: -2px 2px 12px rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin: 0;
    transition: background 0.2s ease, width 0.2s ease;
    font-family: inherit;
    appearance: none;
    -webkit-appearance: none;
    line-height: 1;
}

#aw-widget .aw-toggle:hover,
#aw-widget .aw-toggle:focus {
    background: #004c99;
    width: 64px;
    outline: 3px solid #ffcc00;
    outline-offset: -3px;
}

#aw-widget .aw-toggle svg {
    display: block;
    pointer-events: none;
}

/* Pannello opzioni */
#aw-widget .aw-panel {
    position: absolute;
    right: 64px;
    top: 50%;
    transform: translateY(-50%) translateX(20px);
    width: 300px;
    max-width: calc(100vw - 80px);
    max-height: 80vh;
    overflow-y: auto;
    background: #ffffff;
    color: #222222;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s;
    margin: 0;
    padding: 0;
}

#aw-widget .aw-panel.aw-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(-50%) translateX(0);
}

#aw-widget .aw-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid #e5e5e5;
    background: #0066cc;
    color: #ffffff;
    border-radius: 12px 12px 0 0;
}

#aw-widget .aw-panel-header h2 {
    margin: 0;
    padding: 0;
    font-size: 17px;
    font-weight: 600;
    color: #ffffff;
    font-family: inherit;
    line-height: 1.2;
}

#aw-widget .aw-close {
    background: transparent;
    border: none;
    color: #ffffff;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    margin: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
    appearance: none;
    -webkit-appearance: none;
}

#aw-widget .aw-close:hover,
#aw-widget .aw-close:focus {
    background: rgba(255, 255, 255, 0.25);
    outline: 2px solid #ffcc00;
}

#aw-widget .aw-panel-body {
    padding: 12px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 0;
}

#aw-widget .aw-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 6px;
    background: #f5f5f5;
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
    color: #222222;
    font-size: 12px;
    text-align: center;
    min-height: 78px;
    font-family: inherit;
    line-height: 1.2;
    appearance: none;
    -webkit-appearance: none;
    width: 100%;
}

#aw-widget .aw-option:hover {
    background: #e8f0fa;
    border-color: #0066cc;
}

#aw-widget .aw-option:focus {
    outline: 3px solid #ffcc00;
    outline-offset: 1px;
}

#aw-widget .aw-option.aw-active {
    background: #0066cc;
    color: #ffffff;
    border-color: #004c99;
}

#aw-widget .aw-icon {
    font-size: 20px;
    font-weight: bold;
    line-height: 1;
    display: block;
}

#aw-widget .aw-label {
    font-size: 12px;
    line-height: 1.2;
    display: block;
}

#aw-widget .aw-panel-footer {
    padding: 12px 14px 14px;
    border-top: 1px solid #e5e5e5;
}

#aw-widget .aw-reset {
    width: 100%;
    padding: 10px;
    background: #d9534f;
    color: #ffffff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    appearance: none;
    -webkit-appearance: none;
    transition: background 0.2s ease;
    line-height: 1.2;
    margin: 0;
}

#aw-widget .aw-reset:hover,
#aw-widget .aw-reset:focus {
    background: #c9302c;
    outline: 2px solid #ffcc00;
}

/* ============================================
   EFFETTI ACCESSIBILITÀ
   APPLICATI AL ROOT (<html>) PER NON ROMPERE LAYOUT
   Solo proprietà di colore/testo, MAI layout
   ============================================ */

/* SCALA DI GRIGI - filter, non rompe nulla */
html.aw-grayscale {
    filter: grayscale(100%);
    -webkit-filter: grayscale(100%);
}

/* CONTRASTO NEGATIVO - filter, ripristina immagini */
html.aw-negative-contrast {
    filter: invert(100%) hue-rotate(180deg);
    -webkit-filter: invert(100%) hue-rotate(180deg);
    background: #fff;
}
html.aw-negative-contrast img,
html.aw-negative-contrast video,
html.aw-negative-contrast picture,
html.aw-negative-contrast iframe {
    filter: invert(100%) hue-rotate(180deg);
    -webkit-filter: invert(100%) hue-rotate(180deg);
}

/* ALTO CONTRASTO - solo colori, mai layout */
html.aw-high-contrast body,
html.aw-high-contrast body p,
html.aw-high-contrast body h1,
html.aw-high-contrast body h2,
html.aw-high-contrast body h3,
html.aw-high-contrast body h4,
html.aw-high-contrast body h5,
html.aw-high-contrast body h6,
html.aw-high-contrast body span,
html.aw-high-contrast body li,
html.aw-high-contrast body td,
html.aw-high-contrast body th,
html.aw-high-contrast body div,
html.aw-high-contrast body section,
html.aw-high-contrast body article,
html.aw-high-contrast body header,
html.aw-high-contrast body footer,
html.aw-high-contrast body main,
html.aw-high-contrast body nav,
html.aw-high-contrast body aside,
html.aw-high-contrast body label,
html.aw-high-contrast body figcaption {
    background-color: #000000 !important;
    color: #ffff00 !important;
}

html.aw-high-contrast body {
    background-color: #000000 !important;
}

html.aw-high-contrast body a,
html.aw-high-contrast body a * {
    color: #00ffff !important;
}

html.aw-high-contrast body button:not(.aw-option):not(.aw-close):not(.aw-reset):not(.aw-toggle),
html.aw-high-contrast body input,
html.aw-high-contrast body select,
html.aw-high-contrast body textarea {
    background-color: #000000 !important;
    color: #ffff00 !important;
    border-color: #ffff00 !important;
}

/* SOTTOLINEA LINK - solo decorazione, non layout */
html.aw-links-underline body a {
    text-decoration: underline !important;
    text-underline-offset: 2px !important;
}

/* FONT LEGGIBILE - solo testo, mai box */
html.aw-readable-font body,
html.aw-readable-font body p,
html.aw-readable-font body h1,
html.aw-readable-font body h2,
html.aw-readable-font body h3,
html.aw-readable-font body h4,
html.aw-readable-font body h5,
html.aw-readable-font body h6,
html.aw-readable-font body span,
html.aw-readable-font body li,
html.aw-readable-font body td,
html.aw-readable-font body th,
html.aw-readable-font body a,
html.aw-readable-font body button,
html.aw-readable-font body input,
html.aw-readable-font body label,
html.aw-readable-font body textarea {
    font-family: Verdana, Geneva, Tahoma, sans-serif !important;
    letter-spacing: 0.02em !important;
}

/* CURSORE GRANDE */
html.aw-big-cursor,
html.aw-big-cursor * {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' stroke='%23fff' stroke-width='1.5' d='M3 2l6 18 3-7 7-3z'/%3E%3C/svg%3E"), auto !important;
}

/* IL WIDGET STESSO non deve essere mai colpito dagli effetti */
html.aw-high-contrast #aw-widget,
html.aw-high-contrast #aw-widget *,
html.aw-readable-font #aw-widget,
html.aw-readable-font #aw-widget * {
    background-color: revert !important;
    color: revert !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif !important;
}

html.aw-high-contrast #aw-widget .aw-toggle,
html.aw-high-contrast #aw-widget .aw-panel-header {
    background-color: #0066cc !important;
    color: #ffffff !important;
}

html.aw-high-contrast #aw-widget .aw-panel,
html.aw-high-contrast #aw-widget .aw-panel-body,
html.aw-high-contrast #aw-widget .aw-panel-footer {
    background-color: #ffffff !important;
    color: #222222 !important;
}

html.aw-high-contrast #aw-widget .aw-option {
    background-color: #f5f5f5 !important;
    color: #222222 !important;
}

html.aw-high-contrast #aw-widget .aw-option.aw-active {
    background-color: #0066cc !important;
    color: #ffffff !important;
}

html.aw-high-contrast #aw-widget .aw-reset {
    background-color: #d9534f !important;
    color: #ffffff !important;
}

html.aw-high-contrast #aw-widget .aw-panel-title,
html.aw-high-contrast #aw-widget h2 {
    color: #ffffff !important;
    background-color: transparent !important;
}

/* Il contrasto negativo inverte tutto: contro-inverto il widget */
html.aw-negative-contrast #aw-widget {
    filter: invert(100%) hue-rotate(180deg);
    -webkit-filter: invert(100%) hue-rotate(180deg);
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 600px) {
    #aw-widget .aw-toggle {
        width: 48px;
        height: 48px;
    }
    #aw-widget .aw-panel {
        right: 56px;
        width: 280px;
    }
}

@media (max-width: 380px) {
    #aw-widget .aw-panel {
        position: fixed;
        right: 8px;
        left: 8px;
        top: auto;
        bottom: 8px;
        transform: none;
        width: auto;
        max-width: none;
    }
    #aw-widget .aw-panel.aw-open {
        transform: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    #aw-widget .aw-toggle,
    #aw-widget .aw-panel,
    #aw-widget .aw-option,
    #aw-widget .aw-reset {
        transition: none;
    }
}

/* Stampa: nascondi widget */
@media print {
    #aw-widget {
        display: none !important;
    }
}
