/* Phone presentation only. Business workflows and desktop density are unchanged. */
@media (max-width: 760px), (max-width: 980px) and (pointer: coarse) {
  :root body {
    --mobile-top: env(safe-area-inset-top, 0px);
    --mobile-right: env(safe-area-inset-right, 0px);
    --mobile-bottom: env(safe-area-inset-bottom, 0px);
    --mobile-left: env(safe-area-inset-left, 0px);
  }

  :root body :is(#appView, #loginView) {
    min-height: 100dvh;
  }

  :root body #appView:not(.hidden) .header {
    position: static;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: calc(12px + var(--mobile-top)) calc(12px + var(--mobile-right)) 12px calc(12px + var(--mobile-left));
  }

  :root body #appView:not(.hidden) .header .logo {
    width: 100%;
    min-width: 0;
  }

  :root body #appView:not(.hidden) .header-right {
    width: 100%;
    justify-content: flex-start;
    gap: 6px;
  }
  :root body #appView:not(.hidden) .account-menu { margin-left: auto; }
  :root body #appView:not(.hidden) .account-menu > summary { min-height: 44px; }
  :root body #appView:not(.hidden) .search-camera { flex-basis: 44px; }
  :root body #appView:not(.hidden) .account-menu-panel { max-height: calc(100dvh - 155px); }

  :root body #appView:not(.hidden) .main-tabs {
    position: sticky;
    top: 0;
    max-width: 100%;
    min-height: 56px;
    padding: calc(6px + var(--mobile-top)) calc(12px + var(--mobile-right)) 6px calc(12px + var(--mobile-left));
    scroll-padding-inline: calc(12px + var(--mobile-left)) calc(12px + var(--mobile-right));
    overscroll-behavior-x: contain;
  }

  :root body #appView:not(.hidden) .main-tabs .nav-item {
    flex-shrink: 0;
  }

  :root body #appView:not(.hidden) .workspace-stage {
    width: calc(100% - 24px - var(--mobile-left) - var(--mobile-right));
    margin-left: calc(12px + var(--mobile-left));
    margin-right: calc(12px + var(--mobile-right));
    min-width: 0;
    grid-template-columns: minmax(0, 1fr);
    padding-bottom: calc(24px + var(--mobile-bottom));
  }

  :root body #appView:not(.hidden) :is(.app-grid, .content-shell, .content-grid, .panel, .toolbar-actions, .search-inline, .orders-toolbar-filters, .orders-toolbar-main) {
    min-width: 0;
    max-width: 100%;
  }

  :root body #appView:not(.hidden) :is(button, .nav-item, .table-action, .row-actions-menu > summary, .orders-tools > summary, .order-stock-details > summary),
  :root body :is(#loginView, .modal-shell, dialog) button {
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
  }

  /* 16px avoids Safari zooming the page when a text field receives focus. */
  :root body :is(#appView, #loginView, .modal-shell, dialog) :is(input:not([type="checkbox"]):not([type="radio"]), select, textarea) {
    min-width: 0;
    max-width: 100%;
    min-height: 44px;
    font-size: 16px;
  }

  :root body #appView select,
  :root body #appView #toolbarActions select,
  :root body :is(.modal-shell, dialog) select {
    height: 44px;
    font-size: 16px;
  }

  :root body :is(#appView, .modal-shell, dialog) input:is([type="checkbox"], [type="radio"]) {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
  }

  :root body #appView:not(.hidden) .workspace-stage .toolbar {
    position: static;
    grid-template-columns: minmax(0, 1fr);
  }

  :root body #appView:not(.hidden) #toolbarActions :is(button, summary, select) {
    min-height: 44px;
  }

  :root body #appView:not(.hidden) .toolbar:not(.orders-toolbar) .toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    overflow: visible;
  }

  :root body #appView:not(.hidden) .toolbar:not(.orders-toolbar) .toolbar-actions > * {
    max-width: 100%;
  }

  :root body #appView:not(.hidden) .toolbar:not(.orders-toolbar) .toolbar-actions > button {
    width: auto;
    white-space: normal;
  }

  :root body #appView:not(.hidden) .orders-toolbar .orders-fulfillment-filters {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    overflow: visible;
  }

  :root body #appView:not(.hidden) .orders-toolbar .orders-fulfillment-filters button {
    flex: 0 1 auto;
    min-height: 44px;
    white-space: normal;
  }

  :root body #appView:not(.hidden) .orders-toolbar-main {
    position: relative;
    grid-area: 2 / 1;
    flex-wrap: wrap;
  }

  :root body #appView:not(.hidden) .orders-tools {
    position: static;
  }

  :root body #appView:not(.hidden) .orders-toolbar-filters {
    position: relative;
    grid-area: 3 / 1;
  }

  :root body #appView:not(.hidden) .orders-tools-menu {
    right: 0;
    left: 0;
    width: 100%;
  }
  :root body #appView:not(.hidden) .orders-filters-menu { max-height: 55dvh; }

  :root body #appView:not(.hidden) :is(.orders-selection-bar, .orders-pager, .orders-pager-controls, .factory-tabs, .modal-actions) {
    flex-wrap: wrap;
    gap: 8px;
  }

  :root body #appView:not(.hidden) :is(.table-wrap, .workspace-table-scroll) {
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
  }

  :root body #appView:not(.hidden) :is(#view-orders, #view-shipments) .table-wrap {
    overflow-x: auto;
  }

  :root body #appView:not(.hidden) .catalog-product-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(230px, 100%), 1fr));
  }

  :root body #loginView.login-shell {
    padding: calc(16px + var(--mobile-top)) calc(16px + var(--mobile-right)) calc(24px + var(--mobile-bottom)) calc(16px + var(--mobile-left));
  }

  :root body #loginView :is(.login-topbar, .login-topbar-actions, .login-form-foot) {
    flex-wrap: wrap;
  }

  :root body .modal-shell:not(dialog) {
    padding: calc(8px + var(--mobile-top)) calc(8px + var(--mobile-right)) calc(8px + var(--mobile-bottom)) calc(8px + var(--mobile-left));
  }

  :root body .modal-shell .modal-card {
    min-width: 0;
    max-height: calc(100dvh - 16px - var(--mobile-top) - var(--mobile-bottom));
    padding: 16px;
    scroll-padding-block: 76px 16px;
  }

  :root body .modal-shell .modal-head {
    top: -16px;
    gap: 10px;
  }

  :root body .modal-shell .modal-head :is(h3, .modal-title) {
    overflow-wrap: anywhere;
    font-size: 22px;
  }

  :root body .modal-shell .modal-actions {
    flex-wrap: wrap;
  }

  :root body dialog {
    max-width: calc(100vw - 16px - var(--mobile-left) - var(--mobile-right));
    max-height: calc(100dvh - 16px - var(--mobile-top) - var(--mobile-bottom));
    overscroll-behavior: contain;
    scroll-padding-block: 76px 16px;
  }
}

@media (max-width: 760px) {
  /* Part and line are separate fields inside the existing order card layout. */
  :root body #appView:not(.hidden) #view-orders .orders-table td:nth-child(3) {
    flex-wrap: wrap;
    gap: 6px;
  }

  :root body #appView:not(.hidden) #view-orders .order-part-number {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  :root body #appView:not(.hidden) #view-orders .order-line-meta {
    flex-basis: 100%;
    margin-top: 0;
  }
}

.workspace-read-status { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:7px 12px; margin:4px 0; font-size:12px; color:var(--muted, #9aafb2); }
.workspace-read-status[data-state="error"], .workspace-read-status[data-state="stale"] { border-left:3px solid #d7a84b; background:rgba(215,168,75,.08); }
.workspace-read-status button { flex-shrink:0; min-height:32px; }
.workspace-read-status.hidden { display:none; }
