/* สั่งชา Stock — minimal theme */
:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --subtle: #f5f5f4;
  --ink: #18181b;
  --ink-2: #57534e;
  --ink-3: #a8a29e;
  --line: #eceae7;
  --line-2: #e2dfdb;
  --accent: #3f6b4f;          /* เขียวชา */
  --accent-soft: #eef3ef;
  --ok: #3f7d55;   --ok-bg: #eef6f0;
  --warn: #a16207; --warn-bg: #fdf6e7;
  --bad: #c2410c;  --bad-bg: #fdf0ea;
  --info: #44607a; --info-bg: #eef2f6;
  --radius: 14px;
  --radius-s: 10px;
  --font: "IBM Plex Sans Thai", "Noto Sans Thai", "Sarabun", "Leelawadee UI", "Thonburi", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--ink); font-size: 14.5px; line-height: 1.55; -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
a { color: var(--ink); }
h1 { font-size: 24px; font-weight: 600; margin: 0; letter-spacing: -.015em; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 12px; }
h3 { font-size: 16px; font-weight: 600; margin: 0; }
small, .muted { color: var(--ink-3); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
svg.i { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

/* ----- layout ----- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 22px 14px 16px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.brand { font-weight: 600; font-size: 16px; display: flex; align-items: center; gap: 10px; padding: 0 10px 26px; letter-spacing: -.01em; }
.brand small { font-weight: 400; color: var(--ink-3); font-size: 13px; }
.logo { width: 28px; height: 28px; border-radius: 8px; background: var(--ink); color: #fff; display: grid; place-items: center; }
.logo svg { width: 16px; height: 16px; stroke: #fff; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.brand.big { font-size: 20px; justify-content: center; padding: 0 0 6px; }
.brand.big .logo { width: 34px; height: 34px; }
#nav { display: flex; flex-direction: column; gap: 1px; flex: 1; overflow-y: auto; }
#nav a { color: var(--ink-2); text-decoration: none; padding: 8px 10px; border-radius: 9px; display: flex; align-items: center; gap: 11px; font-size: 14px; transition: background .12s, color .12s; }
#nav a:hover { background: var(--subtle); color: var(--ink); }
#nav a.active { background: var(--subtle); color: var(--ink); font-weight: 600; }
#nav a.active svg.i { color: var(--accent); }
#nav .sep { height: 0; margin: 10px 0; }
#nav .badge-n { margin-left: auto; background: var(--ink); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 7px; line-height: 18px; font-weight: 600; }
.me { border-top: 1px solid var(--line); padding: 14px 10px 0; font-size: 13.5px; display: flex; flex-direction: column; gap: 6px; }
.me .row { gap: 12px; }
.me .link { color: var(--ink-3); font-size: 12.5px; text-decoration: none; }
.me .link:hover { color: var(--ink); }
.topbar { display: none; }
main { padding: 36px 44px 80px; max-width: 1320px; width: 100%; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 28px; flex-wrap: wrap; }
.page-head .sub { color: var(--ink-3); font-size: 13.5px; margin-top: 4px; }
.page-head .link { font-size: 13px; color: var(--ink-3); text-decoration: none; display: inline-block; margin-bottom: 6px; }
.page-head .link:hover { color: var(--ink); }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.gap-s { gap: 6px; }
.spacer { flex: 1; }
.grid { display: grid; gap: 20px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0; margin-bottom: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.kpis > .kpi { border: none; border-radius: 0; border-right: 1px solid var(--line); }
.kpis > .kpi:last-child { border-right: none; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2, .card.flush > .card-head { padding: 18px 22px 6px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; text-decoration: none; color: inherit; display: block; transition: background .12s; }
a.kpi:hover { background: #fcfcfb; }
.kpi .label { color: var(--ink-3); font-size: 12.5px; }
.kpi .value { font-size: 28px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.025em; margin-top: 6px; line-height: 1.15; }
.kpi .hint { font-size: 12px; color: var(--ink-3); margin-top: 4px; }
.kpi.bad .value { color: var(--bad); }
.kpi.warn .value { color: var(--warn); }

/* ----- table ----- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th:first-child, td:first-child { padding-left: 22px; }
th:last-child, td:last-child { padding-right: 22px; }
th { font-weight: 500; color: var(--ink-3); font-size: 12.5px; background: var(--surface); position: sticky; top: 0; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: #fcfbfa; }
tr.click { cursor: pointer; }
tfoot td { font-weight: 600; border-top: 1px solid var(--line-2); border-bottom: none; }
td.empty { text-align: center; color: var(--ink-3); padding: 40px 20px; }
table input, table select { padding: 6px 9px; font-size: 14px; height: 34px; }
td .sku { color: var(--ink-3); font-size: 12px; display: block; margin-top: 1px; }
td b { font-weight: 500; }
td a, .bar-list a { color: var(--ink); text-decoration: none; }
td a:hover, .bar-list a:hover { color: var(--accent); }

/* ----- product images ----- */
.thumb { width: 40px; height: 40px; border-radius: 10px; flex-shrink: 0; object-fit: cover; background: var(--subtle); border: 1px solid var(--line); display: inline-grid; place-items: center; }
.thumb.ph { color: var(--ink-2); font-weight: 600; font-size: 15px; border-color: transparent; }
.thumb.xs { width: 24px; height: 24px; border-radius: 6px; font-size: 11px; }
.thumb.sm { width: 32px; height: 32px; border-radius: 8px; font-size: 13px; }
.thumb.lg { width: 88px; height: 88px; border-radius: 14px; font-size: 30px; }
.thumb.xl { width: 72px; height: 72px; border-radius: 16px; font-size: 26px; }
.cell-item { display: flex; align-items: center; gap: 12px; }
.cell-item > div { min-width: 0; }
.head-item { display: flex; align-items: center; gap: 18px; }
.thumb-btn { padding: 0; border: none; background: none; cursor: pointer; border-radius: 16px; transition: opacity .12s; }
.thumb-btn:hover { opacity: .85; }
.img-pick { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.photo-lg { width: 100%; max-width: 480px; aspect-ratio: 1; object-fit: cover; border-radius: 14px; display: block; margin: 0 auto; }
.line .stock-hint { display: flex; align-items: center; gap: 8px; }

/* ----- badges (dot style) ----- */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; padding: 1px 9px 1px 8px; border-radius: 99px; white-space: nowrap; background: var(--subtle); color: var(--ink-2); vertical-align: 1px; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.b-ok { background: var(--ok-bg); color: var(--ok); }
.b-warn { background: var(--warn-bg); color: var(--warn); }
.b-bad { background: var(--bad-bg); color: var(--bad); }
.b-info { background: var(--info-bg); color: var(--info); }
.b-mute { background: var(--subtle); color: var(--ink-3); }
.t-pos { color: var(--ok); } .t-neg { color: var(--bad); }

/* ----- forms ----- */
label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--ink-2); font-weight: 500; }
input, select, textarea { font: inherit; font-size: 14.5px; padding: 0 12px; height: 40px; border: 1px solid var(--line-2); border-radius: var(--radius-s); background: var(--surface); color: var(--ink); width: 100%; min-width: 0; transition: border-color .12s, box-shadow .12s; }
textarea { padding: 10px 12px; height: auto; }
select { appearance: none; padding-right: 32px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a8a29e' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 11px center; }
input::placeholder { color: var(--ink-3); }
input:hover, select:hover, textarea:hover { border-color: #d3cfca; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(24,24,27,.06); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--ink); padding: 0; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-2); font-weight: 400; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px 16px; }
.form-grid .wide { grid-column: 1 / -1; }
fieldset { border: none; border-top: 1px solid var(--line); padding: 16px 0 6px; margin: 0 0 6px; }
fieldset:first-of-type { border-top: none; padding-top: 0; }
legend { font-size: 12px; font-weight: 600; color: var(--ink-3); padding: 0 0 10px; float: left; width: 100%; }
legend + * { clear: both; }
.help { font-size: 11.5px; color: var(--ink-3); font-weight: 400; }
.error { color: var(--bad); font-size: 13.5px; min-height: 1em; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.filters input, .filters select { width: auto; min-width: 150px; }
.filters input[type=checkbox] { min-width: 0; width: 16px; }
.filters input[type=search] { min-width: 240px; flex: 1; max-width: 340px; padding-left: 36px; background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='%23a8a29e' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 12px center; }
.filters label.check { margin-left: 6px; }

.btn { font: inherit; font-size: 13.5px; font-weight: 500; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); height: 36px; padding: 0 14px; border-radius: var(--radius-s); cursor: pointer; display: inline-flex; align-items: center; gap: 7px; text-decoration: none; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn svg.i { width: 16px; height: 16px; }
.btn:hover { background: var(--subtle); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: #2e2e33; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-bg); border-color: #f1d3c6; }
.btn.small { height: 30px; padding: 0 11px; font-size: 12.5px; }
.btn.block { width: 100%; justify-content: center; height: 44px; font-size: 15px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.link { background: none; border: none; padding: 0; font: inherit; color: var(--ink-2); cursor: pointer; }
.icon-btn { background: none; border: none; cursor: pointer; width: 34px; height: 34px; color: var(--ink-3); border-radius: 8px; display: inline-grid; place-items: center; font-size: 16px; }
.icon-btn:hover { background: var(--subtle); color: var(--ink); }
.tabs { display: flex; gap: 22px; border-bottom: 1px solid var(--line); margin-bottom: 22px; overflow-x: auto; }
.tabs a { padding: 0 0 11px; text-decoration: none; color: var(--ink-3); border-bottom: 1.5px solid transparent; white-space: nowrap; font-size: 14px; margin-bottom: -1px; }
.tabs a:hover { color: var(--ink); }
.tabs a.active { color: var(--ink); border-color: var(--ink); font-weight: 500; }
.seg { display: inline-flex; background: var(--subtle); border-radius: var(--radius-s); padding: 3px; gap: 2px; }
.seg button { font: inherit; font-size: 13.5px; border: none; background: transparent; color: var(--ink-2); height: 32px; padding: 0 14px; cursor: pointer; border-radius: 8px; }
.seg button.on { background: var(--surface); color: var(--ink); font-weight: 500; box-shadow: 0 1px 2px rgba(0,0,0,.06), 0 0 0 1px var(--line); }

/* ----- lines editor ----- */
.lines { display: flex; flex-direction: column; gap: 0; border: 1px solid var(--line); border-radius: var(--radius-s); }
.line { position: relative; display: grid; grid-template-columns: 2.4fr 1fr 1fr 1.1fr 1fr auto; gap: 10px; align-items: end; padding: 14px; border-bottom: 1px solid var(--line); }
.line:last-child { border-bottom: none; }
.line.issue { grid-template-columns: 3fr 1.2fr 1.6fr auto; }
.line .stock-hint { font-size: 12.5px; color: var(--ink-3); grid-column: 1 / -1; margin-top: -2px; }
.line .stock-hint b { color: var(--ink-2); font-weight: 500; }
.line .stock-hint:empty { display: none; }
.add-line { margin: 12px 0 22px; }

/* ----- login ----- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--bg); }
.login-card { width: 100%; max-width: 360px; background: var(--surface); padding: 34px 30px 30px; border-radius: 18px; border: 1px solid var(--line); display: flex; flex-direction: column; gap: 16px; }
.login-card .tagline { text-align: center; color: var(--ink-3); font-size: 13px; margin: -8px 0 6px; }

/* ----- modal / toast ----- */
.modal { position: fixed; inset: 0; background: rgba(24,24,27,.28); backdrop-filter: blur(2px); display: grid; place-items: center; padding: 16px; z-index: 50; animation: fade .12s; }
.modal-card { background: var(--surface); border-radius: 18px; width: 100%; max-width: 660px; max-height: 92vh; overflow-y: auto; padding: 24px 26px 24px; box-shadow: 0 24px 64px rgba(0,0,0,.14); animation: pop .16s ease-out; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.99); } }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(16px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 11px; font-size: 14px; opacity: 0; pointer-events: none; transition: .18s; z-index: 60; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.err { background: var(--bad); }

/* ----- chart ----- */
.chart svg { width: 100%; height: auto; display: block; }
.chart .legend { display: flex; gap: 16px; font-size: 12px; color: var(--ink-3); margin-top: 10px; }
.chart .legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
.bar-list { display: flex; flex-direction: column; gap: 12px; }
.bar-list .bl-row { display: grid; grid-template-columns: 1fr auto; gap: 5px 10px; font-size: 14px; }
.bar-list .bl-bar { grid-column: 1 / -1; height: 4px; background: var(--subtle); border-radius: 2px; overflow: hidden; }
.bar-list .bl-bar span { display: block; height: 100%; background: var(--ink); border-radius: 2px; }
.bar-list.waste .bl-bar span { background: var(--bad); }

.meter { height: 4px; background: var(--subtle); border-radius: 2px; overflow: hidden; min-width: 60px; }
.meter span { display: block; height: 100%; }
.dl { display: grid; grid-template-columns: auto 1fr; gap: 9px 22px; font-size: 14px; margin: 0; }
.dl dt { color: var(--ink-3); }
.dl dd { margin: 0; }
.callout { background: var(--subtle); border-radius: var(--radius-s); padding: 12px 16px; font-size: 13.5px; color: var(--ink-2); }
.callout summary { cursor: pointer; color: var(--ink); }
.callout.warn { background: var(--warn-bg); color: var(--warn); }
pre.code { font-size: 12px; overflow-x: auto; background: var(--subtle); padding: 12px; border-radius: var(--radius-s); }

/* ----- responsive ----- */
@media (max-width: 1100px) { main { padding: 28px 28px 70px; } }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 40; left: 0; top: 0; width: 264px; transform: translateX(-100%); transition: transform .2s; }
  .app.menu-open .side { transform: none; box-shadow: 0 0 0 100vmax rgba(24,24,27,.25); }
  .topbar { display: flex; align-items: center; justify-content: space-between; background: rgba(255,255,255,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); padding: 8px 10px; position: sticky; top: 0; z-index: 30; }
  .topbar .brand { padding: 0; font-size: 15px; }
  .topbar .logo { width: 24px; height: 24px; }
  main { padding: 20px 16px 70px; }
  h1 { font-size: 21px; }
  .page-head { margin-bottom: 20px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpis > .kpi { border-bottom: 1px solid var(--line); }
  .kpi .value { font-size: 23px; }
  .line, .line.issue { grid-template-columns: 1fr 1fr; }
  .line > :first-child { grid-column: 1 / -1; padding-right: 38px; }
  .line [data-rm] { position: absolute; top: 10px; right: 8px; }
  .hide-sm { display: none; }
  .thumb.xl { width: 56px; height: 56px; font-size: 21px; }
  .head-item { gap: 14px; }
  td:first-child { min-width: 150px; }
  th, td { padding: 10px 10px; }
  th:first-child, td:first-child { padding-left: 16px; }
  th:last-child, td:last-child { padding-right: 16px; }
  .filters input[type=search] { min-width: 0; max-width: none; width: 100%; }
  .card { padding: 18px; }
}

/* ----- print ----- */
@media print {
  .side, .topbar, .no-print, .btn, .tabs { display: none !important; }
  .app { display: block; }
  main { padding: 0; }
  .card { border: none; padding: 0; }
  body { background: #fff; font-size: 12.5px; }
}

/* =====================================================================
   MOBILE UI  (body.mobile — แยกจากหน้าจอคอมพิวเตอร์)
   ===================================================================== */
.m-appbar, .m-tabbar { display: none; }
.to-mobile { display: none; color: var(--ink-3); font-size: 12.5px; text-align: left; }
@media (max-width: 900px) { .to-mobile { display: block; } }

body.mobile { background: #f6f5f3; -webkit-tap-highlight-color: transparent; }
body.mobile .app { display: block; min-height: 100vh; }
body.mobile .side, body.mobile .topbar { display: none !important; }
body.mobile main { padding: 8px 14px calc(96px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }
body.mobile .page-head h1, body.mobile .page-head .link { display: none; }
body.mobile .page-head { margin: 6px 0 14px; }
body.mobile input, body.mobile select, body.mobile textarea { font-size: 16px; } /* iOS ไม่ซูมอัตโนมัติ */

body.mobile .m-appbar { display: flex; align-items: center; gap: 4px; position: sticky; top: 0; z-index: 30; height: calc(54px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 6px 0; background: rgba(246,245,243,.88); backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px); border-bottom: 1px solid transparent; }
.m-appbar h1 { flex: 1; font-size: 17px; font-weight: 600; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-appbar .icon-btn { width: 40px; height: 40px; color: var(--ink); }
.m-appbar .icon-btn svg.i { width: 22px; height: 22px; }
#m-action { min-width: 40px; display: flex; justify-content: flex-end; }

body.mobile .m-tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 35; background: rgba(255,255,255,.94); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
.m-tab { display: flex; flex-direction: column; align-items: center; gap: 3px; font: inherit; font-size: 11px; color: var(--ink-3); text-decoration: none; background: none; border: none; padding: 4px 0; cursor: pointer; }
.m-tab svg.i { width: 23px; height: 23px; }
.m-tab.on { color: var(--ink); font-weight: 600; }
.m-tab.on svg.i { color: var(--accent); }
.m-tab.fab { margin-top: -18px; color: var(--ink-2); }
.m-tab .fab-ic { width: 50px; height: 50px; border-radius: 50%; background: var(--ink); color: #fff; display: grid; place-items: center; box-shadow: 0 6px 16px rgba(24,24,27,.22); }
.m-tab .fab-ic svg.i { color: #fff !important; width: 24px; height: 24px; }

/* lists & rows */
.m-list { background: var(--surface); border-radius: 16px; overflow: hidden; margin-bottom: 14px; border: 1px solid var(--line); }
.m-list.flat { border: none; border-radius: 0; background: none; }
.m-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; text-decoration: none; color: var(--ink); background: none; border: none; border-bottom: 1px solid var(--line); font: inherit; text-align: left; cursor: pointer; min-height: 60px; }
.m-row:last-child { border-bottom: none; }
.m-row:active:not(.static) { background: var(--subtle); }
.m-row > svg.i { color: var(--ink-3); width: 16px; height: 16px; }
.m-row-main { flex: 1; min-width: 0; }
.m-row-title { font-size: 15px; font-weight: 500; line-height: 1.35; display: flex; align-items: center; gap: 7px; }
.m-row-title small { font-weight: 400; }
.m-row-sub { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-row-right { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; text-align: right; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.m-row-right b { font-size: 16px; font-weight: 600; }
.m-row-right small { color: var(--ink-3); font-size: 11.5px; }
.m-row .badge-n { background: var(--ink); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 7px; line-height: 18px; font-weight: 600; }
.m-empty { padding: 26px 16px; text-align: center; color: var(--ink-3); font-size: 14px; }
.m-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: currentColor; display: inline-block; }
.m-dot.b-ok { color: #86b598; } .m-dot.b-warn { color: var(--warn); } .m-dot.b-bad { color: var(--bad); } .m-dot.b-info { color: var(--info); } .m-dot.b-mute { color: var(--ink-3); }
.t-warn { color: var(--warn); }
.m-ic { width: 38px; height: 38px; border-radius: 11px; background: var(--subtle); display: grid; place-items: center; flex-shrink: 0; color: var(--ink-2); }
.m-ic.ok { background: var(--ok-bg); color: var(--ok); } .m-ic.info { background: var(--info-bg); color: var(--info); } .m-ic.bad { background: var(--bad-bg); color: var(--bad); }
.m-sec { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 4px 8px; }
.m-sec h3 { font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 0; }
.m-sec a { font-size: 13px; color: var(--accent); text-decoration: none; }
.m-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; margin-bottom: 14px; }
.m-note { font-size: 13px; color: var(--ink-2); background: var(--subtle); border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; }
.m-foot { text-align: center; font-size: 12px; color: var(--ink-3); margin: 20px 12px; }

/* home */
.m-hello { margin: 10px 4px 16px; }
.m-hello h2 { font-size: 24px; font-weight: 600; margin: 2px 0 0; letter-spacing: -.02em; }
.m-quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.m-quick a { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 4px 11px; text-decoration: none; color: var(--ink); font-size: 12.5px; }
.m-quick a:active { background: var(--subtle); }
.m-quick svg.i { width: 24px; height: 24px; color: var(--accent); }
.m-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.m-stats a { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; text-decoration: none; color: var(--ink); display: flex; flex-direction: column; }
.m-stats b { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.2; }
.m-stats span { font-size: 12px; color: var(--ink-3); }
.m-stats .bad b { color: var(--bad); } .m-stats .warn b { color: var(--warn); }
.m-value { display: flex; justify-content: space-between; align-items: flex-end; background: var(--ink); color: #fff; border-radius: 16px; padding: 16px 18px; text-decoration: none; margin-bottom: 4px; }
.m-value small { display: block; color: #a1a1aa; font-size: 12px; }
.m-value b { font-size: 24px; font-weight: 600; letter-spacing: -.02em; }
.m-value .r { text-align: right; font-size: 14px; }

/* search, chips, sticky */
.m-sticky { position: sticky; top: calc(54px + env(safe-area-inset-top)); z-index: 20; background: #f6f5f3; padding: 4px 0 10px; margin: 0 -14px 4px; padding-left: 14px; padding-right: 14px; }
.m-search { height: 44px; border-radius: 12px; background: #ebe9e5 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2378716c' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 13px center; border: none; padding-left: 38px; }
.m-search:focus { background-color: #fff; box-shadow: 0 0 0 2px var(--ink); }
.m-chips { display: flex; gap: 6px; overflow-x: auto; margin-top: 10px; scrollbar-width: none; }
.m-chips.wrap { flex-wrap: wrap; overflow: visible; }
.m-chips button { font: inherit; font-size: 13.5px; white-space: nowrap; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2); border-radius: 99px; padding: 6px 13px; cursor: pointer; }
.m-chips button.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.m-progress { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 13px; }
.m-progress .meter { flex: 1; height: 6px; }

/* item detail */
.m-hero { text-align: center; padding: 10px 0 4px; }
.m-hero h2 { font-size: 21px; font-weight: 600; margin: 12px 0 2px; }
.m-hero small { color: var(--ink-3); }
.thumb.hero { width: 132px; height: 132px; border-radius: 28px; font-size: 48px; }
.m-bigqty { text-align: center; margin: 14px 0; display: flex; flex-direction: column; }
.m-bigqty b { font-size: 40px; font-weight: 600; letter-spacing: -.03em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.m-bigqty span { color: var(--ink-3); font-size: 13px; }
.m-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.m-dl { display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; margin: 0; font-size: 14.5px; }
.m-dl dt { color: var(--ink-3); } .m-dl dd { margin: 0; text-align: right; }

/* transactions */
.m-seg { display: grid; grid-template-columns: repeat(3, 1fr); background: #ebe9e5; border-radius: 12px; padding: 3px; margin: 6px 0 14px; }
.m-seg button { font: inherit; font-size: 14px; border: none; background: none; height: 36px; border-radius: 9px; color: var(--ink-2); cursor: pointer; }
.m-seg button.on { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.m-lines { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.m-line { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px 14px; }
.m-line-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.m-line-qty { display: flex; gap: 10px; align-items: center; }
.m-stepper { display: flex; align-items: center; border: 1px solid var(--line-2); border-radius: 12px; overflow: hidden; flex: 1; height: 48px; }
.m-stepper button { width: 48px; height: 100%; border: none; background: var(--subtle); color: var(--ink); display: grid; place-items: center; cursor: pointer; }
.m-stepper button:active { background: var(--line); }
.m-stepper input { border: none; border-radius: 0; height: 100%; text-align: center; font-size: 20px !important; font-weight: 600; font-variant-numeric: tabular-nums; }
.m-stepper input:focus { box-shadow: none; }
.m-unit { display: flex; background: var(--subtle); border-radius: 10px; padding: 3px; }
.m-unit button { font: inherit; font-size: 13px; border: none; background: none; padding: 0 10px; height: 40px; border-radius: 8px; color: var(--ink-2); cursor: pointer; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-unit button.on { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.m-unit-txt { color: var(--ink-2); font-size: 14px; padding: 0 6px; }
.m-line > .m-row-sub { margin-top: 6px; }
.m-line-extra { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.m-line-extra label:only-child { grid-column: 1 / -1; }
.m-addline { width: 100%; height: 54px; border: 1.5px dashed var(--line-2); background: transparent; border-radius: 16px; font: inherit; font-size: 15px; color: var(--ink-2); display: flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; margin-bottom: 14px; }
.m-addline:active { background: var(--subtle); }
.m-form { display: flex; flex-direction: column; gap: 12px; }
.m-bottom { position: fixed; left: 0; right: 0; bottom: calc(66px + env(safe-area-inset-bottom)); z-index: 32; padding: 10px 14px; background: linear-gradient(rgba(246,245,243,0), #f6f5f3 30%); }
.m-bottom .btn { max-width: 612px; margin: 0 auto; height: 50px; border-radius: 14px; font-size: 16px; }
body.mobile main:has(.m-bottom) { padding-bottom: calc(160px + env(safe-area-inset-bottom)); }

/* count */
.m-count.done { background: #fbfdfb; }
.m-count.done .m-row-title::after { content: "✓"; color: var(--ok); font-weight: 700; margin-left: 2px; }
.m-count-in { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.m-count-in input { width: 96px; height: 46px; text-align: right; font-size: 19px !important; font-weight: 600; border-radius: 12px; font-variant-numeric: tabular-nums; }
.m-count.done .m-count-in input { border-color: #b9d6c3; background: #f4faf6; }
.m-count-in small { color: var(--ink-3); font-size: 12px; min-width: 26px; }

/* menu */
.m-user { display: flex; align-items: center; gap: 12px; padding: 8px 4px 16px; }
.m-user b { display: block; font-size: 17px; font-weight: 600; }
.m-user small { color: var(--ink-3); }

/* sheet */
.sheet { position: fixed; inset: 0; z-index: 55; background: rgba(24,24,27,.32); display: flex; align-items: flex-end; animation: fade .15s; }
.sheet-card { width: 100%; max-width: 640px; margin: 0 auto; background: #f6f5f3; border-radius: 22px 22px 0 0; padding: 8px 14px calc(16px + env(safe-area-inset-bottom)); max-height: 90vh; overflow-y: auto; animation: up .2s ease-out; }
.sheet-card.full { height: 100%; max-height: none; border-radius: 0; padding-top: calc(8px + env(safe-area-inset-top)); }
@keyframes up { from { transform: translateY(30px); opacity: .6; } }
.sheet-grip { width: 38px; height: 5px; border-radius: 3px; background: var(--line-2); margin: 2px auto 12px; }
.sheet-title { font-size: 17px; font-weight: 600; margin: 0 4px 12px; }
.sheet-head { display: flex; align-items: center; gap: 6px; height: 48px; margin-bottom: 6px; font-size: 16px; }
.sheet-card .m-search { margin-bottom: 10px; }
.sheet-card .m-list.flat .m-row { background: var(--surface); border-radius: 14px; border: none; margin-bottom: 6px; }

/* ปรับ modal ให้เป็น bottom sheet บนมือถือ */
body.mobile .modal { align-items: flex-end; padding: 0; }
body.mobile .modal-card { border-radius: 22px 22px 0 0; max-height: 92vh; padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
body.mobile .toast { bottom: calc(84px + env(safe-area-inset-bottom)); }

/* ----- ป๊อปอัปนับสต็อก (มือถือ) ----- */
.sheet.center { align-items: flex-start; padding: calc(9vh + env(safe-area-inset-top)) 14px 0; }
.sheet-card.center { border-radius: 22px; background: var(--surface); padding: 18px 18px 18px; max-width: 420px; animation: pop .18s ease-out; box-shadow: 0 24px 60px rgba(0,0,0,.18); }
.cp-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.cp-head .thumb.lg { width: 56px; height: 56px; border-radius: 14px; font-size: 20px; }
.cp-head .icon-btn { align-self: flex-start; margin: -6px -8px 0 0; }
.cp-name { font-size: 17px; font-weight: 600; line-height: 1.3; }
.cp-sys { display: flex; justify-content: space-between; background: var(--subtle); border-radius: 12px; padding: 10px 14px; font-size: 14px; color: var(--ink-2); margin-bottom: 14px; }
.cp-sys b { color: var(--ink); font-weight: 600; }
.cp-label { font-size: 13px; color: var(--ink-2); margin-bottom: 6px; }
.cp-field { display: flex; align-items: stretch; border: 1.5px solid var(--ink); border-radius: 16px; overflow: hidden; height: 76px; }
.cp-field input { flex: 1; border: none; border-radius: 0; height: 100%; font-size: 36px !important; font-weight: 600; text-align: right; padding: 0 10px 0 16px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.cp-field input:focus { box-shadow: none; }
.cp-field input::-webkit-outer-spin-button, .cp-field input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.cp-field input[type=number] { -moz-appearance: textfield; appearance: textfield; }
.cp-unit { align-self: center; color: var(--ink-3); font-size: 15px; padding-right: 12px; }
.cp-arrows { display: flex; flex-direction: column; width: 62px; border-left: 1px solid var(--line-2); }
.cp-arrows button { flex: 1; border: none; background: var(--subtle); color: var(--ink); display: grid; place-items: center; cursor: pointer; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.cp-arrows button + button { border-top: 1px solid var(--line-2); }
.cp-arrows button:active { background: var(--line-2); }
.cp-arrows svg.i { width: 22px; height: 22px; stroke-width: 2.2; }
.cp-diff { min-height: 20px; margin-top: 8px; font-size: 14px; color: var(--ink-2); text-align: right; }
.cp-err { color: var(--bad); font-size: 13.5px; min-height: 0; }
.cp-err:not(:empty) { margin-top: 4px; }
.cp-foot { display: flex; justify-content: space-between; gap: 10px; margin-top: 14px; }
.cp-foot .btn { height: 50px; border-radius: 14px; font-size: 16px; padding: 0 22px; }
.cp-foot .btn.primary { flex: 1; max-width: 62%; justify-content: center; }
.m-count .m-tap { color: var(--accent); font-size: 12.5px; }
.m-count[disabled] { cursor: default; opacity: 1; color: inherit; }
.m-quick.two { grid-template-columns: 1fr 1fr; }
.m-quick.two a { flex-direction: row; justify-content: center; gap: 10px; font-size: 15px; padding: 16px 8px; }
.m-actions.one { grid-template-columns: 1fr; }
.m-stats > div { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; display: flex; flex-direction: column; }
.m-stats .warn b { color: var(--warn); }
.m-range { display: flex; align-items: center; gap: 6px; margin: 6px 0 12px; }
.m-range input { height: 40px; font-size: 14px !important; padding: 0 8px; }
.m-range span { color: var(--ink-3); }
.m-range .btn { height: 40px; }
.m-row-right small + b { margin-top: -2px; }

/* ----- ป๊อปอัปนับสต็อก: แบบใช้มือเดียว (แผ่นจากขอบล่าง ปุ่มอยู่ในระยะนิ้วโป้ง) ----- */
.sheet-card.onehand { background: var(--surface); border-radius: 24px 24px 0 0; padding: 8px 16px calc(14px + env(safe-area-inset-bottom)); max-width: 520px; box-shadow: 0 -10px 40px rgba(0,0,0,.12); }
.sheet-card.onehand .sheet-grip { margin-bottom: 10px; }
.sheet-card.onehand .cp-head { margin-bottom: 10px; }
.sheet-card.onehand .cp-head .thumb.lg { width: 48px; height: 48px; font-size: 18px; border-radius: 12px; }
.sheet-card.onehand .cp-name { font-size: 16px; }
.sheet-card.onehand .cp-sys { padding: 8px 14px; margin-bottom: 10px; }
.sheet-card.onehand .cp-field { height: 80px; }
.sheet-card.onehand .cp-arrows { width: 72px; }
.sheet-card.onehand .cp-diff { min-height: 18px; margin-top: 6px; }
.sheet-card.onehand .cp-foot { margin-top: 10px; }
.sheet-card.onehand .cp-foot .btn { height: 58px; font-size: 17px; border-radius: 16px; }
.sheet-card.onehand .cp-foot #cp-edit { min-width: 108px; justify-content: center; }
.sheet-card.onehand .cp-foot .btn.primary { max-width: none; }

/* ----- ตัวเลขอยู่บน ลูกศรอยู่กลางจอใต้ตัวเลข (นิ้วไม่บังตัวเลข) ----- */
.cp-label.center { display: block; text-align: center; }
.cp-display { display: flex; align-items: baseline; justify-content: center; gap: 6px; border-bottom: 2px solid var(--ink); margin: 0 18% 0; padding-bottom: 2px; cursor: text; }
.cp-display input { border: none; border-radius: 0; height: 64px; width: 2ch; max-width: 80%; min-width: 1.6ch; padding: 0; background: none; text-align: center; font-size: 46px !important; font-weight: 600; letter-spacing: -.03em; font-variant-numeric: tabular-nums; -moz-appearance: textfield; appearance: textfield; }
.cp-display input:focus { box-shadow: none; }
.cp-display input::-webkit-outer-spin-button, .cp-display input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.cp-display .cp-unit { padding: 0; font-size: 15px; color: var(--ink-3); flex-shrink: 0; }
.cp-steps { display: flex; justify-content: center; gap: 28px; margin: 16px 0 2px; }
.cp-steps button { width: 68px; height: 68px; border-radius: 50%; border: 1px solid var(--line-2); background: var(--subtle); color: var(--ink); display: grid; place-items: center; cursor: pointer; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.cp-steps button:active { background: var(--line-2); transform: scale(.96); }
.cp-steps svg.i { width: 28px; height: 28px; stroke-width: 2.2; }
.sheet-card.onehand .cp-diff { text-align: center; }

/* ----- แบบ B: ลูกศร เพิ่ม/ลด ซ้อนบน-ล่าง กลางจอ + รูปสินค้าใหญ่ ----- */
.cp-steps { flex-direction: column; align-items: center; gap: 8px; margin: 14px 0 2px; }
.cp-steps button { width: 168px; height: 54px; border-radius: 16px; }
.cp-hero { position: relative; text-align: center; margin: 2px 0 10px; }
.cp-hero .cp-name { font-size: 17px; font-weight: 600; line-height: 1.3; margin-top: 10px; padding: 0 30px; }
.cp-hero .m-row-sub { white-space: normal; }
.cp-hero .cp-x { position: absolute; top: -6px; right: -8px; }
.thumb.cp { width: 150px; height: 150px; border-radius: 26px; font-size: 58px; display: inline-grid; }
img.thumb.cp { box-shadow: 0 6px 20px rgba(0,0,0,.08); }
.sheet-card.onehand .cp-sys { margin-bottom: 8px; }
@media (max-height: 720px) { .thumb.cp { width: 112px; height: 112px; font-size: 44px; border-radius: 22px; } }
@media (max-height: 640px) { .thumb.cp { width: 84px; height: 84px; font-size: 32px; border-radius: 18px; } .cp-steps button { height: 48px; } }

/* ----- สต็อกตอนนี้ (มือถือ): ระดับสี ต้องเติม / ใกล้เติม / เพียงพอ ----- */
.lv-need { --lv: #c2410c; --lv-bg: #fdf0ea; }
.lv-near { --lv: #b7791f; --lv-bg: #fdf6e3; }
.lv-ok   { --lv: #3f7d55; --lv-bg: #eef6f0; }
.lv-tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.lv-tabs button { font: inherit; background: var(--surface); border: 1.5px solid var(--line); border-radius: 14px; padding: 8px 4px 7px; display: flex; flex-direction: column; align-items: center; cursor: pointer; color: var(--ink-2); }
.lv-tabs button b { font-size: 21px; font-weight: 600; line-height: 1.2; color: var(--lv, var(--ink)); font-variant-numeric: tabular-nums; }
.lv-tabs button span { font-size: 11.5px; }
.lv-tabs button.on { border-color: var(--lv, var(--ink)); background: var(--lv-bg, var(--subtle)); color: var(--lv, var(--ink)); font-weight: 600; }
.lv-sort { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; font-size: 12.5px; color: var(--ink-3); }
.lv-sort button { font: inherit; font-size: 12.5px; background: none; border: none; color: var(--ink-2); cursor: pointer; padding: 2px 0; }
.lv-row { position: relative; padding-left: 18px; }
.lv-row::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 4px; border-radius: 0 3px 3px 0; background: var(--lv); }
.lv-row .lv-qty { color: var(--lv); font-size: 18px; }
.lv-row.lv-ok .lv-qty { color: var(--ink); }
.lv-pill { margin-top: 3px; font-size: 11px; font-weight: 600; color: var(--lv); background: var(--lv-bg); border-radius: 99px; padding: 1px 8px; }
.lv-txt { color: var(--lv); font-weight: 500; }
.lv-exp { margin-top: 4px; }
.lv-exp .badge { font-size: 11px; }
body.mobile .m-tabbar { grid-template-columns: repeat(4, 1fr); }

/* ----- กันระบบเลือกข้อความ/เมนูกดค้างของ iPhone ในป๊อปอัป และล็อกหน้าด้านหลัง ----- */
.sheet, .sheet * { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
.sheet input, .sheet textarea { -webkit-user-select: text; user-select: text; }
.sheet button, .sheet .m-row { touch-action: manipulation; }
.sheet .cp-display input::selection { background: transparent; }
body.sheet-open { overflow: hidden; }
body.mobile.sheet-open main { touch-action: none; }
.sheet { overscroll-behavior: contain; touch-action: none; }
.sheet-card { touch-action: pan-y; }
