/**
 * Marketplace page – sticky header, search, category pills, card grid, FAB.
 * Uses root theme variables (--bg-page, --bg-card, --text-main, etc.) for light/dark.
 */
body.marketplace-page {
  background-color: var(--bg-page);
  color: var(--text-main);
  font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  margin: 0;
  padding-bottom: 88px; /* Space for FAB */
}

/* Ensure floating burger and navbar are above marketplace sticky header on mobile */
@media (max-width: 768px) {
  body.marketplace-page .mobile-menu-pull-tab {
    display: flex;
    z-index: 1002;
  }
  body.marketplace-page .mobile-menu-backdrop {
    z-index: 1098;
  }
  body.marketplace-page .mobile-menu {
    z-index: 1100;
  }
}

/* ----- Marketplace sticky header (below app-header) ----- */
.marketplace-header {
  background: var(--bg-card);
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 1px solid var(--border-default);
}

.marketplace-header-inner {
  padding: 12px 16px;
}

/* Search bar */
.marketplace-search-form {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 0;
}

.search-bar-container {
  flex: 1;
  min-width: 0;
}

.marketplace-search-form .search-input {
  width: 100%;
  padding: 10px 16px;
  border-radius: 20px;
  border: 1px solid var(--border-default);
  background: var(--bg-input);
  color: var(--text-main);
  font-size: 0.95rem;
  box-sizing: border-box;
}

.marketplace-search-form .search-input::placeholder {
  color: var(--text-muted);
}

.marketplace-search-form .btn-messages {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 20px;
  border: none;
  background: var(--brand-orange-500);
  color: var(--neutral-900, #17212b);
  cursor: pointer;
  text-decoration: none;
  flex-shrink: 0;
}

.marketplace-search-form .btn-messages img {
  width: 24px;
  height: 24px;
  display: block;
  object-fit: contain;
}

.marketplace-search-form .btn-messages:hover {
  filter: brightness(1.08);
}

/* Category pills */
.category-pills {
  display: flex;
  overflow-x: auto;
  padding: 8px 0 0;
  gap: 8px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.category-pills::-webkit-scrollbar {
  display: none;
}

.pill {
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  color: var(--text-main);
  padding: 8px 16px;
  border-radius: 18px;
  font-size: 0.85rem;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
  flex-shrink: 0;
}

.pill:hover {
  background: var(--border-default);
}

.pill.active {
  background: var(--brand-orange-500);
  border-color: var(--brand-orange-500);
  color: var(--neutral-900, #17212b);
  font-weight: 600;
}

/* ----- Main content & grid ----- */
.marketplace-content {
  padding: 12px 16px 24px;
}

.marketplace-feedback {
  margin: 12px 16px 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}

.marketplace-feedback.feedback-error {
  background: color-mix(in srgb, var(--error-500) 12%, var(--bg-card));
  border: 1px solid var(--error-500);
  color: var(--text-main);
}

.marketplace-feedback.feedback-success {
  background: color-mix(in srgb, var(--success-500) 12%, var(--bg-card));
  border: 1px solid var(--success-500);
  color: var(--text-main);
}

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

/* Mobile: responsive grid for different phone sizes – larger cards, better image display */
@media (max-width: 768px) {
  .marketplace-content {
    padding: 12px 12px 24px;
  }
  .grid-layout {
    gap: 12px;
  }
  /* Very small phones: single column for larger, more readable cards */
  @media (max-width: 360px) {
    .grid-layout {
      grid-template-columns: 1fr;
      gap: 14px;
    }
  }
  /* Medium+ phones: more breathing room */
  @media (min-width: 375px) {
    .marketplace-content {
      padding: 14px 16px 24px;
    }
    .grid-layout {
      gap: 14px;
    }
  }
  @media (min-width: 400px) {
    .grid-layout {
      gap: 16px;
    }
  }
}

.market-card {
  background: var(--bg-card);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-default);
  cursor: pointer;
  text-align: left;
  padding: 0;
  color: inherit;
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.market-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-soft);
}

.market-card:focus-visible {
  outline: 2px solid var(--brand-orange-500);
  outline-offset: 2px;
}

.image-wrapper {
  aspect-ratio: 1 / 1;
  overflow: hidden;
  position: relative;
  background: var(--bg-input);
}

.image-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}

.market-card-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  background: var(--text-muted);
  color: var(--bg-card);
  padding: 4px 8px;
  border-radius: 4px;
}

.market-card-badge-pending {
  background: var(--brand-orange-500, #e85d04);
  color: white;
}

.card-details {
  padding: 10px;
}

.market-card .price {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0 0 2px 0;
  color: var(--brand-orange-500);
}

.market-card .title {
  font-size: 0.9rem;
  font-weight: 400;
  margin: 0;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.market-card .location-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 4px 0 0 0;
}

/* Floating Action Button */
.fab-add {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  background: var(--brand-orange-500);
  border: none;
  border-radius: 50%;
  color: var(--neutral-900, #17212b);
  font-size: 1.75rem;
  line-height: 1;
  box-shadow: var(--shadow-card);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1001;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  text-decoration: none;
}

.fab-add:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

.fab-add:focus-visible {
  outline: 2px solid var(--text-main);
  outline-offset: 2px;
}

/* Modal content (create form & detail) – use theme variables */
.marketplace-modal-form,
.marketplace-detail-content {
  background: var(--bg-card);
  color: var(--text-main);
  padding: var(--space-6);
  border-radius: var(--radius-md);
}

.marketplace-modal-form h2,
.marketplace-detail-content h2,
.marketplace-modal-form label,
.marketplace-detail-content .row-meta,
.marketplace-detail-content strong {
  color: var(--text-main);
}

.marketplace-modal-form input,
.marketplace-modal-form textarea,
.marketplace-modal-form select {
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  width: 100%;
  box-sizing: border-box;
}

/* Empty state */
.marketplace-empty {
  color: var(--text-muted);
  font-size: 0.95rem;
  text-align: center;
  padding: 2rem 1rem;
  margin: 0;
}

.marketplace-empty .btn-inline {
  background: none;
  border: none;
  color: var(--brand-orange-500);
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
  font-size: inherit;
}

.marketplace-empty .btn-inline:hover {
  color: var(--brand-orange-600);
}

/* Listing detail modal: one big image + row of thumbs (image swapper) */
.listing-modal-gallery {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.listing-modal-gallery-main {
  width: 100%;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-input);
  aspect-ratio: 4/3;
}

.listing-modal-gallery-main .detail-hero-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.listing-modal-gallery-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-start;
  min-height: 0;
}

.listing-modal-thumb {
  flex: 0 0 72px;
  width: 72px;
  height: 72px;
  padding: 0;
  border: 2px solid var(--border-default);
  border-radius: 0.4rem;
  overflow: hidden;
  background: var(--bg-input);
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.listing-modal-thumb:hover {
  border-color: var(--brand-orange-400);
}

.listing-modal-thumb.is-active {
  border-color: var(--brand-orange-500);
  box-shadow: 0 0 0 2px var(--brand-orange-500);
}

.listing-modal-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.marketplace-detail-content .detail-hero-img {
  width: 100%;
  border-radius: var(--radius-md);
  max-height: 280px;
  object-fit: cover;
}

.marketplace-detail-content .detail-price {
  color: var(--brand-orange-500);
  font-weight: 700;
  font-size: 1.25rem;
}

/* Desktop */
@media (min-width: 768px) {
  .grid-layout {
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
  }

  .marketplace-content {
    padding: 20px 24px 32px;
  }

  .marketplace-header-inner {
    padding: 16px 24px;
  }

  .category-pills {
    padding: 12px 0 0;
    gap: 10px;
  }
}

/* ----- My listings page ----- */
.my-listings-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.my-listing-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
}

.my-listing-thumb {
  flex-shrink: 0;
  width: 80px;
  height: 80px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: block;
}

.my-listing-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.my-listing-info {
  flex: 1;
  min-width: 0;
}

.my-listing-info h3 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.my-listing-info h3 a {
  color: var(--text-main);
  text-decoration: none;
}

.my-listing-info h3 a:hover {
  text-decoration: underline;
}

.my-listing-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

@media (max-width: 768px) {
  body.my-listings-page .app-main {
    padding-left: var(--space-3);
    padding-right: var(--space-3);
  }
  body.my-listings-page .dashboard-intro,
  body.my-listings-page .marketplace-content {
    max-width: 100% !important;
  }
  body.my-listings-page .dashboard-intro h1 {
    font-size: 1.35rem;
  }
  body.my-listings-page .dashboard-intro p {
    font-size: 0.9375rem;
  }
  body.my-listings-page .dashboard-intro .btn {
    font-size: 0.875rem;
  }
  body.my-listings-page .my-listings-list {
    gap: var(--space-3);
    padding: 0;
  }
  body.my-listings-page .my-listing-row {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-2);
    padding: var(--space-3);
  }
  body.my-listings-page .my-listing-thumb {
    width: 100%;
    height: 160px;
    border-radius: var(--radius-sm);
  }
  body.my-listings-page .my-listing-info h3 {
    font-size: 0.9375rem;
  }
  body.my-listings-page .my-listing-info h3 a {
    word-break: break-word;
  }
  body.my-listings-page .my-listing-actions {
    flex-direction: row;
    justify-content: flex-start;
    flex-wrap: wrap;
  }
  body.my-listings-page .my-listing-actions .btn {
    min-width: 0;
    flex: 1 1 auto;
  }
}

/* ----- Listing edit page: image manager ----- */
.listing-edit-images {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 12px 0;
}

.listing-edit-image-wrap {
  position: relative;
  width: 100px;
  height: 100px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid var(--border-default);
}

.listing-edit-image-wrap.is-main {
  border-color: var(--brand-orange-500);
  box-shadow: 0 0 0 2px var(--brand-orange-500);
}

.listing-edit-image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.listing-edit-image-actions {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  gap: 4px;
  padding: 4px;
  background: rgba(0,0,0,0.6);
}

.listing-edit-image-actions button {
  flex: 1;
  padding: 4px 6px;
  font-size: 0.75rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  background: var(--bg-card);
  color: var(--text-main);
}

.listing-edit-image-actions button.set-main {
  background: var(--brand-orange-500);
  color: var(--neutral-900, #17212b);
}

.listing-edit-add-images {
  width: 100px;
  height: 100px;
  border: 2px dashed var(--border-default);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: var(--bg-input);
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 8px;
}

.listing-edit-add-images:hover {
  border-color: var(--brand-teal-500);
  color: var(--text-main);
}

.listing-edit-add-images input[type="file"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

/* ----- My advertensies: 3 tabs (active, pending, rejected) ----- */
.my-listings-tabs-wrap {
  margin-top: var(--space-4);
}

.my-listings-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border-default);
  margin-bottom: var(--space-4);
}

.my-listings-tab {
  padding: var(--space-3) var(--space-4);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: var(--font-size-base);
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.my-listings-tab:hover {
  color: var(--text-main);
}

.my-listings-tab.active {
  color: var(--brand-teal-800);
  border-bottom-color: var(--brand-teal-800);
}

.my-listings-tab .tab-count {
  margin-left: var(--space-2);
  opacity: 0.85;
}

.my-listings-panel {
  min-height: 120px;
}

.rejection-reason {
  margin-top: var(--space-2);
  padding: var(--space-2);
  background: color-mix(in srgb, var(--error-500) 12%, transparent);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: var(--font-size-sm);
}

.my-listing-row-rejected .rejection-reason {
  border-left: 3px solid var(--error-500);
}
