: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;
  --glass: #0e7c86;
  --glass-soft: #e2f4f5;
  --double: #6a4cc2;
  --double-soft: #efeafb;
  --radius: 8px;
  --sidebar: 230px;
}

* { 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);
  font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", Arial, sans-serif;
  line-height: 1.5;
}
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; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num, .ltr { direction: ltr; unicode-bidi: isolate; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ------------------------------------------------ التخطيط */
.sidebar {
  position: fixed; inset-block: 0; inset-inline-start: 0; width: var(--sidebar);
  background: #17212e; color: #cfd8e3; display: flex; flex-direction: column;
  padding: 14px 12px; overflow-y: auto; z-index: 20;
}
.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; }
.new-invoice { 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: #17212e; 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 .new-invoice { 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; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); }
.hint { background: var(--primary-soft); color: #164a78; padding: 8px 12px; border-radius: 6px; margin-bottom: 14px; font-size: .9rem; }

/* ------------------------------------------------ الأزرار */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line-strong); background: #fff; color: var(--ink);
  padding: 7px 14px; border-radius: 6px; font: inherit; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f4f6f9; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.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[readonly] { background: #f6f8fa; }
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 { grid-column: 1 / -1; }
.field .help { color: var(--muted); font-size: .8rem; margin-top: 3px; }
.field .error { color: var(--danger); font-size: .85rem; margin-top: 3px; }
.field.check label { display: flex; align-items: center; gap: 8px; }
.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%); }

/* ------------------------------------------------ الجداول */
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 tr.clickable { cursor: pointer; }
.table-wrap { overflow-x: auto; }
.empty { text-align: center; color: var(--muted); padding: 30px !important; }

/* ------------------------------------------------ الحالات */
.badge { display: inline-block; padding: 1px 9px; border-radius: 20px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.st-draft { background: #eef0f3; color: #5b6673; }
.st-sent { background: var(--primary-soft); color: var(--primary-dark); }
.st-partial { background: var(--warn-soft); color: var(--warn); }
.st-paid { background: var(--success-soft); color: var(--success); }
.st-overdue { background: var(--danger-soft); color: var(--danger); }
.st-cancelled { background: #f1f1f1; color: #888; text-decoration: line-through; }
.st-inactive { background: #f1f1f1; color: #888; }
.st-receipt { background: var(--success-soft); color: var(--success); }
.st-disbursement { background: var(--danger-soft); color: var(--danger); }

.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-error { background: var(--danger-soft); border-color: #f2c1be; color: #8d1f1a; }
.alert-info { background: var(--primary-soft); border-color: #bcd6f0; color: var(--primary-dark); }
.alert-warning { background: var(--warn-soft); border-color: #f2d6a4; color: #7a4a00; }

/* ------------------------------------------------ الرئيسية */
.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; }

/* ------------------------------------------------ قائمة البحث (Combo) */
.combo { position: relative; }
.combo-list {
  position: fixed; z-index: 60; max-height: 260px; overflow-y: auto; margin: 0;
  background: #fff; border: 1px solid var(--line-strong); border-radius: 6px; box-shadow: 0 6px 20px rgba(20,30,50,.15);
  list-style: none; padding: 3px; min-width: 200px;
}
.combo-list li { padding: 6px 9px; border-radius: 4px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.combo-list li .extra { color: var(--muted); font-size: .82rem; direction: ltr; white-space: nowrap; }
.combo-list li.active { background: var(--primary-soft); }
.combo-list li.none { color: var(--muted); cursor: default; }
.combo.free input { background: #fffdf3; }

/* ------------------------------------------------ محرر الفاتورة */
.inv-head { display: grid; grid-template-columns: minmax(min(260px, 100%), 2fr) repeat(auto-fill, minmax(140px, 1fr)); gap: 12px 16px; align-items: end; }
.customer-field { display: flex; gap: 6px; }
.customer-field .combo { flex: 1; }
.due-chips { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.due-chips button { border: 1px solid var(--line-strong); background: #fff; border-radius: 12px; padding: 0 9px; font: inherit; font-size: .78rem; cursor: pointer; color: #45505c; }
.due-chips button:hover { background: var(--primary-soft); }
.due-chips button.on { background: var(--primary); border-color: var(--primary); color: #fff; }
input.invalid { border-color: var(--danger); outline-color: #f2b8b5; background: var(--danger-soft); }
.late { color: var(--danger); font-weight: 600; }
.items { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.item { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); border-inline-start: 4px solid var(--line-strong); }
.item[data-kind=normal] { border-inline-start-color: var(--primary); }
.item[data-kind=single] { border-inline-start-color: var(--glass); }
.item[data-kind=double] { border-inline-start-color: var(--double); }
.item[data-kind=""] { border-style: dashed; background: #fbfcfd; }
.item-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px; flex-wrap: wrap; }
.item-no { font-weight: 700; color: var(--muted); min-width: 22px; }
.kind-btns { display: flex; gap: 6px; }
.kind-btn { border: 1px solid var(--line-strong); background: #fff; border-radius: 20px; padding: 4px 14px; cursor: pointer; font: inherit; font-size: .9rem; }
.kind-btn:hover { background: #f3f6f9; }
.kind-btn.on[data-kind=normal] { background: var(--primary); border-color: var(--primary); color: #fff; }
.kind-btn.on[data-kind=single] { background: var(--glass); border-color: var(--glass); color: #fff; }
.kind-btn.on[data-kind=double] { background: var(--double); border-color: var(--double); color: #fff; }
.item-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); }
.item-body { padding: 4px 12px 12px; }
.item-empty-hint { color: var(--muted); font-size: .88rem; }

.normal-row { display: grid; grid-template-columns: minmax(200px, 3fr) minmax(160px, 3fr) 90px 80px 130px; gap: 8px; align-items: end; }
.glass-config { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px 12px; align-items: end; margin-bottom: 10px; }
.glass-config .mat { grid-column: span 2; display: grid; grid-template-columns: 1fr 100px; gap: 6px; }
.glass-config label, .normal-row label { font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: 2px; }
.g-rows { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 12px; max-width: 900px; }
.g-row { display: grid; grid-template-columns: 130px minmax(220px, 420px) 140px 1fr; gap: 10px; align-items: center; animation: g-in .18s ease-out; }
.g-row > label { margin: 0; font-size: .9rem; color: #45505c; }
.g-price { display: flex; align-items: center; gap: 4px; font-size: .8rem; color: var(--muted); }
.g-price input { background: #f8fafc; min-width: 0; }
.g-price span { white-space: nowrap; }
.g-meas { animation: g-in .18s ease-out; border-top: 1px dashed var(--line); padding-top: 8px; }
/* بدون transform: التحويل يُنشئ حاوية تُزيح القوائم المنبثقة ذات الموضع الثابت */
@keyframes g-in { from { opacity: 0; } to { opacity: 1; } }
@media (max-width: 900px) { .g-row { grid-template-columns: 1fr 120px; } .g-row > label { grid-column: 1 / -1; } }
.permeter { font-size: .85rem; color: var(--muted); align-self: center; }
.permeter b { color: var(--ink); direction: ltr; display: inline-block; }

table.meas { width: 100%; border-collapse: collapse; font-size: .92rem; }
.meas th { font-size: .78rem; color: var(--muted); font-weight: 600; text-align: right; padding: 4px 4px; background: #f7f9fb; border-bottom: 1px solid var(--line); white-space: nowrap; }
.meas tr.auto input { color: #9aa5b1; background: #fafbfc; }
.meas td { padding: 4px 4px; border-bottom: 1px solid #eef1f4; vertical-align: top; }
.meas input { padding: 5px 6px; }
.meas .c-no { width: 26px; color: var(--muted); text-align: center; padding-top: 9px; }
.meas .c-dim { width: 78px; }
.meas .c-cnt { width: 60px; }
.meas .c-calc { width: 72px; padding-top: 9px; direction: ltr; text-align: right; font-weight: 600; color: var(--glass); white-space: nowrap; }
.meas .c-sel { min-width: 130px; }
.meas .c-pos { width: 100px; }
.meas .c-sum { width: 100px; padding-top: 9px; text-align: left; direction: ltr; white-space: nowrap; }
.meas .c-x { width: 26px; }
.meas .price-sub { margin-top: 3px; display: flex; align-items: center; gap: 4px; font-size: .78rem; color: var(--muted); }
.meas .price-sub input { padding: 2px 5px; font-size: .82rem; }
.meas-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; gap: 10px; flex-wrap: wrap; }
.kbd { font-size: .78rem; color: var(--muted); }
.kbd kbd { background: #eef1f4; border: 1px solid #d5dbe2; border-radius: 3px; padding: 0 5px; font-family: inherit; }

.inv-foot { display: grid; grid-template-columns: 1fr 340px; gap: 16px; align-items: start; }
.totals { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.totals .row { display: flex; justify-content: space-between; align-items: center; padding: 5px 0; gap: 10px; }
.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; }
.save-bar {
  position: sticky; bottom: 0; background: rgba(243,245,248,.95); backdrop-filter: blur(4px);
  border-top: 1px solid var(--line); padding: 10px 0; margin-top: 16px; display: flex; gap: 10px; align-items: center; z-index: 10;
}
@media (max-width: 1100px) {
  .inv-foot { grid-template-columns: 1fr; }
  .normal-row { grid-template-columns: 1fr 1fr; }
}

/* ------------------------------------------------ نافذة منبثقة */
.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; }

/* ------------------------------------------------ عرض الفاتورة */
.inv-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px 20px; }
.inv-meta .k { color: var(--muted); font-size: .82rem; }
.inv-meta .v { font-weight: 600; }
.item-desc { white-space: pre-line; color: #45505c; font-size: .88rem; margin-top: 3px; }
.glass-tag { font-size: .75rem; padding: 0 7px; border-radius: 10px; margin-inline-start: 6px; }
.glass-tag.single { background: var(--glass-soft); color: var(--glass); }
.glass-tag.double { background: var(--double-soft); color: var(--double); }
table.sub { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: .85rem; }
.sub th, .sub td { border: 1px solid var(--line); padding: 3px 6px; text-align: right; }
.sub th { background: #f7f9fb; color: var(--muted); font-weight: 600; }
.pay-form { display: grid; grid-template-columns: 1fr 1fr 1.3fr 1.5fr auto; gap: 8px; align-items: end; }
@media (max-width: 1000px) { .pay-form { grid-template-columns: 1fr 1fr; } }

/* ------------------------------------------------ تسجيل الدخول */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #17212e, #0f6cbd); }
.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; }

/* ================================================ الهاتف (425px وأقل) */
@media (max-width: 480px) {
  html { font-size: 14.5px; }
  .main { padding: 12px 10px 70px; }
  h1 { font-size: 1.2rem; }
  h2 { font-size: 1.02rem; }

  /* العناوين والأزرار: الأزرار تملأ العرض وتلتف */
  .page-head { flex-direction: column; align-items: stretch; gap: 10px; }
  .page-head h1 { line-height: 1.4; }
  .page-head .actions { gap: 6px; }
  .page-head .actions > .btn, .page-head .actions > form, .page-head .actions > a { flex: 1 1 auto; }
  .page-head .actions > form .btn { width: 100%; }
  .btn-lg { padding: 9px 16px; font-size: 1rem; }
  .kbd, .hide-mobile { display: none !important; }
  .card { padding: 12px; border-radius: 10px; }
  .hint { font-size: .85rem; }

  /* بطاقات الأرقام: اثنتان في كل صف */
  .stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat .label { font-size: .78rem; }
  .stat .value { font-size: 1.05rem; }

  /* النماذج والفلاتر */
  .form-grid { grid-template-columns: 1fr; gap: 12px; }
  .form-actions > .btn { flex: 1 1 auto; }
  .filters { gap: 6px; }
  .filters input, .filters select, .filters label { width: 100%; flex: 1 1 100%; }
  .filters label input { margin-top: 2px; }
  .filters .btn { flex: 1 1 auto; }
  input, select, textarea { font-size: 16px; } /* يمنع التكبير التلقائي في iPhone */

  /* الجداول تتحول إلى بطاقات (صفوف الجدول نفسه فقط، لا الجداول الداخلية) */
  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 > tbody > tr:nth-child(odd) { background: #fff; }
  table.data.stack > tbody > tr:nth-child(even) { background: #fafbfc; }
  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, table.data.stack > * > tr > td:not([data-label])::before { content: none; }
  table.data.stack > * > tr > td[data-label=""] { justify-content: flex-end; }
  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.full { display: block; text-align: right; }
  table.data.stack > * > tr > td.full::before { display: block; margin-bottom: 3px; }
  table.data.stack > * > tr > td.amount { direction: rtl; }
  table.data.stack > tfoot > tr > td[data-label=""] { justify-content: flex-start; }
  table.data.stack > tfoot > tr { background: #f7f9fb; }
  table.data.stack > tfoot > tr > td:empty { display: none; }
  .data th, .data td { padding: 7px 9px; }
  .data td:first-child a { white-space: nowrap; }
  /* الفلاتر: التاريخان جنبًا إلى جنب */
  .filters label:has(input[type=date]) { flex: 1 1 calc(50% - 3px); width: auto; }

  /* ---------------- شاشة الفاتورة */
  .inv-head { grid-template-columns: 1fr 1fr; gap: 10px; }
  .inv-head > .field:first-child { grid-column: 1 / -1; }
  .customer-field #add-customer { padding: 6px 10px; }
  .item-head { gap: 6px; padding: 8px 10px; }
  .kind-btns { order: 3; width: 100%; }
  .kind-btn { flex: 1; padding: 6px 4px; }
  .item-total { font-size: 1rem; }
  .item-body { padding: 4px 10px 10px; }
  .normal-row { grid-template-columns: 1fr 1fr 1fr; }
  .normal-row > div:nth-child(1), .normal-row > div:nth-child(2) { grid-column: 1 / -1; }
  .g-row { grid-template-columns: 1fr 110px; gap: 4px 8px; }
  .g-row > label { grid-column: 1 / -1; margin-bottom: -2px; }
  .g-row > div:last-child:empty { display: none; }
  .g-row .permeter { grid-column: 1 / -1; }

  /* كل قياس بطاقة: الطول والعرض والعدد، ثم النتائج، ثم الربل والساحبة */
  .meas thead { display: none; }
  .meas, .meas tbody { display: block; }
  .meas tbody tr {
    display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px 8px;
    border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin-bottom: 8px; background: #fff;
  }
  .meas tbody tr.auto { background: #fafbfc; border-style: dashed; }
  .meas td { padding: 0; border: 0; min-width: 0; width: auto !important; }
  .meas td[data-label]::before { content: attr(data-label); display: block; font-size: .72rem; color: var(--muted); font-weight: 600; margin-bottom: 1px; }
  .meas .c-no { order: 1; grid-column: span 5; text-align: right; padding: 0; font-weight: 700; color: var(--ink); }
  .meas .c-no::before { content: "قياس "; }
  .meas .c-x { order: 2; grid-column: span 1; text-align: left; }
  .meas .c-len { order: 3; grid-column: span 2; }
  .meas .c-wid { order: 4; grid-column: span 2; }
  .meas .c-cnt { order: 5; grid-column: span 2; }
  .meas .c-area { order: 6; grid-column: span 2; padding: 0; }
  .meas .c-rlen { order: 7; grid-column: span 2; padding: 0; }
  .meas .c-sum { order: 8; grid-column: span 2; padding: 0; text-align: right; font-weight: 700; }
  .meas .c-rubber1 { order: 9; grid-column: span 3; }
  .meas .c-rubber2 { order: 10; grid-column: span 3; }
  .meas .c-handle { order: 11; grid-column: span 3; }
  .meas .c-pos { order: 12; grid-column: span 3; }
  .meas input { font-size: 16px; padding: 6px 7px; }
  .meas .c-dim input, .meas .c-cnt input { font-weight: 700; }
  .meas-actions { flex-direction: column; align-items: stretch; }
  .meas-actions .btn { width: 100%; }

  .inv-foot { gap: 10px; }
  .totals .row input { width: 120px; }
  .save-bar { flex-wrap: wrap; padding: 8px 0; }
  .save-bar .btn { flex: 1 1 auto; }
  .save-bar > span { width: 100%; text-align: center; }
  .due-chips button { padding: 2px 10px; font-size: .82rem; }

  /* صفحة الفاتورة */
  .inv-meta { 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; }
  .sub { font-size: .78rem; }
  .sub th, .sub td { padding: 3px 4px; white-space: nowrap; }

  .modal-back { padding-top: 6vh; }
  .modal { padding: 14px; }
  .login-card { padding: 20px; }
}

@media print {
  .sidebar, .menu-toggle, .no-print, .alert, .topbar, .sidebar-backdrop { display: none !important; }
  .main { margin: 0; padding: 0; }
  .card { border: 0; padding: 0; }
  body { background: #fff; }
}

/* ------------------------------------------------ أوامر القص */
.cut-mat { margin-top: 18px; }
.cut-mat > h2 { margin-bottom: 10px; }
.cut-sheet { display: grid; gap: 10px; }
.cut-sheet.need-buy { border: 2px solid var(--danger); }
.cut-sheet-head { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; }
.cut-svg-wrap { overflow-x: auto; background: #fafcfd; border: 1px solid var(--line); border-radius: 6px; padding: 6px; }
.cut-svg { display: block; width: 100%; min-width: 480px; height: auto; max-height: 72vh; }
.cut-pieces td, .cut-pieces th { padding: 5px 8px; }
.dot { display: inline-block; width: 11px; height: 11px; border: 1.5px solid; border-radius: 3px; margin-inline-end: 6px; vertical-align: middle; }
.inv-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.inv-chip { display: inline-flex; align-items: center; gap: 6px; color: inherit; font-size: .92rem; }
.inv-chip i { width: 14px; height: 14px; border: 1.5px solid; border-radius: 3px; display: inline-block; }
.inv-chip i.hatch { border-color: #c9544c; background: repeating-linear-gradient(45deg, #f7dcda 0 3px, #c9544c 3px 4px); }
.cut-submit { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: end; }
.sheet-rows input { width: 100%; min-width: 70px; }
.sheet-rows td { padding: 6px; }
@media (max-width: 700px) { .cut-submit { grid-template-columns: 1fr; } }
