/* ==========================================================================
   Site-wide search — overlay + trigger button
   Used on every page. Loaded via <link rel="stylesheet" href="/search.css">
   ========================================================================== */

/* ----- Trigger button (in header) -----
   NOTE: We intentionally do NOT set `display` here.
   Tailwind utility classes (inline-flex, md:hidden) control visibility.
   Pages load Tailwind first, then search.css — so any `display` set here
   would override Tailwind's `md:hidden` and cause both buttons to show.
   The buttons themselves always include `inline-flex` (Tailwind) so they
   render correctly below md and at md+.
*/
.site-search-trigger {
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  background: #ffffff;
  color: #374151;
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease, border-color .15s ease, box-shadow .15s ease;
  -webkit-tap-highlight-color: transparent;
}
.site-search-trigger:hover {
  background: #ecfdf5;
  color: #059669;
  border-color: #a7f3d0;
}
.site-search-trigger:focus-visible {
  outline: 2px solid #059669;
  outline-offset: 2px;
}
.site-search-trigger svg { width: 18px; height: 18px; }

/* Desktop: show inline-block, slightly smaller */
@media (min-width: 768px) {
  .site-search-trigger {
    width: 34px;
    height: 34px;
  }
  .site-search-trigger svg { width: 16px; height: 16px; }
}

/* ----- Overlay ----- */
.site-search-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 5vh 16px 16px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  animation: ssearch-fade .15s ease-out;
}
.site-search-overlay[hidden] { display: none; }

@keyframes ssearch-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.site-search-panel {
  width: 100%;
  max-width: 720px;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 20px 50px -10px rgba(0,0,0,.4), 0 8px 20px -8px rgba(0,0,0,.2);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  animation: ssearch-slide .18s ease-out;
}

@keyframes ssearch-slide {
  from { transform: translateY(-12px); opacity: 0; }
  to   { transform: translateY(0);     opacity: 1; }
}

/* ----- Search form (input row) ----- */
.site-search-form {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid #f1f5f9;
  margin: 0;
}

.site-search-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #059669;
  flex-shrink: 0;
}

.site-search-input {
  flex: 1 1 auto;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 18px;
  line-height: 1.4;
  color: #111827;
  padding: 4px 0;
  -webkit-appearance: none;
  appearance: none;
}
.site-search-input::placeholder { color: #9ca3af; }
/* Hide the native search clear (x) button — we have our own close */
.site-search-input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }

.site-search-close {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 0;
  background: transparent;
  color: #6b7280;
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease;
}
.site-search-close:hover { background: #f3f4f6; color: #111827; }
.site-search-close svg { width: 20px; height: 20px; }

/* ----- Status line ----- */
.site-search-status {
  padding: 6px 18px;
  font-size: 12px;
  color: #6b7280;
  background: #fafafa;
  border-bottom: 1px solid #f1f5f9;
  min-height: 0;
}
.site-search-status:empty { display: none; }

/* ----- Results list ----- */
.site-search-results {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1 1 auto;
  padding: 8px 8px 12px;
  max-height: 60vh;
}
.site-search-results:empty { display: none; }

.site-search-result-link {
  display: block;
  padding: 10px 12px;
  margin: 2px 0;
  border-radius: 10px;
  text-decoration: none;
  color: #111827;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background-color .12s ease, border-color .12s ease;
}
.site-search-result-link:hover,
.site-search-result-link:focus {
  background: #f0fdf4;
  border-color: #bbf7d0;
  outline: none;
}

.site-search-result-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.site-search-result-type {
  flex-shrink: 0;
  display: inline-block;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .02em;
  border: 1px solid;
  text-transform: uppercase;
  line-height: 1.4;
}

.site-search-result-title {
  font-size: 15px;
  font-weight: 600;
  color: #111827;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1 1 auto;
  min-width: 0;
}

.site-search-result-url {
  display: block;
  font-size: 12px;
  color: #059669;
  margin-bottom: 4px;
  font-weight: 500;
}

.site-search-result-snippet {
  display: block;
  font-size: 13px;
  color: #4b5563;
  line-height: 1.45;
}

/* ----- Empty state ----- */
.site-search-empty {
  padding: 24px 18px;
  text-align: center;
  color: #4b5563;
}
.site-search-empty p { margin: 0 0 8px; font-size: 15px; }
.site-search-empty strong { color: #111827; }
.site-search-empty-hint {
  font-size: 13px !important;
  color: #6b7280 !important;
}
.site-search-empty-hint a {
  color: #059669;
  font-weight: 600;
  text-decoration: underline;
}

/* ----- Footer hint ----- */
.site-search-footer {
  display: flex;
  justify-content: center;
  gap: 18px;
  padding: 10px 16px;
  border-top: 1px solid #f1f5f9;
  background: #fafafa;
  font-size: 12px;
  color: #6b7280;
  flex-wrap: wrap;
}
.site-search-footer kbd {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid #d1d5db;
  border-bottom-width: 2px;
  border-radius: 4px;
  background: #fff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  color: #374151;
  line-height: 1.3;
}

/* ----- Mobile adjustments ----- */
@media (max-width: 640px) {
  .site-search-overlay { padding: 3vh 8px 8px; }
  .site-search-panel { border-radius: 12px; max-height: 95vh; }
  .site-search-input { font-size: 16px; } /* ≥16px to prevent iOS zoom */
  .site-search-form { padding: 12px; gap: 8px; }
  .site-search-footer { gap: 12px; font-size: 11px; }
  .site-search-result-title { font-size: 14px; }
  .site-search-result-snippet { font-size: 12px; }
}

/* ----- Reduced motion ----- */
@media (prefers-reduced-motion: reduce) {
  .site-search-overlay,
  .site-search-panel { animation: none; }
}
