/* LLL Stock. Tokens and shell follow lll-hr DESIGN.md (one LLL family); stock-specific parts below "counter". Plain CSS, no build. */
:root {
  /* กรมท่า: PT chose it over lll-hr's green on 2026-11-24. Green now only means "ปกติ" (--success). */
  --primary: #1e3a5f; --primary-hover: #152b47; --primary-soft: #e8eef6; --primary-line: #a9bdd6;
  --canvas: #f5f6f8; --surface: #fff;
  --ink: #111827; --secondary: #4b5563; --muted: #6b7280;
  --border: #e5e7eb; --control: #d1d5db;
  --success: #166534; --success-bg: #dcfce7;
  --warning: #854d0e; --warning-bg: #fef3c7; --warning-fill: #d97706;
  --danger: #991b1b; --danger-bg: #fee2e2;
  --neutral: #374151; --neutral-bg: #f3f4f6;
  --r-sm: 6px; --r-md: 8px; --r-lg: 12px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --shadow: 0 1px 2px rgb(17 24 39 / .04);
  --overlay: 0 10px 30px rgb(17 24 39 / .12);
  --topbar-h: 56px;
}
* { box-sizing: border-box; }
html { scrollbar-color: var(--control) transparent; }
[hidden] { display: none !important; }
body { margin: 0; font: 15px/1.6 "Noto Sans Thai", system-ui, sans-serif; color: var(--ink); background: var(--canvas); font-variant-numeric: tabular-nums; accent-color: var(--primary); caret-color: var(--primary); }
::selection { background: var(--primary-soft); color: var(--primary-hover); }
h1 { font-size: 1.5rem; font-weight: 600; line-height: 1.4; margin: 0; text-wrap: balance; }
h2 { font-size: 1rem; font-weight: 600; line-height: 1.5; margin: 0; }
p { margin: 0; }
a { color: var(--primary); text-underline-offset: 3px; }
small, .muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.i { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- shell: one top bar (logo · menu · user), content below ---------- */
.appbar { position: sticky; top: 0; z-index: 20; display: flex; gap: var(--s5); align-items: center; height: var(--topbar-h); padding: 0 var(--s5); background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: flex; gap: var(--s3); align-items: center; flex: none; text-decoration: none; color: var(--ink); }
.brand b, .user-name b { display: block; font-weight: 600; line-height: 1.25; }
.brand small, .user-name small { display: block; line-height: 1.25; font-size: .8125rem; }
.logo { width: 32px; height: 32px; border-radius: var(--r-md); background: var(--primary); color: #fff; display: grid; place-items: center; }
.logo .i { width: 18px; height: 18px; }
.topnav { flex: 1; display: flex; gap: var(--s1); justify-content: center; }
.topnav a { display: inline-flex; gap: var(--s2); align-items: center; min-height: 38px; padding: 0 var(--s3); border: 1px solid transparent; border-radius: var(--r-md); color: var(--secondary); text-decoration: none; font-weight: 500; font-size: .9375rem; white-space: nowrap; }
.topnav a .i { width: 18px; height: 18px; }
.topnav a:hover { background: var(--neutral-bg); color: var(--ink); }
.topnav a[aria-current] { background: var(--primary-soft); border-color: var(--primary-line); color: var(--primary-hover); }
.user { display: flex; gap: var(--s2); align-items: center; flex: none; }
.user-name { min-width: 0; font-size: .875rem; }
.avatar { flex: none; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-weight: 600; font-size: .875rem; }
.content { max-width: 1360px; margin: 0 auto; padding: var(--s5); }
.page-head { display: flex; flex-wrap: wrap; gap: var(--s3) var(--s4); justify-content: space-between; align-items: flex-end; margin-bottom: var(--s4); }
.page-sub { color: var(--muted); font-size: .875rem; margin-top: 2px; }
.actions { display: flex; flex-wrap: wrap; gap: var(--s2); }
.back { display: inline-flex; gap: var(--s1); align-items: center; color: var(--secondary); text-decoration: none; font-weight: 500; }
.back:hover { color: var(--primary); }
.appbar .menu-btn { display: none; }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; padding: 0; background: none; border: 1px solid transparent; border-radius: var(--r-md); color: var(--secondary); cursor: pointer; }
.icon-btn:hover { background: var(--neutral-bg); border-color: transparent; color: var(--ink); }
#nav-toggle:focus-visible ~ .appbar .menu-btn { outline: 2px solid var(--primary); outline-offset: 2px; }

@media (max-width: 1180px) {
  .appbar { flex-wrap: wrap; height: auto; min-height: var(--topbar-h); padding: var(--s2) var(--s4); gap: var(--s2) var(--s4); }
  .appbar .menu-btn { display: inline-grid; order: 3; }
  .user { order: 2; margin-left: auto; }
  .topnav { order: 4; flex-basis: 100%; flex-direction: column; align-items: stretch; display: none; padding-bottom: var(--s2); }
  #nav-toggle:checked ~ .appbar .topnav { display: flex; }
  .topnav a { min-height: 44px; }
  .content { padding: var(--s4); }
}
@media (max-width: 767px) {
  .user-name { display: none; }
  .actions .lbl { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

/* ---------- buttons, controls ---------- */
button, .btn { display: inline-flex; gap: var(--s2); align-items: center; justify-content: center; min-height: 40px; padding: 0 var(--s4); font: inherit; font-weight: 500; color: #fff; background: var(--primary); border: 1px solid var(--primary); border-radius: var(--r-md); cursor: pointer; text-decoration: none; }
button:hover, .btn:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn .i, button .i { width: 18px; height: 18px; }
.btn-secondary, button.btn-secondary { color: var(--ink); background: var(--surface); border-color: var(--control); }
.btn-secondary:hover, button.btn-secondary:hover { background: var(--neutral-bg); border-color: var(--control); }
.btn-danger, button.btn-danger { color: var(--danger); background: var(--surface); border-color: var(--danger); }
.btn-danger:hover, button.btn-danger:hover { background: var(--danger-bg); border-color: var(--danger); }
.btn-sm, button.btn-sm { min-height: 32px; padding: 0 var(--s3); font-size: .8125rem; }
.btn-lg { width: 100%; min-height: 52px; font-size: 1.0625rem; font-weight: 600; border-radius: var(--r-lg); }
input, select, textarea { width: 100%; min-height: 40px; font: inherit; padding: var(--s2) var(--s3); color: var(--ink); background: var(--surface); border: 1px solid var(--control); border-radius: var(--r-md); }
input::placeholder { color: var(--muted); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
input[aria-invalid=true] { border-color: var(--danger); }
label { display: block; font-size: .875rem; font-weight: 500; margin-bottom: var(--s1); }
.req { color: var(--danger); }
.help { display: block; margin-top: var(--s1); font-size: .8125rem; color: var(--muted); }
.field { margin-bottom: var(--s4); }
.err { display: flex; gap: var(--s2); align-items: flex-start; margin-top: var(--s2); color: var(--danger); font-size: .875rem; font-weight: 500; }
.err .i { width: 16px; height: 16px; margin-top: 3px; }
.alert { padding: var(--s3) var(--s4); margin-bottom: var(--s4); color: var(--danger); background: var(--danger-bg); border-radius: var(--r-md); }
.alert ul { margin: 0; padding: 0; list-style: none; }
.flash { display: flex; gap: var(--s3); align-items: center; padding: var(--s3) var(--s4); margin-bottom: var(--s4); border-radius: var(--r-md); font-weight: 500; background: var(--success-bg); color: var(--success); animation: flash-in .35s cubic-bezier(.16, 1, .3, 1); }
.flash.error { background: var(--danger-bg); color: var(--danger); }
.flash.warning { background: var(--warning-bg); color: var(--warning); }
@keyframes flash-in { from { translate: 0 -6px; opacity: .4; } }
@media (prefers-reduced-motion: reduce) { .flash { animation: none; } }

/* ---------- card, badges, table ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: var(--s5); margin-bottom: var(--s4); }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4); justify-content: space-between; align-items: center; padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border); }
.card-head p { color: var(--muted); font-size: .875rem; }
.badge, .pill { display: inline-flex; gap: 6px; align-items: center; padding: 1px 10px; border-radius: 999px; font-size: .8125rem; font-weight: 600; white-space: nowrap; text-decoration: none; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.red, .st-low { background: var(--danger-bg); color: var(--danger); }
.badge.yellow { background: var(--warning-bg); color: var(--warning); }  /* เหลือน้อย */
.badge.violet, .st-ordered { background: #ede9fe; color: #5b21b6; }      /* สั่งแล้ว: same hue as .kind-order */
.badge.green, .st-ok { background: var(--success-bg); color: var(--success); }
.badge.neutral, .st-no_point { background: var(--neutral-bg); color: var(--neutral); }
.empty { padding: var(--s6) var(--s5); text-align: center; color: var(--muted); }
.scroll { position: relative; overflow-x: auto; }  /* relative: an .sr-only header inside must not widen the page */
table { border-collapse: collapse; width: 100%; }
th { height: 44px; padding: 0 var(--s4); background: #f9fafb; font-size: .8125rem; font-weight: 500; color: var(--muted); text-align: left; white-space: nowrap; border-bottom: 1px solid var(--border); }
td { height: 52px; padding: var(--s2) var(--s4); border-bottom: 1px solid var(--border); vertical-align: middle; }
th:first-child, td:first-child { padding-left: var(--s5); }
th:last-child, td:last-child { padding-right: var(--s5); }
tbody tr:hover td { background: #fafafa; }
tbody tr:last-child td { border-bottom: 0; }
th.r, td.r { text-align: right; white-space: nowrap; }
td small { display: block; font-size: .8125rem; }
td.note { max-width: 22rem; color: var(--secondary); }
td.code { color: var(--secondary); white-space: nowrap; }
table.stock td { white-space: nowrap; }
table.stock td.name { white-space: normal; min-width: 16rem; }
table.stock td.cat { white-space: normal; min-width: 9rem; max-width: 13rem; }
td.name a { color: var(--ink); font-weight: 500; text-decoration: none; }
td.name a:hover { color: var(--primary); text-decoration: underline; }
tr.voided td { color: var(--muted); }
tr.voided td.qty, tr.voided td:nth-child(3) a { text-decoration: line-through; }
.kind-tag { display: inline-flex; padding: 1px 10px; border-radius: 999px; font-size: .8125rem; font-weight: 500; white-space: nowrap; background: var(--tag-bg); color: var(--tag-fg); }
/* kinds avoid red/yellow/green, which mean stock status; ปรับเพิ่ม and ปรับลด differ (PT 2026-11-24) */
.kind-out { --tag-bg: #dbeafe; --tag-fg: #1e40af; }
.kind-in { --tag-bg: #cffafe; --tag-fg: #155e75; }   /* cyan, not teal: teal read as green next to ปกติ */
.kind-order { --tag-bg: #ede9fe; --tag-fg: #5b21b6; }
.kind-adj_up { --tag-bg: #fae8ff; --tag-fg: #86198f; }
.kind-adj_down { --tag-bg: #e2e8f0; --tag-fg: #334155; }
/* tags: ประเภท = round pill, ที่เก็บ = square-cornered chip; both filled. Colours c0..c7 are lll-hr's cool tag
   hues, picked per category/location by |tone in stock_tags.py (--tag-dot = SOLID there, also used by the category bars). */
.tag { display: inline-flex; gap: 6px; align-items: center; padding: 1px 10px; border-radius: 999px; font-size: .8125rem; font-weight: 500; line-height: 1.5; white-space: nowrap; background: var(--tag-bg); color: var(--tag-fg); }
.tag.loc { border-radius: var(--r-sm); }
.c0 { --tag-bg: #dbeafe; --tag-fg: #1e40af; --tag-dot: #3b82f6; }
.c1 { --tag-bg: #e0e7ff; --tag-fg: #3730a3; --tag-dot: #6366f1; }
.c2 { --tag-bg: #e0f2fe; --tag-fg: #075985; --tag-dot: #0ea5e9; }   /* sky: violet is the status สั่งแล้ว */
.c3 { --tag-bg: #fce7f3; --tag-fg: #9d174d; --tag-dot: #ec4899; }
.c4 { --tag-bg: #cffafe; --tag-fg: #155e75; --tag-dot: #06b6d4; }
.c5 { --tag-bg: #fae8ff; --tag-fg: #86198f; --tag-dot: #d946ef; }   /* fuchsia: teal read as green */
.c6 { --tag-bg: #e2e8f0; --tag-fg: #334155; --tag-dot: #64748b; }
.c7 { --tag-bg: #ffedd5; --tag-fg: #9a3412; --tag-dot: #f97316; }
td.cat .tag { white-space: normal; border-radius: var(--r-md); }   /* long names wrap inside the chip */
th.ctr, td.ctr { text-align: center; }   /* chip columns (ประเภท, ที่เก็บ) */
.full-name { margin-top: 2px; color: var(--secondary); }   /* the full (Express) name under a ชื่อเรียก */
.item-meta, .chosen-meta { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s2); align-items: center; }
.setup-name { display: flex; gap: var(--s2); align-items: center; min-width: 0; }
.chip-link { text-decoration: none; }
.chip-link:hover .tag { box-shadow: inset 0 0 0 1px currentColor; }
.swatch { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--tag-dot); }
.toolbar { display: grid; grid-template-columns: minmax(220px, 2fr) repeat(2, minmax(150px, 1fr)); gap: var(--s2); align-items: center; padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border); }
.search { position: relative; }
.search .i { position: absolute; left: var(--s3); top: 50%; translate: 0 -50%; width: 18px; height: 18px; color: var(--muted); pointer-events: none; }
.search input { padding-left: 38px; }
.tbl-meta { padding: var(--s3) var(--s5); font-size: .875rem; color: var(--muted); border-bottom: 1px solid var(--border); }
.status-row { display: flex; flex-wrap: wrap; gap: var(--s2); padding: var(--s3) var(--s5); border-bottom: 1px solid var(--border); }
.status-row .row-label { align-self: center; margin-right: var(--s1); font-size: .8125rem; color: var(--muted); }
td.todo .badge + .badge { margin-top: var(--s1); }
.status-row .pill { min-height: 32px; padding: 0 var(--s3); border: 1px solid var(--border); background: var(--surface); color: var(--secondary); font-weight: 500; }
.status-row .pill b { font-weight: 600; color: var(--ink); }
.status-row .pill:hover { border-color: var(--control); color: var(--ink); }
.status-row .pill.is-on { background: var(--primary-soft); border-color: var(--primary-line); color: var(--primary-hover); }
.status-row .pill.st-low.is-on { background: var(--danger-bg); border-color: #fca5a5; color: var(--danger); }
table.summary td { height: 44px; }
table.summary a:not(.badge) { color: var(--ink); text-decoration: none; font-weight: 500; }
table.summary a:not(.badge):hover { color: var(--primary); text-decoration: underline; }
small.split { color: var(--muted); }
@media (max-width: 767px) { .toolbar { grid-template-columns: 1fr 1fr; } .toolbar .search { grid-column: 1 / -1; } }

/* ---------- login ---------- */
.login { display: grid; grid-template-columns: minmax(380px, 38%) 1fr; min-height: 100vh; }
.login-brand { display: flex; flex-direction: column; justify-content: center; gap: var(--s5); padding: var(--s6) clamp(32px, 5vw, 72px); background: var(--primary); color: #fff; }
.login-brand .brand { color: #fff; padding: 0; gap: var(--s3); }
.login-brand .brand b { font-size: 1.25rem; }
.login-brand .brand small { color: rgb(255 255 255 / .82); }
.login-brand .logo { width: 44px; height: 44px; border-radius: var(--r-lg); background: #fff; color: var(--primary); }
.login-brand .logo .i { width: 24px; height: 24px; }
.login-tag { font-size: clamp(1.5rem, 2.2vw, 2rem); font-weight: 600; line-height: 1.35; }
.login-steps { list-style: none; counter-reset: step; display: grid; gap: var(--s4); margin: var(--s2) 0 0; padding: 0; max-width: 26rem; }
.login-steps li { counter-increment: step; display: grid; grid-template-columns: 32px 1fr; column-gap: var(--s3); }
.login-steps li::before { content: counter(step); grid-row: span 2; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: rgb(255 255 255 / .16); font-weight: 600; }
.login-steps b { font-weight: 600; }
.login-steps span { font-size: .875rem; color: rgb(255 255 255 / .82); }
.login-form { align-self: center; justify-self: center; width: min(400px, calc(100% - 32px)); padding: var(--s6); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: 0 4px 16px rgb(17 24 39 / .06); }
.login-form h1 { margin-bottom: var(--s5); }
.login-mobile-brand { display: none; }
.login-form input { min-height: 46px; }
.login-form .btn-lg { margin-top: var(--s2); }
@media (max-width: 767px) { .login { grid-template-columns: 1fr; } .login-brand { display: none; } .login-form { border: 0; box-shadow: none; background: none; padding: var(--s5) 0; } .login-mobile-brand { display: flex; padding: 0 0 var(--s5); } }

/* ---------- counter (เบิก/รับของ) ---------- */
.kinds { display: flex; flex-wrap: wrap; gap: var(--s2); }
.kind { display: inline-flex; gap: var(--s2); align-items: center; min-height: 48px; padding: 0 var(--s5); border: 1px solid var(--control); border-radius: var(--r-lg); background: var(--surface); color: var(--secondary); font-size: 1.0625rem; font-weight: 600; text-decoration: none; }
.kind:hover { color: var(--ink); border-color: var(--secondary); }
.kind[aria-current] { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 2px 6px rgb(31 122 77 / .25); }
.kind-help { margin: var(--s2) 0 var(--s4); color: var(--secondary); }

.counter { display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 430px); gap: var(--s4); align-items: start; }
.counter > .card { margin: 0; }
.picker { display: flex; flex-direction: column; max-height: calc(100vh - 260px); min-height: 420px; }
.picker-head { padding: var(--s4); border-bottom: 1px solid var(--border); }
.picker-head input { min-height: 50px; font-size: 1.0625rem; border-radius: var(--r-lg); }
.picker-head .help { margin: var(--s2) 0 var(--s3); }
.cats { display: flex; gap: var(--s2); overflow-x: auto; padding-bottom: 2px; scrollbar-width: thin; }
button.cat { flex: none; min-height: 34px; padding: 0 var(--s3); border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--secondary); font-size: .875rem; font-weight: 500; }
button.cat:hover { background: var(--neutral-bg); border-color: var(--control); color: var(--ink); }
button.cat[aria-pressed=true] { background: var(--ink); border-color: var(--ink); color: #fff; }
.items { list-style: none; margin: 0; padding: var(--s2); overflow-y: auto; flex: 1; }
.items li { display: flex; gap: var(--s4); justify-content: space-between; align-items: center; min-height: 56px; padding: var(--s2) var(--s3); border-radius: var(--r-md); cursor: pointer; }
.items li + li { box-shadow: 0 -1px 0 var(--border); }
.items li:hover, .items li.is-active { background: var(--neutral-bg); box-shadow: none; }
.items li.is-active + li, .items li:hover + li { box-shadow: none; }
.items li[aria-selected=true] { background: var(--primary-soft); box-shadow: inset 0 0 0 1px var(--primary-line); }
.it-name { min-width: 0; font-weight: 500; line-height: 1.4; }
.it-thumb { flex: none; width: 44px; height: 44px; object-fit: cover; border-radius: var(--r-md); border: 1px solid var(--border); background: var(--canvas); }
.it-thumb + .it-name { flex: 1; }   /* photo, name, balance: the name takes the middle */
.it-name small { display: block; font-weight: 400; font-size: .8125rem; }
.it-bal { flex: none; display: flex; gap: var(--s2); align-items: baseline; font-weight: 600; white-space: nowrap; }
.it-bal small { font-weight: 400; }
.it-bal .badge { align-self: center; }
.it-bal.is-zero { color: var(--danger); }

.panel { position: sticky; top: calc(var(--topbar-h) + var(--s4)); }
.panel-empty { display: grid; justify-items: center; gap: var(--s2); padding: var(--s6) var(--s4); text-align: center; color: var(--secondary); }
.panel-empty .i { width: 40px; height: 40px; color: var(--primary-line); stroke-width: 1.5; margin-bottom: var(--s2); }
.panel-empty h2 { font-size: 1.125rem; color: var(--ink); }
.chosen { display: flex; gap: var(--s3); justify-content: space-between; align-items: flex-start; margin: calc(var(--s2) * -1) 0 var(--s4); }
.chosen-name { font-size: 1.25rem; font-weight: 600; line-height: 1.35; text-wrap: balance; }
.chosen-meta { color: var(--muted); font-size: .875rem; }

/* the signature: how full the shelf is, now and after this entry, with the reorder line */
.gauge { margin-bottom: var(--s5); padding: var(--s4); border-radius: var(--r-lg); background: var(--canvas); }
.gauge-nums { display: flex; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s3); }
.gauge-nums small { display: block; font-size: .8125rem; }
.gauge-nums b { display: block; font-size: 1.5rem; line-height: 1.25; font-weight: 700; }
.gauge-nums span { display: block; font-size: .8125rem; color: var(--secondary); }
.gauge-after { text-align: right; }
.gauge-after b { color: var(--primary-hover); }
.gauge-after b.is-short { color: var(--danger); }
.meter { --fill: 0%; --d0: 0%; --d1: 0%; --tick: -10%; position: relative; height: 16px; border-radius: 999px; background: #e5e7eb; overflow: visible; }
.meter-fill, .meter-delta { position: absolute; top: 0; bottom: 0; border-radius: 999px; transition: width .25s cubic-bezier(.16, 1, .3, 1), left .25s cubic-bezier(.16, 1, .3, 1); }
.meter-fill { left: 0; width: var(--fill); background: var(--primary); }
.meter-delta { left: var(--d0); width: calc(var(--d1) - var(--d0)); }
.meter[data-dir=in] .meter-delta { background: repeating-linear-gradient(-45deg, var(--primary) 0 4px, var(--primary-line) 4px 8px); }
.meter[data-dir=out] .meter-delta { background: repeating-linear-gradient(-45deg, #c5cad3 0 4px, #e5e7eb 4px 8px); box-shadow: inset 0 0 0 1px #c5cad3; }
.meter.is-low .meter-fill { background: var(--warning-fill); }
.meter-tick { position: absolute; top: -5px; bottom: -5px; left: var(--tick); width: 2px; margin-left: -1px; background: var(--ink); border-radius: 1px; }
.meter-legend { margin-top: var(--s2); font-size: .8125rem; color: var(--secondary); }
@media (prefers-reduced-motion: reduce) { .meter-fill, .meter-delta { transition: none; } }

.units { display: flex; gap: var(--s2); margin: 0 0 var(--s4); padding: 0; border: 0; }
.units legend { padding: 0; margin-bottom: var(--s1); font-size: .875rem; font-weight: 500; }
.unit-box { flex: 1; display: flex; gap: var(--s2); align-items: center; min-height: 48px; margin: 0; padding: 0 var(--s3); border: 1px solid var(--control); border-radius: var(--r-md); font-size: .9375rem; cursor: pointer; }
.unit-box input { width: 18px; height: 18px; min-height: 0; margin: 0; flex: none; }
.unit-box:has(input:checked) { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-hover); font-weight: 600; }
.qty-wrap { position: relative; }
.qty-wrap input { min-height: 56px; padding-right: 7rem; font-size: 1.5rem; font-weight: 600; border-radius: var(--r-lg); }
.qty-unit { position: absolute; right: var(--s4); top: 50%; translate: 0 -50%; color: var(--secondary); font-weight: 500; pointer-events: none; }
.date-pick { margin-bottom: var(--s4); font-size: .875rem; color: var(--secondary); }
.date-pick summary { cursor: pointer; width: fit-content; }
.date-pick[open] summary { margin-bottom: var(--s2); }
.date-pick input { max-width: 11rem; }
.today { margin-top: var(--s4); }

/* ---------- item page ---------- */
.item-head { display: grid; gap: var(--s4); }
.item-photo { width: 120px; height: 120px; object-fit: cover; border-radius: var(--r-md); border: 1px solid var(--border); background: var(--canvas); }
.chosen-photo { flex: none; width: 96px; height: 96px; object-fit: cover; border-radius: var(--r-md); border: 1px solid var(--border); background: var(--canvas); }
.chosen-text { flex: 1; min-width: 0; }
.chosen-photo[hidden] { display: none; }
.item-head h1 { font-size: 1.375rem; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--s3); margin: 0; }
.facts div { padding: var(--s3) var(--s4); border-radius: var(--r-md); background: var(--canvas); }
.facts dt { font-size: .8125rem; color: var(--muted); }
.facts dd { margin: 0; font-weight: 500; }
.facts dd b { font-size: 1.25rem; }
.facts dd small { display: block; }
.void summary { list-style: none; }
.void summary::-webkit-details-marker { display: none; }
.void-form { display: grid; gap: var(--s2); width: 15rem; margin-top: var(--s2); }
.void-form label { margin: 0; }

/* ---------- forms (เพิ่ม/แก้สินค้า): from lll-hr app.css "forms" so the two apps match ---------- */
.form, .form-section, .error-summary { max-width: 760px; }
.form { margin-inline: auto; }
.form-head { margin-bottom: var(--s4); }
.form-head p { margin-top: var(--s1); font-size: .875rem; color: var(--muted); }
.fields { display: grid; gap: var(--s4); align-content: start; }
.fields .field { margin: 0; }
.fields .row { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr)); gap: var(--s4); align-items: start; }
.req-note { margin: 0 0 var(--s4); font-size: .875rem; color: var(--muted); }
input.w-num { max-width: 9rem; } input.w-code { max-width: 16rem; }
.field.has-error :is(input, select, textarea) { border-color: var(--danger); }
.field.check label { display: flex; gap: var(--s2); align-items: center; min-height: 40px; margin: 0; font-size: .9375rem; cursor: pointer; }
.field.check input { width: 18px; height: 18px; min-height: 0; margin: 0; flex: none; }
.error-summary { margin-bottom: var(--s4); padding: var(--s4); color: var(--danger); background: var(--danger-bg); border: 1px solid var(--danger); border-radius: var(--r-md); }
.error-summary h2 { display: flex; gap: var(--s2); align-items: center; font-size: 1rem; }
.error-summary ul { margin: var(--s2) 0 0; padding-left: var(--s5); }
.error-summary a { color: inherit; font-weight: 500; }
.error-summary:focus { outline: none; }
.actionbar { position: sticky; bottom: 0; z-index: 5; display: flex; gap: var(--s2); justify-content: flex-end; padding: var(--s3) 0; margin-top: var(--s4); background: var(--canvas); border-top: 1px solid var(--border); }

/* ---------- ประเภท ที่เก็บ แผนก: one small form per row ---------- */
.setup-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr)); gap: var(--s4); align-items: start; margin-bottom: var(--s4); }
.setup-grid > .card { margin: 0; }
.setup-list { list-style: none; margin: 0; padding: 0; }
.setup-list li { padding: var(--s3) var(--s5); border-bottom: 1px solid var(--border); }
.setup-list li:last-child { border-bottom: 0; }
.setup-new { background: var(--canvas); }
.setup-row { display: grid; grid-template-columns: minmax(0, 1fr) 4.5rem auto; gap: var(--s1) var(--s2); align-items: center; }
.setup-row.no-order { grid-template-columns: minmax(0, 1fr) auto; }
.setup-row .setup-used, .setup-row .err { grid-column: 1 / -1; margin: 0; }
.setup-used { font-size: .8125rem; }
@media (max-width: 767px) { .setup-list li { padding: var(--s3) var(--s4); } }

@media (max-width: 1023px) {
  .counter { grid-template-columns: minmax(0, 1fr); }
  .panel { position: static; }
  .picker { max-height: 60vh; }
}
@media (max-width: 767px) {
  .kind { flex: 1 1 auto; justify-content: center; padding: 0 var(--s3); font-size: 1rem; }
  .card-head, th:first-child, td:first-child { padding-left: var(--s4); }
  .gauge-nums b { font-size: 1.25rem; }
}

/* ---------- movements (รายการเคลื่อนไหว) ---------- */
.mv-filter { display: grid; grid-template-columns: repeat(2, minmax(9rem, 11rem)) repeat(2, minmax(10rem, 1fr)) minmax(12rem, 1.5fr); gap: var(--s2) var(--s3); align-items: end; padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border); }
.mv-filter .field { margin: 0; }
.mv-help { grid-column: 1 / -1; margin: 0; }
.mv-voided { grid-column: 1 / -1; display: flex; gap: var(--s2); align-items: center; margin: 0; font-weight: 400; color: var(--secondary); }
.mv-voided input { width: 16px; height: 16px; min-height: 0; }
.mv-totals { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s6); padding: var(--s3) var(--s5); border-bottom: 1px solid var(--border); background: var(--canvas); }
.mv-totals p { display: flex; gap: var(--s2); align-items: baseline; }
.mv-totals span { color: var(--secondary); font-size: .875rem; }
.mv-totals small { font-size: .875rem; }
table.mv td { white-space: nowrap; }
table.mv td.name, table.mv td.note { white-space: normal; }
table.mv td.name { min-width: 14rem; }
.pager { display: flex; gap: var(--s3); align-items: center; justify-content: center; padding: var(--s3); border-top: 1px solid var(--border); font-size: .875rem; color: var(--secondary); }
@media (max-width: 1023px) { .mv-filter { grid-template-columns: 1fr 1fr; } .mv-q { grid-column: 1 / -1; } }

/* ---------- dashboard (ภาพรวม) ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s4); margin-bottom: var(--s4); }
.kpi { display: flex; flex-direction: column; gap: var(--s1); margin: 0; padding: var(--s4) var(--s5); color: var(--ink); text-decoration: none; transition: border-color .15s; }
.kpi:hover { border-color: var(--primary-line); }
.kpi-label { font-size: .875rem; font-weight: 500; color: var(--secondary); }
.kpi-val { font-size: 1.75rem; font-weight: 700; line-height: 1.25; }
.kpi-val small { font-size: .875rem; font-weight: 500; color: var(--muted); }
.kpi-foot { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; justify-content: space-between; min-height: 36px; }
.kpi-foot small { font-size: .8125rem; }
.kpi-foot.is-badges { justify-content: flex-start; }
.kpi-cmp { font-size: .8125rem; color: var(--muted); }
.kpi.is-alert .kpi-val { color: var(--danger); }
.chip { display: inline-flex; padding: 1px 10px; border-radius: 999px; font-size: .8125rem; font-weight: 500; background: var(--neutral-bg); color: var(--secondary); white-space: nowrap; }
.spark-wrap { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; }
.spark { width: 120px; height: 36px; flex: none; }
/* same hues as the จ่ายออก / รับเข้า tags (.kind-out, .kind-in): one colour per kind across the page */
.spark polyline { fill: none; stroke: #1e40af; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark.in polyline { stroke: #155e75; }
.dash-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(280px, .8fr); gap: var(--s4); margin-bottom: var(--s4); align-items: start; }
.dash-grid.no-orders { grid-template-columns: minmax(0, 2fr) minmax(280px, .8fr); }
.dash-grid > .card { margin: 0; }
.card-head .open { display: inline-flex; gap: var(--s1); align-items: center; font-size: .875rem; font-weight: 500; text-decoration: none; }
.card-head .open .i { width: 16px; height: 16px; }
.card-head.bare { padding: 0 0 var(--s3); border: 0; }
.card-note { padding: var(--s3) var(--s5); border-top: 1px solid var(--border); font-size: .8125rem; color: var(--muted); }
.card-note a { white-space: nowrap; }
table.mini td { height: 46px; }
table.mini td.r { white-space: nowrap; }
/* number and unit in separate columns so the numbers line up whatever the unit's length */
table.mini .qty { padding-right: 0; }
table.mini .unit { padding-left: 6px; white-space: nowrap; font-size: .8125rem; color: var(--muted); }
table.mini td.name a { display: block; margin: calc(var(--s2) * -1) 0; padding: var(--s2) 0; color: var(--ink); text-decoration: none; font-weight: 500; }
table.mini td.name:has(> .badge) a { display: inline-block; }   /* status badge sits on the same line as the name */
table.mini td.name a + .badge { margin-left: var(--s2); vertical-align: middle; }
table.mini td.name a:hover { color: var(--primary); text-decoration: underline; }
.m-only { display: none; }
/* คงเหลือ is a plain number: the badge beside the name already says หมดแล้ว / เหลือน้อย. 0 is red, as on the counter (.it-bal.is-zero). */
table.mini .qty b { font-weight: 600; }
table.mini .qty .is-zero { color: var(--danger); }.dash-search { width: 260px; }
.cat-card { padding: var(--s4) var(--s5); }
.cat-bars { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s3); font-size: .875rem; }
.cat-bars li { display: grid; grid-template-columns: minmax(0, 1fr) 3em 5.5em; gap: var(--s1) var(--s2); align-items: baseline; }
.cat-bars .cb-name { color: var(--secondary); }
.cat-bars .cb-pct { text-align: right; color: var(--muted); }
.cat-bars b { text-align: right; font-weight: 600; white-space: nowrap; }
.cb-track { grid-column: 1 / -1; height: 8px; border-radius: 999px; background: var(--neutral-bg); }
.cb-track span { display: block; height: 100%; min-width: 4px; border-radius: inherit; }
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash-grid, .dash-grid.no-orders { grid-template-columns: 1fr 1fr; }
  .cat-card { grid-column: 1 / -1; }
  .dash-grid.no-orders .cat-card { grid-column: auto; }
}
@media (max-width: 767px) {
  .kpis { gap: var(--s2); }
  .kpi { padding: var(--s3); }
  .kpi-val { font-size: 1.25rem; }
  .kpi-foot { min-height: 0; justify-content: flex-start; }
  .spark-wrap { display: none; }
  .dash-grid, .dash-grid.no-orders { grid-template-columns: 1fr; }
  .dash-grid.no-orders .cat-card { grid-column: 1 / -1; }
  .dash-search { width: 100%; }
  .card-head .open { min-height: 44px; margin: -10px 0; }
  .card-note { padding: var(--s3) var(--s4); }
}
@media (max-width: 1023px) {
  table.mini .use { display: none; }
}
@media (max-width: 1180px) {
  /* table.stack (รายการล่าสุด, รายการเคลื่อนไหว): each row becomes a block, no sideways scroll.
     Both tables share columns 1–6 (date, kind, name, qty, value, dept); the last column (ผู้บันทึก) is dropped
     and an optional td.note gets its own full-width line. */
  .stack thead { display: none; }
  .stack, .stack tbody { display: block; }
  .stack tr { display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto; grid-template-areas: "name name name qty" "kind date dept val"; gap: var(--s1) var(--s2); align-items: center; padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border); }
  .stack tr:last-child { border-bottom: 0; }
  table.stack td { display: block; height: auto; min-width: 0; max-width: none; padding: 0; border: 0; white-space: normal; font-size: .8125rem; color: var(--secondary); }
  table.stack td:nth-child(1) { grid-area: date; white-space: nowrap; }
  table.stack td:nth-child(2) { grid-area: kind; }
  table.stack td:nth-child(3) { grid-area: name; font-size: .9375rem; }
  table.stack td:nth-child(3) a { display: block; margin: -11px 0; padding: 11px 0; }  /* 44px tap target */
  table.stack td:nth-child(4) { grid-area: qty; font-size: .9375rem; color: var(--ink); font-weight: 500; }
  table.stack td:nth-child(5) { grid-area: val; }
  table.stack td:nth-child(6) { grid-area: dept; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  table.stack td.note { grid-column: 1 / -1; }
  table.stack td.note.is-empty, table.stack td:last-child { display: none; }
  .stack .m-only { display: inline; }
}
