/* الأساس العام */
:root { color-scheme: light; }
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Noto Sans", system-ui, -apple-system, "Segoe UI", "Tajawal", "Cairo", sans-serif;
  background: #fff;
  color: #111;
}

/* رأس التطبيق */
.app-header { padding: 16px; border-bottom: 1px solid #eee; }
.app-header h1 { margin: 0 0 6px; font-size: 20px; font-weight: 700; }
.app-header .sub { margin: 0; color: #555; font-size: 13px; }

/* واجهة الإدخال RTL */
.form-view { padding: 16px; }
.bon-form { max-width: 820px; margin: 0 auto; }
.grid {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 10px 14px;
  align-items: center;
}
.grid label { justify-self: end; color: #222; font-weight: 700; }
.grid input[type="text"],
.grid input[type="number"],
.grid input[type="tel"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
}
.checkbox-row { grid-column: 1 / span 2; display: flex; gap: 8px; align-items: center; font-weight: 700; }
.radio-row { display: flex; gap: 8px; align-items: center; font-weight: 700; }
.amount-options { grid-column: 1 / span 2; display: flex; gap: 16px; flex-wrap: wrap; }

.hidden { display: none; }

.weights-block { grid-column: 1 / span 2; }
.weights-header { display: flex; justify-content: space-between; align-items: baseline; }
.weights-header small { color: #666; }
.weights {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 8px 12px;
  margin-top: 10px;
}
.weights label { justify-self: end; font-weight: 700; }

/* أزرار */
.actions { display: flex; gap: 10px; margin-top: 18px; }
.btn {
  appearance: none;
  border: 1px solid #ddd;
  background: #fff;
  color: #111;
  padding: 10px 14px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 2px 6px rgba(0,0,0,0.08); }
.btn.primary { border-color: #111; background: #111; color: #fff; }
.btn.danger { border-color: #c33; color: #c33; }
.preview-toolbar { display: flex; gap: 10px; padding: 12px 16px; border-bottom: 1px solid #eee; }

/* المعاينة */
.preview-view { padding-bottom: 24px; }
.pages-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  padding: 16px;
}
.page-preview {
  border: 1px solid #eee;
  border-radius: 10px;
  overflow: hidden;
  background: #fafafa;
}
.page-preview .page {
  transform: scale(0.6);
  transform-origin: top left;
  width: var(--page-w, 10cm);
  height: var(--page-h, 15cm);
}

/* صفحة الطباعة */
.page {
  width: var(--page-w, 10cm);
  height: var(--page-h, 15cm);
  padding: 0.8cm;
  background: #fff;
  border: 1px solid #0000; /* لا يظهر في الطباعة */
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  /* النصوص محاذاة لليسار أثناء الطباعة */
  text-align: left;
  direction: ltr;
}
.page .title {
  font-family: "Tajawal", "Cairo", sans-serif;
  font-weight: 700;
  font-size: 20px;
  margin-bottom: 6px;
  text-align: center;
}
.page .bon-number {
  font-family: "Tajawal", "Cairo", sans-serif;
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 10px;
  text-align: center;
}
.page .logo {
  height: 72px;
  margin: 0 0 6px auto;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.qr { height: 56px; }
.brand-center { flex: 1; text-align: center; font-weight: 700; }
.row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin: 4px 0;
  padding-bottom: 6px;
  border-bottom: 1px dashed #ccc;
}
.row .label {
  font-weight: 700;
  color: #111;
  text-align: right;
}
.row .value {
  text-align: left;
  max-width: 60%;
  color: #000;
}
.footer {
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #333;
  border-top: 1px dashed #ccc;
  padding-top: 6px;
}

/* الجذر الخاص بالطباعة فقط */
.print-root { display: none; }

/* استجابة */
@media (max-width: 640px) {
  .grid { grid-template-columns: 1fr; }
  .grid label { justify-self: start; }
  .checkbox-row, .amount-options { flex-direction: column; align-items: flex-start; }
  .weights { grid-template-columns: 1fr; }
}

/* إعدادات الطباعة الدقيقة */
@media print {
  /* إخفاء كل عناصر الواجهة */
  .app-header,
  .form-view,
  .preview-view { display: none !important; }

  /* إظهار صفحات الطباعة فقط */
  .print-root { 
    display: flex !important; 
    flex-direction: column; 
    align-items: center; 
    justify-content: center; 
    min-height: 100vh;
  }

  /* حجم الورقة 10x15 سم عمودي */
  @page {
    size: auto;
    margin: 0;
  }
  html, body { height: 100%; }
  .page {
    page-break-after: always;
    margin: auto;
    padding: 0.8cm;
    text-align: left;
    direction: ltr;
    font-family: "Tajawal", "Cairo", sans-serif;
  }
  .page:last-child { page-break-after: auto; }
  .page .logo { height: 144px; }
}