/* ============================================================
   Nobo Deal — Dynamic Island Search (nd-search-island.css)
   Loaded AFTER nd-modern.css: overrides .nd-search rules to turn
   the header search into an iPhone-style morphing "island" with
   live product suggestions.

   States (class on the .nd-search wrapper, added by header.jsx):
   - .nd-island-open  -> expanded island (focus / typing)
   - .nd-island-intro -> first-visit grow-in animation
   ============================================================ */

/* ---------- Wrapper ---------- */
.nd-search { position: relative; z-index: 5; }
.nd-search.nd-island-open { z-index: 1090; }

/* ---------- Backdrop while the island is open ----------
   Soft dim + blur over the whole page so the expanding search feels like an
   iPhone dynamic island "growing" into the space. Click closes the island. */
.nd-island-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1055;
  background: rgba(8, 34, 27, 0.22);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: ndBackdropIn .35s ease both;
  cursor: default;
}
@keyframes ndBackdropIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ---------- The island (form): compact white pill when idle ---------- */
.nd-search form {
  width: 100%;
  max-width: 200px;
  margin: 0 auto;
  padding: 3px;
  border-width: 2px;
  border-radius: 999px;
  background: #ffffff;                          /* solid white pill (reference) */
  border-color: #b9d3c8;                        /* thin sage/teal border (reference) */
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .9),
    0 6px 16px rgba(5, 45, 35, .10);            /* soft drop under the bar */
  transition:
    max-width .45s cubic-bezier(.22, 1, .36, 1),
    padding .45s cubic-bezier(.22, 1, .36, 1),
    background-color .45s cubic-bezier(.22, 1, .36, 1),
    border-color .3s ease,
    box-shadow .45s cubic-bezier(.22, 1, .36, 1);
}

/* Expanded island: grows wider + slightly taller with a springy curve,
   stays white, border deepens to emerald (reference keeps green theme). */
.nd-search.nd-island-open form {
  max-width: 640px;
  padding: 4px;
  background: #ffffff;
  border-color: var(--nd-emerald, #0b5c43);
  box-shadow:
    0 18px 40px rgba(5, 45, 35, .20),
    0 6px 14px rgba(5, 45, 35, .12);
}

.nd-search input {
  padding: 4px 10px;
  font-size: 13px;
  transition:
    padding .45s cubic-bezier(.22, 1, .36, 1),
    font-size .45s cubic-bezier(.22, 1, .36, 1);
}
.nd-search input::placeholder { color: #9aa9a1; }  /* light gray, left-aligned (reference) */
.nd-search.nd-island-open input { padding: 11px 18px; font-size: 15px; }

/* Circular search button: dark forest-green with a subtle vertical gradient
   (lighter top -> darker bottom) + thin gold magnifying icon (reference). */
.nd-search button {
  width: 32px;
  height: 32px;
  font-size: 14px;
  background: linear-gradient(180deg, #147a5b 0%, #05382b 100%);
  color: #e9c86f;
  box-shadow:
    0 4px 10px rgba(5, 45, 35, .35),
    inset 0 1px 0 rgba(255, 255, 255, .22);
  transition:
    width .45s cubic-bezier(.22, 1, .36, 1),
    height .45s cubic-bezier(.22, 1, .36, 1),
    font-size .45s cubic-bezier(.22, 1, .36, 1),
    transform .3s var(--nd-ease, cubic-bezier(.22, .61, .36, 1)),
    background-color .3s ease;
}
.nd-search button:hover {
  background: linear-gradient(180deg, #18906c 0%, #0a4a38 100%);
  color: #ffe08a;
  transform: scale(1.06);
}
.nd-search.nd-island-open button { width: 44px; height: 44px; font-size: 17px; }

/* ---------- Suggestions dropdown ---------- */
.nd-suggest {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  right: 0;
  margin: 0 auto;
  max-width: 640px;
  z-index: 1070;
  background: #ffffff;
  border: 1px solid rgba(11, 92, 67, .12);
  border-radius: 18px;
  box-shadow: var(--nd-shadow-3d, 0 12px 28px rgba(5, 45, 35, .12));
  overflow: hidden;
  animation: ndSuggestIn .22s var(--nd-ease, cubic-bezier(.22, .61, .36, 1));
}
@keyframes ndSuggestIn {
  from { opacity: 0; transform: translateY(-6px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

.nd-suggest ul {
  list-style: none;
  margin: 0;
  padding: 8px;
  max-height: 380px;
  overflow-y: auto;
}
.nd-suggest li + li { border-top: 1px solid #eef2ef; }
.nd-suggest a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 12px;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}
.nd-suggest a:hover,
.nd-suggest a:focus-visible { background: #f1f7f3; outline: none; }
.nd-suggest img {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  object-fit: cover;
  background: #eef2ef;
  border: 1px solid #e4ebe6;
}
.nd-suggest-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--nd-ink, #17332a);
}
.nd-suggest-price {
  flex: 0 0 auto;
  font-size: 13px;
  font-weight: 700;
  color: var(--nd-emerald, #0b5c43);
  background: rgba(11, 92, 67, .08);
  padding: 3px 10px;
  border-radius: 20px;
  white-space: nowrap;
}

/* Loading / empty states */
.nd-suggest-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  font-size: 13px;
  color: var(--nd-muted, #7a8a82);
}
.nd-suggest-spinner {
  flex: 0 0 auto;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid rgba(11, 92, 67, .2);
  border-top-color: var(--nd-emerald, #0b5c43);
  animation: ndIslandSpin .7s linear infinite;
}
@keyframes ndIslandSpin { to { transform: rotate(360deg); } }

/* ---------- First-visit intro: tiny pill -> normal size ---------- */
@keyframes ndIslandIntro {
  0%   { transform: scale(.35); opacity: 0; }
  60%  { transform: scale(1.05); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
.nd-island-intro form {
  animation: ndIslandIntro 1.2s cubic-bezier(.22, 1, .36, 1) both;
  transform-origin: center;
}

/* ---------- Desktop: the island expands IN-FLOW and the header grows with it
   On click/focus the pill smoothly grows edge-to-edge; the header row adds
   vertical padding so the HEADER ITSELF grows taller with a soft panel behind
   the search (real dynamic-island feel). The page dims via .nd-island-backdrop. */
@media (min-width: 768px) {
  .nd-header-row { position: relative; transition: padding .45s cubic-bezier(.22, 1, .36, 1); }
  .nd-search {
    flex: 1 1 auto;
    transition: flex-basis .45s cubic-bezier(.22, 1, .36, 1), flex-grow .45s cubic-bezier(.22, 1, .36, 1);
  }
  .nd-search form {
    max-width: 150px;
    padding: 4px 6px;
    transition:
      max-width .45s cubic-bezier(.22, 1, .36, 1),
      padding .45s cubic-bezier(.22, 1, .36, 1),
      background-color .45s cubic-bezier(.22, 1, .36, 1),
      border-color .3s ease,
      box-shadow .45s cubic-bezier(.22, 1, .36, 1);
  }
  .nd-search input { padding: 7px 14px; font-size: 14px; }
  .nd-search.nd-island-open { flex: 1 1 100%; }
  /* Expanded island stays comfortably sized (not full-width) and centered */
  .nd-search.nd-island-open form { max-width: 560px; margin: 0 auto; padding: 10px 16px; }
  .nd-search.nd-island-open input { text-align: center; }
  .nd-search.nd-island-open .nd-suggest {
    left: 0;
    right: 0;
    max-width: 640px;
  }
  /* The header grows with the island */
  .nd-header-row:has(.nd-search.nd-island-open) { padding-top: 12px; padding-bottom: 14px; }

  /* Focus stays on the search: the header rises ABOVE the page backdrop
     (backdrop z 1055) so the searchbar stays crisp, while everything else
     in the header (logo, actions, nav) blurs like the rest of the page. */
  .nd-header:has(.nd-search.nd-island-open) { z-index: 1060; }
  .nd-header:has(.nd-search.nd-island-open) .nd-logo,
  .nd-header:has(.nd-search.nd-island-open) .nd-actions,
  .nd-header:has(.nd-search.nd-island-open) .nd-navbar {
    filter: blur(2.5px);
    opacity: .55;
    pointer-events: none;
    transition: filter .35s ease, opacity .35s ease;
  }
}

/* ---------- Phones: expanded island spans nearly the whole header ---------- */
@media (max-width: 767.98px) {
  /* Solid white pill on mobile too (overrides the glass treatment in nd-modern.css) */
  .nd-search form {
    background: #ffffff;
    border-color: rgba(11, 92, 67, .45);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .8), 0 5px 18px rgba(5, 45, 35, .08);
  }
}

@media (max-width: 575.98px) {
  .nd-search { z-index: 1080; }
  /* Compact pill idle state — matches the reference (SME) size or slightly
     smaller so it never crowds the header row on small phones. */
  .nd-search {
    flex: 1 1 auto;
    transition: flex-basis .45s cubic-bezier(.22, 1, .36, 1), flex-grow .45s cubic-bezier(.22, 1, .36, 1);
  }
  .nd-search form { max-width: 170px; }
  /* Open state: expand IN-FLOW so the HEADER grows with the island.
     Two synchronized, ANIMATABLE properties:
     - the wrapper grows via flex-basis (170px-ish -> 100% of the row),
     - the pill grows via max-width (170px -> 640px; both lengths, so the
       browser can interpolate — `max-width: none` would snap instantly).
     Hiding the action icons while typing frees the full row width, and the
     row's padding grows so the header itself gets taller with the search. */
  .nd-search.nd-island-open {
    position: static;
    flex: 1 1 100%;
    min-width: 0;
    margin: 0;
    z-index: 1090;
    display: flex !important;
  }
  .nd-search.nd-island-open form { max-width: 100%; padding: 10px 12px; }
  .nd-search.nd-island-open .nd-suggest {
    left: 0;
    right: 0;
    max-width: none;
  }
  /* Hide the side icons while typing so the search spans the whole row */
  .nd-header-row:has(.nd-search.nd-island-open) .nd-actions { display: none !important; }
  /* The header grows taller together with the expanded search */
  .nd-header-row:has(.nd-search.nd-island-open) { padding-top: 10px; padding-bottom: 12px; }
}

/* Even narrower phones: shrink the idle pill a touch more so the logo,
   hamburger and icons all fit on one row without overflow. */
@media (max-width: 400px) {
  .nd-search form { max-width: 148px; }
}

/* ---------- Idle rotating product-name teaser (task 2.1) ----------
   ~1s after load the pill morphs slightly larger (springy overshoot) and an
   absolutely-positioned overlay cycles real product names every 2.5s. The
   overlay never blocks the input (pointer-events: none); focusing/typing
   fades it out and Header.jsx stops the cycle. The existing open/close
   max-width morph keeps working because .nd-island-open rules have higher
   specificity than .nd-island-rotating. */
.nd-search form { position: relative; }

.nd-search-rot {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 3;
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  max-width: 86%;
  overflow: hidden;
  white-space: nowrap;
  font-size: 13.5px;
  color: var(--nd-emerald-deep, #0E3B2E);
  animation: ndRotFade .4s cubic-bezier(.34, 1.56, .64, 1);
}
.nd-search-rot-label { color: #93a39b; font-size: 12px; flex: 0 0 auto; }
.nd-search-rot-name {
  font-weight: 600;
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
@keyframes ndRotFade {
  from { opacity: 0; transform: translate(-50%, -42%); }
  to   { opacity: 1; transform: translate(-50%, -50%); }
}
/* Fade-out when the user focuses/types (element stays mounted 260ms via JS). */
.nd-search-rot.nd-rot-hide {
  animation: ndRotOut .25s ease forwards;
}
@keyframes ndRotOut {
  from { opacity: 1; transform: translate(-50%, -50%); }
  to   { opacity: 0; transform: translate(-50%, -55%); }
}

/* Rotating teaser keeps the SAME width as the idle pill — only the text
   cycles in the placeholder, so the pill never shifts under the cursor. */
.nd-island-rotating form {
  max-width: 240px;
  padding: 4px 6px;
  transition:
    max-width .4s cubic-bezier(.34, 1.56, .64, 1),
    padding .4s cubic-bezier(.34, 1.56, .64, 1),
    background-color .4s cubic-bezier(.34, 1.56, .64, 1),
    border-color .3s ease,
    box-shadow .4s cubic-bezier(.34, 1.56, .64, 1);
}
.nd-island-rotating input { padding: 8px 14px; }

/* Phones (<=575px): ONLY the height grows — the width must stay fixed so the
   row icons (hamburger / wishlist / cart) are never pushed out. */
@media (max-width: 575.98px) {
  .nd-island-rotating form { max-width: 150px; padding: 3px 4px; }
  .nd-island-rotating input { padding: 5px 10px; font-size: 12.5px; }
  .nd-search-rot { font-size: 12px; max-width: 80%; }
}

/* ---------- Reduced motion ----------
   The island shrink/grow morph is the feature the user asked for, so keep a
   fast smooth morph even under reduced-motion (overrides the global
   `* { transition-duration: .01ms }` kill in islamic-theme.css via higher
   specificity). Only the flashy intro / dropdown pop animations are dropped.
   Header.jsx also skips the rotating teaser entirely under reduced motion,
   so these rules are just a safety net. */
@media (prefers-reduced-motion: reduce) {
  .nd-search form,
  .nd-search input,
  .nd-search button {
    transition-duration: .25s !important;
    animation: none !important;
  }
  .nd-suggest {
    transition: none !important;
    animation: none !important;
  }
  .nd-island-intro form { animation: none !important; }
  .nd-search-rot { animation: none !important; }
}
