/**
 * Property Grid Styles - Enhanced Mobile First
 * 
 * Mobile-first responsive grid with list view support
 * Following BEM methodology for consistent styling
 * 
 * @package wbl
 */

/* ================================================================
   PROPERTY ARCHIVE LAYOUT
   ================================================================ */

.property-archive {
  min-height: 100vh;
  background-color: var(--color-bg-alt);
  position: relative;
}

.property-archive__content {
  display: block;
  width: 100%;
}

/* Drawer open state */
body.drawer-open {
  overflow: hidden;
}

.drawer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 999;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  display: none;
}

@media (max-width: 767px) {
  .drawer-overlay {
    display: block;
  }
}

.drawer-overlay.is-active {
  opacity: 1;
  visibility: visible;
}

/* ================================================================
   PROPERTY CONTAINER
   ================================================================ */

.property-container {
  position: relative;
  min-height: 400px;
}

.property-container--list {
  /* List view container adjustments */
}

/* ================================================================
   PROPERTY GRID - MOBILE FIRST
   ================================================================ */

.property-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--spacing-md);
  margin-bottom: var(--spacing-xl);
  position: relative;
}

/* Small phones (320px - 480px) */
@media (min-width: 320px) {
  .property-grid {
    gap: var(--spacing-sm);
  }
}

/* Large phones (481px - 767px) */
@media (min-width: 481px) {
  .property-grid {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--spacing-md);
  }
}

/* Tablets (768px - 991px) */
@media (min-width: 768px) {
  .property-grid {
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--spacing-lg);
  }
}

/* Desktop (992px+) */
@media (min-width: 992px) {
  .property-grid {
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  }
}

/* Large desktop (1200px+) */
@media (min-width: 1200px) {
  .property-grid {
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  }
}

/* ================================================================
   LIST VIEW STYLES
   ================================================================ */

.property-grid--list {
  grid-template-columns: 1fr;
  gap: var(--spacing-md);
}

.property-grid--list .property-card {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  height: auto;
  max-width: none;
}

/* Mobile list view */
@media (max-width: 767px) {
  .property-grid--list .property-card {
    /* Stack vertically on mobile */
  }
  
  .property-grid--list .card__image-container {
    aspect-ratio: 16/9;
    max-height: 200px;
  }
}

/* Desktop list view */
@media (min-width: 768px) {
  .property-grid--list .property-card {
    grid-template-columns: 280px 1fr;
  }
  
  .property-grid--list .card__image-container {
    aspect-ratio: 4/3;
    height: 100%;
  }
  
  .property-grid--list .card__content {
    display: flex;
    flex-direction: column;
  }
  
  .property-grid--list .card__body {
    flex: 1;
    display: flex;
    flex-direction: column;
  }
  
  .property-grid--list .property-card__details {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--spacing-md);
    margin-top: auto;
  }
  
  .property-grid--list .card__footer {
    border-top: 1px solid #eee;
    padding: var(--spacing-md);
  }
}

/* ================================================================
   LOADING STATES
   ================================================================ */

.property-grid.is-loading {
  opacity: 0.5;
  pointer-events: none;
  position: relative;
}

.property-grid.is-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border: 4px solid rgba(115, 53, 16, 0.1);
  border-radius: 50%;
  border-top-color: var(--color-primary);
  animation: spin 1s linear infinite;
}

.loading-skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
}

@keyframes loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* ================================================================
   NO PROPERTIES STATE - ENHANCED
   ================================================================ */

.no-properties {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-xxl) var(--spacing-lg);
  text-align: center;
  background-color: var(--color-white);
  border-radius: var(--radius-medium);
  box-shadow: var(--shadow-light);
  grid-column: 1 / -1;
  min-height: 400px;
}

.no-properties__icon {
  width: 100px;
  height: 100px;
  color: var(--color-text-secondary);
  margin-bottom: var(--spacing-lg);
  opacity: 0.3;
  animation: fadeIn 0.6s ease-out;
}

.no-properties__icon svg {
  width: 100%;
  height: 100%;
}

.no-properties__title {
  font-size: var(--font-size-h2);
  font-weight: var(--font-weight-bold);
  color: var(--color-text-primary);
  margin: 0 0 var(--spacing-md) 0;
  animation: fadeInUp 0.6s ease-out 0.2s both;
}

.no-properties__description {
  font-size: var(--font-size-body);
  color: var(--color-text-secondary);
  margin: 0 0 var(--spacing-xl) 0;
  line-height: var(--line-height-body);
  max-width: 500px;
  animation: fadeInUp 0.6s ease-out 0.3s both;
}

.no-properties .btn {
  animation: fadeInUp 0.6s ease-out 0.4s both;
}

/* Mobile adjustments */
@media (max-width: 767px) {
  .no-properties {
    padding: var(--spacing-xl) var(--spacing-md);
    margin: var(--spacing-md) 0;
  }
  
  .no-properties__icon {
    width: 80px;
    height: 80px;
  }
  
  .no-properties__title {
    font-size: var(--font-size-h3);
  }
  
  .no-properties__description {
    font-size: var(--font-size-small);
  }
}

/* ================================================================
   AJAX ERROR STATE
   ================================================================ */

.ajax-error {
  text-align: center;
  padding: var(--spacing-xl);
  color: var(--color-error);
  grid-column: 1 / -1;
}

.ajax-error p {
  font-size: var(--font-size-body);
  margin-bottom: var(--spacing-lg);
}

/* ================================================================
   ENHANCED ANIMATIONS
   ================================================================ */

/* Grid entrance animation */
.property-grid {
  animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Card entrance animations */
.property-card {
  animation: slideInUp 0.4s ease-out;
  animation-fill-mode: both;
}

@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Stagger animation for cards */
.property-card:nth-child(1) { animation-delay: 0.05s; }
.property-card:nth-child(2) { animation-delay: 0.1s; }
.property-card:nth-child(3) { animation-delay: 0.15s; }
.property-card:nth-child(4) { animation-delay: 0.2s; }
.property-card:nth-child(5) { animation-delay: 0.25s; }
.property-card:nth-child(6) { animation-delay: 0.3s; }
.property-card:nth-child(7) { animation-delay: 0.35s; }
.property-card:nth-child(8) { animation-delay: 0.4s; }
.property-card:nth-child(9) { animation-delay: 0.45s; }

/* Hover effects for desktop */
@media (hover: hover) and (pointer: fine) {
  .property-card {
    transition: transform 0.3s ease, box-shadow 0.3s ease;
  }
  
  .property-grid:not(.property-grid--list) .property-card:hover {
    transform: translateY(-4px);
    z-index: 10;
  }
}

/* ================================================================
   GRID VARIANTS
   ================================================================ */

/* Compact Grid */
.property-grid--compact {
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--spacing-sm);
}

/* Large Grid */
.property-grid--large {
  grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
  gap: var(--spacing-xl);
}

/* Masonry-style grid (optional) */
.property-grid--masonry {
  display: block;
  column-count: 1;
  column-gap: var(--spacing-md);
}

@media (min-width: 768px) {
  .property-grid--masonry {
    column-count: 2;
  }
}

@media (min-width: 992px) {
  .property-grid--masonry {
    column-count: 3;
  }
}

@media (min-width: 1200px) {
  .property-grid--masonry {
    column-count: 4;
  }
}

.property-grid--masonry .property-card {
  break-inside: avoid;
  margin-bottom: var(--spacing-md);
}

/* ================================================================
   INFINITE SCROLL
   ================================================================ */

.infinite-scroll-status {
  text-align: center;
  padding: var(--spacing-lg);
  grid-column: 1 / -1;
}

.infinite-scroll-request {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
}

.infinite-scroll-last,
.infinite-scroll-error {
  color: var(--color-text-secondary);
  font-size: var(--font-size-body);
}

/* ================================================================
   ACCESSIBILITY
   ================================================================ */

/* Focus styles */
.property-card:focus-within {
  outline: 2px solid var(--color-primary);
  outline-offset: 4px;
}

/* Skip to results link */
.skip-to-results {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--color-primary);
  color: var(--color-white);
  padding: var(--spacing-sm) var(--spacing-md);
  text-decoration: none;
  border-radius: var(--radius-small);
  z-index: 100;
}

.skip-to-results:focus {
  top: var(--spacing-sm);
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .property-grid {
    gap: var(--spacing-xl);
  }
  
  .property-card {
    border: 2px solid var(--color-text-primary);
  }
  
  .no-properties {
    border: 2px solid var(--color-text-primary);
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .property-grid,
  .property-card,
  .no-properties__icon,
  .no-properties__title,
  .no-properties__description,
  .no-properties .btn {
    animation: none;
  }
  
  .property-card {
    transition: none;
  }
  
  .property-card:hover {
    transform: none;
  }
  
  .loading-skeleton {
    animation: none;
    background: #e0e0e0;
  }
}

/* Print styles */
@media print {
  .property-grid {
    display: block;
  }
  
  .property-card {
    page-break-inside: avoid;
    margin-bottom: 20pt;
    border: 1pt solid #000;
  }
  
  .loading-state,
  .infinite-scroll-status,
  .ajax-error {
    display: none;
  }
}

/* ================================================================
   RESPONSIVE UTILITIES
   ================================================================ */

/* Hide on mobile */
@media (max-width: 767px) {
  .desktop-only {
    display: none !important;
  }
}

/* Hide on desktop */
@media (min-width: 768px) {
  .mobile-only {
    display: none !important;
  }
}

/* ================================================================
   GRID LAYOUT WITH SIDEBAR (DESKTOP)
   ================================================================ */

@media (min-width: 768px) {
  .property-archive > .container {
    position: relative;
  }
  
  /* When filters are in sidebar */
  .property-archive--with-sidebar .property-container {
    /* Grid adjusts automatically with CSS Grid in parent container */
  }
}