/* Mobile/tablet compatibility layer for the separate VirtuTMS-Web-Mobile build. */
html {
  min-width: 0;
  overflow-x: hidden;
}

body {
  min-width: 0;
}

button,
input,
select,
textarea,
.native-searchable-toggle {
  touch-action: manipulation;
}

.native-searchable-menu {
  max-width: min(100vw - 24px, 520px);
  z-index: 70000;
}

@media (max-width: 1180px) {
  .app-shell,
  body[data-sidebar-collapsed="true"] .app-shell {
    grid-template-columns: 76px minmax(0, 1fr);
  }

  .brand {
    width: 46px;
  }

  .brand-logo,
  body[data-sidebar-collapsed="true"] .brand-logo {
    width: 184px;
    max-width: none;
    flex: 0 0 184px;
  }

  .nav-item {
    grid-template-columns: 1fr;
    justify-items: center;
    padding: 0;
  }

  .nav-item b,
  .nav-item small,
  .subnav {
    display: none;
  }

  .nav-icon,
  .nav-item i,
  body[data-sidebar-collapsed="true"] .sidebar .nav-icon {
    margin-right: 0;
  }

  body.loads-mode .pagebar {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
  }

  body.loads-mode .top-actions,
  .top-actions {
    justify-self: stretch;
    width: 100%;
    flex-wrap: wrap;
  }
}

@media (max-width: 900px) {
  body {
    height: auto;
    min-height: 100svh;
    overflow: auto;
  }

  .app-shell,
  body[data-sidebar-collapsed="true"] .app-shell {
    min-height: 100svh;
    height: auto;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas:
      "header"
      "sidebar"
      "workspace";
    overflow: visible;
  }

  .app-header {
    position: sticky;
    top: 0;
    z-index: 1200;
    min-height: 54px;
    gap: 8px;
    padding: 8px 12px;
  }

  .brand {
    width: 154px;
    min-width: 154px;
    min-height: 0;
  }

  .brand-logo,
  body[data-sidebar-collapsed="true"] .brand-logo {
    width: 154px;
    height: 42px;
    flex-basis: 154px;
  }

  .brand-copy > span,
  .user-name {
    display: none;
  }

  .sidebar {
    position: sticky;
    top: 54px;
    z-index: 1100;
    min-height: 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    box-shadow: 0 8px 20px rgba(21,39,70,.08);
  }

  #nav {
    display: flex;
    gap: 6px;
    padding: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }

  .nav-item,
  body[data-sidebar-collapsed="true"] .sidebar .nav-item {
    min-width: 56px;
    min-height: 44px;
    flex: 0 0 auto;
    border-radius: 10px;
  }

  .workspace {
    height: auto;
    min-height: 0;
    grid-template-rows: auto auto minmax(0, 1fr);
    overflow: visible;
  }

  .pagebar,
  body.loads-mode .pagebar {
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    padding: 12px;
  }

  .pagebar h1,
  body.loads-mode .pagebar h1 {
    font-size: 21px;
  }

  .pagebar p {
    display: none;
  }

  .top-actions > *,
  body.loads-mode .top-actions > * {
    flex: 1 1 150px;
  }

  .board,
  .content,
  main,
  #workspace,
  #pageBody {
    min-width: 0;
    max-width: 100vw;
  }

  .board > .table-panel,
  .board > .standard-page-grid {
    height: auto;
    min-height: 0;
  }

  .table-wrap {
    border-radius: 10px;
    overflow-x: auto;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 760px;
  }

  th,
  td {
    height: auto;
    min-height: 40px;
    padding: 8px 10px;
    font-size: 12px;
  }

  .table-wrap table.has-actions-column th:last-child,
  .table-wrap table.has-actions-column td:last-child,
  .table-wrap table th.actions-col,
  .table-wrap table td.actions,
  .table-wrap table td.row-actions {
    position: static;
    box-shadow: none;
  }

  .table-pager {
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    padding: 10px 4px;
  }

  .table-pager .pager-size {
    width: 100%;
    margin-left: 0;
    justify-content: center;
    flex-wrap: wrap;
  }

  .table-pager .pager-nav {
    max-width: 100%;
    overflow-x: auto;
    justify-content: flex-start;
    padding-bottom: 2px;
  }

  .primary,
  .secondary,
  .danger,
  .ghost,
  .grid-link {
    max-width: 100%;
  }

  .toolbar,
  .metrics,
  .summary-grid,
  .stat-grid,
  .dashboard-grid,
  .review-main-grid,
  .form-grid,
  .grid,
  [class*="grid"] {
    max-width: 100%;
  }

  .toolbar,
  .filters,
  .filter-row,
  .search,
  .segments {
    flex-wrap: wrap;
  }

  .search,
  .search input,
  .toolbar input,
  .toolbar select,
  .top-actions input,
  .top-actions select,
  .top-actions button {
    min-width: 0;
    width: 100%;
  }

  .drawer {
    align-items: stretch;
    justify-content: stretch;
    padding: 0;
  }

  .drawer article {
    width: 100vw;
    max-height: 100svh;
    min-height: 100svh;
    border-radius: 0;
  }

  #drawerBody {
    padding: 10px;
  }

  .modal {
    align-items: stretch;
    justify-content: stretch;
    padding: 0;
  }

  .modal form,
  .modal article {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100svh !important;
    max-height: 100svh !important;
    border-radius: 0 !important;
  }

  .drawer header,
  .modal header,
  .drawer footer,
  .modal footer {
    padding: 10px 12px;
  }

  .drawer footer,
  .modal footer {
    flex-wrap: wrap;
  }

  .drawer footer button,
  .modal footer button {
    flex: 1 1 130px;
  }

  .modal .table-wrap,
  .drawer .table-wrap {
    max-width: 100%;
  }

  #modalForm[class*="vt-modal--"] .vt-form,
  #modalForm[class*="vt-modal--"] .vt-form section,
  #modalForm[class*="vt-modal--"] .vt-form fieldset,
  #modalForm[class*="vt-modal--"] .vt-form .row,
  #modalForm[class*="vt-modal--"] .vt-form .grid,
  #modalForm[class*="vt-modal--"] .vt-form [class*="grid"],
  #modalForm[class*="vt-modal--"] .vt-form [class*="columns"],
  #modalForm[class*="vt-modal--"] .vt-form [class*="split"] {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  #modalForm[class*="vt-modal--"] .vt-form input,
  #modalForm[class*="vt-modal--"] .vt-form select,
  #modalForm[class*="vt-modal--"] .vt-form textarea,
  .native-searchable-select,
  .native-searchable-input {
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 640px) {
  :root {
    --field-h: 40px;
    --row-h: 40px;
  }

  .app-header {
    padding: 7px 10px;
  }

  .brand-mark {
    width: 32px;
    height: 32px;
    border-radius: 9px;
  }

  .brand strong {
    font-size: 16px;
  }

  .header-spacer {
    min-width: 8px;
  }

  .sidebar-toggle {
    width: 36px;
    height: 36px;
  }

  #nav {
    padding: 7px;
  }

  .pagebar,
  body.loads-mode .pagebar {
    padding: 10px;
  }

  .pagebar h1,
  body.loads-mode .pagebar h1 {
    font-size: 19px;
  }

  .primary,
  .secondary,
  button {
    min-height: 38px;
  }

  .load-create-menu {
    position: fixed;
    left: 10px;
    right: 10px;
    top: auto;
    bottom: 10px;
    width: auto;
    max-height: calc(100svh - 90px);
    overflow: auto;
  }

  .load-create-menu button {
    min-height: 64px;
    grid-template-columns: 42px 1fr;
    padding: 10px 12px;
  }

  .load-create-icon {
    width: 36px;
    height: 36px;
  }

  table {
    min-width: 680px;
  }

  .table-wrap td:not(.actions):not(.row-actions),
  .table-wrap th:not(.actions-col) {
    max-width: 220px;
  }

  .table-wrap {
    border-left: 0;
    border-right: 0;
    border-radius: 0;
  }

  .table-pager .pager-nav {
    width: 100%;
    justify-content: center;
  }

  .toast-container,
  #toastHost {
    left: 10px !important;
    right: 10px !important;
    bottom: 10px !important;
    width: auto !important;
  }

  .toast {
    width: 100%;
    max-width: none;
  }

  /* Safety uses a compact command bar and record cards on phones. */
  body.safety-mode .pagebar {
    gap: 10px;
  }

  body.safety-mode .top-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: stretch;
    gap: 8px;
  }

  body.safety-mode .top-actions > * {
    width: auto;
    min-width: 0;
    flex: none;
  }

  body.safety-mode .top-actions .search {
    grid-column: 1;
  }

  body.safety-mode .top-actions .search input {
    width: 100% !important;
  }

  body.safety-mode .top-actions [data-action="export"] {
    grid-column: 2;
    width: auto;
    padding-inline: 12px;
  }

  body.safety-mode .top-actions #primaryAction {
    grid-column: 1 / -1;
    width: 100%;
  }

  body.safety-mode .board {
    padding: 10px;
    overflow: visible;
  }

  body.safety-mode .toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
  }

  body.safety-mode .toolbar .segments {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    min-width: 0;
    overflow-x: auto;
    padding: 1px 1px 7px;
    scroll-snap-type: x proximity;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
  }

  body.safety-mode .toolbar .segment {
    flex: 0 0 auto;
    min-height: 34px;
    padding: 5px 10px;
    font-size: 13px;
    scroll-snap-align: start;
  }

  body.safety-mode .toolbar [data-action="refresh"] {
    min-height: 34px;
    padding: 5px 10px;
  }

  body.safety-mode .table-panel,
  body.safety-mode .board > .table-panel.standard-page-grid {
    height: auto;
  }

  body.safety-mode .table-panel .table-wrap {
    overflow: visible;
    border: 0;
    background: transparent;
    box-shadow: none;
  }

  body.safety-mode .table-panel table {
    display: block;
    min-width: 0;
    width: 100%;
    background: transparent;
  }

  body.safety-mode .table-panel thead {
    display: none;
  }

  body.safety-mode .table-panel tbody {
    display: grid;
    gap: 10px;
  }

  body.safety-mode .table-panel tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 0;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 4px 12px rgba(21, 39, 70, .06);
  }

  body.safety-mode .table-panel tbody td {
    display: grid;
    align-content: start;
    gap: 5px;
    min-width: 0;
    height: auto;
    padding: 10px 12px;
    border: 0;
    border-bottom: 1px solid var(--line);
    white-space: normal;
    overflow-wrap: anywhere;
  }

  body.safety-mode .table-panel tbody td:nth-child(odd) {
    border-right: 1px solid var(--line);
  }

  body.safety-mode .table-panel tbody td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .04em;
    text-transform: uppercase;
  }

  body.safety-mode .table-panel tbody td:nth-last-child(-n + 2) {
    border-bottom: 0;
  }

  body.safety-mode .table-panel tbody td.actions {
    position: static;
    display: grid;
    grid-column: 1 / -1;
    justify-content: stretch;
    background: var(--panel);
    box-shadow: none;
  }

  body.safety-mode .table-panel tbody td.actions > * {
    width: 100%;
  }

  body.safety-mode .table-panel tbody td[colspan] {
    grid-column: 1 / -1;
    border: 0;
    text-align: center;
  }

  body.safety-mode .table-panel tbody td[colspan]::before {
    content: none;
  }

  body.safety-mode .table-pager {
    margin-top: 8px;
  }
}

@media (max-width: 820px) and (orientation: landscape) {
  .sidebar {
    top: 50px;
  }

  .app-header {
    min-height: 50px;
  }

  .modal form,
  .drawer article {
    min-height: 100svh;
  }
}

/* Keep the dispatch controls inside the visible workspace while the calendar grid scrolls. */
.dispatch-board.ez-dispatch-board .dispatch-toolbar {
  width: calc(100vw - 264px) !important;
  max-width: calc(100vw - 264px) !important;
  overflow: visible !important;
  position: relative !important;
  z-index: 30 !important;
}

.dispatch-board.ez-dispatch-board .dispatch-toolbar .native-searchable-select.open,
.dispatch-board.ez-dispatch-board .dispatch-toolbar .native-searchable-menu {
  z-index: 70000 !important;
}

body[data-sidebar-collapsed="true"] .dispatch-board.ez-dispatch-board .dispatch-toolbar {
  width: calc(100vw - 76px) !important;
  max-width: calc(100vw - 76px) !important;
}

@media (max-width: 1180px) {
  .dispatch-board.ez-dispatch-board .dispatch-toolbar,
  body[data-sidebar-collapsed="true"] .dispatch-board.ez-dispatch-board .dispatch-toolbar {
    width: calc(100vw - 76px) !important;
    max-width: calc(100vw - 76px) !important;
  }
}

@media (max-width: 900px) {
  .dispatch-board.ez-dispatch-board .dispatch-toolbar,
  body[data-sidebar-collapsed="true"] .dispatch-board.ez-dispatch-board .dispatch-toolbar {
    width: 100vw !important;
    max-width: 100vw !important;
  }
}

/* Final row-action dropdown override: compact, vertical, and never off-screen. */
.table-wrap td.actions .grid-action-menu > div,
.table-wrap td.row-actions .grid-action-menu > div,
.table-wrap td.actions .equipment-action-menu > div,
.table-wrap td.row-actions .equipment-action-menu > div,
.load-action-menu > div {
  width: max-content !important;
  min-width: 150px !important;
  max-width: min(220px, calc(100vw - 24px)) !important;
  padding: 6px !important;
  overflow: hidden !important;
  border-radius: 8px !important;
}

.table-wrap td.actions .grid-action-menu > div button,
.table-wrap td.row-actions .grid-action-menu > div button,
.table-wrap td.actions .equipment-action-menu > div button,
.table-wrap td.row-actions .equipment-action-menu > div button,
.load-action-menu > div button {
  display: flex !important;
  width: 100% !important;
  min-width: 0 !important;
  min-height: 36px !important;
  justify-content: flex-start !important;
  margin: 0 !important;
  padding: 8px 12px !important;
  border: 0 !important;
  border-radius: 6px !important;
  background: transparent !important;
  text-align: left !important;
  white-space: nowrap !important;
}

.table-wrap td.actions .grid-action-menu > div button + button,
.table-wrap td.row-actions .grid-action-menu > div button + button,
.table-wrap td.actions .equipment-action-menu > div button + button,
.table-wrap td.row-actions .equipment-action-menu > div button + button,
.load-action-menu > div button + button {
  margin-top: 3px !important;
}

.table-wrap td.actions .grid-action-menu > div button.danger,
.table-wrap td.row-actions .grid-action-menu > div button.danger,
.table-wrap td.actions .equipment-action-menu > div button.danger,
.table-wrap td.row-actions .equipment-action-menu > div button.danger,
.load-action-menu > div button.danger {
  background: transparent !important;
  color: var(--red) !important;
}

.table-wrap td.actions .grid-action-menu > div button.danger:hover,
.table-wrap td.row-actions .grid-action-menu > div button.danger:hover,
.table-wrap td.actions .equipment-action-menu > div button.danger:hover,
.table-wrap td.row-actions .equipment-action-menu > div button.danger:hover,
.load-action-menu > div button.danger:hover {
  background: rgba(196, 57, 48, 0.08) !important;
  color: var(--red) !important;
}

.table-wrap td.actions .grid-action-menu > div button.danger:disabled,
.table-wrap td.row-actions .grid-action-menu > div button.danger:disabled,
.table-wrap td.actions .equipment-action-menu > div button.danger:disabled,
.table-wrap td.row-actions .equipment-action-menu > div button.danger:disabled,
.load-action-menu > div button.danger:disabled {
  background: var(--panel-2) !important;
  color: var(--muted) !important;
  opacity: .55 !important;
}
