/* Engineer Portal V2 - unified modal dialogs */

.tp-v2 .modal {
  --bs-modal-bg: var(--tp-card);
  --bs-modal-border-radius: 14px;
  --bs-modal-inner-border-radius: 14px;
}

.tp-v2 .modal-backdrop.show {
  opacity: 0.45;
}

.tp-v2 .modal-dialog {
  margin: 1.25rem auto;
  max-width: min(520px, calc(100% - 2rem));
}

.tp-v2 .modal-dialog.modal-sm {
  max-width: min(400px, calc(100% - 2rem));
}

.tp-v2 .modal-dialog.modal-lg {
  max-width: min(900px, calc(100% - 2rem));
}

.tp-v2 .modal-dialog.modal-xl {
  max-width: min(1140px, calc(100% - 2rem));
}

.tp-v2 .modal-content {
  border: 1px solid var(--tp-border);
  border-radius: 14px;
  box-shadow: 0 24px 48px rgba(15, 23, 42, 0.18);
  overflow: hidden;
}

/* Header - overrides legacy style.css yellow (#ffd777) */
.tp-v2 .modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--tp-primary-dark) !important;
  color: #fff;
  border-bottom: none;
  padding: 1rem 1.25rem;
}

.tp-v2 .modal-header.btn-warning,
.tp-v2 .modal-header.bg-warning {
  background: #D97706 !important;
  color: #fff;
}

.tp-v2 .modal-header.btn-danger,
.tp-v2 .modal-header.bg-danger {
  background: var(--tp-danger) !important;
  color: #fff;
}

.tp-v2 .modal-title,
.tp-v2 .modal-header h4,
.tp-v2 .modal-header h5 {
  color: #fff;
  font-weight: 600;
  font-size: 1.0625rem;
  line-height: 1.35;
  margin: 0;
  flex: 1;
}

/* Legacy BS3 close button */
.tp-v2 .modal-header .close {
  float: none;
  order: 2;
  margin: 0;
  padding: 0.35rem;
  width: 2rem;
  height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 400;
  line-height: 1;
  color: #fff;
  opacity: 0.85;
  background: transparent;
  border: 0;
  border-radius: 8px;
  text-shadow: none;
  transition: background 0.15s, opacity 0.15s;
}

.tp-v2 .modal-header .close:hover,
.tp-v2 .modal-header .close:focus {
  color: #fff;
  opacity: 1;
  background: rgba(255, 255, 255, 0.15);
  outline: none;
}

.tp-v2 .modal-header .btn-close {
  margin: 0;
  opacity: 0.9;
}

.tp-v2 .modal-header .btn-close:hover {
  opacity: 1;
}

.tp-v2 .modal-body {
  padding: 1.25rem;
  color: var(--tp-text);
  max-height: calc(100vh - 12rem);
  overflow-y: auto;
}

.tp-v2 .modal-body.modal-bodyheight,
.tp-v2 .modal-bodyheight {
  max-height: calc(100vh - 10rem);
  overflow-y: auto;
}

.tp-v2 .modal-body p:last-child {
  margin-bottom: 0;
}

.tp-v2 .modal-body .form-group {
  margin-bottom: 1rem;
}

.tp-v2 .modal-body .form-group:last-child {
  margin-bottom: 0;
}

.tp-v2 .modal-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.875rem 1.25rem;
  background: var(--tp-surface);
  border-top: 1px solid var(--tp-border);
}

.tp-v2 .modal-footer::before,
.tp-v2 .modal-footer::after {
  display: none;
}

/* Legacy footer buttons */
.tp-v2 .modal-footer .btn {
  min-height: 40px;
  padding: 0.45rem 1rem;
  border-radius: 8px;
  font-weight: 500;
  font-size: 0.875rem;
}

.tp-v2 .modal-footer .btn-primary {
  background: var(--tp-primary);
  border-color: var(--tp-primary);
  color: #fff;
}

.tp-v2 .modal-footer .btn-primary:hover,
.tp-v2 .modal-footer .btn-primary:focus {
  background: var(--tp-primary-dark);
  border-color: var(--tp-primary-dark);
  color: #fff;
}

.tp-v2 .modal-footer .btn-default,
.tp-v2 .modal-footer .btn-secondary {
  background: var(--tp-card);
  border: 1px solid var(--tp-border);
  color: var(--tp-text);
}

.tp-v2 .modal-footer .btn-default:hover,
.tp-v2 .modal-footer .btn-secondary:hover {
  background: var(--tp-surface);
  border-color: #cbd5e1;
  color: var(--tp-text);
}

.tp-v2 .modal-footer .btn-danger {
  background: var(--tp-danger);
  border-color: var(--tp-danger);
  color: #fff;
}

.tp-v2 .modal-footer .btn-warning {
  background: #D97706;
  border-color: #D97706;
  color: #fff;
}

.tp-v2 .modal-footer .btn-success {
  background: var(--tp-success);
  border-color: var(--tp-success);
  color: #fff;
}

.tp-v2 .modal-footer .tp-btn {
  min-height: 40px;
}

/* Success / info-only modals without header */
.tp-v2 .modal-content > .modal-body.text-center {
  padding: 2rem 1.5rem;
}

/* Loading overlay modal */
.tp-v2 #loadMe .modal-content,
.tp-v2 .modal.tp-modal-loading .modal-content {
  background: transparent;
  border: none;
  box-shadow: none;
}

.tp-v2 #loadMe .tp-loader,
.tp-v2 .modal.tp-modal-loading .tp-loader {
  padding: 2rem;
}

/* Radio / checkbox groups in modals */
.tp-v2 .modal-body .icheck-success,
.tp-v2 .modal-body .radio-inline,
.tp-v2 .modal-body .checkbox-inline {
  display: block;
  margin-bottom: 0.65rem;
}

.tp-v2 .modal-body .icheck-success:last-child {
  margin-bottom: 0;
}

/* jQuery UI autocomplete inside V2 modals (New Charge device code, etc.) */
.tp-v2 .ui-autocomplete {
  position: absolute;
  z-index: 2060 !important;
  max-height: 220px;
  max-width: min(400px, calc(100vw - 2rem));
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0;
  margin: 0;
  list-style: none;
  background-color: var(--tp-card, #fff);
  border: 1px solid var(--tp-border, #ced4da);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.15);
}

.tp-v2 .ui-autocomplete > li {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--tp-border, #e2e8f0);
  font-size: 0.875rem;
  cursor: pointer;
}

.tp-v2 .ui-autocomplete > li:last-child {
  border-bottom: 0;
}

.tp-v2 .ui-autocomplete > li.ui-state-active,
.tp-v2 .ui-autocomplete > li.ui-state-focus,
.tp-v2 .ui-autocomplete > li:hover {
  background-color: rgba(13, 148, 136, 0.1);
  color: var(--tp-text, #0f172a);
}

.tp-v2 .ui-helper-hidden-accessible {
  display: none;
}

/* DevExpress editors/dropdowns inside modals */
.tp-v2 .modal .dxeButtonEditSys,
.tp-v2 .modal .dxeTextBoxSys,
.tp-v2 .modal table.dxeButtonEditSys {
  max-width: 100% !important;
  width: 100% !important;
}

.tp-v2 .dxpc-mainDiv,
.tp-v2 .dxeDropDownWindow_MaterialCompact,
.tp-v2 .dxpcLite_MaterialCompact {
  z-index: 2060 !important;
}

.tp-v2 #NewMaterialModel .modal-dialog,
.tp-v2 #NewDeviceCodeModel .modal-dialog {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 2.5rem);
  margin: 1.25rem auto;
}

.tp-v2 #NewMaterialModel .modal-content,
.tp-v2 #NewDeviceCodeModel .modal-content {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 2.5rem);
  overflow: hidden;
  position: relative;
}

.tp-v2 #NewMaterialModel .modal-body,
.tp-v2 #NewDeviceCodeModel .modal-body {
  flex: 1 1 auto;
  overflow-y: auto !important;
  overflow-x: hidden;
  min-height: 0;
  max-height: none;
  -webkit-overflow-scrolling: touch;
}

.tp-v2 #NewMaterialModel .modal-footer,
.tp-v2 #NewDeviceCodeModel .modal-footer {
  flex-shrink: 0;
  position: relative;
  z-index: 2;
  background: var(--tp-card, #fff);
}

.tp-v2 #NewMaterialModel .modal-content > .loader,
.tp-v2 #NewDeviceCodeModel .modal-content > .loader {
  position: absolute;
  left: 0;
  right: 0;
  top: 3.75rem;
  bottom: 3.75rem;
  z-index: 5;
  margin: 0;
  padding: 0;
  background: rgba(255, 255, 255, 0.88);
  pointer-events: none;
}

.tp-v2 #NewMaterialModel .modal-content > .loader.is-visible,
.tp-v2 #NewDeviceCodeModel .modal-content > .loader.is-visible {
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
}

/* Device Details + Load Assembly: fixed modal height; grids use explicit pixel height via JS */
.tp-v2 #DeviceDetail .modal-dialog,
.tp-v2 #KitDetail .modal-dialog {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 2.5rem);
  max-height: calc(100vh - 2.5rem);
  margin: 1.25rem auto;
  max-width: min(1100px, calc(100vw - 2rem));
}

.tp-v2 #DeviceDetail .modal-content,
.tp-v2 #KitDetail .modal-content {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
  position: relative;
}

.tp-v2 #DeviceDetail .modal-header,
.tp-v2 #DeviceDetail .modal-footer,
.tp-v2 #KitDetail .modal-header,
.tp-v2 #KitDetail .modal-footer {
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}

.tp-v2 #DeviceDetail .modal-footer,
.tp-v2 #KitDetail .modal-footer {
  background: var(--tp-card, #fff);
}

.tp-v2 #DeviceDetail .modal-body,
.tp-v2 #KitDetail .modal-body {
  display: flex !important;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  max-height: none !important;
  overflow: hidden !important;
  -webkit-overflow-scrolling: touch;
  padding: 0.75rem;
}

.tp-v2 #DeviceDetail .modal-content > .loader,
.tp-v2 #KitDetail .modal-content > .loader {
  position: absolute;
  left: 0;
  right: 0;
  top: 3.75rem;
  bottom: 3.75rem;
  z-index: 5;
  margin: 0;
  padding: 0;
  background: rgba(255, 255, 255, 0.88);
  pointer-events: none;
}

.tp-v2 #DeviceDetail .modal-content > .loader.is-visible,
.tp-v2 #KitDetail .modal-content > .loader.is-visible {
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
}

.tp-v2 #DeviceDetail .tp-device-list-toolbar {
  flex-shrink: 0;
  margin-bottom: 0.65rem;
}

.tp-v2 #DeviceDetail .tp-device-list-grid,
.tp-v2 #KitDetail .tp-kit-list-grid {
  flex: 1 1 auto;
  width: 100%;
  min-height: 280px;
  height: auto;
  max-width: 100%;
  position: relative;
  overflow: hidden;
}

.tp-v2 #DeviceDetail .tp-device-list-grid .dx-datagrid,
.tp-v2 #KitDetail .tp-kit-list-grid .dx-datagrid {
  width: 100%;
  max-width: 100%;
  border-radius: 0;
}

.tp-v2 #DeviceDetail .dx-datagrid-rowsview,
.tp-v2 #KitDetail .dx-datagrid-rowsview {
  min-height: 160px;
}

/*
 * Max 3 lines on Device Details.
 * WordWrap cells often have raw text in <td> (no .dx-datagrid-text-content), so JS
 * wraps content in .tp-device-cell-clamp. Adaptive/command cells are left alone.
 */
.tp-v2 #DeviceDetail .tp-device-list-grid .dx-datagrid-rowsview .dx-data-row > td:not(.dx-command-adaptive):not(.dx-command-select):not(.dx-command-expand) {
  vertical-align: top !important;
  overflow: hidden !important;
  box-sizing: border-box;
}

.tp-v2 #DeviceDetail .tp-device-list-grid .tp-device-cell-clamp,
.tp-v2 #DeviceDetail .tp-device-list-grid .dx-datagrid-rowsview .dx-data-row > td .dx-datagrid-text-content.tp-device-cell-clamp {
  display: -webkit-box !important;
  -webkit-box-orient: vertical !important;
  -webkit-line-clamp: 3 !important;
  line-clamp: 3 !important;
  overflow: hidden !important;
  white-space: normal !important;
  word-break: break-word;
  line-height: 1.35;
  max-height: calc(1.35em * 3);
  width: 100%;
  box-sizing: border-box;
}

/* jQuery UI autocomplete inside V2 modals (New Charge device code, etc.) */
.tp-v2 .modal .form-panel .form-group,
.tp-v2 form.form-horizontal .modal .form-group {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  width: 100%;
}

.tp-v2 .modal .form-panel .form-group > [class*="col-sm-"],
.tp-v2 .modal .form-panel .form-group > [class*="col-lg-"],
.tp-v2 .modal .form-panel .form-group > label[class*="col-"],
.tp-v2 form.form-horizontal .modal .form-group > [class*="col-sm-"],
.tp-v2 form.form-horizontal .modal .form-group > [class*="col-lg-"],
.tp-v2 form.form-horizontal .modal .form-group > label[class*="col-"] {
  padding-left: 12px;
  padding-right: 12px;
  box-sizing: border-box;
  min-width: 0;
}

.tp-v2 .modal .form-panel .form-group > .smalllabel {
  flex: 0 0 10%;
  max-width: 10%;
}

.tp-v2 .modal .form-panel .form-group > .smalllabel12 {
  flex: 0 0 12%;
  max-width: 12%;
}

.tp-v2 .modal .form-panel .form-group .form-control,
.tp-v2 .modal .form-panel .form-group select.form-control,
.tp-v2 .modal .form-panel .form-group textarea.form-control {
  width: 100%;
}

.tp-v2 .modal .form-panel .form-group input[type="checkbox"] {
  margin-top: 0.45rem;
}

.tp-v2 .modal .tp-master-data-form .form-group {
  display: block;
}

.tp-v2 .modal .tp-master-data-form .form-group > label {
  display: block;
  margin-bottom: 0.5rem;
  max-width: none;
}

.tp-v2 .modal .tp-master-data-form .form-control {
  width: 100%;
}

@media (min-width: 576px) {
  .tp-v2 .modal .form-panel .form-group > .col-sm-1,
  .tp-v2 form.form-horizontal .modal .form-group > .col-sm-1 { flex: 0 0 8.333333%; max-width: 8.333333%; }

  .tp-v2 .modal .form-panel .form-group > .col-sm-2,
  .tp-v2 form.form-horizontal .modal .form-group > .col-sm-2 { flex: 0 0 16.666667%; max-width: 16.666667%; }

  .tp-v2 .modal .form-panel .form-group > .col-sm-3,
  .tp-v2 form.form-horizontal .modal .form-group > .col-sm-3 { flex: 0 0 25%; max-width: 25%; }

  .tp-v2 .modal .form-panel .form-group > .col-sm-4,
  .tp-v2 form.form-horizontal .modal .form-group > .col-sm-4 { flex: 0 0 33.333333%; max-width: 33.333333%; }

  .tp-v2 .modal .form-panel .form-group > .col-sm-5,
  .tp-v2 form.form-horizontal .modal .form-group > .col-sm-5 { flex: 0 0 41.666667%; max-width: 41.666667%; }

  .tp-v2 .modal .form-panel .form-group > .col-sm-6,
  .tp-v2 form.form-horizontal .modal .form-group > .col-sm-6 { flex: 0 0 50%; max-width: 50%; }

  .tp-v2 .modal .form-panel .form-group > .col-sm-7,
  .tp-v2 form.form-horizontal .modal .form-group > .col-sm-7 { flex: 0 0 58.333333%; max-width: 58.333333%; }

  .tp-v2 .modal .form-panel .form-group > .col-sm-8,
  .tp-v2 form.form-horizontal .modal .form-group > .col-sm-8 { flex: 0 0 66.666667%; max-width: 66.666667%; }

  .tp-v2 .modal .form-panel .form-group > .col-sm-9,
  .tp-v2 form.form-horizontal .modal .form-group > .col-sm-9 { flex: 0 0 75%; max-width: 75%; }

  .tp-v2 .modal .form-panel .form-group > .col-sm-10,
  .tp-v2 form.form-horizontal .modal .form-group > .col-sm-10 { flex: 0 0 83.333333%; max-width: 83.333333%; }

  .tp-v2 .modal .form-panel .form-group > .col-sm-11,
  .tp-v2 form.form-horizontal .modal .form-group > .col-sm-11 { flex: 0 0 91.666667%; max-width: 91.666667%; }

  .tp-v2 .modal .form-panel .form-group > .col-sm-12,
  .tp-v2 form.form-horizontal .modal .form-group > .col-sm-12 { flex: 0 0 100%; max-width: 100%; }
}

@media (max-width: 575.98px) {
  .tp-v2 .modal .form-panel .form-group > [class*="col-sm-"],
  .tp-v2 form.form-horizontal .modal .form-group > [class*="col-sm-"],
  .tp-v2 .modal .form-panel .form-group > .smalllabel,
  .tp-v2 .modal .form-panel .form-group > .smalllabel12 {
    flex: 0 0 100%;
    max-width: 100%;
    padding-left: 0;
    padding-right: 0;
  }

  /* New Charge / device modals: tighter padding, keep controls aligned */
  .tp-v2 #NewMaterialModel .modal-body,
  .tp-v2 #NewDeviceCodeModel .modal-body {
    padding: 0.75rem;
  }

  .tp-v2 #NewMaterialModel .form-panel,
  .tp-v2 #NewDeviceCodeModel .form-panel {
    margin: 0 0 0.75rem !important;
    padding: 0 !important;
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
    border-radius: 0 !important;
  }

  .tp-v2 #NewMaterialModel .form-panel:last-child,
  .tp-v2 #NewDeviceCodeModel .form-panel:last-child {
    margin-bottom: 0 !important;
  }

  .tp-v2 #NewMaterialModel .form-panel > h4.mb,
  .tp-v2 #NewDeviceCodeModel .form-panel > h4.mb {
    margin: 0 0 0.65rem !important;
    padding: 0.5rem 0 !important;
    border-radius: 0 !important;
  }

  .tp-v2 #NewMaterialModel .form-group,
  .tp-v2 #NewDeviceCodeModel .form-group,
  .tp-v2 #NewMaterialModel .form-panel .form-group,
  .tp-v2 #NewDeviceCodeModel .form-panel .form-group {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    margin-left: 0;
    margin-right: 0;
    margin-bottom: 0.35rem;
    width: 100%;
    gap: 0;
  }

  .tp-v2 #NewMaterialModel .form-group > label.control-label,
  .tp-v2 #NewMaterialModel .form-group > label.control-label-sup,
  .tp-v2 #NewDeviceCodeModel .form-group > label.control-label,
  .tp-v2 #NewDeviceCodeModel .form-group > label.control-label-sup {
    flex: 0 0 100%;
    max-width: 100%;
    text-align: left !important;
    margin: 0.45rem 0 0.2rem !important;
    padding: 0 !important;
    float: none !important;
    width: 100% !important;
    line-height: 1.3;
  }

  .tp-v2 #NewMaterialModel .form-group > [class*="col-sm-"],
  .tp-v2 #NewDeviceCodeModel .form-group > [class*="col-sm-"] {
    flex: 0 0 100%;
    max-width: 100%;
    width: 100%;
    margin-bottom: 0.15rem;
  }

  /* Keep checkbox beside its label on one row */
  .tp-v2 #NewMaterialModel .form-group > label.control-label:has(+ [class*="col-"] > input[type="checkbox"]) {
    flex: 1 1 auto;
    width: auto !important;
    max-width: calc(100% - 2.75rem);
    margin: 0.35rem 0 !important;
    min-height: 2.5rem;
    display: flex;
    align-items: center;
  }

  .tp-v2 #NewMaterialModel .form-group > label.control-label + [class*="col-"]:has(> input[type="checkbox"]) {
    flex: 0 0 2.5rem;
    width: 2.5rem !important;
    max-width: 2.5rem;
    min-height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    margin: 0.35rem 0;
  }

  .tp-v2 #NewMaterialModel .form-group input[type="checkbox"] {
    margin: 0 !important;
    width: 1.15rem;
    height: 1.15rem;
    flex-shrink: 0;
  }

  /* Description label + Load stay on one row */
  .tp-v2 #NewMaterialModel .form-group > [class*="col-"][style*="display:flex"],
  .tp-v2 #NewMaterialModel .form-group > [class*="col-"]:has(> label.control-label):has(> .btn) {
    display: flex !important;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.45rem;
  }

  .tp-v2 #NewMaterialModel .form-group > [class*="col-"]:has(> label.control-label):has(> .btn) > label.control-label {
    flex: 0 0 auto;
    width: auto !important;
    max-width: none;
    margin: 0 !important;
  }

  .tp-v2 #NewMaterialModel .form-group .form-control,
  .tp-v2 #NewMaterialModel .form-group select.form-control,
  .tp-v2 #NewMaterialModel .form-group textarea.form-control,
  .tp-v2 #NewDeviceCodeModel .form-group .form-control,
  .tp-v2 #NewDeviceCodeModel .form-group select.form-control,
  .tp-v2 #NewDeviceCodeModel .form-group textarea.form-control {
    width: 100%;
    max-width: 100%;
  }

  /* Date picker: keep calendar addon beside the input (BS3 table layout) */
  .tp-v2 #NewMaterialModel .form-group .input-group.date,
  .tp-v2 #NewDeviceCodeModel .form-group .input-group.date {
    display: table !important;
    width: 100%;
    border-collapse: separate;
  }

  .tp-v2 #NewMaterialModel .form-group .input-group.date > .form-control,
  .tp-v2 #NewDeviceCodeModel .form-group .input-group.date > .form-control {
    display: table-cell;
    width: 100%;
    float: none;
  }

  .tp-v2 #NewMaterialModel .form-group .input-group.date > .input-group-addon,
  .tp-v2 #NewDeviceCodeModel .form-group .input-group.date > .input-group-addon {
    display: table-cell;
    width: 1%;
    white-space: nowrap;
    vertical-align: middle;
    padding: 0.45rem 0.75rem;
  }

  .tp-v2 #NewMaterialModel .modal-footer,
  .tp-v2 #NewDeviceCodeModel .modal-footer {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }
}

/* New Charge: read-only amounts align with form-control text */
.tp-v2 #NewMaterialModel .tp-amount-display,
.tp-v2 #NewMaterialModel #lblTotalMaterialCost,
.tp-v2 #NewMaterialModel #TotalDiscountedPrice,
.tp-v2 #NewMaterialModel #NewTotalCost {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 38px;
  margin: 0;
  padding: 0.45rem 0.75rem;
  float: none;
  border: 1px solid var(--tp-border, #e2e8f0);
  border-radius: 8px;
  background: var(--tp-surface, #f8fafc);
  color: var(--tp-text, #1e293b);
  font-weight: 600;
  font-size: 0.9375rem;
  line-height: 1.4;
  text-align: left;
  box-sizing: border-box;
}

@media (max-width: 575.98px) {
  .tp-v2 #NewMaterialModel .tp-amount-display,
  .tp-v2 #NewMaterialModel #lblTotalMaterialCost,
  .tp-v2 #NewMaterialModel #TotalDiscountedPrice,
  .tp-v2 #NewMaterialModel #NewTotalCost {
    min-height: 42px;
    padding: 0.5rem 0.75rem;
  }
}

@media (max-width: 575px) {
  .tp-v2 .modal-dialog {
    margin: 0.75rem auto;
    max-width: calc(100% - 1.5rem);
  }

  .tp-v2 #NewMaterialModel .modal-dialog,
  .tp-v2 #NewDeviceCodeModel .modal-dialog {
    max-height: calc(100vh - 1rem);
    margin: 0.5rem auto;
  }

  .tp-v2 #NewMaterialModel .modal-content,
  .tp-v2 #NewDeviceCodeModel .modal-content {
    max-height: calc(100vh - 1rem);
  }

  .tp-v2 #DeviceDetail .modal-dialog,
  .tp-v2 #KitDetail .modal-dialog {
    height: calc(100vh - 1rem);
    max-height: calc(100vh - 1rem);
    margin: 0.5rem auto;
    max-width: calc(100vw - 1rem);
  }

  .tp-v2 #DeviceDetail .modal-content,
  .tp-v2 #KitDetail .modal-content {
    height: 100%;
    max-height: 100%;
  }

  .tp-v2 #DeviceDetail .modal-body,
  .tp-v2 #KitDetail .modal-body {
    padding: 0.65rem 0.75rem !important;
    max-height: none !important;
    overflow: hidden !important;
  }

  .tp-v2 #DeviceDetail .modal-footer,
  .tp-v2 #KitDetail .modal-footer {
    padding: 0.75rem;
  }

  .tp-v2 #DeviceDetail .modal-footer .btn,
  .tp-v2 #KitDetail .modal-footer .btn {
    flex: 1 1 auto;
    min-height: 44px;
  }

  .tp-v2 .modal-header {
    padding: 0.875rem 1rem;
  }

  .tp-v2 .modal-body {
    padding: 1rem;
    max-height: calc(100vh - 9rem);
  }

  .tp-v2 .modal-footer {
    padding: 0.75rem 1rem;
    justify-content: stretch;
  }

  .tp-v2 .modal-footer .btn,
  .tp-v2 .modal-footer .tp-btn {
    flex: 1 1 auto;
  }
}

/* Create Appointment modal - datetime picker must escape clipped modal body */
.tp-v2 #createappointment .modal-dialog {
  max-width: min(640px, calc(100% - 2rem));
}

.tp-v2 #createappointment .modal-content {
  overflow: visible;
}

.tp-v2 #createappointment .modal-body.tp-create-appointment-modal {
  overflow: visible;
  max-height: none;
  position: relative;
}

.tp-v2 #createappointment .tp-create-appointment-form .form-group,
.tp-v2 #createappointment .form-panel .form-group {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.tp-v2 #createappointment .tp-create-appointment-form .form-group > label.control-label,
.tp-v2 #createappointment .form-panel .form-group > label.control-label {
  margin-bottom: 0;
}

@media (min-width: 576px) {
  .tp-v2 #createappointment .tp-create-appointment-form .form-group > label.col-sm-3,
  .tp-v2 #createappointment .tp-create-appointment-form .form-group > .col-sm-3 {
    flex: 0 0 25%;
    max-width: 25%;
  }

  .tp-v2 #createappointment .tp-create-appointment-form .form-group > .col-sm-9 {
    flex: 0 0 75%;
    max-width: 75%;
  }

  .tp-v2 #createappointment .form-panel .form-group > label.col-sm-4,
  .tp-v2 #createappointment .form-panel .form-group > .col-sm-4 {
    flex: 0 0 33.333333%;
    max-width: 33.333333%;
  }

  .tp-v2 #createappointment .form-panel .form-group > .col-sm-7 {
    flex: 0 0 58.333333%;
    max-width: 58.333333%;
  }
}

.tp-v2 #createappointment .tp-create-appointment-form .form-control,
.tp-v2 #createappointment .tp-create-appointment-form select.form-control,
.tp-v2 #createappointment .form-panel .form-control,
.tp-v2 #createappointment .form-panel select.form-control {
  width: 100%;
  min-height: 38px;
  font-size: 0.875rem;
}

@media (max-width: 767.98px) {
  .tp-v2 #createappointment .tp-create-appointment-form .form-group,
  .tp-v2 #createappointment .form-panel .form-group {
    flex-direction: column;
    align-items: stretch;
  }

  .tp-v2 #createappointment .tp-create-appointment-form .form-group > label.control-label,
  .tp-v2 #createappointment .form-panel .form-group > label.control-label {
    margin-bottom: 0.25rem;
    padding-top: 0;
  }

  .tp-v2 #createappointment .tp-create-appointment-form .form-control,
  .tp-v2 #createappointment .tp-create-appointment-form select.form-control,
  .tp-v2 #createappointment .form-panel .form-control,
  .tp-v2 #createappointment .form-panel select.form-control {
    font-size: 16px;
  }
}

.tp-v2 #createappointment .tp-create-appointment-form .input-group.date,
.tp-v2 #createappointment .form-panel .input-group.date {
  width: 100%;
}

.tp-v2 #createappointment .tp-notification-row > .col-sm-7 {
  display: flex;
  align-items: center;
}

.tp-v2 #createappointment .has-switch {
  margin-bottom: 0;
}

.tp-v2 #createappointment #divSendCustomerNoti .textareawidth {
  min-height: 0;
  width: 100%;
  overflow-y: auto;
  resize: vertical;
}

.tp-v2 #createappointment .bootstrap-datetimepicker-widget {
  z-index: 2050 !important;
  position: absolute !important;
}

/* BS5 hides .dropdown-menu without .show; datetimepicker adds top/bottom when open */
.tp-v2 .bootstrap-datetimepicker-widget.dropdown-menu.top,
.tp-v2 .bootstrap-datetimepicker-widget.dropdown-menu.bottom {
  display: block !important;
}

/* Preview Test Result modal */
.tp-v2 #TestResultModel .modal-dialog {
  max-width: min(960px, calc(100% - 2rem));
}

.tp-v2 #TestResultModel #divTestResult {
  height: auto !important;
  max-height: calc(100vh - 14rem);
}

.tp-v2 #TestResultModel #divTestResult .testresult-heading {
  display: block;
  height: auto !important;
  padding: 0.5rem 0 0.25rem;
  margin: 0.75rem 0 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--tp-primary-dark);
}

.tp-v2 #TestResultModel #divTestResult .testresult-heading h4 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--tp-primary-dark);
}

.tp-v2 #TestResultModel #divTestResult .testresult-heading .fa-angle-right {
  display: none;
}

.tp-v2 #TestResultModel #divTestResult .form-panel {
  margin-bottom: 0.75rem;
}

.tp-v2 #TestResultModel #divTestResult .form-panel .form-group {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  margin-bottom: 0.75rem;
}

.tp-v2 #TestResultModel #divTestResult .form-panel .form-group > [class*="col-sm-"] {
  float: none;
}

.tp-v2 #TestResultModel #divTestResult .checkall {
  float: none;
  display: block;
  padding: 0 0 0.5rem;
  margin-bottom: 0.5rem;
}

/* Installation List modal */
.tp-v2 #InstallationModel .modal-dialog {
  display: flex;
  flex-direction: column;
  max-width: min(1100px, calc(100% - 2rem));
  max-height: calc(100vh - 2.5rem);
  margin: 1.25rem auto;
}

.tp-v2 #InstallationModel .modal-content {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 2.5rem);
  overflow: hidden;
}

.tp-v2 #InstallationModel .modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.tp-v2 #InstallationModel .modal-footer {
  flex-shrink: 0;
}

.tp-v2 #InstallationModel #filter,
.tp-v2 #InstallationModel #btnSearch,
.tp-v2 #InstallationModel #btnClear {
  margin-bottom: 0.75rem;
  margin-right: 0.35rem;
}

.tp-v2 #InstallationModel .tp-install-list-scroll,
.tp-v2 #InstallationModel #no-more-tables {
  max-width: 100%;
}

.tp-v2 #InstallationModel .tp-install-list-table,
.tp-v2 #InstallationModel #no-more-tables .table {
  width: 100%;
  table-layout: auto;
  font-size: 0.8125rem;
  margin-bottom: 0;
}

.tp-v2 #InstallationModel .tp-install-list-table thead th,
.tp-v2 #InstallationModel #no-more-tables .table thead th {
  font-size: 0.75rem;
  white-space: nowrap;
  padding: 0.35rem 0.5rem;
  vertical-align: middle;
}

.tp-v2 #InstallationModel .tp-install-list-table td,
.tp-v2 #InstallationModel #no-more-tables .table td {
  font-size: 0.8125rem;
  padding: 0.35rem 0.5rem;
  vertical-align: top;
  line-height: 1.35;
}

@media only screen and (min-width: 801px) {
  .tp-v2 #InstallationModel .tp-install-list-table td[data-title="Action"],
  .tp-v2 #InstallationModel .tp-install-list-table td[data-title="Install Ref"],
  .tp-v2 #InstallationModel .tp-install-list-table td[data-title="Contract Start"],
  .tp-v2 #InstallationModel .tp-install-list-table td[data-title="Contract End"],
  .tp-v2 #InstallationModel .tp-install-list-table td[data-title="Last Check"],
  .tp-v2 #InstallationModel .tp-install-list-table td[data-title="Next Check"] {
    white-space: nowrap;
    vertical-align: middle;
  }
}

.tp-v2 #InstallationModel .tp-install-clamp {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
  white-space: normal;
  word-break: break-word;
  line-height: 1.35;
  max-width: 12rem;
}

.tp-v2 #InstallationModel .tp-install-list-table td[data-title="Address"] .tp-install-clamp {
  max-width: 14rem;
}

.tp-v2 #InstallationModel .selectInstallation.btn-xs {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.75rem;
  min-height: 1.75rem;
  padding: 0.15rem 0.35rem;
  line-height: 1;
}

.tp-v2 #InstallationModel .selectInstallation.btn-xs .fa-check {
  font-size: 0.875rem;
  color: #fff;
  opacity: 1;
}

/* Match legacy no-more-tables stacked cards on phone/tablet */
@media only screen and (max-width: 800px) {
  .tp-v2 #InstallationModel .modal-dialog {
    max-width: calc(100% - 1rem);
    max-height: calc(100vh - 1rem);
    margin: 0.5rem auto;
  }

  .tp-v2 #InstallationModel .modal-content {
    max-height: calc(100vh - 1rem);
  }

  .tp-v2 #InstallationModel .modal-body {
    padding: 0.75rem;
  }

  .tp-v2 #InstallationModel > .modal-dialog > .modal-content > .modal-body > div > div:first-child,
  .tp-v2 #InstallationModel #divInstallList > div:first-child {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.75rem;
  }

  .tp-v2 #InstallationModel #filter {
    flex: 1 1 10rem;
    min-width: 0;
    margin: 0 !important;
    min-height: 40px;
  }

  .tp-v2 #InstallationModel #btnSearch,
  .tp-v2 #InstallationModel #btnClear {
    margin: 0 !important;
    min-height: 40px;
    padding: 0.35rem 0.85rem;
  }

  .tp-v2 #InstallationModel .tp-install-list-scroll,
  .tp-v2 #InstallationModel #no-more-tables {
    overflow: visible;
    width: 100%;
    max-width: 100%;
  }

  /*
   * Higher specificity than base `.table td` padding rules (those were winning on
   * mobile and wiped the 42% left padding, so labels overlapped values).
   */
  .tp-v2 #InstallationModel #no-more-tables table.table,
  .tp-v2 #InstallationModel #no-more-tables table.tp-install-list-table,
  .tp-v2 #InstallationModel #no-more-tables thead,
  .tp-v2 #InstallationModel #no-more-tables tbody,
  .tp-v2 #InstallationModel #no-more-tables th,
  .tp-v2 #InstallationModel #no-more-tables td,
  .tp-v2 #InstallationModel #no-more-tables tr {
    display: block !important;
    width: 100% !important;
    max-width: 100%;
    box-sizing: border-box;
  }

  .tp-v2 #InstallationModel #no-more-tables thead tr {
    position: absolute !important;
    top: -9999px;
    left: -9999px;
    height: 0;
    overflow: hidden;
  }

  .tp-v2 #InstallationModel #no-more-tables tbody tr {
    margin-bottom: 0.75rem;
    border: 1px solid var(--tp-border, #e2e8f0) !important;
    border-radius: 10px;
    background: var(--tp-card, #fff);
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  }

  .tp-v2 #InstallationModel #no-more-tables table.table td,
  .tp-v2 #InstallationModel #no-more-tables table.tp-install-list-table td,
  .tp-v2 #InstallationModel #no-more-tables .table td {
    border: none !important;
    border-bottom: 1px solid var(--tp-border, #e2e8f0) !important;
    position: relative !important;
    /* Label above value - avoids overlap with desktop padding overrides */
    padding: 0.45rem 0.75rem 0.55rem !important;
    white-space: normal !important;
    text-align: left !important;
    vertical-align: top !important;
    min-height: 0 !important;
    height: auto !important;
    line-height: 1.4 !important;
  }

  .tp-v2 #InstallationModel #no-more-tables table.table td:last-child,
  .tp-v2 #InstallationModel #no-more-tables table.tp-install-list-table td:last-child,
  .tp-v2 #InstallationModel #no-more-tables .table td:last-child {
    border-bottom: none !important;
  }

  .tp-v2 #InstallationModel #no-more-tables table.table td:before,
  .tp-v2 #InstallationModel #no-more-tables table.tp-install-list-table td:before,
  .tp-v2 #InstallationModel #no-more-tables .table td:before {
    content: attr(data-title);
    display: block !important;
    position: static !important;
    width: auto !important;
    max-width: none !important;
    margin: 0 0 0.2rem !important;
    padding: 0 !important;
    white-space: normal;
    text-align: left;
    font-weight: 600;
    color: var(--tp-text-muted, #64748b);
    font-size: 0.75rem;
    line-height: 1.3;
  }

  .tp-v2 #InstallationModel #no-more-tables td[data-title="Action"] {
    display: flex !important;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
  }

  .tp-v2 #InstallationModel #no-more-tables td[data-title="Action"]:before {
    flex: 0 0 100%;
    margin-bottom: 0.15rem !important;
  }

  .tp-v2 #InstallationModel .tp-install-clamp,
  .tp-v2 #InstallationModel .tp-install-list-table td[data-title="Address"] .tp-install-clamp,
  .tp-v2 #InstallationModel #no-more-tables .tp-install-clamp {
    display: block !important;
    -webkit-line-clamp: unset !important;
    line-clamp: unset !important;
    max-width: none !important;
    overflow: visible !important;
    white-space: normal !important;
    word-break: break-word;
  }

  .tp-v2 #InstallationModel .selectInstallation.btn-xs {
    min-width: 2.25rem;
    min-height: 2.25rem;
  }

  .tp-v2 #InstallationModel .modal-footer {
    padding: 0.75rem;
  }

  .tp-v2 #InstallationModel .modal-footer .btn {
    width: 100%;
    min-height: 44px;
  }
}

/* Desktop/wide: allow horizontal scroll so all columns remain available */
@media only screen and (min-width: 801px) {
  .tp-v2 #InstallationModel .tp-install-list-scroll,
  .tp-v2 #InstallationModel #no-more-tables {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .tp-v2 #InstallationModel .tp-install-list-table,
  .tp-v2 #InstallationModel #no-more-tables .table {
    width: max-content;
    min-width: 100%;
  }
}
