/* JG Search frontend — scoped under plugin roots, theme-aware via custom
   properties (spec 06 section 7). */

.jg-search-box {
  --jg-gap: var(--jg-search-gap, 0.5rem);
  --jg-radius: var(--jg-search-radius, 4px);
  --jg-accent: var(--jg-search-accent, currentColor);
  margin: 0 0 1rem;
}

.jg-search-box__label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.jg-search-box__row {
  display: flex;
  gap: var(--jg-gap);
}

.jg-search-box__input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.5em 0.75em;
  border-radius: var(--jg-radius);
  font: inherit;
}

.jg-search-box__submit {
  padding: 0.5em 1em;
  border-radius: var(--jg-radius);
  font: inherit;
  cursor: pointer;
}

.jg-search-results__status {
  margin: 0.5rem 0 1rem;
}

.jg-search-results__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}

.jg-product-card {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  text-decoration: none;
  color: inherit;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: var(--jg-search-radius, 4px);
  padding: 0.75rem;
}

.jg-product-card:focus-visible {
  outline: 2px solid var(--jg-search-accent, currentColor);
  outline-offset: 2px;
}

.jg-product-card__image {
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.04);
  border-radius: var(--jg-search-radius, 4px);
  overflow: hidden;
}

.jg-product-card__image img {
  max-width: 100%;
  height: auto;
}

.jg-product-card__name {
  font-weight: 600;
}

.jg-product-card__sku {
  font-size: 0.8em;
  opacity: 0.7;
}

.jg-product-card__price del {
  opacity: 0.6;
  margin-right: 0.35em;
}

.jg-product-card__stock {
  font-size: 0.85em;
  color: #8a4b00;
}

.jg-search-results__pagination {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 1.25rem;
}

.jg-search-results__page {
  padding: 0.35em 0.75em;
  border-radius: var(--jg-search-radius, 4px);
  border: 1px solid rgba(0, 0, 0, 0.2);
  background: none;
  font: inherit;
  cursor: pointer;
}

.jg-search-results__page.is-current {
  font-weight: 700;
  cursor: default;
}

@media (prefers-reduced-motion: no-preference) {
  .jg-product-card {
    transition: border-color 120ms ease;
  }
}

/* ---- inline completion (ghost text) ---- */

/* Sits exactly over the search field. The typed portion is transparent so it
 * only reserves width; the grey remainder appears to continue the caret.
 * pointer-events:none keeps every click going to the real input. */
.jg-instant-ghost {
  position: absolute;
  z-index: 1;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  overflow: hidden;
  white-space: pre;
  pointer-events: none;
  background: none;
  border: 0;
}

.jg-instant-ghost[hidden] {
  display: none !important;
}

.jg-instant-ghost__typed {
  color: transparent;
}

.jg-instant-ghost__rest {
  color: var(--jg-search-ghost-colour, #9aa0a6);
}

@media (prefers-color-scheme: dark) {
  .jg-instant-ghost__rest {
    color: var(--jg-search-ghost-colour, #8b9198);
  }
}

/* ---- Phase 2: instant layer ---- */

.jg-instant {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 9999;
  background: #fff;
  color: #1d2327;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: var(--jg-search-radius, 4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  max-height: 70vh;
  overflow-y: auto;
}

.jg-instant__suggestion,
.jg-instant__product,
.jg-instant__all {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.8rem;
  cursor: pointer;
}

.jg-instant__suggestion.is-active,
.jg-instant__product.is-active,
.jg-instant__all.is-active,
.jg-instant__suggestion:hover,
.jg-instant__product:hover,
.jg-instant__all:hover {
  background: rgba(0, 0, 0, 0.06);
}

.jg-instant__product img {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 3px;
  flex-shrink: 0;
}

.jg-instant__meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.jg-instant__name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.jg-instant__price {
  font-size: 0.85em;
  opacity: 0.75;
}

.jg-instant__all {
  font-weight: 600;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
}

/* ---- Phase 2: results layout, facets, toolbar ---- */

.jg-search-results__layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 1.5rem;
  align-items: start;
}

.jg-search-results__toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.75rem;
}

.jg-sort__select {
  font: inherit;
  padding: 0.3em 0.5em;
}

.jg-search-results__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.jg-chip {
  font: inherit;
  font-size: 0.85em;
  padding: 0.25em 0.7em;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.25);
  background: none;
  cursor: pointer;
}

.jg-chip--clear {
  border-style: dashed;
}

.jg-facets {
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: var(--jg-search-radius, 4px);
  padding: 0.9rem;
}

.jg-facets__group {
  border: none;
  padding: 0;
  margin: 0 0 1.1rem;
}

.jg-facets__title {
  font-weight: 700;
  margin-bottom: 0.4rem;
}

.jg-facets__option {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0.25rem 0;
  cursor: pointer;
}

.jg-facets__count {
  margin-left: auto;
  font-size: 0.8em;
  opacity: 0.6;
}

.jg-facets__price {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.jg-facets__price input {
  width: 70px;
  font: inherit;
  padding: 0.25em 0.4em;
}

.jg-facets__apply {
  font: inherit;
  padding: 0.25em 0.7em;
  cursor: pointer;
}

/* ---- cards: Phase 2 additions ---- */

.jg-product-card__link {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  text-decoration: none;
  color: inherit;
}

.jg-product-card.is-pinned {
  border-color: var(--jg-search-accent, #1776a6);
}

.jg-product-card__brand {
  font-size: 0.8em;
  opacity: 0.75;
}

.jg-product-card__rating {
  font-size: 0.85em;
}

.jg-product-card__cart {
  margin-top: 0.5rem;
  font: inherit;
  padding: 0.45em 0.8em;
  border-radius: var(--jg-search-radius, 4px);
  border: 1px solid currentColor;
  background: none;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  color: inherit;
}

.jg-product-card__cart:hover {
  background: rgba(0, 0, 0, 0.05);
}

.jg-banner {
  display: block;
  margin-bottom: 1rem;
}

.jg-banner img {
  max-width: 100%;
  height: auto;
  border-radius: var(--jg-search-radius, 4px);
}

.jg-banner__title {
  display: block;
  padding: 0.9rem 1.2rem;
  background: rgba(0, 0, 0, 0.05);
  border-radius: var(--jg-search-radius, 4px);
  font-weight: 700;
}

.jg-search-results__recovery {
  padding: 1rem 0;
}

/* ---- Phase 3: recommendation units ---- */

.jg-recs__unit {
  margin: 1.5rem 0;
}

.jg-recs__heading {
  font-size: 1.2em;
  margin-bottom: 0.75rem;
}

.jg-recs__track {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(160px, 200px);
  gap: 0.9rem;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  padding-bottom: 0.5rem;
}

.jg-recs__unit--grid .jg-recs__track {
  grid-auto-flow: row;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  overflow-x: visible;
}

.jg-recs__card {
  scroll-snap-align: start;
}

/* ---- mobile ---- */

@media (max-width: 782px) {
  .jg-search-results__layout {
    grid-template-columns: 1fr;
  }
  .jg-facets {
    order: 2;
  }
  .jg-search-results__main {
    order: 1;
  }
  .jg-search-results__toolbar {
    justify-content: stretch;
  }
  .jg-sort__select {
    width: 100%;
  }
}
