/* Phone layouts for entry forms and dialogs. */
@media screen and (max-width: 760px) {
  #content :is(#orderForm, #productionSheetFormV4, #purchaseSheetV23, .quotation-management, .quotation-page)
    :is(input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]), select, textarea),
  :is(.workspace-dialog, .purchase-type-dialog, .qm-dialog, .sales-order-modal:not(.full-order-surface))
    :is(input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]), select, textarea) {
    box-sizing: border-box;
    min-width: 0;
    max-width: 100%;
    min-height: 44px !important;
    font-size: 16px !important;
    scroll-margin-block: 16px 84px;
  }

  #content :is(#orderForm, #productionSheetFormV4, #purchaseSheetV23, .quotation-management)
    label:has(input:is([type="date"], [type="datetime-local"])),
  #content #orderForm .order-form-grid > .span-2 {
    grid-column: 1 / -1 !important;
    min-width: 0;
  }

  #content :is(#orderForm, #productionSheetFormV4, #purchaseSheetV23, .quotation-management)
    input:is([type="date"], [type="datetime-local"]),
  .workspace-body input:is([type="date"], [type="datetime-local"]) {
    width: 100%;
  }

  #content #orderForm .customer-picker {
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: stretch;
  }
  #content #orderForm .customer-picker button {
    min-height: 44px;
    margin: 0;
    padding-inline: 8px;
    font-size: 12px;
  }
  #content #orderForm .customer-match-list { grid-column: 1 / -1; }
  #content #orderForm .customer-match-list button { width: 100%; }
  #content #orderForm .payment-tax-fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  #content #orderForm .tax-toggle-field {
    grid-column: 1 / -1;
    min-height: 44px;
  }
  #content #orderForm .production-requirement-grid label.span-2 { grid-column: 1 / -1; }
  #content #orderForm .draft-sheet-row label { font-size: 12px !important; }
  #content #orderForm .draft-row-actions button { min-width: 44px; min-height: 44px; }
  #content #orderForm .draft-sheet-row[data-review-grouped] {
    grid-template-columns: repeat(6, minmax(0, 1fr)) !important;
  }
  #content #orderForm .draft-sheet-row[data-review-grouped] .review-sale-col-1 {
    grid-area: 1 / 1 / 2 / 3 !important;
  }
  #content #orderForm .draft-sheet-row[data-review-grouped] .review-sale-col-3 {
    grid-area: 1 / 3 / 2 / 7 !important;
  }
  #content #orderForm .draft-sheet-row[data-review-grouped] .review-sale-col-4 {
    grid-area: 2 / 1 / 3 / 7 !important;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  #content #orderForm .draft-sheet-row[data-review-grouped] .review-sale-col-4 label { width: 100%; }
  #content #orderForm .draft-sheet-row[data-review-grouped] .review-sale-col-10 {
    grid-area: 4 / 1 / 5 / 7 !important;
  }
  #content #orderForm .draft-sheet-row[data-review-grouped] .review-sale-col-9 {
    grid-area: 5 / 1 / 6 / 5 !important;
  }
  #content #orderForm .draft-sheet-row[data-review-grouped] .review-sale-col-11 {
    grid-area: 5 / 5 / 6 / 7 !important;
  }

  #content :is(.sales-modal-actions, .production-form-footer-v411, .purchase-entry-tab-actions) {
    gap: 8px;
    flex-wrap: wrap !important;
  }
  #content :is(.sales-modal-actions, .production-form-footer-v411, .purchase-entry-tab-actions) button {
    min-height: 44px;
    padding-inline: 12px;
  }
  #content .sales-modal-actions > .review-live-total {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-right: auto;
  }
  #content .sales-modal-actions > .review-live-total b { font-size: 16px; }
  #content #orderForm .sales-modal-actions { grid-template-columns: auto auto minmax(0,1fr); }
  #content #orderForm .sales-modal-actions > button[type="submit"] { width: 100%; }
  #content .production-form-footer-v411 > div:has(button) {
    display: flex;
    flex: 1 1 100%;
    justify-content: flex-end;
    margin-left: 0;
  }
  #content .production-form-footer-v411 > div > button { flex: 1; }
  #content .purchase-entry-tab-actions > button { flex: 1 1 auto; min-width: 0; }

  #content .production-source-heading-v411 { gap: 8px; }
  #content .production-source-heading-v411 > button { min-height: 44px; }
  #content .production-source-stats-v411 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin: 0 12px 12px;
  }
  #content .production-source-stats-v411 > div { min-width: 0; padding: 9px 10px; }
  #content .production-source-stats-v411 > div:nth-last-child(-n+2) { border-bottom: 0; }
  #content .production-source-stats-v411 strong { overflow-wrap: anywhere; }

  #content #purchaseSheetV23 .purchase-entry-heading button,
  #content #purchaseSheetV23 .purchase-entry-table button { min-height: 44px; }
  #content #purchaseSheetV23 { grid-template-columns: minmax(0, 1fr); }
  #content #purchaseSheetV23 > * { min-width: 0; }
  #content #purchaseSheetV23 .purchase-entry-table td::before { font-size: 12px; }
  #content #purchaseSheetV23 .purchase-entry-heading { align-items: start; }
  #content #purchaseSheetV23 .purchase-entry-heading > div:first-child { flex-basis: 100%; }

  #content .quotation-management .qm-simple-product {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 12px;
  }
  #content .quotation-management .qm-simple-product .qm-product-main {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 12px;
  }
  #content .quotation-management .qm-simple-product .qm-image {
    width: 72px;
    height: 64px;
    flex: 0 0 72px;
  }
  #content .quotation-management .qm-simple-product > label { grid-column: auto; min-width: 0; }
  #content .quotation-management .qm-simple-product > label:has([data-qm-line-field="name"], [data-qm-line-field="spec"], [data-qm-line-field="note"]),
  #content .quotation-management .qm-simple-product .qm-simple-tools { grid-column: 1 / -1; }
  #content .quotation-management .qm-row-field,
  #content .quotation-management .qm-row-total small { font-size: 12px; }
  #content .quotation-management .qm-row-total { align-self: end; padding: 6px 10px; border-radius: 8px; background: #f3f6fb; }
  #content :is(.quotation-management, .quotation-page) :is(.qm-tabs, .qm-actions, .qm-line-tools, .qm-product-footer) button { min-height: 44px; }

  .workspace-modal, .purchase-type-backdrop {
    align-items: end;
    padding: max(8px, env(safe-area-inset-top)) 0 0;
  }
  .workspace-modal > .workspace-dialog,
  .purchase-type-backdrop > .purchase-type-dialog {
    width: 100%;
    max-width: 100%;
    max-height: calc(100vh - 8px);
    max-height: calc(100dvh - max(8px, env(safe-area-inset-top)));
    border-radius: 16px 16px 0 0;
  }
  .workspace-dialog > header, .purchase-type-dialog > header, .qm-dialog > .qm-dialog-head {
    min-width: 0;
    gap: 10px;
    padding: 10px 14px;
  }
  .workspace-dialog > header h2, .purchase-type-dialog > header h3, .qm-dialog-head h2 {
    font-size: 17px;
    overflow-wrap: anywhere;
  }
  :is(.workspace-dialog, .purchase-type-dialog, .qm-dialog) > header > button {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 9px;
    color: #49617e;
    background: #f2f5fa;
    line-height: 1;
  }
  .workspace-dialog > .workspace-body, .qm-dialog > .qm-dialog-body {
    min-width: 0;
    padding: 14px;
    overscroll-behavior: contain;
  }
  .workspace-dialog > .dialog-actions, .qm-dialog > .qm-dialog-foot {
    gap: 8px;
    padding: 10px 14px max(10px, env(safe-area-inset-bottom));
    flex-wrap: wrap;
  }
  :is(.workspace-dialog > .dialog-actions, .qm-dialog > .qm-dialog-foot, .purchase-type-dialog form > footer) button {
    min-height: 44px;
    max-width: 100%;
    white-space: normal;
    touch-action: manipulation;
  }
  .workspace-body .field-grid > label, .purchase-type-fields > label, .qm-dialog .qm-field { min-width: 0; font-size: 13px; }
  .workspace-body .field-grid :is(input, select, textarea), .purchase-type-fields :is(input, select) { width: 100%; }
  .workspace-body .field-grid :is(input[type="checkbox"], input[type="radio"]) { width: 22px; height: 22px; }
  .purchase-type-dialog form > footer { bottom: -14px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .workspace-dialog :is(.settlement-preview, .purchase-print-preview, .order-document-stage) {
    max-height: none;
    max-width: 100%;
    overflow: auto;
  }
  .workspace-dialog .order-document-tabs button { min-height: 44px; }
  .workspace-dialog .order-document-select { flex-wrap: wrap; }
  .workspace-dialog .order-document-select select { flex: 1 1 180px; }

  :is(#productionShipmentForm, #shipmentEntryForm) .shipment-entry-intro {
    flex-wrap: wrap;
    gap: 8px;
  }
  :is(#productionShipmentForm, #shipmentEntryForm) .shipment-entry-intro > button { min-height: 44px; }
  :is(#productionShipmentForm, #shipmentEntryForm) .table-wrap {
    border: 0;
    overflow: visible;
  }
  :is(#productionShipmentForm, #shipmentEntryForm) .shipment-entry-table,
  :is(#productionShipmentForm, #shipmentEntryForm) .shipment-entry-table tbody {
    display: block;
    width: 100%;
    min-width: 0;
  }
  :is(#productionShipmentForm, #shipmentEntryForm) .shipment-entry-table thead { display: none; }
  :is(#productionShipmentForm, #shipmentEntryForm) .shipment-entry-table tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 12px;
    margin-bottom: 10px;
    padding: 12px;
    border: 1px solid #dce5f0;
    border-radius: 10px;
    background: #fff;
  }
  :is(#productionShipmentForm, #shipmentEntryForm) .shipment-entry-table td {
    display: block;
    width: auto;
    min-width: 0;
    padding: 0;
    border: 0;
    text-align: left;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  :is(#productionShipmentForm, #shipmentEntryForm) .shipment-entry-table td:first-child { grid-column: 1 / -1; }
  :is(#productionShipmentForm, #shipmentEntryForm) .shipment-entry-table td::before {
    display: block;
    margin-bottom: 3px;
    font-size: 12px;
    color: #586b85;
  }
  #productionShipmentForm td:nth-child(2)::before { content: '计划'; }
  #productionShipmentForm td:nth-child(3)::before { content: '累计合格'; }
  #productionShipmentForm td:nth-child(4)::before { content: '不良'; }
  #productionShipmentForm td:nth-child(5)::before { content: '已发 / 未发'; }
  #shipmentEntryForm td:nth-child(2)::before { content: '订单数量'; }
  #shipmentEntryForm td:nth-child(3)::before { content: '已发'; }
  #shipmentEntryForm td:nth-child(4)::before { content: '未发'; }
  :is(#productionShipmentForm, #shipmentEntryForm) td:last-child::before { content: '本次发货数量'; }
  :is(#productionShipmentForm, #shipmentEntryForm) .shipment-entry-table input { width: 100%; }
}

@media screen and (max-width: 390px) {
  #content .sales-modal-actions > .review-live-total { flex: 1 1 100%; }
  #content .sales-modal-actions > button { flex: 1 1 auto; }
  #content .sales-modal-actions > button[type="submit"] { flex-grow: 2 !important; }
}

@media screen and (max-width: 760px) and (max-height: 480px) {
  .workspace-dialog > header, .qm-dialog > .qm-dialog-head, .purchase-type-dialog > header { padding-block: 4px; }
  .workspace-dialog > .dialog-actions, .qm-dialog > .qm-dialog-foot { padding-block-start: 6px; }
}
