/* ألوان البراند — غيّرها من هنا */
:root {
  --brand: #d62828;
  --brand-dark: #a31d1d;
  --ink: #1d1d1f;
  --muted: #6b6b70;
  --bg: #f4f1ec;
  --card: #ffffff;
  --line: #e3ded6;
  --ok: #2a9d4b;
  --gift: #f4a300;
  --header: #1d1d1f;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%; /* آيفون: ما يكبّر الخط لحاله لما يلف الجهاز */
}
button { font: inherit; cursor: pointer; border: 0; border-radius: 10px; touch-action: manipulation; }
input, select { font: inherit; }
/* آيفون/آيباد: الحقول أقل من 16px تخلي سفاري يقرّب الشاشة لما تكتب */
@supports (-webkit-touch-callout: none) { input, select, textarea { font-size: max(16px, 1em); } }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }

/* ---------- الشريط العلوي ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  background: var(--header); color: #fff; padding: 8px 16px; height: 60px;
  /* آيفون فيه نوتش/جزيرة: الشريط ينزل تحتها، ويبعد عن الحواف المدورة لما يكون الجهاز بالعرض */
  padding-top: calc(8px + env(safe-area-inset-top));
  padding-left: calc(16px + env(safe-area-inset-left));
  padding-right: calc(16px + env(safe-area-inset-right));
  height: calc(60px + env(safe-area-inset-top));
}
.topbar img { height: 40px; }
.topbar h1 { font-size: 18px; margin: 0; flex: 1; }
.topbar a {
  color: #fff; text-decoration: none; padding: 8px 14px; border-radius: 10px;
  background: rgba(255,255,255,.12); font-size: 15px;
}
.topbar a.active { background: var(--brand); }

/* ---------- شاشة الكاشير ---------- */
.pos { display: grid; grid-template-columns: 1fr 380px; }
.menu-panel { overflow-y: auto; padding: 14px; }
.cat-title { margin: 6px 4px 10px; font-size: 16px; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.item-btn {
  background: var(--card); border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,.08); text-align: center; padding: 0 0 10px;
  display: flex; flex-direction: column; min-height: 150px; transition: transform .08s;
}
.item-btn:active { transform: scale(.96); }
.item-btn .ph { height: 92px; background: #333 center/cover no-repeat; }
.item-btn .ph.empty { background: linear-gradient(135deg, #5a8f3c, #2f5d1e); }
.item-btn .nm { font-weight: 700; font-size: 15px; padding: 8px 6px 2px; line-height: 1.3; }
.item-btn .pr { color: var(--brand); font-weight: 700; }

.cart-panel {
  background: var(--card); border-inline-start: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.cart-head { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.cart-head h2 { margin: 0; font-size: 18px; }
.cart-lines { flex: 1; overflow-y: auto; padding: 8px 12px; }
.empty-cart { color: var(--muted); text-align: center; margin-top: 40px; }
.cline { border-bottom: 1px solid var(--line); padding: 10px 4px; }
.cline-top { display: flex; align-items: center; gap: 8px; }
.cline .nm { flex: 1; font-weight: 600; }
.qty { display: flex; align-items: center; gap: 6px; }
.qty button { width: 38px; height: 38px; background: var(--bg); font-size: 20px; font-weight: 700; }
.qty span { min-width: 22px; text-align: center; font-weight: 700; }
.cline .amt { min-width: 64px; text-align: left; font-weight: 700; }
.badge { display: inline-block; margin-top: 6px; font-size: 13px; padding: 3px 8px; border-radius: 8px; background: #fff3d6; color: #8a5a00; }
.pick-free { margin-top: 6px; font-size: 13px; padding: 5px 10px; background: #fff8e6; color: #8a5a00; border: 1px dashed var(--gift); }

.promo-banner { margin: 0 12px; padding: 10px 12px; border-radius: 10px; background: #fff3d6; color: #6b4500; font-weight: 600; font-size: 14px; }
.totals { padding: 10px 16px; border-top: 1px solid var(--line); }
.trow { display: flex; justify-content: space-between; padding: 3px 0; color: var(--muted); }
.trow.big { color: var(--ink); font-size: 22px; font-weight: 800; padding-top: 6px; }
.trow.save { color: var(--ok); font-weight: 700; }
.actions { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; padding: 0 16px 16px; }
.btn { padding: 16px; font-size: 18px; font-weight: 700; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:disabled { background: #c9c4bc; }
.btn-light { background: var(--bg); color: var(--ink); }
.btn-ok { background: var(--ok); color: #fff; }

/* ---------- النوافذ ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: none; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal-bg.show { display: flex; }
.modal { background: var(--card); border-radius: 18px; padding: 20px; width: 100%; max-width: 460px; max-height: 92vh; overflow-y: auto; }
.modal h3 { margin: 0 0 12px; }
.pay-total { font-size: 30px; font-weight: 800; text-align: center; margin: 4px 0 14px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.seg button { padding: 16px; font-size: 18px; font-weight: 700; background: var(--bg); }
.seg button.on { background: var(--ink); color: #fff; }
.cash-box label { display: block; margin-bottom: 6px; color: var(--muted); }
.cash-box input { width: 100%; padding: 12px; font-size: 22px; border: 1px solid var(--line); border-radius: 10px; text-align: center; }
.quick { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.quick button { padding: 10px 14px; background: var(--bg); font-weight: 700; }
.change { text-align: center; font-size: 20px; font-weight: 700; margin: 8px 0 14px; min-height: 28px; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }

/* ---------- الفاتورة ---------- */
.receipt { width: 300px; margin: 0 auto; font-size: 13px; color: #000; background: #fff; padding: 10px; font-family: Tahoma, Arial, sans-serif; }
.r-head { text-align: center; margin-bottom: 8px; line-height: 1.6; }
.r-logo { height: 56px; filter: invert(1); }
.r-shop { font-size: 17px; font-weight: 700; }
.r-title { font-weight: 700; margin-top: 4px; border-top: 1px dashed #000; border-bottom: 1px dashed #000; padding: 3px 0; }
.r-void { text-align: center; font-weight: 800; font-size: 16px; }
.r-line { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; }
.r-items { width: 100%; border-collapse: collapse; margin: 6px 0; }
.r-items th { border-bottom: 1px solid #000; text-align: right; font-size: 12px; }
.r-items td { padding: 3px 0; vertical-align: top; }
.r-items td.num, .r-items th:nth-child(n+2) { text-align: left; white-space: nowrap; padding-inline-start: 6px; }
.r-discount { font-weight: 700; }
.r-sep { border-top: 1px dashed #000; margin: 6px 0; }
.r-total { font-size: 16px; font-weight: 800; }
.r-foot { text-align: center; margin-top: 10px; }
.r-qr { text-align: center; margin-top: 10px; }
.r-qr svg { display: inline-block; }
.r-note { text-align: center; font-size: 11px; margin-top: 2px; }
#print-area { display: none; }

@media print {
  @page { size: 80mm auto; margin: 2mm; }
  body { background: #fff; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; }
  .receipt { width: 100%; padding: 0; }
}

/* ---------- شاشة المطبخ ---------- */
.kds { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; padding: 14px; }
.kcol { overflow-y: auto; }
.kcol h2 { margin: 4px 4px 10px; font-size: 18px; }
.kcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.kcard { background: var(--card); border-radius: var(--radius); padding: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.1); border-top: 6px solid var(--brand); }
.kcard.ready { border-top-color: var(--ok); }
.kcard .kno { font-size: 26px; font-weight: 800; }
.kcard .kt { color: var(--muted); font-size: 14px; }
.kcard ul { padding: 0; list-style: none; margin: 10px 0; font-size: 18px; }
.kcard li { padding: 4px 0; border-bottom: 1px dashed var(--line); }
.kcard li b { display: inline-block; min-width: 34px; }
.kcard .btn { width: 100%; padding: 12px; }
.late { color: var(--brand); font-weight: 700; }

.muted { color: var(--muted); }

/* ---------- الاتصال بالسيرفر ---------- */
.sync-badge { font-size: 13px; padding: 5px 10px; border-radius: 20px; background: rgba(42,157,75,.15); color: #2a9d4b; white-space: nowrap; }
.sync-badge.off { background: rgba(224,159,0,.18); color: #b07800; }
.topbar .sync-badge { background: rgba(42,157,75,.25); color: #7be29a; }
.topbar .sync-badge.off { background: rgba(244,163,0,.25); color: #ffc94d; }
.setup-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.setup-card { background: #fff; color: #1d1d1f; border-radius: 16px; padding: 24px; width: 100%; max-width: 420px; }
.setup-card h2 { margin: 0 0 8px; }
.setup-card label { display: block; margin: 14px 0 0; font-weight: 600; }
.setup-card small { font-weight: 400; color: #6b6b70; }
.setup-card input { display: block; width: 100%; margin-top: 6px; padding: 12px; font-size: 20px; border: 1px solid #ccc; border-radius: 10px; text-align: center; letter-spacing: 2px; }
.setup-card button { width: 100%; margin-top: 18px; padding: 14px; font-size: 18px; font-weight: 700; background: #d62828; color: #fff; }
.setup-err { color: #d62828; min-height: 20px; margin: 8px 0 0; }
.setup-card .setup-alt { background: #f4f1ec; color: #1d1d1f; font-size: 15px; margin-top: 10px; padding: 12px; }
.setup-card { max-height: 92vh; overflow-y: auto; }

/* شاشة اختيار الجهاز في تطبيق الأندرويد */
.app-pick { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 24px; background: var(--header); color: #fff; }
.app-pick[hidden] { display: none; }
.app-pick img { height: 90px; }
.app-pick h1 { margin: 0 0 8px; font-size: 22px; }
.app-pick button { width: 100%; max-width: 360px; padding: 20px; font-size: 20px; font-weight: 800; background: #fff; color: var(--ink); display: flex; gap: 12px; align-items: center; justify-content: center; }
.app-pick button small { font-weight: 400; color: var(--muted); font-size: 14px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: #1d1d1f; color: #fff; padding: 14px 20px; border-radius: 12px; font-size: 17px; font-weight: 600;
  transition: opacity .2s, transform .2s; z-index: 90; max-width: 92vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- طلبات النادل بانتظار الدفع ---------- */
.unpaid-btn { background: #f4a300; color: #1d1d1f; font-weight: 700; padding: 8px 14px; }
.unpaid-btn[hidden] { display: none; }
.close-day-btn { background: rgba(255,255,255,.12); color: #fff; padding: 8px 14px; font-size: 15px; }
.close-sum { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; font-size: 15px; margin-bottom: 14px; padding: 12px; background: var(--bg); border-radius: 12px; }
.close-sum b { text-align: left; font-variant-numeric: tabular-nums; }
.close-warn { color: #8a5a00; background: #fff3d6; padding: 8px 10px; border-radius: 8px; margin-bottom: 10px; font-size: 14px; }
.unpaid-list { display: flex; flex-direction: column; gap: 10px; }
.unpaid-item { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); text-align: right; width: 100%; }
.unpaid-item .no { font-size: 22px; font-weight: 800; min-width: 70px; }
.unpaid-item .info { flex: 1; font-size: 14px; color: var(--muted); }
.unpaid-item .info b { color: var(--ink); font-size: 15px; }
.unpaid-item .tot { font-size: 18px; font-weight: 800; }
.car-input { width: 100%; padding: 12px; font-size: 16px; border: 1px solid var(--line); border-radius: 10px; margin: 0 0 10px; }
.kcard .car { font-size: 15px; font-weight: 700; background: #fff3d6; border-radius: 8px; padding: 4px 8px; margin-top: 6px; display: inline-block; }
.kcard .src { font-size: 12px; color: var(--muted); }
.tag-unpaid { font-size: 12px; background: #f4a300; color: #1d1d1f; border-radius: 6px; padding: 2px 6px; margin-inline-start: 6px; }

/* ---------- مقاسات الشاشات: تابلت، فولد مفتوح، جوال، فولد مسكّر ---------- */
.cart-bar { display: none; }
.pos, .kds { height: calc(100vh - 60px - env(safe-area-inset-top)); height: calc(100dvh - 60px - env(safe-area-inset-top)); }
.cart-panel .actions { padding-bottom: max(16px, env(safe-area-inset-bottom)); }

/* تابلت عمودي / فولد مفتوح: السلة أنحف */
@media (max-width: 1000px) {
  .pos { grid-template-columns: 1fr 320px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}
@media (max-width: 820px) {
  .kds { grid-template-columns: 1fr; height: auto; }
}

/* جوال / فولد مسكّر: المنيو كامل الشاشة، والسلة شريط تحت ينفتح لفوق */
@media (max-width: 700px) {
  .topbar { height: 54px; padding: 6px 10px; gap: 8px; }
  .topbar img { height: 34px; }
  .topbar h1 { font-size: 16px; }
  .topbar .sync-badge { font-size: 11px; padding: 4px 8px; }
  .unpaid-btn, .close-day-btn { padding: 7px 10px; font-size: 13px; }
  .pos { display: block; height: auto; }
  .menu-panel { padding: 10px 10px calc(96px + env(safe-area-inset-bottom)); }
  .grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; margin-bottom: 12px; }
  .item-btn { min-height: 0; padding-bottom: 8px; }
  .item-btn .ph { height: 72px; }
  .item-btn .nm { font-size: 13px; padding: 6px 4px 2px; }
  .cat-title { font-size: 14px; margin: 4px 2px 8px; }

  .cart-panel {
    position: fixed; inset-inline: 0; bottom: 0; z-index: 40;
    max-height: 88vh; max-height: 88dvh; border: 0;
    border-radius: 18px 18px 0 0; box-shadow: 0 -6px 24px rgba(0,0,0,.18);
    transform: translateY(calc(100% - 72px - env(safe-area-inset-bottom)));
    transition: transform .22s ease;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .cart-panel.open { transform: none; }
  .cart-bar {
    display: flex; align-items: center; gap: 10px; width: 100%; min-height: 72px; flex-shrink: 0;
    padding: 10px 16px; background: var(--ink); color: #fff; border-radius: 18px 18px 0 0; text-align: right;
  }
  .cart-bar .cb-count { background: var(--brand); border-radius: 20px; min-width: 32px; padding: 4px 8px; text-align: center; font-weight: 800; }
  .cart-bar .cb-text { flex: 1; font-weight: 700; font-size: 16px; }
  .cart-bar .cb-total { font-size: 20px; font-weight: 800; }
  .cart-bar .cb-arrow { transition: transform .2s; }
  .cart-panel.open .cart-bar .cb-arrow { transform: rotate(180deg); }
  .cart-bar.bump { animation: bump .3s; }
  .cart-head { padding: 8px 16px; }
  .cart-head h2 { font-size: 15px; color: var(--muted); }
  .cart-lines { min-height: 80px; }
  .trow.big { font-size: 20px; }
  .btn { padding: 14px; font-size: 17px; }
  .toast { bottom: calc(90px + env(safe-area-inset-bottom)); }
  .modal { padding: 16px; }
  .kds { padding: 10px; }
}
@keyframes bump { 50% { transform: scale(1.03); } }

/* جوال صغير جداً */
/* الآيفون: الأزرار ما تنكسر لسطور، والشريط يتمرّر بالعرض لو ما كفّى */
@media (max-width: 480px) {
  .topbar { overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .topbar::-webkit-scrollbar { display: none; }
  .topbar > * { flex-shrink: 0; white-space: nowrap; }
  .topbar img { display: none; }
  .topbar { gap: 6px; }
  .topbar .user-chip { max-width: 88px; }
  .unpaid-btn, .close-day-btn, .topbar .btn-light { padding: 6px 8px; font-size: 12px; }
}
@media (max-width: 380px) {
  .topbar h1 { display: none; }
  .grid { grid-template-columns: repeat(3, 1fr); }
}

/* ---------- دخول الموظف (رمز PIN) والصلاحيات ---------- */
.pin-bg { background: rgba(29,29,31,.92); z-index: 1000; }
.pin-modal { max-width: 340px; text-align: center; }
.pin-logo { height: 44px; background: var(--header); border-radius: 10px; padding: 6px; }
.pin-sub { color: var(--muted); font-size: 14px; margin: 4px 0 8px; }
.pin-dots { font-size: 26px; letter-spacing: 8px; min-height: 40px; direction: ltr; }
.pin-err { color: var(--danger, #d33); min-height: 20px; font-size: 14px; }
.pin-keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 10px 0 14px; direction: ltr; }
.pin-keys button { padding: 16px 0; font-size: 22px; font-weight: 700; background: var(--bg); }
.pin-keys button:active { background: var(--line); }
.user-chip { background: rgba(255,255,255,.12); color: #fff; padding: 8px 12px; font-size: 14px; white-space: nowrap; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; }
.btn-danger { background: var(--danger, #d33); color: #fff; }
.order-row { cursor: default; }
.order-row .row-acts { display: flex; gap: 6px; }
.order-row .row-acts button { padding: 8px 10px; font-size: 14px; }
.order-row .row-acts .danger { color: var(--danger, #d33); }
.tag { font-size: 12px; border-radius: 6px; padding: 2px 6px; color: #fff; }
.tag.paid { background: #2a9d4b; } .tag.void { background: #d33; } .tag.wait { background: #f4a300; color: #1d1d1f; }
.reasons { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.reasons button { background: var(--bg); padding: 8px 12px; font-size: 14px; }
.reasons button.on { background: var(--header); color: #fff; }
#orders-modal .modal { max-height: 85vh; overflow: auto; }
@media (max-width: 700px) { .user-chip { font-size: 12px; padding: 6px 8px; } .order-row { flex-wrap: wrap; } }
