/* ============================================================================
   DataTable, badges et en-tête de page — primitives UI-V2 (DESIGN-04)
   Portées par `body.ui-v2`, comme le reste de la refonte.

   PAS DE SOUPE DE CARTES (§51)
   ----------------------------
   Le tableau n'est pas posé dans une carte arrondie dans une carte arrondie.
   Une bordure, des filets, de l'espace et de la typographie suffisent à
   grouper. Chaque encadré supplémentaire est une hiérarchie qu'on n'a pas su
   exprimer autrement.
   ============================================================================ */

/* ─── En-tête de page (réutilisable) ────────────────────────────────────────*/
body.ui-v2 .v2-page { display: flex; flex-direction: column; gap: var(--space-5); }
.v2-page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--space-6); flex-wrap: wrap;
}
.v2-eyebrow {
  font-size: var(--text-2xs); letter-spacing: var(--tracking-wide);
  text-transform: uppercase; color: var(--text-faint); font-weight: 500;
  margin-bottom: var(--space-1);
}
.v2-page-title-lg {
  font-size: var(--text-title); font-weight: 600; margin: 0;
  letter-spacing: var(--tracking-tight); line-height: 1.1; color: var(--text-primary);
}
.v2-page-sub {
  margin-top: var(--space-2); font-size: var(--text-md);
  color: var(--text-muted); max-width: 56ch;
}

/* Utilitaire lecteur d'écran — le sens ne doit jamais dépendre du seul visuel.
   Il est `position: absolute`, donc son bloc conteneur est le premier ancêtre
   POSITIONNÉ. S'il n'en existe aucun, c'est le bloc conteneur initial : le
   repère sort alors de tout défilement local et sa position statique ALLONGE
   la page. C'est ce qui est arrivé à `#/voice-calls` en 390 px — un repère de
   1 px, posé dans le neuvième en-tête d'un tableau à défilement, portait à lui
   seul 450 px de débordement horizontal. Les conteneurs de défilement
   ci-dessous se déclarent donc positionnés (voir `.v2-table-scroll`). */
.v2-sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ─── Barre de filtres ──────────────────────────────────────────────────────*/
.v2-filterbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-4); flex-wrap: wrap;
}
.v2-search { display: flex; align-items: baseline; gap: var(--space-3); flex: 1 1 320px; min-width: 0; }
.v2-search-input {
  flex: 1 1 auto; min-width: 0;
  background: var(--bg-surface); color: var(--text-primary);
  border: 1px solid var(--border-default); border-radius: var(--radius-sm);
  padding: 6px var(--space-3);
  font-family: var(--font-ui); font-size: var(--text-md);
}
.v2-search-input:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }
.v2-search-input::placeholder { color: var(--text-faint); }
/* La portée de la recherche est écrite, pas devinée : l'API cherche dans le
   nom et l'e-mail, pas dans la société ni le téléphone. Sans cette mention,
   une recherche par société renverrait « aucun résultat » et se lirait comme
   une absence de données. */
.v2-search-hint {
  flex: 0 0 auto; font-size: var(--text-2xs); color: var(--text-faint);
  letter-spacing: var(--tracking-wide); text-transform: uppercase;
}
.v2-filters { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.v2-select {
  background: var(--bg-surface); color: var(--text-secondary);
  border: 1px solid var(--border-default); border-radius: var(--radius-sm);
  padding: 5px var(--space-2);
  font-family: var(--font-ui); font-size: var(--text-sm);
}
/* Le bouton de réinitialisation n'apparaît QUE si un filtre est actif (§44) :
   un bouton permanent occupe de la place pour ne rien dire la plupart du temps. */
.v2-reset {
  background: transparent; border: 1px solid var(--border-default);
  border-radius: var(--radius-sm); padding: 5px var(--space-3);
  font-family: var(--font-ui); font-size: var(--text-sm);
  color: var(--text-muted); cursor: pointer;
}
.v2-reset:hover { border-color: var(--border-strong); color: var(--text-primary); }

/* ─── Tableau ───────────────────────────────────────────────────────────────*/
.v2-table-scroll {
  border: 1px solid var(--border-default); border-radius: var(--radius-md);
  background: var(--bg-surface); overflow-x: auto;
  /* Un conteneur de défilement doit être le bloc conteneur de ce qu'il
     contient, sinon un descendant positionné lui échappe et pousse la page. */
  position: relative;
}
.v2-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.v2-table thead th {
  text-align: left; font-weight: 500;
  font-size: var(--text-2xs); letter-spacing: var(--tracking-wide);
  text-transform: uppercase; color: var(--text-muted);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-default);
  white-space: nowrap;
  /* Volontairement NI `cursor: pointer` NI affordance de tri : l'API ne trie
     pas, et un en-tête qui a l'air cliquable promet ce qu'il ne peut tenir. */
}
.v2-table th.is-right, .v2-table td.is-right { text-align: right; }
.v2-table tbody td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary); vertical-align: middle;
}
.v2-table tbody tr:last-child td { border-bottom: none; }
.v2-row:hover td { background: var(--bg-surface-muted); }

/* Une seule zone cliquable par ligne (§24) : l'identité. Rendre toute la ligne
   cliquable empêcherait de sélectionner un e-mail au curseur. */
.v2-row-link {
  display: flex; align-items: center; gap: var(--space-3);
  color: inherit; text-decoration: none; min-width: 0;
}
.v2-row-link:hover .v2-row-name { text-decoration: underline; }
.v2-row-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-xs); }
.v2-avatar {
  flex: 0 0 auto; width: 26px; height: 26px;
  display: grid; place-items: center; border-radius: var(--radius-sm);
  background: var(--bg-surface-sunken); color: var(--text-muted);
  font-family: var(--font-mono); font-size: var(--text-2xs);
  /* Initiales dérivées du nom réel — jamais une photo inventée (§19). */
}
.v2-row-identity { display: flex; flex-direction: column; min-width: 0; }
.v2-row-name {
  color: var(--text-primary); font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.v2-row-sub {
  font-size: var(--text-xs); color: var(--text-faint);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ─── Badges ────────────────────────────────────────────────────────────────*/
.v2-badge {
  display: inline-block; font-size: var(--text-2xs); font-weight: 500;
  letter-spacing: var(--tracking-wide); text-transform: uppercase;
  padding: 2px 6px; border-radius: var(--radius-xs);
  border: 1px solid var(--border-default); color: var(--text-secondary);
  white-space: nowrap;
}
.v2-badge.is-accent  { border-color: var(--accent); color: var(--accent); }
.v2-badge.is-success { border-color: var(--success); color: var(--success); }
.v2-badge.is-warning { border-color: var(--warning); color: var(--warning); }
.v2-badge.is-muted   { color: var(--text-faint); }

.v2-temp { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.v2-temp-dot {
  width: 7px; height: 7px; border-radius: 50%;
  border: 1px solid var(--border-strong); background: transparent;
}
.v2-temp.is-accent  .v2-temp-dot { background: var(--accent);  border-color: var(--accent); }
.v2-temp.is-warning .v2-temp-dot { background: var(--warning); border-color: var(--warning); }
.v2-temp.is-danger  .v2-temp-dot { background: var(--danger);  border-color: var(--danger); }

.v2-score { display: inline-flex; align-items: center; gap: var(--space-2); justify-content: flex-end; }
.v2-score-value { color: var(--text-primary); font-size: var(--text-sm); }
.v2-score-bar {
  width: 36px; height: 3px; border-radius: 2px;
  background: var(--bg-surface-sunken); overflow: hidden; display: inline-block;
}
.v2-score-bar i { display: block; height: 100%; background: var(--text-muted); }

/* Champ facultatif vide : neutre. Le colorer en rouge ferait passer une donnée
   simplement absente pour une anomalie (§30). */
.v2-empty-cell { color: var(--text-faint); }

/* ─── États ─────────────────────────────────────────────────────────────────*/
.v2-table-state {
  border: 1px solid var(--border-default); border-radius: var(--radius-md);
  background: var(--bg-surface);
  padding: var(--space-10) var(--space-6);
  text-align: center;
}
/* Filet ambre, pas rouge sang : l'écran doit signaler un échec sans mettre en
   scène une catastrophe. Ce qui compte est que ce bloc ne ressemble EN RIEN à
   un tableau vide (§53). */
.v2-table-state.is-error {
  border-left: 3px solid var(--warning); text-align: left;
  padding: var(--space-5) var(--space-6);
}
.v2-state-title { font-size: var(--text-lg); color: var(--text-primary); font-weight: 500; }
.v2-state-body {
  margin-top: var(--space-2); font-size: var(--text-md); color: var(--text-muted);
}
.v2-state-action {
  display: inline-block; margin-top: var(--space-4);
  background: transparent; border: 1px solid var(--border-default);
  border-radius: var(--radius-sm); padding: 6px var(--space-4);
  font-family: var(--font-ui); font-size: var(--text-sm);
  color: var(--accent); cursor: pointer; text-decoration: none;
}
.v2-state-action:hover { border-color: var(--border-strong); text-decoration: none; }

.v2-skel {
  display: block; height: 10px; border-radius: 3px;
  background: var(--bg-surface-sunken);
  animation: v2-pulse 1.4s ease-in-out infinite;
}
@keyframes v2-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
/* Respect du réglage système (§31) : une animation continue peut être
   inconfortable, voire déclencheuse. */
@media (prefers-reduced-motion: reduce) {
  .v2-skel { animation: none; }
  body.ui-v2 .main-content, .v2-sidebar { transition: none; }
}

/* ─── Pagination ────────────────────────────────────────────────────────────*/
.v2-pagination {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-4); flex-wrap: wrap;
}
/* Aucun total affiché : l'API n'en renvoie pas, et l'inventer serait le
   mensonge le plus facile de cet écran (§16). */
.v2-pagination-range { font-size: var(--text-xs); color: var(--text-faint); }
.v2-pagination-controls { display: flex; gap: var(--space-2); }
.v2-page-btn {
  background: var(--bg-surface); border: 1px solid var(--border-default);
  border-radius: var(--radius-sm); padding: 5px var(--space-4);
  font-family: var(--font-ui); font-size: var(--text-sm);
  color: var(--text-secondary); cursor: pointer;
}
.v2-page-btn:hover:not([disabled]) { border-color: var(--border-strong); color: var(--text-primary); }
.v2-page-btn[disabled] { opacity: .45; cursor: default; }

/* ─── Priorité des colonnes ─────────────────────────────────────────────────
   Plutôt qu'un défilement horizontal subi, on décide quelles colonnes
   disparaissent en premier. Le nom et le statut ne disparaissent jamais. */
@media (max-width: 1280px) { .v2-table .p3 { display: none; } }
@media (max-width: 1024px) { .v2-table .p2 { display: none; } }
@media (max-width: 700px) {
  .v2-filterbar { flex-direction: column; align-items: stretch; }
  .v2-search-hint { display: none; }
  .v2-table thead th, .v2-table tbody td { padding: var(--space-2) var(--space-3); }
}

/* ─── Communications (DESIGN-06) ────────────────────────────────────────────
   Tableau + inspecteur. Pas de clone de messagerie : l'API ne porte aucun fil
   de discussion, seulement des enregistrements gouvernés. */
.v2-comm-layout { display: grid; grid-template-columns: 1fr; gap: var(--space-5); }
.v2-comm-layout:has(.v2-inspector) { grid-template-columns: minmax(0, 1fr) 360px; }
@media (max-width: 1100px) {
  .v2-comm-layout:has(.v2-inspector) { grid-template-columns: 1fr; }
}
.v2-comm-main { min-width: 0; }

/* Le canal se lit à son pictogramme et à son nom. Il ne colore pas la ligne :
   trois canaux qui crient rendent le tableau impossible à balayer (§22). */
.v2-channel {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--text-sm); color: var(--text-secondary); white-space: nowrap;
}
.v2-channel .v2-icon { width: 14px; height: 14px; opacity: .7; }

/* Ouvrir un enregistrement est un geste à faible friction : un bouton nu,
   aligné comme du texte. Les actions qui sortent vers un fournisseur vivent
   dans l'inspecteur, pas dans la ligne (§46, §47). */
.v2-comm-open {
  background: none; border: none; padding: 0; cursor: pointer; text-align: left;
  font-family: var(--font-ui); display: flex; flex-direction: column; min-width: 0;
}
.v2-comm-open:hover .v2-row-name { text-decoration: underline; }
.v2-comm-open:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.v2-row.is-selected td { background: var(--accent-subtle); }
.v2-comm-prospect { font-size: var(--text-sm); color: var(--accent); }

.v2-filter-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--text-xs); color: var(--text-secondary);
  border: 1px solid var(--border-default); border-radius: var(--radius-xs);
  padding: 3px var(--space-2);
}
.v2-filter-chip button {
  background: none; border: none; cursor: pointer; color: var(--text-faint);
  font-size: var(--text-md); line-height: 1; padding: 0;
}

.v2-inspector {
  border: 1px solid var(--border-default); border-radius: var(--radius-md);
  background: var(--bg-surface); display: flex; flex-direction: column;
  position: sticky; top: calc(var(--topbar-height) + var(--space-4));
  max-height: calc(100vh - var(--topbar-height) - var(--space-8));
}
.v2-inspector-head {
  display: flex; align-items: baseline; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}
.v2-inspector-close {
  margin-left: auto; background: none; border: none; cursor: pointer;
  color: var(--text-faint); font-size: var(--text-lg); line-height: 1; padding: 0 4px;
}
.v2-inspector-close:hover { color: var(--text-primary); }
.v2-inspector-body { padding: var(--space-4); overflow-y: auto; }
.v2-inspector-link { margin-top: var(--space-4); }
.v2-inspector-foot {
  border-top: 1px solid var(--border-subtle); padding: var(--space-3) var(--space-4);
  display: flex; gap: var(--space-2); flex-wrap: wrap;
}
/* L'action qui sort réellement vers un fournisseur est la SEULE en plein
   contraste. Tout le reste de l'écran est de la lecture. */
.v2-btn-send {
  background: var(--bg-inverse); color: var(--text-inverse);
  border: 1px solid var(--bg-inverse); border-radius: var(--radius-sm);
  padding: 5px var(--space-4); font-family: var(--font-ui);
  font-size: var(--text-sm); cursor: pointer;
}
.v2-btn-send[disabled] { opacity: .5; cursor: default; }

@media (max-width: 700px) {
  .v2-inspector { position: static; max-height: none; }
}

/* Inspecteur ouvert : le tableau perd sa colonne de priorité 3 plutôt que de
   la faire déborder derrière le panneau. Une colonne coupée en plein milieu
   d'une date se lit comme un défaut ; une colonne retirée se lit comme un
   choix — et elle revient dès la fermeture. */
.v2-comm-layout:has(.v2-inspector) .v2-table .p3 { display: none; }
.v2-comm-prospect { white-space: nowrap; }

/* ─── Centre d'opérations (DESIGN-07) ───────────────────────────────────────*/
.v2-ops-refresh { display: flex; align-items: center; gap: var(--space-3); }
.v2-ops-spacer { margin-left: auto; }
.v2-ops-hint { color: var(--text-faint); font-size: var(--text-xs); }
.v2-ops-subhead { margin-top: var(--space-4); }
.v2-ops-tasks, .v2-ops-svcs, .v2-ops-costs { list-style: none; margin: var(--space-2) 0 0; padding: 0; }
.v2-ops-task, .v2-ops-svc {
  display: flex; align-items: baseline; gap: var(--space-3); flex-wrap: wrap;
  padding: var(--space-2) 0; border-bottom: 1px solid var(--border-subtle);
  font-size: var(--text-sm);
}
.v2-ops-task:last-child, .v2-ops-svc:last-child { border-bottom: none; }
.v2-ops-task-cap { color: var(--text-muted); flex: 1 1 auto; }
.v2-ops-svc .cc-dot { align-self: center; }
.v2-ops-svc-status { color: var(--text-secondary); }
/* `deferred` = la sonde n'existe pas encore. Ni panne ni santé : ambre calme. */
.cc-dot.is-deferred { background: var(--warning); }
.v2-ops-cost {
  display: flex; justify-content: space-between; gap: var(--space-3);
  padding: 3px 0; font-size: var(--text-xs); color: var(--text-secondary);
}
.v2-ops-breakdowns {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4); margin-top: var(--space-2);
}
