/* WAD POS — ใช้บนแท็บเล็ตแนวนอนเป็นหลัก (1280×800) ใช้ได้บนมือถือด้วย
   โลกเดียวสีกระดาษ ไม่มีโหมดมืด: ปุ่มเมนูต้องเป็นสีสินค้าจริงเสมอ พนักงานจำด้วยสี */
:root {
  --blue: #2B4BE8;
  --blue-d: #1F39BC;
  --ink: #141414;
  --paper: #F7F3EA;
  --card: #FFFDF8;
  --orange: #FF5C1F;
  --grey: #6E685D;
  --line: #D9D2C4;
  --off: #E4DED1;
  --red: #B02A0F;
  --green: #1E7A3C;
  --s: 'Sriracha', 'Tahoma', cursive;
  --a: 'Anton', Impact, sans-serif;
  --b: 'Anuphan', 'Segoe UI', system-ui, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink); font-family: var(--b); font-size: 16px;
  -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
  overscroll-behavior: none; touch-action: manipulation;
}
input, textarea, select { user-select: text; -webkit-user-select: text; font: inherit; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: not-allowed; }
[hidden] { display: none !important; }
#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
main { flex: 1; min-height: 0; position: relative; }
[data-screen] { height: 100%; overflow: auto; }
.muted { color: var(--grey); }
.err { color: var(--red); min-height: 1.4em; margin: 6px 0; font-weight: 600; }
.num { font-family: var(--a); letter-spacing: .02em; font-weight: 400; }

/* ---------- ปุ่มทั่วไป ---------- */
.btn {
  border: 2px solid var(--ink); background: var(--card); border-radius: 12px;
  padding: 10px 16px; font-weight: 600; min-height: 48px;
}
.btn:active:not(:disabled) { transform: scale(.97); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: var(--paper); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.btn.danger { background: var(--card); border-color: var(--red); color: var(--red); }
.btn.ghost { border-color: transparent; background: transparent; text-decoration: underline; }
.btn.big { min-height: 64px; font-size: 20px; }
.btn:disabled { opacity: .4; }

/* ---------- แถบบน ---------- */
#topbar {
  flex: none; display: flex; align-items: center; gap: 12px; height: 64px; padding: 0 12px 0 16px;
  background: var(--blue); color: var(--paper);
}
.tb-brand { font-family: var(--s); font-size: 34px; line-height: 1; transform: rotate(-3deg); margin-right: 8px; }
#topbar nav { display: flex; gap: 6px; }
#topbar nav button {
  border: 0; background: transparent; color: var(--paper); padding: 10px 18px; border-radius: 10px;
  font-size: 18px; font-weight: 600; min-height: 46px; white-space: nowrap;
}
#topbar nav button.on { background: var(--paper); color: var(--blue); }
.tb-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.tb-user { font-weight: 600; white-space: nowrap; max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.tb-right .btn { border-color: var(--paper); background: transparent; color: var(--paper); min-height: 42px; padding: 6px 12px; }
.sync-chip {
  border: 0; border-radius: 999px; padding: 6px 12px; font-size: 14px; font-weight: 600; min-height: 34px;
  background: rgba(247,243,234,.18); color: var(--paper); white-space: nowrap;
}
.sync-chip.ok { background: rgba(247,243,234,.18); }
.sync-chip.warn { background: var(--orange); color: var(--ink); }
.sync-chip.bad { background: var(--paper); color: var(--red); }

/* ---------- ตั้งค่าครั้งแรก / ล็อกอิน ---------- */
.center { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.brand-big { font-family: var(--s); color: var(--blue); font-size: 72px; line-height: 1; transform: rotate(-3deg); text-align: center; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 24px; }
.setup { width: min(440px, 100%); display: grid; gap: 12px; }
.setup h1 { margin: 4px 0 0; font-size: 24px; }
.setup p { margin: 0; }
label { display: grid; gap: 4px; font-weight: 600; font-size: 15px; }
input, select, textarea {
  border: 2px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; min-height: 48px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); }
.login { display: grid; justify-items: center; gap: 6px; }

/* ---------- แป้น PIN ---------- */
.pinpad { display: grid; justify-items: center; gap: 12px; }
.pin-title { font-size: 22px; font-weight: 700; text-align: center; }
.pin-sub { color: var(--grey); text-align: center; margin-top: -6px; }
.pin-dots { display: flex; gap: 16px; }
.pin-dots i { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--ink); }
.pin-dots i.on { background: var(--ink); }
.pin-msg { color: var(--red); font-weight: 600; min-height: 1.4em; text-align: center; }
.pin-keys { display: grid; grid-template-columns: repeat(3, 84px); gap: 12px; }
.pin-keys button {
  height: 72px; border-radius: 16px; border: 2px solid var(--line); background: var(--card);
  font-family: var(--a); font-size: 30px;
}
.pin-keys button:active { background: var(--off); }
.pin-keys button.blank { border-color: transparent; background: transparent; font-family: var(--b); font-size: 16px; }
.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }

/* ---------- หน้าขาย ---------- */
.sell { display: grid; grid-template-columns: 1fr 360px; height: 100%; }
.menu-area { display: flex; flex-direction: column; gap: 12px; padding: 12px; min-height: 0; }
.hint {
  flex: none; height: 108px; border-radius: 14px; border: 2px dashed var(--line);
  display: flex; align-items: center; gap: 16px; padding: 10px 14px; color: var(--grey); overflow: hidden;
}
.hint.upsell { border: 2px solid var(--blue); background: #EEF1FF; color: var(--ink); }
.up-text { flex: 1; min-width: 0; }
.up-q { font-weight: 700; color: var(--blue); font-size: 15px; }
.up-th { font-size: 21px; font-weight: 700; line-height: 1.3; }
.up-other { font-size: 14px; color: var(--grey); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.up-other small { color: var(--orange); }
.up-act { display: flex; flex-direction: column; gap: 6px; flex: none; }
.up-act .btn { min-height: 44px; padding: 6px 14px; }
.grid {
  flex: 1; min-height: 0; display: grid; gap: 12px;
  grid-template-columns: repeat(4, 1fr); grid-template-rows: 1fr 1fr;
}
.mbtn {
  background: var(--c); color: var(--t); border: 0; border-radius: 16px; text-align: left;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between;
  padding: 14px 16px; min-height: 120px; position: relative; overflow: hidden;
  box-shadow: inset 0 -6px 0 rgba(0,0,0,.14);
}
.mbtn:active:not(:disabled) { transform: scale(.97); box-shadow: inset 0 -2px 0 rgba(0,0,0,.14); }
.mbtn.off { background: var(--off); color: var(--grey); box-shadow: none; }
.mbtn .m-size { font-family: var(--a); font-size: 26px; line-height: 1; }
.mbtn .m-size em { font-family: var(--b); font-style: normal; font-size: 14px; font-weight: 700; margin-left: 6px; vertical-align: middle; }
.mbtn .m-name { font-size: 23px; font-weight: 700; line-height: 1.2; }
.mbtn .m-en { font-size: 12px; opacity: .85; display: block; font-weight: 500; }
.mbtn .m-price { font-family: var(--a); font-size: 36px; line-height: 1; }
.mbtn.off .m-price { font-family: var(--b); font-size: 15px; font-weight: 600; }
.mbtn.flash::after { content: ''; position: absolute; inset: 0; background: rgba(255,255,255,.45); animation: fade .3s forwards; }
@keyframes fade { to { opacity: 0; } }

.cart { display: flex; flex-direction: column; min-height: 0; background: var(--card); border-left: 1px solid var(--line); position: relative; }
.cart-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px 4px; }
.cart-head h2 { margin: 0; font-size: 20px; }
.cart-lines { list-style: none; margin: 0; padding: 4px 12px; flex: 1; overflow: auto; }
.cart-lines .empty { text-align: center; color: var(--grey); padding: 40px 0; }
.cl { display: grid; grid-template-columns: 8px 1fr auto; grid-template-rows: auto auto; gap: 2px 10px; padding: 10px 4px; border-bottom: 1px solid var(--line); align-items: center; }
.cl-sw { grid-row: span 2; align-self: stretch; border-radius: 4px; background: var(--c); }
.cl-name { font-weight: 700; font-size: 17px; }
.cl-name small { color: var(--grey); font-weight: 500; margin-left: 4px; }
.cl-sum { font-family: var(--a); font-size: 22px; text-align: right; }
.cl-qty { grid-column: 2 / 4; display: flex; align-items: center; gap: 4px; }
.cl-qty button { width: 44px; height: 40px; border-radius: 10px; border: 2px solid var(--line); background: #fff; font-size: 22px; font-weight: 700; line-height: 1; }
.cl-qty span { min-width: 36px; text-align: center; font-family: var(--a); font-size: 22px; }
.cart-total { display: flex; align-items: baseline; gap: 8px; padding: 10px 16px; border-top: 2px solid var(--ink); }
.cart-total span { font-weight: 700; font-size: 18px; }
.cart-total small { color: var(--grey); }
.cart-total strong { margin-left: auto; font-family: var(--a); font-size: 44px; font-weight: 400; line-height: 1; }
.pay { display: grid; gap: 8px; padding: 0 12px 12px; }
.pay .btn { min-height: 60px; font-size: 20px; }
.sale-toast {
  position: absolute; inset: 0; background: var(--ink); color: var(--paper); display: grid; place-content: center;
  text-align: center; gap: 6px; z-index: 5; border: 0; width: 100%;
}
.sale-toast .st-no { font-size: 22px; font-weight: 700; }
.sale-toast .st-no b { font-family: var(--a); font-size: 64px; display: block; line-height: 1.1; font-weight: 400; }
.sale-toast .st-change { font-size: 20px; }
.sale-toast .st-change b { font-family: var(--a); font-size: 72px; display: block; color: var(--orange); font-weight: 400; line-height: 1.1; }
.sale-toast small { opacity: .7; }

/* ---------- หน้าต่างลอย ---------- */
.modal { position: fixed; inset: 0; background: rgba(20,20,20,.55); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal-card { background: var(--paper); border-radius: 20px; padding: 22px; width: min(560px, 100%); max-height: calc(100dvh - 32px); overflow: auto; }
.modal-card h2 { margin: 0 0 12px; font-size: 24px; }
.modal-card.wide { width: min(860px, 100%); }
.cash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.cash-grid .quick { margin-top: 0; grid-template-columns: repeat(2, 1fr); }
.cash-side { display: flex; flex-direction: column; }
.cash-side .pm-act { margin-top: auto; }
@media (max-width: 700px) { .cash-grid { grid-template-columns: 1fr; gap: 8px; } }
.pm-row { display: flex; align-items: baseline; justify-content: space-between; padding: 6px 0; font-size: 18px; font-weight: 600; }
.pm-row strong { font-family: var(--a); font-size: 40px; font-weight: 400; }
.pm-row.recv strong { color: var(--blue); }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 8px 0; }
.quick .btn { padding: 8px 4px; font-family: var(--a); font-weight: 400; font-size: 20px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.keypad button { height: 60px; border-radius: 12px; border: 2px solid var(--line); background: var(--card); font-family: var(--a); font-size: 26px; }
.keypad button:active { background: var(--off); }
.pm-change { margin: 12px 0; padding: 12px; border-radius: 14px; text-align: center; background: var(--off); font-size: 18px; font-weight: 700; }
.pm-change b { display: block; font-family: var(--a); font-size: 52px; font-weight: 400; line-height: 1.1; }
.pm-change.ready { background: var(--ink); color: var(--paper); }
.pm-change.ready b { color: var(--orange); }
.pm-act { display: flex; gap: 10px; justify-content: flex-end; margin-top: 12px; }
.pm-act .btn.big { flex: 1; }
.qr-total { text-align: center; font-family: var(--a); font-size: 88px; line-height: 1.1; color: var(--blue); }
.qr-steps { margin: 8px 0 0; padding-left: 22px; font-size: 18px; line-height: 1.6; }
.qr-steps .warn { color: var(--red); font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 12px; }
.chip { border: 2px solid var(--line); background: var(--card); border-radius: 999px; padding: 10px 16px; font-weight: 600; min-height: 48px; }
.chip.on { border-color: var(--blue); background: var(--blue); color: var(--paper); }
textarea { min-height: 72px; resize: vertical; }

/* ---------- toast ทั่วไป ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; max-width: calc(100% - 32px);
  background: var(--ink); color: var(--paper); padding: 14px 20px; border-radius: 14px; font-weight: 600; font-size: 17px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.toast.bad { background: var(--red); }

/* ---------- หน้าบิล ---------- */
.page { padding: 16px; max-width: 1200px; margin: 0 auto; }
.day-nav { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.day-nav h2 { margin: 0; font-size: 22px; flex: 1; text-align: center; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; }
.stat span { display: block; color: var(--grey); font-size: 14px; font-weight: 600; }
.stat b { font-family: var(--a); font-size: 32px; font-weight: 400; }
.tbl { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.tbl th, .tbl td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl th { font-size: 13px; color: var(--grey); background: var(--paper); }
.tbl td.r, .tbl th.r { text-align: right; }
.tbl .no { font-family: var(--a); font-size: 22px; }
.tbl tr.void td { color: var(--grey); }
.tbl tr.void .money { text-decoration: line-through; }
.tbl .money { font-family: var(--a); font-size: 20px; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 13px; font-weight: 700; background: var(--off); }
.tag.void { background: var(--red); color: #fff; }
.tag.cash { background: var(--ink); color: var(--paper); }
.tag.promptpay { background: var(--blue); color: var(--paper); }
.tag.alipay { background: #EEF1FF; color: var(--blue); }
.syncok { color: var(--green); font-weight: 700; }
.syncwait { color: var(--orange); font-weight: 700; }
.void-note { font-size: 13px; color: var(--red); display: block; }
.section-title { font-size: 18px; margin: 20px 0 8px; }
.table-wrap { overflow-x: auto; }

/* ---------- ตั้งค่า ---------- */
.settings h2 { font-size: 20px; margin: 24px 0 10px; }
.settings h2:first-child { margin-top: 0; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.row > label { flex: 1 1 180px; }
.price-in { width: 110px; }
.sw { display: inline-block; width: 14px; height: 14px; border-radius: 4px; background: var(--c); vertical-align: middle; margin-right: 6px; }
.note { background: #FFF3E8; border-left: 4px solid var(--orange); padding: 10px 14px; border-radius: 8px; margin: 8px 0; font-size: 15px; }

/* ---------- จอเล็ก (มือถือ / แท็บเล็ตแนวตั้ง) ---------- */
@media (max-width: 900px) {
  .sell { grid-template-columns: 1fr; grid-template-rows: auto auto; height: auto; min-height: 100%; }
  .grid { grid-template-columns: repeat(2, 1fr); grid-template-rows: none; grid-auto-rows: 120px; }
  .menu-area { min-height: auto; }
  .hint { height: auto; min-height: 96px; flex-wrap: wrap; }
  .cart { border-left: 0; border-top: 1px solid var(--line); min-height: 360px; }
  #topbar { gap: 6px; padding: 0 8px; }
  #topbar nav button { padding: 8px 10px; font-size: 16px; }
  .tb-brand { font-size: 28px; margin-right: 0; }
  .tb-user { display: none; }
  .quick { grid-template-columns: repeat(2, 1fr); }
}
