/* ═══════════════════════════════════════════════════════════════════════════════════════════════
   DTISoft — Écrans « Pilotage » (lot 1, 2026-10-27) : tableau de bord, qualité des données, composants communs.
   Préfixes : pil- (écrans), kpi- (tuiles), stat- (période, filtres, détail, confirmation, tableaux),
              chart- (graphiques SVG de js/chart-svg.js), dq- (qualité des données).
   Couleurs dérivées de la palette de css/style.css (l'application n'a pas de thème sombre).
   §7.16 : .module-wrap = height 100 % + overflow hidden ⇒ défilement INTERNE (.pil-contenu, listes).
   §7.41 : [hidden] repassé en (0,2,0) dans chaque conteneur (des classes déclarent display).
   ═══════════════════════════════════════════════════════════════════════════════════════════════ */
:root {
    --chart-1: var(--blue-mid, #1e5bb5);
    --chart-2: var(--orange, #f97316);
    --chart-3: #0f766e;
    --chart-4: #7c3aed;
    --chart-grille: var(--gray-200, #e2e8f0);
    --chart-zero: var(--gray-400, #94a3b8);
    --chart-texte: var(--gray-500, #64748b);
    --pil-bord: var(--gray-200, #e2e8f0);
    --pil-hausse-fond: #dcfce7; --pil-hausse: #166534;
    --pil-baisse-fond: #fee2e2; --pil-baisse: #991b1b;
    --pil-alerte: #d97706; --pil-ok: #16a34a;
}

.pil-wrap [hidden], .stat-detail-overlay [hidden], .stat-periode [hidden], .stat-confirm-overlay [hidden] { display: none; }

/* ── Écran ── */
.pil-wrap { background: var(--gray-100); }
.pil-tete {
    display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap;
    padding: 10px 16px 8px; background: var(--white); border-bottom: 1px solid var(--pil-bord); flex: 0 0 auto;
}
.pil-titres { min-width: 0; }
.pil-titre { font-size: 17px; font-weight: 700; color: var(--blue-dark); display: flex; align-items: center; gap: 8px; }
.pil-sous { font-size: 12px; color: var(--gray-500); margin-top: 2px; }
.stat-couverture { font-size: 12px; color: var(--gray-500); text-align: right; }
.stat-couverture:not(:empty)::before { content: "\25CF"; color: var(--pil-ok); margin-right: 6px; font-size: 9px; vertical-align: 1px; }
.pil-barre {
    display: flex; align-items: flex-end; gap: 10px 14px; flex-wrap: wrap; flex: 0 0 auto;
    padding: 8px 16px; background: var(--white); border-bottom: 1px solid var(--pil-bord);
}
.pil-actualiser { margin-left: auto; }
.pil-contenu { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 12px 16px 24px; }
.pil-wrap--charge .pil-contenu > :not(.pil-etat) { opacity: .55; transition: opacity .15s; }
.pil-etat {
    padding: 8px 12px; margin-bottom: 12px; background: var(--white); border: 1px solid var(--pil-bord);
    border-radius: 6px; color: var(--gray-500); font-size: 12.5px;
}
.pil-etat--erreur { color: #991b1b; background: #fef2f2; border-color: #fecaca; }
.pil-erreur { padding: 24px; color: #991b1b; }
.pil-vide { padding: 18px 8px; text-align: center; color: var(--gray-400); font-size: 12.5px; }
.pil-note { font-size: 11.5px; color: var(--gray-500); margin-top: 6px; line-height: 1.45; }
.pil-note--pied { margin-top: 4px; }

/* ── Champs : période, filtres, boutons ── */
.stat-periode, .stat-filtres { display: flex; align-items: flex-end; gap: 8px 12px; flex-wrap: wrap; min-width: 0; }
.stat-periode-champ, .stat-filtre { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat-periode-lib, .stat-filtre-lib { font-size: 11px; color: var(--gray-500); font-weight: 600; }
.stat-filtre--case { flex-direction: row; align-items: center; gap: 6px; font-size: 12px; color: var(--gray-700); padding-bottom: 6px; cursor: pointer; }
.stat-periode-resume { font-size: 11.5px; color: var(--gray-500); padding-bottom: 7px; }
.stat-input {
    height: 28px; padding: 2px 6px; font: inherit; font-size: 12.5px; color: var(--gray-700);
    border: 1px solid var(--gray-300); border-radius: 4px; background: var(--white); max-width: 230px;
}
.stat-input:focus { outline: 2px solid var(--blue-light); outline-offset: -1px; border-color: var(--blue-light); }
.stat-input:disabled { background: var(--gray-50); color: var(--gray-400); }
.stat-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 28px; padding: 0 12px;
    background: var(--white); border: 1px solid var(--gray-300); border-radius: 4px; font-size: 12.5px; color: #475569;
    white-space: nowrap; cursor: pointer;
}
.stat-btn:hover:not(:disabled) { background: var(--gray-100); border-color: var(--gray-400); }
.stat-btn:focus-visible { outline: 2px solid var(--blue-light); outline-offset: 1px; }
.stat-btn:disabled { opacity: .5; cursor: default; }
.stat-btn--primaire { background: #2563eb; border-color: #2563eb; color: #fff; }
.stat-btn--primaire:hover:not(:disabled) { background: #1d4ed8; border-color: #1d4ed8; }
.stat-btn--danger { background: #fff; border-color: #fca5a5; color: #b91c1c; }
.stat-btn--danger:hover:not(:disabled) { background: #fef2f2; border-color: #f87171; }
.stat-btn--icone { width: 28px; padding: 0; color: var(--gray-500); }
.stat-btn .fa-file-excel { color: #15803d; }

/* ── Tuiles (kpi-) ── */
.kpi-grille { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 196px), 1fr)); gap: 12px; margin-bottom: 12px; }
.kpi-tuile {
    display: flex; flex-direction: column; gap: 3px; min-width: 0; padding: 12px 14px;
    background: var(--white); border: 1px solid var(--pil-bord); border-radius: 8px; box-shadow: var(--shadow-sm);
}
.kpi-lib { font-size: 13px; font-weight: 700; color: var(--gray-700); }
.kpi-periode { font-size: 11px; color: var(--gray-500); }
.kpi-valeur {
    font-size: 21px; font-weight: 700; color: var(--blue-dark); font-variant-numeric: tabular-nums;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 2px 0;
}
.kpi-comparaison { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 12px; }
.kpi-evol { display: inline-flex; align-items: center; gap: 4px; padding: 1px 7px; border-radius: 10px; font-weight: 700; font-size: 12px; white-space: nowrap; }
.kpi-evol--hausse { background: var(--pil-hausse-fond); color: var(--pil-hausse); }
.kpi-evol--baisse { background: var(--pil-baisse-fond); color: var(--pil-baisse); }
.kpi-evol--neutre { background: var(--gray-100); color: var(--gray-500); font-weight: 600; }
.kpi-n1 { font-size: 11.5px; color: var(--gray-500); }
.kpi-detail { font-size: 11.5px; color: var(--gray-500); }
.kpi-spark { margin-top: 4px; }

/* ── Cartes ── */
.pil-carte {
    background: var(--white); border: 1px solid var(--pil-bord); border-radius: 8px; padding: 12px 14px;
    margin-bottom: 12px; min-width: 0; box-shadow: var(--shadow-sm);
}
.pil-carte-tete { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 8px; }
.pil-carte-titres { flex: 1 1 auto; min-width: 0; }
.pil-carte-titre { flex: 1 1 auto; font-size: 14px; font-weight: 700; color: var(--blue-dark); }
.pil-carte-sous { font-size: 11.5px; color: var(--gray-500); margin-top: 1px; }
.pil-graphe { width: 100%; min-height: 200px; }
.pil-tops { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 12px; }
.pil-tops > .pil-carte { margin-bottom: 0; }

/* ── Tableaux ── */
.stat-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.stat-table th {
    text-align: left; font-weight: 600; color: var(--gray-500); background: var(--gray-50);
    padding: 6px 8px; border-bottom: 1px solid var(--pil-bord); white-space: nowrap;
}
.stat-table td { padding: 5px 8px; border-bottom: 1px solid var(--gray-100); color: var(--gray-700); vertical-align: top; }
.stat-table .stat-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat-table tbody tr:hover td { background: var(--blue-pale); }
.stat-table tbody tr:focus-visible { outline: 2px solid var(--blue-light); outline-offset: -2px; }
.stat-table tbody tr.stat-ligne--sel td { background: #bfdbfe; }
/* Colonnes chiffrées à leur largeur naturelle (width 1 %), le nom prend le reste (width 100 % + max-width 0 : il peut
   rétrécir) et s'affiche sur 2 lignes au plus. */
.pil-top-table { table-layout: auto; }
.pil-top-table .pil-rang { width: 24px; color: var(--gray-400); text-align: center; padding-left: 4px; padding-right: 4px; }
.pil-top-table th.stat-num, .pil-top-table td.stat-num { width: 1%; }
.pil-top-ligne { cursor: pointer; }
.pil-top-nom { width: 100%; max-width: 0; }
.pil-top-lib {
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
    white-space: normal; overflow-wrap: anywhere; line-height: 1.3;
}
.pil-top-code { font-size: 10.5px; color: var(--gray-400); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pil-top-barre { height: 3px; margin-top: 3px; background: var(--gray-100); border-radius: 2px; overflow: hidden; }
.pil-top-barre > span { display: block; height: 100%; background: var(--chart-1); opacity: .55; }

/* ── Graphiques (chart-) ── */
.chart-wrap { width: 100%; position: relative; }
.chart-svg { display: block; width: 100%; height: auto; overflow: visible; font-family: inherit; }
.chart-spark { display: block; }
.chart-etq { font-size: 11px; fill: var(--chart-texte); }
.chart-trait { stroke: var(--chart-grille); stroke-width: 1; }
.chart-zero { stroke: var(--chart-zero); stroke-width: 1; }
.chart-s0 { --c: var(--chart-1); }
.chart-s1 { --c: var(--chart-2); }
.chart-s2 { --c: var(--chart-3); }
.chart-s3 { --c: var(--chart-4); }
.chart-bar { fill: var(--c, var(--chart-1)); }
.chart-bar--partiel { fill-opacity: .38; stroke: var(--c, var(--chart-1)); stroke-width: 1; stroke-dasharray: 3 2; }
.chart-bar--clic { cursor: pointer; }
.chart-bar--clic:hover, .chart-bar--clic:focus { fill-opacity: .8; outline: none; stroke: var(--blue-dark); stroke-width: 1.5; }
.chart-ligne { fill: none; stroke: var(--c, var(--chart-2)); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-spark .chart-ligne { stroke-width: 1.5; }
.chart-point { fill: var(--white); stroke: var(--c, var(--chart-2)); stroke-width: 1.5; }
.chart-spark .chart-point { fill: var(--c, var(--chart-1)); stroke: none; }
.chart-legende { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 6px; font-size: 11.5px; color: var(--gray-500); }
.chart-legende-item { display: inline-flex; align-items: center; gap: 6px; }
.chart-pastille { display: inline-block; width: 11px; height: 11px; border-radius: 2px; background: var(--c, var(--chart-1)); }
.chart-pastille--ligne { height: 3px; width: 16px; border-radius: 2px; }
.chart-sr {
    position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* ── Détail d'une cellule (stat-detail-overlay, z-index 7900 en ligne : sous les fiches) ── */
.stat-detail-overlay {
    position: fixed; inset: 0; z-index: 7900; background: rgba(15, 23, 42, .45);
    display: flex; align-items: center; justify-content: center; padding: 16px;
}
.stat-detail {
    display: flex; flex-direction: column; width: min(1150px, 100%); max-height: 88vh; min-height: 0;
    background: var(--white); border-radius: 8px; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); overflow: hidden;
}
.stat-detail-tete { display: flex; align-items: flex-start; gap: 10px; padding: 12px 16px 8px; border-bottom: 1px solid var(--pil-bord); }
.stat-detail-titres { flex: 1 1 auto; min-width: 0; }
.stat-detail-titre { font-size: 15px; font-weight: 700; color: var(--blue-dark); overflow-wrap: anywhere; }
.stat-detail-sous { font-size: 12px; color: var(--gray-500); margin-top: 2px; }
.stat-detail-x { width: 28px; height: 28px; border-radius: 4px; color: var(--gray-500); flex: 0 0 auto; }
.stat-detail-x:hover { background: var(--gray-100); color: var(--gray-900); }
.stat-detail > .stat-couverture { text-align: left; padding: 6px 16px 0; }
.stat-detail-etat { padding: 14px 16px; color: var(--gray-500); font-size: 12.5px; }
.stat-detail-zone { flex: 1 1 auto; min-height: 0; overflow: auto; margin: 8px 16px 0; border: 1px solid var(--pil-bord); border-radius: 6px; }
.stat-detail-zone:empty { display: none; }
.stat-detail-zone .stat-table thead th, .dq-liste-zone .stat-table thead th { position: sticky; top: 0; z-index: 1; }
.stat-detail-zone tbody tr { cursor: pointer; }
.stat-detail-pied { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--pil-bord); margin-top: 8px; }
.stat-detail-info { flex: 1 1 auto; min-width: 0; font-size: 12px; color: var(--gray-500); }

/* ── Confirmation (stat-confirm-overlay, z-index 10600 en ligne) ── */
.stat-confirm-overlay { position: fixed; inset: 0; z-index: 10600; background: rgba(15, 23, 42, .45); display: flex; align-items: center; justify-content: center; padding: 16px; }
.stat-confirm { background: var(--white); border-radius: 8px; box-shadow: 0 20px 60px rgba(0, 0, 0, .4); width: min(560px, 100%); overflow: hidden; }
.stat-confirm-titre { padding: 12px 18px; background: #1e3a8a; color: #fff; font-size: 14px; font-weight: 700; }
.stat-confirm-titre--danger { background: #991b1b; }
.stat-confirm-texte { padding: 16px 20px; font-size: 13px; color: var(--gray-900); white-space: pre-line; line-height: 1.5; max-height: 50vh; overflow: auto; }
.stat-confirm-pied { display: flex; justify-content: flex-end; gap: 8px; padding: 0 20px 16px; }
.stat-toast {
    position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%); z-index: 11500; max-width: calc(100vw - 32px);
    padding: 9px 18px; border-radius: 8px; background: #1e293b; color: #fff; font-size: 13px; font-weight: 600; pointer-events: none;
}

/* ── Qualité des données (dq-) ── */
.dq-grille { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; margin-bottom: 12px; }
.dq-carte {
    display: flex; flex-direction: column; gap: 3px; min-width: 0; text-align: left; font: inherit; color: inherit;
    padding: 10px 12px; background: var(--white); border: 1px solid var(--pil-bord); border-left: 4px solid var(--pil-alerte);
    border-radius: 8px; box-shadow: var(--shadow-sm); cursor: pointer;
}
.dq-carte--ok { border-left-color: var(--pil-ok); }
.dq-carte:hover { box-shadow: var(--shadow-md); }
.dq-carte:focus-visible { outline: 2px solid var(--blue-light); outline-offset: 1px; }
.dq-carte--active { outline: 2px solid var(--blue-light); outline-offset: 1px; background: #f8fbff; }
.dq-titre { font-size: 13px; font-weight: 700; color: var(--gray-700); }
.dq-carte--alerte .dq-titre i { color: var(--pil-alerte); }
.dq-carte--ok .dq-titre i { color: var(--pil-ok); }
.dq-valeur { font-size: 18px; font-weight: 700; color: var(--blue-dark); font-variant-numeric: tabular-nums; }
.dq-montant { font-size: 12.5px; color: var(--gray-700); font-variant-numeric: tabular-nums; }
.dq-part { font-size: 12px; color: var(--gray-700); }
.dq-desc { font-size: 11.5px; color: var(--gray-500); line-height: 1.4; }
.dq-source { font-size: 10.5px; color: var(--gray-400); font-style: italic; margin-top: 2px; }
.dq-liste-zone { max-height: 420px; overflow: auto; border: 1px solid var(--pil-bord); border-radius: 6px; }
.dq-liste-zone:empty { display: none; }
.dq-liste-info { font-size: 11.5px; color: var(--gray-500); margin-top: 6px; }
.dq-ligne--doc { cursor: pointer; }
.dq-photo-etat { display: grid; grid-template-columns: minmax(150px, 210px) 1fr; gap: 4px 12px; font-size: 12.5px; }
.dq-photo-etat dt { color: var(--gray-500); font-weight: 600; }
.dq-photo-etat dd { color: var(--gray-700); min-width: 0; overflow-wrap: anywhere; }
.dq-progression { margin-top: 10px; padding: 8px 10px; background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 6px; font-size: 12.5px; color: var(--blue-dark); }
.dq-barre { height: 8px; margin-top: 6px; background: var(--gray-200); border-radius: 4px; overflow: hidden; }
.dq-barre > span { display: block; height: 100%; background: var(--blue-light); transition: width .4s; }
.dq-photo-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* ── Écran étroit ── */
@media (max-width: 760px) {
    .pil-tete { flex-direction: column; align-items: flex-start; }
    .stat-couverture { text-align: left; }
    .pil-barre, .pil-contenu { padding-left: 10px; padding-right: 10px; }
    .pil-actualiser { margin-left: 0; }
    .stat-input { max-width: 100%; }
    .kpi-valeur { font-size: 19px; }
    .stat-detail-overlay { padding: 0; }
    .stat-detail { max-height: 100vh; height: 100%; border-radius: 0; }
    .dq-photo-etat { grid-template-columns: 1fr; }
}

/* ── Impression ── */
@media print {
    .pil-wrap { height: auto; overflow: visible; }
    .pil-contenu { overflow: visible; }
    .pil-barre, .pil-actualiser, .stat-btn, .stat-detail-x { display: none !important; }
    .pil-carte, .kpi-tuile, .dq-carte { break-inside: avoid; box-shadow: none; }
    .chart-svg, .kpi-evol, .pil-top-barre, .dq-carte { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ── DT-202 (2026-11-04) : filtre client / fournisseur (recherche), famille client, représentant ── */
.stat-tiers { position: relative; display: inline-flex; align-items: center; min-height: 28px; }
.stat-tiers-input { width: 170px; }
.stat-tiers-puce { display: inline-flex; align-items: center; gap: 4px; height: 28px; padding: 0 4px 0 8px; max-width: 230px;
    background: #e0e7ff; color: #1e3a8a; border-radius: 14px; font-size: 12px; white-space: nowrap; overflow: hidden; }
.stat-tiers-nom { overflow: hidden; text-overflow: ellipsis; }
.stat-tiers-x { border: 0; background: none; color: #1e3a8a; font-size: 15px; line-height: 1; cursor: pointer; padding: 0 4px; }
.stat-tiers-sugg { position: absolute; top: 100%; left: 0; z-index: 30; min-width: 280px; max-height: 280px; overflow: auto;
    background: var(--white); border: 1px solid var(--gray-300); border-radius: 4px; box-shadow: 0 6px 18px rgba(0,0,0,.12); }
.stat-tiers-item { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 6px 10px; font-size: 12.5px; cursor: pointer; }
.stat-tiers-item:hover, .stat-tiers-item:focus { background: #eef2ff; }
.stat-tiers-vide { padding: 6px 10px; font-size: 12.5px; color: var(--gray-500); }

/* DT-202 : graphique de plus de 25 barres : défilement dans le cadre */
.pil-graphe.pil-graphe--long { max-height: 560px; overflow-y: auto; }
.pil-an-nbgraphe { margin-left: auto; }
/* DT-202 : classement de plus de 12 lignes (accueil) : défilement dans la carte */
.pil-top-defil { max-height: 460px; overflow-y: auto; }
