/* ══════════════════════════════════════════════════════════
   رفع المقاسات — قائمة المركّبين (2026-11-02، measurements.js)
   مصمَّمة للجوال أولاً: أزرار كبيرة للمس، حقول أرقام بلوحة أرقام، شريط إرسال ثابت.
   ══════════════════════════════════════════════════════════ */

/* ── الشارات ── */
.ms-pill {
  display: inline-block; font-size: 11.5px; font-weight: 700; padding: 2px 10px;
  border-radius: 999px; white-space: nowrap;
}
.ms-pill-none  { background: var(--panel-2); color: var(--muted); }
.ms-pill-draft { background: var(--warn-soft); color: var(--warn); }
.ms-pill-done  { background: var(--accent-soft); color: var(--accent-strong); }
[data-theme="dark"] .ms-pill-done { color: #86efac; }
.ms-warn-text { color: var(--warn); font-weight: 700; }
.ms-muted { color: var(--muted); font-size: 13px; }

.row-measure-done-badge {
  display: inline-block; font-size: 11px; margin-inline-start: 6px; padding: 1px 6px;
  border-radius: 999px; background: var(--info-soft); color: var(--info);
  vertical-align: middle; white-space: nowrap;
}

/* ── قائمة زيارات القياس ── */
.ms-jobs { display: flex; flex-direction: column; gap: 10px; max-width: 760px; }
.ms-group-label { font-size: 12.5px; font-weight: 700; color: var(--muted); margin-top: 6px; }
.ms-job {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 12px 14px; box-shadow: var(--shadow-sm);
}
.ms-job-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-2); }
.ms-job-name { font-weight: 700; font-size: 16px; margin-top: 4px; }
.ms-job-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.ms-job-sum { font-size: 13px; margin-top: 6px; color: var(--text-2); }
.ms-job-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; align-items: center; }
.ms-job-open { flex: 1 1 160px; min-height: 42px; }
.ms-job-link { text-decoration: none; min-height: 42px; display: inline-flex; align-items: center; }

.myjob-measure-btn { width: 100%; margin-top: 10px; min-height: 40px; }

/* ── داخل لوحة الطلب ── */
.order-measure-section {
  margin-top: 14px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--panel-2);
}
.om-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.om-summary { font-size: 13px; color: var(--text-2); margin: 6px 0 10px; min-height: 1em; }
.om-open-btn { width: 100%; }
.om-open-btn:disabled { opacity: .55; cursor: default; }

/* ── الشاشة الكاملة ── */
body.ms-open { overflow: hidden; }
.ms-screen {
  position: fixed; inset: 0; z-index: 2050; background: var(--bg);
  display: flex; flex-direction: column;
}
.ms-screen.hidden { display: none; }
.ms-top {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  background: var(--panel); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.ms-top .icon-btn { width: 40px; height: 40px; flex-shrink: 0; }
.ms-top-text { flex: 1; min-width: 0; }
.ms-top-text h3 { font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 0; }
.ms-sub { font-size: 12px; color: var(--muted); }
.ms-save-state { font-size: 11.5px; font-weight: 600; white-space: nowrap; color: var(--muted); }
.ms-save-state.saved { color: var(--accent); }
.ms-save-state.offline, .ms-save-state.error { color: var(--warn); }

.ms-body {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 12px; display: flex; flex-direction: column; gap: 12px;
  width: 100%; max-width: 760px; margin: 0 auto;
}
.ms-foot {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--panel); border-top: 1px solid var(--border); flex-shrink: 0;
}
.ms-foot-summary { flex: 1; font-size: 13px; color: var(--text-2); min-width: 0; }
.ms-foot .btn-primary { min-height: 46px; padding: 0 20px; font-size: 15px; }
.ms-foot .btn-primary:disabled { opacity: .6; }

.ms-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 12px; display: flex; flex-direction: column; gap: 6px;
}
.ms-info-row { display: flex; gap: 10px; font-size: 13.5px; }
.ms-info-row span { color: var(--muted); min-width: 64px; flex-shrink: 0; }
.ms-info-row b { font-weight: 600; overflow-wrap: anywhere; }
.ms-info-note { font-size: 13px; background: var(--warn-soft); color: var(--text); border-radius: var(--radius-sm); padding: 8px 10px; }
.ms-info-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.ms-info-actions a { text-decoration: none; min-height: 40px; display: inline-flex; align-items: center; }
.ms-banner {
  background: var(--info-soft); color: var(--info); border-radius: var(--radius-md);
  padding: 10px 12px; font-size: 13px; font-weight: 600;
}

.ms-field-label { font-size: 12.5px; font-weight: 700; color: var(--text-2); margin-top: 6px; }
.ms-input {
  width: 100%; padding: 10px 12px; border: 1.5px solid var(--border-2); border-radius: var(--radius-md);
  background: var(--panel); color: var(--text); font-size: 16px; font-family: inherit; /* 16px يمنع تكبير iOS */
}
.ms-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.ms-input:disabled { background: var(--panel-2); color: var(--text-2); }
textarea.ms-input { resize: vertical; }

.ms-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ms-chip {
  min-height: 38px; padding: 6px 12px; border-radius: 999px; font-size: 13.5px; font-weight: 600;
  border: 1.5px solid var(--border-2); background: var(--panel); color: var(--text-2);
  cursor: pointer; font-family: inherit; transition: all var(--tr);
}
.ms-chip.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-strong); }
[data-theme="dark"] .ms-chip.on { color: #86efac; }
.ms-chip:disabled { cursor: default; opacity: .8; }
.ms-chip:disabled:not(.on) { opacity: .45; }

/* ── الغرف ── */
.ms-rooms { display: flex; flex-direction: column; gap: 10px; }
.ms-room { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.ms-room-head {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 12px;
  background: none; border: none; cursor: pointer; font-family: inherit; color: var(--text); text-align: start;
  min-height: 52px;
}
.ms-room.open .ms-room-head { border-bottom: 1px solid var(--border); background: var(--panel-2); }
.ms-room-num {
  width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.ms-room-name { font-weight: 700; font-size: 15px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-room-meta { font-size: 12px; color: var(--muted); white-space: nowrap; }
.ms-room-caret { color: var(--muted); transition: transform var(--tr); }
.ms-room.open .ms-room-caret { transform: rotate(180deg); }
.ms-room-body { display: none; padding: 12px; flex-direction: column; gap: 6px; }
.ms-room.open .ms-room-body { display: flex; }
.ms-row { display: flex; gap: 10px; }
.ms-col { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.ms-room-actions, .ms-win-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.ms-room-actions .ms-add-win { flex: 1; }
.ms-del { color: var(--error); border-color: var(--error-soft); }
.ms-del:hover { color: var(--error); background: var(--error-soft); border-color: var(--error); }

.ms-add-btn {
  width: 100%; min-height: 48px; border: 2px dashed var(--border-2); border-radius: var(--radius-md);
  background: none; color: var(--accent-strong); font-weight: 700; font-size: 15px; cursor: pointer; font-family: inherit;
}
.ms-add-btn:hover { border-color: var(--accent); background: var(--accent-soft); }
[data-theme="dark"] .ms-add-btn { color: #86efac; }

/* ── النوافذ ── */
.ms-windows { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.ms-win {
  border: 1px solid var(--border); border-inline-start: 4px solid var(--accent);
  border-radius: var(--radius-md); padding: 10px; display: flex; flex-direction: column; gap: 6px;
  background: var(--panel);
}
.ms-win-missing { border-inline-start-color: var(--warn); }
.ms-win-head { display: flex; gap: 8px; align-items: center; }
.ms-win-label { font-weight: 700; flex: 1; min-width: 0; }
.ms-qty { display: flex; align-items: center; border: 1.5px solid var(--border-2); border-radius: var(--radius-md); flex-shrink: 0; }
.ms-qty button {
  width: 38px; height: 42px; border: none; background: none; font-size: 20px; color: var(--text-2);
  cursor: pointer; font-family: inherit;
}
.ms-qty button:disabled { opacity: .4; cursor: default; }
.ms-qty span { min-width: 26px; text-align: center; font-weight: 700; }
.ms-dims { display: flex; align-items: flex-end; gap: 8px; }
.ms-dim { flex: 1; display: flex; flex-direction: column; gap: 4px; position: relative; min-width: 0; }
.ms-dim span { font-size: 12.5px; font-weight: 700; color: var(--text-2); }
.ms-dim .ms-input { font-size: 20px; font-weight: 700; text-align: center; padding-inline-end: 38px; direction: ltr; }
.ms-dim em { position: absolute; inset-inline-end: 12px; bottom: 13px; font-style: normal; font-size: 12px; color: var(--muted); }
.ms-x { font-size: 20px; color: var(--muted); padding-bottom: 12px; }
.ms-switch { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; min-height: 40px; cursor: pointer; }
.ms-switch input { width: 20px; height: 20px; accent-color: var(--accent); }

.ms-photos { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ms-thumb {
  width: 72px; height: 72px; border-radius: var(--radius-sm); overflow: hidden; padding: 0;
  border: 1px solid var(--border); background: var(--panel-2); cursor: pointer;
}
.ms-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ms-photo-add {
  min-height: 72px; padding: 0 12px; border: 1.5px dashed var(--border-2); border-radius: var(--radius-sm);
  background: none; color: var(--text-2); font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.ms-photo-add:hover { border-color: var(--accent); color: var(--accent-strong); }

/* ── عارض الصورة ── */
.ms-lightbox {
  position: fixed; inset: 0; z-index: 2060; background: rgba(0,0,0,.88);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 16px;
}
.ms-lightbox.hidden { display: none; }
.ms-lightbox img { max-width: 100%; max-height: calc(100% - 80px); object-fit: contain; border-radius: var(--radius-sm); }
.ms-lightbox-actions { display: flex; gap: 10px; }
.ms-lightbox-actions .btn-ghost-sm { background: var(--panel); }

/* ── الطباعة ── */
.measure-print { display: none; }
@media print {
  body.ms-printing #print-sheet, body.ms-printing #print-sheet * { visibility: hidden !important; }
  body.ms-printing .measure-print { display: block; position: absolute; top: 0; right: 0; left: 0; }
  body.ms-printing .measure-print, body.ms-printing .measure-print * { visibility: visible; }
  body.ms-printing .ms-screen { position: static; display: none; }
  .measure-print { font-size: 12px; color: #000; }
  .measure-print h2 { font-size: 18px; margin: 0 0 8px; }
  .measure-print h3 { font-size: 14px; margin: 14px 0 6px; }
  .measure-print p { margin: 3px 0; }
  .measure-print table { width: 100%; border-collapse: collapse; }
  .measure-print th, .measure-print td { border: 1px solid #999; padding: 4px 6px; text-align: start; }
  .measure-print th { background: #eee; }
}

@media (min-width: 900px) {
  .ms-screen { background: rgba(15,23,42,.45); padding: 24px; }
  .ms-top, .ms-foot { max-width: 820px; width: 100%; margin: 0 auto; }
  .ms-top { border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .ms-foot { border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
  .ms-body { max-width: 820px; background: var(--bg); }
}

/* التنبيهات فوق شريط الإرسال لا عليه */
body.ms-open .toasts { bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
