:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --line: #e2e5ea;
  --text: #16191d;
  --muted: #6b7280;
  --brand: #0f766e;
  --brand-dark: #115e56;
  --brand-soft: #e6f3f1;
  --danger: #b91c1c;
  --danger-soft: #fdecec;
  --warn: #92400e;
  --warn-soft: #fef3c7;
  --ok: #166534;
  --ok-soft: #dcfce7;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Noto Naskh Arabic", "Noto Sans Arabic", Tahoma, Arial, sans-serif;
  /* يكبر مع عرض الشاشة: 15px على الجوال، ويصل إلى 21px على الشاشات العريضة
     أو عند فتح الموقع بوضع «موقع سطح المكتب» (التخطيط 980px)، فلا يبدو صغيرًا. */
  font-size: clamp(15px, calc(10px + 1.2vw), 21px);
  line-height: 1.6;
}

body { padding-bottom: 76px; overflow-x: clip; }
body.no-nav { padding-bottom: 0; }

/* ---------- header ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--brand);
  color: #fff;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow);
}

.topbar h1 { font-size: .92rem; margin: 0; font-weight: 600; flex: 1; line-height: 1.25; }
.topbar .role-badge {
  background: rgba(255, 255, 255, .18);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: .78rem;
}
.topbar button {
  background: rgba(255, 255, 255, .16);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 6px 12px;
  font: inherit;
  font-size: .82rem;
  cursor: pointer;
}

.rate-chip {
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: 7px 16px;
  font-size: .82rem;
  color: var(--muted);
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}
.rate-chip b { color: var(--text); font-weight: 600; }

/* ---------- layout ---------- */

main { padding: 12px; max-width: 760px; margin: 0 auto; }
@media (min-width: 900px) { main { max-width: 880px; } }
img, svg, video { max-width: 100%; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

.card.tap { cursor: pointer; }
.card.tap:active { background: #fafbfc; }

h2 { font-size: 1rem; margin: 14px 0 6px; }
h2:first-child { margin-top: 0; }
h3 { font-size: .95rem; margin: 0 0 8px; }

.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.row + .row { margin-top: 4px; }
.muted { color: var(--muted); font-size: .85rem; }
.strong { font-weight: 600; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- stats ---------- */

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 8px;
  text-align: center;
}
.stat .value { font-size: 1.2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .label { font-size: .8rem; color: var(--muted); }

/* ---------- alerts ---------- */

.alert {
  border-radius: var(--radius);
  padding: 8px 12px;
  margin-bottom: 8px;
  font-size: .88rem;
  border: 1px solid transparent;
}
.alert.warn { background: var(--warn-soft); color: var(--warn); border-color: #fcd34d; }
.alert.bad { background: var(--danger-soft); color: var(--danger); border-color: #fca5a5; }
.alert.good { background: var(--ok-soft); color: var(--ok); border-color: #86efac; }
.alert.info { background: var(--brand-soft); color: var(--brand-dark); border-color: #99d5cf; }

/* ---------- badges ---------- */

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: .76rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge.pending { background: #f1f5f9; color: #475569; }
.badge.priced { background: var(--brand-soft); color: var(--brand-dark); }
.badge.approved { background: #dcfce7; color: #166534; }
.badge.in_preparation { background: var(--warn-soft); color: var(--warn); }
.badge.confirmed { background: #e0e7ff; color: #3730a3; }
.badge.delivered { background: var(--ok-soft); color: var(--ok); }
.badge.cancelled { background: #f1f5f9; color: #94a3b8; }
.badge.flag { background: var(--warn-soft); color: var(--warn); }
.badge.conflict { background: var(--danger-soft); color: var(--danger); }

/* ---------- forms ---------- */

label { display: block; font-size: .85rem; color: var(--muted); margin: 10px 0 4px; }

input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: .95rem;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand);
  outline-offset: -1px;
  border-color: var(--brand);
}
textarea { min-height: 150px; resize: vertical; line-height: 1.7; }
input[type="number"] { font-variant-numeric: tabular-nums; }

.pw-wrap { position: relative; }
.pw-wrap input { padding-left: 40px; }
.pw-wrap .pw-toggle {
  position: absolute;
  top: 50%;
  left: 2px;
  transform: translateY(-50%);
  background: none;
  border: 0;
  padding: 8px 10px;
  font-size: 1.05rem;
  color: var(--muted);
  line-height: 1;
}
.pw-wrap .pw-toggle:active { background: none; }

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 8px;
  padding: 8px 12px;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
}
button:active { background: var(--brand-dark); }
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: #fff; color: var(--brand); border: 1px solid var(--line); }
button.danger { background: var(--danger); }
button.small { padding: 5px 9px; font-size: .8rem; font-weight: 500; }
button.wide { width: 100%; margin-top: 8px; }

.btn-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.btn-row button { flex: 1 1 30%; min-width: 0; padding: 9px 8px; font-size: .9rem; }

/* صف إجراءات مضغوط لا يلتف على سطرين -- لقوائم طويلة مثل المنتجات */
.actions-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: nowrap;
  overflow-x: auto;
}
.actions-row button { flex: none; min-width: 0; white-space: nowrap; }

/* ---------- filters ---------- */

.filters { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 10px; margin-bottom: 4px; }
.filters button {
  background: #fff;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 7px 14px;
  font-size: .85rem;
  font-weight: 500;
  white-space: nowrap;
}
.filters button.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* بوابة أيقونات تصنيفات المنتجات (ميازين، سبايات...) -- تنقل إلى قسم
   التصنيف ضمن الصفحة نفسها، لا تُخفي بقية المنتجات */
.cat-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.cat-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: #fff;
  color: var(--brand-dark);
  border: 1px solid var(--line);
  padding: 8px 10px;
  border-radius: 12px;
  font-size: .72rem;
  font-weight: 500;
  min-width: 64px;
}
.cat-btn:active { background: var(--brand-soft); }
.cat-icon { width: 22px; height: 22px; line-height: 1; }
.cat-icon svg { width: 100%; height: 100%; }
.cat-label { white-space: nowrap; }

/* عنوان قسم تصنيف ضمن صفحة المنتجات الواحدة */
.cat-section-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 22px 0 8px;
}
.cat-section-heading:first-of-type { margin-top: 4px; }
.cat-section-heading .cat-icon { width: 20px; height: 20px; color: var(--brand); }

/* ---------- list rows ---------- */

.item-line {
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
}
.item-line:last-child { border-bottom: 0; padding-bottom: 0; }
.item-line:first-child { padding-top: 0; }

/* سطر واحد مضغوط: اسم يأخذ ما تبقى من العرض (ويُختصر بنقاط إن طال)،
   وبقية العناصر بحجمها الطبيعي في السطر نفسه. */
.line { display: flex; align-items: center; gap: 6px; }
.line + .line { margin-top: 4px; }
.line-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line > * { flex: none; }
.line > .line-name { flex: 1; }
.line.sub { font-size: .85rem; flex-wrap: wrap; }
.line .flags { flex: 1; display: flex; flex-wrap: wrap; gap: 4px; }
/* كميتا الزبون والسائق تظهران كاملتين دائمًا؛ الأزرار تنزل لسطر تالٍ عند الضيق. */
.line > .facts { flex: 1 0 auto; white-space: nowrap; }
/* أسماء من حفظ النسخة على جواله: تلتف ولا تُقص. */
.line > .holders { flex: 1; min-width: 0; white-space: normal; }
/* اسم طويل يلتف على سطرين بدل أن يُقصّ */
.line-name.wrap2 {
  white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  font-size: .92rem; line-height: 1.3;
}
.line button.icon-btn { padding: 5px 8px; font-size: .9rem; line-height: 1; }
.danger-text { color: var(--danger) !important; }
.line button.small { padding: 5px 9px; font-size: .78rem; }
.card.compact { padding: 8px 12px; }
.item-line.inactive .line-name { color: var(--muted); text-decoration: line-through; }
.item-line.tap { cursor: pointer; }
.totals { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; }
.num.credit { color: var(--ok); }

/* خانة السعر القابلة للتعديل مباشرة + زر حفظها */
.price-edit { display: inline-flex; align-items: center; gap: 4px; flex: none; }
.inline-price {
  width: 74px;
  flex: none;
  padding: 4px 6px;
  font-size: .9rem;
  text-align: left;
}
.price-edit .save-btn {
  padding: 5px 8px; font-size: .78rem;
  background: #fff; color: var(--muted); border: 1px solid var(--line);
}
.price-edit.dirty .inline-price { border-color: var(--warn); }
.price-edit.dirty .save-btn { background: var(--brand); color: #fff; border-color: var(--brand); }

/* سطر منتج عند إرسال الطلبية: الاسم والكمية والسعر في سطر واحد */
.order-row .strong {
  flex: 1; min-width: 0; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.qty-input { width: 54px; flex: none; padding: 4px 6px; font-size: .9rem; text-align: center; }
.price-field {
  width: 64px;
  flex: none;
  padding: 4px 6px;
  font-size: .85rem;
  text-align: left;
  background: #f8fafc;
  color: var(--muted);
  cursor: default;
}

/* ---------- bottom nav ---------- */

.nav {
  position: fixed;
  bottom: 0; right: 0; left: 0;
  max-width: 900px; margin: 0 auto;
  background: #fff;
  border-top: 1px solid var(--line);
  display: flex;
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav button {
  flex: 1;
  background: none;
  color: var(--muted);
  border-radius: 0;
  padding: 8px 2px;
  font-size: .82rem;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.nav button.active { color: var(--brand); background: var(--brand-soft); }
.nav .ic { font-size: 1.45rem; line-height: 1; }

/* ---------- login ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, var(--brand) 0%, var(--brand-dark) 100%);
}
.login-box {
  background: #fff;
  border-radius: 16px;
  padding: 26px 22px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .2);
}
@media (min-width: 700px) { .login-box { max-width: 480px; padding: 32px 30px; } }
.emergency-link { margin-top: 40px; }

.brand-logo { display: block; width: 100%; height: auto; border-radius: 10px; margin-bottom: 16px; }
.login-box h1 { margin: 0 0 4px; font-size: 1.3rem; text-align: center; }
.login-box .sub { text-align: center; color: var(--muted); font-size: .85rem; margin-bottom: 18px; }

/* ---------- toast ---------- */

#toast {
  position: fixed;
  bottom: 90px;
  right: 16px; left: 16px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
#toast div {
  background: #16191d;
  color: #fff;
  padding: 12px 15px;
  border-radius: 10px;
  font-size: .88rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
}
#toast div.err { background: var(--danger); }
#toast div.ok { background: var(--ok); }

/* ---------- modal ---------- */

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 26, .55);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal {
  background: #fff;
  width: 100%;
  max-width: 560px;
  border-radius: 16px 16px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 88vh;
  overflow-y: auto;
}
.modal h3 { font-size: 1.05rem; margin-bottom: 12px; }

@media (min-width: 640px) {
  .modal-back { align-items: center; }
  .modal { border-radius: 16px; }
  .stats { grid-template-columns: repeat(4, 1fr); }
}

.empty { text-align: center; color: var(--muted); padding: 34px 16px; font-size: .9rem; }
.spinner { text-align: center; padding: 34px; color: var(--muted); }
  

/* ---------- الرقابة ---------- */
.num.neg { color: var(--danger); }
.item-line.flagged { border-right: 3px solid var(--danger); padding-right: 8px; }
.small-text { font-size: .8rem; margin-top: 2px; }

/* أزرار القسم (نسخ / إدخال) في طرف سطر العنوان */
.cat-section-heading > span:not(.cat-icon) { flex: 1; }

.check-line { display: flex; gap: 8px; align-items: flex-start; margin: 10px 0; font-weight: normal; }
.check-line input { width: auto; margin-top: 4px; }

/* «المواد المطلوبة»: المنتجات التي حُدّدت كميتها */
.card.chosen { border: 1px solid var(--brand); background: #f3faf8; }


/* Welcome actions: compact on the first screen; details show only after tap. */
.welcome-card .brand-logo {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
  background: #fff;
  border: 0;
  box-shadow: none;
  border-radius: 0;
  margin-bottom: 12px;
}
.welcome-actions { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; margin-top: 17px; }
.login-box .welcome-actions .welcome-action {
  margin: 0; min-width: 0; min-height: 53px; padding: 10px 7px;
  background: linear-gradient(145deg,#007c74,#034944);
  color: white; border: 1px solid #d7b664; border-radius: 13px;
  font-size: clamp(.76rem,3.4vw,.96rem); font-weight: 700;
  line-height: 1.35; box-shadow: 0 4px 10px rgba(0,74,68,.15);
}
.welcome-actions .welcome-action:focus-visible,
.welcome-contact-links a:focus-visible { outline: 3px solid #c9a24b; outline-offset: 3px; }
.welcome-modal { max-width: 460px; text-align: center; }
.welcome-modal-head { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:12px; }
.welcome-modal-head h3 { margin:0; }
.welcome-close { background:#eef3f2; color:#184e49; border-radius:50%; width:38px; height:38px; flex:none; font-size:27px; padding:0; }
.welcome-info-caption { color:#47605f; margin: 8px 0 12px; }
.welcome-phone { color:#064e49; font-size:1.9rem; font-weight:800; letter-spacing:.02em; margin:15px 0; }
.welcome-contact-links { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:10px; }
.welcome-link { display:flex; text-decoration:none; align-items:center; justify-content:center; padding:13px 6px; border-radius:12px; font-weight:700; }
.welcome-link.call { border:1px solid #a9c7c3; background:#f5fbfa; color:#00554d; }
.welcome-link.whatsapp { color:white; background:#16875d; }
.welcome-qr { margin:10px auto; background:#fff; width:min(78vw,270px); max-width:100%; border-radius:16px; border:1px solid #dce5ee; overflow:hidden; }
.welcome-qr svg { display:block; width:100%; height:auto; }
.welcome-payee { font-weight:700; margin: 10px 0; color:#054f49; }
.welcome-wallet-id { font-size:.78rem; overflow-wrap:anywhere; direction:ltr; color:#53616c; background:#f3f5f7; border-radius:9px; padding:9px 5px; }
.welcome-copy { background:#096e64; color:white; margin:14px 0 0; padding:10px 20px; border-radius:10px; }
@media (max-width:370px) { .welcome-actions{gap:7px} .login-wrap{padding:12px} .login-box{padding:18px 14px} }

/* The approved 2026-10 welcome header and two compact action buttons. */
.login-wrap.welcome-page{
  min-height:100vh;min-height:100dvh;
  flex-direction:column;justify-content:flex-start;
  padding:0 12px 26px;gap:13px;overflow-x:hidden;
}
.welcome-page .welcome-topbar{
  align-self:stretch;margin:0 -12px;min-height:68px;
  padding:17px 12px 11px;display:flex;align-items:center;justify-content:center;
  border-bottom:2px solid #cda956;
  background:linear-gradient(115deg,#063f3a,#00766e,#053e3a);
  box-shadow:0 9px 22px rgba(0,39,37,.23);
}
.welcome-topbar h2{
  margin:0;font-size:clamp(1.14rem,5vw,1.7rem);font-weight:800;
  line-height:1.35;text-align:center;color:#f6d48b;
  text-shadow:0 2px 5px rgba(0,0,0,.4);
}
.welcome-page .login-box{
  width:100%;max-width:510px;border-color:#cfa65a;
  border-radius:24px;padding:22px 20px 26px;
}
.welcome-page .welcome-card .brand-logo{
  width:100%;background:#fff;object-fit:contain;
}
.welcome-page .welcome-actions{direction:rtl}
.welcome-page .welcome-actions .welcome-action{
  background:linear-gradient(150deg,#fffefa,#f6f6f0);
  border:1.5px solid #cda956;color:#09534c;font-weight:800;
  box-shadow:0 5px 14px rgba(4,51,48,.15);
}
.welcome-page .welcome-actions .welcome-action:hover{background:#fdf5df}
@media(max-width:390px){
  .welcome-page .login-box{padding:18px 14px 21px}
  .welcome-topbar h2{font-size:1.23rem}
  .welcome-page .welcome-actions .welcome-action{font-size:.82rem}
}

/* Premium finishing touches for the two opt-in welcome dialogs. */
.welcome-modal {
  background: linear-gradient(180deg,#ffffff 0%,#fffefa 100%);
  border-top: 3px solid #c8a553;
  box-shadow: 0 -20px 65px rgba(0,30,27,.24);
}
.welcome-modal .welcome-modal-head {
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(193,152,69,.27);
}
.welcome-modal .welcome-modal-head h3 {
  color: #07534a;
  font-weight: 800;
}
.welcome-modal .welcome-info-caption {
  line-height: 1.65;
  color: #536a64;
}
.welcome-modal .welcome-phone {
  border: 1px solid rgba(195,154,72,.38);
  border-radius: 14px;
  background: linear-gradient(135deg,#f8faf8,#fffaf0);
  padding: 13px 8px;
  font-variant-numeric: tabular-nums;
}
.welcome-modal .welcome-link {
  min-height: 49px;
  box-shadow: 0 5px 14px rgba(0,50,42,.1);
  transition: transform .12s ease, box-shadow .12s ease;
}
.welcome-modal .welcome-link:active { transform: scale(.98); }
.welcome-modal .welcome-info-note {
  margin: 17px 0 4px;
  padding: 12px 13px;
  border-radius: 13px;
  border: 1px solid rgba(192,151,67,.32);
  background: #fbf8ef;
  color: #356058;
  font-size: .85rem;
  line-height: 1.85;
  text-align: right;
}
.welcome-modal .welcome-qr {
  padding: 8px;
  border: 1px solid #c9ab66;
  box-shadow: 0 7px 23px rgba(3,73,65,.09);
}
.welcome-modal .welcome-wallet-id {
  user-select: all;
  -webkit-user-select: all;
}
.welcome-modal .welcome-copy { border: 1px solid #c4a15b; }
@media (prefers-reduced-motion:reduce) {
  .welcome-modal .welcome-link { transition:none; }
}
