/* Mobile is an operational companion surface, not a compressed desktop table. */
@media (max-width: 767.98px) {
  .sp-orders-page--open {
    padding-top: .25rem;
  }

  .sp-orders-header {
    margin-bottom: .85rem;
  }

  .sp-orders-title {
    font-size: 26px;
    line-height: 32px;
  }

  .sp-orders-summary {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    min-height: 0;
  }

  .sp-orders-summary--single {
    grid-template-columns: 1fr;
  }

  .sp-orders-summary-item {
    min-width: 0;
    padding: .75rem;
    border-right: 1px solid var(--sp-border);
    border-bottom: 0;
  }

  .sp-orders-summary-item:last-child {
    border-right: 0;
  }

  .sp-orders-summary-item > span:last-child {
    display: flex;
    align-items: flex-start;
    flex-direction: column;
    gap: 1px;
  }

  .sp-orders-summary-item strong {
    font-size: 21px;
  }

  .sp-orders-summary-item small {
    display: none;
  }

  .sp-orders-summary-icon {
    flex-basis: 34px;
    width: 34px;
    height: 34px;
  }

  .sp-orders-toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
  }

  .sp-orders-search {
    grid-column: 1 / -1;
  }

  .sp-orders-page-size {
    display: none;
  }

  .sp-orders-filter {
    min-width: 0;
  }

  .sp-orders-card {
    border: 0 !important;
    background: transparent;
    box-shadow: none;
  }

  .sp-orders-card > .table-responsive {
    margin: 0;
    overflow: visible;
  }

  .sp-orders-table,
  .sp-orders-table tbody {
    display: block;
    min-width: 0;
    width: 100%;
  }

  .sp-orders-table thead {
    display: none;
  }

  .sp-orders-table tbody tr {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "patient status"
      "id date"
      "provider actions";
    gap: 8px 12px;
    height: auto;
    min-height: 0;
    margin-bottom: 10px;
    padding: 14px;
    border: 1px solid var(--sp-border);
    border-radius: var(--sp-radius-lg);
    background: var(--sp-surface);
    box-shadow: var(--sp-shadow-sm);
  }

  .sp-orders-table tbody tr:hover {
    border-color: #cddcff;
    background: #f8faff;
  }

  .sp-orders-table tbody td {
    display: block;
    min-width: 0;
    padding: 0 !important;
    border: 0;
  }

  .sp-order-mobile-patient {
    grid-area: patient;
  }

  .sp-order-mobile-patient .sp-person-avatar {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
  }

  .sp-order-mobile-status {
    grid-area: status;
    align-self: start;
    text-align: right;
  }

  .sp-order-mobile-id {
    grid-area: id;
    padding-left: 44px !important;
    color: var(--sp-slate-600) !important;
    font-size: 12px;
    font-weight: var(--sp-font-medium);
  }

  .sp-order-mobile-date {
    grid-area: date;
    align-self: center;
    justify-self: end;
    text-align: right;
  }

  .sp-order-mobile-date .sp-order-date {
    display: inline-flex;
    min-width: 0;
    align-items: center;
    flex-direction: row;
    gap: 4px;
  }

  .sp-order-mobile-date .sp-order-date-primary,
  .sp-order-mobile-date .sp-order-date-secondary {
    color: var(--sp-slate-600);
    font-size: 12px;
    font-weight: var(--sp-font-normal);
  }

  .sp-order-mobile-date .sp-order-date-primary::after {
    content: " ·";
  }

  .sp-order-mobile-provider {
    grid-area: provider;
    padding-left: 44px !important;
  }

  .sp-order-mobile-provider .sp-person-avatar {
    display: none;
  }

  .sp-order-mobile-provider .sp-person-name {
    font-size: 12px;
    font-weight: var(--sp-font-medium);
  }

  .sp-order-mobile-provider .sp-person-meta {
    display: none;
  }

  .sp-order-mobile-actions {
    grid-area: actions;
    align-self: end;
  }

  .sp-order-mobile-actions .btn-outline-primary {
    min-width: 44px;
  }

  .sp-order-mobile-pharmacy,
  .sp-order-mobile-secondary {
    display: none !important;
  }

  .sp-orders-table--routed tbody tr {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "id status"
      "patient patient"
      "provider provider"
      "fulfillment chevron";
    padding: 12px 14px;
  }

  .sp-orders-table--attention tbody tr {
    grid-template-areas:
      "id status"
      "patient patient"
      "provider provider"
      "problem problem"
      "fulfillment chevron";
  }

  .sp-orders-table--has-select tbody tr {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "select id status"
      "patient patient patient"
      "provider provider provider"
      "fulfillment fulfillment chevron"
      "preparation preparation preparation";
  }

  .sp-orders-table--pending-signer tbody tr {
    grid-template-areas:
      "select id status"
      "patient patient patient"
      "fulfillment fulfillment chevron"
      "preparation preparation preparation";
  }

  .sp-orders-table--has-select.sp-orders-table--attention tbody tr {
    grid-template-areas:
      "select id status"
      "patient patient patient"
      "provider provider provider"
      "problem problem problem"
      "fulfillment fulfillment chevron";
  }

  .sp-orders-table--routed .sp-order-mobile-select {
    grid-area: select;
    padding: 0 !important;
    align-self: start;
  }

  .sp-orders-table--routed .sp-order-mobile-id {
    grid-area: id;
    padding-left: 0 !important;
    color: var(--sp-text-primary) !important;
    font-size: inherit;
    font-weight: inherit;
  }

  .sp-orders-table--routed .sp-order-mobile-patient {
    grid-area: patient;
  }

  .sp-orders-table--routed .sp-order-mobile-patient .sp-person-avatar {
    display: none;
  }

  .sp-orders-table--routed .sp-order-mobile-provider {
    grid-area: provider;
    padding-left: 0 !important;
  }

  .sp-orders-table--routed .sp-order-mobile-preparation {
    grid-area: preparation;
    padding-left: 0 !important;
    border-top: 1px solid var(--sp-border);
  }

  .sp-orders-table--routed .sp-order-mobile-preparation::before {
    content: "Preparation";
    display: block;
    margin-bottom: .2rem;
    color: var(--sp-text-secondary);
    font-size: 11px;
    font-weight: var(--sp-font-medium);
  }

  .sp-orders-table--routed .sp-order-mobile-provider .sp-person-name {
    font-size: 13px;
  }

  .sp-orders-table--routed .sp-order-mobile-provider .sp-person-meta,
  .sp-orders-table--routed .sp-order-mobile-pharmacy .sp-person-avatar {
    display: none;
  }

  .sp-orders-table--routed .sp-order-mobile-pharmacy {
    display: block !important;
    grid-area: fulfillment;
  }

  .sp-orders-table--routed .sp-order-mobile-pharmacy .sp-order-pharmacy-name::before {
    content: "Fulfillment";
    display: block;
    margin-bottom: .1rem;
    color: var(--sp-text-secondary);
    font-size: 11px;
    font-weight: var(--sp-font-medium);
  }

  .sp-orders-table--routed .sp-order-mobile-problem {
    grid-area: problem;
    padding-left: 0 !important;
    color: var(--sp-text-secondary);
    font-size: 13px;
    overflow-wrap: break-word;
    word-break: normal;
  }

  .sp-orders-table--routed .sp-order-mobile-problem::before {
    content: "Problem";
    display: block;
    margin-bottom: .1rem;
    color: var(--sp-text-secondary);
    font-size: 11px;
    font-weight: var(--sp-font-medium);
  }

  .sp-orders-table--routed .sp-order-mobile-provider .sp-person-copy::before {
    content: "Provider";
    display: block;
    margin-bottom: .1rem;
    color: var(--sp-text-secondary);
    font-size: 11px;
    font-weight: var(--sp-font-medium);
  }

  .sp-orders-table--routed .sp-order-row-chevron {
    grid-area: chevron;
    align-self: end;
    text-align: right;
  }

  .sp-orders-table--routed .sp-routed-empty-row {
    display: block;
  }

  .sp-orders-footer {
    border: 1px solid var(--sp-border);
    border-radius: var(--sp-radius-md);
    background: var(--sp-surface);
  }

  .sp-dashboard-orders,
  .sp-dashboard-orders tbody {
    display: block;
    width: 100% !important;
  }

  .sp-dashboard-orders thead {
    display: none;
  }

  .sp-dashboard-orders tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "patient status"
      "order date"
      "provider action";
    gap: 8px 12px;
    height: auto;
    margin-bottom: 10px;
    padding: 14px;
    border: 1px solid var(--sp-border);
    border-radius: var(--sp-radius-lg);
    background: var(--sp-surface);
    box-shadow: var(--sp-shadow-sm);
  }

  .sp-dashboard-orders tbody td {
    display: block;
    padding: 0 !important;
    border: 0;
  }

  .sp-dashboard-patient { grid-area: patient; }
  .sp-dashboard-status { grid-area: status; text-align: right; }
  .sp-dashboard-order-id { grid-area: order; color: var(--sp-slate-600); font-size: 12px; }
  .sp-dashboard-provider { grid-area: provider; }
  .sp-dashboard-orders tbody td:nth-child(4) { grid-area: date; color: var(--sp-slate-600); font-size: 12px; text-align: right; }
  .sp-dashboard-orders tbody td:nth-child(6) { display: none; }
  .sp-dashboard-orders tbody td:last-child { grid-area: action; align-self: end; }

  .dataTables_wrapper:has(.sp-dashboard-orders) .dataTables_length,
  .dataTables_wrapper:has(.sp-dashboard-orders) .dataTables_info,
  .dataTables_wrapper:has(.sp-orders-table--routed) .dataTables_length {
    display: none;
  }

  .sp-mobile-record-table,
  .sp-mobile-record-table tbody {
    display: block;
    width: 100%;
  }

  .sp-mobile-record-table thead {
    display: none;
  }

  .sp-mobile-record-table tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    height: auto;
    margin-bottom: 10px;
    padding: 14px;
    border: 1px solid var(--sp-border);
    border-radius: var(--sp-radius-lg);
    background: var(--sp-surface);
    box-shadow: var(--sp-shadow-sm);
  }

  .sp-mobile-record-table tbody td {
    display: grid;
    grid-template-columns: minmax(86px, 34%) minmax(0, 1fr);
    gap: 10px;
    padding: 8px 0 !important;
    border: 0;
    border-bottom: 1px solid #f0f2f5;
    text-align: left !important;
    overflow-wrap: anywhere;
  }

  .sp-mobile-record-table tbody td::before {
    content: attr(data-label);
    color: var(--sp-slate-400);
    font-size: 11px;
    font-weight: var(--sp-font-medium);
    line-height: 16px;
  }

  .sp-mobile-record-table tbody td:first-child {
    display: block;
    padding-top: 0 !important;
  }

  .sp-mobile-record-table tbody td:first-child::before,
  .sp-mobile-record-table tbody td.sp-mobile-record-actions::before {
    display: none;
  }

  .sp-mobile-record-table tbody td:last-child {
    border-bottom: 0;
  }

  .sp-mobile-record-table .sp-mobile-record-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-top: 12px !important;
  }

  .sp-mobile-record-table .sp-mobile-record-actions .btn {
    flex: 1 1 auto;
    min-height: 40px;
  }

  .sp-mobile-record-table [class*="refills-due-col-"] {
    width: auto;
  }

  .modal-dialog:not(.modal-sm) {
    margin: 8px;
  }

  .modal-dialog:not(.modal-sm) .modal-content {
    max-height: calc(100dvh - 16px);
    border-radius: var(--sp-radius-lg);
  }

  .modal-dialog:not(.modal-sm) .modal-body {
    overflow-y: auto;
  }

  .new-order-page {
    padding-bottom: 72px;
  }

  .new-order-mobile-steps {
    position: sticky;
    z-index: 1015;
    top: 58px;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 2px;
    margin: 0 0 12px;
    padding: 6px;
    border: 1px solid var(--sp-border);
    border-radius: var(--sp-radius-lg);
    background: rgba(255, 255, 255, .96);
    box-shadow: var(--sp-shadow-sm);
    backdrop-filter: blur(12px);
  }

  .new-order-mobile-steps a {
    display: flex;
    min-width: 0;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 2px;
    border-radius: 8px;
    color: var(--sp-slate-600);
    font-size: 10px;
    font-weight: var(--sp-font-medium);
    text-decoration: none;
  }

  .new-order-mobile-steps a:hover,
  .new-order-mobile-steps a:focus-visible {
    color: var(--sp-blue-600);
    background: var(--sp-nav-active-bg);
  }

  .new-order-mobile-steps span {
    display: inline-flex;
    width: 20px;
    height: 20px;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--sp-blue-600);
    background: var(--sp-nav-active-bg);
    font-size: 10px;
    font-weight: var(--sp-font-semibold);
  }

  .new-order-section {
    scroll-margin-top: 126px;
  }

  .new-order-mobile-bar {
    bottom: calc(68px + env(safe-area-inset-bottom));
    z-index: 1030;
    margin-right: -.85rem;
    margin-left: -.85rem;
  }
}

@media (max-width: 430px) {
  .app-toolbar .page-heading {
    font-size: 24px !important;
    line-height: 32px !important;
  }

  .app-toolbar .app-toolbar-inner {
    min-height: 0;
  }

  .toolbar-actions .btn {
    min-height: 40px;
  }
}

.sp-driver-list {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.sp-driver-card {
  display: block;
  padding: 1rem 1.1rem;
  border: 1px solid var(--sp-border, #e4e6ef);
  border-radius: var(--sp-radius-lg, .75rem);
  background: #fff;
  min-height: 5.5rem;
}

.sp-driver-card:hover,
.sp-driver-card:focus-visible {
  border-color: var(--sp-primary, #3e97ff);
}

.sp-driver-proof-thumb {
  max-width: 160px;
  max-height: 160px;
  object-fit: cover;
}

.sp-driver-proof-preview {
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  background: #f5f8fa;
}

.sp-driver-detail .btn.py-3 {
  min-height: 48px;
}
