/* ==========================================================================
   DataTable — styles autonomes
   Peut être inclus indépendamment de styles.css
   ========================================================================== */

/* ── Conteneur principal ── */
.dt-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0;
  font-size: 0.85em;
  background: #fff;
  border: 1px solid #d0d5dd;
  border-radius: 6px;
  overflow: hidden;
}

/* ── Barre d'outils ── */
.dt-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  padding: 8px 12px;
  background: #f7f8fa;
  border-bottom: 1px solid #d0d5dd;
  flex-shrink: 0;
}

.dt-search {
  flex: 1;
  max-width: 280px;
  padding: 5px 10px;
  border: 1px solid #c8cdd5;
  border-radius: 4px;
  font-size: 0.9em;
  outline: none;
  transition: border-color 0.2s;
}

.dt-search:focus {
  border-color: #2e75b6;
  box-shadow: 0 0 0 2px rgba(46, 117, 182, 0.15);
}

.dt-info {
  font-size: 0.82em;
  color: #666;
  white-space: nowrap;
  margin-left: auto;
}

/* ── Zone de défilement ── */
.dt-scroll-wrap {
  overflow-x: auto;
  overflow-y: auto;
}

/* Mode "tout afficher" : le scroll-wrap s'étire à la hauteur naturelle du tableau */
.dt-scroll-wrap--expanded {
  overflow: visible;
  flex: none !important;
  height: auto !important;
  min-height: 0 !important;
}

/* ── Barre de défilement horizontal (mode "tout afficher") ── */
.dt-hscroll {
  display: none;          /* caché par défaut, JS l'affiche si nécessaire */
  overflow-x: auto;
  overflow-y: hidden;
  position: sticky;
  bottom: 0;
  z-index: 149;           /* sous toolbar (150) mais au-dessus du contenu */
  background: var(--dt-toolbar-bg, #f7f8fa);
  border-top: 1px solid #dde2ea;
}

.dt-hscroll-thumb {
  height: 1px;            /* 1px suffit à créer la scrollbar dans overflow:auto */
}

/* ── Tableau ── */
.dt-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.dt-th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 7px 10px;
  background: linear-gradient(to bottom, #f0f2f5, #e6e9ef);
  border-bottom: 2px solid #c0c8d8;
  border-right: 1px solid #d0d5dd;
  font-size: 0.82em;
  font-weight: 600;
  color: #334;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  user-select: none;
}

.dt-th:last-child {
  border-right: none;
}

.dt-th.dt-sortable {
  cursor: pointer;
}

.dt-th.dt-sortable:hover {
  background: linear-gradient(to bottom, #e6eaf0, #d8dde8);
}

/* Libellé de colonne */
.dt-col-label {
  margin-right: 4px;
}

/* Icônes de tri superposées */
.dt-sort-icons {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  line-height: 0.7;
  margin-left: 2px;
  gap: 0;
}

.dt-sort-asc,
.dt-sort-desc {
  font-size: 0.7em;
  color: #b0b8c8;
  display: block;
  line-height: 1;
  transition: color 0.15s;
}

.dt-sort-asc.active,
.dt-sort-desc.active {
  color: #2e75b6;
}

/* Poignée de redimensionnement de colonne */
.dt-col-rz {
  position: absolute;
  top: 0;
  right: 0;
  width: 5px;
  height: 100%;
  cursor: col-resize;
  z-index: 1;
  background: transparent;
  transition: background 0.15s;
}

.dt-col-rz:hover,
.dt-col-rz:active {
  background: rgba(46, 117, 182, 0.35);
}

/* ── Cellules ── */
.dt-td {
  padding: 6px 10px;
  border-bottom: 1px solid #e8eaee;
  border-right: 1px solid #e8eaee;
  font-size: 0.9em;
  color: #222;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dt-td:last-child {
  border-right: none;
}

.dt-row:hover .dt-td {
  background: #f0f5ff;
}
.dt-row-focused .dt-td {
  background: #dbeafe;
}
.dt-row-focused:nth-child(even) .dt-td {
  background: #dbeafe;
}
.dt-scroll-wrap:focus { outline: none; }

.dt-row:nth-child(even) .dt-td {
  background: #fafbfd;
}

.dt-row:nth-child(even):hover .dt-td {
  background: #f0f5ff;
}

/* ── Ligne de saisie inline ── */
.dt-td-new {
  padding: 0;
  overflow: visible;
}
.dt-new-input,
.dt-new-select {
  display: block;
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 0;
  padding: 6px 10px;
  font-size: inherit;
  font-family: inherit;
  background: transparent;
  color: #222;
  box-sizing: border-box;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.dt-new-select {
  cursor: pointer;
  -webkit-appearance: auto;
  appearance: auto;
}
.dt-new-input:focus,
.dt-new-select:focus {
  background: #fff;
  box-shadow: inset 0 0 0 2px #2e75b6;
}

/* ── États spéciaux ── */
.dt-loading,
.dt-empty,
.dt-error {
  text-align: center;
  padding: 24px 16px;
  color: #888;
  font-style: italic;
}

.dt-error {
  color: #c0392b;
}

.dt-empty-msg {
  margin: 0 0 12px;
}

.dt-empty-add-btn {
  display: inline-block;
  padding: 6px 16px;
  border: 1px solid #3d8ef0;
  border-radius: 4px;
  background: #3d8ef0;
  color: #fff;
  font-size: 13px;
  cursor: pointer;
  font-style: normal;
}
.dt-empty-add-btn:hover {
  background: #2575d8;
  border-color: #2575d8;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.dt-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid #d0d5dd;
  border-top-color: #2e75b6;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

/* ── Fenêtre d'erreur de validation ── */
.dt-error-popup {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fff;
  border: 2px solid #e53935;
  border-radius: 8px;
  padding: 14px 16px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  min-width: 260px;
  max-width: 400px;
  animation: dt-error-in 0.15s ease;
}

@keyframes dt-error-in {
  from { opacity: 0; transform: translate(-50%, -46%); }
  to   { opacity: 1; transform: translate(-50%, -50%); }
}

.dt-error-popup__icon {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #e53935;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dt-error-popup__icon::before {
  content: '!';
}

.dt-error-popup__msg {
  flex: 1;
  font-size: 0.9em;
  color: #333;
  line-height: 1.4;
}

.dt-error-popup__close {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: #888;
  font-size: 14px;
  padding: 2px 5px;
  border-radius: 3px;
  line-height: 1;
}

.dt-error-popup__close:hover {
  background: #f0f0f0;
  color: #333;
}

/* ── Surligné de recherche ── */
mark.dt-highlight {
  background: #fff59d;
  color: inherit;
  font: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

/* ── Types de cellule ── */

/* Checkbox */
.dt-cell-checkbox {
  cursor: default;
  width: 14px;
  height: 14px;
}

/* Switch Oui/Non */
.dt-switch {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.82em;
  font-weight: 600;
  white-space: nowrap;
}

.dt-switch-on {
  background: #d4edda;
  color: #1a6e30;
  border: 1px solid #b7dfc4;
}

.dt-switch-off {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5b7b7;
}

/* Boutons radio (lecture seule) */
.dt-radio-group {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.dt-radio-label {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 0.9em;
  cursor: default;
  white-space: nowrap;
}

.dt-radio-label input[type="radio"] {
  cursor: default;
}

/* Badge (type select) */
.dt-badge {
  display: inline-block;
  padding: 2px 8px;
  background: #e8eef8;
  border: 1px solid #c5d0e8;
  border-radius: 10px;
  font-size: 0.82em;
  color: #2e75b6;
  white-space: nowrap;
}

/* ── Pied de page ── */
.dt-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 7px 12px;
  background: #f7f8fa;
  border-top: 1px solid #d0d5dd;
  flex-shrink: 0;
}

.dt-pagination {
  display: flex;
  align-items: center;
  gap: 4px;
}

.dt-page-btn {
  background: #fff;
  border: 1px solid #c8cdd5;
  border-radius: 3px;
  padding: 3px 9px;
  cursor: pointer;
  font-size: 0.9em;
  color: #444;
  transition: background 0.15s, border-color 0.15s;
  min-width: 28px;
}

.dt-page-btn:hover:not(:disabled) {
  background: #e8eef8;
  border-color: #2e75b6;
  color: #2e75b6;
}

.dt-page-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.dt-page-info {
  padding: 3px 10px;
  font-size: 0.85em;
  color: #555;
  white-space: nowrap;
}

.dt-page-sep {
  display: inline-block;
  width: 1px;
  height: 14px;
  background: #d0d5dd;
  margin: 0 6px;
  align-self: center;
}

.dt-page-btn--more {
  color: #555;
  font-size: 0.8em;
  min-width: 52px;
}

.dt-page-btn--all {
  font-weight: 600;
  color: #2e75b6;
  border-color: #a0c0e0;
  min-width: 52px;
}

.dt-page-btn--all:hover:not(:disabled) {
  background: #2e75b6;
  border-color: #2567a0;
  color: #fff;
}

.dt-page-btn--normal {
  font-weight: 600;
  color: #5a6472;
  border-color: #b0b8c4;
  min-width: 58px;
}

.dt-page-btn--normal:hover:not(:disabled) {
  background: #5a6472;
  border-color: #404a56;
  color: #fff;
}


/* ── DataTable à l'intérieur d'un corps de Modal ── */
.win-body > .dt-wrapper {
  flex: 1;
  min-height: 0;
  border: none;
  border-radius: 0;
}

.win-body > .dt-wrapper .dt-scroll-wrap {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

/* ── Cellules éditables ── */
.dt-editable {
  position: relative;
}

.dt-editable--select          { cursor: pointer; }
.dt-editable--text            { cursor: pointer; }
.dt-editable--text.dt-editing { cursor: text; }

/* Select et input positionnés en absolu : recouvrent la cellule
   sans jamais modifier la hauteur de la ligne */
.dt-cell-select,
.dt-cell-input {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 1px solid #2e75b6;
  border-radius: 0;
  padding: 5px 9px;
  font-size: inherit;
  font-family: inherit;
  background: #fff;
  color: #222;
  z-index: 2;
  box-sizing: border-box;
}

.dt-cell-select { cursor: pointer; }
.dt-cell-input  { cursor: text; outline: none; }

/* Masquer le texte quand le widget est actif */
.dt-cell-text--hidden { visibility: hidden; }

.dt-cell-select--visible { display: block; }
.dt-cell-input--visible  { display: block; }

/* ── Colonne actions ── */
.dt-actions {
  white-space: nowrap;
  text-align: center;
  padding: 3px 6px;
}

.dt-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: 1px solid transparent;
  border-radius: 3px;
  background: none;
  cursor: pointer;
  font-size: 0.8em;
  padding: 0;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  vertical-align: middle;
}

.dt-action-btn + .dt-action-btn {
  margin-left: 3px;
}

.dt-action-btn--edit {
  color: #2e75b6;
  border-color: #a0c0e0;
}

.dt-action-btn--edit:hover {
  background: #2e75b6;
  color: #fff;
  border-color: #2567a0;
}

.dt-action-btn--danger {
  color: #c0392b;
  border-color: #e0b0b0;
}

.dt-action-btn--danger:hover {
  background: #c0392b;
  color: #fff;
  border-color: #a93226;
}

.dt-action-btn--confirm {
  color: #1a6e30;
  background: #d4edda;
  border-color: #b7dfc4;
}

.dt-action-btn--confirm:hover {
  background: #1a6e30;
  color: #fff;
  border-color: #1a6e30;
}

.dt-action-btn--cancel {
  color: #721c24;
  background: #f8d7da;
  border-color: #f5b7b7;
}

.dt-action-btn--cancel:hover {
  background: #721c24;
  color: #fff;
  border-color: #721c24;
}

/* ── Formulaire d'édition (dans la modale) ── */
.dt-edit-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dt-edit-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.dt-edit-label {
  font-size: 0.82em;
  font-weight: 600;
  color: #444;
}

/* Paysage : libellé à gauche, champ à droite */
@media (orientation: landscape) {
  .dt-edit-field {
    flex-direction: row;
    align-items: center;
    gap: 10px;
  }
  .dt-edit-label {
    flex: 0 0 130px;
    text-align: right;
  }
  .dt-edit-ctrl {
    flex: 1;
  }
}

.dt-edit-ctrl input,
.dt-edit-ctrl select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #c8cdd5;
  border-radius: 4px;
  font-size: 0.9em;
  box-sizing: border-box;
  background: #fff;
  color: #222;
  outline: none;
  transition: border-color 0.2s;
}

.dt-edit-ctrl input:focus,
.dt-edit-ctrl select:focus {
  border-color: #2e75b6;
  box-shadow: 0 0 0 2px rgba(46, 117, 182, 0.15);
}

/* ── Bouton Ajouter dans la barre d'outils ── */
.dt-btn-add {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 12px;
  background: #2e75b6;
  color: #fff;
  border: 1px solid #1f5c9a;
  border-radius: 4px;
  font-size: 0.82em;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}

.dt-btn-add:hover {
  background: #1f5c9a;
  border-color: #174d82;
}

/* ── Message d'erreur dans la modale d'ajout ── */
.dt-add-error {
  display: none;
  color: #c0392b;
  font-size: 0.82em;
  padding: 6px 10px;
  background: #fdf0ef;
  border: 1px solid #f5c6c2;
  border-radius: 4px;
}

/* ── Barre de totaux (hors zone de scroll, toujours visible) ── */
.dt-totals-bar {
  flex-shrink: 0;
  overflow: hidden;
  border-top: 2px solid #b0c4de;
  background: #e8eef7;
}

.dt-totals-table {
  table-layout: fixed;
  border-collapse: collapse;
}

.dt-total-td {
  padding: 5px 10px;
  font-size: 0.88em;
  font-weight: 600;
  color: #1a3a5c;
  border-right: 1px solid #d0d5dd;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dt-total-td:last-child {
  border-right: none;
}

/* ── Pills ────────────────────────────────────────────────────────── */
.dt-pills-wrap { display: inline-flex; gap: 4px; flex-wrap: nowrap; }
.dt-pill {
  display: inline-block; padding: 2px 10px; border-radius: 12px;
  font-size: 12px; font-weight: 500; white-space: nowrap;
  transition: opacity .15s, box-shadow .15s;
}
.dt-pill--active { opacity: 1; }
.dt-pill--inactive { opacity: .35; background: #e5e7eb; color: #6b7280; }
.dt-pill--clickable { cursor: pointer; }
.dt-pill--clickable:hover { opacity: .7; box-shadow: 0 0 0 2px rgba(0,0,0,.1); }
