/**
 * Styles pour l'auto-complétion des établissements
 * Design moderne, accessible, responsive
 */

/* Container principal */
.autocomplete-container {
  position: relative;
  width: 100%;
}

/* Listbox des résultats */
.autocomplete-listbox {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin: 4px 0 0 0;
  padding: 0;
  list-style: none;
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1), 0 4px 10px rgba(0, 0, 0, 0.05);
  max-height: 400px;
  overflow-y: auto;
  z-index: 1000;
  animation: slideDown 0.2s ease-out;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Items de la liste */
.autocomplete-item {
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid #f3f4f6;
  transition: background-color 0.15s ease, border-left-color 0.15s ease;
  border-left: 3px solid transparent;
}

.autocomplete-item:last-child {
  border-bottom: none;
  border-radius: 0 0 8px 8px;
}

.autocomplete-item:first-child {
  border-radius: 8px 8px 0 0;
}

.autocomplete-item:hover,
.autocomplete-item.selected {
  background-color: #f0f9ff;
  border-left-color: #2563eb;
}

.autocomplete-item.selected {
  background-color: #dbeafe;
}

/* Nom de l'établissement */
.autocomplete-item-name {
  font-weight: 600;
  font-size: 15px;
  color: #1f2937;
  margin-bottom: 4px;
  line-height: 1.4;
}

.autocomplete-item-name strong {
  color: #2563eb;
  background-color: #eff6ff;
  padding: 1px 2px;
  border-radius: 2px;
}

/* Localisation */
.autocomplete-item-location {
  font-size: 13px;
  color: #6b7280;
  line-height: 1.3;
}

/* Aucun résultat */
.autocomplete-no-result {
  padding: 20px 16px;
  text-align: center;
  color: #6b7280;
  font-size: 14px;
  list-style: none;
}

/* Bouton "Je ne trouve pas" */
.autocomplete-not-found-btn {
  display: block;
  width: calc(100% - 32px);
  margin: 12px 16px;
  padding: 10px 16px;
  background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
  border: 1px solid #bae6fd;
  border-radius: 6px;
  color: #0369a1;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.autocomplete-not-found-btn:hover {
  background: linear-gradient(135deg, #e0f2fe 0%, #bae6fd 100%);
  border-color: #7dd3fc;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(3, 105, 161, 0.15);
}

.autocomplete-not-found-btn:active {
  transform: translateY(0);
}

/* Message d'aide */
.autocomplete-help {
  font-size: 13px;
  color: #6b7280;
  margin-top: 6px;
  line-height: 1.4;
}

/* Message saisie libre */
.autocomplete-free-input-message {
  margin-top: 8px;
  padding: 12px 16px;
  background: #fef3c7;
  border: 1px solid #fde047;
  border-radius: 8px;
  color: #92400e;
  font-size: 14px;
  line-height: 1.5;
}

/* Champ verrouillé */
.autocomplete-container input.locked {
  background-color: #f9fafb;
  border-color: #d1d5db;
  cursor: not-allowed;
  padding-right: 100px; /* Espace pour le bouton */
}

/* Bouton déverrouiller */
.autocomplete-unlock-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  padding: 6px 14px;
  background: #2563eb;
  color: #ffffff;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s ease;
  z-index: 10;
}

.autocomplete-unlock-btn:hover {
  background: #1d4ed8;
}

.autocomplete-unlock-btn:active {
  background: #1e40af;
}

/* Scrollbar personnalisée */
.autocomplete-listbox::-webkit-scrollbar {
  width: 8px;
}

.autocomplete-listbox::-webkit-scrollbar-track {
  background: #f9fafb;
  border-radius: 4px;
}

.autocomplete-listbox::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 4px;
}

.autocomplete-listbox::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

/* Loading state */
.autocomplete-loading {
  padding: 20px;
  text-align: center;
  color: #6b7280;
  font-size: 14px;
}

.autocomplete-loading::before {
  content: "⏳";
  margin-right: 8px;
}

/* Focus states pour accessibilité */
.autocomplete-item:focus {
  outline: 2px solid #2563eb;
  outline-offset: -2px;
  background-color: #dbeafe;
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Responsive */
@media (max-width: 768px) {
  .autocomplete-listbox {
    max-height: 300px;
    font-size: 14px;
  }

  .autocomplete-item {
    padding: 14px 12px;
  }

  .autocomplete-item-name {
    font-size: 14px;
  }

  .autocomplete-item-location {
    font-size: 12px;
  }

  .autocomplete-unlock-btn {
    padding: 5px 10px;
    font-size: 12px;
  }
}

/* Touch devices */
@media (hover: none) and (pointer: coarse) {
  .autocomplete-item {
    padding: 16px 14px;
    min-height: 48px; /* Touch target minimum */
  }

  .autocomplete-not-found-btn {
    min-height: 48px;
  }
}

/* Dark mode support - DISABLED to force light mode only */
/*
@media (prefers-color-scheme: dark) {
  .autocomplete-listbox {
    background: #1f2937;
    border-color: #374151;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3), 0 4px 10px rgba(0, 0, 0, 0.2);
  }

  .autocomplete-item {
    border-bottom-color: #374151;
  }

  .autocomplete-item:hover,
  .autocomplete-item.selected {
    background-color: #1e3a5f;
    border-left-color: #3b82f6;
  }

  .autocomplete-item-name {
    color: #f9fafb;
  }

  .autocomplete-item-name strong {
    color: #60a5fa;
    background-color: #1e3a5f;
  }

  .autocomplete-item-location {
    color: #d1d5db;
  }

  .autocomplete-no-result {
    color: #9ca3af;
  }

  .autocomplete-container input.locked {
    background-color: #1f2937;
    border-color: #374151;
    color: #f9fafb;
  }
}
*/

/* Animation pour le chargement */
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.autocomplete-loading-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid #e5e7eb;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* États d'erreur */
.autocomplete-error {
  padding: 16px;
  background-color: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  color: #991b1b;
  font-size: 14px;
  margin-top: 8px;
}

.autocomplete-error::before {
  content: "⚠️ ";
  margin-right: 4px;
}

/* Indicateur de saisie libre active */
.autocomplete-container.free-input input {
  border-color: #f59e0b;
  border-width: 2px;
}

.autocomplete-container.free-input .autocomplete-help {
  color: #92400e;
  font-weight: 500;
}

/* Badge établissement validé */
.etablissement-validated {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 8px 12px;
  background: #dcfce7;
  border: 1px solid #86efac;
  border-radius: 6px;
  font-size: 13px;
  color: #166534;
}

.etablissement-validated::before {
  content: "✓";
  font-weight: bold;
  font-size: 16px;
}

/* Position relative pour le parent du champ */
.form-group {
  position: relative;
}

/* Amélioration du focus pour les champs */
.autocomplete-container input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
