/* =============================================
   COMPONENT LISTING PAGES
   ============================================= */

.crowd-source {
  padding: var(--space-4) 0 var(--space-3);
  margin-top: var(--space-6);
  margin-bottom: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}

.crowd-source-content {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
}

.crowd-source-content a {
  color: var(--accent-text);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: rgba(91, 141, 239, 0.3);
}

.crowd-source-content a:hover {
  color: var(--accent-hover);
  text-decoration-color: var(--accent-hover);
}

/* Two-column layout: sidebar + results */
.listing-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-6);
  padding-bottom: var(--space-section);
}

/* Sidebar filters — blend with page; no card frame */
.component-filters {
  background: var(--bg-base);
  border: none;
  border-radius: 0;
  padding-inline: var(--space-2);
  padding-bottom: var(--space-4);
  display: none;
}

.component-filters.sidebar-open {
  display: block;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 200;
  width: min(340px, 90vw);
  border-radius: 0;
  overflow-y: auto;
  padding: var(--space-5);
  box-shadow: 8px 0 32px rgba(0, 0, 0, 0.35);
}

.sidebar-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-secondary);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  cursor: pointer;
  margin-bottom: var(--space-4);
  min-height: 44px;
  transition: color var(--duration-normal) var(--ease-out),
              border-color var(--duration-normal) var(--ease-out);
}

.sidebar-toggle:hover {
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.sidebar-toggle svg {
  width: 16px;
  height: 16px;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 199;
  background: var(--bg-overlay);
}

.sidebar-overlay.active {
  display: block;
}

/* Filter sections */
.filter-section {
  margin-bottom: var(--space-5);
  padding-bottom: var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
}

.filter-section:last-of-type {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.filter-section-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-heading);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-2);
}

.filter-section-hint {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  line-height: 1.45;
  margin: 0 0 var(--space-3);
}

.filter-section--ota-extra[hidden] {
  display: none !important;
}

.filter-section-title svg {
  width: 14px;
  height: 14px;
  opacity: 0.5;
}

/* Search in sidebar */
.search-container {
  margin-bottom: var(--space-5);
}

.search-box {
  position: relative;
}

.search-icon {
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  width: 16px;
  height: 16px;
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: var(--space-3) var(--space-3) var(--space-3) calc(var(--space-3) + 22px);
  font-size: var(--text-sm);
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  min-height: 44px;
  transition: border-color var(--duration-normal) var(--ease-out);
}

.filter-inline-search {
  margin-bottom: var(--space-2);
}

.filter-inline-search-input {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  min-height: 38px;
}

.filter-inline-search-input::placeholder {
  color: var(--text-tertiary);
}

.filter-inline-search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.search-input::placeholder {
  color: var(--text-tertiary);
}

.search-clear {
  position: absolute;
  right: var(--space-2);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  cursor: pointer;
  padding: var(--space-2);
  border: none;
  background: none;
  min-width: 32px;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.search-clear:hover {
  color: var(--text-secondary);
}

/* Sort select */
#sort_select,
.filter-section select {
  width: 100%;
  padding: var(--space-3) var(--space-3);
  font-size: var(--text-sm);
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 16 16' fill='%23a0a3b1' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M4.427 6.427l3.396 3.396a.25.25 0 00.354 0l3.396-3.396A.25.25 0 0011.396 6H4.604a.25.25 0 00-.177.427z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  background-size: 14px;
  padding-right: calc(var(--space-3) + 18px);
  cursor: pointer;
  min-height: 44px;
}

#sort_select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

/* Price inputs */
.price-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.price-input-label {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-bottom: 4px;
}

.price-input {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  min-height: 36px;
}

.price-input:focus {
  outline: none;
  border-color: var(--accent);
}

.price-slider-wrapper {
  position: relative;
  height: 20px;
  margin-bottom: var(--space-1);
}

.price-slider {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 6px;
  transform: translateY(-50%);
  background: var(--border-default);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.price-slider-track {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  border-radius: var(--radius-full);
  pointer-events: none;
}

.price-presets {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.price-preset-btn {
  font-size: 11px;
  font-weight: var(--weight-semibold);
  padding: 6px 10px;
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: color var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out),
    background var(--duration-fast) var(--ease-out);
}

.price-preset-btn:hover {
  color: var(--accent-text);
  border-color: var(--accent);
  background: var(--accent-subtle);
}

.price-range-slider {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.price-labels {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

/* Filter checkboxes */
.filter-checkbox-container {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.filter-checkbox-container--scroll {
  max-height: min(320px, 45vh);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 var(--space-1) 0 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.filter-checkbox-container--scroll::-webkit-scrollbar {
  width: 6px;
}

.filter-checkbox-container--scroll::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-full);
}

.filter-empty-note {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin: 0;
}

.filter-checkbox-label {
  border-radius: var(--radius-sm);
  margin: 0;
  transition: background var(--duration-fast) var(--ease-out);
}

.filter-checkbox-label:hover {
  background: rgba(255, 255, 255, 0.04);
}

.filter-checkbox-container label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  cursor: pointer;
  min-height: 32px;
  padding: var(--space-1) var(--space-2);
  margin: 0;
  box-sizing: border-box;
}

.filter-checkbox-container input[type="checkbox"] {
  appearance: none;
  width: 16px;
  height: 16px;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  background: var(--bg-elevated);
  flex-shrink: 0;
  cursor: pointer;
}

.filter-checkbox-container input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 16 16' fill='%230b0d14' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z'/%3E%3C/svg%3E");
  background-size: 10px;
  background-position: center;
  background-repeat: no-repeat;
}

.filter-loading {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  padding: var(--space-2) 0;
}

/* Clear filters */
.clear-filters-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-3) var(--space-3);
  margin-top: var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  background: transparent;
  border: 1px dashed var(--border-default);
  border-radius: var(--radius-md);
  cursor: pointer;
  min-height: 44px;
  transition: color var(--duration-normal) var(--ease-out),
              border-color var(--duration-normal) var(--ease-out),
              background var(--duration-normal) var(--ease-out);
}

.clear-filters-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-strong);
  background: rgba(255, 255, 255, 0.04);
}

.clear-filters-btn svg {
  width: 14px;
  height: 14px;
}

/* Results area */
.component-results {
  min-width: 0;
}

.results-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
  gap: var(--space-3);
}

.type-of-results {
  font-family: var(--font-heading);
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.results-subtitle {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  margin-top: 2px;
}

.results-count {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
}

.view-controls {
  display: flex;
  gap: var(--space-1);
}

.view-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  color: var(--text-tertiary);
  border-radius: var(--radius-md);
  transition: color var(--duration-normal) var(--ease-out),
              background var(--duration-normal) var(--ease-out);
}

.view-toggle:hover,
.view-toggle.active {
  color: var(--accent-text);
  background: var(--accent-subtle);
}

/* Products container (populated by AJAX) */
.products-container {
  min-height: 200px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.products-container .loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-12);
  color: var(--text-tertiary);
  font-size: var(--text-sm);
}

.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border-default);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-bottom: var(--space-3);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Products table (rendered by ajax.php) */
.products-table {
  width: 100%;
}

.products-table th {
  font-family: var(--font-heading);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: var(--space-3) var(--space-3);
  border-bottom: 1px solid var(--border-default);
  text-align: left;
  cursor: pointer;
}

.products-table th:hover {
  color: var(--text-secondary);
}

.products-table td {
  padding: var(--space-3) var(--space-3);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

.products-table tr {
  transition: background var(--duration-fast) var(--ease-out);
}

.products-table tr:hover td {
  background: var(--accent-subtle);
}

.products-table img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: var(--radius-md);
}

.products-table .add-to-build-btn {
  display: inline-flex;
  align-items: center;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  padding: var(--space-2) var(--space-3);
  color: var(--text-inverse);
  background: var(--accent);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  white-space: nowrap;
  min-height: 32px;
  transition: background var(--duration-normal) var(--ease-out),
              box-shadow var(--duration-normal) var(--ease-out);
}

.products-table .add-to-build-btn:hover {
  background: var(--accent-hover);
  box-shadow: var(--shadow-accent);
}

/* Pagination */
.pagination-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: var(--space-8) 0;
}

.pagination-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  cursor: pointer;
  min-height: 44px;
  transition: color var(--duration-normal) var(--ease-out),
              border-color var(--duration-normal) var(--ease-out);
}

.pagination-btn:hover:not(:disabled) {
  color: var(--accent-text);
  border-color: var(--accent);
}

.pagination-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.pagination-btn svg {
  width: 14px;
  height: 14px;
}

.pagination-info {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
}

/* Mobile: ensure interactive controls meet 44px touch targets */
@media (max-width: 1023px) {
  .view-toggle {
    width: 44px;
    height: 44px;
  }

  .products-table .add-to-build-btn {
    min-height: 40px;
  }
}

/* Desktop: sidebar visible */
@media (min-width: 1024px) {
  .listing-layout {
    grid-template-columns: minmax(280px, 320px) 1fr;
    align-items: start;
    gap: var(--space-8);
  }

  .component-filters {
    display: block;
    position: sticky;
    top: calc(var(--header-height) + var(--space-4));
    max-height: calc(100vh - var(--header-height) - var(--space-8));
    overflow-y: auto;
    overflow-x: hidden;
    padding-inline: var(--space-2);
    padding-bottom: var(--space-4);
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
  }

  .component-filters::-webkit-scrollbar {
    width: 6px;
  }

  .component-filters::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: var(--radius-full);
  }

  .sidebar-toggle {
    display: none;
  }
}
