/**
 * Mobile UX Enhancements
 *
 * Purpose: Enhance mobile user experience for WuChatProp property listing platform
 * Components:
 *   1. Homepage Search Section Visibility (Requirements 1.1, 1.2, 1.4, 5.5)
 *   2. Enhanced Floating Bottom Bar (Requirements 2.1-2.7)
 *   3. Toggle-Based Filter Modal (Requirements 3.1-3.16)
 *
 * Target: Mobile viewports (max-width: 768px)
 * Compatibility: Houzez theme, Bootstrap 4, Traditional Chinese (Hong Kong)
 *
 * @package Houzez
 * @since 1.0.0
 */

/* ============================================================================
   Component 1: Homepage Search Section Visibility
   Requirements: 1.1, 1.2, 1.4, 5.5
   ============================================================================ */

@media (max-width: 768px) {
  /* Override existing mobile hide rules to make search section visible */
  .homepage-search-section,
  .search-section-wrapper,
  .elementor-search-form-section,
  .search-banner-wrap,
  .banner-search-wrap {
    display: block !important;
    visibility: visible !important;
  }

  /* Ensure responsive layout within mobile viewport */
  .homepage-search-section {
    width: 100%;
    max-width: 100%;
    padding: 15px;
    overflow-x: hidden;
    box-sizing: border-box;
  }

  /* Make search tabs stack properly on mobile */
  .search-tabs,
  .banner-tabs {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
  }

  /* Ensure tab buttons are touch-friendly */
  .search-tabs .nav-link,
  .banner-tabs .nav-link {
    min-height: 44px;
    padding: 12px 16px;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Make form inputs touch-friendly and prevent iOS zoom */
  .search-form input,
  .search-form select,
  .search-form button,
  .banner-search-wrap input,
  .banner-search-wrap select,
  .banner-search-wrap button {
    min-height: 44px;
    font-size: 16px; /* Prevents iOS zoom on focus */
    padding: 10px 15px;
    box-sizing: border-box;
  }

  /* Ensure search form fields stack vertically on mobile */
  .search-form .form-group,
  .banner-search-wrap .form-group {
    width: 100%;
    margin-bottom: 10px;
  }

  /* Make search button full-width and prominent */
  .search-form .btn-search,
  .banner-search-wrap .btn-search {
    width: 100%;
    min-height: 48px;
    font-size: 16px;
    font-weight: 600;
    margin-top: 10px;
  }

  /* Prevent horizontal scrolling */
  .search-form,
  .banner-search-wrap form {
    overflow-x: hidden;
    max-width: 100%;
  }

  /* Ensure dropdown selects are properly sized */
  .search-form .bootstrap-select,
  .banner-search-wrap .bootstrap-select {
    width: 100% !important;
  }

  .search-form .bootstrap-select .dropdown-toggle,
  .banner-search-wrap .bootstrap-select .dropdown-toggle {
    min-height: 44px;
    font-size: 16px;
  }

  /* Tab content area responsive styling */
  .tab-content {
    width: 100%;
    padding: 15px 0;
  }

  /* Ensure tab panes are visible when active */
  .tab-pane.active {
    display: block !important;
  }
}

/* ============================================================================
   Component 2: Enhanced Floating Bottom Bar
   Requirements: 2.1, 2.2, 2.3, 2.5, 2.6, 2.7, 3.11, 5.5
   ============================================================================ */

/* Hide desktop sort dropdown on mobile */
@media (max-width: 768px) {
  .sort-by {
    display: none !important;
  }

  /* Disable desktop sort select completely on mobile */
  .sort-by select,
  .sort-by .selectpicker,
  .sort-by .bootstrap-select {
    pointer-events: none !important;
    visibility: hidden !important;
    position: absolute !important;
    left: -9999px !important;
  }
}

/* Mobile Bottom Bar Container */
.mobile-listing-bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #ffffff;
  border-top: 1px solid #e0e0e0;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
  z-index: 999;
  padding: 10px 15px;
  max-height: 80px;
  display: none; /* Hidden by default, shown on mobile via media query */
}

/* Show only on mobile viewports */
@media (max-width: 768px) {
  .mobile-listing-bottom-bar {
    display: block;
  }
}

/* Hide on desktop viewports */
@media (min-width: 769px) {
  .mobile-listing-bottom-bar {
    display: none !important;
  }
}

/* Bottom Bar Button Container */
.bottom-bar-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  max-width: 100%;
}

/* Bottom Bar Buttons */
.btn-bottom-bar {
  flex: 1;
  min-height: 44px;
  min-width: 44px;
  padding: 10px 15px;
  border: 1px solid #ddd;
  background: #f8f9fa;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  position: relative;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
  font-size: 14px;
  color: #333;
  /* Performance: Use CSS containment for isolated buttons */
  contain: layout style paint;
}

.btn-bottom-bar:active {
  /* Performance: Use transform for GPU acceleration */
  transform: scale(0.95);
  background: #e9ecef;
}

.btn-bottom-bar:focus {
  outline: 2px solid #00aaff;
  outline-offset: 2px;
}

.btn-bottom-bar:focus-visible {
  outline: 3px solid #00aaff;
  outline-offset: 2px;
}

/* Filter Button Specific Styling */
.btn-open-filters {
  flex: 1.2;
}

.btn-open-filters .filter-text {
  font-weight: 500;
}

/* Filter Count Badge */
.filter-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: #ff5a5f;
  color: white;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  line-height: 1;
}

/* Sort Button */
.btn-open-sort {
  flex: 2;
  justify-content: space-between;
}

.btn-open-sort .sort-text {
  font-weight: 500;
  flex: 1;
  text-align: left;
}

.btn-open-sort .sort-arrow {
  font-size: 12px;
  margin-left: 5px;
  color: #666;
}

/* View Toggle Button */
.btn-view-toggle {
  flex: 1;
}

.btn-view-toggle i {
  font-size: 20px;
  line-height: 1;
}

.btn-view-toggle .view-icon-list {
  color: #00aaff; /* Blue like desktop */
}

.btn-view-toggle .view-icon-grid {
  color: #666; /* Gray like desktop */
}

/* Icon Styling */
.btn-bottom-bar i {
  font-size: 16px;
  line-height: 1;
}

/* Add padding to page content to prevent overlap with bottom bar */
@media (max-width: 768px) {
  .listing-wrap,
  .property-listing-wrap,
  .listing-view {
    padding-bottom: 100px; /* Bottom bar height + buffer */
  }

  /* Ensure pagination is also visible above bottom bar */
  .pagination-wrap {
    margin-bottom: 20px;
  }
}

/* Accessibility: High contrast mode support */
@media (prefers-contrast: high) {
  .btn-bottom-bar {
    border-width: 2px;
  }

  .filter-badge {
    border: 2px solid white;
  }
}

/* Accessibility: Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .btn-bottom-bar {
    transition: none;
  }

  .btn-bottom-bar:active {
    transform: none;
  }
}
/* ============================================================================
   Component 3: Toggle-Based Filter Modal
   Requirements: 3.1, 3.4, 3.12, 3.13, 3.15, 5.2, 5.5, 5.6, 5.9
   ============================================================================ */

/* Modal Overlay - Fixed positioning with semi-transparent background */
.mobile-filter-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  /* Performance: Use CSS containment for isolated rendering */
  contain: layout style paint;
}

.mobile-filter-modal.active {
  display: block;
}

/* Overlay Background with Blur Effect */
.filter-modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  /* Performance: GPU acceleration for opacity */
  will-change: opacity;
}

/* Modal Content - Slide-in from right */
.filter-modal-content {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 85%;
  max-width: 400px;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s ease-out;
  box-shadow: -2px 0 10px rgba(0, 0, 0, 0.2);
  /* Performance: GPU acceleration for transform, hint browser about animation */
  will-change: transform;
  /* Performance: Use CSS containment for isolated component */
  contain: layout style paint;
}

.mobile-filter-modal.active .filter-modal-content {
  transform: translateX(0);
}

/* Modal Header */
.filter-modal-header {
  padding: 20px;
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  background: #ffffff;
}

.filter-modal-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #333;
  line-height: 1.4;
}

/* Close Button - Touch-friendly 44x44px target */
.btn-close-modal {
  background: none;
  border: none;
  font-size: 24px;
  color: #666;
  padding: 0;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.2s ease;
  border-radius: 4px;
}

.btn-close-modal:hover {
  color: #333;
}

.btn-close-modal:active {
  background: #f0f0f0;
}

.btn-close-modal:focus {
  outline: 2px solid #00aaff;
  outline-offset: 2px;
}

.btn-close-modal:focus-visible {
  outline: 3px solid #00aaff;
  outline-offset: 2px;
}

/* Scrollable Modal Body - iOS smooth scrolling */
.filter-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Filter Categories */
.filter-category {
  margin-bottom: 30px;
}

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

.filter-category-title {
  font-size: 16px;
  font-weight: 600;
  color: #333;
  margin-bottom: 15px;
  line-height: 1.4;
}

/* Toggle Button Group - Flexbox with wrap */
.filter-toggle-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* Individual Toggle Buttons - Touch-friendly 44x44px minimum */
.filter-toggle-btn {
  padding: 10px 16px;
  border: 1px solid #ddd;
  background: #ffffff;
  border-radius: 20px;
  font-size: 14px;
  color: #666;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.4;
  white-space: nowrap;
  /* Performance: Use CSS containment for isolated buttons */
  contain: layout style paint;
}

.filter-toggle-btn:active {
  /* Performance: Use transform for GPU acceleration */
  transform: scale(0.95);
}

.filter-toggle-btn:focus {
  outline: 2px solid #00aaff;
  outline-offset: 2px;
}

.filter-toggle-btn:focus-visible {
  outline: 3px solid #00aaff;
  outline-offset: 2px;
}

/* Active State - Blue background with white text */
.filter-toggle-btn.active {
  background: #00aaff;
  border-color: #00aaff;
  color: #ffffff;
  font-weight: 600;
}

.filter-toggle-btn.active:hover {
  background: #0099ee;
  border-color: #0099ee;
}

/* Modal Footer - Action Buttons */
.filter-modal-footer {
  padding: 15px 20px;
  border-top: 1px solid #e0e0e0;
  display: flex;
  gap: 10px;
  flex-shrink: 0;
  background: #ffffff;
}

.filter-modal-footer .btn {
  flex: 1;
  min-height: 48px;
  font-size: 16px;
  font-weight: 600;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.filter-modal-footer .btn:focus {
  outline: 2px solid #00aaff;
  outline-offset: 2px;
}

.filter-modal-footer .btn:focus-visible {
  outline: 3px solid #00aaff;
  outline-offset: 2px;
}

/* Reset Button */
.btn-reset {
  background: #f8f9fa;
  color: #666;
  border: 1px solid #ddd;
}

.btn-reset:hover {
  background: #e9ecef;
  color: #333;
}

.btn-reset:active {
  transform: scale(0.98);
  background: #dee2e6;
}

/* Apply Button */
.btn-apply {
  background: #00aaff;
  color: #ffffff;
}

.btn-apply:hover {
  background: #0099ee;
}

.btn-apply:active {
  transform: scale(0.98);
  background: #0088dd;
}

/* Hide Filter Modal on Desktop */
@media (min-width: 769px) {
  .mobile-filter-modal {
    display: none !important;
  }
}

/* Accessibility: High contrast mode support */
@media (prefers-contrast: high) {
  .filter-toggle-btn {
    border-width: 2px;
  }

  .filter-toggle-btn.active {
    border-width: 3px;
  }

  .filter-modal-footer .btn {
    border-width: 2px;
  }
}

/* Accessibility: Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .filter-modal-content {
    transition: none;
  }

  .filter-toggle-btn,
  .btn-close-modal,
  .filter-modal-footer .btn {
    transition: none;
  }

  .filter-toggle-btn:active,
  .filter-modal-footer .btn:active {
    transform: none;
  }
}

/* Loading Indicator */
.filter-loading {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, 0.95);
  padding: 20px 30px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 10000;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  color: #333;
}

.filter-loading i {
  font-size: 20px;
  color: #00aaff;
}

/* Prevent body scroll when modal is open */
body.modal-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
}

/* Small screen adjustments (iPhone SE, etc.) */
@media (max-width: 375px) {
  .filter-modal-content {
    width: 90%;
  }

  .filter-modal-header {
    padding: 15px;
  }

  .filter-modal-body {
    padding: 15px;
  }

  .filter-modal-footer {
    padding: 12px 15px;
  }

  .filter-toggle-btn {
    font-size: 13px;
    padding: 8px 14px;
  }
}

/* Large screen mobile adjustments (iPhone Pro Max, etc.) */
@media (min-width: 414px) and (max-width: 768px) {
  .filter-modal-content {
    width: 80%;
  }
}

/* ============================================================================
   Error Handling & Empty Results Styles
   Requirements: 16.1, 16.2, 16.3
   ============================================================================ */

/* Error Message Display in Modal */
.filter-error-message {
  background: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: 4px;
  padding: 12px 15px;
  margin-bottom: 15px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #856404;
  font-size: 14px;
  line-height: 1.5;
  position: relative;
  animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.filter-error-message i.fa-exclamation-triangle {
  font-size: 18px;
  color: #ffc107;
  flex-shrink: 0;
}

.filter-error-message span {
  flex: 1;
}

.filter-error-message .close-error {
  background: none;
  border: none;
  color: #856404;
  font-size: 18px;
  padding: 0;
  min-width: 30px;
  min-height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.2s ease;
}

.filter-error-message .close-error:hover {
  background: rgba(0, 0, 0, 0.05);
}

.filter-error-message .close-error:focus {
  outline: 2px solid #856404;
  outline-offset: 2px;
}

/* Empty Results Message */
.no-results-message {
  text-align: center;
  padding: 60px 20px;
  max-width: 400px;
  margin: 0 auto;
}

.no-results-icon {
  font-size: 48px;
  color: #ccc;
  margin-bottom: 20px;
}

.no-results-icon i {
  display: inline-block;
}

.no-results-text {
  font-size: 16px;
  color: #666;
  margin-bottom: 25px;
  line-height: 1.6;
}

.reset-filters-btn {
  min-height: 48px;
  padding: 12px 30px;
  font-size: 16px;
  font-weight: 600;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.reset-filters-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 170, 255, 0.3);
}

.reset-filters-btn:active {
  transform: translateY(0);
}

.reset-filters-btn:focus {
  outline: 2px solid #00aaff;
  outline-offset: 2px;
}

.reset-filters-btn:focus-visible {
  outline: 3px solid #00aaff;
  outline-offset: 2px;
}

/* Timeout/Network Error Specific Styling */
.filter-error-message.error-timeout {
  background: #f8d7da;
  border-color: #f5c6cb;
  color: #721c24;
}

.filter-error-message.error-timeout i {
  color: #dc3545;
}

/* Accessibility: High contrast mode support */
@media (prefers-contrast: high) {
  .filter-error-message {
    border-width: 2px;
  }

  .reset-filters-btn {
    border: 2px solid currentColor;
  }
}

/* Accessibility: Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .filter-error-message {
    animation: none;
  }

  .reset-filters-btn:hover {
    transform: none;
  }

  .reset-filters-btn:active {
    transform: none;
  }
}

/* Mobile-specific adjustments */
@media (max-width: 375px) {
  .no-results-message {
    padding: 40px 15px;
  }

  .no-results-icon {
    font-size: 40px;
  }

  .no-results-text {
    font-size: 14px;
  }

  .reset-filters-btn {
    min-height: 44px;
    font-size: 14px;
    padding: 10px 24px;
  }
}


/* ============================================================================
   Component 4: Mobile Sort Modal (Bottom Sheet)
   Requirements: 2.4, 5.2, 5.5, 5.6
   ============================================================================ */

/* Sort Modal Overlay - Fixed positioning with semi-transparent background */
.mobile-sort-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  /* Performance: Use CSS containment for isolated rendering */
  contain: layout style paint;
}

.mobile-sort-modal.active {
  display: block;
}

/* Overlay Background */
.sort-modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

/* Modal Content - Slide-in from bottom (bottom sheet style) */
.sort-modal-content {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s ease-out;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.2);
  border-radius: 16px 16px 0 0;
  max-height: 60vh;
  /* Performance: GPU acceleration for transform */
  will-change: transform;
  /* Performance: Use CSS containment for isolated component */
  contain: layout style paint;
}

.mobile-sort-modal.active .sort-modal-content {
  transform: translateY(0);
}

/* Sort Modal Header */
.sort-modal-header {
  padding: 20px;
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  background: #ffffff;
  border-radius: 16px 16px 0 0;
}

.sort-modal-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #333;
  line-height: 1.4;
}

/* Close Button - Touch-friendly 44x44px target */
.btn-close-sort-modal {
  background: none;
  border: none;
  font-size: 24px;
  color: #666;
  padding: 0;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.2s ease;
  border-radius: 4px;
}

.btn-close-sort-modal:hover {
  color: #333;
}

.btn-close-sort-modal:active {
  background: #f0f0f0;
}

.btn-close-sort-modal:focus {
  outline: 2px solid #00aaff;
  outline-offset: 2px;
}

.btn-close-sort-modal:focus-visible {
  outline: 3px solid #00aaff;
  outline-offset: 2px;
}

/* Sort Modal Body - Scrollable list of options */
.sort-modal-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Sort Option Buttons - Large touch-friendly buttons */
.sort-option-btn {
  width: 100%;
  min-height: 56px;
  padding: 16px 20px;
  border: none;
  border-bottom: 1px solid #f0f0f0;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: background 0.2s ease;
  text-align: left;
}

.sort-option-btn:hover {
  background: #f8f9fa;
}

.sort-option-btn:active {
  background: #e9ecef;
}

.sort-option-btn:focus {
  outline: 2px solid #00aaff;
  outline-offset: -2px;
  z-index: 1;
}

.sort-option-btn:focus-visible {
  outline: 3px solid #00aaff;
  outline-offset: -2px;
}

.sort-option-text {
  font-size: 16px;
  color: #333;
  font-weight: 400;
  flex: 1;
}

/* Check icon - shown only for active option */
.sort-option-check {
  font-size: 18px;
  color: #00aaff;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.sort-option-btn.active .sort-option-check {
  opacity: 1;
}

.sort-option-btn.active .sort-option-text {
  color: #00aaff;
  font-weight: 600;
}

/* Hide Sort Modal on Desktop */
@media (min-width: 769px) {
  .mobile-sort-modal {
    display: none !important;
  }
}

/* Accessibility: High contrast mode support */
@media (prefers-contrast: high) {
  .sort-option-btn {
    border-bottom-width: 2px;
  }

  .sort-option-btn.active {
    border: 2px solid #00aaff;
  }
}

/* Accessibility: Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .sort-modal-content {
    transition: none;
  }

  .sort-option-btn,
  .btn-close-sort-modal {
    transition: none;
  }
}

/* Small screen adjustments (iPhone SE, etc.) */
@media (max-width: 375px) {
  .sort-modal-header {
    padding: 15px;
  }

  .sort-option-btn {
    min-height: 52px;
    padding: 14px 15px;
  }

  .sort-option-text {
    font-size: 15px;
  }
}

/* Large screen mobile adjustments */
@media (min-width: 414px) and (max-width: 768px) {
  .sort-modal-content {
    max-height: 50vh;
  }
}
