/* واجهة نظام ماسة المحيط — بدون مكتبات خارجية، تعمل بلا إنترنت */
:root {
  --bg: #f6f3ec;
  --panel: #ffffff;
  --ink: #1f1a12;
  --muted: #6f6656;
  --line: #e4dccb;
  --gold: #a87b1f;
  --gold-soft: #f3e7c8;
  --gold-ink: #6b4c0d;
  --ok: #1d7a4b;
  --ok-soft: #e1f2e8;
  --warn: #9a5b00;
  --warn-soft: #fff1d6;
  --bad: #b3261e;
  --bad-soft: #fde7e5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(60, 45, 10, .06), 0 4px 14px rgba(60, 45, 10, .06);
  font-family: "Segoe UI", Tahoma, "Noto Kufi Arabic", "Geeza Pro", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-size: 15px; line-height: 1.5; }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* أزرار وحقول */
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 600; }
.btn:hover { border-color: var(--gold); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--gold); border-color: var(--gold); color: #fff; }
.btn-primary:hover { background: var(--gold-ink); }
.btn-big { width: 100%; padding: 14px; font-size: 17px; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-danger { color: var(--bad); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
input, select { border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; background: #fff; min-width: 0; }
input:focus, select:focus { outline: 2px solid var(--gold-soft); border-color: var(--gold); }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* بطاقات */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card h2 { font-size: 17px; margin: 0 0 12px; }
.card h3 { font-size: 15px; margin: 0 0 8px; }

/* صفحة الدخول */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 400px; }
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.brand-mark { width: 40px; height: 40px; border-radius: 10px; background: var(--gold); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 20px; }
.brand h1 { font-size: 18px; margin: 0; }

/* الشريط العلوي */
.topbar { background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1400px; margin: 0 auto; padding: 10px 16px; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.rates-strip { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { background: var(--gold-soft); color: var(--gold-ink); border-radius: 999px; padding: 3px 10px; font-size: 13px; font-weight: 600; }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-ok { background: var(--ok-soft); color: var(--ok); }
.chip-bad { background: var(--bad-soft); color: var(--bad); }
.tabs { max-width: 1400px; margin: 0 auto; padding: 0 16px; display: flex; gap: 4px; overflow-x: auto; flex-wrap: wrap; row-gap: 0; }
.tab { border: 0; background: transparent; padding: 10px 14px; border-bottom: 3px solid transparent; cursor: pointer; font-weight: 600; color: var(--muted); white-space: nowrap; }
.tab.active { color: var(--gold-ink); border-bottom-color: var(--gold); }

.banner { max-width: 1400px; margin: 12px auto 0; padding: 10px 14px; border-radius: 8px; font-size: 14px; }
.banner-warn { background: var(--warn-soft); color: var(--warn); border: 1px solid #f0d49b; }
main { max-width: 1400px; margin: 0 auto; padding: 16px; }

/* شاشة البيع */
.sale { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(340px, 1fr); gap: 16px; align-items: start; }
.items { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; max-height: calc(100vh - 260px); overflow-y: auto; padding: 2px; }
.item { text-align: start; border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 12px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; }
.item:hover { border-color: var(--gold); box-shadow: var(--shadow); }
.item.in-cart { border-color: var(--ok); background: var(--ok-soft); }
.item .code { font-size: 12px; color: var(--muted); }
.item .name { font-weight: 700; }
.item .price { font-weight: 800; color: var(--gold-ink); font-size: 16px; }
.cart { position: sticky; top: 120px; }
.cart-line { border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: grid; gap: 6px; }
.cart-lines { display: grid; gap: 8px; max-height: 38vh; overflow-y: auto; margin-bottom: 12px; }
.totals { background: #faf7f0; border: 1px solid var(--line); border-radius: 8px; padding: 12px; display: grid; gap: 6px; margin: 12px 0; }
.totals .grand { font-size: 20px; font-weight: 800; color: var(--ok); border-top: 1px solid var(--line); padding-top: 8px; }
.kv { display: flex; justify-content: space-between; gap: 10px; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* جداول */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: start; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; background: #faf7f0; position: sticky; top: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #fbf8f1; }

/* رسائل */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 100; box-shadow: var(--shadow); max-width: 90vw; }
.toast.err { background: var(--bad); }
.toast.ok { background: var(--ok); }
.msg-err { color: var(--bad); font-size: 14px; min-height: 20px; }

dialog { border: 0; border-radius: 12px; padding: 0; max-width: 95vw; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20, 15, 5, .45); }
.dialog-body { padding: 18px; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--line); background: #faf7f0; }

/* الفاتورة المطبوعة (عرض 80 مم) */
.receipt { width: 80mm; max-width: 100%; margin: 0 auto; background: #fff; color: #000; font-size: 12px; padding: 4mm; position: relative; }
.receipt h2 { font-size: 15px; text-align: center; margin: 0 0 2px; }
.receipt .center { text-align: center; }
.receipt .sep { border-top: 1px dashed #000; margin: 6px 0; }
.receipt table { font-size: 11px; }
.receipt th, .receipt td { padding: 2px 1px; border: 0; white-space: normal; background: none; position: static; color: #000; }
.receipt .line-detail { font-size: 10px; color: #333; }
.receipt .grand { font-size: 14px; font-weight: 800; }
.watermark { border: 2px solid #000; text-align: center; font-weight: 800; padding: 4px; margin: 6px 0; font-size: 12px; }

@media (max-width: 900px) {
  .sale { grid-template-columns: 1fr; }
  .cart { position: static; }
  .g4, .g5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3 { grid-template-columns: 1fr; }
}

@media print {
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area { position: absolute; inset: 0 0 auto 0; width: auto; }
  dialog { box-shadow: none; }
  @page { size: A4; margin: 10mm; }
}

/* أدوات مساعدة (بدل الأنماط المضمنة التي تمنعها سياسة الأمان) */
.m0 { margin: 0 !important; }
.mb10 { margin-bottom: 10px; }
.mb12 { margin-bottom: 12px !important; }
.mb16 { margin-bottom: 16px; }
.w260 { width: 260px; max-width: 100%; }
.w200 { width: 200px; max-width: 100%; }
.maxw760 { max-width: 760px; }
.maxw900 { max-width: 900px; }
.minw320 { min-width: 320px; }
.fullrow { grid-column: 1 / -1; }
.jend { justify-content: flex-end; }
.receipt td + td, .receipt th + th { padding-inline-start: 8px; }

/* ===== المرحلة الثانية ===== */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg-btn { border: 0; background: #fff; padding: 7px 14px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg-btn + .seg-btn { border-inline-start: 1px solid var(--line); }
.seg-btn.active { background: var(--gold-soft); color: var(--gold-ink); }
.pv-line { border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: grid; gap: 10px; background: #fff; }
.pv-line .grid { align-items: end; }
.thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.logo-preview { max-height: 60px; max-width: 200px; border: 1px solid var(--line); border-radius: 6px; padding: 4px; background: #fff; }
.report-table td:last-child, .report-table th:last-child { text-align: end; }
.return-line { display: flex; gap: 10px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.return-line.done { opacity: .5; }
.check { width: 18px; height: 18px; accent-color: var(--gold); }
.sig { display: flex; justify-content: space-between; margin-top: 14px; font-size: 11px; }
.sig div { border-top: 1px solid #000; padding-top: 2px; width: 45%; text-align: center; }
@media print {
  .print-report #report-body, .print-report #report-body * { visibility: visible; }
  .print-report #report-body { position: absolute; inset: 0 0 auto 0; display: block; }
  .print-report #report-body .card { box-shadow: none; break-inside: avoid; margin-bottom: 8px; }
}
.receipt-logo { max-height: 14mm; max-width: 40mm; }
.brand-logo { height: 34px; width: auto; display: block; }

/* ===== فاتورة A4 للطباعة على HP ===== */
.dialog-body { max-height: 78vh; overflow: auto; }
.btn-wa { background: #1f9d55; border-color: #1f9d55; color: #fff; }
.btn-wa:hover { background: #17834a; }
.a4 { width: 190mm; max-width: 100%; margin: 0 auto; background: #fff; color: #000; font-size: 10.5pt; line-height: 1.45; }
.a4-head { display: flex; justify-content: space-between; align-items: center; gap: 8mm; border-bottom: 0.6mm solid #000; padding-bottom: 3mm; }
.a4-name { font-size: 14pt; font-weight: 800; }
.a4-logo { height: 16mm; width: auto; }
.a4-title { text-align: center; margin: 4mm 0 2mm; font-size: 13pt; font-weight: 800; }
.a4-title .en { font-size: 9pt; font-weight: 600; color: #444; }
.a4-meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1mm 6mm; border: 0.3mm solid #999; border-radius: 2mm; padding: 2mm 3mm; margin: 2mm 0 4mm; font-size: 9.5pt; }
.a4-meta .kv { justify-content: flex-start; gap: 2mm; }
.a4-meta .kv span:first-child { color: #555; }
.a4-table { width: 100%; border-collapse: collapse; font-size: 9pt; }
.a4-table th { background: #eee; color: #000; font-weight: 700; border: 0.25mm solid #888; padding: 1.5mm 1mm; position: static; white-space: normal; text-align: center; }
.a4-table td { border: 0.25mm solid #bbb; padding: 1.5mm 1mm; white-space: normal; vertical-align: top; text-align: center; }
.a4-table td:nth-child(2) { text-align: start; }
.a4-table td.details { text-align: start; font-size: 8.5pt; }
.muted-print { color: #555; font-size: 8pt; }
.a4-bottom { display: flex; justify-content: space-between; align-items: flex-start; gap: 6mm; margin-top: 4mm; }
.a4-qr { width: 32mm; height: 32mm; border: 0.3mm dashed #999; display: grid; place-items: center; text-align: center; font-size: 7.5pt; color: #666; padding: 2mm; }
.a4-totals { width: 95mm; border: 0.3mm solid #999; border-radius: 2mm; padding: 2mm 3mm; display: grid; gap: 1mm; }
.a4-totals .grand { font-size: 13pt; font-weight: 800; border-top: 0.4mm solid #000; padding-top: 1.5mm; color: #000; }
.a4-foot { margin-top: 6mm; text-align: center; font-size: 9pt; color: #333; display: grid; gap: 1mm; }
.a4 .watermark { margin: 2mm 0; }
@media print {
  .receipt { width: 150mm; font-size: 11pt; }
  .receipt table { font-size: 10pt; }
  .a4 { width: 100%; }
  .dialog-body { max-height: none; overflow: visible; }
}

/* الطباعة: المستند فقط، بعرض الصفحة كاملاً، على خلفية بيضاء */
@media print {
  html, body { background: #fff !important; }
  body:not(.print-report) #app-view { display: none !important; }
  body:not(.print-report) .toast { display: none !important; }
  dialog[open] { position: static; inset: auto; margin: 0; padding: 0; border: 0; width: 100%; max-width: none;
    max-height: none; height: auto; overflow: visible; box-shadow: none; transform: none; background: #fff; }
  dialog::backdrop { background: none; }
  dialog .dialog-actions { display: none !important; }
  #invoice-dialog .dialog-body { padding: 0; max-height: none; overflow: visible; }
  #print-area { position: static; }
}

/* ===== الربط مع الهيئة ===== */
.banner-ok { background: var(--ok-soft); color: var(--ok); border: 1px solid #b7e0c4; }
.banner-err { background: var(--bad-soft); color: var(--bad); border: 1px solid #f1b5b5; font-weight: 600; }
#zatca-card .banner { margin: 0; max-width: none; }
.a4-qr.has-qr { border: none; padding: 0; display: grid; gap: 1mm; justify-items: center; height: auto; }
.qr-svg { width: 32mm; height: 32mm; display: block; }
.receipt .qr-svg { width: 30mm; height: 30mm; margin: 0 auto; }
.qr-cap { font-size: 7.5pt; color: #666; }
@media print { .no-print { display: none !important; } }
.mt8 { margin-top: 8px; }

/* ===== أصناف القطع ===== */
.types-list { display: flex; flex-wrap: wrap; gap: 8px; }
.type-chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line, #e5ddd0); border-radius: 999px; padding: 3px 4px 3px 12px; background: #fff; }
.type-chip.off { opacity: .55; background: #f4f1ec; }
.linkish { background: none; border: 0; padding: 0; font: inherit; font-weight: 600; cursor: pointer; color: inherit; }
.linkish:hover { text-decoration: underline; }

/* ===== المرحلة الأولى من المقترحات ===== */
.item-thumb { width: 100%; height: 110px; object-fit: cover; border-radius: 8px; background: var(--line); }
.thumb { width: 34px; height: 34px; object-fit: cover; border-radius: 6px; }
.thumb-lg { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.nowrap { flex-wrap: nowrap; }
.disc-type { padding: 6px 8px; font-size: 13px; }
.mixed-box { display: grid; gap: 8px; border: 1px dashed var(--line); border-radius: 10px; padding: 10px; }
.mixed-row select { flex: 0 0 120px; }
.mixed-row input { flex: 1 1 90px; min-width: 0; }
.ok-text { color: var(--ok); }
.bad-text { color: var(--bad); }
.check-row { gap: 8px; font-weight: 500; }
.check-row input { width: 18px; height: 18px; }
#cust-hint { min-height: 1.2em; color: var(--muted); }

/* ===== فاتورة المنشآت ===== */
.b2b-toggle { margin-bottom: 8px; }
.b2b-box { border: 1px dashed var(--line); border-radius: 10px; padding: 10px; margin-bottom: 10px; }
.a4-buyer { border: 0.3mm solid #999; border-radius: 2mm; padding: 2mm 3mm; margin: 2mm 0; display: grid; gap: 0.5mm; font-size: 9.5pt; }
.a4-buyer-title { font-weight: 700; font-size: 9pt; color: #555; }
.watermark.bad { border-color: var(--bad); color: var(--bad); }

/* ===== إدخال البضاعة ===== */
.grid-table td { padding: 3px 4px; }
.grid-table input, .grid-table select { padding: 5px 6px; font-size: 13px; }
.w60 { width: 60px; } .w70 { width: 70px; } .w80 { width: 80px; } .w90 { width: 90px; } .w160 { width: 160px; }
.row-bad td { background: var(--bad-soft); }
.row-bad-msg td { color: var(--bad); font-size: 12.5px; padding-top: 0; }
.g4 .span4 { grid-column: 1 / -1; }
.price-row { background: var(--gold-soft, #f6efdc); border-radius: 10px; padding: 8px; }

/* الفاتورة الاحترافية: رأس بثلاثة أعمدة، تفقيط، توقيعات */
.a4-head3 { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 6mm; border-bottom: 0.6mm solid #000; padding-bottom: 3mm; font-size: 9pt; }
.a4-head3 .a4-seller.en { text-align: left; }
.a4-head3 .a4-name { font-size: 13pt; }
.a4-gold th { font-size: 8pt; }
.a4-gold td { font-size: 8.5pt; }
.a4-table tfoot td { font-weight: 700; background: #f5f5f5; border: 0.25mm solid #888; }
.a4-words { font-size: 9pt; font-weight: 600; border-top: 0.25mm dashed #999; padding-top: 1mm; }
.a4-sign { display: grid; grid-template-columns: 1fr 1fr; gap: 20mm; margin-top: 8mm; text-align: center; font-size: 9.5pt; }
.a4-sign .sign-line { border-bottom: 0.3mm solid #000; height: 10mm; margin-bottom: 1mm; }
.a4-footline { border-top: 0.4mm solid #000; padding-top: 1.5mm; font-size: 8.5pt; }
.a4-gold td:nth-child(2) { min-width: 26mm; }
.a4-head3 { grid-template-columns: 1.3fr auto 1fr; }

/* ===== الإضافات: المحاسبة والموردون والجرد والخدمات ===== */
.mt12 { margin-top: 12px; }
.subnav { display: flex; gap: 6px; flex-wrap: wrap; }
.pill-btn { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 6px 14px; cursor: pointer; font-weight: 600; font-size: 14px; }
.pill-btn:hover { border-color: var(--gold); }
.pill-btn.active { background: var(--gold); border-color: var(--gold); color: #fff; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.stat-v { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; direction: ltr; text-align: right; }
.stat-ok { border-color: var(--ok); background: var(--ok-soft); }
.stat-bad { border-color: var(--bad); background: var(--bad-soft); }
.stat-warn { border-color: var(--warn); background: var(--warn-soft); }
tr.voided td { opacity: .55; text-decoration: line-through; }
tr.voided td .msg-err { text-decoration: none; }
.vat-table tr.total td { font-weight: 800; background: var(--gold-soft); }
.vat-table td:first-child { width: 3em; text-align: center; }
.a4 .vat-table { width: 100%; border-collapse: collapse; font-size: 9.5pt; }
.a4 .vat-table td, .a4 .vat-table th { border: 0.25mm solid #999; padding: 1.5mm 2mm; }
tr.row-bad td { background: var(--bad-soft); }
tr.row-ok td { background: var(--ok-soft); }
tr.row-warn td { background: var(--warn-soft); }
.scan-input { font-size: 20px; padding: 14px; width: 100%; direction: ltr; }
.big-count { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; }
@media (max-width: 760px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .span4 { grid-column: span 2; } }
.span4 { grid-column: 1 / -1; }
.w100 { width: 100%; } .w120 { width: 120px; }

/* =====================================================================
   التصميم العصري (الإصدار 2): قائمة جانبية، بطاقات ناعمة، أزرار كبيرة واضحة
   ===================================================================== */
:root {
  --bg: #f5f3ee;
  --panel: #ffffff;
  --ink: #1c1a16;
  --ink-2: #3d382f;
  --muted: #7a7264;
  --line: #ebe5d8;
  --gold: #a9822e;
  --gold-2: #c9a24a;
  --gold-soft: #f6eedb;
  --gold-ink: #6d4f10;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(40, 30, 10, .04), 0 6px 20px rgba(40, 30, 10, .05);
  --side-w: 250px;
}
body { font-size: 15px; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { letter-spacing: 0; }

/* الهيكل: قائمة جانبية يميناً + المحتوى */
.app-shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh; }
.app-shell.hidden { display: none !important; }
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--panel); border-inline-end: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 16px 12px; gap: 8px; z-index: 40; }
.side-brand { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 4px 8px 12px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.side-brand .brand-logo { height: 38px; }
.side-foot { margin-top: auto; border-top: 1px solid var(--line); padding: 12px 8px 0; display: grid; gap: 8px; }
.tabs { flex-direction: column; flex-wrap: nowrap; gap: 2px; padding: 0; margin: 0; max-width: none; overflow: visible; }
.nav-group { font-size: 12px; font-weight: 700; color: var(--muted); padding: 12px 10px 4px; }
.tab { display: flex; align-items: center; gap: 10px; width: 100%; text-align: start; padding: 10px 12px; border: 0; border-radius: 10px;
  color: var(--ink-2); font-weight: 600; font-size: 14.5px; border-bottom: 0; transition: background-color .12s, color .12s; }
.tab svg { width: 20px; height: 20px; flex: 0 0 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; opacity: .85; }
.tab:hover { background: #f7f2e6; color: var(--ink); }
.tab.active { background: var(--gold-soft); color: var(--gold-ink); border-bottom: 0; }
.tab.active svg { opacity: 1; }
.tab.hidden { display: none !important; }

.app-main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 30; background: rgba(255, 255, 255, .92); backdrop-filter: saturate(1.4) blur(8px); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: none; padding: 10px 20px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-title { font-size: 20px; font-weight: 800; margin: 0; }
.menu-btn { display: none; padding: 6px; }
.menu-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.rates-strip { display: flex; gap: 6px; flex-wrap: wrap; }
.topbar .today { white-space: nowrap; }
main { max-width: 1500px; width: 100%; margin: 0 auto; padding: 18px 20px 40px; }
.banner { max-width: none; margin: 12px 20px 0; border-radius: 12px; }

/* البطاقات والأزرار والحقول */
.card { border-color: var(--line); border-radius: var(--radius); padding: 18px; }
.card h2 { font-size: 18px; }
.btn { border-radius: 10px; padding: 9px 16px; transition: background-color .12s, border-color .12s, transform .05s; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(180deg, var(--gold-2), var(--gold)); border-color: var(--gold); box-shadow: 0 2px 6px rgba(169, 130, 46, .25); }
.btn-primary:hover { background: linear-gradient(180deg, var(--gold), var(--gold-ink)); }
.btn-big { padding: 15px; font-size: 18px; border-radius: 12px; }
input, select, textarea { border-radius: 10px; padding: 10px 12px; border-color: #e3dccb; }
textarea { font: inherit; border: 1px solid #e3dccb; }
th { background: #faf8f3; font-size: 13px; }
td { border-bottom-color: #f0ebe0; }
.chip { border-radius: 999px; }

/* شاشة البيع: قطع أوضح وسلة ثابتة */
.sale { grid-template-columns: minmax(0, 1.5fr) minmax(360px, 1fr); gap: 18px; }
.items { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; max-height: calc(100vh - 220px); }
.item { border-radius: 14px; padding: 12px; gap: 4px; transition: border-color .12s, box-shadow .12s, transform .08s; }
.item:hover { transform: translateY(-1px); }
.item .price { font-size: 18px; }
.cart { top: 78px; }
.cart h2 { display: flex; align-items: center; gap: 8px; }
.cart-line { border-radius: 12px; background: #fdfcf9; }
.totals { border-radius: 12px; background: var(--gold-soft); border-color: #eadcb8; }
.totals .grand { font-size: 24px; color: var(--gold-ink); }
#sale-search { font-size: 16px; }

/* أزرار طريقة الدفع */
.pay-seg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.pay-seg button { border: 1.5px solid var(--line); background: #fff; border-radius: 12px; padding: 12px 6px; font-weight: 700; cursor: pointer; font-size: 15px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.pay-seg button small { font-weight: 500; color: var(--muted); font-size: 11.5px; }
.pay-seg button:hover { border-color: var(--gold-2); }
.pay-seg button.active { border-color: var(--gold); background: var(--gold-soft); color: var(--gold-ink); box-shadow: inset 0 0 0 1px var(--gold); }
.pay-label { font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.more-toggle { background: none; border: 0; color: var(--gold-ink); font-weight: 700; cursor: pointer; padding: 4px 0; }

/* لوحة اليوم */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .k-label { color: var(--muted); font-size: 13px; font-weight: 600; }
.kpi .k-value { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; direction: ltr; text-align: right; margin-top: 2px; }
.kpi .k-sub { color: var(--muted); font-size: 12.5px; }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 140px; padding-top: 8px; }
.bars .bar { flex: 1; background: linear-gradient(180deg, var(--gold-2), var(--gold)); border-radius: 6px 6px 2px 2px; min-height: 2px; position: relative; }
.bars .bar.today { background: linear-gradient(180deg, #2f9a64, var(--ok)); }
.bars-labels { display: flex; gap: 4px; font-size: 10.5px; color: var(--muted); }
.bars-labels span { flex: 1; text-align: center; }
.h-1 { height: 1%; } /* أطوال الأعمدة تُضبط بأصناف h-0..h-100 */

/* الجوال والأجهزة اللوحية */
.side-backdrop { display: none; }
@media (max-width: 1000px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; top: 0; bottom: 0; right: 0; width: 270px; transform: translateX(105%); transition: transform .2s ease; box-shadow: -8px 0 30px rgba(0,0,0,.12); }
  .app-shell.menu-open .sidebar { transform: none; }
  .app-shell.menu-open .side-backdrop { display: block; position: fixed; inset: 0; background: rgba(20, 15, 5, .35); z-index: 35; }
  .menu-btn { display: inline-flex; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  main { padding: 14px 12px 40px; }
  .banner { margin: 10px 12px 0; }
  .rates-strip { order: 5; width: 100%; }
}
@media print {
  .sidebar, .topbar, .banner { display: none !important; }
}
.h-0 { height: 0%; } .h-1 { height: 1%; } .h-2 { height: 2%; } .h-3 { height: 3%; } .h-4 { height: 4%; } .h-5 { height: 5%; } .h-6 { height: 6%; } .h-7 { height: 7%; } .h-8 { height: 8%; } .h-9 { height: 9%; } .h-10 { height: 10%; } .h-11 { height: 11%; } .h-12 { height: 12%; } .h-13 { height: 13%; } .h-14 { height: 14%; } .h-15 { height: 15%; } .h-16 { height: 16%; } .h-17 { height: 17%; } .h-18 { height: 18%; } .h-19 { height: 19%; } .h-20 { height: 20%; } .h-21 { height: 21%; } .h-22 { height: 22%; } .h-23 { height: 23%; } .h-24 { height: 24%; } .h-25 { height: 25%; } .h-26 { height: 26%; } .h-27 { height: 27%; } .h-28 { height: 28%; } .h-29 { height: 29%; } .h-30 { height: 30%; } .h-31 { height: 31%; } .h-32 { height: 32%; } .h-33 { height: 33%; } .h-34 { height: 34%; } .h-35 { height: 35%; } .h-36 { height: 36%; } .h-37 { height: 37%; } .h-38 { height: 38%; } .h-39 { height: 39%; } .h-40 { height: 40%; } .h-41 { height: 41%; } .h-42 { height: 42%; } .h-43 { height: 43%; } .h-44 { height: 44%; } .h-45 { height: 45%; } .h-46 { height: 46%; } .h-47 { height: 47%; } .h-48 { height: 48%; } .h-49 { height: 49%; } .h-50 { height: 50%; } .h-51 { height: 51%; } .h-52 { height: 52%; } .h-53 { height: 53%; } .h-54 { height: 54%; } .h-55 { height: 55%; } .h-56 { height: 56%; } .h-57 { height: 57%; } .h-58 { height: 58%; } .h-59 { height: 59%; } .h-60 { height: 60%; } .h-61 { height: 61%; } .h-62 { height: 62%; } .h-63 { height: 63%; } .h-64 { height: 64%; } .h-65 { height: 65%; } .h-66 { height: 66%; } .h-67 { height: 67%; } .h-68 { height: 68%; } .h-69 { height: 69%; } .h-70 { height: 70%; } .h-71 { height: 71%; } .h-72 { height: 72%; } .h-73 { height: 73%; } .h-74 { height: 74%; } .h-75 { height: 75%; } .h-76 { height: 76%; } .h-77 { height: 77%; } .h-78 { height: 78%; } .h-79 { height: 79%; } .h-80 { height: 80%; } .h-81 { height: 81%; } .h-82 { height: 82%; } .h-83 { height: 83%; } .h-84 { height: 84%; } .h-85 { height: 85%; } .h-86 { height: 86%; } .h-87 { height: 87%; } .h-88 { height: 88%; } .h-89 { height: 89%; } .h-90 { height: 90%; } .h-91 { height: 91%; } .h-92 { height: 92%; } .h-93 { height: 93%; } .h-94 { height: 94%; } .h-95 { height: 95%; } .h-96 { height: 96%; } .h-97 { height: 97%; } .h-98 { height: 98%; } .h-99 { height: 99%; } .h-100 { height: 100%; } 
.clickable-banner { cursor: pointer; } .clickable-banner:hover { filter: brightness(.98); }
.sale { grid-template-columns: minmax(0, 1.3fr) minmax(400px, 1fr); }
.cart-line { gap: 4px; padding: 10px 12px; }
.cart-line.loss { border-color: var(--bad); }
.cl-head { flex-wrap: nowrap; }
.cl-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cl-price { font-size: 17px; white-space: nowrap; color: var(--gold-ink); }
.cl-disc input { width: 120px; }
.icon-btn { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 15px; width: 30px; height: 30px; border-radius: 8px; }
.icon-btn:hover { background: var(--bad-soft); color: var(--bad); }
.link-btn { border: 0; background: none; color: var(--gold-ink); font-weight: 700; cursor: pointer; padding: 0; text-decoration: underline; font-size: 13px; }
.totals .kv > :last-child { white-space: nowrap; }
.totals .kv > :first-child { min-width: 0; }
@media (max-width: 1250px) { .sale { grid-template-columns: minmax(0, 1fr) minmax(360px, 1fr); } }
.cart-lines { grid-template-columns: minmax(0, 1fr); }
.cart-line { min-width: 0; }
@media (max-width: 640px) { .g2 { grid-template-columns: minmax(0, 1fr); } .span2 { grid-column: auto; } .kpi .k-value { font-size: 21px; } }
.cl-name { flex: 1 1 auto; } .cl-head .spacer { display: none; } .cl-price, .icon-btn { flex: 0 0 auto; }
@media (max-width: 1000px) { .sale { grid-template-columns: minmax(0, 1fr); } .cart { position: static; } .items { max-height: none; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); } }
.rates-chart { width: 100%; height: auto; margin: 8px 0; }
.legend-a9822e { color: #a9822e; } .legend-1d7a4b { color: #1d7a4b; } .legend-6f6656 { color: #6f6656; }
.piece-cards { display: grid; grid-template-columns: repeat(2, 90mm); gap: 6mm; justify-content: center; background: #fff; color: #000; padding: 4mm; }
.piece-card { width: 90mm; min-height: 60mm; border: 0.5mm solid #a9822e; border-radius: 4mm; padding: 4mm; display: flex; flex-direction: column; gap: 2mm; break-inside: avoid; background: linear-gradient(180deg, #fffdf7, #fff); }
.pc-head { display: flex; align-items: center; gap: 3mm; border-bottom: 0.3mm solid #e6d7b0; padding-bottom: 2mm; }
.pc-logo { height: 9mm; width: auto; }
.pc-title { font-weight: 800; font-size: 11pt; }
.pc-sub { font-size: 7.5pt; color: #6d4f10; }
.pc-name { font-weight: 800; font-size: 12pt; }
.pc-table { font-size: 8.5pt; }
.pc-table td { border: 0; padding: 0.6mm 0; white-space: normal; }
.pc-table td:first-child { color: #555; width: 32mm; }
.pc-foot { margin-top: auto; font-size: 7pt; color: #444; border-top: 0.3mm solid #e6d7b0; padding-top: 1.5mm; }
.pc-note { font-size: 7pt; color: #6d4f10; }
@media (max-width: 700px) { .piece-cards { grid-template-columns: 1fr; } }
.rates-chart text { direction: ltr; unicode-bidi: plaintext; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 7px 16px; font-weight: 700; cursor: pointer; }
.seg button + button { border-inline-start: 1px solid var(--line); }
.seg button.active { background: var(--gold-soft); color: var(--gold-ink); }
.direct-card { background: #fffcf4; border-color: #eadcb8; }
.big-input { font-size: 18px; font-weight: 800; }
.pdf-stage { position: fixed; top: 0; left: -10000px; width: 794px; background: #fff; padding: 28px 30px; box-sizing: border-box; direction: rtl; }
.pdf-stage .a4 { width: 100%; max-width: none; }
.pdf-page { width: 794px; padding: 28px 30px; box-sizing: border-box; background: #fff; direction: rtl; color: #000; } .pdf-page .a4 { width: 100%; max-width: none; }
.wa-mode { padding: 6px 8px; font-size: 13px; }

/* صفحة الكاشير (/pos): قائمة بيع فقط */
.mode-pos .nav-group { display: none; }
.btn-block { display: block; width: 100%; text-align: center; margin-bottom: 8px; text-decoration: none; color: inherit; }
