/*
 * Charte inspirée des sites de branches sgdf.fr :
 * Raleway (titres), Sarabun (texte), Caveat Brush (accents manuscrits),
 * bleu chefs-cadres #003a5d, fond #e5ebee, angles droits, palettes de branches.
 */
:root {
    /* Chefs & cadres */
    --sgdf-bleu: #003a5d;
    --sgdf-bleu-light: #005487;
    --sgdf-bleu-vif: #186dbc;
    --sgdf-fond: #e5ebee;

    /* Branches : base / foncé / encre (texte lisible sur fond clair) */
    --farfadets: #61bd98;  --farfadets-dark: #23ab87;  --farfadets-ink: #006d3e;
    --lj: #ee7f00;         --lj-dark: #c95b00;         --lj-ink: #a04800;
    --sg: #0069b2;         --sg-dark: #00508a;         --sg-ink: #00508a;
    --pc: #c22e16;         --pc-dark: #a52612;         --pc-ink: #a52612;
    --compagnons: #006d3e; --compagnons-dark: #005430; --compagnons-ink: #005430;
    --audace: #6e3c8f;     --audace-dark: #55296f;     --audace-ink: #55296f;
    --impeesa: #7a6a58;    --impeesa-dark: #5a4c3d;    --impeesa-ink: #5a4c3d;

    --bs-primary: var(--sgdf-bleu);
    --bs-primary-rgb: 0, 58, 93;
    --bs-link-color: var(--sg);
    --bs-link-color-rgb: 0, 105, 178;
    --bs-link-hover-color: var(--sgdf-bleu);
    --bs-body-font-family: "Sarabun", "Helvetica Neue", Arial, sans-serif;
    --bs-body-color: #1b2a35;
    --bs-border-radius: .2rem;
    --bs-border-radius-sm: .15rem;
    --bs-border-radius-lg: .25rem;
    --bs-border-color: #d3dce1;
}

body { background: var(--sgdf-fond); }
h1, h2, h3, h4, h5, h6, .navbar-brand, .btn, .nav-link, .badge-b, th, dt, .fw-semibold { font-family: "Raleway", sans-serif; }
h1, h2, h3, h4, h5, h6 { color: var(--sgdf-bleu); font-weight: 800; }
.manuscrit { font-family: "Caveat Brush", cursive; font-weight: 400; letter-spacing: .01em; }
a { text-decoration-thickness: 1px; text-underline-offset: 2px; }

/* En-tête */
.bg-sgdf { background: var(--sgdf-bleu); }
.navbar { padding-top: .6rem; padding-bottom: .6rem; }
.navbar-brand { font-weight: 900; text-transform: uppercase; letter-spacing: .03em; font-size: 1.05rem; }
.navbar-brand small { font-family: "Caveat Brush", cursive; text-transform: none; font-weight: 400; font-size: 1.05rem; opacity: .85; letter-spacing: 0; }
.navbar-dark .nav-link { font-weight: 600; font-size: .92rem; color: rgba(255, 255, 255, .85); }
.navbar-dark .nav-link.active, .navbar-dark .nav-link:hover { color: #fff; }
.navbar-dark .nav-link.active { box-shadow: inset 0 -3px 0 var(--lj); }
.dropdown-menu { border-radius: 0; border: 0; box-shadow: 0 6px 18px rgba(0, 58, 93, .18); font-family: "Raleway", sans-serif; font-size: .92rem; }
.dropdown-item:active { background: var(--sgdf-bleu); }

/* Bandeau aux couleurs des branches */
.bandeau-branches { display: flex; height: 5px; }
.bandeau-branches span { flex: 1; }
.bandeau-branches span:nth-child(1) { background: var(--farfadets); }
.bandeau-branches span:nth-child(2) { background: var(--lj); }
.bandeau-branches span:nth-child(3) { background: var(--sg); }
.bandeau-branches span:nth-child(4) { background: var(--pc); }
.bandeau-branches span:nth-child(5) { background: var(--compagnons); }
.bandeau-branches span:nth-child(6) { background: var(--sgdf-bleu-vif); }

/* Page de connexion */
.auth-page { background: radial-gradient(circle at 30% 20%, var(--sgdf-bleu-light) 0%, var(--sgdf-bleu) 70%); min-height: 100vh; }
.auth-page h1 { color: #fff; font-weight: 900; text-transform: uppercase; letter-spacing: .04em; }
.auth-page .card { border-top: 5px solid var(--lj); }

/* Titres de page */
.page-header { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; }
.page-header h1 { margin: 0; font-size: 1.55rem; font-weight: 900; text-transform: uppercase; letter-spacing: .02em; }
.page-header h1::after { content: ""; display: block; width: 3rem; height: 4px; margin-top: .35rem; background: var(--accent, var(--lj)); }

/* Composants */
.card { border: 0; border-radius: 0; box-shadow: 0 1px 2px rgba(0, 58, 93, .08); }
.card-img-top { border-radius: 0; }
.btn { font-weight: 700; border-radius: 0; }
.btn-primary { --bs-btn-bg: var(--sgdf-bleu); --bs-btn-border-color: var(--sgdf-bleu); --bs-btn-hover-bg: var(--sgdf-bleu-light); --bs-btn-hover-border-color: var(--sgdf-bleu-light); --bs-btn-active-bg: var(--sgdf-bleu-light); --bs-btn-disabled-bg: var(--sgdf-bleu); --bs-btn-disabled-border-color: var(--sgdf-bleu); }
.btn-outline-primary { --bs-btn-color: var(--sgdf-bleu); --bs-btn-border-color: var(--sgdf-bleu); --bs-btn-hover-bg: var(--sgdf-bleu); --bs-btn-hover-border-color: var(--sgdf-bleu); --bs-btn-active-bg: var(--sgdf-bleu); --bs-btn-active-border-color: var(--sgdf-bleu); }
.form-control, .form-select, .input-group-text { border-radius: 0; }
.form-control:focus, .form-select:focus { border-color: var(--sg); box-shadow: 0 0 0 .2rem rgba(0, 105, 178, .2); }
.form-check-input:checked { background-color: var(--sgdf-bleu); border-color: var(--sgdf-bleu); }
.nav-tabs .nav-link { color: var(--sgdf-bleu); }
.nav-tabs .nav-link.active { border-top: 3px solid var(--lj); }
.nav-pills .nav-link { border-radius: 0; color: var(--sgdf-bleu); }
.nav-pills .nav-link.active { background: var(--sgdf-bleu); }
.alert { border-radius: 0; border: 0; border-left: 4px solid; }
.alert-success { border-left-color: var(--compagnons); }
.alert-info { border-left-color: var(--sg); }
.alert-warning { border-left-color: var(--lj); }
.alert-danger { border-left-color: var(--pc); }
.list-group, .list-group-item, .accordion, .accordion-item, .modal-content, .progress { border-radius: 0 !important; }
.accordion-button:not(.collapsed) { background: #eef3f6; color: var(--sgdf-bleu); box-shadow: none; }
.table > thead th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--sgdf-bleu); border-bottom-width: 2px; }
.table td, .table th { vertical-align: middle; }
.small-muted { font-size: .88rem; color: #5b6b77; }
textarea { min-height: 90px; }
footer { color: #5b6b77; }

/* Tuiles de l'accueil, chacune dans une couleur de branche */
.tile { border-top: 5px solid var(--t, var(--sgdf-bleu)); transition: transform .12s ease, box-shadow .12s ease; }
.tile:hover { transform: translateY(-3px); box-shadow: 0 6px 16px rgba(0, 58, 93, .15); }
.tile .bi { font-size: 2rem; color: var(--t, var(--sgdf-bleu)); }
.tile .tile-titre { font-family: "Raleway", sans-serif; color: var(--sgdf-bleu); font-weight: 800 !important; text-transform: uppercase; font-size: .9rem; letter-spacing: .03em; }

/* ---- Badges de couleur ---- */
.b-farfadets  { --b: var(--farfadets);  --b-ink: var(--farfadets-ink);  --b-on: #00351f; }
.b-lj         { --b: var(--lj);         --b-ink: var(--lj-ink);         --b-on: #fff; }
.b-sg         { --b: var(--sg);         --b-ink: var(--sg-ink);         --b-on: #fff; }
.b-pc         { --b: var(--pc);         --b-ink: var(--pc-ink);         --b-on: #fff; }
.b-compagnons { --b: var(--compagnons); --b-ink: var(--compagnons-ink); --b-on: #fff; }
.b-audace     { --b: var(--audace);     --b-ink: var(--audace-ink);     --b-on: #fff; }
.b-impeesa    { --b: var(--impeesa);    --b-ink: var(--impeesa-ink);    --b-on: #fff; }
.b-groupe     { --b: var(--sgdf-bleu-light); --b-ink: var(--sgdf-bleu); --b-on: #fff; }
.b-territoire { --b: var(--sgdf-bleu);  --b-ink: var(--sgdf-bleu);      --b-on: #fff; }
.b-neutre     { --b: #8a99a4;           --b-ink: #3d4b55;               --b-on: #fff; }

/* Badge clair : fond teinté + liseré + texte foncé (lisible quelle que soit la branche) */
.badge-b {
    display: inline-block; padding: .22em .55em .2em; font-size: .76rem; font-weight: 700; line-height: 1.25;
    color: var(--b-ink); background: color-mix(in srgb, var(--b) 15%, #fff); border-left: 3px solid var(--b);
    white-space: normal; vertical-align: middle; margin: 1px 0;
}
/* Badge plein */
.badge-b.plein { color: var(--b-on); background: var(--b); border-left-color: var(--b); }
.badge-b.pastille { border-left: 0; border-radius: 1rem; padding: .25em .7em; }
.legend-dot { display: inline-block; width: .8rem; height: .8rem; border-radius: 50%; margin-right: .3rem; vertical-align: middle; background: var(--b, #8a99a4); }
.bordure-branche { border-left: 4px solid var(--b, var(--sgdf-bleu)); }

/* Annuaire */
.contact-card { border-top: 4px solid var(--b, var(--sgdf-bleu)); }
.contact-card .card-title { font-size: 1.02rem; margin-bottom: .35rem; font-weight: 800; }
.contact-card .card-title a { color: var(--sgdf-bleu); text-decoration: none; }
.contact-card .fonctions { display: flex; flex-wrap: wrap; gap: .25rem; margin-bottom: .25rem; }
.coord { font-size: .9rem; }
.coord .bi { width: 1.2rem; color: #5b6b77; }

/* Organigramme par pôles : zones successives, personnes réparties de façon compacte */
.orga { display: flex; flex-direction: column; align-items: center; gap: 2.2rem; padding-bottom: 2rem; }
.orga-pole {
    position: relative; width: 100%; max-width: 1200px; padding: 1.1rem 1.25rem 1.4rem;
    background: color-mix(in srgb, var(--b) 7%, #fff); border-top: 5px solid var(--b);
    box-shadow: 0 1px 3px rgba(0, 58, 93, .08);
}
/* Trait reliant les zones successives */
.orga-pole + .orga-pole::before {
    content: ""; position: absolute; left: 50%; top: calc(-2.2rem - 5px); height: 2.2rem; border-left: 2px dashed #9fb2bf;
}
.orga-entete { text-align: center; margin-bottom: 1rem; }
.orga-entete h2 { font-size: 1.15rem; font-weight: 900; text-transform: uppercase; letter-spacing: .04em; color: var(--b-ink); margin: 0; }
.orga-entete p { font-size: .9rem; color: #4b5967; margin: .25rem auto 0; max-width: 720px; }

.orga-membres { display: flex; flex-wrap: wrap; justify-content: center; gap: .9rem; margin: 0 auto; }
.orga-grille { max-width: calc(var(--cols) * 176px + (var(--cols) - 1) * .9rem); }

.orga-carte {
    position: relative; width: 176px; min-height: 132px; padding: 1.75rem .7rem .7rem; margin-top: 18px;
    display: flex; flex-direction: column; align-items: center; text-align: center; gap: .15rem;
    background: #fff; border: 0; border-bottom: 3px solid var(--b); box-shadow: 0 2px 6px rgba(0, 58, 93, .12);
    cursor: pointer; transition: transform .12s ease, box-shadow .12s ease; color: inherit; font: inherit;
}
.orga-carte:hover, .orga-carte:focus-visible { transform: translateY(-3px); box-shadow: 0 6px 16px rgba(0, 58, 93, .22); outline: none; }
.orga-avatar {
    position: absolute; top: -18px; left: 50%; transform: translateX(-50%); width: 40px; height: 40px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; border: 3px solid #fff;
    background: var(--b); color: var(--b-on); font-family: "Raleway", sans-serif; font-weight: 800; font-size: .85rem;
}
.orga-fonction { font-family: "Raleway", sans-serif; font-weight: 800; font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; color: var(--b-ink); line-height: 1.2; }
.orga-nom { font-family: "Raleway", sans-serif; font-weight: 700; font-size: .92rem; color: var(--sgdf-bleu); line-height: 1.2; }
.orga-nom.vacant { color: #8a99a4; font-style: italic; font-weight: 600; }
.orga-mission { font-size: .78rem; color: #5b6b77; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* Disposition en cercle (positions calculées côté serveur) */
.orga-cercle { position: relative; margin: 0 auto; max-width: 100%; }
.orga-cercle .orga-carte { position: absolute; margin: 0; transform: translate(-50%, -50%); }
.orga-cercle .orga-carte:hover, .orga-cercle .orga-carte:focus-visible { transform: translate(-50%, calc(-50% - 3px)); }
.orga-centre {
    position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 150px; height: 150px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; text-align: center; padding: 1rem;
    background: var(--b); color: var(--b-on); font-family: "Raleway", sans-serif; font-weight: 900; font-size: .85rem; text-transform: uppercase;
    box-shadow: 0 0 0 8px color-mix(in srgb, var(--b) 20%, #fff);
}
/* Écrans étroits : le cercle redevient une liste compacte */
@media (max-width: 991.98px) {
    .orga-cercle { width: auto !important; height: auto !important; display: flex; flex-wrap: wrap; justify-content: center; gap: .9rem; }
    .orga-cercle .orga-carte { position: relative; left: auto !important; top: auto !important; transform: none; margin-top: 18px; }
    .orga-cercle .orga-carte:hover { transform: translateY(-3px); }
    .orga-centre { display: none; }
}

/* Édition de l'organigramme */
.orga-edit-pole { border-top: 4px solid var(--b); }
.orga-edit-pole .poignee, .orga-edit-membre .poignee { cursor: grab; color: #8a99a4; }
.orga-edit-membres { min-height: 2.6rem; list-style: none; padding: 0; margin: 0; }
.orga-edit-membre { display: flex; align-items: center; gap: .5rem; padding: .35rem .5rem; margin-bottom: .3rem; background: #fff; border-left: 3px solid var(--b); box-shadow: 0 1px 2px rgba(0, 58, 93, .08); }
.orga-edit-membres:empty::after { content: "Glissez des personnes ici"; display: block; padding: .6rem; text-align: center; font-size: .85rem; color: #8a99a4; border: 2px dashed #c5d1d9; }
.sortable-ghost { opacity: .4; }

/* Cartes géographiques */
.map { height: 70vh; min-height: 420px; }
.map-small { height: 320px; }
.leaflet-popup-content { font-family: "Sarabun", sans-serif; }
.leaflet-popup-content strong { font-family: "Raleway", sans-serif; color: var(--sgdf-bleu); }
.leaflet-container a.leaflet-popup-close-button { color: var(--sgdf-bleu); }

/* Calendrier */
#calendar { background: #fff; padding: 1rem; }
#calendar .fc-toolbar-title { font-family: "Raleway", sans-serif; font-weight: 800; color: var(--sgdf-bleu); text-transform: capitalize; }
#calendar .fc-button-primary { background: var(--sgdf-bleu); border-color: var(--sgdf-bleu); border-radius: 0; font-family: "Raleway", sans-serif; font-weight: 700; }
#calendar .fc-button-primary:not(:disabled).fc-button-active, #calendar .fc-button-primary:hover { background: var(--sgdf-bleu-light); border-color: var(--sgdf-bleu-light); }
#calendar .fc-day-today { background: color-mix(in srgb, var(--lj) 10%, #fff); }
.fc-event { cursor: pointer; border-radius: 0; }

/* Matériel */
.materiel-photo { width: 100%; height: 160px; object-fit: cover; background: #dfe7ec; }
.materiel-photo.placeholder { display: flex; align-items: center; justify-content: center; font-size: 3rem; color: #9fb2bf; }

/* PSCAF */
.pscaf-kpi .pscaf-kpi-valeur { font-family: "Raleway", sans-serif; font-weight: 900; font-size: 1.9rem; color: var(--sgdf-bleu); line-height: 1.15; margin: .2rem 0; }
.pscaf-kpi .pscaf-kpi-valeur small { font-size: .95rem; font-weight: 700; color: #5b6b77; }
.pscaf-kpi-principal { background: var(--sgdf-bleu); color: #fff; }
.pscaf-kpi-principal .pscaf-kpi-valeur, .pscaf-kpi-principal .pscaf-kpi-valeur small { color: #fff; }
.pscaf-table-groupes tr.cliquable { cursor: pointer; }
/* Barre horizontale d'une seule série : extrémité arrondie de 4 px, valeur en encre de texte */
.pscaf-barre-h { display: flex; align-items: center; gap: .5rem; min-height: 22px; }
.pscaf-barre-h span { display: block; height: 12px; min-width: 2px; background: var(--sgdf-bleu); border-radius: 0 4px 4px 0; }
.pscaf-barre-h b { font-size: .85rem; color: #1b2a35; white-space: nowrap; }
/* Histogramme mensuel */
.pscaf-mois { display: flex; align-items: stretch; gap: 4px; min-height: 190px; }
.pscaf-mois-col { flex: 1 1 0; display: flex; flex-direction: column; min-width: 0; cursor: default; }
.pscaf-mois-zone { flex: 1; display: flex; align-items: flex-end; border-bottom: 1px solid #c5d1d9; }
.pscaf-mois-zone span { display: block; width: 100%; max-width: 34px; margin: 0 auto; background: var(--sgdf-bleu); border-radius: 4px 4px 0 0; min-height: 0; }
.pscaf-mois-col:hover .pscaf-mois-zone span { background: var(--sgdf-bleu-light); }
.pscaf-mois-label { font-size: .7rem; color: #5b6b77; text-align: center; padding-top: 3px; line-height: 1.15; }
/* Cartes d'unité et barre empilée retenu / non retenu (2 px d'écart entre segments) */
.pscaf-unite { border-top: 4px solid var(--b); }
.pscaf-unite:hover { box-shadow: 0 6px 16px rgba(0, 58, 93, .15); }
.pscaf-unite.hors-total { opacity: .7; }
.pscaf-unite-valeur { font-family: "Raleway", sans-serif; font-weight: 900; font-size: 1.5rem; color: var(--sgdf-bleu); margin: .4rem 0 .3rem; }
.pscaf-unite-valeur small { font-size: .8rem; font-weight: 600; color: #5b6b77; }
.pscaf-pile { display: flex; gap: 2px; height: 10px; }
.pscaf-pile span { display: block; height: 100%; }
.pscaf-pile .retenu { background: var(--sg); border-radius: 4px 0 0 4px; }
.pscaf-pile .exclu { background: var(--lj); border-radius: 0 4px 4px 0; }
.pscaf-pile span:only-child, .pscaf-pile .retenu[style*="width: 100%"] { border-radius: 4px; }
.pscaf-detail tr.exclue td { color: #6b7785; }
.pscaf-detail tr.exclue td.fw-semibold { text-decoration: line-through; text-decoration-color: #b8c3cf; }
.pscaf-detail thead th { position: sticky; top: 0; background: #fff; }
.pscaf-tip { position: fixed; z-index: 2000; pointer-events: none; background: #1b2a35; color: #fff; font-size: .8rem; padding: .3rem .55rem; max-width: 280px; box-shadow: 0 4px 12px rgba(0, 0, 0, .2); }

/* Déclarations PSCAF */
.decl-pile { display: flex; gap: 2px; height: 10px; background: #eef2f5; }
.decl-pile span { display: block; height: 100%; background: var(--b); }
.decl-pile span:first-child { border-radius: 4px 0 0 4px; }
.decl-pile span:last-child { border-radius: 0 4px 4px 0; }
.decl-etapes { display: flex; list-style: none; padding: 0; margin: 0; gap: .5rem; counter-reset: etape; flex-wrap: wrap; }
.decl-etapes li { flex: 1 1 200px; }
.decl-etapes a { display: flex; flex-direction: column; gap: .1rem; height: 100%; padding: .7rem .9rem .7rem 3.2rem; position: relative;
    background: #fff; border-top: 4px solid var(--b); color: inherit; text-decoration: none; box-shadow: 0 1px 2px rgba(0, 58, 93, .08); }
.decl-etapes li.en-cours a { box-shadow: 0 0 0 2px var(--b); }
.decl-pastille { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); width: 1.9rem; height: 1.9rem; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; background: var(--b); color: var(--b-on); }
.decl-etape { border-top: 4px solid var(--b); }
.decl-calcul { display: flex; flex-wrap: wrap; gap: 1rem 1.5rem; padding: .6rem .8rem; background: #f4f7f9; }
.decl-calcul strong { font-family: "Raleway", sans-serif; font-weight: 800; color: var(--sgdf-bleu); }
.bloc-justification .obligatoire { display: none; }
.bloc-justification.requise .obligatoire { display: inline; }
.bloc-justification.requise textarea { border-color: var(--pc); box-shadow: 0 0 0 .15rem rgba(194, 46, 22, .15); }
.decl-annulee { opacity: .75; background: repeating-linear-gradient(135deg, #fff 0 10px, #f4f6f8 10px 20px); }
.decl-etapes li.b-neutre a { opacity: .8; }

/* Environnement hors production, affiché dans l en-tête */
.badge-env { display: inline-block; padding: .15rem .5rem; background: var(--lj); color: #fff; font-family: "Raleway", sans-serif; font-weight: 900; font-size: .7rem; letter-spacing: .08em; }

/* Déclarations TAM : synthèse des groupes */
.tam-kpi-alerte { border-top: 4px solid var(--pc); }
.tam-kpi-alerte .pscaf-kpi-valeur { color: var(--pc-ink); }
.tam-matrice th, .tam-matrice td { white-space: nowrap; }
.tam-matrice td:first-child { white-space: normal; min-width: 12rem; }
.tam-matrice .tam-col-courante { background: color-mix(in srgb, var(--sg) 7%, transparent); }
.tam-points summary { cursor: pointer; list-style: none; }
.tam-points summary::-webkit-details-marker { display: none; }
.tam-points summary::before { content: "\F285"; font-family: "bootstrap-icons"; font-size: .8rem; color: #5b6b77; transition: transform .15s; }
.tam-points details[open] > summary::before { transform: rotate(90deg); }
.tam-equipes td, .tam-equipes th { white-space: nowrap; }
.tam-equipes thead th { vertical-align: bottom; }
/* Accueil : 7 tuiles sur une ligne en très grand écran (Bootstrap s'arrête à 6) */
@media (min-width: 1200px) { .row-cols-xl-7 > * { flex: 0 0 auto; width: 14.2857%; } }
