/* Visual Product Finder · widget público.
   Tokens sobreponibles por el tema: redefine --vpf-* donde lo necesites. */

/* El widget se inyecta en temas arbitrarios: sin su propio reset, cualquier padding
   o borde con box-sizing:content-box desborda el contenedor en pantallas angostas. */
.vpf-box, .vpf-box *, .vpf-box *::before, .vpf-box *::after { box-sizing: border-box; }

.vpf-box {
  --vpf-radius: 14px;
  --vpf-radius-sm: 9px;
  --vpf-gap: clamp(12px, 2.4vw, 20px);
  --vpf-surface: #fff;
  --vpf-surface-2: #f6f6f7;
  --vpf-border: #e3e3e7;
  --vpf-text: #16161a;
  --vpf-muted: #6b6b76;
  --vpf-accent: #16161a;
  --vpf-ring: #4f46e5;
  --vpf-shadow: 0 1px 2px rgba(16, 16, 24, .05), 0 8px 24px -12px rgba(16, 16, 24, .18);
  max-width: 1040px;
  margin: 0 auto;
  font-family: inherit;
  color: var(--vpf-text);
}

.vpf-title { margin: 0 0 4px; font-size: clamp(17px, 2.4vw, 21px); font-weight: 600; line-height: 1.35; }
.vpf-hint { margin: 0 0 16px; color: var(--vpf-muted); font-size: 13.5px; }

/* Zona de carga: botón + drop zone */
.vpf-drop {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  padding: 16px 18px;
  border: 1.5px dashed var(--vpf-border);
  border-radius: var(--vpf-radius);
  background: var(--vpf-surface);
  cursor: pointer;
  transition: border-color .16s ease, background-color .16s ease, transform .16s ease;
}
.vpf-drop:hover { border-color: #b9b9c2; background: var(--vpf-surface-2); }
.vpf-drop:is(:focus-within, .is-over) {
  border-color: var(--vpf-ring);
  border-style: solid;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .22);
}
.vpf-drop.is-over { transform: scale(1.005); }
.vpf-drop[aria-disabled="true"] { opacity: .6; cursor: progress; }
.vpf-drop-icon {
  display: grid; place-items: center;
  width: 38px; height: 38px; flex: none;
  border-radius: 10px;
  background: var(--vpf-surface-2);
  color: var(--vpf-muted);
}
.vpf-drop-label { display: block; font-weight: 600; font-size: 15px; }
.vpf-drop-sub { display: block; color: var(--vpf-muted); font-size: 12.5px; margin-top: 1px; }
.vpf-file { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* Vista previa + progreso */
.vpf-preview { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.vpf-preview img {
  width: 56px; height: 56px; flex: none;
  border-radius: var(--vpf-radius-sm);
  object-fit: cover; background: var(--vpf-surface-2);
  border: 1px solid var(--vpf-border);
}
.vpf-preview-meta { min-width: 0; flex: 1; }
.vpf-status { display: block; min-height: 1.35em; font-size: 13.5px; color: var(--vpf-muted); }
.vpf-reset {
  appearance: none; border: 0; background: none; padding: 2px 0;
  font: inherit; font-size: 12.5px; color: var(--vpf-accent);
  text-decoration: underline; text-underline-offset: 2px; cursor: pointer;
}
.vpf-reset:focus-visible { outline: 2px solid var(--vpf-ring); outline-offset: 2px; border-radius: 4px; }

/* Barra indeterminada: la búsqueda real tarda ~2 s y sin esto parece colgada */
.vpf-bar { position: relative; height: 3px; margin-top: 8px; border-radius: 999px; background: var(--vpf-surface-2); overflow: hidden; }
.vpf-bar::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: 0; width: 38%;
  border-radius: inherit; background: var(--vpf-accent);
  animation: vpf-slide 1.15s cubic-bezier(.65, .05, .36, 1) infinite;
}
@keyframes vpf-slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(310%); } }

/* Resultados */
.vpf-results { margin-top: calc(var(--vpf-gap) + 6px); }
.vpf-results-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 12px; }
.vpf-results-count { font-size: 13px; color: var(--vpf-muted); }

/* Corrección de la grid comprimida: min(100%, X) evita que una columna ancha fuerce
   el desborde en pantallas angostas, y min-width:0 deja truncar el texto en vez de empujar. */
.vpf-compact-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 168px), 1fr));
  gap: var(--vpf-gap);
}
.vpf-compact-card {
  position: relative;
  display: flex; flex-direction: column;
  min-width: 0;
  border: 1px solid var(--vpf-border);
  border-radius: var(--vpf-radius);
  background: var(--vpf-surface);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.vpf-compact-card:hover { transform: translateY(-3px); box-shadow: var(--vpf-shadow); border-color: #d5d5db; }
.vpf-compact-card:focus-visible { outline: 2px solid var(--vpf-ring); outline-offset: 2px; }
.vpf-compact-media { display: block; position: relative; aspect-ratio: 1; background: var(--vpf-surface-2); }
.vpf-compact-image { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.vpf-compact-score {
  position: absolute; left: 8px; bottom: 8px;
  padding: 3px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .01em;
  background: rgba(22, 22, 26, .72); color: #fff;
}
.vpf-compact-body { display: flex; flex: 1 1 auto; flex-direction: column; gap: 3px; padding: 11px 12px 13px; }
.vpf-compact-name {
  font-size: 13.5px; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.vpf-compact-price { margin-top: auto; padding-top: 4px; font-size: 14px; font-weight: 650; font-variant-numeric: tabular-nums; }

/* Esqueleto: misma geometría que la tarjeta real, así nada se salta al llegar los resultados */
.vpf-skeleton-card { position: relative; display: flex; flex-direction: column; min-width: 0; border: 1px solid var(--vpf-border); border-radius: var(--vpf-radius); overflow: hidden; }
.vpf-skeleton-media { position: relative; aspect-ratio: 1; background: var(--vpf-surface-2); }
.vpf-skeleton-line { position: relative; height: 11px; margin: 11px 12px 0; border-radius: 999px; background: var(--vpf-surface-2); }
.vpf-skeleton-line:last-child { width: 45%; margin-bottom: 14px; height: 13px; }
.vpf-shimmer { overflow: hidden; }
.vpf-shimmer::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(100deg, transparent 20%, rgba(255, 255, 255, .7) 50%, transparent 80%);
  transform: translateX(-100%);
  animation: vpf-shimmer 1.35s ease-in-out infinite;
}
@keyframes vpf-shimmer { 100% { transform: translateX(100%); } }

/* Estados vacío y de error */
.vpf-empty, .vpf-error {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  margin: 0; padding: 30px 18px;
  border: 1px dashed var(--vpf-border); border-radius: var(--vpf-radius);
  background: var(--vpf-surface-2);
  color: var(--vpf-muted); text-align: center; font-size: 14px;
}
.vpf-error { border-style: solid; border-color: #f0c9c9; background: #fdf3f3; color: #8a2f2f; }
.vpf-empty svg { opacity: .55; margin-bottom: 2px; }

@media (max-width: 420px) {
  .vpf-compact-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 138px), 1fr)); }
  .vpf-compact-name { -webkit-line-clamp: 1; line-clamp: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .vpf-compact-card, .vpf-drop { transition: none; }
  .vpf-compact-card:hover { transform: none; }
  .vpf-bar::after, .vpf-shimmer::after { animation: none; }
  .vpf-bar::after { width: 100%; opacity: .35; }
}
