/**
 * FORMULAIRES MODERNES - CSS complet
 * Compatible avec le système de formulaires existant
 * Cohérent avec les refontes précédentes
 */

/**************************************** VARIABLES ***************************/

:root {
  /* Couleurs formulaires */
  --md-form-bg: #ffffff;
  --md-form-border: #d0d0d0;
  --md-form-border-focus: #2196f3;
  --md-form-text: #333333;
  --md-form-placeholder: #999999;
  --md-form-error: #f44336;
  --md-form-success: #4caf50;
  --md-form-disabled: #e0e0e0;

  /* Tailles */
  --md-form-input-height: 44px;
  --md-form-input-padding: 12px 16px;
  --md-form-spacing: 1.5rem;
  --md-form-border-radius: 6px;
}

/**************************************** MODAL HEADER ***************************/

.md-modal-header {
  background: linear-gradient(135deg, var(--md-primary-color-lighter) 0%, var(--md-primary-color-darker) 100%);
  color: white;
  padding: var(--md-spacing-lg);
  margin: calc(var(--md-spacing-lg) * -1) calc(var(--md-spacing-lg) * -1) var(--md-spacing-lg);
  border-radius: var(--md-border-radius) var(--md-border-radius) 0 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.md-modal-header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--md-spacing-md);
}

.md-modal-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
  color: white;
}

.md-modal-close {
  all: unset;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  cursor: pointer;
  transition: all var(--md-transition-speed);
}

.md-modal-close:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.1);
}

.md-modal-close:active {
  transform: scale(0.95);
}

.md-modal-close svg {
  color: white;
}

/**************************************** FORM SECTIONS (ACCORDÉONS) ***************************/

.md-form-section {
  margin-bottom: var(--md-spacing-md);
  border: 1px solid var(--md-form-border);
  border-radius: var(--md-form-border-radius);
  background: white;
  overflow: hidden;
  transition: all var(--md-transition-speed);
}

.md-form-section:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.md-section-header {
  all: unset;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: var(--md-spacing-md);
  background: linear-gradient(135deg, #f5f5f5 0%, #e8e8e8 100%);
  border-bottom: 1px solid var(--md-form-border);
  cursor: pointer;
  transition: all var(--md-transition-speed);
}

.md-section-header:hover {
  background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
}

.md-section-active .md-section-header {
  background: var(--md-primary-color-lighter-extended);
  color:var(--md-primary-lighter-extended-text-color);
  border-bottom-color: var(--md-primary-color-darker);
}

.md-section-header-content {
  display: flex;
  align-items: center;
  gap: var(--md-spacing-xs);
  flex: 1;
  min-width: 0; /* Permet la troncature du titre si nécessaire */
}

.md-section-title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--md-form-text);
}

.md-section-chevron {
  flex-shrink: 0;
  transition: transform var(--md-transition-speed);
  color: var(--md-primary-color);
}

.md-section-active .md-section-chevron {
  transform: rotate(180deg);
}

.md-section-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s ease-out;
}

.md-section-active .md-section-content {
  max-height: 5000px; /* Grande valeur pour permettre le contenu long */
  transition: max-height 0.6s ease-in;
}

.md-section-fields {
  padding: var(--md-spacing-lg);
  display: flex;
  flex-direction: column;
  gap: var(--md-spacing-md);
}

/**************************************** FORM FIELDS - BASE ***************************/

.md-form-field {
  display: flex;
  flex-direction: column;
  gap: var(--md-spacing-xs);
}

.md-form-label-wrapper {
  display: flex;
  align-items: center;
  gap: var(--md-spacing-xs);
}

.md-form-label {
  font-weight: 500;
  color: var(--md-form-text);
  font-size: 0.9375rem;
  margin: 0;
}

.md-form-required {
  color: var(--md-form-error);
  font-weight: 600;
  margin-left: 2px;
}

.md-form-help-btn {
  all: unset;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--md-light-color);
  cursor: help;
  transition: all var(--md-transition-speed);
  flex-shrink: 0;
  box-sizing: border-box;
}

.md-form-help-btn:hover {
  background: var(--md-primary-color);
  color: white;
  transform: scale(1.1);
}

.md-form-help-btn svg {
  width: 14px;
  height: 14px;
}

/* Bouton d'aide dans le header de section */
.md-section-header .md-form-help-btn {
  background: rgba(255, 255, 255, 0.3);
}

.md-section-header:hover .md-form-help-btn {
  background: rgba(255, 255, 255, 0.5);
}

.md-section-active .md-section-header .md-form-help-btn {
  background: var(--md-primary-color-lighter);
  color: var(--md-primary-text-color);
}

.md-section-header .md-form-help-btn:hover {
  background: var(--md-primary-color) !important;
  color: white;
}

/**************************************** FORM SECTIONS (ACCORDÉONS) ***************************/

.md-form-input-wrapper {
  position: relative;
}

.md-form-input {
  width: 100%;
  height: var(--md-form-input-height);
  padding: var(--md-form-input-padding);
  border: 1px solid var(--md-form-border);
  border-radius: var(--md-form-border-radius);
  font-size: 1rem;
  color: var(--md-form-text);
  background: var(--md-form-bg);
  transition: all var(--md-transition-speed);
  font-family: inherit;
}

.md-form-input::placeholder {
  color: var(--md-form-placeholder);
}

.md-form-input:hover {
  border-color: var(--md-primary-color);
}

.md-form-input:focus {
  outline: none;
  border-color: var(--md-form-border-focus);
  box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

.md-form-input:disabled {
  background: var(--md-form-disabled);
  cursor: not-allowed;
  opacity: 0.6;
}

/* État d'erreur */
.md-form-input.error,
.md-form-input:invalid:not(:placeholder-shown) {
  border-color: var(--md-form-error);
}

.md-form-input.error:focus {
  box-shadow: 0 0 0 3px rgba(244, 67, 54, 0.1);
}

/**************************************** TEXTAREA ***************************/

.md-form-textarea-wrapper {
  position: relative;
}

.md-form-textarea {
  width: 100%;
  min-height: 120px;
  padding: var(--md-form-input-padding);
  border: 1px solid var(--md-form-border);
  border-radius: var(--md-form-border-radius);
  font-size: 1rem;
  color: var(--md-form-text);
  background: var(--md-form-bg);
  transition: all var(--md-transition-speed);
  font-family: inherit;
  resize: vertical;
}

.md-form-textarea::placeholder {
  color: var(--md-form-placeholder);
}

.md-form-textarea:hover {
  border-color: var(--md-primary-color);
}

.md-form-textarea:focus {
  outline: none;
  border-color: var(--md-form-border-focus);
  box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

/**************************************** SELECT ***************************/

.md-form-select-wrapper {
  position: relative;
}

.md-form-select {
  width: 100%;
  height: var(--md-form-input-height);
  padding: var(--md-form-input-padding);
  padding-right: 40px; /* Espace pour le chevron */
  border: 1px solid var(--md-form-border);
  border-radius: var(--md-form-border-radius);
  font-size: 1rem;
  color: var(--md-form-text);
  background: var(--md-form-bg);
  transition: all var(--md-transition-speed);
  font-family: inherit;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
}

.md-form-select:hover {
  border-color: var(--md-primary-color);
}

.md-form-select:focus {
  outline: none;
  border-color: var(--md-form-border-focus);
  box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

.md-select-chevron {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--md-primary-color);
  transition: transform var(--md-transition-speed);
}

.md-form-select:focus ~ .md-select-chevron {
  transform: translateY(-50%) rotate(180deg);
}

/**************************************** CHECKBOX ***************************/

.md-form-field-checkbox {
  flex-direction: row;
  align-items: flex-start;
}

.md-form-checkbox-wrapper {
  display: flex;
  align-items: center;
  gap: var(--md-spacing-xs);
}

.md-form-checkbox {
  position: absolute;
  opacity: 0;
  cursor: pointer;
  width: 0;
  height: 0;
}

.md-form-checkbox-label {
  display: flex;
  align-items: center;
  gap: var(--md-spacing-sm);
  cursor: pointer;
  user-select: none;
  font-weight: 400;
}

.md-checkbox-custom {
  position: relative;
  width: 20px;
  height: 20px;
  border: 2px solid var(--md-form-border);
  border-radius: 4px;
  background: white;
  transition: all var(--md-transition-speed);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.md-form-checkbox:hover ~ .md-form-checkbox-label .md-checkbox-custom {
  border-color: var(--md-primary-color);
}

.md-form-checkbox:checked ~ .md-form-checkbox-label .md-checkbox-custom {
  background: var(--md-primary-color);
  border-color: var(--md-primary-color);
}

.md-checkbox-icon {
  opacity: 0;
  transform: scale(0);
  transition: all 0.2s ease;
  stroke: white;
}

.md-form-checkbox:checked ~ .md-form-checkbox-label .md-checkbox-icon {
  opacity: 1;
  transform: scale(1);
}

.md-form-checkbox:focus ~ .md-form-checkbox-label .md-checkbox-custom {
  box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.2);
}

.md-checkbox-text {
  flex: 1;
}

.md-form-checkbox-description {
  margin-left: 28px;
  margin-top: var(--md-spacing-xs);
  font-size: 0.875rem;
  color: #666;
}

/**************************************** RADIO ***************************/

.md-form-radio-group {
  display: flex;
  flex-direction: column;
  gap: var(--md-spacing-sm);
}

.md-form-radio-item {
  display: flex;
  align-items: center;
}

.md-form-radio {
  position: absolute;
  opacity: 0;
  cursor: pointer;
  width: 0;
  height: 0;
}

.md-form-radio-label {
  display: flex;
  align-items: center;
  gap: var(--md-spacing-sm);
  cursor: pointer;
  user-select: none;
  font-weight: 400;
  padding: var(--md-spacing-xs);
  border-radius: var(--md-form-border-radius);
  transition: background var(--md-transition-speed);
}

.md-form-radio-label:hover {
  background: rgba(33, 150, 243, 0.05);
}

.md-radio-custom {
  position: relative;
  width: 20px;
  height: 20px;
  border: 2px solid var(--md-form-border);
  border-radius: 50%;
  background: white;
  transition: all var(--md-transition-speed);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.md-form-radio:hover ~ .md-form-radio-label .md-radio-custom {
  border-color: var(--md-primary-color);
}

.md-form-radio:checked ~ .md-form-radio-label .md-radio-custom {
  border-color: var(--md-primary-color);
}

.md-radio-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--md-primary-color);
  transform: scale(0);
  transition: transform 0.2s ease;
}

.md-form-radio:checked ~ .md-form-radio-label .md-radio-dot {
  transform: scale(1);
}

.md-form-radio:focus ~ .md-form-radio-label .md-radio-custom {
  box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.2);
}

/**************************************** FORM FOOTER ***************************/

.md-form-footer {
  margin-top: var(--md-spacing-lg);
  padding-top: var(--md-spacing-lg);
  border-top: 1px solid var(--md-light-color);
}

.md-form-messages {
  margin-bottom: var(--md-spacing-md);
}

.md-error-message {
  padding: var(--md-spacing-sm) var(--md-spacing-md);
  background: #ffebee;
  color: var(--md-form-error);
  border-left: 4px solid var(--md-form-error);
  border-radius: var(--md-form-border-radius);
  font-size: 0.875rem;
  display: none; /* Caché par défaut, affiché via JS */
}

.md-error-message:not(:empty) {
  display: block;
}

.md-form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--md-spacing-sm);
}

/**************************************** RESPONSIVE ***************************/

@media (max-width: 768px) {
  .md-modal-title {
    font-size: 1.25rem;
  }

  .md-section-title {
    font-size: 1rem;
  }

  .md-section-fields {
    padding: var(--md-spacing-md);
  }

  .md-form-input,
  .md-form-select,
  .md-form-textarea {
    font-size: 16px; /* Empêche le zoom sur iOS */
  }

  .md-form-actions {
    flex-direction: column-reverse;
    width: 100%;
  }

  .md-form-actions .md-btn {
    width: 100%;
    justify-content: center;
  }
}

/**************************************** DARK MODE (optionnel) ***************************/

@media (prefers-color-scheme: dark) {
  .md-form-section {
    background: #2c2c2c;
    border-color: #444;
  }

  .md-section-header {
    background: linear-gradient(135deg, #3a3a3a 0%, #2c2c2c 100%);
  }

  .md-section-active .md-section-header {
    background: var(--md-primary-color-lighter-extended);
    color:var(--md-primary-lighter-extended-text-color);
    border-bottom-color: var(--md-primary-color-darker);
  }

  .md-form-input,
  .md-form-select,
  .md-form-textarea {
    background: #2c2c2c;
    border-color: #444;
    color: #e0e0e0;
  }

  .md-form-label,
  .md-section-title {
    color: #e0e0e0;
  }
}

/**************************************** ACCESSIBILITÉ ***************************/

/* Focus visible pour navigation clavier */
*:focus-visible {
  outline: 2px solid var(--md-primary-color);
  outline-offset: 2px;
}

/* Réduction des animations si demandé */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/**************************************** PRINT ***************************/

@media print {
  .md-modal-close,
  .md-form-help-btn,
  .md-form-footer {
    display: none;
  }

  .md-form-section {
    page-break-inside: avoid;
  }

  .md-section-content {
    max-height: none !important;
  }
}
