/**
 * Module d'Accessibilité - Styles RGAA 4.2 / WCAG 2.1 AA
 * 
 * Critères respectés :
 * - Contraste minimum 4.5:1 pour texte normal
 * - Contraste minimum 3:1 pour texte large et composants
 * - Focus visible avec outline personnalisé
 * - Cibles tactiles min 44x44px (mobile)
 * - Responsive et compatible mobile
 * - Animation réduite si prefers-reduced-motion
 * - Pas d'utilisation exclusive de la couleur
 */

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

/* ========== BOUTON FLOTTANT ========== */
.a11y-toggle-btn {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 99998;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 52px;
    height: 52px;
    padding: 0 0.5rem;
    background: linear-gradient(135deg, #ca3c66 0%, #a23055 100%);
    border: 2px solid #fff;
    border-right: 0;
    border-radius: 50% 0 0 50%;
    box-shadow: -4px 0 20px rgba(202, 60, 102, 0.4);
    color: #fff;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 0.3s ease,
                background 0.3s ease;
}

.a11y-toggle-btn svg,
.a11y-toggle-btn__icon {
    width: 26px;
    height: 26px;
    flex-shrink: 0;
    object-fit: contain;
    filter: brightness(0) invert(1); /* Rendre l'icône blanche */
}

.a11y-toggle-btn__text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

.a11y-toggle-btn:hover,
.a11y-toggle-btn:focus {
    width: 62px;
    background: linear-gradient(135deg, #a23055 0%, #7b2644 100%);
    box-shadow: -6px 0 30px rgba(202, 60, 102, 0.5);
}

/* Supprimer le contour par défaut */
.a11y-toggle-btn {
    outline: none;
    border: none;
}

/* Focus visible conforme WCAG */
.a11y-toggle-btn:focus-visible {
    outline: 3px solid #fbbf24;
    outline-offset: 2px;
}

.a11y-toggle-btn[aria-expanded="true"] {
    right: 420px;
}

/* ========== PANNEAU ========== */
.a11y-panel {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0s linear 0.3s;
}

.a11y-panel[hidden] {
    display: none;
}

.a11y-panel.is-open {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.3s ease, visibility 0s;
}

.a11y-panel__overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(4px);
    cursor: pointer;
}

.a11y-panel__dialog {
    position: relative;
    width: 420px;
    max-width: 100%;
    height: 100vh;
    max-height: 100vh;
    background: #ffffff;
    box-shadow: -8px 0 48px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.a11y-panel.is-open .a11y-panel__dialog {
    transform: translateX(0);
}

/* ========== HEADER ========== */
.a11y-panel__header {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.5rem;
    background: linear-gradient(135deg, #ca3c66 0%, #a23055 100%);
    color: #fff;
    flex-shrink: 0;
}

.a11y-panel__branding {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.a11y-panel__icon {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    filter: brightness(0) invert(1); /* Rendre l'icône blanche */
    object-fit: contain;
}

.a11y-panel__title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.2;
}

.a11y-panel__subtitle {
    margin: 0.25rem 0 0;
    font-size: 0.813rem;
    font-weight: 400;
    opacity: 0.9;
}

.a11y-panel__close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid transparent;
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.a11y-panel__close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.a11y-panel__close:focus-visible {
    outline: none;
    border-color: #fbbf24;
    background: rgba(255, 255, 255, 0.3);
}

.a11y-panel__close svg {
    width: 20px;
    height: 20px;
}

/* ========== CORPS ========== */
.a11y-panel__body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1.5rem;
    -webkit-overflow-scrolling: touch;
}

/* ========== CONTRÔLES ========== */
.a11y-control {
    margin-bottom: 1.5rem;
}

.a11y-control__label {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    margin-bottom: 0.75rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: #1f2937;
}

.a11y-control__label svg {
    width: 20px;
    height: 20px;
    color: #ca3c66;
    flex-shrink: 0;
}

.a11y-control__value {
    display: block;
    margin-top: 0.5rem;
    font-size: 0.813rem;
    font-weight: 600;
    color: #6b7280;
    text-align: center;
}

/* ========== SLIDERS ========== */
.a11y-slider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.a11y-slider__btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    padding: 0.5rem;
    background: #f3f4f6;
    border: 2px solid #d1d5db;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 700;
    color: #374151;
    cursor: pointer;
    transition: all 0.2s ease;
}

.a11y-slider__btn:hover {
    background: #fef2f6;
    border-color: #ca3c66;
    color: #ca3c66;
}

.a11y-slider__btn:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
    border-color: #ca3c66;
}

.a11y-slider__input {
    flex: 1;
    height: 6px;
    appearance: none;
    background: #e5e7eb;
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.a11y-slider__input:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 4px;
}

.a11y-slider__input::-webkit-slider-thumb {
    appearance: none;
    width: 22px;
    height: 22px;
    background: linear-gradient(135deg, #ca3c66 0%, #a23055 100%);
    border: 3px solid #fff;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(202, 60, 102, 0.3);
    cursor: pointer;
    transition: transform 0.2s ease;
}

.a11y-slider__input::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.a11y-slider__input::-moz-range-thumb {
    width: 22px;
    height: 22px;
    background: linear-gradient(135deg, #ca3c66 0%, #a23055 100%);
    border: 3px solid #fff;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(202, 60, 102, 0.3);
    cursor: pointer;
    transition: transform 0.2s ease;
}

.a11y-slider__input::-moz-range-thumb:hover {
    transform: scale(1.1);
}

/* ========== TOGGLES (SWITCHES) ========== */
.a11y-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 0;
    border-bottom: 1px solid #e5e7eb;
}

.a11y-toggle__label {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
}

.a11y-toggle__label svg {
    width: 20px;
    height: 20px;
    color: #ca3c66;
    flex-shrink: 0;
}

.a11y-switch {
    position: relative;
    width: 52px;
    height: 28px;
    padding: 0;
    background: #d1d5db;
    border: 2px solid transparent;
    border-radius: 14px;
    cursor: pointer;
    transition: background 0.3s ease, border-color 0.2s ease;
}

.a11y-switch:hover {
    background: #9ca3af;
}

.a11y-switch:focus-visible {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px #dbeafe;
}

.a11y-switch.is-on {
    background: linear-gradient(135deg, #ca3c66 0%, #a23055 100%);
}

.a11y-switch.is-on:hover {
    background: linear-gradient(135deg, #a23055 0%, #7b2644 100%);
}

.a11y-switch__slider {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.a11y-switch.is-on .a11y-switch__slider {
    transform: translateX(24px);
}

/* ========== BOUTONS ========== */
.a11y-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 44px;
    padding: 0.75rem 1.25rem;
    background: #f3f4f6;
    border: 2px solid #d1d5db;
    border-radius: 10px;
    font-size: 0.875rem;
    font-weight: 600;
    color: #374151;
    cursor: pointer;
    transition: all 0.2s ease;
}

.a11y-btn:hover {
    background: #e5e7eb;
    border-color: #9ca3af;
}

.a11y-btn:focus-visible {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px #dbeafe;
}

.a11y-btn svg {
    width: 18px;
    height: 18px;
}

.a11y-btn--sm {
    min-height: 40px;
    padding: 0.5rem 0.875rem;
    font-size: 0.813rem;
}

.a11y-btn.is-active {
    background: linear-gradient(135deg, #ca3c66 0%, #a23055 100%);
    border-color: #ca3c66;
    color: #fff;
}

.a11y-btn--reset {
    width: 100%;
}

/* ========== GROUPE DE BOUTONS ========== */
.a11y-buttongroup {
    display: flex;
    gap: 0.5rem;
}

.a11y-buttongroup .a11y-btn {
    flex: 1;
}

/* ========== SÉPARATEUR ========== */
.a11y-separator {
    margin: 1.25rem 0;
    border: 0;
    border-top: 1px solid #e5e7eb;
}

/* ========== FOOTER ========== */
.a11y-panel__footer {
    padding: 1.5rem;
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
    flex-shrink: 0;
}

/* ========== MODES D'ACCESSIBILITÉ ========== */

/* Zoom texte */
body.a11y-zoom-080 > *:not(.a11y-toggle-btn):not(.a11y-panel) { zoom: 0.8; }
body.a11y-zoom-090 > *:not(.a11y-toggle-btn):not(.a11y-panel) { zoom: 0.9; }
body.a11y-zoom-110 > *:not(.a11y-toggle-btn):not(.a11y-panel) { zoom: 1.1; }
body.a11y-zoom-120 > *:not(.a11y-toggle-btn):not(.a11y-panel) { zoom: 1.2; }
body.a11y-zoom-130 > *:not(.a11y-toggle-btn):not(.a11y-panel) { zoom: 1.3; }
body.a11y-zoom-140 > *:not(.a11y-toggle-btn):not(.a11y-panel) { zoom: 1.4; }
body.a11y-zoom-150 > *:not(.a11y-toggle-btn):not(.a11y-panel) { zoom: 1.5; }
body.a11y-zoom-160 > *:not(.a11y-toggle-btn):not(.a11y-panel) { zoom: 1.6; }
body.a11y-zoom-170 > *:not(.a11y-toggle-btn):not(.a11y-panel) { zoom: 1.7; }
body.a11y-zoom-180 > *:not(.a11y-toggle-btn):not(.a11y-panel) { zoom: 1.8; }
body.a11y-zoom-190 > *:not(.a11y-toggle-btn):not(.a11y-panel) { zoom: 1.9; }
body.a11y-zoom-200 > *:not(.a11y-toggle-btn):not(.a11y-panel) { zoom: 2.0; }

/* Contraste élevé */
body.a11y-high-contrast main,
body.a11y-high-contrast header,
body.a11y-high-contrast section,
body.a11y-high-contrast article,
body.a11y-high-contrast aside,
body.a11y-high-contrast footer {
    filter: contrast(1.5) !important;
}

/* Mode sombre (nouveau) */
body.a11y-dark-mode {
    background: #1f2937 !important;
    color: #f3f4f6 !important;
}

body.a11y-dark-mode *:not(.a11y-toggle-btn):not(.a11y-panel):not(.a11y-panel *) {
    background-color: #111827 !important;
    color: #f3f4f6 !important;
    border-color: #374151 !important;
}

/* Éléments spécifiques */
body.a11y-dark-mode .topbar,
body.a11y-dark-mode .navbar,
body.a11y-dark-mode header,
body.a11y-dark-mode nav,
body.a11y-dark-mode main,
body.a11y-dark-mode section,
body.a11y-dark-mode article,
body.a11y-dark-mode aside,
body.a11y-dark-mode footer,
body.a11y-dark-mode .card,
body.a11y-dark-mode .bg-white,
body.a11y-dark-mode [class*="bg-"] {
    background: #111827 !important;
    background-color: #111827 !important;
    color: #f3f4f6 !important;
}

body.a11y-dark-mode a {
    color: #60a5fa !important;
}

body.a11y-dark-mode h1,
body.a11y-dark-mode h2,
body.a11y-dark-mode h3,
body.a11y-dark-mode h4,
body.a11y-dark-mode h5,
body.a11y-dark-mode h6,
body.a11y-dark-mode strong,
body.a11y-dark-mode b {
    color: #f9fafb !important;
}

body.a11y-dark-mode button,
body.a11y-dark-mode input,
body.a11y-dark-mode select,
body.a11y-dark-mode textarea {
    background: #1f2937 !important;
    color: #f3f4f6 !important;
    border-color: #4b5563 !important;
}

/* Police dyslexique OpenDyslexic */
body.a11y-dyslexia-font * {
    font-family: 'OpenDyslexic', 'Comic Sans MS', 'Trebuchet MS', 'Arial', sans-serif !important;
}

/* Surlignage des liens */
body.a11y-highlight-links a {
    background: #fbbf24 !important;
    color: #000 !important;
    padding: 2px 6px !important;
    border-radius: 4px !important;
    text-decoration: underline !important;
    text-decoration-thickness: 2px !important;
    text-underline-offset: 2px !important;
    text-decoration-color: #000 !important;
    box-shadow: 0 0 0 2px #fbbf24 !important;
    font-weight: 600 !important;
}

/* Focus visuel renforcé (nouveau) - Spécificité maximale */
body.a11y-focus-visible:not(.fake-class) *:not(.a11y-panel):not(.a11y-panel *):focus,
body.a11y-focus-visible:not(.fake-class) *:not(.a11y-panel):not(.a11y-panel *):focus-visible,
body.a11y-focus-visible:not(.fake-class) a:not(.a11y-panel *):focus,
body.a11y-focus-visible:not(.fake-class) button:not(.a11y-panel *):focus,
body.a11y-focus-visible:not(.fake-class) input:not(.a11y-panel *):focus,
body.a11y-focus-visible:not(.fake-class) select:not(.a11y-panel *):focus,
body.a11y-focus-visible:not(.fake-class) textarea:not(.a11y-panel *):focus,
body.a11y-focus-visible:not(.fake-class) [tabindex]:not(.a11y-panel *):focus,
body.a11y-focus-visible:not(.fake-class) [href]:not(.a11y-panel *):focus {
    outline: 6px solid #fbbf24 !important;
    outline-style: solid !important;
    outline-offset: 4px !important;
    box-shadow: 0 0 0 12px rgba(251, 191, 36, 0.7), 
                0 0 30px rgba(251, 191, 36, 0.5),
                0 0 60px rgba(251, 191, 36, 0.3) !important;
    position: relative !important;
    z-index: 999999 !important;
    border-color: #fbbf24 !important;
}

/* Forcer sur les éléments du site (pas le panneau) */
body.a11y-focus-visible:not(.fake-class) main *:focus,
body.a11y-focus-visible:not(.fake-class) header *:focus,
body.a11y-focus-visible:not(.fake-class) nav *:focus,
body.a11y-focus-visible:not(.fake-class) article *:focus,
body.a11y-focus-visible:not(.fake-class) section *:focus,
body.a11y-focus-visible:not(.fake-class) footer *:focus,
body.a11y-focus-visible:not(.fake-class) .topbar *:focus,
body.a11y-focus-visible:not(.fake-class) .navbar *:focus {
    outline: 6px solid #fbbf24 !important;
    outline-style: solid !important;
    outline-offset: 4px !important;
    box-shadow: 0 0 0 12px rgba(251, 191, 36, 0.7), 
                0 0 30px rgba(251, 191, 36, 0.5) !important;
    position: relative !important;
    z-index: 999999 !important;
}

/* Masque de lecture */
.a11y-reading-mask {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 99997;
}

.a11y-reading-mask__window {
    position: absolute;
    left: 0;
    width: 100%;
    height: 120px;
    background: transparent;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.75);
    will-change: top;
    /* Pas de transition, utilise requestAnimationFrame pour fluidité */
}

/* Curseurs personnalisés */
body.a11y-cursor-large * {
    cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24" fill="black" stroke="white" stroke-width="1"><path d="M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z"/></svg>') 8 8, auto !important;
}

body.a11y-cursor-xlarge * {
    cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="black" stroke="white" stroke-width="1"><path d="M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z"/></svg>') 12 12, auto !important;
}

/* ========== RESPONSIVE MOBILE ========== */
@media (max-width: 640px) {
    .a11y-toggle-btn {
        width: 48px;
        height: 48px;
        top: auto;
        bottom: 1rem;
        transform: none;
        border-radius: 50%;
        border: 2px solid #fff;
    }

    .a11y-toggle-btn[aria-expanded="true"] {
        right: 0;
        opacity: 0.5;
    }

    .a11y-panel__dialog {
        width: 100%;
        max-width: 100%;
    }

    .a11y-panel__body {
        padding: 1rem;
    }

    .a11y-buttongroup {
        flex-direction: column;
    }

    .a11y-buttongroup .a11y-btn {
        width: 100%;
    }
}

/* ========== ANIMATIONS RÉDUITES ========== */
@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;
    }

    .a11y-toggle-btn,
    .a11y-panel,
    .a11y-panel__dialog,
    .a11y-panel__overlay,
    .a11y-switch__slider {
        transition: none !important;
    }
}

/* ========== PRINT ========== */
@media print {
    .a11y-toggle-btn,
    .a11y-panel,
    .a11y-reading-mask {
        display: none !important;
    }
}
