/* ============================================
   PREOWNED PROPERTIES — SEARCH PAGE
   ============================================ */

body.search-page {
  background: var(--surface);
}

body.search-page .site-main {
  min-height: 100vh;
  padding-top: var(--nav-height);
}

body.search-page .glass-nav.scrolled .nav-link {
  color: var(--text) !important;
}

body.search-page .glass-nav .nav-link.active {
  color: var(--accent) !important;
}

body.search-page .glass-nav .nav-link.active::after {
  width: calc(100% - 32px);
}

@media (max-width: 991.98px) {
  body.search-page {
    padding-bottom: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom));
  }

  body.search-page .site-footer {
    padding-bottom: calc(24px + var(--mobile-nav-height) + env(safe-area-inset-bottom));
  }

  body.search-page .back-to-top {
    bottom: calc(var(--mobile-nav-height) + 16px + env(safe-area-inset-bottom));
  }
}

/* --------------------------------------------
   SEARCH BAR (below navbar)
   -------------------------------------------- */
.search-bar-section {
  position: relative;
  z-index: 1030;
  background: linear-gradient(135deg, #090059 0%, #1a0a8a 55%, #12006e 100%);
  border-bottom: 1px solid rgba(234, 187, 115, 0.15);
  box-shadow: 0 8px 32px rgba(9, 0, 89, 0.18);
  padding: 20px 0;
}

.search-bar-section .container {
  max-width: 1400px;
}

.search-box--toolbar {
  max-width: none;
  margin: 0;
}

.search-box--toolbar .search-form {
  align-items: stretch;
}

.search-box--toolbar .search-field--location {
  flex: 1.35;
  min-width: 160px;
}

.search-box--toolbar .search-field--type,
.search-box--toolbar .search-field--budget {
  flex: 1;
  min-width: 140px;
}

.search-box--toolbar .search-field--beds {
  flex: 0.95;
  min-width: 130px;
}

.search-box--toolbar .search-filters-btn {
  border-color: rgba(255, 255, 255, 0.35);
  color: #fff;
  background: rgba(255, 255, 255, 0.06);
  padding: 14px 22px;
  font-weight: 600;
  white-space: nowrap;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.search-box--toolbar .search-filters-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--accent);
  color: #fff;
}

.search-box--toolbar .search-filters-btn.is-active {
  background: rgba(234, 187, 115, 0.18);
  border-color: var(--accent);
  color: #fff;
}

.search-filters-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 50px;
  background: var(--accent);
  color: var(--primary);
  font-size: 0.7rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* Filter drawer fields */
.search-toolbar-field {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-toolbar-field:focus-within,
.search-toolbar-field:has(.select2-container--open),
.search-toolbar-field:has(.select2-container--focus) {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.15);
}

.search-toolbar-field label {
  color: var(--accent);
  margin-right: 8px;
  margin-bottom: 0;
  flex-shrink: 0;
}

.search-toolbar-field label i {
  font-size: 0.95rem;
}

.search-toolbar-field input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 11px 0;
  font-size: 0.9rem;
  outline: none;
}

.search-toolbar-field input::placeholder {
  color: var(--muted);
}

.search-toolbar-field .select2-container {
  flex: 1;
  min-width: 0;
}

.search-toolbar-field .select2-container--default .select2-selection--single {
  background: transparent;
  border: none;
  height: auto;
  min-height: 42px;
  display: flex;
  align-items: center;
}

.search-toolbar-field .select2-container--default .select2-selection--single .select2-selection__rendered {
  padding: 11px 24px 11px 0;
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.4;
}

.search-toolbar-field .select2-container--default .select2-selection--single .select2-selection__placeholder {
  color: var(--muted);
}

.search-toolbar-field .select2-container--default .select2-selection--single .select2-selection__arrow {
  height: 100%;
  right: 0;
}

.search-toolbar-field .select2-container--default .select2-selection--single .select2-selection__arrow b {
  border-color: var(--muted) transparent transparent transparent;
}

.search-toolbar-field .select2-container--default.select2-container--open .select2-selection--single .select2-selection__arrow b {
  border-color: transparent transparent var(--muted) transparent;
}

/* --------------------------------------------
   FILTER DRAWER (slides from right)
   -------------------------------------------- */
.search-filter-overlay {
  position: fixed;
  inset: 0;
  z-index: 1055;
  background: rgba(9, 0, 89, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.35s ease, visibility 0.35s ease;
}

.search-filter-overlay.is-open {
  opacity: 1;
  visibility: visible;
}

.search-filter-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: auto;
  z-index: 1060;
  width: min(400px, 92vw);
  max-width: 100%;
  background: var(--background);
  border-left: 1px solid var(--border);
  box-shadow: -20px 0 60px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.4s;
}

.search-filter-drawer.is-open {
  transform: translateX(0);
  visibility: visible;
}

.search-filter-drawer .select2-container--open {
  z-index: 1070;
}

.search-filter-drawer .select2-dropdown {
  z-index: 1070;
}

.search-filter-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.search-filter-drawer-header h2 {
  font-family: var(--font-body);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.search-filter-drawer-close {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
}

.search-filter-drawer-close:hover {
  background: rgba(var(--accent-rgb), 0.15);
  color: var(--primary);
}

.search-filter-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  -webkit-overflow-scrolling: touch;
}

.search-filter-drawer-field > label:not(.search-check-label) {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.search-filter-drawer-field .search-toolbar-field,
.search-filter-drawer-field .search-toggle {
  width: 100%;
}

#filterListingToggle.search-toggle {
  margin-bottom: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 3px;
  gap: 0;
  width: 100%;
}

#filterListingToggle.search-toggle .search-toggle-btn {
  color: var(--muted);
  flex: 1 1 50%;
  width: 50%;
  text-align: center;
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

#filterListingToggle.search-toggle .search-toggle-btn.active {
  background: var(--primary);
  color: #fff;
}

#filterListingToggle.search-toggle .search-toggle-btn:hover:not(.active) {
  color: var(--text);
}

.search-filter-drawer-footer {
  display: flex;
  gap: 12px;
  padding: 20px 24px calc(20px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--background);
  flex-shrink: 0;
}

.search-filter-cancel-btn,
.search-filter-apply-btn {
  flex: 1;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.95rem;
}

body.search-filter-open {
  overflow: hidden;
}

.search-check-label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--text);
  margin: 0;
  user-select: none;
}

.search-check-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.search-check-box {
  width: 20px;
  height: 20px;
  border-radius: 5px;
  border: 2px solid var(--border);
  background: var(--background);
  flex-shrink: 0;
  position: relative;
  transition: all var(--transition);
}

.search-check-input:checked + .search-check-box {
  background: var(--primary);
  border-color: var(--primary);
}

.search-check-input:checked + .search-check-box::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 2px;
  width: 6px;
  height: 10px;
  border: solid var(--accent);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.search-check-input:focus-visible + .search-check-box {
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.25);
}

/* Select2 dropdown */
.select2-dropdown.search-page-select2-dropdown {
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 1060;
  padding: 6px 0;
  font-family: var(--font-body);
}

.search-page-select2-dropdown .select2-results__option {
  padding: 10px 14px;
  color: var(--text);
  font-size: 0.9rem;
}

.search-page-select2-dropdown .select2-results__option--highlighted.select2-results__option--selectable {
  background: rgba(var(--accent-rgb), 0.12);
  color: var(--primary);
}

.search-page-select2-dropdown .select2-results__option--selected {
  background: rgba(var(--primary-rgb), 0.06);
  color: var(--primary);
}

.search-page-select2-dropdown .select2-search--dropdown {
  padding: 8px 12px 4px;
}

.search-page-select2-dropdown .select2-search--dropdown .select2-search__field {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.9rem;
  outline: none;
  box-sizing: border-box;
}

.search-page-select2-dropdown .select2-search--dropdown .select2-search__field:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.12);
}

.search-page-select2-dropdown .select2-search--dropdown .select2-search__field::placeholder {
  color: var(--muted);
}

/* --------------------------------------------
   RESULTS META BAR
   -------------------------------------------- */
.search-results-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 20px 20px 0;
  max-width: 1400px;
  margin: 0 auto;
}

.search-results-count {
  font-size: 0.95rem;
  color: var(--text);
  margin: 0;
}

.search-results-count strong {
  color: var(--primary);
  font-weight: 700;
}

.search-results-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.search-sort-label {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0;
  white-space: nowrap;
}

.search-sort-select {
  min-width: 180px;
  padding: 8px 36px 8px 14px;
  font-size: 0.88rem;
  font-family: var(--font-body);
  color: var(--text);
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%236b7280'%3e%3cpath fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 12px;
  transition: border-color var(--transition);
}

.search-sort-select:focus {
  outline: none;
  border-color: var(--accent);
}

.search-clear-filters {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  background: none;
  border: none;
  padding: 8px 12px;
  cursor: pointer;
  transition: color var(--transition);
  display: none;
}

.search-clear-filters.is-visible {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.search-clear-filters:hover {
  color: var(--primary);
}

/* --------------------------------------------
   RESULTS GRID
   -------------------------------------------- */
.search-results-section {
  padding: 24px 20px 60px;
  max-width: 1400px;
  margin: 0 auto;
}

.search-results-grid {
  transition: opacity 0.25s ease;
}

.search-results-grid.is-loading {
  opacity: 0.5;
  pointer-events: none;
}

.search-no-results {
  text-align: center;
  padding: 80px 24px;
  background: var(--background);
  border-radius: var(--radius-lg);
  border: 1px dashed var(--border);
}

.search-no-results-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  font-size: 1.75rem;
  color: var(--muted);
}

.search-no-results h2 {
  font-family: var(--font-body);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.search-no-results p {
  color: var(--muted);
  margin-bottom: 24px;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}

/* --------------------------------------------
   RESPONSIVE
   -------------------------------------------- */
@media (max-width: 991.98px) {
  .search-bar-section {
    padding: 16px 0;
  }

  .search-box--toolbar .search-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .search-box--toolbar .search-toggle {
    grid-column: 1 / -1;
  }

  .search-box--toolbar .search-field--location,
  .search-box--toolbar .search-field--type,
  .search-box--toolbar .search-field--budget,
  .search-box--toolbar .search-field--beds {
    grid-column: 1 / -1;
    min-width: 0;
  }

  .search-box--toolbar .btn-search,
  .search-box--toolbar .search-filters-btn {
    justify-content: center;
  }

  .search-results-bar {
    padding: 16px 16px 0;
  }

  .search-results-section {
    padding: 20px 16px 40px;
  }
}

@media (max-width: 575.98px) {
  .search-bar-section {
    padding: 12px 0;
  }

  .search-box--toolbar {
    padding: 18px;
  }

  .search-box--toolbar .search-form {
    grid-template-columns: 1fr 1fr;
  }

  .search-box--toolbar .search-toggle {
    width: 100%;
    justify-content: center;
  }

  .search-box--toolbar .search-filters-btn span:not(.search-filters-badge) {
    display: none;
  }

  .search-results-actions {
    width: 100%;
    justify-content: space-between;
  }

  .search-sort-select {
    flex: 1;
    min-width: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .search-filter-drawer {
    transition-duration: 0.01ms;
  }
}
