/**
 * France Minéraux Search Widget - Styles
 * Version: 1.0.0
 */

/* Import Jost font */
@import url("https://fonts.googleapis.com/css2?family=Jost:wght@400;600;700&display=swap");

/* Base styles */
.fm-search-widget {
  position: relative;
  width: 100%;
  font-family: "Jost", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
}

/* Input spinner (chargement discret dans l'input) */
.fm-search-input {
  padding-right: 44px;
}

/* Placeholder = texte automatique */
.ts-search-by-category input[name="s"]::placeholder {
  color: #999999 !important;
  opacity: 1;
}

/* Texte tapé par l’utilisateur */
.ts-search-by-category input[name="s"] {
  color: #45293f !important;
}

.fm-input-spinner {
  position: absolute;
  top: 50%;
  right: 14px;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.fm-input-spinner.fm-active {
  opacity: 1;
  visibility: visible;
}

.fm-input-spinner-circle {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(0, 0, 0, 0.15);
  border-top-color: #45293f;
  border-radius: 50%;
  animation: fm-spin 0.8s linear infinite;
}

/* Conteneur des résultats */
.fm-search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: white;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  max-height: 500px;
  overflow-y: auto;
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.3s ease;
}

/* Conteneur wrapper pour la grille desktop */
.fm-results-wrapper {
  display: flex;
  flex-direction: column;
}

/* Grille desktop uniquement */
@media (min-width: 1024px) {
  .fm-results-wrapper {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
    padding: 16px 20px 20px;
  }

  .fm-search-results {
    max-height: 600px;
    left: 50%;
    right: auto;
    width: calc(100vw - 40px);
    max-width: 1200px;
    transform: translate(-50%, -10px);
  }

  .fm-search-results.fm-active {
    transform: translate(-50%, 0);
  }
}

.fm-search-results.fm-active {
  opacity: 1;
  visibility: visible;
}

@media (max-width: 1023px) {
  .fm-search-results.fm-active {
    transform: translateY(0);
  }
}

@media (max-width: 768px) {
  .ts-search-by-category .fm-search-results {
    position: relative;
    top: 0;
    left: 0;
    right: 0;
    transform: none;
  }

  .ts-search-by-category .fm-search-results.fm-active {
    transform: none;
  }
}

@media (min-width: 1024px) {
  .fm-search-results.fm-active {
    transform: translate(-50%, 0);
  }
}

/* Thème sombre */
.fm-search-results[data-theme="dark"] {
  background: #1f2937;
  color: white;
}

/* Header des résultats */
.fm-search-results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #e5e7eb;
  position: sticky;
  top: 0;
  background: white;
  z-index: 1;
}

.fm-search-results[data-theme="dark"] .fm-search-results-header {
  background: #1f2937;
  border-bottom-color: #374151;
}

.fm-search-results-title {
  font-weight: 600;
  font-size: 14px;
  color: #111827;
}

.fm-search-results[data-theme="dark"] .fm-search-results-title {
  color: white;
}

.fm-search-results-count {
  font-size: 12px;
  color: #6b7280;
  background: #f3f4f6;
  padding: 4px 12px;
  border-radius: 12px;
}

.fm-search-results[data-theme="dark"] .fm-search-results-count {
  background: #374151;
  color: #9ca3af;
}

/* Loading state */
.fm-search-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  gap: 16px;
  color: #6b7280;
}

.fm-search-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #f3f4f6;
  border-top-color: #45293f;
  border-radius: 50%;
  animation: fm-spin 0.8s linear infinite;
}

@keyframes fm-spin {
  to {
    transform: rotate(360deg);
  }
}

/* No results */
.fm-no-results {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  gap: 12px;
  color: #6b7280;
}

.fm-no-results-icon {
  font-size: 48px;
  opacity: 0.5;
}

/* Product result */
.fm-product-result {
  display: flex;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid #f3f4f6;
  text-decoration: none;
  color: inherit;
  transition: background-color 0.2s;
}

.fm-product-result:hover {
  background-color: #f9fafb;
}

.fm-search-results[data-theme="dark"] .fm-product-result {
  border-bottom-color: #374151;
}

.fm-search-results[data-theme="dark"] .fm-product-result:hover {
  background-color: #374151;
}

.fm-product-result:last-child {
  border-bottom: none;
}

/* Grille desktop : layout vertical avec image en haut */
@media (min-width: 1024px) {
  .fm-product-result {
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    border: 1px solid #f3f4f6;
    border-radius: 12px;
    background: white;
    height: 100%;
  }

  .fm-search-results[data-theme="dark"] .fm-product-result {
    background: #1f2937;
    border-color: #374151;
  }
}

/* Product image */
.fm-product-image {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
  background: #f3f4f6;
}

/* Image plus grande sur desktop */
@media (min-width: 1024px) {
  .fm-product-image {
    width: 100%;
    height: 180px;
    object-fit: contain;
    object-position: center;
    background: white;
    padding: 10px;
  }

  .fm-search-results[data-theme="dark"] .fm-product-image {
    background: #111827;
  }
}

/* Product info */
.fm-product-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.fm-product-brand {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: #45293f;
  letter-spacing: 0.5px;
}

/* Product rating */
.fm-product-rating {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  white-space: nowrap;
  margin-top: 4px;
  margin-bottom: 4px;
}

.fm-stars {
  display: flex;
  align-items: center;
  gap: 2px;
}

.fm-star {
  display: inline-block;
}

.fm-star-filled path {
  fill: #45293f;
}

.fm-star-empty path {
  fill: #e5e7eb;
}

.fm-reviews-count {
  color: #6b7280;
  font-size: 11px;
}

.fm-product-name {
  font-size: 16px;
  font-weight: 600;
  color: #45293f;
  line-height: 22px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 6px;
}

@media (min-width: 1024px) {
  .fm-product-name {
    min-height: 44px;
  }
}

.fm-search-results[data-theme="dark"] .fm-product-name {
  color: white;
}

.fm-product-description {
  font-size: 12px;
  color: #6b7280;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.fm-product-attribute {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Product footer */
.fm-product-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}

@media (min-width: 1024px) {
  .fm-product-footer {
    margin-top: auto;
  }
}

.fm-product-price {
  display: inline;
  font-family: "Jost", sans-serif;
  font-size: 16px;
  font-weight: 600;
  font-style: normal;
  letter-spacing: normal;
  line-height: 22px;
  color: rgb(215, 185, 132);
}

.fm-product-prices {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.fm-product-price--original {
  text-decoration: line-through;
  opacity: 0.65;
}

.fm-product-price--promo {
  opacity: 1;
}

.fm-product-footer .fm-product-rating {
  margin: 0;
}

/* Score */
.fm-product-score {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: #6b7280;
}

.fm-score-bar {
  width: 60px;
  height: 4px;
  background: #e5e7eb;
  border-radius: 2px;
  overflow: hidden;
}

.fm-search-results[data-theme="dark"] .fm-score-bar {
  background: #374151;
}

.fm-score-fill {
  height: 100%;
  background: linear-gradient(90deg, #7c3aed, #a78bfa);
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* Responsive */
@media (max-width: 768px) {
  .fm-search-results {
    max-height: 400px;
  }

  .fm-product-result {
    gap: 12px;
    padding: 12px 16px;
  }

  .fm-product-image {
    width: 60px;
    height: 60px;
  }

  .fm-product-name {
    font-size: 13px;
  }

  .fm-product-description {
    font-size: 11px;
  }

  .fm-product-price {
    font-size: 14px;
  }
}

/* Scrollbar personnalisé */
.fm-search-results::-webkit-scrollbar {
  width: 8px;
}

.fm-search-results::-webkit-scrollbar-track {
  background: #f3f4f6;
  border-radius: 0 12px 12px 0;
}

.fm-search-results::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 4px;
}

.fm-search-results::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

.fm-search-results[data-theme="dark"]::-webkit-scrollbar-track {
  background: #374151;
}

.fm-search-results[data-theme="dark"]::-webkit-scrollbar-thumb {
  background: #4b5563;
}

.fm-search-results[data-theme="dark"]::-webkit-scrollbar-thumb:hover {
  background: #6b7280;
}

/* Rate Limit Error */
.fm-rate-limit-error {
  padding: 20px;
  text-align: center;
}

.fm-rate-limit-icon {
  font-size: 32px;
  margin-bottom: 12px;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.8;
    transform: scale(1.05);
  }
}

.fm-rate-limit-title {
  font-size: 16px;
  font-weight: 600;
  color: #45293f;
  margin-bottom: 12px;
}

.fm-rate-limit-retry {
  font-size: 14px;
  color: #ef4444;
  font-weight: 600;
  margin-bottom: 12px;
}

.fm-rate-limit-alternative {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #e5e7eb;
}

.fm-rate-limit-alternative p {
  font-size: 13px;
  color: #6b7280;
  margin: 0;
}

/* Dark theme pour rate limit */
.fm-search-results[data-theme="dark"] .fm-rate-limit-title {
  color: #f3f4f6;
}

.fm-search-results[data-theme="dark"] .fm-rate-limit-retry {
  color: #fca5a5;
}

.fm-search-results[data-theme="dark"] .fm-rate-limit-alternative {
  border-top-color: #374151;
}

.fm-search-results[data-theme="dark"] .fm-rate-limit-alternative p {
  color: #d1d5db;
}
