/* Layout concept: a bright shop counter. White side rail + cool daylight workspace; the bill is a strip of
   receipt paper on the right. Saffron is the only action colour; category colours echo the printed bands
   on Sivakasi cracker boxes. Single light theme by design. */
:root {
  color-scheme: light;
  --bg: #f4f5f9; --surface: #ffffff; --surface-2: #f8f8fb; --sunk: #eef0f5;
  --line: #e1e3eb; --line-2: #eceef3;
  --fg: #1b1d2b; --fg-2: #3c3f52; --muted: #6a6d82; --faint: #9a9db0;
  --primary: #e8590c; --primary-hover: #d24e08; --primary-fg: #ffffff;
  --primary-soft: #fff1e8; --primary-line: #fbd2b8; --primary-ink: #b7440a;
  --spark: #f5a70b;
  --good: #14833f; --good-fg: #ffffff; --good-soft: #e5f6eb;
  --bad: #d0312d; --bad-soft: #fdeceb; --warn: #b26300; --warn-soft: #fff4e0;
  --paper: #ffffff; --paper-ink: #16161d;
  --cat-0: #8a8ca3; --cat-1: #d89a00; --cat-2: #2f9e44; --cat-3: #c2255c; --cat-4: #1c7ed6;
  --cat-5: #e03131; --cat-6: #7048e8; --cat-7: #0c8599; --cat-8: #e8590c;
  --f-display: "Baloo 2", "Trebuchet MS", system-ui, sans-serif;
  --f-body: "Hind", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --r-sm: 8px; --r: 12px; --r-lg: 16px;
  --shadow-1: 0 1px 2px rgba(27, 29, 43, .05);
  --shadow-2: 0 8px 24px -10px rgba(27, 29, 43, .18);
  --shadow-3: 0 24px 60px -18px rgba(27, 29, 43, .35);
  --rail-w: 92px; --top-h: 68px; --tab-h: 62px;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--f-body); font-size: 15px; line-height: 1.45; background: var(--bg); color: var(--fg);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
body.noscroll { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--primary); }
[hidden] { display: none !important; }
:focus-visible { outline: 2.5px solid var(--primary); outline-offset: 2px; }
.ic { width: 20px; height: 20px; flex: none; }
input[type=number] { -moz-appearance: textfield; appearance: textfield; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* ---------- app shell ---------- */
.rail { position: fixed; inset: 0 auto 0 0; z-index: 30; width: calc(var(--rail-w) + env(safe-area-inset-left, 0px));
  padding: 16px 10px 16px calc(10px + env(safe-area-inset-left, 0px)); display: flex; flex-direction: column; align-items: center; gap: 20px;
  background: var(--surface); border-right: 1px solid var(--line); }
.rail-brand, .top-brand { display: grid; place-items: center; flex: none; color: #fff; border-radius: 14px;
  background: linear-gradient(145deg, #ffb238, var(--primary)); box-shadow: 0 6px 16px -6px rgba(232, 89, 12, .6); }
.rail-brand { width: 48px; height: 48px; }
.rail-brand .ic { width: 26px; height: 26px; stroke-width: 2.3; }
.rail-nav { display: flex; flex-direction: column; gap: 4px; width: 100%; }
.rail-nav a { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px; border-radius: var(--r);
  color: var(--muted); text-decoration: none; font-size: 12.5px; font-weight: 600; transition: background .15s, color .15s; }
.rail-nav a .ic { width: 22px; height: 22px; }
.rail-nav a:hover { background: var(--surface-2); color: var(--fg); }
.rail-nav a.on { background: var(--primary-soft); color: var(--primary-ink); }

.shell { margin-left: calc(var(--rail-w) + env(safe-area-inset-left, 0px)); min-height: 100%; display: flex; flex-direction: column; }
.shell:has(> .pos) { height: 100%; }
.topbar { position: sticky; top: 0; z-index: 20; flex: none; height: var(--top-h); display: flex; align-items: center; gap: 14px;
  padding-inline: 24px max(24px, env(safe-area-inset-right, 0px)); background: var(--bg); }
.top-brand { display: none; }
.top-title { min-width: 0; }
.top-title h1 { margin: 0; font-family: var(--f-display); font-size: 25px; line-height: 1.1; font-weight: 700; letter-spacing: -.01em; }
.top-title p { margin: 1px 0 0; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-title .sep { margin: 0 6px; color: var(--faint); }
.printer-pill { margin-left: auto; flex: none; display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px 0 12px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; font-size: 14px; box-shadow: var(--shadow-1); }
.printer-pill:hover { border-color: var(--faint); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.dot.ok { background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
.dot.alt { background: var(--spark); box-shadow: 0 0 0 3px var(--warn-soft); }
.tabbar { display: none; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 0 18px; white-space: nowrap;
  border: 1px solid transparent; border-radius: var(--r); background: var(--primary); color: var(--primary-fg);
  font-weight: 600; text-decoration: none; transition: background .15s, border-color .15s, transform .05s; }
.btn:hover { background: var(--primary-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { background: var(--sunk); color: var(--faint); cursor: not-allowed; transform: none; }
.btn.ghost { background: var(--surface); color: var(--fg); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--faint); background: var(--surface-2); }
.btn.soft { background: var(--primary-soft); color: var(--primary-ink); border-color: var(--primary-line); }
.btn.soft:hover { background: #ffe6d5; }
.btn.ok { background: var(--good); color: var(--good-fg); }
.btn.ok:hover { background: #0f7036; }
.btn.danger { background: var(--surface); color: var(--bad); border-color: #f3c4c2; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.big { width: 100%; min-height: 54px; font-size: 17px; border-radius: 14px; }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 13.5px; border-radius: 9px; }
.btn .ic { width: 18px; height: 18px; }
.lbl { display: block; margin: 16px 0 6px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.inp { width: 100%; min-height: 44px; padding: 9px 13px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface);
  outline: none; transition: border-color .15s, box-shadow .15s; }
textarea.inp { min-height: 0; resize: vertical; }
select.inp { padding-right: 32px; }
.inp:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.inp::placeholder { color: var(--faint); }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 12px; align-items: end; }
.hint { color: var(--muted); font-size: 14px; margin: 10px 0; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.muted { color: var(--muted); }
.seg { display: flex; gap: 4px; padding: 4px; border-radius: var(--r); background: var(--sunk); }
.seg button { flex: 1; min-height: 38px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 600; transition: background .15s, color .15s; }
.seg button:hover { color: var(--fg); }
.seg button.on { background: var(--surface); color: var(--fg); box-shadow: 0 1px 3px rgba(27, 29, 43, .12); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 7px; min-height: 34px; padding: 0 13px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); font-size: 14px; font-weight: 600; white-space: nowrap; color: var(--fg-2); transition: background .15s, border-color .15s, color .15s; }
.chip:hover { border-color: var(--faint); color: var(--fg); }
.chip.on { background: var(--primary-soft); color: var(--primary-ink); border-color: var(--primary-line); }
.chip .sw { width: 9px; height: 9px; border-radius: 3px; background: var(--cat); }
.chip .ct { font-weight: 500; color: var(--faint); font-size: 12px; }
.chip.on .ct { color: var(--primary-ink); opacity: .7; }
.x { width: 38px; height: 38px; flex: none; border: 0; border-radius: 10px; display: grid; place-items: center; background: transparent; color: var(--muted); }
.x:hover { background: var(--sunk); color: var(--fg); }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700;
  background: var(--sunk); color: var(--muted); white-space: nowrap; }
.badge.red { background: var(--bad-soft); color: var(--bad); }
.badge.green { background: var(--good-soft); color: var(--good); }
.badge.amber { background: var(--warn-soft); color: var(--warn); }
.empty { color: var(--muted); text-align: center; padding: 40px 16px; }

/* ---------- POS ---------- */
.pos { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 20px;
  padding: 4px max(24px, env(safe-area-inset-right, 0px)) 20px 24px; }
.catalog { display: flex; flex-direction: column; min-height: 0; min-width: 0; gap: 12px; }
.search { position: relative; flex: none; }
.search .ic { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.search .inp { padding-left: 46px; min-height: 50px; font-size: 16px; border-radius: 14px; }
.cats { flex: none; }
.pgrid { flex: 1; min-height: 0; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr));
  grid-auto-rows: max-content; /* rows must never shrink to fit the scroll box */
  gap: 12px; align-content: start; padding: 2px 6px 16px 2px; margin-right: -6px; }

.pcard { --cat: var(--cat-0); position: relative; display: flex; flex-direction: column; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; cursor: pointer;
  transition: transform .12s, box-shadow .15s, border-color .15s; user-select: none; }
.pcard:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
.pcard:active { transform: scale(.98); }
.pcard .band { height: 6px; flex: none; background: repeating-linear-gradient(135deg, var(--cat) 0 9px, color-mix(in srgb, var(--cat) 70%, #fff) 9px 18px); }
.pcard .body { flex: 1; display: flex; flex-direction: column; gap: 4px; padding: 10px 12px 12px; }
.pcard .meta { display: flex; align-items: center; justify-content: space-between; gap: 6px; height: 20px; }
.pcard .code { font: 600 11.5px var(--f-mono); color: var(--cat); letter-spacing: .03em; }
.pcard .off { font-size: 11.5px; font-weight: 700; color: var(--good); background: var(--good-soft); padding: 0 7px; border-radius: 999px; line-height: 20px; }
.pcard .name { font-weight: 600; font-size: 15px; line-height: 1.3; color: var(--fg);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pcard .foot { margin-top: auto; padding-top: 6px; display: flex; align-items: flex-end; justify-content: space-between; gap: 6px; }
.pcard .rate { display: block; font-family: var(--f-display); font-weight: 700; font-size: 21px; line-height: 1.05; font-variant-numeric: tabular-nums; }
.pcard .mrp { display: block; font-size: 12px; color: var(--faint); text-decoration: line-through; font-variant-numeric: tabular-nums; }
.pcard .stock { font-size: 12px; color: var(--muted); text-align: right; white-space: nowrap; padding-bottom: 1px; }
.pcard .stock.low { color: var(--warn); font-weight: 700; }
.pcard .incart { position: absolute; top: 14px; right: 10px; min-width: 26px; height: 26px; padding: 0 8px; border-radius: 999px;
  display: grid; place-items: center; background: var(--primary); color: #fff; font-weight: 700; font-size: 13px; box-shadow: 0 0 0 3px var(--surface); }
.pcard.has { border-color: var(--primary-line); box-shadow: 0 0 0 1px var(--primary-line); }
.pcard.has .off { visibility: hidden; }

/* bill = receipt paper */
.cart { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow-2); overflow: hidden; }
.cart-head { position: relative; flex: none; display: flex; align-items: center; gap: 10px; padding: 14px 14px 12px 18px; border-bottom: 1px dashed var(--line); }
.cart-head h3 { margin: 0; font-family: var(--f-display); font-size: 21px; font-weight: 700; line-height: 1; }
.cart-head .cnt { font-size: 12.5px; font-weight: 600; color: var(--muted); background: var(--sunk); border-radius: 999px; padding: 2px 9px; }
.cart-head .cnt:empty { display: none; }
.cart-head .grow { flex: 1; }
.perf { display: none; }
.cart-list { flex: 1; min-height: 0; overflow-y: auto; }
.citem { padding: 12px 14px 12px 18px; border-bottom: 1px dashed var(--line); display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 10px; align-items: center; }
.citem:last-child { border-bottom: 0; }
.citem .nm { font-weight: 600; line-height: 1.3; min-width: 0; }
.citem .amt { font: 600 14.5px var(--f-mono); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.citem .ctrl { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; }
.citem .at { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.citem .at input { width: 72px; height: 32px; padding: 0 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2);
  font: 600 13px var(--f-mono); color: var(--fg); }
.citem .at input:focus { outline: none; border-color: var(--primary); background: var(--surface); }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); flex: none; }
.stepper button { width: 32px; height: 32px; border: 0; background: var(--surface-2); font-size: 17px; font-weight: 600; color: var(--fg-2); line-height: 1; }
.stepper button:hover { background: var(--sunk); color: var(--fg); }
.stepper input { width: 40px; height: 32px; border: 0; text-align: center; font: 600 14px var(--f-mono); background: transparent; color: var(--fg); }
.stepper input:focus { outline: none; background: var(--primary-soft); }
.rm { margin-left: auto; width: 32px; height: 32px; flex: none; border: 0; border-radius: 8px; display: grid; place-items: center; background: transparent; color: var(--faint); }
.rm:hover { background: var(--bad-soft); color: var(--bad); }
.rm .ic { width: 17px; height: 17px; pointer-events: none; }
.cart-empty { height: 100%; min-height: 180px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  padding: 32px 24px; text-align: center; color: var(--muted); }
.cart-empty .ic { width: 44px; height: 44px; color: var(--faint); stroke-width: 1.5; margin-bottom: 4px; }
.cart-empty b { color: var(--fg); font-weight: 600; font-size: 16px; }

.totals { flex: none; padding: 14px 18px 18px; border-top: 1px solid var(--line); background: var(--surface-2); }
.trow { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 3px 0; font-size: 14.5px; }
.trow > span:last-child { font-family: var(--f-mono); font-variant-numeric: tabular-nums; font-size: 14px; white-space: nowrap; }
.trow.strike > span:last-child { text-decoration: line-through; color: var(--faint); }
.trow.disc { color: var(--good); font-weight: 600; }
.trow.big { padding: 6px 0 10px; }
.trow.big > span:first-child { font-weight: 700; font-size: 15.5px; }
.trow.big > span:last-child { font-family: var(--f-display); font-size: 30px; font-weight: 800; line-height: 1; }
.saved { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px; background: var(--good-soft); color: var(--good);
  font-size: 13px; font-weight: 700; margin: 0 0 12px; }
.saved:empty { display: none; }

.cart-bar, .cart-scrim, #closeCart { display: none; }

/* ---------- dialogs ---------- */
.modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: rgba(27, 29, 43, .42); animation: fade .15s ease-out; }
.sheet { width: 100%; max-width: 560px; max-height: calc(100% - 8px); display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border-radius: 20px; box-shadow: var(--shadow-3); animation: rise .2s ease-out; }
.sheet.small { max-width: 460px; }
.sheet.wide { max-width: 880px; }
.sheet-head { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 14px 12px 22px; border-bottom: 1px solid var(--line-2); }
.sheet-head h3 { margin: 0; font-family: var(--f-display); font-size: 22px; font-weight: 700; line-height: 1.1; }
.sheet-body { flex: 1; min-height: 0; padding: 4px 22px 22px; overflow-y: auto; }
.sheet-foot { flex: none; display: flex; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--line-2); }
.sheet-foot .btn { flex: 1; min-height: 50px; font-size: 16px; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(12px); } }

/* payment */
.pay-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; }
.pay-grid > div { min-width: 0; }
.sumcard { margin-top: 16px; padding: 10px 14px; border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--line-2); }
.disc-box { margin-top: 14px; padding: 14px; border-radius: 14px; background: var(--primary-soft); border: 1.5px dashed var(--primary-line); }
.disc-box .lbl { margin: 0 0 10px; color: var(--primary-ink); }
.disc-row { display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 8px; }
.disc-row .seg { background: var(--surface); border: 1px solid var(--primary-line); }
.disc-row .seg button.on { background: var(--primary); color: #fff; box-shadow: none; }
.disc-row .inp { min-height: 48px; font: 600 20px var(--f-mono); border-color: var(--primary-line); }
.disc-box .chips { margin-top: 10px; display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); }
.disc-box .chip { justify-content: center; min-height: 34px; padding: 0 8px; font-size: 13.5px; border-color: var(--primary-line); }
.disc-box .chip.wide { grid-column: span 2; }
.disc-box .chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.disc-box .trow { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--primary-line); }
.pay-total { margin-top: 16px; padding: 16px; border-radius: 16px; text-align: center; background: var(--surface); border: 2px solid var(--fg); }
.pay-total .k { font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.pay-total .v { font-family: var(--f-display); font-size: 42px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; color: var(--fg); }
.pay-total .saved { margin: 4px 0 0; }
.paid-inp { font: 600 20px var(--f-mono) !important; min-height: 50px !important; }
.change { margin-top: 10px; padding: 11px 14px; border-radius: var(--r); font-weight: 700; display: flex; justify-content: space-between; gap: 10px; }
.change:empty { display: none; }
.change span:last-child { font-family: var(--f-mono); }
.change.chg-ok { background: var(--good-soft); color: var(--good); }
.change.chg-bad { background: var(--bad-soft); color: var(--bad); }

/* done */
.done-hero { display: flex; align-items: center; gap: 14px; padding: 18px 0 4px; }
.done-hero .tick { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; background: var(--good-soft); color: var(--good); flex: none; }
.done-hero .tick .ic { width: 26px; height: 26px; stroke-width: 2.6; }
.done-hero b { display: block; font-family: var(--f-display); font-size: 24px; line-height: 1.1; }
.done-hero span { color: var(--muted); font-size: 14px; }
.print-opts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 16px; }
.print-opts .btn { min-height: 46px; padding: 0 10px; }

/* receipt preview */
.preview-wrap { margin-top: 14px; padding: 18px 12px 22px; border-radius: 14px; max-height: 44vh; overflow: auto; background: var(--sunk); }
.rcpt { font-family: var(--f-mono); font-size: 12px; line-height: 1.4; background: var(--paper); color: var(--paper-ink);
  margin: 0 auto; padding: 14px 10px 18px; white-space: pre; overflow-x: auto; }
.preview-wrap .rcpt { box-shadow: 0 4px 14px rgba(0, 0, 0, .12); }
.rcpt-58, .rcpt-80 { box-sizing: content-box; }
.rcpt-58 { width: 32ch; } .rcpt-80 { width: 48ch; }
.rl.c { text-align: center; } .rl.r { text-align: right; } .rl.b { font-weight: 600; }
.rl.big { font-size: 2em; line-height: 1.15; }

/* printer dialog */
.printer-status { padding: 10px 12px; border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--line-2); font-weight: 600; font-size: 14px; }
.printer-status:empty { display: none; }

/* ---------- management pages ---------- */
.wrap { width: 100%; max-width: 1240px; padding: 4px max(24px, env(safe-area-inset-right, 0px)) 40px 24px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar .grow { flex: 1 1 240px; min-width: 0; }
.toolbar .date { flex: 0 1 170px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.tbl th, .tbl td { padding: 12px 16px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.tbl th { background: var(--surface-2); font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.tbl th.num, .tbl td.num { text-align: right; }
.tbl td.num { font-family: var(--f-mono); font-size: 13.5px; font-variant-numeric: tabular-nums; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tr.off td { opacity: .5; }
.tbl tbody tr:has([data-edit], [data-view]) { cursor: pointer; }
.tbl .pname { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.tbl .sw { width: 10px; height: 10px; border-radius: 3px; background: var(--cat, var(--cat-0)); flex: none; }
.tbl .code { font: 600 12.5px var(--f-mono); color: var(--muted); }
.tbl .sub { display: none; font-size: 12.5px; color: var(--muted); font-weight: 400; margin-top: 2px; font-family: var(--f-body); }
.tbl td.act { width: 1%; text-align: right; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
.stat .k { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.stat .v { margin-top: 6px; font-family: var(--f-display); font-size: 28px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.stat.hero { background: var(--primary-soft); border-color: var(--primary-line); }
.stat.hero .k, .stat.hero .v { color: var(--primary-ink); }
.modes { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; }
.modes .badge { font-size: 13px; padding: 5px 12px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); }
.modes .badge b { font-family: var(--f-mono); color: var(--fg); }
.form-card { padding: 6px 24px 24px; max-width: 760px; }
.form-sec { font-family: var(--f-display); font-size: 18px; font-weight: 700; margin: 22px 0 0; padding-top: 18px; border-top: 1px solid var(--line-2); }
.form-sec:first-child { border-top: 0; padding-top: 8px; }
.check { display: flex; align-items: center; gap: 10px; margin-top: 16px; font-weight: 600; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }

/* toast */
#toast { position: fixed; left: 50%; bottom: 28px; z-index: 99; max-width: calc(100vw - 32px); padding: 11px 18px; border-radius: 12px;
  background: var(--fg); color: #fff; font-weight: 600; text-align: center; box-shadow: var(--shadow-2);
  opacity: 0; transform: translate(-50%, 16px); pointer-events: none; transition: .2s; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--bad); } #toast.ok { background: var(--good); }
#printArea { display: none; }

/* ---------- small laptops / tablets landscape ---------- */
@media (max-width: 1200px) {
  .pos { grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; padding-left: 16px; padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .pgrid { grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); gap: 10px; }
  .topbar { padding-inline: 16px max(16px, env(safe-area-inset-right, 0px)); }
  .wrap { padding-left: 16px; padding-right: max(16px, env(safe-area-inset-right, 0px)); }
}

/* ---------- phones & tablets portrait ---------- */
@media (max-width: 900px) {
  :root { --top-h: 60px; }
  .rail { display: none; }
  .shell, .shell:has(> .pos) { height: auto; }
  .shell { margin-left: 0; padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px)); }
  body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 25; background: var(--surface); }
  .topbar { top: env(safe-area-inset-top, 0px); gap: 10px; background: var(--surface); border-bottom: 1px solid var(--line);
    padding-inline: max(16px, env(safe-area-inset-left, 0px)) max(16px, env(safe-area-inset-right, 0px)); }
  .top-brand { display: grid; width: 38px; height: 38px; border-radius: 11px; }
  .top-brand .ic { width: 21px; height: 21px; stroke-width: 2.3; }
  .top-title h1 { font-size: 20px; }
  .top-title p { font-size: 12.5px; }
  .top-title .today, .top-title .sep:first-of-type { display: none; }
  .printer-pill { height: 38px; padding: 0 12px; }
  .printer-pill > .ic { display: none; }
  .tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: flex; height: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px));
    padding: 0 max(8px, env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px) max(8px, env(safe-area-inset-left, 0px));
    background: var(--surface); border-top: 1px solid var(--line); }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600; }
  .tabbar a .ic { width: 22px; height: 22px; }
  .tabbar a.on { color: var(--primary); }

  .pos { display: block; padding: 0 max(16px, env(safe-area-inset-right, 0px)) 0 max(16px, env(safe-area-inset-left, 0px)); }
  .catalog { gap: 10px; }
  .search { position: sticky; top: calc(var(--top-h) + env(safe-area-inset-top, 0px)); z-index: 6; padding: 12px 0 8px; margin-bottom: -8px; background: var(--bg); }
  .search .ic { top: calc(50% + 2px); }
  .search .inp { min-height: 46px; }
  .cats { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
    margin-left: calc(-1 * max(16px, env(safe-area-inset-left, 0px))); margin-right: calc(-1 * max(16px, env(safe-area-inset-right, 0px)));
    padding: 2px max(16px, env(safe-area-inset-right, 0px)) 2px max(16px, env(safe-area-inset-left, 0px)); }
  .cats::-webkit-scrollbar { display: none; }
  .pgrid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; overflow: visible; padding: 2px 0 96px; margin: 0; }
  .pcard:hover { transform: none; box-shadow: none; }
  .pcard .rate { font-size: 19px; }

  .cart-bar { position: fixed; z-index: 35; display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 16px;
    left: max(10px, env(safe-area-inset-left, 0px)); right: max(10px, env(safe-area-inset-right, 0px));
    bottom: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px) + 10px);
    border-radius: 16px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-3); }
  .cart-bar.empty { display: none; }
  .cart-bar .info { flex: 1; min-width: 0; line-height: 1.15; cursor: pointer; }
  .cart-bar .info span { color: var(--muted); font-size: 12.5px; }
  .cart-bar .info b { display: block; font-family: var(--f-display); font-size: 22px; }
  .cart-bar .btn { min-height: 44px; padding: 0 16px; }

  .cart { position: fixed; z-index: 50; left: 0; right: 0; bottom: 0; max-height: 88%; border-radius: 20px 20px 0 0; border: 0;
    transform: translateY(105%); transition: transform .25s ease; padding-bottom: env(safe-area-inset-bottom, 0px); }
  .cart.open { transform: none; box-shadow: var(--shadow-3); }
  .cart-head { padding: 20px max(10px, env(safe-area-inset-right, 0px)) 12px max(18px, env(safe-area-inset-left, 0px)); }
  .cart-head::before { content: ""; position: absolute; left: 50%; top: 7px; width: 40px; height: 4px; margin-left: -20px; border-radius: 4px; background: var(--line); }
  .cart-scrim { display: block; position: fixed; inset: 0; z-index: 45; background: rgba(27, 29, 43, .42); }
  #closeCart { display: grid; }
  .citem { padding-left: max(18px, env(safe-area-inset-left, 0px)); padding-right: max(14px, env(safe-area-inset-right, 0px)); }
  .cart-empty { min-height: 140px; }

  .modal { padding: 0; align-items: flex-end; }
  .sheet, .sheet.small, .sheet.wide { max-width: none; max-height: 94%; border-radius: 20px 20px 0 0; }
  .sheet-head { padding-left: max(18px, env(safe-area-inset-left, 0px)); padding-right: max(10px, env(safe-area-inset-right, 0px)); }
  .sheet-body { padding-left: max(18px, env(safe-area-inset-left, 0px)); padding-right: max(18px, env(safe-area-inset-right, 0px)); }
  .sheet-foot { padding: 12px max(18px, env(safe-area-inset-right, 0px)) calc(12px + env(safe-area-inset-bottom, 0px)) max(18px, env(safe-area-inset-left, 0px)); }
  .pay-grid { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .pay-total .v { font-size: 36px; }

  .wrap { padding: 12px max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px)); }
  .toolbar .grow { flex-basis: 100%; }
  .toolbar .btn { flex: 1; }
  .toolbar .date { flex: 1 1 140px; }
  .form-card { padding: 4px 16px 20px; }
  .tbl th, .tbl td { padding: 11px 12px; }
  .tbl .hide-sm { display: none; }
  .tbl .sub { display: block; }
  .tbl td:first-child, .tbl td:nth-child(2) { white-space: normal; }
  .tbl .pname { align-items: flex-start; }
  .tbl .pname .sw { margin-top: 6px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat .v { font-size: 23px; }
  #toast { bottom: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px) + 84px); }
}
@media (max-width: 360px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 420px) {
  .print-opts { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .print-opts .btn:last-child { grid-column: 1 / -1; }
  .pgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pcard .name { font-size: 14.5px; }
  .disc-row { grid-template-columns: 96px minmax(0, 1fr); }
}

/* ---------- printing: only the receipt ---------- */
@media print {
  body > *:not(#printArea) { display: none !important; }
  body::before { display: none; }
  #printArea { display: block !important; }
  /* 32 / 48 monospace columns fit the 48 / 72 mm printable width at ~9px */
  #printArea .rcpt { width: auto; padding: 0 1mm; font-size: 9px; box-shadow: none; white-space: pre; overflow: visible; background: #fff; color: #000; }
}
