/* ==========================================================================
   forms.css — eHaj Design System
   Django form styling: text/number/email/password/date/file inputs,
   textarea, select/select-multiple, checkboxes, radios, required markers,
   error states, help_text, fieldsets, multi-column & long forms.

   Scope: everything below is scoped under `.eh-form` so it never touches
   Django Admin markup or unrelated inputs elsewhere on the site.
   Wrap a Django form like this:

     <form class="eh-form" method="post" novalidate>
       {% csrf_token %}
       ...
     </form>

   Requires base.css + buttons.css (for .eh-form-actions buttons).
   ========================================================================== */

.eh-form {
  display: flex;
  flex-direction: column;
  gap: var(--eh-space-5);
}

/* --------------------------------------------------------------------------
   Champs de base
   -------------------------------------------------------------------------- */

.eh-form label {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--eh-text);
  font-weight: 600;
  font-size: 0.88rem;
}

.eh-form .eh-required::after {
  content: " *";
  color: var(--eh-danger);
}

.eh-form input[type="text"],
.eh-form input[type="search"],
.eh-form input[type="email"],
.eh-form input[type="password"],
.eh-form input[type="number"],
.eh-form input[type="tel"],
.eh-form input[type="url"],
.eh-form input[type="date"],
.eh-form input[type="datetime-local"],
.eh-form input[type="time"],
.eh-form input[type="month"],
.eh-form select,
.eh-form textarea {
  width: 100%;
  min-height: 44px;
  padding: 0.6rem 0.85rem;
  background: var(--eh-white);
  border: 1px solid var(--eh-border-strong);
  border-radius: var(--eh-radius-sm);
  color: var(--eh-text);
  font: inherit;
  font-size: 0.92rem;
  transition: border-color var(--eh-transition), box-shadow var(--eh-transition);
}

.eh-form textarea {
  min-height: 120px;
  resize: vertical;
}

.eh-form input::placeholder,
.eh-form textarea::placeholder {
  color: var(--eh-text-muted);
}

.eh-form input:hover,
.eh-form select:hover,
.eh-form textarea:hover {
  border-color: var(--eh-text-muted);
}

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

.eh-form input:disabled,
.eh-form select:disabled,
.eh-form textarea:disabled,
.eh-form input[readonly] {
  background: var(--eh-bg-muted);
  border-color: var(--eh-border);
  color: var(--eh-text-muted);
  cursor: not-allowed;
}

/* --------------------------------------------------------------------------
   Autocomplete (voir apps.dashboard.widgets.AutocompleteSelect +
   static/js/autocomplete.js) — remplace un <select> pour les listes trop
   longues à parcourir (ex. Organization.objects.all() pour un superuser).
   -------------------------------------------------------------------------- */

.eh-form .eh-autocomplete {
  position: relative;
}

.eh-form .eh-autocomplete-list {
  position: absolute;
  z-index: 10;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 260px;
  overflow-y: auto;
  background: var(--eh-surface);
  border: 1px solid var(--eh-border-strong);
  border-radius: var(--eh-radius-sm);
  box-shadow: var(--eh-shadow);
  padding: 0.35rem;
}

.eh-form .eh-autocomplete-option {
  display: block;
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 0;
  background: none;
  border-radius: var(--eh-radius-sm);
  text-align: left;
  font: inherit;
  font-size: 0.9rem;
  color: var(--eh-text);
  cursor: pointer;
}

.eh-form .eh-autocomplete-option:hover,
.eh-form .eh-autocomplete-option.is-highlighted {
  background: var(--eh-bg-soft);
}

.eh-form .eh-autocomplete-empty {
  padding: 0.5rem 0.65rem;
  margin: 0;
  color: var(--eh-text-muted);
  font-size: 0.88rem;
}

/* --- Select --- */

.eh-form select {
  appearance: none;
  padding-right: 2.4rem;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--eh-text-soft) 50%),
    linear-gradient(135deg, var(--eh-text-soft) 50%, transparent 50%);
  background-position: right 1.05rem center, right 0.75rem center;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

.eh-form select[multiple] {
  min-height: 140px;
  padding: 0.4rem;
  background-image: none;
}

.eh-form select[multiple] option {
  padding: 0.45rem 0.6rem;
  border-radius: var(--eh-radius-sm);
}

.eh-form select[multiple] option:checked {
  background: var(--eh-green-100);
  color: var(--eh-green-900);
}

/* --- Actions groupées (voir templates/_bulk_actions.html) : classes
   distinctes par écran (passées via `widget_class`/`select_class` à
   l'include) plutôt que des sélecteurs [data-bulk-actions]/`select`
   génériques partagés, pour pouvoir régler séparément taille/padding/
   police de chaque select sans se marcher dessus. Duplication volontaire
   — ne pas fusionner en un seul sélecteur. `height`/`font-size` sont
   déclarés explicitement ici (reprenant pour l'instant les valeurs par
   défaut de .eh-form select/select ci-dessus) pour être réglables
   indépendamment sur .eh-select-pilgrims / .eh-select-appointment-days,
   sans toucher au reste des formulaires du site.

   `min-height` doit être écrasé en même temps que `height` : .eh-form
   select (règle de base ci-dessus) pose min-height:44px, et min-height
   l'emporte toujours sur height quand il est plus grand (résolu propriété
   par propriété, pas "la règle la plus spécifique gagne tout") — height
   seul n'a donc aucun effet visuel tant que min-height n'est pas réduit
   ici aussi. padding-top/bottom réduits pour que le texte tienne dans la
   hauteur ainsi libérée ; padding-left/right (dont l'espace du chevron)
   volontairement non touchés, hérités de .eh-form select. --- */

/* Pèlerins (apps.supervisor.views.PilgrimListView) */
.eh-form .eh-bulk-actions-pilgrims {
  flex-wrap: nowrap;
  overflow-x: auto;
}

.eh-form .eh-select-pilgrims {
  width: auto;
  min-width: 12rem;
  height: 32px;
  min-height: 32px;
  padding-top: 0.15rem;
  padding-bottom: 0.15rem;
  font-size: 0.8rem;
}

/* Jours de rendez-vous (apps.dashboard.views.AppointmentDayListView) */
.eh-form .eh-bulk-actions-appointment-days {
  flex-wrap: nowrap;
  overflow-x: auto;
}

.eh-form .eh-select-appointment-days {
  width: auto;
  min-width: 12rem;
  height: 32px;
  min-height: 32px;
  padding-top: 0.15rem;
  padding-bottom: 0.15rem;
  font-size: 0.8rem;
}

/* --- Fichier --- */

.eh-form input[type="file"] {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px dashed var(--eh-border-strong);
  border-radius: var(--eh-radius-sm);
  background: var(--eh-bg-soft);
  font-size: 0.88rem;
  color: var(--eh-text-muted);
}

.eh-form input[type="file"]::file-selector-button {
  margin-right: 0.75rem;
  padding: 0.5rem 0.9rem;
  border: 0;
  border-radius: var(--eh-radius-sm);
  background: var(--eh-green-700);
  color: var(--eh-white);
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background var(--eh-transition);
}

.eh-form input[type="file"]::file-selector-button:hover {
  background: var(--eh-green-900);
}

/* --- Cases à cocher & boutons radio --- */

.eh-form .eh-check,
.eh-form .eh-radio {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  font-weight: 500;
}

.eh-form input[type="checkbox"],
.eh-form input[type="radio"] {
  width: 18px;
  height: 18px;
  margin-top: 0.15rem;
  flex: none;
  accent-color: var(--eh-green-700);
}

.eh-form .eh-check-group,
.eh-form .eh-radio-group {
  display: flex;
  flex-direction: column;
/*gap: 0.55rem;*/
  padding: 0.15rem 0;
}

.eh-form .eh-radio-group.eh-inline {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 1.1rem;
}

.eh-form .eh-check-group.eh-inline {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
/*  gap: 0.4rem 1rem;*/
}

/* Colonnes de largeur égale calée sur le plus long libellé ("Mandingue")
   plutôt qu'étirées sur toute la largeur du champ — la case à cocher se
   place au-dessus de la langue via le label en colonne. */
.eh-form .eh-check-group.eh-inline > div {
  flex: 0 0 auto;
  min-width: 10ch;
  display: flex;
  justify-content: center;
}

.eh-form .eh-check-group.eh-inline label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  text-align: center;
  /* Contrairement au libellé du champ (.eh-form label, gras), le texte de
     chaque case à cocher (langue, pension...) reste en graisse normale —
     même poids que .eh-check/.eh-radio ci-dessus. */
  font-weight: 400;
}

/* --------------------------------------------------------------------------
   Champ conteneur, aide, erreurs
   -------------------------------------------------------------------------- */

.eh-field {
  display: flex;
  flex-direction: column;
}

/* Django rend le texte d'aide dans <span class="helptext"> ou <p class="helptext"> */
.eh-form .helptext,
.eh-form .eh-help-text {
  display: block;
  margin-top: 0.35rem;
  color: var(--eh-text-muted);
  font-size: 0.8rem;
}

/* Django rend les erreurs de champ dans <ul class="errorlist"> */
.eh-form .errorlist {
  margin: 0.4rem 0 0;
  padding: 0;
  list-style: none;
  color: var(--eh-danger);
  font-size: 0.82rem;
  font-weight: 600;
}

.eh-form .errorlist li {
  display: flex;
  align-items: flex-start;
  gap: 0.35rem;
}

.eh-form .errorlist li::before {
  content: "!";
  display: grid;
  place-items: center;
  flex: none;
  width: 16px;
  height: 16px;
  margin-top: 0.05rem;
  border-radius: 50%;
  background: var(--eh-danger);
  color: var(--eh-white);
  font-size: 0.68rem;
}

/* Erreurs non liées à un champ précis (form.non_field_errors) */
.eh-form .eh-non-field-errors {
  margin: 0;
  padding: 0.85rem 1rem;
  background: var(--eh-danger-bg);
  border: 1px solid var(--eh-danger-border);
  border-radius: var(--eh-radius);
  color: var(--eh-danger);
}

.eh-form .eh-non-field-errors .errorlist {
  color: inherit;
}

/* État d'erreur sur un champ : ajouter la classe "eh-field-error" au conteneur
   .eh-field, et/ou "is-invalid" à l'input, depuis le template si
   field.errors est non vide. */
.eh-field.eh-field-error label {
  color: var(--eh-danger);
}

.eh-form input.is-invalid,
.eh-form select.is-invalid,
.eh-form textarea.is-invalid,
.eh-field.eh-field-error input,
.eh-field.eh-field-error select,
.eh-field.eh-field-error textarea {
  border-color: var(--eh-danger);
  background: var(--eh-danger-bg);
}

.eh-form input.is-invalid:focus,
.eh-field.eh-field-error input:focus {
  box-shadow: 0 0 0 3px rgba(163, 54, 43, 0.2);
}

/* État valide (facultatif, ex : validation asynchrone) */
.eh-form input.is-valid,
.eh-field.eh-field-valid input {
  border-color: var(--eh-success);
}

/* --------------------------------------------------------------------------
   Fieldsets
   -------------------------------------------------------------------------- */

.eh-form fieldset {
  margin: 0;
  padding: var(--eh-space-5);
  border: 1px solid var(--eh-border);
  border-radius: var(--eh-radius);
  background: var(--eh-white);
}

.eh-form legend {
  padding: 0 0.5rem;
  margin-left: -0.5rem;
  color: var(--eh-green-900);
  font-weight: 700;
  font-size: 1rem;
}

.eh-form fieldset + fieldset {
  margin-top: 0;
}

.eh-form fieldset p.helptext:first-child {
  margin-top: -0.4rem;
}

/* --------------------------------------------------------------------------
   Photo d'identité (inline façon Django Admin) — portrait 96x128
   -------------------------------------------------------------------------- */

.eh-photo-inline {
  display: flex;
  align-items: flex-start;
  gap: var(--eh-space-4);
}

.eh-photo-frame {
  width: 96px;
  height: 128px;
  flex: none;
  border: 1px solid var(--eh-border);
  border-radius: var(--eh-radius-sm);
  background: var(--eh-bg-soft);
  overflow: hidden;
}

/* Aperçu instantané (voir pilgrim_photos.js) : un fichier vient d'être
   choisi mais pas encore enregistré — mise en valeur dorée le temps de
   confirmer, cohérente avec le reste de l'app (onglet actif, accordéon
   ouvert...). */
.eh-photo-inline.is-pending-upload .eh-photo-frame {
  border-color: var(--eh-gold);
  box-shadow: 0 0 0 2px rgba(185, 148, 76, 0.25);
}

.eh-photo-selected-hint {
  color: var(--eh-gold-700);
  font-size: 0.78rem;
  font-weight: 600;
}

.eh-photo-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.eh-photo-inline-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.4rem;
}

.eh-photo-list {
  display: flex;
  flex-direction: column;
  gap: var(--eh-space-4);
}

.eh-photo-list .eh-photo-inline + .eh-photo-inline {
  padding-top: var(--eh-space-4);
  border-top: 1px solid var(--eh-border);
}

.eh-photo-inline:has(.eh-photo-delete-wrap :checked) {
  opacity: 0.45;
}

/* --- Actions (télécharger / modifier / supprimer / ajouter) : de simples
   liens, pas des boutons pleins --- */

.eh-photo-link {
  display: inline-flex;
  align-items: center;
  border: 0;
  background: none;
  padding: 0;
  color: var(--eh-green-700);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.eh-photo-link:hover {
  text-decoration: underline;
}

.eh-photo-link-danger {
  color: var(--eh-danger);
}

.eh-photo-delete-wrap:has(:checked) + .eh-photo-link {
  text-decoration: underline;
  font-weight: 700;
}

.eh-photo-add-row {
  align-items: stretch;
  padding-top: var(--eh-space-4);
  margin-top: var(--eh-space-4);
  border-top: 1px solid var(--eh-border);
}

/* Documents Nusuk : le cadre suit la largeur de l'aperçu (photo 96, passeport
   Nusuk 92, scan d'une page de passeport 186), toujours 128 de haut. */
.eh-photo-frame-92 { width: 92px; }
.eh-photo-frame-186 { width: 186px; }

.eh-photo-frame-92 img,
.eh-photo-frame-186 img,
.eh-photo-frame-pdf img {
  object-fit: contain;
}

/* MRZ : les 88 caractères doivent s'aligner comme sur le document. */
.eh-form input[type="text"].eh-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  letter-spacing: 0;
}

.eh-photo-frame-spacer {
  visibility: hidden;
}

.eh-photo-inline-actions-end {
  justify-content: flex-end;
}

/* --------------------------------------------------------------------------
   Formulaires en colonnes / longs formulaires
   -------------------------------------------------------------------------- */

.eh-form-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--eh-space-4);
}

.eh-form-row-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.eh-form-row-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.eh-form-section-title {
  margin: 0 0 0.2rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--eh-border);
  color: var(--eh-green-900);
  font-size: 1.05rem;
  font-weight: 700;
}

.eh-form-section-hint {
  margin: -0.6rem 0 0;
  color: var(--eh-text-muted);
  font-size: 0.85rem;
}

/* Barre d'actions, utile pour les longs formulaires (sticky en bas) */
.eh-form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.6rem;
  padding-top: var(--eh-space-4);
  border-top: 1px solid var(--eh-border);
}

/* Boutons alignés à gauche (ex. « Enregistrer le versement » + « Fermer »,
   templates/finances/pilgrim.html). */
.eh-form-actions.eh-form-actions-start {
  justify-content: flex-start;
}

.eh-form-actions.eh-sticky {
  justify-content: flex-start;
  position: sticky;
  bottom: 0;
  z-index: 5;
  margin: 0 calc(-1 * var(--eh-space-5));
  padding: var(--eh-space-4) var(--eh-space-5);
  background: rgba(255, 253, 247, 0.94);
  backdrop-filter: blur(10px);
}

.eh-form-actions .eh-btn-danger {
  margin-left: auto;
}

/* --------------------------------------------------------------------------
   Notes d'intégration Django Admin
   -------------------------------------------------------------------------- */

/*
  Ce fichier n'inclut volontairement AUCUN sélecteur global (input, select,
  form...) et n'est jamais chargé par Django Admin : impossible de casser
  ses gabarits. Pour teinter légèrement l'admin (facultatif), voir
  static/css/admin-extra.css et son inclusion via `class Media` dans un
  ModelAdmin — ce fichier additif ne modifie ni la structure ni les scripts
  de l'admin.
*/
