:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #1f2933;
  --muted: #616e7c;
  --line: #d9dde3;
  --line2: #e4e7eb;
  --input: #c4cad3;
  --blue: #3e7cb1;
  --green: #0b6e4f;
  --red: #c0392b;
  --bar: #1f2933;
  --bar2: #3e4c59;
  --row-red: #fde2e1;
  --row-yellow: #fff4d6;
  --row-green: #e3f6e8;
  --row-grey: #eceef1;
  --sel: #d6e6f5;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", Tahoma, Arial, sans-serif;
}
[dir="rtl"] body { font-family: "Noto Sans Arabic", "Segoe UI", Tahoma, Arial, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- buttons & inputs */
.btn {
  padding: 10px 16px; border-radius: 6px; background: var(--line2);
  border: 1px solid var(--input); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--line); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--blue); color: #fff; border-color: var(--blue); font-weight: 600; }
.btn.danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn.pay { background: var(--green); color: #fff; border: none; font-size: 26px; font-weight: 800; padding: 20px; width: 100%; }
.btn.top { background: var(--bar2); color: #fff; border: none; }
.btn.top.danger { background: var(--red); }
#queue-badge { background: #b7791f; font-weight: 700; }
#queue-badge.danger { background: var(--red); }
.btn.small { padding: 6px 10px; font-size: 14px; }
.btn.link { background: none; border: none; color: var(--blue); padding: 4px 0; text-decoration: underline; }

input[type=text], input[type=password], input[type=email], input[type=number], input[type=date], input[type=tel], select, textarea {
  padding: 8px 10px; border: 1px solid var(--input); border-radius: 6px; background: #fff; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: -1px; }
input.scan { font-size: 22px; padding: 12px; border: 2px solid var(--blue); }
input.big { font-size: 24px; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 12px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 16px; }
.title { font-size: 24px; font-weight: 700; margin: 0; }
h2 { font-size: 20px; margin: 8px 0; }
.banner { background: var(--row-yellow); border: 1px solid #f0c36d; border-radius: 6px; padding: 10px 14px; }
.banner.red { background: var(--row-red); border-color: #e5a5a0; }

form.grid, .formgrid { display: grid; grid-template-columns: max-content 1fr; gap: 10px 14px; align-items: center; }
.formgrid label, form.grid label { color: var(--ink); }
@media (max-width: 560px) { form.grid, .formgrid { grid-template-columns: 1fr; gap: 4px; } }

/* ---------- auth & pin */
.center { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; gap: 16px; }
.auth-card { width: 100%; max-width: 460px; }
.brand { font-size: 34px; font-weight: 800; letter-spacing: -0.5px; color: var(--ink); }
.brand span { color: var(--green); }
.small { font-size: 13px; }
.welcome .btn.pay { font-size: 20px; padding: 16px; }
.welcome .btn.primary { padding: 14px; font-size: 17px; }
.points { margin: 0; padding-inline-start: 20px; display: flex; flex-direction: column; gap: 6px; }
.corner { position: fixed; top: 12px; inset-inline-end: 12px; }
.pin-display { font-size: 30px; letter-spacing: 8px; text-align: center; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; direction: ltr; }
.keypad .btn { font-size: 24px; font-weight: 600; min-height: 64px; background: #fff; }
.keypad .btn.primary { background: var(--blue); color: #fff; }

/* ---------- main layout */
#app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { background: var(--bar); color: #e4e7eb; display: flex; align-items: center; gap: 10px; padding: 8px 16px; flex-wrap: wrap; }
.topbar .store { font-size: 20px; font-weight: 700; color: #fff; }
.topbar .who { font-size: 15px; }
.tabs { display: flex; background: #fff; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { padding: 12px 20px; font-size: 16px; font-weight: 600; border: none; background: none; cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs button.on { border-bottom-color: var(--blue); color: var(--blue); }
.page { flex: 1; padding: 12px 16px; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.offline-bar { background: var(--red); color: #fff; padding: 6px 16px; font-weight: 600; }

/* sell page */
.sell { display: grid; grid-template-columns: 3fr 1fr; gap: 12px; flex: 1; min-height: 0; }
.sell .left, .sell .right { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.total-card { text-align: center; }
.total-amount { font-size: 40px; font-weight: 800; color: var(--green); }
@media (max-width: 900px) { .sell { grid-template-columns: 1fr; } .total-amount { font-size: 32px; } }

/* tables */
.tablewrap { background: #fff; border: 1px solid var(--line); border-radius: 6px; overflow: auto; flex: 1; min-height: 160px; }
table.t { border-collapse: collapse; width: 100%; font-size: 16px; }
table.t th { background: var(--line2); padding: 8px; font-weight: 600; text-align: start; position: sticky; top: 0; white-space: nowrap; }
table.t td { padding: 8px; border-top: 1px solid var(--line2); }
table.t td.n, table.t th.n { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.t tr.sel td { background: var(--sel) !important; }
table.t tbody tr { cursor: default; }
tr.red td { background: var(--row-red); }
tr.yellow td { background: var(--row-yellow); }
tr.green td { background: var(--row-green); }
tr.grey td { background: var(--row-grey); color: var(--muted); }
.empty { padding: 24px; text-align: center; color: var(--muted); }

/* report cards */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.kpi .v { font-size: 20px; font-weight: 700; }
.kpi .v.bad { color: var(--red); }
.subtabs { display: flex; gap: 4px; flex-wrap: wrap; }
.subtabs button { padding: 8px 14px; border: 1px solid var(--line); background: #fff; border-radius: 6px; cursor: pointer; font-weight: 600; }
.subtabs button.on { background: var(--blue); color: #fff; border-color: var(--blue); }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(15, 23, 32, .45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 480px; max-height: calc(100vh - 32px); overflow: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal.wide { max-width: 820px; }
.modal h3 { margin: 0; font-size: 20px; }
.modal .msg { white-space: pre-line; font-size: 16px; }
.modal .buttons { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.big-total { font-size: 32px; font-weight: 800; color: var(--green); text-align: center; }
.change { font-size: 22px; font-weight: 700; }
.warn { color: var(--red); font-weight: 600; }
.ok-text { color: var(--green); font-weight: 700; }
.radio-row { display: flex; gap: 8px; }
.radio-row label { flex: 1; border: 1px solid var(--input); border-radius: 6px; padding: 12px; text-align: center; cursor: pointer; font-size: 18px; font-weight: 600; }
.radio-row input { display: none; }
.radio-row label.on { background: var(--blue); color: #fff; border-color: var(--blue); }

.toast { position: fixed; bottom: 20px; inset-inline-start: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 8px; z-index: 60; font-weight: 600; max-width: 90vw; }
[dir="rtl"] .toast { transform: translateX(50%); }

/* ---------- printing */
#print-area { display: none; }
@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; }
  body { background: #fff; }
}
.receipt { font-family: "Courier New", monospace; font-size: 12px; color: #000; padding: 2mm; }
.receipt h1 { font-size: 16px; text-align: center; margin: 0 0 2px; }
.receipt .c { text-align: center; }
.receipt table { width: 100%; border-collapse: collapse; }
.receipt td { padding: 1px 0; vertical-align: top; }
.receipt td.n { text-align: end; white-space: nowrap; }
.receipt hr { border: none; border-top: 1px dashed #000; margin: 4px 0; }
.receipt .tot { font-size: 16px; font-weight: 800; }
.labels-a4 { display: flex; flex-wrap: wrap; gap: 3mm; }
.label { width: 50mm; height: 30mm; overflow: hidden; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 1mm 2mm; color: #000; font-family: Arial, sans-serif; page-break-inside: avoid; break-inside: avoid; }
.labels-roll .label { page-break-after: always; break-after: page; }
.label .ls { font-size: 7pt; }
.label .ln { font-size: 8pt; font-weight: 700; text-align: center; line-height: 1.1; max-height: 2.3em; overflow: hidden; }
.label .lp { font-size: 11pt; font-weight: 800; }
.label .lb { width: 90%; height: 9mm; }
.label .lb svg { width: 100%; height: 100%; display: block; }
.label .lc { font-size: 7pt; letter-spacing: 1px; }
