/* Pangkati POS — สไตล์ตาม vault:design-system.md
   ครีม/เซจ · ปุ่มทรงแคปซูล · การ์ดมุมมน 12px · เงาบางเบา
   ออกแบบสำหรับแท็บเล็ตแนวนอนหน้าร้านเป็นหลัก แล้วย่อลงมือถือได้ */

:root {
  /* สี — แบรนด์ */
  --sage-head: #555b42;
  --sage-action: #5f6449;
  --sage-deep: #34382b;
  --sage-uplift: #74795b;
  --sage-light: #e5e7dc;
  /* เซจต้นฉบับจาก brand identity — เฉดเดียวที่อ่านออกบนแถบเมนูสีเข้ม (4.7:1)
     เฉดอื่นในระบบถูกทำให้เข้มเพื่อใช้บนพื้นสว่าง เอามาวางบนพื้นเข้มแล้วจมหาย */
  --sage-base: #a1a680;
  --cream: #f3e4d4;
  --ceramic: #e9d8c6;
  --blush: #d99a9e;
  --blush-light: #ebc7c9;

  /* สี — ระบบ */
  --white: #fff;
  --neutral: #f9f9f9;
  --line: rgba(0, 0, 0, 0.1);
  --line-strong: rgba(0, 0, 0, 0.18);
  --ink: rgba(0, 0, 0, 0.87);
  --ink-soft: rgba(0, 0, 0, 0.58);
  --ink-faint: rgba(0, 0, 0, 0.38);
  --danger: #c82014;
  --danger-soft: #fdecea;
  --warn: #b7791f;
  --ok: var(--sage-head);

  /* ระยะ */
  --sp-1: 0.4rem;
  --sp-2: 0.8rem;
  --sp-3: 1.6rem;
  --sp-4: 2.4rem;
  --sp-5: 3.2rem;

  --r-card: 12px;
  --r-pill: 50px;
  --r-sm: 8px;

  --shadow-card: 0 0 0.5px rgba(0, 0, 0, 0.14), 0 1px 1px rgba(0, 0, 0, 0.24);
  --shadow-float: 0 0 6px rgba(0, 0, 0, 0.24), 0 8px 12px rgba(0, 0, 0, 0.14);

  /* ใช้สเกลเดียวกันทั้งแอปเพื่อไม่ให้ลำดับชั้นแกว่งตามแต่ละหน้า */
  --font-sans: 'Noto Sans Thai', system-ui, sans-serif;
  --text-h: 2.4rem;
  --text-body: 1.6rem;
  --text-small: 1.4rem;
  --text-micro: 1.3rem;
  /* ปุ่มสินค้าบนหน้าขายใหญ่กว่าสเกลกลางโดยตั้งใจ — พนักงานหน้าร้านอายุ 40+ สายตายาว
     ต้องอ่านออกจากระยะยืนขายและกดถูกตั้งแต่ครั้งแรก ไม่ใช่เพ่งแล้วกด
     [เจ้าของสั่ง 2026-07-29] ตัวเลขนี้จึงห้ามลดลงเพื่ออัดสินค้าต่อจอให้มากขึ้น */
  --text-tile-name: 1.9rem;
  --text-tile-price: 2.4rem;
  --leading-body: 1.5;
  --leading-compact: 1.2;
  --tracking-body: -0.01em;
  --tracking-head: -0.16px;
  --motion-ui: 0.2s ease;

  --nav-w: 96px;
  --cart-w: 400px;

  font-size: 62.5%; /* 1rem = 10px */
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-body);
  line-height: var(--leading-body);
  letter-spacing: var(--tracking-body);
  color: var(--ink);
  background: var(--cream);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: inherit;
  color: inherit;
}

h1, h2, h3, h4 {
  margin: 0;
  line-height: 3.6rem;
  letter-spacing: var(--tracking-head);
}
h1 { color: var(--sage-head); font-size: var(--text-h); font-weight: 600; }
h2 { color: var(--ink); font-size: var(--text-h); font-weight: 400; }
h3, h4 { color: var(--sage-head); font-size: var(--text-body); font-weight: 600; line-height: var(--leading-body); }

/* ---------- โครงหน้าจอ ---------- */
#app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

.nav {
  width: var(--nav-w);
  flex: 0 0 var(--nav-w);
  background: var(--sage-deep);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: var(--sp-2) 0;
  gap: 2px;
  z-index: 5;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 2px 2px rgba(0, 0, 0, 0.06), 0 0 2px rgba(0, 0, 0, 0.07);
}

.nav__brand {
  color: #fff;
  text-align: center;
  font-size: var(--text-micro);
  font-weight: 700;
  padding: var(--sp-2) var(--sp-1) var(--sp-3);
  opacity: 0.95;
  line-height: 1.25;
}
/* มาสคอตเป็นเส้นสีเซจบนแถบเมนูสีเข้ม — เพิ่มความสว่างให้ตัดกับพื้นพอมองเห็น */
.nav__brand img { display: block; width: 100%; max-width: 56px; height: auto; margin: 0 auto 0.2rem; filter: brightness(1.45); }

.nav__btn {
  background: none;
  border: 0;
  color: rgba(255, 255, 255, 0.7);
  padding: 1.1rem 0.4rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  font-size: var(--text-small);
  transition: transform var(--motion-ui), background var(--motion-ui), color var(--motion-ui);
  position: relative;
}
.nav__btn i { font-style: normal; font-size: 2.2rem; line-height: 1; }
.nav__btn:hover { color: #fff; background: rgba(255, 255, 255, 0.06); }
.nav__btn:active:not(:disabled) { transform: scale(0.95); }
.nav__btn.is-active { color: #fff; background: rgba(255, 255, 255, 0.14); }
.nav__btn.is-active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 8%;
  height: 84%;
  width: 4px;
  background: var(--sage-uplift);
  border-radius: 0 4px 4px 0;
}
.nav__spacer { flex: 1; }

.nav__status {
  color: rgba(255, 255, 255, 0.7);
  font-size: var(--text-micro);
  text-align: center;
  padding: var(--sp-1);
  line-height: 1.4;
}
.nav__dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  /* ไม่ใช้ --ok ตรงนี้ เพราะจุดนี้อยู่บนแถบเมนูสีเข้ม เขียวเข้มบนเขียวเข้ม = มองไม่เห็น (1.7:1) */
  background: var(--sage-base);
  margin-inline-end: 4px;
}
.nav__dot--off { background: var(--ink-faint); }
.nav__dot--pending { background: var(--warn); }

.view {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  background: var(--white);
  border-bottom: 1px solid var(--line);
  min-height: 60px;
  flex-wrap: wrap;
}
.topbar h1 { margin-inline-end: auto; }
.topbar__sub { color: var(--ink-soft); font-size: var(--text-micro); }

/* คู่ช่องวันที่ — มัดไว้ด้วยกันเพื่อให้ตกลงมาทั้งคู่พร้อมกันบนจอแคบ ไม่ใช่ตัวหนึ่งค้างนอกจอ */
.daterange { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.daterange .input { flex: 1 1 0; min-width: 0; max-width: 170px; }

.scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--sp-3);
}

/* ---------- ปุ่ม ---------- */
.btn {
  border: 1px solid transparent;
  border-radius: var(--r-pill);
  padding: 0.7rem 1.6rem;
  font-size: var(--text-body);
  font-weight: 600;
  line-height: var(--leading-compact);
  cursor: pointer;
  background: var(--white);
  color: var(--sage-action);
  border-color: var(--sage-action);
  transition: transform var(--motion-ui), background var(--motion-ui), opacity var(--motion-ui), box-shadow var(--motion-ui);
  min-height: 44px;
  white-space: nowrap;
}
.btn:active:not(:disabled) { transform: scale(0.95); }
.btn:disabled { opacity: 0.42; cursor: not-allowed; transform: none; }
.btn--primary { background: var(--sage-action); color: #fff; }
.btn--ghost { background: transparent; border-color: var(--line-strong); color: var(--ink); }
.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--danger-ghost { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn--sm { padding: 0.7rem 1.2rem; font-size: var(--text-small); min-height: 44px; }
.btn--block { width: 100%; }
.btn--lg { padding: 1.5rem 2.4rem; font-size: var(--text-body); }

.chip {
  border: 1px solid var(--line-strong);
  background: var(--white);
  border-radius: var(--r-pill);
  padding: 0.7rem 1.6rem;
  font-size: var(--text-small);
  font-weight: 600;
  line-height: var(--leading-compact);
  cursor: pointer;
  color: var(--ink-soft);
  min-height: 44px;
  white-space: nowrap; /* กันชื่อหมวดยาวๆ ตัดบรรทัดจนปุ่มบวม */
  flex: 0 0 auto;
}
.chip.is-active {
  background: var(--sage-action);
  border-color: var(--sage-action);
  color: #fff;
}
.chip:active:not(:disabled) { transform: scale(0.95); }

/* คีย์บอร์ดต้องเห็นตำแหน่งชัด โดยไม่เปลี่ยนสีตามบทบาทของปุ่ม */
:where(button, input, select, textarea):focus-visible {
  outline: 3px solid var(--sage-action);
  outline-offset: 2px;
}

button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  transform: none;
}

:where(input, select, textarea):disabled {
  background: var(--neutral);
  color: var(--ink-faint);
  cursor: not-allowed;
  opacity: 0.65;
}

@media (hover: hover) {
  .btn:not(:disabled):hover,
  .chip:not(:disabled):hover,
  .fav:not(:disabled):hover,
  .tile:not(:disabled):hover,
  .qtybtn:not(:disabled):hover,
  .numpad__key:not(:disabled):hover,
  .chooser__opt:not(:disabled):hover,
  .modal__x:not(:disabled):hover,
  .toast__action:not(:disabled):hover {
    box-shadow: 0 0 0 2px rgba(95, 100, 73, 0.18);
  }
}

/* ---------- ฟอร์ม ---------- */
.input,
.select,
textarea.input {
  width: 100%;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--r-sm);
  padding: 1rem 1.2rem;
  background: var(--white);
  min-height: 44px;
  user-select: text;
}
.input:focus,
.select:focus {
  border-color: var(--sage-action);
}
.input--lg { font-size: 1.9rem; padding: 1.3rem 1.4rem; }
.field { margin-bottom: var(--sp-2); }
.field > label {
  display: block;
  font-size: var(--text-micro);
  color: var(--ink-soft);
  margin-bottom: 0.4rem;
  font-weight: 600;
}
.field__hint { font-size: var(--text-micro); color: var(--ink-faint); margin: 0.3rem 0 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2); }
.switch { display: flex; align-items: center; gap: var(--sp-2); cursor: pointer; }
.switch input { width: 22px; height: 22px; accent-color: var(--sage-action); }

/* ---------- การ์ด ---------- */
.card {
  background: var(--white);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-card);
  padding: var(--sp-3);
  margin-bottom: var(--sp-3);
}
.card__title {
  font-size: var(--text-body);
  font-weight: 600;
  color: var(--sage-head);
  margin: 0 0 var(--sp-2);
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  justify-content: space-between;
}

/* ---------- หน้าขาย ---------- */
.sale {
  display: flex;
  flex: 1;
  min-height: 0;
}
.sale__catalog {
  flex: 1;
  min-width: 0;
  min-height: 0; /* สำคัญ: ไม่งั้นกริดสินค้าดันตะกร้าตกจอบนมือถือ */
  display: flex;
  flex-direction: column;
}
.cats {
  display: flex;
  gap: var(--sp-1);
  padding: var(--sp-2) var(--sp-3);
  overflow-x: auto;
  background: var(--white);
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}
.cats::-webkit-scrollbar { display: none; }

/* ---------- แถบสินค้าโปรด ----------
   ตรึงเหนือกริด ไม่เลื่อนหายและไม่หายตอนสลับหมวด
   ต่อให้มีสินค้า 90 รายการ ตัวขายดีก็ยังกดได้ทันทีโดยไม่ต้องเลื่อน/เปลี่ยนหมวด */
.favbar {
  display: flex;
  gap: var(--sp-1);
  padding: var(--sp-2) var(--sp-3);
  overflow-x: auto;
  background: var(--ceramic);
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}
.favbar::-webkit-scrollbar { display: none; }
.favbar[hidden] { display: none; }
.favbar__label {
  flex: 0 0 auto;
  align-self: center;
  font-size: var(--text-body);
  line-height: 1;
  opacity: 0.75;
}
.fav {
  position: relative;
  flex: 0 0 auto;
  min-width: 112px;
  max-width: 168px;
  min-height: 60px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.1rem;
  text-align: start;
  background: var(--white);
  border: 1.5px solid var(--sage-uplift);
  border-radius: var(--r-sm);
  padding: 0.6rem 1rem;
  cursor: pointer;
  transition: transform var(--motion-ui), box-shadow var(--motion-ui);
}
.fav:active:not(:disabled) { transform: scale(0.95); }
.fav__name {
  font-weight: 700;
  font-size: 1.7rem;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fav__price { font-size: var(--text-body); font-weight: 700; color: var(--sage-action); }

.grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(172px, 1fr));
  /* แถวสูงอย่างน้อยเท่าการ์ด แต่ยืดตามเนื้อหาได้ — ชื่อสินค้าบางตัวยาวจนตัด 2 บรรทัด
     ถ้าล็อกความสูงไว้เฉยๆ การ์ดตั้ง overflow:hidden ไว้ ราคาจะโดนตัดหายไปเลย */
  grid-auto-rows: minmax(128px, auto);
  gap: var(--sp-2);
  padding: var(--sp-3);
  align-content: start;
}

/* สินค้าเยอะ = ปุ่มเล็กลง เห็นต่อจอมากขึ้น (ยังกว้างกว่า 100px จึงยังกดง่าย) */
.grid--dense { grid-template-columns: repeat(auto-fill, minmax(136px, 1fr)); grid-auto-rows: minmax(116px, auto); }
.grid--dense .tile { min-height: 116px; padding: 1rem; }
.grid--dense .tile__name { font-size: 1.7rem; }
.grid--dense .tile__price { font-size: 2rem; }
.grid--dense .tile__variants { font-size: var(--text-small); }

/* หัวข้อหมวดในกริด — ค้างไว้ด้านบนตอนเลื่อน จะได้รู้ตลอดว่าอยู่หมวดไหน */
.grid__head {
  grid-column: 1 / -1;
  position: sticky;
  top: calc(var(--sp-3) * -1);
  z-index: 2;
  margin: 0;
  padding: 0.6rem 0 0.6rem 1rem;
  font-size: var(--text-small);
  font-weight: 700;
  color: var(--ink-soft);
  background: var(--cream);
  border-inline-start: 4px solid var(--tile-color, var(--sage-uplift));
}
.grid__count { color: var(--ink-faint); font-weight: 600; }

.tile {
  background: var(--white);
  border: 0;
  border-radius: var(--r-card);
  box-shadow: var(--shadow-card);
  padding: 1.2rem 1rem;
  cursor: pointer;
  text-align: start;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  /* 116px = พอดีกับ emoji + ชื่อ 1 บรรทัด + ขนาด + ราคา ตามสเกลตัวอักษรของ design system
     การ์ดตั้ง overflow:hidden ไว้ ถ้าตั้งเตี้ยกว่านี้ราคาจะโดนตัดหาย */
  min-height: 128px;
  position: relative;
  overflow: hidden;
  transition: transform var(--motion-ui), box-shadow var(--motion-ui);
}
.tile:active:not(:disabled) { transform: scale(0.95); }
.tile::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: var(--tile-color, var(--sage-uplift));
}
/* การ์ดสินค้าใช้ leading แบบกระชับ ไม่ใช่ค่า body — ขนาดตัวอักษรยังอยู่ในสเกลกลาง
   แต่ระยะบรรทัดต้องแน่น เพราะต้องอัดปุ่มให้ได้ ~15 ปุ่มต่อจอบน SUNMI V3
   (ถ้าใช้ leading 1.5 เนื้อหาจะสูง 125px เกินกรอบการ์ด 104px แล้วราคาโดนตัด) */
/* ชื่อสินค้าจองที่ไว้ 2 บรรทัดเสมอ และตัดด้วย … ถ้ายาวกว่านั้น
   เหตุผล: การ์ดตั้ง overflow:hidden คู่กับ min-height เบราว์เซอร์จะตีค่าความสูงเนื้อหาเป็น 0
   แถวของกริดเลยโตตามชื่อที่ตัด 2 บรรทัดไม่ได้ ผลคือราคาโดนตัดหายเงียบๆ
   จองที่ไว้ตายตัวแทน = การ์ดสูงเท่ากันหมด ราคาไม่มีวันหาย ไม่ว่าชื่อจะยาวแค่ไหน */
.tile__name {
  font-weight: 700;
  font-size: var(--text-tile-name);
  line-height: var(--leading-compact);
  min-height: calc(var(--text-tile-name) * var(--leading-compact) * 2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.tile__price { margin-top: auto; color: var(--sage-action); font-weight: 700; font-size: var(--text-tile-price); line-height: var(--leading-compact); }
.tile__variants { font-size: var(--text-small); color: var(--ink-soft); line-height: var(--leading-compact); }
.tile--muted { opacity: 0.45; }
.tile__badge {
  position: absolute;
  top: 6px;
  inset-inline-end: 6px;
  background: var(--warn);
  color: var(--white);
  font-size: var(--text-micro);
  font-weight: 700;
  border-radius: var(--r-pill);
  padding: 0.1rem 0.7rem;
}
/* จำนวนที่อยู่ในตะกร้าแล้ว — เห็นทันทีว่ากดไปกี่ชิ้น ไม่ต้องเปิดตะกร้าดู */
.tile__badge--cart {
  background: var(--sage-action);
  min-width: 26px;
  text-align: center;
  font-size: 1.3rem;
  padding: 0.2rem 0.6rem;
}
.tile--incart {
  outline: 2px solid var(--sage-action);
  outline-offset: -2px;
}

/* ตัวคูณจำนวน: กดเลือกก่อน แล้วแตะสินค้าได้เลยหลายชิ้น */
.qtychip {
  font-variant-numeric: tabular-nums;
  min-width: 56px;
}
.qtychip.is-active {
  background: var(--sage-action);
  border-color: var(--sage-action);
  color: #fff;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  50% { opacity: 0.72; }
}

/* ตะกร้า */
.cart {
  width: var(--cart-w);
  flex: 0 0 var(--cart-w);
  background: var(--white);
  border-inline-start: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}
.cart__head {
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.cart__head h2 { font-size: var(--text-body); font-weight: 600; line-height: var(--leading-body); margin-inline-end: auto; min-width: 0; }
/* ตอนตะกร้าย่อ ยังเห็นรายการล่าสุด — รู้ทันทีว่ากดถูกไหม */
.cart__peek {
  display: block;
  font-size: var(--text-micro);
  font-weight: 400;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cart__lines { flex: 1; overflow-y: auto; padding: var(--sp-2); }

.line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.2rem var(--sp-2);
  padding: var(--sp-2);
  border-radius: var(--r-sm);
  align-items: center;
}
.line + .line { border-top: 1px solid var(--line); }
.line { transition: transform 0.12s ease-out, background 0.12s; touch-action: pan-y; }
.line.is-selected { background: var(--sage-light); }
.line__name { font-weight: 600; font-size: var(--text-body); }
.line__meta { grid-column: 1; color: var(--ink-soft); font-size: var(--text-small); }
.line__total { font-weight: 600; text-align: end; font-size: var(--text-body); }
.line__note { grid-column: 1 / -1; font-size: var(--text-micro); color: var(--ink-soft); }
.line__discount { color: var(--danger); font-size: var(--text-small); }
.line__qty {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.qtybtn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1.5px solid var(--line-strong);
  background: var(--white);
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  transition: transform var(--motion-ui), box-shadow var(--motion-ui);
}
.qtybtn:active:not(:disabled) { transform: scale(0.95); }
.qtynum { min-width: 28px; text-align: center; font-weight: 700; }

.cart__foot { border-top: 1px solid var(--line); padding: var(--sp-2) var(--sp-3) var(--sp-3); }

/* แถวปุ่มปิดการขาย — "พักบิล" กับ "รับเงิน" อยู่คู่กันตรงจุดที่ตัดสินใจ
   รับเงินกว้างกว่าเท่าตัวเพราะเป็นทางที่เดินบ่อยกว่ามาก */
.cart__pay { display: flex; gap: var(--sp-2); }
.cart__pay .cart__charge { flex: 2 1 0; min-width: 0; }
.cart__pay .cart__park { flex: 1 1 0; min-width: 0; }
.totals { margin-bottom: var(--sp-2); }
.totals__row {
  display: flex;
  justify-content: space-between;
  font-size: 1.4rem;
  color: var(--ink-soft);
  padding: 0.2rem 0;
}
.totals__row--big {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--ink);
  border-top: 1px solid var(--line);
  margin-top: var(--sp-1);
  padding-top: var(--sp-1);
}
.totals__row--discount { color: var(--danger); }

.cart__actions { display: flex; gap: var(--sp-1); margin-bottom: var(--sp-2); flex-wrap: wrap; }
.cart__actions .btn { flex: 1; }

/* ---------- ตาราง ---------- */
.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 1.4rem;
}
table.data th,
table.data td {
  padding: 1rem 1.2rem;
  text-align: start;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.data th {
  font-size: var(--text-small);
  color: var(--ink-soft);
  font-weight: 700;
  background: var(--neutral);
  position: sticky;
  top: 0;
  z-index: 1;
}
table.data td.num,
table.data th.num { text-align: end; font-variant-numeric: tabular-nums; }
table.data tbody tr:active { background: var(--sage-light); }
table.data tr.is-void td { color: var(--ink-faint); text-decoration: line-through; }
table.data tr.is-refund td { color: var(--danger); }

/* ---------- ป้าย/สถานะ ---------- */
.badge {
  display: inline-block;
  border-radius: var(--r-pill);
  padding: 0.2rem 1rem;
  font-size: var(--text-micro);
  font-weight: 700;
  background: var(--sage-light);
  color: var(--sage-head);
}
.badge--danger { background: var(--danger-soft); color: var(--danger); }
.badge--warn { background: #fdf3e2; color: var(--warn); }
.badge--ok { background: var(--sage-light); color: var(--ok); }
.badge--muted { background: var(--neutral); color: var(--ink-soft); }

.notice {
  border-radius: var(--r-card);
  padding: var(--sp-2) var(--sp-3);
  margin-bottom: var(--sp-3);
  background: #fdf3e2;
  border-inline-start: 4px solid var(--warn);
  font-size: 1.4rem;
}
.notice--danger { background: var(--danger-soft); border-color: var(--danger); }
.notice--info { background: var(--sage-light); border-color: var(--sage-action); }
.notice--warn { background: #fdf3e2; border-color: var(--warn); }
.notice a { color: inherit; }

/* ---------- สถิติ ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
}
.stat {
  background: var(--white);
  border-radius: var(--r-card);
  padding: var(--sp-2) var(--sp-3);
  box-shadow: var(--shadow-card);
}
.stat__label { font-size: var(--text-small); color: var(--ink-soft); }
.stat__value { font-size: 2.4rem; font-weight: 700; color: var(--sage-head); font-variant-numeric: tabular-nums; }
.stat__sub { font-size: var(--text-micro); color: var(--ink-faint); }
.stat--accent { background: var(--sage-deep); }
.stat--accent .stat__label { color: rgba(255, 255, 255, 0.7); }
.stat--accent .stat__value { color: #fff; }
.stat--accent .stat__sub { color: rgba(255, 255, 255, 0.7); }

/* แถบสัดส่วน */
.bar {
  height: 8px;
  background: var(--sage-light);
  border-radius: var(--r-pill);
  overflow: hidden;
  margin-top: 4px;
}
.bar__fill { height: 100%; background: var(--sage-action); border-radius: var(--r-pill); }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: var(--sp-2);
  animation: fade 0.12s ease-out;
}
.modal-backdrop.is-closing { opacity: 0; transition: opacity 0.12s; }
@keyframes fade { from { opacity: 0; } }

.modal {
  background: var(--white);
  border-radius: var(--r-card);
  width: min(560px, 100%);
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-float);
  animation: pop 0.14s ease-out;
}
@keyframes pop { from { transform: scale(0.96); opacity: 0; } }
.modal--sm { width: min(400px, 100%); }
.modal--lg { width: min(880px, 100%); }
.modal--full { width: min(1100px, 100%); height: 92dvh; }
.modal__head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--line);
}
.modal__head h2 { flex: 1; }
.modal__x {
  border: 0;
  background: none;
  font-size: 2rem;
  cursor: pointer;
  color: var(--ink-soft);
  padding: 0.4rem 0.8rem;
  border-radius: 50%;
  min-width: 44px;
  min-height: 44px;
  transition: transform var(--motion-ui), box-shadow var(--motion-ui);
}
.modal__x:active:not(:disabled) { transform: scale(0.95); }
.modal__body { padding: var(--sp-3); overflow-y: auto; flex: 1; }
.modal__foot {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-top: 1px solid var(--line);
  justify-content: flex-end;
}
.modal__foot .btn { flex: 1; max-width: 240px; }
.modal__text { margin: 0; font-size: 1.6rem; }
.modal__hint { margin: 0 0 var(--sp-2); color: var(--ink-soft); font-size: var(--text-small); }

/* ---------- numpad ---------- */
.numpad__display {
  display: block;
  text-align: end;
  font-size: 3.6rem;
  font-weight: 700;
  padding: var(--sp-2) var(--sp-3);
  background: var(--neutral);
  border-radius: var(--r-sm);
  margin-bottom: var(--sp-2);
  font-variant-numeric: tabular-nums;
  min-height: 62px;
  color: var(--sage-head);
}
.numpad__grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-1);
}
.numpad__key {
  padding: 1.6rem 0;
  font-size: 2.2rem;
  font-weight: 600;
  border: 1.5px solid var(--line-strong);
  background: var(--white);
  border-radius: var(--r-sm);
  cursor: pointer;
  min-height: 56px;
  transition: transform var(--motion-ui), background var(--motion-ui), box-shadow var(--motion-ui);
}
.numpad__key:active:not(:disabled) { transform: scale(0.95); background: var(--sage-light); }
.numpad__key--del { color: var(--danger); }

/* ---------- chooser ---------- */
.chooser { display: grid; gap: var(--sp-2); }
.chooser__opt {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0 var(--sp-2);
  align-items: center;
  background: var(--white);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--r-card);
  padding: var(--sp-2) var(--sp-3);
  cursor: pointer;
  text-align: start;
  min-height: 60px;
  transition: transform var(--motion-ui), background var(--motion-ui), box-shadow var(--motion-ui);
}
.chooser__opt:active:not(:disabled) { transform: scale(0.95); background: var(--sage-light); }
.chooser__icon { font-size: 2.4rem; grid-row: span 2; }
.chooser__label { font-weight: 700; font-size: 1.6rem; }
.chooser__hint { font-size: var(--text-small); color: var(--ink-soft); }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: var(--sp-4);
  left: 50%;
  transform: translate(-50%, 20px);
  background: var(--sage-deep);
  color: #fff;
  padding: 1.2rem 2.4rem;
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-float);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 200;
  font-weight: 600;
  max-width: 90vw;
  text-align: center;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast--error { background: var(--danger); }
.toast__action {
  margin-inline-start: var(--sp-2);
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.45);
  color: #fff;
  border-radius: var(--r-pill);
  padding: 0.3rem 1.2rem;
  font-weight: 700;
  cursor: pointer;
  pointer-events: auto;
  min-height: 44px;
  transition: transform var(--motion-ui), box-shadow var(--motion-ui);
}
.toast__action:active:not(:disabled) { transform: scale(0.95); }
/* ตัวข้อความไม่รับการกดเลย (กันไม่ให้บังปุ่ม/การปัดที่อยู่ข้างใต้)
   มีแค่ปุ่ม "เลิกทำ" ข้างในที่กดได้ */
.toast--ok { background: var(--sage-deep); }

/* ---------- empty ---------- */
.empty { text-align: center; padding: var(--sp-5) var(--sp-3); color: var(--ink-soft); }
.empty__icon { font-size: 4.8rem; opacity: 0.5; }
.empty__title { font-size: var(--text-body); font-weight: 600; margin: var(--sp-2) 0 0; }
.empty__hint { font-size: var(--text-small); color: var(--ink-faint); }

/* ---------- ใบเสร็จ ---------- */
.receipt {
  font-family: var(--font-sans);
  background: #fff;
  color: #000;
  width: 100%;
  max-width: 380px;
  margin: 0 auto;
  padding: 12px;
  font-size: 12.5px;
  line-height: 1.45;
}
.receipt__center { text-align: center; }
.receipt__shop { font-size: 17px; font-weight: 700; }
.receipt__hr { border-top: 1px dashed #000; margin: 6px 0; }
.receipt__row { display: flex; justify-content: space-between; gap: 8px; }
.receipt__row--big { font-size: 16px; font-weight: 700; }
.receipt__line { margin: 3px 0; }
.receipt__line-sub { color: #444; padding-inline-start: 10px; }
.receipt__qr { display: block; margin: 8px auto; width: 190px; height: 190px; }
.receipt__foot { text-align: center; margin-top: 8px; white-space: pre-line; font-size: 11.5px; }

/* ---------- ล็อกอิน ---------- */
/* หน้าล็อกเป็นลูกโดยตรงของ #app ซึ่งเป็น flex แนวนอน
   ถ้าไม่สั่ง flex/width ให้ มันจะหดตามความกว้างเนื้อหา (เคยเหลือ ~186px บนเดสก์ท็อป
   แล้วที่เหลือเป็นพื้นหลังเปล่า) — ต้องกินเต็มจอเสมอ */
.lock {
  display: grid;
  place-items: center;
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  height: 100dvh;
  background: var(--sage-deep);
  padding: var(--sp-3);
}
.lock__card {
  background: var(--white);
  border-radius: var(--r-card);
  padding: var(--sp-4);
  width: min(400px, 100%);
  text-align: center;
  box-shadow: var(--shadow-float);
}
/* โลโก้จริงจากงานแบรนด์ (vault:uploads/2026-07-13) ไม่ใช่อิโมจิแทน */
.lock__logo { width: min(260px, 60%); height: auto; display: block; margin: 0 auto var(--sp-2); }
.splash__logo { width: min(260px, 60%); height: auto; display: block; margin: 0 auto var(--sp-3); }
.lock__dots { display: flex; gap: var(--sp-2); justify-content: center; margin: var(--sp-3) 0; }
.lock__dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--sage-action);
}
.lock__dot.is-on { background: var(--sage-action); }
.lock__err { color: var(--danger); min-height: 20px; font-size: var(--text-small); }
.lock__title { font-size: var(--text-h); margin: 0 0 var(--sp-1); text-align: center; color: var(--sage-head); }
.lock__hint { font-size: var(--text-small); color: var(--ink-soft); text-align: center; margin: 0 0 var(--sp-3); }

/* เลือกว่าใครกำลังเข้ากะ ก่อนใส่ PIN — กันเคส PIN ชนกันแล้วล็อกอินเป็นคนผิด */
.whois {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: var(--sp-2);
  margin: var(--sp-3) 0 var(--sp-2);
}
.whois__btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: var(--sp-3) var(--sp-2);
  min-height: 88px;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--r-card);
  background: var(--white);
  cursor: pointer;
  transition: transform var(--motion-ui), box-shadow var(--motion-ui);
}
.whois__btn:active:not(:disabled) { transform: scale(0.95); }
.whois__face { font-size: 2.8rem; line-height: 1; }
.whois__name { font-weight: 600; font-size: var(--text-small); line-height: var(--leading-compact); }
.whois__btn.is-locked { opacity: 0.55; border-style: dashed; }

/* ---------- utility ---------- */
.row { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }
.row--end { justify-content: flex-end; }
.spacer { flex: 1; }
.muted { color: var(--ink-soft); }
.small { font-size: var(--text-small); }
.danger { color: var(--danger); }
.ok { color: var(--ok); }
.nowrap { white-space: nowrap; }
.mt-2 { margin-top: var(--sp-2); }
.mt-3 { margin-top: var(--sp-3); }
.mt-1 { margin-top: var(--sp-2); }
.mb-2 { margin-bottom: var(--sp-2); }
.tabular { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* ---------- จอเล็ก: มือถือ + เครื่อง POS มือถือ เช่น SUNMI V3 (จอ 6.75") ---------- */
@media (max-width: 860px) {
  :root { --nav-w: 100%; --cart-w: 100%; --nav-h: 60px; }
  #app { flex-direction: column-reverse; }
  .nav {
    flex-direction: row;
    height: var(--nav-h);
    flex: 0 0 var(--nav-h);
    padding: 0;
    overflow-x: auto;
    z-index: 8;
  }
  /* ตัวคั่นมีไว้ดันสถานะไปท้ายแถบตอนเมนูเป็นแนวตั้ง — พอเป็นแถบล่างแนวนอน
     มันกลายเป็นช่องว่างท้ายแถบ ดันปุ่มไปกองซ้าย (เจ้าของทัก 2026-07-29) */
  .nav__brand, .nav__status, .nav__spacer { display: none; }
  .nav__btn { flex: 1; padding: 0.5rem 0.2rem; font-size: var(--text-micro); }
  .nav__btn i { font-size: 1.9rem; }
  .nav__btn.is-active::before { inset: auto 20% 0 20%; height: 3px; width: auto; border-radius: 3px 3px 0 0; }

  /* แถบบนบีบให้อยู่แถวเดียว เลื่อนแนวนอนแทนการตัดบรรทัด */
  .topbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    min-height: 52px;
    padding: var(--sp-1) var(--sp-2);
    gap: var(--sp-1);
  }
  .topbar::-webkit-scrollbar { display: none; }
  .topbar h1 { font-size: var(--text-h); }
  .topbar .input { min-width: 150px; }
  .topbar .btn, .topbar .chip { flex: 0 0 auto; }
  /* "บิลที่พักไว้" โผล่เฉพาะตอนมีบิลค้างจริง — ตรึงขอบขวาไว้ ไม่ให้เลื่อนหลุดจอ
     ถ้าปล่อยให้ไหลไปตามแถบ มันจะโผล่มาแบบโดนตัดครึ่งพอดีตอนที่ต้องใช้ */
  .topbar #btn-parked {
    position: sticky;
    right: 0;
    background: var(--white);
    box-shadow: -1px 0 3px rgba(0, 0, 0, 0.1), -2px 0 2px rgba(0, 0, 0, 0.06), 0 0 2px rgba(0, 0, 0, 0.07);
  }

  /* กลุ่มปุ่มในแถบบนห้ามตกบรรทัด — .row เป็น wrap โดยปริยาย พอถูกบีบในแถบที่ nowrap
     ปุ่มข้างในจะเรียงตัวลงเป็นแนวตั้งซ้อนหัวข้อ (เคยพังจริงที่หน้ารายงานบนจอ 360px) */
  .topbar .row { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .topbar .row::-webkit-scrollbar { display: none; }

  /* หน้าที่มีตัวกรองเยอะ (รายงาน · ประวัติบิล) ให้ตกบรรทัดแทนการเลื่อนแนวนอน
     — ตัวกรองที่ต้องเลื่อนไปหาคือตัวกรองที่ไม่มีใครใช้ */
  .topbar--wrap { flex-wrap: wrap; overflow-x: visible; }
  .topbar--wrap > .row { flex: 1 1 100%; min-width: 0; }
  .topbar--wrap .daterange { flex: 1 1 100%; }
  .topbar--wrap .daterange .input { min-width: 0; max-width: none; }
  .btn--sm { min-height: 44px; } /* เครื่องจริงต้องเหลือพื้นที่นิ้วแม้เป็นปุ่มย่อ */

  /* สองคอลัมน์บนจอ 360px ทำให้ค่าใน select ถูกตัดจนอ่านไม่รู้เรื่อง
     (เจอจริง: "เครื่อง POS And…" / "58 มม. (ใบเสร็จ…") — ยอมสูงขึ้นดีกว่าอ่านไม่ออก */
  .grid-2 { grid-template-columns: 1fr; }

  .sale { flex-direction: column; }
  .cats { padding: var(--sp-1) var(--sp-2); }
  .favbar { padding: var(--sp-1) var(--sp-2); }
  .fav { min-width: 88px; max-width: 128px; min-height: 46px; }
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    padding: var(--sp-2) var(--sp-2) 172px; /* เว้นที่ให้ตะกร้าที่ลอยอยู่ล่าง */
  }
  /* ต้องประกาศซ้ำใน media query นี้ ไม่งั้นกฎ .grid ข้างบนจะทับ (specificity เท่ากันแต่มาทีหลัง) */
  .grid--dense { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); }
  .grid__head { top: calc(var(--sp-2) * -1); }
  .scroll { padding: var(--sp-2); }
  .modal__foot .btn { max-width: none; }

  /* ตะกร้า = แผ่นลอยด้านล่าง ย่อ/ขยายได้ — ปุ่มรับเงินต้องเห็นตลอดเวลา */
  .cart {
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--nav-h);
    z-index: 6;
    max-height: 78dvh;
    border-inline-start: 0;
    border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.1), 0 -2px 2px rgba(0, 0, 0, 0.06), 0 0 2px rgba(0, 0, 0, 0.07);
  }
  .cart__head { padding: var(--sp-1) var(--sp-2); }
  .cart__head h2 { font-size: var(--text-body); }
  .cart__lines { max-height: 40dvh; }
  .cart__foot { padding: var(--sp-1) var(--sp-2) var(--sp-2); }
  /* ตอนย่อ: โชว์แค่ยอดรวม + ปุ่มรับเงิน */
  .cart:not(.is-open) .cart__lines,
  .cart:not(.is-open) .cart__actions,
  .cart:not(.is-open) .totals__row:not(.totals__row--big) { display: none; }
  .cart__toggle { display: inline-flex !important; }

  /* จอเล็ก: วางข้อความแจ้งเตือนเหนือตะกร้าพอดี
     - ไม่บังปุ่มสินค้าแถวแรก (ซึ่งเป็นตัวขายดี กดบ่อยสุด)
     - อยู่ใกล้นิ้วโป้ง กดปุ่ม "เลิกทำ" ได้ทันทีโดยไม่ต้องเอื้อม */
  .toast {
    bottom: calc(var(--nav-h) + 184px); /* = สูงกว่าตะกร้าที่ย่ออยู่ (174px) เล็กน้อย */
    top: auto;
    transform: translate(-50%, 12px);
    max-width: 94vw;
  }
  .toast.is-visible { transform: translate(-50%, 0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

.cart__toggle { display: none; }

/* ---------- พิมพ์ใบเสร็จ ---------- */
@media print {
  body { background: #fff; }
  #app, .modal-backdrop, .toast { display: none !important; }
  #print-area { display: block !important; }
  @page { margin: 3mm; size: auto; }
}

#print-area { display: none; }

/* ---------- แป้นตัวเลข: ปุ่มดูเลขที่กดไป ---------- */
.numpad__row { display: flex; align-items: center; gap: var(--sp-2); }
.numpad__row .numpad__display { flex: 1; min-width: 0; }
.numpad__peek {
  flex: 0 0 auto;
  background: none;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--r-pill);
  padding: 0.6rem 1.2rem;
  font: inherit;
  font-size: var(--text-small);
  color: var(--ink-soft);
  cursor: pointer;
  min-height: 44px;
}
.numpad__peek[aria-pressed='true'] { border-color: var(--sage-action); color: var(--sage-action); font-weight: 700; }

/* ---------- แผ่นเลือกจำนวนหลังแตะสินค้า ---------- */
.addsheet { display: flex; flex-direction: column; gap: var(--sp-3); }
.addsheet__opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: var(--sp-2); }
.addsheet__opt {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 1.2rem 1rem;
  background: var(--white);
  border: 2px solid var(--line-strong);
  border-radius: var(--r-card);
  cursor: pointer;
  font: inherit;
  text-align: start;
}
.addsheet__opt.is-active { border-color: var(--sage-action); background: var(--sage-light); }
.addsheet__optname { font-weight: 700; font-size: 1.8rem; }
.addsheet__optprice { font-weight: 700; font-size: var(--text-body); color: var(--sage-action); }

/* ตัวเลขจำนวนต้องใหญ่พอให้เห็นจากระยะยืนขาย — เหตุผลเดียวกับปุ่มสินค้า */
.addsheet__qty { display: flex; align-items: center; justify-content: center; gap: var(--sp-3); }
.addsheet__step {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid var(--sage-action);
  background: var(--white);
  color: var(--sage-action);
  font-size: 3.2rem;
  line-height: 1;
  cursor: pointer;
}
.addsheet__step:disabled { opacity: 0.3; cursor: default; }
.addsheet__step:active:not(:disabled) { transform: scale(0.95); }
.addsheet__n { font-size: 4.8rem; font-weight: 700; min-width: 90px; text-align: center; font-variant-numeric: tabular-nums; }
.addsheet__quick { display: grid; grid-template-columns: repeat(auto-fit, minmax(56px, 1fr)); gap: var(--sp-2); }
.addsheet__q {
  min-height: 52px;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--r-pill);
  background: var(--white);
  font: inherit;
  font-size: 1.8rem;
  font-weight: 700;
  cursor: pointer;
}
.addsheet__q.is-active { border-color: var(--sage-action); background: var(--sage-action); color: #fff; }

/* ---------- ตั้งค่าขั้นสูง: ซ่อนค่าที่แทบไม่มีใครแตะ ---------- */
.adv { margin-top: var(--sp-2); }
.adv > summary {
  cursor: pointer;
  list-style: none;
  padding: var(--sp-2) 0;
  font-size: var(--text-small);
  font-weight: 700;
  color: var(--ink-soft);
  min-height: 44px;
  display: flex;
  align-items: center;
}
.adv > summary::-webkit-details-marker { display: none; }
.adv > summary::before { content: '›'; display: inline-block; margin-inline-end: 0.8rem; transition: transform var(--motion-ui); }
.adv[open] > summary::before { transform: rotate(90deg); }

/* ---------- ตัวเลือกเสริม (หน้า/topping) ---------- */
.addsheet__mods { display: flex; flex-direction: column; gap: var(--sp-2); }
.addsheet__modname { font-weight: 700; font-size: var(--text-body); }
.line__mods { font-size: var(--text-micro); color: var(--sage-action); font-weight: 600; }
