/* ==========================================================================
   Header inline search — a search bar in the nav bar with an anchored
   dropdown panel (popular products, browse-by-category, live results).
   Desktop: pill bar in the nav, dropdown anchored beneath it.
   Mobile : opened from the search icon as a full-width sheet under the header.
   ========================================================================== */

.nav-search {
  position: relative;
  display: flex;
  align-items: center;
}

body.search-open {
  overflow: hidden; /* lock scroll on mobile while the sheet is open */
}

/* ---- Search bar (pill) ---- */
.nav-search__bar {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 380px;
  height: 42px;
  padding: 0 14px;
  background: #ffffff;
  border: 1px solid #ece6e2;
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(33, 24, 20, 0.08);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.nav-search.is-open .nav-search__bar,
.nav-search__bar:focus-within {
  border-color: var(--materialcolororange-300);
  box-shadow: var(--shadow-orange-lg-orange);
}

.nav-search__icon {
  flex: 0 0 auto;
}

.nav-search__input {
  flex: 1 1 auto;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font-size: 14px;
  color: #3a2c25;
}

.nav-search__input::placeholder {
  color: #9c8e87;
}

.nav-search__close {
  display: none; /* desktop closes on outside-click; shown on mobile */
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
}

@media (min-width: 1024px) and (max-width: 1180px) {
  .nav-search__bar { width: 280px; }
}

@media (min-width: 1280px) {
  .nav-search__bar { width: 520px; }
}

/* ---- Dropdown (anchored beneath the bar on desktop) ---- */
/* Column layout so only the middle band scrolls: the scope bar stays at the
   top and the category toggles stay at the bottom, both always reachable
   without scrolling the panel. */
.nav-search__dropdown {
  position: fixed;
  display: none;
  flex-direction: column;
  z-index: 1000;
  width: 520px;
  max-height: 72vh;
  overflow: hidden;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 20px 48px -12px rgba(33, 24, 20, 0.35);
  padding: 18px;
  animation: nav-search-pop 0.16s ease;
}

.nav-search.is-open .nav-search__dropdown {
  display: flex;
}

/* The only scrolling region. min-height:0 is required or a flex item refuses to
   shrink below its content height and the panel grows past max-height instead
   of scrolling. Negative side margins let the scrollbar sit against the panel
   edge rather than inside the 18px padding. */
.nav-search__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  margin: 0 -18px;
  padding: 0 18px;
}

/* Pinned category toggles. Bleeds over the panel's padding so the divider runs
   the full width. */
.search-panel__footer {
  flex: 0 0 auto;
  margin: 14px -18px -18px;
  padding: 14px 18px 18px;
  border-top: 1px solid #ece6e2;
  background: #fff;
}

.search-panel__footer .search-section__title {
  margin-bottom: 10px;
}

@keyframes nav-search-pop {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- Sections ---- */
.search-section + .search-section {
  margin-top: 22px;
}

.search-section__title {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #8a7a72;
}

/* ---- Category tiles ---- */
.search-tiles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

.search-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 8px;
  border: 1px solid #ece6e2;
  border-radius: 12px;
  text-decoration: none;
  color: #3a2c25;
  background: #fff;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
  /* The tile is a <button> now (a multi-select toggle, not a link), so reset the
     UA button styles that would otherwise override the card look. */
  position: relative;
  width: 100%;
  font: inherit;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.search-tile:hover {
  border-color: var(--materialcolororange-300);
  box-shadow: var(--shadow-orange-lg-orange);
  transform: translateY(-2px);
}

.search-tile:focus-visible {
  outline: 2px solid var(--materialcolororange-300);
  outline-offset: 2px;
}

/* Selected = this category is part of the search scope. Colour alone is not
   enough of a signal at this tile size, so it also carries a check badge. */
.search-tile.is-selected {
  border-color: var(--materialcolororange-300);
  box-shadow: inset 0 0 0 1px var(--materialcolororange-300);
  background: #fdf6f1;
}

.search-tile.is-selected::after {
  content: "✓";
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--materialcolororange-300, #d97b4a);
  color: #fff;
  font-size: 11px;
  line-height: 1;
}

/* ---- Active scope bar ---- */
/* flex:0 0 auto so it is never squeezed when the results list is long; the
   negative side margins run its divider the full width of the panel. */
.search-scope {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: -18px -18px 12px;
  padding: 12px 18px;
  border-bottom: 1px solid #ece6e2;
  background: #fff;
}

.search-scope[hidden] {
  display: none;
}

.search-scope__label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #8a7a72;
}

.search-scope__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Each chip removes its own category -- the "x" is generated so the markup
   stays a single text node set from JS. */
.search-scope__chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--materialcolororange-300, #d97b4a);
  border-radius: 999px;
  background: #fdf6f1;
  color: #3a2c25;
  font: inherit;
  font-size: 13px;
  line-height: 1.2;
  cursor: pointer;
}

.search-scope__chip::after {
  content: "×";
  font-size: 15px;
  line-height: 1;
  color: #8a7a72;
}

.search-scope__chip:hover::after {
  color: #3a2c25;
}

.search-scope__clear {
  margin-left: auto;
  padding: 4px 8px;
  border: 0;
  background: none;
  color: #8a7a72;
  font: inherit;
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
}

.search-scope__clear:hover {
  color: #3a2c25;
}

.search-results__reset {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  color: var(--materialcolororange-300, #d97b4a);
  text-decoration: underline;
  cursor: pointer;
}

.search-tile__img {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  overflow: hidden;
  background: #f6f1ed;
}

.search-tile__img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.search-tile__label {
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  line-height: 1.2;
}

/* ---- Live results ---- */
.search-results__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.search-result a {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  text-decoration: none;
  color: #3a2c25;
  transition: background 0.15s ease;
}

.search-result a:hover,
.search-result.is-active a {
  background: #f6f1ed;
}

.search-result__img {
  flex: 0 0 auto;
  width: 56px;
  height: 56px;
  border-radius: 8px;
  object-fit: cover;
  background: #f6f1ed;
  border: 1px solid #ece6e2;
}

.search-result__img--ph {
  display: inline-block;
}

.search-result__name {
  font-size: 15px;
  font-weight: 500;
  line-height: 1.3;
}

.search-results__empty {
  list-style: none;
  padding: 16px 12px;
  color: #8a7a72;
  font-size: 15px;
}

/* ==========================================================================
   Mobile / tablet (<1024px) — full-width sheet under the header.
   The bar is hidden until opened from the header search icon.
   ========================================================================== */
@media (max-width: 1023px) {
  .nav-search {
    position: static;
  }

  .nav-search .nav-search__bar {
    display: none;
  }

  .nav-search.is-open {
    position: fixed;
    top: 64px;
    left: 0;
    right: 0;
    z-index: 1000;
    display: block;
    background: #fff;
    padding: 12px 16px 16px;
    box-shadow: 0 16px 28px rgba(33, 24, 20, 0.2);
    border-radius: 0 0 16px 16px;
    max-height: calc(100vh - 64px);
    overflow-y: auto;
  }

  .nav-search.is-open .nav-search__bar {
    display: flex;
    width: 100%;
    height: 44px;
  }

  .nav-search.is-open .nav-search__close {
    display: flex;
  }

  .nav-search.is-open .nav-search__dropdown {
    position: static;
    display: block;
    width: auto;
    max-height: none;
    overflow: visible;
    padding: 14px 0 0;
    border-radius: 0;
    box-shadow: none;
    animation: none;
  }

  /* Here the sheet (.nav-search.is-open) is the scroller, not the dropdown, so
     the desktop flex split does not apply -- the body just flows. */
  .nav-search__body {
    overflow: visible;
    margin: 0;
    padding: 0;
  }

  /* Stick the toggles to the bottom of the sheet instead, which is the same
     result through the one mechanism that works against an ancestor scroller. */
  .search-panel__footer {
    position: sticky;
    bottom: 0;
    margin: 14px -16px 0;
    padding: 12px 16px 16px;
    box-shadow: 0 -10px 18px rgba(33, 24, 20, 0.08);
  }

  /* The desktop bleed assumes 18px panel padding; the sheet uses 16px. */
  .search-scope {
    margin: 0 -16px 12px;
    padding: 10px 16px;
  }

  .nav-search__input {
    font-size: 16px; /* avoids iOS zoom on focus */
  }

  .search-tiles {
    grid-template-columns: repeat(2, 1fr);
  }
}
