/**
 * Styles pour le champ de sélection d'icônes FontAwesome
 * Architecture React-like avec interface modale moderne
 * 
 * IMPORTANT: Tous les éléments sont confinés dans leur conteneur parent
 */

/* Règle globale de confinement pour tous les éléments du champ */
.pib-fa-icons-field *,
.pib-fa-icons-field *::before,
.pib-fa-icons-field *::after {
  box-sizing: border-box;
  max-width: 100%;
}

/* Conteneur principal - ne jamais dépasser du parent */
.pib-fa-icons-field {
  width: 100%;
  max-width: 100%;
  height: fit-content;
  box-sizing: border-box;
  overflow: hidden;
}

/* Barre de recherche - confinée dans le parent */
.pib-fa-icons-search-wrapper {
  margin-bottom: 16px;
  max-width: 100%;
  overflow: hidden;
}

.pib-fa-icons-search {
  width: 100%;
  max-width: 100%;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
  box-sizing: border-box;
}

.pib-fa-icons-search:focus {
  outline: none;
  border-color: #2271b1;
  box-shadow: 0 0 0 1px #2271b1;
}

/* Wrapper pour l'option "Aucune" - confiné dans le parent */
.pib-fa-icons-grid-wrapper {
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid #ddd;
  max-width: 100%;
  overflow: hidden;
}

/* Grille d'icônes - confinée et responsive */
.pib-fa-icons-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
  max-height: 400px;
  max-width: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 4px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #fafafa;
  box-sizing: border-box;
}

/* Bouton d'icône - confiné dans sa cellule */
.pib-fa-icon-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 8px;
  border: 2px solid #ddd;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 90px;
  max-width: 100%;
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
}

.pib-fa-icon-button:hover {
  border-color: #2271b1;
  background: #f0f6fc;
  transform: translateY(-2px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.pib-fa-icon-button:focus {
  outline: none;
  border-color: #2271b1;
  box-shadow: 0 0 0 1px #2271b1;
}

/* Icône sélectionnée */
.pib-fa-icon-button.pib-fa-icon-selected {
  border-color: #2271b1;
  background: #e7f3ff;
  box-shadow: 0 0 0 1px #2271b1;
}

.pib-fa-icon-button.pib-fa-icon-selected::after {
  content: "✓";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  background: #2271b1;
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
}

/* SVG de l'icône */
.pib-fa-icon-svg {
  width: 32px;
  height: 32px;
  fill: currentColor;
  color: #1d2327;
  flex-shrink: 0;
}

.pib-fa-icon-button:hover .pib-fa-icon-svg {
  color: #2271b1;
}

.pib-fa-icon-button.pib-fa-icon-selected .pib-fa-icon-svg {
  color: #2271b1;
}

/* Label de l'icône */
.pib-fa-icon-label {
  font-size: 11px;
  color: #50575e;
  text-align: center;
  line-height: 1.2;
  word-break: break-word;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.pib-fa-icon-button:hover .pib-fa-icon-label {
  color: #2271b1;
}

.pib-fa-icon-button.pib-fa-icon-selected .pib-fa-icon-label {
  color: #2271b1;
  font-weight: 600;
}

/* Bouton "Aucune icône" - confiné dans le parent */
.pib-fa-icon-button.pib-fa-icon-null {
  grid-column: 1 / -1;
  max-width: min(150px, 100%);
  box-sizing: border-box;
}

.pib-fa-icon-none {
  font-size: 28px;
  color: #d63638;
  font-weight: bold;
}

.pib-fa-icon-button.pib-fa-icon-null:hover .pib-fa-icon-none {
  color: #d63638;
}

/* Message "Aucune icône disponible" */
.pib-fa-icons-empty {
  padding: 24px;
  text-align: center;
  color: #646970;
  font-style: italic;
}

/* Icône cachée par la recherche */
.pib-fa-icon-button.pib-fa-icon-hidden {
  display: none;
}

/* Scrollbar personnalisée pour la grille */
.pib-fa-icons-grid::-webkit-scrollbar {
  width: 8px;
}

.pib-fa-icons-grid::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

.pib-fa-icons-grid::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 4px;
}

.pib-fa-icons-grid::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* Compteur de résultats */
.pib-fa-results-counter {
  font-size: 12px;
  color: #666;
  margin-top: 8px;
  font-style: italic;
}

/* Bouton "Charger plus" - confiné dans le parent */
.pib-fa-icons-load-more-wrapper {
  text-align: center;
  padding: 12px 0;
  margin-top: 12px;
  max-width: 100%;
  overflow: hidden;
}

.pib-fa-icons-load-more {
  font-size: 12px;
  color: #666;
  padding: 8px 16px;
  max-width: 100%;
  box-sizing: border-box;
}

.pib-fa-icons-load-more strong {
  color: #2271b1;
  font-weight: 600;
}

.pib-fa-icons-load-more:hover {
  color: #2271b1;
  border-color: #2271b1;
}

/* Script JSON caché */
.pib-fa-icons-data {
  display: none;
}

/* =========================================
   INTERFACE REACT-LIKE - Nouveau design
   ========================================= */

/* Interface principale avec aperçu et boutons - layout flex vertical */
.pib-fa-picker-interface {
  display: flex;
  flex-direction: column;
  gap: 12px; /* Espace vertical entre preview et boutons */
  margin-bottom: 12px;
  max-width: 100%;
  overflow: hidden;
  box-sizing: border-box;
}

/* Container des boutons */
.pib-fa-picker-interface .pib-fa-buttons-container {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  background: #f9f9f9;
  border: 1px solid #ddd;
  border-radius: 6px;
}

/* Aperçu d'icône avec design cohérent */
.pib-fa-icon-preview {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: white;
  border: 1px solid #ddd;
  border-radius: 6px;
  transition: all 0.2s ease;
  align-self: flex-start;
  box-sizing: border-box;
  min-height: 44px;
}

.pib-fa-icon-preview:hover {
  border-color: #0073aa;
  box-shadow: 0 0 0 1px rgba(0, 115, 170, 0.1);
}

.pib-fa-icon-preview svg {
  display: block;
  fill: currentColor;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

/* Slug de l'icône dans l'aperçu */
.pib-fa-icon-preview .pib-fa-icon-slug {
  font-size: 12px;
  color: #50575e;
  line-height: 1.3;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

/* État vide de l'aperçu avec message clair */
.pib-fa-icon-preview:empty::before {
  content: "Aucune icône sélectionnée";
  font-size: 12px;
  color: #999;
  opacity: 0.8;
  font-style: italic;
}

/* État avec icône sélectionnée */
.pib-fa-icon-preview:not(:empty) {
  border-color: #0073aa;
  background: #f0f6fc;
}

.pib-fa-icon-preview:not(:empty) svg {
  color: #0073aa;
}

.pib-fa-icon-preview:not(:empty) .pib-fa-icon-slug {
  color: #0073aa;
  font-weight: 600;
}

/* Modal overlay et contenu */
.pib-fa-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000000;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.pib-fa-modal-content {
  background: white;
  border-radius: 8px;
  width: 90%;
  max-width: 800px;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  animation: slideIn 0.2s ease-out;
}

@keyframes slideIn {
  from {
    transform: scale(0.9) translateY(-20px);
    opacity: 0;
  }
  to {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

/* En-tête de la modal */
.pib-fa-modal-content h3 {
  margin: 0;
  font-size: 18px;
  color: #1e1e1e;
}

/* Barre de recherche dans la modal */
.pib-fa-modal-search {
  width: 100%;
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
  box-sizing: border-box;
  transition: border-color 0.2s ease;
}

.pib-fa-modal-search:focus {
  outline: none;
  border-color: #0073aa;
  box-shadow: 0 0 0 1px #0073aa;
}

/* Compteur de résultats dans la modal */
.pib-fa-modal-results-counter {
  font-size: 12px;
  color: #666;
  margin: 8px 0 16px 0;
  font-style: italic;
}

/* Grille d'icônes dans la modal - confinée dans le parent */
.pib-fa-modal-icons-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
  max-height: 400px;
  max-width: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 16px;
  background: #fafafa;
  box-sizing: border-box;
}

/* Boutons d'icônes dans la modal - confinés dans leur cellule */
.pib-fa-modal-icon-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 8px;
  min-height: 80px;
  max-width: 100%;
  font-size: 11px;
  text-align: center;
  border: 2px solid #ddd;
  border-radius: 4px;
  background: white;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  overflow: hidden;
  box-sizing: border-box;
}

.pib-fa-modal-icon-button:hover {
  border-color: #0073aa;
  background-color: #f9f9f9;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.pib-fa-modal-icon-button.selected {
  border-color: #0073aa;
  background-color: #f0f6fc;
  box-shadow: 0 0 0 1px #0073aa;
}

.pib-fa-modal-icon-button svg {
  margin-bottom: 4px;
  fill: currentColor;
}

.pib-fa-modal-icon-button span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  line-height: 1.2;
}

/* Message d'erreur */
.pib-fa-icons-error {
  padding: 12px;
  background: #fef7f7;
  border: 1px solid #f5c6cb;
  border-radius: 4px;
  margin-bottom: 12px;
}

.pib-fa-icons-error p {
  margin: 0;
  color: #d63638;
  font-style: italic;
}

/* Responsive design */
@media (max-width: 768px) {
  .pib-fa-modal-content {
    width: 95%;
    max-height: 90vh;
  }

  .pib-fa-modal-icons-grid {
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: 6px;
    padding: 12px;
  }

  .pib-fa-modal-icon-button {
    min-height: 60px;
    padding: 8px 4px;
    font-size: 10px;
  }

  /* Interface picker responsive - adaptation tablette */
  .pib-fa-icon-preview .pib-fa-icon-slug {
    font-size: 11px; /* Police légèrement plus petite sur tablette */
  }

  /* Version mobile optimisée */
  @media (max-width: 480px) {
    .pib-fa-picker-interface {
      gap: 8px; /* Gap réduit sur mobile */
    }

    .pib-fa-icon-preview {
      padding: 6px 10px;
      gap: 6px;
    }

    .pib-fa-icon-preview svg {
      width: 20px;
      height: 20px;
    }

    .pib-fa-icon-preview .pib-fa-icon-slug {
      font-size: 11px;
    }
  }
}
