/*
 * TOP1 UI safety layer — small post-app guards.
 * No visual redesign; only reduces common overflow/clipping regressions.
 */
.top1-app,
.top1-shell,
.top1-main,
.top1-page,
.top1-content,
.top1-card,
.top1-panel,
.top1-client-card,
.top1rd-card {
  min-width: 0;
  max-width: 100%;
}

.top1-app table,
.top1-shell table,
.top1-page table,
.top1rd-card table {
  max-width: 100%;
}

.top1-table-scroll,
.top1-scroll-x,
.top1rd-table-wrap {
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  -webkit-overflow-scrolling: touch;
}

.top1-card,
.top1-panel,
.top1-client-card,
.top1rd-card {
  overflow-wrap: anywhere;
}

.top1-overlay-root,
.top1-popover-layer,
.top1-dialog-layer {
  isolation: isolate;
}

@media (max-width: 767px) {
  .top1-app,
  .top1-shell,
  .top1-main,
  .top1-page {
    width: 100%;
  }

  .top1-card,
  .top1-panel,
  .top1-client-card,
  .top1rd-card {
    max-width: calc(100dvw - 16px);
  }
}

/* Iteration 04: diagnostics device lifecycle controls stay usable on narrow screens. */
.top1-diagnostics-mobile-device-list,
.top1-diagnostics-mobile-device,
.top1-diagnostics-device-control-panel,
.top1-diagnostics-device-actions,
.top1-diagnostics-device-note-form,
.top1-diagnostics-device-history {
  min-width: 0;
  max-width: 100%;
}

.top1-diagnostics-device-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--top1-control-gap, 8px);
  align-items: center;
}

.top1-diagnostics-device-action-form {
  min-width: 0;
}

.top1-diagnostics-device-action-button {
  min-height: var(--top1-control-min-height, 44px);
  white-space: normal;
}

.top1-diagnostics-device-note-form textarea {
  width: 100%;
  max-width: 100%;
  resize: vertical;
}

@media (max-width: 640px) {
  .top1-diagnostics-device-actions,
  .top1-diagnostics-row-actions {
    align-items: stretch;
  }

  .top1-diagnostics-device-action-form,
  .top1-diagnostics-device-action-button,
  .top1-diagnostics-row-actions > a {
    width: 100%;
  }
}

/* Iteration 04: safer overlay/dropdown bounds without increasing cascade priority. */
.top1-dropdown,
.top1-popover,
.top1-menu,
.top1-modal,
.top1-dialog,
.top1-sheet {
  box-sizing: border-box;
}

.top1-dropdown,
.top1-popover,
.top1-menu {
  z-index: var(--top1-z-dropdown, 100);
}

.top1-modal,
.top1-dialog,
.top1-sheet {
  z-index: var(--top1-z-dialog, 600);
}

.top1-dropdown,
.top1-popover,
.top1-menu,
.top1-modal,
.top1-dialog,
.top1-sheet {
  overflow-wrap: anywhere;
}

@media (max-width: 767px) {
  .top1-dropdown,
  .top1-popover,
  .top1-menu,
  .top1-modal,
  .top1-dialog,
  .top1-sheet {
    max-width: calc(100dvw - 16px);
    max-height: var(--top1-dialog-max-height, 86dvh);
  }
}

/* Iteration 06: hard guards for long data and nested action groups. */
.top1-app-shell :where(.top1-vin, .top1-license-plate, .top1-diagnostics-chip, .top1-order-number, code, pre) {
  max-width: 100%;
  overflow-wrap: anywhere;
}

.top1-app-shell :where(pre) {
  overflow: auto;
  white-space: pre-wrap;
}

.top1-app-shell :where(.top1-card-header, .top1-order-detail-head, .top1-diagnostics-overview-head, .top1-planner-head) {
  min-width: 0;
}

.top1-app-shell :where(.top1-card-header > *, .top1-order-detail-head > *, .top1-diagnostics-overview-head > *, .top1-planner-head > *) {
  min-width: 0;
}

.top1-app-shell :where(.top1-scroll-lock, .top1-overlay-open) {
  overscroll-behavior: contain;
}

@media (max-width: 760px) {
  .top1-app-shell :where(.top1-table-row, .top1-data-management-row, .top1-diagnostics-staff-action-row) {
    min-width: min-content;
  }

  .top1-app-shell :where(.top1-order-add-work-form, .top1-order-work-edit-popover-body, .top1-parts-selection-card) {
    max-width: calc(100dvw - 20px);
  }
}
