/* ===== ACCESSIBILITÉ WCAG 2.1 AA ===== */

/* Classe pour contenu visuellement caché mais accessible aux lecteurs d'écran */
.sr-only,
.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border-width: 0 !important;
}

/* Classe pour rendre visible au focus (utile pour skip links) */
.sr-only-focusable:active,
.sr-only-focusable:focus {
    position: static !important;
    width: auto !important;
    height: auto !important;
    overflow: visible !important;
    clip: auto !important;
    white-space: normal !important;
}

/* Focus visible amélioré pour tous les éléments interactifs */
*:focus-visible {
    outline: 3px solid var(--primary-color, #2563eb) !important;
    outline-offset: 2px !important;
    border-radius: 4px;
}

/* Focus visible pour les boutons et liens */
button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[role="button"]:focus-visible,
[role="link"]:focus-visible {
    outline: 3px solid var(--primary-color, #2563eb) !important;
    outline-offset: 2px !important;
}

/* Assurer que les éléments désactivés ne reçoivent pas le focus */
button:disabled,
input:disabled,
textarea:disabled,
select:disabled,
[disabled] {
    cursor: not-allowed;
    opacity: 0.6;
}

button:disabled:focus,
input:disabled:focus,
textarea:disabled:focus,
select:disabled:focus,
[disabled]:focus {
    outline: none !important;
}

/* Indicateur visuel pour les champs requis */
[required]:not([type="hidden"]):not([aria-hidden="true"])::after,
[aria-required="true"]:not([type="hidden"]):not([aria-hidden="true"])::after {
    content: " *";
    color: #dc2626;
    font-weight: bold;
}

/* Style pour les messages d'erreur */
[role="alert"],
.error-message,
[aria-invalid="true"] ~ .error-text {
    color: #dc2626;
    font-weight: 600;
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

/* Indicateur visuel pour les champs en erreur */
[aria-invalid="true"],
input:invalid:not(:placeholder-shown),
textarea:invalid:not(:placeholder-shown),
select:invalid {
    border-color: #dc2626 !important;
    border-width: 2px !important;
}

/* Supprime le outline par défaut mais garde focus-visible */
*:focus:not(:focus-visible) {
    outline: none;
}

/* Assurer que les images décoratives ne sont pas lues */
img[alt=""],
img[role="presentation"],
[aria-hidden="true"] {
    /* Ces images sont décoratives et ne doivent pas être annoncées */
}

/* Style pour les liens qui s'ouvrent dans un nouvel onglet */
a[target="_blank"]::after {
    content: "";
    display: inline-block;
    width: 0.75rem;
    height: 0.75rem;
    margin-left: 0.25rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='currentColor'%3E%3Cpath d='M6.22 8.72a.75.75 0 001.06 1.06l5.22-5.22v1.69a.75.75 0 001.5 0v-3.5a.75.75 0 00-.75-.75h-3.5a.75.75 0 000 1.5h1.69L6.22 8.72z'/%3E%3Cpath d='M3.5 6.75c0-.69.56-1.25 1.25-1.25H7A.75.75 0 007 4H4.75A2.75 2.75 0 002 6.75v4.5A2.75 2.75 0 004.75 14h4.5A2.75 2.75 0 0012 11.25V9a.75.75 0 00-1.5 0v2.25c0 .69-.56 1.25-1.25 1.25h-4.5c-.69 0-1.25-.56-1.25-1.25v-4.5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-size: contain;
    vertical-align: middle;
}

/* Amélioration du contraste pour le texte secondaire */
.text-secondary,
.secondary-text {
    color: #4b5563; /* Contraste minimum 4.5:1 sur fond blanc */
}

/* Dark mode - Assurer le contraste */
@media (prefers-color-scheme: dark) {
    .text-secondary,
    .secondary-text {
        color: #9ca3af; /* Contraste minimum 4.5:1 sur fond sombre */
    }
}

/* Amélioration de la lisibilité */
body {
    line-height: 1.6; /* WCAG recommande minimum 1.5 */
    font-size: 16px; /* Taille de base lisible */
}

p,
li {
    line-height: 1.7; /* Encore meilleure lisibilité pour les paragraphes */
}

/* Espacement entre les paragraphes */
p + p {
    margin-top: 1rem;
}

/* Taille minimale pour les zones cliquables (44x44px WCAG 2.5.5) */
button,
a,
input[type="submit"],
input[type="button"],
input[type="reset"],
[role="button"],
[role="link"] {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Exception pour les liens dans le texte */
p a,
li a,
span a {
    min-height: auto;
    min-width: auto;
    display: inline;
}

/* Amélioration de la navigation au clavier */
.skip-link {
    position: absolute;
    top: -100px;
    left: 0;
    background: var(--primary-color, #2563eb);
    color: white;
    padding: 12px 24px;
    text-decoration: none;
    font-weight: 600;
    z-index: 10000;
    border-radius: 0 0 8px 0;
    transition: top 0.3s ease;
}

.skip-link:focus {
    top: 0;
    outline: 3px solid var(--primary-dark, #1e40af);
    outline-offset: 2px;
}

/* Préférence pour réduire la transparence */
@media (prefers-reduced-transparency: reduce) {
    * {
        opacity: 1 !important;
    }
}

/* Préférence pour le contraste élevé */
@media (prefers-contrast: high) {
    * {
        border-width: 2px !important;
        outline-width: 3px !important;
    }
    
    button,
    a,
    input,
    textarea,
    select {
        border: 2px solid currentColor !important;
    }
}

/* Support du mode sombre respectant les préférences système */
@media (prefers-color-scheme: dark) {
    :root {
        --primary-color: #3b82f6;
        --text-primary: #f9fafb;
        --text-secondary: #9ca3af;
        --bg-primary: #111827;
        --bg-secondary: #1f2937;
    }
}

/* Assurer que le texte est sélectionnable */
*:not(input):not(textarea) {
    user-select: text;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
}

/* Exception pour les boutons et contrôles */
button,
[role="button"],
.no-select {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/* Style pour les abréviations avec tooltip */
abbr[title] {
    text-decoration: underline dotted;
    cursor: help;
}

/* Amélioration des listes */
ul,
ol {
    padding-left: 2rem;
}

li {
    margin-bottom: 0.5rem;
}

/* Tables accessibles */
table {
    border-collapse: collapse;
    width: 100%;
}

th,
td {
    padding: 0.75rem;
    text-align: left;
    border: 1px solid #e5e7eb;
}

th {
    background-color: #f9fafb;
    font-weight: 600;
}

caption {
    caption-side: top;
    padding: 0.75rem;
    font-weight: 600;
    text-align: left;
}

/* Support des icônes avec texte alternatif */
.icon-with-text {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.icon-decorative {
    aria-hidden: true;
}

/* Animation de chargement accessible */
@keyframes accessible-spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-spinner[role="status"] {
    animation: accessible-spin 1s linear infinite;
}

/* Assurer que les modals sont bien annoncés */
[role="dialog"],
[role="alertdialog"] {
    position: fixed;
    z-index: 9999;
}

/* Overlay pour les modals */
.modal-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.75);
    z-index: 9998;
}

/* Focus trap pour les modals */
[role="dialog"]:focus,
[role="alertdialog"]:focus {
    outline: none;
}

/* Amélioration des formulaires */
label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

input,
textarea,
select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 1rem;
    font-family: inherit;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--primary-color, #2563eb);
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Groupe de champs */
fieldset {
    border: 2px solid #e5e7eb;
    padding: 1rem;
    margin-bottom: 1rem;
    border-radius: 8px;
}

legend {
    padding: 0 0.5rem;
    font-weight: 600;
    color: var(--text-primary, #111827);
}

/* Checkboxes et radios accessibles */
input[type="checkbox"],
input[type="radio"] {
    width: 1.25rem;
    height: 1.25rem;
    margin-right: 0.5rem;
    cursor: pointer;
}

/* Amélioration des tooltips */
[data-tooltip] {
    position: relative;
    cursor: help;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.5rem 0.75rem;
    background: #1f2937;
    color: white;
    font-size: 0.875rem;
    white-space: nowrap;
    border-radius: 4px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 1000;
}

[data-tooltip]:hover::after,
[data-tooltip]:focus::after {
    opacity: 1;
}

