/* -------------------------------------------------------------------------- */
/* Stili Base per il Menu di Accessibilità WP (Versione 3.5 - Definitiva)     */
/* -------------------------------------------------------------------------- */

:root {
    --wpam-primary-color: #0073e6;
    --wpam-secondary-color: #1d2327;
    --wpam-background-color: #ffffff;
    --wpam-text-color-panel: #3c434a;
    --wpam-border-color: #e2e8f0;
    --wpam-panel-shadow: 0 10px 30px rgba(0, 0, 0, 0.07);
    --wpam-button-hover-bg: #0062cc;
    --wpam-focus-outline-color: var(--wpam-primary-color);
    --wpam-focus-ring-color: rgba(0, 115, 230, 0.3);
    --wpam-panel-width: 400px;
    --wpam-icon-color: var(--wpam-primary-color);
    --wpam-border-radius: 12px;
    --wpam-transition-duration: 0.25s;
    --wpam-transition-timing: cubic-bezier(0.4, 0, 0.2, 1);
    --wpam-panel-fixed-font-size: 14px;

    /* Cursori */
    --wpam-large-arrow-cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 24 24"><path fill="black" stroke="white" stroke-width="0.75" d="M5.5,22.5 L12,3.5 L18.5,22.5 L12,18.5 z"/></svg>') 4 0, auto;
    --wpam-large-arrow-cursor-fallback: default;
    --wpam-hc-large-arrow-cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 24 24"><path fill="yellow" stroke="black" stroke-width="0.75" d="M5.5,22.5 L12,3.5 L18.5,22.5 L12,18.5 z"/></svg>') 4 0, auto;
    --wpam-dark-large-arrow-cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 24 24"><path fill="white" stroke="black" stroke-width="0.75" d="M5.5,22.5 L12,3.5 L18.5,22.5 L12,18.5 z"/></svg>') 4 0, auto;

    /* Variabili per la pagina */
    --wpam-hc-bg: #000; --wpam-hc-text: #fff; --wpam-hc-link: #ffea00;
    --wpam-dark-bg: #1a1a1a; --wpam-dark-text: #f0f0f0; --wpam-dark-icon-color-page: #90caf9;
}

/* --- SEZIONE DI ISOLAMENTO E RESET --- */

#wp-accessibility-menu-wrapper {
    z-index: 99998 !important;
    position: relative !important;
    pointer-events: none !important;
}

#wpam-panel, #wpam-panel *, #wpam-panel ::before, #wpam-panel ::after {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
    box-sizing: border-box !important;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    text-shadow: none;
    box-shadow: none;
    line-height: 1.5;
    font-size: 100%;
    font-style: normal;
    font-weight: normal;
    color: inherit;
    vertical-align: baseline;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- STILI DEL PANNELLO --- */

#wpam-panel {
    display: flex;
    flex-direction: column;
    position: fixed;
    z-index: 100000;
    bottom: 85px;
    left: 25px;
    width: var(--wpam-panel-width);
    max-height: calc(100vh - 120px);
    background-color: var(--wpam-background-color);
    color: var(--wpam-text-color-panel);
    border: 1px solid var(--wpam-border-color);
    box-shadow: var(--wpam-panel-shadow);
    border-radius: var(--wpam-border-radius);
    font-size: var(--wpam-panel-fixed-font-size);
    transition: opacity var(--wpam-transition-duration) var(--wpam-transition-timing),
                transform var(--wpam-transition-duration) var(--wpam-transition-timing);
    opacity: 0;
    transform: translateY(10px) scale(0.98);
    transform-origin: bottom left;
    pointer-events: none;
}
#wpam-panel.wpam-panel-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Header */
#wpam-panel .wpam-header {
    display: flex;
    align-items: center;
    padding: 10px 14px; /* Ridotto padding verticale */
    border-bottom: 1px solid var(--wpam-border-color);
    position: relative;
}

/* MODIFICA: Stile per il pulsante Ripristina che funge da titolo */
#wpam-panel .wpam-title-button {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px; /* Leggermente ridotto per coerenza */
    font-weight: bold; /* --- MODIFICA RICHIESTA --- */
    text-transform: uppercase; /* --- MODIFICA RICHIESTA --- */
    color: var(--wpam-secondary-color);
    margin-right: auto; /* Spinge gli altri elementi a destra */
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 6px;
    transition: background-color 0.2s;
}
#wpam-panel .wpam-title-button:hover {
    background-color: #f0f2f5;
}
#wpam-panel .wpam-title-button .wpam-icon {
    width: 16px; /* Adattato alla nuova dimensione font */
    height: 16px;
    color: var(--wpam-secondary-color);
    margin-right: 0;
}
#wpam-panel .wpam-title-button .wpam-icon svg {
    fill: currentColor;
}


#wpam-panel .wpam-language-selector {
    display: flex;
    align-items: center;
    margin-left: 12px;
}
#wpam-panel .wpam-language-selector button {
    font-size: 20px; line-height: 1; margin-left: 5px; cursor: pointer;
    opacity: 0.65; transition: opacity 0.2s, transform 0.2s; padding: 5px; border-radius: 6px;
}
#wpam-panel .wpam-language-selector button:hover,
#wpam-panel .wpam-language-selector button.active { opacity: 1; transform: scale(1.1); }

#wpam-panel .wpam-close-button {
    position: static;
    transform: none;
    margin-left: 8px;
    width: 30px; height: 30px;
    display: flex; align-items: center; justify-content: center;
    font-size: 24px; font-weight: 400; color: #adb5bd;
    cursor: pointer; border-radius: 50%;
    transition: color 0.2s, background-color 0.2s;
}
#wpam-panel .wpam-close-button:hover { color: var(--wpam-primary-color); background-color: #f0f2f5; }

/* Corpo e Griglia Funzionalità */
#wpam-panel .wpam-body { padding: 14px 18px; overflow-y: auto; flex-grow: 1; }
#wpam-panel .wpam-features-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 14px; }
#wpam-panel .wpam-feature-column { display: flex; flex-direction: column; }
#wpam-panel .wpam-feature { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; }
#wpam-panel .wpam-feature-label { display: flex; align-items: center; font-size: 13px; margin-right: 8px; flex-grow: 1; }

/* Icone */
#wpam-panel .wpam-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    color: var(--wpam-icon-color);
    margin-right: 10px;
    flex-shrink: 0;
}
#wpam-panel .wpam-icon svg {
    width: 100%;
    height: 100%;
    fill: currentColor;
}

/* Funzionalità a Larghezza Piena (Dimensione Testo) */
#wpam-panel .wpam-full-width-feature { margin-bottom: 14px; padding-bottom: 14px; border-bottom: 1px solid var(--wpam-border-color); }
#wpam-panel .wpam-text-size-feature-buttons .wpam-feature-label { margin-bottom: 10px; }
#wpam-panel .wpam-text-size-button-controls { display: flex; justify-content: space-between; align-items: center; }
#wpam-panel .wpam-text-size-adj-button {
    display: inline-flex; align-items: center; gap: 6px;
    background-color: #f1f3f5; border: 1px solid #dee2e6;
    padding: 6px 10px; border-radius: 6px;
    font-size: 13px; line-height: 1; cursor: pointer;
    transition: background-color 0.2s;
}
#wpam-panel .wpam-text-size-adj-button:hover { background-color: #e9ecef; }
#wpam-panel .wpam-text-size-adj-button .wpam-icon { width: 18px; height: 18px; margin-right: 0; }
#wpam-panel .wpam-current-text-size-display { font-size: 12px; color: #6c757d; padding: 0 10px; }

/* Interruttori Toggle */
#wpam-panel .wpam-toggle-switch {
    position: relative;
    display: inline-block;
    width: 38px; height: 20px;
    border-radius: 20px;
    background-color: #ced4da;
    cursor: pointer;
    transition: background-color 0.25s ease;
    flex-shrink: 0;
}
#wpam-panel .wpam-toggle-switch .wpam-toggle-slider {
    position: absolute;
    height: 16px; width: 16px;
    left: 2px; bottom: 2px;
    background-color: white;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
#wpam-panel .wpam-toggle-switch[aria-checked="true"] { background-color: var(--wpam-primary-color); }
#wpam-panel .wpam-toggle-switch[aria-checked="true"] .wpam-toggle-slider { transform: translateX(18px); }

/* Pulsanti (Leggi) */
#wpam-panel .wpam-tts-button {
    padding: 7px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.4;
    cursor: pointer;
    transition: background-color 0.2s;
    background-color: var(--wpam-primary-color); color: white; min-width: 70px; text-align: center;
}
#wpam-panel .wpam-tts-button:hover { background-color: var(--wpam-button-hover-bg); }


/* Footer */
#wpam-panel .wpam-footer { display: flex; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--wpam-border-color); }
#wpam-panel .wpam-footer-link {
    flex-grow: 1;
    display: flex; align-items: center; justify-content: center;
    gap: 8px; padding: 7px 12px; border-radius: 6px;
    font-size: 12px; line-height: 1.4;
    background-color: #f1f3f5; border: 1px solid #dee2e6;
    text-decoration: none;
    transition: background-color 0.2s, color 0.2s;
}
#wpam-panel .wpam-footer-link:hover { background-color: #e9ecef; color: var(--wpam-primary-color); }
#wpam-panel .wpam-footer-link .wpam-icon { width: 18px; height: 18px; margin-right: 0; }


/* --- PULSANTE TOGGLE PRINCIPALE --- */
#wpam-toggle-button {
    display: flex; align-items: center; justify-content: center;
    position: fixed;
    width: 42px; height: 42px;
    bottom: 25px; left: 25px;
    z-index: 99999;
    border-radius: 50%;
    background-color: var(--wpam-primary-color);
    box-shadow: 0 5px 15px rgba(0,0,0,0.15);
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    padding: 0;
    pointer-events: auto;
}
#wpam-toggle-button svg { width: 22px; height: 22px; fill: white; }
#wpam-toggle-button:hover { background-color: var(--wpam-button-hover-bg); transform: scale(1.1); box-shadow: 0 8px 20px rgba(0,0,0,0.2); }


/* --- STILI APPLICATI ALLA PAGINA --- */

/* Navigazione da Tastiera (FIX DEFINITIVO) */
body.wpam-keyboard-nav-enhanced *:focus,
body.wpam-keyboard-nav-enhanced *:focus-visible {
    outline-width: 3px !important;
    outline-style: solid !important;
    outline-color: var(--wpam-focus-outline-color) !important;
    outline-offset: 2px !important;
    box-shadow: 0 0 0 4px var(--wpam-focus-ring-color) !important;
    position: relative;
    z-index: 2147483645 !important; /* Valore massimo per essere sempre in primo piano */
}
/* Stili specifici per non applicare lo z-index dentro il pannello */
body.wpam-keyboard-nav-enhanced #wpam-panel *:focus,
body.wpam-keyboard-nav-enhanced #wpam-panel *:focus-visible,
body.wpam-keyboard-nav-enhanced #wpam-toggle-button:focus,
body.wpam-keyboard-nav-enhanced #wpam-toggle-button:focus-visible {
    z-index: auto !important;
}


/* Alto Contrasto */
body.wpam-high-contrast-active { background-color: var(--wpam-hc-bg) !important; color: var(--wpam-hc-text) !important; }
body.wpam-high-contrast-active *:not(#wp-accessibility-menu-wrapper, #wp-accessibility-menu-wrapper *):not(script):not(style) {
    background-color: transparent !important; color: var(--wpam-hc-text) !important;
    border-color: var(--wpam-hc-text) !important; box-shadow: none !important;
}
body.wpam-high-contrast-active a:not(#wp-accessibility-menu-wrapper a) { color: var(--wpam-hc-link) !important; text-decoration: underline !important; }
body.wpam-high-contrast-active img:not(#wp-accessibility-menu-wrapper img) { filter: contrast(500%) grayscale(100%) !important; }

/* Modalità Scura */
body.wpam-dark-mode-active { background-color: var(--wpam-dark-bg) !important; color: var(--wpam-dark-text) !important; }
body.wpam-dark-mode-active *:not(#wp-accessibility-menu-wrapper, #wp-accessibility-menu-wrapper *):not(script):not(style) {
    background-color: transparent !important; color: inherit !important;
    border-color: var(--wpam-dark-border, currentColor) !important; box-shadow: none !important;
}
body.wpam-dark-mode-active a:not(#wp-accessibility-menu-wrapper a) { color: var(--wpam-dark-icon-color-page) !important; }
body.wpam-dark-mode-active img:not(#wp-accessibility-menu-wrapper img) { filter: brightness(0.85) contrast(1.1); }

/* Disattiva Immagini */
body.wpam-images-disabled img:not(#wp-accessibility-menu-wrapper img),
body.wpam-images-disabled svg:not(#wp-accessibility-menu-wrapper svg):not([role="img"])
{ display: none !important; }
body.wpam-images-disabled [style*="background-image"]:not(#wp-accessibility-menu-wrapper [style*="background-image"]) { background-image: none !important; }

/* Modalità Lettura */
body.wpam-reading-mode-active { font-family: "Georgia", "Times New Roman", serif !important; line-height: 1.9 !important; }
body.wpam-reading-mode-active p, body.wpam-reading-mode-active li, body.wpam-reading-mode-active div:not([class]) { max-width: 70ch !important; margin-left: auto !important; margin-right: auto !important; }

/* Cursore Grande */
body.wpam-large-cursor-active, body.wpam-large-cursor-active * { cursor: var(--wpam-large-arrow-cursor, var(--wpam-large-arrow-cursor-fallback)) !important; }
body.wpam-high-contrast-active.wpam-large-cursor-active, body.wpam-high-contrast-active.wpam-large-cursor-active * { cursor: var(--wpam-hc-large-arrow-cursor, var(--wpam-large-arrow-cursor-fallback)) !important; }
body.wpam-dark-mode-active.wpam-large-cursor-active, body.wpam-dark-mode-active.wpam-large-cursor-active * { cursor: var(--wpam-dark-large-arrow-cursor, var(--wpam-large-arrow-cursor-fallback)) !important; }

/* Evidenzia Link */
body.wpam-links-highlighted a:not(#wp-accessibility-menu-wrapper a) {
    background-color: #ffeb3b !important; color: #212121 !important; padding: 2px 4px !important;
    text-decoration: underline !important; border: 1px solid #fbc02d !important; border-radius: 3px;
}

/* Guida alla Lettura */
#wpam-reading-guide-bar {
    position: fixed; height: 30px; width: 100%; background-color: rgba(0, 115, 230, 0.2);
    z-index: 2147483630; pointer-events: none; left: 0;
    border-top: 1px solid rgba(0, 115, 230, 0.3); border-bottom: 1px solid rgba(0, 115, 230, 0.3);
    transition: top 0.03s linear;
}

/* Stili Responsive */
@media (max-width: 600px) {
    #wpam-panel { width: calc(100% - 30px); left: 15px; bottom: 85px; max-height: calc(100vh - 100px); }
    #wpam-panel .wpam-features-grid { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
    #wpam-panel .wpam-header { padding: 10px 12px; flex-wrap: wrap; } /* Permette di andare a capo */
    #wpam-panel .wpam-title-button { font-size: 1em; }
    #wpam-panel .wpam-close-button { width: 28px; height: 28px; }
    #wpam-panel .wpam-language-selector { margin-left: auto; }
    #wpam-panel .wpam-footer { flex-direction: column; gap: 8px; padding: 10px; }
    #wpam-panel .wpam-footer-link { width: 100%; }
    #wpam-toggle-button { width: 42px; height: 42px; bottom: 20px; left: 20px; }
}