/* Cart CSS - Mobile Responsive Layout - Fixed Spacing */
/* First item needs special positioning due to Shopping Bag header */
.item:first-child .buttons {
  top: calc(50% - 6rem);
}

.item:first-child .image {
  top: calc(50% - 6rem);
}

.item:first-child .description {
  position: absolute;
  left: 410px;
  top: calc(50% - 6rem);
  transform: translateY(-50%);
  margin-top: 0;
}

.item:first-child .quantity {
  top: calc(40% + 145px + 0.5rem);
  left: 235px;
}

#main-content {
  min-height: 600px;
  padding-bottom: 2rem;
  padding-top: 6rem;
}

.shopping-cart {
  min-height: 400px;
  margin-top: 4rem;
}

.shopping-cart .title {
  display: none;
}

.shopping-bag-text {
  position: absolute;
  top: 1rem;
  left: 0;
  right: 0;
  color: #2d2d2d;
  font-size: 2rem;
  font-weight: 700;
  padding-bottom: 1.5rem;
  padding-left: 1.5rem;
  border-bottom: 2px solid #2d2d2d;
}

/* Consistent styling applied to all cart items below */

.checkout-buttons-section {
  position: absolute;
  bottom: 3rem;
  left: 1.5rem;
  right: 1.5rem;
  display: flex;
  gap: 1rem;
  justify-content: center;
}

.checkout-buttons-section .btn {
  padding: 0.8rem 1.5rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  min-width: 120px;
}

.login-to-purchase-btn {
  background: #000;
  color: white;
}

.login-to-purchase-btn:hover {
  background: #333;
}

.clear-cart-btn {
  background: #f8f9fa;
  color: #333;
  border: 2px solid #ddd;
}

.clear-cart-btn:hover {
  background: #e9ecef;
}

/* Total price styling moved to general .total-price */

.cart-container {
  padding: 2rem 0;
  max-width: 800px;
  margin: 0 auto;
}

.item {
  background: white;
  padding: 3.5rem 1.5rem;
  margin-bottom: 2rem;
  border-radius: 15px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  border: 2px solid #000;
  display: block;
  position: relative;
  max-width: 850px;
  margin-left: auto;
  margin-right: auto;
  min-height: 900px;
}

.item::after {
  content: "";
  position: absolute;
  bottom: 12rem;
  left: 0;
  right: 0;
  height: 2px;
  background-color: #2d2d2d;
}

.buttons {
  position: absolute;
  left: 50px;
  top: calc(50% - 6rem);
  transform: translateY(-50%);
}

.delete-btn {
  background: #dc3545;
  color: white;
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  font-weight: bold;
}

.delete-btn:hover {
  background: #c82333;
}

.image {
  width: 290px;
  height: 290px;
  border-radius: 10px;
  overflow: hidden;
  position: absolute;
  left: 90px;
  top: calc(50% - 6rem);
  transform: translateY(-50%);
}

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

.description {
  display: block;
  margin-bottom: 1rem;
  position: absolute;
  left: 410px;
  top: calc(50% - 6rem);
  transform: translateY(-50%);
  overflow: hidden;
}

.description span:first-child {
  display: block;
  font-size: 1.6rem;
  font-weight: 800;
  color: #333;
  margin-bottom: 0.5rem;
}

.description span:last-child {
  display: block;
  font-size: 1.4rem;
  font-weight: 800;
  color: #000;
}

.quantity {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-right: 1rem;
  position: absolute;
  left: 235px;
  top: calc(40% + 145px + 0.5rem);
  transform: translateX(-50%);
  margin-top: 0;
}

.quantity button {
  background: #000;
  color: transparent;
  border: none;
  border-radius: 8px;
  width: 26px;
  height: 26px;
  cursor: pointer;
  font-weight: bold;
  font-size: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  position: relative;
}

.quantity button::after {
  content: "+";
  position: absolute;
  color: white;
  font-size: 16px;
  font-weight: bold;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  line-height: 1;
}

.quantity button:first-child::after {
  content: "-";
}

.quantity button:hover {
  background: #333;
  transform: scale(1.05);
}

.quantity input {
  width: 40px;
  height: 24px;
  text-align: center;
  border: 2px solid #ddd;
  border-radius: 8px;
  padding: 0;
  font-weight: 600;
  font-size: 0.8rem;
}

.total-price {
  position: absolute;
  bottom: 6rem;
  left: 1.5rem;
  right: 1.5rem;
  text-align: center;
  font-size: 1.4rem;
  font-weight: 700;
  color: #000;
  margin: 0;
}

.cart-summary-section {
  background: white;
  padding: 2rem;
  border-radius: 15px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  border: 2px solid #000;
  margin-top: 2rem;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
}

.checkout-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.total-amount {
  font-size: 1.5rem;
  font-weight: 700;
  color: #000;
}

.checkout-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

.empty-cart-state {
  text-align: center;
  padding: 3rem 2rem;
  background: white;
  border-radius: 15px;
  margin: 2rem auto;
  border: 2px solid #000;
  max-width: 600px;
}

.empty-message h3 {
  color: #444;
  margin-bottom: 1.5rem;
}

.empty-message p {
  color: #555;
  margin-bottom: 2rem;
  font-weight: 500;
}

/* MOBILE CART RESPONSIVE LAYOUT - iPhone Compatible */
@media (max-width: 768px) {
  .item {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    text-align: center !important;
    padding: 2rem 1.5rem 3rem 1.5rem !important;
    min-height: auto !important;
    position: relative !important;
    gap: 2.5rem !important;
    margin-bottom: 3rem !important;
  }

  /* Reset positioning for main layout elements only */
  .item .buttons,
  .item .image,
  .item .description,
  .item .quantity,
  .item .total-price {
    position: static !important;
    transform: none !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
  }

  /* Keep pseudo-element positioning for quantity buttons */
  .quantity button {
    position: relative !important;
  }

  .quantity button::after {
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
  }

  /* Mobile layout order using flexbox order */

  /* Image container - iPhone optimized */
  .image {
    width: 220px !important;
    height: 220px !important;
    margin: 1rem auto 2rem auto !important;
    border-radius: 12px !important;
    overflow: hidden !important;
    order: 1 !important;
    position: relative !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1) !important;
  }

  /* Position delete button right below the image - iPhone spacing */
  .item .buttons {
    position: static !important;
    order: 2 !important; /* Right after image */
    width: 100% !important;
    display: flex !important;
    justify-content: center !important;
    margin: 0 0 3rem 0 !important;
    padding: 1rem 0 !important;
  }

  /* Delete button styling for mobile - iPhone optimized */
  .item .delete-btn {
    position: static !important;
    width: 32px !important;
    height: 32px !important;
    font-size: 16px !important;
    background: #dc3545 !important;
    border-radius: 50% !important;
    border: 2px solid white !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2) !important;
  }

  /* Product description - Third (after image and delete button) */
  .description {
    text-align: center !important;
    margin: 0 0 3rem 0 !important;
    width: 100% !important;
    order: 3 !important;
    padding: 2rem 1.5rem !important;
    border-bottom: 3px solid #f0f0f0 !important;
    padding-bottom: 3rem !important;
    background: rgba(248, 249, 250, 0.5) !important;
    border-radius: 8px !important;
  }

  .description span:first-child {
    font-size: 1.8rem !important;
    margin-bottom: 1rem !important;
    display: block !important;
    font-weight: 800 !important;
    color: #333 !important;
    line-height: 1.2 !important;
  }

  .description span:last-child {
    font-size: 1.4rem !important;
    display: block !important;
    color: #555 !important;
    font-weight: 600 !important;
  }

  /* Quantity controls - Fourth */
  .quantity {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 1.5rem !important;
    margin: 2rem 0 !important;
    width: 100% !important;
    order: 4 !important;
    padding: 1rem !important;
  }

  /* Total price - Fifth */
  .total-price {
    text-align: center !important;
    margin: 2rem 0 3rem 0 !important;
    width: 100% !important;
    font-size: 1.6rem !important;
    order: 5 !important;
    padding: 1.5rem !important;
    background: rgba(0, 0, 0, 0.08) !important;
    border-radius: 12px !important;
    font-weight: 700 !important;
    border: 2px solid #ddd !important;
  }

  /* Remove the ::after line */
  .item::after {
    display: none !important;
  }

  /* Checkout section - Sixth */
  .checkout-content {
    flex-direction: column !important;
    gap: 1rem !important;
    text-align: center !important;
    order: 6 !important;
  }

  .checkout-actions {
    flex-direction: column !important;
    gap: 1rem !important;
    order: 7 !important;
  }

  .checkout-actions .btn {
    width: 100% !important;
    padding: 1rem !important;
    font-size: 1rem !important;
  }

  /* Cart summary section */
  .cart-summary-section {
    order: 8 !important;
    position: relative !important;
  }

  /* Prevent overlapping issues */
  .item {
    z-index: 2 !important;
    margin-bottom: 2rem !important;
  }

  /* Fix checkout buttons inside first cart item */
  .checkout-buttons-section {
    position: static !important;
    bottom: auto !important;
    left: auto !important;
    right: auto !important;
    margin-top: 2rem !important;
    padding: 2rem !important;
    flex-direction: column !important;
    order: 9 !important; /* Place after everything else */
    width: 100% !important;
    gap: 1rem !important;
    border-top: 2px solid #eee !important;
    padding-top: 2rem !important;
  }

  .checkout-buttons-section .btn {
    width: 100% !important;
    padding: 1.2rem !important;
    font-size: 1.1rem !important;
    margin: 0 !important;
    border-radius: 8px !important;
  }

  /* Make sure first item respects flexbox layout */
  .item:first-child {
    display: flex !important;
    flex-direction: column !important;
  }

  /* Override first-child specific positioning rules on mobile */
  .item:first-child .image,
  .item:first-child .description,
  .item:first-child .quantity {
    position: static !important;
    top: auto !important;
    left: auto !important;
    transform: none !important;
  }

  /* Ensure first-child image follows mobile layout order - pushed down */
  .item:first-child .image {
    width: 200px !important;
    height: 200px !important;
    margin: 2rem auto 1rem auto !important; /* Better spacing */
    border-radius: 10px !important;
    overflow: hidden !important;
    order: 1 !important;
    position: relative !important;
  }

  /* First-child buttons follow same pattern */
  .item:first-child .buttons {
    position: static !important;
    order: 2 !important;
    width: 100% !important;
    display: flex !important;
    justify-content: center !important;
    margin: 0 0 2rem 0 !important;
  }

  /* Container improvements */
  .shopping-cart {
    margin-top: 1rem !important;
    padding: 0 0.5rem !important;
  }

  .empty-cart-state {
    margin: 1rem 0.5rem !important;
    padding: 2rem 1rem !important;
  }

  .cart-summary-section {
    margin: 1rem 0.5rem !important;
    padding: 1.5rem 1rem !important;
  }

  /* Main content spacing */
  #main-content {
    padding-top: 2rem !important;
  }
}

/* iPhone and small mobile screens */
@media (max-width: 480px), (max-device-width: 480px) {
  .item {
    padding: 4rem 1rem 2rem 1rem !important;
    margin-bottom: 2rem !important;
    min-height: 600px !important;
    gap: 1rem !important;
  }

  .image {
    width: 160px !important;
    height: 160px !important;
  }

  .description {
    padding: 0 0.5rem !important;
  }

  .description span:first-child {
    font-size: 1.2rem !important;
  }

  .description span:last-child {
    font-size: 1rem !important;
  }

  .quantity input {
    width: 40px !important;
    height: 35px !important;
  }

  .quantity button {
    width: 35px !important;
    height: 35px !important;
  }

  /* Delete button below image on small screens */
  .item .buttons {
    position: static !important;
    order: 2 !important;
    width: 100% !important;
    display: flex !important;
    justify-content: center !important;
    margin: 1rem 0 !important;
  }

  .item .delete-btn {
    width: 22px !important;
    height: 22px !important;
    font-size: 12px !important;
    background: rgba(220, 53, 69, 0.95) !important;
  }

  /* Override first-child image sizing on small screens - pushed down */
  .item:first-child .image {
    width: 160px !important;
    height: 160px !important;
    margin: 3rem auto 2rem auto !important; /* More top margin for smaller screens */
  }

  /* First-child buttons on small screens follow same pattern */
  .item:first-child .buttons {
    position: static !important;
    order: 2 !important;
    width: 100% !important;
    display: flex !important;
    justify-content: center !important;
    margin: 1rem 0 !important;
  }

  .checkout-buttons-section .btn {
    padding: 1rem !important;
    font-size: 1rem !important;
  }

  .shopping-cart {
    padding: 0 0.5rem !important;
  }

  .empty-cart-state,
  .cart-summary-section {
    margin: 1rem 0.5rem !important;
    padding: 2rem 1rem !important;
  }
}

/* iPhone specific fixes */
@media only screen and (device-width: 375px) and (device-height: 667px) and (-webkit-device-pixel-ratio: 2),
  only screen and (device-width: 375px) and (device-height: 812px) and (-webkit-device-pixel-ratio: 3),
  only screen and (device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 2) {
  .item {
    gap: 3rem !important;
    padding: 2rem 1rem 4rem 1rem !important;
  }

  .item .buttons {
    margin: 0 0 4rem 0 !important;
  }

  .description {
    margin: 0 0 4rem 0 !important;
    padding: 2.5rem 1rem !important;
  }
}
