/* 
  Global Auto Experts - Responsive Media Queries
  Handles: Mobile, Tablet, Small Desktop, Large Screen Layout Shifts
*/

/* 1. Large Desktops & Normal Laptops (Up to 1200px) */
@media (max-width: 1200px) {
  h1 { font-size: 2.2rem; }
  .footer-grid {
    grid-template-columns: 1.5fr repeat(3, 1fr);
  }
}

/* 2. Small Desktops & Tablets Landscape (Up to 992px) */
@media (max-width: 992px) {
  :root {
    --header-height: auto;
  }
  
  .top-bar {
    display: none; /* Hide top bar on tablets and mobiles for space */
  }

  .header-main-row {
    padding: 12px 0;
    flex-wrap: wrap;
    gap: 12px;
  }

  .logo {
    order: 1;
  }

  .header-actions {
    order: 2;
    gap: 14px;
  }

  .search-container {
    order: 3;
    width: 100%;
    max-width: 100%;
    margin-top: 4px;
  }

  .nav-row {
    display: none; /* Hide desktop horizontal navigation */
  }

  .nav-row.active {
    display: block !important;
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    background-color: var(--color-dark-bg);
    border-top: 1px solid var(--color-dark-border);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.35);
    z-index: 1020;
  }

  .nav-row.active .main-nav {
    display: flex !important;
    flex-direction: column !important;
    padding: 16px 20px;
    gap: 8px;
    align-items: flex-start;
  }

  .nav-row.active .nav-item {
    width: 100%;
  }

  .nav-row.active .nav-link {
    width: 100%;
    padding: 12px 16px !important;
    border-radius: var(--radius-md);
    color: black;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .nav-row.active .nav-link:hover {
    background-color: rgba(255, 255, 255, 0.08);
  }

  .mega-menu {
    display: none !important; /* Hide mega menus on mobile devices */
  }

  /* Show mobile hamburger toggle */
  .mobile-nav-toggle {
    display: block;
    order: 1;
  }

  .vehicle-selector-bar {
    padding: 12px 0;
  }

  .vehicle-bar-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .vehicle-selector-fields {
    width: 100%;
    flex-wrap: wrap;
  }

  .vehicle-select {
    flex-grow: 1;
  }

  .vehicle-btn {
    width: 100%;
  }

  /* Product details and sliders responsive */
  .footer-grid {
    grid-template-columns: 1fr 1fr;
    gap: 32px;
  }

  .footer-brand {
    grid-column: span 2;
    max-width: 100%;
  }

  /* Modal body grid responsive */
  .modal-body-grid {
    grid-template-columns: 1fr;
  }

  .modal-gallery {
    padding: 20px;
  }

  .modal-gallery img {
    max-height: 200px;
  }

  .modal-info {
    padding: 20px;
  }

  .hero-grid-split {
    grid-template-columns: 1fr !important;
    gap: 32px !important;
  }

  .product-tabs-grid {
    grid-template-columns: 1fr;
    gap: 32px;
  }
}

/* 3. Tablets Portrait (Up to 768px) */
@media (max-width: 768px) {
  h1 { font-size: 1.8rem; }
  h2 { font-size: 1.5rem; }
  
  .section {
    padding: 40px 0;
  }

  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 24px;
  }

  section .container[style*="grid-template-columns"] > * {
    min-width: 0 !important;
  }

  .product-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)) !important;
    gap: 12px !important;
  }

  .product-card-image-wrap {
    height: 140px;
    padding: 8px;
  }

  .product-card-content {
    padding: 12px;
  }

  .product-card-title {
    font-size: 0.8rem;
    height: 36px;
    margin-bottom: 4px;
  }

  .product-price {
    font-size: 0.95rem;
  }

  .add-to-cart-icon-btn {
    width: 32px;
    height: 32px;
  }

  .add-to-cart-icon-btn svg {
    width: 14px;
    height: 14px;
  }

  .page-header-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  /* Table / Cart columns wrap */
  .cart-table, .cart-table tbody, .cart-table tr, .cart-table td {
    display: block;
    width: 100%;
  }

  .cart-table thead {
    display: none;
  }

  .cart-table tr {
    margin-bottom: 16px;
    border: 1px solid var(--color-light-border);
    border-radius: var(--radius-md);
    padding: 12px;
    background-color: var(--color-light-surface);
  }

  .cart-table td {
    border-bottom: none;
    padding: 8px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .cart-table td:before {
    content: attr(data-label);
    font-weight: 600;
    font-family: var(--font-display);
    font-size: 0.8rem;
    color: var(--color-text-muted);
  }

  .cart-table td.product-cell {
    justify-content: flex-start;
    gap: 12px;
  }

  .cart-table td.product-cell:before {
    display: none;
  }

  .cart-grid {
    grid-template-columns: 1fr;
  }

  .product-gallery-details-grid {
    grid-template-columns: 1fr;
    gap: 32px;
    margin-bottom: 32px;
  }

  .product-gallery-main-wrap {
    height: 320px;
  }
}

/* 4. Small Mobile Screens (Up to 480px) */
@media (max-width: 480px) {
  .logo {
    font-size: 1.25rem;
  }

  .logo-icon {
    width: 28px;
    height: 28px;
    font-size: 0.85rem;
  }

  .container {
    padding-left: 16px;
    padding-right: 16px;
  }

  .footer-grid {
    grid-template-columns: 1fr;
  }

  .footer-brand {
    grid-column: span 1;
  }

  .footer-bottom-inner {
    flex-direction: column;
    gap: 12px;
    text-align: center;
  }

  .btn {
    width: 100%;
  }

  .product-actions-row {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .product-actions-row > div {
    width: 100%;
    justify-content: center;
  }
}

/* ==========================================================================
   5. Custom Component Overrides for Search Widget, Categories, and Reviews
   ========================================================================== */
.category-bento-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}

.reviews-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}

/* Base Product Card Image Optimizations (Desktop & Mobile) */
.product-card-image-wrap {
  padding: 0 !important; /* Elegant full-bleed header images */
  background-color: #fcfcfc !important;
  height: 180px !important;
  overflow: hidden !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  position: relative !important;
}

.product-card-image {
  width: 100% !important;
  height: 100% !important;
  max-width: 100% !important;
  max-height: 100% !important;
  object-fit: cover !important; /* Guarantees crisp, undistorted aspect ratios on all viewports */
  transition: transform var(--transition-slow) !important;
}

/* Category Bento Box Typography Wrap Safeguard */
.category-bento-grid a {
  display: flex !important;
  flex-direction: column !important;
  justify-content: flex-end !important;
  text-decoration: none !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
}

.category-bento-grid a h3 {
  font-family: var(--font-display) !important;
  font-size: 1.3rem !important;
  margin-bottom: 4px !important;
  color: #ffffff !important;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.45) !important;
  word-wrap: break-word !important;
  overflow-wrap: break-word !important;
  white-space: normal !important;
  line-height: 1.2 !important;
}

.category-bento-grid a span {
  font-size: 0.72rem !important;
  color: #f1f5f9 !important;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45) !important;
  display: block !important;
  line-height: 1.2 !important;
}

/* Professional spacing adjustments for reviews */
.reviews-grid > div {
  padding: 24px !important;
  box-sizing: border-box !important;
}

@media (max-width: 992px) {
  .category-bento-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
  }
  .reviews-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
  }
  .category-bento-grid a h3 {
    font-size: 1.15rem !important;
  }
}

@media (max-width: 768px) {
  .category-bento-grid {
    grid-template-columns: 1fr !important;
    gap: 16px;
  }
  .reviews-grid {
    grid-template-columns: 1fr !important;
    gap: 16px;
    padding-left: 0;
    padding-right: 0;
  }
  .reviews-grid > div {
    padding: 20px !important;
  }
  
  /* Mobile-first Product Card Improvements */
  .product-card-image-wrap {
    height: 140px !important;
    padding: 0 !important;
  }

  .product-card-footer {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
    margin-top: 12px !important;
  }

  .product-card-footer .product-price-box {
    flex-direction: row !important;
    align-items: baseline !important;
    gap: 8px !important;
    margin-bottom: 2px !important;
  }

  /* Full-width interactive touch zones for mobile product actions */
  .product-card-footer > div:not(.product-price-box) {
    display: flex !important;
    width: 100% !important;
    gap: 8px !important;
  }

  .product-card-footer > div:not(.product-price-box) .btn,
  .product-card-footer > div:not(.product-price-box) .add-to-cart-icon-btn {
    flex: 1 1 0% !important;
    width: auto !important;
    height: 40px !important; /* Fulfills touch target guidelines beautifully */
    padding: 0 8px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 0.75rem !important;
    border-radius: var(--radius-sm) !important;
  }

  .search-everything-box {
    padding: 20px !important;
    margin-top: -30px !important;
  }
  .search-tabs {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
    border-bottom: none !important;
    margin-bottom: 20px !important;
  }
  .search-tab-btn {
    padding: 10px 8px !important;
    font-size: 0.72rem !important;
    border: 1px solid var(--color-light-border) !important;
    border-radius: var(--radius-md) !important;
    background-color: var(--color-light-bg) !important;
    justify-content: start !important;
    width: 100% !important;
    margin-bottom: 0 !important;
    white-space: normal !important;
    text-align: center !important;
    height: auto !important;
    min-height: 44px !important;
    box-sizing: border-box !important;
  }
  .search-tab-btn.active {
    background-color: var(--color-primary) !important;
    color: #ffffff !important;
    border-color: var(--color-primary) !important;
  }
  .search-form-row {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  .search-form-row-2 {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  .search-form-group {
    width: 100% !important;
  }
  .search-form-input {
    width: 100% !important;
    box-sizing: border-box !important;
  }
}

@media (max-width: 480px) {
  .search-tabs {
    grid-template-columns: 1fr !important;
  }
}

/* ==========================================================================
   6. General Mobile & Tablet Cleanliness, Grid Collapsing & Pagination Fixes
   ========================================================================== */
@media (max-width: 992px) {
  /* Collapse inline 3-column & 4-column grids on tablets/mobiles */
  div[style*="grid-template-columns:repeat(3, 1fr)"],
  div[style*="grid-template-columns: repeat(3, 1fr)"],
  div[style*="grid-template-columns:repeat(4, 1fr)"],
  div[style*="grid-template-columns: repeat(4, 1fr)"] {
    grid-template-columns: 1fr !important;
    gap: 20px !important;
  }
  
  /* Prevent horizontal squeeze in generic flex containers */
  div[style*="display:flex"][style*="justify-content:space-between"] {
    flex-wrap: wrap !important;
    gap: 12px !important;
  }
}

@media (max-width: 768px) {
  /* Force all 2-column inline layouts to stack on mobile */
  div[style*="grid-template-columns:1fr 1fr"],
  div[style*="grid-template-columns: 1fr 1fr"],
  div[style*="grid-template-columns:1.2fr 1fr"],
  div[style*="grid-template-columns: 1.2fr 1fr"],
  div[style*="grid-template-columns:repeat(2, 1fr)"],
  div[style*="grid-template-columns: repeat(2, 1fr)"] {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  /* Specific marketplace car grid adjustments to avoid horizontal clipping */
  #used-cars-marketplace-grid {
    grid-template-columns: 1fr !important;
    gap: 24px !important;
  }

  /* Compact responsive padding for pricing cards */
  div[style*="border-radius:var(--radius-lg)"][style*="padding:32px"],
  div[style*="border-radius:var(--radius-lg)"][style*="padding: 40px"] {
    padding: 24px 20px !important;
  }

  /* Beautiful mobile-optimized pagination wrapping */
  #catalog-pagination {
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
    gap: 6px !important;
    margin-top: 9px !important;
  
  }
  
  #catalog-pagination button {
    padding: 6px 10px !important;
    min-width: 32px !important;
    height: 32px !important;
    font-size: 0.75rem !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  /* Hide excessive breadcrumb steps on mobile if they don't fit */
  .breadcrumbs {
    flex-wrap: wrap !important;
    justify-content: center !important;
    font-size: 0.8rem !important;
  }

  /* Stack inputs with side buttons on mobile */
  .input-with-button {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
  }
  .input-with-button > input {
    width: 100% !important;
  }
  .input-with-button > button {
    width: 100% !important;
    justify-content: center !important;
    padding: 12px 16px !important;
    height: auto !important;
  }
}


