/*
 * Orion phone refinements
 *
 * Deliberately limited to Bootstrap's xs breakpoint. Tablet and desktop
 * layouts retain their existing SB Admin and DataTables presentation.
 */
@media (max-width: 575.98px) {
  /* Detail tabs use an outer card on larger screens, but not on phones. */
  .job-detail-shell {
    background: transparent !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }

  .job-detail-shell > .card-header {
    background: transparent !important;
    border-bottom: 0 !important;
    padding-left: 0;
    padding-right: 0;
  }

  .job-detail-shell > .card-header .card-header-tabs {
    margin: 0;
  }

  .job-detail-shell > .card-body {
    padding-left: 0;
    padding-right: 0;
  }

  body {
    background-color: #ffffff;
    font-size: 0.875rem;
  }

  #layoutSidenav_content,
  #layoutSidenav_content main,
  .card.mobile-table-card {
    background-color: #ffffff;
  }

  h1,
  .h1 {
    font-size: 1.5rem;
  }

  h2,
  .h2 {
    font-size: 1.3rem;
  }

  h3,
  .h3 {
    font-size: 1.15rem;
  }

  h4,
  .h4 {
    font-size: 1.05rem;
  }

  h5,
  .h5 {
    font-size: 0.95rem;
  }

  h6,
  .h6 {
    font-size: 0.875rem;
  }

  .page-header-title {
    font-size: 1rem;
  }

  .form-control,
  .form-select,
  .form-label,
  .btn,
  .dropdown-item,
  .nav-link,
  .alert {
    font-size: 0.825rem;
  }

  small,
  .small,
  .form-text {
    font-size: 0.75rem;
  }

  /* Recover useful width without changing the application grid. */
  #layoutSidenav_content main > .container,
  #layoutSidenav_content main > .container-fluid,
  #layoutSidenav_content main > .container-xl,
  #layoutSidenav_content main > .container-xxl,
  .page-header .container-fluid {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
  }

  .page-header-title {
    align-items: flex-start;
    line-height: 1.25;
    overflow-wrap: anywhere;
  }

  .page-header .row > [class*="col-"] {
    min-width: 0;
  }

  .page-header .page-header-content .col-auto {
    max-width: 100%;
  }

  .card-body {
    padding: 1rem;
  }

  .card.mobile-table-card {
    border: 0;
    border-radius: 0;
    box-shadow: none !important;
  }

  .card.mobile-table-card > .card-body {
    padding: 0;
  }

  /* Dashboard work list: compact vertical summaries prevent page overflow. */
  #taskList,
  #taskList .task-group,
  #taskList .task-parent,
  #taskList .task-subtask,
  #taskList .task-main {
    max-width: 100%;
    min-width: 0;
  }

  #taskList .task-parent {
    padding: 0.65rem 0.75rem;
  }

  #taskList .task-subtasks {
    margin: 0 0.75rem 0.75rem;
  }

  #taskList .task-subtask {
    padding: 0.65rem 0.75rem;
  }

  #taskList .task-row-layout {
    display: block !important;
  }

  #taskList .task-job-heading,
  #taskList .task-summary,
  #taskList .task-description,
  #taskList .task-due,
  #taskList .subtask-label {
    font-size: 0.72rem;
    line-height: 1.3;
  }

  #taskList .task-summary,
  #taskList .task-description {
    overflow-wrap: anywhere;
    white-space: normal;
    word-break: break-word;
  }

  #taskList .job-type-badge,
  #taskList .task-priority,
  #taskList .task-status {
    display: none !important;
  }

  #taskList .task-due {
    margin-top: 0.25rem;
    white-space: normal !important;
  }

  #taskFilters {
    display: grid;
    flex: 1 0 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-width: 100%;
    width: 100%;
  }

  #taskFilters .btn {
    border-radius: 0.25rem !important;
    width: 100%;
  }

  .dashboard-stat .card-body {
    padding: 0.65rem;
  }

  .dashboard-stat .stat-icon {
    height: 2rem !important;
    margin-right: 0.5rem !important;
    min-width: 2rem;
    width: 2rem !important;
  }

  .card-header {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .card-header > .btn,
  .card-header > .btn-group,
  .card-header > .dropdown {
    flex: 0 0 auto;
  }

  /* Long tab sets remain readable and swipe horizontally. */
  .nav-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
  }

  .nav-tabs .nav-item {
    flex: 0 0 auto;
  }

  .nav-tabs .nav-link {
    white-space: nowrap;
  }

  /* Form and action groups wrap only when the phone viewport requires it. */
  .card-body .btn-toolbar,
  .card-body .d-flex.mobile-wrap,
  .form-actions,
  .modal-footer {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .input-group,
  input[type="file"],
  .form-control,
  .form-select {
    max-width: 100%;
  }

  input[type="file"] {
    overflow: hidden;
  }

  /* Keep long modal forms usable above the Android keyboard. */
  .modal-dialog {
    margin: 0.5rem;
    max-width: calc(100% - 1rem);
  }

  .modal-content {
    max-height: calc(100dvh - 1rem);
  }

  .modal-body {
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .modal-footer > * {
    margin: 0;
  }

  /* DataTables controls use the full phone width without changing the table. */
  div.dt-container .dt-layout-row {
    align-items: stretch;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  div.dt-container .dt-layout-cell,
  div.dt-container .dt-search,
  div.dt-container .dt-length,
  div.dt-container .dt-info,
  div.dt-container .dt-paging {
    text-align: left;
    width: 100%;
  }

  div.dt-container .dt-search label {
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    height: 1px;
    overflow: hidden;
    position: absolute;
    white-space: nowrap;
    width: 1px;
  }

  div.dt-container .dt-search input {
    font-size: 0.75rem;
    height: 32px;
    line-height: 1.2;
    margin-left: 0;
    max-width: none;
    padding: 0.25rem 0.6rem;
    width: 100%;
  }

  div.dt-container .dt-paging .pagination {
    flex-wrap: wrap;
    justify-content: center;
  }

  div.dt-container .dt-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
  }

  div.dt-container .dt-buttons .dt-button {
    font-size: 0.7rem !important;
    line-height: 1.2;
    margin: 0 !important;
    min-height: 28px;
    padding: 0.2rem 0.45rem !important;
  }

  div.dt-container .dt-buttons .buttons-create,
  div.dt-container .dt-buttons .buttons-edit,
  div.dt-container .dt-buttons .buttons-remove {
    font-size: 0.7rem !important;
    height: 28px !important;
    line-height: 1 !important;
    min-height: 0 !important;
    padding: 0.2rem 0.45rem !important;
  }

  .datatable-wrapper .datatable-top,
  .datatable-wrapper .datatable-bottom {
    align-items: stretch;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  .datatable-wrapper .datatable-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table.dataTable,
  .datatable-wrapper table {
    font-size: 0.75rem;
  }

  table.dataTable thead th,
  table.dataTable tbody td,
  .datatable-wrapper table th,
  .datatable-wrapper table td {
    font-size: 0.75rem;
  }

  table.dataTable tbody td {
    white-space: normal;
  }

  .job-table-responsive {
    overflow-x: hidden;
  }

  #job_dataTable,
  #workshop_job_dataTable {
    min-width: 0 !important;
    table-layout: fixed !important;
    width: 100% !important;
  }

  #job_dataTable .job-reference-cell,
  #workshop_job_dataTable .job-reference-cell {
    max-width: 112px !important;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #pump_dataTable .pump-number-cell,
  #pump_dataTable thead th:nth-child(3),
  #pump_dataTable colgroup col:nth-child(3) {
    max-width: 58px !important;
    width: 58px !important;
  }

  #pump_dataTable .pump-number-cell {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #job_dataTable .job-customer-cell,
  #workshop_job_dataTable .job-customer-cell {
    max-width: 104px !important;
  }

  #job_dataTable .job-customer-cell,
  #workshop_job_dataTable .job-customer-cell,
  #pump_dataTable .pump-customer-cell {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #pump_dataTable .pump-customer-cell,
  #pump_dataTable thead th:nth-child(7) {
    max-width: none !important;
    width: auto !important;
  }

  #pump_dataTable .pump-actions-cell,
  #pump_dataTable thead th:nth-child(14) {
    max-width: 42px !important;
    padding-left: 3px !important;
    padding-right: 3px !important;
    width: 42px !important;
  }

  #pump_dataTable .pump-actions-cell .pump-info-link {
    margin-right: 0 !important;
  }

  #job_dataTable .job-customer-cell,
  #workshop_job_dataTable .job-customer-cell,
  #job_dataTable thead th:nth-child(4),
  #workshop_job_dataTable thead th:nth-child(4) {
    max-width: 86px !important;
    width: 86px !important;
  }

  #job_dataTable .job-description-cell,
  #workshop_job_dataTable .job-description-cell {
    font-size: 0.75rem;
    line-height: 1.2;
    max-width: none !important;
    overflow-wrap: anywhere;
    white-space: normal;
    width: auto !important;
  }

  #job_dataTable .job-description-cell > *,
  #workshop_job_dataTable .job-description-cell > * {
    display: block;
    overflow-wrap: anywhere;
    white-space: normal;
    word-break: break-word;
  }

  #job_dataTable .job-status-cell,
  #workshop_job_dataTable tbody td:nth-child(8) {
    max-width: 78px !important;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 78px !important;
  }

  #job_dataTable .job-status-cell > *,
  #workshop_job_dataTable tbody td:nth-child(8) > * {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #job_dataTable .job-priority-cell,
  #workshop_job_dataTable .job-priority-cell,
  #job_dataTable thead th:nth-child(8),
  #workshop_job_dataTable thead th:nth-child(7) {
    max-width: 28px !important;
    padding-left: 4px !important;
    padding-right: 4px !important;
    text-align: center;
    width: 28px !important;
  }

  #job_dataTable thead th:nth-child(8),
  #workshop_job_dataTable thead th:nth-child(7) {
    font-size: 0;
  }

  #job_dataTable thead th:nth-child(8) .dt-column-title,
  #workshop_job_dataTable thead th:nth-child(7) .dt-column-title {
    display: none;
  }

  #job_dataTable .job-priority-badge,
  #workshop_job_dataTable .job-priority-badge {
    background: transparent !important;
    display: inline-block;
    font-size: 0.75rem;
    height: auto;
    min-width: 14px;
    padding: 0;
    width: 14px;
  }

  #job_dataTable .job-priority-badge .fa-flag,
  #workshop_job_dataTable .job-priority-badge .fa-flag {
    font-size: 0.75rem;
  }

  #job_dataTable .job-actions-cell,
  #workshop_job_dataTable .workshop-job-actions-cell,
  #job_dataTable thead th:nth-child(14),
  #workshop_job_dataTable thead th:nth-child(14) {
    max-width: 40px !important;
    padding-left: 2px !important;
    padding-right: 2px !important;
    width: 40px !important;
  }

  #job_dataTable .job-actions-cell .job-sheet-link,
  #workshop_job_dataTable .workshop-job-actions-cell .workshop-job-detail-action {
    height: 32px !important;
    margin-right: 0 !important;
    width: 32px !important;
  }

  /* Make the existing full-information details panels obvious and readable. */
  #job_dataTable td.details-control,
  #workshop_job_dataTable td.details-control,
  #pump_dataTable td.details-control {
    min-width: 42px;
    position: relative;
    text-align: center;
    width: 42px;
  }

  #job_dataTable td.details-control::before,
  #workshop_job_dataTable td.details-control::before,
  #pump_dataTable td.details-control::before {
    align-items: center;
    background: #eef2f7;
    border: 1px solid #d7dce3;
    border-radius: 50%;
    color: #344054;
    display: inline-flex;
    font-size: 1rem;
    height: 30px;
    justify-content: center;
    opacity: 1;
    width: 30px;
  }

  .child-row-wrap {
    margin: 0.375rem 0;
    padding: 0.75rem;
  }

  .job-detail-grid {
    gap: 1rem;
    grid-template-columns: 1fr;
  }

  .job-detail-item {
    grid-template-columns: minmax(78px, 34%) minmax(0, 1fr);
  }

  .job-detail-value,
  .job-detail-notes,
  table.dataTable > tbody > tr.child .dtr-data {
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  table.dataTable > tbody > tr.child ul.dtr-details,
  table.dataTable > tbody > tr.child ul.dtr-details > li {
    width: 100%;
  }

  table.dataTable > tbody > tr.child .dtr-title {
    min-width: 38%;
    padding-right: 0.5rem;
    vertical-align: top;
  }

  table.dataTable.dtr-inline.collapsed > tbody > tr > td.dtr-control,
  table.dataTable.dtr-inline.collapsed > tbody > tr > th.dtr-control {
    padding-left: 2.5rem;
  }

  table.dataTable.dtr-inline.collapsed > tbody > tr > td.dtr-control::before,
  table.dataTable.dtr-inline.collapsed > tbody > tr > th.dtr-control::before {
    height: 1.5rem;
    left: 0.5rem;
    line-height: 1.35rem;
    width: 1.5rem;
  }

  /* Keep the primary action comfortably tappable without enlarging all icons. */
  .job-sheet-link,
  .workshop-job-detail-action,
  .pump-info-link,
  .calibration-detail-link {
    height: 36px !important;
    width: 36px !important;
  }

  /* Attachment and note content must never widen the page. */
  .attachment-filename,
  .list-group-item,
  .job-detail-notes,
  [style*="white-space: pre-wrap"] {
    overflow-wrap: anywhere;
    word-break: break-word;
  }
}
