/* ============================================================
   DIPLOMA.AFRICA - Custom Searchable Taxonomy Dropdown
   Remplace le <select> natif de field_filiere par un dropdown
   avec recherche, scroll et hiérarchie parent/enfant
   ============================================================ */
   

/* --- Container principal --- */
.custom-select-wrapper {
  position: relative;
  width: 100%;
}

/* --- Bouton trigger (remplace le select natif) --- */
.custom-select-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #fff;
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  cursor: pointer;
  font-size: 15px;
  color: #334155;
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.custom-select-trigger:hover,
.custom-select-trigger.active {
  border-color: #2563EB;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.custom-select-trigger .trigger-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-select-trigger .trigger-text.placeholder {
  /*color: #94a3b8;*/
  text-align: left;
}

.custom-select-trigger .trigger-arrow {
  width: 20px;
  height: 20px;
  margin-left: 8px;
  flex-shrink: 0;
  transition: transform 0.2s;
  color: #94a3b8;
}

.custom-select-trigger.active .trigger-arrow {
  transform: rotate(180deg);
  color: #2563EB;
}

/* --- Badge de sélection (tag amovible) --- */
.custom-select-trigger .selected-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #EFF6FF;
  color: #2563EB;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  max-width: 85%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-select-trigger .selected-badge .badge-clear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #BFDBFE;
  color: #2563EB;
  font-size: 11px;
  flex-shrink: 0;
  cursor: pointer;
}

.custom-select-trigger .selected-badge .badge-clear:hover {
  background: #2563EB;
  color: #fff;
}

/* --- Dropdown panel --- */
.custom-select-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: opacity 0.2s, transform 0.2s, visibility 0.2s;
  overflow: hidden;
}

.custom-select-dropdown.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* --- Champ de recherche --- */
.custom-select-search {
  padding: 12px;
  border-bottom: 1px solid #f1f5f9;
}

.custom-select-search input {
  width: 100%;
  padding: 10px 12px 10px 36px;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  font-size: 14px;
  color: #334155;
  background: #f8fafc /*url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' */ width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") 10px center no-repeat;
  transition: border-color 0.2s;
  outline: none;
  box-sizing: border-box;
}

.custom-select-search input:focus {
  border-color: #2563EB;
  background-color: #fff;
}

.custom-select-search input::placeholder {
  color: #94a3b8;
}

/* --- Liste scrollable --- */
.custom-select-options {
  max-height: 180px;
  overflow-y: auto;
  /*padding: 9px 16px 9px 32px; */
  text-align: left;
  color: #475569;
  /* Scrollbar custom */
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}

/* Couleur texte des options dans le contexte webform */
.webform-submission-form .custom-select-option {
  color: #475569;
}

.custom-select-options::-webkit-scrollbar {
  width: 6px;
}

.custom-select-options::-webkit-scrollbar-track {
  background: transparent;
}

.custom-select-options::-webkit-scrollbar-thumb {
  background-color: #cbd5e1;
  border-radius: 3px;
}

.custom-select-options::-webkit-scrollbar-thumb:hover {
  background-color: #94a3b8;
}

/* --- Option : parent (domaine) --- */
.custom-select-option.parent {
  padding: 10px 16px;
  font-weight: 600;
  font-size: 13px;
  color: #1e293b;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: #f8fafc;
  border-top: 1px solid #f1f5f9;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s;
}

.custom-select-option.parent:first-child {
  border-top: none;
}

.custom-select-option.parent:hover {
  background: #EFF6FF;
  color: #2563EB;
}

.custom-select-option.parent .option-count {
  font-size: 11px;
  font-weight: 500;
  color: #94a3b8;
  background: #f1f5f9;
  padding: 1px 6px;
  border-radius: 10px;
  margin-left: auto;
}

.custom-select-option.parent:hover .option-count {
  background: #DBEAFE;
  color: #2563EB;
}

/* --- Option : enfant (sous-domaine) --- */
.custom-select-option.child {
  padding: 9px 16px 9px 32px;
  font-size: 14px;
  color: #475569;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  display: flex;
  align-items: center;
  gap: 8px;
}

.custom-select-option.child:hover {
  background: #EFF6FF;
  color: #2563EB;
}

.custom-select-option.child::before {
  content: '';
  display: inline-block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #cbd5e1;
  flex-shrink: 0;
}

.custom-select-option.child:hover::before {
  background: #2563EB;
}

/* --- Option sélectionnée --- */
.custom-select-option.selected {
  background: #EFF6FF;
  color: #2563EB;
  font-weight: 500;
}

.custom-select-option.child.selected::before {
  background: #2563EB;
}

.custom-select-option.selected::after {
  content: '✓';
  margin-left: auto;
  font-size: 14px;
  color: #2563EB;
  font-weight: 600;
}

/* --- Pas de résultat --- */
.custom-select-empty {
  padding: 20px 16px;
  text-align: center;
  color: #94a3b8;
  font-size: 14px;
}

/* --- Masquer l'option "- Tout -" dans le rendu custom --- */
.custom-select-option[data-value="All"] {
  display: none;
}

/* --- Lien "Effacer" en bas --- */
.custom-select-footer {
  padding: 8px 12px;
  border-top: 1px solid #f1f5f9;
  display: flex;
  justify-content: center;
}

.custom-select-footer .clear-btn {
  font-size: 13px;
  color: #94a3b8;
  cursor: pointer;
  padding: 4px 12px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
  background: none;
  border: none;
}

.custom-select-footer .clear-btn:hover {
  color: #ef4444;
  background: #FEF2F2;
}

/* --- Responsive mobile --- */
@media (max-width: 768px) {
  .custom-select-dropdown {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    border-radius: 16px 16px 0 0;
    max-height: 70vh;
    transform: translateY(100%);
  }

  .custom-select-dropdown.open {
    transform: translateY(0);
  }

  /* Overlay fond sombre */
  .custom-select-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.2s;
  }

  .custom-select-overlay.active {
    display: block;
    opacity: 1;
  }

  /* Handle de glissement */
  .custom-select-dropdown::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: #cbd5e1;
    border-radius: 2px;
    margin: 8px auto;
  }

/*  .custom-select-options {
    max-height: calc(70vh - 120px);
  }
*/
  .custom-select-trigger {
    padding: 14px 16px;
    font-size: 16px; /* éviter le zoom iOS */
  }

  .custom-select-search input {
    font-size: 16px; /* éviter le zoom iOS */
  }
}

/* --- Masquer le select natif quand le custom est actif --- */
.custom-select-wrapper select.form-select {
  display: none !important;
}

/* --- Animation d'entrée --- */
@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.custom-select-option {
  animation: slideUp 0.15s ease-out;
  animation-fill-mode: both;
}

.custom-select-option:nth-child(1) { animation-delay: 0.02s; }
.custom-select-option:nth-child(2) { animation-delay: 0.04s; }
.custom-select-option:nth-child(3) { animation-delay: 0.06s; }
.custom-select-option:nth-child(4) { animation-delay: 0.08s; }
.custom-select-option:nth-child(5) { animation-delay: 0.10s; }
