/* =============================================================================
   ARTISCODE ERP — TABLEAUX DE DONNÉES
   Surface opaque et lisible (pas de verre ici), barre d'outils, tri,
   sélection multiple, densité, pagination.
   ========================================================================== */

.data-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
}

/* -----------------------------------------------------------------------------
   BARRE D'OUTILS
   -------------------------------------------------------------------------- */

.table-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
}

.table-toolbar__title {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
}

.table-toolbar__count {
  padding: 0.1rem 0.5rem;
  border-radius: var(--radius-full);
  background: var(--bg-surface-3);
  color: var(--fg-muted);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 700;
}

.table-toolbar__subtitle {
  margin-top: 2px;
  color: var(--fg-muted);
  font-size: var(--text-sm);
}

.table-toolbar__tools {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-left: auto;
}

/* Recherche instantanée dans le tableau */
.table-search {
  position: relative;
  display: flex;
  align-items: center;
  width: clamp(180px, 22vw, 260px);
}

.table-search i {
  position: absolute;
  left: var(--space-3);
  color: var(--fg-subtle);
  font-size: var(--text-sm);
  pointer-events: none;
}

.table-search input {
  min-height: 36px;
  padding-left: 2.2rem;
  border-radius: var(--radius-full);
  background: var(--bg-surface-2);
  font-size: var(--text-sm);
}

.table-search input:focus {
  background: var(--bg-surface);
}

/* Barre d'actions groupées (apparaît à la sélection) */
.bulk-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  max-height: 0;
  padding: 0 var(--space-5);
  overflow: hidden;
  border-bottom: 1px solid transparent;
  background: var(--brand-soft);
  opacity: 0;
  transition:
    max-height var(--dur-base) var(--ease-out),
    padding var(--dur-base) var(--ease-out),
    opacity var(--dur-base) var(--ease-out);
}

.bulk-bar.is-visible {
  max-height: 80px;
  padding: var(--space-3) var(--space-5);
  border-bottom-color: var(--border-subtle);
  opacity: 1;
}

.bulk-bar__count {
  color: var(--brand-soft-fg);
  font-size: var(--text-sm);
  font-weight: 650;
}

.bulk-bar__actions {
  display: flex;
  gap: var(--space-2);
  margin-left: auto;
}

/* -----------------------------------------------------------------------------
   TABLEAU
   -------------------------------------------------------------------------- */

.table-scroll {
  width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
}

.table {
  width: 100%;
  min-width: 760px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--text-md);
}

.table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface-2);
  color: var(--fg-muted);
  font-size: var(--text-2xs);
  font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.table tbody td {
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--fg);
  vertical-align: middle;
}

.table tbody tr {
  transition: background-color var(--dur-fast) var(--ease-out);
}

.table tbody tr:hover {
  background: var(--bg-hover);
}

.table tbody tr:last-child td {
  border-bottom: 0;
}

.table tbody tr.is-selected {
  background: var(--brand-soft);
}

/* Ligne cliquable */
.table tbody tr.is-clickable {
  cursor: pointer;
}

/* Colonnes utilitaires */
.table .col-select { width: 44px; }
.table .col-actions {
  width: 1%;
  text-align: right;
  white-space: nowrap;
}

.table .col-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.table td.col-actions .btn-group {
  justify-content: flex-end;
  flex-wrap: nowrap;
}

/* Actions révélées au survol de la ligne (desktop) */
@media (hover: hover) and (min-width: 993px) {
  .table tbody .row-actions {
    opacity: 0.35;
    transform: translateX(6px);
    transition: opacity var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
  }

  .table tbody tr:hover .row-actions,
  .table tbody tr:focus-within .row-actions {
    opacity: 1;
    transform: none;
  }
}

/* En-têtes triables */
.table th.is-sortable {
  cursor: pointer;
  user-select: none;
  transition: color var(--dur-fast) var(--ease-out);
}

.table th.is-sortable:hover {
  color: var(--fg-strong);
}

.table th.is-sortable::after {
  content: '\f0dc'; /* fa-sort */
  margin-left: var(--space-2);
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  font-size: 0.85em;
  opacity: 0.3;
  transition: opacity var(--dur-fast) var(--ease-out);
}

.table th.is-sortable:hover::after {
  opacity: 0.6;
}

.table th[data-sort-dir='asc']::after {
  content: '\f0de'; /* fa-sort-up */
  color: var(--brand);
  opacity: 1;
}

.table th[data-sort-dir='desc']::after {
  content: '\f0dd'; /* fa-sort-down */
  color: var(--brand);
  opacity: 1;
}

/* Densité compacte */
.data-panel.is-compact .table thead th,
.data-panel.is-compact .table tbody td {
  padding-top: var(--space-2);
  padding-bottom: var(--space-2);
}

.data-panel.is-compact .avatar {
  width: 30px;
  height: 30px;
  font-size: var(--text-2xs);
}

.data-panel.is-compact .identity__meta {
  display: none;
}

/* Lignes de chargement */
.table tbody tr.is-skeleton td > * {
  visibility: hidden;
}

/* Cellule sans résultat de la recherche instantanée */
.table__no-match td {
  padding: var(--space-10) var(--space-5);
  color: var(--fg-muted);
  text-align: center;
}

/* Bandeau de résumé sous le tableau */
.table-summary {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface-2);
  color: var(--fg-muted);
  font-size: var(--text-sm);
}

.table-summary strong {
  color: var(--fg-strong);
}

/* -----------------------------------------------------------------------------
   PAGINATION
   -------------------------------------------------------------------------- */

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border-subtle);
}

.pagination__info {
  color: var(--fg-muted);
  font-size: var(--text-sm);
}

.pagination__info strong {
  color: var(--fg-strong);
  font-weight: 650;
}

.pagination__pages {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-left: auto;
}

.page-link {
  display: grid;
  place-items: center;
  min-width: 34px;
  height: 34px;
  padding: 0 var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  color: var(--fg-muted);
  font-size: var(--text-sm);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  transition:
    background-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    transform var(--dur-fast) var(--ease-out);
}

.page-link:hover {
  border-color: var(--border);
  background: var(--bg-hover);
  color: var(--fg-strong);
  transform: translateY(-1px);
}

.page-link.is-active {
  background: var(--gradient-brand);
  color: var(--fg-onbrand);
  box-shadow: var(--shadow-brand);
}

.page-link.is-active:hover {
  color: var(--fg-onbrand);
}

.page-link.is-disabled {
  opacity: 0.4;
  pointer-events: none;
}

.page-gap {
  padding: 0 var(--space-1);
  color: var(--fg-subtle);
  user-select: none;
}

/* -----------------------------------------------------------------------------
   RESPONSIVE — bascule en cartes empilées sous 720px
   -------------------------------------------------------------------------- */

@media (max-width: 720px) {
  .table--stack {
    min-width: 0;
  }

  .table--stack thead {
    display: none;
  }

  .table--stack tbody tr {
    display: grid;
    gap: var(--space-2);
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border-subtle);
  }

  .table--stack tbody td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: 0;
    border: 0;
  }

  /* Le libellé de colonne est repris via data-label sur chaque cellule */
  .table--stack tbody td::before {
    content: attr(data-label);
    flex-shrink: 0;
    color: var(--fg-muted);
    font-size: var(--text-2xs);
    font-weight: 700;
    letter-spacing: var(--tracking-caps);
    text-transform: uppercase;
  }

  /* En pile, la cellule d'actions redevient pleine largeur : le width: 1% de
     la vue bureau ferait déborder le groupe de boutons hors de l'écran. */
  .table--stack tbody td.col-actions {
    width: auto;
    justify-content: flex-end;
    padding-top: var(--space-2);
    border-top: 1px solid var(--border-subtle);
  }

  .table--stack tbody td.col-actions .btn-group {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .table--stack tbody td.col-actions::before {
    content: none;
  }

  /* La colonne de sélection n'a pas de libellé à afficher en pile. */
  .table--stack tbody td.col-select {
    width: auto;
    justify-content: flex-start;
  }

  .table--stack tbody td.col-select::before {
    content: none;
  }

  .table--stack tbody td.col-num {
    text-align: left;
  }

  .table-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .table-toolbar__tools {
    width: 100%;
    margin-left: 0;
  }

  .table-search {
    width: 100%;
  }

  .pagination {
    justify-content: center;
  }

  .pagination__pages {
    margin-left: 0;
  }
}
