/* Mobile business pages reuse the desktop records and actions.  These rules
   change presentation only; print sheets and desktop layouts are untouched. */
@media screen and (max-width:760px) , screen and (max-width:1000px) and (max-height:540px) and (orientation:landscape){
  /* Shrink grid children, rather than hiding page overflow and losing data. */
  .content, #page-content, .content .card, .content .stack,
  .content .card-body, .content section, .content article,
  .content .two-col, .content .three-col,
  .modal, .modal-content, .modal-content section,
  .form-grid>*, .line-fields>*, .detail-grid>*,
  .erp-form-grid>*, .wh-form-grid>*, .sq-form-grid>*,
  .qc-form-grid>*, .paddy-form-grid>*, .ta-form-grid>* {
    min-width:0;
    max-width:100%;
  }
  .content h1, .content h2, .content h3,
  .content strong, .content p, .content .id-link,
  .modal-header h2, .modal-header p, .modal-content strong,
  .modal-content p, .modal-content dd {
    overflow-wrap:anywhere;
  }
  .content .card, .content .ha-card {
    border-radius:14px;
    box-shadow:0 3px 16px #244a3005;
  }
  .content .card-head {padding:16px;gap:10px;flex-wrap:wrap}
  .content .card-body {padding:0 16px 16px}
  .content .card-title {min-width:0}
  .content .card-head h2 {font-size:17px;line-height:1.5}
  .content .two-col, .content .three-col,
  .content .dashboard-grid, .content .dashboard-grid>.stack,
  .stock-visuals, .ha-grid, .ha-overview-grid, .ha-stock-grid,
  .erp-chart-grid, .erp-chart-grid-primary, .erp-chart-grid-secondary {
    grid-template-columns:minmax(0,1fr);
    gap:14px;
  }
  .content .notice, .content .scope-note, .modal-content .notice,
  .modal-content .small, .modal-content .field-help {
    font-size:12px;
    line-height:1.7;
    overflow-wrap:anywhere;
  }
  .content .notice {padding:11px 12px}
  .content .empty {padding:30px 16px}
  .content .empty p {font-size:13px;line-height:1.7}

  /* Inputs stay at 16px to prevent iOS focus zoom. Controls keep a thumb target. */
  .content input:not([type=checkbox]):not([type=radio]),
  .content select, .content textarea,
  .modal-content input:not([type=checkbox]):not([type=radio]),
  .modal-content select, .modal-content textarea {
    font-size:16px!important;
    min-height:46px;
    min-width:0!important;
    max-width:100%;
    line-height:1.5;
    border-radius:9px;
  }
  .content input[type=date], .content input[type=datetime-local],
  .modal-content input[type=date], .modal-content input[type=datetime-local] {
    display:block;
    width:100%;
    -webkit-appearance:none;
    appearance:none;
  }
  .content input[type=checkbox], .content input[type=radio],
  .modal-content input[type=checkbox], .modal-content input[type=radio] {
    width:21px;
    height:21px;
    min-height:21px;
    flex:0 0 21px;
    accent-color:#244a30;
  }
  .content label, .modal-content label {font-size:13px;line-height:1.65}
  .content button, .content [role=button], .content a.button,
  .modal button, .modal [role=button], .modal a.button {
    touch-action:manipulation;
    -webkit-tap-highlight-color:transparent;
    -webkit-user-select:none;
    user-select:none;
  }
  .content .button, .modal .button,
  .content .tab, .content .ta-tabs button,
  .modal .modal-close, .sq-remove-line, .erp-remove, .wh-remove {
    min-height:44px;
    min-width:44px;
    font-size:14px;
    white-space:normal;
    line-height:1.4;
  }
  .content .button, .modal .button {padding:10px 13px;gap:7px}
  .content .button:active, .modal .button:active {transform:scale(.98)}
  .content .order-status, .modal .order-status {
    font-size:14px;
    font-weight:750;
    min-height:30px;
    padding:5px 10px;
    white-space:normal;
  }
  .content .pill {max-width:100%;line-height:1.45;overflow-wrap:anywhere}
  .content .row-actions, .modal .row-actions,
  .erp-row-actions, .sq-row-actions, .ta-actions {
    display:flex;
    flex-wrap:wrap;
    gap:8px;
    white-space:normal;
    min-width:0;
  }
  .content .row-actions .button, .erp-row-actions .button,
  .sq-row-actions .button, .ta-actions .button {
    flex:1 1 auto;
    justify-content:center;
  }

  /* Filters become short stacked rows, not desktop toolbars squeezed sideways. */
  .content .toolbar, .stock-toolbar, .erp-toolbar, .wh-toolbar,
  .ship-toolbar, .qc-toolbar, .sq-toolbar, .ta-toolbar,
  .paddy-toolbar, .pm-toolbar {
    display:flex;
    flex-wrap:wrap;
    align-items:flex-end;
    gap:10px;
    padding:14px;
    min-width:0;
  }
  .content .toolbar .search, .content .toolbar .search-wrap,
  .content .toolbar .search input, .erp-search, .sq-search,
  .qc-search, .pm-toolbar .pm-search, .paddy-search-label {
    width:100%;
    min-width:0;
    max-width:none;
    flex:1 1 100%;
  }
  .content .toolbar>label, .erp-toolbar label,
  .sq-status-filter, .qc-toolbar select, .wh-toolbar select,
  .pm-toolbar label, .paddy-toolbar label {
    min-width:0;
    max-width:100%;
    flex:1 1 130px;
  }
  .content .toolbar select, .erp-toolbar select,
  .sq-status-filter select, .stock-toolbar select,
  .wh-toolbar select, .qc-toolbar select {
    min-width:0;
    max-width:100%;
    width:100%;
  }
  .content .toolbar .right, .sq-count, .erp-toolbar>span {
    margin-left:0;
    font-size:12px;
  }
  .content .tabs, .content .ta-tabs {
    max-width:100%;
    flex-wrap:nowrap;
    overflow-x:auto;
    overscroll-behavior-x:contain;
    scrollbar-width:thin;
  }
  .content .tab, .content .ta-tabs button {flex:0 0 auto;white-space:nowrap}
  .content .tabs-bar {gap:12px;align-items:stretch}
  .content .tabs-bar>.row-actions {width:100%}
  .ship-filters, .ship-date-range, .erp-period {gap:10px;min-width:0}
  .ship-filters {grid-template-columns:minmax(0,1fr)}
  .ship-date-range, .erp-period {display:flex;flex-wrap:wrap}
  .ship-date-range>*, .erp-period label {flex:1 1 140px;min-width:0;max-width:100%}

  /* The helper opts simple record tables into cards. Comparison tables retain
     columns and scroll locally; print/layout tables must never opt in. */
  .table-scroll, .erp-table-wrap, .wh-table-wrap, .ship-table-wrap,
  .sq-table-wrap, .qc-table-wrap, .paddy-table-wrap, .ta-table-wrap,
  .erp-lines-wrap, .sq-edit-table-wrap, .qc-items-wrap,
  .ha-table-wrap, .sq-preview-stage, .qc-preview, .ship-print-preview {
    width:100%;
    max-width:100%;
    min-width:0;
    overflow-x:auto;
    overscroll-behavior-x:contain;
    -webkit-overflow-scrolling:touch;
  }
  .table-scroll:has(>table[data-mobile-cards]),
  .erp-table-wrap:has(>table[data-mobile-cards]),
  .wh-table-wrap:has(>table[data-mobile-cards]),
  .ship-table-wrap:has(>table[data-mobile-cards]),
  .sq-table-wrap:has(>table[data-mobile-cards]),
  .qc-table-wrap:has(>table[data-mobile-cards]),
  .paddy-table-wrap:has(>table[data-mobile-cards]),
  .ta-table-wrap:has(>table[data-mobile-cards]),
  .erp-lines-wrap:has(>table[data-mobile-cards]),
  .sq-edit-table-wrap:has(>table[data-mobile-cards]),
  .qc-items-wrap:has(>table[data-mobile-cards]) {
    overflow:visible;
    border:0;
  }
  table[data-mobile-cards], table[data-mobile-cards]>tbody {
    display:block!important;
    width:100%!important;
    min-width:0!important;
    max-width:100%!important;
    table-layout:auto;
    border-collapse:separate;
    background:transparent;
  }
  table[data-mobile-cards]>thead {
    position:absolute!important;
    width:1px!important;
    height:1px!important;
    padding:0!important;
    margin:-1px!important;
    overflow:hidden;
    clip:rect(0,0,0,0);
    white-space:nowrap;
    border:0;
  }
  table[data-mobile-cards]>tbody>tr {
    display:grid!important;
    grid-template-columns:repeat(2,minmax(0,1fr));
    gap:13px 16px;
    width:100%;
    min-width:0;
    padding:16px!important;
    margin:0 0 12px;
    border:1px solid #e0e8e2;
    border-radius:12px;
    background:#fff;
    box-shadow:0 3px 12px #244a3004;
    align-items:start;
  }
  table[data-mobile-cards]>tbody>tr[hidden] {display:none!important}
  table[data-mobile-cards]>tbody>tr>td {
    display:block!important;
    position:relative;
    width:auto!important;
    min-width:0!important;
    max-width:100%!important;
    padding:0!important;
    margin:0;
    border:0!important;
    white-space:normal!important;
    text-align:left;
    vertical-align:top;
    overflow-wrap:anywhere;
    font-size:14px;
    line-height:1.65;
    color:#304637;
  }
  table[data-mobile-cards]>tbody>tr>td[data-label]::before {
    content:attr(data-label);
    display:block;
    margin:0 0 4px;
    color:#78867c;
    font-size:11px;
    font-weight:500;
    line-height:1.5;
  }
  table[data-mobile-cards]>tbody>tr>td[data-label="序号"],
  table[data-mobile-cards]>tbody>tr>td[data-label="序"] {
    grid-column:1/-1;
    display:flex!important;
    align-items:center;
    gap:8px;
    padding-bottom:10px!important;
    border-bottom:1px solid #edf1ee!important;
    color:#718477;
    font-size:12px;
  }
  table[data-mobile-cards]>tbody>tr>td[data-label="序号"]::before,
  table[data-mobile-cards]>tbody>tr>td[data-label="序"]::before {margin:0}
  table[data-mobile-cards]>tbody>tr>td[data-mobile-primary],
  table[data-mobile-cards]>tbody>tr>td[data-label*="产品"],
  table[data-mobile-cards]>tbody>tr>td[data-label*="客户"],
  table[data-mobile-cards]>tbody>tr>td[data-label*="订单编号"],
  table[data-mobile-cards]>tbody>tr>td[data-label*="库存项目"],
  table[data-mobile-cards]>tbody>tr>td[data-label*="项目 / 规格"],
  table[data-mobile-cards]>tbody>tr>td[data-label*="操作"],
  table[data-mobile-cards]>tbody>tr>td[data-label*="备注"],
  table[data-mobile-cards]>tbody>tr>td[colspan] {grid-column:1/-1}
  table[data-mobile-cards]>tbody>tr>td[colspan]::before {display:none}
  table[data-mobile-cards] td strong, table[data-mobile-cards] td .id-link {
    font-size:14px;
    white-space:normal;
    overflow:visible;
    text-overflow:clip;
  }
  table[data-mobile-cards] td small, table[data-mobile-cards] .cell-sub {
    display:block;
    max-width:100%;
    font-size:12px;
    line-height:1.6;
    white-space:normal;
    overflow:visible;
    text-overflow:clip;
  }
  table[data-mobile-cards] .row-actions,
  table[data-mobile-cards] .erp-row-actions,
  table[data-mobile-cards] .sq-row-actions,
  table[data-mobile-cards] .ta-actions {padding-top:4px}
  table[data-mobile-cards] input:not([type=checkbox]):not([type=radio]),
  table[data-mobile-cards] select, table[data-mobile-cards] textarea {
    width:100%;
    max-width:none;
    margin-top:0;
    padding:10px 11px;
  }
  table[data-mobile-cards] .production-progress-lines.compact {min-width:0}
  table[data-mobile-cards] .production-quantity-grid {gap:6px}
  table[data-mobile-cards] .production-quantity-grid>span {padding:9px 7px}
  table[data-mobile-cards] .production-quantity-grid b {font-size:21px}

  /* A form is one reading column; short facts may use two, with no hidden text. */
  .modal .form-grid, .modal .line-fields,
  .erp-form-grid, .wh-form-grid, .sq-form-grid,
  .qc-form-grid, .paddy-form-grid, .ta-form-grid,
  .ship-form-grid, .stock-entry-top, .paddy-kind-picker {
    display:grid;
    grid-template-columns:minmax(0,1fr);
    gap:16px;
  }
  .modal .form-grid .span-2, .modal .line-fields label:first-child,
  .erp-span-2, .wh-span-2, .sq-form .sq-span-2,
  .qc-span-2, .paddy-span-2, .ta-form .ta-span-2 {grid-column:1/-1}
  .modal .line-item {padding:14px;border-radius:11px}
  .modal .line-heading {gap:10px;flex-wrap:wrap}
  .modal .detail-grid, .erp-facts, .wh-detail dl,
  .qc-facts, .paddy-facts, .ta-facts,
  .ship-bill-detail dl, .ship-tracking-facts {
    grid-template-columns:repeat(2,minmax(0,1fr));
    gap:16px 13px;
  }
  .modal .detail-field, .modal dl>div, .ta-facts>div {min-width:0}
  .modal .detail-field strong, .modal dd {font-size:14px;line-height:1.65}
  .modal .detail-field small, .modal dt {font-size:12px;line-height:1.55}
  .detail-top, .detail-actions, .sq-line-footer, .erp-line-tools,
  .qc-section-title, .sq-section-title, .ta-section-title {
    flex-wrap:wrap;
    gap:12px;
  }
  .detail-actions .button {flex:1 1 130px}
  .detail-notes, .detail-subsection {overflow-wrap:anywhere}
  .modal .order-progress {max-width:100%;gap:0}
  .modal .order-stage {min-width:0;font-size:10px;line-height:1.6;overflow-wrap:anywhere}
  .crm-contract {flex-wrap:wrap;gap:10px}
  .crm-contract .crm-contract-info {min-width:0;flex:1 1 150px}
  .crm-contract .button {flex:1 1 auto;min-height:44px}
  .crm-autocomplete-options {max-height:min(260px,40dvh);overscroll-behavior:contain}
  .crm-autocomplete-option {min-height:48px}
  .stock-rank-row strong, .task-info strong {
    white-space:normal;
    overflow:visible;
    text-overflow:clip;
    overflow-wrap:anywhere;
  }
  .stock-rank-row {gap:10px;align-items:center}
  .stock-rank-row>div:first-child {width:48%}
  .stock-rank-row>.stock-ratio {min-width:0}
  .stock-ratio {min-width:0}
  .stock-health-content {flex-wrap:wrap;gap:18px}
  .stock-health-legend {min-width:0;flex:1 1 140px}
  .stock-health-key {min-height:44px}
  .stock-entry-guide {flex-wrap:wrap;line-height:1.7}
  .stock-entry-scroll {max-height:none}
  .plan-task {padding:15px}
  .plan-task h3 {font-size:16px;line-height:1.5}
  .plan-task .meta, .plan-task-footer {flex-wrap:wrap;gap:9px;overflow-wrap:anywhere}
  .pm-card-grid, .ta-plot-grid, .ta-media-grid {grid-template-columns:minmax(0,1fr)}
  .ta-code-guide, .ta-domain {flex-wrap:wrap;gap:14px}
  .ta-domain p {overflow-wrap:anywhere}
  .ta-public-preview {max-width:100%;min-height:65dvh}
  .paddy-weight-grid, .paddy-test-grid,
  .paddy-detail-metrics, .paddy-summary-grid {grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}

  /* The keyboard may resize the visible area. Only the form body scrolls; the
     close and save actions stay reachable above the home indicator. */
  .modal-backdrop {
    inset:0;
    padding:max(8px,env(safe-area-inset-top,0px)) 0 0;
    align-items:flex-end;
  }
  .modal, .modal.wide, .modal.narrow {
    display:flex;
    flex-direction:column;
    width:100%;
    max-width:100%;
    max-height:calc(100dvh - max(8px,env(safe-area-inset-top,0px)));
    border-radius:18px 18px 0 0;
    overflow:hidden;
    margin:0;
  }
  .modal-header {
    flex:0 0 auto;
    padding:18px 16px 14px;
    gap:12px;
    align-items:flex-start;
  }
  .modal-header>div {min-width:0}
  .modal-header h2 {font-size:18px;line-height:1.45}
  .modal-header p {font-size:12px;line-height:1.6}
  .modal-close {flex:0 0 44px;margin-top:-7px;margin-right:-7px}
  .modal-content {
    flex:1 1 auto;
    min-height:0;
    padding:16px;
    overflow-y:auto;
    overscroll-behavior:contain;
    scroll-padding-top:14px;
    scroll-padding-bottom:24px;
    -webkit-overflow-scrolling:touch;
  }
  .modal-footer {
    flex:0 0 auto;
    display:flex;
    flex-wrap:wrap;
    align-items:center;
    gap:10px;
    padding:12px 16px calc(12px + env(safe-area-inset-bottom,0px));
    background:#fff;
    border-top:1px solid #e3eae5;
  }
  .modal-footer .button {flex:1 1 120px;justify-content:center}
  .modal-footer .hint {flex:1 1 100%;font-size:11px;line-height:1.6}
  .production-entry-line {grid-template-columns:minmax(0,1fr);padding:14px;gap:12px}
  .production-entry-help strong {font-size:18px;line-height:1.6}
  .production-entry-help span {font-size:13px;line-height:1.65}
  .production-quantity-input input {min-height:60px;font-size:27px!important}
  .production-progress-product {font-size:16px;line-height:1.55}
  .production-quantity-grid b {font-size:23px}
  .production-report-history article {padding:13px}

  /* A phone is a scrollable task sheet, not a wall monitor. Preserve large
     quantities while letting the complete products and notes flow vertically. */
  .touch-shell, .touch-fullscreen .touch-shell {height:auto;min-height:0;padding:14px}
  .touch-carousel-stage, .touch-fullscreen .touch-carousel-stage {
    height:auto!important;
    min-height:0!important;
    flex:none;
  }
  .touch-task.touch-spotlight {height:auto!important;min-height:0!important;overflow:visible}
  .touch-spotlight-header {display:block;padding:16px;gap:12px}
  .touch-spotlight-header>div:first-child {display:block}
  .touch-task.touch-spotlight h3 {font-size:24px;line-height:1.4;margin-top:10px!important}
  .touch-spotlight-id {font-size:12px;margin-top:7px}
  .touch-spotlight .pill.order-status {font-size:18px;min-height:38px;padding:7px 11px}
  .touch-spotlight-cue {display:flex;max-width:none;margin-top:14px;padding:9px 11px;font-size:13px}
  .touch-spotlight-body {display:grid;grid-template-columns:minmax(0,1fr);padding:16px;gap:16px}
  .touch-spotlight-products, .touch-spotlight-context {min-height:0;max-height:none;overflow:visible}
  .touch-spotlight-products .production-progress-lines {min-height:0;gap:12px}
  .touch-spotlight-products .production-progress-line {padding:14px;min-height:0}
  .touch-spotlight .production-progress-product {font-size:20px;line-height:1.45}
  .touch-spotlight .production-progress-product>span {font-size:15px;line-height:1.5}
  .touch-spotlight .production-quantity-grid {grid-template-columns:repeat(3,minmax(0,1fr));gap:6px;margin-top:14px}
  .touch-spotlight .production-quantity-grid>span {font-size:12px;padding:10px 7px;line-height:1.6}
  .touch-spotlight .production-quantity-grid b {font-size:27px;line-height:1.3;letter-spacing:-.02em}
  .touch-spotlight-context {display:block;border-left:0;border-top:1px solid #e2eae5;padding:15px 0 0}
  .touch-spotlight-facts {grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}
  .touch-spotlight-fact>strong {font-size:16px;line-height:1.5}
  .touch-spotlight-requirements {margin-top:14px}
  .touch-spotlight-requirements>p {font-size:16px;line-height:1.7;white-space:pre-wrap}
  .touch-spotlight-footer {display:block;padding:14px 16px}
  .touch-spotlight .touch-buttons {display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:9px}
  .touch-spotlight .touch-buttons .button {min-height:50px;font-size:14px;padding:10px}
  .touch-spotlight-note {display:block;text-align:left;max-width:none;margin-top:12px;font-size:12px}
  .touch-carousel-toolbar {gap:12px}
  .touch-carousel-controls {display:flex;gap:8px;flex-wrap:wrap}
  .touch-carousel-page {font-size:13px}
  .touch-carousel-countdown {font-size:12px;min-width:0;margin-right:0}
  .touch-carousel-controls .button {flex:1 1 auto;min-height:44px;padding:10px;font-size:13px}
  .touch-carousel-stats {font-size:13px;gap:12px}
  .touch-carousel-stats strong {font-size:24px}
  .touch-carousel-stage.is-switching>.touch-spotlight {animation:none}
  .touch-spotlight-cue>i {animation:none}

  .erp-dashboard .erp-dashboard-metrics, .erp-dashboard-metrics,
  .business-metric-grid, .pm-summary, .ta-summary {grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}
  .erp-dashboard .erp-chart-card>header {padding:16px;gap:10px;flex-wrap:wrap}
  .erp-dashboard .erp-chart-card h3 {font-size:16px}
  .erp-dashboard .erp-chart-card header p {font-size:12px;line-height:1.6}
  .erp-dashboard .erp-metric {padding:15px 13px}
  .erp-dashboard .erp-metric strong {font-size:25px;line-height:1.35}
  .erp-dashboard .erp-metric>span {font-size:12px}
  .erp-sales-detail-summary {flex-wrap:wrap;gap:12px}
  .erp-sales-detail-summary>span {min-width:0;flex:1 1 130px}
  .erp-structure {flex-wrap:wrap;gap:12px}
  .erp-structure-legend {min-width:0;flex:1 1 130px}
  .ha-card-head {padding:16px 16px 10px}
  .ha-card-head h3 {font-size:16px}
  .ha-card-head p {font-size:12px;line-height:1.65}
  .ha-ranking-row {min-width:0}
  .ha-ranking-row strong {white-space:normal;overflow-wrap:anywhere}
  .ha-data-details summary, .erp-chart-data summary {min-height:44px;padding-top:10px;padding-bottom:10px}
  .ha-line-chart, .erp-line-chart {width:100%;max-width:100%;height:auto;min-width:0}
  .ha-unit-balances {grid-template-columns:repeat(2,minmax(0,1fr))}
}

/* Coarse pointers must not retain a desktop hover tint after a tap. Press
   feedback remains immediate and keyboard focus keeps the existing outline. */
@media screen and (max-width:760px) and (hover:none) , screen and (max-width:1000px) and (max-height:540px) and (orientation:landscape) and (hover:none){
  .content .button:hover, .modal .button:hover {background:var(--green,#244a30)}
  .content .button.secondary:hover, .modal .button.secondary:hover {background:#fff}
  .content .button.ghost:hover, .modal .button.ghost:hover {background:transparent}
  .content .button.danger:hover, .modal .button.danger:hover {background:var(--red-bg,#fff0ef)}
  .content .card tbody tr:hover {background:inherit}
}
