/* =========================================================
   باجة الأندلس — واجهة النظام
   خفيفة ونظيفة، بنفس الأحمر، مصمَّمة للمس (عناصر 44px فأكثر)
   ========================================================= */

:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --ink: #1b1a1a;
  --muted: #6a6464;
  --line: #e5e2e1;
  --brand: #8b1e1e;
  --brand-strong: #6c1515;
  --brand-soft: #faeceb;
  --ok: #1d7a4b;
  --ok-soft: #e4f4eb;
  --err: #b3261e;
  --err-soft: #fdeceb;
  --radius: 14px;
  --touch: 46px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: 'IBM Plex Sans Arabic', 'Tahoma', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  direction: rtl;
  background: var(--bg);
  color: var(--ink);
  margin: 0;
}

a { color: var(--brand); }

:focus-visible {
  outline: 3px solid rgba(139, 30, 30, 0.35);
  outline-offset: 2px;
}

/* ---------- الشريط العلوي ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar-in {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 20px;
  min-height: 64px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--ink);
  flex-shrink: 0;
}
.mono {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 23px;
  font-weight: 700;
  line-height: 1;
}
.brand-name { font-weight: 700; font-size: 16px; line-height: 1.25; }
.brand-branch { font-size: 12px; color: var(--muted); }

.nav {
  display: flex;
  gap: 2px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }
.nav a {
  display: flex;
  align-items: center;
  min-height: 64px;
  padding: 0 14px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
}
.nav a:hover { color: var(--ink); }
.nav a[aria-current="page"] { color: var(--brand); border-bottom-color: var(--brand); }

.user { display: flex; align-items: center; gap: 10px; font-size: 13px; flex-shrink: 0; }
.user a { color: var(--muted); text-decoration: none; font-weight: 600; }
.user a:hover { color: var(--brand); }
.branch-switch select {
  min-height: 38px;
  width: auto;
  margin: 0;
  padding: 0 10px;
  font-size: 13px;
  background: var(--brand-soft);
  border-color: transparent;
  color: var(--brand-strong);
  font-weight: 600;
}

@media (max-width: 860px) {
  .topbar-in { flex-wrap: wrap; gap: 0 12px; padding-bottom: 0; min-height: 0; }
  .brand { padding: 10px 0; flex: 1; }
  .user { padding: 10px 0; }
  .nav { order: 3; flex-basis: 100%; }
  .nav a { min-height: 48px; }
}

/* ---------- الحاوية والبطاقات ---------- */
.container { max-width: 1200px; margin: 20px auto 40px; padding: 0 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
}
.container h2 { font-size: 18px; font-weight: 700; margin: 0 0 14px; color: var(--ink); }
.container h3 { font-size: 15px; font-weight: 700; margin: 18px 0 8px; }

/* ---------- الأزرار ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, transform 0.08s;
}
.btn:hover { background: var(--brand-strong); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-secondary:hover { background: #f6f4f3; }
.btn-danger { background: var(--err); }
.btn-danger:hover { background: #8f1d17; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn-lg { min-height: 56px; font-size: 17px; border-radius: 12px; width: 100%; }

/* ---------- الحقول ---------- */
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 6px; }

input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
  width: 100%;
  min-height: var(--touch);
  padding: 8px 12px;
  border: 1px solid #d6d1d0;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-family: inherit;
  font-size: 15px;
  margin-bottom: 12px;
}
textarea { min-height: 96px; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(139, 30, 30, 0.15);
}
input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--brand); vertical-align: middle; margin-inline-end: 6px; }
label:has(input[type="checkbox"]) { color: var(--ink); font-size: 14px; font-weight: 500; }

/* ---------- الجداول ---------- */
.container table { width: 100%; border-collapse: collapse; font-size: 14px; }
.container th,
.container td { padding: 11px 10px; text-align: right; border-bottom: 1px solid var(--line); }
.container th { font-size: 12px; font-weight: 600; color: var(--muted); background: transparent; white-space: nowrap; }
.container tbody tr:hover td,
.container tr:hover > td { background: #faf9f9; }
.container td { font-variant-numeric: tabular-nums; }

@media (max-width: 720px) {
  .container table { display: block; overflow-x: auto; white-space: nowrap; }
}

/* ---------- رسائل وشارات ---------- */
.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-size: 14px; border-inline-start: 4px solid; }
.flash.ok { background: var(--ok-soft); color: #145c38; border-color: var(--ok); }
.flash.err { background: var(--err-soft); color: #8f1d17; border-color: var(--err); }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 999px; background: #efedec; color: var(--muted); }

/* ---------- بطاقات الأرقام (التقارير) ---------- */
.stat-box {
  display: inline-block;
  vertical-align: top;
  min-width: 170px;
  margin: 0 0 10px;
  margin-inline-end: 10px;
  padding: 14px 18px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.stat-box .label { font-size: 13px; color: var(--muted); }
.stat-box .value { font-size: 24px; font-weight: 700; line-height: 1.3; font-variant-numeric: tabular-nums; }

.total-line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 2px dashed var(--line);
  font-size: 20px;
  font-weight: 700;
}

/* ---------- شبكة اختيار عامة (اختيار الفرع) ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.menu-item-btn {
  min-height: 84px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: inherit;
  color: var(--ink);
  text-align: start;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.08s;
}
.menu-item-btn:hover { border-color: var(--brand); }
.menu-item-btn:active { transform: scale(0.98); }
.menu-item-btn .name { font-weight: 700; }

/* ---------- صفحات الدخول والتفعيل ---------- */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-wrap { width: 100%; max-width: 400px; margin: 0 auto; padding: 28px; }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.auth-brand .brand-name { font-size: 17px; }
.login-wrap h2 { font-size: 20px; margin-bottom: 4px; }
.login-wrap .sub { color: var(--muted); font-size: 14px; margin: 0 0 18px; }

/* =========================================================
   شاشة الكاشير
   ========================================================= */
.pos { display: grid; grid-template-columns: minmax(0, 1fr) 390px; gap: 20px; align-items: start; }

.pos-tools { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.pos-search { flex: 1; min-width: 180px; }
.pos-search input { margin: 0; }

.cat-tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 14px; scrollbar-width: none; }
.cat-tabs::-webkit-scrollbar { display: none; }
.tab {
  flex-shrink: 0;
  min-height: 44px;
  padding: 0 20px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }

.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 12px; }
.item {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  min-height: 98px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: inherit;
  color: var(--ink);
  text-align: start;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.08s;
  -webkit-tap-highlight-color: transparent;
}
.item:hover { border-color: var(--brand); }
.item:active { transform: scale(0.97); }
.item .n { font-weight: 600; font-size: 15px; line-height: 1.4; padding-inline-end: 22px; }
.item .p { color: var(--brand); font-weight: 700; font-variant-numeric: tabular-nums; }
.item .q {
  position: absolute;
  top: 10px;
  inset-inline-end: 10px;
  display: none;
  min-width: 26px;
  height: 26px;
  padding: 0 7px;
  border-radius: 13px;
  background: var(--brand);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  align-items: center;
  justify-content: center;
}
.item.has-qty { border-color: var(--brand); background: var(--brand-soft); }
.item.has-qty .q { display: flex; }
.item[hidden] { display: none; }
.empty-note { color: var(--muted); padding: 30px 0; text-align: center; }

/* ---------- تذكرة الطلب (شكل الإيصال) ---------- */
.ticket {
  position: sticky;
  top: 84px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 112px);
  margin-bottom: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
}
.ticket::after {
  content: "";
  position: absolute;
  inset-inline: -1px;
  bottom: -10px;
  height: 10px;
  background: var(--surface);
  -webkit-mask: conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) 50% / 20px 100%;
  mask: conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) 50% / 20px 100%;
}
.ticket-head { padding: 16px 18px 12px; }
.ticket-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.ticket-title h2 { margin: 0; }
.link-btn { background: none; border: 0; color: var(--muted); font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer; padding: 8px; min-height: 36px; }
.link-btn:hover { color: var(--err); }

.seg { display: flex; gap: 4px; padding: 4px; background: #f0eeed; border-radius: 12px; }
.seg label { position: relative; display: flex; flex: 1; margin: 0; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}
.seg input:checked + span { background: var(--surface); color: var(--brand); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.seg input:focus-visible + span { outline: 3px solid rgba(139, 30, 30, 0.35); }

.ticket-fields { margin-top: 12px; }
.ticket-fields input { margin-bottom: 8px; }
.ticket-fields details summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted); padding: 6px 0; min-height: 36px; }
.ticket-fields details[open] summary { margin-bottom: 8px; }

.ticket-body { flex: 1; min-height: 90px; overflow-y: auto; padding: 0 18px; border-top: 1px dashed var(--line); }
.cart-empty { color: var(--muted); text-align: center; padding: 28px 0; font-size: 14px; }
.line { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; padding: 12px 0; border-bottom: 1px dashed var(--line); }
.line:last-child { border-bottom: 0; }
.line .ln { font-weight: 600; }
.line .lt { font-weight: 700; font-variant-numeric: tabular-nums; text-align: end; }
.line .lp { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.stepper { display: flex; align-items: center; gap: 4px; justify-self: end; }
.stepper button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.stepper button:active { background: var(--brand-soft); }
.stepper .qty { min-width: 30px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }

.ticket-foot { padding: 14px 18px 20px; border-top: 2px dashed var(--line); }
.total-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.total-row .t-label { font-weight: 600; color: var(--muted); }
.total-row .t-value { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.ticket-foot .seg { margin-bottom: 12px; }

/* شريط الإجمالي السفلي على الشاشات الضيقة */
.pos-bar { display: none; }

@media (max-width: 920px) {
  .pos { grid-template-columns: minmax(0, 1fr); }
  .ticket { position: relative; top: 0; max-height: none; }
  .ticket-body { max-height: 360px; }
  .has-bar { padding-bottom: 92px; }
  .pos-bar {
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--line);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.06);
  }
  .pos-bar .bar-total { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
  .pos-bar .bar-count { font-size: 12px; color: var(--muted); }
  .pos-bar .btn { min-width: 150px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* =========================================================
   إيصال الطباعة (رول 80mm) — لا تغيّر هذا القسم
   ========================================================= */
@media print {
  body * { visibility: hidden; }
  body { background: #fff; }
  #receipt, #receipt * { visibility: visible; }
  #receipt {
    position: absolute;
    top: 0;
    right: 0;
    width: 80mm;
  }
  .no-print { display: none !important; }
}
#receipt {
  width: 80mm;
  margin: 20px auto;
  background: #fff;
  padding: 8px;
  font-family: 'Tahoma', sans-serif;
  font-size: 12px;
  line-height: 1.5;
  color: #000;
}
#receipt h2 { text-align: center; font-size: 15px; margin: 4px 0; color: #000; font-weight: 700; }
#receipt .center { text-align: center; }
#receipt table { width: 100%; border-collapse: collapse; font-size: 11px; }
#receipt th, #receipt td { padding: 2px 0; border: 0; background: none; }
#receipt hr { border: none; border-top: 1px dashed #000; margin: 6px 0; }
#receipt .rline { display: flex; justify-content: space-between; }
#receipt p { margin: 2px 0; }
