:root {
  --bg-color: #f8f9fa;
  --card-bg: #ffffff;
  --text-color: #212529;
  --text-muted: #6c757d;
  --primary-color: #4a55c7;
  --primary-hover: #3a43a1;
  --border-color: #dee2e6;
  --shadow-color: rgba(0, 0, 0, 0.075);
  --success-color: #28a745;
  --error-color: #dc3545;
  --notification-bg: #343a40;
  --notification-text: white;
  --header-height: 5rem;
}

body {
  font-family: "Arial", sans-serif;
  margin: 0;
  background-color: var(--bg-color);
  color: var(--text-color);
  overflow-x: hidden;
  direction: rtl;
  text-align: right;
  padding-top: var(--header-height);
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background-color: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(5px);
  border-bottom: 1px solid var(--border-color);
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 100;
  box-shadow: 0 2px 4px var(--shadow-color);
  box-sizing: border-box;
  height: var(--header-height);
}

.store-identity {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.store-identity .icon {
  color: var(--primary-color);
  width: 40px;
  height: 40px;
  object-fit: contain;
}
.store-info h1 {
  margin: 0;
  font-size: 1.25rem;
}
.store-info p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.icon-button {
  background-color: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  width: 40px;
  height: 40px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  position: relative;
  color: var(--text-color);
  transition: background-color 0.2s;
}
.icon-button:hover {
  background-color: var(--border-color);
}
.icon-button .icon {
  width: 20px;
  height: 20px;
}
#cart-count {
  position: absolute;
  top: -5px;
  right: auto;
  left: -5px;
  background-color: #e63946;
  color: white;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  font-size: 0.7rem;
  font-weight: bold;
  display: flex;
  justify-content: center;
  align-items: center;
  border: 2px solid var(--card-bg);
}

main {
  min-height: calc(100vh - var(--header-height));
  max-width: 1200px;
  margin: 0 auto;
}
.loader-container {
  padding-top: 5rem;
  display: flex;
  justify-content: center;
}
.loader {
  border: 5px solid var(--border-color);
  border-top: 5px solid var(--primary-color);
  border-radius: 50%;
  width: 50px;
  height: 50px;
  animation: spin 1s linear infinite;
}
@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

#product-feed {
  padding: 1.5rem;
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

.product-card {
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 6px var(--shadow-color);
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

@media (hover: hover) {
  .product-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px var(--shadow-color);
  }
}

.product-image-container {
  width: 100%;
  height: 180px;
  display: block;
  flex-shrink: 0;
  cursor: pointer;
  position: relative;
  background-color: #f0f0f0;
}
.product-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.image-count-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  background-color: rgba(0, 0, 0, 0.6);
  color: white;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: bold;
  backdrop-filter: blur(2px);
}

.product-card .product-info {
  padding: 1rem;
  text-align: right;
  display: flex;
  flex-direction: column;
  flex-grow: 1;
}
.product-info h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  text-align: center;
}
.product-info .description {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.4;
  text-align: center;
  flex-grow: 1;
}
.product-info .price {
  margin: 0.5rem 0;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary-color);
  text-align: center;
}

.price-tier-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0 0.5rem;
  font-size: 0.85rem;
}
.price-tier-table th,
.price-tier-table td {
  border: 1px solid var(--border-color);
  padding: 8px;
  text-align: center;
}
.price-tier-table th {
  background-color: var(--bg-color);
  font-weight: 600;
}

.product-controls {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  margin-top: 1rem;
  flex-shrink: 0;
}
.quantity-selector {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}
.quantity-btn {
  background-color: var(--bg-color);
  border: 1px solid var(--border-color);
  color: var(--text-color);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  font-size: 1.3rem;
  font-weight: 300;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s, color 0.2s;
}
.quantity-btn:hover {
  background-color: var(--primary-color);
  color: white;
}
.quantity-value {
  font-size: 1.1rem;
  font-weight: 500;
  min-width: 35px;
  text-align: center;
  direction: ltr;
}
.add-to-cart-btn {
  width: 100%;
  background-color: var(--text-color);
  color: var(--bg-color);
  border: none;
  padding: 0.7rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  transition: background-color 0.2s;
}
.add-to-cart-btn:hover {
  background-color: var(--primary-hover);
}
.add-to-cart-btn.added {
  background-color: var(--success-color);
  color: white;
}

.modal {
  display: none;
  position: fixed;
  z-index: 1001;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.6);
  justify-content: center;
  align-items: center;
  padding: 1rem;
  box-sizing: border-box;
}
.modal-content {
  background-color: var(--card-bg);
  margin: auto;
  padding: 0;
  border-radius: 8px;
  width: 100%;
  max-width: 500px;
  position: relative;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  text-align: center;
  overflow: hidden;
}
.close-button {
  color: var(--text-muted);
  position: absolute;
  top: 10px;
  right: 20px;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
  z-index: 10;
}
#checkout-form-container {
  width: 100%;
  padding: 2rem;
  box-sizing: border-box;
  display: block;
  text-align: right;
}
#modal-order-summary {
  margin: 1rem 0;
}
.summary-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px dotted var(--border-color);
  gap: 10px;
}
.summary-item:last-of-type {
  border-bottom: none;
}
.summary-item span:first-child {
  flex-grow: 1;
  text-align: right;
  direction: rtl;
}
.remove-item-btn {
  background-color: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 0.8rem;
  margin-right: 15px;
  transition: background-color 0.2s;
}
.remove-item-btn:hover {
  background-color: #f1b0b7;
}
#summary-total {
  font-weight: bold;
  font-size: 1.4rem;
  margin-top: 1.5rem;
  text-align: center;
  color: var(--primary-color);
  padding: 0.5rem 0;
  border-top: 2px solid var(--primary-color);
  width: 100%;
  box-sizing: border-box;
}
#checkout-form label {
  display: block;
  margin-top: 1rem;
  margin-bottom: 0.5rem;
  font-weight: bold;
  text-align: right;
}
#checkout-form input,
#checkout-form select {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background-color: var(--bg-color);
  color: var(--text-color);
  font-size: 1rem;
  box-sizing: border-box;
  text-align: right;
  direction: rtl;
}
#checkout-form input[type="tel"] {
  direction: ltr;
  text-align: left;
}
#checkout-form select:disabled {
  background-color: var(--border-color);
  cursor: not-allowed;
  opacity: 0.6;
}
.submit-order-btn {
  width: 100%;
  padding: 1rem;
  margin-top: 1.5rem;
  background-color: var(--primary-color);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1.1rem;
  font-weight: bold;
  cursor: pointer;
}
.submit-order-btn:hover {
  background-color: var(--primary-hover);
}
.order-success-message {
  background-color: var(--success-color);
  color: white;
  padding: 3rem 2rem;
  border-radius: 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
}
.order-success-message h2 {
  font-size: 1.8rem;
  margin: 0;
}
.order-success-message p {
  font-size: 1.1rem;
  line-height: 1.6;
  margin: 0;
}
.order-success-message .success-icon {
  color: white;
  width: 80px;
  height: 80px;
  margin-bottom: 1rem;
}
.ok-button {
  background-color: white;
  color: var(--success-color);
  border: none;
  padding: 0.75rem 2.5rem;
  border-radius: 5px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: bold;
  margin-top: 1.5rem;
  transition: background-color 0.2s, color 0.2s;
  display: block;
  margin-left: auto;
  margin-right: auto;
}
.hidden {
  display: none !important;
}
.notification-popup {
  position: fixed;
  top: calc(var(--header-height) + 20px);
  left: 50%;
  transform: translate(-50%, -20px);
  background-color: var(--notification-bg);
  color: var(--notification-text);
  padding: 1rem 1.5rem;
  border-radius: 8px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 10000;
  font-weight: 500;
  text-align: center;
  min-width: 250px;
  max-width: 90%;
}
.notification-popup.show {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
}
.notification-popup.success {
  background-color: var(--success-color);
  color: white;
}
.notification-popup.error {
  background-color: var(--error-color);
  color: white;
}

@media (min-width: 700px) {
  #product-feed {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media (min-width: 1024px) {
  #product-feed {
    grid-template-columns: repeat(3, 1fr);
  }
}

/*
--- REWRITTEN & FIXED: Lightbox Styles ---
*/
.lightbox {
  position: fixed;
  z-index: 2000;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.85);
  display: flex;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(5px);
  padding: 1rem; /* Add padding to ensure content doesn't touch edges */
  box-sizing: border-box;
}

.lightbox-content {
  /* These dimensions constrain the image to fit within the viewport,
       leaving space for padding and arrows. */
  max-width: calc(
    100vw - 8rem
  ); /* 100vw - (2 * 1rem padding) - (2 * 2rem arrow area) */
  max-height: calc(100vh - 4rem); /* 100vh - (2 * 1rem padding) */
  display: flex;
  justify-content: center;
  align-items: center;
}
#lightbox-img {
  /* Ensure the image scales down to fit its container, maintaining aspect ratio */
  max-width: 100%;
  max-height: 100%;
  object-fit: contain; /* This is key: it fits the entire image within the bounds */
  display: block; /* Removes any extra space below the image */
}

.lightbox-close {
  position: absolute;
  top: 15px;
  right: 15px;
  font-size: 2.5rem;
  line-height: 1;
  padding: 0 15px;
  border-radius: 8px;
  z-index: 2002;
  background-color: rgba(30, 30, 30, 0.5);
  color: white;
  border: none;
  cursor: pointer;
  transition: background-color 0.2s;
  user-select: none;
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background-color: rgba(30, 30, 30, 0.5);
  color: white;
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  z-index: 2001;
  transition: opacity 0.3s ease, background-color 0.2s;
  user-select: none;
  opacity: 0;
  visibility: hidden;
}

.lightbox-nav.visible {
  opacity: 1;
  visibility: visible;
}

.lightbox-nav:hover {
  background-color: rgba(0, 0, 0, 0.7);
}
.lightbox-nav svg {
  width: 24px;
  height: 24px;
}
.lightbox-prev {
  left: 1rem;
}
.lightbox-next {
  right: 1rem;
}

/* Adjust nav button positioning for smaller screens to ensure they are accessible */
@media (max-width: 600px) {
  .lightbox-nav {
    width: 36px;
    height: 36px;
    font-size: 1.5rem;
  }
  .lightbox-nav svg {
    width: 20px;
    height: 20px;
  }
  .lightbox-prev {
    left: 0.5rem;
  }
  .lightbox-next {
    right: 0.5rem;
  }
  .lightbox-content {
    max-width: calc(100vw - 4rem); /* Adjust for smaller button size */
    max-height: calc(100vh - 4rem);
  }
}
