/* 
 * Styles pour les composants checkbox et radio
 * SNCF Design System
 */

/* Styles communs pour les cases à cocher et boutons radio */
.form-field-input {
  margin-bottom: O;
  position: relative;
}

.form-field-input.field-type-checkbox,
.form-field-input.field-type-radio {
  margin-top: 0.5rem;
}

/* Styles spécifiques pour les checkbox */
.custom-checkbox {
  position: relative;
  display: flex;
  align-items: flex-start;
  cursor: pointer;
  padding: 0;
}

.custom-checkbox input[type='checkbox'] {
  position: absolute;
  opacity: 0;
  cursor: pointer;
  /* 1px clippé : le navigateur peut donner le focus (height:0/width:0 bloque le focus clavier) */
  width: 1px;
  height: 1px;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
  /* Aligné sur le pseudo-élément label:before pour que le clic soit capturé */
  left: 0;
  top: 3px;
}

.custom-checkbox label {
  position: relative;
  padding-left: 24px;
  cursor: pointer;
  font-family: var(--wp--preset--font-family--avenir-roman, "Avenir Roman", sans-serif);
  font-size: 1rem;
  line-height: 1.4;
  margin: 0;
  display: inline-block;
  color: var(--wp--custom--semantic--color--text--primary, #121212);
  font-weight: normal;
  user-select: none;
}

.custom-checkbox label:before {
  content: '';
  position: absolute;
  left: 0;
  top: 3px;
  width: var(--wp--custom--component--checkbox--width, 16px);
  height: var(--wp--custom--component--checkbox--height, 16px);
  border: var(--wp--custom--semantic--border--width--default, 1px) solid var(--wp--custom--semantic--color--border--control--indicator--default, #747678);
  background-color: var(--wp--custom--semantic--color--background--surface--body, #ffffff);
  border-radius: 3px;
  transition: all 0.2s ease;
}

.custom-checkbox label:after {
  content: '';
  position: absolute;
  left: 5px;
  top: 5px;
  width: 6px;
  height: 10px;
  border: solid var(--wp--custom--semantic--color--foreground--control--indicator--selected, #ffffff);
  border-width: 0 var(--wp--custom--semantic--border--width--large, 2px) var(--wp--custom--semantic--border--width--large, 2px) 0;
  transform: rotate(45deg) scale(0);
  opacity: 0;
  transition: all 0.1s ease;
}

.custom-checkbox input[type='checkbox']:checked + label:before {
  background-color: var(--wp--custom--semantic--color--background--control--indicator--selected, #6558b1);
  border-color: var(--wp--custom--semantic--color--border--control--indicator--selected, #6558b1);
}

.custom-checkbox input[type='checkbox']:checked + label:after {
  opacity: 1;
}

.custom-checkbox input[type='checkbox']:focus + label:before {
  padding: 5px;
  border: solid var(--wp--custom--semantic--border--width--large, 2px) var(--wp--custom--semantic--color--border--focus--alt--on-primary, #6558b1);
}

.custom-checkbox input[type='checkbox']:disabled + label {
  color: var(--wp--custom--semantic--color--text--disabled, #b9b9b9);
  cursor: not-allowed;
}

.custom-checkbox input[type='checkbox']:disabled + label:before {
  border-color: var(--wp--custom--semantic--color--border--control--indicator--disabled, #d7d7d7);
  background-color: var(--wp--custom--semantic--color--background--control--indicator--disabled, #d7d7d7);
}

.custom-checkbox.checked label:before {
  background-color: var(--wp--custom--semantic--color--background--control--indicator--selected, #6558b1);
  border-color: var(--wp--custom--semantic--color--border--control--indicator--selected, #6558b1);
}

.custom-checkbox.checked label:after {
  opacity: 1;
  transform: rotate(45deg) scale(1);
}

/* Styles pour l'état d'erreur des checkbox */
.custom-checkbox input[type='checkbox'].invalid + label:before {
  border-color: var(--wp--custom--semantic--color--border--critical, #c80e0e);
}

.checkbox-group-preview-wrapper {
  display: flex;
  flex-direction: column;
  gap: var(--wp--custom--semantic--spacing--base, 8px);
  margin: 0;
  padding: 0;
}

.checkbox-group-preview-wrapper .form-field-input.field-type-checkbox {
  margin: 0;
  padding: 0;
}

.form-field-input [role='alert'],
.checkbox-group-preview-wrapper + [role='alert'] {
  display: block;
  margin-top: 0;
  min-height: 0;
}

.form-field-input [role='alert'] .show-error,
.checkbox-group-preview-wrapper + [role='alert'] .show-error,
.show-error {
  color: var(--wp--custom--semantic--color--text--critical, #c80e0e);
  font-family: var(--wp--preset--font-family--avenir-roman, "Avenir Roman", sans-serif);
  font-size: 0.875rem;
  margin: 0;
  display: flex;
}

.form-field-input [role='alert'] .show-error::before,
.checkbox-group-preview-wrapper + [role='alert'] .show-error::before,
.show-error::before {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 6px;
  mask: url('../../../assets/icons/Vector.svg') no-repeat center;
  background-color: var(--wp--custom--semantic--color--text--critical, #c80e0e);
}

.form-field-input.has-error .custom-checkbox label:before,
.form-field-input.has-error .custom-radio label:before {
  border-color: var(--wp--custom--semantic--color--border--critical, #c80e0e);
}

/* Styles spécifiques pour les boutons radio */
.radio-group-container {
  margin-bottom: 1.5rem;
}

.radio-group-label {
  display: block;
  margin-bottom: 0.5rem;
  font-family: var(--wp--preset--font-family--avenir-roman, "Avenir Roman", sans-serif);
  font-weight: 500;
  color: var(--wp--custom--semantic--color--text--primary, #121212);
}

.radio-options {
  display: flex;
  flex-direction: column;
}

.radio-options-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.radio-option {
  position: relative;
  margin-bottom: 0.5rem;
}

.custom-radio {
  position: relative;
  display: flex;
  align-items: flex-start;
  cursor: pointer;
}

.custom-radio input[type='radio'] {
  position: absolute;
  opacity: 0;
  cursor: pointer;
  /* 1px clippé : le navigateur peut donner le focus (height:0/width:0 bloque le focus clavier) */
  width: 1px;
  height: 1px;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
  /* Aligné sur le pseudo-élément label:before pour que le clic soit capturé */
  left: 0;
  top: 3px;
}

.custom-radio label {
  position: relative;
  padding-left: 24px;
  cursor: pointer;
  font-family: var(--wp--preset--font-family--avenir-roman, "Avenir Roman", sans-serif);
  font-size: 1rem;
  line-height: 1.4;
  margin: 0;
  display: inline-block;
  color: var(--wp--custom--semantic--color--text--primary, #121212);
  font-weight: normal;
  user-select: none;
}

.custom-radio label:before {
  content: '';
  position: absolute;
  left: 0;
  top: 3px;
  width: var(--wp--custom--component--radio--width, 16px);
  height: var(--wp--custom--component--radio--height, 16px);
  border: var(--wp--custom--semantic--border--width--large, 2px) solid var(--wp--custom--semantic--color--border--control--indicator--default, #747678);
  background-color: var(--wp--custom--semantic--color--background--surface--body, #ffffff);
  border-radius: 50%;
  transition: all 0.2s ease;
}

.custom-radio label:after {
  content: '';
  position: absolute;
  left: 4px;
  top: 7px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  border: 4px solid var(--wp--custom--semantic--color--background--control--indicator--selected, #6558b1);
  transform: scale(0);
  opacity: 0;
  transition: all 0.1s ease;
}

.custom-radio input[type='radio']:checked + label:before {
  background-color: var(--wp--custom--semantic--color--background--surface--body, #ffffff);
  border-color: var(--wp--custom--semantic--color--border--control--indicator--selected, #6558b1);
}

.custom-radio input[type='radio']:checked + label:after {
  opacity: 1;
  transform: scale(1);
}

.custom-radio input[type='radio']:focus + label:before {
  border: var(--wp--custom--semantic--border--width--large, 2px) solid var(--wp--custom--semantic--color--border--focus--alt--on-primary, #6558b1);
}

.custom-radio input[type='radio']:disabled + label {
  color: var(--wp--custom--semantic--color--text--disabled, #b9b9b9);
  cursor: not-allowed;
}

.custom-radio input[type='radio']:disabled + label:before {
  border-color: var(--wp--custom--semantic--color--border--control--indicator--disabled, #d7d7d7);
  background-color: var(--wp--custom--semantic--color--background--control--indicator--default, #f4f5f6);
}

.custom-radio.checked label:before {
  background-color: var(--wp--custom--semantic--color--border--critical, #c80e0e);
  border-color: var(--wp--custom--semantic--color--border--critical, #c80e0e);
}

.custom-radio.checked label:after {
  opacity: 1;
  transform: scale(1);
}

/* Styles pour l'état d'erreur des radio */
.custom-radio input[type='radio'].invalid + label:before {
  border-color: var(--wp--custom--semantic--color--border--critical, #c80e0e);
}

/* Styles pour l'état focus (souris + clavier) */
.custom-checkbox.focus label:before,
.custom-radio.focus label:before {
  border: solid var(--wp--custom--semantic--border--width--large, 2px) var(--wp--custom--semantic--color--border--focus--alt--on-primary, #6558b1);
  padding: 2px;
}

/* Navigation clavier uniquement (js-keyboard-nav géré via JS) */
.js-keyboard-nav .custom-checkbox.focus label,
.js-keyboard-nav .custom-radio.focus label {
  outline: 2px dashed var(--wp--custom--component--keyboard-line, #000000);
  outline-offset: 3px;
}
.js-keyboard-nav .custom-checkbox.focus label:before,
.js-keyboard-nav .custom-radio.focus label:before {
  border-color: var(--wp--custom--semantic--color--border--focus--base--on-primary);
}

/* Description pour chaque option (checkbox et radio) */
.option-description,
.field-description {
  margin-top: 0.25rem;
  font-family: var(--wp--preset--font-family--avenir-roman, "Avenir Roman", sans-serif);
  font-size: 0.875rem;
  color: var(--wp--custom--semantic--color--text--secondary, #4d4f53);
  padding-left: 30px;
}

/* Styles pour le fieldset */
fieldset {
  border: none;
  padding: 0;
  margin: 0 0 1.5rem 0;
}

fieldset legend {
  font-family: var(--wp--preset--font-family--avenir-roman, "Avenir Roman", sans-serif);
  font-weight: 500;
  margin-bottom: 0.5rem;
  padding: 0;
  color: var(--wp--custom--semantic--color--text--primary, #121212);
}

/* Indicateur de champ requis */
.required {
  color: var(--wp--custom--semantic--color--text--critical, #c80e0e);
  margin-left: 3px;
}

/* Styles responsives */
@media (max-width: 768px) {
  .radio-options-inline {
    flex-direction: column;
  }
}
