/* Truelimbs ERP v5.7 — responsive record windows.
   Screen-only presentation patch. No quantities, saving, or print layouts change. */
@media screen and (max-width: 1100px) {
  :is(.wf-dialog, .v531-dialog, .tl5613420-dialog, .tl5613420-share-dialog,
      .tl5613423-return-dialog, .tl57-add-dialog, .tl5613424-dialog) {
    min-width: 0;
    max-width: calc(100vw - 24px) !important;
    max-height: calc(100dvh - 24px);
    overscroll-behavior: contain;
  }
  :is(.wf-dialog-body, .v531-body, .tl5613420-body, .tl57-add-content,
      .tl5613423-return-content, .tl5613424-content) {
    min-width: 0;
    overflow-wrap: anywhere;
  }
  :is(.wf-dialog, .v531-dialog, .tl5613420-dialog, .tl5613420-share-dialog,
      .tl5613423-return-dialog, .tl57-add-dialog, .tl5613424-dialog) :is(input, select, textarea) {
    box-sizing: border-box;
    min-width: 0;
    max-width: 100%;
  }
  :is(.wf-dialog, .v531-dialog, .tl5613420-dialog, .tl57-add-dialog,
      .tl5613423-return-dialog) :is(.tw, .tl5613417-detail-table,
      .tl5613420-table-wrap, .tl57-add-table, .tl5613423-return-table) {
    min-width: 0;
    max-width: 100%;
    overflow: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }
  .v550-record, .v550-list > div { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .v550-record > *, .v550-list > div > *, .v550-rec-actions { min-width: 0; }
  .v550-rec-actions { flex-wrap: wrap; }
  .v550-summary b { white-space: normal; overflow-wrap: anywhere; }
  .tl5613420-overview > div, .tl5613417-detail-links > div,
  .tl5613417-detail-summary > div, .tl5613415-summary > div { min-width: 0; }
  .tl5613420-overview b, .tl5613417-detail-links b { overflow-wrap: anywhere; }
  .tl5613420-section table { min-width: 760px; }
  .si-picker { min-width: 960px; }
  .tl57-add-table table { min-width: 740px; }
  .tl5613423-return-table table { min-width: 660px; }
  .tl57-pack-board { grid-template-columns: minmax(0, 1fr); }
  .tl57-pack-boxes { grid-template-columns: repeat(auto-fit, minmax(min(100%, 290px), 1fr)); }
  .tl57-pack-unpacked .tl57-pack-cards { max-height: 280px; }
}

@media screen and (max-width: 760px) {
  /* A record fills the viewport; the form body scrolls below its close control. */
  :is(.wf-modal, .v531-modal, .tl5613420-modal, .tl5613423-return-modal,
      .tl57-add-modal, .tl5613424-modal) {
    padding: 0 !important;
    align-items: stretch;
  }
  :is(.wf-modal > .wf-dialog, .v531-modal > .v531-dialog,
      .tl5613420-dialog, .tl5613420-share-dialog, .tl5613423-return-dialog,
      .tl57-add-dialog, .tl5613424-dialog),
  #wfModal:has(.v561342-rx) .wf-dialog {
    box-sizing: border-box;
    width: 100% !important;
    max-width: 100% !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
    margin: 0;
    border-radius: 0;
  }
  .wf-modal > .wf-dialog, .v531-modal > .v531-dialog {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  :is(.wf-dialog-head, .v531-head) { flex: none; gap: 10px; padding: 12px; }
  .wf-dialog-head h3, .v531-head > div { min-width: 0; overflow-wrap: anywhere; }
  :is(.wf-dialog-body, .v531-body), .v550-dialog .v531-body {
    flex: 1;
    min-height: 0;
    padding: 12px !important;
    overflow: auto;
    padding-bottom: max(16px, env(safe-area-inset-bottom)) !important;
  }
  :is(.wf-dialog, .v531-dialog, .tl5613420-dialog, .tl5613420-share-dialog,
      .tl5613423-return-dialog, .tl57-add-dialog, .tl5613424-dialog,
      .tl5613415-workspace) :is(input:not([type=checkbox]):not([type=radio]):not([type=hidden]), select, textarea) {
    font-size: 16px !important;
    min-height: 44px;
    max-width: 100%;
    box-sizing: border-box;
  }
  :is(.wf-dialog, .v531-dialog, .tl5613420-dialog, .tl5613420-share-dialog,
      .tl5613423-return-dialog, .tl57-add-dialog, .tl5613424-dialog,
      .tl5613415-workspace) :is(button, .btn) {
    min-height: 44px !important;
    white-space: normal;
    line-height: 1.3 !important;
    font-size: 12px;
    touch-action: manipulation;
  }
  :is(.wf-dialog, .v531-dialog, .tl5613420-dialog, .tl5613420-share-dialog,
      .tl5613423-return-dialog, .tl57-add-dialog, .tl5613424-dialog)
      input[type=file]::file-selector-button { min-height: 36px; font-size: 14px; }
  :is(.wf-close, .v531-head > button, .tl5613420-x,
      .tl5613423-return-head > button, .tl57-add-dialog header > button,
      .tl5613424-dialog header > button) {
    width: 44px !important;
    min-width: 44px;
    flex-shrink: 0;
    font-size: 26px !important;
  }
  :is(.wf-dialog, .tl57-add-dialog, .tl5613423-return-dialog, .tl5613424-dialog)
      :is(input[type=checkbox], input[type=radio]) { width: 24px; height: 24px; flex-shrink: 0; }
  :is(.wf-tabs, .v550-tabs) {
    flex-wrap: nowrap;
    max-width: 100%;
    overflow-x: auto;
    padding-left: 0;
    padding-right: 0;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }
  :is(.wf-tabs, .v550-tabs) > button { flex-shrink: 0; white-space: nowrap; }
  .wf-body { padding: 12px 0; }
  .wf-form, .si-form { grid-template-columns: minmax(0, 1fr); }
  .wf-form > *, .si-form > * { min-width: 0; }
  .wf-form .full, .si-form .full { grid-column: 1 / -1; }
  .wf-actions, .si-actions { flex-wrap: wrap; }
  .wf-actions > button, .si-actions > button { flex: 1 1 160px; }
  .si-source-head { flex-wrap: wrap; align-items: flex-start; }
  .wf-dialog :is(th, td), .v531-dialog :is(th, td) { font-size: 12px; }

  /* Purchase Order details, catalog selection, costs and receiving. */
  .v534-po-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .v534-po-grid > :first-child, .v534-po-grid > :nth-child(2),
  .v534-po-grid > :last-child { grid-column: 1 / -1; }
  .v534-po-discount, .tl5613422-destination-grid,
  .tl5613422-catalog-toolbar, .v534-po-item > .tl5613422-item-meta {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  .tl5613422-destination-status, .tl5613422-item-customer,
  .tl5613422-toolbar-destination { grid-column: 1 / -1; }
  .tl5613422-destination-head { align-items: flex-start; flex-wrap: wrap; }
  .tl5613422-catalog-toolbar button { height: auto; }
  .tl5613422-toolbar-destination { flex-wrap: wrap; }
  .v534-po-totals { width: 100%; flex-direction: column; align-items: stretch; gap: 9px; }
  .v534-po-totals span { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; }
  .v561342-rx { padding: 8px; }
  .v561342-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .v561342-summary span, .v561342-item-main span { font-size: 10px; }
  .v561342-meta, .v561342-lot { grid-template-columns: minmax(0, 1fr); }
  .v561342-item-main { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
  .v561342-item-main .v561342-prod { grid-column: 1 / -1; }
  .v561342-item-main > label { grid-column: 1 / -1; font-size: 11px; }
  .v561342-unit-head { display: none; }
  .v561342-unit { grid-template-columns: minmax(0, 1fr) 66px; gap: 10px; padding: 10px; }
  .v561342-unit-no, .v561342-unit > .v561342-sn,
  .v561342-unit > input:last-child { grid-column: 1 / -1; }
  .v561342-unit-no { justify-content: flex-start; padding: 8px; font-size: 12px; }
  .v561342-unit > select { grid-column: 1; }
  .v561342-unit > .v561342-photo { grid-column: 2; min-height: 44px; font-size: 13px; }
  .v561342-save { position: static; flex-wrap: wrap; gap: 8px; }
  .v561342-save > button { flex: 1 1 170px; }
  .v561342-save > small { flex-basis: 100%; font-size: 11px; }
  .tl5613423-card-grid { grid-template-columns: minmax(0, 1fr); }
  .tl5613423-po-card > footer { flex-wrap: wrap; }
  .tl5613423-po-card > footer > .btn,
  .tl5613423-po-card > footer details > .btn,
  .tl5613423-po-card footer details button,
  .tl5613423-view-tools button {
    min-height: 44px !important; height: auto !important;
    line-height: 1.3 !important; font-size: 12px !important; padding: 10px !important;
  }
  .tl5613423-po-card footer details > div { bottom: 50px; width: 180px; }
  .tl5613423-items li { font-size: 12px; }
  .tl5613423-items li b { white-space: normal; overflow-wrap: anywhere; }
  .tl5613423-po-meta b { font-size: 13px; }

  /* Invoice folder, cards and item details. */
  #page-invoices .tl5613417-invoice-card { grid-template-columns: minmax(0, 1fr); }
  #page-invoices .tl5613417-paper {
    flex-direction: row; flex-wrap: wrap; justify-content: flex-start;
    padding: 12px; gap: 10px; border-right: 0; border-bottom: 1px solid #d8e6ec;
  }
  #page-invoices .tl5613417-paper-icon { font-size: 30px; }
  #page-invoices .tl5613417-paper > b { max-width: none; font-size: 15px; }
  #page-invoices .tl5613417-card-top { flex-wrap: wrap; }
  #page-invoices .tl5613417-statuses { flex-direction: row; flex-wrap: wrap; }
  #page-invoices .tl5613417-commercial > span { white-space: normal; font-size: 12px; }
  #page-invoices .tl5613417-card-actions .btn,
  #page-invoices .tl5613417-view-toggle button { min-height: 44px; font-size: 12px; }
  .tl5613417-detail-head h2 { font-size: 20px; overflow-wrap: anywhere; }
  .tl5613417-detail-head > div:nth-child(2) { flex: 1; }
  .tl5613417-detail-actions { margin-left: 0; width: 100%; justify-content: flex-start; }
  .tl5613417-detail-actions > button { flex: 1 1 130px; }
  .tl5613417-detail-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tl5613417-detail-links, .tl5613415-grid, .tl5613415-files,
  .tl5613415-noteadd { grid-template-columns: minmax(0, 1fr); }
  .tl5613415-pagehead, .tl5613415-panel { padding: 12px; }
  .tl5613415-pagehead, .tl5613415-panelhead { flex-wrap: wrap; }
  .tl5613415-actions { width: 100%; justify-content: flex-start; }
  .tl5613415-actions > button { flex: 1 1 130px; }

  /* Saved shipping records, item picker and returns. Keep tables readable with local scrolling. */
  .tl5613420-head, .tl5613420-share-head, .tl5613423-return-head,
  .tl57-add-dialog header, .tl5613424-dialog header { padding: 14px 12px; }
  .tl5613420-toolbar { position: static; padding: 12px; }
  .tl5613420-toolbar > button { flex: 1 1 145px; }
  .tl5613420-body, .tl5613420-share-body, .tl5613423-return-content,
  .tl57-add-content, .tl5613424-content { padding: 12px; }
  .tl5613420-overview { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tl5613420-overview b { font-size: 13px; }
  .tl5613420-grid { grid-template-columns: minmax(0, 1fr); }
  .tl5613420-section { padding: 10px; }
  .tl5613420-section table, .tl5613423-return-table table,
  .tl57-add-table table { font-size: 12px; }
  .tl5613420-publication { flex-wrap: wrap; }
  .tl5613420-share-actions, .tl5613423-return-actions { padding: 12px; flex-wrap: wrap; }
  .tl5613420-share-actions > button, .tl5613423-return-actions > button { flex: 1 1 140px; }
  .tl5613420-share-sources { grid-template-columns: minmax(0, 1fr); }
  .tl57-add-dialog footer { position: static; flex-wrap: wrap; padding: 12px; }
  #tl57AddSummary { flex-basis: 100%; }
  .tl57-add-dialog footer > button { flex: 1 1 130px; }
  .tl5613423-return-history > div { grid-template-columns: minmax(0, 1fr); }

  /* Packing on touch uses the existing checkbox + Move Selected controls. */
  .tl57-pack-tools { align-items: stretch; }
  .tl57-pack-tools > input { flex-basis: 100%; min-width: 0; }
  .tl57-pack-tools > label { width: 100%; flex: 1 1 100%; flex-wrap: wrap; }
  .tl57-pack-tools select { flex: 1; min-width: 140px; max-width: 100%; }
  .tl57-pack-tools > button { flex: 1 1 130px; }
  #tl57PackingSelection { width: 100%; font-size: 12px; }
  .tl57-pack-board, .tl57-pack-boxes { grid-template-columns: minmax(0, 1fr); }
  .tl57-pack-unpacked .tl57-pack-cards { display: flex; max-height: 300px; }
  .tl57-pack-cards { max-height: 350px; }
  .tl57-pack-zonehead { padding: 10px; }
  .tl57-pack-zonehead > label { min-width: 0; }
  .tl57-pack-item { cursor: default; }
  .tl57-pack-item p { font-size: 13px; }
  .tl57-pack-item > small, .tl57-pack-item-top { font-size: 11px; }
  .tl57-pack-item-top { min-height: 44px; }
  .tl57-pack-item-bottom { flex-wrap: wrap; font-size: 12px; }
  .tl57-pack-item-bottom label { font-size: 12px; }
  .tl57-pack-item-bottom input { width: 76px; }
  .tl57-pack-boxes .tl5613424-boxhead label { min-width: 100px; }
  .tl5613424-dialog footer { flex-wrap: wrap; padding: 12px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .tl5613424-dialog footer > span { flex-basis: 100%; }
  .tl5613424-dialog footer button { flex: 1 1 120px; }

  /* Sales Order record, related records, notes and attachment upload. */
  .v550-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .v550-summary > div { padding: 10px; }
  .v550-summary span { font-size: 10px; }
  .v550-summary b { font-size: 14px; }
  .v550-flow { scroll-snap-type: x proximity; }
  .v550-step { min-width: 160px; scroll-snap-align: start; }
  .v550-record, .v550-list > div, .v556-fin-grid, .v5521-note-form {
    grid-template-columns: minmax(0, 1fr);
  }
  .v550-section-head { flex-wrap: wrap; align-items: flex-start; }
  .v550-actions > button, .v550-rec-actions > button { flex: 1 1 140px; }
  .tl57so-toolbar, .tl57so-file, .tl57so-form-foot { flex-direction: column; align-items: stretch; }
  .tl57so-toolbar > div { display: grid; grid-template-columns: minmax(0, 1fr); }
  .tl57so-fields { grid-template-columns: minmax(0, 1fr); }
  .tl57so-upload-head, .tl57so-upload-form, .tl57so-file { padding: 12px; }
  .tl57so-file-actions { justify-content: flex-start; }
  .tl57so-file-actions > button { flex: 1 1 90px; }
  .tl57so-queue span { min-width: 0; flex-basis: 100%; }
  .tl57so-empty, .tl57so-error { margin-left: 12px; margin-right: 12px; padding: 16px; }
}

@media screen and (max-width: 380px) {
  .tl5613420-overview, .v550-summary, .tl5613415-summary {
    grid-template-columns: minmax(0, 1fr);
  }
  .v534-po-grid { grid-template-columns: minmax(0, 1fr); }
}

/* A landscape phone needs its content area more than fixed toolbars. */
@media screen and (max-height: 520px) and (max-width: 1100px) {
  .tl5613424-dialog { display: block; overflow-y: auto; }
  #tl5613424PackingBody { display: block; overflow: visible; }
  .tl5613424-content { overflow: visible; }
  .tl5613424-dialog footer, .tl5613420-toolbar, .tl57-add-dialog footer,
  .v561342-save { position: static; }
}
