/* ====== Global Reset ====== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background: #f5f5f5;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  margin: 0;
  padding: 15px;
  color: #333;
  line-height: 1.5;
  min-height: 100vh;
  width: 100%;
  overflow-x: hidden;
}

/* ====== Controls ====== */
.controls {
  max-width: 100%;
  background: #fff;
  margin: 0 auto 15px;
  padding: 15px;
  border: 2px solid #2c3e50;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.controls h2 {
  margin-top: 0;
  margin-bottom: 15px;
  color: #2c3e50;
  border-bottom: 2px solid #3498db;
  padding-bottom: 8px;
  font-size: 18px;
}

.controls label {
  display: block;
  margin-bottom: 12px;
  font-weight: 600;
  font-size: 14px;
}

.controls input[type="text"],
.controls input[type="range"] {
  width: 100%;
  padding: 8px 10px;
  margin-top: 5px;
  box-sizing: border-box;
  border: 1px solid #bdc3c7;
  border-radius: 5px;
  font-size: 14px;
  font-family: inherit;
}

.controls input[type="range"] {
  padding: 0;
  height: 6px;
  border-radius: 3px;
  background: #ecf0f1;
  outline: none;
  -webkit-appearance: none;
}

.controls input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  background: #3498db;
  border-radius: 50%;
  cursor: pointer;
}

.controls input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: #3498db;
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

/* ====== Font Controls ====== */
.font-controls {
  display: flex;
  gap: 15px;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.font-controls label {
  flex: 1;
  min-width: 180px;
  display: flex;
  flex-direction: column;
  font-size: 13px;
}

/* ====== Page Controls ====== */
.page-controls {
  margin-top: 20px;
  padding: 15px;
  border: 2px solid #34495e;
  border-radius: 8px;
  background: #f8f9fa;
}

.page-controls h3 {
  margin-top: 0;
  margin-bottom: 12px;
  color: #2c3e50;
  font-size: 16px;
}

.page-buttons-row,
.page-navigation-row,
.download-buttons-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.page-buttons-row button,
.page-navigation-row button,
.download-buttons-row button {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: all 0.3s ease;
  min-width: 140px;
  font-family: inherit;
  text-align: center;
}

.page-buttons-row button:hover,
.page-navigation-row button:hover,
.download-buttons-row button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

/* Button Colors */
.btn-success {
  background: #27ae60;
  color: white;
}

.btn-info {
  background: #3498db;
  color: white;
}

.btn-danger {
  background: #e74c3c;
  color: white;
}

.btn-warning {
  background: #f39c12;
  color: white;
}

.btn-purple {
  background: #9b59b6;
  color: white;
}

.btn-teal {
  background: #1abc9c;
  color: white;
}

.btn-deep-purple {
  background: #8e44ad;
  color: white;
}

.page-counter {
  flex: 1;
  text-align: center;
  font-size: 16px;
  font-weight: bold;
  padding: 8px;
  background: white;
  border-radius: 6px;
  border: 1px solid #bdc3c7;
  min-width: 120px;
}

.page-label {
  color: #7f8c8d;
  font-weight: normal;
  font-size: 14px;
}

/* ====== Page Navigation ====== */
#pageNavigation {
  max-width: 100%;
  margin: 0 auto 15px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  padding: 8px;
  background: white;
  border-radius: 8px;
  border: 1px solid #ddd;
}

.page-nav-btn {
  padding: 8px 12px;
  background: #ecf0f1;
  border: 2px solid #bdc3c7;
  border-radius: 6px;
  cursor: pointer;
  min-width: 40px;
  text-align: center;
  font-weight: 600;
  transition: all 0.2s ease;
  font-size: 13px;
}

.page-nav-btn:hover {
  background: #d5dbdb;
  border-color: #95a5a6;
}

.page-nav-btn.active {
  background: #3498db;
  color: white;
  border-color: #2980b9;
  transform: scale(1.05);
}

/* ====== Flyer Container ====== */
#flyerContainer {
  max-width: 100%;
  margin: 0 auto;
  position: relative;
  background: white;
  border-radius: 10px;
  padding: 10px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.15);
  border: 1px solid #ddd;
  min-height: 400px;
  width: 100%;
  overflow: visible;
}

/* ====== Flyer (A4) ====== */
.flyer {
  width: 100%;
  max-width: 100%;
  aspect-ratio: 210 / 297;
  padding: 15px;
  box-sizing: border-box;
  border: 1px solid #2c3e50;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
  height: auto;
  min-height: 500px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

/* ====== Header ====== */
.flyer-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 2px solid #2c3e50;
  flex-wrap: wrap;
}

.flyer-header .header-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 200px;
}

.flyer-header h1 {
  margin: 0;
  outline: none;
  cursor: text;
  line-height: 1.2;
  color: #2c3e50;
  font-family: 'Arial Black', Gadget, sans-serif;
  font-size: 28px;
  word-break: break-word;
}

.flyer-header h1:focus {
  background: #fffde7;
  border-radius: 4px;
  outline: 2px solid #3498db;
}

/* ====== Offers Date ====== */
.offers-date {
  font-size: 16px;
  color: #7f8c8d;
  margin: 0;
  outline: none;
  cursor: text;
  font-weight: 500;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  line-height: 1.4;
}

.offers-date:focus {
  background: #f0f8ff;
  border-radius: 4px;
  outline: 2px solid #3498db;
}

/* ====== Logo ====== */
.logo {
  width: auto;
  height: auto;
  object-fit: contain;
  cursor: pointer;
  transition: all 0.3s ease;
  padding: 3px;
  min-width: 80px;
  max-width: 280px;
}

.logo:hover {
  border-color: #3498db;
  transform: scale(1.02);
}

/* ====== Products Grid ====== */
.products {
  flex: 1;
  display: grid;
  gap: 10px;
  margin: 10px 0;
  overflow: hidden;
  min-height: 300px;
  grid-auto-rows: 1fr;
}

/* ====== Product Card ====== */
.product {
  border: 1px solid #34495e;
  overflow: hidden;
  display: flex;
  border-radius: 6px;
  transition: all 0.3s ease;
  background: white;
  min-height: 150px;
  position: relative;
}

.product:hover {
  border-color: #3498db;
  box-shadow: 0 2px 4px rgba(52, 152, 219, 0.2);
}

.product-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 6px;
  box-sizing: border-box;
  height: 100%;
  gap: 5px;
  width: 100%;
}

/* ====== Product Info ====== */
.product-info {
  flex-shrink: 0;
  text-align: center;
  overflow: visible;
  padding: 3px;
  min-height: 50px;
  width: 100%;
}

/* ====== إصلاح مشكلة النص ====== */
.product-name {
  line-height: 1.3;
  outline: none;
  cursor: text;
  
  max-height: none !important;
  overflow: visible !important;
  display: block !important;
  -webkit-line-clamp: unset !important;
  -webkit-box-orient: unset !important;
  
  min-height: 1.3em;
  height: auto;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: normal;
  word-break: break-word;
  
  font-weight: 600;
  color: #2c3e50;
  padding: 4px;
  border-radius: 4px;
  margin: 2px 0;
  /* font-size يتم التحكم فيه بواسطة JavaScript */
}

.product-name:focus {
  background: #e8f4fc;
  outline: 2px solid #3498db;
  min-height: 2.6em;
}

/* ====== Price ====== */
.price {
  font-weight: bold;
  margin-top: 4px;
  direction: ltr;
  unicode-bidi: plaintext;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: text;
  color: #27ae60;
  padding: 3px;
  border-radius: 4px;
  font-family: 'Arial', 'Times New Roman', Times, serif;
  /* font-size يتم التحكم فيه بواسطة JavaScript */
  display: block;
}

.price:focus {
  background: #e8f6f3;
  outline: 2px solid #27ae60;
}

/* ====== Product Image ====== */
.product-image {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #f8f9fa;
  border-radius: 4px;
  border: 1px solid #ecf0f1;
  min-height: 100px;
  height: 150px;
  width: 100%;
}

.product-image img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  cursor: pointer;
  transition: all 0.3s ease;
  padding: 3px;
}

.product-image img:hover {
  transform: scale(1.05);
}

/* ====== Footer ====== */
.flyer-footer {
  border-top: 2px solid #2c3e50;
  padding-top: 8px;
  font-size: 13px;
  color: #7f8c8d;
  margin-top: 8px;
  min-height: 35px;
  width: 100%;
}

.flyer-footer p {
  margin: 3px 0;
  padding: 3px;
  border-radius: 4px;
  cursor: text;
  line-height: 1.4;
}

.flyer-footer p:focus {
  background: #f8f9fa;
  outline: 2px solid #bdc3c7;
}

/* ====== تحسينات للعديد من المنتجات ====== */
.flyer.many-products .products {
    gap: 6px !important;
    min-height: 550px !important;
}

.flyer.many-products .product {
    min-height: 110px !important;
}

.flyer.many-products .product-image {
    height: 80px !important;
    min-height: 80px !important;
}

.flyer.many-products .product-name {
    line-height: 1.2 !important;
    min-height: 35px !important;
}

.flyer.many-products .market-name {
    font-size: 26px !important;
}

/* ====== تحسينات للنص متعدد الأسطر ====== */
.product-name.multi-line {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.4;
  padding: 6px 4px;
}

/* ====== Smart Sizing Indicators ====== */
.smart-size-info {
  background: #e8f4fc;
  border: 1px solid #3498db;
  border-radius: 6px;
  padding: 8px 12px;
  margin: 10px 0;
  font-size: 13px;
  color: #2c3e50;
}

.smart-size-info strong {
  color: #3498db;
}

/* ====== Notification Styles ====== */
.notification {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 12px 20px;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 10000;
  font-weight: 600;
  animation: slideIn 0.3s ease;
  color: white;
  font-size: 14px;
  max-width: 300px;
}

.notification.success {
  background: #27ae60;
}

.notification.error {
  background: #e74c3c;
}

.notification.info {
  background: #3498db;
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes slideOut {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(100%); opacity: 0; }
}

/* ====== Mobile Responsive ====== */
@media (max-width: 768px) {
  body {
    padding: 10px;
  }
  
  .controls,
  #flyerContainer,
  #pageNavigation {
    max-width: 100%;
    padding: 10px;
  }
  
  .controls {
    margin-bottom: 12px;
  }
  
  .font-controls {
    flex-direction: column;
    gap: 12px;
  }
  
  .font-controls label {
    min-width: 100%;
    font-size: 13px;
  }
  
  .page-buttons-row,
  .page-navigation-row,
  .download-buttons-row {
    flex-direction: column;
    gap: 8px;
  }
  
  .page-buttons-row button,
  .page-navigation-row button,
  .download-buttons-row button {
    width: 100%;
    min-width: 100%;
    font-size: 12px !important;
    padding: 10px !important;
  }
  
  .page-counter {
    order: -1;
    width: 100%;
    margin-bottom: 8px;
    font-size: 14px;
    min-width: 100%;
  }
  
  #flyerContainer {
    padding: 8px;
    min-height: 350px;
  }
  
  .flyer {
    aspect-ratio: auto;
    height: auto;
    min-height: 450px;
    padding: 12px;
    max-width: 100%;
  }
  
  .products {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px;
    min-height: 250px;
  }
  
  .flyer-header {
    flex-direction: column;
    text-align: center;
    gap: 8px;
    align-items: center;
    padding-bottom: 10px;
    margin-bottom: 10px;
  }
  
  .flyer-header .header-content {
    text-align: center;
    width: 100%;
  }
  
  .logo { 
    max-width: 250px !important; 
    margin: 0 auto !important; 
  }
  
  .market-name {
    font-size: 22px !important;
    text-align: center !important;
    width: 100% !important;
  }
  
  .offers-date {
    font-size: 14px !important;
    text-align: center !important;
  }
  
  .product-inner {
    padding: 5px !important;
    gap: 4px;
  }
  
  .product {
    min-height: 140px;
  }
  
  .product-name {
    line-height: 1.2 !important;
    min-height: 30px !important;
    padding: 3px;
  }
  
  .price {
    padding: 2px;
  }
  
  .product-image {
    height: 100px !important;
    min-height: 100px !important;
  }
  
  .flyer-footer {
    font-size: 11px !important;
    min-height: 30px !important;
    padding-top: 6px;
  }
  
  .page-nav-btn {
    padding: 6px 10px;
    min-width: 35px;
    font-size: 12px;
  }
}

@media (max-width: 480px) {
  .flyer {
    min-height: 400px;
    padding: 10px;
  }
  
  .products {
    grid-template-columns: 1fr !important;
    gap: 6px;
  }
  
  .product {
    min-height: 130px;
  }
  
  .product-image {
    height: 90px !important;
    min-height: 90px !important;
  }
  
  .market-name {
    font-size: 20px !important;
  }
  
  .offers-date {
    font-size: 13px !important;
  }
  
  .product-name {
    min-height: 25px !important;
  }
  
  .controls h2 {
    font-size: 16px;
  }
  
  .page-controls h3 {
    font-size: 15px;
  }
  
  .page-buttons-row button,
  .page-navigation-row button,
  .download-buttons-row button {
    font-size: 11px !important;
    padding: 8px !important;
  }
}

@media (max-width: 360px) {
  .flyer {
    min-height: 380px;
    padding: 8px;
  }
  
  .product-image {
    height: 80px !important;
    min-height: 80px !important;
  }
  
  .market-name {
    font-size: 18px !important;
  }
}

/* ====== Desktop Styles ====== */
@media (min-width: 769px) {
  #flyerContainer {
    max-width: 794px;
  }
  
  .flyer {
    width: 794px;
    height: 1123px;
    min-height: 1123px;
  }
  
  .products {
    min-height: 600px;
  }
  
  .product-image {
    height: 200px;
  }
}

/* ===============================
   SEO CONTENT SECTION
================================ */
.seo-content {
  padding: 40px 15px;
  background: #f5f6f7;
}

.seo-box {
  max-width: 900px;
  margin: 0 auto;
  background: #ffffff;
  border: 1px solid #e0e0e0;
  border-radius: 14px;
  padding: 30px 35px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.05);
}

.seo-box h2 {
  margin-top: 0;
  margin-bottom: 15px;
  font-size: 26px;
  color: #2c3e50;
  line-height: 1.3;
}

.seo-box p {
  font-size: 16px;
  color: #555;
  line-height: 1.7;
  margin-bottom: 12px;
}

.seo-box strong {
  color: #000;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .seo-box {
    padding: 22px;
  }

  .seo-box h2 {
    font-size: 22px;
  }

  .seo-box p {
    font-size: 15px;
  }
}

@media (max-width: 480px) {
  .seo-box h2 {
    font-size: 20px;
  }

  .seo-box p {
    font-size: 14px;
  }
}
