:root {
  --page: #f2f2ef; --surface: #fcfcfb; --ink: #0b0b0b; --ink-2: #52514e; --muted: #898781;
  --grid: #e1e0d9; --baseline: #c3c2b7; --border: rgba(11,11,11,0.10);
  --accent: #2a78d6; --accent-2: #eb6834; --good: #0ca30c; --warning: #fab219; --critical: #d03b3b; --delta-good: #006300;
}
* { box-sizing: border-box; margin: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body { background: var(--page); color: var(--ink); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; display: flex; flex-direction: column; overflow: hidden; }
button { font-family: inherit; }

header { display: flex; align-items: center; gap: 16px; padding: 8px 18px; background: var(--surface); border-bottom: 1px solid var(--border); }
header .brand { font-weight: 700; font-size: 15px; white-space: nowrap; }
header .brand small { color: var(--muted); font-weight: 500; }
nav { display: flex; gap: 4px; margin-left: 10px; }
nav button { border: none; background: none; font: 600 15px system-ui, sans-serif; color: var(--ink-2); padding: 12px 20px; border-radius: 999px; cursor: pointer; }
nav button.on { background: var(--ink); color: #fff; }
header .meta { margin-left: auto; display: flex; gap: 16px; color: var(--ink-2); font-size: 13.5px; white-space: nowrap; align-items: center; }
header .meta b { font-variant-numeric: tabular-nums; }
.net { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.net .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--good); }
.net.off .dot { background: var(--warning); }

.view { flex: 1; min-height: 0; display: none; }
.view.on { display: grid; }

#view-sale.on { grid-template-columns: 1fr 420px; }
.menu { display: flex; flex-direction: column; min-width: 0; }
.cats { display: flex; gap: 8px; padding: 12px 16px 4px; overflow-x: auto; }
.cats button { border: 1px solid var(--border); background: var(--surface); color: var(--ink-2); font: 600 15.5px system-ui, sans-serif; padding: 13px 22px; border-radius: 999px; cursor: pointer; white-space: nowrap; }
.cats button.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.items { flex: 1; overflow-y: auto; padding: 12px 16px 16px; display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; align-content: start; }
.item { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px; cursor: pointer; text-align: left; font: inherit; display: flex; flex-direction: column; gap: 6px; min-height: 136px; transition: transform .06s ease; }
.item:active { transform: scale(.97); }
.item .em { font-size: 34px; line-height: 1; }
.item .nm { font-weight: 600; font-size: 15.5px; }
.item .ar { color: var(--muted); font-size: 13px; }
.item .pr { margin-top: auto; font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; }

.bill { background: var(--surface); border-left: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.bill .head { display: flex; align-items: baseline; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--grid); }
.bill .head .inv { font-weight: 700; }
.bill .head .kind { color: var(--muted); font-size: 11.5px; margin-left: auto; }
.lines { flex: 1; overflow-y: auto; padding: 4px 16px; min-height: 60px; }
.line { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--grid); font-size: 15.5px; }
.line .nm { font-weight: 600; }
.line .nm small { display: block; color: var(--muted); font-weight: 400; font-size: 13px; }
.qty { display: inline-flex; align-items: center; gap: 2px; }
.qty button { width: 46px; height: 46px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); font-size: 22px; cursor: pointer; color: var(--ink); }
.qty span { min-width: 34px; text-align: center; font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; }
.line .amt { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 84px; text-align: right; font-size: 16px; }
.empty { color: var(--muted); text-align: center; padding: 26px 10px; font-size: 15px; }

.cust { border-top: 1px solid var(--grid); padding: 10px 16px; font-size: 14.5px; }
.cust .toggle { background: none; border: none; color: var(--accent); font: 600 15px system-ui, sans-serif; cursor: pointer; padding: 8px 0; }
.cust .fields { display: none; margin-top: 6px; }
.cust.open .fields { display: block; }
.cust input { width: 100%; margin: 4px 0; padding: 13px 12px; font: 15.5px system-ui, sans-serif; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--ink); }
.namewrap { position: relative; }
.suglist { position: absolute; top: calc(100% - 1px); left: 0; right: 0; z-index: 55; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 28px rgba(0,0,0,.16); overflow: hidden; display: none; }
.suglist.show { display: block; }
.sug { padding: 12px 14px; cursor: pointer; font-size: 15px; }
.sug:hover { background: var(--page); }
.sug small { color: var(--muted); display: block; font-size: 12.5px; }
.cust .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.cust .b2b { color: var(--delta-good); font-weight: 600; font-size: 12px; margin-top: 4px; }

.totals { padding: 8px 16px 0; border-top: 1px solid var(--grid); font-size: 15px; }
.trow { display: flex; justify-content: space-between; padding: 2px 0; color: var(--ink-2); }
.trow.grand { font-size: 28px; font-weight: 800; color: var(--ink); padding: 6px 0; }
.trow .num { font-variant-numeric: tabular-nums; }
.printrow { display: flex; align-items: center; gap: 10px; padding: 8px 16px 0; font-size: 15px; color: var(--ink-2); }
.printrow input { width: 24px; height: 24px; accent-color: var(--accent); }
.payrow { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 10px 16px 6px; }
.payrow button { border: none; border-radius: 16px; padding: 21px 10px; cursor: pointer; font: 700 19px system-ui, sans-serif; color: #fff; display: flex; flex-direction: column; gap: 2px; align-items: center; }
.payrow button small { font-weight: 500; font-size: 13px; opacity: .85; }
.pay-card { background: var(--accent); }
.pay-cash { background: var(--accent-2); }
.payrow button:disabled { opacity: .35; cursor: default; }
.subrow { display: flex; gap: 10px; padding: 0 16px 12px; }
.subrow button { flex: 1; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 13px 6px; font: 600 14.5px system-ui, sans-serif; color: var(--ink-2); cursor: pointer; }

#view-sales.on, #view-reports.on, #view-till.on { display: block; overflow-y: auto; padding: 16px 20px 60px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 18px; max-width: 1080px; margin: 0 auto 14px; }
.panel h2 { font-size: 13px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 10px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.panel h2 .spacer { flex: 1; }
.btn { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 12px 20px; font: 600 14.5px system-ui, sans-serif; color: var(--ink); cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--critical); border-color: rgba(208,59,59,.4); }
table.sales { width: 100%; border-collapse: collapse; font-size: 15px; }
table.sales th, table.sales td { padding: 12px 10px; border-bottom: 1px solid var(--grid); text-align: right; white-space: nowrap; }
table.sales th:nth-child(-n+4), table.sales td:nth-child(-n+4) { text-align: left; }
table.sales thead th { color: var(--muted); font-weight: 600; font-size: 12px; }
table.sales .num { font-variant-numeric: tabular-nums; }
table.sales tr.credit td { color: var(--critical); }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 13.5px; font-weight: 600; border-radius: 999px; padding: 2px 9px; white-space: nowrap; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; }
.chip.ok { background: rgba(12,163,12,.12); color: var(--delta-good); }
.chip.ok .dot { background: var(--good); }
.linkbtn { border: 1px solid var(--border); background: var(--surface); color: var(--ink-2); font: 600 14px system-ui, sans-serif; cursor: pointer; padding: 9px 14px; border-radius: 999px; margin-left: 4px; }
.rtiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; max-width: 1080px; margin: 0 auto 14px; }
.rtile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.rtile .k { color: var(--muted); font-size: 12px; }
.rtile .v { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.splitbar { display: flex; height: 16px; border-radius: 4px; overflow: hidden; background: var(--grid); margin: 8px 0 6px; }
.splitbar span { height: 100%; }
.splitbar .k { background: var(--accent); margin-right: 2px; }
.splitbar .h { background: var(--accent-2); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); align-items: center; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 5px; vertical-align: -1px; }
.footnote { font-size: 11.5px; color: var(--muted); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; font-size: 15px; }
.kv .k { color: var(--muted); }
.kv .v { font-variant-numeric: tabular-nums; word-break: break-all; }
.form label { display: block; margin: 8px 0; font-size: 15px; color: var(--ink-2); }
.form input[type=text], .form input:not([type]) { display: block; width: 100%; max-width: 420px; margin-top: 4px; padding: 13px 12px; font: 15.5px system-ui, sans-serif; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--ink); }
.form .chk input { width: 24px; height: 24px; vertical-align: middle; accent-color: var(--accent); margin-right: 8px; }
.form .actions { display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; }

#overlay, #heldModal { position: fixed; inset: 0; background: rgba(11,11,11,.45); z-index: 60; display: none; align-items: center; justify-content: center; padding: 20px; }
#overlay.show, #heldModal.show { display: flex; }
.sheet { background: #fff; width: 360px; max-height: 92vh; display: flex; flex-direction: column; border-radius: 12px; box-shadow: 0 18px 60px rgba(0,0,0,.35); overflow: hidden; }
.sheet h2 { font-size: 15px; padding: 14px 18px 0; }
.preview { overflow-y: auto; padding: 16px 18px; background: #fff; }
.sheetbtns { display: flex; gap: 10px; padding: 12px 18px 16px; border-top: 1px solid var(--grid); }
.sheetbtns .btn { flex: 1; padding: 14px; }
#heldList { overflow-y: auto; padding: 8px 18px; }
.heldrow { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--grid); font-size: 14.5px; }
.heldrow .what { flex: 1; }
.heldrow small { color: var(--muted); display: block; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 999px; font-size: 14.5px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .15s; z-index: 70; max-width: 90vw; }
#toast.show { opacity: 1; }

/* ---- receipt (screen preview and print share these) ---- */
.rcpt { width: 72mm; margin: 0 auto; font: 11.5px/1.35 "Segoe UI", "Noto Naskh Arabic", system-ui, sans-serif; color: #000; background: #fff; }
.rcpt .hd { text-align: center; }
.rcpt .nm { font-weight: 700; font-size: 14px; }
.rcpt .legal { font-size: 11px; }
.rcpt .en { font-family: "Segoe UI", system-ui, sans-serif; }
.rcpt hr { border: 0; border-top: 1px dashed #000; margin: 5px 0; }
.rcpt .title { display: flex; justify-content: space-between; font-weight: 700; font-size: 12.5px; margin: 3px 0; }
.rcpt .row { display: flex; justify-content: space-between; gap: 8px; padding: 1px 0; }
.rcpt .row .big { font-weight: 700; font-size: 15px; }
.rcpt .box { border: 1px solid #000; border-radius: 3px; padding: 4px 6px; margin: 5px 0; }
.rcpt table.lines { width: 100%; border-collapse: collapse; margin: 5px 0; }
.rcpt table.lines th, .rcpt table.lines td { border-bottom: 1px solid #000; padding: 3px 2px; vertical-align: top; }
.rcpt table.lines th { font-weight: 700; text-align: center; }
.rcpt table.lines td.d { text-align: right; }
.rcpt table.lines th.d { text-align: right; }
.rcpt table.lines td.n { text-align: center; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rcpt table.lines .en { font-size: 10.5px; color: #333; }
.rcpt .tot .grand { font-weight: 700; font-size: 14px; }
.rcpt .qr { text-align: center; margin: 6px 0 2px; }
.rcpt .qr svg { width: 40mm; height: 40mm; display: inline-block; }
.rcpt .ft { text-align: center; font-weight: 600; margin-top: 4px; }

#print-area { display: none; }
@media print {
  @page { size: 80mm auto; margin: 0; }
  html, body { height: auto; overflow: visible; background: #fff; display: block; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; padding: 2mm 4mm 6mm; }
  .rcpt { width: 72mm; }
  .rcpt .qr svg { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}

/* ---- bill line price editing ---- */
.line .amt { border: 1px dashed transparent; background: none; border-radius: 8px; padding: 8px 6px; cursor: pointer; color: var(--ink); font: 700 16px system-ui, sans-serif; min-width: 96px; text-align: right; font-variant-numeric: tabular-nums; }
.line .amt:active { background: var(--page); }
.line .amt small { display: block; font-weight: 500; font-size: 11px; color: var(--accent); }
.line.open .nm::after, .line.edited .nm small b { color: var(--accent-2); }
.hint { color: var(--muted); font-size: 12px; padding: 0 16px 4px; }
.item.open { border-style: dashed; border-color: var(--accent-2); }
.item.open .pr { color: var(--accent-2); }

/* ---- modals: number pad and item editor ---- */
.modal { position: fixed; inset: 0; background: rgba(11,11,11,.45); z-index: 65; display: none; align-items: center; justify-content: center; padding: 20px; }
.modal.show { display: flex; }
.sheet.pad { width: 340px; }
.sheet.editor { width: 420px; }
.sheet.editor .form { padding: 0 18px 8px; }
.sheet.editor .form select { display: block; width: 100%; margin-top: 4px; padding: 12px; font: 15.5px system-ui, sans-serif; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.padval { display: flex; align-items: baseline; gap: 10px; padding: 8px 18px 4px; }
.padval span { color: var(--muted); font-weight: 600; }
.padval input { flex: 1; font: 700 34px system-ui, sans-serif; text-align: right; border: none; border-bottom: 2px solid var(--grid); padding: 4px 0; outline: none; background: none; font-variant-numeric: tabular-nums; min-width: 0; }
.padkeys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 8px 18px; }
.padkeys button { height: 60px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); font: 600 24px system-ui, sans-serif; cursor: pointer; color: var(--ink); }
.padkeys button:active { background: var(--page); }
.padopt { display: block; padding: 4px 18px 6px; font-size: 14px; color: var(--ink-2); }
.padopt input { width: 22px; height: 22px; vertical-align: middle; margin-right: 6px; accent-color: var(--accent); }
table.menu td .pricebtn { border: 1px dashed var(--border); background: var(--surface); border-radius: 8px; padding: 9px 14px; font: 700 15px system-ui, sans-serif; cursor: pointer; font-variant-numeric: tabular-nums; }
table.menu td .em { font-size: 22px; }
table.menu td.openflag { color: var(--accent-2); font-size: 12px; font-weight: 600; }
