/**
 * Agenda public des formations — [apaba_agenda_formations].
 *
 * Valeurs relevées au getComputedStyle sur /ressources-techniques/ (module de référence
 * visuelle) : panneau #f8f9fa filet #e5e7eb rayon 12, champ h36 fond #f5f0e9 filet #ccc rayon 6,
 * carte filet #e5e7eb rayon 12 ombre 0 1px 2px rgba(0,0,0,.04), visuel 180px. Rien n'est
 * approximé à l'œil.
 *
 * ⚠️ Préfixe --ag- obligatoire. Redéclarer un nom --apaba-* ici masquerait les globaux du thème
 * dans tout le sous-arbre (piège déjà présent dans formations.css, l.390).
 * Tailles en px : le thème agrikole impose html{font-size:62.5%}.
 */

.apaba-ag {
    --ag-teal: #1a8781;
    --ag-teal-fonce: #14655f;
    /* Stop foncé du héros de la fiche formation (formations.css, --apaba-primary-dark) :
       l'étiquette sans visuel doit porter EXACTEMENT le même dégradé, pas un voisin. */
    --ag-teal-profond: #0f5f5a;
    --ag-teal-tint: #e6f2f0;
    --ag-olive: #404a3d;
    --ag-texte: #3c4139;
    --ag-gris: #6c7266;
    --ag-filet: #e5e7eb;
    --ag-panneau: #f8f9fa;
    --ag-champ: #f5f0e9;
    --ag-champ-filet: #cccccc;
    --ag-vert: #33702c;
    --ag-serif: "Bookman Old Style", Georgia, "Times New Roman", serif;
    --ag-sans: "Barlow", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 12.5px;
    align-items: start;
    font-family: var(--ag-sans);
    color: var(--ag-texte);
    font-size: 16px;
    line-height: 1.55;
}

.apaba-ag *,
.apaba-ag *::before,
.apaba-ag *::after {
    box-sizing: border-box;
}

/* --- Rail de filtres (desktop). Les <select> de la barre sont son equivalent mobile : un seul
       des deux jeux est affiche a la fois, cf le palier 900 px en bas de fichier. --- */

.apaba-ag-rail {
    position: sticky;
    top: 12px;
    display: flex;
    flex-direction: column;
    gap: 12.5px;
}

.apaba-ag-panel {
    background: var(--ag-panneau);
    border: 1px solid var(--ag-filet);
    border-radius: 12px;
    padding: 10px;
}

.apaba-ag-panel-titre {
    font-family: var(--ag-serif);
    font-size: 24px;
    line-height: 30px;
    font-weight: 700;
    color: var(--ag-olive);
    margin: 2.5px 0 5px;
}

.apaba-ag-groupe {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.apaba-ag-btn {
    font-family: var(--ag-sans);
    font-size: 20px;
    font-weight: 500;
    line-height: 1.3;
    display: block;
    width: 100%;
    text-align: left;
    cursor: pointer;
    background: #fff !important;
    border: 1px solid var(--ag-filet) !important;
    border-radius: 10px !important;
    padding: 6px 8px !important;
    color: var(--ag-olive) !important;
    transition: border-color .15s, background .15s, color .15s;
}

.apaba-ag-btn:hover {
    border-color: var(--ag-teal) !important;
}

/* Poids 600 : à 20px le bouton passe le seuil « grand texte » (3:1), ce qui rend le teal de
   marque conforme — blanc sur #1a8781 ne fait que 4,35:1, sous le seuil du texte courant. */
.apaba-ag-btn[aria-pressed="true"] {
    background: var(--ag-teal) !important;
    border-color: var(--ag-teal) !important;
    color: #fff !important;
    font-weight: 600;
}

/* --- Bandeau catalogue, sous la liste. Pleine largeur : il n'est plus dans un rail de
       260 px, donc le libellé et l'affordance tiennent sur une ligne. --- */

.apaba-ag-cat {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 22px;
    padding: 12px 14px;
    text-decoration: none !important;
    color: var(--ag-texte) !important;
    transition: border-color .15s ease, background-color .15s ease;
}

.apaba-ag-cat:hover,
.apaba-ag-cat:focus-visible {
    background: #fff;
    border-color: var(--ag-teal);
}

.apaba-ag-cat > .apaba-ag-ico {
    width: 26px;
    height: 26px;
    flex: 0 0 26px;
    opacity: 1;
    color: var(--ag-teal);
}

.apaba-ag-cat-txt {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1 1 240px;
}

/* Affordance de téléchargement : un <span>, jamais un <button> — le bandeau est déjà le lien. */
.apaba-ag-cat-action {
    flex: none;
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 15px;
    font-weight: 600;
    color: var(--ag-teal-fonce);
    background: #fff;
    border: 1px solid var(--ag-teal);
    border-radius: 10px;
    padding: 5px 12px;
    white-space: nowrap;
    transition: background .15s, color .15s, gap .15s;
}

.apaba-ag-cat-action .apaba-ag-ico {
    width: 15px;
    height: 15px;
    opacity: 1;
}

.apaba-ag-cat:hover .apaba-ag-cat-action,
.apaba-ag-cat:focus-visible .apaba-ag-cat-action {
    background: var(--ag-teal);
    color: #fff;
    gap: 8px;
}

.apaba-ag-cat-sur {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--ag-teal);
}

.apaba-ag-cat-titre {
    font-size: 17px;
    font-weight: 600;
    line-height: 1.25;
}

.apaba-ag-cat-note {
    font-size: 14px;
    color: var(--ag-gris);
}

/* --- Barre : recherche, filtres, compteur --- */

.apaba-ag-barre {
    display: flex;
    gap: 10px 14px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

/* 420 px : la largeur relevee sur le module de reference, inchangee depuis la v1.38.0.
   `min-width: 0` laisse le champ retrecir sous sa largeur intrinseque quand la place manque. */
.apaba-ag-cherche {
    flex: 0 1 420px;
    min-width: 0;
}

/* Equivalent MOBILE du rail : masque tant que le rail est la, revele au palier 900 px.
   Un seul conteneur, deux selects sur la meme ligne — la pile de boutons du rail, elle,
   faisait la hauteur d'un ecran sur un telephone. */
.apaba-ag-filtres {
    display: none;
    flex: 1 1 100%;
    min-width: 0;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.apaba-ag-filtre {
    min-width: 0;
}

.apaba-ag-select {
    font-family: var(--ag-sans) !important;
    font-size: 15px !important;
    font-weight: 500;
    color: var(--ag-texte) !important;
    width: 100%;
    max-width: 100%;
    height: 36px;
    line-height: 1.2;
    background-color: var(--ag-champ) !important;
    border: 1px solid var(--ag-champ-filet) !important;
    border-radius: 6px !important;
    padding: 4px 30px 4px 8px !important;
    margin: 0 !important;
    cursor: pointer;
    text-overflow: ellipsis;
    /* Chevron dessine ici : le theme agrikole ne fournit aucune fleche une fois
       `appearance: none` pose, et le select serait alors indiscernable du champ de recherche. */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23404a3d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 9px center !important;
    background-size: 16px 16px !important;
    transition: border-color .15s, color .15s;
}

.apaba-ag-select:hover {
    border-color: var(--ag-teal) !important;
}

/* Filtre actif : la classe est posee par le JS, un select ne se distingue pas autrement d'un
   select au repos une fois referme. */
.apaba-ag-select-actif {
    border-color: var(--ag-teal) !important;
    color: var(--ag-teal-fonce) !important;
    font-weight: 600;
}

.apaba-ag-recherche {
    font-family: var(--ag-sans) !important;
    font-size: 15px !important;
    font-weight: 500;
    color: var(--ag-texte) !important;
    width: 100%;
    max-width: 100%;
    height: 36px;
    background: var(--ag-champ) !important;
    border: 1px solid var(--ag-champ-filet) !important;
    border-radius: 6px !important;
    padding: 4px 8px !important;
    margin: 0 !important;
}

/* Le thème remet outline:0 sur TOUT input[type=search], pas seulement au focus (parent
   agrikole/style.css, « Reset search styling ») — plus spécifique que :focus-visible seul dans
   certains contextes (focus programmatique). :focus en plus de :focus-visible, en dur. */
.apaba-ag-recherche:focus {
    outline: 2px solid var(--ag-teal) !important;
    outline-offset: 2px;
}

.apaba-ag-recherche::placeholder {
    color: #878986;
}

.apaba-ag-compte {
    margin: 0;
    font-size: 15px;
    color: var(--ag-gris);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.apaba-ag-compte b {
    color: var(--ag-olive);
    font-weight: 700;
}

/* --- Mois --- */

.apaba-ag-mois + .apaba-ag-mois {
    margin-top: 26px;
}

/* Le thème pose `section{display:block}` en dur (shim HTML5, parent agrikole/style.css) — règle
   AUTEUR qui bat [hidden]{display:none} de l'agent utilisateur quelle que soit la spécificité.
   Même piège que .apaba-ag-carte[hidden] ci-dessous, sur l'élément qui les groupe. */
.apaba-ag-mois[hidden] {
    display: none;
}

.apaba-ag-mois-tete {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0 0 8px;
}

.apaba-ag-mois-titre {
    font-family: var(--ag-serif);
    font-size: 24px;
    line-height: 30px;
    font-weight: 700;
    color: var(--ag-olive);
    margin: 0;
    text-transform: capitalize;
    white-space: nowrap;
}

.apaba-ag-mois-titre span {
    color: var(--ag-gris);
    font-weight: 400;
}

.apaba-ag-filet {
    flex: 1;
    height: 1px;
    background: var(--ag-filet);
}

.apaba-ag-mois-n {
    font-size: 14px;
    color: var(--ag-gris);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* --- Cartes --- */

.apaba-ag-grille {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 10px;
}

.apaba-ag-carte {
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid var(--ag-filet);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
    text-decoration: none;
    color: inherit;
    transition: box-shadow .16s, border-color .16s, transform .16s;
}

/* `display: flex` ci-dessus est une règle AUTEUR : elle bat toujours [hidden]{display:none} de
   l'agent utilisateur, quelle que soit la spécificité — l'origine prime. Sans cette ligne, le JS
   de filtrage pose bien l'attribut `hidden` (les compteurs sont justes) mais la carte reste
   visible à l'écran. */
.apaba-ag-carte[hidden] {
    display: none;
}

.apaba-ag-carte:hover {
    box-shadow: 0 6px 18px rgba(43, 49, 40, .10);
    border-color: #d5d9d0;
    transform: translateY(-2px);
}

.apaba-ag-carte:focus-visible,
.apaba-ag-select:focus-visible,
.apaba-ag-recherche:focus-visible,
.apaba-ag-cat:focus-visible,
.apaba-ag-lien-bas:focus-visible {
    outline: 2px solid var(--ag-teal);
    outline-offset: 2px;
}

.apaba-ag-visuel {
    position: relative;
    display: block;
    background: #f4f4f2;
}

.apaba-ag-visuel img {
    width: 100%;
    height: 180px;
    object-fit: cover;
    display: block;
}

/* Sans visuel : le dégradé du héros de la fiche, avec le titre posé dessus.
   Les deux réserves sont des CONTRAINTES, pas du confort : les étiquettes de filière
   (haut-droite) et le badge de date (bas-gauche) sont en position absolue, donc le flux ne
   les voit pas et rien ne pousse le texte. En bas, 62 px couvrent le badge (8 + ~54). En
   haut, la pile d'étiquettes dépend de leur nombre : Adminapaba_Agenda::reserve_etiquettes()
   passe la valeur en --ag-vide-haut. */
.apaba-ag-visuel-vide {
    height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--ag-vide-haut, 38px) 16px 62px;
    overflow: hidden;
    background: linear-gradient(135deg, var(--ag-teal) 0%, var(--ag-teal-profond) 100%);
}

.apaba-ag-visuel-titre {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    /* Garde-fou exact : `overflow: hidden` du parent rogne à la boîte de padding et laisserait
       donc le texte mordre la réserve. Le plafond de lignes ci-dessous est calé sur la bande
       d'une seule étiquette ; celui-ci reprend la main quand il y en a deux. */
    max-height: calc(180px - var(--ag-vide-haut, 38px) - 62px);
    font-family: var(--ag-serif);
    font-weight: 600;
    color: #fff;
    text-align: center;
    text-wrap: balance;
    overflow-wrap: break-word;
    text-shadow: 0 1px 3px rgba(0, 0, 0, .28);
}

/* Quatre paliers, choisis en PHP par Adminapaba_Agenda::palier_titre() sur le nombre de
   caractères, et calés sur la colonne la plus étroite de la grille (280 px, ~248 px de texte).
   corps x plafond tient dans les 80 px de la bande à une étiquette. Le plafond est un filet :
   il ne se déclenche sur aucun titre du CPT (23 à 119 caractères). */
.apaba-ag-visuel-titre-xl {
    font-size: 24px;
    line-height: 28px;
    -webkit-line-clamp: 2;
}

.apaba-ag-visuel-titre-l {
    font-size: 20px;
    line-height: 24px;
    -webkit-line-clamp: 3;
}

.apaba-ag-visuel-titre-m {
    font-size: 16px;
    line-height: 20px;
    -webkit-line-clamp: 4;
}

.apaba-ag-visuel-titre-s {
    font-size: 14px;
    line-height: 17px;
    -webkit-line-clamp: 4;
}

.apaba-ag-date {
    position: absolute;
    left: 8px;
    bottom: 8px;
    display: block;
    background: #fff;
    border-radius: 8px;
    padding: 5px 9px;
    text-align: center;
    line-height: 1;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .18);
}

.apaba-ag-date-j {
    display: block;
    font-size: 25px;
    font-weight: 700;
    color: var(--ag-olive);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.apaba-ag-date-j i {
    font-style: normal;
    font-weight: 500;
    color: var(--ag-gris);
}

.apaba-ag-date-m {
    display: block;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .11em;
    text-transform: uppercase;
    color: var(--ag-teal-fonce);
    margin-top: 3px;
}

.apaba-ag-etiquettes {
    position: absolute;
    right: 8px;
    top: 8px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

/* Ombre portée : sans elle l'étiquette se perd sur un ciel clair. */
.apaba-ag-etiquette {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .05em;
    text-transform: uppercase;
    line-height: 1;
    padding: 5px 10px;
    border-radius: 999px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .28);
    background: var(--ag-fond);
    color: var(--ag-encre);
}

.apaba-ag-titre {
    display: block;
    font-family: var(--ag-serif);
    font-size: 20px;
    line-height: 25px;
    font-weight: 600;
    color: var(--ag-olive);
    padding: 7.5px 7.5px 0;
}

.apaba-ag-desc {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 15px;
    line-height: 1.5;
    color: var(--ag-texte);
    padding: 6px 7.5px 0;
}

.apaba-ag-desc-vide {
    color: var(--ag-gris);
    font-style: italic;
    -webkit-line-clamp: 2;
}

.apaba-ag-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 7.5px 7.5px;
    margin-top: auto;
    font-size: 14.5px;
    line-height: 1.5;
    color: var(--ag-gris);
}

.apaba-ag-meta > span {
    display: flex;
    align-items: center;
    gap: 6px;
}

.apaba-ag-ico {
    width: 13px;
    height: 13px;
    flex: none;
    opacity: .8;
}

.apaba-ag-type {
    font-weight: 600;
    color: var(--ag-olive);
}

.apaba-ag-type i {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: block;
    flex: none;
    background: var(--ag-teal-fonce);
}

.apaba-ag-type[data-rencontre="1"] i {
    background: var(--ag-vert);
}

.apaba-ag-pied {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    border-top: 1px solid var(--ag-filet);
    margin-top: 5px;
    padding-top: 6px;
}

.apaba-ag-tarif {
    font-size: 18px;
    font-weight: 700;
    color: var(--ag-olive);
    font-variant-numeric: tabular-nums;
}

.apaba-ag-voir {
    font-size: 14px;
    font-weight: 600;
    color: var(--ag-teal-fonce);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    transition: gap .15s;
}

.apaba-ag-carte:hover .apaba-ag-voir {
    gap: 7px;
}

/* --- États --- */

.apaba-ag-vide {
    border: 1px dashed var(--ag-filet);
    border-radius: 12px;
    padding: 44px 20px;
    text-align: center;
    color: var(--ag-gris);
    margin: 0;
}

.apaba-ag-bas {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-top: 22px;
}

.apaba-ag-lien-bas {
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    background: #fff;
    border: 1px solid var(--ag-teal);
    color: var(--ag-teal);
    border-radius: 10px;
    padding: 6px 14px;
    display: inline-block;
    transition: background .15s, color .15s;
}

.apaba-ag-lien-bas:hover {
    background: var(--ag-teal);
    color: #fff;
}

.apaba-ag-modalites {
    margin: 0;
    font-size: 15px;
    color: var(--ag-gris);
}

.apaba-ag-modalites a {
    color: var(--ag-teal-fonce);
    font-weight: 600;
    text-decoration: none;
    border-bottom: 1px solid transparent;
}

.apaba-ag-modalites a:hover {
    border-bottom-color: currentColor;
}

/* Palier historique du rail. En dessous, le rail sort du flux ET de l'arbre d'accessibilite
   (`display: none`, pas `visibility`) : sans ca, deux jeux de commandes pour un meme filtre
   seraient annonces au lecteur d'ecran. Les selects prennent le relais. */
@media (max-width: 900px) {
    .apaba-ag {
        grid-template-columns: 1fr;
    }

    .apaba-ag-rail {
        display: none;
    }

    .apaba-ag-filtres {
        display: grid;
    }

    .apaba-ag-cherche {
        flex: 1 1 100%;
    }

    /* Une fois le bandeau catalogue enroule, `margin-left: auto` collerait l'affordance au bord
       droit, seule sur sa ligne : elle se range sous le texte. */
    .apaba-ag-cat-action {
        margin-left: 0;
    }
}

/* La grille de cartes descend a une colonne bien avant 280 px de large : sans ce palier, une
   carte de 280 px deborde un viewport de 320 px une fois les marges du theme comptees. */
@media (max-width: 400px) {
    .apaba-ag-grille {
        grid-template-columns: 1fr;
    }

    .apaba-ag-mois-tete {
        gap: 8px;
    }

    .apaba-ag-mois-titre {
        font-size: 21px;
        line-height: 26px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .apaba-ag * {
        transition: none !important;
    }
}
