/* =====================================================================
   نظام معمل الألمنيوم — واجهة الشاشة (عربي RTL)
   الأقسام: 1 المتغيرات · 2 الأساس · 3 التخطيط · 4 المكونات · 5 الجداول
            6 الصفحات · 7 محرر الطلبية · 8 أنواع القطع · 9 الهاتف · 10 الطباعة
   الرسومات في drawing.css، والمستندات المطبوعة في print.css
   ===================================================================== */

/* ---------------------------------------------------------------- 1. المتغيرات */
:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --ink: #1d2733;
  --muted: #6b7785;
  --line: #e1e6ec;
  --line-strong: #cbd3dc;
  --primary: #0f6cbd;
  --primary-dark: #0b5394;
  --primary-soft: #e6f0fa;
  --success: #1e8e4f;
  --success-soft: #e5f5ec;
  --warn: #b26a00;
  --warn-soft: #fff3df;
  --danger: #c4312b;
  --danger-soft: #fdeceb;
  --violet: #6a4cc2;
  --violet-soft: #efeafb;
  --door: #8a5a2b;
  --door-soft: #f5ece2;
  --sidebar-bg: #17212e;
  --radius: 8px;
  --sidebar: 230px;
}

/* ---------------------------------------------------------------- 2. الأساس */
* { box-sizing: border-box; }
html { font-size: 15px; scroll-padding-bottom: 110px; scroll-padding-top: 70px; }
body {
  margin: 0; background: var(--bg); color: var(--ink); line-height: 1.5;
  font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", Arial, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
details summary { cursor: pointer; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num, .ltr { direction: ltr; unicode-bidi: isolate; }
div.num { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.late { color: var(--danger); font-weight: 600; }
.warn-txt { color: var(--warn); }
.note { white-space: pre-line; color: #45505c; }
.section { margin-top: 20px; }

/* ---------------------------------------------------------------- 3. التخطيط */
.sidebar {
  position: fixed; inset-block: 0; inset-inline-start: 0; width: var(--sidebar); z-index: 20;
  background: var(--sidebar-bg); color: #cfd8e3; display: flex; flex-direction: column; padding: 14px 12px; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 1.05rem; padding: 4px 6px 14px; }
.brand:hover { text-decoration: none; }
.brand img { width: 38px; height: 38px; object-fit: contain; background: #fff; border-radius: 6px; }
.sidebar-new { margin-bottom: 12px; }
.sidebar nav { display: flex; flex-direction: column; gap: 1px; flex: 1; }
.sidebar nav a { color: #cfd8e3; padding: 7px 10px; border-radius: 6px; }
.sidebar nav a:hover { background: #223043; text-decoration: none; color: #fff; }
.sidebar nav a.on { background: var(--primary); color: #fff; }
.nav-group { font-size: .78rem; color: #7f8ea0; margin: 12px 10px 3px; }
.me { border-top: 1px solid #2a384a; padding-top: 10px; margin-top: 10px; display: flex; justify-content: space-between; align-items: center; font-size: .85rem; gap: 6px; }
.me .link { color: #9fb3c8; }
.main { margin-inline-start: var(--sidebar); padding: 20px 26px 60px; min-height: 100vh; }
.topbar, .sidebar-backdrop { display: none; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(100%); transition: transform .2s; width: min(280px, 82vw); }
  .sidebar.open { transform: none; box-shadow: 0 0 30px rgba(0,0,0,.35); }
  .sidebar-backdrop { position: fixed; inset: 0; background: rgba(10,18,28,.45); z-index: 15; }
  body.menu-open .sidebar-backdrop { display: block; }
  body.menu-open { overflow: hidden; }
  .main { margin: 0; padding: 14px 16px 60px; }
  .topbar {
    display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 12;
    background: var(--sidebar-bg); color: #fff; padding: 8px 12px; box-shadow: 0 2px 8px rgba(0,0,0,.15);
  }
  .menu-toggle { background: #223043; color: #fff; border: 0; border-radius: 6px; font-size: 1.25rem; line-height: 1; padding: 6px 11px; cursor: pointer; }
  .topbar-brand { color: #fff; font-weight: 700; flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .topbar-brand:hover { text-decoration: none; }
  .topbar-new { background: var(--primary); color: #fff; border-radius: 6px; padding: 6px 12px; font-weight: 600; white-space: nowrap; }
  .topbar-new:hover { text-decoration: none; background: var(--primary-dark); }
  .sidebar .sidebar-new { display: none; }
}

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.card-title { padding: 14px 16px 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); }

/* ---------------------------------------------------------------- 4. المكونات */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
  border: 1px solid var(--line-strong); background: #fff; color: var(--ink);
  padding: 7px 14px; border-radius: 6px; font: inherit; cursor: pointer;
}
.btn:hover { background: #f4f6f9; text-decoration: none; }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn-pvc { background: #0f7a68; border-color: #0f7a68; color: #fff; font-weight: 600; }
.btn-pvc:hover { background: #0b6556; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: #17733f; }
.btn-danger { color: var(--danger); border-color: #efc2c0; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-lg { padding: 10px 22px; font-size: 1.05rem; }
.btn-sm { padding: 3px 10px; font-size: .85rem; }
.btn-block { width: 100%; }
.link { background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; font: inherit; }
.link:hover { text-decoration: underline; }
.link.danger { color: var(--danger); }
form.inline { display: inline; }

input, select, textarea {
  font: inherit; color: inherit; border: 1px solid var(--line-strong); border-radius: 6px;
  padding: 6px 9px; background: #fff; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc5ec; outline-offset: -1px; border-color: var(--primary); }
input[type=checkbox] { width: auto; }
input[type=number] { direction: ltr; text-align: right; }
input.invalid { border-color: var(--danger); outline-color: #f2b8b5; background: var(--danger-soft); }
label { font-weight: 600; font-size: .9rem; display: block; margin-bottom: 4px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(230px, 100%), 1fr)); gap: 14px 18px; }
.form-grid .wide, .meta-grid .wide { grid-column: 1 / -1; }
.field .help { color: var(--muted); font-size: .8rem; margin-top: 3px; }
.error, .field .error { color: var(--danger); font-size: .85rem; margin-top: 3px; }
.field.check label { display: flex; align-items: center; gap: 8px; }
.req { color: var(--danger); }
.form-actions { display: flex; gap: 10px; margin-top: 18px; align-items: center; flex-wrap: wrap; }
.filters { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; margin-bottom: 14px; }
.filters input, .filters select { width: auto; }
.filters input[type=search] { min-width: min(240px, 100%); }
.inline-field, .inline-check { display: flex; align-items: center; gap: 6px; margin: 0; font-size: .85rem; font-weight: 400; }
.logo-preview { max-height: 60px; display: block; margin-bottom: 6px; }

.hint { background: var(--primary-soft); color: #164a78; padding: 8px 12px; border-radius: 6px; margin-bottom: 14px; font-size: .9rem; }
.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; border: 1px solid; }
.alert-success { background: var(--success-soft); border-color: #b9e3c9; color: #155f37; }
.alert-info { background: var(--primary-soft); border-color: #b9d4ee; color: #164a78; }
.alert-error { background: var(--danger-soft); border-color: #f2c1be; color: #8d1f1a; }
.alert-warning { background: var(--warn-soft); border-color: #f2d6a4; color: #7a4a00; }

.badge { display: inline-block; padding: 1px 9px; border-radius: 20px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.st-quote { background: #eef0f3; color: #5b6673; }
.st-confirmed { background: var(--primary-soft); color: var(--primary-dark); }
.st-production { background: var(--warn-soft); color: var(--warn); }
.st-ready { background: var(--violet-soft); color: var(--violet); }
.st-installed { background: var(--success-soft); color: var(--success); }
.st-cancelled { background: #f1f1f1; color: #888; text-decoration: line-through; }
.st-inactive { background: #f1f1f1; color: #888; }
.st-short { background: var(--danger-soft); color: var(--danger); }
.mv-purchase, .mv-opening { background: var(--success-soft); color: var(--success); }
.mv-adjust { background: var(--warn-soft); color: var(--warn); }
.mv-production { background: var(--primary-soft); color: var(--primary-dark); }
.data tr.short td { background: #fff6f5; }
.nav-badge { background: var(--danger); color: #fff; border-radius: 10px; padding: 0 7px; font-size: .75rem; margin-inline-start: 4px; }
.cat-window { background: var(--primary-soft); color: var(--primary-dark); }
.cat-door { background: var(--door-soft); color: var(--door); }
.sec-alu { background: #eef1f4; color: #45505c; }
.sec-pvc { background: #e8f6f3; color: #0f6b5c; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs a { border: 1px solid var(--line-strong); background: #fff; border-radius: 20px; padding: 4px 14px; color: var(--ink); font-size: .9rem; }
.tabs a:hover { text-decoration: none; background: #f3f6f9; }
.tabs a.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.tabs a .c { color: var(--muted); font-size: .8rem; margin-inline-start: 4px; }
.tabs a.on .c { color: #cfd8e3; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: .85rem; }
.stat .value { font-size: 1.35rem; font-weight: 700; margin-top: 2px; direction: ltr; text-align: right; }
.stat.danger .value { color: var(--danger); }
.stat a { display: block; color: inherit; }
a.stat { display: block; color: inherit; transition: box-shadow .15s, border-color .15s; }
a.stat:hover { text-decoration: none; border-color: var(--line-strong); box-shadow: 0 3px 12px rgba(20,30,50,.08); }
.stats.kpi { grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); }
.stat .sub { color: var(--muted); font-size: .8rem; margin-top: 4px; }
.stat.good .value { color: var(--success); }

.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px 20px; }
.meta-grid .k { color: var(--muted); font-size: .82rem; }
.meta-grid .v { font-weight: 600; }

.totals-wrap { display: flex; justify-content: flex-end; }
.totals { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; width: min(340px, 100%); }
.totals .row { display: flex; justify-content: space-between; align-items: center; padding: 5px 0; gap: 10px; }
.totals .row label { margin: 0; }
.totals .row input { width: 130px; }
.totals .grand { border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 8px; font-size: 1.25rem; font-weight: 700; }
.totals .v { direction: ltr; }

.modal-back { position: fixed; inset: 0; background: rgba(15,25,40,.45); display: flex; align-items: flex-start; justify-content: center; padding-top: 12vh; z-index: 100; }
.modal { background: #fff; border-radius: 10px; width: min(460px, 92vw); padding: 18px 20px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal .form-grid { grid-template-columns: 1fr; }

.save-bar {
  position: sticky; bottom: 0; z-index: 10; display: flex; gap: 10px; align-items: center; margin-top: 16px; padding: 10px 0;
  background: rgba(243,245,248,.95); backdrop-filter: blur(4px); border-top: 1px solid var(--line);
}
.save-note { margin: 16px 0 0; }
.save-note + .save-bar { margin-top: 6px; }
@media (max-width: 700px) {        /* الهاتف: زرّا الحفظ في سطر واحد بارتفاع صغير */
  .save-bar { padding: 6px 0; gap: 6px; }
  .save-bar .btn { flex: 1 1 0; padding: 9px 6px; font-size: .95rem; }
}
.steps-hint ol { margin: 4px 0 0; padding-inline-start: 22px; }
.steps-hint li { margin: 2px 0; }

/* ---------------------------------------------------------------- 5. الجداول */
table.data { width: 100%; border-collapse: collapse; background: #fff; }
.data th, .data td { padding: 8px 12px; text-align: right; border-bottom: 1px solid var(--line); vertical-align: top; }
.data th { background: #f7f9fb; font-size: .85rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
.data tbody tr:hover { background: #fafcfe; }
.data tr.inactive td { color: #9aa5b1; }
.data tfoot td { font-weight: 700; background: #f7f9fb; }
.data td.amount, .data th.amount { text-align: left; white-space: nowrap; }
.data td.amount { direction: ltr; unicode-bidi: isolate; }
.data td.qty, .data th.qty { text-align: left; white-space: nowrap; }   /* كمية + وحدة: «7 بار» */
.data tr.clickable { cursor: pointer; }
.count-cell { display: flex; align-items: center; gap: 6px; max-width: 200px; }
.count-cell input { direction: ltr; text-align: center; font-weight: 700; font-size: 1.05rem; }
.count-cell input::placeholder { color: #c3cad2; font-weight: 400; }
.count-table td { vertical-align: middle; }
.data .row-actions { white-space: nowrap; text-align: left; }
.table-wrap { overflow-x: auto; }
.empty { text-align: center; color: var(--muted); padding: 30px !important; }

/* ---------------------------------------------------------------- 6. الصفحات */
/* تسجيل الدخول */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--sidebar-bg), var(--primary)); }
.login-card { background: #fff; width: min(380px, 92vw); border-radius: 12px; padding: 28px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-card h1 { text-align: center; margin-bottom: 18px; }
.login-card .field { margin-bottom: 12px; }
.login-card img { display: block; margin: 0 auto 10px; max-height: 70px; }

/* مراحل الطلبية */
.steps-card { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.steps { display: flex; list-style: none; margin: 0; padding: 0; counter-reset: s; flex-wrap: wrap; gap: 4px; }
.steps li { counter-increment: s; padding: 5px 14px 5px 12px; background: #eef1f4; color: var(--muted); font-size: .88rem; border-radius: 20px; }
.steps li::before { content: counter(s) ". "; }
.steps li.done { background: var(--success-soft); color: var(--success); }
.steps li.done::before { content: "✓ "; }
.steps li.now { background: var(--primary); color: #fff; font-weight: 700; }
.steps-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* قطع الطلبية ومخططاتها */
.piece-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); gap: 12px; margin-bottom: 16px; }
.piece-view { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.pv-draw { border-bottom: 1px dashed var(--line); padding-bottom: 6px; margin-bottom: 4px; }
.pv-title { font-size: 1.02rem; }
.survey-box { background: #f7f9fb; border: 1px dashed var(--line-strong); border-radius: 6px; padding: 6px 8px; font-size: .85rem; margin: 4px 0; }
.survey-box .late { font-weight: 600; }
.pv-price { font-weight: 700; font-size: 1.1rem; margin-top: 4px; text-align: left; }
.pay-form { display: grid; grid-template-columns: 1fr 1fr 1.3fr 1.5fr auto; gap: 8px; align-items: end; margin-top: 12px; }
@media (max-width: 1000px) { .pay-form { grid-template-columns: 1fr 1fr; } }

/* ---------------------------------------------------------------- 7. محرر الطلبية */
.order-head { display: grid; grid-template-columns: minmax(min(260px, 100%), 2fr) repeat(auto-fill, minmax(140px, 1fr)); gap: 12px 16px; align-items: end; }
.order-head > *, .customer-field > * { min-width: 0; }
.customer-field { display: flex; gap: 6px; }
.customer-field select { flex: 1; }
.order-foot { display: grid; grid-template-columns: 1fr 340px; gap: 16px; align-items: start; }
.items { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.add-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }

.piece { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); border-inline-start: 4px solid var(--primary); }
.piece[data-cat=door] { border-inline-start-color: var(--door); }
.piece.extra { border-inline-start-color: var(--line-strong); }
.piece-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid #eef1f4; flex-wrap: wrap; }
.piece-head .p-code { width: 80px; font-weight: 700; }
.piece-head .p-type { width: auto; min-width: 200px; font-weight: 600; }
.item-no { font-weight: 700; color: var(--muted); min-width: 22px; }
.piece-total { margin-inline-start: auto; font-weight: 700; font-size: 1.05rem; direction: ltr; }
.item-remove { background: none; border: 0; color: #a0a9b3; font-size: 1.3rem; cursor: pointer; line-height: 1; padding: 0 4px; }
.item-remove:hover { color: var(--danger); }
.piece-body { display: grid; grid-template-columns: 1fr 290px; gap: 6px 16px; padding: 10px 12px; }
.step-f { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px 10px; align-content: start; }
.step-f label, .extra-row label { font-size: .78rem; color: var(--muted); margin-bottom: 2px; }
.step-f .f-loc, .step-f .f-notes { grid-column: span 4; }
.step-f .f-panels { grid-column: span 3; }
.step-f .f-survey { grid-column: 1 / -1; background: #f7f9fb; border: 1px dashed var(--line-strong); border-radius: 6px; padding: 8px; }
.step-f .f-survey-btn { align-self: end; }
.survey-grid { display: grid; grid-template-columns: 60px repeat(3, minmax(0, 1fr)); gap: 6px 8px; align-items: end; }
.survey-grid .sg-label { font-weight: 700; font-size: .85rem; padding-bottom: 6px; }
.survey-grid label { font-size: .75rem; color: var(--muted); margin: 0; }
.survey-grid input { direction: ltr; text-align: center; font-weight: 700; }
.survey-result { margin-top: 8px; }
/* تسجيل القياس للعامل: خانات كبيرة وفيها «سم»، المكان بضغطة، والكشف على صورة الفتحة */
.unit-in { position: relative; display: block; }
.unit-in i { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--muted); font-weight: 600; pointer-events: none; }
.step-f .f-dim .dim-in { width: 100%; font-size: 1.35rem; padding: 8px 10px; padding-left: 2.6em; }
.size-warn { grid-column: 1 / -1; color: var(--warn); font-size: .86rem; line-height: 1.8; }
.size-warn:empty { display: none; }
.loc-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.loc-chips .chip-btn { direction: rtl; padding: 3px 11px; font-size: .82rem; }
.chip-btn.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.sv-title { font-weight: 700; font-size: .88rem; margin-bottom: 8px; }
.sv-pic { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr) minmax(0, 1fr); gap: 10px 8px; align-items: center;
  padding: 12px 8px; border: 12px solid #b9c3cf; border-radius: 3px; background: #e7f1f8; }
.sv-top { grid-column: 2; grid-row: 1; } .sv-right { grid-column: 1; grid-row: 2; } .sv-left { grid-column: 3; grid-row: 2; }
.sv-mid { grid-column: 2; grid-row: 2; display: flex; flex-direction: column; gap: 8px; } .sv-bot { grid-column: 2; grid-row: 3; }
.sv-pic label, .sv-diag label { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .78rem; font-weight: 700; color: var(--ink); margin: 0; }
.sv-pic input, .sv-diag input { width: 100%; max-width: 130px; text-align: center; direction: ltr; font-weight: 700; font-size: 1.1rem; padding: 6px; }
.sv-diag { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: end; margin-top: 8px; font-size: .8rem; color: var(--muted); }
.sv-diag > span { flex-basis: 100%; }
.sv-diag label { flex: 1 1 110px; }
.sv-made { font-size: 1.05rem; font-weight: 700; }
.sv-made b { font-size: 1.4rem; color: var(--primary-dark); direction: ltr; unicode-bidi: isolate; }
.ws-details { border: 1px dashed var(--line-strong); border-radius: 8px; padding: 2px 8px; }
.ws-details > summary { cursor: pointer; font-weight: 700; font-size: .88rem; color: var(--muted); padding: 6px 0; }
.ws-details[open] > summary { margin-bottom: 6px; }
.ws-details > .step { margin-bottom: 8px; }
/* الفردات من التصميم: الأزرار للعرض فقط، والتعديل من محرر التصميم */
.design-lock { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; margin: 4px 0 6px; padding: 6px 10px; border-radius: 8px;
  background: var(--primary-soft); font-size: .86rem; font-weight: 600; color: var(--primary-dark); }
.design-lock .warn-txt { color: var(--warn); }
.f-panels.locked .chips, .f-panels.locked .p-add-panel, .f-panels.locked .p-del-panel, .f-fixed.locked .fx-mode { pointer-events: none; opacity: .6; }
.f-panels.locked .p-add-panel, .f-panels.locked .p-del-panel, .f-panels.locked .sizes-reset, .f-panels.locked label .muted { display: none; }
.toast { position: fixed; bottom: 84px; left: 50%; transform: translateX(-50%); background: var(--success); color: #fff; padding: 10px 18px; border-radius: 10px;
  z-index: 500; box-shadow: 0 8px 24px rgba(0,0,0,.2); font-weight: 600; text-align: center; transition: opacity .6s; max-width: 92vw; }
.toast.out { opacity: 0; }
.dim-in[readonly] { background: #eef5ec; }
.step-f .dim-in { font-weight: 700; font-size: 1.05rem; direction: ltr; text-align: right; }
.piece-draw { background: #fafcfe; border: 1px dashed var(--line); border-radius: 6px; padding: 4px; align-self: start; }
.piece-calc { color: #45505c; }
.p-price.manual { background: #fffdf3; border-color: #e3c77a; }
.panel-editor { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line-strong); border-radius: 6px; padding: 5px 10px; font: inherit; font-size: .88rem; cursor: pointer; background: #fff; min-width: 58px; }
.chip:hover { filter: brightness(.96); }
.chip-S { background: var(--primary-soft); border-color: #9cc5ec; color: var(--primary-dark); }
.chip-F { background: #f1f3f5; color: #45505c; }
.chip-H { background: var(--success-soft); border-color: #a8dcbd; color: #155f37; }
.chip-T { background: var(--warn-soft); border-color: #f2d6a4; color: #7a4a00; }
.chip-TT { background: #f3ecfb; border-color: #d4c1ee; color: #52307c; }
.chip.sel { outline: 2px solid var(--ink); outline-offset: 1px; }
/* لوحة الفردة (النوع ثم الاتجاه) والثوابت فوق/تحت الفردات */
.sash-pick { margin-top: 8px; padding: 8px; background: #f7f9fb; border: 1px dashed var(--line-strong); border-radius: 8px;
             display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.sash-pick .seg button { padding: 5px 12px; }
.step-f .f-fixed { grid-column: 1 / -1; }
.extra-row { display: grid; grid-template-columns: 3fr 90px 150px 2fr; gap: 8px; padding: 10px 12px; }

@media (max-width: 1100px) { .order-foot { grid-template-columns: 1fr; } }
@media (max-width: 1000px) {
  .piece-body { grid-template-columns: 1fr; }
  .piece-draw { grid-row: auto; max-width: 420px; }
}

/* ---------------------------------------------------------------- 8. أنواع القطع وحساب القص */
.type-card { display: grid; grid-template-columns: 160px 1fr auto; gap: 12px; align-items: center; }
.type-head { display: grid; grid-template-columns: 1fr 290px; gap: 16px; }
.vars { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .85rem; margin-top: 6px; }
.vars code { background: #eef1f4; padding: 0 6px; border-radius: 4px; font-weight: 700; direction: ltr; }
.test-bar { align-items: center; }
.test-bar input { width: 80px; }

table.rules { width: 100%; border-collapse: collapse; }
.rules th { font-size: .8rem; color: var(--muted); text-align: right; padding: 4px; background: #f7f9fb; border-bottom: 1px solid var(--line); white-space: nowrap; }
.rules td { padding: 4px; border-bottom: 1px solid #eef1f4; vertical-align: top; }
.rules td.part input { min-width: 130px; }
.rules td.c-qty { min-width: 190px; }
.rules td.c-angle { min-width: 120px; }
.rules select[name$="-profile"], .rules select[name$="-accessory"] { min-width: 140px; }
.rules td > input[name$="-length"], .rules td > input[name$="-qty"] { direction: ltr; font-family: Consolas, "Courier New", monospace; }
.rules .result { color: var(--primary); font-weight: 700; }
.calc { display: flex; gap: 4px; align-items: center; flex-wrap: nowrap; }
.calc select, .calc input { width: auto; padding: 4px 6px; }
.calc .c-base { min-width: 90px; }
.calc .c-num { width: 58px; direction: ltr; text-align: center; font-weight: 700; }
.calc .c-n { width: 46px; direction: ltr; text-align: center; font-weight: 700; }
.calc .c-sign { font-weight: 700; }
.calc .c-divl { display: flex; gap: 3px; align-items: center; margin: 0; font-weight: 400; font-size: .82rem; white-space: nowrap; color: var(--ink); }
.c-toggle { font-size: .75rem; color: var(--muted); margin-top: 2px; }
@media (max-width: 900px) { .type-head { grid-template-columns: 1fr; } }
@media (max-width: 700px) { .type-card { grid-template-columns: 110px 1fr; } .type-card > :last-child { grid-column: 1 / -1; } }

/* ---------------------------------------------------------------- 9. الهاتف */
/* الهاتف واللمس: الأزرار الصغيرة وأزرار الاختيار بحجم الإصبع (كانت ~28px) */
@media (max-width: 480px), (pointer: coarse) {
  .btn-sm { min-height: 38px; padding: 6px 12px; }
  .chip-btn { min-height: 34px; padding: 5px 12px; }
  .chip { min-height: 38px; }
  .mm-box input { min-height: 32px; }
  .item-remove { min-width: 38px; min-height: 38px; }
  .p-drop-design { min-height: 34px; padding: 4px 8px; }
}
@media (max-width: 480px) {
  html { font-size: 14.5px; }
  .main { padding: 12px 10px 70px; }
  h1 { font-size: 1.2rem; }
  /* يمنع التكبير التلقائي في iPhone (أقل من 16 يكبّر الشاشة عند الضغط) — يغلب قواعد الخانات الخاصة */
  input:not([type=checkbox]):not([type=radio]):not([type=hidden]), select, textarea { font-size: 16px !important; }

  .page-head { flex-direction: column; align-items: stretch; gap: 10px; }
  .page-head .actions > .btn, .page-head .actions > form { flex: 1 1 auto; }
  .page-head .actions > form .btn { width: 100%; }
  .card { padding: 12px; border-radius: 10px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stats.kpi { grid-template-columns: 1fr 1fr; }
  .stat .value { font-size: 1.05rem; }
  .form-grid { grid-template-columns: 1fr; gap: 12px; }
  .form-actions > .btn, .save-bar .btn, .filters .btn { flex: 1 1 auto; }
  .filters input, .filters select, .filters label { width: 100%; flex: 1 1 100%; }
  .meta-grid { grid-template-columns: 1fr 1fr; gap: 8px 12px; }
  .pay-form { grid-template-columns: 1fr 1fr; }
  .pay-form > div:nth-child(3), .pay-form > div:nth-child(4), .pay-form > .btn { grid-column: 1 / -1; }

  /* الجداول تتحول إلى بطاقات (يضيف app.js عنوان العمود لكل خلية) */
  table.data.stack > thead { display: none; }
  table.data.stack, table.data.stack > tbody, table.data.stack > tfoot,
  table.data.stack > tbody > tr, table.data.stack > tfoot > tr { display: block; width: 100%; }
  table.data.stack > tbody > tr, table.data.stack > tfoot > tr { padding: 10px 12px; border-bottom: 1px solid var(--line); }
  table.data.stack > * > tr > td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; align-items: baseline; gap: 12px; text-align: left; width: 100%; }
  table.data.stack > * > tr > td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; font-weight: 600; text-align: right; flex-shrink: 0; }
  table.data.stack > * > tr > td[data-label=""]::before { content: none; }
  table.data.stack > tbody > tr > td:first-child { font-size: 1.02rem; font-weight: 700; }
  table.data.stack > * > tr > td.empty { display: block; text-align: center; }
  table.data.stack > * > tr > td.amount { direction: rtl; }
  table.pay-table.stack input { width: 55%; max-width: 180px; font-weight: 700; }   /* خانة المبلغ أمام الطلبية ظاهرة */

  .order-head { grid-template-columns: 1fr 1fr; gap: 10px; }
  .order-head > .field:first-child { grid-column: 1 / -1; }
  .step-f { grid-template-columns: 1fr 1fr; }
  .step-f .f-loc, .step-f .f-panels, .step-f .f-notes { grid-column: 1 / -1; }
  .piece-head .p-type { min-width: 0; flex: 1 1 100%; order: 5; }
  .extra-row { grid-template-columns: 1fr 1fr; }
  .extra-row > div:first-child, .extra-row > div:last-child { grid-column: 1 / -1; }
  .login-card { padding: 20px; }
}
@media (max-width: 380px) { .order-head { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- 10. الطباعة من الشاشة */
@media print {
  .sidebar, .topbar, .sidebar-backdrop, .alert, .no-print, .page-head .actions { display: none !important; }
  .main { margin: 0; padding: 0; }
  .card { border: 0; padding: 0; }
  body { background: #fff; }
}
.data tr.subtotal td { background: #f6f8fa; }


/* محرر الطلبية: خطوات القطعة المتتابعة (الألمنيوم ← الزجاج ← القياس ← الربل ← الساحبة ← السعر) */
.piece-steps { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.step { border: 1px solid #e6ebf0; border-radius: 8px; padding: 6px 10px 10px; background: #fcfdfe; }
.step.done { border-color: #cfe9da; }
.step-h { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: .92rem; margin-bottom: 6px; color: var(--ink); }
.step-n { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--primary); color: #fff; font-size: .8rem; }
.step.done .step-n { background: var(--success); }
.step-ok { display: none; color: var(--success); margin-inline-start: auto; }
.step.done .step-ok { display: inline; }
.step[data-step=alu] .step-f, .step[data-step=glass] .step-f, .step[data-step=cut] .step-f,
.step[data-step=price] .step-f { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.step[data-step=rubber] .step-f { display: block; }
.step .f-kind { grid-column: 1 / -1; }
.seg { display: inline-flex; flex-wrap: wrap; max-width: 100%; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 7px 18px; font: inherit; font-weight: 600; cursor: pointer; border-inline-start: 1px solid var(--line-strong); }
.seg button:first-child { border-inline-start: 0; }
.seg button.on { background: var(--primary); color: #fff; }
.piece.needs-glass .step[data-step=glass] { border-color: var(--danger, #c4312b); box-shadow: 0 0 0 2px #f6d5d3; }
.rubber-list .pane { padding: 5px 0; border-bottom: 1px dashed #e3e8ee; }
.rubber-list .pane:last-child { border-bottom: 0; }
.rubber-total { margin-top: 6px; font-weight: 600; color: #245a7a; }
.piece-name { color: var(--muted); font-weight: 600; }
.piece-size { font-weight: 700; direction: ltr; unicode-bidi: isolate; color: var(--ink); }
.p-fold { min-width: 34px; }
/* طي القطعة: يبقى سطر الرأس (الرمز، النوع، المقاس، السعر) والضغط عليه يفتحها */
.piece.folded .piece-body { display: none; }
.piece.folded .piece-head { cursor: pointer; border-bottom: 0; }
.piece.folded .p-copy { display: none; }
/* طي الخطوة: سطر الملخص بدل الخانات، والضغط على العنوان يفتحها */
.step-h { cursor: pointer; user-select: none; }
.step-sum { display: none; font-weight: 600; color: var(--muted); font-size: .85rem; margin-inline-start: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.step.folded .step-sum { display: inline; flex: 1 1 auto; }
.step.folded .step-f { display: none; }
.step.folded { padding-bottom: 6px; }
.step.folded .step-h { margin-bottom: 0; }
.piece-side { display: flex; flex-direction: column; gap: 6px; align-self: start; }   /* يتحرك مع الصفحة (كان ثابتًا فيختفي أسفل الباب الطويل) */
.piece-draw .dz-svg { display: block; width: 100%; max-height: 60vh; }   /* تصميم الباب الطويل لا يملأ الشاشة */

/* رسم الباب: أشكال جاهزة بأيقونات صغيرة */
.d-presets button { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; padding: 5px 9px; font-size: .78rem; }
.d-ico { width: 18px; height: 30px; }
.d-ico .d-fr { fill: #e7f1f8; stroke: #3b4a5c; stroke-width: 1.4; }
.d-ico .d-pn { fill: #cfd6dd; stroke: #6e7a86; stroke-width: 1; }
.d-ico line { stroke: #3b4a5c; stroke-width: 1.6; }
.d-presets button.on .d-fr { fill: #fff; }
.step[data-step=design] .step-f { grid-template-columns: repeat(3, minmax(0, 1fr)); }

/* الرسم اليدوي: لوحة الرسم */
.sk-modal { position: fixed; inset: 0; background: rgba(16, 24, 32, .55); z-index: 200; display: grid; place-items: center; padding: 10px; }
.sk-panel { background: #fff; border-radius: 12px; width: min(840px, 100%); max-height: 100%; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.sk-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.sk-tools { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.sk-tools .seg button { padding: 5px 10px; font-size: .85rem; }
.sk-color i { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-inline-end: 4px; vertical-align: -1px; }
.sk-stage { border: 1px solid var(--line-strong); border-radius: 8px; background: #fafcfe; touch-action: none; cursor: crosshair; user-select: none; }
.sk-stage svg { display: block; width: 100%; height: auto; max-height: 62vh; }
.sk-foot { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.sketch-bar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
/* محرر التصميم (design-editor.js): شاشة كاملة — القائمة | اللوحة | الخصائص */
.dz-modal { padding: 8px; place-items: stretch; }
.dz-panel { background: #fff; border-radius: 12px; width: 100%; height: 100%; display: grid; grid-template-rows: auto auto 1fr auto; gap: 6px; padding: 10px; overflow: hidden; }
.dz-head, .dz-tools, .dz-foot { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.dz-head-end { margin-inline-start: auto; display: flex; gap: 6px; }
.dz-head .seg button, .dz-tools .seg button { padding: 5px 11px; font-size: .86rem; }
.dz-dim { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; font-size: .9rem; }
.dz-dim input { width: 86px; direction: ltr; text-align: center; font-weight: 700; }
.dz-acts { display: inline-flex; gap: 3px; flex-wrap: wrap; }
.dz-acts .btn { min-width: 34px; font-size: 1rem; padding: 3px 7px; }
.dz-snap { font-size: .86rem; display: inline-flex; gap: 4px; align-items: center; }
.dz-main { display: grid; grid-template-columns: 150px minmax(0, 1fr) 270px; gap: 8px; min-height: 0; }
.dz-palette, .dz-props { overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: #fbfcfd; min-height: 0; }
.dz-pal-title { font-size: .76rem; font-weight: 700; color: var(--muted); margin: 6px 0 4px; }
.dz-pal-group:first-child .dz-pal-title { margin-top: 0; }
.dz-pal { display: flex; align-items: center; gap: 8px; width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 5px 8px; margin-bottom: 4px; font: inherit; font-size: .86rem; cursor: grab; touch-action: none; text-align: start; }
.dz-pal:hover { border-color: var(--primary); background: var(--primary-soft); }
.dz-pal i { font-style: normal; width: 22px; text-align: center; font-weight: 800; color: var(--primary-dark); }
.dz-ghost { position: fixed; z-index: 400; pointer-events: none; background: #fff; border: 2px solid var(--primary); border-radius: 6px; padding: 4px 8px; display: flex; gap: 6px; font-size: .85rem; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.dz-ghost i { font-style: normal; font-weight: 800; }
.dz-stage { position: relative; border: 1px solid var(--line-strong); border-radius: 8px; background: #fafcfe; touch-action: none; user-select: none; overflow: hidden; min-height: 300px; outline: none; }
.dz-stage:focus-visible { border-color: var(--primary); }
.dz-stage > svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.dz-svg .dz-grid { fill: none; stroke: #e8edf2; stroke-width: 1; vector-effect: non-scaling-stroke; }
.dz-svg .dz-sel-cell { fill: rgba(15,108,189,.06); stroke: var(--primary); stroke-dasharray: 8 5; vector-effect: none; }
.dz-svg .dz-sel { fill: none; stroke: var(--primary); stroke-dasharray: 6 4; }
/* خطوط التحديد والإرشاد للعرض فقط: لا تأخذ الضغط (كان إطار الجزء المحدد يغطيه فيلغي تحديده ويحجب ما بداخله) */
.dz-svg .dz-sel-cell, .dz-svg .dz-sel, .dz-svg .dz-sel-label, .dz-svg .dz-guide, .dz-svg .dz-marquee, .dz-svg .dz-draft { pointer-events: none; }
.dz-svg .dz-handle { fill: #fff; stroke: var(--primary); cursor: pointer; }
.dz-svg .dz-rot { fill: var(--primary-soft); cursor: grab; }
.dz-svg .dz-size { fill: var(--primary); stroke: #fff; }
.dz-svg .dz-edge { fill: rgba(15,108,189,.08); }
.dz-svg .dz-edge:hover { fill: rgba(15,108,189,.28); }
.dz-lock { font-size: .82rem; color: var(--warn); font-weight: 600; }
.dz-svg .dz-dw { cursor: ew-resize; } .dz-svg .dz-dh { cursor: ns-resize; } .dz-svg .dz-dwh { cursor: nwse-resize; }
/* الوضع البسيط (العامل): الأدوات الأساسية فقط — «⚙ متقدم» يظهر الباقي */
.dz-simple .adv { display: none !important; }
.dz-simple .dz-main { grid-template-columns: 130px minmax(0, 1fr) 290px; }
.dz-stepper { display: flex; gap: 4px; list-style: none; margin: 0; padding: 0; }
.dz-stepper button { border: 1px solid var(--line-strong); background: #fff; border-radius: 20px; padding: 3px 12px 3px 6px; font: inherit; font-size: .85rem; cursor: pointer; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; }
.dz-stepper button span { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: #e3e8ee; font-weight: 700; font-size: .78rem; }
.dz-stepper button.on { border-color: var(--primary); color: var(--primary-dark); font-weight: 700; background: var(--primary-soft); }
.dz-stepper button.on span { background: var(--primary); color: #fff; }
.dz-icons-t { font-size: .78rem; font-weight: 700; color: var(--muted); margin: 8px 0 4px; }
.dz-icons { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 5px; }
.dz-icons button { border: 1px solid var(--line-strong); background: #fff; border-radius: 8px; padding: 6px 4px; font: inherit; font-size: .78rem; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; line-height: 1.2; }
.dz-icons button i { font-style: normal; font-size: 1.35rem; font-weight: 800; color: var(--primary-dark); line-height: 1.1; }
.dz-icons button:hover { border-color: var(--primary); }
.dz-icons button.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.dz-icons button.on i { color: #fff; }
.dz-glass-f { grid-column: 1 / -1; }
.dz-glass-f input { font-weight: 700; color: var(--primary-dark); background: #eef6fd; text-align: center; direction: ltr; }
.dz-svg [data-dim] { cursor: pointer; }
.dz-svg [data-dim]:hover .dbg { fill: #fff3c4; }
.dz-dim-edit { position: absolute; transform: translate(-50%, -50%); width: 96px; z-index: 5; text-align: center; direction: ltr; font-weight: 700; font-size: 1.05rem;
  padding: 4px 6px; border: 2px solid var(--primary); border-radius: 6px; box-shadow: 0 4px 14px rgba(0,0,0,.2); }
@media (max-width: 900px) { .dz-simple .dz-main { grid-template-columns: 1fr; } .dz-stepper { flex-wrap: wrap; } }
.dz-cuts { margin-top: 10px; border-top: 1px dashed var(--line-strong); padding-top: 8px; }
.dz-cuts .ok { color: var(--success); font-weight: 600; }
.dz-cuts .warn { color: var(--warn); font-weight: 600; }
.dz-svg .dz-guide { stroke: #e0368a; stroke-dasharray: 4 3; }
.dz-svg .dz-marquee { fill: rgba(15,108,189,.08); stroke: var(--primary); stroke-dasharray: 5 4; }
.dz-svg .dz-draft { fill: rgba(15,108,189,.06); stroke: var(--primary); }
.dz-svg .dz-sel-label { fill: var(--primary-dark); font-weight: 700; text-anchor: middle; direction: ltr; paint-order: stroke; stroke: #fff; stroke-width: 3px; }
.dz-svg [data-el], .dz-svg [data-cell] { cursor: move; }
.dz-svg [data-cell] { cursor: pointer; }
.dz-svg [data-bar] { cursor: col-resize; }
.dz-props h4 { margin: 0 0 8px; font-size: .95rem; }
.dz-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 8px; }
.dz-f { display: flex; flex-direction: column; gap: 2px; font-size: .78rem; color: var(--muted); font-weight: 600; min-width: 0; }
.dz-f input, .dz-f select { width: 100%; padding: 4px 6px; font-size: .88rem; }
.dz-f input[inputmode=decimal] { direction: ltr; text-align: center; }
.dz-check { display: flex; gap: 6px; align-items: center; font-size: .85rem; margin: 8px 0 4px; }
.dz-btns { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.dz-parts { margin-top: 8px; border-top: 1px dashed var(--line-strong); padding-top: 6px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 8px; }
.dz-parts > b, .dz-parts > p, .dz-parts > .dz-btns { grid-column: 1 / -1; margin: 0; }
.dz-table { width: 100%; border-collapse: collapse; font-size: .8rem; margin-top: 6px; }
.dz-table th, .dz-table td { border-bottom: 1px solid var(--line); padding: 3px 4px; text-align: right; }
.dz-table td.num { direction: ltr; text-align: center; white-space: nowrap; }
.dz-table tr[data-cell] { cursor: pointer; }
.dz-table tr[data-cell]:hover { background: var(--primary-soft); }
@media (max-width: 900px) {            /* التابلت والهاتف: صفحة واحدة تنزل بالإصبع — القائمة فوق، اللوحة، الخصائص تحت */
  .dz-modal { padding: 0; }
  .dz-panel { display: block; border-radius: 0; padding: 8px 8px 0; overflow-y: auto; overscroll-behavior: contain;
              -webkit-overflow-scrolling: touch; }
  .dz-panel > * + * { margin-top: 6px; }
  .dz-main { display: flex; flex-direction: column; gap: 8px; }
  /* لا يُضغط أي جزء: القائمة والخصائص بطولها الكامل (كانت تنكمش إلى 17 بكسل فلا يمكن الضغط عليها) */
  .dz-palette, .dz-props { flex: none; min-height: auto; overflow: visible; }
  .dz-palette { display: flex; gap: 6px; overflow-x: auto; overflow-y: hidden; }
  .dz-pal-group { display: flex; gap: 4px; align-items: center; }
  .dz-pal-title { display: none; }
  .dz-pal { width: auto; white-space: nowrap; margin: 0; padding: 8px 10px; touch-action: pan-x; }   /* السحب أفقيًا يمرر القائمة */
  .dz-stage { flex: none; height: 58vh; min-height: 300px; }
  .dz-head-end { margin-inline-start: 0; }
  /* الحفظ والإلغاء ظاهران دائمًا أسفل الشاشة */
  .dz-foot { position: sticky; bottom: 0; z-index: 6; background: #fff; padding: 8px 0 10px; border-top: 1px solid var(--line);
             box-shadow: 0 -4px 10px rgba(0,0,0,.06); }
  .dz-acts .btn { min-width: 40px; min-height: 38px; }
  .dz-foot .dz-hint { display: none; }                 /* تلميحات لوحة المفاتيح والماوس لا تفيد في الهاتف */
}
.piece-sheet svg, .sk-sheet-view svg { border: 1px dashed var(--line); border-radius: 6px; margin-top: 4px; }

/* القبض والدفع */
.money-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); gap: 12px; margin-bottom: 16px; }
.money-btn { display: flex; flex-direction: column; gap: 4px; padding: 18px 20px; border-radius: var(--radius); color: #fff; text-decoration: none; }
.money-btn:hover { text-decoration: none; filter: brightness(1.05); }
.money-btn b { font-size: 1.25rem; }
.money-btn span { opacity: .9; font-size: .9rem; }
.money-btn.in { background: var(--success); }
.money-btn.out { background: var(--danger); }
.receipt-total { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 6px; }
.receipt-total label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
.big-in { font-size: 1.3rem; font-weight: 700; direction: ltr; text-align: right; max-width: 220px; }
.pay-in { font-weight: 700; direction: ltr; text-align: right; max-width: 160px; }
.data tr.hl td { background: #fff8e1; }
.amount.pos { color: var(--success); }
.amount.neg { color: var(--danger); }
.stat.warn .value { color: #b0661a; }
.pay-now { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.pay-now > label { font-weight: 600; }
.pay-fields { display: flex; flex-wrap: wrap; gap: 10px; }
.pay-fields label { display: flex; flex-direction: column; font-size: .85rem; gap: 2px; }
.sp-size { display: inline-flex; flex-direction: column; font-size: .8rem; gap: 2px; }
.sp-size input { width: 110px; }
.sp-place, .sp-move { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sp-place .seg button { padding: 3px 12px; }
.sizes-line { margin-top: 4px; }

.p-presets { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; color: var(--muted, #667); }
.p-presets:empty { display: none; }
.chip-btn { border: 1px solid #c9d3e0; background: #f4f7fb; border-radius: 12px; padding: 1px 9px; font-size: .8rem; cursor: pointer; direction: ltr; }
.chip-btn:hover { background: #e3ecf8; }

/* شكل المقطع (رسم تلقائي أو صورة) وشرح الخصم */
.pf-cell { display: flex; align-items: center; gap: 6px; }
.pf-shape { flex: none; display: block; max-width: 80px; max-height: 56px; }
.pf-img { width: 56px; height: 40px; object-fit: contain; background: #fff; border: 1px solid #dde3ea; border-radius: 4px; }
.calc { unicode-bidi: isolate; font-size: .78rem; white-space: normal; line-height: 1.35; }
.calc [dir="ltr"] { unicode-bidi: isolate; display: inline-block; text-align: left; }
.calc-legend { line-height: 1.6; }
.calc-legend .nowrap { white-space: nowrap; }.pf-preview { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.pf-preview .pf-shape { max-width: 110px; max-height: 70px; }
.pf-preview .pf-img { width: 90px; height: 64px; }
/* رسم «أين يُقاس» في مقاسات المقاطع */
.md-cell .md-svg { width: 125px; height: auto; display: block; }
.pf-preview .md-svg { width: 320px; max-width: 100%; height: auto; background: #fff; border: 1px solid #e3e8ee; border-radius: 6px; }
.pf-preview { flex-wrap: wrap; }.md-cell { display: flex; align-items: center; gap: 6px; }
.md-pf { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; margin: 0; }
.md-pf small { font-size: .7rem; color: #667; direction: ltr; }
.md-cell .pf-img { width: 64px; height: 48px; }
.pf-preview .md-pf .pf-shape { max-width: 160px; max-height: 110px; }
.pf-preview .md-pf .pf-img { width: 160px; height: 110px; }
.rules td.c-rubber { min-width: 190px; }
.rules td.c-rubber select { width: auto; max-width: 140px; }
.rules input.num-sm { width: 3.5em; }

/* ربل الإحكام على القطعة (بنفس طولها) */
.seal { color: #1f6b3a; font-size: .78rem; margin-top: 2px; }

/* السبيسر (الفراغ بين لوحي الدبل) في الطلبية */
.g-spacer .unit-in input { max-width: 7em; }
.gap-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.gap-chips .chip-btn.on { background: #1f5f99; color: #fff; border-color: #1f5f99; }

.dz-svg .dhit { fill: transparent; }            /* مساحة ضغط رقم القياس (أكبر من الرقم) */

/* القياسات على الرسم */
.mm-pick select { margin-inline-start: 6px; min-width: 220px; }
.mm-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 14px; align-items: start; }
@media (max-width: 1000px) { .mm-grid { grid-template-columns: 1fr; } }
.mm-title { font-weight: 700; margin-bottom: 6px; }
.mm-stage { position: relative; }
.mm-stage > svg { display: block; width: 100%; height: auto; }
.mm-box { position: absolute; transform: translate(-50%, -50%); display: inline-flex; align-items: center; gap: 3px; background: #fff;
          border: 2px solid #c4312b; border-radius: 8px; padding: 1px 5px; box-shadow: 0 2px 6px rgba(0,0,0,.18); z-index: 2; cursor: text; }
.mm-box b { color: #b3261e; font-size: .8rem; direction: ltr; }
.mm-box input { width: 3.8em; border: 0; padding: 2px 3px; font-weight: 800; font-size: .95rem; direction: ltr; text-align: center; background: transparent; }
.mm-box input:focus { outline: 2px solid #1f5f99; border-radius: 4px; }
.mm-box i { font-style: normal; font-size: .72rem; color: #667; }
@media (max-width: 600px) {
  .mm-pick select { min-width: 0; max-width: 100%; }
  .mm-box { padding: 0 3px; gap: 1px; border-radius: 6px; }
  .mm-box i { display: none; }
  .mm-box input { width: 3em; padding: 1px; }
}
.mm-box.changed, .mm-inline.changed { background: #fff7cc; border-color: #d18a00; }
.mm-box.bad, .mm-inline.bad { background: #fdeceb; border-color: #c4312b; }
.mm-list td { vertical-align: top; padding: 6px; }
.mm-list tr { cursor: pointer; }
.mm-list tr.on { background: #eef6fd; }
.mm-dg .md-svg { width: 110px; height: auto; }
.mm-inline { display: inline-flex; gap: 4px; align-items: center; margin-top: 4px; border: 2px solid #c9d3e0; border-radius: 8px; padding: 1px 6px; }
.mm-inline input { width: 4em; direction: ltr; text-align: center; font-weight: 700; }
.mm-derived { padding-inline-start: 18px; line-height: 1.8; }
.warn-text { color: #a15c00; }
.mm-result td { padding: 4px 6px; }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.how { color: #1f6b3a; }
.code { color: #b3261e; background: #fdeceb; border-radius: 4px; padding: 0 3px; font-weight: 700; font-size: .78rem; }