/* ============================================
   CHRU Nancy — Fondations RGAA 4.1.2
   Accessibilité numérique obligatoire (site public)
   ============================================ */

/* === 1. Skip Link (RGAA 12.7) ===
   Lien d'accès rapide "Aller au contenu principal"
   Invisible par défaut, visible au focus clavier
   ============================================ */

.skip-link {
    position: absolute;
    top: -100%;
    left: 0;
    z-index: 100000;
    padding: 0.75rem 1.5rem;
    background-color: var(--chru-secondary);
    color: var(--chru-white);
    font-size: 1rem;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
    transition: top var(--transition-fast);
}

.skip-link:focus {
    top: 0;
    outline: 3px solid var(--chru-accent);
    outline-offset: 2px;
}

/* === 2. Focus visible (RGAA 10.7, 12.8) ===
   Tous les éléments interactifs doivent avoir
   un indicateur de focus visible.
   ============================================ */

*:focus-visible {
    outline: 3px solid var(--color-focus, var(--chru-accent));
    outline-offset: 2px;
}

/* Supprimer l'outline sur :focus (non-clavier) */
*:focus:not(:focus-visible) {
    outline: none;
}

/* Focus spécifique pour les liens dans le contenu */
.entry-content a:focus-visible,
.chru-content a:focus-visible {
    outline: 3px solid var(--color-focus);
    outline-offset: 2px;
    border-radius: 2px;
}

/* Focus sur les boutons */
button:focus-visible,
[role="button"]:focus-visible,
.chru-btn:focus-visible,
input[type="submit"]:focus-visible {
    outline: 3px solid var(--color-focus);
    outline-offset: 2px;
}

/* === 3. Screen Reader Only (RGAA 10.2) ===
   Masquer visuellement tout en restant
   accessible aux lecteurs d'écran.
   ============================================ */

.sr-only,
.screen-reader-text {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* Version qui redevient visible au focus (pour skip links alternatifs) */
.sr-only-focusable:focus,
.sr-only-focusable:active {
    position: static;
    width: auto;
    height: auto;
    padding: inherit;
    margin: inherit;
    overflow: visible;
    clip: auto;
    clip-path: none;
    white-space: normal;
}

/* === 4. Mouvement réduit (RGAA 13.8) ===
   Respecter la préférence utilisateur
   pour la réduction des animations.
   ============================================ */

@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;
    }
}

/* === 5. Images (RGAA 1.1, 1.2, 1.8) ===
   Images décoratives et informatives.
   ============================================ */

/* Images décoratives explicites */
img[alt=""],
img[role="presentation"] {
    user-select: none;
}

/* SVG inline décoratifs */
svg[aria-hidden="true"] {
    pointer-events: none;
}

/* === 6. Liens (RGAA 6.1, 6.2) ===
   Les liens doivent être identifiables
   autrement que par la couleur seule.
   ============================================ */

/* Liens dans le contenu : soulignés par défaut (RGAA 6.1)
   L'animation slide est gérée dans style.css pour p a et li a uniquement */
.entry-content a,
.chru-content a {
    text-decoration: underline;
    text-underline-offset: 0.2em;
}

.entry-content a:hover,
.chru-content a:hover {
    text-decoration-thickness: 2px;
}

/* Liens externes : indicateur visuel
   Exclus : liens avec aria-label (boutons icônes), boutons partage,
   liens de navigation, boutons CTA */
a[target="_blank"]:not([aria-label]):not(.chru-btn):not(.chru-post-share__btn):not(.chru-card-event__link):not(.chru-card-post__link):not(.chru-liens-externes__link):not(.chru-kit__link):not(.chru-ressource-card__link)::after {
    content: "";
    display: inline-block;
    width: 0.75em;
    height: 0.75em;
    margin-left: 0.25em;
    background-color: currentColor;
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='m24,3v7c0,.552-.447,1-1,1s-1-.448-1-1V3.414l-11.793,11.793c-.195.195-.451.293-.707.293s-.512-.098-.707-.293c-.391-.391-.391-1.023,0-1.414L20.586,2h-6.586c-.553,0-1-.448-1-1s.447-1,1-1h7c1.654,0,3,1.346,3,3Zm-1,11c-.553,0-1,.448-1,1v4c0,1.654-1.346,3-3,3H5c-1.654,0-3-1.346-3-3V5c0-1.654,1.346-3,3-3h4c.553,0,1-.448,1-1s-.447-1-1-1h-4C2.243,0,0,2.243,0,5v14c0,2.757,2.243,5,5,5h14c2.757,0,5-2.243,5-5v-4c0-.552-.447-1-1-1Z'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='m24,3v7c0,.552-.447,1-1,1s-1-.448-1-1V3.414l-11.793,11.793c-.195.195-.451.293-.707.293s-.512-.098-.707-.293c-.391-.391-.391-1.023,0-1.414L20.586,2h-6.586c-.553,0-1-.448-1-1s.447-1,1-1h7c1.654,0,3,1.346,3,3Zm-1,11c-.553,0-1,.448-1,1v4c0,1.654-1.346,3-3,3H5c-1.654,0-3-1.346-3-3V5c0-1.654,1.346-3,3-3h4c.553,0,1-.448,1-1s-.447-1-1-1h-4C2.243,0,0,2.243,0,5v14c0,2.757,2.243,5,5,5h14c2.757,0,5-2.243,5-5v-4c0-.552-.447-1-1-1Z'/%3E%3C/svg%3E");
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-size: contain;
    mask-size: contain;
    vertical-align: baseline;
}

/* === 7. Formulaires (RGAA 11.1, 11.10) ===
   Labels explicites, messages d'erreur.
   ============================================ */

/* Champs obligatoires */
.required-field::after {
    content: " *";
    color: var(--color-error);
}

/* Champs en erreur */
input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
    border-color: var(--color-error);
    box-shadow: 0 0 0 2px rgba(218, 21, 0, 0.2);
}

/* Messages d'erreur */
.field-error-message {
    color: var(--color-error);
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

/* Placeholder : ne pas utiliser comme label (RGAA 11.11) */
::placeholder {
    color: #767676; /* Ratio 4.54:1 sur blanc — conforme AA */
    opacity: 1;
}

/* === 8. Tableaux (RGAA 5.1, 5.4, 5.6, 5.7) ===
   Entêtes et légendes explicites.
   ============================================ */

table {
    border-collapse: collapse;
    width: 100%;
}

table caption {
    text-align: left;
    font-weight: 700;
    padding-bottom: 0.5rem;
    caption-side: top;
}

th {
    text-align: left;
    font-weight: 700;
}

/* === 9. Zoom et reflow (RGAA 10.4, 10.11) ===
   Le contenu doit rester lisible à 200% de zoom
   sans scroll horizontal.
   ============================================ */

html {
    overflow-x: hidden;
}

img,
video,
iframe,
object,
embed {
    max-width: 100%;
    height: auto;
}

/* Conteneurs : empêcher le débordement */
.chru-section {
    max-width: 100vw;
    overflow-x: hidden;
}

/* === 10. Contrastes renforcés (RGAA 3.2, 3.3) === */

@media (forced-colors: active) {
    .skip-link:focus {
        outline: 3px solid ButtonText;
    }

    a:focus-visible {
        outline: 3px solid LinkText;
    }

    button:focus-visible,
    [role="button"]:focus-visible {
        outline: 3px solid ButtonText;
    }
}

/* === 11. Print === */

@media print {
    .skip-link,
    nav[aria-label],
    .chru-header,
    .chru-footer {
        display: none !important;
    }

    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
    }

    a[href^="#"]::after,
    a[href^="tel:"]::after,
    a[href^="javascript:"]::after {
        content: "";
    }
}