/*
 * Habillage centralise des tableaux FacControl.
 *
 * Objectifs :
 * - uniformiser le rendu de tous les tableaux HTML et simple-datatables ;
 * - reutiliser strictement la couleur primaire deja exposee par Bootstrap
 *   dans l'application, la meme que le header "Facturation" ;
 * - ameliorer la lisibilite, le zebra, le hover et le responsive
 *   sans toucher aux donnees ni a la logique metier.
 */

:root {
  /*
   * On s'aligne explicitement sur la couleur du header "Facturation",
   * qui repose sur `bg-primary` / `--bs-primary`.
   */
  --faccontrol-table-primary: var(--bs-primary, #0d6efd);
  --faccontrol-table-primary-rgb: var(--bs-primary-rgb, 13, 110, 253);
  --faccontrol-table-primary-soft: rgba(var(--faccontrol-table-primary-rgb), 0.08);
  --faccontrol-table-border: #e6ebf5;
  --faccontrol-table-zebra: #f8faff;
  --faccontrol-table-hover: rgba(var(--faccontrol-table-primary-rgb), 0.08);
  --faccontrol-table-text: #334155;
  --faccontrol-table-muted: #64748b;
  --faccontrol-table-shadow: 0 16px 36px rgba(15, 23, 42, 0.08);
  --faccontrol-table-radius: 16px;
}

/*
 * Les conteneurs responsives servent de coque visuelle commune :
 * scroll horizontal propre, coins arrondis et ombre legere.
 */
.table-responsive,
.datatable-wrapper .datatable-container {
  border: 1px solid var(--faccontrol-table-border);
  border-radius: var(--faccontrol-table-radius);
  background: #ffffff;
  box-shadow: var(--faccontrol-table-shadow);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.datatable-wrapper .datatable-container {
  margin-bottom: 1rem;
}

/*
 * Style commun des tableaux Bootstrap et de ceux generes par simple-datatables.
 */
.table,
.datatable-table {
  width: 100%;
  margin-bottom: 0;
  color: var(--faccontrol-table-text);
  background: #ffffff;
  border-collapse: separate !important;
  border-spacing: 0;
  border: 1px solid var(--faccontrol-table-border);
  border-radius: var(--faccontrol-table-radius);
  box-shadow: var(--faccontrol-table-shadow);
  overflow: hidden;
}

.table-responsive > .table,
.datatable-wrapper .datatable-container > .datatable-table {
  border: 0;
  box-shadow: none;
  border-radius: 0;
}

.table > :not(caption) > * > *,
.datatable-table > :not(caption) > * > * {
  padding: 0.95rem 1rem;
  vertical-align: middle;
  border-bottom: 1px solid var(--faccontrol-table-border);
}

.table.table-sm > :not(caption) > * > *,
.datatable-table.table-sm > :not(caption) > * > * {
  padding: 0.7rem 0.8rem;
}

/*
 * Entete uniforme : on reutilise exactement le meme bleu que `bg-primary`
 * pour supprimer toutes les variations visuelles entre tableaux.
 */
.table > thead,
.datatable-table > thead,
.table > thead > tr,
.datatable-table > thead > tr {
  background-color: var(--faccontrol-table-primary) !important;
}

.table > thead > tr > th,
.datatable-table > thead > tr > th {
  background-color: var(--faccontrol-table-primary) !important;
  background-image: none !important;
  color: #ffffff !important;
  font-family: "Nunito", sans-serif;
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
  border-bottom: 0 !important;
}

.table > thead > tr:first-child > th:first-child,
.datatable-table > thead > tr:first-child > th:first-child {
  border-top-left-radius: calc(var(--faccontrol-table-radius) - 1px);
}

.table > thead > tr:first-child > th:last-child,
.datatable-table > thead > tr:first-child > th:last-child {
  border-top-right-radius: calc(var(--faccontrol-table-radius) - 1px);
}

.table > tbody > tr:nth-of-type(odd) > *,
.datatable-table > tbody > tr:nth-of-type(odd) > * {
  background-color: #ffffff;
}

.table > tbody > tr:nth-of-type(even) > *,
.datatable-table > tbody > tr:nth-of-type(even) > * {
  background-color: var(--faccontrol-table-zebra);
}

.table > tbody > tr,
.datatable-table > tbody > tr {
  transition: background-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.table > tbody > tr:hover > *,
.datatable-table > tbody > tr:hover > * {
  background-color: var(--faccontrol-table-hover) !important;
}

.table > tfoot > tr > *,
.datatable-table > tfoot > tr > * {
  background: #f5f7fc;
  color: #1f2937;
  font-weight: 700;
}

.table > tbody > tr:last-child > *:first-child,
.datatable-table > tbody > tr:last-child > *:first-child,
.table > tfoot > tr:last-child > *:first-child,
.datatable-table > tfoot > tr:last-child > *:first-child {
  border-bottom-left-radius: calc(var(--faccontrol-table-radius) - 1px);
}

.table > tbody > tr:last-child > *:last-child,
.datatable-table > tbody > tr:last-child > *:last-child,
.table > tfoot > tr:last-child > *:last-child,
.datatable-table > tfoot > tr:last-child > *:last-child {
  border-bottom-right-radius: calc(var(--faccontrol-table-radius) - 1px);
}

.table :is(td, th),
.datatable-table :is(td, th) {
  text-align: left;
}

.table :is(.text-end, .text-end *),
.datatable-table :is(.text-end, .text-end *) {
  text-align: right !important;
}

.table :is(.text-center, .text-center *),
.datatable-table :is(.text-center, .text-center *) {
  text-align: center !important;
}

.table .badge,
.datatable-table .badge {
  vertical-align: middle;
}

/*
 * Harmonisation de simple-datatables pour que la recherche, les filtres
 * et la pagination aient le meme niveau de finition visuelle.
 */
.datatable-wrapper {
  margin-top: 0.5rem;
}

.datatable-top,
.datatable-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
  padding: 0.85rem 0;
}

.datatable-top > nav:first-child,
.datatable-top > div:first-child,
.datatable-bottom > nav:first-child,
.datatable-bottom > div:first-child,
.datatable-top > nav:last-child,
.datatable-top > div:not(first-child),
.datatable-bottom > nav:last-child,
.datatable-bottom > div:last-child {
  float: none;
}

.datatable-dropdown,
.datatable-search {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.datatable-selector,
.datatable-input {
  min-height: 42px;
  border: 1px solid #d7deec;
  border-radius: 12px;
  background: #ffffff;
  color: var(--faccontrol-table-text);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.datatable-selector {
  padding: 0.45rem 0.75rem;
}

.datatable-input {
  padding: 0.55rem 0.85rem;
}

.datatable-selector:focus,
.datatable-input:focus {
  outline: none;
  border-color: rgba(var(--faccontrol-table-primary-rgb), 0.55);
  box-shadow: 0 0 0 0.25rem rgba(var(--faccontrol-table-primary-rgb), 0.14);
}

.datatable-info {
  margin: 0;
  color: var(--faccontrol-table-muted);
  font-size: 0.92rem;
}

.datatable-pagination ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0;
}

.datatable-pagination li {
  float: none;
}

.datatable-pagination a,
.datatable-pagination button {
  min-width: 40px;
  border: 1px solid var(--faccontrol-table-border);
  border-radius: 10px;
  background: #ffffff;
  color: var(--faccontrol-table-text);
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.datatable-pagination a:hover,
.datatable-pagination button:hover {
  background-color: var(--faccontrol-table-primary-soft);
  color: var(--faccontrol-table-primary);
  border-color: rgba(var(--faccontrol-table-primary-rgb), 0.25);
  transform: translateY(-1px);
}

.datatable-pagination .datatable-active a,
.datatable-pagination .datatable-active a:focus,
.datatable-pagination .datatable-active a:hover,
.datatable-pagination .datatable-active button,
.datatable-pagination .datatable-active button:focus,
.datatable-pagination .datatable-active button:hover {
  background-color: var(--faccontrol-table-primary);
  border-color: var(--faccontrol-table-primary);
  color: #ffffff;
}

.datatable-sorter::before,
.datatable-sorter::after {
  right: 0.15rem;
  opacity: 0.72;
}

.datatable-sorter::before {
  border-top-color: rgba(255, 255, 255, 0.88);
}

.datatable-sorter::after {
  border-bottom-color: rgba(255, 255, 255, 0.88);
}

.datatable-filter::before {
  border-top-color: rgba(255, 255, 255, 0.88);
}

/*
 * Adaptation mobile : on privilegie le scroll horizontal propre
 * plutot que de casser les colonnes et les donnees.
 */
@media (max-width: 991.98px) {
  .table-responsive,
  .datatable-wrapper .datatable-container {
    border-radius: 14px;
  }

  .table,
  .datatable-table {
    min-width: 680px;
  }

  .datatable-top,
  .datatable-bottom {
    flex-direction: column;
    align-items: stretch;
  }

  .datatable-dropdown,
  .datatable-search {
    width: 100%;
    justify-content: space-between;
  }

  .datatable-input {
    width: 100%;
  }
}

/*
 * A l'impression, on allegre le style pour conserver un rendu net,
 * economique en encre et compatible avec les documents de gestion.
 */
@media print {
  .table-responsive,
  .datatable-wrapper .datatable-container,
  .table,
  .datatable-table {
    box-shadow: none !important;
    border-radius: 0 !important;
  }

  .table > thead > tr > th,
  .datatable-table > thead > tr > th,
  .table > tfoot > tr > *,
  .datatable-table > tfoot > tr > * {
    background: #f4f6fb !important;
    color: #1f2937 !important;
  }
}
