/* ========================= */
/* ترتيب عرض الأصناف الموحد */
/* ========================= */

.item-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: var(--dm-item-bg);
  border-radius: 16px;
  margin-bottom: 12px;
  position: relative;
  /* Allow normal touch scrolling */
  touch-action: pan-y;
  -webkit-touch-callout: none;
}

/* ==========================================
   الهيدر: الاسم والسعر جنب الصورة
   ========================================== */
.item-header {
  display: flex;
  gap: 12px;
  align-items: center;
  width: 100%;
}

/* العربية: الصورة شمال (يسار الشاشة)، النص يمين */
.item-box[dir="rtl"] .item-header {
  flex-direction: row-reverse;
}

/* الإنجليزية: الصورة شمال، النص يمين */
.item-box[dir="ltr"] .item-header {
  flex-direction: row;
}

/* ==========================================
   صورة الصنف - مربعة ومناسبة للكارد
   ========================================== */
.item-img {
  flex-shrink: 0;
  width: 130px;
  min-width: 130px;
  max-width: 130px;
  height: 130px;
  position: relative;
  background: none !important;
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
  border-radius: 0 !important;
}

.item-img > img,
.item-img > .dm-item-gallery > img {
  width: 130px !important;
  height: 130px !important;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  object-position: center;
  display: block;
  background: #f7f9fc;
  border-radius: 14px !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  border: 3px solid var(--dm-add-bg);
  /* Prevent mobile long-press download menu */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  pointer-events: auto;
}

.item-img > .dm-img-placeholder {
  width: 130px !important;
  height: 130px !important;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 14px !important;
  border: 3px solid var(--dm-add-bg) !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1) !important;
  background: rgba(0, 0, 0, 0.04);
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  pointer-events: auto;
}

.item-img > .dm-img-placeholder > img,
.item-img > .dm-img-placeholder > svg {
  width: 100% !important;
  height: 100% !important;
  object-fit: contain;
  transform: scale(1.3);
  border: none !important;
  box-shadow: none !important;
  background: transparent !important;
}

/* ==========================================
   محتوى الصنف - الاسم والسعر
   ========================================== */
.item-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.item-text {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.item-top {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.item-box[dir="rtl"] .item-top {
  align-items: flex-start;
  text-align: right;
}

.item-box[dir="rtl"] .item-content {
  text-align: right;
}

.item-box[dir="ltr"] .item-top {
  align-items: flex-start;
  text-align: left;
}

/* الاسم */
.item-name {
  color: var(--dm-name);
  font-weight: 800;
  font-size: 18px;
  line-height: 1.3;
}

/* السعر */
.dm-item-price {
  color: var(--dm-price);
  font-weight: bold;
  font-size: 18px;
  white-space: nowrap;
}

.dm-item-price .price-old {
  text-decoration: line-through;
  color: #999;
  margin-inline-start: 8px;
  font-size: 16px;
}

.dm-item-price .price-new {
  color: #e03131;
  font-weight: 800;
  font-size: 22px;
}

.dm-item-price .price-normal {
  color: var(--dm-price-color, var(--dm-price));
  font-size: 22px;
  font-weight: 800;
}

/* Points price (loyalty) */
.dm-item-points-price {
  margin-top: 2px;
  font-size: var(--dm-font-xs, 14px);
  font-weight: 700;
  color: #6b7280;
}

.dm-item-points-price .dm-points-num {
  margin-inline: 4px;
  color: #111827;
}

.dm-item-points-price .dm-points-unit {
  color: #6b7280;
}

/* ==========================================
   الفوتر: الوصف + الزرار (عرض كامل)
   ========================================== */
.item-footer {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px !important;
  padding-top: 10px;
  clear: both;
}

/* لو مفيش وصف، الزر يكون على بعد من الصورة */
.item-footer:not(:has(.item-desc)) {
  margin-top: 16px !important;
}

/* الوصف - عرض كامل */
.item-desc {
  color: var(--dm-desc);
  font-size: 16px;
  line-height: 1.6;
}

/* لو الوصف فاضي، نخفيه */
.item-desc:empty {
  display: none !important;
}

.item-box[dir="rtl"] .item-desc {
  text-align: right;
}

.item-box[dir="ltr"] .item-desc {
  text-align: left;
}

/* زر إضافة للسلة - عرض كامل */
.item-cta {
  width: 100%;
  margin-top: 8px;
}

/* CTA row when Favorites star is present */
.item-cta.dm-cta-with-fav {
  display: flex;
  align-items: center;
  gap: 10px;
}

.item-cta.dm-cta-with-fav .dm-add {
  flex: 1 1 auto;
  width: auto;
  padding: 10px 12px;
  font-size: var(--dm-font-sm, 15px);
  line-height: 1.2;
}

.item-cta.dm-cta-with-fav .dm-fav-btn {
  margin: 0;
  width: 38px;
  height: 38px;
}

.dm-add {
  width: 100%;
  display: block;
  background: var(--dm-add-bg);
  color: var(--dm-add-text);
  border: 0;
  padding: 12px 16px;
  border-radius: 12px;
  font-weight: 700;
  font-size: var(--dm-font-md, 16px);
  cursor: pointer;
  text-align: center;
  transition: filter 0.2s ease;
}

.dm-add:hover {
  filter: brightness(0.95);
}

.dm-add:disabled,
.dm-add.is-preview-only {
  background: #e5e7eb;
  color: #6b7280;
  cursor: default;
  filter: none;
  box-shadow: none;
  pointer-events: none;
}

.dm-add:disabled:hover,
.dm-add.is-preview-only:hover {
  filter: none;
}

/* ==========================================
   البادج فوق الصورة
   ========================================== */
.item-tags {
  display: none;
}

.dm-badge-overimage {
  position: absolute;
  top: 8px;
  left: 8px;
  right: auto;
  background: linear-gradient(135deg, #27ae60, #2ecc71);
  color: #fff;
  font-size: var(--dm-font-xs, 14px);
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 999px;
  z-index: 10;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.9);
}

.item-box[dir="ltr"] .dm-badge-overimage {
  right: 8px;
  left: auto;
}

.badge-new {
  background: linear-gradient(135deg, #27ae60, #2ecc71);
}

.badge-popular {
  background: linear-gradient(135deg, #f39c12, #e67e22);
}

.badge-offer {
  background: linear-gradient(135deg, #e74c3c, #c0392b);
}

/* ==========================================
   Lightbox للصور
   ========================================== */
#image-overlay,
#dm-image-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 4000000 !important;
}

#image-overlay #overlay-img,
#dm-image-overlay #dm-overlay-img {
  max-width: min(92vw, 860px);
  max-height: 92vh;
  width: auto;
  height: auto;
  border-radius: 16px;
  display: block;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
}

/* ==========================================
   موبايل - شاشات صغيرة
   ========================================== */
@media (max-width: 480px) {
  .item-img {
    width: 120px;
    height: 120px;
  }

  .item-img > img,
  .item-img > .dm-item-gallery > img,
  .item-img > .dm-img-placeholder {
    width: 120px !important;
    height: 120px !important;
  }

  .item-name {
    font-size: 16px;
  }

  .dm-item-price {
    font-size: 16px;
  }

  .dm-item-price .price-new,
  .dm-item-price .price-normal {
    font-size: 20px;
  }
}

/* =========================
 * Item Details Modal Styles
 * ========================= */
#dm-item-modal .dm-item-dialog {
  width: min(520px, 96vw);
  max-height: calc(92dvh - 24px);
}

#dm-item-modal .dm-cart-body {
  padding: 18px 22px;
}

#dm-item-modal[dir="rtl"] .dm-cart-header,
#dm-item-modal[dir="rtl"] .dm-cart-body {
  direction: rtl;
  text-align: right;
}

#dm-item-modal[dir="ltr"] .dm-cart-header,
#dm-item-modal[dir="ltr"] .dm-cart-body {
  direction: ltr;
  text-align: left;
}

#dm-item-modal[dir="rtl"] .dm-cart-header {
  justify-content: space-between;
}

#dm-item-modal .dm-item-modal-title {
  color: var(--dm-name);
  font-weight: 700;
  font-size: 20px;
  line-height: 1.3;
  flex-grow: 1;
}

#dm-item-modal .dm-item-modal-body {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 0 20px;
  align-items: center;
}

#dm-item-modal[dir="rtl"] .dm-item-modal-body {
  grid-template-columns: 1fr 150px;
}

#dm-item-modal .dm-item-modal-img {
  grid-row: 1 / 5;
}

#dm-item-modal[dir="ltr"] .dm-item-modal-img {
  grid-column: 1 / 2;
}

#dm-item-modal[dir="rtl"] .dm-item-modal-img {
  grid-column: 2 / 3;
}

#dm-item-modal .dm-item-modal-img img {
  width: 150px;
  height: 150px;
  object-fit: cover;
  border-radius: 16px;
}

#dm-item-modal .dm-item-modal-desc {
  grid-column: 2 / 3;
  color: var(--dm-desc);
  font-size: 16px;
  line-height: 1.4;
  margin: 0;
}

#dm-item-modal .dm-item-modal-price {
  grid-column: 2 / 3;
  font-size: 18px;
  font-weight: bold;
  color: var(--dm-price);
  margin: 8px 0;
}

#dm-item-modal .dm-item-modal-actions {
  grid-column: 2 / 3;
  display: block;
  margin-top: 8px;
}

#dm-item-modal[dir="rtl"] .dm-item-modal-desc,
#dm-item-modal[dir="rtl"] .dm-item-modal-price,
#dm-item-modal[dir="rtl"] .dm-item-modal-actions {
  grid-column: 1 / 2;
}

#dm-item-modal .dm-item-modal-actions button {
  width: 100% !important;
  display: block !important;
  padding: 12px 16px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
}
