:root {
  --bg: #f4f6f8; --card: #fff; --ink: #0f172a; --muted: #475569; --line: #e2e8f0;
  --brand: #0f766e; --brand-ink: #fff; --warn: #b45309; --bad: #b91c1c; --ok: #15803d;
  --radius: 14px; --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Sarabun", "Noto Sans Thai", system-ui, sans-serif; font-size: 16px; line-height: 1.45;
  background: var(--bg); color: var(--ink); -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; font-size: 16px; } /* >=16px: iOS won't zoom */
button { cursor: pointer; border: 0; border-radius: 10px; min-height: 44px; padding: 0 14px; background: #e2e8f0; color: var(--ink); }
button.primary { background: var(--brand); color: var(--brand-ink); font-weight: 600; }
button.danger { background: #fee2e2; color: var(--bad); }
button.ghost { background: transparent; color: var(--brand); }
button:disabled { opacity: .45; }
input, select { width: 100%; min-height: 44px; padding: 8px 12px; border: 1px solid #cbd5e1; border-radius: 10px; background: #fff; color: var(--ink); }
label { display: block; font-size: 14px; color: var(--muted); margin: 10px 0 4px; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 18px; margin-bottom: 10px; }
.muted { color: var(--muted); font-size: 14px; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.card { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: 0 1px 2px rgba(15,23,42,.06); }
.row { display: flex; gap: 8px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.topbar { position: sticky; top: 0; z-index: 5; background: var(--brand); color: #fff; padding: 10px 16px; }
.topbar .row { justify-content: space-between; }
.topbar h1 { font-size: 18px; }
.chip { background: rgba(255,255,255,.18); color: #fff; border-radius: 999px; padding: 4px 12px; min-height: 32px; font-size: 14px; }
.tabs { display: flex; gap: 4px; margin-top: 8px; }
.tabs button { flex: 1; background: rgba(255,255,255,.12); color: #fff; min-height: 40px; }
.tabs button[aria-selected="true"] { background: #fff; color: var(--brand); font-weight: 600; }

.tile-img { display: grid; place-items: center; width: 100%; aspect-ratio: 1; border-radius: 10px; color: #fff; font-weight: 700; font-size: 20px; background-size: cover; background-position: center; }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.quick button { display: flex; flex-direction: column; gap: 4px; padding: 6px; height: auto; background: var(--card); font-size: 13px; line-height: 1.2; box-shadow: 0 1px 2px rgba(15,23,42,.08); }
.quick button b { font-size: 14px; color: var(--brand); }

.cart-line { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.cart-line:last-child { border-bottom: 0; }
.qty { display: flex; align-items: center; gap: 6px; }
.qty button { min-width: 44px; padding: 0; font-size: 20px; }
.qty span { min-width: 28px; text-align: center; font-weight: 600; }
.unit-toggle { min-height: 32px; font-size: 13px; padding: 0 10px; background: #ccfbf1; color: var(--brand); }

.paybar { position: sticky; bottom: 0; z-index: 4; background: var(--card); border-top: 1px solid var(--line); padding: 10px 16px calc(10px + var(--safe-b)); }
.paybar .total { font-size: 26px; font-weight: 700; }
.big-change { font-size: 44px; font-weight: 700; color: var(--ok); text-align: center; }
.cash-btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cash-btns button { min-height: 52px; font-weight: 600; }

.sheet-bg { position: fixed; inset: 0; z-index: 20; background: rgba(15,23,42,.5); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--card); width: 100%; max-width: 520px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + var(--safe-b)); }
@media (min-width: 700px) { .sheet-bg { align-items: center; } .sheet { border-radius: 18px; } }
.sheet .actions { display: flex; gap: 8px; margin-top: 16px; }
.sheet .actions button { flex: 1; }
.qr { width: 240px; margin: 8px auto; }
.photo-prev { width: 96px; height: 96px; border-radius: 10px; object-fit: cover; background: #e2e8f0; }

.toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%); z-index: 30; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; max-width: 90vw; }
.toast.bad { background: var(--bad); }
.badge { display: inline-block; border-radius: 999px; padding: 1px 10px; font-size: 13px; background: #e2e8f0; color: var(--ink); }
.badge.warn { background: #fef3c7; color: var(--warn); }
.badge.bad { background: #fee2e2; color: var(--bad); }
.badge.ok { background: #dcfce7; color: var(--ok); }
.list > * + * { border-top: 1px solid var(--line); }
.list > * { padding: 10px 0; }
.search-results { margin-top: 6px; }
.search-results button { width: 100%; display: flex; justify-content: space-between; background: #fff; border: 1px solid var(--line); margin-top: 4px; text-align: left; }
video.scanner { width: 100%; border-radius: 10px; background: #000; max-height: 50vh; object-fit: cover; }

/* ---------- round 2: category boxes (2 columns, thumb-sized) ---------- */
.scanrow { margin-bottom: 6px; }
.crumbs { display: flex; align-items: center; gap: 8px; margin: 6px 0 10px; flex-wrap: wrap; }
.crumbs nav { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; min-width: 0; }
.crumbs nav button { background: none; min-height: 40px; padding: 0 6px; color: var(--brand); font-weight: 600; }
.crumbs nav span { color: var(--muted); }
.crumbs .back { background: var(--brand); color: #fff; font-weight: 600; min-height: 48px; padding: 0 16px; }
.boxes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (min-width: 700px) { .boxes { grid-template-columns: repeat(4, 1fr); } }
.boxes .sect { grid-column: 1 / -1; font-size: 15px; color: var(--muted); margin: 6px 0 -2px; }
.box { position: relative; display: flex; flex-direction: column; justify-content: flex-end; align-items: flex-start; gap: 2px;
  min-height: 112px; padding: 12px; text-align: left; border-radius: 16px; background: var(--card); color: var(--ink);
  box-shadow: 0 1px 3px rgba(15,23,42,.10); overflow: hidden; line-height: 1.25; }
.box b { font-size: 17px; }
.box small { color: var(--muted); font-size: 13px; }
.box.cat { background: var(--c); color: #fff; }
.box.cat small { color: rgba(255,255,255,.9); }
.box.cat .ic { position: absolute; top: 10px; right: 12px; font-size: 22px; opacity: .85; }
.box.prod { border-left: 8px solid var(--c); }
.box.prod .price { font-size: 20px; font-weight: 700; color: var(--brand); }
.box.prod .ph { position: absolute; inset: 0 0 auto auto; width: 56px; height: 56px; border-radius: 0 0 0 12px; background-size: cover; background-position: center; }
.box .n { position: absolute; top: 8px; right: 8px; min-width: 30px; height: 30px; border-radius: 999px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 15px; padding: 0 6px; }
.box.prod .ph ~ .n { right: 64px; }
.box.add { background: transparent; border: 2px dashed #94a3b8; color: var(--muted); box-shadow: none; justify-content: center; align-items: center; text-align: center; font-weight: 600; min-height: 72px; }
.stockmode .box.prod { border-left-color: #b45309; }
.stockmode .topbar { background: #92400e; }

.paybar { display: flex; gap: 10px; align-items: stretch; }
.billbtn { flex: 1; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; background: #f1f5f9; min-height: 60px; text-align: left; }
.billbtn b { font-size: 24px; }
.paybtn { min-height: 60px; min-width: 42%; font-size: 20px; }
.stockmode .paybtn { background: #b45309; }
.paytabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.paytabs button[aria-selected="true"] { background: var(--brand); color: #fff; font-weight: 600; }
.cash-btns .primary { grid-column: span 3; min-height: 56px; font-size: 18px; }
.qty input { width: 64px; text-align: center; min-height: 44px; padding: 4px; }
.sum { border-top: 2px solid var(--line); margin-top: 6px; padding-top: 8px; }
.receipt { font-size: 14px; line-height: 1.5; }
.receipt h3 { text-align: center; margin: 10px 0 2px; font-size: 16px; }
.receipt .lines, .receipt .buyer { border-top: 1px dashed #94a3b8; border-bottom: 1px dashed #94a3b8; padding: 6px 0; margin: 6px 0; }
.staff .paybar { position: fixed; left: 0; right: 0; bottom: 0; }
.staff main { padding-bottom: calc(100px + var(--safe-b)) !important; }
/* product photo on top, name + price under it */
.box.prod.has-ph { padding: 0 0 10px; border-left: 0; justify-content: flex-start; }
.box.prod.has-ph .ph { position: static; display: block; width: 100%; height: auto; aspect-ratio: 4 / 3; border-radius: 0; margin-bottom: 6px; }
.box.prod.has-ph > b, .box.prod.has-ph > .price, .box.prod.has-ph > small { padding: 0 12px; }
.box.prod.has-ph .n { right: 8px; box-shadow: 0 0 0 3px #fff; }
.stockmode .box.prod.has-ph { outline: 3px solid #b45309; outline-offset: -3px; }
