:root { --sb-w: 248px; }
body { background: rgb(var(--bg)); }
body { font-feature-settings: "cv11", "ss01"; }
.lbl { font-size: .8rem; font-weight: 500; color: rgb(var(--ink-700)); }
.inp { height: 2.5rem; border: 1px solid rgb(var(--ink-200)); border-radius: .65rem; padding: 0 .8rem; font-size: .9rem; background: rgb(var(--surface)); color: rgb(var(--ink-900)); transition: border-color .15s, box-shadow .15s; }
textarea.inp { height: auto; padding: .6rem .8rem; }
.inp:focus { outline: none; border-color: rgb(var(--brand-500)); box-shadow: 0 0 0 3px rgb(var(--brand-500) / .15); }
.inp::placeholder { color: rgb(var(--ink-400)); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; height: 2.5rem; padding: 0 1rem; border-radius: .65rem; font-size: .9rem; font-weight: 500; transition: background .15s, border-color .15s, opacity .15s; white-space: nowrap; }
.btn-pri { background: rgb(var(--btn)); color: #fff; } .btn-pri:hover { background: rgb(var(--btn-h)); }
.btn-sec { background: rgb(var(--surface)); border: 1px solid rgb(var(--ink-200)); color: rgb(var(--ink-900)); } .btn-sec:hover { background: rgb(var(--ink-50)); border-color: rgb(var(--ink-300)); }
.btn-ghost { color: rgb(var(--ink-700)); } .btn-ghost:hover { background: rgb(var(--ink-100)); }
.btn-sm { height: 2rem; padding: 0 .7rem; font-size: .8rem; border-radius: .55rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.card { background: rgb(var(--surface)); border: 1px solid rgb(var(--line)); border-radius: 1rem; box-shadow: 0 1px 2px rgba(15,23,42,.04); }
.card-h { display: flex; align-items: center; gap: .75rem; padding: 1rem 1.25rem; border-bottom: 1px solid rgb(var(--ink-100)); }
.card-t { font-weight: 600; font-size: .95rem; }
.chip { display: inline-flex; align-items: center; gap: .3rem; padding: .1rem .55rem; border-radius: 999px; font-size: .72rem; font-weight: 500; }
.num { font-variant-numeric: tabular-nums; }

.tbl { width: 100%; font-size: .85rem; }
.tbl th { text-align: left; font-weight: 500; font-size: .75rem; color: rgb(var(--ink-500)); padding: .6rem 1rem; background: rgb(var(--ink-50)); border-bottom: 1px solid rgb(var(--ink-100)); white-space: nowrap; }
.tbl td { padding: .7rem 1rem; border-bottom: 1px solid rgb(var(--ink-100) / .7); }
/* หัวตารางค้างไว้เมื่อเลื่อนภายในกล่องที่เลื่อนได้ (รายการสินค้า ใบโอน ฯลฯ) */
.tbl thead th { position: sticky; top: 0; z-index: 2; box-shadow: 0 1px 0 rgb(var(--ink-100)); }
.tbl th.text-right, .tbl td.text-right { text-align: right; } .tbl th.text-center, .tbl td.text-center { text-align: center; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: rgb(var(--ink-50) / .7); }

/* sidebar */
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sb-w); background: rgb(var(--surface)); border-right: 1px solid rgb(var(--line)); display: flex; flex-direction: column; z-index: 40; transition: width .2s, transform .2s; }
.main { margin-left: var(--sb-w); transition: margin .2s; min-width: 0; }
.nav-group-t { font-size: .68rem; font-weight: 600; letter-spacing: .04em; color: rgb(var(--ink-400)); text-transform: uppercase; padding: 0 .75rem .4rem; }
.nav-item { display: flex; align-items: center; gap: .7rem; height: 2.35rem; padding: 0 .75rem; border-radius: .6rem; font-size: .875rem; color: rgb(var(--ink-700)); cursor: pointer; white-space: nowrap; }
.nav-item:hover { background: rgb(var(--ink-100)); }
.nav-item.on { background: rgb(var(--brand-50)); color: rgb(var(--brand-700)); font-weight: 600; }
.nav-item .ext { margin-left: auto; font-size: .6rem; color: rgb(var(--ink-300)); }
body.sb-mini { --sb-w: 76px; }
.nav-gt { cursor: pointer; padding-top: .1rem; text-transform: inherit; letter-spacing: inherit; font: inherit; color: inherit; }
.nav-pin { width: 1.3rem; height: 1.3rem; border-radius: .35rem; color: rgb(var(--ink-300)); opacity: 0; transition: opacity .15s; transform: rotate(45deg); }
.nav-g:hover .nav-pin { opacity: 1; }
.nav-pin:hover { background: rgb(var(--ink-100)); color: rgb(var(--ink-600)); }
.nav-g.pinned .nav-pin { opacity: 1; color: rgb(var(--brand-600)); transform: none; }
.nav-g.pinned .nav-gc { display: none; }
.nav-g.pinned .nav-gt { cursor: default; }
@media (hover: none) { .nav-pin { opacity: .6; } }
.nav-gn { font-size: .62rem; font-weight: 600; color: rgb(var(--ink-400)); background: rgb(var(--ink-100)); border-radius: 999px; padding: 0 .4rem; line-height: 1.1rem; }
.nav-gc { transition: transform .15s; }
.nav-g.shut .nav-gc { transform: rotate(-90deg); }
.nav-g.shut .nav-gi { display: none; }
#nav.nav-search .nav-g .nav-gi { display: block; }
#nav .nav-hide { display: none !important; }
#nav.nav-search .nav-gc, #nav.nav-search .nav-gn, #nav.nav-search .nav-pin { visibility: hidden; }
body.sb-mini .nav-g.shut .nav-gi { display: block; }
body.sb-mini .sb-label, body.sb-mini .nav-group-t, body.sb-mini .nav-item .ext { display: none; }
body.sb-mini .nav-item { justify-content: center; padding: 0; }
body.sb-mini #sbCollapse i { transform: rotate(180deg); }
@media (max-width: 1023px) {
  .sidebar { transform: translateX(-100%); width: 272px; }
  body.sb-open .sidebar { transform: none; }
  .main { margin-left: 0; }
}
.topbar { position: sticky; top: 0; z-index: 20; height: 4rem; display: flex; align-items: center; gap: .75rem; padding: 0 1.25rem; background: rgb(var(--bg) / .85); backdrop-filter: blur(10px); border-bottom: 1px solid rgb(var(--line)); }
.branch-pill { display: flex; align-items: center; gap: .5rem; height: 2.25rem; padding: 0 .75rem; border: 1px solid rgb(var(--ink-200)); background: rgb(var(--surface)); border-radius: 999px; cursor: pointer; }
.menu-item { display: flex; width: 100%; align-items: center; gap: .6rem; padding: .5rem .75rem; border-radius: .5rem; font-size: .875rem; text-align: left; }
.menu-item:hover { background: rgb(var(--ink-100)); }

/* KPI */
.kpi { padding: 1.1rem 1.25rem; }
.kpi-l { font-size: .78rem; color: rgb(var(--ink-500)); display: flex; align-items: center; gap: .5rem; }
.kpi-v { font-size: 1.65rem; font-weight: 600; letter-spacing: -.01em; margin-top: .35rem; }
.kpi-s { font-size: .75rem; color: rgb(var(--ink-400)); margin-top: .15rem; }
.kpi-ic { width: 2rem; height: 2rem; border-radius: .6rem; display: grid; place-items: center; font-size: .85rem; }

.seg { display: inline-flex; background: rgb(var(--ink-100)); border-radius: .65rem; padding: .2rem; }
.seg button { height: 1.9rem; padding: 0 .8rem; border-radius: .5rem; font-size: .8rem; color: rgb(var(--ink-500)); }
.seg button.on { background: rgb(var(--surface)); color: rgb(var(--ink-900)); font-weight: 500; box-shadow: 0 1px 2px rgba(15,23,42,.08); }
.skel { background: linear-gradient(90deg, rgb(var(--ink-100)) 25%, rgb(var(--ink-200)) 37%, rgb(var(--ink-100)) 63%); background-size: 400% 100%; animation: sk 1.4s ease infinite; border-radius: .4rem; }
@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.fade-in { animation: fi .25s ease both; } @keyframes fi { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.swal2-popup { border-radius: 1rem !important; font-family: inherit !important; }
.swal2-confirm { background: rgb(var(--btn)) !important; border-radius: .6rem !important; }
.swal2-cancel { border-radius: .6rem !important; }
.line-clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
@media print {
  body.printing-receipt * { visibility: hidden !important; }
  body.printing-receipt #posPrint, body.printing-receipt #posPrint * { visibility: visible !important; }
  body.printing-receipt #posPrint { display: block !important; position: absolute; left: 0; top: 0; width: 100%; }
  @page { margin: 4mm; }
}
#printZone { display: none; }
@media print {
  /* ซ่อนหน้าจอทั้งหมดแบบไม่กินพื้นที่ (เดิมซ่อนแต่ยังกินความสูง → พิมพ์ออกหลายแผ่นเปล่า) */
  body.printing > *:not(#printZone) { display: none !important; }
  body.printing #printZone { display: block !important; position: static; width: 100%; }
  html, body.printing { height: auto !important; min-height: 0 !important; overflow: visible !important; background: #fff !important; }
}

/* ---------- ธีมพื้นมีสี: กล่องสีขาวให้ใช้สีพื้นของธีม (เฉพาะบนจอ) ---------- */
@media screen { .tn .bg-white { background-color: rgb(var(--surface)) !important; } .tn .bg-white\/80, .tn .bg-white\/90 { background-color: rgb(var(--surface) / .9) !important; } .tn .swal2-popup { background: rgb(var(--surface)) !important; } }
/* ---------- ธีมมืด (เฉพาะบนจอ) ---------- */
@media screen {
.dk .bg-white { background-color: rgb(var(--surface)) !important; }
.dk .hover\:bg-white:hover { background-color: rgb(var(--ink-100)) !important; }
.dk .bg-white\/80, .dk .bg-white\/90 { background-color: rgb(var(--surface) / .9) !important; }
.dk .shadow-pop, .dk .shadow-lg, .dk .shadow-2xl { box-shadow: 0 12px 32px -8px rgba(0,0,0,.6) !important; }
.dk .card { box-shadow: none; }
.dk .swal2-popup { background: rgb(var(--surface)) !important; color: rgb(var(--ink-700)) !important; border: 1px solid rgb(var(--line)); }
.dk .swal2-title { color: rgb(var(--ink-900)) !important; }
.dk .swal2-html-container, .dk .swal2-validation-message { color: rgb(var(--ink-700)) !important; }
.dk .swal2-validation-message { background: rgb(var(--ink-100)) !important; }
.dk .swal2-input, .dk .swal2-textarea, .dk .swal2-select { background: rgb(var(--ink-50)) !important; color: rgb(var(--ink-900)) !important; border-color: rgb(var(--ink-200)) !important; }
.dk .swal2-cancel, .dk .swal2-deny { opacity: .9; }
.dk .swal2-close { color: rgb(var(--ink-400)) !important; }
.dk .swal2-container.swal2-backdrop-show { background: rgba(0,0,0,.6) !important; }
.dk img:not([src*="svg"]) { filter: brightness(.92); }
.dk ::-webkit-scrollbar { width: 10px; height: 10px; } .dk ::-webkit-scrollbar-thumb { background: rgb(var(--ink-200)); border-radius: 8px; } .dk ::-webkit-scrollbar-track { background: transparent; }
}
/* พิมพ์เอกสารเป็นพื้นขาวเสมอ */
@media print {
  :root { --ink-900: 15 23 42 !important; --ink-700: 51 65 85 !important; --ink-500: 100 116 139 !important; --ink-400: 148 163 184 !important; --ink-300: 203 213 225 !important; --ink-200: 226 232 240 !important; --ink-100: 241 245 249 !important; --ink-50: 248 250 252 !important;
    --surface: 255 255 255 !important; --bg: 255 255 255 !important; --line: 237 240 243 !important; --brand-50: 236 253 247 !important; --brand-100: 209 250 236 !important; --brand-700: 11 124 95 !important; --brand-600: 12 154 116 !important; color-scheme: light !important; }
  body { background: #fff !important; color: #0f172a !important; }
}

/* ---------- มือถือ / แอป ---------- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; display: flex; background: rgb(var(--surface) / .96); backdrop-filter: blur(10px); border-top: 1px solid rgb(var(--line)); padding-bottom: env(safe-area-inset-bottom); }
.tabbar a, .tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: 3.5rem; font-size: .66rem; color: rgb(var(--ink-500)); min-width: 0; }
.tabbar i { font-size: 1.15rem; }
.tabbar span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
.tabbar .on { color: rgb(var(--brand-600)); font-weight: 600; }
@media (max-width: 1023px) {
  #page { padding-bottom: calc(5rem + env(safe-area-inset-bottom)); }
  .topbar { padding-top: env(safe-area-inset-top); height: calc(3.5rem + env(safe-area-inset-top)); padding-left: .6rem; padding-right: .6rem; gap: .4rem; }
  #pageTitle { font-size: 1rem; }
  .sidebar { padding-top: env(safe-area-inset-top); }
}
@media (max-width: 767px) {
  /* ตารางกว้าง: เลื่อนซ้ายขวาในกล่องแทนการล้นจอ */
  table.tbl { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tbl th, .tbl td { padding: .55rem .7rem; }
  .swal2-popup { width: calc(100vw - 1.5rem) !important; max-width: 100% !important; }
  .inp { font-size: 16px; } /* กันจอซูมเองตอนพิมพ์บน iPhone */
  .card-h { flex-wrap: wrap; }
  #page .grid > * { min-width: 0; }
}
body.standalone .topbar { background: rgb(var(--bg)); }

/* ป้ายจำนวนรอยืนยัน */
.req-badge { min-width: 1.15rem; height: 1.15rem; padding: 0 .3rem; border-radius: 999px; background: #f59e0b; color: #fff; font-size: .68rem; font-weight: 700; display: inline-grid; place-items: center; margin-left: .25rem; line-height: 1; }
#tabBar a { position: relative; } #tabBar .req-badge { position: absolute; top: .3rem; right: calc(50% - 1.3rem); margin: 0; }
[data-ql] .req-badge, #nav .req-badge { animation: reqPulse 2s ease-in-out infinite; } @keyframes reqPulse { 50% { transform: scale(1.12); } }
