/* =============================================================================
   OrganicSystem — ERP Responsive Forms (Edit pages)
   Shared by every Edit surface via _UiAutoScaleHead. Layout only.

   Desktop  (>=1400, landscape): 3 columns
   Laptop   (1200–1399, landscape): 2 columns
   Tablet   (768–1199, landscape): 2 columns
   Portrait / narrow: single column

   Labels stay visible · inputs/images fluid · buttons wrap · no page X-scroll
   ============================================================================= */

:root {
  --os-form-col-gap: 0.75rem;
  --os-form-row-gap: 0.65rem;
  --os-form-label-min: 4.5rem;
  --os-form-label-max: 7.5rem;
}

/* ---------- Scope helpers ---------- */
.os-erp-form-scope,
[class*="-edit-page"],
.os-desktop-form,
.prs-page .prs-content-panel,
body.os-module-shell .os-app-main,
body.os-app-shell .os-app-main {
  --os-form-field-cols: 1;
}

/* ---------- Containment: no page horizontal scroll ---------- */
[class*="-edit-page"],
.os-desktop-form,
.prs-page form,
body.os-module-shell .os-app-main form:not(.os-report-filter-form):not(.module-main-filter-form):not(.prs-station-form),
body.os-app-shell .os-app-main form:not(.os-report-filter-form) {
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

[class*="-edit-page"] .row,
.os-desktop-form .row,
.prs-page form .row,
body.os-module-shell .os-app-main form:not(.os-report-filter-form) .row,
body.os-app-shell .os-app-main form:not(.os-report-filter-form) .row {
  max-width: 100%;
  min-width: 0;
  margin-left: 0;
  margin-right: 0;
}

/* ---------- Labels always visible ---------- */
[class*="-edit-page"] .form-label,
[class*="-edit-page"] label.form-label,
.os-desktop-form .form-label,
.os-desktop-form-table th,
.aps-site-table th,
.prs-page form .form-label,
body.os-module-shell .os-app-main form .form-label,
body.os-app-shell .os-app-main form .form-label {
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  color: inherit;
  white-space: normal;
  overflow: visible;
  text-overflow: unset;
  max-width: 100%;
  min-width: 0;
  align-items: center;
}

.os-desktop-form {
  --os-desktop-label-width: clamp(var(--os-form-label-min), 22vw, var(--os-form-label-max));
}

/* ---------- Fluid inputs ---------- */
[class*="-edit-page"] .form-control,
[class*="-edit-page"] .form-select,
[class*="-edit-page"] textarea.form-control,
[class*="-edit-page"] .input-group,
.os-desktop-form .form-control,
.os-desktop-form .form-select,
.os-desktop-form textarea.form-control,
.os-desktop-form .input-group,
.os-desktop-form-table .form-control,
.os-desktop-form-table .form-select,
.aps-site-table .form-control,
.aps-site-table .form-select,
.prs-page form .form-control,
.prs-page form .form-select,
body.os-module-shell .os-app-main form:not(.os-report-filter-form) .form-control,
body.os-module-shell .os-app-main form:not(.os-report-filter-form) .form-select,
body.os-app-shell .os-app-main form:not(.os-report-filter-form) .form-control,
body.os-app-shell .os-app-main form:not(.os-report-filter-form) .form-select {
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  box-sizing: border-box;
}

[class*="-edit-page"] .input-group > .form-control,
[class*="-edit-page"] .input-group > .form-select,
.os-desktop-form .input-group > .form-control,
.os-desktop-form .input-group > .form-select {
  width: 1% !important; /* Bootstrap input-group shrink pattern */
  flex: 1 1 auto !important;
  max-width: 100% !important;
  min-width: 0 !important;
}

/* ---------- Bootstrap field columns (dominant Edit layout) ----------
   Only .row.g-3 / .row.g-2 field rows — not page layout splitters
   (e.g. .prs-li-layout col-lg-8/4, export dual panels). */
[class*="-edit-page"] form .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"],
[class*="-edit-page"] form .row.g-2:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"],
.os-desktop-form > .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"],
.os-desktop-form > .row.g-2:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"],
.prs-page form .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"],
.prs-page form .row.g-2:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"],
body.os-module-shell .os-app-main form:not(.os-report-filter-form):not(.module-main-filter-form):not(.prs-station-form) .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"],
body.os-module-shell .os-app-main form:not(.os-report-filter-form) .row.g-2:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"],
body.os-module-shell .os-app-main form:not(.os-report-filter-form) .card-body.row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"],
body.os-module-shell .os-app-main form:not(.os-report-filter-form) .card-body > .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"],
body.os-app-shell .os-app-main form:not(.os-report-filter-form) .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"],
body.os-app-shell .os-app-main form:not(.os-report-filter-form) .row.g-2:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"] {
  min-width: 0 !important;
  max-width: 100%;
  box-sizing: border-box;
}

/* Layout splitters: fluid, never forced into equal field columns */
form .row.prs-li-layout > [class*="col-"],
form .row.ags-export-invoice-layout > [class*="col-"],
[class*="-edit-page"] form > .row:not(.g-3):not(.g-2) > [class*="col-lg-"],
[class*="-edit-page"] form > .row:not(.g-3):not(.g-2) > [class*="col-xl-"] {
  min-width: 0 !important;
  max-width: 100%;
}

/* Full-span fields stay full width at every breakpoint */
[class*="-edit-page"] form .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > .col-12,
[class*="-edit-page"] form .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > .col-md-12,
[class*="-edit-page"] form .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > .col-lg-12,
[class*="-edit-page"] form .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > .col-xl-12,
[class*="-edit-page"] form .row.g-2:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > .col-12,
[class*="-edit-page"] form .row.g-2:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > .col-md-12,
.os-desktop-form > .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > .col-12,
.os-desktop-form > .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > .col-md-12,
.os-desktop-form > .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > .col-lg-12,
.prs-page form .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > .col-12,
.prs-page form .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > .col-md-12,
body.os-module-shell .os-app-main form:not(.os-report-filter-form) .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > .col-12,
body.os-module-shell .os-app-main form:not(.os-report-filter-form) .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > .col-md-12,
body.os-app-shell .os-app-main form:not(.os-report-filter-form) .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > .col-12,
body.os-app-shell .os-app-main form:not(.os-report-filter-form) .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > .col-md-12 {
  flex: 0 0 100% !important;
  max-width: 100% !important;
  width: 100% !important;
}

/* Portrait / narrow: 1 column */
@media (orientation: portrait), (max-aspect-ratio: 1/1), (max-width: 767.98px) {
  html.os-portrait-root,
  html[data-os-bp="tablet-portrait"],
  html[data-os-bp="mobile-landscape"],
  html[data-os-bp="mobile-portrait"] {
    --os-form-field-cols: 1;
  }

  [class*="-edit-page"] form .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12):not(.col-lg-12):not(.col-xl-12),
  [class*="-edit-page"] form .row.g-2:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12):not(.col-lg-12):not(.col-xl-12),
  .os-desktop-form > .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12):not(.col-lg-12),
  .os-desktop-form > .row.g-2:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12),
  .prs-page form .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12),
  .prs-page form .row.g-2:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12),
  body.os-module-shell .os-app-main form:not(.os-report-filter-form):not(.module-main-filter-form):not(.prs-station-form) .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12),
  body.os-module-shell .os-app-main form:not(.os-report-filter-form) .row.g-2:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12),
  body.os-module-shell .os-app-main form:not(.os-report-filter-form) .card-body.row.g-3 > [class*="col-"]:not(.col-12):not(.col-md-12),
  body.os-module-shell .os-app-main form:not(.os-report-filter-form) .card-body > .row.g-3 > [class*="col-"]:not(.col-12):not(.col-md-12),
  body.os-app-shell .os-app-main form:not(.os-report-filter-form) .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12),
  body.os-app-shell .os-app-main form:not(.os-report-filter-form) .row.g-2:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12),
  /* Dual-panel edit layouts stack in portrait */
  form .row.prs-li-layout > [class*="col-"],
  form .row.ags-export-invoice-layout > [class*="col-"] {
    flex: 0 0 100% !important;
    max-width: 100% !important;
    width: 100% !important;
  }
}

/* Tablet + Laptop landscape: 2 columns */
@media (min-width: 768px) and (max-width: 1399.98px) and (orientation: landscape),
       (min-width: 768px) and (max-width: 1399.98px) and (min-aspect-ratio: 1/1) {
  html[data-os-bp="laptop"],
  html[data-os-bp="tablet-landscape"] {
    --os-form-field-cols: 2;
  }

  [class*="-edit-page"] form .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12):not(.col-lg-12):not(.col-xl-12),
  [class*="-edit-page"] form .row.g-2:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12):not(.col-lg-12):not(.col-xl-12),
  .os-desktop-form > .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12):not(.col-lg-12),
  .os-desktop-form > .row.g-2:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12),
  .prs-page form .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12),
  .prs-page form .row.g-2:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12),
  body.os-module-shell .os-app-main form:not(.os-report-filter-form):not(.module-main-filter-form):not(.prs-station-form) .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12),
  body.os-module-shell .os-app-main form:not(.os-report-filter-form) .row.g-2:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12),
  body.os-module-shell .os-app-main form:not(.os-report-filter-form) .card-body.row.g-3 > [class*="col-"]:not(.col-12):not(.col-md-12),
  body.os-module-shell .os-app-main form:not(.os-report-filter-form) .card-body > .row.g-3 > [class*="col-"]:not(.col-12):not(.col-md-12),
  body.os-app-shell .os-app-main form:not(.os-report-filter-form) .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12),
  body.os-app-shell .os-app-main form:not(.os-report-filter-form) .row.g-2:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12) {
    flex: 0 0 50% !important;
    max-width: 50% !important;
    width: 50% !important;
  }
}

/* Desktop landscape: 3 columns */
@media (min-width: 1400px) and (orientation: landscape),
       (min-width: 1400px) and (min-aspect-ratio: 1/1) {
  html[data-os-bp="desktop"],
  html[data-os-bp="desktop-xl"] {
    --os-form-field-cols: 3;
  }

  [class*="-edit-page"] form .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12):not(.col-lg-12):not(.col-xl-12),
  [class*="-edit-page"] form .row.g-2:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12):not(.col-lg-12):not(.col-xl-12),
  .os-desktop-form > .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12):not(.col-lg-12),
  .os-desktop-form > .row.g-2:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12),
  .prs-page form .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12),
  .prs-page form .row.g-2:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12),
  body.os-module-shell .os-app-main form:not(.os-report-filter-form):not(.module-main-filter-form):not(.prs-station-form) .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12),
  body.os-module-shell .os-app-main form:not(.os-report-filter-form) .row.g-2:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12),
  body.os-module-shell .os-app-main form:not(.os-report-filter-form) .card-body.row.g-3 > [class*="col-"]:not(.col-12):not(.col-md-12),
  body.os-module-shell .os-app-main form:not(.os-report-filter-form) .card-body > .row.g-3 > [class*="col-"]:not(.col-12):not(.col-md-12),
  body.os-app-shell .os-app-main form:not(.os-report-filter-form) .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12),
  body.os-app-shell .os-app-main form:not(.os-report-filter-form) .row.g-2:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12) {
    flex: 0 0 33.3333% !important;
    max-width: 33.3333% !important;
    width: 33.3333% !important;
  }
}

/* BP attribute reinforcement (when orientation media is ambiguous) */
html[data-os-bp="desktop"] body:not(.os-portrait-layout) .os-app-main form:not(.os-report-filter-form) > .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12),
html[data-os-bp="desktop-xl"] body:not(.os-portrait-layout) .os-app-main form:not(.os-report-filter-form) > .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12),
html[data-os-bp="desktop"] body:not(.os-portrait-layout) .os-desktop-form > .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12),
html[data-os-bp="desktop-xl"] body:not(.os-portrait-layout) .os-desktop-form > .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12) {
  flex: 0 0 33.3333% !important;
  max-width: 33.3333% !important;
  width: 33.3333% !important;
}

html[data-os-bp="laptop"] body:not(.os-portrait-layout) .os-app-main form:not(.os-report-filter-form) > .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12),
html[data-os-bp="tablet-landscape"] body:not(.os-portrait-layout) .os-app-main form:not(.os-report-filter-form) > .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12),
html[data-os-bp="laptop"] body:not(.os-portrait-layout) .os-desktop-form > .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12),
html[data-os-bp="tablet-landscape"] body:not(.os-portrait-layout) .os-desktop-form > .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"]:not(.col-12):not(.col-md-12) {
  flex: 0 0 50% !important;
  max-width: 50% !important;
  width: 50% !important;
}

html.os-portrait-root .os-app-main form:not(.os-report-filter-form) > .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"],
html.os-portrait-root .os-desktop-form > .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"],
body.os-portrait-layout .os-app-main form:not(.os-report-filter-form) > .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"],
body.os-portrait-layout .os-desktop-form > .row.g-3:not(.ags-export-invoice-layout):not(.prs-li-layout):not(.prs-ro-layout):not(.prs-export-order-layout):not(.os-split-view) > [class*="col-"] {
  flex: 0 0 100% !important;
  max-width: 100% !important;
  width: 100% !important;
}

/* ---------- ERP table forms (--cols-3 / --cols-2) ---------- */
.os-desktop-form-table[class*="--cols-3"],
.os-desktop-form-table[class*="--cols-2"],
.aps-site-table[class*="--cols-3"],
.aps-site-table[class*="--cols-2"],
table.os-desktop-form-table[class*="--cols-"],
table[class*="-table--cols-3"],
table[class*="-table--cols-2"] {
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  table-layout: fixed;
  overflow-x: visible !important;
}

.os-desktop-form-table[class*="--cols-"] colgroup,
.aps-site-table[class*="--cols-"] colgroup,
table[class*="-table--cols-"] colgroup {
  display: none;
}

/* Desktop: native 3-field table (leave table layout) */
@media (min-width: 1400px) and (orientation: landscape),
       (min-width: 1400px) and (min-aspect-ratio: 1/1) {
  table[class*="-table--cols-3"],
  .os-desktop-form-table[class*="--cols-3"],
  .aps-site-table[class*="--cols-3"] {
    display: table !important;
  }

  table[class*="-table--cols-3"] > tbody,
  .os-desktop-form-table[class*="--cols-3"] > tbody,
  .aps-site-table[class*="--cols-3"] > tbody {
    display: table-row-group !important;
  }

  table[class*="-table--cols-3"] > tbody > tr,
  .os-desktop-form-table[class*="--cols-3"] > tbody > tr,
  .aps-site-table[class*="--cols-3"] > tbody > tr {
    display: table-row !important;
  }

  table[class*="-table--cols-3"] > tbody > tr > th,
  table[class*="-table--cols-3"] > tbody > tr > td,
  .os-desktop-form-table[class*="--cols-3"] > tbody > tr > th,
  .os-desktop-form-table[class*="--cols-3"] > tbody > tr > td,
  .aps-site-table[class*="--cols-3"] > tbody > tr > th,
  .aps-site-table[class*="--cols-3"] > tbody > tr > td {
    display: table-cell !important;
    width: auto !important;
    min-width: 0 !important;
  }

  table[class*="-table--cols-3"] > tbody > tr > th,
  .os-desktop-form-table[class*="--cols-3"] > tbody > tr > th,
  .aps-site-table[class*="--cols-3"] > tbody > tr > th {
    width: 10% !important;
    white-space: normal !important;
  }

  table[class*="-table--cols-3"] > tbody > tr > td,
  .os-desktop-form-table[class*="--cols-3"] > tbody > tr > td,
  .aps-site-table[class*="--cols-3"] > tbody > tr > td {
    width: 23.3333% !important;
  }
}

/* Laptop + Tablet landscape: 2 field columns (label|value × 2, third wraps) */
@media (min-width: 768px) and (max-width: 1399.98px) and (orientation: landscape),
       (min-width: 768px) and (max-width: 1399.98px) and (min-aspect-ratio: 1/1) {
  table[class*="-table--cols-3"],
  .os-desktop-form-table[class*="--cols-3"],
  .aps-site-table[class*="--cols-3"],
  table[class*="-table--cols-2"],
  .os-desktop-form-table[class*="--cols-2"],
  .aps-site-table[class*="--cols-2"] {
    display: block !important;
    width: 100% !important;
  }

  table[class*="-table--cols-3"] > tbody,
  .os-desktop-form-table[class*="--cols-3"] > tbody,
  .aps-site-table[class*="--cols-3"] > tbody,
  table[class*="-table--cols-2"] > tbody,
  .os-desktop-form-table[class*="--cols-2"] > tbody,
  .aps-site-table[class*="--cols-2"] > tbody {
    display: block !important;
    width: 100% !important;
  }

  table[class*="-table--cols-3"] > tbody > tr,
  .os-desktop-form-table[class*="--cols-3"] > tbody > tr,
  .aps-site-table[class*="--cols-3"] > tbody > tr {
    display: grid !important;
    grid-template-columns: minmax(var(--os-form-label-min), 22%) minmax(0, 1fr) minmax(var(--os-form-label-min), 22%) minmax(0, 1fr);
    width: 100% !important;
    border-bottom: 1px solid var(--os-color-form-border, #c8c8c8);
  }

  table[class*="-table--cols-2"] > tbody > tr,
  .os-desktop-form-table[class*="--cols-2"] > tbody > tr,
  .aps-site-table[class*="--cols-2"] > tbody > tr {
    display: grid !important;
    grid-template-columns: minmax(var(--os-form-label-min), 22%) minmax(0, 1fr) minmax(var(--os-form-label-min), 22%) minmax(0, 1fr);
    width: 100% !important;
  }

  table[class*="-table--cols-3"] > tbody > tr > th,
  table[class*="-table--cols-3"] > tbody > tr > td,
  .os-desktop-form-table[class*="--cols-3"] > tbody > tr > th,
  .os-desktop-form-table[class*="--cols-3"] > tbody > tr > td,
  .aps-site-table[class*="--cols-3"] > tbody > tr > th,
  .aps-site-table[class*="--cols-3"] > tbody > tr > td,
  table[class*="-table--cols-2"] > tbody > tr > th,
  table[class*="-table--cols-2"] > tbody > tr > td,
  .os-desktop-form-table[class*="--cols-2"] > tbody > tr > th,
  .os-desktop-form-table[class*="--cols-2"] > tbody > tr > td,
  .aps-site-table[class*="--cols-2"] > tbody > tr > th,
  .aps-site-table[class*="--cols-2"] > tbody > tr > td {
    display: flex !important;
    align-items: center;
    width: auto !important;
    max-width: 100% !important;
    min-width: 0 !important;
    border-right: 1px solid var(--os-color-form-border, #c8c8c8);
  }

  table[class*="-table--cols-3"] > tbody > tr > th:empty,
  table[class*="-table--cols-3"] > tbody > tr > td:empty,
  .os-desktop-form-table[class*="--cols-3"] > tbody > tr > th:empty,
  .os-desktop-form-table[class*="--cols-3"] > tbody > tr > td:empty,
  .aps-site-table[class*="--cols-3"] > tbody > tr > th:empty,
  .aps-site-table[class*="--cols-3"] > tbody > tr > td:empty {
    display: none !important;
  }
}

/* Portrait: single field column (label | value), labels remain visible */
@media (orientation: portrait), (max-aspect-ratio: 1/1), (max-width: 767.98px) {
  table[class*="-table--cols-3"],
  .os-desktop-form-table[class*="--cols-3"],
  .aps-site-table[class*="--cols-3"],
  table[class*="-table--cols-2"],
  .os-desktop-form-table[class*="--cols-2"],
  .aps-site-table[class*="--cols-2"],
  .os-desktop-form-table:not([data-os-keep-table="true"]),
  .aps-site-table:not([data-os-keep-table="true"]) {
    display: block !important;
    width: 100% !important;
    overflow-x: visible !important;
  }

  table[class*="-table--cols-3"] > tbody,
  .os-desktop-form-table[class*="--cols-3"] > tbody,
  .aps-site-table[class*="--cols-3"] > tbody,
  table[class*="-table--cols-2"] > tbody,
  .os-desktop-form-table[class*="--cols-2"] > tbody,
  .aps-site-table[class*="--cols-2"] > tbody,
  .os-desktop-form-table:not([data-os-keep-table="true"]) > tbody,
  .aps-site-table:not([data-os-keep-table="true"]) > tbody {
    display: block !important;
    width: 100% !important;
  }

  table[class*="-table--cols-3"] > tbody > tr,
  .os-desktop-form-table[class*="--cols-3"] > tbody > tr,
  .aps-site-table[class*="--cols-3"] > tbody > tr,
  table[class*="-table--cols-2"] > tbody > tr,
  .os-desktop-form-table[class*="--cols-2"] > tbody > tr,
  .aps-site-table[class*="--cols-2"] > tbody > tr,
  .os-desktop-form-table:not([data-os-keep-table="true"]) > tbody > tr,
  .aps-site-table:not([data-os-keep-table="true"]) > tbody > tr {
    display: grid !important;
    grid-template-columns: minmax(var(--os-form-label-min), 32%) minmax(0, 1fr);
    width: 100% !important;
  }

  table[class*="-table--cols-3"] > tbody > tr > th,
  table[class*="-table--cols-3"] > tbody > tr > td,
  .os-desktop-form-table[class*="--cols-3"] > tbody > tr > th,
  .os-desktop-form-table[class*="--cols-3"] > tbody > tr > td,
  .aps-site-table[class*="--cols-3"] > tbody > tr > th,
  .aps-site-table[class*="--cols-3"] > tbody > tr > td,
  table[class*="-table--cols-2"] > tbody > tr > th,
  table[class*="-table--cols-2"] > tbody > tr > td,
  .os-desktop-form-table[class*="--cols-2"] > tbody > tr > th,
  .os-desktop-form-table[class*="--cols-2"] > tbody > tr > td,
  .aps-site-table[class*="--cols-2"] > tbody > tr > th,
  .aps-site-table[class*="--cols-2"] > tbody > tr > td,
  .os-desktop-form-table:not([data-os-keep-table="true"]) > tbody > tr > th,
  .os-desktop-form-table:not([data-os-keep-table="true"]) > tbody > tr > td,
  .aps-site-table:not([data-os-keep-table="true"]) > tbody > tr > th,
  .aps-site-table:not([data-os-keep-table="true"]) > tbody > tr > td {
    display: flex !important;
    align-items: center;
    width: auto !important;
    max-width: 100% !important;
    min-width: 0 !important;
    white-space: normal !important;
  }

  table[class*="-table--cols-3"] > tbody > tr > th:empty,
  table[class*="-table--cols-3"] > tbody > tr > td:empty,
  .os-desktop-form-table[class*="--cols-3"] > tbody > tr > th:empty,
  .os-desktop-form-table[class*="--cols-3"] > tbody > tr > td:empty,
  .aps-site-table[class*="--cols-3"] > tbody > tr > th:empty,
  .aps-site-table[class*="--cols-3"] > tbody > tr > td:empty {
    display: none !important;
  }
}

/* Keep-table headers (invoice line headers): contain width, never push page */
.os-desktop-form-table[data-os-keep-table="true"],
table[data-os-keep-table="true"] {
  display: block;
  width: 100% !important;
  max-width: 100% !important;
  overflow-x: auto;
  overflow-y: hidden;
}

/* ---------- Specialty CSS-grid field hosts ---------- */
.ags-export-invoice-header-grid,
.ags-export-invoice-footer-fields,
.prs-export-order-header-grid,
.aps-qcap-protocol-form-grid {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

@media (min-width: 1400px) and (orientation: landscape),
       (min-width: 1400px) and (min-aspect-ratio: 1/1) {
  .aps-qcap-protocol-form-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }
}

@media (min-width: 768px) and (max-width: 1399.98px) and (orientation: landscape),
       (min-width: 768px) and (max-width: 1399.98px) and (min-aspect-ratio: 1/1) {
  .aps-qcap-protocol-form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .ags-export-invoice-header-grid .field-row-split,
  .prs-export-order-header-grid .field-row-split {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

@media (orientation: portrait), (max-aspect-ratio: 1/1), (max-width: 767.98px) {
  .aps-qcap-protocol-form-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .ags-export-invoice-header-grid .field-row-split,
  .prs-export-order-header-grid .field-row-split,
  .ags-export-invoice-footer-fields {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .aps-qcap-protocol-form-grid .field-wide {
    grid-column: auto !important;
  }
}

/* ---------- Images: fluid + column policy ---------- */
.os-desktop-images-row,
.aps-site-images-row {
  display: grid !important;
  gap: var(--os-form-col-gap);
  width: 100%;
  max-width: 100%;
  min-width: 0;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.os-desktop-images-row img,
.aps-site-images-row img,
.os-desktop-image-panel img,
.aps-site-image-panel img,
.aps-site-image-preview,
[class*="-edit-page"] img,
.os-desktop-form img {
  max-width: 100% !important;
  width: auto;
  height: auto !important;
  object-fit: contain;
}

.os-desktop-image-placeholder,
.aps-site-image-placeholder,
.aps-site-image-frame {
  max-width: 100%;
  min-width: 0;
}

@media (min-width: 768px) and (max-width: 1399.98px) and (orientation: landscape),
       (min-width: 768px) and (max-width: 1399.98px) and (min-aspect-ratio: 1/1) {
  .os-desktop-images-row,
  .aps-site-images-row {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

@media (orientation: portrait), (max-aspect-ratio: 1/1), (max-width: 767.98px) {
  .os-desktop-images-row,
  .aps-site-images-row {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}

/* ---------- Buttons wrap automatically ---------- */
[class*="-edit-page"] .mt-4.d-flex,
[class*="-edit-page"] .mt-3.d-flex,
[class*="-edit-page"] .d-flex.gap-2,
.os-desktop-form > .mt-4.d-flex,
.os-desktop-form > .mt-3.d-flex,
.os-desktop-form-actions,
.prs-page form .mt-4.d-flex,
.prs-page form .mt-3.d-flex,
body.os-module-shell .os-app-main form:not(.os-report-filter-form) > .mt-4.d-flex,
body.os-module-shell .os-app-main form:not(.os-report-filter-form) > .mt-3.d-flex,
body.os-app-shell .os-app-main form:not(.os-report-filter-form) > .mt-4.d-flex,
body.os-app-shell .os-app-main form:not(.os-report-filter-form) > .mt-3.d-flex {
  flex-wrap: wrap !important;
  gap: 0.5rem !important;
  max-width: 100%;
  min-width: 0;
}

[class*="-edit-page"] .btn,
.os-desktop-form .btn,
.prs-page form .btn {
  flex: 0 1 auto;
  max-width: 100%;
  white-space: normal;
}

/* ---------- Neutralize older form X-scroll / forced stack conflicts ---------- */
@media (max-width: 991.98px) {
  .os-desktop-form-table:not([data-os-keep-table="true"]),
  .aps-site-table:not([data-os-keep-table="true"]),
  .prs-ro-header-table:not([data-os-keep-table="true"]),
  .prs-li-header-table:not([data-os-keep-table="true"]) {
    overflow-x: visible !important;
  }
}

/* PrsLocalInvoice header is a single label|value column like the WinForms form.
   Keep native table cells so captions stay beside their editors. */
.prs-local-invoice-edit table.os-desktop-form-table.prs-li-header-table,
.prs-local-invoice-edit table.os-desktop-form-table.prs-li-header-table > tbody {
  display: table !important;
  width: 100% !important;
  table-layout: fixed;
}

.prs-local-invoice-edit table.os-desktop-form-table.prs-li-header-table > tbody > tr {
  display: table-row !important;
}

.prs-local-invoice-edit table.os-desktop-form-table.prs-li-header-table > tbody > tr > th,
.prs-local-invoice-edit table.os-desktop-form-table.prs-li-header-table > tbody > tr > td {
  display: table-cell !important;
  white-space: nowrap !important;
  width: auto !important;
  max-width: none !important;
  min-width: 0;
}

.prs-local-invoice-edit table.os-desktop-form-table.prs-li-header-table > tbody > tr > th {
  width: 8.75rem !important;
  min-width: 8.75rem;
}
