/* search.css — Cross-chapter search widget for the digital Geometria book.
 *
 * Independent from style.css so we can ship/iterate without touching the
 * book's main stylesheet. Variables mirror style.css to stay consistent.
 */

:root {
  --search-bg:       #ffffff;
  --search-fg:       #1a1a1a;
  --search-muted:    #5f6c7b;
  --search-accent:   #1f4b8e;
  --search-border:   #d6dde7;
  --search-shadow:   0 12px 40px rgba(15, 35, 70, 0.18);
  --search-hl:       #ffe98a;
}

/* -----------------------------------------------------------------------
 * Search bar — floating top-right pill.
 *
 * On wide layouts this floats above the page. On narrow screens (<720px)
 * it spans the top edge to remain reachable.
 * --------------------------------------------------------------------- */
.search-widget {
  position: fixed;
  top: 18px;
  right: 24px;
  z-index: 1100;
  width: 320px;
  max-width: calc(100vw - 36px);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.search-widget input[type="search"] {
  width: 100%;
  box-sizing: border-box;
  padding: 9px 14px 9px 36px;
  border-radius: 999px;
  border: 1px solid var(--search-border);
  background: var(--search-bg) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235f6c7b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='7'/><line x1='21' y1='21' x2='16.65' y2='16.65'/></svg>") no-repeat 11px center;
  background-size: 16px 16px;
  color: var(--search-fg);
  box-shadow: 0 2px 8px rgba(15, 35, 70, 0.08);
  outline: none;
  transition: box-shadow .15s ease, border-color .15s ease;
}

.search-widget input[type="search"]::placeholder {
  color: var(--search-muted);
}

.search-widget input[type="search"]:focus {
  border-color: var(--search-accent);
  box-shadow: 0 0 0 3px rgba(31, 75, 142, 0.18);
}

/* The little kbd hint shown on the right of the pill */
.search-widget .kbd-hint {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--search-muted);
  background: #f3f5f9;
  border: 1px solid var(--search-border);
  border-radius: 4px;
  padding: 1px 6px;
  pointer-events: none;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.search-widget input[type="search"]:focus + .kbd-hint,
.search-widget input[type="search"]:not(:placeholder-shown) + .kbd-hint {
  display: none;
}

/* -----------------------------------------------------------------------
 * Results dropdown
 * --------------------------------------------------------------------- */
#search-results {
  margin-top: 6px;
  max-height: 70vh;
  overflow-y: auto;
  background: var(--search-bg);
  border: 1px solid var(--search-border);
  border-radius: 12px;
  box-shadow: var(--search-shadow);
  padding: 6px;
}

#search-results[hidden] { display: none; }

.search-empty {
  padding: 18px 14px;
  color: var(--search-muted);
  text-align: center;
  font-size: 13px;
}

.search-meta {
  padding: 6px 12px 8px;
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--search-muted);
  border-bottom: 1px solid var(--search-border);
}

.search-result {
  display: block;
  padding: 9px 12px;
  border-radius: 8px;
  color: inherit;
  text-decoration: none;
  border: 1px solid transparent;
}

.search-result + .search-result {
  margin-top: 2px;
}

.search-result:hover,
.search-result.is-active {
  background: #f1f5fb;
  border-color: #e1ebf7;
}

.search-result .res-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 3px;
}

.search-result .res-badge {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 1px 7px;
  border-radius: 999px;
  background: #eef2f8;
  color: var(--search-accent);
}

.search-result .res-badge[data-type="exercise"]  { background: #fff1d6; color: #9a6500; }
.search-result .res-badge[data-type="theorem"]   { background: #e3f1e3; color: #1f6f3a; }
.search-result .res-badge[data-type="glossary"]  { background: #f3e8ff; color: #6024a8; }
.search-result .res-badge[data-type="section"]   { background: #eef2f8; color: var(--search-accent); }

.search-result .res-title {
  font-weight: 600;
  color: var(--search-fg);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-result .res-chip {
  font-size: 11px;
  color: var(--search-muted);
  white-space: nowrap;
}

.search-result .res-snippet {
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--search-muted);
  margin: 0;
  /* Clamp to 2 lines on supported browsers */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.search-result mark {
  background: var(--search-hl);
  color: inherit;
  padding: 0 1px;
  border-radius: 2px;
}

/* -----------------------------------------------------------------------
 * Responsive — on mobile span the top edge and let results take the
 * width of the viewport.
 * --------------------------------------------------------------------- */
@media (max-width: 720px) {
  .search-widget {
    top: 8px;
    right: 8px;
    left: 8px;
    width: auto;
    max-width: none;
  }
  #search-results { max-height: 65vh; }
}

/* Sidebar layout — when the host page has an .app/.sidebar layout, the
 * floating widget overlaps the sidebar on very wide screens; nudge it
 * slightly toward the main column.
 */
@media (min-width: 1280px) {
  .search-widget { right: 32px; }
}

/* The bare cover page (index.html) doesn't have a sidebar; center the
 * widget below the title so it isn't lost in the corner. */
body.cover-host .search-widget {
  position: static;
  margin: 24px auto 32px;
  width: min(520px, 100%);
}
