/* ============================================================
   ПОИСК — бесшовная интеграция в шапку
   ============================================================ */

/* ---------- Обёртка поиска в навигации -------------------- */
.nav-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

/* Кнопка-иконка (по умолчанию) */
.search-trigger {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.4rem 0.5rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  font-family: inherit;
  transition: color 0.2s ease, background 0.2s ease;
  white-space: nowrap;
  line-height: 1;
}

.search-trigger:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.search-trigger svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.search-trigger:hover svg {
  transform: scale(1.1);
}

.search-trigger-label {
  font-size: 0.875rem;
}

.search-shortcut {
  font-size: 0.7rem;
  opacity: 0.55;
  padding: 0.1rem 0.35rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  font-family: system-ui, sans-serif;
  letter-spacing: 0.02em;
}

/* ---------- Модальное окно поиска ------------------------- */
.search-modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 20, 0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 9000;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 8vh 1rem 1rem;
}

.search-modal.active {
  display: flex;
  animation: search-modal-in 0.2s ease;
}

@keyframes search-modal-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

/* ---------- Контейнер поиска ------------------------------ */
.search-container {
  width: 100%;
  max-width: 660px;
  background: rgba(18, 27, 56, 0.98);
  border: 1px solid rgba(102, 126, 234, 0.35);
  border-radius: 20px;
  box-shadow:
    0 24px 80px rgba(0, 0, 0, 0.65),
    0 0 0 1px rgba(102, 126, 234, 0.1) inset;
  display: flex;
  flex-direction: column;
  max-height: 78vh;
  animation: search-container-in 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
}

@keyframes search-container-in {
  from {
    opacity: 0;
    transform: translateY(-18px) scale(0.97);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ---------- Поле ввода ------------------------------------ */
.search-input-wrapper {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid rgba(102, 126, 234, 0.15);
}

.search-icon {
  color: #667eea;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.search-icon svg {
  width: 22px;
  height: 22px;
}

.search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: 1.05rem;
  color: #e0e7ff;
  font-family: inherit;
  caret-color: #667eea;
}

.search-input::placeholder {
  color: rgba(160, 174, 192, 0.6);
}

/* Индикатор загрузки рядом с полем */
.search-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(102, 126, 234, 0.2);
  border-top-color: #667eea;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: none;
  flex-shrink: 0;
}

.search-spinner.visible {
  display: block;
}

.search-close {
  background: transparent;
  border: none;
  color: rgba(160, 174, 192, 0.7);
  cursor: pointer;
  padding: 0.35rem;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.search-close:hover {
  background: rgba(239, 68, 68, 0.12);
  color: #ef4444;
}

.search-close svg {
  width: 18px;
  height: 18px;
}

/* ---------- Фильтры --------------------------------------- */
.search-filters {
  display: flex;
  gap: 0.4rem;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid rgba(102, 126, 234, 0.12);
  overflow-x: auto;
  scrollbar-width: none;
}

.search-filters::-webkit-scrollbar {
  display: none;
}

.search-filter-btn {
  padding: 0.3rem 0.8rem;
  background: transparent;
  border: 1px solid rgba(102, 126, 234, 0.2);
  border-radius: 20px;
  color: rgba(160, 174, 192, 0.8);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  font-family: inherit;
}

.search-filter-btn:hover {
  background: rgba(102, 126, 234, 0.12);
  border-color: rgba(102, 126, 234, 0.4);
  color: #c7d2fe;
}

.search-filter-btn.active {
  background: rgba(102, 126, 234, 0.25);
  border-color: #667eea;
  color: #c7d2fe;
}

/* ---------- Результаты ------------------------------------ */
.search-results {
  overflow-y: auto;
  flex: 1;
  padding: 0.5rem;
}

.search-results::-webkit-scrollbar {
  width: 6px;
}

.search-results::-webkit-scrollbar-track {
  background: transparent;
}

.search-results::-webkit-scrollbar-thumb {
  background: rgba(102, 126, 234, 0.2);
  border-radius: 3px;
}

.search-results::-webkit-scrollbar-thumb:hover {
  background: rgba(102, 126, 234, 0.4);
}

/* ---------- Пустое состояние ------------------------------ */
.search-empty {
  padding: 2.5rem 2rem;
  text-align: center;
  color: rgba(160, 174, 192, 0.7);
}

.search-empty-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
  display: block;
  opacity: 0.7;
}

.search-empty-text {
  font-size: 1rem;
  font-weight: 500;
  color: rgba(224, 231, 255, 0.7);
  margin-bottom: 0.4rem;
}

.search-empty-hint {
  font-size: 0.875rem;
  opacity: 0.65;
}

/* ---------- Карточка результата --------------------------- */
.search-result-item {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.875rem 1rem;
  border-radius: 12px;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
  border: 1px solid transparent;
  margin-bottom: 2px;
}

.search-result-item:hover,
.search-result-item.selected {
  background: rgba(102, 126, 234, 0.12);
  border-color: rgba(102, 126, 234, 0.25);
  transform: translateX(3px);
}

.search-result-item:active {
  transform: translateX(1px);
}

.search-result-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.search-result-icon.page {
  background: rgba(102, 126, 234, 0.18);
  color: #818cf8;
}

.search-result-icon.material {
  background: rgba(74, 196, 145, 0.18);
  color: #6bc491;
}

.search-result-icon.crossword {
  background: rgba(240, 147, 251, 0.18);
  color: #c084fc;
}

.search-result-icon svg {
  width: 18px;
  height: 18px;
}

.search-result-content {
  flex: 1;
  min-width: 0;
}

.search-result-title {
  font-size: 0.975rem;
  font-weight: 600;
  color: #e0e7ff;
  margin-bottom: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-badge {
  font-size: 0.72rem;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  background: rgba(102, 126, 234, 0.12);
  color: #818cf8;
  font-weight: 500;
  display: inline-block;
  margin-bottom: 0.3rem;
}

.search-result-description {
  font-size: 0.82rem;
  color: rgba(160, 174, 192, 0.75);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-result-arrow {
  color: rgba(160, 174, 192, 0.4);
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease;
  flex-shrink: 0;
}

.search-result-item:hover .search-result-arrow,
.search-result-item.selected .search-result-arrow {
  opacity: 1;
  color: #667eea;
}

.search-result-arrow svg {
  width: 16px;
  height: 16px;
}

/* ---------- Подсветка совпадений -------------------------- */
.search-highlight {
  background: rgba(240, 147, 251, 0.25);
  color: #f0abfc;
  font-weight: 700;
  padding: 0 1px;
  border-radius: 2px;
}

/* ---------- Подсказки в подвале --------------------------- */
.search-footer {
  padding: 0.875rem 1.5rem;
  border-top: 1px solid rgba(102, 126, 234, 0.12);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.search-hints {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.search-hint {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: rgba(160, 174, 192, 0.55);
}

.search-hint-key {
  padding: 0.1rem 0.35rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
}

.search-powered {
  font-size: 0.72rem;
  color: rgba(160, 174, 192, 0.35);
}

/* ---------- Анимации -------------------------------------- */
@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

/* ---------- Адаптивность ---------------------------------- */
@media (max-width: 768px) {
  .search-modal {
    padding: 4vh 0.5rem 0.5rem;
    align-items: flex-start;
  }

  .search-container {
    border-radius: 16px;
    max-height: 88vh;
  }

  .search-input-wrapper {
    padding: 1rem 1.25rem;
  }

  .search-filters {
    padding: 0.6rem 1.25rem;
  }

  .search-footer {
    display: none;
  }

  .search-result-item {
    padding: 0.75rem;
  }

  .search-result-title {
    font-size: 0.9rem;
  }

  .search-shortcut {
    display: none;
  }

  .search-trigger-label {
    display: none;
  }
}

@media (max-width: 480px) {
  .search-modal {
    padding: 3vh 0 0;
  }

  .search-container {
    border-radius: 16px 16px 0 0;
    max-height: 92vh;
  }
}