/* ── Inline Search Dropdown ── */

.search-layer {
  position: fixed;
  inset: 0;
  z-index: 120;
  pointer-events: none;
  visibility: hidden;
}

.search-layer.is-open {
  visibility: visible;
  /* pointer-events stays none on the layer itself so the search input
     underneath remains tappable on mobile; only scrim + dropdown catch events */
}

.search-layer.is-open .search-scrim {
  pointer-events: auto;
}

/* Scrim — below the search bar, not covering it */
.search-layer .search-scrim {
  position: absolute;
  top: var(--search-dropdown-top, 60px);
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.0);
  transition: background 0.25s ease;
}

.search-layer.is-open .search-scrim {
  background: rgba(15, 23, 42, 0.06);
}

/* ── Dropdown panel ── */
.search-layer .search-dropdown {
  position: fixed;
  left: var(--search-dropdown-left, 12px);
  top: var(--search-dropdown-top, 86px);
  width: var(--search-dropdown-width, min(560px, calc(100vw - 24px)));
  max-height: var(--search-dropdown-max-height, 60vh);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border: 1px solid rgba(226, 232, 240, 0.6);
  border-radius: 18px;
  box-shadow:
    0 8px 32px rgba(15, 23, 42, 0.10),
    0 2px 8px rgba(15, 23, 42, 0.04),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
  overflow: hidden;
  pointer-events: auto;
  display: flex;
  flex-direction: column;

  /* Smooth open/close */
  opacity: 0;
  transform: translateY(-8px) scale(0.98);
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.search-layer.is-open .search-dropdown {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* ── Results scroll area ── */
.search-layer .search-results {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 8px;
}

/* ── Empty / loading state ── */
.search-layer .search-state {
  min-height: 90px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px 16px;
  color: #94a3b8;
}

.search-layer .search-state svg {
  margin-bottom: 8px;
  opacity: 0.25;
  width: 28px;
  height: 28px;
}

.search-layer .search-state p {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.45;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.search-layer .search-state p + p {
  margin-top: 4px;
}

/* ── Results header ── */
.search-layer .search-results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px 10px;
}

.search-layer .search-results-header h3 {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.search-layer .search-results-count {
  font-size: 11px;
  color: #94a3b8;
  font-weight: 500;
}

/* ── Spinner ── */
.search-layer .search-spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid #e2e8f0;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: search-spin 0.6s linear infinite;
  margin-bottom: 8px;
}

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

/* ── Result items ── */
.search-layer .search-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.search-layer .search-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 12px;
  text-decoration: none;
  color: inherit;
  transition: background 0.15s ease, transform 0.1s ease;
  min-height: 56px;

  /* Stagger animation */
  opacity: 0;
  transform: translateY(6px);
  animation: search-item-in 0.25s ease forwards;
}

/* Stagger delay via nth-child */
.search-layer .search-item:nth-child(1) { animation-delay: 0s; }
.search-layer .search-item:nth-child(2) { animation-delay: 0.03s; }
.search-layer .search-item:nth-child(3) { animation-delay: 0.06s; }
.search-layer .search-item:nth-child(4) { animation-delay: 0.09s; }
.search-layer .search-item:nth-child(5) { animation-delay: 0.12s; }
.search-layer .search-item:nth-child(6) { animation-delay: 0.15s; }
.search-layer .search-item:nth-child(7) { animation-delay: 0.18s; }
.search-layer .search-item:nth-child(8) { animation-delay: 0.21s; }
.search-layer .search-item:nth-child(n+9) { animation-delay: 0.24s; }

@keyframes search-item-in {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.search-layer .search-item:active {
  background: rgba(59, 130, 246, 0.08);
  transform: scale(0.98);
}

@media (hover: hover) {
  .search-layer .search-item:hover {
    background: rgba(15, 23, 42, 0.04);
  }
}

/* ── Thumbnail ── */
.search-layer .search-item-thumb {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
  background: #f1f5f9;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.06);
}

/* ── Item text ── */
.search-layer .search-item-info {
  flex: 1;
  min-width: 0;
}

.search-layer .search-item-title {
  font-size: 14.5px;
  font-weight: 600;
  color: #0f172a;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-layer .search-item-price {
  font-size: 13.5px;
  font-weight: 700;
  color: #334155;
  line-height: 1.35;
  margin-top: 2px;
}

.search-layer .search-item-discount {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  color: #fff;
  background: #ef4444;
  padding: 1px 5px;
  border-radius: 4px;
  margin-left: 6px;
  vertical-align: middle;
  letter-spacing: -0.01em;
}

/* ── Chevron arrow on each item ── */
.search-layer .search-item::after {
  content: '';
  flex-shrink: 0;
  width: 7px;
  height: 7px;
  border-right: 2px solid #cbd5e1;
  border-bottom: 2px solid #cbd5e1;
  transform: rotate(-45deg);
  margin-right: 2px;
  opacity: 0.6;
  transition: opacity 0.15s;
}

.search-layer .search-item:hover::after {
  opacity: 1;
}

/* ── Focus ring on input when search is open ── */
body.search-open .topbar .search input,
body.search-open .search-container .search-input,
body.search-open .search-display {
  box-shadow: 0 0 0 2.5px rgba(59, 130, 246, 0.18), 0 2px 8px rgba(15, 23, 42, 0.06);
  border-color: rgba(59, 130, 246, 0.3);
}

/* ── Clear button (X) — pull to right edge ── */
.search input[type="search"]::-webkit-search-cancel-button,
.search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%2394a3b8'%3E%3Cpath d='M10 8.586L15.293 3.293a1 1 0 111.414 1.414L11.414 10l5.293 5.293a1 1 0 01-1.414 1.414L10 11.414l-5.293 5.293a1 1 0 01-1.414-1.414L8.586 10 3.293 4.707a1 1 0 011.414-1.414L10 8.586z'/%3E%3C/svg%3E") center / contain no-repeat;
  cursor: pointer;
  margin-right: -4px;
}

/* ── Mobile ── */
@media (max-width: 520px) {
  .search-layer .search-dropdown {
    border-radius: 16px;
  }

  .search-layer .search-results {
    padding: 6px;
  }

  .search-layer .search-item {
    padding: 7px 8px;
    gap: 10px;
    min-height: 50px;
  }

  .search-layer .search-item-thumb {
    width: 46px;
    height: 46px;
    border-radius: 9px;
  }

  .search-layer .search-item-title {
    font-size: 14px;
  }

  .search-layer .search-item-price {
    font-size: 13px;
  }

  .search-layer .search-state {
    min-height: 72px;
    padding: 20px 12px;
  }

  .search-layer .search-results-header {
    padding: 4px 6px 8px;
  }
}

/* Very small screens */
@media (max-width: 359px) {
  .search-layer .search-item-thumb {
    width: 40px;
    height: 40px;
  }
}
