:root {
  --bg: #f1f5f4;
  --surface: #ffffff;
  --surface-2: #f6f9f8;
  --border: #e2e8e6;
  --border-strong: #cdd6d3;
  --text: #14201d;
  --muted: #64716d;
  --primary: #0f766e;
  --primary-hover: #0d5f59;
  --primary-soft: #e3f3f0;
  --accent: #f59e0b;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --warning: #a16207;
  --warning-soft: #fef6e2;
  --success: #15803d;
  --success-soft: #e7f6ec;
  --sidebar: #11302c;
  --sidebar-text: #9fbdb8;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 22, 0.06);
  --shadow: 0 1px 3px rgba(16, 24, 22, 0.08), 0 6px 16px rgba(16, 24, 22, 0.06);
  --shadow-lg: 0 24px 60px rgba(16, 24, 22, 0.28);
  --font: 'IBM Plex Sans Thai', 'Sarabun', 'Leelawadee UI', Tahoma, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body, #app { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}
input, textarea, .mono, td, .selectable { user-select: text; }
h1, h2, h3 { font-weight: 600; }
.icon { flex-shrink: 0; }

/* ---------- โครงหลัก ---------- */
.shell { display: grid; grid-template-columns: 88px minmax(0, 1fr); height: 100vh; }
.sidebar {
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 8px;
}
.brand {
  display: block; width: 48px; height: 48px;
  margin: 2px auto 14px;
  border-radius: 28%; box-shadow: 0 0 0 1px rgba(255, 255, 255, .16); /* โลโก้สีเขียวเข้มบนแถบเมนูสีเข้ม — เส้นขอบให้เห็นขอบโลโก้ */
}
.nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 4px; border-radius: 10px; border: 0; background: none;
  color: var(--sidebar-text); font: inherit; font-size: 13px;
  text-decoration: none; cursor: pointer; position: relative;
}
.nav-item:hover { color: #fff; background: rgba(255, 255, 255, 0.06); }
.nav-item.active { color: #fff; background: rgba(255, 255, 255, 0.12); }
.nav-item.active::before {
  content: ''; position: absolute; left: -8px; top: 12px; bottom: 12px;
  width: 4px; border-radius: 0 4px 4px 0; background: #5eead4;
}
.terminal-chip {
  margin: 8px auto 2px; font-size: 12px; color: var(--sidebar-text);
  border: 1px solid rgba(255, 255, 255, 0.18); border-radius: 6px; padding: 1px 8px;
}
.main { min-width: 0; min-height: 0; overflow: hidden; }
.spacer { flex: 1; }

.boot { height: 100vh; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--muted); }
.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- ปุ่ม ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, transform 0.06s;
}
.btn:hover { background: var(--surface-2); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn.danger.ghost { color: var(--danger); background: transparent; }
.btn.danger.ghost:hover:not(:disabled) { background: var(--danger-soft); }
.btn.sm { height: 34px; padding: 0 10px; font-size: 14px; }
.btn.lg { height: 52px; padding: 0 22px; font-size: 18px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 8px; border: 0; background: transparent;
  color: var(--muted); display: inline-grid; place-items: center; cursor: pointer;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.icon-btn.starred { color: var(--accent); }
.icon-btn.starred svg { fill: currentColor; }
.link {
  border: 0; background: none; color: var(--primary); cursor: pointer; padding: 0;
  font: inherit; display: inline-flex; align-items: center; gap: 6px;
}
.link:disabled { color: var(--muted); cursor: default; }
kbd {
  font-family: var(--font); font-size: 11px; line-height: 1.6; padding: 0 6px; border-radius: 5px;
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--muted);
}
.btn.primary kbd { background: rgba(255, 255, 255, 0.15); border-color: rgba(255, 255, 255, 0.35); color: #fff; }

/* ---------- ฟอร์ม ---------- */
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  height: 42px; padding: 0 12px; width: 100%;
  border: 1px solid var(--border-strong); border-radius: 10px;
}
textarea { height: auto; padding: 10px 12px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input[type='checkbox'], input[type='radio'] { width: 18px; height: 18px; padding: 0; accent-color: var(--primary); flex-shrink: 0; }
input[type='radio'] { border-radius: 50%; }
.check-col { display: flex; flex-direction: column; gap: 2px; }
input[type='date'] { width: auto; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 13.5px; color: var(--muted); font-weight: 500; }
.field.big input { height: 62px; font-size: 30px; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid.one { grid-template-columns: 1fr; }
.form-grid.three { grid-template-columns: repeat(3, 1fr); }
.span-2 { grid-column: span 2; }
.check { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 4px 0; }
.check-row { display: flex; flex-wrap: wrap; gap: 6px 22px; }
.input-group { display: flex; gap: 8px; }
.input-group > input, .input-group > select { flex: 1; min-width: 0; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.form-actions.start { justify-content: flex-start; }
.notice {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: 10px; margin: 12px 0; font-size: 14.5px;
}
.notice.warn { background: var(--warning-soft); color: var(--warning); }
.notice.ok { background: var(--success-soft); color: var(--success); }
.notice.danger { background: var(--danger-soft); color: var(--danger); }
.error-list { margin: 6px 0 0; padding-left: 18px; max-height: 200px; overflow: auto; font-size: 13.5px; }

/* ---------- ทั่วไป ---------- */
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.mono { font-family: var(--mono); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.mt { margin-top: 22px !important; }
.badge { background: var(--primary-soft); color: var(--primary); border-radius: 999px; padding: 1px 10px; font-size: 13px; font-weight: 500; }
.tag { display: inline-block; font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 0 8px; }
.status { font-size: 12.5px; padding: 2px 10px; border-radius: 999px; background: var(--success-soft); color: var(--success); white-space: nowrap; }
.status.void { background: var(--danger-soft); color: var(--danger); }

/* ---------- หน้าขาย ---------- */
.sale-page { display: grid; grid-template-columns: minmax(0, 1fr) 430px; height: 100%; }
.catalog { display: flex; flex-direction: column; gap: 12px; padding: 16px; min-height: 0; }
.search-bar { display: flex; gap: 10px; }
.search-input {
  flex: 1; display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 2px solid var(--border); border-radius: 12px;
  padding: 0 8px 0 14px; height: 56px; color: var(--muted);
}
.search-input:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.search-input input { border: 0; box-shadow: none !important; height: 100%; padding: 0; font-size: 18px; background: transparent; }
.search-input.sm { height: 42px; flex: 0 1 340px; border-width: 1px; border-color: var(--border-strong); }
.search-input.sm input { font-size: 15px; }
.search-bar .btn { height: 56px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; min-height: 34px; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px;
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  font: inherit; font-size: 14px; cursor: pointer; color: var(--text);
}
.chip:hover { border-color: var(--border-strong); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.product-grid {
  flex: 1; overflow: auto; display: grid; gap: 10px; align-content: start;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); padding: 2px 2px 12px;
}
.tile {
  display: flex; flex-direction: column; justify-content: space-between; gap: 8px;
  min-height: 98px; padding: 12px; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-sm); font: inherit; color: var(--text);
  transition: border-color 0.12s, transform 0.06s;
}
.tile:hover { border-color: var(--primary); }
.tile:active { transform: scale(0.97); }
.tile-name { font-weight: 500; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile-foot { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.tile-price { font-weight: 600; font-size: 17px; color: var(--primary); font-variant-numeric: tabular-nums; }
.tile-stock { font-size: 12px; color: var(--muted); background: var(--surface-2); border-radius: 6px; padding: 0 6px; }
.tile-stock.low { color: var(--danger); background: var(--danger-soft); }
.grid-empty { grid-column: 1 / -1; display: flex; flex-direction: column; align-items: center; color: var(--muted); padding: 56px 16px; text-align: center; }

.cart { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-left: 1px solid var(--border); }
.cart-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.cart-head h2 { margin: 0; font-size: 18px; }
.cart-lines { flex: 1; overflow: auto; padding: 4px 8px; }
.line {
  display: grid; grid-template-columns: minmax(0, 1fr) auto 92px; gap: 10px; align-items: center;
  padding: 10px 8px; border-bottom: 1px dashed var(--border); cursor: pointer; border-radius: 8px;
}
.line:hover { background: var(--surface-2); }
.line.flash { animation: flash 0.7s ease-out; }
@keyframes flash { from { background: #c8efe8; } to { background: transparent; } }
.line-name { font-weight: 500; line-height: 1.3; word-break: break-word; }
.line-sub { font-size: 13px; color: var(--muted); }
.line-qty { display: grid; grid-template-columns: 30px minmax(34px, 1fr) 30px; align-items: center; gap: 2px; }
.line-qty span { min-width: 34px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
/* ช่องจำนวนพิมพ์ได้ (ดูเหมือนตัวเลข มีกรอบเมื่อชี้/แก้) */
.qty-input { height: 32px; width: 100%; min-width: 0; padding: 0 2px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums;
  border: 1px solid transparent; border-radius: 8px; background: transparent; }
.qty-input:hover { border-color: var(--border); background: var(--surface); }
.qty-input:focus { border-color: var(--primary); background: var(--surface); box-shadow: 0 0 0 3px var(--primary-soft); }
/* ช่อง "จำนวน" ของสินค้าถัดไป (ข้างช่องค้นหา) — เด่นขึ้นเมื่อไม่ใช่ 1 */
.next-qty { flex-shrink: 0; width: 96px; height: 56px; display: flex; flex-direction: column; justify-content: center; gap: 0; padding: 3px 10px;
  background: var(--surface); border: 2px solid var(--border); border-radius: 12px; cursor: text; }
.next-qty span { font-size: 11.5px; color: var(--muted); line-height: 1.2; white-space: nowrap; }
.next-qty input { border: 0; box-shadow: none !important; height: 28px; padding: 0; font-size: 22px; font-weight: 700; text-align: center; background: transparent; font-variant-numeric: tabular-nums; }
.next-qty:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.next-qty.on { border-color: var(--primary); background: var(--primary-soft); }
.next-qty.on input { color: var(--primary); }
/* หน้าต่างใส่น้ำหนัก/ความยาว (สินค้าขายแบบชั่ง/วัด) */
.measure-field { margin-bottom: 12px; }
.measure-input { display: flex; align-items: center; gap: 10px; border: 2px solid var(--primary); border-radius: 12px; padding: 4px 14px; background: var(--surface); }
.measure-input:focus-within { box-shadow: 0 0 0 3px var(--primary-soft); }
.measure-input input { flex: 1; min-width: 0; border: 0; box-shadow: none !important; height: 52px; padding: 0; background: transparent;
  font-size: 34px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.measure-input b { font-size: 20px; color: var(--muted); }
.measure-calc { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 10px 14px; border-radius: 12px; background: var(--surface-2); margin-bottom: 8px; }
.measure-calc span { color: var(--muted); }
.measure-calc strong { font-size: 26px; font-variant-numeric: tabular-nums; }
.qty-btn {
  width: 30px; height: 32px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); display: grid; place-items: center; cursor: pointer;
}
.qty-btn:hover { border-color: var(--primary); color: var(--primary); }
.line-amount { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.cart-empty { display: flex; flex-direction: column; align-items: center; text-align: center; color: var(--muted); padding: 64px 20px; }
.cart-empty svg { color: var(--border-strong); margin-bottom: 8px; }
.cart-empty p { margin: 4px 0; }
.cart-summary { padding: 12px 16px 16px; border-top: 1px solid var(--border); background: var(--surface-2); }
.sum-row { display: flex; justify-content: space-between; align-items: center; padding: 3px 0; font-variant-numeric: tabular-nums; }
.sum-row.total { padding-top: 8px; font-size: 32px; font-weight: 700; line-height: 1.2; }
.sum-row.total span:first-child { font-size: 18px; font-weight: 500; color: var(--muted); }
.pay-actions { display: flex; gap: 10px; margin-top: 12px; }
.pay-btn { flex: 1; height: 64px; font-size: 22px; border-radius: 12px; }
.drawer-btn { height: 64px; border-radius: 12px; }

/* ---------- ชำระเงิน ---------- */
.pay-total { display: flex; flex-direction: column; align-items: center; padding: 0 0 16px; }
.pay-total span { color: var(--muted); }
.pay-total strong { font-size: 50px; line-height: 1.15; font-weight: 700; font-variant-numeric: tabular-nums; }
.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px;
  padding: 4px; margin-bottom: 16px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
}
.segmented button {
  height: 48px; border: 0; background: transparent; border-radius: 9px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 500; color: var(--muted);
}
.segmented button.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }
.segmented.small { display: inline-grid; margin: 0; }
.segmented.small button { height: 32px; padding: 0 14px; font-size: 14px; }
.quick-cash { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.quick-cash .btn { flex: 1 1 88px; height: 48px; font-size: 17px; font-variant-numeric: tabular-nums; }
.change-box {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px; border-radius: 12px; background: var(--success-soft); color: var(--success);
}
.change-box strong { font-size: 38px; font-variant-numeric: tabular-nums; }
.change-box.short { background: var(--danger-soft); color: var(--danger); }
.pay-qr { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; }
.qr-card {
  display: flex; flex-direction: column; align-items: center; padding-bottom: 12px;
  background: #fff; border: 1px solid var(--border); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow);
}
.qr-card-head { width: 100%; padding: 8px; margin-bottom: 12px; background: #0f3d6e; color: #fff; font-weight: 600; letter-spacing: 0.5px; }
.qr-img { display: block; margin: 0 18px; image-rendering: pixelated; }
.qr-card-name { font-weight: 600; margin-top: 8px; }
.qr-card-amount { font-size: 22px; font-weight: 700; color: var(--primary); }
.pay-other { display: flex; flex-direction: column; align-items: center; color: var(--muted); padding: 24px; }

.done { text-align: center; padding: 8px 0; }
.done h2 { margin: 0; }
.done-icon { width: 72px; height: 72px; margin: 0 auto 12px; border-radius: 50%; display: grid; place-items: center; background: var(--success-soft); color: var(--success); }
.done-amount { display: flex; flex-direction: column; margin-top: 16px; }
.done-amount strong { font-size: 54px; line-height: 1.2; font-weight: 700; color: var(--success); font-variant-numeric: tabular-nums; }

/* ---------- Modal / แจ้งเตือน ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; padding: 16px;
  display: grid; place-items: center; background: rgba(9, 22, 20, 0.48);
  animation: fade 0.12s ease-out;
}
.modal {
  display: flex; flex-direction: column; max-width: min(100%, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg);
  animation: pop 0.14s ease-out;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px 8px; }
.modal-head h3 { margin: 0; font-size: 19px; }
.modal-body { padding: 8px 20px 18px; overflow: auto; }
.modal-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 16px 16px; }
.dialog-message { margin: 0 0 8px; white-space: pre-line; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } }

.toasts { position: fixed; top: 16px; right: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast {
  display: flex; gap: 10px; align-items: center; max-width: 440px;
  padding: 12px 16px; border-radius: 10px; color: #fff; background: #1f2d2a; box-shadow: var(--shadow-lg);
  animation: slide 0.18s ease-out;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
.toast.warning { background: #b45309; }
@keyframes slide { from { opacity: 0; transform: translateX(20px); } }

/* ---------- หน้าทั่วไป ---------- */
.page { height: 100%; overflow: auto; padding: 20px 24px 32px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; font-size: 26px; line-height: 1.2; }
.page-head p { margin: 4px 0 0; }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar select { width: auto; min-width: 200px; }
.date-nav .btn { min-width: 42px; padding: 0 12px; }

.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--surface-2); }
.table tr.row-selected td { background: var(--primary-soft); }
.sel-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 13px; font-weight: 500; color: var(--muted);
  padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .center { text-align: center; }
.table.clickable tbody tr { cursor: pointer; }
.table.clickable tbody tr:hover td, .table tbody tr:hover td { background: var(--surface-2); }
.table.compact th, .table.compact td { padding: 7px 8px; }
.table tr.voided td:not(:last-child) { color: var(--muted); text-decoration: line-through; }
/* ปุ่มท้ายแถวตาราง: เรียงขวา กึ่งกลางแนวตั้ง ปุ่มไอคอนมีกรอบสูงเท่าปุ่มเล็ก */
.row-actions { display: flex; justify-content: flex-end; align-items: center; gap: 6px; white-space: nowrap; }
.row-actions .icon-btn { width: 34px; height: 34px; border: 1px solid var(--border-strong); border-radius: 10px; background: var(--surface); color: var(--text); }
.row-actions .icon-btn:hover:not(:disabled) { background: var(--surface-2); }
.row-actions .icon-btn.danger { color: var(--danger); }
.row-actions .icon-btn.danger:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }
.empty-row { text-align: center; color: var(--muted); padding: 44px !important; }
.table-foot { padding: 12px; text-align: center; border-top: 1px solid var(--border); }

.bill-meta { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; color: var(--muted); margin-bottom: 12px; }
.bill-meta span { display: inline-flex; gap: 6px; align-items: center; }
.bill-sum { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 8px; }
.bill-sum > div { display: flex; justify-content: space-between; padding: 3px 8px; font-variant-numeric: tabular-nums; }
.bill-sum .total { font-size: 20px; font-weight: 600; }

/* ---------- รายงาน ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 14px; }
.kpi { display: flex; flex-direction: column; gap: 2px; padding: 16px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.kpi span { color: var(--muted); font-size: 14px; }
.kpi strong { font-size: 28px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--muted); }
.report-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; min-width: 0; }
.card h3 { display: flex; gap: 8px; align-items: center; margin: 0 0 12px; font-size: 16px; }
.bars { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 76px minmax(0, 1fr) 96px; gap: 10px; align-items: center; font-size: 14px; }
.bar-track { height: 14px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar { display: block; height: 100%; background: var(--primary); border-radius: 4px; }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- ตั้งค่า ---------- */
.tabs { display: flex; gap: 2px; margin-bottom: 16px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab {
  display: flex; gap: 8px; align-items: center; padding: 10px 14px; margin-bottom: -1px;
  border: 0; border-bottom: 2px solid transparent; background: none;
  font: inherit; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }
.settings-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.save-bar { grid-column: 1 / -1; display: flex; justify-content: flex-end; }
.logo-box { display: grid; place-items: center; min-height: 100px; padding: 12px; background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: 10px; }
.logo-box img { max-width: 100%; max-height: 160px; }
.preview-card { position: sticky; top: 0; }
.receipt-preview { display: flex; justify-content: center; max-height: 72vh; overflow: auto; padding: 16px; background: #e6ebe9; border-radius: 10px; }
.receipt-preview img { width: 300px; background: #fff; box-shadow: var(--shadow); }
.label-preview { display: flex; justify-content: center; padding: 20px; background: #e6ebe9; border-radius: 10px; }
.label-preview img { background: #fff; box-shadow: var(--shadow); border-radius: 4px; }
.qr-test { display: flex; gap: 12px; align-items: center; margin-top: 10px; }
.scan-test {
  display: flex; gap: 14px; align-items: center; padding: 16px;
  border: 2px dashed var(--border-strong); border-radius: 12px; color: var(--muted); transition: background 0.2s, border-color 0.2s;
}
.scan-test .big { font-size: 20px; font-weight: 600; color: var(--text); word-break: break-all; }
.scan-test.hit { border-color: var(--primary); background: var(--primary-soft); }
details.help { margin-top: 16px; }
details.help summary { cursor: pointer; color: var(--primary); font-weight: 500; }
details.help ol { padding-left: 20px; line-height: 1.8; }
code { font-family: var(--mono); font-size: 0.9em; background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; }

/* ---------- ตั้งค่าฐานข้อมูลครั้งแรก ---------- */
.setup-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(160deg, #e3f3f0, var(--bg) 60%); }
.setup-card { width: min(660px, 100%); padding: 28px; background: var(--surface); border-radius: 18px; box-shadow: var(--shadow-lg); }
.setup-head { display: flex; gap: 16px; align-items: center; margin-bottom: 16px; }
.setup-head h1 { margin: 0; font-size: 24px; }
.setup-head p { margin: 2px 0 0; }
.brand-mark { display: block; width: 56px; height: 56px; flex-shrink: 0; }

/* ---------- สมาชิก / ลูกหนี้ ---------- */
.member-bar { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--border); min-height: 54px; }
.member-add { color: var(--primary); }
.member-chip {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 6px 10px;
  border: 1px solid #b9e3dc; background: var(--primary-soft); color: var(--primary); border-radius: 10px;
  font: inherit; cursor: pointer; text-align: left;
}
.member-chip-main { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.member-chip-main b { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member-chip-main small { color: var(--muted); font-size: 12px; }
.member-chip-pts { font-size: 13px; font-weight: 600; white-space: nowrap; }
.member-chip-debt { font-size: 12.5px; font-weight: 600; white-space: nowrap; color: var(--danger); background: var(--danger-soft); border-radius: 6px; padding: 0 6px; }
.sum-row.points { color: var(--primary); font-weight: 500; }
.sum-row.points span:first-child { display: inline-flex; gap: 6px; align-items: center; }

.points-use {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; margin-bottom: 14px; border-radius: 12px; background: var(--warning-soft); color: var(--warning);
}
.points-use-label { flex: 1; min-width: 180px; display: flex; flex-direction: column; line-height: 1.3; color: var(--text); font-weight: 500; }
.points-use input { width: 110px; height: 38px; text-align: right; font-weight: 600; }
.pay-credit { display: flex; flex-direction: column; gap: 12px; }
.credit-info { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.credit-info > div { display: flex; flex-direction: column; padding: 8px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.credit-info span { font-size: 13px; color: var(--muted); }
.change-box.credit { background: var(--warning-soft); color: var(--warning); }
.change-box.credit.short { background: var(--danger-soft); color: var(--danger); }
.pay-credit .notice { align-items: center; }
.done-amount.credit strong { color: var(--warning); }
.done-member { margin-top: 14px; padding: 8px 12px; border-radius: 10px; background: var(--primary-soft); color: var(--primary); display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: center; }

.search-input.wide { flex: none; width: 100%; margin-bottom: 10px; }
.member-list { display: flex; flex-direction: column; gap: 4px; max-height: 52vh; overflow: auto; }
.member-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid transparent; background: none; font: inherit; color: var(--text); text-align: left; cursor: pointer;
}
.member-row:hover, .member-row.active { background: var(--primary-soft); border-color: #b9e3dc; }
.member-avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); flex-shrink: 0; }
.member-main { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.member-stats { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-size: 13px; white-space: nowrap; }
.member-stats .pts { color: var(--primary); font-weight: 600; }
.member-stats .debt { color: var(--danger); font-weight: 600; }
.member-empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 28px; color: var(--muted); }

.kpis.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis.compact .kpi { padding: 12px 14px; }
.kpis.compact .kpi strong { font-size: 24px; }
.kpi strong.sm { font-size: 20px; }
.member-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.member-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; }
.member-meta span { display: inline-flex; gap: 6px; align-items: center; }
.ledger-wrap { max-height: 42vh; overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
.ledger-wrap .table th { position: sticky; top: 0; z-index: 1; }
.sub-head { margin: 16px 0 6px; font-size: 14px; color: var(--muted); font-weight: 500; }
.mt-sm { margin-top: 10px; }

.choice-list { display: flex; flex-direction: column; gap: 8px; }
.choice {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; cursor: pointer;
  border: 1px solid var(--border-strong); border-radius: 12px;
}
.choice input { margin-top: 4px; width: 18px; height: 18px; accent-color: var(--primary); flex-shrink: 0; }
.choice span { display: flex; flex-direction: column; }
.choice small { color: var(--muted); }
.choice.active { border-color: var(--primary); background: var(--primary-soft); }
.choice-detail { padding: 4px 14px 8px 44px; }

/* ---------- จอเล็ก ---------- */
@media (max-width: 1200px) {
  .sale-page { grid-template-columns: minmax(0, 1fr) 370px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .report-grid, .settings-grid { grid-template-columns: minmax(0, 1fr); }
  .preview-card { position: static; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 72px minmax(0, 1fr); }
  .sale-page { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); }
  .cart { border-left: 0; border-top: 1px solid var(--border); }
  .form-grid, .form-grid.three { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
}

/* =================== v2: ระบบเต็มรูปแบบ =================== */
.btn.block { width: 100%; }
.btn.warn { background: var(--warning-soft); border-color: #f1d59a; color: var(--warning); }
.status.ok { background: var(--success-soft); color: var(--success); }
.status.bad { background: var(--danger-soft); color: var(--danger); }
.status.warn { background: var(--warning-soft); color: var(--warning); }
.status.muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.tag.warn { background: var(--warning-soft); color: var(--warning); border-color: #f1d59a; }
.tag.ok { background: var(--success-soft); color: var(--success); border-color: #bfe5cb; }
.tag.bad { background: var(--danger-soft); color: var(--danger); border-color: #f5c2c2; }
.tab-badge { background: var(--danger); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 6px; margin-left: 4px; }
.empty-state { display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--muted); padding: 64px 16px; text-align: center; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.big-num { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.split.wide-left { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.card + .card { margin-top: 0; }
.card h3 .spacer { flex: 1; }
.card-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 12px; }
.kv-list { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 14.5px; }
.kv-list > span:nth-child(odd) { color: var(--muted); }
.section-title { margin: 18px 0 8px; font-size: 15px; color: var(--muted); font-weight: 500; }
tfoot td { background: var(--surface-2); border-top: 1px solid var(--border); }
.table td .sub { display: block; font-size: 12.5px; color: var(--muted); }
.table input, .table select { height: 34px; padding: 0 8px; }
.table input[type='checkbox'], .table input[type='radio'] { height: 18px; padding: 0; }
.inline-input { width: 110px; }
.toolbar .grow { flex: 1; }
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filter-bar select, .filter-bar input { width: auto; min-width: 140px; }
.filter-bar .search-input.sm { flex: 1 1 260px; }
.filter-bar input[type='checkbox'], .filter-bar input[type='radio'] { width: 18px; min-width: 18px; }

/* ---------- เข้าสู่ระบบ / PIN ---------- */
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(160deg, #11302c, #0f766e 120%); }
.login-card { width: min(380px, 100%); padding: 26px; background: var(--surface); border-radius: 20px; box-shadow: var(--shadow-lg); }
.login-offline { margin: 10px 0 0; padding: 8px 10px; border-radius: 10px; background: var(--warning-soft); color: var(--warning); }
.login-offline .icon { vertical-align: -2px; }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 10px; text-align: center; }
.login-brand img { max-height: 70px; max-width: 200px; }
.login-brand h1 { margin: 6px 0 0; font-size: 22px; }
.login-brand p { margin: 0; }
.pinpad { display: flex; flex-direction: column; gap: 10px; }
.pin-dots { display: flex; justify-content: center; gap: 12px; padding: 8px 0 0; }
.pin-dots span { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border-strong); }
.pin-dots span.on { background: var(--primary); border-color: var(--primary); }
.pin-dots.shake { animation: shake 0.35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.pin-error { text-align: center; color: var(--danger); min-height: 22px; margin: 0; font-size: 14px; }
.pin-keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pin-keys button { height: 58px; font: inherit; font-size: 24px; font-weight: 600; border: 1px solid var(--border); background: var(--surface-2); border-radius: 12px; cursor: pointer; display: grid; place-items: center; color: var(--text); }
.pin-keys button:hover { border-color: var(--primary); }
.pin-keys button:active { transform: scale(0.97); }
.pin-keys button.soft { font-size: 15px; color: var(--muted); }
.approval-head { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 12px; background: var(--warning-soft); color: var(--warning); margin-bottom: 6px; }
.approval-head div { display: flex; flex-direction: column; color: var(--text); }
.user-chip { display: flex; flex-direction: column; align-items: center; padding: 6px 2px; color: #fff; font-size: 12px; text-align: center; line-height: 1.25; }
.user-chip b { font-weight: 500; max-width: 76px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip small { color: var(--sidebar-text); }

/* ---------- ตัวเลือกค้นหา ---------- */
.picker { position: relative; }
.picker-chosen { display: flex; align-items: center; justify-content: space-between; gap: 8px; height: 42px; padding: 0 6px 0 12px; border: 1px solid var(--primary); background: var(--primary-soft); border-radius: 10px; }
.picker-chosen span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-list { position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px); max-height: 300px; overflow: auto; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px; box-shadow: var(--shadow); }
.picker-list button { display: flex; flex-direction: column; align-items: flex-start; width: 100%; padding: 8px 12px; border: 0; background: none; font: inherit; text-align: left; cursor: pointer; color: var(--text); }
.picker-list button:hover, .picker-list button.active { background: var(--primary-soft); }
.date-range { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.date-range input { width: auto; }

/* ---------- หน้าขาย v2 ---------- */
.tile.banned { opacity: 0.5; border-color: var(--danger); }
.tile-price small { font-size: 12px; color: var(--muted); font-weight: 400; }
.member-alerts { padding: 6px 12px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 3px; }
.alert-line { display: flex; gap: 6px; align-items: center; font-size: 13.5px; padding: 3px 8px; border-radius: 6px; }
.alert-line.danger { background: var(--danger-soft); color: var(--danger); }
.alert-line.warn { background: var(--warning-soft); color: var(--warning); }
.alert-line.info { background: var(--primary-soft); color: var(--primary); }
.cart-warnings { padding: 6px 14px; font-size: 13px; color: var(--warning); background: var(--warning-soft); display: flex; flex-direction: column; gap: 2px; }
.cart-warnings > div { display: flex; gap: 6px; align-items: center; }
.cart-tools { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.cart-tools .btn { flex: 1 1 auto; }
.shift-line { margin-top: 8px; font-size: 13px; color: var(--muted); display: flex; justify-content: center; }
.shift-line span, .shift-line button { display: inline-flex; gap: 6px; align-items: center; }
.quick-add { margin-top: 12px; padding-top: 8px; border-top: 1px solid var(--border); }

.pay-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 18px; }
.pay-main { min-width: 0; }
.pay-side { display: flex; flex-direction: column; gap: 6px; padding: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; align-self: start; }
.pay-side .change-box { padding: 10px 14px; margin: 6px 0; }
.pay-side .change-box strong { font-size: 28px; }
.pay-points { color: var(--primary); font-size: 14px; display: flex; gap: 6px; align-items: center; }
.method-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; margin-bottom: 12px; }
.method-btn { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 6px; border: 1px solid var(--border-strong); border-radius: 12px; background: var(--surface); font: inherit; font-size: 14px; cursor: pointer; color: var(--text); }
.method-btn:hover:not(:disabled) { border-color: var(--primary); }
.method-btn.active { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.method-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.pay-rows { display: flex; flex-direction: column; gap: 10px; }
.pay-row { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; }
.pay-row-head { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.big-input { height: 54px !important; font-size: 26px !important; font-weight: 600; text-align: right; }
.pay-qr-row { display: flex; gap: 14px; align-items: center; }
.inst-box { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.inst-preview { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.inst-preview > div { display: flex; flex-direction: column; padding: 6px 10px; background: var(--primary-soft); border-radius: 8px; }
.inst-preview span { font-size: 12.5px; color: var(--muted); }

/* ---------- รายละเอียดเอกสาร ---------- */
.doc-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: flex-start; margin-bottom: 10px; }
.doc-head h2 { margin: 0; font-size: 20px; }
.doc-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.line-input { width: 90px; }
.limit-note { display: block; font-size: 12px; }
.table tr.total-row td { background: var(--surface-2); }
.badge.warn { background: var(--warning-soft); color: var(--warning); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.chart-bars { display: flex; align-items: flex-end; gap: 4px; height: 140px; padding-top: 8px; }
.chart-bars div { flex: 1; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.chart-bars div span { position: absolute; bottom: -18px; left: 0; right: 0; text-align: center; font-size: 11px; color: var(--muted); }
.legend { display: flex; gap: 12px; font-size: 13px; color: var(--muted); }

@media (max-width: 1000px) {
  .pay-layout, .split, .split.wide-left { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- ปรับให้พอดีจอ 1366×768 / 1024×768 ---------- */
.sidebar { overflow-y: auto; gap: 2px; padding: 10px 6px; scrollbar-width: none; }
.sidebar::-webkit-scrollbar { display: none; }
.brand { width: 42px; height: 42px; margin: 0 auto 8px; }
.nav-item { padding: 6px 2px; font-size: 12px; gap: 2px; border-radius: 8px; }
.nav-item.active::before { left: -6px; top: 8px; bottom: 8px; }
.cart-tools { flex-wrap: nowrap; }
.cart-tools .btn.sm { flex: 1 1 0; min-width: 0; height: 32px; padding: 0 6px; font-size: 13px; gap: 4px; }
.cart-tools .btn.sm.danger { flex: 0 0 36px; }
.cart-summary { padding: 10px 14px 12px; }
.sum-row.total { font-size: 28px; padding-top: 4px; }
.pay-actions { margin-top: 8px; }
.pay-btn, .drawer-btn { height: 56px; }
.shift-line { margin-top: 6px; }
@media (max-height: 760px) {
  .search-input { height: 46px; }
  .search-bar .btn { height: 46px; }
  .next-qty { height: 46px; padding: 1px 10px; }
  .next-qty input { height: 24px; font-size: 19px; }
  .next-qty span { font-size: 10.5px; }
  .sum-row { padding: 1px 0; font-size: 14px; }
  .sum-row.total { font-size: 24px; }
  .pay-btn, .drawer-btn { height: 50px; font-size: 19px; }
}
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 2px 14px; max-height: 46vh; overflow: auto; padding: 4px; border: 1px solid var(--border); border-radius: 10px; }
.denoms { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.denoms input { text-align: right; }
a.alert-line { text-decoration: none; }
.card h3 small { font-weight: 400; font-size: 13px; }

/* ---------- แม่แบบเอกสาร ---------- */
.tpl-layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 14px; align-items: start; }
.tpl-list { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 8px; position: sticky; top: 0; max-height: calc(100vh - 150px); overflow: auto; }
.tpl-group + .tpl-group { margin-top: 8px; }
.tpl-group-title { font-size: 12.5px; color: var(--muted); font-weight: 600; padding: 4px 8px; }
.tpl-item { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 6px; text-align: left; border: 0; background: transparent; font: inherit; font-size: 14px; color: var(--text); padding: 7px 8px; border-radius: 8px; cursor: pointer; }
.tpl-item:hover { background: var(--surface-2); }
.tpl-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 500; }
.tpl-badge { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.tpl-badge.custom { color: var(--primary); font-weight: 600; }
.tpl-editor { min-width: 0; }
.tpl-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; margin-bottom: 12px; }
.tpl-title { flex: 1; min-width: 200px; }
.tpl-title h3 { margin: 0; font-size: 17px; }
.tpl-title p { margin: 2px 0 0; }
.tpl-body { display: grid; grid-template-columns: minmax(340px, 0.9fr) minmax(0, 1.1fr); gap: 12px; align-items: start; }
.tpl-settings { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.tpl-form { display: flex; flex-direction: column; gap: 8px; }
.tpl-sec { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 0 14px; }
.tpl-sec > summary { cursor: pointer; padding: 11px 0; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 8px; }
.tpl-sec > summary::before { content: '▸'; color: var(--muted); transition: transform .15s; }
.tpl-sec[open] > summary::before { transform: rotate(90deg); }
.tpl-sec[open] { padding-bottom: 14px; }
.tpl-num { width: 72px !important; height: 34px !important; padding: 0 8px !important; }
.tpl-margins { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tpl-margins label { display: flex; align-items: center; gap: 4px; font-size: 13.5px; color: var(--muted); }
.tpl-margins input { width: 64px; height: 34px; padding: 0 8px; }
.tpl-deflist { display: flex; flex-direction: column; gap: 4px; }
.tpl-defrow { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 8px; align-items: center; }
.tpl-defrow input:not([type='checkbox']), .tpl-col input:not([type='checkbox']), .tpl-col select { height: 34px; padding: 0 8px; font-size: 14px; }
.tpl-cols { display: flex; flex-direction: column; gap: 4px; }
.tpl-col, .tpl-col-head { display: grid; grid-template-columns: 22px minmax(0, 1fr) 76px 72px 64px; gap: 6px; align-items: center; }
.tpl-col-head { font-size: 12.5px; color: var(--muted); }
.tpl-move { display: flex; gap: 2px; }
.tpl-block { display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; align-items: center; padding: 3px 0; }
.icon-btn.sm { width: 28px; height: 28px; font-size: 14px; }
.icon-btn.danger { color: var(--danger); }
textarea.code { font-family: var(--mono); font-size: 12.5px; line-height: 1.5; white-space: pre; overflow: auto; tab-size: 2; }
.tpl-html .field > span { font-weight: 600; }
.tpl-preview { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px; position: sticky; top: 0; min-width: 0; }
.tpl-preview-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.tpl-preview-bar .check { font-size: 13.5px; padding: 0; gap: 6px; }
.tpl-preview-body { background: #d9dee3; border-radius: 8px; overflow: auto; max-height: calc(100vh - 230px); display: flex; justify-content: center; }
.tpl-frame-wrap { width: 100%; overflow: hidden; }
.tpl-frame { border: 0; transform-origin: 0 0; background: #d9dee3; display: block; }
.tpl-slip-img { width: 300px; height: auto; margin: 16px auto; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.18); image-rendering: auto; }
.tpl-designer-wrap { display: flex; flex-direction: column; gap: 8px; }
.tpl-paper-inline { padding-bottom: 0; }
.var-picker { display: flex; flex-direction: column; gap: 6px; }
.var-picker input { height: 34px; font-size: 14px; }
.var-groups { max-height: 300px; overflow: auto; display: flex; flex-direction: column; gap: 6px; }
.var-picker.compact .var-groups { max-height: 220px; }
.var-title { font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 2px; }
.var-chip { border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text); border-radius: 999px; font: inherit; font-size: 12.5px; padding: 1px 9px; margin: 0 4px 4px 0; cursor: pointer; }
.var-chip:hover { border-color: var(--primary); color: var(--primary); }
.docno-preview { display: flex; flex-direction: column; align-items: center; padding: 12px; border-radius: 10px; background: var(--primary-soft); }
.docno-preview b { font-size: 22px; color: var(--primary); }
.docno-preview.bad { background: var(--warning-soft); }
.docno-preview.bad b { color: var(--warning); }
@media (max-width: 1200px) { .tpl-body { grid-template-columns: minmax(0, 1fr); } .tpl-preview { position: static; } }
@media (max-width: 900px) { .tpl-layout { grid-template-columns: minmax(0, 1fr); } .tpl-list { position: static; max-height: 220px; } }

/* ---------- ตัวออกแบบลากวาง ---------- */
.dz { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 10px; height: calc(100vh - 210px); min-height: 520px; }
.dz-side { overflow: auto; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.dz-box { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; }
.dz-box-title { font-weight: 600; font-size: 14px; display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 6px; }
.dz-actions { display: flex; gap: 2px; }
.dz-palette { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.dz-tool { display: flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface-2); border-radius: 8px; padding: 6px 8px; font: inherit; font-size: 13px; color: var(--text); cursor: pointer; text-align: left; }
.dz-tool:hover { border-color: var(--primary); color: var(--primary); }
.dz-tool b { width: 18px; text-align: center; }
.dz-vars { margin-top: 6px; font-size: 13.5px; }
.dz-vars > summary { cursor: pointer; color: var(--primary); padding: 4px 0; }
.dz-props input:not([type='checkbox']):not([type='color']), .dz-props select, .dz-props textarea { height: 32px; padding: 0 8px; font-size: 13.5px; }
.dz-props textarea { height: auto; padding: 6px 8px; }
.dz-props input[type='color'] { height: 32px; padding: 2px; }
.dz-grid4, .dz-grid3 { display: grid; gap: 6px; margin-bottom: 6px; }
.dz-grid4 { grid-template-columns: repeat(4, 1fr); }
.dz-grid3 { grid-template-columns: repeat(3, 1fr); }
.dz-grid4 label, .dz-grid3 label, .dz-field { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.dz-check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); margin: 2px 0; }
.dz-inline-color { width: 48px !important; }
.dz-toggles { display: flex; flex-wrap: wrap; gap: 3px; align-items: center; }
.dz-toggles button { border: 1px solid var(--border); background: var(--surface); border-radius: 6px; min-width: 30px; height: 28px; font: inherit; font-size: 12.5px; color: var(--text); cursor: pointer; padding: 0 6px; }
.dz-toggles button.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.dz-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.dz-col { display: grid; grid-template-columns: 1fr 1.2fr 46px 52px; gap: 4px; align-items: center; margin-bottom: 4px; position: relative; padding-bottom: 22px; }
.dz-col input, .dz-col select { height: 30px !important; font-size: 12.5px !important; padding: 0 6px !important; }
.dz-col-btns { position: absolute; right: 0; bottom: 0; display: flex; gap: 2px; }
.dz-col-btns .icon-btn.sm { width: 22px; height: 20px; }
.dz-total-row { display: grid; grid-template-columns: 22px 1fr; gap: 6px; align-items: center; margin-bottom: 3px; }
.dz-layers { max-height: 220px; overflow: auto; }
.dz-layer { display: grid; grid-template-columns: 20px minmax(0, 1fr) 26px 26px; gap: 4px; align-items: center; padding: 3px 6px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.dz-layer:hover { background: var(--surface-2); }
.dz-layer.on { background: var(--primary-soft); color: var(--primary); }
.dz-layer-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dz-main { display: flex; flex-direction: column; min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.dz-toolbar { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.dz-zoom { min-width: 44px; text-align: center; font-size: 13px; }
.dz-snap { width: 64px !important; height: 30px !important; padding: 0 6px !important; }
.dz-hint { margin-left: auto; }
.dz-canvas { flex: 1; overflow: auto; background: #cfd5db; padding: 24px; outline: none; }
.dz-sizer { position: relative; margin: 0 auto; }
.dz-page { position: absolute; left: 0; top: 0; transform-origin: 0 0; background: #fff; color: #111; box-shadow: 0 2px 12px rgba(0,0,0,.2); font-size: 11pt; line-height: 1.3; }
.dz-page.grid { background-image: linear-gradient(rgba(15,118,110,.08) 1px, transparent 1px), linear-gradient(90deg, rgba(15,118,110,.08) 1px, transparent 1px); background-size: 5mm 5mm; }
.dz-safe { position: absolute; inset: 5mm; border: 1px dashed rgba(220,38,38,.35); pointer-events: none; }
.dz-el { position: absolute; cursor: move; outline: 1px dashed rgba(100,113,109,.35); }
.dz-el:hover { outline-color: var(--primary); }
.dz-el.sel { outline: 1.5px solid var(--primary); z-index: 5; }
.dz-el .el { pointer-events: none; }
.dz-h { position: absolute; width: 9px; height: 9px; background: #fff; border: 1.5px solid var(--primary); border-radius: 2px; z-index: 6; }
.dz-h.h-nw { left: -5px; top: -5px; cursor: nwse-resize; } .dz-h.h-n { left: calc(50% - 5px); top: -5px; cursor: ns-resize; }
.dz-h.h-ne { right: -5px; top: -5px; cursor: nesw-resize; } .dz-h.h-e { right: -5px; top: calc(50% - 5px); cursor: ew-resize; }
.dz-h.h-se { right: -5px; bottom: -5px; cursor: nwse-resize; } .dz-h.h-s { left: calc(50% - 5px); bottom: -5px; cursor: ns-resize; }
.dz-h.h-sw { left: -5px; bottom: -5px; cursor: nesw-resize; } .dz-h.h-w { left: -5px; top: calc(50% - 5px); cursor: ew-resize; }
@media (max-width: 1100px) { .dz { grid-template-columns: 260px minmax(0, 1fr); } }

/* ---------- สติ๊กเกอร์ ---------- */
.tpl-name-input { font-size: 17px; font-weight: 600; height: 36px; max-width: 360px; }
.tpl-add { color: var(--primary); }
.tpl-label-preview { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 18px 10px; width: 100%; }
.tpl-label-preview img { background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.18); image-rendering: pixelated; max-width: 100%; }
.lp { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 14px; }
.lp-add { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 10px; }
.lp-table { max-height: 52vh; overflow: auto; }
.lp-table tr { cursor: pointer; }
.lp-table tr.lp-sel td { background: var(--primary-soft); }
.lp-in { height: 34px !important; padding: 0 8px !important; font-size: 14px; }
.lp-side { display: flex; flex-direction: column; gap: 10px; }
.lp-preview { background: #cfd5db; border-radius: 10px; min-height: 140px; display: flex; align-items: center; justify-content: center; padding: 12px; }
.lp-preview img { width: 100%; max-width: 240px; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.2); image-rendering: pixelated; }
.lp-sum { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; }
.lp-sum > div { display: flex; justify-content: space-between; }
@media (max-width: 860px) { .lp { grid-template-columns: minmax(0, 1fr); } }
.basis-select { width: 118px !important; min-width: 0; font-size: 13px !important; }
.unit-calc { font-size: 11.5px; color: var(--muted); white-space: nowrap; margin-top: 2px; text-align: right; }

/* ---------- หน้าขาย: ตารางบิลทางซ้าย / ข้อมูลสมาชิกทางขวา ---------- */
.sale-page { grid-template-columns: minmax(0, 1fr) 400px; }
.bill { display: flex; flex-direction: column; gap: 10px; padding: 14px 16px; min-height: 0; min-width: 0; }
.search-wrap { position: relative; flex: 1; min-width: 0; }
.search-wrap .search-input { width: 100%; }
.search-results { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 20; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 12px; box-shadow: var(--shadow-lg); max-height: 62vh; overflow: auto; }
.search-results-head { position: sticky; top: 0; background: var(--surface); padding: 8px 12px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: 8px; }
.search-result { display: grid; grid-template-columns: minmax(0, 1fr) auto 128px; gap: 10px; width: 100%; align-items: center; text-align: left; border: 0; border-bottom: 1px solid var(--border); background: transparent; font: inherit; color: var(--text); padding: 8px 12px; cursor: pointer; }
.search-result:hover, .search-result.active { background: var(--primary-soft); }
.search-result.banned { opacity: 0.5; }
.sr-name { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.sr-name b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-name small { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-stock { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.sr-stock.low { color: var(--danger); }
.sr-price { text-align: right; font-weight: 600; color: var(--primary); font-variant-numeric: tabular-nums; white-space: nowrap; }
.sr-price small { font-weight: 400; color: var(--muted); }
.search-empty { padding: 20px; text-align: center; color: var(--muted); }
.quick-open { color: var(--primary); font-weight: 600; }
.quote-bar { display: flex; align-items: center; gap: 8px; margin: 0; padding: 6px 10px; flex-wrap: wrap; }
.order-chip { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.chip-x { border: 0; background: transparent; cursor: pointer; font-size: 15px; line-height: 1; padding: 0 2px; color: inherit; opacity: 0.7; }
.chip-x:hover { opacity: 1; color: var(--danger); }
.bill-table { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.bill-head, .bill-line { display: grid; grid-template-columns: 30px minmax(0, 1fr) 118px 104px 96px 86px 108px 36px; gap: 8px; align-items: center; padding: 0 8px 0 12px; }
.bill-head { height: 38px; background: var(--surface-2); border-bottom: 1px solid var(--border); font-size: 13px; color: var(--muted); font-weight: 500; }
.bill-head .c { text-align: center; }
.bill-head .num, .bill-line .num { text-align: right; font-variant-numeric: tabular-nums; }
.bill-lines.cart-lines { flex: 1; overflow: auto; padding: 0; }
.bill-line { min-height: 56px; padding-top: 6px; padding-bottom: 6px; border-bottom: 1px solid var(--border); cursor: pointer; }
.bill-line:hover { background: var(--surface-2); }
.bill-line.flash { animation: flash 0.7s ease-out; }
.bill-line.short { background: var(--danger-soft); box-shadow: inset 3px 0 0 var(--danger); }
.bill-line.short:hover { background: var(--danger-soft); }
.bl-no { text-align: center; color: var(--muted); font-size: 13px; }
.bl-main { min-width: 0; }
.bl-main .line-sub { display: flex; flex-wrap: wrap; gap: 4px; }
.bl-unit { display: flex; flex-direction: column; line-height: 1.2; }
.bl-unit small { color: var(--muted); font-size: 12px; }
.bl-disc { color: var(--danger); font-size: 14px; }
.bl-amount { font-weight: 600; font-size: 16px; }
.bl-del { display: flex; justify-content: center; }
.bl-del .icon-btn { color: var(--danger); }
.bl-del .icon-btn:hover:not(:disabled) { background: var(--danger-soft); color: var(--danger); }
.bill-foot { display: flex; justify-content: space-between; gap: 10px; padding: 8px 14px; border-top: 1px solid var(--border); background: var(--surface-2); font-size: 14px; }
.bill .cart-warnings { border-radius: 10px; }

.member-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; border-bottom: 1px solid var(--border); }
.member-empty-btn { margin: 14px; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 22px 14px; border: 2px dashed var(--border-strong); border-radius: 14px; background: var(--surface-2); color: var(--primary); font: inherit; cursor: pointer; }
.member-empty-btn:hover { border-color: var(--primary); }
.member-empty-btn small { color: var(--muted); }
.mp-head { display: flex; gap: 10px; align-items: flex-start; padding: 12px 12px 10px 14px; border-bottom: 1px solid var(--border); }
.mp-avatar { width: 46px; height: 46px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: 17px; overflow: hidden; flex-shrink: 0; }
.mp-avatar img { width: 100%; height: 100%; object-fit: cover; }
.mp-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.mp-title b { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mp-title small { color: var(--muted); }
.mp-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.mp-badge { font-size: 11.5px; padding: 0 7px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); }
.mp-badge.bday { background: #fdf2f8; border-color: #fbcfe8; color: #be185d; }
.mp-actions { display: flex; }
.mp-body { flex: 1; overflow: auto; padding: 10px 14px 12px; display: flex; flex-direction: column; gap: 10px; }
.mp-body .member-alerts { padding: 0; border: 0; }
.mp-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.mp-stats > div { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 6px 10px; display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.mp-stats span { font-size: 12px; color: var(--muted); }
.mp-stats b { font-size: 18px; font-variant-numeric: tabular-nums; }
.mp-stats b.sm { font-size: 15px; }
.mp-stats small { font-size: 11.5px; color: var(--muted); }
.mp-section { border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column; gap: 3px; }
.mp-section-title { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-weight: 600; font-size: 13.5px; margin-bottom: 2px; }
.mp-row { display: flex; justify-content: space-between; gap: 8px; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.mp-row span:last-child { text-align: right; }
.mp-row small { color: var(--muted); }
.mp-row.small { font-size: 12.5px; color: var(--muted); }
.mp-row.mp-cr span:last-child { white-space: nowrap; }
.mp-row.mp-cr-total { font-weight: 600; padding-bottom: 4px; margin-bottom: 2px; border-bottom: 1px dashed var(--border); }
.mp-section-title small { font-weight: 400; font-size: 12px; }
.mp-bad, .mp-bad small, .mp-badge.mp-bad { color: var(--danger) !important; }
.mp-badge.mp-bad { border-color: var(--danger); }
.mp-top { display: flex; flex-wrap: wrap; gap: 6px; }
.mp-top .chip { height: 30px; font-size: 13px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; line-height: 28px; }
.mp-note { font-size: 13px; background: var(--warning-soft); color: var(--warning); padding: 6px 10px; border-radius: 8px; display: flex; gap: 6px; align-items: flex-start; }
.cart .cart-summary { flex-shrink: 0; }
@media (max-width: 1360px) {
  .sale-page { grid-template-columns: minmax(0, 1fr) 360px; }
  .bill-head, .bill-line { grid-template-columns: 28px minmax(0, 1fr) 112px 88px 90px 78px 100px 34px; gap: 6px; padding: 0 6px 0 10px; }
}
@media (max-width: 1180px) {
  .sale-page { grid-template-columns: minmax(0, 1fr) 330px; }
  .bill-head, .bill-line { grid-template-columns: 26px minmax(0, 1fr) 108px 80px 86px 96px 34px; }
  .bill-head > :nth-child(6), .bill-line > :nth-child(6) { display: none; }
}
/* จอแคบ: ซ่อนราคา/หน่วย ให้ชื่อ จำนวน ยอด และถังขยะยังอยู่ในจอเสมอ */
@media (max-width: 1040px) {
  .sale-page { grid-template-columns: minmax(0, 1fr) 300px; }
  .bill-head, .bill-line { grid-template-columns: 22px minmax(0, 1fr) 104px 64px 88px 32px; gap: 4px; padding: 0 4px 0 8px; }
  .bill-head > :nth-child(5), .bill-line > :nth-child(5) { display: none; }
}
/* จอแคบมาก: บิลอยู่บน ข้อมูลสมาชิก/ยอดชำระอยู่ล่าง (ต้องอยู่หลังกฎด้านบนเพื่อไม่ถูกทับ) */
@media (max-width: 860px) {
  .sale-page { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(320px, 1fr) auto; height: auto; min-height: 100%; }
  .bill-head, .bill-line { grid-template-columns: 22px minmax(0, 1fr) 100px 60px 84px 32px; }
}

/* ---------- หน้าต่างขายด่วน ---------- */
.qk { display: flex; flex-direction: column; gap: 10px; min-height: 50vh; }
.qk-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.qk-tab { height: 40px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); font: inherit; cursor: pointer; display: flex; align-items: center; gap: 6px; color: var(--text); }
.qk-tab small { font-size: 12px; color: var(--muted); }
.qk-tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.qk-tab.active small { color: #d1fae5; }
.qk-tab.add { border-style: dashed; color: var(--primary); }
.qk-key { font-size: 11px; border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; opacity: 0.7; }
.qk-edit-bar { display: grid; grid-template-columns: 220px auto minmax(240px, 1fr); gap: 10px; align-items: end; padding: 10px; background: var(--surface-2); border-radius: 10px; }
.qk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; align-content: start; max-height: 62vh; overflow: auto; padding: 2px; }
.qk-grid.editing { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.qk-tile { --qk: var(--primary); position: relative; display: flex; flex-direction: column; justify-content: space-between; gap: 8px; min-height: 96px; padding: 12px; background: var(--surface); border: 1px solid var(--border); border-left: 5px solid var(--qk); border-radius: 12px; box-shadow: var(--shadow-sm); cursor: pointer; user-select: none; }
.qk-grid:not(.editing) .qk-tile:hover { border-color: var(--qk); }
.qk-grid:not(.editing) .qk-tile:active { transform: scale(0.98); }
.qk-grid.editing .qk-tile { cursor: default; }
.qk-tile.banned { opacity: 0.5; }
.qk-tile.hit { background: var(--primary-soft); }
.qk-name { font-weight: 500; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.qk-foot { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.qk-price { font-weight: 600; font-size: 17px; color: var(--primary); font-variant-numeric: tabular-nums; }
.qk-price small { font-weight: 400; font-size: 12px; color: var(--muted); }
.qk-stock { font-size: 12px; color: var(--muted); background: var(--surface-2); border-radius: 6px; padding: 0 6px; }
.qk-stock.low { color: var(--danger); background: var(--danger-soft); }
.qk-hit { position: absolute; top: 6px; right: 6px; background: var(--primary); color: #fff; border-radius: 999px; font-size: 12px; font-weight: 700; padding: 0 7px; }
.qk-tile-edit { display: flex; flex-direction: column; gap: 5px; }
.qk-tile-edit input, .qk-tile-edit select { height: 30px; font-size: 13px; padding: 0 6px; }
.qk-colors { display: flex; gap: 4px; flex-wrap: wrap; }
.qk-color { width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--border-strong); cursor: pointer; padding: 0; }
.qk-color.on { outline: 2px solid var(--text); outline-offset: 1px; }
.qk-tile-actions { display: flex; gap: 3px; align-items: center; }
.qk-move { flex: 1; min-width: 0; }
.qk-empty { grid-column: 1 / -1; display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--muted); padding: 48px 16px; }
@media (max-width: 900px) { .qk-edit-bar { grid-template-columns: minmax(0, 1fr); } }
.search-bar .btn .btn-text { margin-left: 2px; }
@media (max-width: 1180px) {
  .search-bar .btn .btn-text { display: none; }
  .search-bar .btn { padding: 0 14px; }
}
.return-credit { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: var(--surface-2); }
.rc-row { display: flex; justify-content: space-between; gap: 10px; padding: 2px 0; font-variant-numeric: tabular-nums; }
.rc-row.hi { color: var(--warning); font-weight: 600; }

/* ---------- สินค้าแบ่งขาย / สินค้าชุด ---------- */
.text-ok { color: var(--success); }
.table tr.row-warn td { background: var(--warning-soft); }
.section-title-row { display: flex; align-items: center; gap: 10px; }
.section-title-row .section-title { margin: 18px 0 8px; }
.split-ratio { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 14px 0; padding: 12px 14px; border: 2px solid var(--primary); border-radius: 12px; background: var(--primary-soft); }
.split-ratio b { font-size: 17px; }
.split-ratio select { width: auto; min-width: 140px; }
.split-ratio .ratio-qty { width: 110px; font-size: 18px; font-weight: 700; text-align: right; }
.split-ratio .ratio-unit { width: 110px; }
.kit-sum { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 14px 0 8px; }
.kit-sum > div { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); min-width: 0; }
.kit-sum span { font-size: 12.5px; color: var(--muted); }
.kit-sum b { font-size: 20px; font-variant-numeric: tabular-nums; }
.kit-sum small { color: var(--muted); font-size: 12px; }
.kit-sum .kit-price { border: 2px solid var(--primary); background: var(--surface); }
.kit-sum .kit-price input { height: 36px; font-size: 18px; font-weight: 700; text-align: right; }
.kit-more { margin-top: 10px; }
.kit-more summary { cursor: pointer; color: var(--primary); font-weight: 500; }
.split-info { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.split-info > div { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); min-width: 0; }
.split-info span, .split-info small { font-size: 12.5px; color: var(--muted); }
.split-info b { font-size: 16px; }
.split-form { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.cart-warnings .split-short { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
/* แผงแจ้งเตือนให้แบ่งเพิ่ม (มุมขวาบนหน้าขาย) */
.split-alerts { position: fixed; top: 16px; right: 16px; z-index: 60; width: min(380px, calc(100vw - 32px)); background: var(--surface);
  border: 2px solid var(--accent); border-radius: 14px; box-shadow: var(--shadow-lg); overflow: hidden; }
.split-alerts-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 14px; background: var(--warning-soft); color: var(--warning); font-weight: 600; }
.split-alert { display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 14px; border-top: 1px solid var(--border); }
.split-alert .sa-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.split-alert .sa-text small { color: var(--muted); font-size: 12.5px; }
/* สินค้าชุดในหน้าขาย: ส่วนประกอบใต้ชื่อในบิล / ผลค้นหา / หน้าต่างแก้รายการ */
.sr-name .sr-kind { margin-left: 6px; font-size: 11.5px; padding: 0 6px; vertical-align: 1px; }
.sr-name small.sr-parts { color: var(--primary); }
.bundle-parts { list-style: none; margin: 4px 0 0; padding: 4px 0 0 10px; border-left: 2px solid var(--primary-soft); font-size: 12.5px; color: var(--muted); line-height: 1.45; }
.bundle-parts li::before { content: '• '; color: var(--primary); }
.bundle-parts li b { color: var(--text); font-weight: 600; }
.bundle-parts li.short, .bundle-parts .bp-short { color: var(--danger); }
.bundle-parts .bp-short { margin-left: 4px; }
.field-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
/* ผลค้นหาหน้าขายกว้างพอให้อ่านชื่อ/ส่วนประกอบชุด (ล้นทับปุ่มข้างช่องค้นหาได้) */
.search-results { min-width: min(560px, calc(100vw - 32px)); }
.sr-name small.sr-parts { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.table tr.row-muted td { color: var(--muted); }
.promo-products { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
/* สารออกฤทธิ์ */
.toolbar .ing-filter { width: auto; min-width: 150px; }
.ing-targets { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 340px; font-size: 13px; }
.ing-box { margin-top: 4px; display: flex; flex-direction: column; gap: 6px; }
.ing-item { padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); font-size: 13px; line-height: 1.45; }
.ing-item b { font-size: 14px; }
.ing-item .tag { margin-left: 6px; font-size: 11.5px; }
.ing-item .muted { font-size: 12.5px; }
.sub.ing-sub { color: var(--primary); }
.sub.ing-ref { font-size: 11.5px; max-width: 220px; white-space: normal; }

/* โหมด cloud: จับคู่เครื่อง / รหัสจับคู่ */
.setup-tabs { margin-bottom: 16px; }
.code-input { font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: 1px; width: 100%; }
.pair-code { font: 600 34px/1.2 ui-monospace, Menlo, Consolas, monospace; letter-spacing: 4px; text-align: center; padding: 18px; margin: 10px 0;
  background: var(--primary-soft); color: var(--primary); border-radius: 12px; user-select: all; }
.badge.ok { background: var(--success-soft, var(--primary-soft)); color: var(--success, var(--primary)); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.table.compact td, .table.compact th { padding: 8px 10px; }
.table td.actions { white-space: nowrap; text-align: right; }
.table td.actions .btn + .btn { margin-left: 6px; }
.badge { white-space: nowrap; }

/* เว็บขายออนไลน์ */
.nav-item { position: relative; }
.nav-badge { position: absolute; top: 4px; right: 10px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11.5px; line-height: 18px; text-align: center; }
.totals-line { display: flex; gap: 18px; justify-content: flex-end; margin-top: 8px; font-size: 16px; }

/* โหมดออฟไลน์ (ร้านบน cloud) */
.offline-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 16px; background: var(--success-soft); color: var(--success); font-size: 14px; border-bottom: 1px solid var(--border); }
.offline-bar.on { background: var(--warning-soft); color: var(--warning); }
.offline-bar.warn { background: var(--danger-soft); color: var(--danger); }

/* license โปรแกรม (โหมดติดตั้งในร้าน) */
.license-panel .kv-grid { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; align-items: center; margin: 10px 0 12px; }
.license-panel textarea { width: 100%; font-size: 13px; word-break: break-all; }
.license-machine { font-size: 18px; letter-spacing: 1px; }
.license-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 16px; background: var(--warning-soft); color: var(--warning); font-size: 14px; border-bottom: 1px solid var(--border); }
.license-bar.info { background: var(--primary-soft); color: var(--primary); }

/* ค่าบริการร้านบน cloud */
.billing .kv-grid { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; align-items: center; margin: 4px 0 10px; }
.billing .segmented { flex-wrap: wrap; height: auto; }
.billing .segmented button { min-height: 40px; }
.billing-pay { display: flex; gap: 18px; flex-wrap: wrap; align-items: flex-start; margin: 14px 0; }
.billing-qr { background: #fff; border-radius: 12px; padding: 10px; line-height: 0; }
.billing-qr canvas { width: 220px; height: auto; }
.billing-pay > div:last-child { flex: 1; min-width: 240px; }
.billing-amount { font-size: 26px; color: var(--primary); }

/* ---------- รูปสินค้า (หน้าแก้ไขสินค้า แท็บ รูป/รายละเอียด) ---------- */
.pimg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; margin-bottom: 6px; }
.pimg-item, .pimg-add { position: relative; aspect-ratio: 1 / 1; border-radius: 12px; border: 1px solid #d5dedb; background: #f3f6f5; overflow: hidden; }
.pimg-item img { width: 100%; height: 100%; object-fit: contain; display: block; }
.pimg-item.main { border: 2px solid var(--primary); }
.pimg-tag { position: absolute; left: 6px; top: 6px; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: rgba(0, 0, 0, .55); color: #fff; }
.pimg-item.main .pimg-tag { background: var(--primary); }
.pimg-actions { position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; gap: 4px; padding: 8px 6px 6px; background: linear-gradient(transparent, rgba(0, 0, 0, .45)); opacity: 0; transition: opacity .15s; }
.pimg-item:hover .pimg-actions, .pimg-item:focus-within .pimg-actions { opacity: 1; }
@media (hover: none) { .pimg-actions { opacity: 1; } }
.pimg-actions .icon-btn { width: 30px; height: 30px; background: #fff; font-size: 18px; line-height: 1; }
.pimg-add { display: grid; place-content: center; justify-items: center; gap: 4px; border-style: dashed; border-width: 2px; color: var(--muted); cursor: pointer; text-align: center; font-size: 14px; }
.pimg-add:hover { border-color: var(--primary); color: var(--primary); }
.pimg-add.busy { opacity: .6; cursor: progress; }

/* ตกแต่งเว็บขายออนไลน์: แบนเนอร์ / รูปหมวด (public/js/pages/web-design.js) */
.btn.disabled { opacity: 0.45; pointer-events: none; }
.wb-list { display: grid; gap: 10px; }
.wb-item { display: grid; grid-template-columns: 1fr auto; gap: 8px 10px; align-items: center; padding: 10px; border: 1px solid var(--border); border-radius: 12px; }
.wb-item img { grid-column: 1 / -1; width: 100%; aspect-ratio: 8 / 3; object-fit: cover; border-radius: 8px; background: var(--surface-2); }
.wb-fields { display: grid; gap: 6px; }
.wb-actions { display: flex; flex-direction: column; gap: 2px; }
.wc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
.wc-item { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.wc-img { width: 100%; aspect-ratio: 1; border-radius: 16px; overflow: hidden; display: grid; place-items: center; background: var(--surface-2); font-size: 26px; color: var(--muted); }
.wc-img img { width: 100%; height: 100%; object-fit: cover; }
.wc-name { font-size: 14px; line-height: 1.3; }
.wc-actions { display: flex; gap: 4px; align-items: center; }
.color-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.color-row input[type=color] { width: 48px; height: 40px; padding: 2px; border-radius: 10px; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--border); cursor: pointer; padding: 0; }
.swatch.on { box-shadow: 0 0 0 2px var(--text); }

/* ตั้งค่า → ประเภทร้าน */
.type-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; margin-top: 10px; }
.type-card { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 12px 14px; border: 1px solid var(--border-strong); border-radius: 12px; background: var(--surface); font: inherit; color: var(--text); text-align: left; cursor: pointer; }
.type-card:hover { border-color: var(--primary); }
.type-card.active { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 1px var(--primary); }
.type-card .icon { color: var(--primary); }
.type-card small { color: var(--muted); font-size: 12.5px; line-height: 1.45; }
.feat-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 8px; }
.feat-row { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; background: var(--surface); }
.feat-row.on { border-color: var(--primary); background: var(--primary-soft); }
.feat-row.disabled { cursor: default; }
.feat-row input { margin-top: 3px; }
.feat-icon { color: var(--muted); margin-top: 1px; }
.feat-row.on .feat-icon { color: var(--primary); }
.feat-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.feat-text small { font-size: 12.5px; line-height: 1.45; color: var(--muted); }
.feat-text .feat-block { color: var(--warning); }
