/* Enhanced Mobile Responsive Design - Fixed Version */

/* Larger Tablets and Small Desktops */
@media (max-width: 1024px) {
  .sidebar {
    width: 320px;
  }

  .property-grid {
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--space-4);
  }

  .header-container {
    padding: 0 var(--space-4);
    gap: var(--space-4);
  }

  .header-center {
    margin: 0 var(--space-4);
  }

  .list-container {
    padding: var(--space-4);
  }
}

/* Tablets and below (Mobile View Activation) */
@media (max-width: 768px) {
  /* Header Mobile Optimizations */
  .header {
    height: 65px; /* Slightly shorter on mobile */
  }

  .main-layout {
    height: calc(100vh - 65px); /* Adjust for shorter header */
  }

  .mobile-menu-btn {
    display: flex; /* Show mobile menu button */
    align-items: center;
    justify-content: center;
    width: 44px; /* Touch-friendly size */
    height: 44px;
    border-radius: var(--radius);
  }

  .header-container {
    padding: 0 var(--space-3);
    gap: var(--space-2);
  }

  .header-left {
    flex-shrink: 0;
    gap: var(--space-2);
  }

  .header-left .logo h1 {
    display: none; /* Hide logo text on mobile to save space */
  }

  .header-left .logo i {
    font-size: var(--font-size-xl); /* Slightly smaller icon */
  }

  /* Search Bar Mobile Optimization */
  .header-center {
    flex: 1; /* Take remaining space */
    margin: 0; /* Remove margins */
    min-width: 0; /* Allow shrinking */
  }

  .search-bar {
    position: relative;
    width: 100%;
  }

  .search-input {
    width: 100%;
    padding: var(--space-2) var(--space-3) var(--space-2) var(--space-10); /* Adjusted padding */
    font-size: var(--font-size-sm);
    border-radius: var(--radius-lg); /* Less rounded for mobile */
    border: 1px solid var(--gray-300); /* Thinner border */
  }

  .search-icon {
    left: var(--space-3);
    font-size: var(--font-size-sm);
  }

  .search-clear {
    right: var(--space-3);
    width: 28px;
    height: 28px;
    border-radius: var(--radius);
  }

  /* Header Right Mobile Optimization */
  .header-right {
    flex-shrink: 0;
    gap: var(--space-1);
  }

  .view-switcher {
    padding: 2px; /* Smaller padding */
  }

  .view-btn {
    padding: var(--space-2);
    min-width: 44px; /* Touch-friendly minimum */
    justify-content: center;
  }

  .view-btn span {
    display: none; /* Hide text labels */
  }

  .view-btn i {
    font-size: var(--font-size-base);
  }

  .contact-btn {
    padding: var(--space-2) var(--space-3);
    min-width: 44px;
  }

  .contact-btn span {
    display: none; /* Hide text label */
  }

  /* Sidebar Mobile Behavior */
  .sidebar {
    position: fixed;
    top: 65px; /* Match header height */
    left: 0;
    bottom: 0;
    z-index: 1001;
    transform: translateX(-100%);
    box-shadow: var(--shadow-xl);
    border-right: none;
    width: 320px; /* Slightly wider for better usability */
    background: var(--white);
  }

  .sidebar.active {
    transform: translateX(0);
  }

  .mobile-overlay {
    position: fixed;
    top: 65px; /* Match header height */
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition), visibility var(--transition);
  }

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

  .main-content {
    margin-left: 0;
  }

  /* Property Grid Mobile */
  .property-grid {
    grid-template-columns: 1fr;
    gap: var(--space-4);
  }

  .list-container {
    padding: var(--space-3);
  }

  .mobile-only {
    display: block;
  }

  /* Map Controls Mobile */
  .map-controls {
    bottom: var(--space-4);
    right: var(--space-3);
    flex-direction: column;
    gap: var(--space-2);
  }

  .map-control-btn {
    width: 44px; /* Touch-friendly size */
    height: 44px;
    box-shadow: var(--shadow-lg); /* More prominent shadow for mobile */
  }

  /* Modal Mobile Improvements */
  .modal {
    padding: var(--space-2);
    align-items: flex-start; /* Align to top for better mobile experience */
    padding-top: var(--space-4);
  }

  .modal-content {
    width: 100%;
    max-width: none;
    max-height: calc(100vh - var(--space-8));
    margin: 0;
    border-radius: var(--radius-lg);
  }

  .modal-close {
    top: var(--space-3);
    right: var(--space-3);
    width: 36px;
    height: 36px;
    z-index: 1002;
  }

  /* Property Modal Mobile Specific */
  #property-modal .modal-content {
    max-height: calc(100vh - var(--space-4));
  }

  #property-modal .modal-body {
    padding: var(--space-4);
  }

  #property-modal .property-images {
    margin-bottom: var(--space-4);
  }

  #property-modal .property-images img {
    height: 200px;
    margin-bottom: var(--space-3);
    border-radius: var(--radius-md);
  }

  /* Create horizontal scroll for multiple images */
  #property-modal .property-images {
    display: flex;
    overflow-x: auto;
    gap: var(--space-3);
    padding-bottom: var(--space-2);
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
  }

  #property-modal .property-images img {
    flex-shrink: 0;
    width: 85%;
    min-width: 250px;
    scroll-snap-align: start;
  }

  /* Property info responsive grid */
  #property-modal .property-info div[style*="grid-template-columns"] {
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)) !important;
    gap: var(--space-3);
  }

  /* Buttons responsive */
  #property-modal .property-info div[style*="display: flex; gap: 1rem"] {
    flex-wrap: wrap;
    gap: var(--space-2) !important;
  }

  #property-modal .property-info button {
    min-height: 44px; /* Touch-friendly height */
  }

  /* Toast Mobile */
  .toast-container {
    top: var(--space-2);
    right: var(--space-2);
    left: var(--space-2);
    width: auto;
    max-width: none;
  }

  .toast {
    font-size: var(--font-size-sm);
    padding: var(--space-3);
  }

  /* Pagination Mobile */
  .pagination-container {
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-4);
  }

  .pagination-info {
    width: 100%;
    justify-content: space-between;
  }

  .pagination-controls {
    width: 100%;
    justify-content: center;
  }

  .page-numbers {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* Smaller Mobile Phones */
@media (max-width: 480px) {
  .header {
    height: 60px;
  }

  .main-layout {
    height: calc(100vh - 60px);
  }

  .mobile-overlay {
    top: 60px;
  }

  .sidebar {
    top: 60px;
    width: 100%; /* Full width on very small screens */
  }

  .header-container {
    padding: 0 var(--space-2);
    gap: var(--space-1);
  }

  .mobile-menu-btn {
    width: 40px;
    height: 40px;
  }

  .header-left .logo i {
    font-size: var(--font-size-lg);
  }

  /* Ultra-compact search bar */
  .search-input {
    padding: var(--space-2) var(--space-2) var(--space-2) var(--space-8);
    font-size: var(--font-size-xs);
  }

  .search-icon {
    left: var(--space-2);
    font-size: var(--font-size-xs);
  }

  .search-clear {
    right: var(--space-2);
    width: 24px;
    height: 24px;
  }

  .view-btn,
  .contact-btn {
    min-width: 40px;
    padding: var(--space-2);
  }

  .view-btn i,
  .contact-btn i {
    font-size: var(--font-size-sm);
  }

  /* Property Cards */
  .property-card {
    border-radius: var(--radius-lg);
  }

  .property-details {
    padding: var(--space-3);
  }

  .property-title {
    font-size: var(--font-size-base);
  }

  .property-features {
    gap: var(--space-2);
    font-size: var(--font-size-xs);
  }

  .property-actions {
    gap: var(--space-2);
  }

  .btn-primary {
    font-size: var(--font-size-xs);
    padding: var(--space-2) var(--space-3);
  }

  .btn-secondary {
    width: 36px;
    height: 36px;
    font-size: var(--font-size-xs);
  }

  /* Sidebar Content */
  .sidebar-content {
    padding: var(--space-3);
  }

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

  .filter-group label {
    font-size: var(--font-size-sm);
    margin-bottom: var(--space-2);
  }

  .form-input,
  .checkmark,
  .radio-mark {
    font-size: var(--font-size-sm);
  }

  .checkmark,
  .radio-mark {
    padding: var(--space-2);
    min-width: 50px;
  }

  .apply-filters-btn {
    font-size: var(--font-size-sm);
    padding: var(--space-3);
  }

  /* Map Controls */
  .map-control-btn {
    width: 40px;
    height: 40px;
  }

  /* Modal Ultra-Mobile */
  .modal {
    padding: var(--space-1);
    padding-top: var(--space-2);
  }

  .modal-content {
    border-radius: var(--radius-md);
    max-height: calc(100vh - var(--space-2));
  }

  #property-modal .modal-body {
    padding: var(--space-3);
  }

  #property-modal .property-images img {
    height: 180px;
    min-width: 220px;
  }

  #property-modal .property-info h2 {
    font-size: var(--font-size-lg);
  }

  #property-modal .property-info div[style*="font-size: 1.25rem"] {
    font-size: var(--font-size-base) !important;
  }

  /* Ultra-compact feature grid */
  #property-modal .property-info div[style*="grid-template-columns"] {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: var(--space-2);
  }

  #property-modal
    .property-info
    div[style*="text-align: center; padding: 1rem"] {
    padding: var(--space-2) !important;
  }

  #property-modal .property-info i[style*="font-size: 1.5rem"] {
    font-size: var(--font-size-base) !important;
  }

  /* Buttons container */
  #property-modal .property-info div[style*="display: flex; gap: 1rem"] {
    gap: var(--space-1) !important;
  }

  #property-modal .property-info button {
    padding: var(--space-2) !important;
    font-size: var(--font-size-xs) !important;
    min-height: 40px;
  }

  #property-modal .property-info button.btn-secondary {
    width: 40px;
    height: 40px;
    padding: var(--space-2) !important;
  }

  /* Touch-friendly interactive elements */
  .property-card,
  .filter-tag,
  .pagination-btn,
  .page-number-btn {
    min-height: 44px;
  }

  /* Improved touch targets for form elements */
  .form-input,
  .checkmark,
  .radio-mark,
  .view-btn,
  .contact-btn {
    min-height: 44px;
  }
}
