/*
 * Rôle    : Styles globaux des formulaires Django (inputs, labels, errors, fieldsets).
 * Scope   : Toutes les pages avec un formulaire — chargé globalement via main/templates/main/bases/base.html
 *           et explicitement dans plusieurs templates admin (contact_management, blog, user_guide).
 * Charge  : main/templates/main/bases/base.html:140
 *           contact_management/templates/contact_management/admin/change_contact_infos.html:7
 *           contact_management/templates/contact_management/admin/change_user_names_form.html:7
 *           contact_management/templates/contact_management/admin/change_user_email_form.html:7
 *           user_guide/templates/user_guide/admin/article_form.html:8
 *           blog/templates/blog/admin/category_form.html:7
 *           blog/templates/blog/admin/post_form.html:11
 * Dépend  : Tailwind (utilisé en parallèle dans les templates) / palette custom primary-green-{200,300}
 *           Convention Django : balises <form>, <p>, <label>, <ul.errorlist> et id auto `#id_<field>`.
 */

/* === Layout général du <form> === */
/* Empile les champs verticalement avec un gap régulier — repose sur le rendu Django par défaut
   où chaque champ est wrappé dans un <p>. */
form {
    display: flex;
    flex-direction: column;
    gap: 1rem;

}

/* Wrapper Django : chaque <p> contient label + input + help_text — colonne serrée. */
form p {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

/* === Labels === */
form label {
    font-size: 0.9rem;
    font-weight: 500;
}

/* === Inputs === */
/* Classe à appliquer manuellement sur les widgets (via attrs={'class': 'form-field'} côté form Python).
   !important : nécessaire pour surcharger Tailwind (preflight + classes utilitaires concurrentes). */
.form-field {
    width: 100%!important;
    padding: .75rem 1rem!important;
    border-radius: 6px!important;
    border: 1.5px solid #2a4134e1!important; /* primary-green-200 */
    transition: border-color 0.2s ease-in-out!important;
}

/* Focus state — anneau vert (primary-green-300) avec halo léger. */
.form-field:focus {
    outline: none!important;
    border-color: #7fffb7!important; /* primary-green-300 */
    box-shadow: 0 0 0 3px rgba(127, 255, 183, 0.1)!important; /* primary-green-300 avec transparence */
}

/* === Errors / States === */
/* État erreur : à appliquer en plus de .form-field (ex. via JS de validation client). */
.form-field.error {
    border-color: #ef4444!important; /* rouge */
}

/* État succès : à appliquer en plus de .form-field après validation. */
.form-field.success {
    border-color: #10b981!important; /* vert */
}

/* Checkbox carrée — override de la largeur 100% héritée de .form-field. */
.form-field.form-checkbox {
    width: 28px!important;
    height:28px!important;
    padding: 0!important;
}

/* === Champ fichier === */
/* Style du <input type="file"> natif — pas de !important ici, sélecteur déjà spécifique. */
form input[type="file"] {
    width: 100%;
    padding: .75rem 1rem;
    border-radius: 6px;
    border: 1px solid #b2ffd3;
    background-color: white;
    cursor: pointer;
    transition: border-color 0.2s ease-in-out;
}

form input[type="file"]:hover {
    border-color: #7fffb7;
}

form input[type="file"]:focus {
    outline: none;
    border-color: #7fffb7;
    box-shadow: 0 0 0 3px rgba(127, 255, 183, 0.1);
}

/* Hack : masque l'input file natif quand un bouton custom (label.custom-file-upload) le déclenche
   via `for="file-upload-button"`. Permet d'avoir un trigger stylé sans toucher au widget natif. */
form #file-upload-button {
    display: none!important;
}

/* Bouton de remplacement (label cliquable) pour l'input file caché ci-dessus. */
form .custom-file-upload {
    display: inline-block;
    padding: .75rem 1.5rem;
    cursor: pointer;
    background-color: #7fffb7;
    color: white;
    border-radius: 6px;
    border: none;
    transition: all 0.2s ease-in-out;
    font-weight: 500;
    text-align: center;
    box-shadow: 0 2px 4px rgba(127, 255, 183, 0.2);
}

form .custom-file-upload:hover {
    background-color: #33f589;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(127, 255, 183, 0.3);
}

/* === Errors (Django form validation) === */
/* Style du <ul class="errorlist"> rendu automatiquement par Django pour `form.errors` /
   `field.errors`. Texte centré, fond rouge translucide. */
form ul.errorlist {
    list-style: none;
    padding: 0;
    margin: 0;
    color: #b82c2c; /* rouge */

    background-color: #ca141442;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 500;
    text-align: center;
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
    margin-left: 0.5rem;
}


/* === Checkboxes multiples (#id_categories) === */
/* Cible spécifiquement le champ Django `categories` rendu en CheckboxSelectMultiple.
   Transforme la <ul> native en grille de cartes cliquables avec checkboxes natives masquées.
   La classe `.selected` sur le <label> est ajoutée par JS (cf. templates qui utilisent ce champ)
   pour afficher l'icône ✓ via le pseudo-element `::after`. */

/* Grille responsive — auto-fit pour s'adapter au nombre de catégories. */
#id_categories {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.5rem;
    margin-top: 0.5rem;
    width: 100%;
    max-width: 100%;
    height: fit-content;

    /* Reset : annule l'éventuel style hérité de `.form-field` si la classe est appliquée
       au conteneur — on veut une grille nue, pas une carte bordée. */
    background: none!important;
    border: none !important;
    padding: 0 !important;
    box-shadow: none !important;
}

/* Wrapper Django de chaque <input> + <label> — `position: relative` pour ancrer le ::after. */
#id_categories > div {
    position: relative;
}

/* Carte cliquable (le <label> couvre toute la zone, l'input natif est masqué dessous). */
#id_categories label {
    display: block;
    padding: 0.75rem 1rem;
    border: 1px solid #b2ffd3; /* primary-green-200 */
    border-radius: 6px;
    background-color: white;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    font-weight: 500;
    font-size: 0.9rem;
    text-align: center;
    position: relative;
    width: 100%;
    box-sizing: border-box;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Hover : élévation visuelle sans changer l'état logique. */
#id_categories label:hover {
    border-color: #7fffb7; /* primary-green-300 */
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(127, 255, 183, 0.15);
}

/* Hack : on masque la checkbox native (sans `display: none` pour préserver l'accessibilité
   et la soumission du form) — le label sert de zone cliquable. */
#id_categories input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

/* Icône ✓ injectée en haut-à-droite de chaque carte, invisible par défaut. */
#id_categories label::after {
    content: '✓';
    position: absolute;
    top: 0.5rem;
    right: 0.75rem;
    font-size: 14px;
    font-weight: bold;
    color: white;
    opacity: 0;
    transform: scale(0);
    transition: all 0.2s ease-in-out;
}

/* Affiche le ✓ — la classe `.selected` est togglée en JS sur change/click de la checkbox.
   Note : pas de fallback CSS-only via `:has()` ou `+` ici, donc le JS est requis pour
   refléter l'état coché. */
#id_categories label.selected::after {
    opacity: 1;
    transform: scale(1);
}



