:root {
  --bg: #f4f7fb;
  --card: #ffffff;
  --ink: #16233a;
  --muted: #6b7a92;
  --line: #e3e9f2;
  --brand: #2f7fe0;
  --brand-dark: #2467b8;
  --brand-soft: #eaf2fd;
  --green: #17976b;
  --green-soft: #e6f6f0;
  --amber: #b57a12;
  --amber-soft: #fdf3e0;
  --red: #d0453d;
  --red-soft: #fdeceb;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(22,35,58,.05), 0 6px 20px rgba(22,35,58,.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

/* ── الهيدر ─────────────────────────────────────── */
.topbar {
  background: linear-gradient(135deg, var(--brand) 0%, #1e5fae 100%);
  color: #fff;
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.logo {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -.3px;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 9px;
}
.logo-mark {
  width: 34px; height: 34px;
  background: rgba(255,255,255,.2);
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 18px;
}
.topbar .sub {
  color: rgba(255,255,255,.8);
  font-size: 13.5px;
  margin: 0;
}
.topbar .spacer { flex: 1; }
.topbar a.navlink {
  color: #fff;
  background: rgba(255,255,255,.16);
  border: 1px solid rgba(255,255,255,.25);
  padding: 8px 16px;
  border-radius: 10px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  transition: background .15s;
}
.topbar a.navlink:hover { background: rgba(255,255,255,.28); }

/* ── التخطيط ────────────────────────────────────── */
.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px 20px 60px;
}
.layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 20px;
  align-items: start;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .summary-col { position: static !important; }
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 18px;
}
.card h2 {
  margin: 0 0 14px;
  font-size: 16.5px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card h2 .badge {
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 20px;
}

/* ── عناصر الإدخال ──────────────────────────────── */
label.fld { display: block; margin-bottom: 12px; }
label.fld > span {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 5px;
}
input[type=text], input[type=number], input[type=search], select {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  font: inherit;
  font-size: 14.5px;
  color: var(--ink);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
input[type=number] { -moz-appearance: textfield; }
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  background: var(--brand);
  color: #fff;
  transition: background .15s, transform .05s;
}
.btn:hover { background: var(--brand-dark); }
.btn:active { transform: translateY(1px); }
.btn.ghost {
  background: #fff;
  color: var(--ink);
  border: 1.5px solid var(--line);
}
.btn.ghost:hover { background: var(--bg); }
.btn.danger { background: var(--red); }
.btn.danger:hover { background: #b23b34; }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn.block { width: 100%; }

/* ── اختيار المنتجات ────────────────────────────── */
.picker-tools {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.picker-tools input[type=search] { flex: 1; min-width: 180px; }
.picker-tools select { width: auto; min-width: 160px; }

.product-list {
  max-height: 420px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.cat-head {
  background: var(--bg);
  padding: 7px 14px;
  font-size: 12.5px;
  font-weight: 800;
  color: var(--muted);
  position: sticky;
  top: 0;
  border-bottom: 1px solid var(--line);
}
.prod-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background .12s;
}
.prod-row:last-child { border-bottom: none; }
.prod-row:hover { background: var(--brand-soft); }
.prod-row.in-cart { background: var(--green-soft); }
.prod-row .pname { flex: 1; font-size: 14.5px; font-weight: 600; }
.prod-row .pprice {
  font-size: 14px;
  font-weight: 800;
  color: var(--brand-dark);
  white-space: nowrap;
}
.prod-row .padd {
  width: 30px; height: 30px;
  border-radius: 8px;
  border: none;
  background: var(--brand);
  color: #fff;
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}
.prod-row.in-cart .padd { background: var(--green); }

.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

/* ── السلة ──────────────────────────────────────── */
.cart-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
  background: #fff;
}
.cart-item-top {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}
.cart-item-top .ci-name { flex: 1; font-weight: 700; font-size: 14.5px; }
.cart-item-top .ci-unit { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.ci-remove {
  background: var(--red-soft);
  color: var(--red);
  border: none;
  border-radius: 8px;
  width: 28px; height: 28px;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
}
.ci-controls {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}
.ci-field { display: flex; flex-direction: column; gap: 4px; }
.ci-field > span { font-size: 11.5px; font-weight: 700; color: var(--muted); }
.qty-box { display: flex; align-items: center; gap: 0; }
.qty-box button {
  width: 32px; height: 36px;
  border: 1.5px solid var(--line);
  background: #fff;
  cursor: pointer;
  font-size: 17px;
  color: var(--ink);
}
.qty-box button:first-child { border-radius: 0 9px 9px 0; }
.qty-box button:last-child { border-radius: 9px 0 0 9px; }
.qty-box input {
  width: 52px;
  height: 36px;
  text-align: center;
  border: 1.5px solid var(--line);
  border-inline: none;
  border-radius: 0;
  font-weight: 700;
  padding: 0;
}
.disc-box { position: relative; }
.disc-box input { width: 82px; height: 36px; padding-inline-end: 26px; text-align: center; font-weight: 700; }
.disc-box .pctsign {
  position: absolute;
  inset-inline-end: 9px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  color: var(--muted);
  pointer-events: none;
}
.ci-total {
  margin-inline-start: auto;
  text-align: end;
  font-size: 15.5px;
  font-weight: 800;
}
.ci-total .was {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: line-through;
}
.ci-total .saved { color: var(--green); }

/* ── الملخص ─────────────────────────────────────── */
.summary-col { position: sticky; top: 18px; }
.sum-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 8px 0;
  font-size: 14.5px;
  border-bottom: 1px dashed var(--line);
}
.sum-row:last-of-type { border-bottom: none; }
.sum-row .lbl { color: var(--muted); font-weight: 600; }
.sum-row .val { font-weight: 700; }
.sum-row.discount .val { color: var(--green); }
.sum-row.grand {
  border-top: 2px solid var(--ink);
  border-bottom: none;
  margin-top: 8px;
  padding-top: 12px;
  font-size: 19px;
}
.sum-row.grand .lbl { color: var(--ink); font-weight: 800; font-size: 16px; }
.sum-row.grand .val { font-size: 24px; font-weight: 900; color: var(--brand-dark); }

.note {
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13.5px;
  font-weight: 600;
  margin: 12px 0;
  line-height: 1.5;
}
.note.free { background: var(--green-soft); color: var(--green); }
.note.half { background: var(--amber-soft); color: var(--amber); }
.note.info { background: var(--brand-soft); color: var(--brand-dark); }

.ship-modes {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 6px;
}
.ship-modes label {
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 8px 6px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  background: #fff;
  transition: all .12s;
}
.ship-modes label:hover { border-color: var(--brand); }
.ship-modes input { display: none; }
.ship-modes input:checked + span {
  color: var(--brand-dark);
}
.ship-modes label:has(input:checked) {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand-dark);
}

.actions { display: flex; gap: 8px; margin-top: 14px; }
.actions .btn { flex: 1; }

/* ── لوحة التحكم ────────────────────────────────── */
table.grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.grid th, table.grid td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: start;
}
table.grid th {
  background: var(--bg);
  font-size: 12.5px;
  font-weight: 800;
  color: var(--muted);
  position: sticky;
  top: 0;
  z-index: 1;
}
table.grid td input[type=number] { width: 100px; padding: 6px 9px; }
table.grid td input[type=text] { padding: 6px 9px; }
table.grid tr:hover td { background: #fafcff; }
.scroll-box { max-height: 560px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; }

.tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.tab {
  padding: 9px 18px;
  border-radius: 10px;
  border: 1.5px solid var(--line);
  background: #fff;
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  color: var(--muted);
}
.tab.active { background: var(--brand); border-color: var(--brand); color: #fff; }

.toast {
  position: fixed;
  inset-block-end: 24px;
  inset-inline-start: 50%;
  transform: translateX(50%) translateY(80px);
  background: var(--ink);
  color: #fff;
  padding: 12px 22px;
  border-radius: 12px;
  font-size: 14.5px;
  font-weight: 700;
  box-shadow: 0 8px 30px rgba(0,0,0,.25);
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  z-index: 99;
}
.toast.show { opacity: 1; transform: translateX(50%) translateY(0); }

.hint { font-size: 12.5px; color: var(--muted); margin: 4px 0 0; }

@media print {
  .topbar, .picker-card, .actions, .no-print { display: none !important; }
  .layout { grid-template-columns: 1fr; }
  body { background: #fff; }
  .card { box-shadow: none; border: 1px solid #ccc; }
}
