/* ============================================================
 * outsend UI · chips.css
 * ============================================================
 * Composant chips/tags réutilisable pour saisie multi-valeurs.
 *
 * Utilisation HTML :
 *   <div class="chips-input" @click="$refs.myInput.focus()">
 *     <template x-for="(chip, idx) in myChips" :key="idx">
 *       <span class="chip">
 *         <span x-text="chip"></span>
 *         <button class="chip-close" @click.stop="...">✕</button>
 *       </span>
 *     </template>
 *     <input type="text" x-ref="myInput" x-model="myInput" @keydown="..." @paste="...">
 *   </div>
 *
 * Variables CSS utilisées (définies globalement dans style.css) :
 *   --accent, --accent-soft, --accent-text, --border, --bg-card,
 *   --font-mono, --r-sm, --ink, --ink-muted
 * ============================================================ */

.chips-input {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 12px;
  min-height: 80px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm, 4px);
  background: var(--bg-card, #fff);
  font-size: 14px;
  cursor: text;
  align-items: flex-start;
  align-content: flex-start;
}

.chips-input:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.chips-input .chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 4px 4px 10px;
  background: var(--accent-soft, #DEEDED);
  color: var(--accent-text, #094543);
  border-radius: 14px;
  font-size: 13px;
  font-family: var(--font-mono, monospace);
  line-height: 1.2;
  white-space: nowrap;
  max-width: 100%;
}

.chips-input .chip > span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.chips-input .chip-close {
  background: transparent;
  border: 0;
  color: inherit;
  opacity: 0.55;
  cursor: pointer;
  padding: 2px 6px;
  font-size: 12px;
  line-height: 1;
  border-radius: 50%;
}

.chips-input .chip-close:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.08);
}

.chips-input input[type="text"] {
  flex: 1 1 160px;
  min-width: 100px;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--font-mono, monospace);
  font-size: 13px;
  padding: 4px 2px;
  color: var(--ink, #1a1a1a);
}

.chips-input input[type="text"]::placeholder {
  color: var(--ink-muted, #9aa0a6);
  opacity: 0.85;
}

/* ============================================================
 * Variante display-only : chip "cliquable pour supprimer".
 * À utiliser hors d'un chips-input pour afficher une liste éditable
 * (ex: préfixes téléphone choisis dans filtres avancés pipeline).
 *
 * Usage :
 *   <span class="chip chip--removable" @click="removeItem(x)" x-text="x"></span>
 *
 * Hover : passe en rouge soft pour indiquer la suppression.
 * ============================================================ */

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 22px;
}

/* Chip display-only (lecture seule, sans × ni interaction).
   Hors d'un .chips-input. Pour afficher une liste de tags figés
   (ex: requêtes/zones d'un job, tags d'article, etc.). */
.chip-list > .chip,
.chip {
  position: relative; /* anchor pour le tooltip ::before/::after */
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  background: var(--accent-soft, #DEEDED);
  color: var(--accent-text, #094543);
  border-radius: 14px;
  font-size: 13px;
  font-family: var(--font-mono, monospace);
  line-height: 1.2;
  white-space: nowrap;
  user-select: text;
}

/* ============================================================
 * Tooltip custom au survol — instant (pas de délai natif 500ms),
 * stylé en cohérence (au lieu du tooltip système moche). Pur CSS
 * via attribut data-tooltip → pas de JS, pas de fetch, pas de lag.
 *
 * Usage HTML :
 *   <span class="chip" data-tooltip="secrétaire BTP — 45 résultats">…</span>
 *
 * Le saut de ligne `\n` est rendu via white-space: pre-line, donc on peut
 * mettre une liste multi-ligne dans data-tooltip (ex: chip overflow "+12").
 * ============================================================ */

.chip[data-tooltip]:hover::before {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: #1f1d1a;
  color: #fff;
  padding: 7px 11px;
  border-radius: 6px;
  font-size: 12px;
  font-family: var(--font-sans, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif);
  font-weight: 500;
  line-height: 1.45;
  white-space: pre-line;
  text-align: left;
  max-width: 380px;
  min-width: max-content;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22), 0 1px 3px rgba(0, 0, 0, 0.12);
  z-index: 999;
  pointer-events: none;
  /* Fade-in léger (80ms) pour ne pas pop trop sec, mais imperceptible côté lag. */
  animation: chip-tooltip-in 90ms ease-out;
}

.chip[data-tooltip]:hover::after {
  content: '';
  position: absolute;
  bottom: calc(100% + 3px);
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: #1f1d1a;
  z-index: 999;
  pointer-events: none;
  animation: chip-tooltip-in 90ms ease-out;
}

@keyframes chip-tooltip-in {
  from { opacity: 0; transform: translateX(-50%) translateY(2px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.chip-count--zero {
  background: rgba(0, 0, 0, 0.18);
  color: rgba(0, 0, 0, 0.55);
}

.chip--removable {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--accent-soft, #DEEDED);
  color: var(--accent-text, #094543);
  border-radius: 14px;
  font-size: 13px;
  font-family: var(--font-mono, monospace);
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
  user-select: none;
}

.chip--removable::after {
  content: ' ×';
  opacity: 0.6;
  margin-left: 2px;
}

.chip--removable:hover {
  background: #f8d7d4;
  color: #b00020;
}

.chip--removable:hover::after {
  opacity: 1;
}
