/* ===================================================================
   pos.css — สไตล์เฉพาะหน้า "ขายสินค้า POS" (pos.js)
   ใช้ CSS variable ชุดเดียวกับระบบทั้งหมด (โทนเขียวเข้ม/สีเทาอุ่น) ไม่ประกาศ
   สีใหม่นอกระบบ — ปรับให้ดูเป็นเครื่อง POS จริงมากขึ้น: การ์ดสินค้าแบบกดง่าย
   บนจอสัมผัส, ตัวเลขราคาใช้ font mono, ตะกร้าเด่นชัดเจนพร้อมปุ่มยืนยันใหญ่
   =================================================================== */

.pos-layout {
  display: grid;
  grid-template-columns: 1fr 560px;
  gap: 20px;
  align-items: start;
}

@media (max-width: 900px) {
  .pos-layout { grid-template-columns: 1fr; }
  .pos-product-grid { max-height: 60vh; }
}

/* ===================================================================
   จอมือถือ (<=860px, ตรงกับ breakpoint ของแถบเมนูล่าง/is-mobile-modern) —
   ปรับโครงสร้างหน้า POS ใหม่ทั้งชุด: เดิม .pos-product-grid ใช้ overflow-y
   ของตัวเองซ้อนกับ scroll ของทั้งหน้า (ดีบนจอคอมที่มีพื้นที่แน่นอน แต่บนมือถือ
   กลายเป็น "เลื่อนสองชั้น" กะระยะยาก + ตะกร้าถูกดันลงไปไกลกว่าจะเห็นยอดสุทธิ)
   บนมือถือเปลี่ยนมาให้ทั้งหน้าเลื่อนเป็นชั้นเดียว แล้วสลับลำดับ: ตะกร้า/ยอดสุทธิ
   ขึ้นก่อนตารางสินค้า เพราะเป็นสิ่งที่พนักงานต้องเช็คบ่อยที่สุดระหว่างขาย
   =================================================================== */
@media (max-width: 860px) {
  .pos-layout {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
  }
  .pos-main,
  .pos-cart {
    min-width: 0;   /* ป้องกันบั๊ก flexbox คลาสสิก: child ไม่ยอมหดต่ำกว่าความกว้างเนื้อหาขั้นต่ำของตัวเอง
                       (เช่น ตัวเลขยอดสุทธิฟอนต์ใหญ่) จนดันทั้งคอลัมน์กว้างเกินจอ */
  }
  .pos-cart { order: -1; }
  .pos-cart.card { margin-top: 0; }

  .pos-product-grid {
    max-height: none;
    overflow-y: visible;
    padding-right: 0;
  }
}

/* ฝั่งซ้าย (ค้นหา + ตารางสินค้า): ให้เฉพาะตารางสินค้าเลื่อนได้ในกรอบของตัวเอง
   ส่วนแถบค้นหา/หมวดหมู่อยู่นิ่งด้านบนเสมอ ไม่ไหลตามการเลื่อนของสินค้า */
.pos-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.pos-toolbar {
  flex-shrink: 0;
}

@media (max-width: 860px) {
  .pos-toolbar #pos-category-chips.chip-row {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .pos-toolbar #pos-category-chips.chip-row::-webkit-scrollbar { display: none; }
  .pos-toolbar #pos-category-chips.chip-row .chip { flex-shrink: 0; }
}

/* ── กรองหมวดหมู่บนมือถือ: ใช้ dropdown (<select>) แทนแถบชิปเลื่อนแนวนอน ──
   แถบชิปเดิมกดยากบนจอแคบ (ปุ่มเล็ก/เลื่อนบัง) — <select> เดียวกินพื้นที่บรรทัด
   เดียวเต็มความกว้าง กดง่ายกว่าและเห็นหมวดที่เลือกอยู่ชัดเจน
   ข้อมูล/state ใช้ร่วมกับแถบชิป (ดู renderCategoryChips ใน pos.js) จอกว้างยังคงเห็นชิปตามเดิม */
.pos-category-select-mobile {
  display: none;
}

@media (max-width: 860px) {
  .pos-toolbar #pos-category-chips.chip-row { display: none; }
  .pos-category-select-mobile {
    display: block;
    width: 100%;
  }
}

/* ── แถบเตือนยังไม่เปิดกะ ─────────────────────────────────────────── */
.pos-shift-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--amber-dim);
  border: 1px solid var(--amber);
  border-radius: var(--radius-lg);
  font-size: 13.5px;
  color: var(--text);
}

.pos-shift-banner i {
  color: var(--amber);
  font-size: 18px;
}

/* ── Toolbar (ค้นหา + หมวดหมู่) ───────────────────────────────────── */
.pos-toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.pos-toolbar .search-wrap {
  border-radius: var(--radius-lg);
}

/* ── ตารางสินค้า ──────────────────────────────────────────────────── */
/* จำกัดความสูงตามพื้นที่ที่เหลือของจอ แล้วเลื่อนเฉพาะส่วนนี้ (ไม่ลากทั้งหน้าตาม) —
   ลบ 220px ครอบคลุม header, padding เนื้อหา และแถบค้นหา/หมวดหมู่ด้านบน */
.pos-product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(138px, 1fr));
  gap: 10px;
  max-height: calc(100vh - 220px);
  overflow-y: auto;
  padding-right: 6px;
  padding-bottom: 4px;
}

.pos-product-card {
  position: relative;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.12s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
  box-shadow: 0 1px 2px rgba(20, 30, 30, 0.04);
}

/* ── รูปสินค้า: กรอบสี่เหลี่ยมจัตุรัส พื้นหลังอ่อนนุ่ม + object-fit:contain
   (เห็นสินค้าทั้งชิ้นแบบแอปช้อปปิ้งทั่วไป ไม่ครอปเหมือน cover เดิม) ───────── */
.pos-product-thumb-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--panel-hover);
  overflow: hidden;
}

.pos-product-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.pos-product-thumb-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 32px;
}

.pos-product-oos-ribbon {
  position: absolute;
  left: 8px;
  top: 8px;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}

.pos-product-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px 12px;
  flex: 1;
}

.pos-product-cat {
  align-self: flex-start;
}

@media (max-width: 860px) {
  /* บังคับ 2 คอลัมน์เท่ากันเสมอบนมือถือ (แทน auto-fill ที่บางความกว้างจะได้แค่ 1 คอลัมน์
     กว้างเกะกะ หรือ 2 คอลัมน์ไม่เท่ากัน) กดง่ายด้วยนิ้วโป้งขณะถือเครื่องมือเดียว
     เดิมใช้ 600px แต่มือถือส่วนใหญ่กว้างกว่านั้นแล้ว (เช่น 700-800px) เลยไม่เคยเข้าเงื่อนไขนี้
     เปลี่ยนมาใช้ 860px ให้ตรงกับ breakpoint มือถือจริงของทั้งแอป (is-mobile-modern)

     ต้นเหตุจริงของที่ล้นจอ (ไม่ใช่แคช): "1fr" เฉยๆ ยังยอมให้คอลัมน์ขยายเกินส่วนแบ่งของตัวเอง
     ถ้าเนื้อหาข้างในห่อบรรทัดไม่ได้ (.badge และ .pos-product-stock ใช้ white-space:nowrap)
     เปลี่ยนเป็น minmax(0, 1fr) + min-width:0 บนตัวการ์ด เพื่อบังคับให้คอลัมน์หดได้จริง แล้วให้
     .pos-product-card ตัด (overflow:hidden) เนื้อหาที่ยาวเกินการ์ดของตัวเองแทน — จำกัดผลแค่ในกรอบ
     การ์ดเล็กๆ เท่านั้น ไม่แตะ overflow ของ .pos-layout/.pos-product-grid/หน้าเว็บ เพื่อไม่ให้กระทบ
     การเลื่อนหน้าจอเหมือนที่เคยพังไปรอบก่อน */
  .pos-product-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .pos-product-card {
    min-width: 0;
    overflow: hidden;
  }
  .pos-product-body {
    padding: 8px 8px 10px;
  }
  .pos-product-name {
    font-size: 12.5px;
    overflow-wrap: break-word;
  }
  .pos-product-price { font-size: 16px; }
  .pos-product-card .badge {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .pos-product-stock {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

.pos-product-card:hover {
  border-color: var(--accent);
  box-shadow: 0 6px 16px rgba(20, 108, 104, 0.14);
  transform: translateY(-2px);
}

.pos-product-card:active {
  transform: scale(0.97) translateY(0);
}

.pos-product-card.disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

.pos-product-card.disabled .pos-product-thumb,
.pos-product-card.disabled .pos-product-thumb-placeholder {
  filter: grayscale(0.6);
}

.pos-product-card.disabled:hover {
  transform: none;
  border-color: var(--line);
  box-shadow: none;
}

.pos-product-name {
  font-weight: 600;
  font-size: 14px;
  line-height: 1.3;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.pos-product-brand {
  font-size: 11.5px;
  color: var(--text-faint);
}

.pos-product-bottom-row {
  margin-top: 4px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: wrap;
}

.pos-product-price {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -0.01em;
  color: var(--accent);
}

.pos-product-stock {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-dim);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  width: fit-content;
}

.pos-product-stock.low {
  color: var(--red);
  border-color: var(--red-dim);
  background: var(--red-dim);
}

/* ── ตะกร้า ────────────────────────────────────────────────────────── */
.pos-cart {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-radius: var(--radius-lg);
  box-shadow: 0 2px 10px rgba(20, 30, 30, 0.06);
  padding-top: 0;      /* เดิมเผื่อพื้นที่ให้หัวข้อ "ตะกร้าปัจจุบัน" ด้านบน ตอนนี้ย้ายหัวข้อไปอยู่ที่ topbar แล้ว เลยไม่ต้องเผื่ออีก — ให้กล่อง "ยอดสุทธิ" ชิดขอบบนกรอบพอดี */
  margin-top: -28px;
}

@media (max-width: 860px) {
  .pos-cart {
    position: static;
    margin-top: 0;
  }
}

.pos-print-pref {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 2px;
}

.pos-print-pref-toggle {
  display: flex;
  gap: 4px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 3px;
}

.pos-print-pref-toggle .btn {
  border: none;
  border-radius: calc(var(--radius-md) - 2px);
  background: transparent;
  box-shadow: none;
  font-size: 12px;
  padding: 5px 10px;
}

.pos-print-pref-toggle .btn.btn-primary {
  background: var(--accent);
  color: var(--btn-primary-text);
}

/* ── ป้าย "ตะกร้าปัจจุบัน" (ตอนนี้อยู่ท้ายแถว topbar ร่วมกับปุ่ม ล้างตะกร้า/บิลที่พักไว้ — ดู .pos-topbar-cart-group) ─── */
.pos-cart-panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
}

.pos-held-badge-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
}

.pos-held-badge-btn .badge {
  font-size: 11px;
  padding: 1px 7px;
}

/* ── แถวปุ่มด้านล่างตะกร้า: พักบิล / ยืนยันการขาย ───────────────────── */
.pos-cart-footer-actions {
  display: flex;
  gap: 8px;
}

.pos-cart-footer-actions #pos-hold-btn {
  flex: 1;
}

.pos-cart-footer-actions #pos-checkout-btn {
  flex: 2;
}

/* ── รายการ "บิลที่พักไว้" (ใน modal) ───────────────────────────────── */
.pos-held-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 60vh;
  overflow-y: auto;
}

.pos-held-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--bg-soft);
}

.pos-held-row-main {
  min-width: 0;
}

.pos-held-row-title {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pos-held-row-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.pos-cart-lines {
  display: flex;
  flex-direction: column;
  height: 320px;               /* ตรึงความสูงคงที่ — ไม่ขยาย/หดตามจำนวนรายการ แม้ตะกร้าว่างก็ยังกว้างเท่าเดิม เลื่อนดูรายการเกินในกรอบนี้แทน */
  overflow-y: auto;
  border-top: 1px dashed var(--line);
  border-bottom: 1px dashed var(--line);
  padding: 4px 0;
  overflow-anchor: none;      /* กัน browser "ชดเชย" scroll เองตอน layout ขยับหลังวาด (เช่น ฟอนต์ไอคอนโหลดเสร็จทีหลัง) จนดูเหมือนเลื่อนไปแล้วเด้งกลับ */
  scrollbar-width: none;      /* Firefox */
  -ms-overflow-style: none;   /* เก่า Edge/IE */
  min-width: 0;
  max-width: 100%;
}

.pos-cart-lines::-webkit-scrollbar {
  display: none;              /* Chrome/Safari/Edge ใหม่ */
}

@media (max-width: 480px) {
  .pos-cart-lines { height: 220px; }
}

.pos-cart-line {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 2px;
  border-bottom: 1px dashed var(--line);
  min-width: 0;
  max-width: 100%;
}

.pos-cart-line:last-child {
  border-bottom: none;
}

/* ไฮไลต์รายการที่เพิ่งเพิ่มใหม่ — จางหายเองไว ไม่รบกวนสายตา ไม่มีการเลื่อนซ้ำๆ ตอนกด +/- */
.pos-cart-line-flash {
  animation: pos-cart-line-flash 0.6s ease-out;
}

@keyframes pos-cart-line-flash {
  0% { background: var(--primary-dim, rgba(16, 122, 87, 0.14)); }
  100% { background: transparent; }
}

.pos-cart-line-name {
  font-size: 13.5px;
  font-weight: 400;
  line-height: 1.3;
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pos-cart-line-remove {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
}

.pos-cart-line-remove:hover {
  background: var(--btn-danger-bg, rgba(220, 38, 38, 0.12));
  color: var(--btn-danger-text);
}

.pos-cart-line-qty {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px;
  flex-shrink: 0;
}

.pos-cart-line-qty button.btn {
  width: 24px;
  height: 24px;
  min-width: 0;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  font-weight: 400;
  border: none;
  background: var(--panel);
  box-shadow: 0 1px 2px rgba(20, 30, 30, 0.08);
}

.pos-cart-line-qty span {
  min-width: 22px;
  text-align: center;
  font-family: var(--font-mono);
  font-weight: 400;
  font-size: 13px;
}

.pos-cart-qty-input {
  width: 32px;
  min-width: 0;
  text-align: center;
  font-family: var(--font-mono);
  font-weight: 400;
  font-size: 13px;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 0;
  -moz-appearance: textfield;
}

.pos-cart-qty-input::-webkit-outer-spin-button,
.pos-cart-qty-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.pos-cart-qty-input:focus {
  outline: none;
  background: var(--panel);
  border-radius: 4px;
  box-shadow: 0 0 0 2px var(--accent-dim);
}

.pos-cart-line-amount {
  font-family: var(--font-mono);
  font-weight: 400;
  font-size: 13.5px;
  text-align: right;
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 68px;
}

.pos-cart-total-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 12px 12px;
  margin: 0 0 16px;
  background: var(--accent);
  color: var(--btn-primary-text);
  border-radius: var(--radius-md);
  text-align: center;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  box-sizing: border-box;
}

.pos-cart-total-hero-label {
  font-size: 15px;
  font-weight: 600;
  opacity: 0.85;
  letter-spacing: 0.03em;
}

.pos-cart-total-hero-value {
  font-family: var(--font-mono);
  /* clamp() แทนขนาดคงที่ 68px เดิม — ปรับต่อเนื่องตามความกว้างจอจริงเสมอ กันตัวเลขกว้างเกินกล่อง
     "ยอดสุทธิ" แล้วดันการ์ดล้นขอบจอ (ของเดิมพึ่ง breakpoint เดียวซึ่งไม่ครอบคลุมทุกความกว้างจอ) */
  font-size: clamp(26px, 8vw, 68px);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  max-width: 100%;
}

.pos-cart-total-hero-value small {
  font-family: var(--font-sans);
  font-size: 0.32em;
  font-weight: 600;
  margin-left: 6px;
  opacity: 0.85;
}

/* ขายแบบ "เงินสด" — แตกกล่องยอดสุทธิเป็นซ้าย (ยอดสุทธิ) / ขวา (รับมา・ทอน) แทนที่จะจัดกึ่งกลางเฉยๆ */
.pos-cart-total-hero--split {
  flex-direction: row;
  align-items: center;
  gap: 14px;
  text-align: left;
  padding: 12px 14px;
}

.pos-cart-total-hero-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1 1 auto;
  min-width: 0;
}

.pos-cart-total-hero--split .pos-cart-total-hero-value {
  font-size: clamp(22px, 7vw, 40px);
}

.pos-cart-total-hero-divider {
  align-self: stretch;
  width: 1px;
  background: rgba(255, 255, 255, 0.22);
  flex-shrink: 0;
}

.pos-cart-total-hero-side {
  display: flex;
  flex-direction: column;
  gap: 7px;
  flex-shrink: 0;
}

.pos-cart-total-hero-side-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
}

.pos-cart-total-hero-side-row span:first-child {
  opacity: 0.7;
  font-weight: 600;
  white-space: nowrap;
}

.pos-cart-total-hero-side-row span:last-child {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

.pos-cart-total-hero-side-row.is-insufficient span:last-child {
  color: #ffb3ac;
}

.pos-cart-totals {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11.5px;
  padding-top: 4px;
}

.pos-cart-totals > div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 20px;
}

.pos-cart-totals span:last-child {
  font-family: var(--font-mono);
}

.pos-cart-discount-input {
  width: 80px;
  padding: 2px 6px;
  text-align: right;
  font-size: 11.5px;
  font-family: var(--font-mono);
}

.pos-cart-total-final {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 12px;
  border-top: 1px solid var(--line);
  margin-top: 3px;
  padding-top: 6px;
}

.pos-cart-total-final span:last-child {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
}

.pos-cash-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
  padding: 10px;
  background: rgba(0, 0, 0, 0.03);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.pos-cash-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
}

.pos-cash-received-input {
  width: 120px;
  padding: 4px 8px;
  text-align: right;
  font-size: 13px;
  font-family: var(--font-mono);
}

.pos-cash-quick-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pos-cash-quick-buttons .btn {
  flex: 1 1 auto;
  padding: 4px 6px;
  font-size: 11px;
  font-family: var(--font-mono);
}

.pos-cash-change {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 13px;
  border-top: 1px dashed var(--line);
  margin-top: 2px;
  padding-top: 6px;
}

.pos-cash-change span:last-child {
  font-family: var(--font-mono);
  color: #1a7f37;
}

.pos-cash-change.pos-cash-change-insufficient span:last-child {
  color: #c0362c;
}

#pos-checkout-btn {
  padding: 14px;
  font-size: 15px;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 12px rgba(20, 108, 104, 0.25);
}

#pos-checkout-btn:disabled {
  box-shadow: none;
}

/* ── แถบควบคุมใน topbar: สลับเข้าบิลห้อง/เงินสด + เลือกห้อง หรือ ช่องทางรับเงิน/VAT ─── */
/* บน POS ต้องการให้แถว topbar-actions (กล่องกลางของแอปทั้งระบบ) ยืดเต็มพื้นที่ที่เหลือจริงๆ
   (ปกติ .topbar-actions หดตามเนื้อหา ไม่ได้ยืดเต็ม) เพื่อให้ .pos-topbar-mode-fields ขยายเต็มได้จริง
   และกลุ่มตะกร้าท้ายแถวอยู่ตำแหน่งเดิมเสมอไม่ว่าจะสลับโหมดไหน — ผูกเงื่อนไขด้วย :has() ให้จำกัดผลแค่หน้า POS เท่านั้น
   *** เฉพาะจอกว้าง (>860px) เท่านั้น *** เพราะ :has() ทำให้ specificity สูงกว่ากฎ .topbar-actions
   { flex-basis:100%; order:3 } ของ layout.css ตอนจอมือถือ (ดู @media max-width:860 ในไฟล์นั้น) ถ้าไม่กันไว้
   flex:1 ตรงนี้จะไปเซ็ต flex-basis กลับเป็น 0 ทับของมือถือ ทำให้แถวควบคุมไม่ยอมเต็มความกว้างจอ
   ผลคือปุ่ม/ช่องเลือกด้านในไม่มีพื้นที่ให้ wrap ขึ้นบรรทัดใหม่ แล้วล้นขอบจอขวาแทน (บั๊กที่เจอจริง) */
@media (min-width: 861px) {
  .topbar-actions:has(.pos-topbar-actions) {
    flex: 1;
    min-width: 0;
  }
}

/* จอมือถือ: บังคับให้แถวควบคุมเต็มความกว้างจอเสมอ (specificity เท่ากับกฎข้างบนเพื่อกันปัญหาเดิมซ้ำ
   ถ้ามีใครมาเพิ่มกฎ :has() อื่นทับอีกในอนาคต) ให้ .pos-topbar-actions ข้างในมีพื้นที่ wrap ได้จริง */
@media (max-width: 860px) {
  .topbar-actions:has(.pos-topbar-actions) {
    flex-basis: 100%;
    min-width: 0;
  }
}

.pos-topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  width: 100%;
}

.pos-topbar-cart-group {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 12px;
  border-left: 1px solid var(--line);
  flex-shrink: 0;
}

.pos-topbar-cart-group .pos-cart-panel-title {
  white-space: nowrap;
}

/* ปุ่มสลับ "เข้าบิลห้อง/เงินสด": เลิกใช้พื้นแคปซูลรวม เปลี่ยนเป็นปุ่มขอบแยกกัน 2 ปุ่ม
   แล้วให้สีต่างกันตามประเภทตอน active — น้ำเงิน = เข้าบิลห้อง, เขียว = เงินสด — เพื่อให้เห็นชัดจากที่ไกลว่ากำลังขายโหมดไหน */
.pos-topbar-toggle.view-switch {
  background: transparent;
  border: none;
  padding: 0;
  gap: 8px;
  flex-shrink: 0;
}

@media (min-width: 861px) {
  .pos-topbar-toggle.view-switch {
    margin-left: auto;   /* ดันกลุ่มควบคุม (สลับโหมด + ช่องทางรับเงิน/VAT + ตะกร้า) ทั้งหมดไปชิดขวา แทนที่จะดันแค่กลุ่มตะกร้าอย่างเดียว — เฉพาะจอกว้างที่มีพื้นที่เหลือให้ดัน */
  }
}

.pos-topbar-toggle.view-switch button {
  padding: 8px 16px;
  font-size: 12.5px;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text-dim);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.pos-topbar-toggle.view-switch button:hover {
  background: var(--bg-soft);
}

.pos-topbar-toggle.view-switch button.active {
  border-color: transparent;
  color: #fff;
  box-shadow: none;
}

.pos-topbar-toggle.view-switch button:nth-child(1).active {
  background: #185FA5;
}

.pos-topbar-toggle.view-switch button:nth-child(2).active {
  background: #3B6D11;
}

/* กล่องนี้ห่อฟิลด์ที่เปลี่ยนไปตามโหมด (เลือกห้อง หรือ ช่องทางรับเงิน+VAT)
   ตรึง min-width ไว้เท่ากับความกว้างฝั่ง "เงินสด" (2 ช่องเลือก + ป้ายอัตราภาษี ~ 500px)
   เพื่อไม่ให้ทั้งแถว (toggle/ช่องทางรับเงิน/ตะกร้า) เลื่อนตำแหน่งตอนสลับไปโหมด "เข้าบิลห้อง" ที่มีฟิลด์น้อยกว่า
   ถ้าชื่อช่องทางรับเงินหรือป้าย VAT ยาวขึ้นจนล้น ค่อยปรับตัวเลขนี้เพิ่มได้ */
.pos-topbar-mode-fields {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 500px;
}

.pos-topbar-select-wrap-grow {
  min-width: 200px;
  flex: 1 0 auto;   /* ให้ช่อง "เลือกห้อง" ยืดเต็มพื้นที่ที่ตรึงไว้แทนที่จะเหลือช่องว่างเปล่าท้ายแถว */
}

.pos-topbar-select-wrap-grow .pos-topbar-select {
  max-width: none;
  width: 100%;
}

.pos-topbar-select-wrap {
  display: flex;
  align-items: center;
  gap: 9px;
  height: 36px;
  box-sizing: border-box;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 16px;
  flex-shrink: 0;
}

.pos-topbar-select-wrap i {
  font-size: 15px;
  color: var(--text-faint);
  flex-shrink: 0;
  display: flex;
}

.pos-topbar-select {
  border: none;
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  padding: 0;
  line-height: 1;
  text-align: center;
  cursor: pointer;
  max-width: 190px;
  outline: none;
}

/* จัดระยะรายการในดรอปดาวน์ให้ไม่ชิดขอบ (รองรับเต็มที่บน Chrome/Edge, เบราว์เซอร์อื่นจะไม่พังแค่ไม่ได้ผลเท่ากัน) */
.pos-topbar-select option {
  padding: 10px 14px;
  font-size: 13px;
}

.pos-topbar-info-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text-faint);
  cursor: help;
  flex-shrink: 0;
  font-size: 15px;
  transition: background 0.15s, color 0.15s;
}

.pos-topbar-info-btn:hover {
  background: var(--panel);
  color: var(--accent);
}

.pos-topbar-rate-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 36px;
  box-sizing: border-box;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  white-space: nowrap;
  flex-shrink: 0;
}

@media (max-width: 860px) {
  .pos-topbar-select {
    max-width: 140px;
  }
  .pos-topbar-mode-fields {
    min-width: 0;
  }

  /* จอมือถือ: แต่ละกลุ่มควบคุมขึ้นแถวของตัวเอง เต็มความกว้าง แทนที่จะพยายามยัดรวมแถวเดียว
     กับปุ่มสลับโหมด/ช่องทางรับเงิน แล้วล้นจนปุ่มดูใหญ่ผิดปกติหรือถูกดันไปอยู่โดดๆ */
  .pos-topbar-actions {
    gap: 10px;
  }
  .pos-topbar-toggle.view-switch {
    width: 100%;
  }
  .pos-topbar-toggle.view-switch button {
    flex: 1 1 0;
    justify-content: center;
    padding: 10px 8px;
  }
  .pos-topbar-mode-fields {
    width: 100%;
    flex-wrap: wrap;
  }
  .pos-topbar-select-wrap {
    flex: 1 1 auto;
    min-width: 0;
  }
  .pos-topbar-cart-group {
    width: 100%;
    padding-left: 0;
    border-left: none;
    border-top: 1px dashed var(--line);
    padding-top: 10px;
    justify-content: space-between;
  }
  .pos-topbar-cart-group .btn.btn-sm {
    flex: 1 1 0;
    justify-content: center;
  }
}

@media (max-width: 480px) {
  .pos-topbar-actions {
    width: 100%;
  }
  .pos-topbar-select {
    max-width: none;
    width: 100%;
  }
  .pos-topbar-cart-group .pos-cart-panel-title {
    display: none;   /* จอแคบมาก: ซ่อนป้ายข้อความ เหลือแค่ปุ่ม ล้างตะกร้า/บิลที่พักไว้ ให้พอดีแถวเดียว */
  }
}
