/* ============================================================================
 * kdCommun/css/forms.css
 * Design system partagé pour les éléments de formulaire kdFast.
 *
 * Pensé pour être utilisé conjointement avec modals.css : les classes de type
 * (.kdModalDanger / Primary / Success / Info / Warning) exposent les variables
 * --kd-accent / --kd-accent-strong / --kd-accent-bg / --kd-accent-shadow qui
 * sont consommées ici (focus inputs, gradients des boutons primary, etc.).
 *
 * Utilisable aussi en dehors d'une modale : un parent qui définit
 * --kd-accent suffit. Sinon, fallback violet par défaut.
 *
 * Usage minimal :
 *   <div class="kdFieldsRow row2">
 *     <div class="kdField">
 *       <label><i class="fa-solid fa-hashtag"></i> Numéro <span class="kdReq">*</span></label>
 *       <input type="text" name="num" required>
 *     </div>
 *     <div class="kdField">
 *       <label><i class="fa-regular fa-calendar"></i> Date</label>
 *       <input type="date" name="date">
 *     </div>
 *   </div>
 *
 * Boutons :
 *   <button class="kdBtn kdBtnSecondary">Annuler</button>
 *   <button class="kdBtn kdBtnPrimary">Valider</button>     (reprend l'accent du parent)
 *   <button class="kdBtn kdBtnDanger">Supprimer</button>    (rouge explicite)
 * ============================================================================ */

/* Fallbacks si pas dans un .kdModal* qui définit l'accent */
:root {
    --kd-accent: #8b5cf6;
    --kd-accent-strong: #7c3aed;
    --kd-accent-bg: rgba(139, 92, 246, 0.18);
    --kd-accent-shadow: rgba(139, 92, 246, 0.35);
}

/* === Champ unitaire (label + input) === */
.kdField {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
}
.kdField label {
    font-size: 11.5px;
    font-weight: 600;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.kdField label i {
    color: var(--kd-accent);
    font-size: 12px;
}

/* Astérisque "obligatoire" */
.kdReq {
    color: #dc2626;
    font-weight: 700;
}

/* === Inputs / select / textarea === */
.kdField input[type="text"],
.kdField input[type="number"],
.kdField input[type="email"],
.kdField input[type="tel"],
.kdField input[type="password"],
.kdField input[type="date"],
.kdField input[type="time"],
.kdField input[type="datetime-local"],
.kdField input[type="search"],
.kdField input[type="url"],
.kdField select,
.kdField textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid #e3e8ef;
    border-radius: 9px;
    background: #fff;
    color: #0f172a;
    font-size: 13.5px;
    font-family: inherit;
    outline: none;
    transition: all 0.15s ease;
    box-sizing: border-box;
}
.kdField textarea {
    min-height: 80px;
    resize: vertical;
    line-height: 1.5;
}

/* Champ texte = police mono (cohérent avec le projet : doc, codes, refs) */
.kdField input[type="text"] {
    font-family: 'SF Mono', 'Roboto Mono', monospace;
    letter-spacing: 0.3px;
}

/* Select natif → chevron SVG custom */
.kdField select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 34px;
}

/* États */
.kdField input:focus,
.kdField select:focus,
.kdField textarea:focus {
    border-color: var(--kd-accent);
    box-shadow: 0 0 0 3px var(--kd-accent-bg);
}
.kdField input:disabled,
.kdField select:disabled,
.kdField textarea:disabled {
    background: #f1f5f9;
    color: #94a3b8;
    cursor: not-allowed;
}
.kdField input.error,
.kdField select.error,
.kdField textarea.error {
    border-color: #dc2626;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12);
}

/* === Suffixe d'unité (kg, €, %, etc.) === */
.kdInputSuffix { position: relative; }
.kdInputSuffix input { padding-right: 50px !important; }
.kdInputUnit {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 13px;
    font-weight: 600;
    color: #94a3b8;
    pointer-events: none;
}

/* === Grille de champs === */
.kdFieldsRow {
    display: grid;
    gap: 14px;
    margin-bottom: 14px;
    grid-template-columns: 1fr;
}
.kdFieldsRow.row2 { grid-template-columns: 1fr 1fr; }
.kdFieldsRow.row3 { grid-template-columns: 1fr 1fr 1fr; }
.kdFieldsRow.row4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

@media (max-width: 900px) {
    .kdFieldsRow.row4 { grid-template-columns: 1fr 1fr; }
    .kdFieldsRow.row3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 680px) {
    .kdFieldsRow.row2,
    .kdFieldsRow.row3,
    .kdFieldsRow.row4 { grid-template-columns: 1fr; }
}

/* === Boutons === */
.kdBtn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 10px 20px;
    border-radius: 9px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    border: none;
    font-family: inherit;
    line-height: 1.2;
    white-space: nowrap;
}
.kdBtn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

/* Secondaire — gris neutre */
.kdBtnSecondary {
    background: #f1f5f9;
    color: #334155;
    border: 1px solid #cbd5e1;
}
.kdBtnSecondary:hover:not(:disabled) { background: #e2e8f0; }

/* Primary — reprend l'accent du parent (.kdModal* ou :root) */
.kdBtnPrimary {
    background: linear-gradient(135deg, var(--kd-accent-strong), var(--kd-accent));
    color: #fff;
    box-shadow: 0 4px 12px var(--kd-accent-shadow);
}
.kdBtnPrimary:hover:not(:disabled) {
    filter: brightness(0.95);
    box-shadow: 0 6px 16px var(--kd-accent-shadow);
    transform: translateY(-1px);
}

/* Variantes explicites (utile hors modale ou pour forcer une couleur) */
.kdBtnDanger {
    background: linear-gradient(135deg, #b91c1c, #dc2626);
    color: #fff;
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.35);
}
.kdBtnDanger:hover:not(:disabled) {
    background: linear-gradient(135deg, #991b1b, #b91c1c);
    box-shadow: 0 6px 16px rgba(220, 38, 38, 0.45);
    transform: translateY(-1px);
}

.kdBtnSuccess {
    background: linear-gradient(135deg, #059669, #10b981);
    color: #fff;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.35);
}
.kdBtnSuccess:hover:not(:disabled) {
    background: linear-gradient(135deg, #047857, #059669);
    box-shadow: 0 6px 16px rgba(16, 185, 129, 0.45);
    transform: translateY(-1px);
}

.kdBtnInfo {
    background: linear-gradient(135deg, #1d4ed8, #3b82f6);
    color: #fff;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.35);
}
.kdBtnInfo:hover:not(:disabled) {
    background: linear-gradient(135deg, #1e40af, #1d4ed8);
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.45);
    transform: translateY(-1px);
}

.kdBtnWarning {
    background: linear-gradient(135deg, #c2410c, #ea580c);
    color: #fff;
    box-shadow: 0 4px 12px rgba(234, 88, 12, 0.35);
}
.kdBtnWarning:hover:not(:disabled) {
    background: linear-gradient(135deg, #9a3412, #c2410c);
    box-shadow: 0 6px 16px rgba(234, 88, 12, 0.45);
    transform: translateY(-1px);
}

/* Bouton "fantôme" — uniquement bordure + accent */
.kdBtnGhost {
    background: transparent;
    color: var(--kd-accent);
    border: 1.5px solid var(--kd-accent);
}
.kdBtnGhost:hover:not(:disabled) {
    background: var(--kd-accent-bg);
}

/* Tailles */
.kdBtnSm { padding: 7px 14px; font-size: 12.5px; }
.kdBtnLg { padding: 13px 26px; font-size: 14.5px; }

/* === Cartes radio sélectionnables (style "tuile") ===
 * Usage :
 *   <label class="kdRadioCard selected">
 *     <input type="radio" name="grp" value="X" checked>
 *     <div class="kdRadioCardIcon iconBlue"><i class="fa-..."></i></div>
 *     <div class="kdRadioCardName">Titre</div>
 *     <div class="kdRadioCardSub">Description courte</div>
 *     <i class="kdRadioCardCheck fa-solid fa-check"></i>
 *   </label>
 */
.kdRadioCard {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 14px 10px 12px;
    background: #fff;
    border: 2px solid #e3e8ef;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.18s ease;
    min-height: 96px;
}
.kdRadioCard:hover {
    border-color: color-mix(in srgb, var(--kd-accent) 60%, white);
    background: color-mix(in srgb, var(--kd-accent) 6%, white);
    transform: translateY(-1px);
}
.kdRadioCard input[type="radio"] { display: none; }
.kdRadioCard.selected {
    border-color: var(--kd-accent);
    background: color-mix(in srgb, var(--kd-accent) 8%, white);
    box-shadow: 0 4px 12px var(--kd-accent-bg);
}

.kdRadioCardIcon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    margin-bottom: 2px;
}
/* Variantes de couleur pour l'icône de la carte (indépendantes de l'accent) */
.kdRadioCardIcon.iconBlue   { background: #dbeafe; color: #1e40af; }
.kdRadioCardIcon.iconGreen  { background: #dcfce7; color: #166534; }
.kdRadioCardIcon.iconOrange { background: #fed7aa; color: #9a3412; }
.kdRadioCardIcon.iconRed    { background: #fee2e2; color: #991b1b; }
.kdRadioCardIcon.iconViolet { background: #ede9fe; color: #6d28d9; }
.kdRadioCardIcon.iconGray   { background: #f1f5f9; color: #475569; }

.kdRadioCardName {
    font-size: 14px;
    font-weight: 700;
    color: #0f172a;
    letter-spacing: 0.2px;
    text-align: center;
}
.kdRadioCardSub {
    font-size: 11px;
    color: #64748b;
    font-weight: 400;
    text-align: center;
}
.kdRadioCardCheck {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--kd-accent);
    color: #fff;
    font-size: 9px;
    display: none;
    align-items: center;
    justify-content: center;
}
.kdRadioCard.selected .kdRadioCardCheck { display: inline-flex; }
