/**
 * RTJ Advanced Assembly Builder - Frontend Styles
 * 
 * @version 2.5.7 - Final Modal Fix
 * ✅ Modal Header همیشه در دسترس
 * ✅ Modal Body اسکرول می‌کنه (min-height: 0)
 * ✅ Overlay تداخل نداره
 * ✅ همه چیز کامل!
 */

/* ==================== Variables ==================== */
:root {
  --rtj-primary: #0073aa;
  --rtj-primary-hover: #005a87;
  --rtj-secondary: #00a0d2;
  --rtj-success: #46b450;
  --rtj-warning: #ffb900;
  --rtj-danger: #dc3232;
  --rtj-gray-light: #f1f1f1;
  --rtj-gray: #ddd;
  --rtj-gray-dark: #666;
  --rtj-text: #333;
  --rtj-shadow: 0 2px 8px rgba(0,0,0,0.1);
  --rtj-border-radius: 8px;
  --rtj-transition: all 0.3s ease;
}

/* ==================== Base Styles ==================== */
.rtj-assembly-builder-wrapper {
  font-family: 'Segoe UI', sans-serif, Geneva, Vazir, sans-serif;
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  direction: rtl;
  text-align: right;
}

/* ==================== Builder Container ==================== */
.rtj-builder-container {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 30px;
  background: #fff;
  border-radius: var(--rtj-border-radius);
  box-shadow: var(--rtj-shadow);
  overflow: hidden;
}

/* ==================== Main Builder Area ==================== */
.rtj-builder-main {
  padding: 30px;
  border-left: 1px solid var(--rtj-gray);
}

/* ✅ هشدار سازگاری */
.rtj-compatibility-warning {
  background: #fff3cd;
  border: 2px solid #ffc107;
  border-radius: var(--rtj-border-radius);
  padding: 15px 20px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideDown 0.3s ease;
}

.rtj-compatibility-warning strong {
  color: #856404;
  font-size: 14px;
}

.rtj-compatibility-warning span {
  color: #856404;
  font-size: 13px;
  flex: 1;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==================== Tabs ==================== */
.rtj-tabs-header {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 2px solid var(--rtj-gray-light);
}

.rtj-tab-btn {
  background: var(--rtj-gray-light);
  border: 2px solid transparent;
  padding: 12px 20px;
  border-radius: var(--rtj-border-radius);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--rtj-gray-dark);
  transition: var(--rtj-transition);
  min-width: 120px;
  text-align: center;
}

.rtj-tab-btn:hover {
  background: var(--rtj-primary);
  color: #fff;
  transform: translateY(-2px);
}

.rtj-tab-btn.active {
  background: var(--rtj-primary);
  color: #fff;
  border-color: var(--rtj-primary-hover);
  box-shadow: 0 4px 12px rgba(0,115,170,0.3);
}

/* Tab Content */
.rtj-tab-content {
  display: none;
  animation: fadeIn 0.3s ease;
}

.rtj-tab-content.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==================== Role Row ==================== */
.rtj-role-row {
  background: #fff;
  border: 2px solid var(--rtj-gray-light);
  border-radius: var(--rtj-border-radius);
  margin-bottom: 20px;
  padding: 20px;
  transition: var(--rtj-transition);
}

.rtj-role-row:hover {
  border-color: var(--rtj-primary);
  box-shadow: 0 4px 12px rgba(0,115,170,0.15);
  transform: translateY(-2px);
}

.rtj-role-row.has-selection {
  border-color: var(--rtj-success);
  background: rgba(70, 180, 80, 0.02);
}

.rtj-role-row.has-warning {
  border-color: var(--rtj-warning);
  background: rgba(255, 185, 0, 0.05);
}

/* ✅ هدر نقش - برای Responsive */
.rtj-role-header-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 15px;
  margin-bottom: 15px;
}

.rtj-role-info {
  flex: 1;
}

.rtj-role-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--rtj-text);
  margin: 0;
}

/* Select Button */
.rtj-select-btn {
  background: var(--rtj-primary);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: var(--rtj-border-radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: var(--rtj-transition);
  white-space: nowrap;
  flex-shrink: 0;
}

.rtj-select-btn:hover {
  background: var(--rtj-primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,115,170,0.3);
}

.rtj-select-btn.selected {
  background: var(--rtj-secondary);
}

/* ==================== Selected Products Container ==================== */
.rtj-selected-products-container {
  margin-top: 15px;
}

.rtj-no-selection {
  color: var(--rtj-gray-dark);
  font-style: italic;
  text-align: center;
  display: block;
  padding: 15px;
  background: var(--rtj-gray-light);
  border-radius: var(--rtj-border-radius);
}

/* ✅ محصول تک‌انتخابی */
.rtj-selected-item-single {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 15px;
  background: var(--rtj-gray-light);
  border-radius: var(--rtj-border-radius);
  position: relative;
}

/* ✅ Badge در selected-item */
.rtj-selected-item-single .rtj-default-badge {
  position: absolute;
  top: 5px;
  right: 5px;
  font-size: 9px;
  padding: 3px 6px;
}

.rtj-product-thumb {
  width: 60px;
  height: 60px;
  border-radius: var(--rtj-border-radius);
  object-fit: cover;
  border: 2px solid #fff;
  box-shadow: var(--rtj-shadow);
  flex-shrink: 0;
}

.rtj-product-info-text {
  flex: 1;
  min-width: 0;
}

.rtj-product-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--rtj-text);
  margin-bottom: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rtj-product-price {
  font-size: 13px;
  color: var(--rtj-primary);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.rtj-qty-badge {
  font-size: 11px;
  color: var(--rtj-gray-dark);
  background: rgba(0,0,0,0.05);
  padding: 2px 6px;
  border-radius: 4px;
}

/* ✅ دکمه حذف (تک‌انتخابی) */
.rtj-remove-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid #ef4444;
  background: #fff;
  color: #b91c1c;
  cursor: pointer;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  transition: var(--rtj-transition);
  flex-shrink: 0;
}

.rtj-remove-btn:hover {
  background: #fee2e2;
  transform: scale(1.1);
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}

/* ✅ محصولات چندگانه */
.rtj-selected-multiple {
  background: var(--rtj-gray-light);
  border-radius: var(--rtj-border-radius);
  padding: 15px;
}

.rtj-multi-header {
  font-size: 14px;
  font-weight: 600;
  color: var(--rtj-text);
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(0,0,0,0.1);
}

.rtj-multi-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rtj-multi-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 6px;
  background: #fff;
  transition: var(--rtj-transition);
}

.rtj-multi-item:hover {
  background: rgba(0,115,170,0.02);
  border-color: var(--rtj-primary);
}

.rtj-item-name {
  flex: 1;
  font-size: 13px;
  color: var(--rtj-text);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rtj-item-price {
  font-size: 13px;
  color: var(--rtj-primary);
  font-weight: 600;
  white-space: nowrap;
}

/* ✅ دکمه حذف (چندگانه) */
.rtj-remove-one-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid #ef4444;
  background: #fff;
  color: #b91c1c;
  cursor: pointer;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  transition: var(--rtj-transition);
  flex-shrink: 0;
}

.rtj-remove-one-btn:hover {
  background: #fee2e2;
  transform: scale(1.1);
  box-shadow: 0 2px 6px rgba(239, 68, 68, 0.3);
}

/* ==================== Services Section ==================== */
.rtj-services-section {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.rtj-service-row {
  background: #fff;
  border: 2px solid var(--rtj-gray-light);
  border-radius: var(--rtj-border-radius);
  padding: 20px;
  transition: var(--rtj-transition);
}

.rtj-service-row:hover {
  border-color: var(--rtj-primary);
  box-shadow: 0 4px 12px rgba(0,115,170,0.15);
}

.rtj-service-label {
  display: flex;
  align-items: center; /* ✅ تغییر: flex-start → center */
  gap: 15px;
  cursor: pointer;
}

.rtj-service-checkbox {
  width: 20px;
  height: 20px;
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 0; /* ✅ تغییر: 2px → 0 */
  vertical-align: middle; /* ✅ اضافه شد */
}

.rtj-service-content {
  flex: 1;
}

.rtj-service-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--rtj-text);
  margin-bottom: 5px;
}

.rtj-service-desc {
  font-size: 13px;
  color: var(--rtj-gray-dark);
  margin-bottom: 8px;
}

/* ✅ اضافه شد: استایل‌های تخفیف */
.rtj-service-price-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.rtj-service-original-price {
  font-size: 14px;
  color: #999;
  text-decoration: line-through;
  font-weight: 500;
}

.rtj-service-discount-badge {
  background: #d63638;
  color: #fff;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}

.rtj-service-final-price {
  font-size: 15px;
  font-weight: 700;
  color: var(--rtj-primary);
}


/* ==================== Sidebar ==================== */
.rtj-builder-sidebar {
  background: var(--rtj-gray-light);
  padding: 30px;
}

/* Summary Section */
.rtj-summary-section {
  margin-bottom: 25px;
}

.rtj-summary-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--rtj-text);
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--rtj-gray);
}

.rtj-summary-box {
  background: #fff;
  border-radius: var(--rtj-border-radius);
  padding: 20px;
  box-shadow: var(--rtj-shadow);
}

.rtj-summary-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--rtj-gray-light);
}

.rtj-summary-item:last-child {
  border-bottom: none;
}

.rtj-summary-name {
  font-size: 13px;
  color: var(--rtj-gray-dark);
  font-weight: 500;
  text-align: right !important;  /* ✅ راست‌چین */
  flex: 1;
}

.rtj-summary-price {
  font-size: 14px;
  font-weight: 700;
  color: var(--rtj-primary);
  text-align: left !important;  /* ✅ چپ‌چین */
  white-space: nowrap;
  margin-left: 10px;
}

/* Price Section */
.rtj-price-section {
  margin-bottom: 20px;
}

.rtj-price-box {
  background: linear-gradient(135deg, var(--rtj-primary) 0%, var(--rtj-primary-hover) 100%);
  color: #fff;
  border-radius: var(--rtj-border-radius);
  padding: 25px;
  text-align: center !important;
  box-shadow: 0 4px 15px rgba(0,115,170,0.3);
}

.rtj-price-label {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 10px;
  opacity: 0.9;
  text-align: center !important;
}

.rtj-price-amount {
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 5px;
  text-align: center !important;
}

.rtj-currency {
  font-size: 16px;
  font-weight: 600;
  opacity: 0.9;
  text-align: center !important;
  display: block !important;  /* ✅ تبدیل به block */
  width: 100% !important;
}

/* ✅ مطمئن شدن از center بودن ID */
#rtj-total-price {
  text-align: center !important;
  display: block !important;
}

#rtj-mobile-total {
  text-align: center !important;
  display: block !important;
}

/* ✅ همه چیز داخل price-box باید center باشه */
.rtj-price-box * {
  text-align: center !important;
}

.rtj-price-section * {
  text-align: center !important;
}

/* Add to Cart Button */
.rtj-add-to-cart-btn {
  width: 100%;
  background: var(--rtj-success);
  color: #fff;
  border: none;
  padding: 16px 24px;
  border-radius: var(--rtj-border-radius);
  cursor: pointer;
  font-size: 16px;
  font-weight: 700;
  transition: var(--rtj-transition);
  box-shadow: 0 4px 12px rgba(70, 180, 80, 0.3);
}

.rtj-add-to-cart-btn:hover {
  background: #3a9d43;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(70, 180, 80, 0.4);
}

.rtj-add-to-cart-btn:disabled {
  background: var(--rtj-gray);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* ==================== Modal ==================== */
.rtj-modal,
.rtj-product-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 999999 !important; /* ✅ افزایش z-index برای جلوگیری از تداخل */
  display: none;
  isolation: isolate; /* ✅ اضافه شد */
}

.rtj-modal.active,
.rtj-product-modal.active {
  display: flex !important; /* ✅ تغییر: block → flex */
  align-items: center;
  justify-content: center;
}

.rtj-modal-backdrop,
.rtj-modal-overlay {
  position: fixed !important; /* ✅ تغییر: absolute → fixed */
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75) !important; /* ✅ تیره‌تر: 0.7 → 0.75 */
  z-index: 1 !important; /* ✅ نسبت به parent */
  backdrop-filter: blur(3px); /* ✅ اضافه: blur پس‌زمینه */
}

.rtj-modal-content {
  position: fixed; /* ✅ تغییر: absolute → fixed */
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  border-radius: var(--rtj-border-radius);
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  max-width: 900px;
  width: 90%;
  max-height: 90vh;
  overflow: hidden;
  z-index: 1000000 !important;
  display: flex;
  flex-direction: column;
}

.rtj-modal-header {
  background: var(--rtj-primary);
  color: #fff;
  padding: 20px 25px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  position: relative; /* ✅ اضافه شد */
  z-index: 10; /* ✅ اضافه شد - بالاتر از modal body */
}

.rtj-modal-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: #fff; /* ✅ اضافه شد - مطمئن بشیم سفیده */
}

.rtj-modal-close {
  background: none;
  border: none;
  color: #fff !important; /* ✅ !important اضافه شد */
  font-size: 28px;
  cursor: pointer;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: var(--rtj-transition);
  position: relative; /* ✅ اضافه شد */
  z-index: 11; /* ✅ اضافه شد - بالاتر از همه */
}

.rtj-modal-close:hover {
  background: rgba(255,255,255,0.2);
  transform: scale(1.1); /* ✅ اضافه شد - بزرگتر شه */
}

.rtj-modal-body {
  padding: 25px;
  overflow-y: auto;
  flex: 1;
  min-height: 0; /* ✅ مهم: جلوگیری از بزرگ شدن بیش از حد */
  /* ✅ اسکرول بار زیباتر */
  scrollbar-width: thin;
  scrollbar-color: rgba(0,0,0,0.3) rgba(0,0,0,0.1);
}

.rtj-modal-body::-webkit-scrollbar {
  width: 8px;
}

.rtj-modal-body::-webkit-scrollbar-track {
  background: rgba(0,0,0,0.05);
  border-radius: 4px;
}

.rtj-modal-body::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.3);
  border-radius: 4px;
}

.rtj-modal-body::-webkit-scrollbar-thumb:hover {
  background: rgba(0,0,0,0.5);
}

/* ✅ Modal Products List - 4 ستونه دقیق */
.rtj-products-list {
  display: grid;
  grid-template-columns: repeat(4, 1fr); /* ✅ تغییر یافت: دقیقاً 4 ستون */
  gap: 15px; /* ✅ کاهش gap */
  margin-top: 20px;
}

/* ✅ کارت محصول - مربع شکل */
.rtj-modal-product-item {
  background: #fff;
  border: 2px solid var(--rtj-gray-light);
  border-radius: var(--rtj-border-radius);
  padding: 15px;
  cursor: pointer;
  transition: var(--rtj-transition);
  display: flex;
  flex-direction: column;
  gap: 10px;
  aspect-ratio: 1 / 1; /* ✅ اضافه شد: کارت مربع */
  position: relative; /* ✅ برای Badge */
}

/* ✅ Badge محصول پیش‌فرض */
.rtj-default-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--rtj-warning);
  color: #fff;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  z-index: 5;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  white-space: nowrap;
  text-align: center;
  line-height: 1.3;
}

.rtj-modal-product-item:hover {
  border-color: var(--rtj-primary);
  box-shadow: 0 4px 12px rgba(0,115,170,0.2);
  transform: translateY(-2px);
}

.rtj-modal-product-item.selected {
  border-color: var(--rtj-success);
  background: rgba(70, 180, 80, 0.05);
}

/* ✅ تصویر محصول - مربع شکل */
.rtj-modal-product-image {
  width: 100%;
  height: auto; /* ✅ تغییر یافت از 150px */
  aspect-ratio: 1 / 1; /* ✅ اضافه شد: تصویر مربع */
  object-fit: contain; /* ✅ تغییر یافت از cover */
  border-radius: var(--rtj-border-radius);
  background: var(--rtj-gray-light); /* ✅ اضافه شد */
  padding: 10px; /* ✅ اضافه شد */
}

.rtj-modal-product-placeholder {
  width: 100%;
  height: auto; /* ✅ تغییر یافت از 150px */
  aspect-ratio: 1 / 1; /* ✅ اضافه شد */
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--rtj-gray-light);
  border-radius: var(--rtj-border-radius);
}

.rtj-modal-product-content {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.rtj-modal-product-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--rtj-text);
  margin-bottom: 8px;
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.rtj-product-link {
  text-decoration: none;
  font-size: 14px;
}

.rtj-modal-product-price {
  font-size: 15px;
  color: var(--rtj-primary);
  font-weight: 700;
  margin-bottom: 10px;
}

/* Quantity Selector */
.rtj-qty-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  margin-top: auto;
}

.rtj-qty-btn {
  width: 32px;
  height: 32px;
  background: var(--rtj-primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 18px;
  font-weight: 700;
  transition: var(--rtj-transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.rtj-qty-btn:hover {
  background: var(--rtj-primary-hover);
  transform: scale(1.1);
}

.rtj-qty-input {
  width: 50px;
  height: 32px;
  text-align: center;
  border: 2px solid var(--rtj-gray);
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
}

/* ==================== Responsive Styles ==================== */

/* تبلت (768px - 1024px) */
@media (max-width: 1024px) {
  .rtj-builder-container {
    grid-template-columns: 1fr;
  }
  
  .rtj-builder-main {
    border-left: none;
    border-bottom: 1px solid var(--rtj-gray);
  }
  
  .rtj-modal-content {
    max-width: 600px;
  }
  
  /* ✅ تبلت: 3 ستون */
  .rtj-products-list {
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
  }
  
  /* ✅ کارت‌ها مربع بمانند */
  .rtj-modal-product-item {
    aspect-ratio: 1 / 1;
  }
  
  .rtj-modal-product-image,
  .rtj-modal-product-placeholder {
    aspect-ratio: 1 / 1;
  }
}

/* موبایل (< 768px) */
@media (max-width: 768px) {
  .rtj-assembly-builder-wrapper {
    padding: 15px;
  }
  
  .rtj-builder-main,
  .rtj-builder-sidebar {
    padding: 20px;
  }
  
  /* ✅ تب‌ها */
  .rtj-tabs-header {
    gap: 8px;
  }
  
  .rtj-tab-btn {
    padding: 10px 15px;
    font-size: 13px;
    min-width: auto;
    flex: 1;
  }
  
  /* ✅ هدر نقش - چیدمان موبایل */
  .rtj-role-header-wrapper {
    flex-direction: row;
    align-items: flex-start;
  }
  
  .rtj-role-info {
    flex: 1;
  }
  
  .rtj-role-title {
    font-size: 14px;
  }
  
  .rtj-select-btn {
    padding: 8px 14px;
    font-size: 12px;
  }
  
  /* ✅ محصول تک‌انتخابی - چیدمان موبایل */
  .rtj-selected-item-single {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  
  .rtj-product-thumb {
    width: 50px;
    height: 50px;
  }
  
  .rtj-product-info-text {
    width: 100%;
  }
  
  .rtj-product-name {
    font-size: 13px;
    white-space: normal;
  }
  
  .rtj-product-price {
    font-size: 12px;
    flex-wrap: wrap;
  }
  
  .rtj-remove-btn {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 28px;
    height: 28px;
    font-size: 16px;
  }
  
  /* ✅ محصولات چندگانه */
  .rtj-multi-header {
    font-size: 13px;
  }
  
  .rtj-multi-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    position: relative;
    padding-left: 40px;
  }
  
  .rtj-item-name,
  .rtj-item-price {
    font-size: 12px;
  }
  
  .rtj-remove-one-btn {
    position: absolute;
    top: 8px;
    left: 8px;
  }
  
  /* Summary */
  .rtj-summary-box {
    padding: 15px;
  }
  
  .rtj-summary-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
  }
  
  .rtj-summary-name,
  .rtj-summary-price {
    font-size: 12px;
  }
  
  /* Price Box */
  .rtj-price-amount {
    font-size: 24px;
  }
  
  .rtj-currency {
    font-size: 14px;
  }
  
  /* Modal */
  .rtj-modal-content {
    max-width: 100%;
    max-height: 90vh;
    margin: 0;
  }
  
  .rtj-modal-header {
    padding: 15px 20px;
  }
  
  .rtj-modal-title {
    font-size: 16px;
  }
  
  .rtj-modal-body {
    padding: 15px;
  }
  
  /* ✅ موبایل: 2 ستون مربع */
  .rtj-products-list {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  
  /* ✅ کارت‌ها مربع بمانند */
  .rtj-modal-product-item {
    aspect-ratio: 1 / 1;
    padding: 12px;
  }
  
  .rtj-modal-product-image,
  .rtj-modal-product-placeholder {
    aspect-ratio: 1 / 1;
  }
  
  .rtj-modal-product-name {
    font-size: 12px;
    min-height: 32px;
  }
  
  .rtj-modal-product-price {
    font-size: 12px;
  }
  
  .rtj-qty-selector {
    gap: 6px;
  }
  
  .rtj-qty-btn {
    width: 28px;
    height: 28px;
    font-size: 16px;
  }
  
  .rtj-qty-input {
    width: 40px;
    height: 28px;
    font-size: 12px;
  }
  
  /* Services */
  .rtj-service-row {
    padding: 15px;
  }
  
  .rtj-service-label {
    gap: 12px;
  }
  
  .rtj-service-name {
    font-size: 14px;
  }
  
  .rtj-service-desc {
    font-size: 12px;
  }
  
  .rtj-service-final-price {
    font-size: 14px;
  }
}

/* موبایل کوچک (< 480px) */
@media (max-width: 480px) {
  .rtj-assembly-builder-wrapper {
    padding: 10px;
  }
  
  .rtj-builder-main,
  .rtj-builder-sidebar {
    padding: 15px;
  }
  
  .rtj-role-row {
    padding: 15px;
  }
  
  .rtj-tab-btn {
    font-size: 12px;
    padding: 8px 12px;
  }
  
  .rtj-price-amount {
    font-size: 20px;
  }
  
  .rtj-add-to-cart-btn {
    padding: 14px 20px;
    font-size: 14px;
  }
  
  /* ✅ موبایل کوچک: کارت‌ها مربع بمانند */
  .rtj-modal-product-item {
    aspect-ratio: 1 / 1;
  }
  
  .rtj-modal-product-image,
  .rtj-modal-product-placeholder {
    aspect-ratio: 1 / 1;
  }
}

/* ==================== Utilities ==================== */
.rtj-error {
  background: #fee;
  border: 2px solid var(--rtj-danger);
  color: var(--rtj-danger);
  padding: 15px 20px;
  border-radius: var(--rtj-border-radius);
  text-align: center;
  font-weight: 600;
}

/* RTL Support */
[dir="ltr"] .rtj-assembly-builder-wrapper {
  direction: ltr;
  text-align: left;
}

[dir="ltr"] .rtj-builder-main {
  border-left: none;
  border-right: 1px solid var(--rtj-gray);
}
/* ==================== Modal Actions Top (v2.4.9) ==================== */
.rtj-modal-actions-top {
  background: linear-gradient(135deg, #e7f3ff 0%, #f0f6fc 100%);
  border: 2px solid #b3d9ff;
  border-radius: var(--rtj-border-radius);
  padding: 15px 20px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  animation: slideDown 0.3s ease;
}

.rtj-modal-counter {
  flex: 1;
  font-size: 15px;
  color: #135e96;
  font-weight: 500;
}

.rtj-modal-counter strong {
  font-size: 24px;
  font-weight: 700;
  color: #2271b1;
  margin-left: 5px;
}

.rtj-modal-buttons {
  display: flex;
  gap: 10px;
}

.rtj-btn {
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.rtj-btn-confirm {
  background: var(--rtj-success);
  color: #fff;
}

.rtj-btn-confirm:hover {
  background: #3fa047;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(70, 180, 80, 0.3);
}

.rtj-btn-clear {
  background: #f0f0f0;
  color: #333;
  border: 1px solid #ddd;
}

.rtj-btn-clear:hover {
  background: #e0e0e0;
  border-color: #ccc;
}

/* ==================== Selected Badge (v2.4.9) ==================== */
.rtj-modal-product-item {
  position: relative;
}

.rtj-selected-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  background: var(--rtj-success);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: bold;
  box-shadow: 0 2px 8px rgba(70, 180, 80, 0.4);
  animation: scaleIn 0.2s ease;
  z-index: 10;
}

/* Filter Info Message */
.rtj-filter-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  margin: 10px 0;
  background: #f0f7ff;
  border: 1px solid #b3d9ff;
  border-radius: 8px;
  color: #0066cc;
  font-size: 13px;
  font-weight: 500;
}

.rtj-filter-info svg {
  flex-shrink: 0;
}

/* ==================== Animations (v2.4.9) ==================== */
@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.5);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ==================== Body Modal Open (v2.4.9) ==================== */
body.rtj-modal-open {
  overflow: hidden !important;
}

/* ==================== Responsive Updates (v2.4.9) ==================== */
@media (max-width: 768px) {
  .rtj-modal-actions-top {
    flex-direction: column;
    align-items: stretch;
  }
  
  .rtj-modal-buttons {
    width: 100%;
  }
  
  .rtj-btn {
    flex: 1;
  }
}

/* ==================== Accordion for Roles (v2.5.0) ==================== */
.rtj-role-accordion {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  margin-bottom: 10px;
  transition: all 0.3s ease;
}

.rtj-role-accordion:hover {
  border-color: #c0c0c0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

/* Accordion Header (یک خط فشرده) */
.rtj-accordion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 15px;
  background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
  border-radius: 6px;
}

.rtj-accordion-toggle {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  cursor: pointer;
  text-align: right;
  font-size: 15px;
  font-weight: 600;
  color: #333;
  padding: 0;
  transition: all 0.3s ease;
}

.rtj-accordion-toggle:hover {
  color: var(--rtj-primary);
}

.rtj-accordion-icon {
  display: inline-block;
  font-size: 18px;
  font-weight: 600;
  color: #666;
  transition: all 0.3s ease;
  min-width: 18px;
  text-align: center;
}

.rtj-accordion-icon::before {
  content: '+';
}

.rtj-role-accordion.open .rtj-accordion-icon::before {
  content: '−'; /* استفاده از minus sign Unicode */
}

.rtj-accordion-title {
  font-weight: 600;
  color: #2c3e50;
  white-space: nowrap;
}

.rtj-accordion-summary {
  flex: 1;
  color: #7f8c8d;
  font-size: 14px;
  font-weight: 400;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rtj-accordion-summary.has-selection {
  color: var(--rtj-primary);
  font-weight: 600;
}

/* دکمه انتخاب فشرده */
.rtj-btn-compact {
  padding: 8px 16px;
  font-size: 13px;
  white-space: nowrap;
}

/* Accordion Body */
.rtj-accordion-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s ease, padding 0.4s ease;
  padding: 0 15px;
}

.rtj-role-accordion.open .rtj-accordion-body {
  max-height: 1000px;
  padding: 15px;
  border-top: 1px solid #e9ecef;
}

/* ==================== Sticky Sidebar (v2.5.0) ==================== */
@media (min-width: 992px) {
  .rtj-builder-container {
    display: grid;
    grid-template-columns: 1fr 350px;
    gap: 30px;
    align-items: start;
  }
  
  .rtj-builder-main {
    order: 1;
  }
  
  .rtj-builder-sidebar {
    order: 2;
    position: sticky;
    top: 100px;
    align-self: flex-start;
  }
  
  /* مخفی کردن Mobile Toggle در دسکتاپ */
  .rtj-summary-mobile-toggle {
    display: none;
  }
  
  .rtj-sidebar-content {
    display: block !important;
  }
}

/* ==================== Mobile Summary Toggle (v2.5.0) ==================== */
@media (max-width: 991px) {
  .rtj-builder-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
  }
  
  .rtj-builder-sidebar {
    order: -1; /* بالای همه */
    position: sticky;
    top: 0;
    z-index: 100;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    border-radius: 0 0 8px 8px;
  }
  
  .rtj-summary-mobile-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 20px;
    background: linear-gradient(135deg, #2271b1 0%, #135e96 100%);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    transition: all 0.3s ease;
  }
  
  .rtj-summary-mobile-toggle:active {
    background: #135e96;
  }
  
  .rtj-summary-mobile-icon {
    font-size: 12px;
    transition: transform 0.3s ease;
  }
  
  .rtj-builder-sidebar.open .rtj-summary-mobile-icon {
    transform: rotate(180deg);
  }
  
  .rtj-sidebar-content {
    display: none;
    padding: 15px;
    animation: slideDown 0.3s ease;
  }
  
  .rtj-builder-sidebar.open .rtj-sidebar-content {
    display: block;
  }
  
  .rtj-builder-main {
    order: 1;
  }
}

/* ==================== Compact Selected Products (v2.5.0) ==================== */
.rtj-selected-products-container {
  min-height: auto;
}

.rtj-selected-products-container .rtj-no-selection {
  display: block;
  padding: 10px;
  text-align: center;
  color: #999;
  font-size: 13px;
  font-style: italic;
}

/* ==================== Responsive Adjustments (v2.5.0) ==================== */
@media (max-width: 768px) {
  .rtj-accordion-header {
    flex-wrap: wrap;
    padding: 10px 12px;
  }
  
  .rtj-accordion-toggle {
    font-size: 14px;
  }
  
  .rtj-accordion-summary {
    font-size: 13px;
  }
  
  .rtj-btn-compact {
    padding: 6px 12px;
    font-size: 12px;
  }
  
  .rtj-builder-sidebar {
    top: 60px; /* برای موبایل */
  }
}

@media (max-width: 480px) {
  .rtj-accordion-toggle {
    font-size: 13px;
    gap: 8px;
  }
  
  .rtj-accordion-title {
    font-size: 13px;
  }
  
  .rtj-accordion-summary {
    font-size: 12px;
  }
  
  .rtj-summary-mobile-toggle {
    padding: 12px 15px;
    font-size: 14px;
  }
}

/* ==================== Modal Responsive Fix (v2.5.1) ==================== */
@media (max-width: 768px) {
  .rtj-modal-content {
    width: 95%;
    max-height: 95vh;
    top: 2.5vh;
    left: 50%;
    transform: translateX(-50%);
  }
  
  .rtj-modal-header {
    padding: 15px 20px;
  }
  
  .rtj-modal-title {
    font-size: 16px;
  }
  
  .rtj-modal-body {
    padding: 15px;
  }
  
  .rtj-products-list {
    grid-template-columns: repeat(2, 1fr); /* موبایل: 2 ستون */
    gap: 12px;
  }
}

@media (max-width: 480px) {
  .rtj-products-list {
    grid-template-columns: 1fr; /* موبایل کوچک: 1 ستون */
    gap: 10px;
  }
  
  .rtj-modal-product-item {
    aspect-ratio: auto; /* حذف مربع شدن */
  }
}
/* ================================
   LOADING MODAL - v3.0.0
   ================================ */
.rtj-loading-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.rtj-loading-modal.active {
    opacity: 1;
    visibility: visible;
}

.rtj-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
}

.rtj-loading-content {
    position: relative;
    background: #fff;
    border-radius: 16px;
    padding: 40px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    max-width: 400px;
    width: 90%;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.rtj-loading-modal.active .rtj-loading-content {
    transform: scale(1);
}

/* Spinner */
.rtj-loading-spinner {
    margin-bottom: 20px;
}

.rtj-spinner {
    width: 60px;
    height: 60px;
    margin: 0 auto;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #2271b1;
    border-radius: 50%;
    animation: rtj-spin 1s linear infinite;
}

@keyframes rtj-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Loading Message */
.rtj-loading-message h3 {
    margin: 0 0 10px 0;
    font-size: 20px;
    font-weight: 600;
    color: #1d2327;
}

.rtj-loading-message p {
    margin: 0;
    font-size: 14px;
    color: #757575;
}

/* Success & Error Icons */
.rtj-loading-icon {
    margin-bottom: 20px;
    display: flex;
    justify-content: center;
}

.rtj-loading-icon svg {
    animation: rtj-icon-appear 0.5s ease;
}

@keyframes rtj-icon-appear {
    0% {
        opacity: 0;
        transform: scale(0.5);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

.rtj-loading-icon.success svg .rtj-check-circle {
    stroke-dasharray: 220;
    stroke-dashoffset: 220;
    animation: rtj-draw-circle 0.6s ease forwards;
}

.rtj-loading-icon.success svg .rtj-check-mark {
    stroke-dasharray: 50;
    stroke-dashoffset: 50;
    animation: rtj-draw-check 0.4s 0.6s ease forwards;
}

@keyframes rtj-draw-circle {
    to {
        stroke-dashoffset: 0;
    }
}

@keyframes rtj-draw-check {
    to {
        stroke-dashoffset: 0;
    }
}

/* Responsive */
@media (max-width: 480px) {
    .rtj-loading-content {
        padding: 30px 20px;
    }
    
    .rtj-loading-message h3 {
        font-size: 18px;
    }
    
    .rtj-loading-message p {
        font-size: 13px;
    }
    
    .rtj-spinner {
        width: 50px;
        height: 50px;
    }
    
    .rtj-loading-icon svg {
        width: 60px;
        height: 60px;
    }
}

/* ================================
   TOAST NOTIFICATIONS
   ================================ */
.rtj-toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #fff;
    border-radius: 8px;
    padding: 15px 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 999998;
    min-width: 300px;
    max-width: 500px;
    opacity: 0;
    transform: translateX(400px);
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.rtj-toast.active {
    opacity: 1;
    transform: translateX(0);
}

.rtj-toast-icon {
    font-size: 24px;
    line-height: 1;
}

.rtj-toast-message {
    flex: 1;
    font-size: 14px;
    line-height: 1.5;
    color: #1d2327;
}

/* Toast Types */
.rtj-toast-success {
    border-left: 4px solid #46b450;
}

.rtj-toast-warning {
    border-left: 4px solid #ffb900;
}

.rtj-toast-error {
    border-left: 4px solid #dc3545;
}

.rtj-toast-info {
    border-left: 4px solid #2271b1;
}

/* ================================
   CLOSE ACCORDION BUTTON
   ================================ */
.rtj-close-accordion {
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 5px 12px;
    font-size: 13px;
    color: #666;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: all 0.2s ease;
}

.rtj-close-accordion:hover {
    background: #e0e0e0;
    border-color: #ccc;
    color: #333;
}

.rtj-close-accordion .dashicons {
    font-size: 16px;
    width: 16px;
    height: 16px;
}

/* Responsive Toast */
@media (max-width: 480px) {
    .rtj-toast {
        right: 10px;
        left: 10px;
        min-width: auto;
        transform: translateY(-100px);
    }
    
    .rtj-toast.active {
        transform: translateY(0);
    }
}

/* ================================
   IMPROVED CLOSE ACCORDION BUTTON
   ================================ */
.rtj-close-accordion {
    background: linear-gradient(135deg, #46b450 0%, #3fa047 100%);
    border: none;
    border-radius: 6px;
    padding: 6px 14px;
    font-size: 13px;
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(70, 180, 80, 0.2);
    font-weight: 600;
}

.rtj-close-accordion:hover {
    background: linear-gradient(135deg, #3fa047 0%, #358a3c 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(70, 180, 80, 0.3);
}

.rtj-close-accordion .rtj-icon {
    font-size: 12px;
    line-height: 1;
}

/* Highlight Animation */
@keyframes rtj-highlight-pulse {
    0%, 100% {
        background: transparent;
    }
    50% {
        background: #e7f3ff;
    }
}

.rtj-role-highlight {
    animation: rtj-highlight-pulse 1.5s ease-in-out;
}