/**
 * 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: 120px !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
}

[data-fm-chip="1"] .fm-input-clear {
  display: none !important;
}

[data-fm-chip="1"] .fm-query-chip {
  position: absolute;
  top: 50%;
  left: 12px;
  right: auto;
  transform: translateY(-50%);
  display: none;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #f3f4f6;
  border: 1px solid rgba(69, 41, 63, 0.25);
  color: #45293f;
  font-family: "Jost", sans-serif;
  font-size: 14px;
  line-height: 18px;
  width: auto;
  max-width: calc(100% - 64px);
  box-sizing: border-box;
  z-index: 10002;
}

[data-fm-chip="1"] .fm-query-chip.fm-active {
  display: flex;
}

[data-fm-chip="1"] .fm-query-chip-text {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

[data-fm-chip="1"] .fm-query-chip-clear {
  appearance: none;
  border: none;
  background: transparent;
  color: #6b7280;
  width: 20px;
  height: 20px;
  padding: 0;
  margin: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 999px;
  text-transform: none !important;
  letter-spacing: normal !important;
}

[data-fm-chip="1"] .fm-query-chip-clear:active {
  opacity: 0.85;
}

[data-fm-chip="1"] .fm-search-input.fm-chip-active {
  color: transparent !important;
  caret-color: transparent !important;
}

[data-fm-chip="1"][data-fm-theme="dark"] .fm-query-chip {
  background: #374151;
  border-color: rgba(243, 244, 246, 0.22);
  color: #f3f4f6;
}

[data-fm-chip="1"][data-fm-theme="dark"] .fm-query-chip-clear {
  color: #d1d5db;
}

/* 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: 44px;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 10001;
}

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

.fm-input-clear {
  position: absolute;
  top: 50%;
  right: 44px;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  padding: 0;
  margin: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: #6b7280;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  border-radius: 999px;
  text-transform: none !important;
  letter-spacing: normal !important;
  transition: none !important;
  z-index: 10002;
}

.fm-input-clear.fm-active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.fm-input-clear.fm-hidden {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

.fm-input-clear:focus {
  outline: none;
}

.fm-input-clear:focus-visible {
  outline: 2px solid rgba(69, 41, 63, 0.35);
  outline-offset: 2px;
}

[data-fm-theme="dark"] .fm-input-clear {
  color: #9ca3af;
}

.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;
  overflow-x: hidden;
  scrollbar-gutter: stable;
  z-index: 10000;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  will-change: opacity, transform;
}

.fm-search-results.fm-no-transition {
  transition: none !important;
}

/* 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;
  }

  /* Mode "large" desktop (mosaïque) uniquement quand des produits sont affichés */
  .fm-search-results.fm-wide {
    left: 50%;
    right: auto;
    width: calc(100vw - 40px);
    max-width: 1200px;
    transform: translate(-50%, -10px);
  }

  .fm-search-results.fm-wide.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: absolute;
    top: calc(100% + 8px);
    left: 50%;
    right: auto;
    width: 100vw;
    max-width: 100vw;
    transform: translate(-50%, -10px);
    max-height: 550px;
  }

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

  .fm-search-results-title {
    font-size: 15px;
  }

  .fm-search-results-count {
    font-size: 13px;
  }

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

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

  .fm-product-rating {
    font-size: 12px;
  }

  .fm-stars {
    gap: 1px;
  }

  .fm-product-price {
    font-size: 15px;
    line-height: 20px;
  }

  .fm-product-prices {
    gap: 8px;
  }

  .fm-product-rating svg.fm-star {
    width: 15px !important;
    height: 15px !important;
  }

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

@media (min-width: 1024px) {
  .fm-search-results.fm-active {
    transform: translateY(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: 10;
}

.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: #45293f;
}

.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-loading--compact {
  padding: 18px 16px;
  gap: 10px;
  font-size: 15px;
}

.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;
}

.fm-search-loading--compact .fm-search-spinner {
  width: 22px;
  height: 22px;
  border-width: 2px;
}

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

.fm-search-results[data-theme="dark"] .fm-search-spinner {
  border-color: rgba(255, 255, 255, 0.15);
  border-top-color: rgb(215, 185, 132);
}

@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;
  text-align: center;
}

.fm-no-results-icon {
  font-size: 34px;
  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: 14px;
    padding: 18px;
    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-wrapper {
  position: relative;
  width: 80px;
  height: 80px;
  flex-shrink: 0;
}

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

.fm-product-discount-badge {
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 550;
  line-height: 14px;
  background: #d7b984;
  color: #ffffff;
}

.fm-product-discount-badge--image {
  position: absolute;
  left: 8px;
  bottom: 8px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
}

.fm-product-discount-badge--footer {
  display: none;
  box-shadow: none;
}

/* Image plus grande sur desktop */
@media (min-width: 1024px) {
  .fm-product-image-wrapper {
    width: 100%;
    height: 180px;
  }

  .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;
  }
}

@media (max-width: 1023px) {
  .fm-product-image-wrapper {
    height: auto;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .fm-product-discount-badge--image {
    display: none;
  }

  .fm-product-discount-badge--footer {
    display: inline-flex;
    align-items: center;
  }

  .fm-product-footer .fm-product-discount-badge--footer {
    position: absolute;
    left: calc(-1 * (80px + 16px));
    top: 0;
    transform: none;
    z-index: 1;
  }
}

@media (max-width: 768px) {
  .fm-product-discount-badge {
    line-height: 12px;
  }

  .fm-product-footer .fm-product-discount-badge--footer {
    left: calc(-1 * (88px + 14px));
  }
}

@media (max-width: 768px) {
  .fm-product-image-wrapper {
    width: 88px;
  }

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

/* 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: 15px;
  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: 13px;
  color: #6b7280;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.fm-product-accordion {
  margin-top: 2px;
  padding-top: 0;
}

.fm-search-results[data-theme="dark"] .fm-product-accordion {
  border-top-color: transparent;
}

.fm-product-accordion-toggle {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
  font-size: 12px;
  font-weight: 600;
  color: #45293f;
}

.fm-search-results[data-theme="dark"] .fm-product-accordion-toggle {
  color: rgb(215, 185, 132);
}

.fm-product-accordion-panel {
  margin-top: 6px;
  background: #f9fafb;
  border: 1px solid #f3f4f6;
  border-radius: 10px;
  padding: 9px 12px;
}

.fm-search-results[data-theme="dark"] .fm-product-accordion-panel {
  background: #111827;
  border-color: #374151;
}

.fm-product-detail-row {
  display: grid;
  grid-template-columns: 78px 1fr;
  column-gap: 10px;
  row-gap: 6px;
}

.fm-product-detail-row + .fm-product-detail-row {
  margin-top: 8px;
}

.fm-product-detail-label {
  font-size: 12px;
  font-weight: 600;
  color: #6b7280;
}

.fm-product-detail-value {
  font-size: 12px;
  color: #111827;
  min-width: 0;
  word-break: break-word;
}

.fm-search-results[data-theme="dark"] .fm-product-detail-value {
  color: #e5e7eb;
}

/* Product footer */
.fm-product-footer {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  position: relative;
}

.fm-product-footer .fm-product-prices,
.fm-product-footer .fm-product-price {
  margin-left: auto;
}

.fm-results-actions {
  display: flex;
  justify-content: center;
  padding: 12px 20px 20px;
}

.fm-load-more {
  appearance: none;
  border: none;
  border-radius: 9999px;
  padding: 10px 16px;
  font-family: "Jost", sans-serif;
  font-size: 14px;
  font-weight: 600;
  line-height: 20px;
  cursor: pointer;
  background: #45293f;
  color: white;
}

.fm-load-more:hover {
  opacity: 0.92;
}

.fm-load-more:active {
  opacity: 0.85;
}

.fm-search-results[data-theme="dark"] .fm-load-more {
  background: rgb(215, 185, 132);
  color: #111827;
}

@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;
}

/* 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;
}

.fm-results-title-mobile {
  display: none;
}

@media (max-width: 768px) {
  .fm-results-title-desktop {
    display: none;
  }

  .fm-results-title-mobile {
    display: inline;
  }

  .fm-search-results .fm-search-results-header {
    justify-content: space-between;
    flex-wrap: nowrap;
    row-gap: 0;
    column-gap: 0;
  }

  .fm-search-results .fm-search-results-count {
    margin-left: 0;
  }

  .fm-search-results .fm-product-footer {
    flex-wrap: wrap;
    row-gap: 6px;
    column-gap: 10px;
  }

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

  .fm-search-results .fm-stars {
    gap: 0px !important;
  }

  .fm-search-results .fm-product-price {
    font-size: 14px !important;
    line-height: 18px !important;
  }

  .fm-search-results .fm-product-prices {
    gap: 6px !important;
  }

  .fm-search-results .fm-product-rating svg.fm-star {
    width: 13px !important;
    height: 13px !important;
  }
}

/* Search History */
.fm-search-history {
  padding: 20px;
}

.fm-search-history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid #e5e7eb;
}

.fm-search-history-title {
  font-size: 14px;
  font-weight: 600;
  color: #45293f;
}

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

.fm-search-history-clear {
  appearance: none;
  border: none;
  background: none;
  font-size: 13px;
  font-weight: 600;
  color: #45293f;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background-color 0.2s;
  font-family: "Jost", sans-serif;
  line-height: 1.2;
  text-transform: none !important;
  letter-spacing: normal !important;
  background-color: transparent !important;
  text-decoration: none !important;
}

.fm-search-history-clear:hover {
  background-color: transparent !important;
  color: #6b7280 !important;
  text-decoration: underline !important;
}

.fm-search-history-clear:focus {
  outline: none;
}

.fm-search-history-clear:focus-visible {
  outline: 2px solid rgba(69, 41, 63, 0.35);
  outline-offset: 2px;
}

.fm-search-results[data-theme="dark"] .fm-search-history-clear {
  color: rgb(215, 185, 132);
}

.fm-search-results[data-theme="dark"] .fm-search-history-clear:hover {
  background-color: transparent !important;
  color: #d1d5db !important;
  text-decoration: underline !important;
}

.fm-search-history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fm-search-history-item {
  appearance: none;
  border: none;
  background: white;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid #e5e7eb;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s;
  font-family: "Jost", sans-serif;
}

.fm-search-history-item:hover {
  background-color: #f9fafb;
  border-color: #45293f;
}

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

.fm-search-results[data-theme="dark"] .fm-search-history-item:hover {
  background-color: #374151;
  border-color: rgb(215, 185, 132);
}

.fm-history-icon {
  flex-shrink: 0;
  color: #6b7280;
}

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

.fm-history-text {
  flex: 1;
  font-size: 14px;
  color: #45293f;
  font-weight: 500;
  text-transform: none;
}

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