/* ==========================================================================
   STATE COMPONENTS
   ========================================================================== */

/* Loading States */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-12) var(--space-8);
  text-align: center;
  color: var(--text-secondary);
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 2px solid var(--gray-200);
  border-top: 2px solid var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: var(--space-4);
}

/* ── LA ROUE SEULE EST VRAIMENT CENTRÉE ───────────────────────────────────
   `margin-bottom` n'existe que pour ÉCARTER la roue du texte qu'elle coiffait.
   Depuis le 14-09 le texte est l'exception (`loading_state()` rend la roue
   nue) : gardée sans lui, cette marge pousse la roue de 16 px vers le haut de
   son bloc et « centré » devient faux — exactement la chose qu'on venait de
   demander. On la retire quand la roue est le DERNIER enfant, donc le seul. */
.loading-state > .loading-spinner:last-child,
.table-loading > .loading-spinner:last-child {
  margin-bottom: 0;
}

.loading-spinner.inline {
  display: inline-block;
  vertical-align: middle;
  width: 1rem;
  height: 1rem;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  animation: spin 0.6s linear infinite;
  margin: 0;
  flex-shrink: 0;
  align-self: center;
}

/* Boutons à fond CLAIR : le blanc-sur-transparent ci-dessus (pensé pour
   btn-primary) y est invisible — le bouton s'élargissait sans spinner
   apparent. Même géométrie, teintes lisibles sur clair. */
.btn-secondary .loading-spinner.inline,
.btn-ghost .loading-spinner.inline,
.btn-outline .loading-spinner.inline {
  border-color: var(--gray-200);
  border-top-color: var(--text-secondary);
}

/* ── L'ATTENTE D'UNE PAGE — la roue SEULE, sur le fond de page ────────────
   Décisions Olivier du 14-09 : « 1 seul [spinner] suffit, centré », « je veux
   pas voir de cadre blanc au chargement, c'est le spinner sur le gris centré
   sur la page », « ça devrait pas afficher le header et le cadre du tableau
   tant qu'il n'est pas prêt ».

   ⚠ CE BLOC N'EST PAS UNE CARTE, et c'est tout le propos : ni fond, ni
   bordure, ni ombre. Le conteneur qu'il remplace (la carte d'une synthèse, la
   coquille d'une liste) est REPLIÉ tant que rien n'est peint — un cadre
   dessiné autour d'une roue promet une forme que le contenu ne prendra pas.

   ⚠ LE CENTRAGE VERTICAL SE PAIE PAR UNE HAUTEUR, jamais par une marge : une
   roue centrée dans un bloc de la hauteur de son propre rembourrage est
   centrée dans 96 px, c'est-à-dire collée en haut de la page. `.loading-state`
   fait le reste (flex, centré sur les deux axes) et son rembourrage devient
   donc inutile. */
.page-wait {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 55vh;
}

.page-wait > .loading-state { padding: 0; }

/* ── UNE ROUE INLINE HORS D'UN BOUTON ─────────────────────────────────────
   `.loading-spinner.inline` est dessinée pour `btn-primary` : blanc sur
   transparent. Posée dans une cellule, un libellé ou une liste, elle est
   INVISIBLE — et une attente qu'on ne voit pas ne se distingue pas d'un bloc
   vide, c'est-à-dire de « rien à montrer ». Les boutons à fond clair ont leur
   correctif juste au-dessus ; ceci est le même, pour ce qui n'est pas un
   bouton. Opt-in, parce qu'un sélecteur « tout sauf un bouton » repeindrait
   aussi les roues des boutons à venir. */
.loading-spinner.inline.on-surface {
  border-color: var(--gray-200);
  border-top-color: var(--primary);
}

.line-items-loading {
  opacity: 0.6;
  pointer-events: none;
}

.financial-summary-loading .financial-summary-value {
  background: var(--gray-200);
  color: transparent;
  border-radius: var(--radius-sm);
  animation: pulse 1.5s ease-in-out infinite;
}

/* Empty States */
.empty-state,
.empty-content {
  text-align: center;
  padding: var(--space-12) var(--space-8);
  background: var(--surface);
  border-radius: var(--radius);
  border: 2px dashed var(--border);
  color: var(--text-secondary);
}

.empty-state-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto var(--space-8);
  color: var(--text-muted);
  opacity: 0.7;
}

.empty-state-icon svg {
  width: 64px !important;
  height: 64px !important;
}

.empty-state-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: var(--space-3);
  color: var(--text);
}

.empty-state-description {
  color: var(--text-secondary);
  margin-bottom: var(--space-8);
  font-size: 0.9375rem;
  line-height: 1.5;
  max-width: 500px;
  margin-left: auto;
  margin-right: auto;
}

/* Spacing between adjacent CTAs (multi-button empty_state via 'extra_buttons') */
.empty-state .btn + .btn {
  margin-left: var(--space-2);
}

/* Compact section-level empty placeholder (section_empty() helper) — for
   sub-sections in detail pages where the full .empty-state hero treatment
   would be visually too large. Single short line of muted text. */
.section-empty {
  padding: var(--space-4) var(--space-6);
  margin-bottom: var(--space-6);
  text-align: center;
  background: var(--surface);
  border-radius: var(--radius);
}

.section-empty p {
  margin: 0;
  font-size: 0.9375rem;
  color: var(--text-secondary);
}

.empty-content p {
  margin: var(--space-2) 0;
  font-size: 0.875rem;
}

/* Table States — in-tbody flat rows for empty / loading / error cases.
   Use when <thead> must stay visible. Helpers: table_empty_row(),
   table_loading_row(), table_error_row() / window.tableEmptyRow(),
   window.tableLoadingRow(), window.tableErrorRow(). */
.table-empty,
.table-loading,
.table-error {
  text-align: center;
  padding: var(--space-8) var(--space-4);
  color: var(--text-secondary);
}

.table-loading {
  color: var(--text-muted);
}

.table-loading .loading-spinner {
  margin: 0 auto var(--space-3);
}

.table-error {
  color: var(--error);
}

/* `base.css` pose `svg { display: block }` : un SVG en bloc IGNORE le
   `text-align: center` du parent. Il faut donc une largeur + marge auto sur le
   conteneur, comme le fait `.empty-state-icon`. Sans ça l'icône se colle à
   gauche pendant que le titre reste centré — visible sur toute liste en erreur
   (corrigé 2026-08-01 ; le spinner de `.table-loading`, lui, avait déjà sa
   marge auto, d'où le décalage entre les trois états côte à côte). */
.table-error-icon {
  color: var(--error);
  width: 32px;
  margin: 0 auto var(--space-3);
  opacity: 0.9;
  line-height: 0;
}

.table-error-icon svg {
  width: 32px;
  height: 32px;
}

.table-error-title {
  font-weight: 600;
  color: var(--error);
  font-size: 0.9375rem;
  margin: 0;
}

.table-error-description {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin: var(--space-1) auto 0;
  max-width: 420px;
  line-height: 1.5;
}

.table-error-actions {
  margin-top: var(--space-4);
}

/* Même correction que `.table-error-icon` ci-dessus — voir son commentaire. */
.table-empty-icon {
  color: var(--text-muted);
  width: 32px;
  margin: 0 auto var(--space-3);
  opacity: 0.7;
  line-height: 0;
}

.table-empty-icon svg {
  width: 32px;
  height: 32px;
}

.table-empty-title {
  font-weight: 600;
  color: var(--text);
  font-size: 0.9375rem;
  margin: 0;
}

.table-empty-description {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin: var(--space-1) auto 0;
  max-width: 420px;
  line-height: 1.5;
}

.table-empty-actions {
  margin-top: var(--space-4);
}

/* Info Box */
.info-box {
  background: var(--gray-50);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
}

.info-box h4 {
  margin: 0 0 var(--space-3) 0;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
}

/* Image Gallery States */
.image-preview-container {
  width: 100%;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--border);
  border-radius: 0.5rem;
  padding: 1rem;
  background-color: var(--gray-50);
}

.image-placeholder {
  text-align: center;
  color: var(--gray-400);
}

.image-preview-container img {
  max-width: 100%;
  height: auto;
  object-fit: contain;
}

/* Mobile Responsive */
@media (max-width: 480px) {
  .loading-state {
    padding: var(--space-8) var(--space-4);
  }
  
  .empty-state {
    padding: var(--space-8) var(--space-6);
  }
}