/* K12 Search Grid - LoveForm-Style Layout System */
/* Matches LoveForm's responsive grid exactly */

.search-results-container {
  padding: 23px 0 0 0; /* 23px top only - map extends to viewport bottom like LoveForm */
}

.results-grid {
  display: grid;
  gap: var(--space-6);
  
  /* LoveForm's responsive grid system */
  grid-template-columns: repeat(1, 1fr);
  
  /* Small devices (576px and up) */
  @media (min-width: 576px) {
    grid-template-columns: repeat(1, 1fr);
    gap: var(--space-5);
  }
  
  /* Medium devices (768px and up) */
  @media (min-width: 768px) {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-6);
  }
  
  /* Large devices (992px and up) */
  @media (min-width: 992px) {
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-6);
  }
  
  /* Extra large devices (1200px and up) */
  @media (min-width: 1200px) {
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-6);
  }
  
  /* XXL devices (1400px and up) */
  @media (min-width: 1400px) {
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-8);
  }
}

/* Results Header */
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-8);
  padding: 0 var(--space-4);
}

.results-info h2 {
  font-size: 1.375rem;
  font-weight: var(--font-weight-semibold);
  color: var(--neutral-dark);
  margin: 0 0 var(--space-1) 0;
}

.results-count {
  font-size: 0.875rem;
  color: var(--neutral-medium);
  margin: 0;
}

/* View Controls */
.view-controls {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.view-toggle {
  display: flex;
  background: var(--white);
  border: 1px solid var(--neutral-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.view-toggle-btn {
  background: none;
  border: none;
  padding: var(--space-2) var(--space-3);
  color: var(--neutral-medium);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 32px;
}

.view-toggle-btn:hover {
  background: var(--neutral-background);
  color: var(--neutral-dark);
}

.view-toggle-btn.active {
  background: var(--neutral-dark);
  color: var(--white);
}

.sort-select {
  background: var(--white);
  border: 1px solid var(--neutral-border);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-4);
  font-size: 0.875rem;
  color: var(--neutral-dark);
  min-width: 140px;
  cursor: pointer;
  transition: border-color 0.2s ease;
}

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

/* Filters Sidebar */
.filters-sidebar {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-6);
  height: fit-content;
}

.filters-title {
  font-size: 1.125rem;
  font-weight: var(--font-weight-semibold);
  color: var(--neutral-dark);
  margin: 0 0 var(--space-6) 0;
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--neutral-border);
}

.filter-group {
  margin-bottom: var(--space-6);
}

.filter-group:last-child {
  margin-bottom: 0;
}

.filter-label {
  font-size: 1rem;
  font-weight: var(--font-weight-medium);
  color: var(--neutral-dark);
  margin-bottom: var(--space-3);
  display: block;
}

.filter-options {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.filter-checkbox {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
  padding: var(--space-2) 0;
  transition: color 0.2s ease;
}

.filter-checkbox:hover {
  color: var(--neutral-dark);
}

.filter-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary-coral);
}

.filter-checkbox-label {
  font-size: 0.875rem;
  color: var(--neutral-medium);
  cursor: pointer;
  flex: 1;
}

.filter-checkbox-count {
  font-size: 0.875rem;
  color: var(--neutral-light);
}

/* Price Range Filter */
.price-range {
  margin: var(--space-4) 0;
}

.price-range-slider {
  width: 100%;
  height: 4px;
  background: var(--neutral-border);
  border-radius: 2px;
  outline: none;
  margin: var(--space-4) 0;
  appearance: none;
}

.price-range-slider::-webkit-slider-thumb {
  appearance: none;
  width: 20px;
  height: 20px;
  background: var(--primary-coral);
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid var(--white);
  box-shadow: var(--shadow-sm);
}

.price-range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.875rem;
  color: var(--neutral-medium);
}

/* Map View Layout */
.map-view-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-6);
  height: 70vh;
}

.map-container {
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.map-results-list {
  overflow-y: auto;
  padding-right: var(--space-2);
}

.map-results-list::-webkit-scrollbar {
  width: 4px;
}

.map-results-list::-webkit-scrollbar-track {
  background: var(--neutral-background);
  border-radius: 2px;
}

.map-results-list::-webkit-scrollbar-thumb {
  background: var(--neutral-border);
  border-radius: 2px;
}

.map-results-list::-webkit-scrollbar-thumb:hover {
  background: var(--neutral-medium);
}

/* Compact Card for Map View */
.loveform-card-compact {
  display: flex;
  background: var(--white);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: var(--space-4);
  cursor: pointer;
  transition: all 0.2s ease;
}

.loveform-card-compact:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.loveform-card-compact-image {
  width: 120px;
  height: 80px;
  flex-shrink: 0;
}

.loveform-card-compact-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.loveform-card-compact-content {
  padding: var(--space-3);
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.loveform-card-compact-title {
  font-size: 0.875rem;
  font-weight: var(--font-weight-semibold);
  color: var(--neutral-dark);
  margin: 0 0 var(--space-1) 0;
  line-height: 1.3;
}

.loveform-card-compact-subtitle {
  font-size: 0.75rem;
  color: var(--neutral-medium);
  margin: 0 0 var(--space-2) 0;
}

.loveform-card-compact-rating {
  font-size: 0.75rem;
  color: var(--neutral-dark);
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: var(--space-20) var(--space-4);
}

.empty-state-icon {
  font-size: 3rem;
  color: var(--neutral-light);
  margin-bottom: var(--space-4);
}

.empty-state-title {
  font-size: 1.5rem;
  font-weight: var(--font-weight-semibold);
  color: var(--neutral-dark);
  margin-bottom: var(--space-2);
}

.empty-state-description {
  font-size: 1rem;
  color: var(--neutral-medium);
  margin-bottom: var(--space-6);
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}

/* Loading States */
.loading-skeleton {
  background: var(--neutral-background);
  border-radius: var(--radius-md);
  position: relative;
  overflow: hidden;
}

.loading-skeleton::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.6), transparent);
  animation: loading-shimmer 1.5s infinite;
}

@keyframes loading-shimmer {
  0% {
    left: -100%;
  }
  100% {
    left: 100%;
  }
}

.loading-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  height: 320px;
}

.loading-card-image {
  height: 200px;
  background: var(--neutral-background);
}

.loading-card-content {
  padding: var(--space-4);
}

.loading-text {
  height: 16px;
  background: var(--neutral-background);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-2);
}

.loading-text.short {
  width: 60%;
}

.loading-text.medium {
  width: 80%;
}

/* Responsive Adjustments */
@media (max-width: 1199px) {
  .map-view-container {
    grid-template-columns: 1fr;
    gap: var(--space-4);
  }
  
  .map-container {
    height: 400px;
  }
  
  .map-results-list {
    height: auto;
    max-height: 600px;
  }
}

@media (max-width: 991px) {
  .results-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-4);
  }
  
  .view-controls {
    width: 100%;
    justify-content: space-between;
  }
  
  .filters-sidebar {
    position: static;
    margin-bottom: var(--space-6);
  }
}

@media (max-width: 767px) {
  .search-results-container {
    padding: var(--space-4) 0;
  }
  
  .results-grid {
    gap: var(--space-4);
  }
  
  .results-header {
    padding: 0 var(--space-2);
    margin-bottom: var(--space-6);
  }
  
  .view-controls {
    gap: var(--space-2);
  }
  
  .sort-select {
    min-width: 120px;
    font-size: 0.8125rem;
  }
  
  .filters-sidebar {
    padding: var(--space-4);
  }
  
  .loveform-card-compact {
    margin-bottom: var(--space-3);
  }
  
  .loveform-card-compact-image {
    width: 100px;
    height: 70px;
  }
  
  .loveform-card-compact-content {
    padding: var(--space-2);
  }
}

/* ================================================================
   K12 Search Split View (LoveForm Pattern)
   Always split on desktop: cards left, map right
   Breakpoints: 550px (2 cols), 1240px (3 cols) per LoveForm.com
   ================================================================ */

/* Split Layout Container - Fills viewport below nav (LoveForm pattern)
 * Nav is ~80px, we want ~24px bottom margin like LoveForm
 * Total: 100vh - 80px nav - 24px bottom = 100vh - 104px
 */
.search-split-layout {
  display: flex;
  flex-direction: column;
  /* Min-height ensures split view fills viewport, but can expand for footer scroll */
  min-height: calc(100vh - 80px); /* viewport - nav height */
  overflow: visible; /* Allow page scroll to footer */
  margin-bottom: 24px; /* Gap before footer (LoveForm pattern) */
}

/* Results Header in Split View */
.search-results-header {
  flex-shrink: 0;
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--neutral-border);
  background: var(--white);
}

/* Split Content Row - Container for cards + map columns
 * TRANSITIONING SCROLL PATTERN: Cards scroll first, then page scrolls to footer
 */
.search-split-content {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: visible; /* Allow page scroll to footer */
  /* Reset Bootstrap .row negative gutters for exact viewport-based parity math. */
  margin-left: 0 !important;
  margin-right: 0 !important;
}

/* Cards Column (Left) - SCROLLABLE with fixed height
 * Transitioning scroll: cards scroll first, then page scrolls to footer
 * Height is set in search.ejs: calc(100vh - 80px - 56px)
 */
.search-cards-column {
  display: flex;
  flex-direction: column;
  /* Min-height matches map so pagination can align with map bottom */
  min-height: calc(100vh - 128px);
  padding: 8px 24px 8px 32px; /* Bottom reduced to 8px for 32px total gap to footer (LoveForm pattern) */
  background: var(--white);
}

/* 1128px+: 48px left padding (LoveForm breakpoint) */
@media (min-width: 1128px) {
  .search-cards-column {
    padding-left: 48px;
  }
}

/* 1440px+: 80px left padding (LoveForm breakpoint) */
@media (min-width: 1440px) {
  .search-cards-column {
    padding-left: 80px;
  }
}

/*
 * LoveForm-Style Split View Ratios (Measured from actual LoveForm screenshots)
 * =========================================================================
 * LoveForm uses DIFFERENT ratios at different viewport sizes:
 * - At 1280px: ~63% listings / ~37% map
 * - At 1440px+: ~59% listings / ~41% map
 *
 * See BUG-104 for measurement methodology.
 */

/* Split starts at 950px (measured Airbnb tablet transition). */
@media (min-width: 950px) {
  .search-cards-column {
    flex: 0 0 63% !important;
    max-width: 63% !important;
    width: 63% !important;
  }
  .search-map-column {
    flex: 0 0 37% !important;
    max-width: 37% !important;
    width: 37% !important;
  }
}

/* 1128px+: 59% cards / 41% map (measured Airbnb tablet->desktop tier) */
@media (min-width: 1128px) {
  .search-cards-column {
    flex: 0 0 59% !important;
    max-width: 59% !important;
    width: 59% !important;
  }
  .search-map-column {
    flex: 0 0 41% !important;
    max-width: 41% !important;
    width: 41% !important;
  }
}

/* 950-1127px: single listings column pinned to measured 440px width + map visible */
@media (min-width: 950px) and (max-width: 1127px) {
  .search-cards-column {
    /* Airbnb parity at 1024px: 440px card with 32px inner gutters on both sides. */
    flex: 0 0 504px !important;
    max-width: 504px !important;
    width: 504px !important;
    padding-left: 32px;
    padding-right: 32px;
  }

  .search-map-column {
    display: block;
    flex: 1 1 auto !important;
    max-width: none !important;
    width: auto !important;
    padding-right: 32px;
  }

  .search-cards-grid {
    grid-template-columns: minmax(0, 1fr) !important;
    width: 440px;
    max-width: 440px;
  }
}

/* Cards Grid - LoveForm exact breakpoints (with map visible) */
/* Reference: https://www.loveform.com/s/Miami/homes */
/* Note: minmax(0, 1fr) allows columns to shrink below content min-width */
/* Gap: 40px row (vertical), 24px column (horizontal)
 * Measured against Airbnb tablet/pro references on 2026-03-08.
 */
.search-cards-grid {
  display: grid;
  row-gap: 40px;
  column-gap: 24px;
  /* Default: 1 column (mobile) */
  grid-template-columns: minmax(0, 1fr);
}

/* 550px+: 2 columns (LoveForm breakpoint) */
@media (min-width: 550px) {
  .search-cards-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    /* Keep same gaps - explicit for clarity */
    row-gap: 40px;
    column-gap: 24px;
  }
}

/* 1128-2119px: return to two-card split after the 950-1127 single-card map tier */
@media (min-width: 1128px) and (max-width: 2119px) {
  .search-cards-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    row-gap: 40px;
    column-gap: 24px;
  }
}

/* 2120px+: 3 columns with map visible.
   Measured against Airbnb on 2026-03-08:
   - 1365, 1439, 1440, 1500, 1600, 1700, 1800, 1900, 2000, 2100 => 2 cards
   - 2120 => first width that expands to 3 cards
*/
@media (min-width: 2120px) {
  .search-cards-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    /* Keep same gaps - explicit for clarity */
    row-gap: 40px;
    column-gap: 24px;
  }
}

/* Map Column (Right - Sticky) */
/* Sticky map stays visible while cards scroll, then page scrolls to footer */
/* LoveForm pattern: Column stretches full height, sticky map inside fills viewport */
.search-map-column {
  /* Sticky Sidecar offsets (reusable across any 2-column page). */
  --sticky-sidecar-gap: 24px;
  --sticky-sidecar-top: calc(var(--k12-header-row-height, 80px) + var(--sticky-sidecar-gap));
  --sticky-sidecar-bottom: var(--sticky-sidecar-gap);

  background: transparent;
  padding: 0 48px var(--sticky-sidecar-gap) 0; /* Right: 48px, Bottom: 24px */
  box-sizing: border-box;
  /* Column stretches to match cards column height (no align-self: flex-start) */
  /* The .search-map-container inside uses sticky positioning */
}

.search-map-container {
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
}

/* ================================================================
   Map Expanded State - Fills content viewport (not browser fullscreen)
   Triggered by custom expand control in map-integration.js
   ================================================================ */
/* Cards column collapses to 0 width (not display:none) for smooth slide */
.search-split-content.is-map-expanded .search-cards-column {
  flex: 0 0 0% !important;
  max-width: 0% !important;
  width: 0% !important;
  padding: 0 !important;
  overflow: hidden;
}

.search-map-column.is-map-expanded {
  flex: 1 1 100% !important;
  max-width: 100% !important;
  width: 100% !important;
  padding: 0 48px var(--sticky-sidecar-gap) 32px; /* Right: 48px, Left: 32px, Bottom: 24px */
}

/* Expanded map responsive left padding - matches cards column */
@media (min-width: 1128px) {
  .search-map-column.is-map-expanded {
    padding-left: 48px;
  }
}

@media (min-width: 1440px) {
  .search-map-column.is-map-expanded {
    padding-left: 80px;
  }
}

/* Instant expand/collapse - LoveForm pattern (no visible slide animation) */
.search-cards-column,
.search-map-column {
  transition: none;
}

/* ================================================================
   Search Cards - LoveForm Visual Style Overrides
   Uses wishlist-school-card functionality but LoveForm appearance
   ================================================================ */

/* Image Aspect Ratio: Optimized to match LoveForm card height
 * LoveForm: 228px wide × 216px tall = ratio 1.056
 * Our cards: 234px wide, need ~216px tall = ratio 1.083 ≈ 13/12
 */
.search-cards-grid .wishlist-school-image-carousel,
.search-cards-grid .loveform-card-image,
.search-cards-grid .loveform-listing-card__image {
  aspect-ratio: 13 / 12;
}

/* Card Content: Tighter spacing to match LoveForm card height (339px target) */
.search-cards-grid .loveform-listing-card__content {
  /* Match Airbnb card rhythm on tablet/desktop tiers. */
  padding-top: 12px;
  gap: 2px;
}

.search-cards-grid .loveform-listing-card__type,
.search-cards-grid .loveform-listing-card__name,
.search-cards-grid .loveform-listing-card__details,
.search-cards-grid .loveform-listing-card__availability,
.search-cards-grid .loveform-listing-card__rating {
  font-size: 15px;
  line-height: 1.27;
}

.search-cards-grid .loveform-listing-card__price {
  margin-top: 4px;
  font-size: 15px;
  line-height: 1.27;
}

/* Card hover state for map sync - supports both old and new card classes */
.search-cards-grid .loveform-card,
.search-cards-grid .wishlist-school-card {
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.search-cards-grid .loveform-card:hover,
.search-cards-grid .wishlist-school-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

/* Highlighted card (from map hover) */
.search-cards-grid .loveform-card.map-highlighted,
.search-cards-grid .wishlist-school-card.map-highlighted {
  box-shadow: 0 0 0 2px var(--primary-coral), var(--shadow-lg);
}

/* Scrollbar Styling - Cards column scrollbar (Transitioning scroll pattern)
 * More specific styling in search.ejs overrides this for LoveForm-style scrollbar
 */
.search-cards-column::-webkit-scrollbar {
  width: 8px;
}

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

.search-cards-column::-webkit-scrollbar-thumb {
  background: var(--neutral-border);
  border-radius: 4px;
}

.search-cards-column::-webkit-scrollbar-thumb:hover {
  background: var(--neutral-medium);
}

/* ================================================================
   Responsive: Tablet and Mobile (hide map, show full-width cards)
   ================================================================ */
@media (max-width: 949px) {
  .search-split-layout {
    min-height: auto;
    overflow: visible;
  }

  .search-split-content {
    flex-direction: column;
    overflow: visible;
  }

  /* Mobile: no fixed height, cards scroll with page normally */
  .search-cards-column {
    max-height: none !important;
    overflow: visible !important;
    /* Airbnb parity on tablet widths (768/820): 32px viewport gutters each side. */
    padding: 0 32px 16px !important;
    width: 100%;
  }

  /* Hide map on tablet/mobile */
  .search-map-column {
    display: none;
  }

  /* Full width cards */
  .search-cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 549px) {
  .search-cards-grid {
    grid-template-columns: 1fr;
  }

  .search-results-header {
    padding: var(--space-3) var(--space-4);
  }

  .search-cards-column {
    padding: var(--space-3);
  }
}
