@font-face { font-family: "Plex"; src: url("assets/IBMPlexSansArabic-regular.ttf") format("truetype"); font-weight: 400; font-display: block; }
@font-face { font-family: "Plex"; src: url("assets/IBMPlexSansArabic-bold.ttf") format("truetype"); font-weight: 700; font-display: block; }

:root {
  --navy: #163a66; --blue: #1e7fb0; --grey: #63666a; --line: #9fb6cb;
  --border: #c9d6e3; --light: #eef4f9; --bg: #f3f6f9; --ink: #1b2430; --danger: #b42318;
  --ok: #157f3b; --warn: #b26a00;
  --tabs-h: 64px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: "Plex", system-ui, sans-serif; }
body { padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom)); }
body.has-bar { padding-bottom: calc(var(--tabs-h) + 76px + env(safe-area-inset-bottom)); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- shell ---------- */
.top { background: #fff; border-bottom: 1px solid var(--border); padding: calc(10px + env(safe-area-inset-top)) 16px 10px; display: flex; align-items: center; justify-content: space-between; gap: 12px; position: sticky; top: 0; z-index: 8; }
.top img { height: 34px; }
.top .t { text-align: left; }
.top .t b { display: block; color: var(--navy); font-size: 16px; }
.top .t span { color: var(--grey); font-size: 12px; }
main { max-width: 640px; margin: 0 auto; padding: 14px 16px; }
.view-title { display: flex; align-items: center; justify-content: space-between; margin: 2px 0 12px; }
.view-title h1 { font-size: 19px; color: var(--navy); margin: 0; }
.view-title small { color: var(--grey); font-size: 13px; }

.tabs { position: fixed; inset: auto 0 0 0; height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: #fff; border-top: 1px solid var(--border); display: flex; z-index: 12; }
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--grey); text-decoration: none; font-size: 11.5px; position: relative; }
.tabs a svg { width: 23px; height: 23px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs a.on { color: var(--navy); font-weight: 700; }
.tabs a .badge { position: absolute; top: 6px; left: calc(50% - 22px); background: var(--danger); color: #fff; border-radius: 10px; font-size: 11px; min-width: 19px; height: 19px; line-height: 19px; text-align: center; padding: 0 5px; font-weight: 700; }

.card { background: #fff; border: 1px solid var(--border); border-radius: 14px; margin-bottom: 14px; overflow: hidden; }
.card > h2 { margin: 0; background: var(--navy); color: #fff; font-size: 15px; padding: 10px 14px; display: flex; align-items: baseline; gap: 8px; }
.card > h2 small { color: #bfd7e8; font-weight: 400; font-size: 12px; }
.card .body { padding: 14px; display: grid; gap: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.muted { color: var(--grey); font-size: 13px; }
.note { background: var(--light); border-radius: 10px; padding: 10px 12px; font-size: 14px; line-height: 1.7; }
.note.warn { background: #fff4e5; color: #6b3d00; }
.note.bad { background: #fdecea; color: #7a1a12; }

label.f { display: grid; gap: 5px; }
label.f > span { font-weight: 700; color: var(--navy); font-size: 14px; }
label.f > span em { font-style: normal; font-weight: 400; color: var(--grey); font-size: 11px; margin-inline-start: 6px; }
input, select, textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 10px; background: #fff;
  padding: 11px 12px; font-size: 16px; outline: none; min-height: 46px;
}
textarea { min-height: 92px; resize: vertical; line-height: 1.6; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(30,127,176,.15); }
input.num, input.ltr { direction: ltr; text-align: right; }
input:disabled { background: var(--light); color: var(--grey); }
.req::after { content: " *"; color: var(--danger); }
.invalid { border-color: var(--danger) !important; }

.seg { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: #fff; min-height: 46px; font-weight: 700; color: var(--grey); }
.seg button.on { background: var(--navy); color: #fff; }
.seg button.urgent { color: var(--danger); }
.seg button.on.urgent { background: var(--danger); color: #fff; }

/* items */
.item { border: 1px solid var(--border); border-radius: 12px; padding: 12px; display: grid; gap: 10px; background: #fbfcfe; }
.item .ih { display: flex; justify-content: space-between; align-items: center; }
.item .ih b { color: var(--navy); font-size: 14px; }
.item .ih button { border: 0; background: none; color: var(--danger); font-size: 13px; padding: 6px 4px; }
.item .row3 { display: grid; grid-template-columns: 1fr 1fr 1.2fr; gap: 8px; }
.item .tot { display: flex; justify-content: space-between; color: var(--grey); font-size: 13px; border-top: 1px dashed var(--border); padding-top: 8px; }
.item .tot b { color: var(--navy); direction: ltr; }
.add { border: 1.5px dashed var(--blue); color: var(--blue); background: #fff; border-radius: 12px; min-height: 48px; font-weight: 700; width: 100%; }
.sums { background: var(--light); border-radius: 12px; padding: 10px 12px; display: grid; gap: 6px; font-size: 14px; }
.sums div { display: flex; justify-content: space-between; }
.sums div b { direction: ltr; }
.sums .g { border-top: 1px solid var(--border); padding-top: 8px; color: var(--navy); font-size: 16px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--grey); }
.check input { width: 20px; height: 20px; min-height: 0; accent-color: var(--navy); }

/* signature */
.sigbox { position: relative; border: 1px solid var(--border); border-radius: 12px; background: #fff; height: 170px; touch-action: none; }
.sigbox canvas { width: 100%; height: 100%; display: block; border-radius: 12px; }
.sigbox .ph { position: absolute; inset: 0; display: grid; place-items: center; color: #aab6c3; pointer-events: none; font-size: 14px; }
.sigbox .base { position: absolute; left: 16px; right: 16px; bottom: 36px; border-bottom: 1px solid var(--line); pointer-events: none; }
.sigbar { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--grey); gap: 8px; }
.sigbar button, .tlink { border: 0; background: none; color: var(--blue); font-weight: 700; padding: 6px 0; font-size: 13px; }
.saved-sig { border: 1px solid var(--border); border-radius: 12px; background: #fff; height: 120px; display: grid; place-items: center; position: relative; }
.saved-sig img { max-height: 96px; max-width: 80%; }
.saved-sig .tag { position: absolute; top: 8px; right: 10px; font-size: 11px; color: var(--ok); font-weight: 700; }

/* buttons + action bar */
.bar { position: fixed; inset: auto 0 calc(var(--tabs-h) + env(safe-area-inset-bottom)) 0; background: #fff; border-top: 1px solid var(--border); padding: 10px 16px; z-index: 10; }
.bar .in { max-width: 640px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.bar .gt { flex: 1; }
.bar .gt span { display: block; font-size: 11px; color: var(--grey); }
.bar .gt b { color: var(--navy); font-size: 18px; direction: ltr; display: inline-block; }
.btn { border: 0; border-radius: 12px; min-height: 50px; padding: 0 20px; font-weight: 700; font-size: 16px; background: var(--navy); color: #fff; }
.btn.alt { background: #fff; color: var(--navy); border: 1px solid var(--border); }
.btn.ok { background: var(--ok); }
.btn.bad { background: #fff; color: var(--danger); border: 1px solid #f1b7b0; }
.btn.block { width: 100%; }
.btn.sm { min-height: 40px; font-size: 14px; padding: 0 14px; border-radius: 10px; }
.btn:disabled { opacity: .55; }
.btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.link { border: 0; background: none; color: var(--grey); font-size: 13px; text-decoration: underline; padding: 8px; display: block; margin: 0 auto 8px; }

/* lists */
.filters { display: flex; gap: 8px; margin-bottom: 12px; }
.filters input { flex: 1; min-height: 42px; }
.filters select { width: auto; min-height: 42px; }
.rq { display: block; background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; margin-bottom: 10px; color: inherit; text-decoration: none; }
.rq .r1 { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.rq .no { direction: ltr; font-weight: 700; color: var(--navy); font-size: 15px; }
.rq .r2 { margin-top: 6px; font-size: 14px; display: flex; justify-content: space-between; gap: 10px; }
.rq .r2 b { direction: ltr; color: var(--navy); white-space: nowrap; }
.rq .r3 { margin-top: 4px; font-size: 12.5px; color: var(--grey); display: flex; justify-content: space-between; gap: 10px; }
.rq.urgent { border-right: 4px solid var(--danger); }
.chip { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 20px; white-space: nowrap; }
.chip.pending { background: #fff4e5; color: var(--warn); }
.chip.returned { background: #fdecea; color: var(--danger); }
.chip.approved { background: #e7f6ec; color: var(--ok); }
.chip.paid { background: #e3eefb; color: var(--navy); }
.chip.cancelled { background: #eceff2; color: var(--grey); }
.empty { text-align: center; color: var(--grey); padding: 40px 16px; font-size: 15px; }
.empty b { display: block; color: var(--navy); font-size: 17px; margin-bottom: 6px; }

/* detail */
.kv { display: grid; grid-template-columns: 112px 1fr; gap: 6px 10px; font-size: 14px; }
.kv dt { color: var(--grey); }
.kv dd { margin: 0; }
.mini-items { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.mini-items td { padding: 7px 4px; border-bottom: 1px solid #e6edf3; vertical-align: top; }
.mini-items td.n { direction: ltr; text-align: left; white-space: nowrap; color: var(--navy); }
.mini-items tr:last-child td { border-bottom: 0; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 22px 14px 0; font-size: 14px; }
.timeline li::before { content: ""; position: absolute; right: 5px; top: 7px; width: 10px; height: 10px; border-radius: 50%; background: var(--blue); }
.timeline li::after { content: ""; position: absolute; right: 9.5px; top: 19px; bottom: 0; width: 1px; background: var(--border); }
.timeline li:last-child::after { display: none; }
.timeline li.wait::before { background: #fff; border: 2px solid var(--warn); }
.timeline li.bad::before { background: var(--danger); }
.timeline li.ok::before { background: var(--ok); }
.timeline small { display: block; color: var(--grey); font-size: 12px; }
.timeline q { display: block; quotes: none; color: var(--ink); background: var(--light); border-radius: 8px; padding: 6px 10px; margin-top: 4px; font-size: 13px; }

/* admin */
.user { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 1px solid #e6edf3; }
.user:last-child { border-bottom: 0; }
.user .u b { display: block; font-size: 14.5px; }
.user .u span { font-size: 12.5px; color: var(--grey); direction: ltr; display: block; text-align: right; }
.user .u i { font-style: normal; font-size: 12px; color: var(--blue); }
.user.off { opacity: .5; }

/* overlays */
.pv { position: fixed; inset: 0; background: rgba(15, 25, 40, .82); z-index: 20; display: none; flex-direction: column; }
.pv.open { display: flex; }
.pv .stage { flex: 1; overflow: auto; padding: 16px; display: flex; justify-content: center; }
.pv .stage img { width: 100%; max-width: 640px; height: auto; background: #fff; box-shadow: 0 8px 30px rgba(0,0,0,.35); align-self: flex-start; }
.pv .acts { background: #fff; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); display: flex; gap: 10px; justify-content: center; }
.pv .acts .btn { flex: 1; max-width: 220px; }
.sheet-modal { position: fixed; inset: 0; background: rgba(15,25,40,.5); z-index: 25; display: flex; align-items: flex-end; justify-content: center; }
.sheet-modal .panel { background: #fff; width: 100%; max-width: 640px; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); display: grid; gap: 12px; max-height: 92vh; overflow: auto; }
.sheet-modal h3 { margin: 0; color: var(--navy); font-size: 17px; }
.toast { position: fixed; top: calc(16px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 30; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: calc(100% - 32px); text-align: center; }
.toast.show { opacity: 1; }
.loading { text-align: center; color: var(--grey); padding: 40px; }

/* ---------- A4 sheet (what becomes the PDF) ---------- */
#sheetWrap { position: fixed; left: -10000px; top: 0; }
.sheet { width: 794px; height: 1123px; background: #fff; padding: 35px 57px 0; position: relative; color: #000; font-size: 12px; line-height: 1.45; font-family: "Plex"; direction: rtl; }
.sheet table { width: 680px; border-collapse: collapse; table-layout: fixed; }
.sheet td { vertical-align: top; }
.sh-head { display: flex; justify-content: space-between; align-items: center; height: 80px; }
.sh-head img { width: 150px; height: 72px; }
.sh-head .meta { direction: ltr; text-align: left; color: var(--grey); font-size: 10px; line-height: 2.1; }
.sh-head .meta b { color: var(--navy); font-size: 10.7px; }
.sh-head .meta .d { color: #000; font-size: 12px; }
.sh-title { background: var(--blue); color: #fff; text-align: center; padding: 6px 10px 7px; margin-top: 10px; }
.sh-title b { font-size: 17.3px; }
.sh-title span { color: #e3f0f8; font-size: 12.6px; margin-right: 18px; }
.sec { margin-top: 9px; }
.sheet .bar-s { background: var(--navy); color: #fff; padding: 3px 9px 4px; font-weight: 700; font-size: 12.6px; }
.bar-s span { color: #bfd7e8; font-weight: 400; font-size: 10px; margin-right: 14px; }
.sheet .fc { border: 1px solid var(--border); padding: 3px 8px 4px; }
.lb b { color: var(--navy); }
.lb span { color: var(--grey); font-size: 10px; margin-right: 10px; }
.val { border-bottom: 1px solid var(--line); min-height: 22px; margin-top: 7px; padding-bottom: 1px; font-size: 12.5px; }
.val.ltr { direction: ltr; text-align: right; }
.box { font-family: "Segoe UI Symbol", "Arial Unicode MS", sans-serif; color: var(--navy); font-size: 14px; margin-left: 3px; }
.it th { background: var(--light); border: 1px solid var(--border); padding: 4px 3px; text-align: center; vertical-align: middle; font-weight: 400; }
.it th b { display: block; color: var(--navy); font-size: 11px; }
.it th span { display: block; color: var(--grey); font-size: 8.7px; }
.it td { border: 1px solid var(--border); padding: 3px 6px; vertical-align: middle; font-size: 11.5px; }
.it td.n { text-align: center; color: var(--grey); }
.it td.m { direction: ltr; text-align: center; }
.it td.mr { direction: ltr; text-align: left; }
.it tr.s td { height: 25px; }
.it tr.s td.l { text-align: left; }
.it tr.s td.l b { color: var(--navy); }
.it tr.s td.l span { color: var(--grey); font-size: 9.3px; margin-right: 8px; }
.it tr.s.g td { background: var(--light); }
.it tr.s.g td.l b { font-size: 12.5px; }
.it .cur { color: var(--grey); font-size: 8.7px; margin-left: 4px; }
.just { white-space: pre-wrap; line-height: 26px; background-image: linear-gradient(to bottom, transparent 25px, var(--line) 25px); background-size: 100% 26px; min-height: 52px; margin-top: 3px; font-size: 12px; }
.sg td.c { border: 1px solid var(--border); padding: 7px 14px 9px; width: 340px; }
.sg .hd { display: flex; align-items: baseline; justify-content: space-between; border-bottom: 1px solid #e3eaf1; padding-bottom: 5px; }
.sg .hd b { color: var(--navy); font-size: 12.5px; }
.sg .hd span { color: var(--grey); font-size: 9.3px; }
.sg .dec { display: flex; gap: 22px; margin-top: 7px; font-size: 10.7px; align-items: center; height: 20px; }
.sg .dec b { color: var(--navy); }
.sg .dec small { color: var(--grey); font-size: 8px; margin-right: 4px; }
.sg .box { font-size: 14px; margin-left: 4px; display: inline-block; width: 13px; text-align: center; }
.sg .box.on { color: var(--ok); }
.sg .ack { color: var(--grey); font-size: 9.3px; margin-top: 7px; height: 20px; display: flex; align-items: center; }
.sg .ack i { font-size: 8px; margin-right: 6px; }
.sg .ln { border-bottom: 1px solid var(--line); margin-top: 10px; color: var(--grey); font-size: 9.3px; height: 24px; position: relative; display: flex; align-items: flex-end; gap: 5px; padding-bottom: 2px; white-space: nowrap; }
.sg .ln small { font-size: 8px; }
.sg .ln .v { color: #000; font-size: 11.5px; flex: 1; text-align: center; height: 18px; overflow: hidden; }
.sg .two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.sg .ln img { position: absolute; left: 6px; bottom: 1px; height: 38px; max-width: 120px; object-fit: contain; }
.sh-foot { position: absolute; left: 57px; right: 57px; bottom: 30px; border-top: 1px solid #d5dde5; padding-top: 5px; text-align: center; color: var(--grey); font-size: 8.7px; }
.sh-foot i { margin-right: 8px; }
.sh-foot .e { display: block; margin-top: 2px; font-size: 8px; color: #8a9199; }
