/* ═══════════════════════════════════════════════════════════════════════════════════════════════
   DTISoft — Écrans « Pilotage » du lot 3 (2026-10-27) : ventes, achats, marges.
   Préfixes : pil-an- (écran d'analyse, js/stat-analyse.js), stat-tc- (tableau croisé, js/stat-tableau.js).
   S'appuie sur css/pilotage.css (lot 1 : pil-wrap, pil-barre, pil-contenu, stat-btn, stat-input, kpi-, chart-).
   §7.16 : défilement INTERNE (.pil-contenu, .stat-tc-zone) ; §7.41 : [hidden] repassé en (0,2,0).
   ═══════════════════════════════════════════════════════════════════════════════════════════════ */
.pil-an [hidden], .stat-tc [hidden] { display: none; }

.stat-btn--petit { height: 24px; padding: 0 8px; font-size: 11.5px; }

/* ── Barre, panneau « Personnaliser », filtres actifs ── */
.pil-an-rapport .stat-input { max-width: 320px; min-width: 220px; }
.pil-an-desc { margin: 0 0 10px; font-size: 12.5px; color: var(--gray-700); line-height: 1.45; }
.pil-an-desc:empty { display: none; }
.pil-an-panneau {
    flex: 0 0 auto; padding: 10px 16px; background: #f8fbff; border-bottom: 1px solid var(--pil-bord);
    max-height: 45vh; overflow-y: auto;
}
.pil-an-pgrille { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: flex-start; }
.pil-an-bloc {
    display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: flex-end; min-width: 0; margin: 0;
    padding: 6px 10px 8px; border: 1px solid var(--pil-bord); border-radius: 6px; background: var(--white);
}
.pil-an-bloc legend { font-size: 11.5px; font-weight: 700; color: var(--gray-500); padding: 0 4px; }
.pil-an-bloc .pil-note { flex-basis: 100%; margin: 2px 0 0; }
.pil-an-bloc--mesures { max-width: 560px; }
.pil-an-case { padding-bottom: 0; min-width: 150px; }
.pil-an-num { width: 72px; }
.pil-an-nom { width: 220px; }
.pil-an-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.pil-an-puces {
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px; flex: 0 0 auto;
    padding: 6px 16px; background: #fffbeb; border-bottom: 1px solid #fde68a; font-size: 12px;
}
.pil-an-puces-lib { font-weight: 700; color: #92400e; }
.pil-an-puce {
    display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 8px; font: inherit; font-size: 12px;
    color: #78350f; background: #fef3c7; border: 1px solid #fcd34d; border-radius: 12px; cursor: pointer; max-width: 360px;
}
.pil-an-puce span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pil-an-puce:hover, .pil-an-puce:focus-visible { background: #fde68a; outline: none; }

/* ── Cartes ── */
.pil-an-tableau .pil-carte-tete { align-items: center; flex-wrap: wrap; }
.pil-an-recherche { display: inline-flex; align-items: center; gap: 6px; color: var(--gray-400); }
.pil-an-recherche .stat-input { width: 220px; }
.pil-an-synthese { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); gap: 12px; margin-bottom: 12px; }
.pil-an-abc { border-left: 4px solid var(--gray-300); }
.pil-an-abc--A { border-left-color: #15803d; }
.pil-an-abc--B { border-left-color: #d97706; }
.pil-an-abc--C { border-left-color: #94a3b8; }
.pil-an-notes { margin: 8px 0 0; padding-left: 18px; font-size: 11.5px; color: var(--gray-500); line-height: 1.5; }
.pil-an-notes li { margin: 1px 0; }

/* ── Tableau croisé (stat-tc-) ── */
.stat-tc { display: flex; flex-direction: column; min-width: 0; }
.stat-tc-outils { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-bottom: 6px; }
.stat-tc-info { font-size: 11.5px; color: #92400e; }
.stat-tc-etat { padding: 10px; color: var(--gray-500); font-size: 12.5px; }
.stat-tc-etat--erreur { color: #991b1b; }
/* Défilement INTERNE dans les deux sens : en-tête collé en haut, total collé en bas, libellés collés à gauche. */
.stat-tc-zone { overflow: auto; max-height: min(64vh, 720px); border: 1px solid var(--pil-bord); border-radius: 6px; background: var(--white); }
.stat-tc-table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 12px; }
.stat-tc-table th, .stat-tc-table td { padding: 4px 8px; border-bottom: 1px solid var(--gray-100); white-space: nowrap; }
.stat-tc-table thead th {
    position: sticky; top: 0; z-index: 3; background: var(--gray-50); color: var(--gray-500); font-weight: 600;
    border-bottom: 1px solid var(--pil-bord); vertical-align: bottom; text-align: right;
}
.stat-tc-table thead th.stat-tc-lib { text-align: left; z-index: 4; left: 0; }
.stat-tc-table tfoot th, .stat-tc-table tfoot td {
    position: sticky; bottom: 0; z-index: 2; background: #eef2ff; font-weight: 700; color: var(--blue-dark);
    border-top: 2px solid #c7d2fe; border-bottom: 0;
}
.stat-tc-table tfoot th.stat-tc-lib { z-index: 3; left: 0; text-align: left; }
.stat-tc-table .stat-num { text-align: right; font-variant-numeric: tabular-nums; }
.stat-tc-table td.stat-tc-lib {
    position: sticky; left: 0; z-index: 1; background: var(--white); min-width: 240px; max-width: 420px;
    white-space: normal; border-right: 1px solid var(--gray-100);
}
.stat-tc-trier {
    display: inline-flex; flex-direction: column; align-items: flex-end; gap: 0; background: none; border: 0; padding: 0;
    font: inherit; color: inherit; cursor: pointer; text-align: right; position: relative; padding-right: 14px;
}
.stat-tc-trier:focus-visible { outline: 2px solid var(--blue-light); outline-offset: 2px; }
.stat-tc-icotri { position: absolute; right: 0; top: 2px; font-size: 10px; color: var(--gray-400); }
th[aria-sort="ascending"] .stat-tc-icotri, th[aria-sort="descending"] .stat-tc-icotri { color: var(--blue-mid, #1e5bb5); }
.stat-tc-ent { font-weight: 700; color: var(--gray-700); }
.stat-tc-ent-sous { font-size: 10.5px; font-weight: 400; color: var(--gray-400); }
.stat-tc-libbox { display: flex; align-items: flex-start; gap: 4px; min-width: 0; }
.stat-tc-tog {
    flex: 0 0 auto; width: 18px; height: 18px; padding: 0; border: 0; background: none; color: var(--gray-500);
    cursor: pointer; border-radius: 3px; line-height: 18px;
}
.stat-tc-tog:hover { background: var(--gray-100); color: var(--blue-dark); }
.stat-tc-tog-vide { flex: 0 0 18px; }
.stat-tc-libtxt { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; }
.stat-tc-lib1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-tc-lib2 { font-size: 10.5px; color: var(--gray-400); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-tc-dont { font-style: italic; color: var(--gray-500); }
.stat-tc-filtre {
    flex: 0 0 auto; width: 20px; height: 20px; padding: 0; border: 0; background: none; color: var(--gray-300);
    cursor: pointer; border-radius: 3px; opacity: 0; transition: opacity .1s;
}
.stat-tc-table tr:hover .stat-tc-filtre, .stat-tc-table tr:focus-within .stat-tc-filtre, .stat-tc-filtre:focus-visible { opacity: 1; }
.stat-tc-filtre:hover { color: #b45309; background: #fef3c7; }
/* Niveaux : la ligne parente est le sous-total de ses enfants. */
.stat-tc-l0.stat-tc-parent td { font-weight: 700; background: #f8fafc; }
.stat-tc-l0.stat-tc-parent td.stat-tc-lib { background: #f8fafc; }
.stat-tc-l1.stat-tc-parent td { font-weight: 600; }
.stat-tc-l1 td.stat-tc-lib, .stat-tc-l2 td.stat-tc-lib, .stat-tc-l3 td.stat-tc-lib { color: var(--gray-700); }
.stat-tc-ldont td { color: var(--gray-500); font-style: italic; font-weight: 400 !important; }
.stat-tc-table tbody tr:hover td, .stat-tc-table tbody tr:hover td.stat-tc-lib { background: var(--blue-pale); }
.stat-tc-table tbody tr:focus { outline: none; }
.stat-tc-table tbody tr:focus-visible td { box-shadow: inset 0 2px 0 var(--blue-light), inset 0 -2px 0 var(--blue-light); }
.stat-tc-clic { cursor: pointer; }
.stat-tc-clic:hover { text-decoration: underline; color: var(--blue-dark); }
.stat-tc-neg { color: #b91c1c; }
.stat-tc-pos { color: #15803d; }
.stat-tc-centre { text-align: center !important; }
.stat-tc-absent { color: var(--gray-300); }
.stat-tc-special td { color: var(--gray-500); font-style: italic; font-size: 11.5px; background: var(--white); }
.stat-tc-erreur td { color: #991b1b; font-style: normal; }
.stat-tc-vide { padding: 18px 8px; text-align: center; color: var(--gray-400); }
.stat-tc-badge {
    display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 9px; font-size: 11px; font-weight: 700;
    line-height: 18px; text-align: center; color: #fff; background: #94a3b8;
}
.stat-tc-badge--A { background: #15803d; }
.stat-tc-badge--B { background: #d97706; }
.stat-tc-badge--C { background: #94a3b8; }
.stat-tc-pied { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-top: 8px; font-size: 12px; color: var(--gray-500); }
.stat-tc-nav { display: inline-flex; align-items: center; gap: 4px; }
.stat-tc-page { padding: 0 6px; color: var(--gray-700); }
.stat-tc-taille { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; }
.stat-tc-taille .stat-input { width: 72px; }

/* ── Écran étroit ── */
@media (max-width: 760px) {
    .pil-an-rapport .stat-input { min-width: 0; max-width: 100%; }
    .pil-an-panneau, .pil-an-puces { padding-left: 10px; padding-right: 10px; }
    .stat-tc-table td.stat-tc-lib { min-width: 160px; max-width: 220px; }
    .pil-an-recherche .stat-input { width: 150px; }
    .stat-tc-zone { max-height: 70vh; }
}

/* ── Impression ── */
@media print {
    .pil-an-panneau, .pil-an-recherche, .stat-tc-outils, .stat-tc-pied, .stat-tc-filtre, .stat-tc-tog { display: none !important; }
    .stat-tc-zone { max-height: none; overflow: visible; border: 0; }
    .stat-tc-table thead th, .stat-tc-table tfoot th, .stat-tc-table tfoot td, .stat-tc-table td.stat-tc-lib { position: static; }
    .stat-tc-badge, .stat-tc-neg, .stat-tc-pos { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
