/* ============================================================
   FIX-SPACING.CSS — إصلاح شامل لمشاكل التلاصق في الحقول
   يُضاف في نهاية index.html بعد جميع ملفات CSS الأخرى
   ============================================================ */

/* ── 1. إصلاح التعارض: توحيد تعريف .field-group ── */
.field-group {
  margin-bottom: 1rem !important;
  display: flex;
  flex-direction: column;
}

.field-label,
.input-label {
  display: block;
  font-size: .72rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: .45rem !important;
  letter-spacing: .02em;
}

/* ── 2. الحقول النصية — padding وarتفاع مريح ── */
.field-inp,
.form-inp {
  width: 100%;
  box-sizing: border-box;
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .65rem .95rem !important;
  color: var(--text-primary);
  font-size: .84rem;
  font-family: inherit;
  transition: var(--transition-fast);
  display: block;
  line-height: 1.5;
}

.field-inp:focus,
.form-inp:focus {
  border-color: rgba(200,169,110,.5);
  box-shadow: 0 0 0 3px rgba(200,169,110,.1);
  outline: none;
}

.field-inp::placeholder,
.form-inp::placeholder {
  color: var(--text-muted);
  opacity: .7;
}

textarea.field-inp,
textarea.form-inp {
  resize: vertical;
  min-height: 72px;
  line-height: 1.7;
}

select.field-inp {
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%239CA3AF'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left .75rem center;
  padding-left: 2rem;
}

/* ── 3. داخل المودالات — مسافات أكبر ── */
.modal-box .field-group,
.modal-overlay .field-group,
.s14-modal-box .field-group,
.s13-modal-box .field-group,
.inv-movement-box .field-group,
.wa-template-box .field-group {
  margin-bottom: 1rem !important;
}

/* ── 4. حقول s14-modal بدون field-group wrapper ── */
/* Sprint 14 modal: العناصر المباشرة في الـ grid */
.s14-modal-box .s14-2col > *,
.s14-modal-box > * + * {
  margin-top: 0;
}

/* أي field-inp داخل s14-modal-box بدون wrapper يحصل على margin */
.s14-modal-box .field-inp,
.s14-modal-box select.field-inp {
  margin-bottom: 0;
}

/* s14-section-label — مسافة أعلى وأسفل */
.s14-section-label {
  font-size: .7rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: .05em;
  text-transform: uppercase;
  margin: 1rem 0 .6rem !important;
  padding-bottom: .35rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

/* ── 5. field-row — مسافات صحيحة ── */
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
  margin-bottom: 0; /* المسافة تأتي من field-group الأب */
}

@media(max-width: 540px) {
  .field-row {
    grid-template-columns: 1fr;
  }
}

/* ── 6. panel-card — padding داخلي كافٍ ── */
.panel-card {
  background: linear-gradient(135deg, var(--bg-card), var(--bg-card2));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.4rem !important;
  margin-bottom: 2rem !important;
}

.panel-card .field-group:last-child {
  margin-bottom: 0 !important;
}

/* ── 7. tool-screen-wrap — تباعد صحيح ── */
.tool-screen-wrap {
  max-width: 860px;
  margin: 0 auto;
  padding: 1.5rem;
}

.tool-screen-wrap .panel-card + .panel-card {
  margin-top: 0; /* المسافة تأتي من margin-bottom على البطاقة */
}

/* ── 8. ai-tool-wrap ── */
.ai-tool-wrap .panel-card {
  margin-bottom: 1rem;
}

/* ── 9. Sprint 13 — حقول النماذج ── */
.s13-modal-box .field-group {
  margin-bottom: 1rem !important;
}

/* ── 10. inv-movement-body — حقول سجل المخزون ── */
.inv-movement-body {
  padding: 1.25rem 1.5rem;
  box-sizing: border-box;
}

.inv-movement-body .field-group {
  margin-bottom: .9rem !important;
}

.inv-movement-body .field-group:last-child {
  margin-bottom: 0 !important;
}

/* ── 11. student-field في صفحات المراحل ── */
.student-field {
  margin-bottom: 1.1rem;
}

.student-field:last-child {
  margin-bottom: 0;
}

.student-label {
  display: block;
  font-size: .72rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: .45rem;
}

.student-ta {
  width: 100%;
  box-sizing: border-box;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .85rem 1rem;
  color: var(--text-primary);
  font-size: .83rem;
  resize: vertical;
  line-height: 1.75;
  min-height: 85px;
  transition: var(--transition);
  font-family: inherit;
}

.student-ta:focus {
  border-color: rgba(200,169,110,0.4);
  box-shadow: 0 0 0 3px rgba(200,169,110,0.08);
  outline: none;
}

/* ── 12. order-modal — حقول نموذج الطلب ── */
.modal-backdrop .field-group,
.modal-backdrop .field-group + .field-group {
  margin-bottom: 1rem !important;
}

/* ── 13. QA Tool — حقول الفحص ── */
.qa-layout .field-group {
  margin-bottom: .9rem !important;
}

/* ── 14. validate tool — حقول التحقق ── */
.vld-two-col .field-group {
  margin-bottom: .9rem !important;
}

/* ── 15. تأكيد عدم تلاصق label مع input ── */
/* كل label فوق input/select/textarea يحصل على margin-bottom */
.field-group > label + input,
.field-group > label + select,
.field-group > label + textarea,
.field-group > label + div {
  margin-top: 0;
}

/* ── 16. إصلاح field-hint — ظهوره بشكل صحيح ── */
.field-hint {
  font-size: .65rem;
  color: var(--text-muted);
  margin-top: .35rem;
  line-height: 1.4;
}

/* ── 17. إصلاح field-suffix ── */
.field-suffix {
  position: relative;
}

.field-suffix .field-inp {
  padding-left: 2.5rem;
}

.field-suffix-label {
  position: absolute;
  left: .75rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: .75rem;
  color: var(--text-muted);
  pointer-events: none;
}

/* ── 18. modal-form-actions — تباعد من الحقول ── */
.modal-form-actions {
  display: flex;
  gap: .65rem;
  justify-content: flex-end;
  padding-top: 1rem;
  margin-top: .5rem;
  border-top: 1px solid var(--border);
}

/* ── 19. Sprint 14 inline fields (بدون wrapper) ── */
/* الحقول الـ inline في s14-modal-box تحتاج gap */
.s14-modal-box {
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* العنصر الذي يحتوي على field-inp مباشرة */
.s14-modal-box > .field-inp,
.s14-modal-box .s14-2col {
  margin-bottom: .9rem;
}

/* ── 20. light-mode overrides ── */
body.light-mode .field-inp,
body.light-mode .form-inp {
  background: rgba(0,0,0,.04);
  color-scheme: light;
}

body.light-mode .field-inp:focus,
body.light-mode .form-inp:focus {
  background: rgba(0,0,0,.06);
}

body.light-mode select.field-inp option {
  background: #fff;
  color: #0F172A;
}

/* ── 21. إصلاح s14-modal داخلي — مسافات بين الأقسام ── */
.s14-modal-box .s14-modal-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

/* ── 22. spacing بين الـ sections في modal ── */
.s14-modal-box > .field-group,
.s14-modal-box > div > .field-group {
  margin-bottom: 1rem !important;
}

/* ── 23. قسم CRM select في s14 ── */
.s14-modal-box select.field-inp {
  margin-bottom: 1rem;
  display: block;
}

/* ── 24. تحسين عام للـ textarea في جميع الأدوات ── */
.ai-tool-wrap textarea.field-inp,
.tool-screen-wrap textarea.field-inp {
  min-height: 80px;
}

/* ── 25. caption tool field-groups ── */
.caption-layout .field-group {
  margin-bottom: 1rem !important;
}

/* ── 26. CRM Detail fields ── */
.crm-detail-hdr .field-group,
.student-zone .student-field {
  margin-bottom: 1rem;
}

/* ── 27. إصلاح نهائي: أي field-group متتالي لا يُلاصق ── */
.field-group + .field-group {
  margin-top: 0;
}

/* حالة خاصة: field-group بدون margin (مضمّن في grid) */
.field-row > .field-group {
  margin-bottom: 0 !important;
}

.field-row {
  margin-bottom: 1rem;
}

/* ── 28. s8 project modal ── */
.modal-overlay .modal-body .field-group {
  margin-bottom: .95rem !important;
}

.modal-overlay .modal-body .field-group:last-child {
  margin-bottom: 0 !important;
}

/* ── 29. settings-inp spacing ── */
.settings-inp {
  padding: .5rem .85rem;
  line-height: 1.4;
}

/* ── 30. ops-search spacing ── */
.ops-search {
  line-height: 1.4;
  padding: .6rem .85rem;
}
