/* iPOS Phone & Tablet shell (js/mshell.js). Everything is scoped to body.ms-phone / body.ms-tab, so the PC layout is untouched.
 * Colours come from the app's own --brand variables, so every app keeps its own look. */

/* ---------- always-available bits (hidden on PC) ---------- */
#msBack, #msMoreBtn, #msFab, #msPhoneBtn, #msSheet, .ms-toast { display: none; }
body.ms-on #msSheet { display: block; }

/* ============================ PHONE ============================ */
body.ms-phone { --bar-h: 0px; font-size: 16px; overscroll-behavior-y: none; }
body.ms-phone .shopbar { display: none; }                      /* shop name is shown on the dashboard instead */
body.ms-phone .app { min-height: 100dvh; }
body.ms-phone .sidenav { display: none !important; }
body.ms-phone .main { min-width: 0; }

/* compact app bar */
body.ms-phone .topbar { position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 6px; flex-wrap: nowrap;
  padding: calc(8px + env(safe-area-inset-top)) 10px 8px 12px; min-height: 54px; background: var(--brand-bar, var(--card)); border-bottom: 1px solid var(--line); }
body.ms-phone .topbar h1 { flex: 1; min-width: 0; font-size: 19px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -.2px; }
body.ms-phone #msBack { display: none; width: 40px; height: 40px; margin-left: -6px; border: 0; border-radius: 12px; background: transparent; color: var(--ink); align-items: center; justify-content: center; flex: none; padding: 0; }
body.ms-phone #msBack svg { width: 24px; height: 24px; }
body.ms-phone.ms-detail #msBack { display: flex; }
body.ms-phone #msBack:active, body.ms-phone #msMoreBtn:active { background: var(--brand-soft, #eef2f6); }
body.ms-phone #msMoreBtn { display: flex; width: 40px; height: 40px; border: 0; border-radius: 12px; background: transparent; color: var(--ink); align-items: center; justify-content: center; flex: none; padding: 0; }
body.ms-phone #msMoreBtn[hidden] { display: none; }
body.ms-phone #msMoreBtn svg { width: 22px; height: 22px; }
body.ms-phone .topbar .gs-btn { width: 40px; height: 40px; min-height: 0; padding: 0; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex: none; border: 0; background: var(--brand-soft, #eef2f6); color: var(--brand); }
body.ms-phone .topbar .gs-btn svg { width: 21px; height: 21px; }
body.ms-phone .topbar .gs-btn span { display: none; }
body.ms-phone .topbar .user-chip { display: none !important; }
body.ms-phone .topbar .inst-btn { margin: 0; width: 40px; height: 40px; padding: 0; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex: none; }
body.ms-phone .topbar .inst-btn[hidden] { display: none !important; }
body.ms-phone #topActions { display: none; }
body.ms-phone.ms-acts-open #topActions { display: flex; order: 9; flex: 1 0 100%; overflow-x: auto; flex-wrap: nowrap; padding-top: 6px; scrollbar-width: none; }
body.ms-phone.ms-acts-open .topbar { flex-wrap: wrap; }
body.ms-phone.ms-acts-open #topActions > * { flex: none; }

/* page area */
body.ms-phone .content { padding: 12px 12px calc(96px + env(safe-area-inset-bottom)); }
body.ms-phone.ms-has-fab .content { padding-bottom: calc(150px + env(safe-area-inset-bottom)); }
body.ms-phone .banner { margin: 10px 12px 0; }
body.ms-phone .card { padding: 14px; border-radius: 16px; margin-bottom: 12px; }
body.ms-phone h2 { font-size: 16.5px; }

/* touch-sized controls (16 px text stops iPhone zooming in) */
body.ms-phone input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]), body.ms-phone select, body.ms-phone textarea { font-size: 16px; min-height: 46px; border-radius: 12px; }
body.ms-phone .btn { min-height: 44px; border-radius: 12px; font-weight: 700; }
body.ms-phone .btn.sm { min-height: 38px; padding: 6px 12px; }
body.ms-phone label { font-size: 13px; }
body.ms-phone .g2 { grid-template-columns: minmax(0, 1fr); }
body.ms-phone .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
body.ms-phone .g4, body.ms-phone .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
body.ms-phone .stat { padding: 12px 14px; border-radius: 16px; }
body.ms-phone .stat .val { font-size: 21px; }
body.ms-phone .tabs { margin: 0 -12px 12px; padding: 0 12px; gap: 2px; position: sticky; top: calc(54px + env(safe-area-inset-top)); z-index: 30; background: var(--bg); scrollbar-width: none; }
body.ms-phone .tabs::-webkit-scrollbar { display: none; }
body.ms-phone .tabs button { padding: 12px 14px; font-size: 15px; }
body.ms-phone .row { gap: 8px; }
body.ms-phone .row > .btn { flex: 1 1 auto; }

/* bottom tabs */
body.ms-phone .bottomnav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 45; background: rgba(255,255,255,.97); backdrop-filter: blur(10px); border-top: 1px solid var(--line); padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
body.ms-phone .bottomnav a { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 7px 2px 5px; font-size: 11.5px; font-weight: 600; color: var(--muted); border-radius: 14px; text-decoration: none; position: relative; }
body.ms-phone .bottomnav a svg { width: 24px; height: 24px; }
body.ms-phone .bottomnav a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.ms-phone .bottomnav a.active { color: var(--brand); }
body.ms-phone .bottomnav a.active::before { content: ""; position: absolute; top: 0; left: 28%; right: 28%; height: 3px; border-radius: 0 0 4px 4px; background: var(--brand); }
body.ms-phone .bottomnav a:active { background: var(--brand-soft, #eef2f6); }

/* floating main action */
body.ms-on #msFab { position: fixed; z-index: 44; right: 14px; bottom: calc(76px + env(safe-area-inset-bottom)); height: 54px; padding: 0 20px 0 16px; border: 0; border-radius: 28px; background: var(--brand); color: #fff; font-weight: 800; font-size: 15.5px; align-items: center; gap: 8px; box-shadow: 0 8px 22px rgba(0,0,0,.28); }
body.ms-on #msFab:not([hidden]) { display: flex; }
body.ms-on #msFab svg { width: 22px; height: 22px; flex: none; }
body.ms-on #msFab:active { transform: scale(.97); }
body.ms-tab #msFab { bottom: 24px; right: 24px; }

/* tables -> cards */
body.ms-phone table.ms-cards { display: block; }
body.ms-phone table.ms-cards thead { display: none; }
body.ms-phone table.ms-cards tbody, body.ms-phone table.ms-cards tfoot { display: block; }
body.ms-phone table.ms-cards tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px 14px; padding: 12px 4px; border-bottom: 1px solid var(--line); align-items: start; }
body.ms-phone table.ms-cards tr:last-child { border-bottom: 0; }
body.ms-phone table.ms-cards tr[onclick], body.ms-phone table.ms-cards tr[data-go], body.ms-phone table.ms-cards tr.click, body.ms-phone table.ms-cards tr.clickable { cursor: pointer; }
body.ms-phone table.ms-cards tr:active { background: var(--brand-soft, #f1f5f9); }
body.ms-phone table.ms-cards td { display: block; padding: 0 !important; border: 0 !important; min-width: 0; word-break: break-word; text-align: left !important; font-size: 14.5px; }
body.ms-phone table.ms-cards td[data-label]:not(:empty)::before { content: attr(data-label); display: block; font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin-bottom: 1px; }
body.ms-phone table.ms-cards td.ms-title { grid-column: 1 / -1; font-size: 16.5px; font-weight: 800; }
body.ms-phone table.ms-cards td.ms-title::before { display: none !important; }
body.ms-phone table.ms-cards tr.ms-hasava { position: relative; padding-left: 60px; min-height: 66px; }
body.ms-phone table.ms-cards td.ms-ava { position: absolute; left: 6px; top: 12px; width: 46px; grid-column: auto; }
body.ms-phone table.ms-cards td.ms-ava::before { display: none !important; }
body.ms-phone table.ms-cards td.ms-empty { display: none; }
body.ms-phone table.ms-cards td.ms-act { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; }
body.ms-phone table.ms-cards td.ms-act::before { display: none !important; }
body.ms-phone table.ms-cards td.ms-act .btn { flex: 1 1 auto; }
body.ms-phone table.ms-cards td.num, body.ms-phone table.ms-cards td[style*="right"] { font-variant-numeric: tabular-nums; }
body.ms-phone table.ms-cards tr.total, body.ms-phone table.ms-cards tfoot tr { background: var(--brand-soft, #f1f5f9); border-radius: 12px; padding: 12px; margin-top: 6px; font-weight: 800; }
body.ms-phone table.ms-cards td[colspan] { grid-column: 1 / -1; }
body.ms-on .ms-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -2px; }
body.ms-on table.ms-wide { min-width: 640px; }

/* forms: full-screen sheets with the Save bar always in reach */
body.ms-phone .modal-bg { padding: 0; align-items: stretch; background: var(--card); overflow: hidden; }
body.ms-phone .modal, body.ms-phone .modal.wide { max-width: none; width: 100%; height: 100dvh; max-height: none; min-height: 0; border-radius: 0; box-shadow: none; display: flex; flex-direction: column; }
body.ms-phone .modal header { flex: none; padding: calc(10px + env(safe-area-inset-top)) 14px 10px; min-height: 56px; background: var(--card); border-bottom: 1px solid var(--line); }
body.ms-phone .modal header h2 { font-size: 18px; }
body.ms-phone .modal .body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px; }
body.ms-phone .modal footer { flex: none; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--card); display: flex; gap: 8px; justify-content: stretch; box-shadow: 0 -6px 18px rgba(0,0,0,.06); }
body.ms-phone .modal footer .btn { flex: 1 1 0; min-height: 50px; font-size: 16px; }
body.ms-phone .modal footer .btn.primary { flex: 2 1 0; order: 9; }
body.ms-phone.kb-open .modal { height: var(--vvh, 100dvh); }
body.ms-phone.kb-open .modal .body { padding-bottom: 36vh; }
body.ms-phone.kb-open .modal footer { display: none; }
body.ms-phone.kb-open #msFab, body.ms-phone.kb-open .bottomnav { display: none; }
body.ms-phone .toast, body.ms-phone #toast { bottom: calc(80px + env(safe-area-inset-bottom)); }

/* More page as big tiles */
body.ms-phone .more-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
body.ms-phone .more-item { display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 10px; min-height: 92px; margin: 0; padding: 16px; border-radius: 18px; text-decoration: none; color: var(--ink); }
body.ms-phone .more-item svg { width: 26px; height: 26px; color: var(--brand); }
body.ms-phone .more-item b { font-size: 15px; }
body.ms-tab .more-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
body.ms-tab .more-item { display: flex; flex-direction: column; gap: 10px; min-height: 100px; margin: 0; padding: 18px; text-decoration: none; color: var(--ink); }
body.ms-tab .more-item svg { width: 28px; height: 28px; color: var(--brand); }

/* demo pill: a thin chip above the bottom tabs, never over the content */
body.ms-on #demoPill { left: 10px !important; right: auto !important; bottom: calc(76px + env(safe-area-inset-bottom)) !important; padding: 5px 10px !important; gap: 6px !important; border-radius: 999px !important; font-size: 11px !important; max-width: calc(100vw - 110px); }
body.ms-on #demoPill span { display: none !important; }
body.ms-tab #demoPill { bottom: 14px !important; }

/* ---- bottom sheets ---- */
body.ms-on #msSheet { position: fixed; inset: 0; z-index: 90; }
.ms-sheet-bg { position: absolute; inset: 0; background: rgba(10,20,30,.45); animation: msf .15s ease; }
.ms-sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: 82dvh; display: flex; flex-direction: column; background: var(--card); border-radius: 22px 22px 0 0; padding: 8px 14px calc(14px + env(safe-area-inset-bottom)); animation: msu .2s ease; max-width: 640px; margin: 0 auto; }
.ms-grab { width: 42px; height: 5px; border-radius: 3px; background: var(--line); margin: 2px auto 10px; }
.ms-sheet h3 { margin: 2px 4px 10px; font-size: 17px; }
.ms-sheet-body { overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.ms-act-row { min-height: 52px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); font-size: 16px; font-weight: 700; text-align: left; padding: 0 16px; color: var(--ink); }
.ms-act-row.bad { color: var(--bad); }
.ms-act-row:active { background: var(--brand-soft, #eef2f6); }
@keyframes msu { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes msf { from { opacity: 0; } to { opacity: 1; } }
.ms-toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translate(-50%, 10px); background: #111827; color: #fff; padding: 10px 18px; border-radius: 999px; font-weight: 700; z-index: 120; opacity: 0; transition: .25s; }
body.ms-on .ms-toast { display: block; } .ms-toast.on { opacity: 1; transform: translate(-50%, 0); }
#msPhoneBtn { display: block; position: fixed; right: 10px; top: 10px; z-index: 100; border: 0; border-radius: 999px; padding: 9px 16px; background: var(--brand); color: #fff; font-weight: 800; box-shadow: 0 4px 14px rgba(0,0,0,.3); }

/* ============================ TABLET ============================ */
body.ms-tab { --bar-h: 52px; font-size: 16px; }
body.ms-tab .bottomnav { display: none !important; }
body.ms-tab .shopbar { height: 52px; min-height: 52px; padding: 0 18px; }
body.ms-tab .shopbar .nav-toggle { display: none; }
/* slim icon rail with the labels underneath */
body.ms-tab .sidenav { display: flex !important; width: 86px; position: sticky; top: var(--bar-h); height: calc(100dvh - var(--bar-h)); }
body.ms-tab .sidenav .brand { display: none; }
body.ms-tab .sidenav nav { padding: 8px 6px; overflow-y: auto; scrollbar-width: none; }
body.ms-tab .navlink { flex-direction: column; justify-content: center; gap: 4px; text-align: center; padding: 11px 2px; margin-bottom: 2px; min-height: 62px; border-radius: 14px; }
body.ms-tab .navlink svg { width: 24px; height: 24px; }
body.ms-tab .navlink span { display: block !important; font-size: 10.5px; line-height: 1.15; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
body.ms-tab .navlink[data-kbd]::after { display: none !important; }
body.ms-tab .netstate { display: none; }
body.ms-tab .main { min-width: 0; }
body.ms-tab .topbar { top: var(--bar-h); padding: 12px 22px; }
body.ms-tab #msBack { display: none; }
body.ms-tab #msMoreBtn { display: flex; width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink); align-items: center; justify-content: center; padding: 0; }
body.ms-tab #msMoreBtn[hidden] { display: none; }
body.ms-tab #msMoreBtn svg { width: 22px; height: 22px; }
body.ms-tab #topActions { display: none; }
body.ms-tab.ms-acts-open #topActions { display: flex; }
body.ms-tab .content { padding: 18px 22px 110px; }
body.ms-tab .g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
body.ms-tab .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
body.ms-tab .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
body.ms-tab .kv { grid-template-columns: 150px 1fr; }
body.ms-tab .btn { min-height: 44px; }
body.ms-tab .btn.sm { min-height: 38px; }
body.ms-tab input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]), body.ms-tab select { min-height: 44px; font-size: 16px; }
body.ms-tab table td, body.ms-tab table th { padding-top: 12px; padding-bottom: 12px; }
body.ms-tab .tabs button { padding: 13px 18px; font-size: 15px; }
body.ms-tab .modal-bg { padding: 5vh 16px; align-items: flex-start; }
body.ms-tab .modal { max-width: 680px; max-height: 90dvh; display: flex; flex-direction: column; border-radius: 20px; }
body.ms-tab .modal.wide { max-width: 860px; }
body.ms-tab .modal .body { overflow-y: auto; flex: 1; }
body.ms-tab .modal footer .btn { min-height: 46px; }
body.ms-tab.kb-open .modal-bg { padding-top: 2vh; }
/* portrait tablets: keep 2 columns */
@media (max-width: 820px) { body.ms-tab .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } body.ms-tab .more-list { grid-template-columns: repeat(2, 1fr); } }

/* ============ number pad + keyboard fit (touch screens) ============ */
#numpad { position: fixed; left: 0; right: 0; bottom: 0; z-index: 400; display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; padding: 9px 10px calc(10px + env(safe-area-inset-bottom)); background: #e9eef2; border-top: 1px solid #c9d3db; box-shadow: 0 -8px 24px rgba(0,0,0,.16); max-width: 640px; margin: 0 auto; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
#numpad[hidden] { display: none; }
#numpad button { height: 52px; border: 0; border-radius: 12px; background: #fff; font-size: 24px; font-weight: 700; color: #1d2b36; box-shadow: 0 1px 0 #b9c4cc; cursor: pointer; -webkit-tap-highlight-color: transparent; }
#numpad button:active { background: #dbe5ec; }
#numpad button.fn { background: #d6dee5; font-size: 16px; font-weight: 700; }
#numpad button.kb { font-size: 13px; }
#numpad button.ok { background: var(--brand, #0e7490); color: #fff; font-size: 17px; box-shadow: none; }
#numpad.int .pt { visibility: hidden; }
body.np-open { padding-bottom: 292px !important; }
body.np-open .modal-bg { padding-bottom: 0; }
body.np-open .modal { height: calc(100dvh - 292px) !important; max-height: calc(100dvh - 292px) !important; }
body.np-open #msFab, body.np-open .bottomnav, body.np-open #demoPill { display: none !important; }
body.np-open input[data-np="1"]:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft, rgba(14,116,144,.22)); }
body.ms-on input[data-np="1"] { caret-color: var(--brand); }

@media print { #msFab, #msBack, #msMoreBtn, #msSheet, #numpad, #msPhoneBtn { display: none !important; } }

/* controls inside card rows fill their cell */
body.ms-phone table.ms-cards td input:not([type=checkbox]):not([type=radio]), body.ms-phone table.ms-cards td select { width: 100%; min-width: 0; }
body.ms-phone table.ms-cards td input[type=time], body.ms-phone table.ms-cards td input[type=date] { padding-left: 8px; padding-right: 4px; }

body.ms-phone table.ms-cards { min-width: 0 !important; width: 100% !important; }
body.ms-phone .tablewrap { overflow-x: visible; }
body.ms-phone table.ms-cards td.ms-title { order: -1; }

/* nothing may push the page wider than the screen */
body.ms-on .main, body.ms-on .content, body.ms-on .card, body.ms-on .grid > *, body.ms-on .modal .body { min-width: 0; max-width: 100%; }
body.ms-on .tablewrap { max-width: 100%; overflow-x: auto; }
body.ms-on .content { overflow-x: clip; }
body.ms-phone table.ms-cards tr.ms-head { display: none; }
body.ms-phone .topbar:has(.ctx) { flex-wrap: wrap; row-gap: 6px; }
body.ms-phone .topbar .ctx { flex: 1 0 100%; min-width: 0; order: 8; }
body.ms-phone .topbar .ctx select { flex: 1; min-width: 0; max-width: none; }
body.ms-tab .topbar:has(.ctx) { flex-wrap: wrap; row-gap: 6px; }
body.ms-tab .topbar .ctx { flex: 1 0 100%; min-width: 0; order: 8; }
body.ms-tab .topbar { flex-wrap: wrap; row-gap: 6px; }
body.ms-tab #topActions { flex-wrap: wrap; max-width: 100%; }
body.ms-on .keyhint { display: none !important; }
body.ms-on:has(.modal-bg) #demoPill, body.ms-on:has(#msSheet) #demoPill { display: none !important; }
body.ms-on.ms-acts-open #topActions > button, body.ms-on.ms-acts-open #topActions > a { display: none; }
body.ms-phone.ms-acts-open #topActions { align-items: center; gap: 8px; }
body.ms-phone.ms-acts-open #topActions input, body.ms-phone.ms-acts-open #topActions select { flex: 1 1 0; min-width: 0; }

/* fields that span columns must not create extra narrow columns */
body.ms-phone .g2 > [style*="grid-column"], body.ms-phone .g3 > [style*="span 2"], body.ms-phone .g3 > [style*="span 3"], body.ms-phone .g4 > [style*="span 3"], body.ms-phone .g4 > [style*="span 4"] { grid-column: 1 / -1 !important; }
body.ms-tab .g2 > [style*="span 3"], body.ms-tab .g3 > [style*="span 3"] { grid-column: 1 / -1 !important; }
@media (max-width: 820px) { body.ms-tab .g3 > [style*="span 3"], body.ms-tab .g3 > [style*="span 2"] { grid-column: 1 / -1 !important; } }
