/* ═══════════════════════════════════════════════════════════
   Search Modal — The Loop
   ═══════════════════════════════════════════════════════════ */

/* ── Blur wrapper (all page content except the modal) ────── */
#srchBlurWrap {
  transition: filter 0.2s ease;
}
#srchBlurWrap.srch-blur {
  filter: blur(3px) brightness(0.82);
  pointer-events: none;
  user-select: none;
}

/* ── Overlay ─────────────────────────────────────────────── */
#srchOverlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(20, 19, 17, 0.25);
  align-items: flex-start;
  justify-content: center;
  padding: 68px 20px 40px;
}
#srchOverlay.srch-open {
  display: flex;
  animation: srchFadeIn 0.16s ease forwards;
}
@keyframes srchFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── Modal card ──────────────────────────────────────────── */
.srch-modal {
  background: var(--bg);
  border: 1px solid var(--border-md);
  border-radius: var(--r-lg);
  width: 100%;
  max-width: 580px;
  box-shadow:
    0 0 0 1px rgba(44,43,40,0.05),
    0 20px 56px rgba(20,19,18,0.22),
    0 4px 14px rgba(20,19,18,0.1);
  overflow: hidden;
  /* Fixed height — never shrinks between states */
  min-height: 320px;
  display: flex;
  flex-direction: column;
  transform: translateY(-6px) scale(0.98);
  transition: transform 0.2s cubic-bezier(0.34, 1.3, 0.64, 1);
  isolation: isolate;
}
#srchOverlay.srch-open .srch-modal {
  transform: translateY(0) scale(1);
}

/* ── Input row ───────────────────────────────────────────── */
.srch-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.srch-input-row.has-content {
  border-bottom-color: var(--border);
}
/* Same ink-colored focus treatment used by .search-wrap / .err-search-wrap
   elsewhere on the site, instead of the browser's default ring. */
.srch-input-row:focus-within {
  box-shadow: inset 0 -1px 0 0 var(--ink);
}
.srch-icon {
  color: var(--ink-4);
  flex: none;
  display: flex;
  align-items: center;
}
.srch-field {
  flex: 1;
  border: none;
  outline: none;
  background: none;
  -webkit-appearance: none;
  appearance: none;
  font-family: var(--sans);
  font-size: 15px;
  color: var(--ink);
  line-height: 1.4;
  min-width: 0;
}
.srch-field::-webkit-search-decoration,
.srch-field::-webkit-search-cancel-button,
.srch-field::-webkit-search-results-button,
.srch-field::-webkit-search-results-decoration {
  -webkit-appearance: none;
}
.srch-field::placeholder { color: var(--ink-4); }

/* Spinner */
.srch-spinner {
  display: none;
  width: 14px; height: 14px;
  border: 2px solid var(--border-md);
  border-top-color: var(--ink-3);
  border-radius: 50%;
  animation: srchSpin 0.6s linear infinite;
  flex: none;
}
.srch-spinner.visible { display: block; }
@keyframes srchSpin { to { transform: rotate(360deg); } }

/* ── Idle state — shown when modal opens, nothing typed ──── */
.srch-idle {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 36px 24px 32px;
  text-align: center;
  flex: 1;
  min-height: 180px;
}
.srch-idle-icon {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-4);
  margin-bottom: 2px;
}
.srch-idle-title {
  font-family: var(--serif);
  font-size: 15px; font-weight: 600;
  color: var(--ink-2);
  line-height: 1.3;
}
.srch-idle-sub {
  font-size: 12.5px;
  color: var(--ink-4);
  line-height: 1.55;
  max-width: 260px;
}
/* Post type chips shown in idle */
.srch-idle-types {
  display: flex; align-items: center; gap: 6px;
  flex-wrap: wrap; justify-content: center;
  margin-top: 4px;
}
.srch-idle-type {
  font-size: 10px; font-weight: 600; letter-spacing: 0.07em;
  text-transform: uppercase; padding: 3px 9px;
  border-radius: 100px; border: 1px solid var(--border);
  color: var(--ink-4); background: var(--bg);
}

/* ── Char notice ─────────────────────────────────────────── */
.srch-chars-notice {
  display: none;
  padding: 36px 24px 32px;
  font-size: 13px; color: var(--ink-4);
  text-align: center;
  min-height: 180px;
  align-items: center; justify-content: center;
  border-bottom: 1px solid var(--border);
}
.srch-chars-notice.visible { display: flex; }

/* ── Results list ────────────────────────────────────────── */
.srch-results {
  display: none;
  /* flex:1 fills fixed modal height; max-height caps scrollable area */
  flex: 1;
  max-height: 300px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-md) transparent;
}
.srch-results::-webkit-scrollbar { width: 4px; }
.srch-results::-webkit-scrollbar-thumb { background: var(--border-md); border-radius: 2px; }
.srch-results.visible { display: block; }
/* Items hidden by type filter */
.srch-item.srch-hidden { display: none !important; }

/* ── Single result ───────────────────────────────────────── */
.srch-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 16px; text-decoration: none;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s; cursor: pointer;
}
.srch-item:last-child { border-bottom: none; }
.srch-item:hover,
.srch-item.srch-active { background: var(--surface); }

/* Thumbnail */
.srch-item-thumb {
  width: 44px; height: 33px; border-radius: 5px;
  overflow: hidden; background: var(--surface);
  border: 1px solid var(--border); flex: none;
  display: flex; align-items: center; justify-content: center;
}
.srch-item-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.srch-thumb-placeholder { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.srch-thumb-placeholder svg { width: 13px; height: 13px; opacity: 0.4; }

/* Text */
.srch-item-body { flex: 1; min-width: 0; }
.srch-item-top  { display: flex; align-items: center; gap: 6px; margin-bottom: 2px; }

.srch-item-type {
  font-size: 9px; font-weight: 700; letter-spacing: 0.09em;
  text-transform: uppercase; padding: 2px 6px; border-radius: 100px;
  flex: none; white-space: nowrap; line-height: 1.5;
}
/* Result badges. Every badge gets .srch-type-default + .srch-type-{slug}.
   Default is declared FIRST so a per-type colour below overrides it; a new
   CPT with no rule of its own just uses the default. Add a line to colour it. */
.srch-type-default  { background: var(--surface); color: var(--ink-4); border: 1px solid var(--border); }
.srch-type-newsletter { background: #fdecef; color: #b4234a; border-color: transparent; }
.srch-type-post     { background: #e8f0fe; color: #1558d6; border-color: transparent; }
.srch-type-projects { background: #e8f5e9; color: #177314; border-color: transparent; }
.srch-type-course   { background: #fff3e0; color: #e65100; border-color: transparent; }
.srch-type-page     { background: var(--surface); color: var(--ink-4); border: 1px solid var(--border); }

.srch-item-title {
  font-family: var(--serif); font-size: 13px; font-weight: 600;
  color: var(--ink); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; line-height: 1.3; flex: 1; min-width: 0;
}
.srch-item:hover .srch-item-title,
.srch-item.srch-active .srch-item-title { color: var(--ink-2); }

.srch-item-excerpt {
  font-size: 11.5px; color: var(--ink-4); line-height: 1.45;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.srch-item-arrow { color: var(--ink-4); flex: none; opacity: 0; transition: opacity 0.1s; }
.srch-item:hover .srch-item-arrow,
.srch-item.srch-active .srch-item-arrow { opacity: 1; }

/* ── Infinite scroll loader ──────────────────────────────── */
.srch-load-more {
  display: none; align-items: center; justify-content: center;
  gap: 8px; padding: 10px 16px; font-size: 11.5px; color: var(--ink-4);
  border-top: 1px solid var(--border);
}
.srch-load-more.visible { display: flex; }
.srch-load-spinner {
  width: 11px; height: 11px;
  border: 1.5px solid var(--border-md); border-top-color: var(--ink-4);
  border-radius: 50%; animation: srchSpin 0.6s linear infinite;
}

/* ── Empty state ─────────────────────────────────────────── */
.srch-empty {
  display: none; flex-direction: column; align-items: center;
  justify-content: center; padding: 36px 24px 32px;
  text-align: center; color: var(--ink-4); gap: 10px;
  min-height: 180px;
  border-bottom: 1px solid var(--border);
}
.srch-empty.visible { display: flex; }
.srch-empty-icon {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-4);
}
.srch-empty-title { font-family: var(--serif); font-size: 14px; font-weight: 600; color: var(--ink-3); }
.srch-empty-sub   { font-size: 12px; line-height: 1.55; max-width: 260px; }

/* ── Footer — keyboard hints + result count ──────────────── */
.srch-footer {
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  gap: 12px;
  /* Always stick to bottom of the flex-column modal */
  flex-shrink: 0;
  margin-top: auto;
}
.srch-footer-count {
  font-size: 11px; color: var(--ink-4); min-width: 0;
  /* hidden until there are results */
  opacity: 0; transition: opacity 0.15s;
}
.srch-footer-count.has-count { opacity: 1; }

.srch-footer-hints {
  display: flex; align-items: center; gap: 10px;
  margin-left: auto;
}
.srch-footer-hint-item {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 10.5px; color: var(--ink-4); white-space: nowrap;
}
.srch-kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 16px; padding: 0 3px;
  background: var(--bg); border: 1px solid var(--border-md);
  border-bottom-width: 2px; border-radius: 3px;
  font-family: var(--mono); font-size: 9px; color: var(--ink-3); line-height: 1;
}

/* ── Thumb colour palette ────────────────────────────────── */
.srch-t-green  { background: linear-gradient(135deg, #d5e8d5, #b8d8b8); }
.srch-t-amber  { background: linear-gradient(135deg, #ede8d8, #ddd0b0); }
.srch-t-purple { background: linear-gradient(135deg, #ddd8e8, #c8c0d8); }
.srch-t-teal   { background: linear-gradient(135deg, #d5e3e8, #b8d0d8); }
.srch-t-rose   { background: linear-gradient(135deg, #e8d8d8, #d8c0c0); }
.srch-t-blue   { background: linear-gradient(135deg, #d8dde8, #c0c8d8); }

.srch-type-ebook   { background: #f3e8ff; color: #7c3aed; border-color: transparent; }

/* ── Highlight matched text ──────────────────────────────── */
.srch-hl { background: rgba(21,88,214,0.11); color: var(--blue); border-radius: 2px; padding: 0 1px; }

/* ── Type filter tabs ───────────────────────────────────── */
.srch-type-tabs {
  display: none; /* JS sets display:flex when results exist */
  align-items: center;
  gap: 5px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  overflow-x: auto;
  scrollbar-width: none;
  flex-wrap: nowrap;
  flex-shrink: 0;
  min-height: 42px; /* reserve height so modal doesn't jump */
}
.srch-type-tabs.srch-tabs-visible {
  display: flex;
}
.srch-type-tabs::-webkit-scrollbar { display: none; }

.srch-tab {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 11px;
  border-radius: 100px;
  border: 1px solid var(--border);
  background: none;
  font-family: var(--sans);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-3);
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.12s;
  flex-shrink: 0;
}
.srch-tab:hover {
  border-color: var(--border-md);
  color: var(--ink);
  background: var(--surface);
}
.srch-tab-active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
.srch-tab-active:hover { background: var(--ink); color: #fff; }

.srch-tab-count {
  font-size: 10px;
  font-weight: 600;
  opacity: 0.65;
}
.srch-tab-active .srch-tab-count { opacity: 0.8; }

/* ── Mobile ──────────────────────────────────────────────── */
@media (max-width: 640px) {
  #srchOverlay { padding: 0; align-items: flex-end; }
  .srch-modal  { border-radius: var(--r-lg) var(--r-lg) 0 0; max-width: 100%; }
  .srch-results { max-height: 45vh; }
  .srch-idle, .srch-empty { min-height: 140px; padding: 24px 20px; }
  .srch-footer-hints { gap: 7px; }
}

/* ── Close button (× top-right of input row) ─────────────── */
.srch-close-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border-md);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--ink-3);
  flex: none;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  padding: 0;
}
.srch-close-btn:hover {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

/* ── Modal size increase (slight) ─────────────────────── */
.srch-modal {
  max-width: 720px;   /* was ~580px — bump up modestly */
  width: 92vw;
}

/* Infinite-scroll trigger at the end of the results list */
.srch-sentinel { height: 1px; }
