/* The phone app layout, used below 761px and inside the desktop phone preview.
   Made for someone standing in a warehouse: large targets, one column, bins first. */
@media (max-width: 760px) {
  .app-body { --tabs: calc(60px + env(safe-area-inset-bottom, 0px)); font-size: 16px; }
  /* Inside the preview it should feel like a phone: dragging moves the screen instead of selecting text */
  .is-embed { user-select: none; -webkit-user-select: none; }
  .is-embed :is(input, textarea) { user-select: text; -webkit-user-select: text; }
  .app-body.is-embed { --bar: 0px; }
  .is-embed .demo-bar { display: none; }
  html:has(.is-embed) { scrollbar-width: none; }
  html:has(.is-embed)::-webkit-scrollbar { display: none; }

  /* Title bar */
  .m-bar { position: sticky; top: var(--bar); z-index: 12; display: flex; align-items: center; gap: 6px; min-height: 60px; padding: 8px 10px 8px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
  .m-bar h1, .m-bar .m-title { flex: 1; min-width: 0; margin: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font: 700 25px/1.2 var(--head); }
  .m-bar > div { display: flex; gap: 2px; }
  .m-bar > div:empty { display: none; }
  .m-app--sub .m-bar { padding-left: 6px; }
  .m-app--sub .m-bar h1, .m-app--sub .m-bar .m-title { font-size: 21px; }
  .m-icon { position: relative; display: inline-grid; place-items: center; flex: none; width: 44px; height: 44px; border: 0; border-radius: 10px; background: none; color: var(--ink); cursor: pointer; }
  .m-icon:active { background: var(--soft); }
  .m-icon .icon { width: 22px; height: 22px; }
  .m-icon .dot { top: 2px; right: 1px; }

  .app-body .content.m-content { max-width: none; padding: 14px 14px calc(var(--tabs) + 28px); }
  .app-body .m-app--fab .content.m-content { padding-bottom: calc(var(--tabs) + 96px); }

  /* Bottom tab bar and add button */
  .m-tabs { position: fixed; z-index: 14; left: 0; right: 0; bottom: 0; height: var(--tabs); padding: 0 4px env(safe-area-inset-bottom, 0px); background: var(--surface); border-top: 1px solid var(--line); }
  .m-tabs ul { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); height: 100%; }
  .m-tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; height: 100%; padding: 6px 0; color: var(--ink-2); font-size: 12px; font-weight: 600; line-height: 1.2; text-decoration: none; white-space: nowrap; }
  .m-tabs i { position: relative; display: grid; place-items: center; width: 44px; height: 25px; border-radius: 99px; font-style: normal; }
  .m-tabs i .icon { width: 18px; height: 18px; }
  .m-tabs i .dot { top: -4px; right: 2px; min-width: 16px; height: 16px; padding: 0 4px; font-size: 12px; line-height: 16px; }
  .m-tabs a.is-on { color: var(--accent-dark); font-weight: 700; }
  .m-tabs a.is-on i { background: var(--accent-tint); }
  .m-fab { position: fixed; z-index: 13; right: 16px; bottom: calc(var(--tabs) + 16px); display: grid; place-items: center; width: 56px; height: 56px; border: 0; border-radius: 16px; background: var(--accent); color: #fff; box-shadow: 0 12px 24px -8px rgba(31, 42, 49, .7); cursor: pointer; }
  .m-fab .icon { width: 26px; height: 26px; }
  .m-fab:active { transform: scale(.95); }

  /* Screens shared with the desktop layout: the title bar already names them */
  .m-content .page-head { gap: 10px; }
  .m-content .page-head > div:first-child > h1 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .m-content .page-head p { margin: 0; font-size: 15px; }
  .m-content .page-head .page-actions:not(:has(.filter)) { display: none; }
  .m-content .page-head .page-actions, .m-content .page-head .filter { width: 100%; }
  .m-content .back { display: none; }
  .m-content .record-head { align-items: stretch; flex-direction: column; gap: 10px; }
  .m-content .record-head h1 { font-size: 24px; line-height: 1.2; }
  .m-content .record-head p { font-size: 15px; }
  .m-content .actionbar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .m-content .actionbar .btn:first-child:last-child, .m-content .actionbar .btn-primary:first-child { grid-column: 1 / -1; }
  .m-content .actionbar > .btn-primary:first-child ~ :last-child:nth-child(even), .m-content .actionbar > :first-child:not(.btn-primary) ~ :last-child:nth-child(odd) { grid-column: 1 / -1; }

  .btn { min-height: 48px; font-size: 15.5px; }
  .btn-small { min-height: 44px; font-size: 14.5px; }
  .badge { font-size: 13px; }
  .card { padding: 14px; border-radius: 12px; }
  .card-flush { padding: 0; }
  .card-head a { display: inline-flex; align-items: center; min-height: 36px; }
  .columns { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .column { gap: 12px; }
  .content .segmented { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
  .segmented button { min-height: 44px; padding: 0 8px; }
  .content > .m-list { margin-top: 12px; }
  .list-count { font-size: 14px; }

  /* Filters */
  .filterbar { gap: 10px; }
  .searchfield { flex: 1 1 100%; max-width: none; min-height: 48px; }
  .searchfield input { height: 46px; font-size: 16px; }
  .m-content .tabs { margin-inline: -14px; padding: 2px 14px; max-width: none; width: calc(100% + 28px); gap: 8px; background: none; border-radius: 0; }
  .m-content .tabs { display: flex; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .m-content .tabs::-webkit-scrollbar { display: none; }
  .m-content .tabs .tab { display: inline-flex; flex: none; align-items: center; gap: 7px; font-weight: 600; white-space: nowrap; cursor: pointer; min-height: 42px; padding: 0 15px; border: 1px solid var(--line-2); border-radius: 99px; background: var(--surface); color: var(--ink); box-shadow: none; }
  .m-content .tabs .tab.is-active { background: var(--navy); border-color: var(--navy); color: #fff; }
  .m-content .tabs .tab.is-active .pill { background: #fff; color: var(--ink); }
  .filter-selects { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; }
  .filter-selects .filter:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .filter select { width: 100%; min-height: 46px; font-size: 16px; }
  .filter-inline select { min-height: 44px; }

  /* Lists */
  .m-list { display: block; margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
  .m-list > li + li { border-top: 1px solid var(--line); }
  .m-card { padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
  .m-card--list { padding: 6px 14px; }
  .m-row { display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 12px 14px; color: var(--ink); text-decoration: none; }
  .m-row:active { background: var(--accent-tint); }
  .m-row-main { display: grid; flex: 1; min-width: 0; line-height: 1.38; }
  .m-row-main strong { font-size: 16px; font-weight: 600; }
  .m-row-main > span { color: var(--ink-2); font-size: 14.5px; }
  .m-row-main > span .code { margin-right: 4px; color: var(--ink); }
  .m-row-main small { margin-top: 2px; color: var(--ink-2); font-size: 13.5px; }
  .m-row-main small .late { font-size: inherit; }
  .m-row-end { display: grid; justify-items: end; gap: 2px; flex: none; max-width: 44%; text-align: right; }
  .m-row-end small { color: var(--ink-2); font-size: 13px; }
  .m-qty { font: 700 24px/1.1 var(--head); font-variant-numeric: tabular-nums; }
  .m-flag { display: inline-flex; align-items: center; gap: 5px; font-weight: 700; }
  .m-flag .icon { width: 14px; height: 14px; }
  .flag-low { color: var(--warn); }
  .flag-out { color: var(--danger); }
  .m-count { padding: 0 2px 8px; color: var(--ink-2); font-size: 14px; }
  .m-group-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 36px; margin-top: 4px; }
  .m-group-head h2 { font: 700 20px/1.2 var(--head); }
  .m-group-head a { display: inline-flex; align-items: center; min-height: 40px; font-size: 15px; font-weight: 600; text-decoration: none; }
  .m-list .queue > li > a { padding: 12px 14px; }
  .m-list .queue > li:first-child > a { padding-top: 12px; }

  /* Search and More */
  .m-search--wide { margin-bottom: 14px; }
  .m-row strong.code { font-size: 15px; }
  .m-me { display: flex; align-items: center; gap: 14px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
  .m-me .avatar { width: 52px; height: 52px; font-size: 17px; }
  .m-me div { display: grid; }
  .m-me strong { font-size: 19px; }
  .m-me div span { color: var(--ink-2); font-size: 14.5px; }
  .m-menu :is(a, button) { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 56px; padding: 0 16px; border: 0; background: none; color: var(--ink); font-size: 16.5px; font-weight: 600; text-align: left; text-decoration: none; cursor: pointer; }
  .m-menu :is(a, button):active { background: var(--accent-tint); }
  .m-menu span { flex: 1; }
  .m-menu b { min-width: 22px; border-radius: 99px; background: var(--accent); color: #fff; font-size: 13px; line-height: 22px; text-align: center; }
  .m-menu .icon:last-child { color: var(--ink-2); }

  /* Records and lists */
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat-value { font-size: 23px; }
  .linestrip { grid-template-columns: minmax(0, 1fr); gap: 1px; }
  .dot { position: absolute; border-radius: 99px; background: var(--accent-dark); color: #fff; font-weight: 700; text-align: center; box-shadow: 0 0 0 2px var(--surface); }
  .m-content .page-head .page-actions:not(:has(.filter)) { display: none; }
  .m-content .page-head .page-actions:has(a.btn) { display: flex; }
  .m-content .page-head .page-actions a.btn { flex: 1; }
  .m-tickets { display: grid; gap: 10px; margin-top: 12px; }
  .m-tickets > div > p { margin-bottom: 3px; color: var(--ink-2); font-size: 13px; font-weight: 600; }
  .ticket { padding: 12px; }
  .ticket strong { font-size: 16px; }
  .ticket small, .ticket .code { font-size: 13.5px; }
  .ticket .btn { min-height: 46px; }
  .steps { display: flex; gap: 6px; overflow-x: auto; padding: 8px; scrollbar-width: none; }
  .steps li { flex: none; padding: 4px 8px 4px 4px; font-size: 13px; }
  .steps li::after { display: none; }
  .steps-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); padding: 8px 4px; }
  .steps-4 li { flex-direction: column; gap: 4px; padding: 0; text-align: center; font-size: 12px; }
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
  table.stack tr:last-child { border-bottom: 0; }
  table.stack td { padding: 0 !important; border: 0; text-align: left; white-space: normal; min-width: 0; }
  table.stack td:first-child { grid-column: 1 / -1; }
  table.stack td::before { content: attr(data-label); display: block; color: var(--ink-2); font-size: 12px; }
  table.stack td:first-child::before { display: none; }
  .woref { flex-wrap: wrap; }
  .card .segmented { margin-bottom: 10px; }
  .queue > li { flex-wrap: wrap; }
  .queue > li .btn { width: 100%; }
  .notice li { flex-wrap: wrap; }
  .fgstrip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .splitbar { gap: 6px; }
  .form-grid.thirds { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .linerow { grid-template-columns: minmax(0, 1fr) 96px 44px; gap: 6px; }

  /* Popups slide up from the bottom */
  dialog { position: fixed; inset: auto 0 0 0; width: 100%; max-width: 100%; margin: 0; max-height: calc(100dvh - var(--bar) - 12px); border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom, 0px); }
  dialog form { max-height: calc(100dvh - var(--bar) - 12px); }
  dialog[open] { animation: m-up .24s cubic-bezier(.2, .8, .2, 1); }
  dialog .modal-head { position: relative; padding-top: 20px; }
  dialog .modal-head::before { content: ""; position: absolute; top: 8px; left: 50%; width: 38px; height: 4px; margin-left: -19px; border-radius: 99px; background: var(--line-2); }
  dialog .icon-btn { width: 44px; height: 44px; }
  dialog .modal-foot > .btn { flex: 1; min-height: 50px; }
  .addline { width: 100%; }
  .m-sheet ul { max-height: 62vh; overflow-y: auto; padding: 4px 8px 14px; }
  .m-sheet li button { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 56px; padding: 8px 10px; border: 0; border-radius: 10px; background: none; text-align: left; cursor: pointer; }
  .m-sheet li button:active { background: var(--accent-tint); }
  .m-sheet li button span { display: grid; min-width: 0; line-height: 1.38; }
  .m-sheet li b { font-weight: 600; }
  .m-sheet li small { color: var(--ink-2); font-size: 13.5px; }

  .toasts { left: 12px; right: 12px; max-width: none; bottom: calc(var(--tabs, 0px) + 84px); }

  /* The role choice screen */
  .signin { padding: 28px 16px 40px; }

  /* Nothing under 13px on a phone except the tab labels and count badges on the tab icons */
  .code { font-size: max(.88em, 13px); }
  .pill { font-size: 13px; }
  .bin small { font-size: 13px; }
}
@media (max-width: 350px) {
  .stat-value { font-size: 20px; }
  .linerow { grid-template-columns: minmax(0, 1fr) 72px 44px; }
}
body.is-grabbing, body.is-grabbing * { cursor: grabbing !important; }
.tabs, .table-wrap { -webkit-overflow-scrolling: touch; }
@keyframes m-up { from { transform: translateY(40px); opacity: .4; } }

/* Desktop and phone switch in the demo bar */
.view-switch { display: none; }
.preview { display: none; }
@media (min-width: 900px) {
  .view-switch { display: inline-flex; gap: 2px; padding: 3px; border-radius: 99px; background: rgba(31, 42, 49, .13); }
  .view-switch button { display: inline-flex; align-items: center; gap: 6px; min-height: 28px; padding: 0 13px; border: 0; border-radius: 99px; background: none; color: #1f2a31; font-size: 13.5px; font-weight: 700; cursor: pointer; }
  .view-switch button .icon { width: 15px; height: 15px; }
  .view-switch button[aria-pressed="true"] { background: #fff; box-shadow: 0 1px 3px rgba(31, 42, 49, .25); }

  .app-body.is-preview { background: #e2e6e8; }
  .is-preview #app, .is-preview > dialog, .is-preview .toasts { display: none; }
  .is-preview .preview { display: flex; align-items: center; justify-content: center; gap: clamp(32px, 6vw, 96px); min-height: calc(100vh - var(--bar)); padding: 20px 32px; }
  .preview-notes { max-width: 360px; }
  .preview-notes h2 { font: 700 clamp(28px, 2.8vw, 38px)/1.12 var(--head); }
  .preview-notes > p { margin-top: 10px; color: var(--ink-2); font-size: 17px; }
  .preview-notes ul { margin-top: 20px; border-top: 1px solid var(--line-2); }
  .preview-notes li { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line-2); }
  .preview-notes li .icon { margin-top: 2px; color: var(--accent); }

  .device { --h: 844px; flex: none; width: 414px; padding: 11px; border-radius: 56px; background: #141517; box-shadow: 0 40px 70px -30px rgba(20, 21, 23, .65), inset 0 0 0 2px #45474c; }
  .device-screen { position: relative; display: flex; flex-direction: column; width: 392px; height: var(--h); border-radius: 45px; overflow: hidden; background: var(--surface); isolation: isolate; }
  .device-status { display: flex; align-items: center; justify-content: space-between; flex: none; height: 44px; padding: 0 30px; background: var(--surface); font-size: 15px; font-weight: 700; }
  .device-status::after { content: ""; width: 25px; height: 12px; border: 1.5px solid var(--ink); border-radius: 4px; background: linear-gradient(var(--ink), var(--ink)) 2px 50% / 16px 6px no-repeat; }
  .device-island { position: absolute; top: 10px; left: 50%; width: 108px; height: 26px; margin-left: -54px; border-radius: 99px; background: #141517; }
  .device iframe { flex: 1; width: 100%; min-height: 0; border: 0; background: var(--bg); }
  .device-home { flex: none; height: 12px; background: var(--surface); }
}

@media (max-width: 760px) {
  /* Role screen: both roles are visible at once, each as one large row */
  .signin .roles { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; margin-top: 22px; }
  .signin h1 { margin-top: 22px; font-size: 25px; text-wrap: balance; }
  .signin-sub { margin-inline: auto; font-size: 15px; text-wrap: balance; }
  .signin .role-points, .signin .role-org { display: none; }
  .signin .role { display: grid; grid-template-columns: 46px minmax(0, 1fr) 10px; grid-template-areas: "ico title go" "ico name go" "ico short go"; align-content: center; align-items: center; column-gap: 14px; row-gap: 1px; height: auto; min-height: 104px; padding: 16px; text-align: left; }
  .signin .role::after { content: ""; grid-area: go; width: 8px; height: 8px; border: solid currentColor; border-width: 2px 2px 0 0; transform: rotate(45deg); opacity: .55; }
  .signin .role-icon { grid-area: ico; align-self: center; }
  .signin .role-title { grid-area: title; margin: 0; font-size: 18px; line-height: 1.25; }
  .signin .role-name { grid-area: name; font-size: 14px; line-height: 1.35; }
  .signin .role-short { grid-area: short; display: block; font-size: 13.5px; line-height: 1.35; color: var(--ink-2); }
}

/* Desktop and Mobile switch sits in the exact middle of the bar */
@media (min-width: 900px) {
  .app-body .demo-bar { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }
  .app-body .demo-bar > p { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .app-body .demo-bar > .view-switch { justify-self: center; }
  .app-body .demo-bar > nav { justify-self: end; }
}
