/* ====== PLP & Search Results Redesign (PBI #45290) ====== */

:root {
  --red: #C4112F;
  --red-dark: #9E0D25;
  --dark: #333;
  --body: #444;
  --g500: #767676;
  --g400: #999;
  --g300: #bbb;
  --g200: #ddd;
  --g150: #e5e5e5;
  --g100: #eee;
  --g50: #f5f5f5;
  --green: #28a745;
  --amber: #e67e22;
  --font: 'Open Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --r: 6px;
  --rl: 10px;
}

/* ====== PRODUCT GRID ====== */
/* Default: 4 columns (used inside sidebar layout where ~1030px available) */
#hits .ais-Hits-list {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  list-style: none;
  padding: 0;
  margin: 0;
}
/* Full-width pages (no sidebar): 5 columns at >=1024px */
.plp-full-width #hits .ais-Hits-list,
.plp-full-width .plp-product-grid {
  grid-template-columns: repeat(5, 1fr);
}

/* Reserve space before Algolia renders to prevent CLS */
#hits {
  min-height: 80vh;
}

#hits .ais-Hits-item {
  width: 100% !important;
  max-width: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
  box-shadow: none !important;
  min-width: 0;
}

/* ====== PRODUCT CARD ====== */
.product-card {
  background: #fff;
  border: 1px solid var(--g200);
  border-radius: var(--rl);
  overflow: hidden;
  text-decoration: none;
  color: var(--body);
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.2s, transform 0.2s;
  height: 100%;
}
.product-card:hover {
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  transform: translateY(-2px);
}

.product-card-img {
  aspect-ratio: 1;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  border-bottom: 1px solid var(--g150);
  position: relative;
  overflow: hidden;
}
.product-card-img img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.product-card-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(255,255,255,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 800;
  color: var(--red);
  letter-spacing: 1px;
}

.product-card-body {
  padding: 14px;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.product-card-body a {
  text-decoration: none;
  color: inherit;
}
.product-card-brand {
  font-size: 12px;
  color: var(--red);
  font-weight: 600;
  margin-bottom: 3px;
}
.product-card-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--dark);
  line-height: 1.35;
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.product-card-meta {
  font-size: 11px;
  color: var(--g400);
  margin-bottom: 10px;
}
.product-card-meta span + span { margin-left: 8px; }
.product-card-meta .item-number { font-weight: 600; color: var(--dark); }
.product-card-pricing {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 10px;
  margin-top: auto;
}
.product-card-price {
  font-size: 20px;
  font-weight: 800;
  color: var(--dark);
}
.product-card-msrp {
  font-size: 13px;
  color: var(--g300);
  text-decoration: line-through;
}
.product-card-msrp.hidden { display: none; }
.product-card-uom {
  font-size: 13px;
  font-weight: 400;
  color: var(--g400);
  margin-left: 2px;
}

.product-card-stock {
  font-size: 12px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 5px;
}
.stock-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
}
.stock-in { background: var(--green); }
.stock-out { background: var(--g300); }
.stock-low { background: var(--amber); }
.in-stock-text { color: var(--green); }
.out-stock-text { color: var(--g400); }
.low-stock-text { color: var(--amber); }

.product-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.product-card-qty {
  width: 52px;
  height: 36px;
  text-align: center;
  border: 1px solid var(--g200);
  border-radius: var(--r);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
}
.product-card-qty:focus { outline: none; border-color: var(--red); }

.btn-add-cart {
  flex: 1;
  padding: 9px;
  border: none;
  background: var(--red);
  color: #fff;
  font-family: var(--font);
  font-weight: 700;
  font-size: 13px;
  border-radius: var(--r);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
}
.btn-add-cart:hover { background: var(--red-dark); }

.product-card-status {
  width: 100%;
  font-size: 12px;
  min-height: 18px;
}

/* ====== FILTER SIDEBAR ====== */
.SearchFacets {
  position: sticky;
  top: 80px;
}

.FacetList {
  margin-bottom: 20px !important;
  min-height: 120px;
}
.FacetList > span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px !important;
  font-weight: 700 !important;
  color: var(--dark) !important;
  padding-bottom: 8px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--g200);
}
.FacetList > span::after {
  content: '\f078'; /* fa-chevron-down */
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  font-size: 10px;
  color: var(--g400);
}

.ais-RefinementList-checkbox {
  width: 16px;
  height: 16px;
  accent-color: var(--red);
}

.ais-RefinementList-item {
  padding: 0;
}
.ais-RefinementList-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 13px;
  color: var(--body);
  cursor: pointer;
}
.ais-RefinementList-labelText {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  min-width: 0;
}

.ais-RefinementList-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--g400);
  background: var(--g50);
  padding: 1px 6px;
  border-radius: 10px;
  border: none;
}

.ais-RefinementList-showMore {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--red) !important;
  font-weight: 600;
  cursor: pointer;
  background: none !important;
  border: none !important;
  padding: 4px 0 !important;
}
.ais-RefinementList-showMore::before {
  content: '\f067'; /* fa-plus */
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  font-size: 10px;
}
.ais-RefinementList-showMore--disabled {
  display: none;
}

/* ====== TOOLBAR (stats + sort) ====== */
.plp-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0 8px;
}
.plp-result-count {
  font-size: 13px;
  color: #666;
}
.plp-sort-select,
#cboSortedBy-mobile {
  padding: 6px 28px 6px 10px;
  border: 1px solid var(--g200);
  border-radius: var(--r);
  font-size: 13px;
  font-family: var(--font);
  background: #fff;
}

/* ====== PAGINATION ====== */
.ais-Pagination-list {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--g200);
  list-style: none;
  padding-left: 0;
}
.ais-Pagination-link {
  min-width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--g200);
  background: #fff;
  border-radius: var(--r);
  font-family: var(--font);
  font-size: 13px;
  color: var(--body);
  cursor: pointer;
  text-decoration: none;
  padding: 0 8px;
}
.ais-Pagination-link:hover {
  border-color: var(--red);
  color: var(--red);
}
.ais-Pagination-item--selected .ais-Pagination-link {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
  font-weight: 700;
}
.ais-Pagination-item--disabled .ais-Pagination-link {
  opacity: 0.3;
  cursor: default;
  pointer-events: none;
}

/* ====== SEARCH SUGGESTIONS ====== */
.search-suggest {
  font-size: 13px;
  color: var(--g500);
  margin-top: 6px;
}
.search-suggest a {
  color: var(--red);
  font-weight: 600;
  text-decoration: none;
}
.search-suggest a:hover {
  text-decoration: underline;
}

/* ====== SEARCH RESULTS INLINE STYLES (moved from AISearchResult.cshtml) ====== */
.ais-Stats-text {
  font-size: 15px;
}
.mark mark {
  padding: 0px !important;
  font-weight: normal !important;
}
.itemSkuLabel {
  color: #969696;
  font-size: 13px;
}
.itemSku {
  font-size: 13px;
  font-weight: 600;
}
.hit-name {
  font-weight: normal !important;
  line-height: normal !important;
}

/* ====== PLP LAYOUT GRID ====== */
.plp-page {
  padding: 0 20px;
  display: flex;
  flex-direction: column;
}
.plp-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 24px;
  align-items: start;
}
.plp-main {
  min-width: 0;
}

/* ====== RESPONSIVE VISIBILITY ====== */
.plp-show-mobile { display: none !important; }
.plp-show-desktop { display: flex !important; }

/* ====== TOOLBAR RIGHT GROUP (in-stock toggle + sort) ====== */
.plp-toolbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.plp-instock-toggle,
.plp-instock-toggle .plp-instock-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--body);
  cursor: pointer;
  white-space: nowrap;
  margin: 0;
  line-height: 1;
}
.plp-instock-toggle input[type="checkbox"],
.plp-instock-label input[type="checkbox"] {
  accent-color: var(--red);
  width: 14px;
  height: 14px;
  cursor: pointer;
  margin: 0;
}

/* ====== FACET "SHOW MORE" LINK ====== */
.facet-show-more {
  display: inline-block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--red);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.facet-show-more:hover {
  text-decoration: underline;
}

/* ====== DESKTOP FILTER SIDEBAR (card-based per PBI spec) ====== */
.filter-section {
  border: 1px solid var(--g150);
  border-radius: var(--rl);
  overflow: hidden;
  margin-bottom: 12px;
  background: #fff;
}
.filter-header {
  background: var(--g50);
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--g500);
  border-bottom: 1px solid var(--g150);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}
.filter-header .clear-link {
  font-size: 10px;
  color: var(--red);
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
  text-decoration: none;
}
.filter-header .clear-link:hover { text-decoration: underline; }
.filter-header::after {
  content: '\f078'; /* fa-chevron-down */
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  font-size: 9px;
  color: var(--g400);
  transition: transform 0.2s;
}
.filter-section.is-expanded .filter-header::after {
  transform: rotate(180deg);
}
.filter-body {
  padding: 12px 16px;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
  padding: 0 16px;
}
.filter-section.is-expanded .filter-body {
  max-height: 600px;
  padding: 12px 16px;
}
.filter-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--body);
  padding: 4px 0;
  cursor: pointer;
  line-height: 1.4;
}
.filter-item input[type="checkbox"] {
  accent-color: var(--red);
  width: 14px;
  height: 14px;
  cursor: pointer;
  flex-shrink: 0;
}
.filter-item span:not(.count) {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  min-width: 0;
}
.filter-item .count {
  margin-left: auto;
  font-size: 11px;
  color: var(--g400);
  font-weight: 400;
}
.filter-item.checked,
.filter-item input[type="checkbox"]:checked + span {
  color: var(--red);
  font-weight: 600;
}

/* Map Algolia InstantSearch classes to filter card styles */
.filter-section .ais-RefinementList-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--body);
  padding: 0;
  cursor: pointer;
}
.filter-section .ais-RefinementList-item--selected .ais-RefinementList-labelText {
  color: var(--red);
  font-weight: 600;
}

/* ====== MOBILE FILTER PANEL ====== */
/* On desktop: .plp-filter-panel is static sidebar (positioned by grid).
   On mobile: it becomes a fixed full-screen overlay that slides up. */
.plp-filter-panel {
  position: sticky;
  top: 80px;
  padding-top: 4px;
}
.plp-filter-panel__header {
  display: none; /* hidden on desktop */
}
.plp-filter-panel__footer {
  display: none; /* hidden on desktop */
}
.plp-filter-overlay {
  display: none; /* hidden on desktop */
}

/* ====== MOBILE TOOLBAR (Sort + Filter buttons) ====== */
.plp-mobile-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.plp-mobile-toolbar select {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--g200);
  border-radius: var(--r);
  font-family: var(--font);
  font-size: 13px;
  background: #fff;
}
.plp-filter-btn {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--g200);
  border-radius: var(--r);
  background: #fff;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--dark);
}
.plp-filter-btn:hover { border-color: var(--red); color: var(--red); }
.plp-filter-btn.has-filters {
  border-color: var(--red);
  color: var(--red);
}
.plp-filter-btn .filter-count-badge {
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ====== ACTIVE FILTER CHIPS ====== */
.plp-active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.plp-active-filters:empty { display: none; }

.plp-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--red);
  background: #fff;
  border: 1px solid var(--red);
  border-radius: 20px;
  cursor: default;
  white-space: nowrap;
}
.plp-chip button {
  background: none;
  border: none;
  color: var(--red);
  font-size: 14px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  display: flex;
  align-items: center;
}
.plp-chip button:hover { color: var(--red-dark); }

.plp-clear-all {
  font-size: 12px;
  font-weight: 600;
  color: var(--g500);
  text-decoration: underline;
  cursor: pointer;
  border: none;
  background: none;
  padding: 4px 6px;
}
.plp-clear-all:hover { color: var(--red); }

/* ====== PRODUCT GRID (category server-rendered) ====== */
.plp-product-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  min-height: 80vh;
}

/* ====== CATEGORY PAGINATION (responsive) ====== */
.plp-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--g200);
  flex-wrap: wrap;
}
.plp-pagination a,
.plp-pagination .page-btn {
  min-width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--g200);
  background: #fff;
  border-radius: var(--r);
  font-family: var(--font);
  font-size: 13px;
  color: var(--body);
  cursor: pointer;
  text-decoration: none;
  padding: 0 8px;
}
.plp-pagination a:hover,
.plp-pagination .page-btn:hover {
  border-color: var(--red);
  color: var(--red);
}
.plp-pagination .page-btn.active {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
  font-weight: 700;
}
.plp-pagination .page-btn.disabled {
  opacity: 0.3;
  cursor: default;
  pointer-events: none;
}
.plp-pagination-footer {
  text-align: center;
  font-size: 13px;
  color: var(--g500);
  margin-top: 12px;
}

/* ====== RESPONSIVE ====== */
@media (max-width: 1024px) {
  /* Tablet: 3 columns (both sidebar and full-width contexts) */
  #hits .ais-Hits-list,
  .plp-product-grid,
  .plp-full-width #hits .ais-Hits-list,
  .plp-full-width .plp-product-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .SearchFacets {
    position: static;
  }
}
@media (max-width: 768px) {
  /* Responsive visibility */
  .plp-show-desktop { display: none !important; }
  .plp-show-mobile { display: flex !important; }

  /* Layout: single column, no sidebar */
  .plp-layout {
    grid-template-columns: 1fr;
  }
  .plp-page {
    padding: 0 12px;
  }

  /* Filter panel: fixed full-screen overlay */
  .plp-filter-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1050;
    background: #fff;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
  }
  .plp-filter-panel.is-open {
    transform: translateY(0);
  }
  .plp-filter-panel__header {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--g150);
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 1;
  }
  .plp-filter-panel__title {
    font-size: 16px;
    font-weight: 700;
    color: var(--dark);
  }
  .plp-filter-panel__close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--g400);
    cursor: pointer;
    padding: 0;
    line-height: 1;
  }
  .plp-filter-panel__close:hover { color: var(--dark); }
  .plp-filter-panel__body {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
  }
  .plp-filter-panel__footer {
    display: flex !important;
    padding: 12px 16px;
    border-top: 1px solid var(--g150);
    position: sticky;
    bottom: 0;
    background: #fff;
    z-index: 1;
  }
  .btn-show-results {
    width: 100%;
    padding: 12px;
    background: var(--red);
    color: #fff;
    border: none;
    border-radius: var(--r);
    font-family: var(--font);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
  }
  .btn-show-results:hover { background: var(--red-dark); }

  /* Filter sections: all expanded on mobile by default for accordion UX */
  .filter-section .filter-body {
    max-height: 0;
    padding: 0 16px;
  }
  .filter-section.is-expanded .filter-body {
    max-height: 600px;
    padding: 12px 16px;
  }

  /* Overlay backdrop */
  .plp-filter-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1049;
  }
  .plp-filter-overlay.is-visible {
    display: block;
  }

  /* Product grid: 2 columns on mobile */
  #hits .ais-Hits-list,
  .plp-product-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
  .product-card-price {
    font-size: 16px;
  }
  .product-card-img {
    padding: 12px;
  }
  .product-card-body {
    padding: 10px;
  }
  .product-card-meta {
    font-size: 10px;
  }
  .product-card-actions {
    flex-wrap: wrap;
  }
  .product-card-qty {
    width: 44px;
    height: 32px;
    font-size: 12px;
  }
  .btn-add-cart {
    font-size: 12px;
    padding: 7px;
    min-height: 32px;
  }

  /* Pagination: simplified for mobile */
  .plp-pagination {
    gap: 4px;
    margin-top: 20px;
    padding-top: 16px;
  }
  .plp-pagination a,
  .plp-pagination .page-btn {
    min-width: 32px;
    height: 32px;
    font-size: 12px;
  }
}

/* ====== TRENDING "POPULAR" BADGE ====== */
.product-card-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 3px 8px;
  border-radius: 4px;
  line-height: 1;
  z-index: 1;
  pointer-events: none;
}
.product-card-badge--popular {
  background: #FDF2F4;
  color: #C4112F;
  border: 1px solid rgba(196, 17, 47, 0.15);
}
