:root {
  --orange: #F77D2A;
  --orange-dark: #d9631a;
  --orange-soft: #fff1e7;
  --ink: #111;
  --ink-2: #4a4d55;
  --muted: #8a8f98;
  --line: #e6e7ea;
  --bg: #f4f4f6;
  --card: #fff;
  --red: #d63a2f;
  --red-soft: #fdecea;
  --amber: #c98a00;
  --amber-soft: #fff6dc;
  --green: #239a55;
  --green-soft: #e6f6ec;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 10px rgba(0,0,0,.04);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", sans-serif; }
body { padding-bottom: calc(70px + var(--safe-bottom)); }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: #fff; border-bottom: 3px solid var(--orange); padding: calc(8px + var(--safe-top)) 12px 8px; display: flex; align-items: center; gap: 10px; min-height: 58px; }
.topbar .logo { height: 38px; }
.topbar .back { border: 0; background: none; padding: 6px 8px 6px 0; font-size: 26px; line-height: 1; cursor: pointer; }
.topbar .title { flex: 1; min-width: 0; }
.topbar .title b { display: block; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title small { color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .actions { display: flex; gap: 4px; }
.icon-btn { border: 0; background: none; width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; cursor: pointer; font-size: 20px; }
.icon-btn:hover { background: var(--bg); }
.icon-btn svg { width: 22px; height: 22px; }

main { max-width: 980px; margin: 0 auto; padding: 14px 12px 24px; }

/* ---------- bottom nav ---------- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: #111; display: flex; padding-bottom: var(--safe-bottom); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 9px; color: #9a9ca3; font-size: 11px; font-weight: 600; letter-spacing: .02em; position: relative; }
.tabbar a svg { width: 22px; height: 22px; }
.tabbar a.on { color: var(--orange); }
.tabbar .badge { position: absolute; top: 4px; left: calc(50% + 6px); background: var(--red); color: #fff; border-radius: 9px; min-width: 18px; height: 18px; font-size: 11px; display: grid; place-items: center; padding: 0 5px; }

/* ---------- generic ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; }
.card.flush { padding: 0; overflow: hidden; }
.section-h { display: flex; align-items: center; justify-content: space-between; margin: 18px 2px 8px; }
.section-h h2 { font-size: 1.02rem; color: var(--ink); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.right { text-align: right; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty b { display: block; color: var(--ink); font-size: 1.05rem; margin-bottom: 4px; }
.hidden { display: none !important; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1.5px solid var(--line); background: #fff; border-radius: 11px; padding: 10px 14px; font-weight: 600; cursor: pointer; min-height: 44px; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn.primary { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn.primary:active { background: var(--orange-dark); }
.btn.dark { background: #111; border-color: #111; color: #fff; }
.btn.danger { color: var(--red); border-color: #f3c5c1; }
.btn.sm { min-height: 34px; padding: 6px 10px; font-size: .88rem; border-radius: 9px; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; }

.fab { position: fixed; right: 16px; bottom: calc(82px + var(--safe-bottom)); z-index: 25; background: var(--orange); color: #fff; border: 0; border-radius: 28px; height: 56px; padding: 0 20px 0 16px; font-weight: 700; font-size: 1rem; box-shadow: 0 6px 18px rgba(247,125,42,.45); display: flex; align-items: center; gap: 6px; cursor: pointer; }
.fab svg { width: 22px; height: 22px; }

.chip { display: inline-flex; align-items: center; gap: 4px; border-radius: 20px; padding: 2px 9px; font-size: .78rem; font-weight: 700; background: var(--bg); color: var(--ink-2); white-space: nowrap; }
.chip.overdue { background: var(--red-soft); color: var(--red); }
.chip.urgent { background: #ffe6d6; color: #c24f0c; }
.chip.soon { background: var(--amber-soft); color: var(--amber); }
.chip.ok { background: var(--green-soft); color: var(--green); }
.chip.done { background: #111; color: #fff; }
.chip.orange { background: var(--orange-soft); color: var(--orange-dark); }

.bar { height: 8px; background: #ececef; border-radius: 8px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--orange); border-radius: 8px; }
.bar.green > i { background: var(--green); }

/* ---------- lists ---------- */
.list { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 12px; }
.li { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.li:last-child { border-bottom: 0; }
.li:active { background: #fafafa; }
.li .av { width: 40px; height: 40px; border-radius: 12px; background: var(--orange-soft); color: var(--orange-dark); display: grid; place-items: center; font-weight: 800; flex: none; }
.li .av.dark { background: #111; color: #fff; }
.li .av.done { background: var(--green-soft); color: var(--green); }
.li .main { flex: 1; min-width: 0; }
.li .main b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li .main .sub { color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li .main .bar { margin-top: 6px; }
.li .end { text-align: right; flex: none; font-size: .85rem; }
.chev { color: #c4c6cc; font-size: 20px; }

/* ---------- dashboard ---------- */
.hero { background: #111; border-left: 6px solid var(--orange); color: #fff; border-radius: var(--radius); padding: 16px; margin-bottom: 12px; position: relative; overflow: hidden; }
.hero .big { font-size: 2.2rem; font-weight: 800; line-height: 1; }
.hero .bar { background: #333; margin-top: 10px; }
.hero small { color: #bbb; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; }
.stat .n { font-size: 1.6rem; font-weight: 800; }
.stat .l { color: var(--muted); font-size: .82rem; font-weight: 600; }
.stat .s { font-size: .8rem; color: var(--ink-2); }
.status-strip { display: flex; height: 12px; border-radius: 8px; overflow: hidden; background: #ececef; margin: 8px 0; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .82rem; color: var(--ink-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

.alert { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 12px; margin-bottom: 8px; cursor: pointer; border-left: 5px solid; background: #fff; box-shadow: var(--shadow); }
.alert.overdue { border-color: var(--red); background: var(--red-soft); }
.alert.urgent { border-color: #e8650f; background: #fff0e5; }
.alert.soon { border-color: var(--amber); background: var(--amber-soft); }
.alert.ok { border-color: var(--green); }
.alert .d svg { width: 24px; height: 24px; }
.alert .d { font-weight: 800; font-size: 1.25rem; text-align: center; min-width: 52px; line-height: 1.05; }
.alert .d small { display: block; font-size: .72rem; font-weight: 700; }

/* ---------- forms ---------- */
.field { margin-bottom: 12px; }
.field label, .lbl { display: block; font-weight: 600; font-size: .85rem; color: var(--ink-2); margin-bottom: 4px; }
input, select, textarea { width: 100%; font: inherit; color: inherit; border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; min-height: 44px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--orange); box-shadow: 0 0 0 3px rgba(247,125,42,.15); }
textarea { min-height: 80px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 10px; }
.check { display: flex; align-items: center; gap: 10px; padding: 8px 0; font-weight: 600; }
.check input { width: 22px; height: 22px; min-height: 0; accent-color: var(--orange); }
.seg { display: flex; background: var(--bg); border-radius: 11px; padding: 3px; gap: 3px; overflow-x: auto; }
.seg button { flex: 1; border: 0; background: none; padding: 8px 10px; border-radius: 9px; font-weight: 600; font-size: .88rem; color: var(--ink-2); cursor: pointer; white-space: nowrap; }
.seg button.on { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.search { position: relative; margin-bottom: 10px; }
.search input { padding-left: 38px; }
.search svg { position: absolute; left: 12px; top: 12px; width: 20px; height: 20px; color: var(--muted); }

/* ---------- measurements ---------- */
.mgrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 560px) { .mgrid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 860px) { .mgrid { grid-template-columns: repeat(4, 1fr); } }
.mcard { background: #fff; border-radius: 12px; box-shadow: var(--shadow); padding: 10px; display: flex; flex-direction: column; gap: 6px; border: 2px solid transparent; }
.mcard.filled { border-color: #ffd9bf; }
.mcard .dg { width: 100%; height: 104px; cursor: pointer; }
.mcard .name { font-weight: 700; font-size: .9rem; line-height: 1.2; }
.mcard .hint { font-size: .74rem; color: var(--muted); line-height: 1.25; min-height: 1.9em; }
.mcard .inp { display: flex; align-items: center; gap: 6px; }
.mcard .inp input { text-align: center; font-size: 1.2rem; font-weight: 700; padding: 6px; }
.mcard .inp span { font-size: .75rem; color: var(--muted); font-weight: 600; }
.posture { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.posture label { background: #fff; border-radius: 12px; box-shadow: var(--shadow); padding: 8px; text-align: center; font-size: .75rem; font-weight: 600; cursor: pointer; border: 2px solid transparent; }
.posture label.on { border-color: var(--orange); background: var(--orange-soft); }
.posture img { width: 100%; height: 90px; object-fit: contain; }
.posture input { display: none; }

/* ---------- items ---------- */
.item { background: #fff; border-radius: 12px; box-shadow: var(--shadow); padding: 12px; margin-bottom: 10px; }
.item .top { display: flex; align-items: center; gap: 10px; }
.item .gi { width: 44px; height: 52px; flex: none; }
.item .gi .dg { width: 44px; height: 52px; }
.steps { display: flex; gap: 4px; margin-top: 10px; }
.steps button { flex: 1; border: 0; padding: 8px 2px; border-radius: 8px; background: var(--bg); font-size: .72rem; font-weight: 700; color: var(--muted); cursor: pointer; }
.steps button.on { color: #fff; }
.steps button.past { color: var(--ink-2); background: #e9e9ec; }

.gpick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (min-width: 560px) { .gpick { grid-template-columns: repeat(5, 1fr); } }
.gpick button { border: 2px solid var(--line); background: #fff; border-radius: 12px; padding: 8px 4px; font-weight: 700; font-size: .82rem; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.gpick button.on { border-color: var(--orange); background: var(--orange-soft); }
.gpick .dg { width: 40px; height: 48px; }
.gpick .ph { width: 40px; height: 48px; display: grid; place-items: center; font-size: 22px; }

/* ---------- sheet / modal ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { background: #fff; width: 100%; max-width: 620px; max-height: 92vh; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 8px 16px calc(16px + var(--safe-bottom)); animation: up .2s ease-out; }
@media (min-width: 700px) { .sheet-bg { align-items: center; } .sheet { border-radius: 18px; } }
.sheet .grip { width: 40px; height: 5px; background: #ddd; border-radius: 3px; margin: 4px auto 10px; }
.sheet h2 { margin-bottom: 12px; }
.sheet .foot { position: sticky; bottom: calc(-16px - var(--safe-bottom)); background: #fff; padding: 12px 0 calc(4px); margin-top: 8px; border-top: 1px solid var(--line); }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.toast { position: fixed; left: 50%; bottom: calc(150px + var(--safe-bottom)); transform: translateX(-50%); background: #111; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 60; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,.25); animation: fade .2s; max-width: 90vw; }

.howto { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: center; }
.howto .dg { width: 100%; height: 180px; }
.howto img { width: 100%; max-height: 200px; object-fit: contain; }
.howto figcaption { text-align: center; font-size: .75rem; color: var(--muted); }

.money { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; gap: 6px; }
.money div { background: var(--bg); border-radius: 10px; padding: 8px 4px; }
.money b { display: block; font-size: 1.05rem; }
.money small { color: var(--muted); font-weight: 600; font-size: .78rem; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: .9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }

/* ---------- print (job order card) ---------- */
#print-root { display: none; }
@media print {
  body { background: #fff; padding: 0; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block; }
}
.jo { font: 12px/1.35 system-ui, sans-serif; color: #000; page-break-after: always; padding: 8mm; }
.jo .head { display: flex; justify-content: space-between; align-items: center; border-bottom: 3px solid var(--orange); padding-bottom: 6px; margin-bottom: 8px; }
.jo .head img { height: 56px; }
.jo table { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
.jo td, .jo th { border: 1px solid #333; padding: 4px 6px; text-align: left; vertical-align: top; }
.jo .mt { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.jo .mt div { border: 1px solid #333; text-align: center; padding: 2px; }
.jo .mt svg { width: 52px; height: 62px; display: block; margin: 0 auto; }
.jo .mt b { display: block; font-size: 14px; }
.jo .mt small { font-size: 9px; }
