/* ============================================================
   ACCESSIBILITY.CSS — Chambre d'Agriculture de Jijel
   Corrections WCAG 2.1 AA + bonnes pratiques
   ============================================================ */

/* ============================================================
   1. SKIP LINK — Aller au contenu principal
   ============================================================ */
.skip-link {
    position: absolute;
    top: -100px;
    left: 10px;
    background: #198754;
    color: #fff !important;
    padding: 14px 24px;
    border-radius: 0 0 8px 8px;
    text-decoration: none;
    font-weight: 700;
    font-size: 1rem;
    z-index: 100000;
    transition: top 0.25s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.skip-link:focus,
.skip-link:focus-visible {
    top: 0;
    outline: 3px solid #ffc107;
    outline-offset: 2px;
}

[dir="rtl"] .skip-link {
    left: auto;
    right: 10px;
}

/* ============================================================
   2. FOCUS VISIBLE — Navigation clavier
   ============================================================ */
*:focus {
    outline: none;
}

*:focus-visible {
    outline: 3px solid #ffc107;
    outline-offset: 2px;
    border-radius: 4px;
    transition: outline-offset 0.1s ease;
}

/* Focus renforcé sur les éléments interactifs */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
    outline: 3px solid #ffc107;
    outline-offset: 3px;
}

/* Focus sur fond sombre */
.bg-dark *:focus-visible,
footer *:focus-visible,
.top-bar *:focus-visible {
    outline-color: #ffd54f;
}

/* Focus sur fond vert */
.btn-success:focus-visible,
.btn-primary:focus-visible,
.cookie-btn--accept:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 2px;
    box-shadow: 0 0 0 5px rgba(25, 135, 84, 0.5);
}

/* ============================================================
   3. CONTRASTE — Couleurs accessibles (WCAG AA)
   ============================================================ */
:root {
    /* Couleurs à contraste vérifié */
    --color-text: #212529;          /* 16.1:1 sur blanc */
    --color-text-muted: #5a6268;    /* 6.3:1 sur blanc — plus foncé que #6c757d */
    --color-link: #146c43;          /* 5.5:1 sur blanc */
    --color-link-hover: #0a3622;    /* 9.9:1 sur blanc */
    --color-success: #198754;       /* 4.6:1 sur blanc */
    --color-warning: #b8860b;       /* 5.5:1 sur blanc */
    --color-danger: #a71d2a;        /* 6.5:1 sur blanc */
}

body {
    color: var(--color-text);
}

.text-muted,
.small.text-muted {
    color: var(--color-text-muted) !important;
}

a {
    color: var(--color-link);
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

a:hover,
a:focus {
    color: var(--color-link-hover);
}

/* Liens dans le footer (fond sombre) */
footer a,
.bg-dark a {
    color: #a8e6b8;
}

footer a:hover,
.bg-dark a:hover {
    color: #fff;
    text-decoration: underline;
}

/* Liens dans le top-bar */
.top-bar a {
    color: #146c43;
}

.top-bar a:hover {
    color: #0a3622;
    text-decoration: underline;
}

/* ============================================================
   4. IMAGES — Alt, dimensions, ratio
   ============================================================ */
img {
    max-width: 100%;
    height: auto;
}

/* Images décoratives : ne pas les annoncer aux lecteurs d'écran */
img[alt=""],
img[aria-hidden="true"] {
    pointer-events: none;
}

/* Images dans les articles : éviter le débordement */
.com-content img {
    height: auto;
    max-width: 100%;
    object-fit: contain;
}

/* ============================================================
   5. TYPOGRAPHIE — Lisibilité
   ============================================================ */
body {
    font-size: 16px;
    line-height: 1.6;
    letter-spacing: 0.01em;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Texte trop petit : agrandir */
small,
.small {
    font-size: 0.875rem;
    line-height: 1.5;
}

/* Paragraphes : espacement minimal */
p {
    margin-bottom: 1rem;
}

/* Listes : espacement */
ul li,
ol li {
    margin-bottom: 0.5rem;
}

/* ============================================================
   6. BOUTONS — Taille minimale et lisibilité
   ============================================================ */
button,
.btn,
input[type="submit"],
input[type="button"] {
    /* min-height: 44px; */
    /* min-width: 44px; */
    /* padding: 10px 20px; */
    font-size: 1rem;
    cursor: pointer;
}

/* Boutons icônes seulement */
button[aria-label]:empty,
button:has(> i:only-child) {
    padding: 10px;
}

/* ============================================================
   7. FORMULAIRES — Labels et erreurs
   ============================================================ */
input,
select,
textarea {
    font-size: 1rem;
    min-height: 44px;
    padding: 10px 14px;
    border: 2px solid #ced4da;
    border-radius: 6px;
}

input:focus,
select:focus,
textarea:focus {
    border-color: #198754;
    box-shadow: 0 0 0 3px rgba(25, 135, 84, 0.15);
}

/* Champs obligatoires : indicateur visuel */
input[required]::after,
select[required]::after,
textarea[required]::after {
    content: " *";
    color: #a71d2a;
}

/* Labels */
label {
    font-weight: 600;
    margin-bottom: 6px;
    display: inline-block;
}

/* Messages d'erreur */
.form-error,
.invalid-feedback {
    color: #a71d2a;
    font-weight: 500;
    font-size: 0.9rem;
}

/* ============================================================
   8. UTILITAIRES — Visually hidden (lecteurs d'écran uniquement)
   ============================================================ */
.visually-hidden,
.sr-only {
    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: 0 !important;
}

/* Focusable sr-only (skip link) */
.sr-only-focusable:focus {
    position: static !important;
    width: auto !important;
    height: auto !important;
    overflow: visible !important;
    clip: auto !important;
    white-space: normal !important;
}

/* ============================================================
   9. MOUVEMENT — Réduire les 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;
    }
    
    .fade-in,
    .slide-up,
    .scale-in {
        opacity: 1 !important;
        transform: none !important;
    }
}

/* ============================================================
   10. NAVIGATION — Menu accessible
   ============================================================ */
.navbar-toggler:focus-visible {
    outline: 3px solid #ffc107;
    outline-offset: 2px;
}

/* Menu ouvert : indiquer l'état */
.nav-collapse[aria-hidden="true"] {
    display: none;
}

/* Menu mobile : plein écran */
@media (max-width: 991px) {
    .nav-collapse.show {
        max-height: 100vh;
        overflow-y: auto;
    }
}

/* ============================================================
   11. LIENS EXTERNES — Indicateur visuel
   ============================================================ */
a[target="_blank"]:not([aria-label])::after {
    content: " ↗";
    font-size: 0.8em;
    opacity: 0.7;
    margin-left: 2px;
}

/* Ne pas ajouter la flèche si un aria-label est présent */
a[target="_blank"][aria-label]::after {
    content: none;
}

/* ============================================================
   12. TABLEAUX — Accessibles
   ============================================================ */
table {
    border-collapse: collapse;
    width: 100%;
}

table caption {
    font-weight: 700;
    text-align: left;
    padding: 10px 0;
    color: var(--color-text);
}

table th {
    text-align: left;
    font-weight: 700;
    background: #f8f9fa;
    padding: 10px;
}

table td,
table th {
    padding: 10px;
    border-bottom: 1px solid #dee2e6;
}

/* ============================================================
   13. TITRES — Hiérarchie et lisibilité
   ============================================================ */
h1, h2, h3, h4, h5, h6 {
    line-height: 1.3;
    color: var(--color-text);
    /* margin-top: 1.5rem; */
    /* margin-bottom: 0.75rem; */
}

h1 { font-size: 2rem; font-weight: 800; }
h2 { font-size: 1.6rem; font-weight: 700; }
h3 { font-size: 1.3rem; font-weight: 700; }
h4 { font-size: 1.15rem; font-weight: 600; }

/* Ancres invisibles pour les titres (bonus SEO) */
h1[id], h2[id], h3[id] {
    scroll-margin-top: 100px;
}

/* ============================================================
   14. BOUTON RETOUR EN HAUT — Accessible
   ============================================================ */
#back-to-top {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: #03A9F4;
    color: #fff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: all 0.3s ease;
    z-index: 9998;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

#back-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

#back-to-top:hover {
    background: #00BCD4;
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}

#back-to-top:focus-visible {
    outline: 3px solid #ffc107;
    outline-offset: 3px;
}

[dir="rtl"] #back-to-top {
    right: auto;
    left: 30px;
}

/* ============================================================
   15. BANDEAU COOKIES — Accessible
   ============================================================ */
.cookie-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background: #fff;
    border-top: 3px solid #198754;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
    padding: 20px;
    transition: transform 0.4s ease, opacity 0.4s ease;
    font-family: 'Inter', 'Tajawal', sans-serif;
}

.cookie-banner[hidden] {
    display: none;
}

.cookie-banner.cookie-banner--hidden {
    transform: translateY(100%);
    opacity: 0;
    pointer-events: none;
}

.cookie-banner:focus-visible {
    outline: 3px solid #ffc107;
    outline-offset: -3px;
}

.cookie-banner__content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 25px;
    flex-wrap: wrap;
}

.cookie-banner__text {
    flex: 1 1 500px;
}

.cookie-banner__title {
    margin: 0 0 6px 0;
    font-size: 1.1rem;
    color: #1b5e20;
    font-weight: 700;
}

.cookie-banner__message {
    margin: 0;
    font-size: 0.92rem;
    color: #212529;
    line-height: 1.5;
}

.cookie-banner__link {
    color: #146c43;
    text-decoration: underline;
    font-weight: 500;
}

.cookie-banner__link:hover {
    color: #0a3622;
}

.cookie-banner__actions {
    display: flex;
    gap: 12px;
    flex-shrink: 0;
}

.cookie-btn {
    padding: 12px 24px;
    border-radius: 25px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s ease;
    white-space: nowrap;
    min-height: 44px;
}

.cookie-btn--accept {
    background: #198754;
    color: #fff;
    border-color: #198754;
}

.cookie-btn--accept:hover {
    background: #146c43;
    border-color: #146c43;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(25, 135, 84, 0.3);
}

.cookie-btn--refuse {
    background: transparent;
    color: #495057;
    border-color: #6c757d;
}

.cookie-btn--refuse:hover {
    background: #f8f9fa;
    border-color: #495057;
    color: #212529;
}

.cookie-btn:focus-visible {
    outline: 3px solid #ffc107;
    outline-offset: 2px;
}

/* ============================================================
   16. RTL — Support arabe
   ============================================================ */
[dir="rtl"] body {
    font-family: 'Tajawal', 'Noto Sans Arabic', 'Inter', sans-serif;
}

[dir="rtl"] .skip-link {
    border-radius: 0 0 8px 8px;
}

[dir="rtl"] .cookie-banner__actions {
    flex-direction: row-reverse;
}

/* ============================================================
   17. RESPONSIVE — Mobile accessible
   ============================================================ */
@media (max-width: 768px) {
    body {
        font-size: 15px;
    }
    
    .cookie-banner {
        padding: 15px;
    }
    
    .cookie-banner__content {
        flex-direction: column;
        align-items: stretch;
        gap: 15px;
    }
    
    .cookie-banner__actions {
        flex-direction: column-reverse;
    }
    
    .cookie-btn {
        width: 100%;
        padding: 14px;
    }
    
    #back-to-top {
        width: 44px;
        height: 44px;
        bottom: 20px;
        right: 20px;
    }
    
    [dir="rtl"] #back-to-top {
        left: 20px;
        right: auto;
    }
}

/* ============================================================
   18. IMPRESSION — Version imprimable accessible
   ============================================================ */
@media print {
    .skip-link,
    #back-to-top,
    .cookie-banner,
    .navbar-toggler,
    .social-icons,
    .nav-search,
    .nav-language {
        display: none !important;
    }
    
    body {
        font-size: 12pt;
        color: #000;
        background: #fff;
    }
    
    a {
        color: #000;
        text-decoration: underline;
    }
    
    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 0.85em;
        color: #555;
    }
}

/* ============================================================
   19. HIGH CONTRAST MODE — Windows
   ============================================================ */
@media (prefers-contrast: high) {
    body {
        color: #000;
        background: #fff;
    }
    
    a {
        color: #0000ee;
        text-decoration: underline;
    }
    
    button,
    .btn {
        border: 2px solid #000;
    }
    
    *:focus-visible {
        outline: 3px solid #000;
        outline-offset: 3px;
    }
}

/* ============================================================
   20. DARK MODE — Support système
   ============================================================ */
@media (prefers-color-scheme: dark) {
    /* Optionnel : si tu actives un dark mode plus tard */
    /* Pas activé par défaut pour éviter les conflits */
}

[dir="rtl"] .bs-phone {
    direction: ltr;
}

/* ============================================================
   FIN — accessibility.css
   ============================================================ */