/* === Reset and Base Styles === */
*,
*::before,
*::after {
  box-sizing: border-box; /* More intuitive box model */
}

html {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
}

body {
  margin: 0;
  background-color: #f39c6b;
  display: flex;
  justify-content: center;
  align-items: flex-start; /* Align to the top */
  min-height: 100vh;
  padding: 2rem; /* Add some padding around the whole page */
}

/* === Main Vending Machine Layout === */
.vending-machine {
  background-color: rgb(140, 215, 140);
  display: flex;
  flex-wrap: wrap; /* Allow items to wrap to the next line on smaller screens */
  gap: 30px; /* Space between product grid and panel */
  padding: 30px;
  width: 100%;
  max-width: 1800px; /* Set a max-width for very large screens */
  border-radius: 15px;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
  position: relative; /* For the h1 positioning */
}

h1 {
  position: absolute;
  top: -5px; /* Adjust positioning slightly */
  left: 30px;
  margin: 0; /* Remove default margin */
  color: white;
  text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.5);
}

/* === Product Grid === */
.product-container {
  flex: 3; /* Take up 3 parts of the available space */
  min-width: 600px; /* Don't get too squished before wrapping */
  display: grid;
  /* This creates a responsive grid that automatically adjusts columns */
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 20px; /* Consistent spacing between all items */
  background-color: white;
  padding: 20px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  align-content: flex-start; /* Align items to the top */
}

.product {
  /* No fixed width needed, the grid handles it automatically */
  height: 150px;
  background-color: #f0f0f0; /* Lighter gray */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between; /* Better vertical alignment */
  border-radius: 10px;
  cursor: pointer;
  position: relative;
  border: 1px solid #ddd;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  padding-bottom: 5px; /* Add some space for the price */
}

.product:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 15px rgba(0, 0, 0, 0.15);
}

.product > img {
  width: 100%; /* Make image fill the container width */
  height: 100px;
  padding: 10px;
  object-fit: contain;
  background-color: rgb(218, 176, 176);
  border-radius: 10px 10px 0 0; /* Match parent rounding */
  transition: transform 0.3s ease-in-out;
}

.product:hover img {
    transform: scale(1.05);
}

.product > p {
  margin: 0; /* Remove default margin for better control */
  font-weight: bold;
}

.product-name {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%); /* Center perfectly */
  background-color: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 5px 10px;
  border-radius: 5px;
  font-size: 14px;
  white-space: nowrap;
  opacity: 0; /* Use opacity for smoother transition */
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  z-index: 10;
}

.product:hover .product-name {
  opacity: 1;
  visibility: visible;
}

/* === Side Panel (Screen & Push Area) === */
.panel {
  flex: 1; /* Take up 1 part of the available space */
  min-width: 400px; /* Ensure panel doesn't get too small */
  display: flex;
  flex-direction: column;
}

.screen {
  width: 100%; /* Fill the panel */
  height: 680px; /* Increased Height */
  background-color: white;
  border: 10px solid rgb(40, 40, 40);
  border-radius: 30px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden; /* Hide overflowing content */
}

.push {
  display: flex;
  width: 100%;
  height: 150px; 
  background-color: crimson;
  margin-top: 20px;
  justify-content: center;
  align-items: center;
  border-radius: 0px 0px 20px 20px;
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
  position: relative; /* For the collect div */
}

.push > p {
  margin: 0;
  padding: 0;
  font-size: 100px;
  font-weight: bold;
  color: lemonchiffon;
  text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.4);
}

/* === Screen Content === */
.default {
  display: flex;
  flex-direction: column;
  height: 100%; /* Make it fill the screen */
  align-items: center;
  justify-content: space-between; /* Space out the content nicely */
  padding-bottom: 10px; /* Lifts the PAY button from the bottom */
}

.cart {
  height: 210px;
  border: 2px solid #e0e0e0;
  border-radius: 10px;
  position: relative;
  margin-top: 20px;
  display: flex;
  flex-direction: row;
  width: 100%; /* Fill the width */
  overflow-x: auto;
  overflow-y: hidden; /* Prevent vertical scroll */
  padding: 10px;
  padding-top: 45px; /* Make space for the new title bar */
  gap: 10px; /* Space between cart items */
  background-color: #f9f9f9;
}

/* Custom scrollbar for cart */
.cart::-webkit-scrollbar {
  height: 8px;
}
.cart::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 10px;
}
.cart::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 10px;
}
.cart::-webkit-scrollbar-thumb:hover {
  background: #555;
}

#cart {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  font-weight: bold;
  background-color: #f9f9f9; /* Match cart background */
  padding: 10px 15px;
  z-index: 2; /* Keep it above scrolling items */
  border-bottom: 2px solid #e0e0e0;
  border-radius: 8px 8px 0 0;
}

#empty{
  width: 100%;
  text-align: center;
  align-self: center;
  margin: 0;
  padding: 0 20px;
  color: #777;
}

.cart-item {
  flex-shrink: 0; /* Prevent items from shrinking */
  position: relative;
  height: 150px;
  width: 100px;
  border: 2px solid #ddd;
  border-radius: 5px;
  background: white; /* Changed background */
}

hr {
  margin: 5px 0;
  border: none;
  border-top: 1px solid #ccc;
}

.photo > img {
  height: 90px;
  width: 90px;
  margin: 5px;
  object-fit: contain;
}

#cart-price {
  margin: 0;
  padding: 0 5px;
  font-size: 14px;
}

.counter {
  position: absolute;
  bottom: -10px;
  right: -10px;
  border: 1px solid #aaa;
  background-color: yellow;
  border-radius: 50%;
  font-size: 16px;
  font-weight: bold;
  padding: 2px 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.remove {
  position: absolute;
  top: -10px;
  right: -10px;
  font-size: 14px;
  color: white;
  background-color: crimson;
  cursor: pointer;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  border: 1px solid white;
  z-index: 3; /* Ensures it appears above the cart header */
}

.bill-container {
  width: 100%;
  padding: 0 10px;
}

.bill-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
}

.bill-row span {
  font-size: 16px;
}

#pay {
  font-size: 40px;
  font-weight: bold;
  box-shadow: 0 9px #999;
  width: 80%;
  max-width: 250px;
  padding: 10px;
  border-radius: 10px;
  border: none;
  background-color: #4CAF50;
  color: white;
  cursor: pointer;
  transition: background-color 0.2s;
}

#pay:hover {
  background-color: #45a049;
}
#pay:active {
  background-color: #3e8e41;
  box-shadow: 0 5px #666;
  transform: translateY(4px);
}

#admin {
  position: absolute;
  bottom: 10px;
  right: 10px;
  border-radius: 3px;
  border: 1px solid #ccc;
  background-color: #f0f0f0;
  opacity: 0.7;
  cursor: pointer;
}
#admin:hover{
    opacity: 1;
}

/* === Payment & Feedback Screens === */
.payment,
.payment-success,
.payment-failed,
.admin-login,
.admin {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: white;
  padding: 20px;
  display: none; /* Kept from original CSS */
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

#title {
  font-size: 35px;
  margin: 0;
  font-weight: bold;
}
#money, #timer {
  font-size: 25px;
  font-weight: bold;
}
#warning {
  margin-top: -10px;
  font-size: 18px;
}
#cancel, .main-menu, .try-again {
  width: 150px;
  font-size: 25px;
  margin-top: 15px;
  padding: 10px;
  border-radius: 8px;
}
.happy > img {
  height: 250px;
  width: 250px;
}
#thanks, #failed {
  font-size: 22px;
  margin: 0;
  text-align: center;
}

/* === Push Area Animation Item === */
.collect {
  position: absolute;
  display: none;
  justify-content: center;
  align-items: center;
}
.collect img {
  width: 130px;
  height: 130px;
  object-fit: contain;
}
.expand-fade {
  transform: scale(2);
  opacity: 0;
  transition: transform 0.5s ease-in-out, opacity 0.5s ease-in-out;
}


/* === Admin Panel Styles === */
.admin-login {
  gap: 15px;
}
.admin-login > p {
  font-size: 40px;
  font-weight: bold;
  margin: 0;
}
.admin-login > input {
  font-size: 20px;
  padding: 10px;
  width: 80%;
  border: 1px solid #ccc;
  border-radius: 5px;
}
#login-feedback {
  font-size: 16px;
  font-weight: normal;
  color: rgb(173, 5, 5);
  height: 20px; /* Reserve space to prevent layout shift */
}
#login-button,
#login-cancel {
  font-size: 20px;
  width: 80%;
  padding: 10px;
}

.admin {
  justify-content: flex-start;
  overflow-y: auto;
}
.admin > p {
  font-size: 30px;
  margin-bottom: 10px;
}
.logOut {
  position: absolute;
  top: 20px;
  right: 25px;
  cursor: pointer;
  font-size: 24px;
}
.product-cont {
  display: flex;
  flex-direction: column;
  border: 1px solid #ccc;
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 15px;
  width: 100%;
}
.title {
  display: flex;
  font-weight: bold;
  margin-bottom: 10px;
  align-items: center;
}
.title p {
  margin: 0;
}
.edit-name {
  margin-left: 10px;
  cursor: pointer;
}
.detail {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
}
.visual {
  position: relative;
  width: 100px;
  height: 100px;
  border: solid #ddd;
  border-radius: 10px;
}
.visual > img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.details{
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.det {
  display: flex;
  align-items: center;
  gap: 5px;
}
#quantity-num {
  min-width: 25px;
  text-align: center;
}
.det > button {
  height: 25px;
  width: 25px;
}
#price-change {
  width: 60px;
}
.image-link {
  width: 100%;
  flex-grow: 1;
}
#save {
  margin-top: 10px;
  align-self: flex-start;
  padding: 8px 16px;
}

/* === Media Queries for Responsiveness === */

/* For tablets and smaller desktops */
@media (max-width: 1100px) {
  body {
    padding: 1rem; /* Less padding on smaller screens */
  }

  .vending-machine {
    flex-direction: column; /* Stack product grid and panel vertically */
    align-items: center; /* Center them when stacked */
  }

  .product-container {
    width: 100%;
    min-width: unset; /* Remove min-width to allow it to shrink */
  }

  .panel {
    width: 100%;
    max-width: 500px; /* Constrain panel width on medium screens */
    min-width: unset;
  }
}

/* For mobile phones */
@media (max-width: 480px) {
  body {
    padding: 0.5rem;
  }
  .vending-machine {
    padding: 15px;
  }
  h1 {
      font-size: 1.5rem;
      position: static; /* Let h1 flow normally in the document */
      width: 100%;
      text-align: center;
      margin-bottom: 15px;
  }
  .screen {
      height: 90vh; /* Make screen taller on mobile */
      max-height: 700px;
  }
  .push > p {
      font-size: 80px;
  }
  #pay{
      font-size: 30px;
  }
  .happy > img {
    height: 180px;
    width: 180px;
  }
  #title{
      font-size: 28px;
  }
}

