:root {
  --bg: #f3f5f4; --card: #fff; --ink: #14201d; --muted: #63736f; --line: #dfe5e3;
  --brand: #0f5c4d; --brand-ink: #fff; --brand-soft: #e3f1ed;
  --new: #6b7280; --assigned: #2563eb; --out: #c2410c; --delivered: #15803d; --failed: #b91c1c;
  --radius: 14px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif; }
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }

.top { position: sticky; top: 0; z-index: 5; background: var(--brand); color: var(--brand-ink); padding: 10px 16px; display: flex; align-items: center; gap: 10px; }
.top h1 { font-size: 18px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .who { font-size: 13px; opacity: .85; }
.top button { background: rgba(255,255,255,.15); color: inherit; border: 0; border-radius: 8px; padding: 6px 10px; cursor: pointer; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 16px; }

.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 14px; padding-bottom: 2px; }
.tab { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 14px; cursor: pointer; white-space: nowrap; display: flex; gap: 6px; align-items: center; }
.tab.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.tab b { font-variant-numeric: tabular-nums; background: rgba(0,0,0,.08); border-radius: 999px; padding: 0 7px; font-size: 13px; }
.tab.on b { background: rgba(255,255,255,.22); }

.bar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.bar input { flex: 1; min-width: 180px; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
textarea { min-height: 70px; resize: vertical; }
label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 12px; }
label > span { display: block; margin-bottom: 4px; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--ink); }
label.check input { width: auto; }

.btn { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 10px 14px; cursor: pointer; text-decoration: none; color: var(--ink); display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-weight: 600; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--failed); border-color: #f0c9c9; }
.btn.big { width: 100%; padding: 14px; font-size: 17px; }
.btn.sm { padding: 6px 10px; font-size: 14px; font-weight: 500; }
.btn:disabled { opacity: .5; cursor: default; }

.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.card.click { cursor: pointer; }
.card.click:hover { border-color: var(--brand); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.ref { font-weight: 700; font-size: 15px; direction: ltr; unicode-bidi: isolate; }
.cust { font-size: 17px; font-weight: 600; }
.muted { color: var(--muted); font-size: 14px; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.badge { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; color: #fff; white-space: nowrap; }
.badge.new { background: var(--new); } .badge.assigned { background: var(--assigned); } .badge.out { background: var(--out); }
.badge.delivered { background: var(--delivered); } .badge.failed { background: var(--failed); }
.actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)); gap: 8px; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.note { background: #fff8e1; border-radius: 10px; padding: 8px 10px; font-size: 14px; }
.warn { color: var(--failed); font-size: 14px; }

.overlay { position: fixed; inset: 0; background: rgba(10,20,18,.5); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--card); width: 100%; max-width: 560px; max-height: 94vh; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
@media (min-width: 640px) { .overlay { align-items: center; } .sheet { border-radius: 18px; } }
.sheet h2 { font-size: 19px; margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.sheet h3 { font-size: 14px; color: var(--muted); margin: 16px 0 8px; text-transform: uppercase; letter-spacing: .04em; }
.x { border: 0; background: var(--bg); border-radius: 999px; width: 34px; height: 34px; cursor: pointer; font-size: 18px; flex: none; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 15px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; overflow-wrap: anywhere; }
.proof { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.proof img { width: 100%; border-radius: 10px; border: 1px solid var(--line); background: #fff; display: block; }
.code { font-size: 26px; font-weight: 800; letter-spacing: .25em; direction: ltr; }

.sig { border: 2px dashed var(--line); border-radius: 12px; background: #fff; width: 100%; height: 170px; touch-action: none; display: block; }
.preview { width: 100%; max-height: 220px; object-fit: contain; border-radius: 10px; border: 1px solid var(--line); margin-top: 8px; }
.step { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 12px; }
.step > b { display: block; margin-bottom: 8px; }
.step.ok { border-color: var(--delivered); background: #f3faf5; }

.auth { max-width: 380px; margin: 8vh auto; padding: 16px; }
.auth .card { padding: 22px; }
.auth h1 { font-size: 24px; margin-bottom: 4px; }
.auth .lang { text-align: center; margin-top: 14px; }
.linkbtn { background: none; border: 0; color: var(--brand); cursor: pointer; text-decoration: underline; }

#toast { position: fixed; inset-inline: 16px; bottom: 20px; margin: 0 auto; max-width: 420px; background: #14201d; color: #fff; padding: 12px 16px; border-radius: 12px; text-align: center; z-index: 40; opacity: 0; pointer-events: none; transition: opacity .2s; }
#toast.show { opacity: 1; }
table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: start; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 15px; }
th { color: var(--muted); font-size: 13px; font-weight: 600; }
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }

/* ---- Version 2 ---- */
.badge.urgent { background: #dc2626; } .badge.late { background: #7c2d12; } .badge.partial { background: #a16207; }
.card.hot { border-color: #f1a5a5; box-shadow: inset 4px 0 0 #dc2626; }
[dir=rtl] .card.hot { box-shadow: inset -4px 0 0 #dc2626; }
.cod { background: #ecfdf3; border-radius: 10px; padding: 8px 10px; font-size: 15px; }
.stop { background: var(--brand); color: #fff; border-radius: 999px; min-width: 26px; height: 26px; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; }
select.narrow { width: auto; flex: none; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 0 10px; }
.itemrow { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.itemrow .iname { flex: 1; min-width: 0; }
.itemrow .iqty, .itemrow .dqty { width: 84px; flex: none; text-align: center; }
label.inline { display: flex; align-items: center; gap: 6px; margin: 0; }
label.inline > span { margin: 0; white-space: nowrap; }
label.inline input { width: auto; }
.map { height: 58vh; min-height: 320px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--card); overflow: hidden; z-index: 0; }
.truck { transform: translate(-50%, -100%); white-space: nowrap; font-size: 22px; display: inline-flex; flex-direction: column; align-items: center; filter: grayscale(1); width: max-content; }
.truck.live { filter: none; }
.truck span { font-size: 12px; font-weight: 700; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 0 5px; color: var(--ink); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #c3cbc9; }
.dot.live { background: #16a34a; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 6px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.tile span { display: block; color: var(--muted); font-size: 13px; }
.tile b { font-size: 24px; }
h3.sec { font-size: 15px; margin: 18px 0 8px; }
.steps { list-style: none; padding: 0; margin: 6px 0; }
.steps li { position: relative; padding: 0 0 16px; padding-inline-start: 30px; color: var(--muted); }
.steps li b { display: block; font-weight: 600; }
.steps li::before { content: ''; position: absolute; inset-inline-start: 4px; top: 4px; width: 14px; height: 14px; border-radius: 50%; background: var(--line); }
.steps li::after { content: ''; position: absolute; inset-inline-start: 10px; top: 20px; bottom: 0; width: 2px; background: var(--line); }
.steps li:last-child::after { display: none; }
.steps li.done { color: var(--ink); } .steps li.done::before, .steps li.done::after { background: var(--delivered); }
.steps li.now::before { box-shadow: 0 0 0 4px #cdebd8; }

/* ---- Version 3: customers ---- */
.suggestwrap { position: relative; margin-bottom: 12px; }
.suggest { position: absolute; inset-inline: 0; top: 2px; z-index: 5; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.14); max-height: 280px; overflow-y: auto; }
.suggest button { display: block; width: 100%; text-align: start; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 9px 12px; cursor: pointer; }
.suggest button:last-child { border-bottom: 0; }
.suggest button:hover, .suggest button:focus { background: var(--brand-soft); }
.suggest button b, .suggest button span.muted { display: block; }
.btn.sm.primary { color: var(--brand-ink); }

/* ---- Version 4: home screen with app tiles ---- */
body.home { background: linear-gradient(135deg, #e4e7f1 0%, #f2f1f7 48%, #e6e9f2 100%) fixed; min-height: 100vh; }
.top.clear { background: transparent; color: var(--ink); }
.top.clear button { background: rgba(255,255,255,.7); }
.homebtn { display: inline-flex; align-items: center; justify-content: center; padding: 7px !important; }
.launcher { display: grid; grid-template-columns: repeat(auto-fit, 116px); justify-content: center; gap: 30px 20px; max-width: 860px; margin: 7vh auto 0; }
.app { background: none; border: 0; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 4px; border-radius: 12px; }
.app .ico { position: relative; width: 76px; height: 76px; border-radius: 16px; background: #fff; display: grid; place-items: center; box-shadow: 0 1px 2px rgba(30,35,70,.12), 0 6px 16px rgba(30,35,70,.08); transition: transform .15s, box-shadow .15s; }
.app:hover .ico, .app:focus-visible .ico { transform: translateY(-3px); box-shadow: 0 2px 4px rgba(30,35,70,.14), 0 12px 24px rgba(30,35,70,.14); }
.app .lbl { font-size: 15px; color: var(--ink); text-align: center; }
.app .n { position: absolute; top: -7px; inset-inline-end: -7px; min-width: 24px; height: 24px; padding: 0 6px; border-radius: 999px; background: #dc2626; color: #fff; font-size: 13px; display: grid; place-items: center; }
@media (max-width: 480px) { .launcher { grid-template-columns: repeat(3, 1fr); gap: 24px 8px; margin-top: 5vh; } }

/* ---- Version 5: push notifications ---- */
.pushcard { max-width: 560px; margin: 8vh auto 0; background: #fff; border-radius: var(--radius); padding: 14px 16px; display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; box-shadow: 0 1px 2px rgba(30,35,70,.12), 0 6px 16px rgba(30,35,70,.08); }
.pushline { max-width: 560px; margin: 8vh auto 0; text-align: center; }

/* ---- Version 6: scan a delivery PDF ---- */
.scanrow { margin-bottom: 10px; gap: 6px; }
.scanrow.isdone { opacity: .6; }
.rawtext { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; background: var(--bg); border-radius: 10px; padding: 10px; max-height: 260px; overflow: auto; direction: ltr; text-align: start; }

/* ---- Version 7: welcome page ---- */
.welcome { max-width: 760px; margin: 0 auto; padding: 4vh 20px 40px; text-align: center; }
.wlogo { border-radius: 20px; box-shadow: 0 2px 4px rgba(30,35,70,.14), 0 12px 28px rgba(30,35,70,.16); }
.welcome h1 { font-size: clamp(34px, 6vw, 46px); line-height: 1.15; margin: 18px 0 4px; letter-spacing: -.01em; }
.wcompany { color: var(--brand); font-weight: 600; }
.wlead { font-size: 18px; color: var(--muted); max-width: 520px; margin: 14px auto 24px; }
.wgo { max-width: 280px; }
.wpoints { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin: 40px 0 26px; text-align: start; }
.wpoint { background: #fff; border-radius: var(--radius); padding: 16px; display: flex; gap: 12px; align-items: flex-start; box-shadow: 0 1px 2px rgba(30,35,70,.1), 0 6px 16px rgba(30,35,70,.06); }
.wpoint .ico { flex: none; width: 52px; height: 52px; border-radius: 12px; background: var(--bg); display: grid; place-items: center; }
.wpoint .ico svg { width: 32px; height: 32px; }
.wpoint p { margin-top: 2px; }
.wfoot { font-size: 13px; }
