/* =========================================================
   COMPONENT — Input / Field
   Remplaçant moderne de `.form-control` Bootstrap 3 (682 occ.).
   Structure :
     <div class="ds-field">
       <label class="ds-field__label" for="x">Libellé</label>
       <input id="x" class="ds-input" type="text">
       <span class="ds-field__hint">Texte d'aide</span>
     </div>

     Erreur :
     <div class="ds-field ds-field--error">
       …
       <span class="ds-field__error">Saisie obligatoire</span>
     </div>

   Sélecteurs natifs : <select class="ds-input"> et <textarea class="ds-input">.
   Compatible avec Select2 (qui remplace le <select> par son propre rendu).

   Testabilité (cf. 06-testability-guidelines.md) :
   - Toujours <label for="id"> lié à l'input (Playwright `getByLabel('Libellé')`).
   - En erreur : aria-invalid="true" + aria-describedby pointant vers
     l'<span class="ds-field__error" id="..." role="alert">.
   ========================================================= */

.ds-field {
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-1);
  margin-bottom: var(--ds-space-4);
}

.ds-field__label {
  font-size: var(--ds-font-size-sm);
  font-weight: var(--ds-font-weight-bold);     /* gras comme les <label> Bootstrap 3 / legacy */
  color: var(--ds-color-text);
  line-height: var(--ds-line-height-tight);
}

.ds-field__required {
  color: var(--ds-color-danger);
  margin-left: 2px;
}

.ds-field__hint {
  font-size: var(--ds-font-size-xs);
  color: var(--ds-color-text-muted);
  line-height: var(--ds-line-height-normal);
}

.ds-field__error {
  font-size: var(--ds-font-size-xs);
  color: var(--ds-color-danger);
  line-height: var(--ds-line-height-normal);
  display: none;
}

.ds-field--error .ds-field__error {
  display: block;
}

/* ---------- Input ---------- */

.ds-input,
select.ds-input,
textarea.ds-input {
  display: block;
  width: 100%;
  height: 36px;
  padding: 0 var(--ds-space-3);
  font-family: var(--ds-font-sans);
  font-size: var(--ds-font-size-md);
  line-height: var(--ds-line-height-normal);
  color: var(--ds-color-text);
  background: var(--ds-color-bg-surface);
  border: 1px solid var(--ds-color-border);
  border-radius: var(--ds-radius-md);
  transition: border-color var(--ds-transition-fast),
              box-shadow var(--ds-transition-fast),
              background var(--ds-transition-fast);
  appearance: none;
}

textarea.ds-input {
  height: auto;
  min-height: 80px;
  padding: var(--ds-space-2) var(--ds-space-3);
  resize: vertical;
  line-height: var(--ds-line-height-normal);
}

.ds-input::placeholder,
textarea.ds-input::placeholder {
  color: var(--ds-color-text-subtle);
}

.ds-input:hover {
  border-color: var(--ds-color-border-strong);
}

.ds-input:focus,
select.ds-input:focus,
textarea.ds-input:focus {
  outline: none;
  border-color: var(--ds-color-border-focus);
  box-shadow: var(--ds-shadow-focus);
}

.ds-input:disabled,
.ds-input[readonly] {
  background: var(--ds-color-gray-50);
  color: var(--ds-color-text-muted);
  cursor: not-allowed;
}

/* ---------- Select natif ---------- */

select.ds-input {
  padding-right: var(--ds-space-8);
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ds-color-text-muted) 50%),
    linear-gradient(135deg, var(--ds-color-text-muted) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 50%,
    calc(100% - 12px) 50%;
  background-size: 6px 6px;
  background-repeat: no-repeat;
}

/* ---------- Tailles ---------- */

.ds-input--sm { height: 30px; font-size: var(--ds-font-size-sm); padding: 0 var(--ds-space-2); }
.ds-input--lg { height: 44px; font-size: var(--ds-font-size-lg); padding: 0 var(--ds-space-4); }
/* #1866 — un champ DANS une phrase (liste déroulante d'une question « à trous ») : à la largeur de son contenu. */
.ds-input.ds-input--en-ligne { display: inline-block; width: auto; min-width: 150px; max-width: 100%; vertical-align: baseline; margin: 0 var(--ds-space-1); }

/* ---------- États de validation ---------- */

.ds-field--error .ds-input,
.ds-input.ds-input--error {
  border-color: var(--ds-color-danger);
}
.ds-field--error .ds-input:focus,
.ds-input.ds-input--error:focus {
  box-shadow: 0 0 0 3px rgba(237, 85, 101, 0.25);
}

.ds-field--success .ds-input,
.ds-input.ds-input--success {
  border-color: var(--ds-color-success);
}

/* ---------- Leading icon (icône intégrée à gauche de l'input) ----------
   Pattern moderne (Notion, Linear, Figma) : icône discrète positionnée
   à l'intérieur du champ, sans box séparée. Structure :
     <div class="ds-input-wrap">
       <i class="ds-input-wrap__leading fa fa-user"></i>
       <input class="ds-input ds-input--has-leading" type="text">
     </div>
   ---------------------------------------------------------------------- */
.ds-input-wrap {
  position: relative;
  display: block;
}
.ds-input-wrap__leading {
  position: absolute;
  left: var(--ds-space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--ds-color-text-subtle);
  font-size: var(--ds-font-size-md);
  pointer-events: none;
  line-height: 1;
}
.ds-input--has-leading {
  padding-left: 36px;
}
.ds-input-wrap:focus-within .ds-input-wrap__leading {
  color: var(--ds-color-text-muted);
}

/* ---------- Input group (préfixe / suffixe) ---------- */

.ds-input-group {
  display: flex;
  align-items: stretch;
  width: 100%;
}

.ds-input-group .ds-input {
  flex: 1 1 auto;
  min-width: 0;
  border-radius: 0;
}

.ds-input-group__addon {
  display: inline-flex;
  align-items: center;
  padding: 0 var(--ds-space-3);
  font-size: var(--ds-font-size-sm);
  color: var(--ds-color-text-muted);
  background: var(--ds-color-gray-50);
  border: 1px solid var(--ds-color-border);
}

.ds-input-group > :first-child {
  border-top-left-radius: var(--ds-radius-md);
  border-bottom-left-radius: var(--ds-radius-md);
}
.ds-input-group > :last-child {
  border-top-right-radius: var(--ds-radius-md);
  border-bottom-right-radius: var(--ds-radius-md);
}
.ds-input-group > * + * {
  border-left: 0;
}

/* ---------- Option discrète à droite du libellé (#1768) ----------
   <div class="ds-field__tete">
     <label class="ds-field__label" for="x">Chargé de recrutement</label>
     <label class="ds-check ds-check--discret"><input type="checkbox"><span>Anciens chargés</span></label>
   </div>
   Pour une option rarement utilisée qui modifie le champ : elle ne prend pas de ligne à elle. */
.ds-field__tete {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--ds-space-2);
  margin-bottom: var(--ds-space-1);
}
/* `> *` : les <label> reçoivent une marge basse de Bootstrap 3, qui grandirait la ligne. */
.ds-field__tete > *,
.ds-filtres .ds-field__tete > .ds-field__label { margin-bottom: 0; }
.ds-check.ds-check--discret {   /* deux classes : l'emporte sur `.ds-root label` (legacy-skin) */
  gap: var(--ds-space-1);
  font-weight: var(--ds-font-weight-regular);
  font-size: var(--ds-font-size-xs);
  color: var(--ds-color-text-muted);
  white-space: nowrap;
}
/* Ni la case ni son texte ne grandissent la ligne du libellé : le champ reste aligné sur ses voisins. */
.ds-field__tete { align-items: center; }
.ds-field__tete .ds-check.ds-check--discret { line-height: 1; max-height: 14px; }
.ds-field__tete .ds-check.ds-check--discret input[type="checkbox"] { width: 12px; height: 12px; margin: 0; }

/* ---------- Checkbox & Radio natifs ---------- */

.ds-check {
  display: inline-flex;
  align-items: center;
  gap: var(--ds-space-2);
  font-size: var(--ds-font-size-md);
  color: var(--ds-color-text);
  cursor: pointer;
  user-select: none;
}

.ds-check input[type="checkbox"],
.ds-check input[type="radio"] {
  width: 16px;
  height: 16px;
  margin: 0;
  cursor: pointer;
  accent-color: var(--ds-color-secondary);
}

.ds-check input:disabled + span,
.ds-check input:disabled {
  color: var(--ds-color-text-muted);
  cursor: not-allowed;
}

/* ---------- Switch (Oui/Non) ---------- */

.ds-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex: 0 0 auto;
}

.ds-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.ds-switch__slider {
  position: absolute;
  inset: 0;
  background: var(--ds-color-gray-300);
  border-radius: var(--ds-radius-pill);
  transition: background var(--ds-transition-base);
  cursor: pointer;
}

.ds-switch__slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  top: 3px;
  left: 3px;
  background: var(--ds-color-white);
  border-radius: 50%;
  transition: transform var(--ds-transition-base);
  box-shadow: var(--ds-shadow-xs);
}

.ds-switch input:checked + .ds-switch__slider {
  background: var(--ds-color-secondary);
}

.ds-switch input:checked + .ds-switch__slider::before {
  transform: translateX(20px);
}

.ds-switch input:focus-visible + .ds-switch__slider {
  box-shadow: var(--ds-shadow-focus);
}

.ds-switch input:disabled + .ds-switch__slider {
  opacity: 0.5;
  cursor: not-allowed;
}
