/*
  Noren : champs de formulaire.
  Les couleurs, tailles et rayons viennent des variables de main.css.
  Exceptions locales (voir :root ci-dessous) : --rouge-texte (rouge assez
  foncé pour un texte AA) et les masques d'icônes (coche, chevron), qui
  prennent la couleur du fond via background-color (donc une variable).

  Exemples de HTML :

  Champ texte avec aide et erreur :
  <div class="champ">
    <label class="champ__label" for="nom">Votre nom</label>
    <input class="saisie est-invalide" id="nom" type="text" aria-invalid="true" aria-describedby="nom-aide nom-erreur">
    <p class="champ__aide" id="nom-aide">Comme sur votre pièce d'identité.</p>
    <p class="champ__erreur" id="nom-erreur" role="alert">
      <svg class="icone icone--petite" aria-hidden="true"><use href="/assets/icons.svg#alert-triangle"></use></svg>
      Indiquez votre nom.
    </p>
  </div>

  Téléphone (préfixe +229) :
  <div class="champ">
    <label class="champ__label" for="tel">Téléphone</label>
    <div class="champ-telephone">
      <span class="champ-telephone__prefixe">+229</span>
      <input class="champ-telephone__saisie" id="tel" type="tel" inputmode="tel" autocomplete="tel-national">
    </div>
  </div>

  Liste déroulante :
  <div class="champ">
    <label class="champ__label" for="quartier">Quartier</label>
    <div class="champ-select">
      <select class="saisie" id="quartier"><option>Fidjrossè</option></select>
    </div>
  </div>

  Zone de texte :
  <textarea class="saisie" id="message" rows="4"></textarea>

  Case à cocher, radio, interrupteur (le label est la zone tactile) :
  <label class="option"><input class="case" type="checkbox"> J'accepte les conditions</label>
  <label class="option"><input class="radio" type="radio" name="tri"> Plus proche</label>
  <label class="option"><input class="interrupteur" type="checkbox" role="switch"> Je suis disponible</label>

  Curseur :
  <label class="champ__label" for="rayon">Rayon de recherche</label>
  <input class="curseur" id="rayon" type="range" min="1" max="10" value="3">

  Cartes de choix (véhicule) :
  <fieldset class="rangee">
    <legend class="visuellement-cache">Type de véhicule</legend>
    <label class="choix-carte">
      <input class="choix-carte__input" type="radio" name="vehicule" value="moto">
      <svg class="icone" aria-hidden="true"><use href="/assets/icons.svg#motorbike"></use></svg>
      <span class="choix-carte__texte">Moto</span>
      <span class="choix-carte__coche" aria-hidden="true"></span>
    </label>
  </fieldset>
*/

:root {
  --rouge-texte: #b42318; /* rouge foncé : texte d'erreur lisible (AA) sur blanc */
  --bordure-champ: var(--slate-400); /* contour des champs : contraste suffisant */
  --masque-coche: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 12 5 5L20 7'/%3E%3C/svg%3E");
  --masque-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

/* ---------- Bloc champ ---------- */
.champ {
  display: flex;
  flex-direction: column;
  gap: var(--espace-1);
}

.champ__label {
  color: var(--navy-900);
  font-size: var(--texte-s);
  font-weight: 600;
  line-height: var(--interligne-s);
}

.champ__aide {
  color: var(--texte-secondaire);
  font-size: var(--texte-s);
  line-height: var(--interligne-s);
}

.champ__erreur {
  display: flex;
  align-items: flex-start;
  gap: var(--espace-1);
  color: var(--rouge-texte);
  font-size: var(--texte-s);
  font-weight: 500;
  line-height: var(--interligne-s);
}
.champ__erreur .icone {
  margin-top: 1px;
  color: var(--red-500);
}
.champ__erreur:empty {
  display: none;
}

/* ---------- Saisies : texte, select, textarea ---------- */
.saisie {
  display: block;
  width: 100%;
  min-height: var(--hauteur-bouton);
  margin: 0;
  padding: 0 var(--espace-2);
  border: 1px solid var(--bordure-champ);
  border-radius: var(--rayon-champ);
  background: var(--surface);
  color: var(--texte);
  font-family: var(--police-texte);
  font-size: var(--texte-base);
  line-height: var(--interligne-base);
  -webkit-appearance: none;
  appearance: none;
}

.saisie::placeholder {
  color: var(--texte-secondaire);
  opacity: 1;
}

textarea.saisie {
  min-height: 104px;
  padding: 14px var(--espace-2);
  resize: vertical;
}

/* Focus : bordure et contour navy bien visibles */
.saisie:focus,
.saisie:focus-visible {
  border-color: var(--navy-900);
  outline: 2px solid var(--lien);
  outline-offset: 2px;
  box-shadow: none;
}

/* Invalide : bordure rouge épaissie (le message avec icône l'accompagne) */
.saisie.est-invalide,
.saisie[aria-invalid="true"] {
  border-color: var(--red-500);
  box-shadow: inset 0 0 0 1px var(--red-500);
}
.saisie.est-invalide:focus,
.saisie[aria-invalid="true"]:focus {
  border-color: var(--navy-900);
  box-shadow: none;
}

.saisie:disabled {
  background: var(--slate-50);
  color: var(--slate-400);
  border-color: var(--bordure);
  cursor: not-allowed;
}

/* ---------- Téléphone : préfixe +229 collé à gauche ---------- */
.champ-telephone {
  display: flex;
  align-items: stretch;
  min-height: var(--hauteur-bouton);
  border: 1px solid var(--bordure-champ);
  border-radius: var(--rayon-champ);
  background: var(--surface);
  overflow: hidden;
}

.champ-telephone__prefixe {
  display: flex;
  align-items: center;
  padding: 0 var(--espace-2);
  border-right: 1px solid var(--bordure-champ);
  background: var(--slate-50);
  color: var(--navy-900);
  font-weight: 600;
  white-space: nowrap;
}

.champ-telephone__saisie {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 0 var(--espace-2);
  border: 0;
  background: transparent;
  color: var(--texte);
  font-family: var(--police-texte);
  font-size: var(--texte-base);
  line-height: var(--interligne-base);
}
.champ-telephone__saisie:focus,
.champ-telephone__saisie:focus-visible {
  outline: none;
  box-shadow: none;
}

/* Le focus se voit sur tout le bloc */
.champ-telephone:focus-within {
  border-color: var(--navy-900);
  outline: 2px solid var(--lien);
  outline-offset: 2px;
}

.champ-telephone.est-invalide {
  border-color: var(--red-500);
  box-shadow: inset 0 0 0 1px var(--red-500);
}
.champ-telephone.est-invalide:focus-within {
  border-color: var(--navy-900);
  box-shadow: none;
}

/* ---------- Select avec chevron ---------- */
.champ-select {
  position: relative;
}
.champ-select .saisie {
  padding-right: var(--espace-6);
  cursor: pointer;
}
.champ-select::after {
  content: "";
  position: absolute;
  top: 50%;
  right: var(--espace-2);
  width: 20px;
  height: 20px;
  margin-top: -10px;
  background-color: var(--texte-secondaire);
  -webkit-mask: var(--masque-chevron) center / contain no-repeat;
  mask: var(--masque-chevron) center / contain no-repeat;
  pointer-events: none;
}

/* ---------- Ligne d'option (zone tactile ≥ 48 px) ---------- */
.option {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--zone-tactile);
  color: var(--texte);
  font-size: var(--texte-base);
  line-height: var(--interligne-base);
  cursor: pointer;
}

/* ---------- Case à cocher ---------- */
.case,
.radio {
  position: relative;
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  margin: 0;
  border: 2px solid var(--bordure-champ);
  background: var(--surface);
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.case {
  border-radius: 4px;
}
.case::before {
  content: "";
  position: absolute;
  inset: 2px;
  background-color: var(--surface);
  -webkit-mask: var(--masque-coche) center / contain no-repeat;
  mask: var(--masque-coche) center / contain no-repeat;
  transform: scale(0);
}
.case:checked {
  background: var(--navy-900);
  border-color: var(--navy-900);
}
.case:checked::before {
  transform: scale(1);
}

/* ---------- Bouton radio ---------- */
.radio {
  border-radius: var(--rayon-pilule);
}
.radio::before {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: var(--rayon-pilule);
  background: var(--navy-900);
  transform: scale(0);
}
.radio:checked {
  border-color: var(--navy-900);
}
.radio:checked::before {
  transform: scale(1);
}

.case:focus-visible,
.radio:focus-visible,
.interrupteur:focus-visible,
.curseur:focus-visible {
  outline: 2px solid var(--lien);
  outline-offset: 2px;
  box-shadow: none;
}

.case:disabled,
.radio:disabled,
.interrupteur:disabled,
.curseur:disabled {
  opacity: .5;
  cursor: not-allowed;
}

/* ---------- Interrupteur (input checkbox) : vert quand actif ---------- */
.interrupteur {
  position: relative;
  flex-shrink: 0;
  width: 52px;
  height: 32px;
  margin: 0;
  border-radius: var(--rayon-pilule);
  background: var(--slate-400);
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  transition: background-color .2s ease;
}
.interrupteur::before {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 24px;
  height: 24px;
  border-radius: var(--rayon-pilule);
  background: var(--surface);
  transition: transform .2s ease;
}
.interrupteur:checked {
  background: var(--action);
}
.interrupteur:checked::before {
  transform: translateX(20px);
}

/* ---------- Curseur (input range) : piste verte, pouce blanc rond ---------- */
.curseur {
  display: block;
  width: 100%;
  height: var(--zone-tactile);
  margin: 0;
  background: transparent;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.curseur::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: var(--rayon-pilule);
  background: var(--action);
}
.curseur::-moz-range-track {
  height: 8px;
  border-radius: var(--rayon-pilule);
  background: var(--action);
}

.curseur::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 28px;
  height: 28px;
  margin-top: -10px; /* centre le pouce sur la piste : (8 - 28) / 2 */
  border: 2px solid var(--action-survol);
  border-radius: var(--rayon-pilule);
  background: var(--surface);
  box-shadow: none;
  border: 1px solid var(--bordure);
}
.curseur::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border: 2px solid var(--action-survol);
  border-radius: var(--rayon-pilule);
  background: var(--surface);
  box-shadow: none;
  border: 1px solid var(--bordure);
}

/* ---------- Cartes de choix (véhicule) ---------- */
.choix-carte {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--espace-1);
  min-width: 96px;
  min-height: 96px;
  padding: var(--espace-2);
  border: 2px solid var(--bordure);
  border-radius: var(--rayon-carte);
  background: var(--surface);
  color: var(--navy-900);
  text-align: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .2s ease, border-color .2s ease;
}

.choix-carte:hover {
  border-color: var(--bordure-champ);
}

/* L'input reste dans le flux d'accessibilité (clavier, lecteurs d'écran) mais invisible */
.choix-carte__input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.choix-carte__texte {
  font-size: var(--texte-s);
  font-weight: 600;
  line-height: var(--interligne-s);
}

/* Petite coche en haut à droite, visible seulement si coché */
.choix-carte__coche {
  position: absolute;
  top: var(--espace-1);
  right: var(--espace-1);
  display: none;
  width: 20px;
  height: 20px;
  border-radius: var(--rayon-pilule);
  background: var(--navy-900);
}
.choix-carte__coche::after {
  content: "";
  position: absolute;
  inset: 4px;
  background-color: var(--surface);
  -webkit-mask: var(--masque-coche) center / contain no-repeat;
  mask: var(--masque-coche) center / contain no-repeat;
}

/* Coché : bordure navy 2 px + fond vert clair + coche */
.choix-carte:has(.choix-carte__input:checked) {
  border-color: var(--navy-900);
  background: var(--action-pale);
}
.choix-carte__input:checked ~ .choix-carte__coche {
  display: block;
}

/* Focus clavier : anneau sur toute la carte */
.choix-carte:has(.choix-carte__input:focus-visible) {
  outline: 2px solid var(--lien);
  outline-offset: 2px;
  box-shadow: none;
}

.choix-carte:has(.choix-carte__input:disabled) {
  opacity: .5;
  cursor: not-allowed;
}
