/* الهوية البصرية: المجد للديكور، أسود وذهبي وأبيض. الأرقام بخط Futura */
@font-face { font-family: 'FuturaNum'; src: url('/fonts/futura-Medium.woff2') format('woff2'); font-weight: 400 500; font-display: swap; }
@font-face { font-family: 'FuturaNum'; src: url('/fonts/futura-Demi.woff2') format('woff2'); font-weight: 600 800; font-display: swap; }

:root {
  --ink: #111111;
  --ink-2: #1d1d1d;
  --ink-3: #2e2e2e;
  --on-ink: #ffffff;
  --on-ink-muted: #a9a49b;
  --saffron: #c9912c;
  --saffron-ink: #1a1203;
  --gold-text: #8f6414;
  --bg: #f6f5f2;
  --surface: #ffffff;
  --sunk: #f0eee9;
  --line: #e5e1d8;
  --line-strong: #cec7b8;
  --text: #141414;
  --muted: #69655e;
  --accent: #111111;
  --accent-ink: #ffffff;
  --accent-soft: #f1ead9;
  --ok: #15803d;
  --ok-soft: #e3f4e8;
  --danger: #c0262d;
  --danger-soft: #fbe5e4;
  --warn: #a16207;
  --warn-soft: #fdf2d2;
  --radius: 8px;
  --nav-h: 66px;
  --top-h: 58px;
  --font: 'FuturaNum', 'GESS', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
[data-theme='dark'] {
  --ink: #000000;
  --ink-2: #141414;
  --ink-3: #262626;
  --bg: #0b0b0b;
  --surface: #161616;
  --sunk: #1e1e1e;
  --line: #2a2a2a;
  --line-strong: #3b3b3b;
  --text: #f3f1ec;
  --muted: #a5a29b;
  --gold-text: #d9a646;
  --accent: #c9912c;
  --accent-ink: #1a1203;
  --accent-soft: #2a2419;
  --ok: #4ade80;
  --ok-soft: #12291a;
  --danger: #f87171;
  --danger-soft: #331617;
  --warn: #facc15;
  --warn-soft: #2e2810;
}
body { background: var(--bg); letter-spacing: 0; }
h1 { font-size: 22px; }
a { color: var(--gold-text); }
.ok-text { color: var(--ok); }
button, a, label { -webkit-tap-highlight-color: transparent; }
.btn, .chip, .seg span, .nav a, .side a, .row-link { transition: background-color .14s ease-out, color .14s ease-out, border-color .14s ease-out, opacity .14s ease-out; }
.btn:active, .row-link:active { opacity: .82; }

/* الشريط العلوي */
.top { background: var(--ink); color: var(--on-ink); border-bottom: 0; }
.top .brand { display: flex; align-items: center; gap: 10px; font-size: 16px; min-width: 0; }
.top .brand > span { overflow: hidden; text-overflow: ellipsis; }
.mark { width: 26px; height: 26px; flex: none; color: var(--saffron); }
.top .who { color: var(--on-ink-muted); display: inline-flex; align-items: center; gap: 8px; }
.top .who i {
  display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 50%;
  background: var(--ink-3); color: var(--on-ink); font-style: normal; font-weight: 700; font-size: 13px;
}
.top .back { color: var(--on-ink); }
@media (hover: hover) { .top .back:hover { background: var(--ink-3); } }

/* القائمة السفلية */
.nav { background: var(--ink); border-top: 0; }
.nav a { position: relative; color: var(--on-ink-muted); font-size: 11.5px; }
.nav a.on { color: var(--saffron); }
.nav a.on::before { content: ''; position: absolute; top: 0; inset-inline: 26%; height: 3px; background: var(--saffron); border-radius: 0 0 3px 3px; }

/* القائمة الجانبية */
@media (min-width: 900px) {
  .side { background: var(--ink); border-inline-end: 0; }
  .side a { color: var(--on-ink-muted); }
  .side a svg { color: inherit; }
  .side a.on { background: var(--ink-3); color: var(--saffron); }
  .side a.on svg { color: var(--saffron); }
  .side .sep { background: var(--ink-3); }
}
@media (hover: hover) and (min-width: 900px) { .side a:hover:not(.on) { background: var(--ink-2); color: var(--on-ink); } }

/* الأزرار */
.btn { font-weight: 700; border-color: var(--line-strong); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.btn.gold { background: var(--saffron); border-color: var(--saffron); color: var(--saffron-ink); }
.btn.ghost { color: var(--gold-text); }
[data-theme='dark'] .btn.primary { background: var(--saffron); border-color: var(--saffron); color: var(--saffron-ink); }
.sticky-actions .btn.primary, form > .btn.primary { min-height: 52px; font-size: 15px; }
.seg input:checked + span { background: var(--ink); border-color: var(--ink); color: var(--saffron); }
.chip { border-color: var(--line-strong); background: transparent; }
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--saffron); }
.input, select.input, textarea.input { background: var(--surface); border-color: var(--line-strong); }
.input:focus { border-color: var(--ink-3); box-shadow: 0 0 0 3px rgba(201, 145, 44, .3); }

/* الصناديق والقوائم */
.box { background: var(--surface); border-color: var(--line); }
.box-head { background: transparent; }
.page-head h1 { font-size: 22px; }
table.t th { background: var(--sunk); }
.total-bar { background: var(--ink); color: var(--on-ink); border-top: 0; border-radius: 0 0 7px 7px; }
.total-bar .v { color: var(--saffron); font-size: 24px; }
.stat .v { font-size: 22px; }
.row-link .t, .row .t { font-size: 15px; }
.tag.ok { color: var(--ok); }
.progress > div, .bars .b .fill { background: var(--saffron); }

/* رأس الصفحة الرئيسية */
.hero {
  background: var(--ink); color: var(--on-ink);
  margin: -16px -16px 16px; padding: 10px 20px 22px;
}
.hero-k { color: var(--on-ink-muted); font-size: 13px; }
.hero-v { direction: ltr; text-align: right; font-size: 46px; line-height: 1.15; font-weight: 700; color: var(--on-ink); margin-top: 2px; }
.hero-v small { font-size: 16px; font-weight: 600; color: var(--saffron); margin-inline-end: 6px; }
.split { display: flex; height: 8px; gap: 2px; margin-top: 16px; border-radius: 4px; overflow: hidden; background: var(--ink-3); direction: rtl; }
.split i { display: block; height: 100%; }
.c-cash { background: var(--saffron); } .c-card { background: #f7f3ea; } .c-transfer { background: #6fb7a6; } .c-credit { background: #d9694f; }
.legend { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 12px; }
.legend div { min-width: 0; }
.legend span { display: flex; align-items: center; gap: 5px; color: var(--on-ink-muted); font-size: 12px; }
.legend span i { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.legend b { display: block; direction: ltr; text-align: right; font-size: 15px; font-weight: 600; white-space: nowrap; }

.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 16px; }
.quick a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 78px; padding: 8px 2px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); font-size: 12.5px; font-weight: 600; text-align: center;
}
.quick a svg { width: 22px; height: 22px; }
.quick a.main-act { background: var(--saffron); border-color: var(--saffron); color: var(--saffron-ink); }

.money-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.money-grid a { display: block; padding: 13px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); min-width: 0; }
.money-grid .k { font-size: 12.5px; color: var(--muted); }
.money-grid .v { direction: ltr; text-align: right; font-size: 21px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.money-grid .v small { font-size: 12px; color: var(--muted); font-weight: 500; }
.money-grid a.alert-card .v { color: var(--danger); }

/* صف صنف مع توزيعه على المستودعات */
.stockbar { grid-column: 1; display: flex; flex-direction: column; gap: 5px; margin-top: 3px; min-width: 0; }
.stockbar .wh { display: grid; grid-template-columns: 52px 1fr 30px; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); }
.stockbar .track { height: 5px; border-radius: 3px; background: var(--sunk); overflow: hidden; }
.stockbar .fill { height: 100%; border-radius: 3px; background: var(--ink-3); }
.stockbar .wh b { font-weight: 600; color: var(--text); text-align: left; direction: ltr; }
[data-theme='dark'] .stockbar .fill { background: var(--saffron); }
.row-link .e.big { font-size: 22px; line-height: 1.1; }

/* الشاشة العامة */
.public { background: var(--bg); }
.public header { background: var(--ink); color: var(--on-ink); border-bottom: 0; padding: 12px 20px; }
.public header .brand { display: flex; align-items: center; gap: 10px; }
.public header .btn { background: transparent; color: var(--on-ink); border-color: var(--ink-3); }
.public .pub-hero { background: var(--ink); color: var(--on-ink); padding: 26px 20px 62px; }
.public .pub-hero > div { max-width: 560px; margin: 0 auto; }
.public .pub-hero h1 { font-size: 32px; margin: 0 0 6px; }
.public .pub-hero p { color: var(--on-ink-muted); margin: 0; }
.public main { padding: 0 20px 40px; margin-top: -36px; }
.search-big { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px; box-shadow: 0 10px 28px rgba(12, 43, 46, .14); }
.search-big .input { border: 0; min-height: 54px; font-size: 20px; font-weight: 600; background: transparent; }
.search-big .input:focus { box-shadow: none; }
.search-big .btn { background: var(--saffron); border-color: var(--saffron); color: var(--saffron-ink); }
.result { padding: 22px; border-radius: 10px; background: var(--surface); border-color: var(--line); }
.result .name { font-size: 30px; margin: 0 0 12px; }
.result.yes .state { color: var(--ok); } .result.yes .dot { background: var(--ok); }
.result .low { background: var(--saffron); color: var(--saffron-ink); padding: 12px 14px; }

.search-big { align-items: center; }
.search-big .s-icon { display: inline-flex; padding-inline-start: 10px; color: var(--muted); }
.search-big .s-icon svg { width: 22px; height: 22px; }
.pub-list { list-style: none; margin: 16px 0 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.pub-list li + li { border-top: 1px solid var(--line); }
.pub-list button { display: flex; align-items: center; justify-content: space-between; width: 100%; min-height: 56px; padding: 8px 18px; border: 0; background: none; cursor: pointer; }
.pub-list b { font-size: 18px; font-weight: 600; }
.pub-list span { font-size: 14px; font-weight: 700; }
.p-yes { color: var(--ok); } .p-low { color: var(--warn); } .p-no { color: var(--danger); }
@media (hover: hover) { .pub-list button:hover { background: var(--sunk); } }

/* الدخول */
.login { flex-direction: column; justify-content: flex-start; padding: 0; background: var(--bg); }
.login-top { width: 100%; background: var(--ink); color: var(--on-ink); padding: 56px 24px 78px; }
.login-top > div { max-width: 380px; margin: 0 auto; }
.login-top .mark { width: 42px; height: 42px; margin-bottom: 18px; display: block; }
.login-top h1 { font-size: 28px; margin: 0 0 4px; }
.login-top p { color: var(--on-ink-muted); margin: 0; font-size: 14px; }
.login .box { margin: -46px 20px 24px; width: calc(100% - 40px); max-width: 380px; box-shadow: 0 10px 28px rgba(12, 43, 46, .14); border-radius: 10px; }

@media (min-width: 900px) {
  .hero { margin: 0 0 16px; border-radius: 10px; padding: 22px 26px 24px; }
  .hero-v { font-size: 54px; }
  .quick { grid-template-columns: repeat(4, 180px); }
  .money-grid { grid-template-columns: repeat(4, 1fr); }
}
/* توزيع الصنف على المستودعات بسطر واحد */
.stockline { grid-column: 1; min-width: 0; margin-top: 2px; }
.stocklabels { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); }
.stocklabels span { display: inline-flex; align-items: center; gap: 5px; }
.stocklabels i { width: 8px; height: 8px; border-radius: 2px; }
.stocklabels b { color: var(--text); font-weight: 600; }
.stocktrack { display: flex; gap: 2px; height: 5px; margin-top: 6px; border-radius: 3px; overflow: hidden; background: var(--sunk); }
.stocktrack i { display: block; height: 100%; }
.w0 i, i.w0 { background: var(--ink-3); }
.w1 i, i.w1 { background: var(--saffron); }
.stocktrack i.w0 { background: var(--ink-3); } .stocktrack i.w1 { background: var(--saffron); }

/* أزرار رأس الصفحة بسطر واحد يتمرر على الجوال */
@media (max-width: 760px) {
  .page-head .actions:has(> :nth-child(3)) {
    order: 3; width: calc(100% + 32px); margin: 0 -16px; padding: 0 16px 2px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
  }
  .page-head .actions:has(> :nth-child(3))::-webkit-scrollbar { display: none; }
  .page-head .actions > * { flex: none; }
}
.row-link .e bdi { font-size: 14px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* الفروع والعملاء */
.top a.who { text-decoration: none; }
.tabs { display: flex; gap: 2px; padding: 3px; margin-bottom: 12px; background: var(--sunk); border-radius: var(--radius); overflow-x: auto; }
.tabs a { flex: 1; text-align: center; white-space: nowrap; padding: 9px 12px; border-radius: 6px; color: var(--muted); font-weight: 700; font-size: 14px; }
.tabs a.on { background: var(--ink); color: var(--saffron); }
a.chip { display: inline-flex; align-items: center; color: var(--text); }
a.chip.on { color: var(--saffron); }
.branch-line { font-weight: 700; margin-bottom: 12px; }
.auto-driver { display: flex; justify-content: space-between; padding: 10px 12px; background: var(--sunk); border-radius: var(--radius); }
.auto-driver span { color: var(--muted); }
.picked { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; background: var(--accent-soft); border-radius: var(--radius); }
.picked > div { display: flex; flex-direction: column; min-width: 0; }
.picked span { font-size: 13px; color: var(--muted); }
.picker .results .add-new { color: var(--ok); font-weight: 700; grid-template-columns: 1fr; }
.picker .results .add-new svg { width: 15px; height: 15px; vertical-align: -2px; }

/* التوفر بكل مستودع بشاشة العملاء */
.stores { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.store { padding: 12px; border-radius: var(--radius); background: var(--sunk); min-width: 0; }
.store span { display: block; font-size: 13px; color: var(--muted); }
.store b { font-size: 16px; }
.store.yes b { color: var(--ok); } .store.no b { color: var(--danger); }
.store.low { background: var(--saffron); } .store.low span, .store.low b { color: var(--saffron-ink); }
.p-stores { display: inline-flex; gap: 10px; font-size: 12.5px !important; }
.p-stores em { font-style: normal; white-space: nowrap; }

/* الطباعة */
#print-sheet { display: none; }
.doc { color: #000; background: #fff; font-size: 13px; }
.doc-head { display: flex; justify-content: space-between; border-bottom: 2px solid #000; padding-bottom: 10px; margin-bottom: 12px; }
.doc-head div { display: flex; flex-direction: column; }
.doc-head b { font-size: 18px; }
.doc-no { text-align: left; }
.doc-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 20px; margin: 0 0 14px; }
.doc-meta div { display: flex; gap: 8px; } .doc-meta dt { color: #555; } .doc-meta dd { margin: 0; font-weight: 700; }
.doc table { width: 100%; border-collapse: collapse; }
.doc th, .doc td { border: 1px solid #999; padding: 6px 8px; text-align: right; }
.doc th { background: #eee; }
.doc-total { display: flex; justify-content: space-between; margin-top: 12px; padding: 10px 12px; border: 2px solid #000; font-size: 16px; }
@media print {
  @page { size: A4; margin: 14mm; }
  body { background: #fff !important; }
  .top, .nav, .side, .no-print, .chips, .toolbar, .sticky-actions, .toast { display: none !important; }
  .layout { display: block !important; } .main { padding: 0 !important; max-width: none !important; }
  .box { break-inside: avoid; border-color: #999; }
  body.printing #app { display: none !important; }
  body.printing #print-sheet { display: block !important; }
}

.picked em, .picker .results em { font-style: normal; font-weight: 600; }
.row-link .e svg { width: 16px; height: 16px; }

/* الجولة الثالثة: سطر الفاتورة بالقوائم، والدفع المقسّم، وأزرار التسليم */
.order-row .t { white-space: normal; }
.order-row .t .addr { display: block; font-weight: 700; font-size: 14px; color: var(--text); margin-top: 2px; }
.row-link .it, .row .it { grid-column: 1; font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.6; min-width: 0; overflow-wrap: anywhere; }
.order-row .e, .transfer-box .row-link .e, #list .row-link:has(.it) .e { grid-row: 1 / span 3; }
.items-cell { font-size: 13px; font-weight: 600; max-width: 260px; }
.line-sum { font-weight: 700; white-space: nowrap; direction: ltr; }
.pay-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.pay-grid .field { margin-bottom: 8px; }
.pay-sum { display: flex; justify-content: space-between; gap: 10px; padding: 10px 12px; background: var(--sunk); border-radius: var(--radius); font-size: 14px; margin-bottom: 10px; }
.pay-sum b { margin-inline-start: 6px; }
.deliver-actions { display: flex; gap: 10px; }
.deliver-actions .btn.primary { flex: 1; }
.deliver-actions .btn.danger { flex: 0 0 auto; min-height: 52px; }
.transfer-box .box-head .tag { margin-inline-start: auto; }
details.box > summary { list-style: none; }
details.box > summary::-webkit-details-marker { display: none; }
details.box > summary h2::after { content: ' ›'; color: var(--muted); }
details.box[open] > summary h2::after { content: ' ⌄'; }

/* الجولة الرابعة: قائمة المندوب، والخصم، وأمين المستودع */
.drv-row .t { font-size: 17px; font-weight: 700; }
.it-big { grid-column: 1; display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; min-width: 0; }
.it-big span { font-size: 16px; font-weight: 700; color: var(--text); background: var(--sunk); border: 1px solid var(--line); border-radius: 6px; padding: 3px 9px; line-height: 1.5; }
.drv-row .e { grid-row: 1 / span 2; font-size: 17px; font-weight: 700; }
.disc-row { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line-strong); }
.disc-row .input { max-width: 180px; }
.disc-row p { margin: 6px 0 0; }
.disc-bar { display: flex; justify-content: space-between; padding: 8px 16px; font-size: 14px; color: var(--muted); border-top: 1px solid var(--line); }
.disc-bar .num { color: var(--text); font-weight: 600; direction: ltr; }
.doc-total.sub { border-width: 1px; font-size: 13px; margin-top: 6px; padding: 6px 12px; }
.seg-wrap label { flex: 1 1 30%; }
.kp-list { display: grid; gap: 10px; }
.kp-card { padding: 14px 16px; }
.kp-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.kp-head b { font-size: 17px; }
.kp-head .small { white-space: nowrap; }
.kp-items { display: flex; flex-wrap: wrap; gap: 8px; }
.kp-items span { display: inline-flex; align-items: stretch; border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; font-size: 17px; }
.kp-items b { padding: 5px 10px; background: var(--surface); }
.kp-items i { font-style: normal; font-weight: 700; padding: 5px 10px; background: var(--ink); color: var(--saffron); }
.kp-qty { font-size: 18px; }
/* الألوان الثابتة (طلب ماجد): أحمر للآجل والملغي وغير متوفر، أخضر للكاش وتم التوصيل ومتوفر، أصفر للشبكة، أبيض للتحويل */
.pm { display: inline-block; font-size: 12px; font-weight: 700; line-height: 1.5; padding: 1px 8px; border-radius: 5px; border: 1px solid transparent; white-space: nowrap; margin-inline-start: 4px; }
.pm-cash { background: #16a34a; color: #fff; }
.pm-card { background: #facc15; color: #2b2100; }
.pm-transfer { background: #fff; color: #111; border-color: #bdb6a6; }
.pm-credit { background: #dc2626; color: #fff; }
small.pms { display: flex; flex-wrap: wrap; gap: 3px; justify-content: flex-end; margin-top: 3px; }
small.pms .pm { margin: 0; }
.tag.ok { background: #16a34a; color: #fff; border-color: #16a34a; }
.tag.danger { background: #dc2626; color: #fff; border-color: #dc2626; }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.seg input[value=cash]:checked + span { background: #16a34a; border-color: #16a34a; color: #fff; }
.seg input[value=card]:checked + span { background: #facc15; border-color: #facc15; color: #2b2100; }
.seg input[value=transfer]:checked + span { background: #fff; border-color: #111; color: #111; box-shadow: inset 0 0 0 1px #111; }
.seg input[value=credit]:checked + span, .seg input[value=debt]:checked + span { background: #dc2626; border-color: #dc2626; color: #fff; }
.seg input[name=method][value=split]:checked + span { background: var(--ink); border-color: var(--ink); color: var(--saffron); }
.store.yes b, .p-yes { color: #16a34a; }
.store.no b, .p-no { color: #dc2626; }
.cost-in { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 12px; }
.cost-in .input { min-height: 34px; max-width: 120px; padding: 0 8px; }
.rep-table table.t td, .rep-table table.t th { white-space: nowrap; }
.rep-table table.t td.wrap { white-space: normal; min-width: 140px; }
.doc-report table { font-size: 10px; }
.mark { color: var(--saffron); }
