/* ============================================================
   BHSearchBar.css
   Barra de búsqueda omnisearch — Biblioteca Humana
   Coherente con series.css: fondo oscuro, acento #9174b3
   ============================================================ */

/* ── Wrapper principal ─────────────────────────────────────── */
.bh-search-wrapper {
  position: relative;
  width: 100%;
  max-width: 480px;
  /* Se puede reducir en el header según el layout */
}

/* ── Contenedor del input ──────────────────────────────────── */
.bh-search-input-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background-color: rgba(255, 255, 255, 0.07);
  border: 1.5px solid #495057;
  border-radius: 10px;
  padding: 0.5rem 0.75rem;
  transition: border-color 0.25s ease, background-color 0.25s ease,
              box-shadow 0.25s ease;
}

.bh-search-input-container:focus-within,
.bh-search-input-container--open {
  border-color: #9174b3;
  background-color: rgba(145, 116, 179, 0.08);
  box-shadow: 0 0 0 3px rgba(145, 116, 179, 0.18);
  border-radius: 10px 10px 0 0; /* se "une" al dropdown */
}

/* Cuando el dropdown está abierto, solo redondear arriba */
.bh-search-input-container--open {
  border-bottom-color: transparent;
}

/* ── Ícono lupa ────────────────────────────────────────────── */
.bh-search-icon {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
  color: #9174b3;
  transition: color 0.2s ease;
}

.bh-search-input-container:focus-within .bh-search-icon {
  color: #b19bca;
}

/* ── Input de texto ────────────────────────────────────────── */
.bh-search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #f1f1f1;
  font-size: 0.9rem;
  font-family: 'Montserrat', sans-serif;
  caret-color: #b19bca;
  min-width: 0; /* evita overflow en flex */
}

.bh-search-input::placeholder {
  color: #6c757d;
  font-style: italic;
  font-size: 0.85rem;
}

/* Quitar el botón "x" nativo de type="search" en Chrome */
.bh-search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

/* ── Spinner de indexado ───────────────────────────────────── */
.bh-search-indexing-indicator {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  color: #6c757d;
  cursor: default;
}

.bh-search-spinner {
  width: 14px;
  height: 14px;
  animation: bh-spin 1.2s linear infinite;
}

@keyframes bh-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* ── Botón limpiar ─────────────────────────────────────────── */
.bh-search-clear-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  padding: 2px;
  cursor: pointer;
  color: #6c757d;
  border-radius: 4px;
  flex-shrink: 0;
  transition: color 0.2s ease, background-color 0.2s ease;
}

.bh-search-clear-btn:hover {
  color: #f1f1f1;
  background-color: rgba(255, 255, 255, 0.1);
}

.bh-search-clear-btn svg {
  width: 14px;
  height: 14px;
}

/* ── Dropdown ──────────────────────────────────────────────── */
.bh-search-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 1050;
  background-color: #1e1e2e;
  border: 1.5px solid #9174b3;
  border-top: none;
  border-radius: 0 0 10px 10px;
  overflow: hidden;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  animation: bh-dropdown-in 0.18s ease-out;
  max-height: 70vh;
  overflow-y: auto;
}

@keyframes bh-dropdown-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Scrollbar personalizado para el dropdown */
.bh-search-dropdown::-webkit-scrollbar {
  width: 5px;
}
.bh-search-dropdown::-webkit-scrollbar-track {
  background: #1e1e2e;
}
.bh-search-dropdown::-webkit-scrollbar-thumb {
  background: #495057;
  border-radius: 3px;
}
.bh-search-dropdown::-webkit-scrollbar-thumb:hover {
  background: #9174b3;
}

/* ── Grupo de resultados ───────────────────────────────────── */
.bh-search-group {
  padding: 0.5rem 0;
}

.bh-search-group + .bh-search-group {
  border-top: 1px solid rgba(73, 80, 87, 0.5);
}

.bh-search-group-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #9174b3;
  padding: 0.4rem 1rem 0.3rem;
  margin: 0;
}

/* ── Ítem de resultado ─────────────────────────────────────── */
.bh-search-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  text-decoration: none;
  color: #dee2e6;
  transition: background-color 0.15s ease;
  cursor: pointer;
  outline: none;
}

.bh-search-item:hover,
.bh-search-item:focus {
  background-color: rgba(145, 116, 179, 0.15);
  text-decoration: none;
  color: #f1f1f1;
}

.bh-search-item:hover .bh-search-item-arrow,
.bh-search-item:focus .bh-search-item-arrow {
  opacity: 1;
  transform: translateX(3px);
}

/* ── Thumbnail del ítem ────────────────────────────────────── */
.bh-search-item-thumb {
  flex-shrink: 0;
  width: 44px;
  height: 60px;
  border-radius: 5px;
  overflow: hidden;
  background-color: #2a2a3e;
  border: 1px solid #495057;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bh-search-item-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.bh-search-item-thumb-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: #6c757d;
}

.bh-search-item-thumb-placeholder svg {
  width: 20px;
  height: 20px;
}

/* Thumbnail para capítulos: cuadrado con ícono play */
.bh-search-item-thumb--chapter {
  height: 44px;
  background: linear-gradient(135deg, #2a2a3e 0%, #1e1e2e 100%);
  border-color: rgba(145, 116, 179, 0.3);
}

.bh-search-item-thumb--chapter svg {
  width: 18px;
  height: 18px;
  color: #9174b3;
}

/* ── Info del ítem ─────────────────────────────────────────── */
.bh-search-item-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding-top: 0.1rem;
}

.bh-search-item-title {
  font-size: 0.875rem;
  font-weight: 500;
  color: #f1f1f1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.bh-search-item-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.bh-search-item-year {
  font-size: 0.75rem;
  color: #6c757d;
}

.bh-search-item-desc {
  font-size: 0.75rem;
  color: #adb5bd;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bh-search-item-parent {
  font-size: 0.72rem;
  color: #9174b3;
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Flecha ────────────────────────────────────────────────── */
.bh-search-item-arrow {
  flex-shrink: 0;
  font-size: 1.2rem;
  color: #495057;
  opacity: 0;
  transition: opacity 0.15s ease, transform 0.15s ease;
  line-height: 1;
  align-self: center;
}

/* ── Badges de tipo ────────────────────────────────────────── */
.bh-search-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  line-height: 1.4;
}

.bh-search-badge--libro {
  background-color: rgba(145, 116, 179, 0.2);
  color: #b19bca;
  border: 1px solid rgba(145, 116, 179, 0.35);
}

.bh-search-badge--serie {
  background-color: rgba(23, 209, 252, 0.12);
  color: #17d1fc;
  border: 1px solid rgba(23, 209, 252, 0.25);
}

.bh-search-badge--chapter {
  background-color: rgba(255, 255, 255, 0.07);
  color: #adb5bd;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* ── Texto resaltado ───────────────────────────────────────── */
.bh-search-highlight {
  background-color: rgba(177, 155, 202, 0.3);
  color: #f1f1f1;
  border-radius: 2px;
  padding: 0 1px;
  font-weight: 600;
}

/* ── Estado vacío ──────────────────────────────────────────── */
.bh-search-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 2rem 1.5rem;
  color: #6c757d;
  text-align: center;
}

.bh-search-empty svg {
  width: 32px;
  height: 32px;
  opacity: 0.4;
  margin-bottom: 0.25rem;
}

.bh-search-empty p {
  font-size: 0.9rem;
  color: #adb5bd;
  margin: 0;
}

.bh-search-empty strong {
  color: #dee2e6;
}

.bh-search-empty span {
  font-size: 0.78rem;
  color: #6c757d;
  font-style: italic;
}

/* ── Pie del dropdown ──────────────────────────────────────── */
.bh-search-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  border-top: 1px solid rgba(73, 80, 87, 0.5);
  font-size: 0.72rem;
  color: #6c757d;
  background-color: rgba(0, 0, 0, 0.2);
}

.bh-search-footer-indexing {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: #9174b3;
  font-style: italic;
}

.bh-search-footer-indexing .bh-search-spinner {
  width: 11px;
  height: 11px;
}

/* ── Integración en el header ──────────────────────────────── */
/*
   En Header.js, envuelve <BHSearchBar /> con:
   <div className="bh-search-in-header"> ... </div>
   para controlarlo desde el navbar.
*/
.bh-search-in-header {
  flex: 1;
  max-width: 420px;
  margin: 0 1.5rem;
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 991px) {
  .bh-search-in-header {
    max-width: 300px;
    margin: 0 0.75rem;
  }
}

@media (max-width: 767px) {
  .bh-search-in-header {
    max-width: 100%;
    margin: 0.5rem 0;
    width: 100%;
    order: 3; /* mueve la barra debajo de los logos en móvil */
  }

  .bh-search-wrapper {
    max-width: 100%;
  }

  .bh-search-dropdown {
    max-height: 55vh;
  }

  .bh-search-item-thumb {
    width: 38px;
    height: 52px;
  }

  .bh-search-item-thumb--chapter {
    height: 38px;
  }

  .bh-search-item {
    padding: 0.5rem 0.75rem;
  }
}

@media (max-width: 480px) {
  .bh-search-item-desc {
    display: none;
  }

  .bh-search-footer {
    flex-direction: column;
    gap: 0.25rem;
    text-align: center;
  }
}