:root {
  --bg: #f5f5f7; --card: #fff; --ink: #1d1d1f; --mute: #6e6e73; --line: #e5e5ea;
  --blue: #0071e3; --blue-ink: #fff; --green: #248a3d; --red: #d70015; --orange: #c93400;
  --soft: #f2f2f7; --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Noto Sans Arabic", sans-serif;
  padding-top: var(--safe-t);
}
[dir="rtl"] body { font-family: -apple-system, "SF Arabic", "Noto Sans Arabic", "Segoe UI", sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.hide { display: none !important; }

/* layout */
header.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; background: rgba(245, 245, 247, .86); backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px); border-bottom: .5px solid var(--line);
}
header.top h1 { flex: 1; margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -.01em; }
header.top .back { border: 0; background: none; color: var(--blue); font-size: 17px; padding: 4px 0; cursor: pointer; }
main { max-width: 760px; margin: 0 auto; padding: 14px 16px calc(96px + var(--safe-b)); }
h2 { font-size: 28px; letter-spacing: -.02em; margin: 6px 0 14px; }
h3 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--mute); margin: 22px 4px 8px; }
[dir="rtl"] h3 { text-transform: none; letter-spacing: 0; }

nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex;
  background: rgba(250, 250, 252, .92); backdrop-filter: saturate(180%) blur(18px); -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-top: .5px solid var(--line); padding-bottom: var(--safe-b);
}
nav.tabs button {
  flex: 1; border: 0; background: none; padding: 7px 2px 6px; font-size: 10.5px; color: var(--mute);
  display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; min-height: 52px;
}
nav.tabs button svg { width: 25px; height: 25px; }
nav.tabs button[aria-current="page"] { color: var(--blue); }

/* blocks */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: .5px solid var(--line);
  background: none; border-left: 0; border-right: 0; border-top: 0; width: 100%; text-align: start; cursor: pointer;
}
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .t { font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.row .s { font-size: 13px; color: var(--mute); }
.row .chev { color: #c7c7cc; }
[dir="rtl"] .row .chev { transform: scaleX(-1); }
.row img { width: 52px; height: 52px; border-radius: 10px; object-fit: contain; background: #fff; border: 1px solid var(--line); flex: none; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.kpi { background: var(--card); border-radius: var(--radius); padding: 14px 16px; }
.kpi .l { font-size: 13px; color: var(--mute); }
.kpi .v { font-size: 24px; font-weight: 600; letter-spacing: -.02em; margin-top: 2px; }
.kpi .v small { font-size: 14px; font-weight: 500; color: var(--mute); }
.bar { height: 8px; border-radius: 4px; background: var(--soft); overflow: hidden; margin-top: 10px; }
.bar > i { display: block; height: 100%; background: var(--blue); border-radius: 4px; }
.bar.ok > i { background: var(--green); }
.muted { color: var(--mute); }
.small { font-size: 13px; }
.note { font-size: 14px; color: var(--mute); margin: 8px 4px; }
.note.ok { color: var(--green); }
.note.bad { color: var(--red); }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 99px; background: var(--soft); color: var(--mute); white-space: nowrap; }
.pill.new { background: #e8f1fd; color: var(--blue); }
.pill.sent { background: #fff4e5; color: var(--orange); }
.pill.done { background: #e9f7ec; color: var(--green); }
.pill.off { background: #fdecee; color: var(--red); }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; display: inline-block; }

/* controls */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 50px; border: 0;
  border-radius: 12px; background: var(--blue); color: var(--blue-ink); font-size: 17px; font-weight: 600; cursor: pointer; padding: 0 16px;
}
.btn.ghost { background: var(--soft); color: var(--blue); }
.btn.danger { background: #fdecee; color: var(--red); }
.btn.green { background: var(--green); }
.btn.sm { min-height: 38px; font-size: 15px; width: auto; border-radius: 10px; padding: 0 14px; }
.btn[disabled] { opacity: .45; }
.btns { display: flex; gap: 10px; margin-top: 12px; }
.btns > * { flex: 1; }
.stack > * + * { margin-top: 10px; }
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 13px; color: var(--mute); margin: 0 4px 6px; }
input.i, select.i, textarea.i {
  width: 100%; min-height: 48px; border: 1px solid var(--line); border-radius: 12px; background: #fff; padding: 10px 14px; font-size: 17px;
  -webkit-appearance: none; appearance: none;
}
textarea.i { min-height: 80px; resize: vertical; }
input.i:focus, select.i:focus, textarea.i:focus { outline: 0; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0,113,227,.15); }
.seg { display: flex; background: var(--soft); border-radius: 10px; padding: 3px; gap: 3px; margin-bottom: 12px; }
.seg button { flex: 1; border: 0; background: none; border-radius: 8px; padding: 8px 6px; font-size: 14px; font-weight: 500; cursor: pointer; color: var(--ink); }
.seg button[aria-pressed="true"] { background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { flex: none; border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 7px 14px; font-size: 14px; cursor: pointer; }
.chips button[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.choice { display: grid; gap: 8px; }
.choice button {
  border: 1.5px solid var(--line); background: #fff; border-radius: 12px; padding: 13px 14px; font-size: 16px; text-align: start; cursor: pointer;
}
.choice button[aria-pressed="true"] { border-color: var(--blue); background: #f0f6fe; color: var(--blue); font-weight: 600; }
.qty { display: flex; align-items: center; gap: 10px; }
.qty button { width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--soft); color: var(--blue); font-size: 24px; cursor: pointer; flex: none; }
.qty input { text-align: center; font-size: 20px; font-weight: 600; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.switch input { width: 51px; height: 31px; -webkit-appearance: none; appearance: none; background: #e9e9eb; border-radius: 99px; position: relative; cursor: pointer; flex: none; transition: background .2s; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.2); transition: transform .2s; }
.switch input:checked { background: #34c759; }
.switch input:checked::after { transform: translateX(20px); }
.search { position: relative; margin-bottom: 12px; }
.search input { padding-inline-start: 40px; background: #e9e9ee; border-color: transparent; min-height: 42px; font-size: 16px; }
.search svg { position: absolute; inset-inline-start: 12px; top: 11px; width: 20px; height: 20px; color: var(--mute); }

/* catalogue */
.fams { display: grid; gap: 12px; }
.fam { border: 0; border-radius: 20px; padding: 26px 20px; text-align: start; cursor: pointer; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.fam b { display: block; font-size: 22px; letter-spacing: -.02em; }
.fam span { color: var(--mute); font-size: 14px; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); } }
.prod { background: #fff; border-radius: var(--radius); padding: 10px; border: 0; text-align: start; cursor: pointer; display: flex; flex-direction: column; gap: 6px; }
.prod .ph { aspect-ratio: 1; border-radius: 12px; background: #fff; border: 1px solid var(--line); overflow: hidden; display: flex; }
.prod .ph img { width: 100%; height: 100%; object-fit: contain; }
.prod .n { font-size: 14px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.prod .p { font-size: 15px; font-weight: 600; }
.prod.off { opacity: .5; }
.big-ph { width: 100%; aspect-ratio: 1.2; object-fit: contain; background: #fff; border-radius: var(--radius); border: 1px solid var(--line); }
table.tiers { width: 100%; border-collapse: collapse; font-size: 15px; }
table.tiers td { padding: 7px 4px; border-bottom: .5px solid var(--line); }
table.tiers td:last-child { text-align: end; font-weight: 600; }
table.tiers tr.on td { color: var(--blue); }
.tot { display: flex; justify-content: space-between; padding: 6px 0; gap: 10px; }
.tot.big { font-size: 20px; font-weight: 700; border-top: .5px solid var(--line); margin-top: 6px; padding-top: 10px; }
.cartbtn { position: fixed; inset-inline-end: 16px; bottom: calc(68px + var(--safe-b)); z-index: 25; border: 0; border-radius: 99px; background: var(--blue); color: #fff; font-weight: 600; padding: 12px 18px; box-shadow: 0 6px 20px rgba(0,113,227,.35); cursor: pointer; }

/* sheet */
.sheet-bg { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.32); display: flex; align-items: flex-end; justify-content: center; animation: fade .2s; }
.sheet {
  background: var(--bg); width: 100%; max-width: 760px; max-height: 92vh; overflow-y: auto; border-radius: 16px 16px 0 0;
  padding: 8px 16px calc(24px + var(--safe-b)); animation: up .25s cubic-bezier(.2,.8,.2,1);
}
.sheet .grab { width: 36px; height: 5px; border-radius: 3px; background: #c7c7cc; margin: 4px auto 10px; }
.sheet h2 { font-size: 22px; margin: 4px 0 12px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%); z-index: 80; background: rgba(29,29,31,.92); color: #fff; padding: 11px 18px; border-radius: 14px; font-size: 15px; max-width: 88vw; text-align: center; }
.map { height: 340px; border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; background: #e9e9ee; z-index: 0; }
.map.mini { height: 180px; }
.leaflet-popup-content { font: 14px/1.4 -apple-system, sans-serif; }
.pin { width: 18px; height: 18px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
table.stats { width: 100%; border-collapse: collapse; font-size: 14px; }
table.stats th { text-align: start; font-weight: 600; color: var(--mute); font-size: 12px; padding: 6px 4px; }
table.stats td { padding: 8px 4px; border-top: .5px solid var(--line); vertical-align: top; }
.scroll-x { overflow-x: auto; }
.login { max-width: 400px; margin: 8vh auto 0; }
.login .logo { width: 64px; height: 64px; border-radius: 16px; display: block; margin: 0 auto 16px; }
.login h2 { text-align: center; }
.receipt { white-space: pre-wrap; font: 14px/1.45 ui-monospace, Menlo, monospace; background: #fff; border-radius: 12px; padding: 14px; }
.lang { border: 0; background: var(--soft); border-radius: 99px; padding: 6px 12px; font-size: 14px; cursor: pointer; }
.cards-print { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8mm; }
.qrcard { border: 1px dashed #999; border-radius: 4mm; padding: 5mm; text-align: center; font-size: 12px; }
.qrcard img { width: 38mm; height: 38mm; }
.qrcard b { display: block; font-size: 16px; letter-spacing: .1em; }
@media print {
  body * { visibility: hidden; }
  #print, #print * { visibility: visible; }
  #print { position: absolute; inset: 0; }
}
