/* ===== POS ODY — Stylesheet ===== */
:root {
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-light: #dbeafe;
  --ok: #16a34a;
  --ok-light: #dcfce7;
  --warn: #d97706;
  --warn-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --info: #0891b2;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --sidebar: #0f172a;
  --sidebar-text: #cbd5e1;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-lg: 0 20px 45px -15px rgba(15, 23, 42, .28);
  --nav-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: "Sarabun", "Leelawadee UI", "Noto Sans Thai", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 15px; line-height: 1.5;
  overscroll-behavior: none;
}
body { -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -.01em; }
a { color: var(--brand); text-decoration: none; }
.hide { display: none !important; }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.bold { font-weight: 700; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 10px; }
.gap4 { gap: 4px; } .gap6 { gap: 6px; } .gap16 { gap: 16px; }
.mt8 { margin-top: 8px; } .mt16 { margin-top: 16px; } .mb8 { margin-bottom: 8px; }
.text-ok { color: var(--ok); } .text-danger { color: var(--danger); }
.text-warn { color: var(--warn); } .text-brand { color: var(--brand); }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- ปุ่ม ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 600; cursor: pointer;
  transition: transform .06s ease, background .15s ease, box-shadow .15s ease;
  user-select: none; white-space: nowrap; min-height: 42px;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-success { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-success:hover { filter: brightness(.94); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.94); }
.btn-warn { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: rgba(15, 23, 42, .06); }
.btn-sm { padding: 6px 11px; min-height: 34px; font-size: 13px; border-radius: 8px; }
.btn-lg { padding: 14px 22px; min-height: 54px; font-size: 17px; }
.btn-block { width: 100%; }
.btn-icon { padding: 8px; min-width: 38px; min-height: 38px; }

/* ---------- ฟอร์ม ---------- */
.field { display: flex; flex-direction: column; gap: 5px; }
.field > label { font-size: 13px; font-weight: 600; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface); outline: none;
  transition: border-color .15s, box-shadow .15s; min-height: 42px;
}
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37, 99, 235, .15); }
textarea.input { min-height: 78px; resize: vertical; }
.input-lg { font-size: 18px; padding: 13px 15px; min-height: 52px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

/* ---------- การ์ด / ตาราง ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-pad { padding: 16px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.card-head h3 { font-size: 16px; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl th, table.tbl td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--border); }
table.tbl th {
  font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  background: var(--surface-2); font-weight: 700; position: sticky; top: 0; z-index: 1;
}
table.tbl tbody tr:hover { background: var(--surface-2); }
table.tbl tbody tr:last-child td { border-bottom: none; }
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--muted);
}
.badge-ok { background: var(--ok-light); color: #15803d; }
.badge-warn { background: var(--warn-light); color: #b45309; }
.badge-danger { background: var(--danger-light); color: #b91c1c; }
.badge-brand { background: var(--brand-light); color: var(--brand-dark); }
.empty { padding: 44px 20px; text-align: center; color: var(--muted); }
.empty .ico { font-size: 44px; display: block; margin-bottom: 10px; opacity: .5; }

/* ---------- โครงหน้าจอ ---------- */
#app { height: 100%; }
.layout { display: flex; height: 100%; overflow: hidden; }
.sidebar {
  width: 236px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-text);
  display: flex; flex-direction: column; overflow: hidden;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 11px; padding: 18px 18px 14px;
  color: #fff; font-weight: 800; font-size: 19px;
}
.sidebar .brand .logo {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), #7c3aed); font-size: 19px;
}
.sidebar .brand small { display: block; font-size: 11px; font-weight: 500; color: #94a3b8; }
.nav { flex: 1; overflow-y: auto; padding: 6px 10px 14px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 11px 13px; border-radius: 10px;
  cursor: pointer; font-weight: 600; font-size: 14.5px; margin-bottom: 2px;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.nav-item.active { background: var(--brand); color: #fff; }
.nav-item .ico { font-size: 18px; width: 22px; text-align: center; }
.nav-sep { margin: 12px 13px 6px; font-size: 11px; letter-spacing: .08em; color: #64748b; text-transform: uppercase; }
.sidebar-foot { padding: 12px; border-top: 1px solid rgba(255, 255, 255, .09); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; cursor: pointer; }
.user-chip:hover { background: rgba(255, 255, 255, .07); }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--brand);
  display: grid; place-items: center; color: #fff; font-weight: 700; flex-shrink: 0;
}
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 11px 18px; background: var(--surface);
  border-bottom: 1px solid var(--border); flex-shrink: 0; min-height: 60px;
}
.topbar h2 { font-size: 19px; }
.content { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 18px; }
.content.flush { padding: 0; overflow: hidden; }
.mobile-nav { display: none; }
.menu-btn { display: none; }

/* ---------- แดชบอร์ด ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.kpi .label { font-size: 13px; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 27px; font-weight: 800; margin-top: 5px; letter-spacing: -.02em; }
.kpi .sub { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.panel-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 16px; margin-top: 16px; }
.bar-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; }
.bar-row .nm { width: 40%; font-size: 13.5px; }
.bar-track { flex: 1; height: 9px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--brand); border-radius: 999px; transition: width .5s ease; }
.chart { display: flex; align-items: flex-end; gap: 8px; height: 170px; padding-top: 10px; }
.chart .col-bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.chart .col-bar .fill {
  width: 100%; max-width: 46px; background: linear-gradient(180deg, var(--brand), #60a5fa);
  border-radius: 8px 8px 3px 3px; min-height: 4px; transition: height .5s ease;
}
.chart .col-bar .lbl { font-size: 11px; color: var(--muted); }
/* กราฟรายชั่วโมง: แท่งเยอะ จึงแคบลงและเลื่อนดูด้านข้างได้บนจอเล็ก */
.chart-hours { gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.chart-hours .col-bar { min-width: 22px; }
.chart-hours .col-bar .fill { max-width: 26px; border-radius: 5px 5px 2px 2px; }
.chart-hours .col-bar .lbl { font-size: 10px; }
.chart-hours .col-bar.peak .fill { background: linear-gradient(180deg, var(--ok), #34d399); }
.chart-hours .col-bar.peak .lbl { color: var(--ok); font-weight: 800; }

/* ---------- หน้าขาย (POS) ---------- */
.pos { display: grid; grid-template-columns: 1fr 396px; height: 100%; overflow: hidden; }
.pos-left { display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }
.pos-search { display: flex; gap: 9px; padding: 12px 14px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.pos-search .input { flex: 1; min-width: 160px; }
.cat-bar { display: flex; gap: 8px; padding: 11px 14px; overflow-x: auto; background: var(--surface); border-bottom: 1px solid var(--border); scrollbar-width: none; }
.cat-bar::-webkit-scrollbar { display: none; }
.chip {
  padding: 8px 15px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border);
  cursor: pointer; white-space: nowrap; font-weight: 600; font-size: 14px; flex-shrink: 0;
}
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.prod-grid {
  flex: 1; overflow-y: auto; padding: 14px; display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); align-content: start;
}
.prod {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; cursor: pointer; display: flex; flex-direction: column; gap: 6px;
  transition: transform .08s, box-shadow .15s, border-color .15s; position: relative; min-height: 132px;
}
.prod:hover { border-color: var(--brand); box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.prod:active { transform: scale(.97); }
.prod.out { opacity: .55; }
.prod .thumb {
  height: 62px; border-radius: 10px; display: grid; place-items: center; font-size: 30px;
  background: var(--surface-2); overflow: hidden;
}
.prod .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* รูปสินค้าขนาดเล็กในตาราง */
.thumb-sm {
  width: 40px; height: 40px; border-radius: 8px; object-fit: cover; display: block;
  background: var(--surface-2); border: 1px solid var(--border);
}
.thumb-sm-ph {
  width: 40px; height: 40px; border-radius: 8px; display: grid; place-items: center;
  background: var(--surface-2); font-size: 20px; border: 1px solid var(--border);
}
/* กล่องเลือก/แสดงรูปในฟอร์มสินค้า */
.img-picker { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.img-preview {
  width: 116px; height: 116px; border-radius: 14px; border: 2px dashed var(--border);
  display: grid; place-items: center; overflow: hidden; background: var(--surface-2);
  font-size: 40px; flex-shrink: 0; cursor: pointer; position: relative;
}
.img-preview img { width: 100%; height: 100%; object-fit: cover; }
.img-preview:hover { border-color: var(--brand); }
.img-preview .hint {
  position: absolute; bottom: 0; left: 0; right: 0; background: rgba(15, 23, 42, .68);
  color: #fff; font-size: 10.5px; text-align: center; padding: 3px 2px; font-weight: 600;
}
/* ชื่อสินค้า: กันตัวหนังสือไทยถูกตัดครึ่ง — จองความสูงไว้ 2 บรรทัดเต็มเสมอ
   (flex:1 กับ min-height ของการ์ดทำให้กล่องชื่อถูกบีบจนเห็นแค่ครึ่งบรรทัด) */
.prod .nm {
  font-size: 13.5px; font-weight: 600; line-height: 1.5;
  flex: 0 0 auto; min-height: 3em; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  word-break: break-word;
}
.prod > :last-child { margin-top: auto; }
.prod .pr { font-weight: 800; color: var(--brand); font-size: 16px; }
/* สินค้าราคา 0 (ภาชนะ/วัตถุดิบ) — ให้ดูออกว่าไม่ได้ลืมใส่ราคา */
.prod .pr-free { color: var(--muted); font-size: 13px; font-weight: 700; }
.prod .st { position: absolute; top: 8px; right: 8px; font-size: 11px; padding: 2px 7px;
  border-radius: 999px; background: var(--surface-2); color: var(--muted); font-weight: 700; }
.prod .st.low { background: var(--warn-light); color: #b45309; }
.prod .st.zero { background: var(--danger-light); color: #b91c1c; }
/* สต๊อกติดลบ: เน้นให้เห็นชัดว่าค้างส่ง ต้องบันทึกรับของเข้า */
.prod .st.neg { background: var(--danger); color: #fff; }

.cart { background: var(--surface); border-left: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.cart-head { padding: 12px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.cart-items { flex: 1; overflow-y: auto; padding: 8px 10px; }
.citem { display: flex; gap: 10px; padding: 10px 8px; border-bottom: 1px dashed var(--border); }
.citem:last-child { border-bottom: none; }
.citem .info { flex: 1; min-width: 0; }
.citem .nm { font-weight: 600; font-size: 14px; line-height: 1.3; }
.citem .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.citem .amt { font-weight: 700; text-align: right; white-space: nowrap; }
.qty-box { display: flex; align-items: center; gap: 2px; margin-top: 6px; }
.qty-box button {
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); font-size: 17px; font-weight: 700; cursor: pointer; line-height: 1;
}
.qty-box button:active { background: var(--brand); color: #fff; }
.qty-box input { width: 48px; text-align: center; border: 1px solid var(--border); border-radius: 8px; height: 30px; }
.cart-foot { border-top: 1px solid var(--border); padding: 12px 14px; background: var(--surface-2); }
.sum-row { display: flex; justify-content: space-between; font-size: 14px; padding: 3px 0; }
.sum-row.total { font-size: 24px; font-weight: 800; padding-top: 9px; margin-top: 6px; border-top: 1px solid var(--border); }
.cart-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }

/* ปุ่มตะกร้าลอย (มือถือ) */
.cart-fab { display: none; }

/* ---------- ชำระเงิน ---------- */
.pay-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(112px, 1fr)); gap: 10px; }
.pay-opt {
  padding: 13px 8px; border: 2px solid var(--border); border-radius: var(--radius-sm);
  text-align: center; cursor: pointer; font-weight: 600; font-size: 13.5px; background: var(--surface);
}
.pay-opt .ico { font-size: 23px; display: block; margin-bottom: 3px; }
.pay-opt.active { border-color: var(--brand); background: var(--brand-light); color: var(--brand-dark); }
.quick-cash { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: 8px; }
.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.numpad button {
  padding: 15px 0; font-size: 20px; font-weight: 700; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
}
.numpad button:active { background: var(--brand); color: #fff; }
.big-amount { font-size: 34px; font-weight: 800; text-align: right; letter-spacing: -.02em; }

/* ---------- Modal ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .55); display: flex;
  align-items: center; justify-content: center; z-index: 900; padding: 16px;
  animation: fade .15s ease; backdrop-filter: blur(2px);
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.modal {
  background: var(--surface); border-radius: 18px; width: 100%; max-width: 560px;
  max-height: 92vh; display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
  animation: pop .18s ease;
}
@keyframes pop { from { transform: translateY(14px) scale(.98); opacity: 0 } }
.modal.wide { max-width: 900px; }
/* จอเต็ม (หันให้ลูกค้าดู QR / จอจ่ายสำเร็จ) */
.modal.full { max-width: 100vw; width: 100vw; height: 100vh; max-height: 100vh; border-radius: 0; }
.modal.full .modal-head { display: none; }
.modal.full .modal-body { display: flex; align-items: center; justify-content: center; }
.modal-bg:has(.modal.full) { padding: 0; }
.modal.narrow { max-width: 420px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 17px; }
.modal-body { padding: 18px; overflow-y: auto; flex: 1; }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.close-x { background: none; border: none; font-size: 25px; cursor: pointer; color: var(--muted); line-height: 1; padding: 0 4px; }

/* ---------- Toast ---------- */
#toasts { position: fixed; top: 16px; right: 16px; z-index: 1000; display: flex; flex-direction: column; gap: 9px; pointer-events: none; }
.toast {
  background: var(--text); color: #fff; padding: 12px 17px; border-radius: 11px;
  box-shadow: var(--shadow-lg); font-weight: 600; font-size: 14px; max-width: 340px;
  animation: slide .2s ease; display: flex; gap: 9px; align-items: center;
}
@keyframes slide { from { transform: translateX(24px); opacity: 0 } }
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }
.toast.warn { background: var(--warn); }

/* ---------- เข้าสู่ระบบ ---------- */
.login-wrap {
  height: 100%; display: grid; place-items: center; padding: 20px;
  background: linear-gradient(135deg, #1e293b, #0f172a 55%, #1e3a8a);
}
.login-card { background: var(--surface); border-radius: 22px; padding: 30px 26px; width: 100%; max-width: 400px; box-shadow: var(--shadow-lg); }
.login-logo {
  width: 62px; height: 62px; border-radius: 18px; margin: 0 auto 14px;
  background: linear-gradient(135deg, var(--brand), #7c3aed); display: grid;
  place-items: center; font-size: 31px;
}
.pin-dots { display: flex; gap: 12px; justify-content: center; margin: 18px 0; }
.pin-dot { width: 15px; height: 15px; border-radius: 50%; border: 2px solid var(--border); }
.pin-dot.on { background: var(--brand); border-color: var(--brand); }
.tab-bar { display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 11px; margin-bottom: 18px; }
.tab-bar button { flex: 1; padding: 9px; border: none; background: none; border-radius: 8px; font-weight: 700; cursor: pointer; color: var(--muted); }
.tab-bar button.active { background: var(--surface); color: var(--brand); box-shadow: var(--shadow); }

/* ---------- ใบเสร็จ ---------- */
.receipt {
  font-family: "Courier New", "Sarabun", monospace; font-size: 12.5px; line-height: 1.55;
  background: #fff; color: #000; padding: 12px; width: 300px; margin: 0 auto;
}
.receipt.w58 { width: 220px; font-size: 11.5px; }
.receipt .r-center { text-align: center; }
.receipt .r-line { border-top: 1px dashed #000; margin: 6px 0; }
.receipt .r-row { display: flex; justify-content: space-between; gap: 8px; }
.receipt .r-big { font-size: 15px; font-weight: bold; }
.receipt h4 { margin: 0; font-size: 15px; }

/* ---------- สถานะออฟไลน์ ---------- */
.offline-bar {
  background: var(--warn); color: #fff; text-align: center; padding: 6px; font-size: 13px;
  font-weight: 700;
}
.spinner {
  width: 18px; height: 18px; border: 2.5px solid rgba(255, 255, 255, .35);
  border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }
.loading-full { display: grid; place-items: center; height: 100%; }
.spinner-dark { border-color: var(--border); border-top-color: var(--brand); width: 34px; height: 34px; border-width: 3px; }

/* ---------- แท็บเล็ต ---------- */
@media (max-width: 1180px) {
  .pos { grid-template-columns: 1fr 340px; }
  .sidebar { width: 200px; }
}

/* ---------- มือถือ ---------- */
@media (max-width: 860px) {
  body { font-size: 15px; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 800; transform: translateX(-100%);
    transition: none; width: 264px; box-shadow: var(--shadow-lg);
  }
  body.anim-ready .sidebar { transition: transform .22s ease; }
  .sidebar.open { transform: translateX(0); }
  .backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); z-index: 790; }
  .menu-btn { display: inline-flex; }
  .content { padding: 13px; padding-bottom: calc(var(--nav-h) + var(--safe-b) + 14px); }
  .content.flush { padding-bottom: 0; }
  .main { padding-bottom: 0; }

  .mobile-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 700;
    background: var(--surface); border-top: 1px solid var(--border);
    padding-bottom: var(--safe-b); height: calc(var(--nav-h) + var(--safe-b));
  }
  .mobile-nav .mi {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; font-size: 11px; font-weight: 600; color: var(--muted); cursor: pointer;
  }
  .mobile-nav .mi .ico { font-size: 21px; }
  .mobile-nav .mi.active { color: var(--brand); }

  /* แท็บเล็ตแนวตั้ง (701-860px): ยังคงแสดงตะกร้าข้างจอแต่แคบลง */
  .pos { grid-template-columns: 1fr 296px; position: relative; }
  .kpi .value { font-size: 23px; }
  .modal { max-height: 94vh; }
  .modal-foot .btn { flex: 1; }
  table.tbl th, table.tbl td { padding: 9px 8px; font-size: 13px; }
  .topbar { padding: 9px 12px; min-height: 54px; }
  .topbar h2 { font-size: 17px; }
  #toasts { left: 12px; right: 12px; top: 12px; align-items: center; }
  .toast { max-width: 100%; width: 100%; }
}

/* ---------- มือถือ: ตะกร้าเป็นแผงเลื่อนขึ้น ---------- */
@media (max-width: 700px) {
  .pos { grid-template-columns: 1fr; position: relative; }
  .cart {
    position: fixed; left: 0; right: 0; bottom: 0; top: 0; z-index: 750; border-left: none;
    transform: translateY(100%); transition: none;
  }
  body.anim-ready .cart { transition: transform .25s ease; }
  .cart.open { transform: translateY(0); }
  .prod-grid { padding-bottom: 92px; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); }
  .cart-fab {
    display: flex; position: fixed; left: 12px; right: 12px;
    bottom: calc(var(--nav-h) + var(--safe-b) + 10px); z-index: 600;
    background: var(--brand); color: #fff; border: none; border-radius: 14px;
    padding: 14px 18px; align-items: center; justify-content: space-between;
    font-weight: 700; font-size: 16px; box-shadow: var(--shadow-lg); cursor: pointer;
  }
}

@media (max-width: 420px) {
  .prod-grid { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 9px; }
  .prod { min-height: 118px; padding: 9px; }
  .prod .thumb { height: 42px; font-size: 25px; }
  .cart-actions { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- พิมพ์ ---------- */
@media print {
  body * { visibility: hidden !important; }
  #print-area, #print-area * { visibility: visible !important; }
  #print-area {
    position: absolute; left: 0; top: 0; width: 100%; padding: 0; margin: 0;
    background: #fff;
  }
  .receipt { width: 100% !important; padding: 0 4mm; }
  .rq-sheet { padding: 0; font-size: 12px; }
  .rq-tbl thead { display: table-header-group; }
  .rq-tbl tr, .rq-sign { page-break-inside: avoid; }
  @page { margin: 8mm; }
}


/* ---------- ใบสั่งสินค้าสำหรับพิมพ์ (สาขาละ 1 ใบ) ---------- */
.rq-sheet {
  background: #fff; color: #111; font-size: 13px; line-height: 1.5;
  padding: 6mm 4mm; page-break-after: always; break-after: page;
}
.rq-sheet:last-child { page-break-after: auto; break-after: auto; }
.rq-sheet-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.rq-shop { font-size: 11px; color: #6b7b72; }
.rq-doctitle { font-size: 24px; font-weight: 800; color: #143d2b; line-height: 1.2; }
.rq-stamp { font-size: 11px; color: #6b7b72; text-align: right; }
.rq-branchbar {
  background: #2d6a4f; color: #fff; font-size: 17px; font-weight: 800;
  padding: 7px 10px; margin-top: 6px;
}
.rq-meta {
  display: grid; grid-template-columns: 1.6fr 1fr; gap: 2px 12px;
  background: #e6f4ec; color: #143d2b; padding: 7px 10px; font-size: 12px;
}
.rq-tbl { width: 100%; border-collapse: collapse; margin-top: 10px; }
.rq-tbl th {
  background: #143d2b; color: #fff; font-size: 12px; font-weight: 700;
  padding: 6px; border: 1px solid #143d2b; text-align: center;
}
.rq-tbl th:nth-child(2) { text-align: left; }
.rq-tbl td { border: 1px solid #c9d6ce; padding: 6px; }
.rq-tbl tbody tr:nth-child(even) td { background: #f6faf7; }
.rq-tbl td.c { text-align: center; }
.rq-tbl td.r { text-align: right; }
.rq-tbl .rq-blank { background: #fffdf5 !important; }
.rq-sku { font-size: 11px; color: #6b7b72; }
.rq-sum {
  display: flex; justify-content: space-between; background: #e6f4ec;
  padding: 7px 10px; font-size: 12.5px;
}
.rq-sign {
  display: flex; justify-content: space-between; gap: 30px;
  margin-top: 22px; text-align: center; font-size: 12px; color: #4b5a52;
}
.rq-sign > div { flex: 1; line-height: 2; }


/* ---------- โหมดจัดเรียงลำดับสินค้า ---------- */
.drag-on { touch-action: pan-y; }
.drag-on [data-sort-id] { user-select: none; }
.drag-on .prod { cursor: grab; }
.drag-on .prod:active { cursor: grabbing; transform: none; }
.drag-active {
  opacity: .92; box-shadow: 0 10px 26px rgba(15, 23, 42, .28) !important;
  border-color: var(--brand) !important; position: relative; z-index: 5;
  /* ต้องปิดการรับ pointer ของตัวที่กำลังลาก ไม่งั้นจะหาไม่เจอว่าลากไปทับอันไหน */
  pointer-events: none;
}
tr.drag-active { background: var(--brand-light) !important; }
.drag-busy { cursor: grabbing; }
.drag-handle {
  cursor: grab; color: var(--muted); font-size: 17px; line-height: 1;
  padding: 2px 6px; border-radius: 7px; background: var(--surface-2); user-select: none;
  touch-action: none;
}
.drag-handle:active { cursor: grabbing; background: var(--brand-light); color: var(--brand); }
/* ป้ายลำดับมุมการ์ดตอนจัดเรียง */
.prod .ord {
  position: absolute; top: 8px; left: 8px; min-width: 22px; text-align: center;
  font-size: 11px; font-weight: 800; padding: 2px 6px; border-radius: 999px;
  background: var(--brand); color: #fff;
}
.prod .card-grip {
  position: absolute; top: 6px; right: 6px; z-index: 2;
  padding: 3px 7px; font-size: 15px;
}
.sortbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--warn-light); color: #92400e; border-radius: 10px;
  padding: 8px 12px; font-size: 13px; font-weight: 600;
}
body.dark .sortbar { color: #fde68a; }

/* ---------- โหมดมืด ---------- */
body.dark {
  --bg: #0b1120; --surface: #131c2e; --surface-2: #1b2538; --border: #2a3651;
  --text: #e2e8f0; --muted: #94a3b8; --sidebar: #080d18;
  --brand-light: #1e3a8a; --ok-light: #14532d; --warn-light: #78350f; --danger-light: #7f1d1d;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
}
body.dark .btn-ghost:hover { background: rgba(255, 255, 255, .07); }
body.dark .receipt { background: #fff; color: #000; }
body.dark .rq-sheet { background: #fff; color: #111; }

/* ---------- QR รับเงิน ---------- */
.qr-panel { margin-top: 14px; padding: 14px; border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface-2); }
.qr-wrap { display: inline-block; background: #fff; padding: 10px; border-radius: 12px;
  border: 1px solid var(--border); line-height: 0; }
.qr-wrap svg, .qr-svg { display: block; width: min(70vw, 380px); height: auto; }
.qr-wrap-big svg { width: min(80vw, 55vh, 560px); }
.qr-amount { font-size: 30px; font-weight: 800; color: var(--brand); margin-top: 8px; font-variant-numeric: tabular-nums; }
.qr-fullscreen { text-align: center; padding: 24px; }
.qr-full-shop { font-size: 20px; font-weight: 700; color: var(--muted); }
.qr-full-title { font-size: 26px; font-weight: 800; margin: 6px 0 14px; }
.qr-full-amount { font-size: 48px; font-weight: 900; color: var(--brand); margin-top: 14px; font-variant-numeric: tabular-nums; }
.qr-paid { text-align: center; padding: 30px; color: #fff; background: linear-gradient(160deg, #16a34a, #15803d);
  border-radius: 24px; width: min(92vw, 640px); animation: pop .25s ease; }
.qr-paid-ico { font-size: 96px; line-height: 1; }
.qr-paid-title { font-size: 40px; font-weight: 900; margin-top: 10px; }
.qr-paid-amount { font-size: 56px; font-weight: 900; margin-top: 6px; font-variant-numeric: tabular-nums; }
.qr-paid-code { opacity: .85; margin-top: 8px; font-size: 16px; }
.qr-paid-thanks { margin-top: 16px; font-size: 20px; opacity: .9; }
.modal-bg:has(.qr-paid) { background: rgba(22, 163, 74, .35); }
.modal.full:has(.qr-paid) { background: transparent; box-shadow: none; }

/* ---------- สถานะระบบ (พื้นที่ใกล้เต็ม / รหัสเริ่มต้น) ---------- */
.sys-bar { background: var(--warn); color: #fff; text-align: center; padding: 6px 10px; font-size: 13px; font-weight: 700; }
.sys-bar.critical { background: var(--danger); }
.sys-bar-link { color: #fff; text-decoration: underline; margin-left: 6px; }
.sys-warn { background: #fff7ed; border: 1px solid #fdba74; color: #9a3412; border-radius: 10px; padding: 10px 12px; font-weight: 600; }
.sys-warn.critical { background: #fef2f2; border-color: #fca5a5; color: #991b1b; }
.sys-ok { color: var(--ok); font-weight: 700; }
.sys-meter { height: 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.sys-meter-fill { height: 100%; border-radius: 999px; transition: width .3s; }
body.dark .sys-warn { background: rgba(251, 146, 60, .12); color: #fdba74; }
body.dark .sys-warn.critical { background: rgba(248, 113, 113, .12); color: #fca5a5; }
