/* Mobile workspace overrides; printed documents retain their paper layout. */
@media screen and (max-width: 768px) {
  html body[data-auth-state="authenticated"] header.topbar {position:relative!important;top:auto!important;left:auto!important;right:auto!important;height:auto!important;max-height:none!important;display:flex!important;flex-direction:column!important;align-items:stretch!important;overflow:visible!important;}
  html body[data-auth-state="authenticated"] header.topbar>div {display:flex!important;width:100%!important;min-width:0!important;max-width:100%!important;flex:0 0 auto!important;flex-wrap:wrap!important;}
  html body[data-auth-state="authenticated"] header.topbar>div:first-child {width:100%!important;min-width:0!important;max-width:100%!important;flex:0 0 auto!important;}
  html body[data-auth-state="authenticated"] header.topbar #page-title {display:block!important;}
  html body[data-auth-state="authenticated"] header.topbar #mobile-menu {width:44px!important;min-width:44px!important;max-width:44px!important;height:44px!important;}
  html body[data-auth-state="authenticated"] header.topbar h1 {flex:1 1 180px!important;min-width:0!important;max-width:100%!important;}
  html body[data-auth-state="authenticated"] header.topbar .top-actions {flex:0 0 auto!important;}
  html:not([data-public-surface="1"]) main {min-width:0!important;width:auto!important;margin-left:0!important;}
  #app.content {min-width:0!important;width:100%!important;padding:12px!important;}
  #app .panel,#app .form-card,#app .sb-so,#app .so-order-panel {min-width:0!important;max-width:100%!important;}
  .topbar {height:auto!important;min-height:64px;flex-wrap:wrap!important;gap:10px;padding:10px 12px!important;}
  .topbar>div,.top-actions {min-width:0;max-width:100%;flex-wrap:wrap!important;gap:8px!important;}
  .topbar h1 {font-size:20px!important;overflow-wrap:anywhere;}
  .top-actions {width:100%;}
  #sb-search {flex:1 1 180px;min-width:0!important;max-width:100%!important;}
  #app .form-grid,#app .so-order-window .so-main-fields,#app .so-order-window .so-pricing-fields,
  #modal-root .form-grid,#app .split,#app .so-order-bottom {grid-template-columns:minmax(0,1fr)!important;}
  #app .form-grid>.field,#modal-root .form-grid>.field {min-width:0!important;grid-column:auto!important;}
  #app .field input,#app .field select,#app .field textarea,
  #modal-root .field input,#modal-root .field select,#modal-root .field textarea {max-width:100%!important;min-width:0!important;}
  #app input,#app select,#app textarea,#modal-root input,#modal-root select,#modal-root textarea {font-size:16px!important;}
  #app .btn,#modal-root .btn,.topbar button {min-height:44px!important;}
  #app .page-actions,#app .page-actions>div,#app .so-order-actions,#app .listpage-actions {flex-wrap:wrap!important;gap:8px!important;}
  #app .page-actions>input {min-width:0!important;max-width:100%;flex:1 1 100%;}
  #app .so-order-window>.so-order-actions {position:static!important;}
  #app .so-order-totals {grid-column:auto!important;grid-row:auto!important;width:100%!important;}
  #app .table-wrap,#modal-root .table-wrap {display:block;max-width:100%!important;min-width:0!important;overflow-x:auto!important;overscroll-behavior-x:contain;-webkit-overflow-scrolling:touch;}
  #app .table-wrap table,#modal-root .table-wrap table {min-width:640px;}
  .sb-sales-path{max-width:100%;overflow-x:auto;flex-wrap:nowrap!important;}
  .sb-sales-path button{flex-shrink:0;min-height:44px;}
  #app .sb-scan-row {flex-wrap:wrap;max-width:100%;}
  #app .sb-scan-row input {min-width:0!important;flex:1 1 100%;}
  #app .cards,#app .ex-summary {grid-template-columns:repeat(2,minmax(0,1fr))!important;}
  #modal-root .modal {width:calc(100vw - 16px)!important;max-width:calc(100vw - 16px)!important;min-width:0!important;max-height:calc(100dvh - 16px)!important;margin:8px auto!important;}
  #modal-root .modal-body {max-height:calc(100dvh - 160px)!important;overflow-y:auto!important;padding:12px!important;}
  #modal-root .modal-footer {flex-wrap:wrap;gap:8px;padding-bottom:max(12px,env(safe-area-inset-bottom));}
}
@media screen and (max-width: 380px) {
  #app .cards,#app .ex-summary {grid-template-columns:minmax(0,1fr)!important;}
}

/* Keep editor controls usable without shrinking the document's paper columns. */
@media screen and (max-width: 768px) {
  html body[data-auth-state="authenticated"] #app :is(.commercial-notice,.commercial-upload,.commercial-designer-head,.commercial-section-head) {
    flex-wrap:wrap;gap:12px;min-width:0;
  }
  html body #app .commercial-upload input[type="file"] {width:100%;min-width:0;max-width:100%;}
  html body :is(#app,#modal-root) .commercial-column-row {
    grid-template-columns:repeat(3,minmax(0,1fr));gap:8px;padding:12px 0;border-bottom:1px solid var(--line);
  }
  html body :is(#app,#modal-root) .commercial-column-row>input:first-child,
  html body :is(#app,#modal-root) .commercial-column-row>input:nth-child(2) {grid-column:1/-1;}
  /* The register's rename dialog uses a separate three-control row. */
  html body :is(#app,#modal-root) label.commercial-column-row {grid-template-columns:24px minmax(0,1fr) auto;}
  html body :is(#app,#modal-root) label.commercial-column-row>input {grid-column:auto;}
  html body :is(#app,#modal-root) .format-column-row {grid-template-columns:minmax(0,1fr) minmax(0,1fr);}
  html body :is(#app,#modal-root) .format-column-row>input[data-fmt-label] {grid-column:1/-1;grid-row:1;}
  html body :is(#app,#modal-root) :is(.format-column-row,.commercial-column-row)>input {min-width:0;max-width:100%;width:100%;box-sizing:border-box;}
  html body #app .sb-settings {grid-template-columns:minmax(0,1fr)!important;grid-template-rows:auto auto!important;height:auto!important;max-height:none!important;}
  html body #app .sb-settings-main {padding:16px 12px 24px;}
  html body #app .sb-settings .field.sb-pref-row {grid-template-columns:minmax(0,1fr)!important;gap:8px;}
  html body #app .sb-settings-nav {display:flex!important;flex-direction:row!important;min-width:0;max-width:100%;height:auto!important;overflow-x:auto!important;}
  html body #app .sb-settings-nav button {min-height:44px;width:auto!important;flex:0 0 auto!important;}
  html body #modal-root .modal-backdrop {padding:8px!important;align-items:center!important;height:100dvh;box-sizing:border-box;}
  html body #modal-root .modal {display:flex;flex-direction:column;overflow:hidden;}
  html body #modal-root .modal-body {flex:1 1 auto;min-height:0;max-height:none!important;overflow:auto!important;}
  html body #modal-root :is(.modal-head,.modal-foot,.modal-footer) {flex:0 0 auto;flex-wrap:wrap;gap:8px;}
  html body #modal-root :is(.modal-foot,.modal-footer) {padding:12px;padding-bottom:max(12px,env(safe-area-inset-bottom));}
  html body #modal-root :is(.modal-head .close,.line-delete) {min-width:44px;min-height:44px;}
  html body #app .sb-preview-toolbar .field {min-width:0;flex:1 1 100%;}
  html body #app .sb-doc-paper {padding:12px;min-width:0;}
  html body #app .sb-doc-paper .table-wrap {overflow-x:auto!important;}
  html body #app .sb-doc-paper :is(.sb-doc-head,.print-parties,.print-signatures) {display:flex;flex-wrap:wrap;gap:16px;}
  html body #app .sb-doc-paper .print-parties>* {flex:1 1 100%;min-width:0;overflow-wrap:anywhere;}
  html body #app .sb-doc-paper .print-signatures>* {flex:1 1 140px;}
}
