/* ==========================================================================
   MAGNETIE — Navigation & Search (Function B)
   Adds interactive states on top of the Function A header shell: hamburger
   + mobile drawer, collapsible mobile search, and the transparent-over-hero
   header mode. Loaded after header.css so these rules extend/override its
   defaults for specific states without editing header.css itself.
   ========================================================================== */

/* ---------- Utility icon affordance ---------- */

.icon-btn:hover {
  color: var(--color-ink-soft);
}

.site-search__icon {
  cursor: pointer;
}

.site-search__icon:hover {
  color: var(--color-ink-soft);
}

/* ---------- Desktop search: collapsed icon expands leftward on hover/
   focus/typing, keeping Wishlist/Account/Cart fixed in place (Function F
   fix — was a permanently-open, center-positioned bar with two magnifying-
   glass icons). Pure CSS: :hover and :focus-within cover "hovered" and
   "focused/typing", and :not(:placeholder-shown) covers "has a value" so a
   typed query stays visible even after the pointer leaves and focus moves
   away — exactly the three conditions that must ALL fail (not hovered, not
   focused, empty) before nav.js's Escape handler (below) or a plain
   mouseout is allowed to collapse it back down. Scoped to the tablet band
   (769–1024px) since the frontend redesign; >1024px shows a permanent
   field (next block) and the mobile collapse-to-icon + fixed flyout
   further down this file is untouched. ---------- */

@media (min-width: 769px) and (max-width: 1024px) {
  .site-search:hover .site-search__input,
  .site-search:focus-within .site-search__input,
  .site-search__input:not(:placeholder-shown) {
    width: 260px;
    padding-inline: var(--space-4) 40px;
    opacity: 1;
    pointer-events: auto;
  }

  .site-search__input:focus {
    border-color: var(--color-line-strong);
  }
}

/* ---------- Desktop (>1024px): permanently visible search field ----------
   Same form/input/button as every other width (no markup change): the
   magnifier sits at the field's left, the input spans the slot as a quiet
   underline field. nav.js already treats >768px as "open"
   (syncSearchToViewport), so submit, suggestions and Escape (clears the
   query) work unchanged. */

@media (min-width: 1025px) {
  .site-search {
    width: var(--header-search-w);
    justify-content: flex-start;
  }

  .site-search__icon {
    width: 24px;
    color: var(--color-ink);
  }

  .site-search__icon svg {
    width: 16px;
    height: 16px;
  }

  .site-search__input {
    width: 100%;
    padding-inline: 30px 0;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--color-line-strong);
    border-radius: 0;
    font-size: var(--fs-small);
    opacity: 1;
    pointer-events: auto;
    appearance: none;
  }

  .site-search__input:hover {
    border-bottom-color: var(--color-ink-soft);
  }

  /* The underline itself is the focus indicator (thickens to ink) rather
     than the global 2px outline box around an underline-only field. */
  .site-search__input:focus-visible {
    outline: none;
    border-bottom-color: var(--color-ink);
    box-shadow: 0 1px 0 var(--color-ink);
  }

  .search-suggest {
    left: 0;
    right: auto;
    width: max(100%, 320px);
  }
}

/* ---------- Live search suggestions (js/nav.js) ---------- */

.search-suggest {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  z-index: var(--z-overlay);
  display: flex;
  flex-direction: column;
  width: 300px;
  max-height: 360px;
  overflow-y: auto;
  padding: var(--space-2);
  background: var(--color-surface);
  border: var(--border-hairline);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
}

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

.search-suggest__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--fs-small);
  color: var(--color-ink);
}

.search-suggest__item:hover,
.search-suggest__item:focus-visible {
  background: var(--color-bg);
}

.search-suggest__thumb {
  width: 32px;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  object-position: top center;
  border-radius: var(--radius-sm);
  background: var(--color-bg-cool);
}

.search-suggest__label {
  flex: 1 1 auto;
  min-width: 0;
}

.search-suggest__meta,
.search-suggest__empty {
  font-size: var(--fs-small);
  color: var(--color-ink-muted);
}

.search-suggest__empty {
  padding: var(--space-2);
}

/* ---------- Menu toggle (hamburger) — mobile only ---------- */

.menu-toggle {
  display: none;
  flex: 0 0 auto;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  width: 36px;
  height: 36px;
}

.menu-toggle span {
  display: block;
  width: 18px;
  height: 1.5px;
  background: var(--color-ink);
  transition: transform var(--duration-fast) var(--ease-standard),
              opacity var(--duration-fast) var(--ease-standard);
}

.menu-toggle[aria-expanded="true"] span:nth-child(1) {
  transform: translateY(5.5px) rotate(45deg);
}

.menu-toggle[aria-expanded="true"] span:nth-child(2) {
  opacity: 0;
}

.menu-toggle[aria-expanded="true"] span:nth-child(3) {
  transform: translateY(-5.5px) rotate(-45deg);
}

/* ---------- Mobile nav drawer ---------- */

.mobile-nav {
  position: fixed;
  top: var(--header-bottom, var(--header-height));
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-overlay);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  padding: var(--space-7) var(--container-pad);
  background: var(--color-surface);
  border-top: var(--border-hairline);
  overflow-y: auto;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity var(--duration-base) var(--ease-standard),
              transform var(--duration-base) var(--ease-standard);
}

.mobile-nav[hidden] {
  display: none;
}

.mobile-nav[data-open="true"] {
  opacity: 1;
  transform: translateY(0);
}

.mobile-nav a {
  font-family: var(--font-display);
  font-size: var(--fs-display-md);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--color-ink);
}

.mobile-nav a[aria-current="page"] {
  color: var(--color-ink-soft);
}

/* "Search by category" group (js/nav.js initMenuCategories): a toggle set
   like the links above, expanding to a smaller list of categories. */
.mobile-nav__toggle {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  font-family: var(--font-display);
  font-size: var(--fs-display-md);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  text-align: left;
  color: var(--color-ink);
}

.mobile-nav__toggle::after {
  content: "";
  width: 9px;
  height: 9px;
  margin: -5px 0 0 auto;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  transition: transform var(--duration-fast) var(--ease-standard);
}

.mobile-nav__toggle[aria-expanded="true"]::after {
  margin-top: 4px;
  transform: rotate(-135deg);
}

/* The drawer's heading: same look as the old toggle, without the arrow. */
.mobile-nav__heading { margin: 0; cursor: default; }
.mobile-nav__heading::after { content: none; }

.mobile-nav__sub {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-4) 0 0 var(--space-4);
}

.mobile-nav__sub[hidden] {
  display: none;
}

.mobile-nav .mobile-nav__sub a,
.mobile-nav__note {
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 500;
  text-transform: none;
  letter-spacing: normal;
  color: var(--color-ink);
}

.mobile-nav__note {
  color: var(--color-ink-soft);
}

body.has-scroll-lock {
  overflow: hidden;
}

/* ---------- Mobile: hamburger visible, search collapses to an icon
   trigger and expands into a flyout bar under the header ---------- */

@media (max-width: 768px) {
  .menu-toggle {
    display: flex;
    width: 28px;
  }

  /* Tighten the shell's own gap/padding so the hamburger fits without
     pushing the wishlist/account/cart icons off-screen (header.css's
     defaults were sized for logo + search + utility only). icon-btn
     (wishlist/account/cart) keeps Function A's 36px — only spacing
     and Function B's own new elements shrink. */
  .site-header {
    gap: var(--space-1);
    padding-inline: var(--space-2);
  }

  .site-utility {
    gap: var(--space-1);
  }

  .site-search {
    flex: 0 0 auto;
    width: 28px;
    justify-content: center;
  }

  /* The desktop redesign turned .site-search__icon into a 36px icon-btn-
     sized button and .site-search__input into an absolutely-positioned,
     right-anchored element that only gains width via the >768px hover/
     focus rules in this file — neither is appropriate at 28px collapsed
     mobile width, so both are restored to their pre-existing mobile sizing/
     behavior here. */
  .site-search__icon {
    width: 28px;
    height: 36px;
    color: var(--color-ink);
  }

  .site-search__icon svg {
    width: 18px;
    height: 18px;
  }

  .site-search__input {
    display: none;
  }

  .site-search[data-open="true"] {
    position: fixed;
    top: var(--header-bottom, var(--header-height));
    left: 0;
    right: 0;
    z-index: var(--z-overlay);
    width: auto;
    height: 56px;
    padding-inline: var(--container-pad);
    background: var(--color-surface);
    border: none;
    border-top: var(--border-hairline);
    border-bottom: var(--border-hairline);
    border-radius: 0;
  }

  .site-search[data-open="true"] .site-search__input {
    display: flex;
    position: static;
    flex: 1 1 auto;
    width: auto;
    height: 100%;
    padding-inline: var(--space-3);
    background: transparent;
    border: none;
    opacity: 1;
    pointer-events: auto;
  }

  .search-suggest {
    top: 100%;
    left: 0;
    right: 0;
    width: auto;
    border-radius: 0;
  }

  .site-search:not([data-open="true"]) .search-suggest {
    display: none;
  }
}

/* Phones: the logo is sized against what's left of the row (hamburger 28 +
   search 28 + 3 × 36px icon-btns + gaps/padding ≈ 200px), so at 375–430px
   a 42px-tall logotype (~126px wide, 3:1) fits with room to spare and reads
   clearly larger than the hamburger. Width stays auto — no distortion.
   Very narrow phones (≤360px) step down so the row never overflows. */
@media (max-width: 480px) {
  .site-logo__image {
    height: 42px;
  }
}

@media (max-width: 360px) {
  .site-logo__image {
    height: 34px;
  }
}
