/*
 * Panneau « Accessibilité » (scripts/a11y-panel.js, inclus par inc/a11y-panel.php sur toutes les pages).
 * Deux parties :
 *  1. le bouton et le panneau (classes .sx-a11y-*, indépendantes de Bootstrap et des styles de page) ;
 *  2. les préférences, appliquées par des classes sur <html> (html.a11y-*), posées avant l'affichage.
 * Le panneau ne remplace pas la conformité RGAA du code : il offre des réglages de confort au visiteur.
 */

@font-face {
    font-family: 'Atkinson Hyperlegible';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('/fonts/atkinson/atkinson-hyperlegible-latin-400-normal.woff2') format('woff2');
}

@font-face {
    font-family: 'Atkinson Hyperlegible';
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url('/fonts/atkinson/atkinson-hyperlegible-latin-700-normal.woff2') format('woff2');
}

/* ============ 1. Bouton et panneau ============ */

:root {
    /* Hauteur du bouton depuis le bas : au-dessus de la barre de navigation mobile du site */
    --sx-a11y-bottom: 24px;
}

@media (max-width: 991px) {
    :root {
        --sx-a11y-bottom: calc(76px + 14px + env(safe-area-inset-bottom));
    }
}

/* Landing page : pas de barre de navigation, mais une barre d'action fixe sous 1000 px */
body.lp {
    --sx-a11y-bottom: 24px;
}

@media (max-width: 999px) {
    body.lp {
        --sx-a11y-bottom: calc(86px + env(safe-area-inset-bottom));
    }
}

.sx-a11y-trigger {
    position: fixed;
    left: 16px;
    bottom: var(--sx-a11y-bottom);
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    margin: 0;
    padding: 0;
    border: 2px solid #ffffff;
    border-radius: 50%;
    background: #3c5e99;
    color: #ffffff;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(12, 15, 26, 0.35);
    transition: background-color 0.15s ease;
}

.sx-a11y-trigger:hover,
.sx-a11y-trigger[aria-expanded='true'] {
    background: #2b4880;
}

.sx-a11y-trigger svg {
    width: 1.75rem;
    height: 1.75rem;
    display: block;
}

.sx-a11y-trigger:focus-visible,
.sx-a11y-panel :focus-visible {
    outline: 3px solid #ebb919;
    outline-offset: 3px;
}

.sx-a11y-panel {
    position: fixed;
    left: 16px;
    bottom: calc(var(--sx-a11y-bottom) + 3rem + 12px);
    z-index: 10001;
    width: min(22.5rem, calc(100vw - 32px));
    max-height: calc(100vh - var(--sx-a11y-bottom) - 3rem - 36px);
    max-height: calc(100dvh - var(--sx-a11y-bottom) - 3rem - 36px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 1.25rem;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 16px;
    background: #17243a;
    color: #ffffff;
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    font-size: 0.9375rem;
    line-height: 1.45;
    letter-spacing: 0;
    text-align: left;
    box-shadow: 0 18px 50px rgba(5, 10, 25, 0.45);
}

.sx-a11y-panel[hidden] {
    display: none;
}

.sx-a11y-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

/* Le titre reçoit le focus à l'ouverture (lecteurs d'écran) mais n'est pas interactif : pas de contour */
.sx-a11y-panel h2:focus {
    outline: none;
}

.sx-a11y-panel h2 {
    margin: 0;
    color: #ffffff;
    font-family: inherit;
    font-size: 1.1875rem;
    font-weight: 700;
    line-height: 1.2;
}

.sx-a11y-close {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 2.75rem;
    height: 2.75rem;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
}

.sx-a11y-close:hover {
    background: rgba(255, 255, 255, 0.16);
}

.sx-a11y-intro {
    margin: 6px 0 16px;
    color: rgba(255, 255, 255, 0.78);
    font-size: 0.8125rem;
}

/* Taille du texte : trois boutons « A » de taille croissante */
.sx-a11y-size {
    margin: 0 0 8px;
    padding: 14px 0 0;
    border: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.sx-a11y-size legend,
.sx-a11y-label {
    display: block;
    padding: 0;
    color: #ffffff;
    font-size: 0.9375rem;
    font-weight: 600;
}

.sx-a11y-size-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 10px;
}

.sx-a11y-size-buttons button {
    min-height: 2.75rem;
    margin: 0;
    padding: 0;
    border: 2px solid rgba(255, 255, 255, 0.25);
    border-radius: 10px;
    background: transparent;
    color: #ffffff;
    font-family: inherit;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
}

.sx-a11y-size-buttons button:nth-child(1) { font-size: 0.875rem; }
.sx-a11y-size-buttons button:nth-child(2) { font-size: 1.125rem; }
.sx-a11y-size-buttons button:nth-child(3) { font-size: 1.375rem; }

.sx-a11y-size-buttons button:hover {
    border-color: rgba(255, 255, 255, 0.55);
}

.sx-a11y-size-buttons button[aria-pressed='true'] {
    border-color: #ebb919;
    background: #ebb919;
    color: #17243a;
}

/* Réglages oui / non : un interrupteur par ligne */
.sx-a11y-options {
    margin: 0;
    padding: 0;
    list-style: none;
}

.sx-a11y-options li {
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.sx-a11y-switch {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    width: 100%;
    margin: 0;
    padding: 12px 0;
    border: 0;
    background: transparent;
    color: #ffffff;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
}

.sx-a11y-switch-text {
    display: block;
}

.sx-a11y-hint {
    display: block;
    margin-top: 2px;
    color: rgba(255, 255, 255, 0.72);
    font-size: 0.8125rem;
    font-weight: 400;
}

.sx-a11y-track {
    position: relative;
    flex-shrink: 0;
    width: 2.75rem;
    height: 1.625rem;
    border-radius: 0.8125rem;
    background: rgba(255, 255, 255, 0.22);
    transition: background-color 0.15s ease;
}

.sx-a11y-track::after {
    content: '';
    position: absolute;
    top: 0.1875rem;
    left: 0.1875rem;
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 50%;
    background: #ffffff;
    transition: transform 0.15s ease;
}

.sx-a11y-switch[aria-checked='true'] .sx-a11y-track {
    background: #ebb919;
}

.sx-a11y-switch[aria-checked='true'] .sx-a11y-track::after {
    transform: translateX(1.125rem);
    background: #17243a;
}

.sx-a11y-reset {
    display: block;
    width: 100%;
    margin: 8px 0 0;
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    background: transparent;
    color: #ffffff;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
}

.sx-a11y-reset:hover {
    border-color: #ffffff;
}

.sx-a11y-status {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ============ 2. Préférences appliquées au site ============ */

/* Taille du texte : le site est en rem, tout suit la taille de base */
html.a11y-text-1 {
    font-size: 112.5% !important;
}

html.a11y-text-2 {
    font-size: 125% !important;
}

/* Contraste renforcé : les textes atténués passent en couleur pleine */
html.a11y-contrast {
    --hero-text-secondary: #ffffff;
}

html.a11y-contrast .text-white-50,
html.a11y-contrast .text-muted,
html.a11y-contrast .text-secondary,
html.a11y-contrast .text-body-secondary {
    color: #ffffff !important;
}

/* Landing page EHPAD (fond clair) : textes secondaires en encre pleine, aides du formulaire en blanc */
html.a11y-contrast body.lp {
    --lp-muted: #17213d;
}

html.a11y-contrast body.lp .lp-form-intro,
html.a11y-contrast body.lp .lp-legal,
html.a11y-contrast body.lp .lp-field-hint,
html.a11y-contrast body.lp .lp-optional,
html.a11y-contrast body.lp .lp-work-list p,
html.a11y-contrast body.lp .lp-offer-sub {
    color: #ffffff;
}

html.a11y-contrast body.lp .lp-field input:not([type='checkbox']),
html.a11y-contrast body.lp .lp-field textarea {
    border-color: #17213d;
}

/* Police plus lisible : Atkinson Hyperlegible (Braille Institute), hébergée sur le site.
   Les icônes Font Awesome du blog (classes fa*) gardent leur police, sinon elles deviennent des carrés. */
html.a11y-font body,
html.a11y-font body *:not(svg):not(svg *):not([class^='fa']):not([class*=' fa']) {
    font-family: 'Atkinson Hyperlegible', 'Inter', system-ui, sans-serif !important;
}

/* Espacement du texte : valeurs du critère RGAA 10.12 (WCAG 1.4.12) */
html.a11y-spacing body :is(p, li, dd, dt, td, th, label, blockquote, figcaption, summary, h1, h2, h3, h4, h5, h6, a, span, button, input, textarea, select) {
    line-height: 1.5 !important;
    letter-spacing: 0.12em !important;
    word-spacing: 0.16em !important;
}

html.a11y-spacing body p {
    margin-bottom: 2em !important;
}

/* Liens soulignés, pour les distinguer sans la couleur */
html.a11y-links body a:not(.sx-a11y-trigger) {
    text-decoration: underline !important;
    text-decoration-thickness: 2px !important;
    text-underline-offset: 3px !important;
}

/* Arrêt des animations : transitions, défilements, effets 3D et parallaxe de l'accueil */
html.a11y-no-motion,
html.a11y-no-motion body {
    scroll-behavior: auto !important;
}

html.a11y-no-motion *,
html.a11y-no-motion *::before,
html.a11y-no-motion *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0s !important;
    transition-duration: 0.001ms !important;
    transition-delay: 0s !important;
}

html.a11y-no-motion .scroll-animate {
    opacity: 1 !important;
    transform: none !important;
}

html.a11y-no-motion .service-card-3d,
html.a11y-no-motion .hero-image-3d,
html.a11y-no-motion .btn-glass,
html.a11y-no-motion .btn-glass-primary {
    transform: none !important;
}

/* Impression : ni bouton ni panneau */
@media print {
    .sx-a11y-trigger,
    .sx-a11y-panel {
        display: none !important;
    }
}
