/* 144 — Table Motion
   Table animée. Tri : les lignes glissent vers leur nouvelle position en FLIP
   (transform inverse posé sans transition par anim.js, puis la transition de
   .table-motion__row ramène à 0, léger stagger) ; la flèche de l'en-tête actif
   pivote asc/desc. Expansion : le panneau de détail s'ouvre en animant
   grid-template-rows 0fr→1fr, son contenu apparaît en fondu décalé, le
   chevron tourne. Une seule ligne ouverte à la fois. */

.table-motion {
  width: 320px;
  max-width: 100%;
  font-size: 12px;
}

.table-motion__panel {
  background: var(--ml-surface, #151a24);
  border: 1px solid rgba(139, 145, 163, 0.16);
  border-radius: 14px;
  overflow: hidden;
}

/* — En-tête : mêmes colonnes que les lignes — */
.table-motion__head {
  display: grid;
  grid-template-columns: 18px 1fr 74px 54px;
  align-items: center;
  padding: 3px 12px 3px 10px;
  border-bottom: 1px solid rgba(139, 145, 163, 0.16);
  background: rgba(139, 145, 163, 0.05);
}

.table-motion__sort {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  justify-self: start;
  padding: 6px 0;
  background: none;
  border: none;
  border-radius: 6px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ml-muted, #8b91a3);
  cursor: pointer;
  transition: color 0.2s ease;
}

.table-motion__sort--num {
  justify-self: end;
}

.table-motion__sort:hover {
  color: var(--ml-fg, #e8eaf2);
}

.table-motion__sort:focus-visible {
  outline: none;
  color: var(--ml-fg, #e8eaf2);
  box-shadow:
    0 0 0 2px var(--ml-surface, #151a24),
    0 0 0 4px var(--ml-accent, #7c8cff);
}

.table-motion__sort.is-sorted {
  color: var(--ml-accent, #7c8cff);
}

/* Flèche de tri : invisible au repos, pivote 180° en desc */
.table-motion__arrow {
  width: 8px;
  height: 8px;
  flex: none;
  opacity: 0;
  transform: translateY(-1px) scale(0.6);
  transition:
    transform 0.3s cubic-bezier(0.3, 1.4, 0.4, 1),
    opacity 0.2s ease;
}

.table-motion__sort.is-sorted .table-motion__arrow {
  opacity: 1;
  transform: translateY(0) scale(1) rotate(0deg);
}

.table-motion__sort.is-sorted.is-desc .table-motion__arrow {
  transform: translateY(0) scale(1) rotate(180deg);
}

/* — Lignes : transition transform = rail des FLIP de tri — */
.table-motion__body {
  display: flex;
  flex-direction: column;
}

.table-motion__row {
  position: relative;
  background: transparent;
  will-change: transform;
  transition:
    transform 0.34s cubic-bezier(0.25, 0.8, 0.3, 1),
    background-color 0.2s ease;
}

.table-motion__row:not(:first-child) {
  border-top: 1px solid rgba(139, 145, 163, 0.1);
}

.table-motion__row:hover {
  background: rgba(124, 140, 255, 0.05);
}

.table-motion__row.is-open {
  background: rgba(124, 140, 255, 0.07);
}

/* Ligne cliquable (bouton pleine largeur, mêmes colonnes que l'en-tête) */
.table-motion__line {
  display: grid;
  grid-template-columns: 18px 1fr 74px 54px;
  align-items: center;
  width: 100%;
  padding: 8px 12px 8px 10px;
  background: none;
  border: none;
  text-align: left;
  font: inherit;
  color: var(--ml-fg, #e8eaf2);
  cursor: pointer;
}

.table-motion__line:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--ml-accent, #7c8cff);
  border-radius: 8px;
}

.table-motion__chevron {
  width: 10px;
  height: 10px;
  color: var(--ml-muted, #8b91a3);
  transition: transform 0.32s cubic-bezier(0.3, 1.2, 0.4, 1), color 0.2s ease;
}

.table-motion__row.is-open .table-motion__chevron {
  transform: rotate(90deg);
  color: var(--ml-accent, #7c8cff);
}

.table-motion__name {
  min-width: 0;
  padding-right: 8px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.table-motion__badge {
  justify-self: start;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ml-accent-2, #2dd4bf);
  background: rgba(45, 212, 191, 0.12);
}

.table-motion__badge--pause {
  color: #f2a65a;
  background: rgba(242, 166, 90, 0.12);
}

.table-motion__badge--off {
  color: var(--ml-muted, #8b91a3);
  background: rgba(139, 145, 163, 0.12);
}

.table-motion__value {
  justify-self: end;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ml-muted, #8b91a3);
}

/* — Panneau de détail : hauteur animée via grid-template-rows 0fr→1fr — */
.table-motion__detail {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.34s cubic-bezier(0.25, 0.8, 0.3, 1);
}

.table-motion__row.is-open .table-motion__detail {
  grid-template-rows: 1fr;
}

.table-motion__detail-in {
  overflow: hidden;
  min-height: 0;
}

/* Contenu du détail : fondu décalé, part légèrement plus tard que la hauteur */
.table-motion__detail-body {
  display: flex;
  gap: 16px;
  padding: 2px 12px 10px 28px;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.table-motion__row.is-open .table-motion__detail-body {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.26s ease 0.1s, transform 0.26s ease 0.1s;
}

.table-motion__stat-label {
  display: block;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ml-muted, #8b91a3);
}

.table-motion__stat-value {
  display: block;
  margin-top: 1px;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ml-fg, #e8eaf2);
}

.table-motion__hint {
  margin-top: 8px;
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--ml-muted, #8b91a3);
  opacity: 0.75;
  text-align: center;
}

/* — Reduced motion : tri et expansion instantanés, tout reste fonctionnel — */
@media (prefers-reduced-motion: reduce) {
  .table-motion__row,
  .table-motion__arrow,
  .table-motion__chevron,
  .table-motion__detail,
  .table-motion__detail-body,
  .table-motion__row.is-open .table-motion__detail-body {
    transition: none;
  }
}
