/* CSS Reset and Global Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: "Khmer OS Battambang", "Arial", sans-serif;
  transition: all 0.2s ease-in-out;
}

body {
  background-color: #f7f9fc;
  color: #1f1f1f;
  padding-bottom: 65px; /* កន្លែងសម្រាប់ Bottom Navigation */
  line-height: 1.6;
}

/* ------------------ PROMOTION BANNER STYLES (កែសម្រួល) ------------------ */
.promotion-banner {
  /* ប្រើ Gradient សម្រាប់ Background */
  background: linear-gradient(
    135deg,
    #ff3d6f 0%,
    #e70050 100%
  ); /* ពណ៌ក្រហមឆ្អៅ/ផ្កាឈូក */
  color: #ffffff;
  padding: 12px 15px; /* បង្កើន Padding បន្តិច */
  text-align: center;
  font-size: 1em; /* ធ្វើឱ្យអក្សរធំបន្តិច */
  font-weight: 700;
  margin: 10px 15px 0 15px;
  border-radius: 10px; /* ធ្វើឱ្យរាងមូលស្អាត */
  box-shadow: 0 4px 15px rgba(231, 0, 80, 0.4); /* ស្រមោលពណ៌ក្រហម */
  display: flex;
  align-items: center;
  justify-content: center;
  /* Animation blink ថ្មី */
  animation: blinkShadow 3s infinite;
}

.promotion-banner i {
  margin-right: 10px;
  font-size: 1.2em;
  animation: pulse 1.5s infinite; /* រក្សា Icon animation */
}

.promotion-banner .banner-text {
  /* ធ្វើឱ្យអក្សរភ្លឺរលោង */
  text-shadow: 0 0 5px rgba(255, 255, 255, 0.5);
  letter-spacing: 0.5px;
}

/* Keyframes សម្រាប់ Icon (រក្សាទុក) */
@keyframes pulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
  }
}

/* Keyframes សម្រាប់ Shadow Blink (ថ្មី) */
@keyframes blinkShadow {
  0% {
    box-shadow: 0 4px 15px rgba(231, 0, 80, 0.4);
  }
  50% {
    box-shadow: 0 4px 20px rgba(255, 61, 111, 0.8); /* ភ្លឺជាងមុន */
  }
  100% {
    box-shadow: 0 4px 15px rgba(231, 0, 80, 0.4);
  }
}

/* សម្រាប់ Desktop/Tablet ត្រូវកែតម្រូវ margin */
@media (min-width: 768px) {
  .promotion-banner {
    max-width: 1000px;
    margin: 10px auto 0 auto;
    font-size: 1.1em;
  }
}
/* ----------------------------------------------------------------- */

/* ------------------ PROMOTION SLIDESHOW STYLES (NEW) ------------------ */

.slideshow-container {
  margin: 15px 15px 15px 15px; /* Margin ជុំវិញ */
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
  position: relative;
  width: calc(100% - 30px); /* ទទឹងពេញអេក្រង់ដក Margin */
}

.mySlides {
  display: none; /* លាក់ Slides ដំបូង */
  width: 100%;
  cursor: pointer;
}

.mySlides img {
  width: 100%;
  height: 150px; /* កំណត់កម្ពស់ថេរសម្រាប់ Mobile */
  object-fit: cover; /* ធានារូបភាពពេញកន្លែង */
  display: block;
}

/* ចំណុចរុករក (Dots) */
.dot-container {
  text-align: center;
  padding: 8px 0;
  background-color: #f7f9fc; /* ពណ៌ Background ដូច Body */
  margin-top: -5px; /* ជួយឱ្យវាភ្ជាប់ជាមួយ Slideshow */
}

.dot {
  cursor: pointer;
  height: 10px;
  width: 10px;
  margin: 0 4px;
  background-color: #bbb;
  border-radius: 50%;
  display: inline-block;
  transition: background-color 0.6s ease;
}

.active-dot,
.dot:hover {
  background-color: #e70050; /* ពណ៌ផ្កាឈូក */
}

/* សម្រាប់ Desktop/Tablet */
@media (min-width: 768px) {
  .slideshow-container {
    max-width: 1000px;
    margin: 15px auto 15px auto;
    width: 100%;
  }

  .mySlides img {
    height: 250px; /* កម្ពស់ធំជាងសម្រាប់ Desktop */
  }
}

/* ---------------------------------------------------------------------- */

/* ------------------ Order History Styles (NEW) ------------------ */
#order-history-modal-overlay .cart-modal-content {
  /* ប្រើ .cart-modal-content ដើម្បីកំណត់ទំហំ */
  max-width: 500px;
  max-height: 90vh; /* កំណត់កម្ពស់អតិបរមា */
}
.order-history-list {
  flex-grow: 1;
  overflow-y: auto;
  padding: 15px;
}
.order-card {
  background-color: #ffffff;
  border: 1px solid #eee;
  border-radius: 8px;
  margin-bottom: 15px;
  padding: 15px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}
.order-card h4 {
  font-size: 1.1em;
  color: #e70050; /* ពណ៌សម្រាប់ចំណងជើងកម្ម៉ង់ */
  margin-bottom: 5px;
}
.order-card .order-meta {
  font-size: 0.85em;
  color: #777;
  margin-bottom: 10px;
  border-bottom: 1px dashed #eee;
  padding-bottom: 5px;
  display: flex;
  justify-content: space-between;
}
.order-items {
  list-style: none;
  padding: 0;
  margin-top: 5px;
}
.order-item-detail {
  font-size: 0.9em;
  color: #555;
  padding: 3px 0;
}
.order-total-display {
  font-weight: bold;
  color: #333;
  margin-top: 10px;
  text-align: right;
  font-size: 1.1em;
  border-top: 1px solid #f0f0f0;
  padding-top: 8px;
}
.empty-history-message {
  text-align: center;
  padding: 30px 10px;
  color: #888;
  font-style: italic;
}

/* ------------------ Header Bar ------------------ */
.top-header {
  background: #ffffff;
  padding: 12px 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  position: sticky;
  top: 0;
  z-index: 100;
}

.top-header .logo {
  font-size: 1.4em;
  font-weight: 800;
  color: #e70050;
}

/* Desktop Cart Icon */
.top-header .icons {
  position: relative;
  cursor: pointer;
  padding: 5px;
}

.top-header .icons i {
  font-size: 1.5em;
  color: #333;
}

/* Desktop Cart Count Styling (NEW) */
#desktop-cart-count {
  position: absolute;
  top: 0px;
  right: 0px;
  background-color: #e70050;
  color: white;
  border-radius: 50%;
  padding: 3px 7px;
  font-size: 0.7em;
  font-weight: bold;
  display: none;
  z-index: 101;
}

/* ------------------ Search Bar ------------------ */
.search-bar {
  padding: 10px 15px;
  background-color: #ffffff;
  border-bottom: 1px solid #f0f0f0;
}

.search-bar input {
  width: 100%;
  padding: 10px 15px;
  border: 1px solid #ddd;
  border-radius: 25px;
  font-size: 1em;
  outline: none;
  background-color: #f7f9fc;
}

.search-bar input:focus {
  border-color: #e70050;
  box-shadow: 0 0 5px rgba(231, 0, 80, 0.1);
}

/* ------------------ Category Filter ------------------ */
.category-filter {
  padding: 10px 15px;
  white-space: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background-color: #ffffff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* 🔥 IMPROVEMENT: Hide scrollbar more reliably */
.category-filter::-webkit-scrollbar {
  display: none;
}
.category-filter {
  -ms-overflow-style: none; /* IE and Edge */
  scrollbar-width: none; /* Firefox */
}

.category-item {
  display: inline-block;
  padding: 8px 15px;
  margin-right: 10px;
  border-radius: 20px;
  background-color: #eee;
  color: #555;
  font-size: 0.9em;
  cursor: pointer;
  font-weight: 600;
  border: 1px solid #eee;
  transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}

.category-item:hover {
  background-color: #e70050;
  color: white;
  border-color: #e70050;
}

.category-item.active {
  background-color: #e70050;
  color: white;
  border-color: #e70050;
}

/* ------------------ Product Grid ------------------ */
.product-grid {
  padding: 15px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 15px;
}

.product-card {
  background: #ffffff;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  text-align: left;
  position: relative;
  cursor: pointer; /* make the whole card feel clickable */
  transition: transform 0.2s, box-shadow 0.2s;
}

/* 🔥 IMPROVEMENT: Add hover effect for desktop interaction */
.product-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
}

.product-card:active {
  transform: translateY(-2px);
}

/* Image container to make it clickable */
.image-clickable {
  cursor: pointer;
  display: block;
}

.product-card img {
  width: 100%;
  height: 200px;
  display: block;
  object-fit: cover;
}

.sale-tag,
.new-tag {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 4px 8px;
  border-radius: 5px;
  font-size: 0.75em;
  font-weight: bold;
  color: white;
  z-index: 10;
}

.sale-tag {
  background-color: #e70050;
}

.new-tag {
  background-color: #4caf50;
}

.product-info {
  padding: 10px;
}

.product-info h3 {
  font-size: 0.9em;
  margin-bottom: 5px;
  font-weight: 600;
  color: #333;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-clamp: 2;
  min-height: 2.2em; /* Fix height for consistent card size */
}

.price-group {
  display: flex;
  align-items: baseline;
  margin-top: 5px;
}

.price {
  color: #e70050;
  font-size: 1.1em;
  font-weight: 800;
}

.old-price {
  color: #999;
  font-size: 0.8em;
  text-decoration: line-through;
  margin-left: 8px;
}

/* Add to Cart Button */
.add-to-cart-btn {
  background-color: #28a745;
  color: white;
  border: none;
  padding: 8px;
  border-radius: 5px;
  cursor: pointer;
  width: 100%;
  font-size: 0.9em;
  font-weight: 700;
  margin-top: 8px;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: background-color 0.2s;
}

.add-to-cart-btn:hover {
  background-color: #1e8735;
}

.add-to-cart-btn i {
  margin-right: 5px;
  font-size: 1em;
}

.add-to-cart-btn span {
  display: none;
}

/* Show 'ទិញ' text on slightly larger screens */
@media (min-width: 380px) {
  .add-to-cart-btn span {
    display: inline;
  }
  .add-to-cart-btn i {
    margin-right: 5px;
  }
}

/* ------------------ Bottom Navigation ------------------ */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
  background-color: #ffffff;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
  padding: 8px 0;
  z-index: 1000;
  border-top-left-radius: 15px;
  border-top-right-radius: 15px;
}

.nav-item {
  text-align: center;
  color: #999;
  font-size: 0.75em;
  cursor: pointer;
  padding: 5px 0;
  width: 33.33%;
  position: relative;
}

/* 🔥 IMPROVEMENT: Better look for active state */
.nav-item.active {
  color: #e70050;
  font-weight: 600;
}
.nav-item:hover {
  color: #e70050;
}

.nav-item i {
  font-size: 1.4em;
  display: block;
  margin-bottom: 3px;
}

/* Cart Count Styling (Mobile) */
#cart-count {
  position: absolute;
  top: 2px;
  right: 25%;
  background-color: #e70050;
  color: white;
  border-radius: 50%;
  padding: 2px 6px;
  font-size: 0.7em;
  font-weight: bold;
  display: none;
}

/* ======================================================== */
/* ------------------ MODAL STYLES (All Modals) ------------------- */
/* ======================================================== */

.cart-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  z-index: 2000;
  display: none;
  justify-content: center;
  align-items: flex-end;
}

.cart-modal-overlay.open {
  display: flex;
}

.cart-modal-content {
  background: white;
  width: 100%;
  max-height: 80vh;
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
    opacity: 0.8;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* 🔥 IMPROVEMENT: Modal Header with Icon */
.modal-header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #e70050;
}
.modal-header-title i {
  font-size: 1.2em;
}

.cart-header {
  padding: 15px;
  border-bottom: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1.2em;
  font-weight: 700;
}

.cart-header .close-btn {
  font-size: 1.5em;
  cursor: pointer;
  color: #333;
}

#cart-items-container {
  flex-grow: 1;
  overflow-y: auto;
  padding: 15px;
}

.empty-cart-message {
  text-align: center;
  padding: 30px 10px;
  color: #888;
  font-style: italic;
}

/* Styles សម្រាប់ Cart Items ក្នុង Modal */
.cart-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px dashed #f1f1f1;
}

.item-info h4 {
  font-size: 1em;
  color: #333;
  font-weight: 600;
}

.item-info p {
  font-size: 0.9em;
  color: #777;
}

.item-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.qty-btn {
  background-color: #f0f0f0;
  border: 1px solid #ccc;
  padding: 4px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-weight: bold;
  transition: background-color 0.2s;
}

.qty-btn:hover {
  background-color: #ddd;
}

.remove-btn {
  color: #e70050;
  cursor: pointer;
  font-size: 1.1em;
  margin-left: 5px;
  transition: color 0.2s, transform 0.2s;
}

.remove-btn:hover {
  color: #b70040;
  transform: scale(1.1);
}

/* Styles សម្រាប់ Cart Summary និង Checkout Button */
.cart-summary {
  padding: 15px;
  border-top: 1px solid #eee;
  background: #fff;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.summary-row.total {
  font-weight: 700;
  font-size: 1.1em;
  color: #e70050;
  border-top: 2px solid #f1f1f1;
  padding-top: 10px;
  margin-top: 10px;
}

.checkout-btn {
  background-color: #e70050;
  color: white;
  border: none;
  padding: 12px;
  width: 100%;
  border-radius: 8px;
  font-size: 1.1em;
  font-weight: 700;
  margin-top: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background-color 0.2s;
}

.checkout-btn:hover {
  background-color: #b70040;
}

/* Image Modal Specific Styles */
#image-modal-overlay {
  align-items: center;
}

#image-modal-overlay .cart-modal-content {
  max-height: 95vh;
  max-width: 90%;
  padding: 0;
  border-radius: 10px;
  animation: fadeIn 0.3s ease-out;
}

#image-modal-overlay .image-display {
  width: 100%;
  height: auto;
  max-height: 70vh;
  object-fit: contain;
  border-radius: 10px;
}

#image-modal-overlay .modal-image-caption {
  padding: 15px;
  text-align: center;
  font-size: 1.1em;
  color: #333;
  font-weight: 600;
}

/* Size Selector Modal Styles (NEW) */
#size-modal-overlay {
  align-items: center;
}

#size-modal-overlay .cart-modal-content {
  max-width: 350px;
  max-height: fit-content;
  padding: 0;
  border-radius: 10px;
  animation: fadeIn 0.3s ease-out;
}

#size-modal-overlay .size-options {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 20px 0;
  padding: 0 15px;
  flex-wrap: wrap;
}

.size-option {
  min-width: 45px;
  height: 45px;
  padding: 5px 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  border: 2px solid #ccc;
  border-radius: 8px;
  font-weight: bold;
  cursor: pointer;
  color: #555;
  font-size: 0.9em;
}

/* ស្បែកជើងប្រើរង្វង់មូល */
.size-option.shoe-size {
  border-radius: 50%;
  width: 45px;
  height: 45px;
  min-width: 45px;
  font-size: 0.85em;
}

.size-option:hover {
  background-color: #f0f0f0;
}

.size-option.selected {
  border-color: #e70050;
  background-color: #e70050;
  color: white;
  box-shadow: 0 0 10px rgba(231, 0, 80, 0.5);
}

#size-modal-overlay .confirm-size-btn {
  margin: 0 15px 15px 15px;
  background-color: #e70050;
}

/* Custom Success Modal Overrides for centering */
#success-modal-overlay {
  align-items: center; /* Center vertically on desktop/mobile */
}

#success-modal-overlay .cart-modal-content {
  animation: fadeIn 0.3s ease-out;
  max-width: 450px; /* Width limit for confirmation */
  border-radius: 10px;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Login Modal Specific */
#account-content-area {
  padding: 20px;
}

/* ------------------ TOAST NOTIFICATION STYLES ------------------ */
#toast-notification {
  position: fixed;
  /* 🔥 IMPROVEMENT: Slightly higher from the bottom nav */
  bottom: 85px;
  left: 50%;
  transform: translateX(-50%);
  background-color: #333;
  color: white;
  padding: 12px 20px;
  border-radius: 8px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 5000;
  max-width: 90%;
  text-align: center;
  font-size: 0.9em;
}

#toast-notification.toast-show {
  opacity: 1;
  transform: translateX(-50%) translateY(-10px);
}

.toast-success {
  background-color: #28a745;
}

.toast-error {
  background-color: #dc3545;
}
/* --------------------------------------------------------------- */

/* Responsive Desktop/Tablet */
@media (min-width: 768px) {
  .product-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    padding: 25px;
    max-width: 1000px;
    margin: 0 auto;
  }

  .product-card img {
    height: 250px;
  }

  .bottom-nav {
    display: none;
  }

  body {
    padding-bottom: 0;
  }

  /* Desktop specific styles */
  .top-header {
    max-width: 1000px;
    margin: 0 auto;
    padding: 15px 0;
    box-shadow: none;
  }

  .search-bar,
  .category-filter {
    max-width: 1000px;
    margin: 0 auto;
    padding-left: 0;
    padding-right: 0;
  }

  .category-filter {
    margin-bottom: 10px;
    box-shadow: none;
    background-color: transparent;
  }

  .category-item {
    background-color: #ffffff;
  }

  /* Modal Desktop Fixes */
  .cart-modal-overlay {
    align-items: center; /* Align middle for desktop */
  }

  .cart-modal-content {
    max-width: 500px;
    max-height: 90vh;
    border-radius: 10px;
  }

  #toast-notification {
    bottom: 20px; /* Adjust for no bottom nav */
  }
}
