/* ==================== ROOT COLORS & BASE SETUP ==================== */
:root {
  --teal-primary: #008f82;
  --teal-dark: #00665c;
  --teal-light: #e6f4f3;
  --text-dark: #212121;
  --text-muted: #878787;
  --border-light: #f0f0f0;
  --bg-gray: #f1f3f6;
  --star-green: #388e3c;
  --discount-green: #388e3c;
  --white: #ffffff;
}

/* Strictly enforce box-sizing and prevent body overflow */
*, *::before, *::after {
  box-sizing: border-box !important;
}

html, body {
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  overflow-x: hidden !important;
  -webkit-text-size-adjust: 100%;
  background-color: var(--bg-gray);
  font-family: -apple-system, BlinkMacSystemFont, "Roboto", "Segoe UI", sans-serif;
  color: var(--text-dark);
  margin: 0;
  padding: 0;
}

body {
  min-width: 0 !important;
}

/* Global Container Width Safeguard */
.listing-wrapper, 
.listing-main-layout, 
.list-products-section, 
.products-container-wrapper, 
.products-grid {
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
}

/* ==================== CONTAINER & LAYOUT ==================== */
.listing-wrapper {
  width: 100%;
  max-width: 1380px;
  min-width: 0;
  margin: 0 auto;
  padding: 12px 16px;
}

/* Header & Breadcrumb Section */
.list-header-section {
  background: var(--white);
  padding: 12px 16px;
  border-radius: 2px;
  margin-bottom: 10px;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.08);
}

.cat-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.cat-breadcrumb a {
  color: var(--text-muted);
  text-decoration: none;
}

.cat-breadcrumb a:hover {
  color: var(--teal-primary);
}

.cat-breadcrumb i {
  font-size: 10px;
}

.list-title-box {
  display: flex;
  align-items: center;
  gap: 10px;
}

.list-page-title {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  color: var(--text-dark);
}

.product-total-badge {
  font-size: 12px;
  color: var(--text-muted);
}

.list-page-subtitle {
  font-size: 12px;
  color: #666;
  margin: 4px 0 0 0;
}

/* Main Two-Column Layout (Sidebar + Products Grid) */
.listing-main-layout {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  min-width: 0;
}

/* ==================== SIDEBAR FILTERS ==================== */
.list-sidebar {
  width: 270px;
  flex-shrink: 0;
  background: var(--white);
  border-radius: 2px;
  padding: 16px;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.08);
}

.sidebar-header-mobile {
  display: none;
}

.filter-group {
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 14px;
  margin-bottom: 14px;
}

.filter-group:last-of-type {
  border-bottom: none;
}

.filter-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-dark);
  margin: 0 0 10px 0;
  letter-spacing: 0.3px;
}

.filter-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.filter-options label {
  font-size: 13px;
  color: #212121;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-options input[type="checkbox"],
.filter-options input[type="radio"] {
  accent-color: var(--teal-primary);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.apply-filter-btn {
  width: 100%;
  background: var(--teal-primary);
  color: var(--white);
  border: none;
  padding: 10px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 2px;
  cursor: pointer;
  text-transform: uppercase;
  transition: background 0.2s ease;
}

.apply-filter-btn:hover {
  background: var(--teal-dark);
}

/* ==================== MAIN PRODUCTS AREA ==================== */
.list-products-section {
  flex: 1 1 auto;
  min-width: 0;
  background: var(--white);
  border-radius: 2px;
  padding: 16px;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.08);
}

/* Desktop Top Bar */
.desktop-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 12px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--text-dark);
}

.desktop-sort-box {
  display: flex;
  align-items: center;
  gap: 8px;
}

.desktop-sort-box select {
  border: 1px solid #d7d7d7;
  padding: 6px 10px;
  font-size: 13px;
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  background: var(--white);
}

.mobile-filter-bar {
  display: none;
}

/* Loader Overlay */
.product-loader-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.75);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
}

/* ==================== PRODUCTS GRID (DESKTOP: 4 PER ROW) ==================== */
.products-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  min-width: 0;
}

.product-card {
  position: relative;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  background: var(--white);
  border: 1px solid var(--border-light);
  border-radius: 4px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.25s ease, border-color 0.25s ease;
  overflow: hidden;
}

.product-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  border-color: #e0e0e0;
}

.discount-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  background: var(--discount-green);
  color: var(--white);
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 2px;
  z-index: 2;
}

/* Product Image Box */
.product-img-box {
  width: 100%;
  height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-bottom: 10px;
}

.product-img-box img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transition: transform 0.3s ease, opacity 0.15s ease;
}

.product-card:hover .product-img-box img {
  transform: scale(1.04);
}

.product-cat {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 500;
  margin-bottom: 4px;
}

.product-title {
  min-width: 0;
  max-width: 100%;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dark);
  line-height: 1.4;
  height: 36px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow-wrap: anywhere;
  word-break: break-word;
  margin: 0 0 8px 0;
}

/* Rating Strip */
.rating-strip {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
  margin-bottom: 8px;
}

.star-badge {
  background: var(--star-green);
  color: var(--white);
  font-size: 11px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.rating-count {
  font-size: 11px;
  color: var(--text-muted);
}

/* Variant Chips Group */
.weight-chips-group {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  min-width: 0;
  max-width: 100%;
  margin-bottom: 10px;
}

.chip-btn {
  background: var(--bg-gray);
  border: 1px solid var(--border-light);
  color: var(--text-dark);
  font-size: 10px;
  font-weight: 500;
  padding: 3px 6px;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.chip-btn.active, 
.chip-btn:hover {
  background: var(--teal-light);
  border-color: var(--teal-primary);
  color: var(--teal-primary);
  font-weight: 600;
}

/* Price Block */
.price-block {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
  flex-wrap: wrap;
  margin-top: auto;
  margin-bottom: 10px;
}

.current-price {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-dark);
}

.mrp-price {
  font-size: 12px;
  color: var(--text-muted);
  text-decoration: line-through;
}

/* Card Actions */
.card-actions {
  width: 100%;
  min-width: 0;
}

.add-cart-btn {
  width: 100%;
  background: var(--teal-primary);
  color: var(--white);
  border: none;
  padding: 8px 0;
  font-size: 12px;
  font-weight: 600;
  border-radius: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.2s ease;
  white-space: nowrap;
}

.add-cart-btn:hover {
  background: var(--teal-dark);
}

/* ==================== PAGINATION ==================== */
.pagination-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
}

.page-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid #d7d7d7;
  color: var(--text-dark);
  text-decoration: none;
  font-size: 12px;
  font-weight: 500;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.page-link.active,
.page-link:hover:not(.disabled) {
  background: var(--teal-primary);
  color: var(--white);
  border-color: var(--teal-primary);
}

.page-link.disabled {
  color: #ccc;
  border-color: #eee;
  cursor: not-allowed;
}

/* ==================== RESPONSIVE MEDIA QUERIES ==================== */

/* Desktop & Large Tablet (Max 1100px) */
@media (max-width: 1100px) {
  .products-grid {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 10px;
  }
}

/* Medium Tablet & Small Screens (Max 850px) */
@media (max-width: 850px) {
  /* Hide site top-bar if it overflows */
  .top-header-strip, 
  header .top-bar {
    display: none !important;
  }

  header, .main-header, .navbar {
    width: 100% !important;
    max-width: 100% !important;
    padding: 8px 10px !important;
  }

  .sub-header-categories {
    display: flex !important;
    white-space: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    padding: 6px 0 !important;
  }

  .sub-header-categories::-webkit-scrollbar {
    display: none;
  }

  .listing-wrapper {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    padding: 8px !important;
  }

  .listing-main-layout {
    flex-direction: column !important;
    gap: 0 !important;
  }

  .list-products-section {
    width: 100% !important;
    min-width: 0 !important;
    padding: 10px !important;
  }

  /* Drawer Sidebar Fix */
  .list-sidebar {
    position: fixed !important;
    top: 0;
    left: -100%;
    height: 100vh;
    height: 100dvh;
    width: 280px;
    max-width: 85vw;
    z-index: 1050;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    box-shadow: 4px 0 16px rgba(0,0,0,0.15);
  }

  .list-sidebar.active {
    left: 0 !important;
  }

  .sidebar-header-mobile {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-light);
    padding-bottom: 10px;
    margin-bottom: 14px;
  }

  .sidebar-header-mobile h3 {
    font-size: 15px;
    margin: 0;
  }

  .close-sidebar-btn {
    background: transparent;
    border: none;
    font-size: 20px;
    padding: 4px;
    cursor: pointer;
  }

  .mobile-filter-bar {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    background: var(--white);
    padding: 8px 10px;
    margin-bottom: 10px;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    width: 100%;
  }

  .mobile-filter-btn {
    flex: 1;
    background: var(--white);
    border: 1px solid #d7d7d7;
    padding: 8px;
    font-size: 12.5px;
    font-weight: 500;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
    white-space: nowrap;
  }

  .mobile-sort-select {
    flex: 1;
  }

  .mobile-sort-select select {
    width: 100%;
    border: 1px solid #d7d7d7;
    padding: 8px;
    font-size: 12px;
    border-radius: 4px;
    background: var(--white);
  }

  .desktop-top-bar {
    display: none !important;
  }

  .products-grid {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1040;
    backdrop-filter: blur(2px);
  }

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

/* Mobile Devices (Pixel 9, Samsung, iPhone, Oppo, Vivo - Max 480px) */
@media (max-width: 480px) {
  .list-header-section {
    padding: 10px !important;
  }

  .list-page-title {
    font-size: 16px !important;
  }

  /* Strict bounds prevention against right-side cutoff */
  .products-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
    width: 100% !important;
  }

  .product-card {
    padding: 8px !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    overflow: hidden !important;
  }

  .product-img-box {
    height: 120px !important;
    width: 100% !important;
    min-width: 0 !important;
    margin-bottom: 6px;
  }

  .product-img-box img {
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    object-fit: contain !important;
  }

  .product-title {
    min-width: 0 !important;
    max-width: 100% !important;
    font-size: 11px !important;
    line-height: 1.3 !important;
    height: 29px !important;
    margin: 4px 0 !important;
    overflow: hidden !important;
    overflow-wrap: anywhere !important;
    word-break: break-word !important;
  }

  .weight-chips-group {
    display: flex !important;
    gap: 3px !important;
    min-width: 0 !important;
    max-width: 100% !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    padding-bottom: 2px !important;
    -webkit-overflow-scrolling: touch;
  }

  .weight-chips-group::-webkit-scrollbar {
    display: none;
  }

  .chip-btn {
    font-size: 9px !important;
    padding: 2px 4px !important;
    flex-shrink: 0 !important;
  }

  .price-block {
    gap: 4px !important;
    min-width: 0 !important;
    max-width: 100% !important;
    flex-wrap: wrap !important;
    margin-bottom: 6px !important;
  }

  .current-price {
    font-size: 13.5px !important;
  }

  .mrp-price {
    font-size: 10.5px !important;
  }

  .add-cart-btn {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    padding: 6px 4px !important;
    font-size: 11px !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .pagination-wrapper {
    gap: 4px !important;
    margin-top: 16px !important;
  }

  .page-link {
    width: 28px !important;
    height: 28px !important;
    font-size: 11px !important;
  }
}

/* Extra Small Mobile Devices (Max 360px) */
@media (max-width: 360px) {
  .listing-wrapper {
    padding: 6px !important;
  }

  .list-products-section {
    padding: 8px !important;
  }

  .products-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 6px !important;
  }

  .product-card {
    padding: 6px !important;
  }

  .product-img-box {
    height: 105px !important;
  }

  .product-cat {
    font-size: 9px !important;
  }

  .product-title {
    font-size: 10.5px !important;
    height: 28px !important;
  }

  .star-badge {
    font-size: 10px !important;
    padding: 1px 4px !important;
  }

  .rating-count {
    font-size: 9.5px !important;
  }

  .current-price {
    font-size: 12.5px !important;
  }

  .mrp-price {
    font-size: 9.5px !important;
  }

  .add-cart-btn {
    padding: 6px 2px !important;
    font-size: 10px !important;
    gap: 4px !important;
  }
}

/* ==================== FINAL MOBILE OVERFLOW SAFETY ==================== */
@media (max-width: 850px) {
  .listing-wrapper,
  .listing-main-layout,
  .list-products-section,
  .products-grid,
  .product-card,
  .product-img-box,
  .product-title,
  .card-actions {
    min-width: 0 !important;
    max-width: 100% !important;
  }

  .product-card *,
  .list-products-section * {
    max-width: 100%;
  }

  .product-title,
  .product-cat,
  .rating-count,
  .current-price,
  .mrp-price {
    overflow-wrap: anywhere;
  }

  .add-cart-btn {
    overflow: hidden;
  }
}
