/* --------------------------------------------------------------------------
   Search popup (js/search.js), opened from the Header search field.
   Uses the site tokens, chips, plan pills and the nav-item hover (Glass 5% + white text).
   -------------------------------------------------------------------------- */

/* Header trigger: looks exactly like the old search field */
.search-trigger {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  cursor: pointer;
}
.search-trigger .search-field__input {
  display: block;
  color: var(--gray-500);
  text-align: left;
  transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}
.search-trigger:hover .search-field__input,
.search-trigger:focus-visible .search-field__input {
  background: var(--glass-10);
  color: var(--gray-50);
}
.search-trigger:focus-visible { outline: none; }
.search-trigger:focus-visible .search-field__input { box-shadow: inset 0 0 0 1px var(--glass-10); }

/* Page behind does not scroll */
html.has-search-open { overflow: hidden; }
html.has-search-open body { padding-right: var(--scrollbar-gap, 0); }
html.has-search-open .header { right: var(--scrollbar-gap, 0); }

.search-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.search-modal[hidden] { display: none; }
.search-modal.is-open { opacity: 1; }

.search-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 10, 0.7);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.search-modal__panel {
  --search-top: min(14vh, 120px);
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(640px, calc(100% - 2 * var(--page-gutter)));
  max-height: calc(100vh - var(--search-top) - 40px);
  max-height: calc(100dvh - var(--search-top) - 40px);
  margin: var(--search-top) auto 0;
  overflow: hidden;
  border: 1px solid var(--glass-10);
  border-radius: 24px;
  background: var(--gray-950);
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.6);
  transform: translateY(-8px) scale(0.98);
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
.search-modal.is-open .search-modal__panel { transform: none; }

/* Search bar */
.search-modal__bar {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 12px;
  padding: 14px 14px 14px 20px;
  border-bottom: 1px solid var(--glass-5);
}
.search-modal__icon { flex-shrink: 0; opacity: 0.9; }
.search-modal__input {
  flex: 1;
  min-width: 0;
  padding: 6px 0;
  border: 0;
  background: none;
  font: 500 18px/1.4 var(--font);
  color: var(--gray-50);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.search-modal__input::placeholder { color: var(--gray-500); opacity: 1; }
.search-modal__input::-webkit-search-cancel-button { display: none; }

.search-modal__btn {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--glass-5);
  border-radius: 10px;
  background: var(--glass-5);
  transition: background-color 0.2s ease, border-color 0.2s ease;
}
.search-modal__btn[hidden] { display: none; }
.search-modal__btn img { opacity: 0.7; transition: opacity 0.2s ease; }
.search-modal__btn:hover,
.search-modal__btn:focus-visible { background: var(--glass-10); border-color: var(--glass-10); outline: none; }
.search-modal__btn:hover img,
.search-modal__btn:focus-visible img { opacity: 1; }

/* Results area */
.search-modal__body {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--gray-800) transparent;
}

/* Before typing */
.search-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 36px 20px 32px;
  text-align: center;
}
.search-empty__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  margin-bottom: 16px;
  border: 1px solid var(--glass-10);
  border-radius: var(--radius);
  background: var(--glass-5);
}
.search-empty__title {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--gray-50);
}
.search-empty__text {
  max-width: 340px;
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--gray-500);
}

/* Groups */
.search-group { padding: 6px 0 10px; }
.search-group + .search-group { border-top: 1px solid var(--glass-5); padding-top: 12px; }
.search-group__title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 6px 12px 8px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gray-500);
}
.search-group__count {
  padding: 1px 8px;
  border: 1px solid var(--glass-5);
  border-radius: 999px;
  background: var(--glass-5);
  font-size: 11px;
  letter-spacing: 0;
  color: var(--gray-400);
}
.search-group__list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* One result: preview, name, plan */
.search-result {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 10px;
  border-radius: var(--radius);
  color: var(--gray-400);
  box-shadow: inset 0 0 0 1px transparent;
  transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}
.search-result:hover,
.search-result.is-active,
.search-result:focus-visible {
  background: var(--glass-5);
  color: var(--gray-50);
  outline: none;
}
.search-result.is-active,
.search-result:focus-visible { box-shadow: inset 0 0 0 1px var(--glass-10); }

.search-result__thumb {
  position: relative;
  flex-shrink: 0;
  width: 88px;
  aspect-ratio: 411 / 238;
  overflow: hidden;
  border: 1px solid var(--glass-5);
  border-radius: 8px;
  background: var(--gray-900);
}
.search-result__thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.search-result__title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.search-result__title mark {
  background: none;
  color: var(--gray-50);
  text-decoration: underline;
  text-decoration-color: var(--gray-600);
  text-underline-offset: 3px;
}
.search-modal .plan-pill { padding: 4px 10px; font-size: 12px; }
.search-modal .plan-pill--pro img { width: 13px; height: 13px; }

/* "See all N in Category" */
.search-group__all {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0 0 4px;
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.5;
  color: var(--gray-500);
  box-shadow: inset 0 0 0 1px transparent;
  transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}
.search-group__all img { transition: transform 0.2s ease, filter 0.2s ease; }
.search-group__all:hover,
.search-group__all.is-active,
.search-group__all:focus-visible {
  background: var(--glass-5);
  color: var(--gray-50);
  outline: none;
}
.search-group__all.is-active,
.search-group__all:focus-visible { box-shadow: inset 0 0 0 1px var(--glass-10); }
.search-group__all:hover img,
.search-group__all.is-active img { transform: translateX(2px); filter: brightness(0) invert(0.97); }

.search-none {
  margin: 0;
  padding: 40px 20px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--gray-500);
  text-align: center;
}

/* Library: the search that came from "See all", shown as a pill that clears it */
.search-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid var(--glass-10);
  border-radius: var(--radius);
  background: var(--glass-5);
  font-size: 14px;
  line-height: 1.5;
  color: var(--gray-50);
  white-space: nowrap;
  transition: background-color 0.2s ease;
}
.search-pill[hidden] { display: none; }
/* Sits right after the Latest / Most Popular tabs, not in the middle of the bar */
.sort-filters .search-pill { margin-right: auto; margin-left: 16px; }
.search-pill:hover { background: var(--glass-10); }
.search-pill img { opacity: 0.7; }

@media (max-width: 640px) {
  .search-modal__panel {
    --search-top: 12px;
    width: calc(100% - 24px);
    border-radius: 20px;
  }
  .search-modal__input { font-size: 16px; } /* 16px keeps iOS from zooming in */
  .search-result { gap: 12px; }
  .search-result__thumb { width: 72px; }
}

@media (prefers-reduced-motion: reduce) {
  .search-modal,
  .search-modal__panel { transition: none; }
  .search-modal__panel { transform: none; }
}

/* "Clear" in words, so it is not mistaken for the close button next to it */
.search-modal__clear {
  flex-shrink: 0;
  padding: 6px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  font: 500 13px/1.5 var(--font);
  color: var(--gray-500);
  transition: background-color 0.2s ease, color 0.2s ease;
}
.search-modal__clear[hidden] { display: none; }
.search-modal__clear:hover,
.search-modal__clear:focus-visible { background: var(--glass-5); color: var(--gray-50); outline: none; }
