/**
 * ProductSearch Module Phase 1B - Scoped CSS
 * Namespace: .ps-*
 */

:root {
  --ps-primary: #2563eb;
  --ps-primary-hover: #1d4ed8;
  --ps-primary-light: #eff6ff;
  --ps-orange: #f97316;
  --ps-orange-hover: #ea580c;
  --ps-orange-light: #fff7ed;
  --ps-text-main: #1e293b;
  --ps-text-muted: #64748b;
  --ps-text-light: #94a3b8;
  --ps-border: #e2e8f0;
  --ps-bg-card: #ffffff;
  --ps-bg-page: #f8fafc;
  --ps-radius-sm: 6px;
  --ps-radius-md: 10px;
  --ps-radius-lg: 16px;
  --ps-shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --ps-shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -2px rgba(0,0,0,0.04);
  --ps-shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.05);
  --ps-transition: all 0.2s ease-in-out;
}

/* Container */
.ps-container {
  font-family: 'Inter', 'Be Vietnam Pro', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ps-text-main);
  font-size: 14px;
  line-height: 1.5;
  width: 100%;
  box-sizing: border-box;
  margin: 10px 0 28px 0;
  -webkit-font-smoothing: auto;
}

.ps-container * {
  box-sizing: border-box;
}

/* Header & Search Bar */
.ps-search-wrapper {
  position: relative;
  width: 100%;
  margin-bottom: 20px;
}

.ps-search-box {
  display: flex;
  align-items: center;
  position: relative;
  width: 100%;
  background: #ffffff;
  border: 2px solid var(--ps-primary);
  border-radius: var(--ps-radius-md);
  box-shadow: var(--ps-shadow-sm);
  transition: var(--ps-transition);
}

.ps-search-box:focus-within {
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.15);
}

.ps-search-input {
  flex: 1;
  border: none;
  outline: none;
  padding: 12px 18px;
  font-size: 15px;
  color: var(--ps-text-main);
  background: transparent;
  width: 100%;
}

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

.ps-clear-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 10px;
  color: var(--ps-text-light);
  font-size: 18px;
  display: none;
  align-items: center;
  justify-content: center;
}

.ps-clear-btn:hover {
  color: var(--ps-text-main);
}

.ps-search-submit {
  background: var(--ps-primary);
  color: #ffffff;
  border: none;
  padding: 10px 24px;
  margin: 4px;
  border-radius: var(--ps-radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: var(--ps-transition);
}

.ps-search-submit:hover {
  background: var(--ps-primary-hover);
}

/* Autocomplete Suggestion Dropdown */
.ps-suggest-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: #ffffff;
  border: 1px solid var(--ps-border);
  border-radius: var(--ps-radius-md);
  box-shadow: var(--ps-shadow-lg);
  z-index: 1000;
  display: none;
  max-height: 420px;
  overflow-y: auto;
}

.ps-suggest-dropdown.active {
  display: block;
}

.ps-suggest-header {
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--ps-text-muted);
  border-bottom: 1px solid var(--ps-border);
  background: #f8fafc;
}

.ps-suggest-item {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  transition: var(--ps-transition);
  text-decoration: none;
  color: inherit;
}

.ps-suggest-item:hover, .ps-suggest-item.highlighted {
  background: var(--ps-primary-light);
}

.ps-suggest-thumb {
  width: 44px;
  height: 44px;
  border-radius: var(--ps-radius-sm);
  object-fit: cover;
  background: #f1f5f9;
  margin-right: 14px;
  flex-shrink: 0;
}

.ps-suggest-info {
  flex: 1;
  min-width: 0;
}

.ps-suggest-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--ps-text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.ps-suggest-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}

.ps-suggest-cat {
  background: #e2e8f0;
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--ps-text-muted);
  font-size: 11px;
}

.ps-suggest-price {
  color: #dc2626;
  font-weight: 700;
}

.ps-suggest-footer {
  padding: 10px 16px;
  text-align: center;
  background: #f8fafc;
  color: var(--ps-primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-top: 1px solid var(--ps-border);
}

.ps-suggest-footer:hover {
  text-decoration: underline;
}

/* Control Panel: Filters & Sorting */
.ps-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
  background: #ffffff;
  border: 1px solid var(--ps-border);
  border-radius: var(--ps-radius-md);
  padding: 14px 16px;
  box-shadow: var(--ps-shadow-sm);
}

.ps-filters-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.ps-filter-label {
  font-size: 13px;
  font-weight: 600;
  color: #334155;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ps-filter-select {
  padding: 6px 12px;
  border: 1px solid #cbd5e1;
  border-radius: var(--ps-radius-sm);
  background: #ffffff;
  font-size: 13px;
  font-weight: 500;
  color: #0f172a;
  outline: none;
  cursor: pointer;
  transition: var(--ps-transition);
}

.ps-filter-select:focus {
  border-color: var(--ps-primary);
}

/* Quick Price Chips */
.ps-price-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ps-chip {
  padding: 5px 12px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  color: #334155;
  cursor: pointer;
  transition: var(--ps-transition);
  white-space: nowrap;
}

.ps-chip:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.ps-chip.active {
  background: var(--ps-primary-light);
  border-color: var(--ps-primary);
  color: var(--ps-primary);
  font-weight: 600;
}

/* Sorting Bar */
.ps-sort-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid #f1f5f9;
  padding-top: 12px;
  gap: 8px;
}

.ps-sort-left {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.ps-sort-left .ps-filter-label {
  font-size: 13px;
  margin-right: 2px;
}

.ps-sort-btn {
  padding: 5px 10px;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: var(--ps-radius-sm);
  font-size: 12.5px;
  font-weight: 500;
  color: #334155;
  cursor: pointer;
  transition: var(--ps-transition);
  line-height: 1.4;
  white-space: nowrap;
}

.ps-sort-btn:hover {
  background: #f8fafc;
  border-color: #94a3b8;
  color: #0f172a;
}

.ps-sort-btn.active {
  background: var(--ps-primary);
  border-color: var(--ps-primary);
  color: #ffffff;
  font-weight: 600;
}

.ps-results-count {
  font-size: 13px;
  color: #475569;
  white-space: nowrap;
}

.ps-results-count strong {
  color: #0f172a;
  font-weight: 700;
}

/* Active Filter Badges */
.ps-active-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--ps-border);
}

.ps-badge-filter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #e0e7ff;
  color: #3730a3;
  padding: 4px 10px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 500;
}

.ps-badge-remove {
  cursor: pointer;
  font-weight: bold;
  border-radius: 50%;
  width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.ps-badge-remove:hover {
  color: #dc2626;
}

.ps-clear-all-btn {
  background: none;
  border: none;
  color: #dc2626;
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

/* Product Cards Grid */
.ps-product-grid {
  display: grid !important;
  grid-template-columns: repeat(5, 1fr) !important;
  gap: 16px !important;
  margin-bottom: 30px !important;
  width: 100% !important;
  box-sizing: border-box !important;
}

@media (max-width: 1200px) {
  .ps-product-grid {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 14px !important;
  }
}

@media (max-width: 900px) {
  .ps-product-grid {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 12px !important;
  }
}

@media (max-width: 600px) {
  .ps-product-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }
}

.ps-product-card {
  position: relative !important;
  background: #ffffff !important;
  border: 1px solid #e2e8f0 !important;
  border-radius: 12px !important;
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
  width: 100% !important;
  text-decoration: none !important;
  color: inherit !important;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1) !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04) !important;
  box-sizing: border-box !important;
  height: 100% !important;
}

.ps-product-card:hover {
  transform: translateY(-4px) !important;
  border-color: #60a5fa !important;
  box-shadow: 0 12px 28px -4px rgba(37, 99, 235, 0.14), 0 4px 8px -2px rgba(0, 0, 0, 0.04) !important;
  text-decoration: none !important;
}

.ps-img-container {
  position: relative !important;
  width: 100% !important;
  padding-top: 100% !important;
  background: #ffffff !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
  border-bottom: 1px solid #f1f5f9 !important;
}

.ps-product-img {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
  object-fit: contain !important;
  object-position: center !important;
  padding: 10px !important;
  box-sizing: border-box !important;
  background: #ffffff !important;
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1) !important;
  display: block !important;
}

.ps-product-card:hover .ps-product-img {
  transform: scale(1.06) !important;
}

.ps-badge-discount {
  position: absolute !important;
  top: 8px !important;
  left: 8px !important;
  background: linear-gradient(135deg, #ef4444, #dc2626) !important;
  color: #ffffff !important;
  font-size: 11px !important;
  font-weight: 800 !important;
  padding: 3px 7px !important;
  border-radius: 6px !important;
  box-shadow: 0 2px 6px rgba(220, 38, 38, 0.35) !important;
  letter-spacing: 0.02em !important;
  z-index: 2 !important;
  line-height: 1 !important;
}

.ps-badge-mall {
  position: absolute !important;
  top: 8px !important;
  left: 8px !important;
  background: #dc2626 !important;
  color: #ffffff !important;
  font-size: 11px !important;
  font-weight: 600 !important;
  padding: 3px 7px !important;
  border-radius: 5px !important;
  box-shadow: 0 2px 5px rgba(220, 38, 38, 0.25) !important;
  z-index: 2 !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 3px !important;
  line-height: 1.1 !important;
}

.ps-badge-freeship {
  position: absolute !important;
  bottom: 8px !important;
  left: 8px !important;
  background: #ecfdf5 !important;
  color: #059669 !important;
  border: 1px solid #a7f3d0 !important;
  font-size: 11px !important;
  font-weight: 600 !important;
  padding: 3px 7px !important;
  border-radius: 5px !important;
  z-index: 2 !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 3px !important;
  line-height: 1.1 !important;
}

.ps-card-body {
  padding: 12px 14px 14px 14px !important;
  display: flex !important;
  flex-direction: column !important;
  flex: 1 1 auto !important;
  justify-content: space-between !important;
  background: #ffffff !important;
  box-sizing: border-box !important;
}

.ps-card-meta {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 6px !important;
  margin-bottom: 6px !important;
}

.ps-card-category {
  font-size: 12px !important;
  font-weight: 500 !important;
  color: #334155 !important;
  background: #f1f5f9 !important;
  padding: 2px 7px !important;
  border-radius: 4px !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  max-width: 115px !important;
  border: 1px solid #e2e8f0 !important;
}

.ps-card-seller {
  font-size: 12px !important;
  font-weight: 500 !important;
  color: #475569 !important;
  display: flex !important;
  align-items: center !important;
  gap: 3px !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  max-width: 105px !important;
}

.ps-card-title {
  font-size: 14px !important;
  font-weight: 500 !important;
  color: #0f172a !important;
  line-height: 1.43 !important;
  margin: 0 0 6px 0 !important;
  display: -webkit-box !important;
  -webkit-line-clamp: 2 !important;
  -webkit-box-orient: vertical !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  height: 40px !important;
  transition: color 0.15s ease !important;
  text-align: left !important;
}

.ps-product-card:hover .ps-card-title {
  color: #2563eb !important;
}

.ps-card-social {
  display: flex !important;
  align-items: center !important;
  gap: 6px !important;
  margin-bottom: 8px !important;
  font-size: 12px !important;
  color: #475569 !important;
}

.ps-stars {
  color: #f59e0b !important;
  font-weight: 700 !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 2px !important;
}

.ps-social-dot {
  color: #cbd5e1 !important;
}

.ps-sold {
  color: #475569 !important;
  font-weight: 500 !important;
}

.ps-card-pricing {
  margin-top: auto !important;
  margin-bottom: 10px !important;
  padding-top: 0 !important;
  display: flex !important;
  align-items: baseline !important;
}

.ps-price-row {
  display: flex !important;
  align-items: baseline !important;
  flex-wrap: wrap !important;
  gap: 6px !important;
}

.ps-price-current {
  font-size: 16.5px !important;
  font-weight: 700 !important;
  color: #dc2626 !important;
  letter-spacing: -0.01em !important;
  font-variant-numeric: tabular-nums !important;
  line-height: 1.1 !important;
  display: inline-flex !important;
  align-items: baseline !important;
}

.ps-price-current .ps-curr {
  font-size: 13px !important;
  font-weight: 700 !important;
  margin-left: 2px !important;
}

.ps-price-old {
  font-size: 12.5px !important;
  color: #94a3b8 !important;
  text-decoration: line-through !important;
  font-weight: 500 !important;
}

.ps-price-contact {
  font-size: 15px !important;
  font-weight: 700 !important;
  color: #059669 !important;
}

.ps-card-btn-wrap {
  margin-top: auto !important;
  padding-top: 4px !important;
}

.ps-card-btn {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 6px !important;
  width: 100% !important;
  height: 36px !important;
  padding: 0 12px !important;
  background: #eff6ff !important;
  color: #2563eb !important;
  border: 1.5px solid #bfdbfe !important;
  border-radius: 8px !important;
  font-size: 13px !important;
  font-weight: 600 !important;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1) !important;
  box-sizing: border-box !important;
  cursor: pointer !important;
  margin-top: 0 !important;
}

.ps-card-btn .arrow-svg {
  transition: transform 0.2s ease !important;
}

.ps-product-card:hover .ps-card-btn {
  background: linear-gradient(135deg, #2563eb, #1d4ed8) !important;
  color: #ffffff !important;
  border-color: #2563eb !important;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.28) !important;
}

.ps-product-card:hover .ps-card-btn .arrow-svg {
  transform: translateX(3px) !important;
}

/* Pagination */
.ps-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 25px;
}

.ps-page-btn {
  padding: 8px 14px;
  border: 1px solid var(--ps-border);
  background: #ffffff;
  border-radius: var(--ps-radius-sm);
  font-size: 13px;
  color: var(--ps-text-main);
  cursor: pointer;
  transition: var(--ps-transition);
}

.ps-page-btn:hover:not(:disabled) {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.ps-page-btn.active {
  background: var(--ps-primary);
  color: #ffffff;
  border-color: var(--ps-primary);
  font-weight: 600;
}

.ps-page-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Loading Skeleton */
.ps-skeleton {
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 200% 100%;
  animation: ps-shimmer 1.5s infinite;
  border-radius: var(--ps-radius-sm);
}

@keyframes ps-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.ps-card-skeleton {
  height: 320px;
  border: 1px solid var(--ps-border);
  border-radius: var(--ps-radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* States: Empty & Error */
.ps-state-container {
  padding: 60px 20px;
  text-align: center;
  background: #ffffff;
  border: 1px dashed var(--ps-border);
  border-radius: var(--ps-radius-lg);
  margin: 20px 0;
}

.ps-state-icon {
  font-size: 48px;
  margin-bottom: 16px;
  color: var(--ps-text-light);
}

.ps-state-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--ps-text-main);
  margin-bottom: 8px;
}

.ps-state-desc {
  font-size: 14px;
  color: var(--ps-text-muted);
  max-width: 480px;
  margin: 0 auto 20px auto;
  line-height: 1.5;
}

.ps-retry-btn {
  background: var(--ps-primary);
  color: #ffffff;
  border: none;
  padding: 10px 24px;
  border-radius: var(--ps-radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--ps-transition);
}

.ps-retry-btn:hover {
  background: var(--ps-primary-hover);
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
  .ps-container {
    margin: 8px 0 20px 0;
  }
  .ps-product-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .ps-controls {
    padding: 10px 12px;
    gap: 10px;
  }
  .ps-search-submit span {
    display: none;
  }
  .ps-search-submit {
    padding: 10px 14px;
  }
  .ps-filters-row {
    gap: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .ps-filters-row::-webkit-scrollbar {
    display: none;
  }
  .ps-filter-label {
    font-size: 12px;
    flex-shrink: 0;
  }
  .ps-filter-select {
    padding: 6px 10px;
    font-size: 12px;
    flex-shrink: 0;
  }
  .ps-price-chips {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 6px;
    padding-bottom: 2px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }
  .ps-price-chips::-webkit-scrollbar {
    display: none;
  }
  .ps-chip {
    padding: 5px 11px;
    font-size: 12.5px;
    flex-shrink: 0;
    white-space: nowrap;
  }
  .ps-sort-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding-top: 10px;
  }
  .ps-sort-left {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 6px;
    max-width: 100%;
    padding-bottom: 2px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .ps-sort-left::-webkit-scrollbar {
    display: none;
  }
  .ps-sort-btn {
    padding: 5px 10px;
    font-size: 12px;
    flex-shrink: 0;
    white-space: nowrap;
  }
  .ps-sort-total {
    font-size: 12px;
    color: var(--ps-text-muted);
  }
  .ps-product-card {
    border-radius: 8px;
  }
  .ps-product-info,
  .ps-card-body {
    padding: 10px 10px 12px 10px !important;
  }
  .ps-product-title,
  .ps-card-title {
    font-size: 13px !important;
    line-height: 1.38 !important;
    height: 36px !important;
  }
  .ps-price-current {
    font-size: 15px !important;
  }
}

/* Hide duplicate in-page search bar when header search bar is present */
#ps-root.has-header-search .ps-search-wrapper,
body:has(#shopeeHeaderSearchBox) #ps-root .ps-search-wrapper {
  display: none !important;
}

/* Ẩn hoàn toàn thanh sắp xếp cũ và phân trang cũ thừa ở cuối danh sách sản phẩm */
.view-productgeneral .shopee-sort-bar,
.shopee-sort-bar,
.view-productgeneral .paging,
.view-productgeneral > .paging,
.view-productgeneral .input-form ~ .paging,
.view-productgeneral .col.pagef,
.view-productgeneral .f-paging,
#ps-root ~ .shopee-sort-bar,
#ps-root ~ * .shopee-sort-bar,
#ps-root ~ .paging,
#ps-root ~ * .paging,
.view-productgeneral:has(#ps-root) .shopee-sort-bar,
.view-productgeneral:has(#ps-root) .paging,
.view-productgeneral:has(.ps-container) .shopee-sort-bar,
.view-productgeneral:has(.ps-container) .paging {
  display: none !important;
  visibility: hidden !important;
  height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
  pointer-events: none !important;
}

