/*
 * Header search (markup: Components/HeaderDiscovery; behaviour: js/search.js).
 * Prefix: sx-
 */
:root {
  --sx-green-800: #146b33;
  --sx-green-700: #1d8a43;
  --sx-green-100: #e4f4ea;
  --sx-green-50: #f3faf5;
  --sx-ink: #13241b;
  --sx-muted: #5f6d66;
  --sx-faint: #8a958f;
  --sx-border: #dfe8e3;
  --sx-field: #f5f8f6;
  --sx-red: #b42318;
  --sx-amber-50: #fff8e6;
  --sx-amber-700: #8a5a00;
  --sx-radius: 14px;
  --sx-focus: 0 0 0 3px rgba(29, 138, 67, 0.28);
}

.sx {
  position: relative;
}

/* ---------- Field ---------- */

.sx-field {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 52px;
  padding: 0.3rem 0.3rem 0.3rem 0.9rem;
  border: 1.5px solid var(--sx-border);
  border-radius: var(--sx-radius);
  background: var(--sx-field);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.sx-field:hover {
  border-color: #c9d8cf;
}

.sx-field:focus-within,
.sx.is-open .sx-field {
  border-color: var(--sx-green-700);
  background: #fff;
  box-shadow: var(--sx-focus);
}

.sx-icon {
  flex: 0 0 auto;
  color: var(--sx-muted);
  font-size: 1.05rem;
}

.sx-spinner {
  display: none;
  flex: 0 0 auto;
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--sx-green-100);
  border-top-color: var(--sx-green-700);
  border-radius: 50%;
  animation: sx-spin 0.7s linear infinite;
}

.sx.is-loading .sx-icon {
  display: none;
}

.sx.is-loading .sx-spinner {
  display: inline-block;
}

.sx-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 40px;
  padding: 0 0.25rem;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--sx-ink);
  font-size: 0.97rem;
  font-weight: 500;
}

.sx-input::placeholder {
  color: var(--sx-faint);
  font-weight: 400;
  transition: opacity 0.2s ease;
}

.sx-input.is-swapping::placeholder {
  opacity: 0;
}

/* Our own clear button replaces the browser's. */
.sx-input::-webkit-search-cancel-button,
.sx-input::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
}

.sx-clear {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #a3aea8;
  font-size: 1rem;
}

.sx-clear:hover {
  color: var(--sx-muted);
}

.sx-clear:focus-visible {
  outline: 0;
  box-shadow: var(--sx-focus);
}

.sx-clear[hidden] {
  display: none;
}

.sx-kbd {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 0.35rem;
  border: 1px solid var(--sx-border);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: #fff;
  color: var(--sx-faint);
  font: 600 0.72rem/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.sx-field:focus-within .sx-kbd,
.sx.has-value .sx-kbd {
  display: none;
}

.sx-submit {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  height: 42px;
  padding: 0 1.05rem;
  border: 0;
  border-radius: 11px;
  background: var(--sx-green-700);
  color: #fff;
  font-weight: 700;
  font-size: 0.92rem;
  transition: background-color 0.15s ease;
}

.sx-submit .bi {
  display: none;
}

.sx-submit:hover {
  background: var(--sx-green-800);
}

.sx-submit:focus-visible {
  outline: 0;
  box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--sx-green-700);
}

/* ---------- Panel ---------- */

.sx-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  z-index: 30;
  max-height: min(72vh, 600px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.4rem 0;
  border: 1px solid var(--sx-border);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 24px 60px rgba(12, 32, 20, 0.16), 0 2px 6px rgba(12, 32, 20, 0.06);
  animation: sx-in 0.14s ease-out;
}

.sx-panel[hidden] {
  display: none;
}

/* The first-visit delivery hint would sit on top of the open panel. */
body.sx-active .dl-nudge {
  visibility: hidden;
}

.sx.is-loading .sx-panel.has-results {
  opacity: 0.7;
}

.sx-section + .sx-section {
  margin-top: 0.25rem;
  padding-top: 0.25rem;
  border-top: 1px solid #eef3f0;
}

.sx-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 1rem 0.3rem;
}

.sx-section-title {
  margin: 0;
  color: var(--sx-faint);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.sx-link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--sx-green-700);
  font-size: 0.78rem;
  font-weight: 700;
}

.sx-link-btn:hover {
  text-decoration: underline;
}

/* An option is a link: middle-click / long-press "open in new tab" keep working. */
.sx-opt {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 1rem;
  color: var(--sx-ink);
  text-decoration: none;
  cursor: pointer;
}

.sx-opt:hover,
.sx-opt.is-active {
  background: var(--sx-green-50);
  color: var(--sx-ink);
}

.sx-opt.is-active::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--sx-green-700);
}

/* A row = option link + a sibling button (ADD / remove). Buttons can't live inside a link or an option,
   so the row carries the hover/active styling for both. */
.sx-row {
  position: relative;
  display: flex;
  align-items: center;
  padding-right: 1rem;
}

.sx-row > .sx-opt {
  flex: 1 1 auto;
  min-width: 0;
  padding-right: 0.6rem;
}

.sx-row:hover,
.sx-row.is-active {
  background: var(--sx-green-50);
}

.sx-row > .sx-opt:hover,
.sx-row > .sx-opt.is-active {
  background: transparent;
}

.sx-row.is-active::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--sx-green-700);
}

.sx-row > .sx-opt.is-active::before {
  content: none;
}

.sx-opt-icon {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: #f1f5f3;
  color: var(--sx-muted);
  font-size: 0.95rem;
}

.sx-opt-copy {
  flex: 1 1 auto;
  min-width: 0;
}

.sx-opt-label {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.93rem;
  font-weight: 500;
}

.sx-opt-label strong {
  font-weight: 800;
}

.sx-opt-meta {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--sx-faint);
  font-size: 0.76rem;
}

.sx-opt-go {
  flex: 0 0 auto;
  color: #b4beb9;
  font-size: 0.85rem;
}

.sx-opt.is-active .sx-opt-go,
.sx-opt:hover .sx-opt-go {
  color: var(--sx-green-700);
}

.sx-remove {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin-right: -0.35rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #a3aea8;
}

.sx-remove:hover {
  background: #e8eeea;
  color: var(--sx-ink);
}

mark.sx-hl {
  padding: 0;
  background: none;
  color: inherit;
  font-weight: 800;
}

/* ---------- Trending chips ---------- */

.sx-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0.25rem 1rem 0.6rem;
}

.sx-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.38rem 0.75rem;
  border: 1px solid var(--sx-border);
  border-radius: 999px;
  background: #fff;
  color: var(--sx-ink);
  font-size: 0.84rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.sx-chip .bi {
  color: var(--sx-green-700);
  font-size: 0.8rem;
}

.sx-chip:hover,
.sx-chip.is-active {
  border-color: var(--sx-green-700);
  background: var(--sx-green-50);
  color: var(--sx-ink);
}

/* ---------- Product rows ---------- */

.sx-product {
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
}

.sx-thumb {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  padding: 3px;
  border: 1px solid #edf1ee;
  border-radius: 10px;
  background: #fff;
  object-fit: contain;
}

.sx-product .sx-opt-label {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  white-space: normal;
  line-height: 1.3;
  font-size: 0.89rem;
}

.sx-price {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.05rem;
  min-width: 64px;
  text-align: right;
}

.sx-price-now {
  color: var(--sx-ink);
  font-weight: 800;
  font-size: 0.92rem;
}

.sx-price-was {
  color: var(--sx-faint);
  font-size: 0.74rem;
  text-decoration: line-through;
}

.sx-off {
  color: var(--sx-green-700);
  font-size: 0.7rem;
  font-weight: 800;
}

.sx-oos {
  color: var(--sx-muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.sx-product.is-oos .sx-thumb {
  opacity: 0.55;
  filter: grayscale(0.6);
}

/* Mouse/touch shortcut only (keyboard users pick the product and add it on its page). */
.sx-add {
  flex: 0 0 auto;
  min-width: 64px;
  height: 32px;
  padding: 0 0.7rem;
  border: 1.5px solid var(--sx-green-700);
  border-radius: 9px;
  background: #fff;
  color: var(--sx-green-700);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.sx-add:hover {
  background: var(--sx-green-700);
  color: #fff;
}

.sx-add:disabled {
  opacity: 0.6;
}

.sx-add.is-added {
  border-color: var(--sx-green-700);
  background: var(--sx-green-700);
  color: #fff;
}

.sx-add.is-error {
  border-color: var(--sx-red);
  color: var(--sx-red);
}

/* ---------- Notes, footer, states ---------- */

.sx-note {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.2rem 0.75rem 0.35rem;
  padding: 0.5rem 0.75rem;
  border-radius: 10px;
  background: var(--sx-amber-50);
  color: var(--sx-amber-700);
  font-size: 0.82rem;
}

.sx-note strong {
  color: var(--sx-ink);
}

.sx-see-all {
  justify-content: space-between;
  margin-top: 0.25rem;
  padding-top: 0.75rem;
  padding-bottom: 0.75rem;
  border-top: 1px solid #eef3f0;
  color: var(--sx-green-800);
  font-weight: 700;
  font-size: 0.9rem;
}

.sx-see-all:hover,
.sx-see-all.is-active {
  color: var(--sx-green-800);
}

.sx-empty {
  padding: 1.1rem 1rem 0.6rem;
  text-align: center;
}

.sx-empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin-bottom: 0.5rem;
  border-radius: 50%;
  background: #f1f5f3;
  color: var(--sx-muted);
  font-size: 1.2rem;
}

.sx-empty-title {
  margin: 0 0 0.2rem;
  color: var(--sx-ink);
  font-weight: 700;
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}

.sx-empty-text {
  margin: 0;
  color: var(--sx-muted);
  font-size: 0.82rem;
}

.sx-skeleton {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 1rem;
}

.sx-skeleton span {
  display: block;
  border-radius: 8px;
  background: linear-gradient(90deg, #eef2ef 25%, #f7f9f8 50%, #eef2ef 75%);
  background-size: 200% 100%;
  animation: sx-shimmer 1.1s linear infinite;
}

.sx-skeleton span:first-child {
  flex: 0 0 48px;
  height: 48px;
  border-radius: 10px;
}

.sx-skeleton span:last-child {
  flex: 1 1 auto;
  height: 14px;
  max-width: 60%;
}

/* ---------- Results page (Views/Store/ProductList) ---------- */

/* "Showing results for tomato · Search instead for tomoto" */
.sx-notice {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.7rem 0.9rem;
  border: 1px solid #f3e2b3;
  border-radius: 12px;
  background: var(--sx-amber-50);
  color: var(--sx-ink);
  font-size: 0.92rem;
}

.sx-notice > .bi {
  margin-top: 0.1rem;
  color: var(--sx-amber-700);
}

.sx-notice .small {
  color: var(--sx-muted);
}

.sx-notice a {
  color: var(--sx-green-800);
  font-weight: 700;
}

.sx-nr-group {
  width: 100%;
  max-width: 560px;
  margin-top: 1.5rem;
}

.sx-nr-label {
  margin: 0 0 0.6rem;
  color: var(--sx-faint);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.sx-nr-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}

@keyframes sx-spin {
  to { transform: rotate(360deg); }
}

@keyframes sx-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}

@keyframes sx-shimmer {
  to { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .sx-panel,
  .sx-skeleton span {
    animation: none;
  }
  .sx-spinner {
    animation-duration: 2s;
  }
}

/* ---------- Tablets & phones ---------- */

@media (max-width: 991px) {
  .sx-kbd {
    display: none;
  }
}

@media (max-width: 767px) {
  .sx-field {
    min-height: 46px;
    padding: 0.2rem 0.2rem 0.2rem 0.75rem;
    border-radius: 12px;
  }

  .sx-input {
    height: 36px;
    font-size: 1rem; /* 16px: stops iOS zooming into the field */
  }

  .sx-submit {
    width: 38px;
    height: 38px;
    padding: 0;
    justify-content: center;
    border-radius: 10px;
  }

  .sx-submit .bi {
    display: inline;
  }

  .sx-submit-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  /* Open panel takes the rest of the screen below the field, like a native search screen.
     --sx-panel-top is set by search.js from the field's position. */
  .sx.is-open .sx-panel {
    position: fixed;
    top: var(--sx-panel-top, 120px);
    left: 0;
    right: 0;
    bottom: 0;
    max-height: none;
    border: 0;
    border-top: 1px solid var(--sx-border);
    border-radius: 0;
    box-shadow: none;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  }

  /* backdrop-filter would make the header the containing block for the fixed panel. */
  body.sx-open .top-header {
    backdrop-filter: none;
  }

  body.sx-open {
    overflow: hidden;
  }

  body.sx-open #mobileCartStrip {
    display: none !important;
  }

  .sx-opt {
    padding-top: 0.65rem;
    padding-bottom: 0.65rem;
  }

  .sx-product .sx-price {
    min-width: 56px;
  }
}
