/*
 * TableauSYP — feuille de style autonome (reprise de Gestion AE, aux couleurs de SYPManager).
 * Variables modifiables pour adapter les couleurs au projet.
 */
:root {
  /* Couleurs SYPManager : noir, blanc, orange */
  --tsyp-bordure: #e2e2e2;
  --tsyp-discret: #6e6e6e;
  --tsyp-selection: var(--teal-l, #ffe7cf);
  --tsyp-survol: var(--teal-xl, #fff6ed);
  --tsyp-entete: #1b1b1b;
  --tsyp-entete-texte: #ffffff;
  --tsyp-entete-survol: #333333;
  --tsyp-accent: var(--teal, #f07c00);
  --tsyp-haut: 54px; /* hauteur de la barre du haut (en-tête fixe juste dessous) */
}

/* ---- Tableau de base */
.defilement { overflow: auto; max-height: 520px; }
.tableau { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tableau th { position: sticky; top: 0; text-align: left; padding: 9px 12px; white-space: nowrap; user-select: none; }
.tableau th[data-sens="asc"]::after { content: " ▲"; font-size: 10px; }
.tableau th[data-sens="desc"]::after { content: " ▼"; font-size: 10px; }
.tableau td { padding: 8px 12px; border-bottom: 1px solid #f0f2f6; vertical-align: top; white-space: nowrap; }
.tableau td.texte-long { white-space: normal; min-width: 220px; }
.tableau tbody tr:hover { background: var(--tsyp-survol); }
.tableau .nombre { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tableau tr.vide td { text-align: center; color: var(--tsyp-discret); padding: 22px; }
.tableau tbody tr.selection { background: var(--tsyp-selection); }

/* ---- Composant */
.tableau.tsyp th { color: var(--tsyp-entete-texte); font-weight: 700; font-size: 12.5px; background: var(--tsyp-entete); border-bottom: 2px solid var(--tsyp-accent); border-right: 1px solid #333; position: sticky; top: 0; z-index: 2; }
.tableau.tsyp thead th:last-child { border-right: 0; }
.tableau.tsyp th.tsyp-triable { cursor: pointer; }
.tableau.tsyp th.tsyp-triable:hover { background: var(--tsyp-entete-survol); }
.tableau.tsyp td { border-right: 1px solid #f0f2f6; }
.tableau.tsyp tbody tr:nth-child(even):not(.selection) { background: #fafafa; }
.tableau.tsyp tbody tr.selection, .tableau.tsyp tbody tr.selection:nth-child(even) { background: var(--tsyp-selection); }
.tableau.tsyp tbody td { cursor: default; }
.tableau.tsyp tbody td a, .tableau.tsyp tbody td input, .tableau.tsyp tbody td button, .tableau.tsyp tbody td select { cursor: pointer; }
.tableau.tsyp tbody td input[type=text], .tableau.tsyp tbody td textarea { cursor: text; }
.tableau.tsyp-fixe { table-layout: fixed; }
.tableau.tsyp-fixe td, .tableau.tsyp-fixe th { overflow: hidden; text-overflow: ellipsis; }
.tableau.tsyp:focus { outline: none; box-shadow: 0 0 0 2px color-mix(in srgb, var(--teal, #f07c00) 45%, transparent); }
.tableau.tsyp tbody tr.tsyp-courante td { box-shadow: inset 0 1px 0 var(--tsyp-accent), inset 0 -1px 0 var(--tsyp-accent); }
.tableau.tsyp tbody tr.tsyp-courante td:first-child { box-shadow: inset 2px 0 0 var(--tsyp-accent), inset 0 1px 0 var(--tsyp-accent), inset 0 -1px 0 var(--tsyp-accent); }
.tsyp-poignee { position: absolute; top: 0; right: -3px; width: 7px; height: 100%; cursor: col-resize; z-index: 3; }
.tsyp-poignee:hover, body.tsyp-redim .tsyp-poignee { background: color-mix(in srgb, var(--teal, #f07c00) 45%, transparent); }
body.tsyp-redim { cursor: col-resize; user-select: none; }
.tableau.tsyp tr.tsyp-filtres th { background: #2a2a2a; padding: 4px 6px; border-bottom: 1px solid #444; top: calc(var(--tsyp-haut) + 32px); }
.tableau.tsyp tr.tsyp-filtres input { width: 100%; min-width: 50px; padding: 3px 6px; font-size: 12px; font-weight: 400; border: 1px solid #555; border-radius: 4px; background: #fff; color: #161616; }
.tableau.tsyp tr.tsyp-aucune td { text-align: center; color: var(--tsyp-discret); padding: 18px; font-style: italic; }
.tableau.tsyp tfoot.tsyp-totaux td { position: sticky; bottom: 0; background: #f7f7f7; border-top: 2px solid var(--tsyp-accent); font-weight: 700; color: #161616; padding: 8px 12px; }
.tableau.tsyp tfoot .tsyp-libelle-total { text-align: left; }

/* ---- Barre au-dessus et pied sous le tableau */
.tsyp-barre { display: flex; align-items: center; gap: 6px; margin: 0 0 6px; flex-wrap: wrap; }
.tsyp-recherche { padding: 3px 8px; font-size: 12px; border: 1px solid #d6d6d6; border-radius: 4px; width: 180px; }
.tsyp-bouton { padding: 3px 9px; font-size: 12px; border: 1px solid #d6d6d6; border-radius: 4px; background: #fff; cursor: pointer; }
.tsyp-bouton:hover { background: var(--tsyp-survol); }
.tsyp-pied { display: flex; gap: 18px; align-items: center; padding: 6px 4px 0; font-size: 12px; color: var(--tsyp-discret); min-height: 22px; }
.tsyp-compte { min-width: 70px; }
.tsyp-position { font-variant-numeric: tabular-nums; }

/* ---- Menus clic droit / Colonnes */
.tsyp-menu { position: absolute; z-index: 1000; min-width: 220px; max-height: 70vh; overflow: auto; padding: 4px 0; background: #fff; border: 1px solid #d6d6d6; border-top: 3px solid var(--tsyp-accent); border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.18); font-size: 13px; }
.tsyp-menu button, .tsyp-menu label { display: flex; align-items: center; gap: 6px; width: 100%; padding: 6px 14px; border: 0; background: none; text-align: left; cursor: pointer; font: inherit; }
.tsyp-menu button:hover:not(:disabled), .tsyp-menu label:hover { background: var(--tsyp-survol); }
.tsyp-menu button:disabled { color: #aab; cursor: default; }
.tsyp-menu hr { margin: 4px 0; border: 0; border-top: 1px solid #e2e2e2; }

/* ---- Intégration SYPManager (tableaux .grid) */
table.grid.tsyp { background: #fff; }
table.grid.tsyp thead th { position: sticky; top: var(--tsyp-haut); }
.defilement table.grid.tsyp thead th, .table-scroll table.grid.tsyp thead th { top: 0; }
.defilement .tableau.tsyp tr.tsyp-filtres th, .table-scroll .tableau.tsyp tr.tsyp-filtres th, .defilement table.grid.tsyp tr.tsyp-filtres th { top: 32px; }
table.grid.tsyp tr.tsyp-filtres th { top: calc(var(--tsyp-haut) + 32px); background: #2a2a2a; padding: 4px 6px; }
table.grid.tsyp tr.tsyp-filtres input { width: 100%; min-width: 50px; padding: 3px 6px; font-size: 12px; font-weight: 400; border: 1px solid #555; border-radius: 4px; }
table.grid.tsyp th a { color: #fff; }
table.grid.tsyp th[data-sens="asc"]::after { content: " ▲"; font-size: 10px; color: var(--tsyp-accent); }
table.grid.tsyp th[data-sens="desc"]::after { content: " ▼"; font-size: 10px; color: var(--tsyp-accent); }
table.grid.tsyp th.tsyp-triable:hover { background: var(--tsyp-entete-survol); }
table.grid.tsyp tbody tr:hover { background: var(--tsyp-survol); }
table.grid.tsyp tbody tr.selection, table.grid.tsyp tbody tr.selection:nth-child(even), table.grid.tsyp tbody tr.selection:hover { background: var(--tsyp-selection) !important; }
table.grid.tsyp tbody tr.tsyp-courante td { box-shadow: inset 0 1px 0 var(--tsyp-accent), inset 0 -1px 0 var(--tsyp-accent); }
table.grid.tsyp tbody tr.tsyp-courante td:first-child { box-shadow: inset 3px 0 0 var(--tsyp-accent), inset 0 1px 0 var(--tsyp-accent), inset 0 -1px 0 var(--tsyp-accent); }
table.grid.tsyp th { position: sticky; }
table.grid.tsyp tfoot.tsyp-totaux td { position: sticky; bottom: 0; background: #f7f7f7; border-top: 2px solid var(--tsyp-accent); font-weight: 700; }
table.grid.tsyp tr.vide td, table.grid.tsyp tr.tsyp-aucune td { text-align: center; color: var(--tsyp-discret); font-style: italic; padding: 16px; }
table.grid.tsyp.tsyp-fixe td, table.grid.tsyp.tsyp-fixe th { overflow: hidden; text-overflow: ellipsis; }
table.grid.tsyp.tsyp-fixe { table-layout: fixed; }
.tsyp-barre .tsyp-bouton:hover { border-color: var(--tsyp-accent); }
.tsyp-recherche:focus { outline: none; border-color: var(--tsyp-accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--teal, #f07c00) 20%, transparent); }
.tsyp-pied { color: var(--tsyp-discret); }
table.clickable.tsyp tbody tr[data-href] { cursor: default; }
table.clickable.tsyp tbody tr[data-href] td { cursor: pointer; }
@media print { .tsyp-barre, .tsyp-pied { display: none !important; } }

/* ---- Zone de défilement (ascenseur vertical et horizontal) */
.defilement.tsyp-zone { max-height: calc(100vh - 250px); min-height: 220px; overflow: auto; border: 1px solid var(--tsyp-bordure); border-radius: 4px; background: #fff; }
.defilement.tsyp-zone::-webkit-scrollbar { width: 12px; height: 12px; }
.defilement.tsyp-zone::-webkit-scrollbar-thumb { background: #c9c9c9; border-radius: 6px; border: 2px solid #fff; }
.defilement.tsyp-zone::-webkit-scrollbar-thumb:hover { background: var(--tsyp-accent); }
.defilement.tsyp-zone { scrollbar-color: #c9c9c9 #fff; }
.defilement table.grid.tsyp tr.tsyp-filtres th { top: 33px; }
/* poignée de largeur visible au survol de l'en-tête */
table.grid.tsyp thead th:hover .tsyp-poignee { background: color-mix(in srgb, var(--teal, #f07c00) 35%, transparent); }
table.grid.tsyp:focus { outline: none; box-shadow: 0 0 0 2px color-mix(in srgb, var(--teal, #f07c00) 45%, transparent); }

/* ---- Pied : ligne courante et nombre d'éléments côte à côte ; totaux alignés */
.tsyp-pied { gap: 14px; }
.tsyp-pied .tsyp-elements { color: var(--tsyp-discret); }
.tsyp-pied .tsyp-elements::before { content: "·"; margin-right: 14px; color: #bbb; }
table.grid.tsyp tfoot.tsyp-totaux td.nombre { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---- Menus : alignement (indépendant des styles des formulaires de l'application) */
.tsyp-menu label, .tsyp-menu button { display: flex !important; flex-direction: row !important; align-items: center; justify-content: flex-start;
  gap: 8px; width: 100%; margin: 0; padding: 6px 14px; font-size: 13px; font-weight: 400; line-height: 1.3; color: #161616; text-align: left; white-space: nowrap; }
.tsyp-menu label input[type=checkbox] { width: auto; height: auto; margin: 0; flex: none; accent-color: var(--tsyp-accent); }
.tsyp-menu label:hover, .tsyp-menu button:hover:not(:disabled) { background: var(--tsyp-survol); }

/* ---- Déplacement des colonnes */
table.grid.tsyp thead th { cursor: grab; }
body.tsyp-deplace, body.tsyp-deplace * { cursor: grabbing !important; user-select: none; }
table.grid.tsyp th.tsyp-glisse { opacity: .55; }
table.grid.tsyp th.tsyp-cible-avant { box-shadow: inset 4px 0 0 var(--tsyp-accent); }
table.grid.tsyp th.tsyp-cible-apres { box-shadow: inset -4px 0 0 var(--tsyp-accent); }
