/* BugMart Styles */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f5f5f5;
  color: #333;
  line-height: 1.6;
}

/* Header */
header {
  background: #2c3e50;
  color: white;
  padding: 1rem 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-size: 1.5rem;
  font-weight: bold;
  color: white;
  text-decoration: none;
}

nav a {
  color: white;
  text-decoration: none;
  margin-left: 1.5rem;
  font-size: 1rem;
}

nav a:hover {
  text-decoration: underline;
}

.cart-link {
  background: #e74c3c;
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
}

/* Main Content */
main {
  max-width: 1200px;
  margin: 2rem auto;
  padding: 0 1rem;
}

h1 {
  margin-bottom: 1.5rem;
  color: #2c3e50;
}

/* Product Grid */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1.5rem;
}

/* BUG 3: Fixed height instead of min-height — product 5 (long description) overflows */
.product-card {
  background: white;
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  height: 380px;
  cursor: pointer;
  transition: transform 0.2s;
}

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

.product-card img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  border-radius: 4px;
  margin-bottom: 0.75rem;
}

.product-card h3 {
  font-size: 1rem;
  margin-bottom: 0.5rem;
}

.product-card .description {
  font-size: 0.85rem;
  color: #666;
  flex-grow: 1;
  overflow: hidden;
}

/* BUG 1: max-width: 40px causes price text overflow on products >$99.99 */
.product-card .price {
  font-size: 1.2rem;
  font-weight: bold;
  color: #e74c3c;
  margin: 0.5rem 0;
  max-width: 40px;
  overflow: visible;
}

/* Buttons */
.btn {
  background: #3498db;
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  text-decoration: none;
  display: inline-block;
  text-align: center;
}

.btn:hover {
  background: #2980b9;
}

.btn-large {
  padding: 0.75rem 1.5rem;
  font-size: 1.1rem;
  width: 100%;
  margin-top: 1rem;
}

.btn-small {
  padding: 0.25rem 0.6rem;
  font-size: 0.9rem;
}

.btn-remove {
  background: #e74c3c;
  color: white;
  border: none;
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
}

.btn-remove:hover {
  background: #c0392b;
}

.add-to-cart-btn {
  margin-top: auto;
}

/* Product Detail */
.product-detail {
  background: white;
  border-radius: 8px;
  padding: 2rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.detail-layout {
  display: flex;
  gap: 2rem;
}

.detail-image {
  flex: 1;
}

.detail-image img {
  width: 100%;
  border-radius: 8px;
}

.detail-info {
  flex: 1;
}

.detail-price {
  font-size: 1.8rem;
  font-weight: bold;
  color: #e74c3c;
  margin: 1rem 0;
}

.detail-description {
  color: #666;
  margin-bottom: 1rem;
}

.stock-info {
  color: #27ae60;
  margin-bottom: 1rem;
}

.quantity-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.quantity-selector input {
  width: 60px;
  padding: 0.4rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  text-align: center;
  font-size: 1rem;
}

/* Cart Page */
.cart-item {
  background: white;
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  display: flex;
  align-items: center;
  gap: 1rem;
}

.cart-item-image {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 4px;
}

.cart-item-info {
  flex: 1;
}

.cart-item-info h3 {
  font-size: 1rem;
}

.cart-item-price {
  color: #666;
}

.quantity-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.quantity-display {
  min-width: 30px;
  text-align: center;
  font-weight: bold;
}

.cart-item-line-total {
  font-weight: bold;
  min-width: 80px;
  text-align: right;
}

.cart-summary {
  background: white;
  border-radius: 8px;
  padding: 1.5rem;
  margin-top: 1.5rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.summary-row {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0;
}

.total-row {
  font-weight: bold;
  font-size: 1.2rem;
  border-top: 2px solid #eee;
  padding-top: 0.75rem;
  margin-top: 0.5rem;
}

.checkout-btn {
  margin-top: 1rem;
  background: #27ae60;
}

.checkout-btn:hover {
  background: #219a52;
}

/* Checkout Page */
.checkout-layout {
  max-width: 600px;
}

.checkout-form h2 {
  margin: 1.5rem 0 1rem;
  color: #2c3e50;
}

.checkout-form h2:first-child {
  margin-top: 0;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group input {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 1rem;
}

.form-group input:focus {
  outline: none;
  border-color: #3498db;
}

.form-row {
  display: flex;
  gap: 1rem;
}

.form-row .form-group {
  flex: 1;
}

.error-msg {
  color: #e74c3c;
  font-size: 0.8rem;
  display: block;
  margin-top: 0.25rem;
}

.discount-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.discount-row input {
  flex: 1;
  padding: 0.5rem;
  border: 1px solid #ddd;
  border-radius: 4px;
}

.discount-message {
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.discount-message.success {
  color: #27ae60;
}

.discount-message.error {
  color: #e74c3c;
}

/* Order Summary */
.order-summary {
  background: #f9f9f9;
  border-radius: 8px;
  padding: 1rem;
  margin-top: 1.5rem;
}

.order-summary h3 {
  margin-bottom: 0.75rem;
}

.summary-item {
  display: flex;
  justify-content: space-between;
  padding: 0.3rem 0;
  font-size: 0.9rem;
}

.summary-item.total {
  font-weight: bold;
  border-top: 1px solid #ddd;
  padding-top: 0.5rem;
  margin-top: 0.3rem;
}

.summary-item.discount {
  color: #27ae60;
}

/* Order Confirmation */
.order-confirmation {
  background: white;
  border-radius: 8px;
  padding: 2rem;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.order-confirmation h2 {
  color: #27ae60;
  margin-bottom: 1rem;
}

.order-confirmation p {
  margin-bottom: 0.5rem;
}

.order-confirmation .btn {
  margin-top: 1.5rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: #27ae60;
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  animation: fadeIn 0.3s ease;
  z-index: 1000;
}

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

/* Responsive */
@media (max-width: 768px) {
  .detail-layout {
    flex-direction: column;
  }

  .cart-item {
    flex-wrap: wrap;
  }

  .product-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }
}
