:root {
  --surface: #e9edf1;
  --panel: #ffffff;
  --ink: #16202b;
  --ink-2: #4a5866;
  --ink-3: #7d8a96;
  --line: #d3dae1;
  --line-2: #e4e9ee;
  --jade: #0b7a5c;
  --jade-ink: #075a44;
  --jade-tint: #e3f2ec;
  --amber: #b86e00;
  --amber-tint: #fbf0dc;
  --red: #b7342b;
  --red-tint: #f8e4e2;
  --blue: #2b5c8a;
  --blue-tint: #e3edf6;
  --paper: #fffef9;
  --r-sm: 6px;
  --r-md: 10px;
  --font: "Sukhumvit Set", "Leelawadee UI", "Noto Sans Thai", "IBM Plex Sans Thai", -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", Tahoma, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--surface);
  -webkit-font-smoothing: antialiased;
}
.num, td.r, .money { font-variant-numeric: tabular-nums; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); }
:focus-visible { outline: 3px solid #6aa7de; outline-offset: 1px; }
h1 { font-size: 22px; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 17px; font-weight: 650; margin: 0 0 10px; }
h3 { font-size: 15px; font-weight: 650; margin: 16px 0 8px; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); font-size: 13px; }
.r { text-align: right; }
.c { text-align: center; }
.hidden { display: none !important; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 196px 1fr; min-height: 100vh; }
.rail {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { padding: 16px 16px 12px; border-bottom: 1px solid var(--line-2); }
.brand b { display: block; font-size: 16px; line-height: 1.2; }
.brand span { font-size: 12.5px; color: var(--ink-3); }
.nav { flex: 1; overflow-y: auto; padding: 8px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: var(--r-sm);
  color: var(--ink-2); text-decoration: none; font-size: 14.5px;
}
.nav a svg { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav a:hover { background: var(--surface); color: var(--ink); }
.nav a.on { background: var(--jade-tint); color: var(--jade-ink); font-weight: 600; }
.nav .sep { height: 1px; background: var(--line-2); margin: 8px 4px; }
.rail-foot { border-top: 1px solid var(--line-2); padding: 10px 12px; font-size: 13px; }
.rail-foot .who { font-weight: 600; }
.langs { display: flex; gap: 4px; margin: 8px 0; }
.langs button { flex: 1; border: 1px solid var(--line); background: none; border-radius: var(--r-sm); padding: 3px 0; cursor: pointer; font-size: 12.5px; }
.langs button.on { border-color: var(--jade); color: var(--jade-ink); font-weight: 600; }
.rail-foot .links { display: flex; justify-content: space-between; }
.rail-foot .links button { background: none; border: 0; color: var(--blue); cursor: pointer; padding: 0; font-size: 13px; }
.main { min-width: 0; padding: 20px 24px 40px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin-right: auto; }
.mobile-bar { display: none; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 14px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--panel); cursor: pointer;
  font-weight: 550; white-space: nowrap; text-decoration: none; color: var(--ink);
}
.btn:hover { border-color: var(--ink-3); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--jade); border-color: var(--jade); color: #fff; }
.btn.primary:hover { background: var(--jade-ink); }
.btn.danger { color: var(--red); border-color: #e3b5b1; }
.btn.danger:hover { background: var(--red-tint); }
.btn.ghost { border-color: transparent; background: none; color: var(--blue); padding: 0 8px; }
.btn.sm { min-height: 30px; padding: 0 10px; font-size: 13.5px; }
.btn.lg { min-height: 52px; font-size: 18px; padding: 0 22px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], input[type=tel], select, textarea {
  width: 100%; min-height: 38px; padding: 7px 10px;
  border: 1px solid var(--line); border-radius: var(--r-sm); background: #fff;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--jade); outline: none; box-shadow: 0 0 0 3px var(--jade-tint); }
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 4px; }
label.f small { display: block; color: var(--ink-3); font-size: 12px; margin-top: 3px; }
label.chk { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 12px; cursor: pointer; }
label.chk input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--jade); }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 12px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type=search] { max-width: 320px; }
.toolbar input[type=date] { width: auto; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; background: var(--panel); flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 7px 12px; cursor: pointer; font-size: 14px; color: var(--ink-2); border-right: 1px solid var(--line-2); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--ink); color: #fff; }

/* ---------- tables & panels ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md); }
.panel.pad { padding: 16px; }
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-weight: 600; color: var(--ink-2); font-size: 13px; padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #f6f8fa; }
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: #f6f9fb; }
.tbl th.r, .tbl td.r { text-align: right; }
.tbl .sub { color: var(--ink-3); font-size: 12.5px; }
.empty { padding: 36px 16px; text-align: center; color: var(--ink-3); }
.tag { display: inline-block; font-size: 12.5px; padding: 1px 8px; border-radius: 999px; background: var(--surface); color: var(--ink-2); white-space: nowrap; }
.tag.g { background: var(--jade-tint); color: var(--jade-ink); }
.tag.a { background: var(--amber-tint); color: var(--amber); }
.tag.r { background: var(--red-tint); color: var(--red); }
.tag.b { background: var(--blue-tint); color: var(--blue); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; font-size: 14px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px 16px; text-decoration: none; color: inherit; display: block; }
a.stat:hover { border-color: var(--ink-3); }
.stat .v { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.stat .l { font-size: 13.5px; color: var(--ink-2); }
.stat.warn .v { color: var(--amber); }
.stat.alert .v { color: var(--red); }

/* ---------- POS ---------- */
.pos { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 20px; align-items: start; }
.scan {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 2px solid var(--ink); border-radius: var(--r-md);
  padding: 4px 6px 4px 14px; margin-bottom: 14px;
}
.scan svg { width: 22px; height: 22px; flex: none; stroke: var(--ink-2); fill: none; stroke-width: 1.8; }
.scan input { border: 0 !important; box-shadow: none !important; font-size: 18px; min-height: 48px; padding: 0; }
.scan:focus-within { border-color: var(--jade); box-shadow: 0 0 0 4px var(--jade-tint); }
.pos-tools { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.plist { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.pitem {
  text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 10px 12px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; min-height: 84px;
}
.pitem:hover { border-color: var(--jade); }
.pitem b { font-weight: 600; font-size: 14.5px; line-height: 1.3; }
.pitem .p { margin-top: auto; display: flex; justify-content: space-between; align-items: baseline; font-variant-numeric: tabular-nums; }
.pitem .p strong { font-size: 15px; }
.pitem .q { font-size: 12.5px; color: var(--ink-3); }
.pitem .q.zero { color: var(--red); }
.pitem:disabled { opacity: .45; cursor: not-allowed; }

/* receipt strip */
.receipt {
  position: sticky; top: 16px;
  background: var(--paper);
  padding: 18px 18px 30px;
  box-shadow: 0 1px 0 var(--line), 0 10px 30px -18px rgba(22, 32, 43, .45);
  --zz: 9px;
  -webkit-mask: conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) 50% / calc(var(--zz) * 2) 100%;
  mask: conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) 50% / calc(var(--zz) * 2) 100%;
}
.receipt::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 5px;
  background: repeating-linear-gradient(90deg, var(--ink) 0 2px, transparent 2px 7px); opacity: .12;
}
.r-cust { display: flex; align-items: center; gap: 8px; padding-bottom: 12px; border-bottom: 1px dashed #c9ccc4; }
.r-cust .who { flex: 1; min-width: 0; }
.r-cust .who b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.r-cust .who span { font-size: 12.5px; color: var(--ink-3); }
.r-lines { list-style: none; margin: 0; padding: 4px 0; max-height: 42vh; overflow-y: auto; }
.r-lines li { padding: 9px 0; border-bottom: 1px dotted #d9dbd3; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; }
.r-lines li:last-child { border-bottom: 0; }
.r-lines .nm { font-weight: 550; cursor: pointer; }
.r-lines .nm:hover { text-decoration: underline; }
.r-lines .meta { grid-column: 1; font-size: 12.5px; color: var(--ink-3); }
.r-lines .amt { grid-row: 1 / span 2; grid-column: 2; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.r-lines .ctl { grid-column: 1 / -1; display: flex; gap: 6px; align-items: center; margin-top: 4px; }
.r-lines .ctl button { width: 28px; height: 28px; border: 1px solid var(--line); background: #fff; border-radius: 50%; cursor: pointer; line-height: 1; }
.r-lines .ctl .x { margin-left: auto; width: auto; border: 0; background: none; color: var(--red); font-size: 13px; border-radius: 0; }
.r-empty { padding: 34px 0; text-align: center; color: var(--ink-3); }
.r-adj { display: flex; gap: 6px; flex-wrap: wrap; padding: 10px 0; border-top: 1px dashed #c9ccc4; }
.r-adj .btn { min-height: 32px; font-size: 13.5px; padding: 0 10px; background: transparent; }
.r-sum { border-top: 1px dashed #c9ccc4; padding-top: 10px; font-variant-numeric: tabular-nums; }
.r-sum div { display: flex; justify-content: space-between; padding: 2px 0; font-size: 14px; }
.r-sum .minus { color: var(--jade-ink); }
.r-sum .vat { color: var(--ink-3); font-size: 12.5px; }
.r-total { display: flex; justify-content: space-between; align-items: baseline; margin: 10px 0 14px; padding-top: 10px; border-top: 2px solid var(--ink); }
.r-total span { font-size: 14px; font-weight: 600; }
.r-total strong { font-size: 38px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1; }
.r-actions { display: grid; grid-template-columns: auto 1fr; gap: 8px; }

/* payment modal */
.pay-due { display: flex; justify-content: space-between; align-items: baseline; padding: 12px 14px; background: var(--ink); color: #fff; border-radius: var(--r-sm); margin-bottom: 14px; }
.pay-due strong { font-size: 30px; font-variant-numeric: tabular-nums; }
.pay-rows { display: grid; gap: 8px; }
.pay-row { display: grid; grid-template-columns: 120px 1fr auto; gap: 8px; align-items: center; }
.pay-row label { font-weight: 600; }
.pay-row input { font-size: 17px; text-align: right; font-variant-numeric: tabular-nums; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0 0 128px; }
.quick button { border: 1px solid var(--line); background: #fff; border-radius: var(--r-sm); padding: 4px 10px; cursor: pointer; font-variant-numeric: tabular-nums; }
.pay-status { margin-top: 14px; padding: 10px 14px; border-radius: var(--r-sm); display: flex; justify-content: space-between; font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.pay-status.ok { background: var(--jade-tint); color: var(--jade-ink); }
.pay-status.short { background: var(--amber-tint); color: var(--amber); }
.ppqr { display: grid; grid-template-columns: 170px 1fr; gap: 14px; align-items: center; margin-top: 12px; padding: 12px; border: 1px solid var(--line); border-radius: var(--r-sm); }
.ppqr svg { width: 170px; height: 170px; display: block; }
.ppqr .amt { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.subbox { margin-top: 12px; padding: 12px; border: 1px solid var(--line); border-radius: var(--r-sm); background: #fafbfc; }
.done-mark { width: 64px; height: 64px; border-radius: 50%; background: var(--jade); color: #fff; display: grid; place-items: center; margin: 4px auto 10px; }
.done-mark svg { width: 34px; height: 34px; stroke: #fff; fill: none; stroke-width: 3; }

/* ---------- modal & toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(22, 32, 43, .45); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 12px; z-index: 50; overflow-y: auto; }
.modal { background: var(--panel); border-radius: var(--r-md); width: 100%; max-width: 560px; box-shadow: 0 20px 60px -20px rgba(0,0,0,.4); animation: pop .14s ease-out; }
.modal.wide { max-width: 820px; }
.modal-h { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line-2); }
.modal-h h2 { margin: 0; }
.modal-h .x { border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--ink-3); line-height: 1; padding: 4px; }
.modal-b { padding: 16px 18px; }
.modal-f { padding: 12px 18px; border-top: 1px solid var(--line-2); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
@keyframes pop { from { transform: translateY(6px); opacity: 0; } to { transform: none; opacity: 1; } }
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 99; display: grid; gap: 8px; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: var(--r-sm); font-size: 14.5px; box-shadow: 0 8px 24px -10px rgba(0,0,0,.5); max-width: 90vw; }
.toast.err { background: var(--red); }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: 100%; max-width: 360px; }
.login h1 { margin-bottom: 4px; }
.login .panel { padding: 22px; margin-top: 16px; }

.list-pick { max-height: 50vh; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--r-sm); }
.list-pick button { display: flex; width: 100%; justify-content: space-between; gap: 10px; text-align: left; padding: 10px 12px; border: 0; border-bottom: 1px solid var(--line-2); background: #fff; cursor: pointer; }
.list-pick button:hover { background: var(--jade-tint); }
.list-pick button:last-child { border-bottom: 0; }
.timeline { list-style: none; padding: 0; margin: 0; font-size: 13.5px; }
.timeline li { padding: 6px 0 6px 14px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 12px; width: 8px; height: 8px; border-radius: 50%; background: var(--jade); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }

@media (max-width: 1100px) {
  .pos { grid-template-columns: minmax(0, 1fr) 340px; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: fixed; z-index: 40; left: 0; top: 0; width: 240px; transform: translateX(-100%); transition: transform .18s; box-shadow: 0 0 40px rgba(0,0,0,.2); }
  .rail.open { transform: none; }
  .mobile-bar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; }
  .mobile-bar button { border: 1px solid var(--line); background: none; border-radius: var(--r-sm); width: 38px; height: 38px; font-size: 18px; cursor: pointer; }
  .main { padding: 16px; }
  .pos { grid-template-columns: 1fr; }
  .receipt { position: static; }
  .grid2, .split { grid-template-columns: 1fr; }
  .pay-row { grid-template-columns: 90px 1fr auto; }
  .quick { margin-left: 0; }
  .ppqr { grid-template-columns: 1fr; justify-items: center; text-align: center; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
