/* =====================================================================================
   M1 — RÉFLEXION SUR MARGE. Tout est borné à `.marge` : aucune règle ne peut fuir sur un
   autre écran. ⚠️ La leçon est fraîche (T-UI) : styler un conteneur PARTAGÉ — .btn-filtres,
   .crud-toolbar-actions — a cassé deux fois des écrans que la tranche ne touchait pas.
   Couleurs = tokens :root uniquement, zéro hex en dur.
   ===================================================================================== */

/* ---------- bandeau « document interne » ---------- */
.marge .marge-interne {
    display: flex; align-items: center; gap: 8px;
    background: var(--amber-soft); color: var(--amber);
    border: 1px solid var(--amber); border-radius: 10px;
    padding: 8px 12px; font-size: 12.5px; font-weight: 600; margin-bottom: 14px;
}

/* ---------- barre de filtres ---------- */
.marge .marge-filtres { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px; }
.marge .marge-filtre { display: flex; flex-direction: column; gap: 4px; }
.marge .marge-filtre > select,
.marge .marge-filtre > input { min-width: 150px; }
.marge .marge-seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.marge .marge-seg button {
    border: 0; background: var(--surface); color: var(--slate);
    padding: 7px 13px; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.marge .marge-seg button + button { border-left: 1px solid var(--line); }
.marge .marge-seg button.actif { background: var(--teal); color: #fff; }

/* ---------- la CASCADE : 3 tuiles enchaînées ---------- */
.marge .marge-cascade { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 14px 0; }
.marge .marge-kpi {
    background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
    padding: 14px 16px; position: relative;
}
.marge .marge-kpi::before {
    content: ""; position: absolute; left: 0; top: 12px; bottom: 12px;
    width: 3px; border-radius: 3px; background: var(--teal);
}
.marge .marge-kpi-lbl { font-size: 11.5px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .06em; color: var(--slate); }
.marge .marge-kpi-val { font-family: Sora, sans-serif; font-size: 24px; font-weight: 700;
    color: var(--ink); font-variant-numeric: tabular-nums; margin-top: 4px; }
.marge .marge-kpi-taux { font-size: 12.5px; color: var(--slate); font-variant-numeric: tabular-nums; }
/* ⚠️ ROUGE SI NÉGATIF — une marge négative doit se voir sans lire le signe. */
.marge .marge-kpi.negatif::before { background: var(--red); }
.marge .marge-kpi.negatif .marge-kpi-val,
.marge .marge-kpi.negatif .marge-kpi-taux { color: var(--red); }
.marge .marge-kpi.grise { opacity: .6; }
.marge .marge-kpi.grise::before { background: var(--slate); }

/* ---------- bandeau d'alerte « vendus à perte » ---------- */
.marge .marge-alerte { border-radius: 10px; padding: 9px 13px; font-size: 13px; font-weight: 600; margin-bottom: 12px; }
.marge .marge-alerte.rouge { background: var(--red-soft); color: var(--red); }
.marge .marge-alerte.vert { background: var(--green-soft); color: var(--green); }

/* ---------- variation N-1 ---------- */
.marge .marge-var { font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.marge .marge-var.pos { color: var(--green); }
.marge .marge-var.neg { color: var(--red); }
.marge .marge-var.nul { color: var(--slate); font-weight: 500; }

/* ---------- blocs de pied (charges / prélèvements / exclues) ---------- */
.marge .marge-blocs { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin-top: 14px; }
.marge .marge-bloc { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.marge .marge-bloc h3 { font-size: 11.5px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .06em; color: var(--slate); margin: 0 0 8px; }
.marge .marge-poste { display: flex; justify-content: space-between; gap: 10px;
    font-size: 13px; padding: 3px 0; font-variant-numeric: tabular-nums; }
.marge .marge-poste.total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 7px; font-weight: 700; }
.marge .marge-bloc.grise { opacity: .72; }
.marge .marge-bloc-note { font-size: 11.5px; color: var(--slate); margin-top: 8px; line-height: 1.45; }

/* ---------- tableau ---------- */
.marge .marge-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.marge .marge-table th {
    position: sticky; top: 0;              /* ⚠️ 0 et NON 64px : le tableau vit dans un conteneur
                                              de défilement (overflow-x), donc sticky se cale sur
                                              LUI. Un 64px cacherait la 1re ligne EN PERMANENCE —
                                              c'est le défaut des 46 états, retour terrain n°1. */
    background: var(--thead-bg); z-index: 2;
    font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
    color: var(--slate); text-align: left; padding: 9px 10px; white-space: nowrap;
    box-shadow: inset 0 -1px 0 var(--line);
}
.marge .marge-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.marge .marge-table tbody tr:hover { background: var(--thead-bg); }
.marge .marge-num { text-align: right; font-variant-numeric: tabular-nums; }
.marge .marge-neg { color: var(--red); font-weight: 600; }
.marge .marge-table tfoot td { font-weight: 700; border-top: 2px solid var(--line);
    background: var(--paper); font-variant-numeric: tabular-nums; }
.marge .marge-scroll { overflow-x: auto; }

/* point mort — 3 états (WinDev R6) */
.marge .pm { display: inline-block; border-radius: 6px; padding: 2px 8px; font-weight: 600; font-size: 12px; }
.marge .pm-na { background: var(--red-soft); color: var(--red); }
.marge .pm-non { background: var(--amber-soft); color: var(--amber); }
.marge .pm-ok { background: var(--green-soft); color: var(--green); }

/* ---------- MOBILE : lisible, sans promettre le desktop ---------- */
@media (max-width: 768px) {
    .marge .marge-cascade { grid-template-columns: 1fr; }
    .marge .marge-filtres { flex-direction: column; align-items: stretch; }
    .marge .marge-filtre > select,
    .marge .marge-filtre > input { width: 100%; min-width: 0; }
    .marge .marge-seg { width: 100%; }
    .marge .marge-seg button { flex: 1 1 auto; }
    /* ⚠️ On ne convertit PAS le tableau en cartes : 18 colonnes de contrôle de gestion en cartes
       seraient illisibles. Il défile horizontalement, et l'écran le DIT. */
    .marge .marge-mobile-note { display: block; }
}
.marge .marge-mobile-note { display: none; font-size: 12px; color: var(--slate); margin-bottom: 8px; }
