/* ==========================================================================
   File — dépôt de fichier (#1714)
   --------------------------------------------------------------------------
   Habille un <input type="file"> natif, qui reste dans la page (même id, même
   data-testid, même lecture `input.files` par l'écran) : seul son rendu change.

   Deux présentations, une règle (cf. 07-usage-policy.md § Dépôt de fichier) :
     data-ds-file="zone"   UN fichier attendu, au cœur du geste (un modèle, une
                           signature, un PDF de référence) : grande zone où glisser.
     data-ds-file="champ"  plusieurs fichiers, ou un fichier facultatif (pièces
                           jointes) : un champ de la hauteur des autres.

   .ds-file                      conteneur posé par DS.File autour du champ natif
     .ds-file__input             le champ natif, masqué mais focalisable
     .ds-file__cible             ce qu'on clique ou survole avec un fichier
       [--survol]                un fichier est glissé au-dessus
     .ds-file__fichier           un fichier retenu (zone, ou champ à un fichier)
     .ds-file__puces             les fichiers retenus d'un champ multiple
     .ds-file__type              pastille du format (DOCX, PDF, PNG…)
     .ds-file__aide / __erreur   formats et taille, ou ce qui a été refusé
   [--erreur]                    un fichier vient d'être refusé
   ========================================================================== */

.ds-file { display: flex; flex-direction: column; gap: var(--ds-space-1); min-width: 0; }
/* Une zone prend toute la largeur, même posée dans une `ds-row` dont les champs se resserrent. */
.ds-row > .ds-field:has(> .ds-file--zone) { flex: 1 1 100%; }

.ds-file__input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  opacity: 0;
}

.ds-file__cible { cursor: pointer; font-weight: var(--ds-font-weight-normal, 400); }
.ds-file__lien {
  color: var(--ds-color-secondary-active, #5f8a56);
  font-weight: var(--ds-font-weight-semibold, 600);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.ds-file__aide { font-size: var(--ds-font-size-xs); color: var(--ds-color-text-muted); }
.ds-file__erreur {
  display: flex;
  gap: var(--ds-space-1);
  align-items: center;
  font-size: var(--ds-font-size-xs);
  color: var(--ds-color-danger-strong);
}

/* Pastille de format : une page cornée, teintée selon la famille de fichier. */
.ds-file__type {
  position: relative;
  flex: none;
  display: grid;
  place-items: end center;
  width: 28px;
  height: 32px;
  padding-bottom: 4px;
  border-radius: 4px;
  background: var(--ds-color-gray-100);
  color: var(--ds-color-gray-600);
  font-size: 8.5px;
  font-weight: var(--ds-font-weight-bold, 700);
  letter-spacing: .02em;
}
.ds-file__type::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 8px;
  height: 8px;
  background: var(--ds-color-bg-surface);
  border-bottom-left-radius: 3px;
  box-shadow: -1px 1px 0 rgba(20, 26, 31, .08);
}
.ds-file__type--doc, .ds-file__type--docx { background: #e6edf7; color: #2b579a; }
.ds-file__type--pdf { background: var(--ds-color-danger-soft); color: var(--ds-color-danger-strong); }
.ds-file__type--png, .ds-file__type--jpg, .ds-file__type--jpeg, .ds-file__type--gif, .ds-file__type--webp {
  background: var(--ds-color-info-soft); color: var(--ds-color-info-strong);
}
.ds-file__type--xls, .ds-file__type--xlsx, .ds-file__type--csv { background: var(--ds-color-success-soft); color: var(--ds-color-success-strong); }

.ds-file__nom { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: var(--ds-font-weight-semibold, 600); color: var(--ds-color-text); }
.ds-file__taille { color: var(--ds-color-text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

.ds-file__retirer {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: var(--ds-radius-sm);
  background: transparent;
  color: var(--ds-color-text-muted);
  cursor: pointer;
}
.ds-file__retirer:hover { background: var(--ds-color-bg-muted); color: var(--ds-color-danger-strong); }
.ds-file__retirer:focus-visible { outline: none; box-shadow: var(--ds-shadow-focus); }

/* ---------------------------------------------------------------- Zone */
.ds-file--zone .ds-file__cible {
  display: grid;
  justify-items: center;
  gap: var(--ds-space-1);
  padding: var(--ds-space-5) var(--ds-space-4);
  border: 1.5px dashed var(--ds-color-border-strong);
  border-radius: var(--ds-radius-lg, 8px);
  background: var(--ds-color-bg-muted);
  text-align: center;
  color: var(--ds-color-text-muted);
  transition: border-color var(--ds-transition-fast, .15s), background var(--ds-transition-fast, .15s);
}
.ds-file--zone .ds-file__cible strong { color: var(--ds-color-text); font-size: var(--ds-font-size-md); }
.ds-file--zone .ds-file__cible:hover { border-color: var(--ds-color-secondary); }
.ds-file--zone .ds-file__pictogramme {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  margin-bottom: var(--ds-space-1);
  border: 1px solid var(--ds-color-border);
  border-radius: 50%;
  background: var(--ds-color-bg-surface);
  color: var(--ds-color-secondary-active, #5f8a56);
  transition: transform .2s;
}
.ds-file--zone .ds-file__cible--survol { border-style: solid; border-color: var(--ds-color-secondary); background: var(--ds-color-secondary-soft); }
.ds-file--zone .ds-file__cible--survol .ds-file__pictogramme {
  transform: translateY(-3px);
  border-color: var(--ds-color-secondary);
  background: var(--ds-color-secondary);
  color: var(--ds-color-white);
}
.ds-file--zone.ds-file--erreur .ds-file__cible { border-color: var(--ds-color-danger); background: var(--ds-color-danger-soft); }

.ds-file--zone .ds-file__fichier {
  display: flex;
  align-items: center;
  gap: var(--ds-space-3);
  min-width: 0;
  padding: var(--ds-space-2) var(--ds-space-2) var(--ds-space-2) var(--ds-space-3);
  border: 1px solid var(--ds-color-border);
  border-radius: var(--ds-radius-lg, 8px);
  background: var(--ds-color-bg-surface);
}
.ds-file--zone .ds-file__texte { display: grid; gap: 1px; flex: 1; min-width: 0; font-size: var(--ds-font-size-md); }
.ds-file--zone .ds-file__actions { display: flex; align-items: center; gap: var(--ds-space-1); }

/* ---------------------------------------------------------------- Champ */
.ds-file--champ .ds-file__cible {
  display: flex;
  align-items: center;
  gap: var(--ds-space-2);
  height: 36px;
  padding: 0 var(--ds-space-1) 0 var(--ds-space-3);
  border: 1px solid var(--ds-color-border);
  border-radius: var(--ds-radius-md);
  background: var(--ds-color-bg-surface);
  color: var(--ds-color-text-muted);
  transition: border-color var(--ds-transition-fast, .15s), box-shadow var(--ds-transition-fast, .15s), background var(--ds-transition-fast, .15s);
}
.ds-file--champ .ds-file__cible:hover { border-color: var(--ds-color-border-strong); }
.ds-file--champ .ds-file__invite { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ds-color-text-subtle); font-size: var(--ds-font-size-md); }
.ds-file--champ .ds-file__parcourir {
  flex: none;
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 var(--ds-space-2);
  border: 1px solid var(--ds-color-border);
  border-radius: var(--ds-radius-md);
  color: var(--ds-color-text);
  font-size: var(--ds-font-size-sm);
  font-weight: var(--ds-font-weight-semibold, 600);
}
.ds-file--champ .ds-file__cible--survol { border-style: dashed; border-color: var(--ds-color-secondary); background: var(--ds-color-secondary-soft); }
.ds-file--champ .ds-file__cible--survol .ds-file__invite { color: var(--ds-color-secondary-active, #5f8a56); }
.ds-file--champ.ds-file--erreur .ds-file__cible { border-color: var(--ds-color-danger); }
.ds-file--champ .ds-file__fichier { flex: 1; display: flex; align-items: center; gap: var(--ds-space-2); min-width: 0; font-size: var(--ds-font-size-sm); }
.ds-file--champ .ds-file__type { width: 20px; height: 24px; padding-bottom: 2px; font-size: 6.5px; }
.ds-file--champ .ds-file__type::before { width: 6px; height: 6px; }

.ds-file__puces { display: flex; flex-wrap: wrap; gap: var(--ds-space-1); }
.ds-file__puce {
  display: inline-flex;
  align-items: center;
  gap: var(--ds-space-2);
  max-width: 100%;
  height: 28px;
  padding: 0 2px 0 var(--ds-space-2);
  border: 1px solid var(--ds-color-border);
  border-radius: var(--ds-radius-pill);
  background: var(--ds-color-bg-muted);
  font-size: var(--ds-font-size-sm);
}
.ds-file__puce .ds-file__nom { font-weight: var(--ds-font-weight-normal, 400); }
.ds-file__puce .ds-file__retirer { width: 22px; height: 22px; border-radius: 50%; }

/* Le focus clavier tombe sur le champ natif masqué : la cible le montre, ou la fiche du
   fichier retenu quand une zone a caché sa cible. */
.ds-file__input:focus-visible + .ds-file__cible,
.ds-file__input:focus-visible ~ .ds-file__fichier,
.ds-file__cible:focus-within {
  border-color: var(--ds-color-border-focus);
  box-shadow: var(--ds-shadow-focus);
}

@media (prefers-reduced-motion: reduce) {
  .ds-file__cible, .ds-file__pictogramme { transition: none; }
}
