/* v2.38 Mobile UI. Loaded with media="(max-width: 860px)" from index.html, so a desktop window never applies any of it.
   Phone screens (≤ 768px) are in the later blocks. The first block only adds Android PWA safe-area insets to the tablet layout (769–860px). */
@media (max-width: 860px) {
  .topbar { padding-top: env(safe-area-inset-top); height: calc(54px + env(safe-area-inset-top)); padding-left: max(1rem, env(safe-area-inset-left)); padding-right: max(1rem, env(safe-area-inset-right)); }
  .sidebar { top: calc(54px + env(safe-area-inset-top)); }
  /* v2.26.2 camera scanner (full screen) */
  .m-scan { position: fixed; inset: 0; z-index: 200; background: #000; color: #fff; overflow: hidden; }
  .m-scan video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
  .ms-top { position: absolute; top: 0; left: 0; right: 0; z-index: 2; display: flex; align-items: center; gap: 10px; padding: calc(8px + env(safe-area-inset-top)) 10px 18px; background: linear-gradient(rgba(0,0,0,.65), transparent); }
  .ms-top b { flex: 1; font-size: 1.05rem; }
  .ms-kind { font-size: .7rem; opacity: .6; }
  .ms-x { width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(255,255,255,.18); color: #fff; font-size: 1.2rem; }
  .ms-hint { position: absolute; z-index: 2; top: calc(76px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); width: min(86vw, 360px); background: #fff; color: #111827; border-radius: 10px; padding: 9px 12px; text-align: center; font-size: .86rem; }
  .ms-box { position: absolute; z-index: 1; left: 50%; top: 50%; width: min(80vw, 330px); height: min(44vw, 180px); transform: translate(-50%, -50%); border: 3px solid #22c55e; border-radius: 12px; box-shadow: 0 0 0 200vmax rgba(0,0,0,.38); }
  .ms-box i { position: absolute; left: 8px; right: 8px; top: 50%; height: 2px; background: #ef4444; box-shadow: 0 0 8px #ef4444; animation: msline 1.6s ease-in-out infinite alternate; }
  @keyframes msline { from { top: 18%; } to { top: 82%; } }
  .ms-last { position: absolute; z-index: 2; left: 50%; transform: translateX(-50%); bottom: calc(110px + env(safe-area-inset-bottom)); background: rgba(21,128,61,.92); border-radius: 99px; padding: 6px 14px; font-family: ui-monospace, monospace; font-size: .9rem; max-width: 90vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .ms-bottom { position: absolute; z-index: 2; left: 0; right: 0; bottom: calc(24px + env(safe-area-inset-bottom)); display: flex; justify-content: center; align-items: center; gap: 18px; }
  .ms-torch { width: 60px; height: 60px; border-radius: 50%; border: 0; background: #fff; font-size: 1.5rem; box-shadow: 0 4px 14px rgba(0,0,0,.35); }
  .ms-torch.on { background: #f59e0b; }
  .ms-done { min-height: 52px; padding: 0 26px; border-radius: 99px; border: 0; background: #fff; color: #0f4c81; font: inherit; font-weight: 700; font-size: 1rem; }
}

@media (max-width: 768px) {
  body.m-ui { --m-pad: 14px; --m-bar-h: 52px; --m-blue: #0f4c81; --m-blue-2: #1565c0; --m-tint: #e8f0fa; --m-amber: #f59e0b; --m-line: #e6eaf0; --m-get: #15803d; --m-give: #c2410c;
    padding-bottom: env(safe-area-inset-bottom); -webkit-tap-highlight-color: rgba(15, 76, 129, .12); }
  /* the desktop slide-in menu is replaced by the drawer on a phone */
  body.m-ui #nav, body.m-ui #navShade { display: none !important; }
  body.m-ui main { padding: 0 0 calc(.85rem + env(safe-area-inset-bottom)); }
  body.m-ui .bo-appfoot { display: none; }
  body.m-ui .topbar { gap: .45rem; padding-left: max(.5rem, env(safe-area-inset-left)); padding-right: max(.6rem, env(safe-area-inset-right)); }
  body.m-ui .topbar .icon-btn,
  body.m-ui.byteobill-shop #menuBtn { min-width: 44px; min-height: 44px; font-size: 1.5rem; }
  body.m-ui #netStatus, body.m-ui #installBtn { display: none; }
  body.m-ui #lockBtn { min-height: 44px; min-width: 44px; justify-content: center; }
  body.m-ui:not([data-route=home]) main > .card:first-child, body.m-ui:not([data-route=home]) main > .row:first-child { margin-top: .8rem; }
  body.m-ui:not(.m-full) main > *:not(.m-home):not(.m-page) { margin-left: max(.75rem, env(safe-area-inset-left)); margin-right: max(.75rem, env(safe-area-inset-right)); }
  /* full-screen phone pages (item details, sale view, new sale): own header, no app top bar */
  body.m-ui.m-full .topbar, body.m-ui.m-full .topbanner { display: none !important; }
  .m-head { position: sticky; top: 0; z-index: 25; display: flex; align-items: center; gap: .3rem; background: #fff; border-bottom: 1px solid var(--m-line);
    padding: env(safe-area-inset-top) .4rem 0; min-height: calc(56px + env(safe-area-inset-top)); }
  .m-head h2 { margin: 0; font-size: 1.15rem; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .m-back, .m-head-act > button, .m-head-act > a { min-width: 44px; min-height: 44px; border: 0; background: none; font-size: 1.35rem; color: #1f2937; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; text-decoration: none; cursor: pointer; }
  .m-head-act { display: flex; align-items: center; gap: .1rem; }

  /* ---------------- drawer */
  .m-drawer { position: fixed; z-index: 60; top: 0; bottom: 0; left: 0; width: min(86vw, 330px); background: #fff; transform: translateX(-102%); transition: transform .22s ease; visibility: hidden;
    display: flex; flex-direction: column; box-shadow: 6px 0 28px rgba(0,0,0,.18); overflow: hidden; }
  body.md-open .m-drawer { transform: none; visibility: visible; }
  .md-shade { position: fixed; inset: 0; z-index: 59; background: rgba(15, 23, 42, .45); opacity: 0; pointer-events: none; transition: opacity .2s; }
  body.md-open .md-shade { opacity: 1; pointer-events: auto; }
  .md-head { background: linear-gradient(135deg, #0f4c81, #1565c0); color: #fff; padding: calc(18px + env(safe-area-inset-top)) 16px 14px; display: flex; gap: 12px; align-items: flex-start; }
  .md-logo { width: 46px; height: 46px; border-radius: 12px; background: #fff; padding: 5px; flex: none; }
  .md-shop { display: flex; flex-direction: column; min-width: 0; gap: 2px; }
  .md-shop b { font-size: 1.08rem; line-height: 1.25; overflow-wrap: anywhere; }
  .md-shop span { font-size: .84rem; opacity: .9; overflow-wrap: anywhere; }
  .md-shop .md-user { opacity: .75; font-size: .78rem; }
  .md-change { align-self: flex-start; margin-top: 4px; background: rgba(255,255,255,.16); color: #fff; border: 1px solid rgba(255,255,255,.35); border-radius: 99px; padding: .3rem .75rem; font: inherit; font-size: .82rem; min-height: 44px; }
  .md-list { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 6px 0 calc(16px + env(safe-area-inset-bottom)); }
  .md-item { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 48px; padding: 6px 16px; border: 0; background: none; color: #1f2937; text-decoration: none; font: inherit; font-size: .97rem; text-align: left; cursor: pointer; }
  .md-item i { font-style: normal; width: 24px; text-align: center; font-size: 1.15rem; flex: none; filter: saturate(.75); }
  .md-item span { flex: 1; min-width: 0; display: flex; flex-direction: column; }
  .md-item small { font-size: .75rem; color: #6b7280; }
  .md-item em { font-style: normal; color: #6b7280; transition: transform .2s; }
  .md-item.active { background: var(--m-tint); color: var(--m-blue); font-weight: 600; }
  .md-item:active { background: #f1f5f9; }
  .md-plus { font-weight: 400; font-size: 1.4rem; color: #64748b; min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .md-sub { display: none; background: #f8fafc; }
  .md-group.open .md-sub { display: block; }
  .md-group.open > .md-h em { transform: rotate(180deg); }
  .md-item .nav-count { margin-left: .35rem; flex: none; }
  .md-group.open > .md-h .nav-count { display: none; }
  .md-subitem { padding-left: 28px; color: #475569; }
  .md-sep { height: 1px; background: var(--m-line); margin: 6px 0; }
  .md-ver { color: #94a3b8; font-size: .8rem; text-align: center; padding: 14px 0 4px; }

  /* ---------------- home */
  .m-home { padding-bottom: calc(var(--m-bar-h) + 34px + env(safe-area-inset-bottom)); }
  .m-sums { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; overflow: hidden; padding: 12px var(--m-pad) 6px; }
  .m-sum { min-width: 0; background: #fff; border: 1px solid var(--m-line); border-radius: 14px; padding: 12px 12px 10px;
    box-shadow: 0 2px 6px rgba(15, 23, 42, .06); text-decoration: none; color: #111827; display: flex; flex-direction: column; gap: 6px; }
  .m-sum-l { font-size: .8rem; color: #4b5563; display: flex; align-items: center; gap: 5px; white-space: normal; }
  .m-sum-l i { font-style: normal; width: 22px; height: 22px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; font-size: .85rem; font-weight: 700; }
  .m-sum.get i { background: #dcfce7; color: var(--m-get); } .m-sum.give i { background: #ffedd5; color: var(--m-give); } .m-sum.sale i { background: #fef3c7; } .m-sum.received i { background: #dbeafe; color: #17569a; }
  .m-period { display: flex; justify-content: space-between; gap: 12px; padding: 8px var(--m-pad); color: #334155; background: #eff6ff; font-size: .8rem; font-weight: 700; }
  .m-period a { color: #14518a; text-decoration: underline; }
  .m-sum-l em { font-style: normal; font-size: .72rem; font-weight: 700; } .m-sum-l em.neg { color: #dc2626; } .m-sum-l em.pos { color: var(--m-get); }
  .m-sum b { font-size: 1.22rem; letter-spacing: .01em; }
  .m-seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 8px var(--m-pad); }
  .m-seg a { min-height: 44px; display: flex; align-items: center; justify-content: center; border: 1px solid #d5dbe4; border-radius: 99px; color: #374151; text-decoration: none; font-size: .9rem; background: #fff; }
  .m-seg a.on { background: var(--m-tint); border-color: var(--m-blue); color: var(--m-blue); font-weight: 700; }
  .m-tools { display: flex; align-items: center; gap: 6px; padding: 6px var(--m-pad) 8px; position: sticky; top: calc(54px + env(safe-area-inset-top)); z-index: 5; background: var(--bg); }
  .m-search { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; margin: 0; background: #fff; border: 1px solid #d5dbe4; border-radius: 10px; padding: 0 10px; min-height: 44px; color: #6b7280; }
  .m-search input { border: 0; padding: 0; min-height: 42px; background: transparent; outline: none; font-size: .95rem; }
  .m-search input:focus { outline: none; }
  .m-icon-btn, .m-filter { position: relative; flex: none; width: 44px; height: 44px; margin: 0; border-radius: 10px; border: 1px solid #d5dbe4; background: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 1.15rem; color: #374151; }
  .m-filter select { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; }
  .m-new { flex: none; min-height: 44px; display: inline-flex; align-items: center; padding: 0 12px; border-radius: 99px; background: var(--m-tint); color: var(--m-blue); border: 1px solid #bcd3ee; font: inherit; font-weight: 700; font-size: .88rem; text-decoration: none; white-space: nowrap; }
  .m-list { background: #fff; border-top: 1px solid var(--m-line); }
  .m-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; min-height: 60px; padding: 10px var(--m-pad); border-bottom: 1px solid var(--m-line); text-decoration: none; color: #111827; }
  .m-row:active { background: #f8fafc; }
  .m-l { display: flex; flex-direction: column; min-width: 0; gap: 2px; }
  .m-l b { font-weight: 600; font-size: .96rem; overflow-wrap: anywhere; }
  .m-l small, .m-r small { color: #6b7280; font-size: .78rem; }
  .m-r { display: flex; flex-direction: column; align-items: flex-end; flex: none; text-align: right; gap: 2px; }
  .m-r b { font-size: .98rem; }
  .m-r.get b, .m-r.get small { color: var(--m-get); } .m-r.give b, .m-r.give small { color: var(--m-give); }
  .m-r small.due { color: var(--m-give); }
  .m-tag, .m-chip { display: inline-block; font-size: .68rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; color: #475569; background: #eef2f7; border-radius: 6px; padding: 2px 6px; }
  .m-item { flex-direction: column; align-items: stretch; gap: 6px; }
  .m-item-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
  .m-item-top b { font-weight: 700; font-size: .95rem; text-transform: uppercase; letter-spacing: .01em; overflow-wrap: anywhere; }
  .m-item-top .m-chip { flex: none; max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .m-kv { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; font-size: .92rem; }
  .m-kv > span { display: flex; flex-direction: column; }
  .m-kv small { color: #6b7280; font-size: .74rem; }
  .st-ok { color: var(--m-get); } .st-low { color: #b45309; } .st-out { color: #dc2626; }
  .m-type { align-self: flex-start; font-size: .66rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; border-radius: 5px; padding: 1px 6px; background: #e0f2fe; color: #075985; }
  .m-type.t-payin { background: #dcfce7; color: #166534; } .m-type.t-return { background: #fee2e2; color: #991b1b; } .m-type.t-purchase { background: #ede9fe; color: #5b21b6; } .m-type.t-payout { background: #ffedd5; color: #9a3412; }
  .m-empty { padding: 28px var(--m-pad); text-align: center; color: #6b7280; }

  /* ---------------- floating bottom bar + quick sheet */
  .m-bar { position: fixed; z-index: 30; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); display: flex; align-items: center; justify-content: space-between; gap: 10px; pointer-events: none; }
  .m-bar[hidden] { display: none; }
  .m-bar > * { pointer-events: auto; }
  .mb-pay, .mb-sale { flex: 1; max-width: 42%; min-height: var(--m-bar-h); border-radius: 99px; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1rem; text-decoration: none; box-shadow: 0 6px 16px rgba(15, 23, 42, .25); }
  .mb-pay { background: var(--m-amber); color: #1f2937; }
  .mb-sale { background: var(--m-blue); color: #fff; }
  .mb-plus { width: 56px; height: 56px; flex: none; border-radius: 50%; border: 3px solid var(--m-blue); background: #fff; color: var(--m-blue); font-size: 2rem; line-height: 1; font-weight: 300; box-shadow: 0 6px 16px rgba(15, 23, 42, .22); }
  dialog.m-sheet { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: 18px 18px 0 0; }
  dialog.m-sheet #modalBody { padding: 8px 16px calc(14px + env(safe-area-inset-bottom)); }
  .mq-grab { width: 42px; height: 4px; border-radius: 4px; background: #cbd5e1; margin: 2px auto 10px; }
  .mq-sheet h3 { font-size: 1rem; margin: 0 0 10px; }
  .mq-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
  .mq-tile { min-height: 78px; border: 1px solid var(--m-line); border-radius: 14px; background: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; font: inherit; font-size: .8rem; color: #1f2937; padding: 6px 4px; text-align: center; }
  .mq-tile span { font-size: 1.5rem; }
  .mq-tile:active { background: var(--m-tint); }
  .btn.block { width: 100%; justify-content: center; min-height: 44px; }
  /* touch targets on the usual screens */
  body.m-ui .btn, body.m-ui .btn.small, body.m-ui .link-btn { min-height: 44px; min-width: 44px; }
}
@media (max-width: 768px) {
  body.m-ui .toast { bottom: calc(84px + env(safe-area-inset-bottom)); }
}
/* v2.26.1 item details + sale view */
@media (max-width: 768px) {
  .m-page { padding-bottom: calc(86px + env(safe-area-inset-bottom)); }
  .m-sec { background: #fff; padding: 14px var(--m-pad); border-bottom: 8px solid #eef1f5; }
  .m-sec.m-flush { padding-left: 0; padding-right: 0; }
  .m-title { font-size: 1.05rem; text-transform: uppercase; margin: 0 0 12px; overflow-wrap: anywhere; }
  .m-grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 10px; }
  .m-grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .m-grid3 > div, .m-grid2 > div { display: flex; flex-direction: column; min-width: 0; }
  .m-grid3 small, .m-grid2 small, .m-field small { color: #6b7280; font-size: .76rem; }
  .m-grid3 b, .m-grid2 b { font-size: .98rem; overflow-wrap: anywhere; font-weight: 600; }
  .m-sec-h { font-size: 1rem; margin: 0; padding: 0 var(--m-pad) 10px; }
  .m-sec-h0 { font-size: 1rem; margin: 0 0 8px; }
  .m-trow { display: grid; grid-template-columns: 1.3fr .9fr 1fr; gap: 8px; align-items: center; min-height: 56px; padding: 8px var(--m-pad); border-top: 1px solid var(--m-line); text-decoration: none; color: #111827; }
  .m-trow > span:not(:first-child) { text-align: right; }
  .m-trow > span:first-child { display: flex; flex-direction: column; min-width: 0; }
  .m-trow small { color: #6b7280; font-size: .76rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .m-trow-h { min-height: 36px; background: #f8fafc; color: #6b7280; font-size: .78rem; }
  .m-trow .neg { color: #b91c1c; } .m-trow .pos { color: var(--m-get); }
  .m-foot { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; background: #fff; border-top: 1px solid var(--m-line); padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); display: flex; gap: 8px; }
  .m-foot-center { flex-direction: column; align-items: center; background: transparent; border: 0; pointer-events: none; }
  .m-foot-center > * { pointer-events: auto; }
  .m-foot-center small { background: rgba(255,255,255,.95); padding: 2px 8px; border-radius: 6px; text-align: center; }
  .m-pill { min-height: 52px; min-width: 190px; border: 0; border-radius: 99px; background: var(--m-blue); color: #fff; font: inherit; font-weight: 700; font-size: 1rem; box-shadow: 0 6px 16px rgba(15,76,129,.35); }
  .m-pill:disabled { background: #94a3b8; box-shadow: none; }
  .m-foot3 { padding: 0 0 env(safe-area-inset-bottom); gap: 0; }
  .m-fbtn { flex: 1; min-height: 54px; display: inline-flex; align-items: center; justify-content: center; border: 0; border-right: 1px solid var(--m-line); background: #fff; color: #1f2937; font: inherit; font-weight: 600; font-size: 1rem; text-decoration: none; }
  .m-fbtn.primary { background: var(--m-blue); color: #fff; border-right: 0; }
  .m-fbtn.off { opacity: .4; }
  .m-banner { margin: 0; padding: 10px var(--m-pad); font-size: .9rem; } .m-banner.err { background: #fee2e2; color: #991b1b; }
  .m-meta { padding-top: 10px; padding-bottom: 10px; }
  .m-field { border: 1px solid #d5dbe4; border-radius: 8px; padding: 6px 10px; min-height: 48px; display: flex; flex-direction: column; justify-content: center; }
  .m-cust { margin-top: 10px; } .m-cust b { font-size: 1rem; } .m-cust span { color: #4b5563; font-size: .85rem; }
  .m-right-notes { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; margin-top: 6px; font-size: .82rem; }
  .get-t { color: var(--m-get); } .give-t { color: var(--m-give); }
  .m-billed-h { display: flex; justify-content: space-between; align-items: center; margin: 0 var(--m-pad) 8px; background: #dbeafe; color: #1e40af; border-radius: 6px; padding: 7px 10px; font-size: .85rem; }
  .m-bitem { margin: 0 var(--m-pad) 8px; background: #f8fafc; border: 1px solid var(--m-line); border-radius: 8px; padding: 9px 10px; }
  .m-bitem-top { display: flex; gap: 6px; align-items: baseline; }
  .m-bitem-top b:not(.m-amt) { flex: 1; min-width: 0; text-transform: uppercase; font-size: .9rem; overflow-wrap: anywhere; }
  .m-n { font-size: .72rem; color: #6b7280; background: #e5e7eb; border-radius: 4px; padding: 0 4px; }
  .m-amt { flex: none; }
  .m-bitem-row { display: flex; justify-content: space-between; gap: 8px; font-size: .8rem; color: #4b5563; margin-top: 3px; }
  .m-bitem-row span:last-child { text-align: right; overflow-wrap: anywhere; }
  .m-sum-rows > div { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; font-size: .92rem; border-bottom: 1px dashed #e5e7eb; }
  .m-sum-rows .m-total { font-weight: 800; font-size: 1.05rem; border-bottom: 1px solid #cbd5e1; }
  .m-wa { margin-top: .6rem; } .m-wa .btn { width: 100%; justify-content: center; }
}
@media (max-width: 768px) { .m-grid3 b.mono { font-size: .86rem; word-break: break-all; } }
/* v2.26.1 phone New Sale / Add Item / Serial numbers */
@media (max-width: 768px) {
  .m-foot2 { padding: 0 0 env(safe-area-inset-bottom); gap: 0; }
  .m-toggle { display: inline-flex; background: #eef2f7; border-radius: 99px; padding: 3px; margin-right: 2px; }
  .m-toggle button { min-height: 44px; min-width: 72px; border: 0; border-radius: 99px; background: transparent; font: inherit; font-weight: 600; font-size: .88rem; color: #6b7280; padding: 0 10px; }
  .m-toggle button.on[data-mode=Credit] { background: var(--m-give); color: #fff; }
  .m-toggle button.on[data-mode=Cash] { background: var(--m-get); color: #fff; }
  .m-banner.warn { background: #fef3c7; color: #92400e; }
  .m-banner:not(.warn):not(.err) { background: var(--m-tint); color: #1e3a5f; }
  .m-field input, .m-field select, .m-field textarea { border: 0; padding: 2px 0; margin: 0; font: inherit; font-size: 1rem; background: transparent; width: 100%; min-height: 28px; outline: none; color: #111827; box-shadow: none; }
  .m-field:focus-within { border-color: var(--m-blue-2); box-shadow: 0 0 0 2px rgba(21,101,192,.15); }
  .m-field select:disabled { color: #374151; opacity: 1; -webkit-appearance: none; appearance: none; }
  .m-cust-box { position: relative; margin-top: 12px; }
  .m-purchase-invoice { margin-top: 12px; padding: 10px; border: 1px solid #d5dbe4; border-radius: 9px; background: #f8fafc; }
  .m-purchase-invoice summary { cursor: pointer; font-weight: 700; color: #0f4c81; }
  .m-purchase-invoice .m-grid2, .m-purchase-invoice > .m-field { margin-top: 10px; }
  .m-cust-box .results, .m-add-item .results { position: absolute; left: 0; right: 0; z-index: 40; max-height: 52vh; overflow: auto; }
  .m-cust-chip { display: flex; align-items: center; gap: 6px; min-height: 30px; font-size: .98rem; }
  .m-cust-chip b { color: #111827; flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .m-cust-chip em { font-style: normal; font-size: .72rem; background: #fef3c7; color: #92400e; border-radius: 4px; padding: 0 5px; }
  .m-cust-chip button { margin-left: auto; min-width: 44px; min-height: 44px; border: 0; background: none; color: #6b7280; font-size: 1.05rem; }
  .m-add-row { display: flex; gap: 10px; align-items: stretch; margin-top: 14px; }
  .m-add { flex: 1; min-height: 50px; display: flex; align-items: center; justify-content: center; gap: 6px; border: 1.5px dashed var(--m-blue-2); border-radius: 10px; color: var(--m-blue-2); font-weight: 700; text-decoration: none; background: var(--m-tint); }
  .m-add span { font-weight: 400; font-size: .8rem; color: #4b5563; }
  .m-scan-btn { width: 50px; height: auto; min-height: 50px; color: var(--m-blue); border-color: var(--m-blue-2); }
  .m-sink { position: absolute; left: 0; top: 0; width: 1px; height: 1px; overflow: hidden; opacity: 0; }
  .m-sink input { width: 1px; min-width: 0; max-width: 1px; padding: 0; border: 0; }
  .m-bitem.tap { cursor: pointer; }
  .m-bitem .m-x { flex: none; min-width: 44px; min-height: 44px; margin: -8px -6px -8px 0; border: 0; background: none; color: #9ca3af; font-size: 1rem; }
  .m-sn { display: inline-flex; align-items: center; min-height: 30px; padding: 0 8px; border-radius: 6px; font-weight: 600; text-decoration: none; font-size: .78rem; }
  .m-sn.ok { background: #dcfce7; color: #166534; } .m-sn.bad { background: #fee2e2; color: #991b1b; }
  .m-line { display: flex; justify-content: space-between; align-items: center; gap: 10px; min-height: 40px; font-size: .95rem; }
  .m-line.small { min-height: 26px; font-size: .84rem; }
  .m-disc { display: inline-flex; gap: 6px; align-items: center; }
  .m-disc input { width: 110px; min-height: 44px; text-align: right; margin: 0; }
  .m-disc select { min-height: 44px; width: auto; margin: 0; }
  .m-chips { display: inline-flex; gap: 6px; }
  .m-chips button { min-height: 44px; min-width: 56px; border: 1px solid #d5dbe4; border-radius: 99px; background: #fff; font: inherit; font-size: .88rem; }
  .m-chips button.on { background: var(--m-blue); border-color: var(--m-blue); color: #fff; }
  .m-grand { font-size: 1.1rem; } .m-grand b { font-size: 1.2rem; }
  .m-total-sec { padding-top: 8px; padding-bottom: 8px; }
  .m-hint { color: #6b7280; font-size: .82rem; margin: 6px 0 0; }
  .m-add-item .search-wrap { position: relative; }
  .m-in-scan { position: absolute; right: 6px; top: 6px; width: 44px; height: 44px; border: 0; color: var(--m-blue); }
  .m-add-item #miName { padding-right: 44px; }
  .m-serial-btn { display: flex; align-items: center; justify-content: center; min-height: 48px; margin-top: 12px; border: 1px solid var(--m-blue-2); border-radius: 8px; color: var(--m-blue-2); font-weight: 600; text-decoration: none; }
  .m-serial-btn.ok { border-color: var(--m-get); color: var(--m-get); background: #f0fdf4; }
  .m-count { font-weight: 700; color: var(--m-blue); }
  .m-sn-add { display: flex; gap: 8px; margin-top: 8px; }
  .m-sn-add input { flex: 1; min-height: 48px; margin: 0; font-family: ui-monospace, monospace; }
  .m-sn-add .btn { min-height: 48px; min-width: 76px; justify-content: center; margin: 0; }
  .m-snlist { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
  .m-snchip { display: inline-flex; align-items: center; gap: 4px; background: var(--m-tint); border: 1px solid #c7d7ec; border-radius: 8px; padding: 0 0 0 10px; font-size: .88rem; }
  .m-snchip button { min-width: 44px; min-height: 44px; border: 0; background: none; color: #6b7280; }
  .m-snavail { display: flex; flex-direction: column; }
  .m-snpick { display: flex; justify-content: space-between; align-items: center; min-height: 48px; border: 0; border-bottom: 1px solid var(--m-line); background: #fff; font: inherit; text-align: left; padding: 0 2px; }
  .m-snpick b { color: var(--m-blue-2); font-size: 1.2rem; }
}
/* v2.26.2 polish */
@media (max-width: 768px) {
  .m-new-sale .m-meta { grid-template-columns: minmax(0, 1.55fr) minmax(0, 1.05fr) minmax(0, .8fr); }
  .m-new-sale #msNo { font-size: .88rem; overflow-wrap: normal; word-break: normal; }
  .m-field input[type=number]::-webkit-inner-spin-button, .m-field input[type=number]::-webkit-outer-spin-button, .m-disc input::-webkit-inner-spin-button, .m-disc input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
  .m-field input[type=number], .m-disc input { -moz-appearance: textfield; appearance: textfield; }
  body.m-ui.m-full .toast { bottom: auto; top: calc(62px + env(safe-area-inset-top)); }
}

/* v2.28 temporary (offline) document number */
.m-pend { display: block; color: #b45309; font-style: normal; font-size: 11px; font-weight: 600; }
small .m-pend { display: inline; }

/* v2.29.0 phone forms (quotation, purchase, credit / debit note, payment in / out) in the New Sale look */
@media (max-width: 768px) {
  .m-form .m-meta { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1.25fr) minmax(0, .75fr); }
  .m-form #mfNo { font-size: .88rem; overflow-wrap: normal; word-break: normal; }
  .m-meta input.m-date, .m-meta input.m-meta-in { border: 0; border-bottom: 1px dashed #cbd5e1; border-radius: 0; padding: 2px 0; margin: 0; min-height: 44px; font: inherit; font-size: 1rem; font-weight: 600; background: transparent; width: 100%; color: #111827; box-shadow: none; }
  .m-meta input.m-date:focus, .m-meta input.m-meta-in:focus { outline: none; border-bottom-color: var(--m-blue-2); }
  .m-chips-wrap { flex-wrap: wrap; justify-content: flex-end; }
  .m-step { display: inline-flex; align-items: center; gap: 0; margin-top: 8px; border: 1px solid #d5dbe4; border-radius: 10px; overflow: hidden; }
  .m-step button { min-width: 48px; min-height: 44px; border: 0; background: #f1f5f9; font: inherit; font-size: 1.2rem; color: var(--m-blue); }
  .m-step input { width: 64px; min-height: 44px; border: 0; margin: 0; text-align: center; font: inherit; font-size: 1rem; -moz-appearance: textfield; appearance: textfield; }
  .m-step input::-webkit-inner-spin-button, .m-step input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
  .m-sntick { padding: 0 10px; min-height: 44px; cursor: pointer; }
  .m-sntick input { width: 44px; height: 44px; margin: 0 4px 0 0; }
  .m-sntick:has(input:checked) { background: #dcfce7; border-color: #86efac; }
  .m-ret-lines .m-bitem { padding-bottom: 10px; }
  .m-form .m-line input[type=checkbox], .m-add-item .m-line input[type=checkbox] { width: 44px; height: 44px; min-width: 44px; min-height: 44px; margin: 0; }
  .m-form .m-trow { min-height: 52px; }
}
@media (max-width: 768px) { .m-form .m-line:has(> .m-chips-wrap) { flex-direction: column; align-items: stretch; gap: 6px; padding: 6px 0; } .m-form .m-line > .m-chips-wrap { justify-content: flex-start; } }

/* Shared mobile pattern for read-only lists across sales, purchases, parties, service and reports. */
@media (max-width: 768px) {
  body.m-ui .table.m-auto-cards,
  body.m-ui .table.m-auto-cards tbody { display: block; width: 100%; }
  body.m-ui .table.m-auto-cards thead { display: none; }
  body.m-ui .table.m-auto-cards tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .55rem .75rem; padding: .8rem .15rem; border-bottom: 1px solid var(--m-line); }
  body.m-ui .table.m-auto-cards tr:last-child { border-bottom: 0; }
  body.m-ui .table.m-auto-cards td { display: block; min-width: 0; padding: 0; border: 0; text-align: left; overflow-wrap: anywhere; }
  body.m-ui .table.m-auto-cards td:first-child,
  body.m-ui .table.m-auto-cards td.m-main,
  body.m-ui .table.m-auto-cards td[colspan] { grid-column: 1 / -1; }
  body.m-ui .table.m-auto-cards td:first-child { font-weight: 700; font-size: .96rem; }
  body.m-ui .table.m-auto-cards td[data-l]:not(:first-child):not(.m-main)::before { content: attr(data-l); display: block; color: #64748b; font-size: .72rem; font-weight: 600; line-height: 1.25; margin-bottom: .1rem; }
  body.m-ui .table.m-auto-cards td:empty,
  body.m-ui .table.m-auto-cards td.hide-sm { display: none; }
  body.m-ui .table.m-auto-cards td:has(> .btn),
  body.m-ui .table.m-auto-cards td:has(> button) { grid-column: 1 / -1; }
  body.m-ui .table.m-auto-cards td .btn { max-width: 100%; white-space: normal; }
  body.m-ui .table.m-auto-cards td:last-child:not([data-l]):not([colspan]) { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: .2rem; }
  body.m-ui .table.m-auto-cards td:last-child:not([data-l]) > :is(a, button) { display: inline-flex; align-items: center; min-height: 44px; padding: .25rem .45rem; white-space: normal; }
  body.m-ui .table-wrap:has(> .table.m-auto-cards) { overflow-x: hidden; }
  body.m-ui .purchase-tabs { flex-wrap: wrap; width: 100%; max-width: 100%; overflow-x: hidden; gap: .35rem; }
  body.m-ui .purchase-tabs > * { flex: 1 1 auto; min-height: 44px; white-space: normal; text-align: center; }
  body.m-ui .m-module-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; gap: .45rem; }
  body.m-ui .m-module-actions > .m-primary { grid-column: 1 / -1; }
  body.m-ui .m-module-actions > .btn { justify-content: center; text-align: center; white-space: normal; }
  body.m-ui .m-pay .m-trow { grid-template-columns: minmax(0, 1fr) auto; }
  body.m-ui .m-pay .m-trow > span:nth-child(2):empty { display: none; }
  body.m-ui .m-pay .m-trow > span:last-child { white-space: nowrap; }
  body.m-ui .m-pay .m-trow small { white-space: normal; }
  body.m-ui #view > .row.between { align-items: flex-start; }
  body.m-ui #view > .row.between > :is(h1, h2, h3) { min-width: 0; overflow-wrap: anywhere; }
  body.m-ui #view > .row.between > .row { min-width: 0; }
  body.m-ui .card > :is(input, select, textarea),
  body.m-ui .card label > :is(input, select, textarea) { max-width: 100%; }
}
@media (max-width: 380px) {
  body.m-ui .purchase-filters .grid,
  body.m-ui .grid.m-filters { grid-template-columns: minmax(0, 1fr); }
  body.m-ui .purchase-filters .grid > :first-child,
  body.m-ui .grid.m-filters > :first-child { grid-column: auto; }
}

@media (max-width: 768px) {
  dialog.item-editor-modal { inset: 0; width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; overflow: hidden; }
  dialog.item-editor-modal #modalBody { height: 100dvh; max-height: 100dvh; padding: 0 0 calc(72px + env(safe-area-inset-bottom)); overflow-y: auto; }
  .item-editor-head { align-items: center; padding: calc(12px + env(safe-area-inset-top)) 16px 8px; border-bottom: 1px solid var(--m-line); }
  .item-editor-head .item-editor-back { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border: 0; background: transparent; color: var(--text); font-size: 1.5rem; margin-left: -8px; }
  .item-editor-head h2 { margin: 0; font-size: 1.18rem; }
  .item-editor-head > span { display: none; }
  .item-editor .item-kind-switch { margin: 0; padding: 12px 16px; background: #f8fafc; }
  .item-editor .item-tabs { position: sticky; top: 0; z-index: 5; margin: 0; }
  .item-editor .item-pane-grid { display: grid; grid-template-columns: minmax(0, 1fr); padding: 18px 16px; gap: 18px; }
  .item-editor .item-pane-grid > div { grid-column: 1 / -1 !important; }
  .item-editor .item-pane-grid label { font-size: .87rem; font-weight: 650; }
  .item-editor .item-pane-grid :is(input, select, textarea) { min-height: 48px; font-size: 1rem; }
  .item-editor .item-stock-flags, .item-editor .item-active, .item-editor #imgSection, .item-editor #marginHint { margin-left: 16px; margin-right: 16px; }
  .item-editor .item-stock-flags { flex-direction: column; align-items: flex-start; }
  .item-editor .item-stock-flags .check { min-height: 44px; }
  dialog.item-editor-modal .item-editor-actions { position: fixed; left: 0; right: 0; bottom: 0; margin: 0; padding: 0 0 env(safe-area-inset-bottom); gap: 0; box-shadow: 0 -3px 12px rgba(15,23,42,.08); }
  dialog.item-editor-modal .item-editor-actions .btn { flex: 1; min-height: 54px; border-radius: 0; justify-content: center; }
}

/* v2.38.0 Dedicated phone layout. Widths above 768px do not load this file's phone blocks.
   Colours stay the theme variables. Cost / purchase / profit cells that are .hide-sm stay hidden. */
@media (max-width: 768px) {
  body.m-ui main, body.m-ui #view { max-width: 100%; }
  body.m-ui main:has(#boDashboard) { padding: 0 0 env(safe-area-inset-bottom); }
  body.m-ui main:has(#boDashboard) > * { margin-left: 0; margin-right: 0; }
  body.m-ui .topbar { min-height: calc(54px + env(safe-area-inset-top)); }
  body.m-ui .topbar .brand { min-height: 44px; }
  body.m-ui #view > h2,
  body.m-ui #view > .row.between > :is(h1, h2, h3) { font-size: 1.2rem; line-height: 1.25; letter-spacing: -.01em; }
  body.m-ui #view > .row.between { flex-direction: column; align-items: stretch; gap: .55rem; }
  body.m-ui #view > .row.between > .row { width: 100%; display: flex; flex-wrap: wrap; gap: .4rem; }
  body.m-ui #view > .row.between .btn { flex: 1 1 calc(50% - .4rem); justify-content: center; text-align: center; white-space: normal; }

  body.m-ui .grid.cols-2,
  body.m-ui .grid.cols-3,
  body.m-ui .grid.cols-4,
  body.m-ui .grid.cols-5,
  body.m-ui .grid.cols-6,
  body.m-ui .settings-form .grid,
  body.m-ui .wp-filters,
  body.m-ui .bn-size-guide,
  body.m-ui .sp-slots,
  body.m-ui .web-metrics,
  body.m-ui .oq-hdr,
  body.m-ui .oq-brief,
  body.m-ui .wap-grid { grid-template-columns: minmax(0, 1fr); }
  body.m-ui .grid.cols-5 > :nth-child(3) { grid-column: auto; }

  body.m-ui :is(input, select, textarea):not([type=checkbox]):not([type=radio]):not([type=hidden]) { min-height: 44px; font-size: 1rem; }
  body.m-ui label.check { min-height: 44px; align-items: center; }
  body.m-ui input[type=checkbox], body.m-ui input[type=radio] { width: 44px; height: 44px; min-width: 44px; min-height: 44px; }
  body.m-ui .tab, body.m-ui .chip, body.m-ui .exp-chips .chip { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  body.m-ui .link-btn { display: inline-flex; align-items: center; min-height: 44px; padding: .35rem .55rem; }
  body.m-ui summary { min-height: 44px; }
  body.m-ui .bo-dash-action, body.m-ui .bo-dash-search, body.m-ui .bo-report-links a { min-height: 44px; }
  body.m-ui .settings-nav { flex-wrap: wrap; overflow: visible; }
  body.m-ui .settings-nav .btn { flex: 1 1 calc(50% - .3rem); min-height: 44px; white-space: normal; text-align: center; justify-content: center; }

  /* Keep staff-hidden purchase / cost columns hidden when rows become cards. */
  body.m-ui td.hide-sm,
  body.m-ui th.hide-sm,
  body.m-ui .bp-table[data-hide~="cost"] [data-col="cost"],
  body.m-ui .bp-table[data-hide~="margin"] [data-col="margin"] { display: none !important; }

  body.m-ui .table.m-cards td.m-act,
  body.m-ui .table.m-auto-cards td:last-child:not([data-l]):not([colspan]) {
    display: flex; flex-wrap: wrap; align-items: center; gap: .15rem .25rem; max-width: 100%;
  }
  body.m-ui .item-more { margin-left: 0; max-width: 100%; }
  body.m-ui .item-more summary { padding: 0 .55rem; }
  body.m-ui .item-more[open] { display: flex; flex-wrap: wrap; align-items: center; width: 100%; }
  body.m-ui .item-more .danger { flex: 1 1 100%; white-space: normal; max-width: 100%; box-sizing: border-box; }

  body.m-ui #numberCard .table,
  body.m-ui #formatTable { min-width: 0; }
  body.m-ui #formatTable, body.m-ui #formatTable tbody,
  body.m-ui #numberTable, body.m-ui #numberTable tbody { display: block; width: 100%; }
  body.m-ui #formatTable thead, body.m-ui #numberTable thead { display: none; }
  body.m-ui #formatTable tr, body.m-ui #numberTable tr {
    display: grid; grid-template-columns: minmax(0, 1fr); gap: .4rem; padding: .8rem 0; border-bottom: 1px solid var(--border);
  }
  body.m-ui #formatTable td, body.m-ui #numberTable td { display: block; min-width: 0; text-align: left; padding: 0; border: 0; }
  body.m-ui #formatTable td:nth-child(2)::before { content: "Prefix"; }
  body.m-ui #formatTable td:nth-child(3)::before { content: "Year in number"; }
  body.m-ui #formatTable td:nth-child(4)::before { content: "Digits"; }
  body.m-ui #formatTable td:nth-child(5)::before { content: "Prints as"; }
  body.m-ui #numberTable td:nth-child(n+2)::before { content: attr(data-l); }
  body.m-ui #formatTable td::before, body.m-ui #numberTable td::before {
    display: block; color: #64748b; font-size: .72rem; font-weight: 600; margin-bottom: .15rem;
  }
  body.m-ui #formatTable td:first-child::before, body.m-ui #numberTable td:first-child::before,
  body.m-ui #numberTable td:not([data-l])::before, body.m-ui #numberTable td[data-l=""]::before { content: none; display: none; }
  body.m-ui #formatTable :is(input, select), body.m-ui #numberTable :is(input, select) { width: 100% !important; max-width: 100%; }

  body.m-ui .table-wrap:not(:has(.inv)) { overflow-x: hidden; }
  body.m-ui .bo-sale .cart-table { min-width: 0; }
  body.m-ui .inv-preview { overflow-x: hidden; padding: .45rem; }
  body.m-ui .inv.a4, body.m-ui .inv.thermal { width: 100%; min-height: 0; padding: .7rem; box-sizing: border-box; }
  body.m-ui .inv.a4 .inv-head,
  body.m-ui .inv.a4 .inv-party,
  body.m-ui .inv.a4 .inv-bottom,
  body.m-ui .inv.a4 .inv-foot { flex-direction: column; align-items: stretch; }
  body.m-ui .inv.a4 .inv-title { text-align: left; }
  body.m-ui .inv.a4 .inv-doc-head { display: block; }
  body.m-ui .inv.a4 table.tot { min-width: 0; width: 100%; }
  body.m-ui .inv.a4 table.items th, body.m-ui .inv.a4 table.items td { padding: 3px 2px; }
  body.m-ui .label-preview-wrap { overflow: hidden; }
  body.m-ui .label-sheet { zoom: .78; }

  body.m-ui .settings-toolbar { top: calc(54px + env(safe-area-inset-top)); }
  body.m-ui .settings-save {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 28; margin: 0;
    background: #fff; border-top: 1px solid var(--border); border-left: 0; border-radius: 0;
    padding: .5rem .75rem calc(.5rem + env(safe-area-inset-bottom));
    box-shadow: 0 -3px 12px rgba(15, 23, 42, .08);
  }
  body.m-ui[data-route=settings] main { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
  body.m-ui .settings-save .btn { min-height: 48px; flex: 1; justify-content: center; }
  body.m-ui .purchase-save-bar { bottom: 0; padding-bottom: calc(.55rem + env(safe-area-inset-bottom)); }
  body.m-ui .purchase-save-actions .btn, body.m-ui .m-foot .m-fbtn, body.m-ui .m-pill { min-height: 48px; }
  body.m-ui #mpCancelDraft, body.m-ui .m-foot button, body.m-ui .m-foot a { min-height: 44px; }
  body.m-ui p a:not(.btn), body.m-ui li a:not(.btn) { display: inline-flex; align-items: center; min-height: 44px; padding: .2rem .15rem; }
  body.m-ui .wp-namebtn, body.m-ui .wp-slabbtn { min-height: 44px; white-space: normal; }
  body.m-ui .wp-sheet select.wp-cat { min-height: 44px; font-size: 1rem; width: 100%; }
  body.m-ui .cat-row :is(input, select, button) { min-height: 44px; }
  body.m-ui .m-line:has(:is(button, a, input, select)) { min-height: 44px; }
  body.m-ui .m-sale-switch button { min-height: 44px; }
  body.m-ui .m-period a { display: inline-flex; align-items: center; min-height: 44px; }
  body.m-ui dialog:not(.m-sheet):not(.item-editor-modal) { width: 100vw; max-width: 100vw; max-height: 100dvh; margin: 0; border-radius: 0; }
  body.m-ui dialog:not(.m-sheet):not(.item-editor-modal) #modalBody { max-height: 100dvh; padding: calc(.9rem + env(safe-area-inset-top)) 1rem calc(1rem + env(safe-area-inset-bottom)); }
  body.m-ui .modal-actions { position: sticky; bottom: 0; display: flex; gap: .4rem; background: #fff; padding-top: .6rem; }
  body.m-ui .modal-actions .btn { flex: 1; min-height: 48px; justify-content: center; }
}

/* v2.41.17 Phone design system. Widths above 768px do not use this block.
   Spacing, type, filters, list rows, sticky primary action, keyboard inset.
   Print resets for this block live in the print section below. */
@media (max-width: 768px) {
  body.m-ui {
    --m-gap: 12px;
    --m-radius: 12px;
    --kb: 0px;
    scroll-padding-top: calc(60px + env(safe-area-inset-top));
    scroll-padding-bottom: calc(96px + var(--kb, 0px) + env(safe-area-inset-bottom));
  }
  body.m-ui :is(input, select, textarea):focus {
    scroll-margin-top: calc(68px + env(safe-area-inset-top));
    scroll-margin-bottom: calc(128px + var(--kb, 0px));
  }
  body.m-ui .card { border-radius: var(--m-radius); }
  body.m-ui .btn kbd { display: none; }

  /* Search full width. Dates, status and other short fields sit in pairs. */
  body.m-ui .card > .grid.cols-4,
  body.m-ui .card > .grid.cols-5,
  body.m-ui .grid.m-filters,
  body.m-ui .purchase-filters .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .55rem;
  }
  body.m-ui .card > .grid.cols-4 > div:has(> input:not([type=date]):not([type=number]):not([type=checkbox]):not([type=radio])),
  body.m-ui .card > .grid.cols-5 > div:has(> input:not([type=date]):not([type=number]):not([type=checkbox]):not([type=radio])),
  body.m-ui .grid.m-filters > div:has(> input:not([type=date]):not([type=number]):not([type=checkbox]):not([type=radio])),
  body.m-ui .purchase-filters .grid > div:has(> input:not([type=date]):not([type=number]):not([type=checkbox]):not([type=radio])) {
    grid-column: 1 / -1;
  }
  body.m-ui .card > .grid:has(.tabs) { grid-template-columns: minmax(0, 1fr); }
  body.m-ui .settings-form .grid,
  body.m-ui .settings-form .card > .grid.cols-4,
  body.m-ui .settings-form .card > .grid.cols-5 { grid-template-columns: minmax(0, 1fr); }
  body.m-ui #rangeCard > .row { flex-wrap: wrap; align-items: flex-end; gap: .45rem; width: 100%; }
  body.m-ui #rangeCard > .row > div:not(.row) { flex: 1 1 calc(50% - .45rem); min-width: 0; }
  body.m-ui #rangeCard > .row > .row { flex: 1 1 100%; flex-wrap: wrap; }
  body.m-ui #rangeCard [data-preset] { flex: 1 1 calc(33% - .4rem); justify-content: center; text-align: center; }

  /* Header actions scroll sideways. The primary action stays at the bottom of the phone. */
  body.m-ui #view > .row.between > .row {
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: none;
    gap: .4rem;
    padding-bottom: .1rem;
  }
  body.m-ui #view > .row.between > .row::-webkit-scrollbar { display: none; }
  body.m-ui #view > .row.between .btn { flex: 0 0 auto; white-space: nowrap; }
  body.m-ui .m-sticky-go {
    position: fixed;
    z-index: 27;
    left: max(12px, env(safe-area-inset-left));
    right: max(12px, env(safe-area-inset-right));
    bottom: calc(10px + env(safe-area-inset-bottom) + var(--kb, 0px));
    width: auto;
    min-height: 48px;
    justify-content: center;
    box-shadow: 0 8px 18px rgba(15, 23, 42, .22);
  }
  body.m-ui:has(.m-sticky-go) main { padding-bottom: calc(78px + env(safe-area-inset-bottom) + var(--kb, 0px)); }

  body.m-ui .m-bar { bottom: calc(12px + env(safe-area-inset-bottom) + var(--kb, 0px)); }
  body.m-ui .m-foot { bottom: var(--kb, 0px); }
  body.m-ui .m-page { padding-bottom: calc(86px + env(safe-area-inset-bottom) + var(--kb, 0px)); }
  body.m-ui .settings-save,
  body.m-ui .purchase-save-bar { bottom: var(--kb, 0px); }
  body.m-ui .toast {
    left: 12px;
    right: 12px;
    transform: translateY(200%);
    max-width: none;
    width: auto;
    bottom: calc(16px + env(safe-area-inset-bottom) + var(--kb, 0px));
  }
  body.m-ui .toast.show { transform: translateY(0); }
  body.m-ui[data-route=home] .toast,
  body.m-ui:has(.m-bar:not([hidden])) .toast { bottom: calc(84px + env(safe-area-inset-bottom) + var(--kb, 0px)); }
  body.m-ui.m-full .toast { bottom: auto; top: calc(62px + env(safe-area-inset-top)); transform: translateY(-140%); }
  body.m-ui.m-full .toast.show { transform: translateY(0); }

  .m-filter, .m-icon-btn { border: 0; box-shadow: inset 0 0 0 1px #d5dbe4; }
  .m-filter select { inset: 0; width: 44px; height: 44px; }
  .m-sum b { font-size: clamp(1rem, 5vw, 1.22rem); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
  .m-seg a { padding: 0 4px; text-align: center; line-height: 1.15; }
  body.m-ui .table.m-cards td a,
  body.m-ui .table.m-auto-cards td a,
  body.m-ui .bo-widget-list > a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    max-width: 100%;
  }
  body.m-ui .table.m-cards td:first-child > a,
  body.m-ui .table.m-auto-cards td:first-child > a { min-width: min(100%, 8rem); }
  body.m-ui td.empty, body.m-ui .m-empty, body.m-ui .empty {
    padding: 1.4rem .8rem;
    text-align: center;
    color: #64748b;
    line-height: 1.45;
  }
  body.m-ui .m-more { margin: .35rem 0 .15rem; }
  body.m-ui .m-row,
  body.m-ui .table.m-cards tbody tr,
  body.m-ui .table.m-auto-cards tbody tr {
    content-visibility: auto;
    contain-intrinsic-size: auto 72px;
  }
  body.m-ui .stat .value, body.m-ui .m-r b, body.m-ui .ins-kpis b { overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
  body.m-ui .insights > .row.between { flex-direction: column; align-items: flex-start; gap: .35rem; }
  body.m-ui .ins-lists { grid-template-columns: minmax(0, 1fr); }
  body.m-ui .chart7 { max-width: 100%; }
  body.m-ui a.stat { text-decoration: none; color: inherit; }
  .auth-screen {
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }
  .auth-card { width: min(420px, 100%); padding: 1.15rem 1rem; }
  .auth-card .btn, .auth-card input, .auth-card select { min-height: 48px; font-size: 1rem; }
  .pin-channels { grid-template-columns: 1fr; }
  .auth-card .otp-input { letter-spacing: .28em; font-size: 1.35rem; }
  .m-sale-switch button { white-space: normal; line-height: 1.15; }
  .m-sale-price { flex-wrap: wrap; }
  .m-sale-price button { min-width: 0; flex: 1 1 7rem; }
  .m-search input { min-height: 44px; }
  body.m-ui .m-more { min-height: 48px; width: 100%; }
  /* A pair of dates beside a button (debit notes) shares the row and stays inside the screen. */
  body.m-ui #view > .row.wrap > .row.wrap { flex: 1 1 100%; min-width: 0; max-width: 100%; }
  body.m-ui #view > .row.wrap > .row.wrap > div { flex: 1 1 calc(50% - .5rem); min-width: 0; max-width: calc(50% - .15rem); }
}
@media (max-width: 400px) {
  .m-tools { flex-wrap: wrap; row-gap: 8px; }
  .m-search { flex: 1 1 100%; }
  .m-new { margin-left: auto; }
  .m-seg a { font-size: .8rem; }
  .m-head h2 { font-size: 1.05rem; }
}
@media print {
  /* Phone rules above also match A4/A5 paper. Put the GST summary back beside a compact totals column. */
  body.m-ui .inv.a4, body.m-ui .inv.thermal { width: auto; min-height: 0; padding: 0; zoom: 1; }
  body.m-ui .inv.a4 .inv-head, body.m-ui .inv.a4 .inv-party, body.m-ui .inv.a4 .inv-bottom, body.m-ui .inv.a4 .inv-foot { flex-direction: row; align-items: stretch; }
  body.m-ui .inv.a4 .inv-title { text-align: right; }
  body.m-ui .inv.a4 .inv-doc-head { display: grid; }
  body.m-ui .inv.a4 .inv-bottom { flex-wrap: nowrap; justify-content: space-between; width: 100%; }
  body.m-ui .inv.a4 .tax-wrap { display: block; flex: 1 1 auto; width: auto; min-width: 0; max-width: none; overflow: visible; }
  body.m-ui .inv.a4 table.tot { display: table; flex: 0 0 auto; width: auto; min-width: 250px; max-width: none; }
  body.m-ui .inv.a4.a5 table.tot { min-width: 170px; }
  body.m-ui .inv.a4 table.tax { width: auto; }
  body.m-ui .label-sheet { zoom: 1; }
  body.m-ui .m-sticky-go { position: static; left: auto; right: auto; bottom: auto; width: auto; box-shadow: none; }
  body.m-ui .m-row,
  body.m-ui .table.m-cards tbody tr,
  body.m-ui .table.m-auto-cards tbody tr { content-visibility: visible; contain-intrinsic-size: none; }
  body.m-ui .toast { left: 50%; right: auto; width: auto; transform: none; }
}
