/* ===========================================
   NEW MAP - SEARCH PANEL
   ----------------------------------------------------------------
   Panel anchored under the magnifying-glass button (#nm-search-btn).
   Contains:
     - input row (search icon + text input + clear button)
     - results area (idle / loading / no-results / error / rows)

   Result rows are "rich":
     [thumb]  Title (truncated)
              Location . Topic

   Sizing rules (the only place numbers live):
     panel width    clamp(300px, 90vw, 400px)
     panel max-h    min(80vh, clamp(380px, 70vmin, 600px))
     row thumb      44px square
     up to 8 rows visible; vertical scroll if more

   All scoped under #new-map-section to prevent leaks.
   =========================================== */

/* ========== Panel shell ========== */
#new-map-section .nm-search-panel {
  position: absolute;
  top: 72px;     /* under the 44px search button (top: 20px) + small gap */
  left: 24px;
  z-index: 50;
  width: clamp(300px, 90vw, 400px);
  max-height: min(80vh, clamp(380px, 70vmin, 600px));
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
  font-family: 'Helvetica', 'Arial', sans-serif;
  color: #222;
  display: flex;
  flex-direction: column;
  overflow: hidden;       /* clip rounded corners */
  box-sizing: border-box;
}
#new-map-section .nm-search-panel[hidden] {
  display: none;
}

/* ========== Input row ========== */
#new-map-section .nm-search-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid #f0f0f0;
  flex-shrink: 0;
}

#new-map-section .nm-search-input-icon {
  color: #888;
  flex-shrink: 0;
}

#new-map-section .nm-search-input {
  flex: 1 1 auto;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font: inherit;
  font-size: 0.95rem;
  color: #222;
  padding: 4px 0;
  /* Hide native <input type="search"> clear button - we have our own */
  -webkit-appearance: none;
  appearance: none;
}
#new-map-section .nm-search-input::-webkit-search-cancel-button { display: none; }
#new-map-section .nm-search-input::placeholder { color: #aaa; }

#new-map-section .nm-search-clear {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border: none;
  background: #ececec;
  color: #555;
  border-radius: 50%;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}
#new-map-section .nm-search-clear:hover {
  background: #d6d6d6;
  color: #222;
}
#new-map-section .nm-search-clear[hidden] { display: none; }

/* ========== Results area ========== */
#new-map-section .nm-search-results {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 0;
}

/* Subtle scrollbar */
#new-map-section .nm-search-results::-webkit-scrollbar { width: 6px; }
#new-map-section .nm-search-results::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.18);
  border-radius: 3px;
}
#new-map-section .nm-search-results::-webkit-scrollbar-track { background: transparent; }

/* ----- States: idle / loading / no-results / error ----- */
#new-map-section .nm-search-state {
  margin: 0;
  padding: 18px 16px;
  text-align: center;
  font-size: 0.88rem;
  color: #888;
  font-style: italic;
}
#new-map-section .nm-search-state--error { color: #c62828; font-style: normal; }

/* ----- Result row ----- */
#new-map-section .nm-search-result {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  transition: background 0.12s ease;
  border-bottom: 1px solid #f7f7f7;
}
#new-map-section .nm-search-result:last-child { border-bottom: none; }
#new-map-section .nm-search-result:hover  { background: #f5f9ff; }
#new-map-section .nm-search-result:active { background: #ebf2fa; }
#new-map-section .nm-search-result:focus  { outline: none; background: #f0f6ff; }

#new-map-section .nm-search-result__thumb {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  object-fit: cover;
  background: #ececec;
  flex-shrink: 0;
}

#new-map-section .nm-search-result__body {
  flex: 1 1 auto;
  min-width: 0;
}

#new-map-section .nm-search-result__title {
  margin: 0 0 2px;
  font-weight: 600;
  font-size: 0.92rem;
  color: #222;
  /* Single-line ellipsis */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#new-map-section .nm-search-result__meta {
  margin: 0;
  font-size: 0.78rem;
  color: #777;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#new-map-section .nm-search-result__meta-sep {
  color: #ccc;
}

/* Tiny topic chip in meta line */
#new-map-section .nm-search-result__topic {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
#new-map-section .nm-search-result__topic-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ========== Tiny screens: smaller search button + panel anchor ========== */
@media (max-width: 500px) {
  #new-map-section .nm-search-panel {
    top: 62px;
    left: 20px;
    /* Cap to leave breathing room from the right edge of viewport */
    width: min(calc(100vw - 40px), 360px);
  }
}
