/* Case Operations v2.54 — tablet and phone layouts only.
   Nothing in this stylesheet applies to desktop viewports (1024px and wider).
   Existing application and Supabase behavior is unchanged. */
@media screen and (max-width: 1023px), screen and (max-width: 1199px) and (pointer: coarse) {
  /* Consistent viewport sizing and touch targets */
  html, body { max-width: 100%; }
  main, .app-shell, .panel, .page, .builder-layout, .builder-panel { min-width: 0; }
  img, video, canvas { max-width: 100%; }
  .button, .view-tab, .hub-button, .hub-tile, .section-button,
  .assignment-option, .nested-record { min-height: 42px; touch-action: manipulation; }
  input, select, textarea { max-width: 100%; min-width: 0; }

  /* Cases / Inspections home */
  #app-view.app-shell { padding: 12px; }
  #app-view .topbar { gap: 12px; padding: 14px; }
  #app-view .topbar h1 { font-size: clamp(19px, 3vw, 24px); }
  #app-view .user-controls { min-width: 0; }
  #app-view .user-chip { max-width: 100%; overflow-wrap: anywhere; }
  #app-view > .metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; }
  #app-view > .metrics .metric-card { min-width: 0; padding: 12px; }
  #app-view > .metrics .metric-card strong { font-size: 22px; }
  #app-view .operations-nav { position: sticky; top: 0; z-index: 30; display: flex;
    gap: 8px; overflow-x: auto; overflow-y: hidden; flex-wrap: nowrap;
    scrollbar-width: thin; -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity;
    background: #eef3f7; padding: 10px 2px 10px; margin: 0 0 10px; }
  #app-view .operations-nav .view-tab { flex: 0 0 auto; white-space: nowrap;
    scroll-snap-align: start; padding: 11px 14px; }
  #cases-view .case-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  #cases-view .list-heading { align-items: flex-start; flex-wrap: wrap; }
  #cases-view .list-heading .helper { max-width: 100%; text-align: left; line-height: 1.4; }

  /* Keep the sort control; present the wide 13-column case table as cards. */
  #cases-view .cases-top-scroll { display: none; }
  #cases-view .cases-table-wrap { overflow: visible; overflow-x: visible; max-height: none;
    border: 0; border-radius: 0; background: transparent; scrollbar-gutter: auto; }
  #cases-view .cases-table { display: block; width: 100%; min-width: 0; border-spacing: 0; }
  #cases-view .cases-table thead { display: block; margin-bottom: 9px; }
  #cases-view .cases-table thead tr { display: block; }
  #cases-view .cases-table thead th { display: none; }
  #cases-view .cases-table thead th:first-child { display: inline-block; position: static;
    border: 0; border-radius: 8px; padding: 9px 12px; }
  #cases-view .cases-table thead th:first-child::before { content: 'Sort by '; font-weight: 400; }
  #cases-view .cases-table tbody { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px; width: 100%; }
  #cases-view .cases-table tbody tr.case-row { display: flex; flex-direction: column;
    min-width: 0; width: 100%; border: 1px solid #cbd9e4; border-radius: 12px;
    overflow: hidden; background: #fff; box-shadow: 0 3px 12px rgba(25,55,80,.07); }
  #cases-view .cases-table tbody tr.case-row:focus-visible {
    outline: 3px solid #4d87b4; outline-offset: 2px; }
  #cases-view .cases-table tbody td { display: block; width: 100%; min-width: 0;
    padding: 10px 12px; border: 0; border-top: 1px solid #edf1f5;
    overflow-wrap: anywhere; font-size: 13px; background: #fff; }
  #cases-view .cases-table tbody td:first-child { border-top: 0; background: #123f64;
    color: #fff; padding: 12px; font-size: 16px; }
  #cases-view .cases-table tbody td:first-child .secondary-line { color: #dbeaf6; }
  #cases-view .cases-table tbody td:nth-child(2) { font-weight: 750; font-size: 15px; }
  #cases-view .cases-table tbody td:nth-child(3),
  #cases-view .cases-table tbody td:nth-child(4),
  #cases-view .cases-table tbody td:nth-child(5),
  #cases-view .cases-table tbody td:nth-child(12),
  #cases-view .cases-table tbody td:nth-child(9),
  #cases-view .cases-table tbody td:nth-child(10) { display: none; }
  #cases-view .cases-table tbody td:nth-child(6)::before,
  #cases-view .cases-table tbody td:nth-child(8)::before,
  #cases-view .cases-table tbody td:nth-child(11)::before,
  #cases-view .cases-table tbody td:nth-child(7)::before {
    display: block; font-size: 10px; font-weight: 800; letter-spacing: .06em;
    text-transform: uppercase; color: #687e90; margin-bottom: 5px; }
  #cases-view .cases-table tbody td:nth-child(6)::before { content: 'Next action'; }
  #cases-view .cases-table tbody td:nth-child(8)::before { content: 'Report'; }
  #cases-view .cases-table tbody td:nth-child(11)::before { content: 'Crash location'; }
  #cases-view .cases-table tbody td:nth-child(7)::before { content: 'Case status'; }
  #cases-view .cases-table tbody td:last-child { margin-top: auto; background: #f8fafc; }
  #cases-view .cases-table tbody .row-actions { display: flex; gap: 7px; }
  #cases-view .cases-table tbody .row-actions .button { flex: 1 1 auto; min-height: 40px;
    font-size: 12px; white-space: normal; padding: 8px; }

  /* Inspection map and popups */
  #map-view .map-heading { gap: 12px; flex-wrap: wrap; }
  #map-view .map-actions { flex-wrap: wrap; }
  #map-view #map { height: min(65dvh, 640px); min-height: 390px; }
  #map-view .map-legend { gap: 10px 12px; }
  .leaflet-popup-content-wrapper { max-width: calc(100vw - 42px); }

  /* Full case workspace, intake and inspection forms */
  .modal { padding: 10px; overflow: hidden; align-items: center; }
  .modal-surface, .modal-surface.small, .modal-surface.medium,
  .modal-surface.xlarge { width: 100%; max-width: 100%; max-height: calc(100dvh - 20px);
    overflow-y: auto; overscroll-behavior: contain; }
  .modal-heading { gap: 12px; flex-wrap: wrap; }
  .workspace-heading-actions { flex-wrap: wrap; gap: 7px; }
  .workspace-summary-grid, .setup-checks { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .overview-grid, .four-column, .admin-date-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .two-column, .three-column { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .vehicle-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .material-row { grid-template-columns: minmax(0,1fr) minmax(0,1fr); }
  .material-row > :last-child { grid-column: 1/-1; }
  .activity-item { grid-template-columns: minmax(100px, 140px) minmax(0,1fr); }
  .task-card, .report-card, .inspection-row-card { flex-wrap: wrap; }
  .inspection-cdr-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .form-actions { flex-wrap: wrap; }

  /* PDF intake / review: dynamically injected rules must be overridden with
     a higher-specificity scoped selector. No new review screens. */
  #document-import-modal.document-import-modal { padding: 10px; align-items: center; }
  #document-import-modal .document-import-surface { width: 100%; max-width: 980px;
    max-height: calc(100dvh - 20px); border-radius: 13px; padding: 15px;
    overscroll-behavior: contain; }
  #document-import-modal .document-import-header { flex-wrap: wrap; }
  #document-import-modal .document-import-header p { overflow-wrap: anywhere; }
  #document-import-modal .document-import-row { grid-template-columns: 26px minmax(0,1fr);
    gap: 6px 10px; }
  #document-import-modal .document-import-row > .document-import-current,
  #document-import-modal .document-import-row > .document-import-value { grid-column: 2; min-width:0; }
  #document-import-modal .document-import-vehicle { grid-template-columns: 26px minmax(0,1fr); }
  #document-import-modal .document-import-vehicle > .document-import-status-pill { grid-column:2;justify-self:start; }
  #document-import-modal .document-import-edit-fields { grid-template-columns: repeat(2,minmax(0,1fr)); }
  #document-import-modal .document-import-edit-fields .span-3 { grid-column:1/-1; }
  #document-import-modal .document-import-edit-fields input,
  #document-import-modal .document-import-edit-fields select,
  #document-import-modal .document-import-edit-fields textarea { min-height: 40px; }
  #document-import-modal .document-import-actions { position: sticky; bottom: -15px;
    z-index: 2; border-top: 1px solid #e2e8f0; padding: 11px 0; gap: 9px;
    flex-wrap: wrap; }
  #document-import-modal .document-import-actions .button { flex: 1 1 auto; }

  /* Landing page / home tiles */
  .hub-shell { padding: 0 14px 24px; }
  .hub-brand { padding: 18px 0; }
  .hub-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 15px; }
  .hub-tile { min-height: 120px; padding: 18px; gap: 13px;
    border-radius: 10px; }
  .hub-tile strong { font-size: 18px; }
  .hub-tile .tile-icon { flex: none; }
  .hub-topbar { gap: 12px; }

  /* Embedded Report Writing and Research pages */
  body.embedded-body .app-shell { padding: 10px 2px 18px; }
  body.embedded-body .page { padding: 9px 2px 18px; }
  body.embedded-body .builder-layout { grid-template-columns: minmax(0,1fr); }
  body.embedded-body .builder-nav { position: static; display: flex;
    flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity; gap: 6px; padding: 9px; }
  body.embedded-body .builder-nav .case-chip { flex: 0 0 170px; padding: 7px 9px;
    border-right: 1px solid #e1e8ed; border-bottom: 0; margin: 0; }
  body.embedded-body .builder-nav .section-button { flex: 0 0 auto; width: auto;
    border: 1px solid #dce6ec; border-radius: 7px; white-space: nowrap;
    scroll-snap-align: start; }
  body.embedded-body .field-grid { grid-template-columns: 1fr; }
  body.embedded-body .field { min-width:0; }
  body.embedded-body .panel-heading, body.embedded-body .page-heading,
  body.embedded-body .builder-heading { flex-wrap: wrap; gap: 9px; }
  body.embedded-body .report-filters, body.embedded-body .research-filters { grid-template-columns: repeat(2,minmax(0,1fr)); }
  body.embedded-body .cdr-filters { grid-template-columns: repeat(3,minmax(0,1fr)); }
  body.embedded-body .stats { grid-template-columns: repeat(2,minmax(0,1fr)); }
  body.embedded-body .review-grid, body.embedded-body .cards { grid-template-columns: 1fr; }
  body.embedded-body .builder-footer { flex-wrap: wrap; }
  body.embedded-body .material-line { grid-template-columns: 1fr; }
  body.embedded-body .report-dialog { width: min(94vw,720px); max-height:calc(100dvh - 20px); }

  /* Embedded data tables become labeled, readable cards, rather than tiny text. */
  body.embedded-body .cases-table-wrap { max-height:none; overflow:visible; border:0; }
  body.embedded-body .cases-table.report-table,
  body.embedded-body .cases-table.cdr-table,
  body.embedded-body .cases-table.research-table { display:block; min-width:0; width:100%; }
  body.embedded-body .report-table thead,
  body.embedded-body .cdr-table thead,
  body.embedded-body .research-table thead { display:none; }
  body.embedded-body .report-table tbody,
  body.embedded-body .cdr-table tbody,
  body.embedded-body .research-table tbody { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:11px; }
  body.embedded-body .report-table tbody tr,
  body.embedded-body .cdr-table tbody tr,
  body.embedded-body .research-table tbody tr { display:flex; flex-direction:column;
    min-width:0; border:1px solid #d3dfe8; border-radius:11px;
    overflow:hidden; background:#fff; box-shadow:0 2px 9px rgba(20,50,75,.06); }
  body.embedded-body .report-table tbody td,
  body.embedded-body .cdr-table tbody td,
  body.embedded-body .research-table tbody td { display:block; min-width:0; padding:8px 11px;
    border:0; border-top:1px solid #edf2f6; overflow-wrap:anywhere; font-size:13px; }
  body.embedded-body .report-table tbody td:first-child,
  body.embedded-body .cdr-table tbody td:first-child,
  body.embedded-body .research-table tbody td:first-child { border-top:0; color:#fff;
    background:#123f64; font-weight:800; }
  body.embedded-body .report-table tbody td:nth-child(2),
  body.embedded-body .cdr-table tbody td:nth-child(2),
  body.embedded-body .research-table tbody td:nth-child(2) { font-weight:700; }
  body.embedded-body .report-table tbody td::before,
  body.embedded-body .cdr-table tbody td::before,
  body.embedded-body .research-table tbody td::before { display:block;
    color:#667b8d; font-size:10px; font-weight:800; text-transform:uppercase;
    letter-spacing:.04em; margin-bottom:3px; }
  body.embedded-body .report-table tbody td:first-child::before,
  body.embedded-body .cdr-table tbody td:first-child::before,
  body.embedded-body .research-table tbody td:first-child::before { color:#d9eafa; }
  body.embedded-body .report-table tbody td:nth-child(1)::before { content:'Case #'; }
  body.embedded-body .report-table tbody td:nth-child(2)::before { content:'Case name'; }
  body.embedded-body .report-table tbody td:nth-child(3)::before { content:'Attorney'; }
  body.embedded-body .report-table tbody td:nth-child(4)::before { content:'Firm'; }
  body.embedded-body .report-table tbody td:nth-child(5)::before { content:'Vehicles'; }
  body.embedded-body .report-table tbody td:nth-child(6)::before { content:'Status'; }
  body.embedded-body .report-table tbody td:nth-child(7)::before { content:'Missing'; }
  body.embedded-body .report-table tbody td:nth-child(8)::before { content:'Updated'; }
  body.embedded-body .report-table tbody td:nth-child(9)::before { content:'Action'; }
  body.embedded-body .cdr-table tbody td:nth-child(1)::before { content:'Year'; }
  body.embedded-body .cdr-table tbody td:nth-child(2)::before { content:'Make / Model'; }
  body.embedded-body .cdr-table tbody td:nth-child(3)::before { content:'Module'; }
  body.embedded-body .cdr-table tbody td:nth-child(4)::before { content:'Software'; }
  body.embedded-body .cdr-table tbody td:nth-child(5)::before { content:'Interface'; }
  body.embedded-body .cdr-table tbody td:nth-child(6)::before { content:'DLC / OBD'; }
  body.embedded-body .cdr-table tbody td:nth-child(7)::before { content:'Direct to Module'; }
  body.embedded-body .cdr-table tbody td:nth-child(8)::before { content:'Module Location'; }
  body.embedded-body .cdr-table tbody td:nth-child(9)::before { content:'Market'; }
  body.embedded-body .research-table tbody td:nth-child(1)::before { content:'Title / Citation'; }
  body.embedded-body .research-table tbody td:nth-child(2)::before { content:'Category'; }
  body.embedded-body .research-table tbody td:nth-child(3)::before { content:'Topic'; }
  body.embedded-body .research-table tbody td:nth-child(4)::before { content:'Author / Source'; }
  body.embedded-body .research-table tbody td:nth-child(5)::before { content:'Year'; }
  body.embedded-body .research-table tbody td:nth-child(6)::before { content:'Notes'; }
  body.embedded-body .research-table tbody td:nth-child(7)::before { content:'Added'; }
  body.embedded-body .research-table tbody td:nth-child(8)::before { content:'Action'; }
  body.embedded-body .report-table tbody td:last-child,
  body.embedded-body .research-table tbody td:last-child { margin-top:auto; }
}

@media screen and (max-width: 700px) {
  /* Phones */
  #app-view.app-shell { padding: 8px; }
  #app-view .topbar { padding:12px; }
  #app-view .topbar h1 { font-size:20px; }
  #app-view .user-controls { display:grid; grid-template-columns:repeat(2,minmax(0,1fr));
    width:100%; gap:7px; }
  #app-view .user-controls .user-chip { grid-column:1/-1; grid-row:2; text-align:center; }
  #app-view .user-controls .button { padding:9px; white-space:normal; }
  #app-view > .metrics { grid-template-columns:repeat(2,minmax(0,1fr)); gap:7px; }
  #app-view > .metrics .metric-card { padding:10px; }
  #app-view > .metrics .metric-card strong { font-size:20px; }
  #app-view .operations-nav .view-tab { padding:10px 13px; }
  #cases-view.main-panel, #map-view.map-panel { padding:10px; }
  #cases-view .case-filters { grid-template-columns:1fr; }
  #cases-view .cases-table tbody { grid-template-columns:1fr; }
  #cases-view .cases-table tbody td { padding:9px 11px; }
  #map-view #map { min-height:340px; height:min(56dvh,520px); }
  #map-view .map-heading { align-items:flex-start; }
  #map-view .map-actions { width:100%; }
  .modal { padding:0; }
  .modal-surface, .modal-surface.small, .modal-surface.medium,
  .modal-surface.xlarge { width:100%; max-height:100dvh; height:100dvh;
    border-radius:0; border:0; padding:14px 12px calc(16px + env(safe-area-inset-bottom,0px)); }
  .modal-heading { align-items:flex-start; }
  .modal-heading h2 { font-size:20px; }
  .workspace-heading-actions { max-width:100%; }
  .workspace-heading-actions .button { flex:1 1 auto; }
  .workspace-heading-actions .modal-close { min-width:40px; }
  .workspace-summary-grid, .overview-grid, .setup-checks, .setup-checks-dated,
  .two-column, .three-column, .four-column, .admin-date-grid,
  .vehicle-grid { grid-template-columns:1fr; }
  .detail-card.wide { grid-column:auto; }
  .material-row { grid-template-columns:1fr; }
  .activity-item { grid-template-columns:1fr; gap:4px; }
  .task-card, .report-card, .inspection-row-card { flex-direction:column; }
  .setup-check.dated, .inspection-cdr-grid { grid-template-columns:1fr; }
  .form-actions { justify-content:stretch; }
  .form-actions .button { flex:1 1 auto; }
  .toast { left:8px; right:8px; max-width:none; bottom:calc(8px + env(safe-area-inset-bottom,0px)); }
  #document-import-modal.document-import-modal { padding:0; }
  #document-import-modal .document-import-surface { width:100vw; max-width:none;
    max-height:100dvh; height:100dvh; border-radius:0;
    padding:12px 12px calc(16px + env(safe-area-inset-bottom,0px)); }
  #document-import-modal .document-import-grid,
  #document-import-modal .document-import-edit-fields { grid-template-columns:1fr; }
  #document-import-modal .document-import-edit-fields .span-2,
  #document-import-modal .document-import-edit-fields .span-3 { grid-column:1/-1; }
  #document-import-modal .document-import-edit-fields .document-import-vin-line > input { min-width:0; }
  #document-import-modal .document-import-actions { bottom:-12px; }
  #document-import-modal .document-import-actions .button { flex:1 1 140px; }
  #document-import-modal input, #document-import-modal textarea,
  #document-import-modal select, .modal input, .modal select,
  .modal textarea, #app-view input, #app-view select, #app-view textarea { font-size:16px; }
  .hub-shell { padding:0 12px 22px; }
  .hub-grid { grid-template-columns:1fr; gap:10px; }
  .hub-tile { padding:14px; min-height:96px; }
  .hub-tile strong { font-size:17px; }
  .hub-tile .tile-icon { font-size:30px; width:38px; }
  .hub-topbar { align-items:flex-start; flex-wrap:wrap; }
  .hub-user { gap:6px; flex-wrap:wrap; align-items:center; }
  .hub-brand { padding:13px 0; }
  .hub-brand .main-logo { width:min(360px,90vw); }

  /* Embedded content on phone */
  body.embedded-body .page { padding:8px 1px 16px; }
  body.embedded-body .report-filters,
  body.embedded-body .cdr-filters,
  body.embedded-body .research-filters,
  body.embedded-body .stats { grid-template-columns:1fr; }
  body.embedded-body .report-table tbody,
  body.embedded-body .cdr-table tbody,
  body.embedded-body .research-table tbody { grid-template-columns:1fr; }
  body.embedded-body .builder-panel-heading { flex-wrap:wrap; }
  body.embedded-body .builder-nav .section-button { font-size:12px; }
  body.embedded-body .field { grid-template-columns:19px minmax(0,1fr) auto; gap:6px; }
  body.embedded-body .field > label:not(.na-toggle) { grid-column:2; }
  body.embedded-body .field input:not([data-na-path]),
  body.embedded-body .field select, body.embedded-body .field textarea,
  body.embedded-body .field small { grid-column:2; }
  body.embedded-body .field .na-toggle { grid-column:3; grid-row:1 / span 2; }
  body.embedded-body .builder-footer .button { flex:1 1 160px; }
  body.embedded-body .report-dialog { width:100vw; max-height:100dvh; border-radius:0; }
  body.embedded-body input, body.embedded-body select,
  body.embedded-body textarea { font-size:16px; }
}

@media screen and (max-width: 380px) {
  #app-view .user-controls { grid-template-columns:1fr; }
  #app-view .user-controls .user-chip { grid-row:auto; }
  #document-import-modal .document-import-actions { flex-direction:column; }
}


/* v2.55: PHONE LIST REFINEMENTS ONLY. Keep tablet/desktop and storage logic untouched. */
@media screen and (max-width: 700px) {
  /* A slim dashboard strip makes the case list visible without three rows of metrics. */
  #app-view > .metrics {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    padding-bottom: 5px;
    scroll-snap-type: x proximity;
  }
  #app-view > .metrics .metric-card {
    flex: 0 0 143px;
    min-width: 143px;
    scroll-snap-align: start;
  }

  /* Case list: one tap opens full workspace. Show only case #, name, attorney, firm. */
  #cases-view .list-heading .helper { display: none; }
  #cases-view .case-filters {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  #cases-view .case-filters > label:first-child { grid-column: 1 / -1; }
  #cases-view .cases-table tbody tr.case-row {
    gap: 0;
    cursor: pointer;
    border-color: #bbcedc;
    touch-action: manipulation;
  }
  #cases-view .cases-table tbody td,
  #cases-view .cases-table tbody td:nth-child(6),
  #cases-view .cases-table tbody td:nth-child(8),
  #cases-view .cases-table tbody td:nth-child(11),
  #cases-view .cases-table tbody td:nth-child(7),
  #cases-view .cases-table tbody td:last-child { display: none; }
  #cases-view .cases-table tbody td:nth-child(1),
  #cases-view .cases-table tbody td:nth-child(2),
  #cases-view .cases-table tbody td:nth-child(3),
  #cases-view .cases-table tbody td:nth-child(4) {
    display: block;
    min-width: 0;
    width: 100%;
    overflow-wrap: anywhere;
  }
  #cases-view .cases-table tbody td:nth-child(1) {
    border: 0;
    padding: 11px 13px;
    position: relative;
  }
  #cases-view .cases-table tbody td:nth-child(1)::after {
    content: '›';
    position: absolute;
    right: 13px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 27px;
    line-height: 1;
    font-weight: 400;
    color: #fff;
  }
  #cases-view .cases-table tbody td:nth-child(1) .secondary-line { display: none; }
  #cases-view .cases-table tbody td:nth-child(2) {
    font-size: 15px;
    font-weight: 750;
    line-height: 1.35;
    border-top: 0;
    padding: 10px 13px 7px;
  }
  #cases-view .cases-table tbody td:nth-child(3),
  #cases-view .cases-table tbody td:nth-child(4) {
    font-size: 13px;
    padding: 6px 13px;
    line-height: 1.35;
    border-top: 0;
    font-weight: 500;
  }
  #cases-view .cases-table tbody td:nth-child(4) { padding-bottom: 13px; }
  #cases-view .cases-table tbody td:nth-child(3)::before,
  #cases-view .cases-table tbody td:nth-child(4)::before {
    display: inline;
    font-size: 11px;
    text-transform: none;
    letter-spacing: 0;
    font-weight: 750;
    color: #637d91;
    margin-right: 6px;
  }
  #cases-view .cases-table tbody td:nth-child(3)::before { content: 'Attorney:'; }
  #cases-view .cases-table tbody td:nth-child(4)::before { content: 'Firm:'; }
  #cases-view .cases-table tbody tr.case-row:active { background: #f1f7fb; }

  /* Inspection worklist: each inspection becomes a readable touch card. */
  #open-inspections-page { min-width: 0; }
  #open-inspections-page > .section-heading { display: grid; gap: 10px; }
  #open-inspections-page > .section-heading > div:last-child {
    width: 100%;
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px !important;
    align-items: stretch !important;
    justify-content: stretch !important;
  }
  #open-inspections-page > .section-heading > div:last-child > #open-inspections-count {
    grid-column: 1 / -1;
    line-height: 1.4;
  }
  #open-inspections-page > .section-heading > div:last-child > #inspection-build-badge { display:none; }
  #open-inspections-page > .section-heading > div:last-child .button {
    width:100%; min-width: 0; white-space: normal; line-height: 1.3;
    min-height: 43px; padding: 8px 7px;
  }
  #open-inspections-page #inspection-worklist-filters,
  #open-inspections-page #completed-inspection-filters {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }
  #open-inspections-page #inspection-worklist-filters > label:first-child,
  #open-inspections-page #completed-inspection-filters > label:first-child {
    grid-column: 1 / -1;
  }
  #open-inspections-page #inspection-worklist-filters label,
  #open-inspections-page #completed-inspection-filters label { min-width: 0; }
  #open-inspections-page #inspection-worklist-filters select,
  #open-inspections-page #completed-inspection-filters select {
    width: 100%; min-width: 0; text-overflow: ellipsis;
  }
  #open-inspections-page #inspection-sort-summary { line-height: 1.4; }
  #open-inspections-page #inspection-worklist-wrap,
  #open-inspections-page #completed-inspections-wrap {
    max-height: none;
    overflow: visible;
    border: 0;
    border-radius: 0;
    scrollbar-gutter: auto;
  }
  #open-inspections-page #inspection-worklist-table,
  #open-inspections-page #completed-inspections-table {
    display: block;
    width: 100%;
    min-width: 0;
    border: 0;
  }
  #open-inspections-page #inspection-worklist-table thead {
    display: block;
    margin-bottom: 10px;
  }
  #open-inspections-page #inspection-worklist-table thead tr {
    display: flex; gap: 8px; flex-wrap: wrap;
  }
  #open-inspections-page #inspection-worklist-table thead th { display: none; }
  #open-inspections-page #inspection-worklist-table thead th:first-child,
  #open-inspections-page #inspection-worklist-table thead th:nth-child(8) {
    display: flex; align-items: center;
    position: static;
    min-width: 0;
    white-space: normal;
    padding: 8px 10px;
    background: #eef4f9;
    border: 1px solid #cedce7;
    border-radius: 7px;
    color: #24455f;
  }
  #open-inspections-page #inspection-worklist-table thead th button {
    width: 100%; min-height: 28px; justify-content: center;
    white-space: normal; text-align: center;
  }
  #open-inspections-page #inspection-worklist-table tbody,
  #open-inspections-page #completed-inspections-table tbody {
    display: grid;
    grid-template-columns: minmax(0,1fr);
    gap: 12px;
    width: 100%;
  }
  #open-inspections-page #inspection-worklist-table tbody tr.case-row,
  #open-inspections-page #completed-inspections-table tbody tr.case-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0,1fr));
    min-width: 0;
    overflow: hidden;
    border-radius: 12px;
    border: 1px solid #cbd9e4;
    background: #fff;
    box-shadow: 0 2px 10px rgba(25,55,80,.07);
  }
  #open-inspections-page #inspection-worklist-table tbody td,
  #open-inspections-page #completed-inspections-table tbody td {
    display: block;
    width: 100%;
    min-width: 0;
    padding: 9px 12px;
    border: 0;
    border-top: 1px solid #eef2f6;
    background: #fff;
    font-size: 13px;
    overflow-wrap: anywhere;
    line-height: 1.4;
  }
  #open-inspections-page #inspection-worklist-table tbody td strong,
  #open-inspections-page #completed-inspections-table tbody td strong { font-size: inherit; }
  #open-inspections-page #inspection-worklist-table tbody .secondary-line,
  #open-inspections-page #completed-inspections-table tbody .secondary-line {
    color: #657d90; max-width: 100%; white-space: normal;
  }
  #open-inspections-page #inspection-worklist-table tbody td::before,
  #open-inspections-page #completed-inspections-table tbody td::before {
    display: block;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .045em;
    color: #637c90;
    margin: 0 0 4px;
  }
  #open-inspections-page #inspection-worklist-table tbody td .workstream-line {
    display: flex; flex-wrap: wrap; gap: 6px; min-width: 0;
  }

  /* Open inspections: case header, then two-column status/date. */
  #open-inspections-page #inspection-worklist-table tbody td:nth-child(1),
  #open-inspections-page #inspection-worklist-table tbody td:nth-child(2) {
    background: #123f64; color:#fff; border-top:0;
  }
  #open-inspections-page #inspection-worklist-table tbody td:nth-child(1) {
    grid-column: 1; font-weight: 800;
  }
  #open-inspections-page #inspection-worklist-table tbody td:nth-child(2) {
    grid-column: 2; font-size: 12px;
  }
  #open-inspections-page #inspection-worklist-table tbody td:nth-child(3),
  #open-inspections-page #inspection-worklist-table tbody td:nth-child(4),
  #open-inspections-page #inspection-worklist-table tbody td:nth-child(9),
  #open-inspections-page #inspection-worklist-table tbody td:nth-child(10) {
    grid-column: 1 / -1;
  }
  #open-inspections-page #inspection-worklist-table tbody td:nth-child(5),
  #open-inspections-page #inspection-worklist-table tbody td:nth-child(6) {
    display: none;
  }
  #open-inspections-page #inspection-worklist-table tbody td:nth-child(7),
  #open-inspections-page #inspection-worklist-table tbody td:nth-child(8) {
    grid-column: auto;
  }
  #open-inspections-page #inspection-worklist-table tbody td:nth-child(3)::before { content:'Inspection'; }
  #open-inspections-page #inspection-worklist-table tbody td:nth-child(4)::before { content:'Vehicle / Location'; }
  #open-inspections-page #inspection-worklist-table tbody td:nth-child(7)::before { content:'Status'; }
  #open-inspections-page #inspection-worklist-table tbody td:nth-child(8)::before { content:'Date'; }
  #open-inspections-page #inspection-worklist-table tbody td:nth-child(9)::before { content:'Assigned'; }
  #open-inspections-page #inspection-worklist-table tbody td:nth-child(10)::before { content:'Actions'; }
  #open-inspections-page #inspection-worklist-table tbody select[data-inspection-status-select] {
    max-width: 100%; min-width: 0; width: 100%;
    min-height: 43px; font-size: 16px;
  }
  #open-inspections-page #inspection-worklist-table tbody .row-actions,
  #open-inspections-page #completed-inspections-table tbody .row-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0,1fr));
    gap: 8px;
  }
  #open-inspections-page #inspection-worklist-table tbody .row-actions .button,
  #open-inspections-page #completed-inspections-table tbody .row-actions .button {
    width: 100%; min-height: 43px;
    padding: 8px 7px; font-size: 12px; white-space: normal;
  }

  /* Completed inspections: same readable card structure. */
  #open-inspections-page #completed-inspections-table thead { display: none; }
  #open-inspections-page #completed-inspections-table tbody td:nth-child(1),
  #open-inspections-page #completed-inspections-table tbody td:nth-child(2) {
    grid-column: 1; background: #123f64; color: #fff; border-top: 0;
  }
  #open-inspections-page #completed-inspections-table tbody td:nth-child(2) {
    grid-column: 2; grid-row: 1; font-weight: 800;
  }
  #open-inspections-page #completed-inspections-table tbody td:nth-child(1) {
    grid-row: 1;
  }
  #open-inspections-page #completed-inspections-table tbody td:nth-child(3),
  #open-inspections-page #completed-inspections-table tbody td:nth-child(4),
  #open-inspections-page #completed-inspections-table tbody td:nth-child(5),
  #open-inspections-page #completed-inspections-table tbody td:nth-child(8),
  #open-inspections-page #completed-inspections-table tbody td:nth-child(9) {
    grid-column: 1 / -1;
  }
  #open-inspections-page #completed-inspections-table tbody td:nth-child(6),
  #open-inspections-page #completed-inspections-table tbody td:nth-child(7) { display: none; }
  #open-inspections-page #completed-inspections-table tbody td:nth-child(1)::before { content:'Completed'; color:#dbeaf6; }
  #open-inspections-page #completed-inspections-table tbody td:nth-child(2)::before { content:'Case #'; color:#dbeaf6; }
  #open-inspections-page #completed-inspections-table tbody td:nth-child(3)::before { content:'Case name'; }
  #open-inspections-page #completed-inspections-table tbody td:nth-child(4)::before { content:'Inspection'; }
  #open-inspections-page #completed-inspections-table tbody td:nth-child(5)::before { content:'Vehicle / Location'; }
  #open-inspections-page #completed-inspections-table tbody td:nth-child(8)::before { content:'Assigned'; }
  #open-inspections-page #completed-inspections-table tbody td:nth-child(9)::before { content:'Actions'; }

  /* Excel import preview is a dense spreadsheet; keep it scrollable, not broken. */
  #open-inspections-page #inspection-excel-import-panel .cases-table-wrap {
    overflow-x: auto; overflow-y: auto; max-width: 100%;
    -webkit-overflow-scrolling: touch;
  }
  #open-inspections-page #inspection-excel-import-panel .cases-table { min-width: 1160px; }
}

/* v2.57: keep the stop-work cue visible on tablet/phone case cards. */
@media screen and (max-width: 1023px), screen and (max-width: 1199px) and (pointer: coarse) {
  #cases-view .cases-table tbody tr.case-row.case-closed-or-archived {
    background: #fff0f1;
    border-color: #e8b7bd;
  }
  #cases-view .cases-table tbody tr.case-row.case-closed-or-archived td:first-child,
  #cases-view .cases-table tbody tr.case-row.case-closed-or-archived:hover td:first-child {
    background: #8b404b;
    color: #fff;
  }
  #cases-view .cases-table tbody tr.case-row.case-closed-or-archived td:first-child .secondary-line {
    color: #ffe6e9;
  }
}
