/**
 * Public marketplace mobile layout fixes (≤1023px).
 * Filter sheets, chip scrollers, map gating, FAB clearance.
 */

/* —— Chip / category rows: scroll, don’t wrap —— */
@media (max-width: 1023px) {
  .ccc-explore-chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    margin-inline: calc(-1 * var(--gutter, 1rem));
    padding-inline: var(--gutter, 1rem);
    padding-bottom: 0.25rem;
  }
  .ccc-explore-chips::-webkit-scrollbar {
    display: none;
  }
  .ccc-explore-chips a {
    flex: 0 0 auto;
    white-space: nowrap;
  }
}

/* —— Explore: filters as bottom sheet on mobile —— */
.mp-filter-bar {
  display: none;
}

.mp-filter-backdrop {
  display: none;
}

@media (max-width: 1023px) {
  .mp-explore {
    padding-top: var(--space-3);
  }

  .mp-filter-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
  }

  .mp-filters {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    z-index: 220;
    max-height: min(88vh, 640px);
    margin: 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: 0 -12px 40px rgba(15, 23, 42, 0.18);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transform: translateY(110%);
    transition: transform 0.28s ease;
    padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
  }

  .mp-filters.is-open {
    transform: translateY(0);
  }

  .mp-filters__sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 1;
    padding-top: 0.25rem;
  }

  .mp-filter-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 210;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  .mp-filter-backdrop.is-open {
    opacity: 1;
    pointer-events: auto;
  }

  .mp-explore .mp-results-list {
    order: 1;
  }

  /* Map only when explicitly in map view on mobile */
  .mp-map-panel,
  .mp-map-panel.is-visible {
    display: none !important;
  }

  .mp-explore[data-view="map"] .mp-map-panel {
    display: block !important;
    min-height: 0;
    padding: var(--space-2);
  }

  .mp-explore[data-view="map"] .mp-explore-map {
    height: min(70vh, 480px);
    min-height: 280px;
  }

  .mp-explore[data-view="map"] .mp-results-list {
    display: none;
  }

  .mp-result-card__actions {
    min-width: 0;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .mp-result-card__actions .ec-btn {
    flex: 1 1 auto;
  }
}

@media (min-width: 1024px) {
  .mp-filters__sheet-head .mp-filter-close {
    display: none;
  }

  .mp-explore[data-view="list"] .mp-map-panel {
    display: block;
  }

  .mp-explore[data-view="map"] .mp-map-panel {
    display: block;
  }
}

/* —— Parts: sidebar as sheet; results first —— */
.mp-parts-filter-bar {
  display: none;
}

@media (max-width: 959px) {
  .mp-parts-filter-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
  }

  .mp-parts-layout {
    display: flex;
    flex-direction: column;
  }

  .mp-parts-main {
    order: 1;
  }

  .mp-parts-sidebar {
    order: 0;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 220;
    max-height: min(88vh, 680px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--surface);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: 0 -12px 40px rgba(15, 23, 42, 0.18);
    padding: var(--space-4);
    padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
    transform: translateY(110%);
    transition: transform 0.28s ease;
  }

  .mp-parts-sidebar.is-open {
    transform: translateY(0);
  }

  .mp-parts-sidebar__sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-3);
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 1;
  }

  /* Horizontal category chips when sheet closed preview not needed — inside sheet only */
  .mp-parts-categories ul {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 0.4rem;
    list-style: none;
    margin: 0 0 var(--space-3);
    padding: 0 0 0.35rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .mp-parts-categories ul::-webkit-scrollbar {
    display: none;
  }

  .mp-parts-categories li {
    flex: 0 0 auto;
  }

  .mp-parts-cat {
    white-space: nowrap;
  }

  .mp-parts-vehicle {
    flex-wrap: wrap;
  }

  .mp-parts-vehicle .ec-select {
    min-width: 0;
    flex: 1 1 100%;
  }
}

@media (min-width: 960px) {
  .mp-parts-sidebar__sheet-head {
    display: none;
  }
}

/* —— Assistance: denser type cards —— */
@media (max-width: 480px) {
  .mp-assist-type__thumb {
    min-height: 3.5rem;
    aspect-ratio: 21 / 9;
  }

  .mp-assist-type {
    min-height: 0;
    padding: var(--space-2) var(--space-3);
  }
}

/* —— Home hero stats: don’t crush —— */
@media (max-width: 480px) {
  .ccc-hero-stage__stats {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .ccc-hero-stage__stats::-webkit-scrollbar {
    display: none;
  }

  .ccc-hero-stage__stats > div {
    flex: 0 0 auto;
    min-width: 7.5rem;
    border-right: 1px solid rgba(255, 255, 255, 0.2);
  }
}

/* —— FAB clearance so chips/CTAs stay tappable —— */
.ec-body {
  padding-bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px));
}

@media (min-width: 960px) {
  .ec-body {
    padding-bottom: 0;
  }
}

.ec-assistant-fab {
  bottom: calc(1.1rem + env(safe-area-inset-bottom, 0px));
  right: calc(1.1rem + env(safe-area-inset-right, 0px));
}

/* —— Header: less crowding —— */
@media (max-width: 480px) {
  .header-main__login {
    padding: 0.38rem 0.55rem;
    font-size: 0.75rem;
  }

  .header-main__actions {
    gap: 0.35rem;
  }
}

/* —— Prefer reduced motion: kill carousel “refresh” feel —— */
@media (prefers-reduced-motion: reduce) {
  .ccc-hero-carousel__slide,
  .ccc-services-showcase__panel,
  [data-home-quote] {
    transition: none !important;
  }
}
