/* =====================================================================
   Tra cứu vật tư - giao diện
   Tùy chỉnh (bảng Tùy chỉnh giao diện) gắn lên <html>:
     data-theme="light|dark" (không có = theo máy), data-accent, data-fsz,
     data-density="full|compact", --fs (hệ số cỡ chữ)
   ===================================================================== */

/* ---------- Màu chủ đạo ---------- */
:root {
  --fs: 1;
  --a: #0f5fa8; --a-press: #0b4a84; --a-rgb: 15, 95, 168;
  --a-d: #2f81d7; --a-d-press: #2569b3; --a-d-rgb: 47, 129, 215; --a-lt: #6cb6ff;
}
:root[data-accent="teal"] {
  --a: #0f766e; --a-press: #0b5c56; --a-rgb: 15, 118, 110;
  --a-d: #0d9488; --a-d-press: #0b7a70; --a-d-rgb: 13, 148, 136; --a-lt: #5eead4;
}
:root[data-accent="indigo"] {
  --a: #4338ca; --a-press: #3730a3; --a-rgb: 67, 56, 202;
  --a-d: #6366f1; --a-d-press: #4f46e5; --a-d-rgb: 99, 102, 241; --a-lt: #a5b4fc;
}
:root[data-accent="violet"] {
  --a: #6d28d9; --a-press: #5b21b6; --a-rgb: 109, 40, 217;
  --a-d: #7c3aed; --a-d-press: #6d28d9; --a-d-rgb: 124, 58, 237; --a-lt: #c4b5fd;
}
:root[data-accent="slate"] {
  --a: #334155; --a-press: #1e293b; --a-rgb: 51, 65, 85;
  --a-d: #64748b; --a-d-press: #475569; --a-d-rgb: 100, 116, 139; --a-lt: #cbd5e1;
}

/* ---------- Giao diện sáng ---------- */
:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --sunken: #f6f7f9;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e6e9ef;
  --col-line: #dbe0e8;
  --sub-bg: rgba(var(--a-rgb), .08);
  --sub-line: rgba(var(--a-rgb), .28);
  --sub-text: var(--a);
  --field: #ffffff;
  --field-line: #cfd6df;
  --primary: var(--a);
  --primary-press: var(--a-press);
  --on-primary: #ffffff;
  --accent-text: var(--a);
  --soft: rgba(var(--a-rgb), .09);
  --soft-press: rgba(var(--a-rgb), .16);
  --focus: rgba(var(--a-rgb), .22);
  --primary-shadow: 0 6px 16px -8px rgba(var(--a-rgb), .7);
  --loc: var(--a);
  --ok: #15803d;
  --ok-bg: #e8f6ee;
  --danger: #c4320a;
  --danger-bg: #fff1ec;
  --warn: #8a5a00;
  --warn-bg: #fff6db;
  --tabs-bg: #e6e9ef;
  --tab-active: #ffffff;
  --mark: #ffe58a;
  --scrim: rgba(15, 23, 42, .45);
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .06);
  --shadow-seg: 0 1px 3px rgba(15, 23, 42, .14);
  --shadow-lg: 0 -10px 40px rgba(15, 23, 42, .2);
  --radius: 16px;
  color-scheme: light;
}

/* ---------- Giao diện tối (chọn "Tối", hoặc "Tự động" khi máy đang tối) ---------- */
:root[data-theme="dark"] {
  --bg: #0b0f14; --surface: #141a21; --sunken: #10151b; --text: #e6edf3; --muted: #93a0ae;
  --line: #252d37; --field: #0e1318; --field-line: #36404c; --col-line: #2e3743;
  --sub-bg: rgba(var(--a-d-rgb), .15); --sub-line: rgba(var(--a-d-rgb), .4); --sub-text: var(--a-lt);
  --primary: var(--a-d); --primary-press: var(--a-d-press); --on-primary: #ffffff;
  --accent-text: var(--a-lt); --soft: rgba(var(--a-d-rgb), .16); --soft-press: rgba(var(--a-d-rgb), .26);
  --focus: rgba(var(--a-d-rgb), .38); --primary-shadow: none; --loc: var(--a-lt);
  --ok: #56d364; --ok-bg: #12261a; --danger: #ff8b6b; --danger-bg: #2d1712;
  --warn: #e3b341; --warn-bg: #2b2210; --tabs-bg: #1a2028; --tab-active: #2c343f; --mark: #6b5300;
  --scrim: rgba(0, 0, 0, .6); --shadow: none; --shadow-seg: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 -10px 40px rgba(0, 0, 0, .55);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0f14; --surface: #141a21; --sunken: #10151b; --text: #e6edf3; --muted: #93a0ae;
    --line: #252d37; --field: #0e1318; --field-line: #36404c; --col-line: #2e3743;
    --sub-bg: rgba(var(--a-d-rgb), .15); --sub-line: rgba(var(--a-d-rgb), .4); --sub-text: var(--a-lt);
    --primary: var(--a-d); --primary-press: var(--a-d-press); --on-primary: #ffffff;
    --accent-text: var(--a-lt); --soft: rgba(var(--a-d-rgb), .16); --soft-press: rgba(var(--a-d-rgb), .26);
    --focus: rgba(var(--a-d-rgb), .38); --primary-shadow: none; --loc: var(--a-lt);
    --ok: #56d364; --ok-bg: #12261a; --danger: #ff8b6b; --danger-bg: #2d1712;
    --warn: #e3b341; --warn-bg: #2b2210; --tabs-bg: #1a2028; --tab-active: #2c343f; --mark: #6b5300;
    --scrim: rgba(0, 0, 0, .6); --shadow: none; --shadow-seg: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 -10px 40px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}

/* ---------- Nền tảng ---------- */
* { box-sizing: border-box; }

html {
  font-size: calc(16px * var(--fs));
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
body.noscroll { overflow: hidden; }

button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

[hidden] { display: none !important; }

.app {
  max-width: 560px;
  margin: 0 auto;
  padding:
    max(12px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(28px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

.label {
  font-size: .8125rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- Màn hình mật khẩu ---------- */
.lock {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding:
    max(56px, calc(env(safe-area-inset-top) + 36px))
    max(16px, env(safe-area-inset-right))
    24px
    max(16px, env(safe-area-inset-left));
}
.lock-card {
  width: 100%;
  max-width: 400px;
  padding: 28px 22px 24px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}
.lock-icon { display: block; margin: 0 auto 14px; border-radius: 18px; box-shadow: var(--shadow); }
.lock-card h1 { margin: 0 0 4px; font-size: 1.5rem; font-weight: 800; letter-spacing: -.015em; }
.lock-sub { margin: 0 0 20px; color: var(--muted); font-size: 1rem; }
.lock-card input {
  width: 100%;
  height: 62px;
  padding: 0 18px;
  font-size: max(16px, 1.75rem);
  font-weight: 700;
  letter-spacing: .3em;
  text-align: center;
  color: var(--text);
  background: var(--field);
  border: 1.5px solid var(--field-line);
  border-radius: var(--radius);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.lock-card input::placeholder { font-size: max(16px, 1.125rem); font-weight: 400; letter-spacing: 0; color: var(--muted); }
.lock-card input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--focus); }
.lock-msg { min-height: 24px; margin: 10px 0 8px; color: var(--danger); font-size: 1rem; font-weight: 600; }
.lock-card .go { width: 100%; }

/* ---------- Đầu trang ---------- */
.top { display: flex; align-items: center; gap: 12px; margin: 2px 0 8px; }
.top-icon { flex: none; width: 40px; height: 40px; border-radius: 11px; box-shadow: var(--shadow); }
.top-text { flex: 1; min-width: 0; }
.top h1 { margin: 0; font-size: 1.25rem; font-weight: 800; letter-spacing: -.015em; line-height: 1.2; }
.data-info {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 1px;
  font-size: .8125rem;
  line-height: 1.3;
  color: var(--muted);
}
.data-info::before { content: ""; flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.data-info.err::before { background: var(--warn); }
.data-info:empty::before { display: none; }

.icon-btn {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { background: var(--sunken); }

.warn {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: .875rem;
}

/* ---------- Thanh tab (dính trên cùng khi cuộn) ---------- */
.tabbar {
  position: sticky;
  top: 0;
  z-index: 20;
  margin: 0 calc(-1 * max(16px, env(safe-area-inset-right))) 12px calc(-1 * max(16px, env(safe-area-inset-left)));
  padding: 4px max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
  background: var(--bg);
  transition: box-shadow .15s;
}
.tabbar.stuck { box-shadow: 0 8px 14px -10px rgba(15, 23, 42, .35); }

.tabs {
  display: flex;
  gap: 3px;
  padding: 4px;
  border-radius: 14px;
  background: var(--tabs-bg);
}
.tab {
  flex: 1 1 0;
  min-width: 0;
  min-height: 54px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 5px 1px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  font-size: min(.8125rem, 3.15vw);
  letter-spacing: -.01em;
  font-weight: 700;
  line-height: 1.1;
  white-space: nowrap;
}
.tab svg { flex: none; width: 21px; height: 21px; }
.tab.active { background: var(--tab-active); color: var(--text); box-shadow: var(--shadow-seg); }
.tab.active svg { color: var(--accent-text); }
/* Cuộn xuống xa: ô tab đang mở đổi thành nút "Lên đầu" (thay cho nút tròn nổi che số liệu) */
.tab-t { display: block; }
.tab-up { display: none; }
.tabbar.up .tab.active > svg, .tabbar.up .tab.active > .tab-t { display: none; }
.tabbar.up .tab.active > .tab-up { display: contents; }
.tabbar.up .tab.active { background: var(--primary); color: var(--on-primary); box-shadow: 0 4px 12px -4px rgba(15, 23, 42, .45); }
.tabbar.up .tab.active svg { color: var(--on-primary); }

/* ---------- Ô nhập ---------- */
.field { position: relative; }
.field input {
  width: 100%;
  height: 62px;
  padding: 0 60px 0 18px;
  font-size: max(16px, 1.5rem);   /* >= 16px: iOS không tự phóng to khi chạm vào ô */
  font-weight: 650;
  letter-spacing: .03em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--field);
  border: 1.5px solid var(--field-line);
  border-radius: var(--radius);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.field input::placeholder { color: var(--muted); font-weight: 400; letter-spacing: 0; }
.field input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--focus); }
.field-hint { margin: 8px 4px 0; font-size: .875rem; color: var(--muted); }
.field-hint b { color: var(--text); font-weight: 600; }

.clear {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 50px;
  height: 50px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
}
.clear svg { width: 28px; height: 28px; }
.clear:active { color: var(--text); }

.actions { display: flex; gap: 10px; margin-top: 12px; }

.go {
  flex: 1;
  height: 58px;
  border: 0;
  border-radius: var(--radius);
  background: var(--primary);
  color: var(--on-primary);
  font-size: 1.25rem;
  font-weight: 750;
  letter-spacing: .01em;
  box-shadow: var(--primary-shadow);
}
.go:active { background: var(--primary-press); }
.go:disabled { opacity: .7; }

.kb {
  flex: 0 0 76px;
  height: 58px;
  border: 1.5px solid var(--field-line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 1.0625rem;
  font-weight: 700;
}
.kb:active { background: var(--sunken); }

/* ---------- Đếm số đã gõ (mã 9 số, chia nhóm 3-3-3) ---------- */
.meter { display: flex; align-items: center; gap: 10px; margin: 9px 4px 0; font-size: .875rem; color: var(--muted); }
.meter-bar { display: flex; flex: none; gap: 3px; }
.meter-bar i { width: .75rem; height: .4rem; border-radius: 3px; background: var(--field-line); transition: background .12s; }
.meter-bar i:nth-child(3), .meter-bar i:nth-child(6) { margin-right: 5px; }
.meter-bar i.on { background: var(--primary); }
.meter-text { min-width: 0; line-height: 1.3; }
.meter-text b { color: var(--text); font-weight: 800; font-variant-numeric: tabular-nums; }
.meter.full .meter-bar i { background: var(--ok); }
.meter.full .meter-text, .meter.full .meter-text b { color: var(--ok); font-weight: 700; }
.meter.over .meter-bar i { background: var(--danger); }
.meter.over .meter-text, .meter.over .meter-text b { color: var(--danger); font-weight: 700; }
.meter.bad .meter-bar i.on { background: var(--warn); }
.meter.bad .meter-text { color: var(--warn); font-weight: 650; }

/* ---------- Gợi ý mã khi đang gõ ---------- */
.suggest {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: pop .14s ease-out;
}
.sg-head { padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--sunken); font-size: .8125rem; color: var(--muted); }
.sg-item {
  display: block;
  width: 100%;
  padding: 10px 14px;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  text-align: left;
}
.sg-head + .sg-item { border-top: 0; }
.sg-item:active, .sg-item.active { background: var(--soft); }
.sg-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.sg-code { min-width: 0; font-size: 1.125rem; font-weight: 650; letter-spacing: .03em; font-variant-numeric: tabular-nums; }
.sg-code mark { padding: 0 1px; border-radius: 4px; background: var(--soft-press); color: var(--accent-text); font-weight: 800; }
.sg-exact {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--ok-bg);
  color: var(--ok);
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: 0;
  vertical-align: 2px;
}
.sg-qty { flex: none; font-size: 1rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.sg-qty.zero { color: var(--danger); }
.sg-qty small { margin-left: 4px; font-size: .8125rem; font-weight: 600; color: var(--muted); }
.sg-sub { display: block; margin-top: 2px; font-size: .875rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sg-loc { color: var(--loc); font-weight: 700; }
.sg-empty { padding: 12px 14px; font-size: .9375rem; color: var(--muted); }
@media (prefers-reduced-motion: reduce) { .suggest { animation: none; } }

/* ---------- Kết quả ---------- */
.result { margin-top: 16px; }
.result > * { animation: pop .18s ease-out; }
@keyframes pop {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .result > * { animation: none; }
}
.result.busy { opacity: .5; pointer-events: none; transition: opacity .15s; }

.card {
  padding: 16px 18px 4px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.code-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.code {
  padding: 3px 10px;
  border-radius: 9px;
  background: var(--soft);
  color: var(--accent-text);
  font-size: 1.25rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
}
.name { margin: 10px 0 12px; font-size: 1.0625rem; font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }

/* Định khu | Tồn kho cạnh nhau */
.hero-stats { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); border-top: 1px solid var(--line); }
.hstat { min-width: 0; padding: 14px 0 16px; }
.hstat + .hstat { padding-left: 16px; border-left: 1px solid var(--line); }
.hstat:first-child { padding-right: 12px; }
.hstat .value {
  display: block;
  margin-top: 4px;
  font-size: 2.125rem;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -.01em;
  overflow-wrap: anywhere;
}
.hstat.loc .value { color: var(--loc); }
.hstat.qty .value { font-variant-numeric: tabular-nums; }
.hstat .unit { margin-left: 6px; font-size: 1rem; font-weight: 650; letter-spacing: 0; color: var(--muted); }
.hstat.qty.zero .value { color: var(--danger); }
.hstat .value.empty { font-size: 1.125rem; font-weight: 500; font-style: italic; color: var(--muted); }

/* Nhiều định khu */
.multi-note { padding: 10px 0 4px; border-top: 1px solid var(--line); font-size: .9375rem; color: var(--muted); }
.rows-head, .row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.rows-head { padding: 6px 0; }
.row { padding: 12px 0; border-top: 1px solid var(--line); }
.row .loc-v { font-size: 1.625rem; font-weight: 800; color: var(--loc); overflow-wrap: anywhere; }
.row .loc-v.empty { font-size: 1.125rem; font-weight: 500; font-style: italic; color: var(--muted); }
.row .qty-v { font-size: 1.625rem; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.row .qty-v.zero { color: var(--danger); }
.row .qty-v .unit { margin-left: 6px; font-size: .9375rem; font-weight: 600; color: var(--muted); }
.row.total .loc-v { font-size: 1.0625rem; font-weight: 700; color: var(--text); }

.card-foot { padding: 12px 0 14px; border-top: 1px solid var(--line); }

/* Thông báo */
.notice { padding: 22px 18px; border-radius: 20px; text-align: center; }
.notice svg { width: 44px; height: 44px; margin-bottom: 6px; }
.notice h2 { margin: 0 0 6px; font-size: 1.375rem; font-weight: 800; }
.notice p { margin: 0; font-size: 1.0625rem; color: var(--text); overflow-wrap: anywhere; }
.notice.notfound, .notice.error { background: var(--danger-bg); color: var(--danger); }
.notice.hint { padding: 14px 18px; background: var(--warn-bg); color: var(--warn); }
.notice.hint h2 { margin: 0; font-size: 1.125rem; font-weight: 700; }

.loading { margin: 14px 4px; color: var(--muted); font-size: .9375rem; }
.empty-p { margin: 4px 0 12px; color: var(--muted); font-size: .9375rem; font-style: italic; }
.result .warn, .detail .warn { margin: 10px 0 0; }

/* ---------- Nút phụ, chip ---------- */
.more-btn {
  display: block;
  width: 100%;
  min-height: 50px;
  padding: 8px 14px;
  border: 0;
  border-radius: 14px;
  background: var(--soft);
  color: var(--accent-text);
  font-size: 1.0625rem;
  font-weight: 700;
}
.more-btn:active { background: var(--soft-press); }
.more-btn:disabled { opacity: .7; }
.groups + .more-btn { margin: 12px 0 4px; }
.more-btn.older { min-height: 44px; margin: 2px 0 10px; font-size: 1rem; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip {
  flex: none;
  height: 40px;
  padding: 0 14px;
  border: 1.5px solid var(--field-line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: .9375rem;
  font-weight: 650;
  white-space: nowrap;
}
.chip:active { background: var(--sunken); }
.chip.active { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }

/* Nhóm nút dạng "segmented" (loại hàng) */
.chips.seg { flex-wrap: nowrap; gap: 3px; padding: 3px; border-radius: 12px; background: var(--tabs-bg); }
.chips.seg .chip {
  flex: 1 1 auto;
  min-width: 0;
  height: auto;
  min-height: 38px;
  padding: 3px 4px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: min(.9375rem, 4.2vw);
  font-weight: 700;
  line-height: 1.15;
  white-space: normal;
}
.chips.seg .chip.active { background: var(--tab-active); color: var(--text); box-shadow: var(--shadow-seg); }

/* Hàng chip cuộn ngang (chọn nhanh ngày) */
.chips.scroll {
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  margin-left: calc(-1 * max(16px, env(safe-area-inset-left)));
  margin-right: calc(-1 * max(16px, env(safe-area-inset-right)));
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
}
.chips.scroll::-webkit-scrollbar { display: none; }
.chips.mini { margin-top: 0; gap: 6px; }
.chips.mini .chip { height: 34px; padding: 0 12px; font-size: .875rem; }

/* ---------- Tìm theo tên ---------- */
.list-head { margin: 0 4px 8px; font-size: .875rem; color: var(--muted); }
.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: block;
  width: 100%;
  padding: 12px 14px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.item:active { background: var(--sunken); }
.item-name { display: block; font-size: 1.0625rem; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.item-name mark { padding: 0 1px; border-radius: 3px; background: var(--mark); color: inherit; }
.item-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; margin-top: 6px; }
.item-meta .k { margin-right: 4px; font-size: .75rem; font-weight: 700; letter-spacing: .04em; color: var(--muted); }
.item-code { font-size: .9375rem; font-variant-numeric: tabular-nums; color: var(--muted); }
.item-loc { font-size: 1.0625rem; font-weight: 800; color: var(--loc); overflow-wrap: anywhere; }
.item-loc.empty { font-size: .9375rem; font-weight: 500; font-style: italic; color: var(--muted); }
.item-qty { margin-left: auto; font-size: 1.0625rem; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.item-qty.zero { color: var(--danger); }
.item-qty .unit { margin-left: 4px; font-size: .875rem; font-weight: 600; color: var(--muted); }

/* ---------- Chi tiết giao dịch ---------- */
.detail { margin-top: 18px; scroll-margin-top: calc(var(--tabbar-h, 0px) + 8px); }
.detail-head h2 { margin: 0 2px; font-size: 1.25rem; font-weight: 800; letter-spacing: -.01em; }
.detail-head .chips { margin-top: 10px; }
.detail-body .list-head { margin: 10px 4px 0; }

.sgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0 0; }
.tile {
  position: relative;
  min-width: 0;
  padding: 10px 12px 10px 15px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.tile::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--field-line); }
.tile .label { font-size: .75rem; }
.tile .v {
  display: block;
  margin-top: 1px;
  font-size: 1.4375rem;
  font-weight: 800;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.tile .unit { margin-left: 6px; font-size: .875rem; font-weight: 600; color: var(--muted); }
.tile.in::before { background: var(--ok); }
.tile.out::before { background: var(--danger); }
.tile.end::before { background: var(--primary); }
.tile.in .v { color: var(--ok); }
.tile.out .v { color: var(--danger); }
.tile.end .v { color: var(--accent-text); }
.tile.neg .v { color: var(--danger); }
.tile.zero .v { color: var(--muted); }

.dsec {
  margin-top: 12px;
  padding: 12px 14px 4px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.dsec-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 10px; padding-bottom: 8px; }
.dsec-head h3 { margin: 0; font-size: 1.0625rem; font-weight: 800; }
.dsec-note { font-size: .875rem; color: var(--muted); }
.compact-hint { display: none; margin: -4px 0 8px; font-size: .8125rem; color: var(--muted); }

/* Bảng Ngày | Nhập | Xuất | Tồn - có vạch dọc chia cột */
.tx-grid {
  display: grid;
  grid-template-columns: 3.5rem repeat(3, minmax(0, 1fr));
  align-items: stretch;
}
.tx-grid > * { min-width: 0; padding: 0 .5rem; }
.tx-grid > :first-child { padding-left: 0; }
.tx-grid > :last-child { padding-right: 0; }
.tx-grid > * + * { border-left: 1px solid var(--col-line); }
.tx-head {
  position: sticky;
  top: var(--tabbar-h, 0px);
  z-index: 2;
  margin: 0 -14px;
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1.5px solid var(--col-line);
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}
.tx-head > * { padding-top: 8px; padding-bottom: 8px; }
.c-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.c-date { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Đầu tháng: tên tháng + số giao dịch */
.tx-month {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin: 0 -14px;
  padding: 8px 14px;
  background: var(--sunken);
  border-bottom: 1px solid var(--line);
}
.m-name { font-size: .875rem; font-weight: 800; letter-spacing: .01em; }
.m-count { font-size: .8125rem; color: var(--muted); }

.tx { border-bottom: 1px solid var(--line); }
.tx > .tx-grid { font-size: 1rem; }
.tx > .tx-grid > * { padding-top: 9px; padding-bottom: 9px; }
.q-in { color: var(--ok); font-weight: 750; font-variant-numeric: tabular-nums; }
.q-out { color: var(--danger); font-weight: 750; font-variant-numeric: tabular-nums; }
.c-ton { font-weight: 800; }
.c-ton.neg { color: var(--danger); }
.tx-info { margin-top: -5px; padding-bottom: 9px; font-size: .875rem; line-height: 1.35; color: var(--muted); overflow-wrap: anywhere; }
.tx-info b { color: var(--text); font-weight: 650; }

/* Dòng tổng cuối tháng (tô màu): Tổng nhập | Tổng xuất | Còn tồn, mỗi số nằm đúng cột */
.tx-subtotal {
  margin: 0 -14px;
  padding: 0 14px;
  background: var(--sub-bg);
  border-top: 1.5px solid var(--sub-line);
  border-bottom: 1.5px solid var(--sub-line);
}
.txs > .tx-subtotal:last-child { margin-bottom: -4px; border-bottom: 0; border-radius: 0 0 15px 15px; }
.tx-subtotal > * { padding-top: 7px; padding-bottom: 8px; border-left-color: var(--sub-line) !important; }
.tx-subtotal small {
  display: block;
  margin-bottom: 1px;
  font-size: .6875rem;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: .02em;
  color: var(--sub-text);
  white-space: normal;
}
.tx-subtotal b { font-size: 1rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.tx-subtotal .c-date b { color: var(--sub-text); }
.tx-subtotal .t-ton { color: var(--text); }
.tx-subtotal .t-ton.neg { color: var(--danger); }
.tx-subtotal .nil { color: var(--muted); font-weight: 500; }

/* Kiểu bảng "Gọn": ẩn dòng thông tin, chạm vào dòng để xem */
:root[data-density="compact"] .tx { cursor: pointer; }
:root[data-density="compact"] .tx > .tx-grid > * { padding-top: 7px; padding-bottom: 7px; }
:root[data-density="compact"] .tx-info { display: none; }
:root[data-density="compact"] .tx.open { background: var(--sunken); margin: 0 -14px; padding: 0 14px; }
:root[data-density="compact"] .tx.open .tx-info { display: block; }
:root[data-density="compact"] .compact-hint { display: block; }

/* ---------- Theo định khu ---------- */
.loc-card { padding: 14px 18px 16px; }
.pick { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.pick .srow:first-child { border-top: 0; }
.loc-title {
  display: block;
  margin-top: 2px;
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -.01em;
  color: var(--loc);
  overflow-wrap: anywhere;
}
.loc-meta { margin: 6px 0 0; font-size: .9375rem; color: var(--muted); }
.loc-meta b { color: var(--text); font-weight: 700; }
.loc-card + .chips { margin-top: 12px; }
.loc-empty { padding: 18px 4px 14px; text-align: center; color: var(--muted); font-size: .9375rem; }
.loc-empty .more-btn { margin-top: 10px; }

/* Bảng Mã VT – Tên | ĐVT | SL, có vạch dọc chia cột */
.lc-grid { display: grid; grid-template-columns: minmax(0, 1fr) 3.4rem 4.6rem; align-items: stretch; }
.lc-grid > * { min-width: 0; padding: 9px .5rem; }
.lc-grid > :first-child { padding-left: 0; }
.lc-grid > :last-child { padding-right: 0; }
.lc-grid > * + * { border-left: 1px solid var(--col-line); }
.lc-head {
  position: sticky;
  top: var(--tabbar-h, 0px);
  z-index: 2;
  margin: 0 -14px;
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1.5px solid var(--col-line);
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}
.lc-head > * { padding-top: 8px; padding-bottom: 8px; }
.lc-row { margin: 0 -14px; padding: 0 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.lc-row:active, .lc-row:focus-visible { background: var(--sunken); }
.lc-row:last-child { border-bottom: 0; }
.lc-code {
  display: block;
  font-size: .875rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  letter-spacing: .01em;
  color: var(--accent-text);
}
.lc-name { display: block; margin-top: 1px; font-size: .9375rem; line-height: 1.3; overflow-wrap: anywhere; }
.lc-where { display: block; margin-top: 2px; font-size: .75rem; color: var(--muted); }
.lc-dvt, .lc-head > :nth-child(2) { text-align: center; }
.lc-dvt { font-size: .875rem; color: var(--muted); overflow-wrap: anywhere; }
.lc-qty { font-size: 1rem; font-weight: 800; }
.lc-qty.zero { color: var(--danger); }
.lc-list + .more-btn { margin: 10px 0 8px; }

/* ---------- Theo ngày ---------- */
.dates { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.date-field { display: block; min-width: 0; }
.date-field .label { display: block; margin: 0 4px 4px; }
.date-field input {
  display: block;
  width: 100%;
  min-width: 0;
  height: 52px;
  padding: 0 12px;
  font: inherit;
  font-size: max(16px, 1.125rem);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  text-align: left;
  color: var(--text);
  background: var(--field);
  border: 1.5px solid var(--field-line);
  border-radius: 14px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.date-field input::-webkit-date-and-time-value { text-align: left; }
.date-field input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--focus); }
#datePresets { margin-top: 10px; }
#dateLoai { margin-top: 10px; }

.field.small { margin-top: 10px; }
.field.small input { height: 50px; padding-right: 56px; font-size: max(16px, 1.0625rem); font-weight: 500; letter-spacing: 0; }
.field.small .clear { width: 46px; height: 46px; }

.list-head.note { margin: 8px 4px 0; }
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 6px; }
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  min-height: 36px;
  padding: 4px 12px;
  border: 0;
  border-radius: 999px;
  background: var(--primary);
  color: var(--on-primary);
  font-size: .9375rem;
  font-weight: 650;
  text-align: left;
}
.filter-chip .x { font-size: .8125rem; opacity: .85; }

.stats4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 4px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.st { min-width: 0; padding: 10px 4px; text-align: center; }
.st + .st { border-left: 1px solid var(--line); }
.st-v { display: block; font-size: 1.3125rem; font-weight: 800; line-height: 1.2; font-variant-numeric: tabular-nums; }
.st.in .st-v { color: var(--ok); }
.st-l { display: block; font-size: .75rem; line-height: 1.2; color: var(--muted); }

details.dsum {
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  overflow: hidden;
}
details.dsum > summary { padding: 12px 14px; font-size: 1rem; font-weight: 700; cursor: pointer; }
.dsum-hint { margin: 0; padding: 0 14px 8px; font-size: .8125rem; color: var(--muted); }
.srow {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  text-align: left;
  font-size: 1rem;
}
.srow:active { background: var(--sunken); }
.s-name { min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.s-num { flex: none; font-size: .875rem; color: var(--muted); white-space: nowrap; }

.sortbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin-top: 14px; }
.sortbar > .label { flex: none; }

.groups { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.gcard {
  padding: 12px 14px 6px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.g-head { display: flex; align-items: flex-start; gap: 10px; }
.g-title { flex: 1; min-width: 0; }
.g-name { font-size: 1.0625rem; font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; }
.g-meta { margin-top: 2px; font-size: .875rem; color: var(--muted); }
.g-code { font-variant-numeric: tabular-nums; }
.g-loc { color: var(--loc); font-weight: 750; }
.go-mini {
  flex: none;
  height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: var(--soft);
  color: var(--accent-text);
  font-size: .875rem;
  font-weight: 700;
}
.go-mini:active { background: var(--soft-press); }
.g-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin: 10px 0 8px; }
.g-stats > div { min-width: 0; padding: 7px 9px; border-radius: 10px; background: var(--sunken); }
.g-stats .label { font-size: .6875rem; }
.g-stats .v { display: block; font-size: 1.125rem; font-weight: 800; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.g-stats .in .v { color: var(--ok); }
.g-stats .end .v { color: var(--accent-text); }
.g-stats .neg .v { color: var(--danger); }
.g-tag { margin: 2px 0; font-size: .875rem; overflow-wrap: anywhere; }
.g-tag b { color: var(--muted); font-weight: 650; }
.g-lines { margin-top: 8px; }
details.g-lines > summary { padding: 8px 0; font-size: .9375rem; font-weight: 650; color: var(--accent-text); cursor: pointer; }
.gline { padding: 8px 0; border-top: 1px solid var(--line); }
.gline-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; font-size: 1rem; }

/* ---------- Bảng Tùy chỉnh giao diện ---------- */
.sheet { position: fixed; inset: 0; z-index: 100; }
.sheet-backdrop { position: absolute; inset: 0; background: var(--scrim); opacity: 0; transition: opacity .22s; }
.sheet-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 560px;
  max-height: 90vh;
  max-height: 90dvh;
  margin: 0 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px max(18px, env(safe-area-inset-right)) max(20px, calc(env(safe-area-inset-bottom) + 12px)) max(18px, env(safe-area-inset-left));
  border-radius: 22px 22px 0 0;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  transform: translateY(100%);
  transition: transform .26s cubic-bezier(.2, .8, .2, 1);
}
.sheet.show .sheet-backdrop { opacity: 1; }
.sheet.show .sheet-panel { transform: none; }
@media (prefers-reduced-motion: reduce) {
  .sheet-backdrop, .sheet-panel { transition: none; }
}
.sheet-grab { width: 40px; height: 5px; margin: 2px auto 10px; border-radius: 3px; background: var(--field-line); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 10px; }
.sheet-head h2 { margin: 0; font-size: 1.25rem; font-weight: 800; letter-spacing: -.01em; }
.sheet-head .icon-btn { box-shadow: none; }

.set-group { padding: 14px 0; border-top: 1px solid var(--line); }
.set-label { margin: 0 0 10px; }
.set-hint { margin: 8px 2px 0; font-size: .8125rem; color: var(--muted); }

.seg { display: flex; gap: 3px; padding: 3px; border-radius: 12px; background: var(--tabs-bg); }
.seg button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 3px 4px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: min(.9375rem, 4.2vw);
  font-weight: 700;
  line-height: 1.15;
}
.seg button svg { flex: none; width: 18px; height: 18px; }
.seg button.active { background: var(--tab-active); color: var(--text); box-shadow: var(--shadow-seg); }
.seg .fs-a { font-weight: 800; line-height: 1; }

.swatches { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 8px 2px 6px;
  border: 1.5px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: .75rem;
  font-weight: 650;
  line-height: 1.2;
  text-align: center;
}
.swatch i {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: #fff;
  font-style: normal;
}
.swatch i svg { width: 18px; height: 18px; opacity: 0; }
.swatch.active { border-color: var(--field-line); background: var(--sunken); color: var(--text); }
.swatch.active i svg { opacity: 1; }

.set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
  font-size: 1rem;
  font-weight: 650;
  cursor: pointer;
}
.set-row small { display: block; margin-top: 2px; font-size: .8125rem; font-weight: 400; color: var(--muted); }
.switch { position: relative; flex: none; width: 52px; height: 32px; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--field-line); transition: background .2s; pointer-events: none; }
.switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  transition: transform .2s;
}
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }

.set-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(11.5rem, 1fr)); gap: 10px; padding-top: 14px; border-top: 1px solid var(--line); }
.sheet-panel:focus { outline: none; }
.set-actions .more-btn { min-height: 48px; font-size: 1rem; }
.more-btn.danger { background: var(--danger-bg); color: var(--danger); }
.set-foot { margin: 14px 2px 0; font-size: .75rem; color: var(--muted); text-align: center; }

/* ---------- Xuất hàng ---------- */
.xuat-top { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.date-field > .label { display: block; margin: 0 4px 4px; }
.sel {
  display: block;
  width: 100%;
  min-width: 0;
  height: 52px;
  padding: 0 38px 0 14px;
  font: inherit;
  font-size: max(16px, 1.125rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--field) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center / 18px;
  border: 1.5px solid var(--field-line);
  border-radius: 14px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.sel:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--focus); }
.xuat-top .sel { padding-right: 32px; background-position: right 10px center; font-size: max(16px, min(1.125rem, 4.8vw)); }
.field.mini input { height: 52px; padding: 0 48px 0 14px; border-radius: 14px; font-size: max(16px, 1.125rem); font-weight: 700; letter-spacing: 0; }
.field.mini .clear { width: 44px; height: 44px; right: 4px; }
.field.mini .clear svg { width: 24px; height: 24px; }
#xuatHint b { color: var(--text); font-weight: 700; }

/* Danh sách phiếu */
.xl-bar { justify-content: space-between; margin-top: 0; margin-bottom: 8px; }
.xl-bar .list-head { margin: 0 4px; }
.xl-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 14px;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  text-align: left;
  font: inherit;
}
.xl-row:first-child { border-top: 0; }
.xl-row:active { background: var(--sunken); }
.xl-no {
  min-width: 3.4rem;
  padding: 5px 8px 6px;
  border-radius: 12px;
  background: var(--soft);
  color: var(--accent-text);
  font-size: 1.375rem;
  font-weight: 800;
  line-height: 1;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.xl-no small { display: block; margin-bottom: 2px; font-size: .625rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; opacity: .8; }
.xl-main { min-width: 0; }
.xl-who { display: block; font-size: 1rem; font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; }
.xl-first { display: block; margin-top: 2px; font-size: .875rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xl-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; text-align: right; }
.xl-date { font-size: .9375rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.xl-prog { font-size: .75rem; font-weight: 650; color: var(--muted); white-space: nowrap; }
.xl-row.part .xl-prog { padding: 1px 7px; border-radius: 999px; background: var(--warn-bg); color: var(--warn); }
.xl-row.done .xl-prog { padding: 1px 7px; border-radius: 999px; background: var(--ok-bg); color: var(--ok); }
.xl-row.done .xl-no { background: var(--ok-bg); color: var(--ok); }

/* Phiếu đang mở */
.slip-nav { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.nav-pair { display: flex; gap: 6px; margin-left: auto; }
.nav-btn {
  min-height: 40px;
  padding: 0 12px;
  border: 1.5px solid var(--field-line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent-text);
  font-size: .9375rem;
  font-weight: 700;
  white-space: nowrap;
}
.nav-btn:active { background: var(--sunken); }
.nav-btn:disabled { color: var(--muted); opacity: .5; }
.nav-btn.back { padding-left: 10px; }
.slip-card { padding: 14px 18px 16px; }
.slip-title { margin-top: 2px; font-size: 2.25rem; font-weight: 800; line-height: 1.1; color: var(--accent-text); font-variant-numeric: tabular-nums; }
.slip-title small { margin-right: 8px; font-size: 1rem; font-weight: 700; color: var(--muted); }
.slip-meta { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 10px 0 0; padding-top: 10px; border-top: 1px solid var(--line); font-size: .9375rem; }
.slip-meta .mi { min-width: 0; overflow-wrap: anywhere; }
.slip-meta .k { margin-right: 6px; color: var(--muted); font-weight: 600; }
.slip-meta b { font-weight: 750; }
.prog { margin-top: 14px; }
.prog-bar { height: 10px; border-radius: 999px; background: var(--tabs-bg); overflow: hidden; }
.prog-bar i { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--primary); transition: width .25s; }
.prog-text { margin: 7px 0 0; font-size: .9375rem; color: var(--muted); }
.prog-text b { color: var(--text); font-weight: 800; font-variant-numeric: tabular-nums; }
.prog.full .prog-bar i { background: var(--ok); }
.prog.full .prog-text, .prog.full .prog-text b { color: var(--ok); font-weight: 750; }
.chip.toggle.active { background: var(--ok); border-color: var(--ok); color: #fff; }

/* Dòng hàng cần lấy: ô tick | mã, tên, định khu | xuất, tồn */
.pk-sec { padding-bottom: 6px; }
.pk-row {
  display: grid;
  grid-template-columns: 2.25rem minmax(0, 1fr) auto;
  align-items: start;
  gap: 4px 12px;
  margin: 0 -14px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s;
}
.pk-row:active { background: var(--sunken); }
.pk-row:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.pk-box {
  width: 2.25rem;
  height: 2.25rem;
  display: grid;
  place-items: center;
  border: 2px solid var(--field-line);
  border-radius: 10px;
  background: var(--field);
  color: transparent;
  transition: background .15s, border-color .15s, color .15s;
}
.pk-box svg { width: 1.4rem; height: 1.4rem; }
.pk-main { min-width: 0; }
.pk-top { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.pk-code { font-size: .9375rem; font-weight: 750; font-variant-numeric: tabular-nums; color: var(--muted); letter-spacing: .02em; }
.pk-loai { padding: 0 7px; border-radius: 999px; background: var(--sunken); font-size: .75rem; font-weight: 700; color: var(--muted); }
.pk-name { display: block; margin-top: 2px; font-size: 1rem; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.pk-where { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 5px; }
.pk-loc { display: inline-block; padding: 1px 9px; border-radius: 8px; background: var(--soft); color: var(--loc); font-size: 1.0625rem; font-weight: 800; overflow-wrap: anywhere; }
.pk-loc.empty { padding: 0; background: none; font-size: .875rem; font-weight: 500; font-style: italic; color: var(--muted); }
.pk-extra { display: block; margin-top: 4px; font-size: .8125rem; color: var(--muted); }
.pk-done { font-size: .875rem; font-weight: 750; color: var(--ok); white-space: nowrap; }
.pk-done:empty { display: none; }
.pk-side { display: flex; flex-direction: column; align-items: flex-end; text-align: right; }
.pk-side .label { font-size: .6875rem; }
.pk-sl { font-size: 1.5rem; font-weight: 800; line-height: 1.15; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pk-sl small { margin-left: 4px; font-size: .8125rem; font-weight: 650; color: var(--muted); }
.pk-ton { margin-top: 4px; font-size: .8125rem; color: var(--muted); white-space: nowrap; }
.pk-ton b { color: var(--text); font-weight: 750; font-variant-numeric: tabular-nums; }
.pk-ton.zero b { color: var(--muted); }
.pk-ton.neg b { color: var(--danger); }
/* Đã lấy: nền xanh, ô tick đầy, chữ mờ đi */
.pk-row.on { background: var(--ok-bg); }
.pk-row.on .pk-box { border-color: var(--ok); background: var(--ok); color: #fff; }
.pk-row.on .pk-top, .pk-row.on .pk-name, .pk-row.on .pk-loc, .pk-row.on .pk-extra, .pk-row.on .pk-side { opacity: .55; }
.pk-row.on .pk-name { text-decoration: line-through; text-decoration-thickness: 1px; }
.pk-alldone { margin: 8px 0 6px; padding: 12px; border-radius: 12px; background: var(--ok-bg); color: var(--ok); font-weight: 750; text-align: center; }
.slip-acts { margin-top: 14px; border-top: 0; padding-top: 0; }
.slip-acts .more-btn { min-height: 48px; font-size: 1rem; }
.slip-acts .more-btn:disabled { opacity: .45; }

.toast {
  position: fixed;
  z-index: 60;
  left: 50%;
  bottom: max(20px, calc(env(safe-area-inset-bottom) + 12px));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 12px 16px;
  border-radius: 14px;
  background: #1f2937;
  color: #fff;
  font-size: .9375rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .3);
}

/* ---------- Xuất hàng: chọn kho + lấy gộp nhiều phiếu ---------- */
.xuat-go { align-self: end; }
.xuat-go .go { width: 100%; height: 52px; border-radius: 14px; font-size: 1.125rem; }

.xl-multi { margin: 0 0 10px; }
.xl-multi .chip { height: 38px; }

/* Tiêu đề ngày trong danh sách phiếu */
.xl-day {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 8px;
  min-height: 40px;
  padding: 6px 14px;
  border-top: 1px solid var(--line);
  background: var(--sunken);
  font-size: .875rem;
  font-weight: 750;
}
.xl-day:first-child { border-top: 0; }
.xl-day + .xl-row { border-top: 0; }
.xl-day-n { font-weight: 600; color: var(--muted); }
.xl-day-btn {
  margin-left: auto;
  min-height: 32px;
  padding: 0 12px;
  border: 1.5px solid var(--primary);
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent-text);
  font-size: .8125rem;
  font-weight: 750;
  white-space: nowrap;
}
.xl-day-btn.on { background: var(--primary); color: var(--on-primary); }

/* Đang chọn nhiều phiếu */
.selecting .xl-row { grid-template-columns: auto auto minmax(0, 1fr) auto; gap: 10px; }
.xl-check {
  width: 1.75rem;
  height: 1.75rem;
  display: grid;
  place-items: center;
  border: 2px solid var(--field-line);
  border-radius: 8px;
  background: var(--field);
  color: transparent;
}
.xl-check svg { width: 1.15rem; height: 1.15rem; }
.xl-row.chosen { background: var(--soft); }
.xl-row.chosen .xl-check { border-color: var(--primary); background: var(--primary); color: var(--on-primary); }

/* Thanh dưới cùng: đã chọn N phiếu · Lấy gộp */
.xl-bbar {
  position: sticky;
  bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding: 8px 8px 8px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 8px 28px rgba(15, 23, 42, .22);
}
.xl-bbar-t { flex: 1 1 7.5rem; min-width: 0; margin: 0; font-size: .875rem; line-height: 1.25; color: var(--muted); }
.xl-bbar-t b { display: block; font-size: 1rem; color: var(--text); font-weight: 800; }
.xl-bbar-clear { flex: none; min-height: 44px; padding: 0 8px; border: 0; background: none; color: var(--muted); font-size: .9375rem; font-weight: 700; }
.xl-bbar .go { flex: 1 0 auto; height: 48px; padding: 0 18px; border-radius: 13px; font-size: 1.0625rem; white-space: nowrap; }
.xl-bbar .go:disabled { opacity: .45; box-shadow: none; }
.has-bbar .toast { bottom: calc(max(20px, calc(env(safe-area-inset-bottom) + 12px)) + 76px); }

/* Phiếu gộp: các phiếu trong lượt + tiến độ từng phiếu */
.bt-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 10px; margin-top: 12px; }
.bt-sum { font-size: .9375rem; color: var(--muted); }
.bt-sum b { color: var(--text); font-weight: 800; font-variant-numeric: tabular-nums; }
.bt-sum.full, .bt-sum.full b { color: var(--ok); }
.bt-toggle { min-height: 36px; padding: 0 12px; border: 1.5px solid var(--field-line); border-radius: 999px; background: var(--surface); color: var(--accent-text); font-size: .875rem; font-weight: 700; }
.bt-toggle:active { background: var(--sunken); }
.bt-slips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.bt-slip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  min-height: 34px;
  padding: 5px 10px;
  border: 1.5px solid var(--field-line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: .875rem;
  line-height: 1.2;
}
.bt-slip:active { background: var(--sunken); }
.bt-slip b { font-weight: 800; font-variant-numeric: tabular-nums; }
.bt-st { font-weight: 650; color: var(--muted); font-variant-numeric: tabular-nums; }
.bt-slip.part { border-color: var(--warn); }
.bt-slip.part .bt-st { color: var(--warn); }
.bt-slip.done { border-color: var(--ok); background: var(--ok-bg); }
.bt-slip.done .bt-st { color: var(--ok); }

/* Dòng hàng gộp: thuộc phiếu nào, mỗi phiếu bao nhiêu */
.pk-part {
  padding: 1px 8px;
  border-radius: 6px;
  background: var(--sunken);
  color: var(--muted);
  font-size: .8125rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.pk-part.ok { background: var(--ok-bg); color: var(--ok); }
.pk-part.ok::before { content: '✓ '; }
.pk-box .dash { display: none; }
.pk-row.half .pk-box { border-color: var(--ok); background: var(--ok-bg); color: var(--ok); }
.pk-row.half .pk-box .ck { display: none; }
.pk-row.half .pk-box .dash { display: block; }
.pk-row.half .pk-done { color: var(--warn); }
.pk-row.on .pk-part.ok { background: transparent; }

/* ---------- Thay / Thêm định khu ---------- */
.ic { flex: none; width: 1.2em; height: 1.2em; }

/* Theo mã: chân thẻ 2 nút, thẳng hàng với 2 cột Định khu | Tồn kho ở trên */
.card-foot .more-btn { display: flex; align-items: center; justify-content: center; gap: 8px; line-height: 1.2; text-align: center; }
.card-foot.two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
/* Biểu tượng trên, chữ dưới: 2 nút luôn cao bằng nhau, chữ không bị xuống dòng (kể cả cỡ chữ Rất lớn) */
.card-foot.two .more-btn { flex-direction: column; gap: 5px; min-height: 64px; padding: 9px 6px 8px; font-size: min(1rem, 4.1vw); white-space: nowrap; }
.card-foot.two .more-btn .ic { width: 22px; height: 22px; }
.dk-note { display: block; margin-top: 6px; font-size: .8125rem; font-weight: 650; line-height: 1.3; color: var(--warn); }

/* Theo ngày: thanh định khu cùng kiểu các ô Tồn cũ | Nhập | Tồn nay */
.g-dk {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 7px 7px 7px 11px;
  border-radius: 10px;
  background: var(--sunken);
}
.g-dk-t { flex: 1; min-width: 0; }
.g-dk-l { display: flex; align-items: center; gap: 6px; }
.g-dk .label { font-size: .6875rem; }
.g-dk-v { display: block; font-size: 1.125rem; font-weight: 800; line-height: 1.25; color: var(--loc); overflow-wrap: anywhere; }
.g-dk-v.empty { font-size: .9375rem; font-weight: 500; font-style: italic; color: var(--muted); }
.g-dk + .g-stats { margin-top: 6px; }
.dk-tag { padding: 0 6px; border-radius: 6px; background: var(--warn-bg); color: var(--warn); font-size: .6875rem; font-weight: 700; line-height: 1.5; }
.dk-btn:not(.more-btn) {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 14px 0 11px;
  border: 0;
  border-radius: 999px;
  background: var(--soft);
  color: var(--accent-text);
  font-size: .875rem;
  font-weight: 750;
  white-space: nowrap;
}
.dk-btn:not(.more-btn):active { background: var(--soft-press); }

/* Bảng sửa định khu */
.dk-item { display: flex; align-items: baseline; gap: 10px; padding: 12px 0; border-top: 1px solid var(--line); }
.dk-item .code { flex: none; font-size: 1.0625rem; }
.dk-name { min-width: 0; margin: 0; font-size: 1rem; font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }
.dk-now { padding: 11px 14px 12px; border-radius: 14px; background: var(--sunken); }
.dk-cur { display: block; margin-top: 2px; font-size: 1.5rem; font-weight: 800; line-height: 1.2; color: var(--loc); overflow-wrap: anywhere; }
.dk-cur.empty { font-size: 1.0625rem; font-weight: 500; font-style: italic; color: var(--muted); }
.dk-orig { display: block; margin-top: 4px; font-size: .8125rem; font-weight: 650; color: var(--warn); }
.dk-mode { margin-top: 14px; }
.dk-lbl { display: block; margin: 14px 2px 6px; font-size: .875rem; font-weight: 700; }
.dk-lbl small { font-size: .8125rem; font-weight: 500; color: var(--muted); }
.field.mini.plain input { padding-right: 14px; }
#dkPin { letter-spacing: .12em; }
#dkPin::placeholder { letter-spacing: 0; }
.dk-sug { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.dk-sug .chip { height: 34px; padding: 0 12px; font-size: .9375rem; font-weight: 650; }
.dk-preview { min-height: 1.35em; margin: 8px 2px 0; font-size: .9375rem; line-height: 1.35; color: var(--muted); overflow-wrap: anywhere; }
.dk-preview b { font-weight: 800; color: var(--loc); }
.dk-preview.warn { font-weight: 650; color: var(--warn); }
.dk-row2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); align-items: end; gap: 0 12px; }
.dk-msg { min-height: 1.35em; margin: 10px 2px 0; font-size: .9375rem; font-weight: 650; color: var(--danger); }
.dk-msg:empty { min-height: 0; margin-top: 4px; }
.dk-actions { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; margin-top: 10px; }
.dk-actions .more-btn, .dk-actions .go { height: 52px; min-height: 52px; padding: 0 8px; border-radius: 14px; font-size: min(1.0625rem, 4.4vw); white-space: nowrap; }
.dk-actions .go:disabled { opacity: .6; }
.dk-info { margin: 12px 2px 0; font-size: .8125rem; line-height: 1.35; text-align: center; color: var(--muted); }
.dk-info:empty { display: none; }
.dk-info.warn { color: var(--warn); }

/* ---------- Tên người làm ---------- */
.who-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 12rem;
  min-height: 34px;
  padding: 0 12px 0 8px;
  border: 1.5px solid var(--field-line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: .875rem;
  font-weight: 700;
  line-height: 1.1;
}
.who-chip span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-chip .ic { width: 1.1rem; height: 1.1rem; color: var(--accent-text); }
.who-chip.empty { border-style: dashed; color: var(--accent-text); }
.who-chip:active { background: var(--sunken); }
.who-hint { margin: 0 0 14px; }

/* ---------- Nhập hàng: Lên kệ ---------- */
.ke-panel {
  margin-top: 12px;
  padding: 12px 14px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.ke-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.ke-head h3 { display: flex; align-items: center; gap: 7px; margin: 0; font-size: 1.0625rem; font-weight: 800; }
.ke-head h3 .ic { width: 1.3rem; height: 1.3rem; color: var(--accent-text); }
.ke-panel .prog { margin-top: 10px; }
.ke-chips { margin-top: 12px; }
.ke-chips .chip { display: inline-flex; align-items: center; gap: 6px; }
.ke-n { font-weight: 800; font-variant-numeric: tabular-nums; opacity: .8; }
.ke-sheet { margin: 10px 0 0; font-size: .8125rem; line-height: 1.35; color: var(--muted); overflow-wrap: anywhere; }
.ke-sheet.ok { color: var(--ok); }
.ke-sheet.ok::before { content: '✓ '; }
.ke-sheet.warn { margin: 10px 0 0; padding: 8px 10px; border-radius: 10px; }
.ke-sheet small { display: block; margin-top: 3px; font-size: .75rem; opacity: .9; overflow-wrap: anywhere; }

/* Nhãn trên thẻ mã: Chưa lên kệ / Lên kệ 1/3 / Đã lên kệ */
.ke-tag { display: inline-block; margin-left: 8px; padding: 1px 8px; border-radius: 999px; font-size: .75rem; font-weight: 750; white-space: nowrap; vertical-align: 1px; }
.ke-tag.no { background: var(--warn-bg); color: var(--warn); }
.ke-tag.part { background: var(--soft); color: var(--accent-text); }
.ke-tag.ok { background: var(--ok-bg); color: var(--ok); }

/* Mỗi lần nhập: ô tick "Lên kệ" bên trái | ngày, số lượng, NCC... */
.gline.ke-row {
  display: grid;
  grid-template-columns: 3rem minmax(0, 1fr);
  align-items: start;
  gap: 0 10px;
  margin: 0 -14px;
  padding: 10px 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s;
}
.ke-row:active { background: var(--sunken); }
.ke-row:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.ke-box { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.ke-cap { font-size: .6875rem; font-weight: 750; line-height: 1.1; color: var(--muted); white-space: nowrap; }
.ke-main { min-width: 0; }
.ke-done { display: block; margin-top: 4px; font-size: .875rem; font-weight: 750; color: var(--ok); }
.ke-done:empty { display: none; }
.ke-row.on { background: var(--ok-bg); }
.ke-row.on .pk-box { border-color: var(--ok); background: var(--ok); color: #fff; }
.ke-row.on .ke-cap { color: var(--ok); }
.ke-row.no-ke { cursor: default; }
.ke-row.no-ke .ke-box { visibility: hidden; }

/* ---------- Xuất hàng: đã tích, chờ xác nhận ---------- */
.pk-row.wait { background: var(--soft); }
.pk-row.wait .pk-box { border-color: var(--primary); background: var(--primary); color: var(--on-primary); }
.pk-row.wait .pk-done { color: var(--accent-text); }
.xl-wait { padding: 1px 7px; border-radius: 999px; background: var(--soft); color: var(--accent-text); font-size: .75rem; font-weight: 700; white-space: nowrap; }
.pk-cbar { margin-top: 10px; }
.pk-cbar .xl-bbar-t { flex-basis: 9rem; }
.pk-cbar .xl-bbar-t b { font-size: .9375rem; }
.pk-cwho { display: flex; align-items: center; gap: 4px; margin-top: 4px; font-size: .8125rem; white-space: nowrap; }
.pk-cwho .who-chip { min-height: 28px; max-width: 9rem; padding: 0 9px 0 6px; font-size: .8125rem; }

/* ---------- Quyền CHỈ XEM (mật khẩu chỉ xem): ẩn nút sửa, ô tích không bấm được ---------- */
.ro-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin: 0 0 8px;
  padding: 8px 12px;
  border: 1px solid var(--warn);
  border-radius: 12px;
  background: var(--warn-bg);
  color: var(--warn);
  font: inherit;
  font-size: .875rem;
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
}
.ro-bar[hidden] { display: none; }
.ro-bar svg { flex: none; width: 18px; height: 18px; }
.ro-bar-t { flex: 1; min-width: 0; }
.ro-bar-t b { font-weight: 800; text-transform: uppercase; letter-spacing: .02em; }
.ro-bar-go { flex: none; font-weight: 800; text-decoration: underline; text-underline-offset: 2px; }
.ro .ro-hide { display: none !important; }
.ro-show { display: none; }
.ro .ro-show { display: inline; }
.ro .ke-row, .ro .pk-row { cursor: default; }
.ro .ke-row:not(.on) .pk-box, .ro .pk-row:not(.on):not(.wait):not(.half) .pk-box { opacity: .4; }

/* ---------- Link dùng 4G (trong Tùy chỉnh) ---------- */
.set-4g { display: flex; align-items: center; gap: 10px; }
.set-4g-link { flex: 1; min-width: 0; font-weight: 700; color: var(--accent-text); overflow-wrap: anywhere; }
.set-4g .more-btn { flex: none; width: auto; min-height: 44px; padding: 8px 16px; font-size: 1rem; }
