/* Typesense instant search — desktop: wide panel under the header search; mobile (<768px): full-screen overlay */
#search[data-typesense] { position: relative; }

.ts-dropdown {
  --ts-text: var(--black, #232323);
  --ts-muted: var(--gray, #636363);
  --ts-soft: var(--light-beige, #faf7f3);
  --ts-line: #ececec;
  --ts-accent: var(--oil, #6a6b59);
  --ts-sale: var(--red, #c75959);

  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: min(880px, calc(100vw - 32px));
  max-height: min(640px, calc(100vh - 140px));
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, .14), 0 2px 6px rgba(0, 0, 0, .06);
  overflow: hidden;
  z-index: 1000;
  text-align: left;
  font-size: 14px;
  line-height: 1.4;
  color: var(--ts-text);
  animation: ts-in .14s ease-out;
}
.ts-dropdown[hidden] { display: none; }
.ts-dropdown a { color: inherit; text-decoration: none; font-size: inherit; }
@keyframes ts-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

.ts-body { display: grid; grid-template-columns: 230px minmax(0, 1fr); min-height: 0; flex: 1; overflow-y: auto; }
.ts-body--single { grid-template-columns: minmax(0, 1fr); }
.ts-aside { padding: 18px 12px 18px 18px; background: var(--ts-soft); }
.ts-main { padding: 18px; min-width: 0; }

.ts-group + .ts-group { margin-top: 18px; }
.ts-group__title { font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ts-muted); margin: 0 0 8px; }

/* aside: vertical list on desktop */
.ts-aside .ts-chips { display: flex; flex-direction: column; gap: 2px; }
.ts-aside .ts-chip { display: block; padding: 6px 10px; margin: 0 -10px; border-radius: 8px; font-size: 14px; line-height: 1.35; transition: background .12s; }
.ts-aside .ts-chip:hover, .ts-aside .ts-chip:focus-visible { background: #fff; }

/* products grid */
.ts-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.ts-product { display: flex; flex-direction: column; gap: 6px; border-radius: 10px; padding: 6px; margin: -6px; transition: background .12s; }
.ts-product:hover, .ts-product:focus-visible { background: var(--ts-soft); }
.ts-product__img { display: block; aspect-ratio: 1 / 1; background: #f6f6f6; border-radius: 8px; overflow: hidden; }
.ts-product__img img { width: 100%; height: 100%; object-fit: contain; mix-blend-mode: multiply; }
.ts-product__model { font-size: 11px; letter-spacing: .04em; color: var(--ts-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ts-product__name { font-size: 13px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.7em; }
.ts-product__prices { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px; }
.ts-price--new { font-size: 14px; font-weight: 700; }
.ts-price--old { font-size: 12px; color: var(--ts-muted); text-decoration: line-through; }
.ts-price--old + .ts-price--new { color: var(--ts-sale); }

.ts-dropdown mark { background: none; color: inherit; font-weight: 700; padding: 0; }

.ts-banner { display: block; width: 100%; height: auto; border-radius: 10px; margin-bottom: 14px; }

.ts-footer { padding: 12px 18px; border-top: 1px solid var(--ts-line); display: flex; justify-content: center; background: #fff; }
.ts-dropdown .ts-all { display: inline-flex; align-items: center; gap: 8px; padding: 10px 22px; border-radius: 999px; background: var(--ts-text); color: #fff; font-size: 13px; font-weight: 600; letter-spacing: .02em; transition: opacity .12s; }
.ts-dropdown .ts-all:hover { opacity: .88; color: #fff; }
.ts-all__count { font-weight: 400; opacity: .75; }

.ts-empty { padding: 28px 0; text-align: center; color: var(--ts-muted); font-size: 14px; }

.ts-close { display: none; }

/* ---------- mobile: full-screen overlay ---------- */
@media (max-width: 767px) {
  body.ts-open { overflow: hidden; }
  /* floating widgets (Zendesk launcher, ESPA badge) would cover the overlay footer */
  body.ts-open iframe[data-testid="launcher"],
  body.ts-open #launcher,
  body.ts-open .espa-image { display: none !important; }

  #search[data-typesense].ts-active {
    position: fixed !important;
    inset: 0;
    z-index: 2147483000;
    margin: 0 !important;
    max-width: none !important;
    width: 100% !important;
    background: #fff;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-rows: auto minmax(0, 1fr);
    align-items: center;
    gap: 0 4px;
    padding: 10px 12px 0;
  }
  /* !important: theme's .shortcuts-items.mobile #search rules are more specific */
  #search.ts-active .form-control { grid-column: 1; grid-row: 1; float: none; width: 100%; height: 44px !important; min-height: 44px !important; font-size: 16px; border: 0 !important; border-radius: 10px; background: #f4f4f4; padding: 0 14px !important; }
  #search.ts-active .input-group-btn { grid-column: 2; grid-row: 1; position: static !important; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; }
  #search.ts-active .search-btn { display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; padding: 0; margin: 0; }
  #search.ts-active .search-icon, #search.ts-active .search-icon svg { top: 0 !important; display: block; width: 20px !important; height: 20px !important; }
  #search.ts-active .ts-close { display: flex; grid-column: 3; grid-row: 1; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 10px; color: var(--black, #232323); cursor: pointer; user-select: none; }
  #search.ts-active .ts-close svg { display: block; width: 20px; height: 20px; }

  #search.ts-active .ts-dropdown {
    grid-column: 1 / -1;
    grid-row: 2;
    align-self: stretch; /* fill the row so the footer button sits at the bottom */
    position: static;
    width: auto;
    max-height: none;
    min-height: 0;
    margin: 10px -12px 0;
    border-radius: 0;
    box-shadow: none;
    border-top: 1px solid #ececec;
    animation: none;
  }

  .ts-body { grid-template-columns: minmax(0, 1fr); } /* minmax: long chip rows must scroll, not widen the column */
  .ts-aside { padding: 14px 12px 4px; background: #fff; }
  .ts-main { padding: 12px; }

  /* aside lists become horizontal scrolling chips */
  .ts-aside .ts-group + .ts-group { margin-top: 12px; }
  .ts-aside .ts-chips { flex-direction: row; flex-wrap: nowrap; overflow-x: auto; gap: 8px; margin: 0 -12px; padding: 0 12px 2px; scrollbar-width: none; }
  .ts-aside .ts-chips::-webkit-scrollbar { display: none; }
  .ts-aside .ts-chip { flex: none; margin: 0; padding: 7px 14px; border-radius: 999px; background: #f4f4f4; font-size: 13px; white-space: nowrap; }

  .ts-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }

  .ts-footer { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  .ts-dropdown .ts-all { width: 100%; justify-content: center; padding: 13px 22px; font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) { .ts-dropdown { animation: none; } }
