/* ========== CONTAINER ========== */
.container {
  max-width: 1200px; /* naikkan sedikit dari 1100 apabila perlu */
  margin: 0 auto;
  padding: 28px;
}

/* ========== CATALOG: sections by product type; grid lives in .product-type-section__grid ========== */

#products {
  display: block;
  margin-top: 1.5rem;
  width: 100%;
  min-height: 320px;
  box-sizing: border-box;
}

#products.products-catalog {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.product-type-section {
  width: 100%;
  box-sizing: border-box;
}

.product-type-section__title {
  font-size: 1.35rem;
  font-weight: 700;
  color: #1a237e;
  margin: 0 0 0.75rem 0;
  letter-spacing: -0.02em;
}

.product-type-section__grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  width: 100%;
  justify-items: stretch;
  align-items: stretch;
  box-sizing: border-box;
}

#products > .products-loading {
  width: 100%;
}

.products-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  min-height: 400px;
  box-sizing: border-box;
}

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

.products-loading__spinner {
  width: 50px;
  height: 50px;
  border: 4px solid #e5e7eb;
  border-top-color: #1a237e;
  border-radius: 50%;
  animation: products-loading-spin 0.9s linear infinite;
  margin-bottom: 16px;
}

.products-loading__title {
  color: #6b7280;
  font-size: 16px;
  margin: 0;
}

.products-loading__hint {
  color: #9ca3af;
  font-size: 14px;
  margin: 8px 0 0;
}

#products .product-type-section__grid > .product-card {
  justify-self: stretch;
  align-self: start;
}

/* Card produk */
.product-card {
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
  min-height: 280px; /* reduced height */
}

.product-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

/* Gambar */
.product-card .image-container {
  position: relative;
  width: 100%;
  height: 120px;
  overflow: hidden;
}

.product-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Label di pojok (book / clothes / equipment) */
.product-card .label {
  position: absolute;
  top: 8px;
  right: 8px;
  background: linear-gradient(135deg, #1a237e 0%, #3949ab 100%);
  color: #fff;
  font-size: 0.65rem;
  padding: 3px 8px;
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(26,35,126,0.3);
  text-transform: capitalize;
}

/* Info produk */
.product-info {
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1;
}

.product-info h4 {
  font-size: 0.9rem;
  font-weight: 600;
  color: #111827;
  margin-bottom: 0.15rem;
  min-height: 36px;
  line-height: 1.3;
}

/* Footer (harga + ikon/cart) */
.product-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-top: auto;
}

/* Harga */
.product-footer .price {
  font-weight: 600;
  font-size: 0.85rem;
  color: #1a237e;
}

.icon-btn {
  display: flex;
  justify-content: flex-end;
}

.icon-btn:hover {
  transform: scale(1.1);
}

/* Tombol beli langsung selalu di bawah */
.buy-btn {
  margin-top: 6px;
  background: linear-gradient(135deg, #1a237e 0%, #3949ab 100%);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 2px 8px rgba(26,35,126,0.25);
}

.buy-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(26,35,126,0.35);
}

/* search bar stretch */
.page-header .search-bar {
  width: 100%;
  max-width: 760px; /* batasi lebar input agar tidak terlalu panjang */
  padding-left: 0 !important;
  margin-left: 0 !important;
}

.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  width: 100%;
  /* agar controls tidak ter-push ke tengah ketika grid berubah */
}

/* ===== FINAL OVERRIDE: fixed card width, left-aligned grid, responsive ===== */

/* container spacing so grid doesn't touch edges */
.container {
  padding-left: 40px !important;
  padding-right: 40px !important;
}

/* Catalog wrapper + per-type grids (horizontal padding matches page header) */
#products {
  display: block !important;
  width: 100% !important;
  margin-top: 1.5rem !important;
  box-sizing: border-box !important;
  padding-left: 120px !important;
  padding-right: 120px !important;
  padding-bottom: 40px !important;
}

#products.products-catalog {
  display: flex !important;
  flex-direction: column !important;
  gap: 2rem !important;
}

.product-type-section__grid {
  display: grid !important;
  grid-template-columns: repeat(4, 1fr) !important;
  gap: 1rem !important;
  justify-content: start !important;
  justify-items: stretch !important;
  align-items: stretch !important;
  width: 100% !important;
  box-sizing: border-box !important;
}

/* Cards stretch to fill their grid cell */
#products .product-type-section__grid > .product-card,
section#products .product-type-section__grid > .product-card {
  width: 100% !important;
  max-width: 100% !important;
  margin: 0 !important;
  justify-self: stretch !important;
  align-self: stretch !important;
  box-sizing: border-box !important;
  height: 100% !important;
}

.product-type-section__title {
  font-size: 1.35rem !important;
  font-weight: 700 !important;
  color: #1a237e !important;
  margin: 0 0 0.75rem 0 !important;
  letter-spacing: -0.02em !important;
}

#products > .products-loading,
section#products > .products-loading {
  width: 100% !important;
  justify-self: stretch !important;
}

/* bila ada wrapper yang membuat center (flex/justify-center), override child */
main .container,
main > .container {
  display: block !important;
  width: 100% !important;
  max-width: none !important;
  margin: 0 !important;
  padding: 0 0 40px 0 !important; /* Add bottom padding for footer spacing */
  box-sizing: border-box !important;
}

.page-header,
.controls {
  display: block !important;
  width: 100% !important;
  max-width: none !important;
  margin: 0 !important;
  padding: 0 !important;
  box-sizing: border-box !important;
}

/* force search / controls area tetap di atas dan tidak dipengaruhi */
.page-header { 
  padding-bottom: 12px !important; 
  padding-left: 120px !important; 
  padding-right: 120px !important; 
  padding-top: 60px !important;
  text-align: left !important;
}
.page-header h1 {
  text-align: left !important;
  padding-left: 0 !important;
  margin: 0 0 16px 0 !important;
}
.page-header .search-bar {
  margin-left: 0 !important;
  margin-right: auto !important;
}
.controls { display:flex !important; justify-content: space-between !important; align-items:center !important; }

/* debug visual aid (hapus nanti) - akan beri border merah pada #courses agar mudah lihat area */
#products.debug-show {
  outline: 1px dashed rgba(255,0,0,0.35) !important;
}

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

@media (max-width: 1024px) {
  .product-type-section__grid {
    grid-template-columns: repeat(3, 1fr) !important;
  }
}

@media (max-width: 768px) {
  #products {
    padding-left: 16px !important;
    padding-right: 16px !important;
  }

  .product-type-section__grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  
  .page-header {
    padding-left: 16px !important;
    padding-right: 16px !important;
    padding-top: 20px !important;
  }
  
  .page-header h1 {
    font-size: 1.3rem !important;
  }
  
  .page-header .search-bar {
    max-width: 100% !important;
  }
  
  .controls {
    flex-wrap: wrap;
    gap: 8px !important;
  }
  
  .filters {
    flex-wrap: wrap;
    gap: 6px;
  }
  
  .filter-btn {
    font-size: 11px !important;
    padding: 6px 10px !important;
  }
  
  .sorting {
    width: 100%;
  }
  
  .sorting select {
    width: 100%;
  }
}

@media (max-width: 480px) {
  #products {
    padding-left: 12px !important;
    padding-right: 12px !important;
  }

  .product-type-section__grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
    align-items: stretch !important;
  }

  #products .product-type-section__grid > .product-card {
    align-self: stretch !important;
    height: 100% !important;
  }
  
  .page-header {
    padding-left: 12px !important;
    padding-right: 12px !important;
  }
  
  .page-header h1 {
    font-size: 1.1rem !important;
  }
  
  .product-card {
    min-height: 240px !important;
  }
  
  .product-card .image-container {
    height: 100px !important;
  }
  
  .product-info {
    padding: 0.5rem !important;
  }
  
  .product-info h4 {
    font-size: 0.75rem !important;
    min-height: 28px !important;
  }
  
  /* Mobile: Reorganize footer layout */
  .product-footer {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 6px !important;
  }
  
  .product-footer .price {
    font-size: 0.75rem !important;
    text-align: left !important;
    width: 100% !important;
  }
  
  /* icon-btn contains either add-cart-btn or card-qty-control */
  .product-footer .icon-btn {
    width: 100% !important;
    display: flex !important;
    justify-content: flex-end !important;
  }
  
  /* When showing add-cart-btn, keep compact and right-aligned */
  .product-footer .icon-btn .add-cart-btn {
    width: auto !important;
    font-size: 9px !important;
    padding: 6px 10px !important;
    text-align: center !important;
  }
  
  /* When showing qty control, keep it compact and right-aligned */
  .product-footer .icon-btn .card-qty-control {
    margin-left: auto !important;
  }
  
  .buy-btn {
    font-size: 0.7rem !important;
    padding: 0.4rem !important;
    width: 100% !important;
  }
  
  .card-qty-control .qty-btn {
    width: 24px !important;
    height: 24px !important;
    font-size: 14px !important;
  }
  
  .card-qty-control .qty-value {
    min-width: 22px !important;
    font-size: 11px !important;
  }
}

/* Modal overlay */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 999;
  transition: opacity 0.25s ease;
  overflow-y: auto; /* ✅ agar bisa scroll seluruh layar */
  padding: 40px 16px; /* biar modal punya jarak atas bawah saat scroll */
}

.modal.hidden {
  opacity: 0;
  pointer-events: none;
}

/* Konten modal */
.modal-content {
  background: white;
  border-radius: 16px;
  max-width: 700px;
  width: 100%;
  max-height: 90vh; /* ✅ batasi tinggi agar tidak keluar layar */
  overflow-y: auto; /* ✅ scroll isi modal saja */
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.3s ease;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.modal-body {
  display: flex;
  flex-direction: column; /* ✅ ubah jadi column untuk fleksibilitas konten panjang */
  gap: 16px;
  padding: 24px;
}

.modal-body img {
  width: 100%;
  height: auto;
  max-height: 250px;
  object-fit: cover;
  border-radius: 12px;
}

.modal-info {
  flex: 1;
  overflow-y: auto;
}

.modal-info p {
  line-height: 1.6;
  color: #374151;
  white-space: pre-line;
}

.close-modal {
  align-self: flex-end;
  background: none;
  border: none;
  font-size: 28px;
  cursor: pointer;
  padding: 8px 12px;
  color: #555;
}

.modal-actions {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn-primary {
  background-color: #2563eb;
  color: white;
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}

.btn-secondary {
  background-color: #e5e7eb;
  color: #111;
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
}

@keyframes fadeIn {
  from {opacity: 0; transform: translateY(10px);} 
  to {opacity: 1; transform: translateY(0);} 
}

/* Modal Quantity Controls */
.cart-controls-container {
  margin-top: 16px;
}

.modal-qty-control {
  display: inline-flex;
  align-items: center;
  gap: 0;
  background: #f3f4f6;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #e5e7eb;
}

.modal-qty-control .qty-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: #e5e7eb;
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  color: #374151;
  transition: background 0.2s, color 0.2s;
}

.modal-qty-control .qty-btn:hover {
  background: #0aa678;
  color: white;
}

.modal-qty-control .qty-btn:active {
  transform: scale(0.95);
}

.modal-qty-control .qty-value {
  min-width: 50px;
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  color: #111827;
  padding: 0 8px;
}

/* Product Card Cart Controls */
.add-cart-btn {
  background: linear-gradient(135deg, #e91e63 0%, #f48fb1 100%);
  color: white;
  border: none;
  padding: 5px 8px;
  border-radius: 5px;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(233,30,99,0.3);
}

.add-cart-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(233,30,99,0.4);
}

.add-cart-btn:active {
  transform: scale(0.95);
}

.card-qty-control {
  display: inline-flex;
  align-items: center;
  gap: 0;
  background: #f3f4f6;
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid #e5e7eb;
}

.card-qty-control .qty-btn {
  width: 24px;
  height: 24px;
  border: none;
  background: #e5e7eb;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: #374151;
  transition: background 0.2s, color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-qty-control .qty-btn:hover {
  background: #1a237e;
  color: white;
}

.card-qty-control .qty-btn:active {
  transform: scale(0.95);
}

.card-qty-control .qty-value {
  min-width: 24px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: #111827;
  padding: 0 2px;
}