/**
 * Styles de CustomSelect.
 *
 * Personnalisation PAR SELECT : chaque `.cs` généré peut recevoir des
 * variables CSS inline (posées automatiquement par le JS à partir des
 * options `fontSize`, `controlHeight`, etc.), ou vous pouvez cibler un
 * select précis en CSS :
 *
 *   #mon-select + .cs { --cs-font-size: 18px; --cs-control-height: 48px; }
 *
 * Personnalisation GLOBALE : changez les valeurs par défaut ci-dessous
 * (dans :root), elles s'appliquent à tous les selects qui ne définissent
 * pas leur propre valeur.
 */

:root {
  --cs-font-size: 15px;
  --cs-control-height: 40px;
  --cs-option-font-size: 15px;
  --cs-option-height: 38px;
  --cs-menu-max-height: 280px;
  --cs-width: 100%;

  --cs-radius: 8px;
  --cs-border: #d7dbe0;
  --cs-border-hover: #b7bec7;
  --cs-border-focus: #f6833b;
  --cs-bg: #ffffff;
  --cs-bg-hover: #f4f6f8;
  --cs-text: #1f2430;
  --cs-text-muted: #8a93a2;
  --cs-selected-bg: #eef4ff;
  --cs-selected-text: #d86b1d;
  --cs-chip-bg: #eef1f5;
  --cs-shadow: 0 8px 24px rgba(20, 24, 33, 0.12);
}

.cs {
  position: relative;
  width: var(--cs-width);
  max-width: 100%;
  font-size: var(--cs-font-size);
  font-family: inherit;
  color: var(--cs-text);
  box-sizing: border-box;
}
.cs * { box-sizing: border-box; }

/* ---------------------------- Contrôle (bouton visible) ---------------------------- */

.cs__control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: var(--cs-control-height);
  padding: 4px 10px;
  background: var(--cs-bg);
  border: 1px solid var(--cs-border);
  border-radius: var(--cs-radius);
  cursor: pointer;
  font: inherit;
  color: inherit;
  text-align: left;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.cs__control:hover { border-color: var(--cs-border-hover); }
.cs__control:focus-visible,
.cs.is-open .cs__control {
  outline: none;
  border-color: var(--cs-border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.cs__values {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  overflow: hidden;
}
.cs__placeholder { color: var(--cs-text-muted); }

.cs__control-icons {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.cs__clear {
  cursor: pointer;
  color: var(--cs-text-muted);
  font-size: 1.15em;
  line-height: 1;
  padding: 0 2px;
  border-radius: 4px;
}
.cs__clear:hover { color: var(--cs-text); background: var(--cs-bg-hover); }

.cs__arrow {
  width: 9px;
  height: 9px;
  border-right: 2px solid var(--cs-text-muted);
  border-bottom: 2px solid var(--cs-text-muted);
  transform: rotate(45deg);
  margin-top: -4px;
  transition: transform 0.15s ease;
  flex-shrink: 0;
}
.cs.is-open .cs__arrow { transform: rotate(-135deg); margin-top: 2px; }

/* ------------------------------------- Puces (multi) ------------------------------------- */

.cs__chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 2px 6px 2px 8px;
  background: var(--cs-chip-bg);
  border-radius: 999px;
  font-size: 0.85em;
  line-height: 1.6;
}
.cs__chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cs__chip--count { background: var(--cs-selected-bg); color: var(--cs-selected-text); font-weight: 600; }
.cs__chip-remove {
  cursor: pointer;
  color: var(--cs-text-muted);
  font-size: 1.1em;
  line-height: 1;
  padding: 0 1px;
}
.cs__chip-remove:hover { color: var(--cs-text); }

/* ----------------------------------------- Menu ----------------------------------------- */

.cs__menu {
  position: absolute;
  z-index: 60;
  top: calc(100% + 6px);
  left: 0;
  width: 100%;
  min-width: 100%;
  background: var(--cs-bg);
  border: 1px solid var(--cs-border);
  border-radius: var(--cs-radius);
  box-shadow: var(--cs-shadow);
  overflow: hidden;
  flex-direction: column;
}
/* Important : ne fixer display:flex QUE quand le menu n'est pas [hidden].
   Sans ce garde-fou, cette règle a la même spécificité que le [hidden]
   natif du navigateur et l'écrase à cause de l'ordre des feuilles de
   style — le menu resterait alors visible en permanence. */
.cs__menu:not([hidden]) {
  display: flex;
}
/* Ouverture vers le haut quand il n'y a pas de place en dessous (responsive vertical) */
.cs--drop-up .cs__menu {
  top: auto;
  bottom: calc(100% + 6px);
}

.cs__search-wrap { padding: 8px; border-bottom: 1px solid var(--cs-border); flex-shrink: 0; }
.cs__search {
  width: 100%;
  border: 1px solid var(--cs-border);
  border-radius: 6px;
  padding: 7px 9px;
  font: inherit;
  font-size: var(--cs-option-font-size);
  color: var(--cs-text);
}
.cs__search:focus { outline: none; border-color: var(--cs-border-focus); }

.cs__options {
  overflow-y: auto;
  max-height: var(--cs-menu-max-height);
  padding: 4px;
}

.cs__group-label {
  padding: 6px 10px 2px;
  font-size: 0.78em;
  font-weight: 600;
  color: var(--cs-text-muted);
}

.cs__option {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--cs-option-height);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: var(--cs-option-font-size);
  cursor: pointer;
}
.cs__option.is-active { background: var(--cs-bg-hover); }
.cs__option.is-selected { background: var(--cs-selected-bg); color: var(--cs-selected-text); }
.cs__option.is-disabled { color: var(--cs-text-muted); cursor: not-allowed; }
.cs__option-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.cs__check {
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--cs-border);
  border-radius: 4px;
  flex-shrink: 0;
  position: relative;
}
.cs__option.is-selected .cs__check {
  background: var(--cs-selected-text);
  border-color: var(--cs-selected-text);
}
.cs__option.is-selected .cs__check::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 1px;
  width: 4px;
  height: 8px;
  border-right: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(40deg);
}

.cs__empty { padding: 14px 10px; text-align: center; color: var(--cs-text-muted); font-size: 0.9em; }

/* ------------------------------------------ Icônes ------------------------------------------ */

.cs__icon {
  flex-shrink: 0;
  width: 1.15em;
  height: 1.15em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05em;
  border-radius: 3px;
  object-fit: cover;
}
.cs__icon--text { font-size: 1.1em; }

/* -------------------------------------- Responsive -------------------------------------- */

@media (max-width: 640px) {
  :root {
    --cs-control-height: 44px; /* cible tactile plus grande sur mobile */
    --cs-option-height: 42px;
  }
  .cs__menu {
    /* Sur mobile, le menu se rapproche des bords de l'écran plutôt que
       de rester strictement collé à la largeur du contrôle, pour rester
       lisible même si le select est étroit. */
    left: 50%;
    right: auto;
    width: max(100%, min(92vw, 420px));
    transform: translateX(-50%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .cs__control, .cs__arrow { transition: none; }
}
