/* ============================================================
   Site Search — header trigger + ⌘K modal (all pages).
   Port of the React "SearchModal" command palette to vanilla JS.
   Design tokens come from :root in style.css.
   ============================================================ */

/* ---- Header search trigger (all pages) ---- */
.search-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 999px;
  padding: 8px 12px;
  color: #fff;
  cursor: pointer;
  line-height: 1;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.search-trigger:hover,
.search-trigger:focus-visible {
  background: #fff;
  color: #000;
  border-color: #fff;
  outline: none;
}
.search-trigger-icon {
  display: block;
  flex-shrink: 0;
}
.search-trigger-kbd {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  padding: 2px 5px;
  line-height: 1.4;
}
.search-trigger:hover .search-trigger-kbd,
.search-trigger:focus-visible .search-trigger-kbd {
  border-color: rgba(0, 0, 0, 0.3);
}

/* ---- Homepage static-search section (kept for the modal's ancestry) ---- */
.site-search {
  background: var(--ink);
  color: var(--paper);
  border-top: 1px solid #222;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(72px, 10vh, 140px) 0;
}

.site-search .wrap {
  width: 100%;
  max-width: 620px;
}

.site-search-head {
  text-align: center;
  margin-bottom: 30px;
}

.site-search-head h2 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(1.7rem, 3.4vw, 2.6rem);
  line-height: 1.15;
  letter-spacing: -0.01em;
  color: var(--paper);
}

/* ---- Search panel card ---- */
.search-panel {
  width: 100%;
  overflow: hidden;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.07);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 10px 40px -14px rgba(0, 0, 0, 0.22);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  color: #0e0e0f;
  transition: border-radius 0.25s ease, box-shadow 0.25s ease;
}

.search-panel.is-active {
  border-radius: 18px;
  box-shadow: 0 18px 50px -18px rgba(0, 0, 0, 0.32);
}

.search-panel:focus-within {
  border-color: rgba(0, 0, 0, 0.28);
}

/* ---- Dropdown body (hidden until the bar is focused/clicked) ---- */
.search-body {
  display: none;
}

.search-panel.is-active .search-body {
  display: block;
  max-height: min(55vh, 520px);
  overflow-y: auto;
  animation: search-pop 0.18s ease-out;
}

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

/* ---- Search bar row ---- */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 18px 22px;
  border-bottom: 1px solid transparent;
}

.search-panel.is-active .search-bar {
  border-bottom-color: rgba(0, 0, 0, 0.06);
}

.search-bar-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  color: #9ca3af;
}

.search-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  outline: none;
  padding: 0 12px;
  font-family: inherit;
  font-size: 14px;
  color: inherit;
}

.search-input::placeholder {
  color: #9ca3af;
}

.search-bar-hint {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, 0.06);
  background: rgba(0, 0, 0, 0.03);
  padding: 3px 6px;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 500;
  color: #9ca3af;
}

/* ---- "I'm looking for…" chips ---- */
.search-chips {
  padding: 14px 16px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.search-chips-label {
  display: block;
  font-size: 13px;
  color: #9ca3af;
  margin-bottom: 10px;
}

.search-chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.search-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.04);
  padding: 7px 12px 7px 13px;
  font-family: inherit;
  font-size: 13px;
  color: inherit;
  cursor: pointer;
  min-height: 44px;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.search-chip:hover {
  background: rgba(0, 0, 0, 0.07);
}

.search-chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.search-chip .search-chip-x {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  color: inherit;
  opacity: 0.75;
}

/* ---- Results ---- */
.search-results {
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.search-results-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 14px 16px 8px;
  font-size: 13px;
  color: #9ca3af;
}

.search-results-count {
  color: #52525b;
  font-weight: 600;
}

.search-results-list {
  list-style: none;
  margin: 0;
  padding: 0 6px 6px;
}

.search-result {
  margin: 0;
}

.search-result-link {
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 8px;
  padding: 11px 10px;
  min-height: 44px;
  color: inherit;
  text-decoration: none;
  transition: background-color 0.15s ease;
}

.search-result-link:hover,
.search-result-link[aria-selected="true"] {
  background: rgba(0, 0, 0, 0.04);
}

.search-result-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: #d4d4d8;
  color: #52525b;
}

.search-result-icon svg {
  width: 13px;
  height: 13px;
}

.search-result-name {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-meta {
  padding-left: 6px;
  color: #9ca3af;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-arrow {
  margin-left: auto;
  flex-shrink: 0;
  padding-left: 12px;
  color: #a1a1aa;
  font-size: 14px;
}

.search-empty {
  padding: 28px 16px 32px;
  text-align: center;
  color: #6b6b6b;
  font-size: 14px;
}

/* ---- Quick actions ---- */
.search-actions {
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  padding: 6px;
}

.search-section-label {
  padding: 10px 10px 6px;
  font-size: 13px;
  color: #9ca3af;
}

.search-action {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 9px 10px;
  min-height: 48px;
  background: transparent;
  font-family: inherit;
  font-size: 14px;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.search-action:hover {
  background: rgba(0, 0, 0, 0.04);
}

.search-action-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.05);
  color: #737373;
}

.search-action-icon svg {
  width: 15px;
  height: 15px;
}

.search-action-label {
  flex: 1;
  min-width: 0;
}

/* ---- Files ---- */
.search-files {
  padding: 6px;
}

.search-file {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 9px 10px;
  min-height: 48px;
  background: transparent;
  font-family: inherit;
  font-size: 14px;
  color: inherit;
  text-align: left;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s ease;
}

.search-file:hover {
  background: rgba(0, 0, 0, 0.04);
}

.search-file-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.05);
  color: #737373;
}

.search-file-icon svg {
  width: 15px;
  height: 15px;
}

.search-file-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-file-ext {
  color: #9ca3af;
}

.search-file-share {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  border: 0;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  color: #a1a1aa;
  cursor: pointer;
  min-height: 44px;
  transition: color 0.15s ease;
}

.search-file-share:hover {
  color: #3f3f46;
}

.search-file-share svg {
  width: 15px;
  height: 15px;
}

/* ---- Modal overlay ---- */
.search-overlay {
  position: fixed;
  inset: 0;
  z-index: 600;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 16px;
  padding-top: 12vh;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.search-overlay.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.search-overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.search-overlay .search-panel {
  position: relative;
  z-index: 1;
  max-width: 576px;
  transform: translateY(-8px) scale(0.98);
  transition: transform 0.2s ease-out, opacity 0.2s ease-out;
}

.search-overlay.open .search-panel {
  transform: translateY(0) scale(1);
}

/* ---- Dark variant ---- */
.theme-dark .search-panel,
.search-overlay .search-panel {
  border-color: rgba(255, 255, 255, 0.08);
  background: rgba(23, 23, 23, 0.9);
  color: #ffffff;
  box-shadow: 0 18px 50px -16px rgba(0, 0, 0, 0.7);
}

.theme-dark .search-panel:focus-within,
.search-overlay .search-panel:focus-within {
  border-color: rgba(255, 255, 255, 0.35);
}

.theme-dark .search-bar,
.search-overlay .search-bar {
  border-bottom-color: rgba(255, 255, 255, 0.06);
}

.theme-dark .search-bar-hint,
.search-overlay .search-bar-hint {
  border-color: rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.06);
  color: #6b7280;
}

.theme-dark .search-input::placeholder,
.search-overlay .search-input::placeholder {
  color: #6b7280;
}

.theme-dark .search-chips,
.search-overlay .search-chips {
  border-bottom-color: rgba(255, 255, 255, 0.06);
}

.theme-dark .search-chip,
.search-overlay .search-chip {
  background: rgba(255, 255, 255, 0.07);
}

.theme-dark .search-chip:hover,
.search-overlay .search-chip:hover {
  background: rgba(255, 255, 255, 0.11);
}

.theme-dark .search-chip[aria-pressed="true"],
.search-overlay .search-chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.theme-dark .search-results,
.search-overlay .search-results {
  border-bottom-color: rgba(255, 255, 255, 0.06);
}

.theme-dark .search-result-link:hover,
.search-overlay .search-result-link:hover,
.theme-dark .search-result-link[aria-selected="true"],
.search-overlay .search-result-link[aria-selected="true"] {
  background: rgba(255, 255, 255, 0.06);
}

.theme-dark .search-result-icon,
.search-overlay .search-result-icon {
  background: #3f3f46;
  color: #d4d4d8;
}

.theme-dark .search-result-meta,
.search-overlay .search-result-meta {
  color: #6b7280;
}

.theme-dark .search-actions,
.search-overlay .search-actions {
  border-bottom-color: rgba(255, 255, 255, 0.06);
}

.theme-dark .search-action:hover,
.search-overlay .search-action:hover,
.theme-dark .search-file:hover,
.search-overlay .search-file:hover {
  background: rgba(255, 255, 255, 0.06);
}

.theme-dark .search-action-icon,
.search-overlay .search-action-icon,
.theme-dark .search-file-icon,
.search-overlay .search-file-icon {
  background: rgba(255, 255, 255, 0.08);
  color: #d4d4d8;
}

.theme-dark .search-empty,
.search-overlay .search-empty {
  color: #a1a1aa;
}

/* ---- No-JS / static fallback ---- */
.search-static-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0;
  border: 1px solid rgba(0, 0, 0, 0.07);
  border-radius: 16px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.88);
}

.search-static-list a {
  display: block;
  padding: 14px 18px;
  min-height: 48px;
  color: #0e0e0f;
  font-size: 14px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  transition: background-color 0.15s ease;
}

.search-static-list a:hover {
  background: rgba(0, 0, 0, 0.04);
}

.search-static-list li:nth-child(odd) a {
  border-right: 1px solid rgba(0, 0, 0, 0.06);
}

.search-static-list li:nth-last-child(1) a,
.search-static-list li:nth-last-child(2) a {
  border-bottom: 0;
}

/* Dark static fallback (the section is theme-dark) */
.site-search.theme-dark .search-static-list {
  border-color: rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
}

.site-search.theme-dark .search-static-list a {
  color: var(--paper);
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

.site-search.theme-dark .search-static-list a:hover {
  background: rgba(255, 255, 255, 0.06);
}

.site-search.theme-dark .search-static-list li:nth-child(odd) a {
  border-right-color: rgba(255, 255, 255, 0.08);
}

.js .search-static-list {
  display: none;
}

/* ---- Focus visible ---- */
.search-chip:focus-visible,
.search-action:focus-visible,
.search-file:focus-visible,
.search-file-share:focus-visible,
.search-result-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  .search-overlay,
  .search-overlay .search-panel,
  .search-chip,
  .search-result-link,
  .search-action,
  .search-file,
  .search-file-share {
    transition: none;
  }
}

/* ---- Mobile ---- */
@media (max-width: 700px) {
  .site-search .wrap {
    padding: 0 20px;
  }

  .search-static-list {
    grid-template-columns: 1fr;
  }

  .search-static-list li:nth-child(odd) a {
    border-right: 0;
  }

  .search-static-list li a {
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  }

  .search-static-list li:last-child a {
    border-bottom: 0;
  }

  .search-result-meta {
    display: none;
  }

  .search-overlay {
    padding-top: 8vh;
  }
}
