/* =========================================================
   MARKET.css — modernized, responsive, accessible
   Covers: toolbar, tabs, grids, cards, modals, requests,
           external marketplace links, soft gate states.
   ========================================================= */

/* Container & Hero */
.market-container {
  padding: 2rem;
  max-width: 1200px;
  margin: auto;
}
.market-hero {
  text-align: center;
  margin-bottom: 2rem;
}

/* Toolbar */
.market-toolbar {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 2rem;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-md);
  padding: 1rem;
  background: var(--clr-bg-alt);
  box-shadow: var(--shadow-sm);
}
.market-toolbar input[type="search"],
.market-toolbar select {
  padding: 0.65rem 1.1rem;
  border-radius: 0.5rem;
  border: 1px solid var(--clr-border);
  font-size: 1rem;
  background: var(--clr-bg);
  color: var(--clr-text);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.market-toolbar input[type="search"]:focus,
.market-toolbar select:focus {
  outline: none;
  border-color: var(--clr-accent);
  box-shadow: 0 0 0 2px rgba(100, 108, 255, 0.15);
}

/* Location group */
.market-location-group {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}
.market-location-group input[type="text"] {
  padding: 0.6rem 1rem;
  border-radius: 0.5rem;
  border: 1px solid var(--clr-border);
  font-size: 1rem;
  width: 240px;
}
.market-location-group .btn--small {
  padding: 0.5rem 0.9rem;
  font-size: 0.9rem;
  border-radius: 0.5rem;
  background: var(--clr-bg-alt);
  border: 1px solid var(--clr-border);
  cursor: pointer;
  transition: background 0.2s ease;
}
.market-location-group .btn--small:hover {
  background: var(--clr-muted);
}

/* Settings wrapper merges filters & primary tabs (final, grid version) */
.market-settings {
  display: grid;
  grid-template-columns: 1fr auto; /* filters grow, tabs size to content */
  align-items: start;
  gap: .75rem 1rem;
  margin-bottom: 2rem;
  padding: .75rem 1rem;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-md);
  background: var(--clr-bg-alt);
  box-shadow: var(--shadow-sm);
}
/* Inside the wrapper, flatten the toolbar chrome so we don’t double-frame */
.market-settings .market-toolbar {
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;

  /* Compact grid for the 4 pieces:
     [Search] [Category] [Location input] [Nearest btn] */
  display: grid;
  grid-template-columns:
    minmax(220px, 2fr)
    minmax(160px, 1fr)
    minmax(220px, 2fr)
    auto;
  gap: .75rem;
  align-items: center;
}
/* Make controls feel consistent in height */
.market-settings .market-toolbar input[type="search"],
.market-settings .market-toolbar select,
.market-settings .market-location-group input[type="text"],
.market-settings .market-location-group .btn--small {
  height: 40px;
}
/* Location group stretches nicely */
.market-settings .market-location-group {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .5rem;
  align-items: center;
}
/* Tabs sit to the right on wide screens */
.market-settings .market-tabs {
  margin: 0;
  justify-content: flex-end;
  align-self: center;
  gap: .5rem;
}
/* Slightly tighter tab paddings so everything fits better */
.market-settings .tab-button {
  padding: .6rem 1rem;
}
/* — Responsive adjustments — */
@media (max-width: 1100px) {
  .market-settings {
    grid-template-columns: 1fr; /* stack: toolbar above tabs */
  }
  .market-settings .market-tabs {
    justify-content: center; /* center tabs when stacked */
    margin-top: .25rem;
  }
  .market-settings .market-toolbar {
    grid-template-columns:
      minmax(200px, 1fr)
      minmax(150px, .8fr)
      minmax(200px, 1fr)
      auto;
  }
}
@media (max-width: 700px) {
  .market-settings .market-toolbar {
    grid-template-columns: 1fr; /* one control per row */
  }
  .market-settings .market-location-group {
    grid-template-columns: 1fr auto; /* input stretches, button stays tight */
  }
  .market-settings .tab-button {
    flex: 1 1 auto; /* allow tabs to wrap neatly */
  }
}

/* Tabs */
.market-tabs,
.market-subtabs {
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}
.tab-button,
.subtab-button {
  position: relative;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 999px;
  background: var(--clr-bg);
  color: var(--clr-text);
  cursor: pointer;
  transition: color .15s ease, background .15s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.tab-button:hover,
.subtab-button:hover {
  background-color: var(--clr-bg);
}
.tab-button.active,
.subtab-button.active {
  background: var(--clr-bg);
  color: var(--clr-text);
}
.tab-button.active::after,
.subtab-button.active::after {
  content: "";
  position: absolute;
  left: 0; bottom: -4px;
  width: 100%; height: 3px;
  background-color: var(--clr-accent);
  border-radius: 2px;
  box-shadow: 0 0 6px rgba(100,108,255,.6);
  animation: underlineSlide .25s ease-out;
}
@keyframes underlineSlide { from{width:0;} to{width:100%;} }

.subtab-button { padding: 0.6rem 1.2rem; font-size: 0.95rem; font-weight: 500; }

/* Tertiary tabs */
.market-tertiary-tabs {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.tertiary-tab-button {
  position: relative;
  padding: 0.5rem 1rem;
  font-size: 0.95rem;
  font-weight: 500;
  border-radius: 0.5rem;
  border: 1px solid var(--clr-border);
  background: var(--clr-bg-alt);
  cursor: pointer;
  transition: all .15s ease;
}
.tertiary-tab-button.active {
  background: var(--clr-bg);
}
.tertiary-tab-button.active::after {
  content: "";
  position: absolute;
  left: 0; bottom: -4px;
  width: 100%; height: 3px;
  background-color: var(--clr-accent);
  border-radius: 2px;
  box-shadow: 0 0 6px rgba(100,108,255,.6);
}

/* Panels */
.tab-content,
.subtab-content,
.tertiary-tab-content { display: none; }
.tab-content.active,
.subtab-content.active,
.tertiary-tab-content.active {
  display: block;
  animation: fadeIn .35s ease-in-out;
}
@keyframes fadeIn { from{opacity:0; transform: translateY(12px);} to{opacity:1; transform: none;} }

/* Equipment grid & cards */
.equipment-grid {
  display: grid;
  gap: 2rem;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  border-top: 1px dashed var(--clr-border);
  padding-top: 2rem;
}

.equipment-card {
  background: var(--clr-bg);
  border: 1px solid var(--clr-border);
  border-top: 4px solid var(--clr-accent);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform .15s ease, box-shadow .2s ease;
}
.equipment-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}
.equipment-card img {
  width: 100%;
  height: 180px;
  object-fit: cover;
  background: var(--clr-bg-alt);
}
.equipment-card__details {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  border-top: 1px solid var(--clr-border);
}
.equipment-card__title { font-weight: 600; font-size: 1.05rem; }
.equipment-card__meta {
  display: flex; justify-content: space-between;
  font-size: .9rem; color: var(--clr-text-muted);
}
.equipment-card__location { display:flex; align-items:center; gap:.4rem; }
.equipment-card__price { font-size: 1.1rem; font-weight: 700; color: var(--clr-accent); }
.equipment-card__source { display:flex; align-items:center; gap:.4rem; font-size:.85rem; font-weight:500; color: var(--clr-text-muted); }
.equipment-card__source i { color: var(--clr-accent); }
.equipment-card__source span { color: var(--clr-link); }

.equipment-card__desc { font-size: .9rem; color: var(--clr-text-muted); margin-top: .3rem; }
.equipment-card__specs { list-style:none; padding:0; margin:.5rem 0 0; font-size:.85rem; color:var(--clr-text-muted); }
.equipment-card__specs li { border-bottom: 1px solid var(--clr-border); padding: .15rem 0; }
.equipment-card__seller { font-size:.85rem; color: var(--clr-link); margin-top: .4rem; display:flex; align-items:center; gap:.3rem; }

/* Card thumbnails */
.card-thumbs {
  display: grid;
  gap: 6px;
  padding: 8px;
  grid-auto-rows: 56px;
  background: var(--clr-bg);
  border-top: 1px solid var(--clr-border);
}
.card-thumbs img {
  width: 100%; height: 100%; object-fit: cover;
  border-radius: 6px; border: 1px solid var(--clr-border);
}
.card-thumbs.thumbs--1 { grid-template-columns: 1fr; }
.card-thumbs.thumbs--2 { grid-template-columns: repeat(2, 1fr); }
.card-thumbs.thumbs--3 { grid-template-columns: 2fr 1fr; }
.card-thumbs.thumbs--4,
.card-thumbs.thumbs--5 { grid-template-columns: repeat(3, 1fr); }
.card-thumbs.thumbs--3 img:first-child { grid-row: span 2; }
.card-thumbs.thumbs--5 img:last-child { grid-column: 3; }

/* Loading & states */
.market-loading { display:flex; justify-content:center; align-items:center; padding:4rem 0; }
.market-loading .spinner {
  width:48px;height:48px;border:5px solid var(--clr-border);border-top:5px solid var(--clr-accent);
  border-radius:50%; animation: spin .8s linear infinite;
}
@keyframes spin { to{ transform: rotate(360deg);} }
.market-message {
  text-align:center; padding:3rem 1rem; font-size:1.1rem; color: var(--clr-text-muted);
  border:1px dashed var(--clr-border); background: var(--clr-bg-alt); border-radius: var(--radius-md);
}
.market-message strong { color: var(--clr-danger); display:block; margin-bottom:.5rem; }

/* Responsive tabs */
@media (max-width: 600px) {
  .tab-button, .subtab-button { flex: 1 1 100%; text-align: center; }
  .market-tabs, .market-subtabs { flex-direction: column; align-items: stretch; }
}

/* ================================
   Requests Cards – gold theme
   ================================ */
.equipment-card.request-card {
  border-top-color: var(--clr-warning, #f4b400);
  background: linear-gradient(180deg, var(--clr-bg-alt) 0%, #fffaf0 100%);
}
.equipment-card.request-card:hover { box-shadow: 0 4px 12px rgba(212,160,23,.25); }
.equipment-card.request-card .equipment-card__source {
  font-size:.8rem;font-weight:600;background: rgba(212,160,23,.1);
  padding:.25rem .5rem;border-radius: var(--radius-sm); display:inline-flex; gap:.3rem; color: var(--clr-warning);
}
.equipment-card.request-card .equipment-card__meta { flex-wrap: wrap; gap: .5rem; }
.equipment-card.request-card .equipment-card__price { color: var(--clr-warning); }
.request-badge {
  display:inline-block;padding:.15rem .4rem;font-size:.75rem;font-weight:600;border-radius:4px;
  background: rgba(244,180,0,.15); color: var(--clr-warning); margin-left:.3rem;
}

/* ================================
   Modals
   ================================ */
.modal {
  position: fixed; inset: 0;
  background: rgba(17, 18, 23, .75);
  display: none; align-items: center; justify-content: center;
  padding: clamp(.5rem, 2vw, 1rem);
  z-index: 9999;
  backdrop-filter: blur(3px);
}
.modal.open { display: flex; animation: fadeIn .2s ease-in-out; }
.modal-content {
  position: relative;
  background: var(--clr-bg);
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(0,0,0,.35);
  max-width: 1180px; width: 100%;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--clr-border) 60%, transparent);
}
.modal-content--product { border-top: 5px solid var(--clr-accent); }
.modal-content--request { border-top: 5px solid var(--clr-warning); }

.modal-close {
  position: absolute; top: .75rem; right: .75rem;
  background: rgba(0,0,0,.55); color: #fff;
  border: 1px solid rgba(255,255,255,.25);
  width: 38px; height: 38px; border-radius: 999px;
  font-size: 1.4rem; cursor: pointer;
  display:grid;place-items:center;
  transition: transform .06s ease, background .15s ease;
}
.modal-close:hover { background: rgba(0,0,0,.7); }
.modal-close:active { transform: scale(.97); }

.modal-body {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 1rem;
  /* allow grid columns to shrink and scroll if needed */
  min-height: 0;
  overflow: auto;
}
.modal-body--single { grid-template-columns: 1fr; }
@media (max-width: 900px) { .modal-body { grid-template-columns: 1fr; } }

.modal-header { display:flex; flex-direction: column; gap:.35rem; }

.modal-title { font-size: clamp(1.25rem, 2.2vw, 1.55rem); font-weight: 800; }
.modal-meta { display:flex; gap:1rem; flex-wrap: wrap; color: var(--clr-text-muted); }
.modal-price { font-size: 1.25rem; font-weight: 800; color: var(--clr-accent); }
.modal-specs { list-style:none; padding:0; margin:0; border:1px solid var(--clr-border); border-radius:10px; overflow:hidden; }
.modal-specs li { padding:.5rem .75rem; display:flex; gap:.35rem; border-top:1px solid var(--clr-border); }
.modal-specs li:first-child { border-top: none; }
.modal-specs strong { min-width: 120px; color: var(--clr-text); font-weight: 600; }

.modal-seller div { margin-top: .3rem; font-size: .95rem; }
.modal-seller i { color: var(--clr-accent); margin-right: .5rem; }

/* Gallery (consolidated final) */
.modal-gallery {
  position: relative;
  padding: 1rem;
  display: flex; flex-direction: column; gap: 10px;
}
.gallery-stage {
  /* union of earlier + final rules */
  position: relative;
  width: 100%;
  height: clamp(240px, 60vh, 640px);
  background: var(--clr-bg-alt);
  border: 1px solid var(--clr-border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.gallery-stage .modal-image {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;      /* show whole image by default */
  object-position: center;
  background: var(--clr-bg);
  /* Prevent blurriness on downscale */
  image-rendering: auto;
}
.gallery-stage .modal-image.is-cover { object-fit: cover; }

/* Keep nav buttons inside the visible stage on small screens */
.gallery-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  z-index: 2; width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--clr-border);
  background: rgba(0,0,0,.45); color: #fff; cursor: pointer;
  display:grid; place-items:center;
}
.gallery-nav.prev { left: 18px; }
.gallery-nav.next { right: 18px; }
.gallery-nav:hover { background: rgba(0,0,0,.65); }
@media (max-width: 900px) {
  .gallery-nav.prev { left: 10px; }
  .gallery-nav.next { right: 10px; }
}

/* Thumbs strip */
.modal-thumbs {
  display: grid; gap: 8px; grid-template-columns: repeat(5, 1fr);
}
.modal-thumbs button {
  border: 1px solid var(--clr-border);
  padding: 0; background: transparent; cursor: pointer;
  border-radius: 8px; overflow: hidden; height: 64px;
}
.modal-thumbs img { width: 100%; height: 100%; object-fit: cover; }
.modal-thumbs button[aria-selected="true"] {
  outline: 2px solid var(--clr-accent);
  outline-offset: 1px;
}

/* Info column */
.modal-info {
  padding: 1.25rem 1.25rem 1.35rem;
  display: flex; flex-direction: column; gap: 1rem;
}

/* Actions row */
.modal-actions {
  display: flex; gap: .5rem; flex-wrap: wrap; align-items: center;
}
.modal-actions .btn { padding: .55rem .8rem; border-radius: 8px; }
.modal-actions .btn i { margin-right: .4rem; }

/* Guest state helpers */
.soft-gate-banner{
  margin: .75rem 0;
  padding: .75rem 1rem;
  border: 1px dashed var(--clr-border,#dcdcdc);
  border-radius: 8px;
  background: color-mix(in srgb, var(--clr-surface,#fff) 85%, #f0f4ff);
}
.guest-blur{ filter: blur(6px) saturate(.7); }
.guest-pixelate{ image-rendering: pixelated; transform: scale(1.01); }
.guest-mask{
  background: linear-gradient(90deg, #eee 30%, #ddd 50%, #eee 70%);
  display:inline-block; border-radius:6px; color: transparent !important;
}
.guest-chip{
  display:inline-flex; gap:.35rem; align-items:center;
  padding:.2rem .5rem; border-radius:999px; font-size:.85rem;
  background:#eef3ff; color:#2c4cff; border:1px solid #dbe6ff;
}
.modal-cta{ display:flex; gap:.5rem; flex-wrap:wrap; }
.modal-cta .btn{ padding:.5rem .75rem; }

/* External marketplace links */
.equipment-card__market {
  display:flex; gap:.5rem; flex-wrap: wrap; margin-top: .35rem;
}
.market-link {
  display:inline-flex; align-items:center; gap:.4rem;
  padding:.35rem .55rem; border:1px solid var(--clr-border);
  border-radius:999px; font-size:.85rem; background: var(--clr-bg-alt);
  color: var(--clr-link); text-decoration:none;
  transition: background .15s ease, box-shadow .15s ease, transform .02s ease;
}
.market-link:hover { background: var(--clr-muted); }
.market-link:active { transform: translateY(1px); }
.market-link__ext { opacity:.75; font-size:.8em; }

.market-link--facebook { border-color:#4064ac33; background:#4064ac0e; }
.market-link--craigslist { border-color:#66009933; background:#6600990e; }
.market-link--ebay { border-color:#e5323826; background:#e532380d; }

.modal-market { display:flex; flex-direction: column; gap:.5rem; }
.modal-market__title { font-weight:600; color: var(--clr-text-muted); display:flex; align-items:center; gap:.4rem; }
.modal-market__links { display:flex; gap:.5rem; flex-wrap: wrap; }

/* Request Modal accents */
#requestModal .modal-title { color: var(--clr-warning); }
#requestModal .modal-price { color: var(--clr-warning); }
#requestModal .modal-contact i { color: var(--clr-warning); }

/* ================================
   Auth-gated visibility helpers
   ================================ */

/* Make sure anything with [hidden] truly disappears everywhere */
[hidden],
.modal-cta[hidden],
.modal-market[hidden] {
  display: none !important;
}

/* Belt & suspenders: when JS sets inert, kill interaction */
[inert] {
  pointer-events: none !important;
  user-select: none !important;
}

/* (Optional) Utilities for future gating without JS toggling [hidden] */
.is-authed .guest-only { display: none !important; }
.is-guest  .authed-only { display: none !important; }

/* ===========================================
   Robust media framing for cards & modals
   =========================================== */

/* 1) Global image sanity */
img {
  display: block;                /* kill inline baseline gap */
  max-width: 100%;
  height: auto;
}

/* 2) Equipment cards – consistent cover crop */
.equipment-card > img {
  /* Lock the visual box height without distortion */
  aspect-ratio: 4 / 3;           /* consistent grid rhythm */
  height: auto;                  /* let aspect-ratio drive height */
  max-height: none;
  object-fit: cover;             /* center-crop tall/wide images */
  object-position: center center;
  background: var(--clr-bg-alt);
  image-rendering: auto;
}
/* Fallback for browsers without aspect-ratio support */
@supports not (aspect-ratio: 4 / 3) {
  .equipment-card > img {
    height: 180px;               /* your existing fixed height */
  }
}

/* Optional variants (apply via class on the <img> if you want different behavior) */
.img-cover   { object-fit: cover !important;  object-position: center !important; }
.img-contain { object-fit: contain !important; object-position: center !important; background: var(--clr-bg) !important; }

/* 3) Card thumbnails – stable squares, no jumpiness */
.card-thumbs {
  grid-auto-rows: 64px;          /* a touch taller for clarity */
}
.card-thumbs img {
  aspect-ratio: 1 / 1;           /* every thumb is square */
  object-fit: cover;
  object-position: center;
  background: var(--clr-bg-alt);
}

/* 4) Modal gallery stage – handle ANY ratio gracefully (uses consolidated .gallery-stage above) */

/* 6) Prevent layout shift while images stream in */
.equipment-card > img,
.gallery-stage .modal-image,
.card-thumbs img,
.modal-thumbs img {
  background-image: linear-gradient(120deg, #eceff6 25%, #f7f8fb 25%, #f7f8fb 50%, #eceff6 50%, #eceff6 75%, #f7f8fb 75%, #f7f8fb);
  background-size: 24px 24px;
  animation: imgShimmer 1.2s linear infinite;
}
@keyframes imgShimmer {
  to { background-position: 24px 0; }
}
/* Kill shimmer once an actual image is painted (cheap heuristic) */
.equipment-card > img[src^="blob:"],
.equipment-card > img[src^="http"],
.gallery-stage .modal-image[src^="blob:"],
.gallery-stage .modal-image[src^="http"],
.card-thumbs img[src^="blob:"],
.card-thumbs img[src^="http"],
.modal-thumbs img[src^="blob:"],
.modal-thumbs img[src^="http"] {
  background: var(--clr-bg);
  animation: none;
}

/* 7) Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  .equipment-card:hover { transform: none; }
  .modal.open { animation: none; }
  .market-link { transition: none; }
  .tab-button.active::after,
  .subtab-button.active::after { animation: none; }
  .market-loading .spinner { animation-duration: 1.6s; }
  .equipment-card > img,
  .gallery-stage .modal-image,
  .card-thumbs img,
  .modal-thumbs img { animation: none; }
}

/* 8) Tiny portrait/pano tweaks (optional helpers)
   Add these classes via JS if you detect extreme aspect ratios */
.img--portrait { object-fit: contain !important; }
.img--pano     { object-fit: cover !important; object-position: center 45% !important; }

/* ================================
   Requests Modal — polished UI
   ================================ */
#requestModal .modal-actions--request .btn i { margin-right: .4rem; }

.rq-badges {
  display: flex;
  gap: .4rem .5rem;
  flex-wrap: wrap;
}
.rq-chip {
  display: inline-flex;
  gap: .35rem;
  align-items: center;
  padding: .25rem .55rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--clr-warning) 35%, transparent);
  background: color-mix(in srgb, var(--clr-warning) 12%, var(--clr-bg));
  color: var(--clr-warning);
  font-size: .85rem;
  font-weight: 600;
}
.rq-chip i { color: var(--clr-warning); }

.rq-kpis {
  display: grid;
  grid-template-columns: repeat(3, minmax(0,1fr));
  gap: .75rem;
  margin-top: .35rem;
}
@media (max-width: 700px) {
  .rq-kpis { grid-template-columns: 1fr; }
}
.rq-kpi {
  padding: .6rem .75rem;
  border: 1px solid var(--clr-border);
  border-radius: 10px;
  background: linear-gradient(180deg, var(--clr-bg) 0%, #fffaf0 100%);
}
.rq-kpi__label {
  font-size: .8rem;
  color: var(--clr-text-muted);
  display: flex; align-items: center; gap: .4rem;
  margin-bottom: .2rem;
}
.rq-kpi__label i { color: var(--clr-warning); }
.rq-kpi__value { font-weight: 700; color: var(--clr-text); }

.rq-divider {
  border: 0; height: 1px; margin: .75rem 0;
  background: color-mix(in srgb, var(--clr-border) 70%, transparent);
}

.rq-section { display: grid; gap: .5rem; }
.rq-section + .rq-section { margin-top: .25rem; }
.rq-section__title {
  display: flex; align-items: center; gap: .5rem;
  font-size: .95rem; color: var(--clr-text-muted); font-weight: 700;
}
.rq-section__title i { color: var(--clr-warning); }

.rq-desc p { margin: 0; line-height: 1.55; }
.rq-desc .is-clamped {
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.rq-desc__toggle {
  margin-top: .35rem;
  align-self: start;
  padding: .3rem .6rem;
  font-size: .85rem;
  border-radius: 8px;
  border: 1px solid var(--clr-border);
  background: var(--clr-bg-alt);
  cursor: pointer;
}
.rq-desc__toggle:hover { background: var(--clr-muted); }

.rq-contact div { margin-top: .3rem; font-size: .95rem; }
.rq-contact i { color: var(--clr-warning); margin-right: .5rem; }
.rq-contact__actions { display: flex; gap: .5rem; margin-top: .5rem; }

.modal-actions--request {
  display: flex; gap: .5rem; flex-wrap: wrap;
  margin-top: .75rem;
}
@media (max-width: 700px) {
  /* Sticky actions for mobile ergonomics */
  #requestModal .modal-content {
    padding-bottom: 64px; /* room for sticky bar */
  }
  .modal-actions--request {
    position: sticky;
    bottom: -1px;
    background: var(--clr-bg);
    padding: .5rem .25rem .5rem 0;
    border-top: 1px solid var(--clr-border);
    z-index: 2;
  }
}

/* Keep soft gate visuals consistent */
#requestModal .guest-chip {
  background: #fff4d6;
  color: #8a6b00;
  border-color: #ffe7a3;
}

/* ================================
   Product Modal — mobile compact layout (no scrolling)
   ================================ */
@media (max-width: 540px) {
  /* Full-bleed, safe-area aware modal */
  #productModal.modal { padding: 0; }
  #productModal .modal-content {
    width: 100%;
    max-width: none;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    /* respect notches */
    padding-top: env(safe-area-inset-top, 0);
    padding-bottom: env(safe-area-inset-bottom, 0);
    display: grid;
    grid-template-rows: 1fr; /* single grid so we can control children */
  }

  /* Close button pinned & tappable (final) */
  #productModal .modal-close {
    position: fixed; /* keep visible even if modal scrolls */
    top: calc(env(safe-area-inset-top, 0) + 0.5rem);
    right: calc(env(safe-area-inset-right, 0) + 0.5rem);
    width: 44px;
    height: 44px;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    border: none;
    border-radius: 999px;
    font-size: 1.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000; /* above gallery arrows & content */
    cursor: pointer;
    -webkit-tap-highlight-color: transparent; /* remove iOS highlight */
    touch-action: manipulation;
  }
  #productModal .modal-close:active {
    transform: scale(0.96);
    background: rgba(0, 0, 0, 0.8);
  }

  /* One-column layout with fixed regions that fit in viewport */
  #productModal .modal-body {
    display: grid;
    grid-template-rows:
      minmax(0, 42dvh)     /* gallery stage */
      auto                 /* thumbs strip */
      minmax(0, 1fr);      /* info block (title, specs, actions) */
    gap: .5rem;
    padding: 0;
    overflow: hidden;      /* prevent scroll of the body */
  }

  /* ==== Gallery (top) ==== */
  #productModal .modal-gallery {
    padding: .5rem .75rem 0 .75rem;
    gap: .5rem;
  }
  #productModal .gallery-stage {
    height: 100%;
    aspect-ratio: auto;    /* let height rule */
    border-radius: 10px;
  }
  #productModal .gallery-nav {
    width: 32px; height: 32px;
    background: rgba(0,0,0,.55);
    border: 0;
  }

  /* Thumbs: single-line filmstrip with horizontal scroll */
  #productModal .modal-thumbs {
    padding: 0 .75rem .5rem;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 44px;
    gap: .5rem;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }
  #productModal .modal-thumbs button {
    aspect-ratio: 1 / 1;
    height: auto;
    border-radius: 6px;
  }
  #productModal .modal-thumbs img { object-fit: contain; }

  /* ==== Info block (bottom) ==== */
  #productModal .modal-info {
    padding: .65rem .75rem max(3.25rem, calc(env(safe-area-inset-bottom, 0) + 3rem));
    display: grid;
    grid-template-rows:
      auto          /* header (title + meta) */
      auto          /* description (clamped) */
      auto          /* specs grid (first N only) */
      auto          /* seller / external links (compact) */
      auto;         /* actions (sticky-looking) */
    gap: .55rem;
    min-height: 0;
    overflow: hidden; /* no scrolling */
    grid-auto-rows: max-content;
  }

  /* Header */
  #productModal .modal-header { gap: .25rem; }
  #productModal .modal-title {
    font-size: clamp(1.05rem, 3.6vw, 1.2rem);
    line-height: 1.15;
    max-height: calc(1.15em * 2 + 2px);
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    margin: 0;
  }
  #productModal .modal-meta {
    gap: .6rem .8rem;
    font-size: .92rem;
  }
  #productModal .modal-price { font-size: 1.05rem; }
  #productModal .modal-location { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* Description: concise snippet only */
  #productModal .modal-description {
    margin: 0;
    font-size: .95rem;
    color: var(--clr-text);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    padding: 0; /* prevent padding creep */
  }

  /* Specs: two-column, mobile-optimized (show up to 8) */
  #productModal .modal-specs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    border: 0;
    padding: 0;
  }
  #productModal .modal-specs li {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: .35rem;
    padding: .48rem .6rem;
    border: 1px solid var(--clr-border);
    border-radius: 8px;
    line-height: 1.25;
    font-size: .9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #productModal .modal-specs li strong {
    min-width: 0;
    font-weight: 700;
    margin-right: .1rem;
  }
  #productModal .modal-specs li span,
  #productModal .modal-specs li em,
  #productModal .modal-specs li small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  /* Show up to 8 items (a touch more room), hide the rest */
  #productModal .modal-specs li:nth-child(n+9) { display: none; }

  /* Seller + external links */
  #productModal .modal-seller { font-size: .92rem; margin-bottom: .4rem; }
  #productModal .modal-seller,
  #productModal .modal-seller * { overflow-wrap: anywhere; word-break: break-word; }
  #productModal .modal-seller a { text-decoration: none; color: var(--clr-link); }
  #productModal .modal-market__title { display: none; }
  #productModal .modal-market { margin-top: .25rem; }
  #productModal .modal-market__links {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    gap: .45rem;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    padding-top: .15rem;
    padding-bottom: .25rem;
  }
  #productModal .market-link {
    padding: .28rem .5rem;
    font-size: .82rem;
    border-radius: 999px;
    white-space: nowrap;
    line-height: 1.1;
  }

  /* Actions: fixed at bottom of info block without overlapping */
  #productModal .modal-actions {
    margin-top: .15rem;
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: .4rem;
  }
  #productModal .modal-actions .btn {
    display: flex;
    align-items: center;       /* vertical centering */
    justify-content: center;   /* horizontal centering */
    text-align: center;
    line-height: 1.2;          /* improve multi-line readability */
    white-space: normal;       /* allow wrapping */
    padding: .55rem .6rem;
    font-size: .95rem;
  }
  #productModal .modal-actions .btn i {
    margin-right: .4rem;
    flex-shrink: 0; /* keep icon from squishing */
  }
  /* Make primary action span two columns if space is tight */
  @media (max-width: 380px) {
    #productModal .modal-actions {
      grid-template-columns: 1fr 1fr;
    }
    #productModal .modal-actions .modal-contact-btn {
      grid-column: 1 / -1;
    }
  }

  /* Ensure nothing inside overflows vertically */
  #productModal .modal-info > * { min-height: 0; }
}

/* Micro-phones: further compress below 360px */
@media (max-width: 360px) {
  #productModal .gallery-nav { display: none; } /* rely on swipe/arrow keys */
  #productModal .modal-thumbs { grid-auto-columns: 40px; gap: .4rem; }
  #productModal .modal-title { -webkit-line-clamp: 2; }
  #productModal .modal-description { -webkit-line-clamp: 2; }
  #productModal .modal-specs li { font-size: .86rem; padding: .35rem .45rem; }
  #productModal .market-link { padding: .28rem .5rem; font-size: .8rem; }
}

/* ===========================================
   Background scroll lock (iOS + Android)
   =========================================== */
html {
  overscroll-behavior-y: none;
}
/* When a modal is open, lock the page behind it */
body.is-lock-scroll {
  overflow: hidden !important;
  height: 100dvh;            /* Android: prevent address-bar jank */
  touch-action: none;        /* block wheel/touch scroll */
}
/* iOS fix: use fixed positioning + remember scroll position via CSS var */
@supports (-webkit-touch-callout: none) {
  body.is-lock-scroll {
    position: fixed;
    width: 100%;
    top: var(--scroll-y, 0);  /* set by JS to negative px value */
    left: 0; right: 0;
  }
}
/* Keep scroll/overscroll contained within the modal itself */
.modal.open {
  overscroll-behavior: contain;  /* stop background chain scrolling */
  touch-action: none;            /* prevent scrolling the backdrop */
}
/* Still allow internal focus and minor scroll if you ever re-enable it */
.modal.open .modal-content {
  overscroll-behavior: contain;
}
/* (Optional) Belt & suspenders: prevent wheel scroll on backdrop in desktop */
@media (hover: hover) {
  .modal.open { pointer-events: auto; }
  .modal.open ~ * { pointer-events: none; /* block background interactions while open */ }
}

/* =========================================================
   Requests Modal — mobile compact layout (no scrolling)
   Match product modal behavior on ≤540px
   ========================================================= */
@media (max-width: 540px) {
  /* Full-bleed, safe-area aware frame */
  #requestModal.modal { padding: 0; }
  #requestModal .modal-content {
    width: 100%;
    max-width: none;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    padding-top: env(safe-area-inset-top, 0);
    padding-bottom: env(safe-area-inset-bottom, 0);
    display: grid;
    grid-template-rows: 1fr; /* let body control layout */
  }

  /* Close button pinned & tappable (like product modal) */
  #requestModal .modal-close {
    position: fixed;
    top: calc(env(safe-area-inset-top, 0) + .5rem);
    right: calc(env(safe-area-inset-right, 0) + .5rem);
    width: 44px; height: 44px;
    background: rgba(0,0,0,.65);
    color:#fff; border: 0; border-radius: 999px;
    font-size: 1.6rem; display:flex; align-items:center; justify-content:center;
    z-index: 10000;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
  #requestModal .modal-close:active { transform: scale(.96); background: rgba(0,0,0,.8); }

  /* One-column, fixed regions that fit viewport (no body scroll) */
  #requestModal .modal-body.modal-body--single {
    display: grid;
    grid-template-rows:
      auto          /* header + badges */
      auto          /* KPIs row */
      minmax(0, 1fr)/* details/contact/links (clamped) */
      auto;         /* actions */
    gap: .5rem;
    padding: 0;
    overflow: hidden; /* prevent modal-body scrolling */
  }

  /* Main info stack with guaranteed breathing room for actions */
  #requestModal .modal-info {
    padding: .65rem .75rem max(3rem, calc(env(safe-area-inset-bottom, 0) + 2.75rem));
    display: grid;
    grid-template-rows:
      auto          /* header */
      auto          /* KPIs */
      minmax(0, 1fr)/* content area (details/contact/links) */
      auto;         /* actions */
    gap: .6rem;
    min-height: 0;  /* allow internal content to clamp instead of scroll */
    overflow: hidden;
  }

  /* Header: tighter, multi-line safe */
  #requestModal .modal-title {
    font-size: clamp(1.05rem, 3.6vw, 1.2rem);
    line-height: 1.15;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden;
    margin: 0;
  }
  #requestModal .rq-badges { gap: .4rem .45rem; }

  /* KPIs: stack on mobile with consistent touch targets */
  #requestModal .rq-kpis {
    grid-template-columns: 1fr;
    gap: .5rem;
    margin-top: 0;
  }
  #requestModal .rq-kpi { padding: .55rem .65rem; border-radius: 10px; }

  /* Details text: clamp for height control */
  #requestModal .rq-section { gap: .4rem; }
  #requestModal .rq-section + .rq-section { margin-top: .25rem; }
  #requestModal .rq-desc p {
    margin: 0; line-height: 1.5;
    display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical;
    overflow: hidden;
  }
  #requestModal .rq-desc__toggle { display: none !important; } /* keep compact */

  /* Contact info: wrap long email/phone/company cleanly */
  #requestModal .rq-contact,
  #requestModal .rq-contact * {
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  /* External marketplace links: compact chips, horizontal scroll */
  #requestModal .modal-market__links {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    gap: .45rem;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    padding-bottom: .15rem;
  }
  #requestModal .modal-market .market-link {
    padding: .32rem .6rem;
    font-size: .84rem;
    border-radius: 999px;
    white-space: nowrap;
    line-height: 1.1;
  }

  /* Actions: centered labels, multi-line friendly, never overlap content */
  #requestModal .modal-actions--request {
    position: relative;
    z-index: 2;
    margin-top: .2rem;
    padding: 0;
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: .4rem;
    border-top: 1px solid var(--clr-border);
    background: var(--clr-bg);
  }
  #requestModal .modal-actions--request .btn {
    display: flex; align-items: center; justify-content: center;
    text-align: center; line-height: 1.2; white-space: normal;
    padding: .55rem .6rem; font-size: .95rem;
  }
  #requestModal .modal-actions--request .btn i { margin-right: .4rem; flex-shrink: 0; }

  /* Ultra-narrow: make primary span full width */
  @media (max-width: 380px) {
    #requestModal .modal-actions--request { grid-template-columns: 1fr 1fr; }
    #requestModal .modal-actions--request .rq-message-btn { grid-column: 1 / -1; }
  }
}

/* Micro phones */
@media (max-width: 360px) {
  #requestModal .modal-title { -webkit-line-clamp: 2; }
  #requestModal .modal-market .market-link { padding: .28rem .5rem; font-size: .8rem; }
  #requestModal .rq-kpi { padding: .45rem .55rem; }
}

/* =========================================================
   Requests Cards — mobile-friendly description tweaks
   ========================================================= */
@media (max-width: 540px) {
  /* Target only request cards */
  .equipment-card.request-card .equipment-card__desc {
    font-size: 0.95rem;              /* slightly larger for legibility */
    line-height: 1.4;                /* better vertical spacing */
    padding: 0.5rem 0.65rem 0.65rem; /* inner breathing room */
    background: rgba(255, 250, 240, 0.6); /* soft hint background for separation */
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    overflow-wrap: anywhere;         /* break very long words/URLs */
    display: -webkit-box;
    -webkit-line-clamp: 4;           /* show max 4 lines */
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  /* Ensure meta/details stack nicely */
  .equipment-card.request-card .equipment-card__meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
  }
}

/* =========================================================
   Saved Tab — Professional Card Layout
   Targets only the Saved panel so My Listings keeps its look.
   ========================================================= */

/* Grid */
#uh-saved .uh-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  align-items: start;
}

/* Card shell */
#uh-saved .uh-card {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 0;
  background: var(--clr-bg);
  border: 1px solid var(--clr-border);
  border-top: 4px solid var(--clr-accent);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  transition: transform .15s ease, box-shadow .2s ease, border-color .2s ease;
}
#uh-saved .uh-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

/* Thumbnail column */
#uh-saved .uh-card__thumb {
  width: 100%;
  height: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  object-position: center;
  background: var(--clr-bg-alt);
  border-right: 1px solid var(--clr-border);
  transition: filter .2s ease, transform .2s ease;
}
@supports not (aspect-ratio: 4 / 3) {
  #uh-saved .uh-card__thumb { height: 180px; }
}
#uh-saved .uh-card:hover .uh-card__thumb {
  filter: saturate(1.05);
}

/* Body */
#uh-saved .uh-card__body {
  padding: 0.85rem 1rem;
  display: grid;
  gap: .5rem;
  align-content: start;
}

/* Title */
#uh-saved .uh-card__title {
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.25;
  color: var(--clr-text);
}

/* Meta row (category • location • price) */
#uh-saved .uh-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem .6rem;
  font-size: .92rem;
  color: var(--clr-text-muted);
}
#uh-saved .uh-card__meta span {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .22rem .5rem;
  border: 1px solid var(--clr-border);
  border-radius: 999px;
  background: var(--clr-bg-alt);
}
#uh-saved .uh-card__meta i { color: var(--clr-accent); }

/* Emphasize price chip */
#uh-saved .uh-card__meta .fa-dollar-sign,
#uh-saved .uh-card__meta [data-price] i { color: var(--clr-accent); }
#uh-saved .uh-card__meta [data-price] {
  font-weight: 700;
  color: var(--clr-accent);
  border-color: color-mix(in srgb, var(--clr-accent) 35%, var(--clr-border));
  background: color-mix(in srgb, var(--clr-accent) 12%, var(--clr-bg));
}

/* Source/category tag style parity with marketplace cards */
#uh-saved .uh-card__source,
#uh-saved .uh-card__source * { pointer-events: none; }
#uh-saved .uh-card__source {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-size: .85rem;
  font-weight: 600;
  color: var(--clr-text-muted);
}
#uh-saved .uh-card__source i { color: var(--clr-accent); }
#uh-saved .uh-card__source span { color: var(--clr-link); }

/* Actions */
#uh-saved .uh-card__actions {
  margin-top: .25rem;
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}
#uh-saved .uh-card__actions .btn {
  border-radius: 8px;
  padding: .45rem .7rem;
  font-size: .92rem;
  line-height: 1;
  transition: transform .06s ease, background .15s ease, color .15s ease;
}
#uh-saved .uh-card__actions .btn i { margin-right: .4rem; }
#uh-saved .uh-card__actions .btn:active { transform: translateY(1px); }

/* Subtle reveal on hover for non-touch screens */
@media (hover: hover) {
  #uh-saved .uh-card__actions { opacity: .92; }
  #uh-saved .uh-card:hover .uh-card__actions { opacity: 1; }
}

/* Focus states for a11y */
#uh-saved .uh-card:focus-within {
  outline: 2px solid color-mix(in srgb, var(--clr-accent) 55%, transparent);
  outline-offset: 2px;
}

/* Empty state alignment inside Saved tab */
#uh-saved .uh-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 2rem 1rem;
  border: 1px dashed var(--clr-border);
  border-radius: var(--radius-md);
  background: var(--clr-bg-alt);
  color: var(--clr-text-muted);
}

/* Responsive: stack image above content on narrow screens */
@media (max-width: 560px) {
  #uh-saved .uh-card {
    grid-template-columns: 1fr;      /* image on top, body below */
  }
  #uh-saved .uh-card__thumb {
    border-right: 0;
    border-bottom: 1px solid var(--clr-border);
    height: auto;
  }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  #uh-saved .uh-card:hover { transform: none; box-shadow: var(--shadow-md); }
  #uh-saved .uh-card__thumb,
  #uh-saved .uh-card { transition: none; }
}

/* === Modal thumbnails — adaptive layout, no-stretch, AR-safe === */
.modal-thumbs {
  --thumb: 64px;
  display: grid;
  /* fixed-size squares that auto-fit across the row */
  grid-template-columns: repeat(auto-fit, minmax(var(--thumb), var(--thumb)));
  grid-auto-rows: var(--thumb);
  gap: 8px;
  justify-content: center; /* center when 1–3 images */
}
.modal-thumbs button {
  display: block;
  aspect-ratio: 1 / 1;     /* perfect square targets */
  height: auto;            /* driven by aspect-ratio */
  padding: 0;
  background: transparent;
  border: 1px solid var(--clr-border);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
}
.modal-thumbs img {
  width: 100%;
  height: 100%;
  object-fit: contain;      /* preserve aspect ratio; no cropping, no stretch */
  object-position: center;
  background: var(--clr-bg-alt);
}
.modal-thumbs button[aria-selected="true"] {
  outline: 2px solid var(--clr-accent);
  outline-offset: 1px;
}
/* Hide the strip entirely if nothing to show (defensive) */
.modal-thumbs:empty { display: none; }

/* --- Mobile filmstrip: horizontal, scrollable, still no-stretch --- */
@media (max-width: 540px) {
  #productModal .modal-thumbs {
    padding: 0 .75rem .5rem;
    display: grid;
    grid-auto-flow: column;   /* single-row filmstrip */
    grid-auto-columns: 44px;  /* square thumbs */
    gap: .5rem;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    justify-content: start;   /* left align the strip on small screens */
  }
  #productModal .modal-thumbs button {
    aspect-ratio: 1 / 1;
    height: auto;
    border-radius: 6px;
  }
  #productModal .modal-thumbs img {
    object-fit: contain;      /* keep entire image visible in the thumb */
  }
}

/* --- Fix: listing thumbnail strip images (no stretch, center-fit) --- */
.equipment-card .card-thumbs img {
  object-fit: contain !important;
  object-position: center;
  background: var(--clr-bg);
}


/* Guest thumbnail blur (cards & modal thumbnails) */
.guest-thumb-blur {
  filter: blur(6px) saturate(.85);
  transform: scale(1.01);
}

/* Belt & suspenders: if a card was marked as guest-locked, blur its thumb strip */
.equipment-card.guest-locked .card-thumbs img {
  filter: blur(6px) saturate(.85);
  transform: scale(1.01);
}


