/* ============================================================
   LISTING.CSS — Cards + Listing Detail Page
   Mobile-first · Brand-strict · No shortcuts
   ============================================================ */

/* ═══════════════════════════════════════════════════════════════
   PART 1 — LISTING CARD GRID (mobile-first)
   ═══════════════════════════════════════════════════════════════ */

.listings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

@media (min-width: 640px) {
  .listings-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
  }
}

@media (min-width: 900px) {
  .listings-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 24px;
  }
}

/* ═══════════════════════════════════════════════════════════════
   LISTING CARD COMPONENT
   ═══════════════════════════════════════════════════════════════ */

.listing-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: transform var(--trans), box-shadow var(--trans), border-color var(--trans);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  color: inherit;
  display: block;
}
.listing-card:hover {
  transform: translateY(-6px);
  box-shadow: var(--shadow-card-hover);
  border-color: var(--mnuc-blue);
}

/* 4:3 Aspect Ratio Image */
.listing-img-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: linear-gradient(135deg, rgba(0, 82, 255, 0.06), rgba(201, 162, 39, 0.08));
}
.listing-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  transition: transform 400ms cubic-bezier(0.16, 1, 0.3, 1);
}
.listing-card:hover .listing-img { transform: scale(1.05); }

/* Promoted ribbon */
.promoted-ribbon {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(14, 32, 64, 0.85);
  color: var(--white);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 2;
}

/* Airbnb-style floating heart */
.save-listing-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: none;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform var(--trans), background var(--trans);
  -webkit-tap-highlight-color: transparent;
}
.save-listing-btn:hover { transform: scale(1.1); background: var(--white); }
.save-listing-btn:active { transform: scale(0.92); }
.save-listing-btn svg {
  width: 18px;
  height: 18px;
  color: var(--mnuc-navy);
  fill: none;
  stroke: var(--mnuc-navy);
  stroke-width: 2;
}
.save-listing-btn.saved svg {
  color: var(--red);
  fill: var(--red);
  stroke: var(--red);
}
.save-listing-btn span { display: none; }

/* Card body — mobile tightened for 2-up density */
.listing-body { padding: 8px 6px; }
.listing-cat {
  font-size: 0.68rem;
  font-weight: 800;
  color: var(--mnuc-blue);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 4px;
}
.listing-title {
  font-family: var(--ff-head);
  font-weight: 700;
  font-size: 0.88rem;
  line-height: 1.3;
  margin-bottom: 4px;
  color: var(--mnuc-navy);
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.listing-price {
  font-family: var(--ff-head);
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text);
}
.listing-price small {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
}
.listing-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
  color: var(--text-muted);
}

@media (min-width: 640px) {
  .listing-body { padding: 12px 14px; }
  .listing-cat { font-size: 0.7rem; margin-bottom: 6px; }
  .listing-title {
    font-size: 1rem;
    -webkit-line-clamp: 2;
    margin-bottom: 8px;
  }
  .listing-price { font-size: 1.1rem; }
  .listing-meta {
    margin-top: 12px;
    padding-top: 12px;
    font-size: 0.8rem;
  }
}

/* ═══════════════════════════════════════════════════════════════
   SKELETONS
   ═══════════════════════════════════════════════════════════════ */

.skeleton-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.skeleton-img {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: linear-gradient(90deg, rgba(14,32,64,0.04) 25%, rgba(14,32,64,0.08) 50%, rgba(14,32,64,0.04) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease infinite;
}
.skeleton-img-lg { aspect-ratio: 16 / 10; }
.skeleton-body { padding: 12px 14px; }
.skeleton-line {
  height: 10px;
  border-radius: 6px;
  background: linear-gradient(90deg, rgba(14,32,64,0.04) 25%, rgba(14,32,64,0.08) 50%, rgba(14,32,64,0.04) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease infinite;
  margin-bottom: 8px;
}
.skeleton-line.short { width: 40%; }
.skeleton-line.price { width: 50%; height: 14px; }
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ═══════════════════════════════════════════════════════════════
   LAYOUT UTILITIES (listing-specific)
   ═══════════════════════════════════════════════════════════════ */

.flex-wrap { flex-wrap: wrap; }
.listing-state-card { max-width: 680px; margin: 40px auto; }
.listing-meta-start {
  justify-content: flex-start !important;
  flex-wrap: wrap;
}

/* ═══════════════════════════════════════════════════════════════
   MAIN IMAGE PLACEHOLDER — intentional gradient fallback
   ═══════════════════════════════════════════════════════════════ */

.main-img-placeholder {
  display: grid;
  place-items: center;
  text-align: center;
  padding: 40px 24px;
  background:
    radial-gradient(circle at 30% 20%, rgba(0, 82, 255, 0.06) 0%, transparent 50%),
    radial-gradient(circle at 70% 80%, rgba(201, 162, 39, 0.08) 0%, transparent 50%),
    linear-gradient(135deg, rgba(14, 32, 64, 0.03), rgba(14, 32, 64, 0.01));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  aspect-ratio: 4 / 3;
}
.main-img-placeholder .badge { margin-bottom: 12px; }
.main-img-placeholder .listing-info-title { font-size: 1.1rem; }
.main-img-placeholder .text-muted { font-size: 0.85rem; }

/* ═══════════════════════════════════════════════════════════════
   RATING WIDGET (already styled — preserved here)
   ═══════════════════════════════════════════════════════════════ */

.rating-widget {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-top: 16px;
  box-shadow: var(--shadow-sm);
}
.rating-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}
.rating-label-muted { opacity: 0.7; }
.rating-summary {
  display: flex;
  align-items: center;
  gap: 6px;
}
.rating-avg {
  font-size: 1rem;
  font-weight: 800;
  color: var(--text);
  margin-left: 4px;
}
.rating-total {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.rating-empty {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.rate-section { margin-top: 16px; }
.star-input {
  display: flex;
  gap: 4px;
}
.star-input-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  transition: transform 0.15s ease, color 0.15s ease;
  color: var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
}
.star-input-btn.active { color: var(--mnuc-gold); }
.star-input-btn svg { width: 24px; height: 24px; }
.star-icon { width: 20px; height: 20px; display: inline-block; }
.star-filled { color: var(--mnuc-gold); }
.star-empty { color: var(--border-strong); }
.rated-you-badge {
  font-size: 0.75rem;
  color: var(--mnuc-blue);
  margin-top: 8px;
  font-weight: 700;
}
.review-area { margin-top: 12px; }
.review-textarea {
  width: 100%;
  min-height: 80px;
  resize: vertical;
  font-family: var(--ff-body);
  box-sizing: border-box;
}
.rating-reviews-list { margin-top: 16px; }
.review-card {
  padding: 12px 0;
  border-top: 1px solid var(--border);
}
.review-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.review-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
}
.review-stars { display: flex; gap: 2px; }
.review-stars .star-icon { width: 16px; height: 16px; }
.review-body {
  font-size: 0.85rem;
  color: var(--text);
  line-height: 1.5;
}

/* ═══════════════════════════════════════════════════════════════
   ═══════════════════════════════════════════════════════════════
   PART 2 — LISTING DETAIL PAGE LAYOUT
   ═══════════════════════════════════════════════════════════════
   ═══════════════════════════════════════════════════════════════ */

/* ── Page Container ── */
.listing-page {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 0 100px;
}

/* ── Grid (mobile = single column) ── */
.listing-page-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  padding: 16px;
}

/* ── Gallery (left column) ── */
.listing-gallery {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

/* Main image */
.main-img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  object-position: top center;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, rgba(0, 82, 255, 0.04), rgba(201, 162, 39, 0.06));
}

/* Thumbnail strip */
.thumb-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding: 4px 0 8px;
}
.thumb-row::-webkit-scrollbar { display: none; }

.thumb {
  flex: 0 0 auto;
  width: 56px;
  height: 56px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color var(--trans), opacity var(--trans);
  opacity: 0.6;
  -webkit-tap-highlight-color: transparent;
}
.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
}
.thumb.active,
.thumb:hover {
  border-color: var(--mnuc-blue);
  opacity: 1;
}
.thumb:active { transform: scale(0.95); }

/* ── Gallery card sections ── */
.listing-gallery > .card { margin-top: 0; }
.listing-gallery > .card.mt-2 { margin-top: 16px; }

/* ── Listing meta inside gallery ── */
.listing-gallery .listing-meta {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* ── Info Card (aside) ── */
.listing-info-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Price */
.listing-info-price {
  font-family: var(--ff-head);
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--mnuc-navy);
  line-height: 1.1;
}

/* Title in aside */
.listing-info-title {
  font-family: var(--ff-head);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--mnuc-navy);
  line-height: 1.3;
}

/* ── Seller Card — horizontal compact ── */
.seller-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.seller-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--mnuc-navy), var(--mnuc-blue));
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--ff-head);
  font-size: 1rem;
  font-weight: 800;
  flex-shrink: 0;
  text-decoration: none;
  overflow: hidden;
  border: 2px solid var(--surface);
  box-shadow: 0 2px 8px rgba(14, 32, 64, 0.12);
  transition: transform var(--trans);
}
.seller-avatar:hover { transform: scale(1.05); }
.seller-avatar img { width: 100%; height: 100%; object-fit: cover; }

.seller-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.seller-info-name {
  font-family: var(--ff-head);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--mnuc-navy);
  text-decoration: none;
  line-height: 1.3;
}
.seller-info-name:hover { color: var(--mnuc-blue); }
.seller-info-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Verified badge */
.seller-verified-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* ── Seller Details Card — key/value list ── */
.seller-details-card {
  display: grid;
  gap: 0;
  padding: 4px 0;
}
.seller-details-card > div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.seller-details-card > div:last-child { border-bottom: none; }
.seller-details-card > div > strong {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  font-family: var(--ff-body);
}
.seller-details-card > div > span {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--mnuc-navy);
  text-align: right;
}

/* ── Description ── */
.listing-desc {
  font-family: var(--ff-body);
  font-size: 0.95rem;
  color: var(--text);
  line-height: 1.7;
  margin: 0;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* "Read more" / "Show less" — quiet text-link */
.listing-desc + .btn,
section.card .btn-secondary.btn-sm {
  background: none;
  border: none;
  color: var(--mnuc-blue);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 4px 0;
  text-decoration: none;
  cursor: pointer;
  box-shadow: none;
}
.listing-desc + .btn:hover { text-decoration: underline; }

/* ── Rating widget inside info card ── */
.listing-info-card .rating-widget {
  margin-top: 0;
}

/* ── Skeleton state must match layout ── */
.listing-page-grid[aria-busy="true"] .listing-gallery { gap: 16px; }
.listing-page-grid[aria-busy="true"] .listing-info-card { gap: 12px; }

/* ═══════════════════════════════════════════════════════════════
   STICKY BOTTOM ACTION BAR — MOBILE ONLY
   WhatsApp CTA + Save pinned to viewport bottom
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 899px) {
  /* Bar background */
  .listing-page::after {
    content: '';
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(64px + env(safe-area-inset-bottom, 0px));
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 20px rgba(14, 32, 64, 0.06);
    z-index: 90;
    pointer-events: none;
  }

  /* WhatsApp button — fills left portion of bar */
  #listing-wa-btn {
    position: fixed;
    bottom: 0;
    left: 0;
    width: calc(100% - 124px);
    margin: 0;
    border-radius: 0;
    min-height: 64px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    z-index: 91;
    box-shadow: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
  }

  /* Save button — right portion of bar */
  #listing-page [data-save-listing] {
    position: fixed;
    bottom: 0;
    right: 0;
    width: 124px;
    margin: 0;
    border-radius: 0;
    min-height: 64px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    z-index: 91;
    box-shadow: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-left: 1px solid var(--border);
  }

  /* Reveal save label in bar */
  #listing-page [data-save-listing] span,
  #listing-page [data-save-label] {
    display: inline !important;
    font-size: 0.72rem;
  }

  /* Prevent content hidden behind bar */
  .listing-page-grid {
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px) + 16px);
  }
}

/* ═══════════════════════════════════════════════════════════════
   MOBILE FLOW REORDERING — display:contents + order
   Gallery → title → price → seller → description → details
   → related → seller-other → rating → CTAs
   ═══════════════════════════════════════════════════════════════ */

@supports (display: contents) {
  @media (max-width: 899px) {
    .listing-page-grid {
      display: flex;
      flex-direction: column;
      gap: 16px;
      padding: 16px 16px calc(64px + env(safe-area-inset-bottom, 0px) + 16px);
    }
        .thumb-row { order: 1; }
    .listing-gallery { display: contents; }
    .listing-info-card { display: contents; }

    .main-img,
    .main-img-placeholder { order: 1; }
    .listing-gallery > .card:nth-of-type(1) { order: 2; }
    .listing-info-price { order: 3; }
    .listing-info-card > .listing-info-title { order: 4; }
    .listing-info-card > .text-muted.text-sm { order: 5; }
    .seller-card { order: 6; }
    .listing-gallery > .card:nth-of-type(2) { order: 7; }
    .seller-details-card { order: 8; }
    .rating-widget,
    #seller-rating-block { order: 9; }
    .listing-gallery > .card:nth-of-type(3) { order: 10; }
    .listing-gallery > .card:nth-of-type(4) { order: 11; }
    .listing-info-card > .btn-secondary[href*="wa.me"]:not(#listing-wa-btn) { order: 12; }
    .listing-info-card > .btn-danger { order: 13; }
  }
}

/* Fallback for browsers without display:contents */
@supports not (display: contents) {
  @media (max-width: 899px) {
    .listing-page-grid {
      display: flex;
      flex-direction: column;
      gap: 16px;
      padding: 16px;
    }
    /* Price sticky at top of aside so it's visible early */
    .listing-info-price {
      position: sticky;
      top: 68px;
      z-index: 50;
      background: var(--surface);
      padding: 16px;
      margin: -16px -16px 0;
      border-bottom: 1px solid var(--border);
      border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    }
  }
}

/* ═══════════════════════════════════════════════════════════════
   RELATED / SELLER-OTHER — horizontal scroll on mobile
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 899px) {
  #related-listings,
  #seller-other-listings {
    display: flex !important;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 12px;
    padding-bottom: 8px;
  }
  #related-listings::-webkit-scrollbar,
  #seller-other-listings::-webkit-scrollbar { display: none; }

  #related-listings .listing-card,
  #seller-other-listings .listing-card {
    flex: 0 0 160px;
    scroll-snap-align: start;
  }

  #related-listings .listing-body,
  #seller-other-listings .listing-body { padding: 10px 8px; }
  #related-listings .listing-title,
  #seller-other-listings .listing-title {
    -webkit-line-clamp: 1;
    font-size: 0.85rem;
  }
}

/* ═══════════════════════════════════════════════════════════════
   TABLET (640–899px)
   ═══════════════════════════════════════════════════════════════ */

@media (min-width: 640px) and (max-width: 899px) {
  .listing-page-grid {
    padding: 24px 24px 100px;
    gap: 20px;
  }
  .main-img,
  .main-img-placeholder {
    aspect-ratio: 16 / 10;
    border-radius: var(--radius-lg);
  }
}

/* ═══════════════════════════════════════════════════════════════
   DESKTOP (900px+) — two-column, sticky aside
   ═══════════════════════════════════════════════════════════════ */

@media (min-width: 900px) {
  .listing-page-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(360px, 0.7fr);
    gap: 32px;
    padding: 32px 24px 48px;
    align-items: start;
  }

  .listing-gallery {
    display: flex;
    flex-direction: column;
    gap: 20px;
  }

  .main-img,
  .main-img-placeholder {
    aspect-ratio: 16 / 10;
  }

  .listing-info-card {
    position: sticky;
    top: 100px;
    padding: 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
  }

  .listing-gallery > .card {
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
  }
}

/* ═══════════════════════════════════════════════════════════════
   INTERACTION STATES
   ═══════════════════════════════════════════════════════════════ */

@media (hover: hover) {
  .listing-gallery > .card:hover {
    box-shadow: var(--shadow-md);
  }
}

@media (hover: none) {
  .listing-card:hover { transform: none; }
  .listing-card:hover .listing-img { transform: none; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .main-img,
  .thumb,
  .seller-avatar,
  .listing-card,
  .listing-img,
  .save-listing-btn,
  #listing-wa-btn,
  #listing-page [data-save-listing] {
    transition: none !important;
  }
  .skeleton-img,
  .skeleton-line {
    animation: none !important;
  }
}