/* ========================================
   MARKETPLACE CATEGORY & PRODUCT PAGES
   E-ink optimized, using design tokens
   ======================================== */

/* ========================================
   CATEGORY HEADER
   ======================================== */

.category-header {
  display: flex;
  flex-direction: column;
  margin-bottom: var(--spacing-6);
  background-color: var(--color-bg-primary);
  border-radius: var(--border-radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--color-border-light);
}

.category-image-container {
  width: 100%;
  height: 200px;
  overflow: hidden;
}

.category-banner {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.category-banner:hover {
  transform: scale(1.03);
}

.category-info {
  padding: var(--spacing-6);
}

.category-title {
  font-family: var(--font-serif);
  font-size: var(--text-3xl);
  font-weight: 600;
  margin-bottom: var(--spacing-3);
  color: var(--color-text-primary);
  position: relative;
  padding-bottom: var(--spacing-3);
}

.category-title::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 60px;
  height: 3px;
  background-color: var(--color-gold);
  border-radius: 2px;
}

.category-description {
  color: var(--color-text-secondary);
  line-height: var(--leading-relaxed);
  font-size: var(--text-base);
}

/* ========================================
   PRODUCTS HEADER
   ======================================== */

.products-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: var(--spacing-4);
  margin-bottom: var(--spacing-6);
  padding: var(--spacing-6);
  background-color: var(--color-bg-primary);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow);
  border: 1px solid var(--color-border-light);
}

.products-title {
  font-family: var(--font-serif);
  font-size: var(--text-2xl);
  font-weight: 600;
  color: var(--color-text-primary);
  margin: 0;
  flex: 1;
}

.products-filters {
  display: flex;
  align-items: center;
  gap: var(--spacing-4);
  flex-wrap: wrap;
}

/* ========================================
   RESULTS COUNT
   ======================================== */

.results-count {
  display: flex;
  align-items: baseline;
  gap: var(--spacing-2);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

.count-info {
  color: var(--color-text-primary);
}

.count-info strong {
  color: var(--color-gold);
  font-weight: 700;
}

.count-detail {
  color: var(--color-text-muted);
}

/* ========================================
   SORT CONTROLS - GOLD THEME
   ======================================== */

.sort-controls {
  display: flex;
  align-items: center;
}

.sort-form {
  display: flex;
  align-items: center;
  gap: var(--spacing-2);
  background-color: var(--color-bg-secondary);
  padding: var(--spacing-2) var(--spacing-3);
  border-radius: var(--border-radius);
  border: 1px solid var(--color-border);
}

.sort-form label {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  font-weight: 500;
  white-space: nowrap;
}

.sort-form select {
  padding: var(--spacing-2) var(--spacing-3);
  padding-right: var(--spacing-8);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-sm);
  background-color: var(--color-bg-primary);
  font-size: var(--text-sm);
  color: var(--color-text-primary);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%234a4a4a' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  min-width: 140px;
}

.sort-form select:focus {
  border-color: var(--color-gold);
  outline: none;
  box-shadow: var(--focus-ring);
}

.sort-button {
  background-color: var(--color-gold);
  color: white;
  border: none;
  padding: var(--spacing-2) var(--spacing-4);
  border-radius: var(--border-radius-sm);
  font-weight: 600;
  font-size: var(--text-sm);
  cursor: pointer;
  transition: var(--transition);
}

.sort-button:hover {
  background-color: var(--color-gold-dark);
  transform: translateY(-1px);
}

.sort-button:focus-visible {
  outline: 3px solid var(--color-gold);
  outline-offset: 2px;
}

/* ========================================
   PRODUCTS SECTION
   ======================================== */

.products-section {
  margin-top: var(--spacing-6);
}

.section-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: var(--spacing-4);
  margin-bottom: var(--spacing-6);
}

.section-title {
  font-family: var(--font-serif);
  font-size: var(--text-xl);
  font-weight: 600;
  margin: 0;
  color: var(--color-text-primary);
}

/* ── Filter Bar (bordered card) ────────────── */

.filter-bar {
  padding: var(--spacing-3) var(--spacing-4);
  background-color: var(--color-bg-primary);
  border: 1px solid var(--color-border-light);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-sm);
}

.filter-bar-controls {
  display: flex;
  align-items: center;
  gap: var(--spacing-2);
}

.filter-bar-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-2);
  padding-top: var(--spacing-3);
  margin-top: var(--spacing-3);
  border-top: 1px solid var(--color-border-light);
}

.filter-bar-active {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--spacing-2);
  width: 100%;
  padding-top: var(--spacing-3);
  margin-top: var(--spacing-3);
  border-top: 1px solid var(--color-border-light);
}

.product-count {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  background-color: var(--color-bg-secondary);
  padding: var(--spacing-1) var(--spacing-3);
  border-radius: var(--border-radius-sm);
}

/* ========================================
   PRODUCT GRID
   ======================================== */

.product-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--spacing-8);
  margin-left: var(--spacing-8);
  margin-right: var(--spacing-8);
  margin-bottom: var(--spacing-6);
}

@media (max-width: 992px) {
  .product-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 768px) {
  .product-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .product-grid {
    grid-template-columns: 1fr;
  }
}

.product-card {
  height: 100%;
  transition: var(--transition);
  border-radius: var(--border-radius-lg);
  overflow: hidden;
  background-color: var(--color-bg-primary);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
}

.product-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--color-gold-light);
}

/* ========================================
   PRODUCT CARD OVERRIDES FOR GRID VIEW
   Cleaner, more compact display
   ======================================== */

.product-card .product-price {
  padding: 0;
  margin-bottom: var(--spacing-2);
  background-color: transparent;
  box-shadow: none;
  border: none;
}

.product-card .price-display {
  margin-bottom: 0.25rem;
  background: none;
  padding: 0;
  border-left: none;
}

.product-card .price-label {
  display: none;
}

.product-card .price {
  font-size: 1.2em;
  flex-direction: row;
  align-items: baseline;
  gap: 3px;
  color: var(--color-gold);
}

.product-card .price small {
  font-size: 0.75em;
  color: var(--color-text-muted);
  font-weight: normal;
}

.product-card .availability {
  font-size: var(--text-xs);
  padding: var(--spacing-1) var(--spacing-2);
  margin-top: var(--spacing-2);
  display: inline-flex;
  border-radius: var(--border-radius-sm);
}

.product-card .price-per-kg {
  font-size: var(--text-xs);
  margin-top: var(--spacing-1);
  padding: 2px 6px;
  display: inline-block;
}

.product-card .product-content {
  padding: var(--spacing-3);
}

.product-card .product-title {
  font-weight: 600;
  margin-bottom: var(--spacing-2);
  line-height: var(--leading-tight);
  height: 2.6em;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.product-card .product-image {
  height: 180px;
}

/* ========================================
   ADD TO CART - GOLD THEME
   ======================================== */

.product-card .add-to-cart-btn {
  font-size: var(--text-xs);
  padding: var(--spacing-2) var(--spacing-3);
  background: var(--color-gold);
  transition: var(--transition);
}

.product-card .add-to-cart-btn:hover {
  background: var(--color-gold-dark);
  transform: translateY(-1px);
}

.product-card .card-quantity-input {
  width: 50px;
  padding: var(--spacing-1);
  font-size: var(--text-xs);
}

.product-card .card-quantity-label {
  font-size: var(--text-xs);
}

.product-card .card-quantity-unit {
  font-size: 0.7rem;
}

/* ========================================
   EMPTY STATE
   ======================================== */

.empty-state {
  text-align: center;
  padding: var(--spacing-12) var(--spacing-6);
  background-color: var(--color-bg-secondary);
  border-radius: var(--border-radius-lg);
  margin-top: var(--spacing-6);
  border: 1px dashed var(--color-border);
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: var(--spacing-4);
  color: var(--color-text-muted);
}

.empty-icon::before {
  content: '📦';
}

.empty-message {
  font-size: var(--text-lg);
  color: var(--color-text-secondary);
  margin-bottom: var(--spacing-6);
  line-height: var(--leading-relaxed);
}

.no-results {
  color: var(--color-text-muted);
  font-style: italic;
}

/* Empty state button - gold theme */
.empty-state .btn-outline-primary {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-2);
  padding: var(--spacing-3) var(--spacing-6);
  border: 2px solid var(--color-gold);
  color: var(--color-gold);
  background: transparent;
  border-radius: var(--border-radius);
  font-weight: 600;
  text-decoration: none;
  transition: var(--transition);
}

.empty-state .btn-outline-primary:hover {
  background-color: var(--color-gold);
  color: white;
}

/* ========================================
   PRODUCT CARD STRUCTURE
   ======================================== */

.product-card-inner {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.product-content {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
}

.product-actions {
  margin-top: auto;
}

/* ========================================
   RESPONSIVE ADJUSTMENTS
   ======================================== */

@media (max-width: 992px) {
  .products-header {
    flex-direction: column;
    align-items: stretch;
  }

  .products-filters {
    flex-direction: column;
    align-items: stretch;
    gap: var(--spacing-3);
  }

  .sort-controls {
    width: 100%;
  }

  .sort-form {
    width: 100%;
    justify-content: space-between;
  }

  .sort-form select {
    flex: 1;
  }

  .category-title {
    font-size: var(--text-2xl);
  }
}

@media (max-width: 768px) {
  .product-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--spacing-3);
  }

  .product-card .product-image {
    height: 150px;
  }

  .product-card .product-content {
    padding: var(--spacing-3);
  }

  .product-card .product-title {
    font-size: var(--text-sm);
  }

  .products-header,
  .category-header {
    padding: var(--spacing-4);
  }

  .category-info {
    padding: var(--spacing-4);
  }

  /* Touch-friendly targets */
  .sort-form select,
  .sort-button,
  .product-card .add-to-cart-btn {
    min-height: 44px;
  }
}

@media (max-width: 480px) {
  .product-grid {
    grid-template-columns: 1fr;
  }

  .product-card {
    display: flex;
    flex-direction: row;
    height: auto;
  }

  .product-card .product-image {
    width: 120px;
    height: 120px;
    flex-shrink: 0;
  }

  .product-card-inner {
    flex-direction: row;
    width: 100%;
  }

  .product-card .product-content {
    flex: 1;
    justify-content: center;
  }

  .product-card .product-title {
    height: auto;
    -webkit-line-clamp: 3;
  }
}

/* ========================================
   FILTER TOOLBAR
   Horizontal filter bar above product grid.
   E-ink optimized: uses border weight + font
   weight for active state, not color alone.
   ======================================== */

.filter-toolbar {
  margin-bottom: var(--spacing-6);
  padding: var(--spacing-4);
  background-color: var(--color-bg-primary);
  border: 1px solid var(--color-border-light);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-sm);
}

.filter-toolbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--spacing-2);
}

.filter-toolbar-row + .filter-toolbar-row {
  margin-top: var(--spacing-2);
}

/* ── Filter Chips ────────────────────────── */

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-1);
  padding: var(--spacing-1) var(--spacing-3);
  min-height: 36px;
  border: 2px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-bg-primary);
  font-size: var(--text-sm);
  color: var(--color-text-primary);
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  user-select: none;
}

.filter-chip:hover {
  border-color: var(--color-gold-light);
  background-color: var(--color-bg-secondary);
}

/* Active: bold weight + gold border (e-ink distinguishable) */
.filter-chip-active {
  border-color: var(--color-gold);
  font-weight: 700;
  background-color: var(--color-bg-secondary);
}

/* Visually hidden checkbox inside chip labels */
.filter-chip-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.filter-chip-count {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-weight: 400;
}

/* ── Filter Dropdown (details/summary) ───── */

.filter-dropdown {
  position: relative;
}

.filter-dropdown-trigger {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-2);
  padding: var(--spacing-1) var(--spacing-3);
  min-height: 36px;
  border: 2px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-bg-primary);
  font-size: var(--text-sm);
  color: var(--color-text-primary);
  cursor: pointer;
  transition: var(--transition);
  list-style: none;
  user-select: none;
}

.filter-dropdown-trigger::-webkit-details-marker {
  display: none;
}

.filter-dropdown-trigger::after {
  content: '';
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  margin-left: var(--spacing-1);
  transition: transform 0.2s ease;
}

.filter-dropdown[open] .filter-dropdown-trigger::after {
  transform: rotate(180deg);
}

.filter-dropdown[open] .filter-dropdown-trigger {
  border-color: var(--color-gold);
}

.filter-dropdown-trigger:hover {
  border-color: var(--color-gold-light);
  background-color: var(--color-bg-secondary);
}

.filter-dropdown-trigger:focus-visible {
  outline: 3px solid var(--color-gold);
  outline-offset: 2px;
}

.filter-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  background-color: var(--color-gold);
  color: white;
  font-size: var(--text-xs);
  font-weight: 700;
  border-radius: 999px;
  line-height: 1;
}

.filter-dropdown-content {
  position: absolute;
  top: calc(100% + var(--spacing-1));
  left: 0;
  z-index: 10;
  min-width: 200px;
  padding: var(--spacing-3);
  background-color: var(--color-bg-primary);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-md);
}

.filter-dropdown-content .filter-option {
  display: flex;
  align-items: center;
  padding: var(--spacing-2) 0;
  cursor: pointer;
  transition: var(--transition);
}

.filter-dropdown-content .filter-option:hover {
  color: var(--color-gold);
}

.filter-dropdown-content .filter-option input[type="checkbox"] {
  width: 1.25rem;
  height: 1.25rem;
  margin-right: var(--spacing-3);
  cursor: pointer;
  accent-color: var(--color-gold);
  flex-shrink: 0;
}

.filter-dropdown-content .filter-option-label {
  font-size: var(--text-sm);
  color: var(--color-text-primary);
}

/* ── Sort Control (inline) ───────────────── */

.filter-sort {
  display: flex;
  align-items: center;
  gap: var(--spacing-2);
}

.filter-sort-label {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  font-weight: 500;
  white-space: nowrap;
}

.filter-sort-select {
  padding: var(--spacing-2) var(--spacing-3);
  padding-right: var(--spacing-8);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-sm);
  background-color: var(--color-bg-primary);
  font-size: var(--text-sm);
  color: var(--color-text-primary);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%234a4a4a' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  min-width: 140px;
  min-height: 36px;
}

.filter-sort-select:focus {
  border-color: var(--color-gold);
  outline: none;
  box-shadow: var(--focus-ring);
}

/* ── Apply Button ─────────────────────────── */

.filter-apply-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: var(--spacing-2) var(--spacing-3);
  background-color: var(--color-gold);
  color: white;
  border: 2px solid var(--color-gold);
  border-radius: 999px;
  font-weight: 600;
  font-size: var(--text-sm);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.filter-apply-btn:hover {
  background-color: var(--color-gold-dark);
  border-color: var(--color-gold-dark);
}

.filter-apply-btn:focus-visible {
  outline: 3px solid var(--color-gold);
  outline-offset: 2px;
}

/* ── Active Filters Row ──────────────────── */

.filter-toolbar-active {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--spacing-2);
  width: 100%;
  padding-top: var(--spacing-3);
  border-top: 1px solid var(--color-border-light);
}

.filter-toolbar-active-label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-right: var(--spacing-1);
}

.filter-toolbar-active .active-filter-tag {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-1);
  background-color: var(--color-bg-secondary);
  border: 2px solid var(--color-gold);
  padding: var(--spacing-1) var(--spacing-3);
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-primary);
}

.filter-clear-link {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  text-decoration: underline;
  margin-left: auto;
  transition: var(--transition);
}

.filter-clear-link:hover {
  color: var(--color-gold);
}

/* ── Responsive: Filter Toolbar ──────────── */

@media (max-width: 768px) {
  .filter-toolbar {
    padding: var(--spacing-3);
  }

  .filter-toolbar-row {
    gap: var(--spacing-2);
  }

  .filter-chip,
  .filter-dropdown-trigger,
  .filter-apply-btn {
    min-height: 44px;
  }

  .filter-sort-select {
    min-height: 44px;
  }

  .filter-bar {
    width: 100%;
  }

  /* Dropdown becomes inline on mobile */
  .filter-dropdown-content {
    position: static;
    box-shadow: none;
    border: 1px solid var(--color-border-light);
    border-radius: var(--border-radius-sm);
    margin-top: var(--spacing-2);
    width: 100%;
  }

  .filter-dropdown {
    width: 100%;
  }

  .filter-dropdown-trigger {
    width: 100%;
    justify-content: space-between;
  }
}

/* ========================================
   CONTEXTUAL SIDEBAR NAVIGATION
   Shows parent + children or siblings
   depending on current category depth.
   E-ink optimized: weight + border, not
   color alone, for active state.
   ======================================== */

.context-sidebar {
  background-color: var(--color-bg-primary);
  border: 1px solid var(--color-border-light);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.context-sidebar-header {
  padding: var(--spacing-3) var(--spacing-4) var(--spacing-4);
  background: linear-gradient(
    135deg,
    var(--color-bg-secondary) 0%,
    var(--color-bg-primary) 100%
  );
  border-bottom: 2px solid var(--color-gold);
}

/* Small "go up" breadcrumb inside header */
.context-sidebar-parent {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-1);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-text-muted);
  text-decoration: none;
  transition: var(--transition);
  margin-bottom: var(--spacing-2);
}

.context-sidebar-parent:hover {
  color: var(--color-gold);
}

.context-sidebar-parent:focus-visible {
  outline: 3px solid var(--color-gold);
  outline-offset: 2px;
}

/* Current category = sidebar heading */
.context-sidebar-title {
  font-family: var(--font-serif);
  font-size: var(--text-lg);
  font-weight: 700;
  margin: 0;
  color: var(--color-text-primary);
}

/* Category list */
.context-sidebar-list {
  list-style: none;
  margin: 0;
  padding: var(--spacing-2) 0;
}

.context-sidebar-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-2);
  padding: var(--spacing-2) var(--spacing-4);
  font-size: var(--text-sm);
  color: var(--color-text-primary);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: var(--transition);
}

.context-sidebar-item:hover {
  background-color: var(--color-bg-secondary);
  border-left-color: var(--color-gold-light);
}

.context-sidebar-item:focus-visible {
  outline: 3px solid var(--color-gold);
  outline-offset: -3px;
}

.context-sidebar-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Product count badge */
.context-sidebar-count {
  flex-shrink: 0;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  background-color: var(--color-bg-secondary);
  padding: 1px var(--spacing-2);
  border-radius: 999px;
  min-width: 22px;
  text-align: center;
  border: 1px solid var(--color-border-light);
}



