/* ===================================================================
   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; }
}

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

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

/* ── แถบเตือนยังไม่เปิดกะ ─────────────────────────────────────────── */
.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);
  padding: 14px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.12s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 1px 2px rgba(20, 30, 30, 0.04);
}

.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.42;
  cursor: not-allowed;
  box-shadow: none;
}

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

.pos-product-thumb {
  width: calc(100% + 28px);
  height: 92px;
  margin: -14px -14px 2px -14px;
  object-fit: cover;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  display: block;
  background: var(--bg-soft);
}

.pos-product-name {
  font-weight: 600;
  font-size: 14px;
  line-height: 1.3;
  color: var(--text);
}

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

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

.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;
}

.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);
}

@media (max-width: 420px) {
  .pos-cart-total-hero-value {
    font-size: 48px;
  }
}

/* ── ป้าย "ตะกร้าปัจจุบัน" (ตอนนี้อยู่ท้ายแถว 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 */
}

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

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

.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;
}

.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);
  font-size: 68px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

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

.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-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 เท่านั้น */
.topbar-actions:has(.pos-topbar-actions) {
  flex: 1;
  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;
  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;
  }
}

@media (max-width: 480px) {
  .pos-topbar-actions {
    width: 100%;
  }
  .pos-topbar-toggle.view-switch {
    width: 100%;
  }
  .pos-topbar-toggle.view-switch button {
    flex: 1 1 0;
    justify-content: center;
  }
  .pos-topbar-mode-fields {
    width: 100%;
    min-width: 0;
    flex-wrap: wrap;
  }
  .pos-topbar-select-wrap {
    flex: 1 1 auto;
    min-width: 0;
  }
  .pos-topbar-select {
    max-width: none;
    width: 100%;
  }
}
