/* Buy Page Styles - Modern Design inspired by AutoTrader.ca and Clutch.ca */

/* Page Layout */
.buy-page {
  min-height: 100vh;
  background: #f8fafc;
}

/* Header Section */
.buy-header {
  background: white;
  border-bottom: 1px solid #e5e7eb;
  padding: 2rem 0;
}

.buy-header-container {
  max-width: 80rem;
  margin: 0 auto;
  padding: 0 1rem;
}

.buy-header-content {
  text-align: center;
}

.buy-title {
  font-size: 3rem;
  font-weight: 800;
  color: #111827;
  margin-bottom: 1rem;
  line-height: 1.1;
}

.buy-subtitle {
  font-size: 1.25rem;
  color: #6b7280;
  max-width: 58rem;
  margin: 0 auto;
  line-height: 1.6;
}

/* Search and Filter Bar */
.search-filter-bar {
  background: white;
  border-bottom: 1px solid #e5e7eb;
  position: sticky;
  top: 4rem;
  z-index: 30;
  padding: 1rem 0;
}

.search-filter-container {
  max-width: 80rem;
  margin: 0 auto;
  padding: 0 1rem;
}

.search-filter-content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.search-bar-container {
  flex: 1;
}

.search-bar {
  position: relative;
}

.search-input {
  width: 100%;
  padding: 0.875rem 1rem 0.875rem 2.75rem;
  border: 2px solid #e5e7eb;
  border-radius: 0.75rem;
  font-size: 1rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  background: white;
}

.search-input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.search-input::placeholder {
  color: #9ca3af;
}

.search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.25rem;
  height: 1.25rem;
  color: #9ca3af;
  pointer-events: none;
}

.filter-toggle-button {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.875rem 1.5rem;
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: white;
  border-radius: 0.75rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background 0.2s ease;
  box-shadow: 0 4px 6px -1px rgba(59, 130, 246, 0.3);
}

.filter-toggle-button:hover {
  background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
}

.filter-badge {
  background: white;
  color: #2563eb;
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
  border-radius: 1rem;
  font-weight: 700;
}

/* Advanced Filters Panel */
.filters-panel {
  margin-top: 1.5rem;
  padding: 1.5rem;
  background: #f8fafc;
  border-radius: 0.75rem;
  border: 1px solid #e5e7eb;
}

.filters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.filter-group {
  display: flex;
  flex-direction: column;
}

.filter-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: #374151;
  margin-bottom: 0.2rem;
}

.filter-select,
.filter-input {
  width: 100%;
  padding: 0.6rem;
  border: 2px solid #e5e7eb;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  background: white;
}

.filter-select:focus,
.filter-input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.filter-select:disabled {
  background: #f3f4f6;
  color: #9ca3af;
  cursor: not-allowed;
}

.filter-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 1rem;
  border-top: 1px solid #e5e7eb;
}

.clear-filters-button {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #6b7280;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.875rem;
  transition: color 0.2s ease;
}

.clear-filters-button:hover {
  color: #374151;
}

.results-count {
  font-size: 0.875rem;
  color: #6b7280;
}

/* Results Section */
.results-section {
  padding: 2rem 0;
}

.results-container {
  max-width: 80rem;
  margin: 0 auto;
  padding: 0 1rem;
}

.results-header {
  display: flex;
  justify-content: space-between;
  /* align-items: flex-start; */
  margin-bottom: 1.5rem;
}

.results-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: #111827;
  margin-bottom: 0.25rem;
}

.results-subtitle {
  color: #6b7280;
  font-size: 0.875rem;
}

/* Cars Grid */
.cars-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-bottom: 3rem;
}

/* Loading State */
.loading-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
}

.loading-card {
  background: white;
  border-radius: 1rem;
  border: 1px solid #e5e7eb;
  overflow: hidden;
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.loading-image {
  height: 14rem;
  background: #e5e7eb;
}

.loading-content {
  padding: 1.25rem;
}

.loading-line {
  height: 1rem;
  background: #e5e7eb;
  border-radius: 0.25rem;
  margin-bottom: 0.75rem;
}

.loading-line:last-child {
  margin-bottom: 0;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 4rem 0;
}

.empty-state-icon {
  width: 6rem;
  height: 6rem;
  color: #d1d5db;
  margin: 0 auto 1rem;
}

.empty-state-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: #6b7280;
  margin-bottom: 0.5rem;
}

.empty-state-description {
  color: #9ca3af;
  margin-bottom: 1.5rem;
}

.empty-state-button {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 0.5rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background 0.2s ease;
}

.empty-state-button:hover {
  background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  margin-top: 3rem;
}

.pagination-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.pagination-button {
  padding: 0.5rem 1rem;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  background: white;
  color: #374151;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.pagination-button:hover:not(:disabled) {
  background: #f9fafb;
  border-color: #9ca3af;
}

.pagination-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pagination-button-active {
  background: #2563eb;
  color: white;
  border-color: #2563eb;
}

.pagination-button-active:hover {
  background: #2563eb;
  border-color: #2563eb;
}

.pagination-ellipsis {
  padding: 0.5rem;
  color: #6b7280;
}

/* Responsive Design */
@media (max-width: 1024px) {
  .search-filter-content {
    flex-direction: column;
  }
  
  .filter-toggle-button {
    align-self: flex-start;
  }
}

@media (max-width: 768px) {
  .buy-title {
    font-size: 2.25rem;
  }
  
  .buy-subtitle {
    font-size: 1.125rem;
  }
  
  .filters-grid {
    grid-template-columns: 1fr;
  }
  
  .cars-grid {
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  }
  
  .results-header {
    flex-direction: column;
    gap: 0.5rem;
  }
}

@media (max-width: 480px) {
  .buy-title {
    font-size: 1.875rem;
  }
  
  .cars-grid {
    grid-template-columns: 1fr;
  }
  
  .pagination-container {
    flex-wrap: wrap;
    justify-content: center;
  }
}

/* Catalog Section - moved to top, right after header */
.catalog-section {
  background: white;
  padding: 2rem 0;
  border-bottom: 1px solid #e5e7eb;
}

.catalog-container {
  max-width: 80rem;
  margin: 0 auto;
  padding: 0 1rem;
}

.catalog-title {
  font-size: 1.875rem;
  font-weight: 700;
  color: #111827;
  margin-bottom: 2rem;
  text-align: center;
}

.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(50px, 1fr));
  gap: 1rem;
  max-width: 80rem;
  margin: 0 auto;
}

.catalog-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  /* gap: 0.75rem; */
  /* padding: 1.5rem 1rem; */
  background: white;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  /* border-radius: 0.75rem; */
  cursor: pointer;
  transition: background 0.2s ease, box-shadow 0.2s ease;
  text-align: center;
}

.catalog-button:hover {
  border: none !important;
  outline: none !important;
  background: #eff6ff;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
}

.catalog-button-active {
  border: none !important;
  outline: none !important;
  background: #eff6ff;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}

.catalog-icon {
  width: 100%;
  height: 100%;
  display: flex;
  border-radius: 0.6rem;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  overflow: hidden;
  align-items: center;
  justify-content: center;
}

.catalog-icon img {
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  display: block;
}

.catalog-label {
  display: none;
}

.catalog-button-active .catalog-label {
  color: #2563eb;
}

@media (max-width: 768px) {
  .catalog-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
  }
  
  .catalog-button {
    padding: 1rem 0.75rem;
  }
  
  .catalog-icon {
    width: 100%;
    height: 100%;
  }
  
  .catalog-title {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
  }
}

@media (max-width: 480px) {
  .catalog-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
  }
  
  .catalog-icon {
    max-width: 150px;
    max-height: 150px;
  }
  
  .catalog-label {
    font-size: 0.7rem;
  }
}

/* Main Container - Desktop Sidebar Layout */
.buy-main-container {
  display: flex;
  gap: 2rem;
  max-width: 80rem;
  margin: 0 auto;
  padding: 2rem 1rem;
  /* align-items: flex-start; */
}

/* Filters Sidebar - Desktop */
.filters-sidebar {
  width: 100%;
  max-width: 20rem;
  flex-shrink: 0;
  position: sticky;
  top: 5rem;
  height: fit-content;
  max-height: calc(100vh - 6rem);
  overflow-y: auto;
}

/* Search and Filter Bar - Mobile (kept for backward compatibility) */
.search-filter-bar {
  background: white;
  border-bottom: 1px solid #e5e7eb;
  position: sticky;
  top: 4rem;
  z-index: 30;
  padding: 1rem 0;
}

/* Hide sidebar on mobile, show search-filter-bar instead */
@media (max-width: 1023px) {
  .buy-main-container {
    flex-direction: column;
    padding: 0;
  }
  
  .filters-sidebar {
    width: 100%;
    max-width: 100%;
    position: static;
    top: auto;
    max-height: none;
    padding: 0;
  }
  
  .search-filter-bar {
    display: block;
  }
  
  .filters-panel {
    margin-top: 1.5rem;
    padding: 1.5rem;
    background: #f8fafc;
    border-radius: 0.75rem;
    border: 1px solid #e5e7eb;
    overflow: hidden;
  }
}

/* Desktop: Hide mobile filter toggle, show sidebar always */
@media (min-width: 1024px) {
  .search-filter-bar {
    display: none;
  }
  
  .filter-toggle-button.mobile-only {
    display: none;
  }
  
  .filters-panel {
    margin-top: 0;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0;
  }
  
  .filters-sidebar {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
    padding: 1.5rem;
  }
  
  .search-bar-container {
    margin-bottom: 1.5rem;
  }
}

/* Mobile: Show filter toggle button */
@media (max-width: 1023px) {
  .filter-toggle-button.mobile-only {
    display: flex;
  }
  
  .search-filter-container {
    max-width: 80rem;
    margin: 0 auto;
    padding: 0 1rem;
  }
  
  .search-filter-content {
    display: flex;
    flex-direction: row;
    gap: 1rem;
    align-items: center;
  }
}

/* Main Content Area - remove catalog margin since it's now separate */
.buy-content-main {
  flex: 1;
  min-width: 0; /* Prevents flex item from overflowing */
}

/* Results Section - adjust for new layout */
.results-section {
  padding: 0;
}

/* ===== 设计改进 A4：更宽的内容区、宽屏 3 列、浅色车型图标行 ===== */
.buy-main-container,
.catalog-container {
  max-width: 82.5rem; /* 1320px */
}

@media (min-width: 1024px) {
  .filters-sidebar {
    max-width: 17rem;
  }
}

.results-container {
  max-width: none;
  padding: 0;
}

.cars-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.25rem;
}

@media (min-width: 1200px) {
  .cars-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 1023px) {
  .results-container {
    padding: 0 1rem;
  }
}

@media (max-width: 640px) {
  .cars-grid {
    grid-template-columns: 1fr;
  }
}

.catalog-section {
  padding: 1rem 0;
}

.catalog-title {
  font-size: 1rem;
  font-weight: 600;
  color: #374151;
  margin-bottom: 0.75rem;
  text-align: left;
}

.catalog-grid {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  padding-bottom: 0.25rem;
}

.catalog-button {
  flex: 0 0 auto;
  scroll-snap-align: start;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.125rem;
  min-width: 5.25rem;
  max-height: 80px;
  padding: 0.375rem 0.75rem !important;
  background: #f1f5f9;
  border: 1px solid transparent !important;
  border-radius: 0.625rem;
  color: #374151;
}

.catalog-button:hover {
  background: #e2e8f0;
  box-shadow: none !important;
}

.catalog-button:focus-visible {
  outline: 2px solid #2563eb !important;
  outline-offset: 2px;
}

.catalog-button-active {
  background: #dbeafe;
  border-color: #2563eb !important;
  box-shadow: none !important;
}

.catalog-icon {
  width: 56px !important;
  height: 28px !important;
  max-width: none !important;
  max-height: none !important;
  border-radius: 0;
  background: transparent;
}

/* 图标原图是黑底白线并带文字：反色成白底黑线，再用 multiply 融进浅灰背景；只显示车身，不显示图里的文字 */
.catalog-icon img {
  width: 56px !important;
  height: 28px !important;
  aspect-ratio: auto !important;
  object-fit: cover !important;
  object-position: 50% 14% !important;
  filter: invert(1);
  mix-blend-mode: multiply;
}

.catalog-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
}

@media (max-width: 768px) {
  .catalog-title {
    font-size: 0.9375rem;
    margin-bottom: 0.5rem;
  }
}

@media (min-width: 1024px) {
  .catalog-grid {
    justify-content: flex-start;
  }
}
