/* Shared field/width contract. Keep business handlers and sheet viewport logic intact. */
*, *::before, *::after {
  box-sizing: border-box;
}

@media screen and (max-width: 640px), screen and (max-width: 950px) and (max-height: 500px) and (pointer: coarse) {
  /* Legacy table selectors are more specific; focus zoom must be prevented everywhere. */
  body.ui-pilot :is(input, textarea, select) {
    font-size: 16px !important;
    min-width: 0;
    max-width: 100%;
  }

  body.ui-pilot :is(input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), textarea, select) {
    min-height: 44px;
  }

  .ui-pilot :is(.app-shell, .app-workspace, .app-content, .view, .panel, .card, form, fieldset,
      .filters, .ops-toolbar, .ops-form-grid, .ops-month-layout, .ops-summary,
      .inventory-toolbar, .inventory-summary, .work-summary, .pilot-calculator-grid,
      .sale-lines, .sale-line-row, .delivery-lines, .delivery-line-row,
      .delivery-line-new-fields, .client-extra-block, .client-systems-rows,
      .client-system-row, .notification-subpanel, .notification-card-grid,
      .notification-fields, .notification-reminder-form, .notification-exclude-form) {
    min-width: 0;
    max-width: 100%;
  }

  .ui-pilot :is(form, .filters, .ops-form-grid, .sale-line-row, .delivery-line-row,
      .delivery-line-new-fields, .client-system-row, .notification-fields,
      .notification-reminder-form, .notification-exclude-form, .pilot-calculator-grid) > *,
  .ui-pilot :is(.ops-field, .work-field, .inventory-field, .pilot-field, .notification-field) {
    min-width: 0;
    max-width: 100%;
  }

  .ui-pilot :is(.ops-field, .work-field, .inventory-field, .pilot-field, .notification-field) > :is(input, textarea, select) {
    width: 100%;
  }
}

@media screen and (max-width: 420px) {
  /* At phone widths, native date/select controls and numeric values need a full track. */
  .ui-pilot :is(.ops-form-grid, .ops-sales-filters, .ops-cash-filters, .inventory-add-form,
      .workspace-migration .inline-form, .workspace-migration .filters, .pilot-form,
      .delivery-line-new-fields, .notification-fields) {
    grid-template-columns: minmax(0, 1fr);
  }

  .ui-pilot #view-sales .sale-line-row,
  .ui-pilot .workspace-migration .delivery-line-row {
    grid-template-columns: minmax(0, 1fr) 44px;
  }
  .ui-pilot #view-sales .sale-line-row > .ops-field,
  .ui-pilot .workspace-migration .delivery-line-row > .work-field {
    grid-column: 1 / -1;
  }
  .ui-pilot #view-sales .sale-line-row > .ops-line-scent,
  .ui-pilot .workspace-migration .delivery-line-row > .work-field:first-child {
    grid-column: 1;
  }
  .ui-pilot #view-sales .sale-line-row .sale-line-remove,
  .ui-pilot .workspace-migration .delivery-line-row .delivery-line-remove {
    grid-column: 2;
    grid-row: 1;
  }

  .ui-pilot .workspace-migration .client-system-row {
    grid-template-columns: minmax(0, 1fr) 44px;
  }
  .ui-pilot .workspace-migration .client-system-row > .work-field {
    grid-column: 1 / -1;
  }
  .ui-pilot .workspace-migration .client-system-row > .work-field:first-child {
    grid-column: 1;
  }
  .ui-pilot .workspace-migration .client-system-remove {
    grid-column: 2;
    grid-row: 1;
  }
}

@media screen and (max-width: 360px) {
  .ui-pilot #view-inventory #inventoryTable tr.inventory-expanded {
    grid-template-columns: minmax(0, 1fr);
  }
}
