/* 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;
  min-width: 40px;
  max-width: 40px;
  min-height: 40px;
  max-height: 40px;
  object-fit: contain;
  border-radius: 3px;
  flex-shrink: 0;
}

.jg-instant__meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  min-width: 0;
  flex: 1;
}

.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%;
  }
}

/* ------------------------------------------------------------------ posts
 * A blog post in among the products: quieter, and clearly not something to
 * put in a basket.
 * ------------------------------------------------------------------------ */

.jg-instant__kind {
  font-size: 0.75em;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.55;
}

.jg-instant__product--post .jg-instant__name {
  font-weight: 500;
}

/* ---------------------------------------------------------------- best match
 * The closest product to what was typed, shown first and larger. Sized from
 * the panel's own scale so a theme with a bigger base font gets a bigger card
 * rather than a broken one.
 * ------------------------------------------------------------------------ */

.jg-instant__hero {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 14px;
  cursor: pointer;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  background: linear-gradient(180deg, rgba(23, 118, 166, 0.05), transparent);
}

.jg-instant__hero:hover,
.jg-instant__hero[aria-selected="true"] {
  background: rgba(23, 118, 166, 0.1);
}

.jg-instant__hero-image {
  width: 88px;
  height: 88px;
  min-width: 88px;
  max-width: 88px;
  min-height: 88px;
  max-height: 88px;
  flex-shrink: 0;
  object-fit: contain;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 3px;
}

.jg-instant__hero-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  gap: 3px;
  min-width: 0;
  flex: 1;
}

.jg-instant__hero-badge {
  align-self: flex-start;
  font-size: 0.65em;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #1776a6;
  background: rgba(23, 118, 166, 0.12);
  border-radius: 2px;
  padding: 2px 6px;
  margin-bottom: 2px;
}

.jg-instant__hero-name {
  font-size: 1.15em;
  font-weight: 600;
  line-height: 1.3;
}

.jg-instant__hero-brand,
.jg-instant__hero-sku {
  font-size: 0.8em;
  opacity: 0.7;
}

.jg-instant__hero-sku {
  font-family: Consolas, Monaco, monospace;
}

.jg-instant__hero-price {
  font-size: 1.1em;
  font-weight: 700;
  margin-top: 2px;
}

.jg-instant__hero-stock {
  font-size: 0.8em;
  color: #b32d2e;
}

@media (max-width: 480px) {
  .jg-instant__hero-image {
    width: 64px;
    height: 64px;
    min-width: 64px;
    max-width: 64px;
    min-height: 64px;
    max-height: 64px;
  }

  .jg-instant__hero-name {
    font-size: 1.05em;
  }
}

/* ------------------------------------------------------------------ mobile
 * The panel is positioned against the search form, which is fine on a desktop
 * header but not on a phone: a theme that squeezes its search box into a
 * 100px corner gives us a 100px dropdown, and the contents spill off the edge
 * of the screen.
 *
 * Below this width the panel stops following the form and spans the viewport
 * instead. Only the vertical offset cannot be expressed in CSS — the script
 * measures the input and sets --jg-instant-top, with a sane fallback if it
 * has not run yet.
 * ------------------------------------------------------------------------ */

@media (max-width: 600px) {
  .jg-instant {
    position: fixed;
    top: var(--jg-instant-top, 64px);
    left: 8px;
    right: 8px;
    width: auto;
    max-height: var(--jg-instant-max-height, 60vh);
    border-radius: 6px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  }

  /* Rows need room to breathe once the panel is full width. */
  .jg-instant__product,
  .jg-instant__suggestion,
  .jg-instant__all {
    padding: 12px 14px;
  }

  .jg-instant__product img {
    width: 44px;
    height: 44px;
    min-width: 44px;
    max-width: 44px;
    min-height: 44px;
    max-height: 44px;
  }

  .jg-instant__name,
  .jg-instant__hero-name {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }
}
