/* Phone layouts for existing portal features. Desktop rules and business flows stay owned by their original modules. */
@media (max-width:760px) {
  /* Native text controls need a readable size and room to shrink inside cards. */
  html body[data-portal-design] :is(input:not([type="checkbox"],[type="radio"],[type="range"],[type="hidden"]),select,textarea) {
    min-width:0;
    max-width:100%;
    font-size:16px;
  }
  html body[data-portal-design] :is(input:not([type="checkbox"],[type="radio"],[type="range"],[type="hidden"]),select) {min-height:44px}
  html body[data-portal-design] :is(textarea,fieldset) {min-width:0}
  html body[data-portal-design] :is(.portal-card,.campaign-card,.auth-card,.owner-surface,.filter-card,.score-panel,.payroll-card,.workflow-row,.lead-workspace) {min-width:0}
  html body[data-portal-design] :is(.portal-card,.campaign-card) {padding:18px}
  html body[data-portal-design] :is(.portal-card,.campaign-card,.owner-manage,.record-head,.lead-intake-intro) :is(h2,h3,h4,p) {overflow-wrap:anywhere}
  html body[data-portal-design] :is(.primary,.secondary,.text-action,.lead-title,.manage-client,.owner-reload,.crm-btn,.client-view,.target-edit,.filter-pill,.seller,.qc-record,.score-link,.lead-intake-status) {
    min-height:44px;
    white-space:normal;
    overflow-wrap:anywhere;
    touch-action:manipulation;
  }
  html body[data-portal-design] a:is(.primary,.secondary,.crm-btn,.client-view,.score-link,.lead-intake-status) {display:inline-flex;align-items:center}
  html body[data-portal-design] :is(.section-heading,.detail-head,.filter-head,.filter-footer,.results-head,.report-list-heading,.shuffle-heading,.work-head,.qc-meta,.qc-actions,.ticket-tools,.dialog-actions,.delivery-actions,.pagination,.paging) {flex-wrap:wrap}
  html body[data-portal-design] :is(.section-heading,.detail-head,.filter-head,.results-head,.shuffle-heading,.work-head) > :is(h1,h2,h3,div) {min-width:0}
  html body[data-portal-design] .section-heading > :first-child {flex:1 1 11rem}
  html body[data-portal-design] :is(.pagination,.paging) {gap:8px 12px}
  html body[data-portal-design] :is(.pagination,.paging) > :is(button,span) {flex-shrink:0}

  /* Client overview, leads and campaign details. */
  html body[data-portal-design] .stat-grid {grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}
  html body[data-portal-design] .stat-grid article {min-width:0;padding:15px 13px}
  html body[data-portal-design] .stat-grid strong {font-size:clamp(1.8rem,7vw,2.5rem);overflow-wrap:anywhere}
  html body[data-portal-design] .stat-grid article > span {align-items:flex-start;gap:6px}
  html body[data-portal-design] :is(.campaign-list,.portal-grid,.support-grid) {grid-template-columns:minmax(0,1fr)}
  html body[data-portal-design] .campaign-card > div {flex-wrap:wrap;align-items:flex-start}
  html body[data-portal-design] .campaign-card h3 {flex:1 1 10rem;min-width:0}
  html body[data-portal-design] .lead-list > .lead-row {flex-wrap:wrap;padding:16px}
  html body[data-portal-design] .lead-list > .lead-row > div:first-child {flex:1 1 100%;min-width:0}
  html body[data-portal-design] .lead-list > .lead-row > div:last-child {display:flex;align-items:center;gap:8px 16px;flex-wrap:wrap;text-align:left;max-width:100%}
  html body[data-portal-design] .lead-list > .lead-row > div:last-child p {margin:0}
  html body[data-portal-design] .lead-row a[href^="tel:"] {display:inline-flex;align-items:center;min-height:44px}
  html body[data-portal-design] .lead-list .status-pill {white-space:normal}
  html body[data-portal-design] .detail-grid {grid-template-columns:minmax(0,1fr);gap:14px}
  html body[data-portal-design] .long-notes {padding:14px;font-size:14px}
  html body[data-portal-design] .dispute-card {padding:16px}
  html body[data-portal-design] :is(.dispute-card,.workflow-row,.filter-card,.lead-intake-help,.day-details,.score-guide) > summary {min-height:44px;padding-block:10px}
  html body[data-portal-design] .desk-quick :is(a,button) {min-height:44px}
  html body[data-portal-design] .desk-identity > div {min-width:0}
  html body[data-portal-design] .desk-hero h1 {overflow-wrap:anywhere;font-size:clamp(1.85rem,7.6vw,2.55rem)}
  html body[data-portal-design] .desk-hero-actions a {min-height:46px;white-space:normal;text-align:center}

  /* Filters and management lists keep their actual controls instead of squeezing labels. */
  html body[data-portal-design] :is(.lead-filters,.filter-grid,.qc-filters,.workflow-controls,.workflow-edit,.score-form,.pay-fields,.provider-grid) > * {min-width:0}
  html body[data-portal-design] :is(.owner-tabs,.archive-tabs,#provider-tabs) {gap:4px;flex-wrap:wrap}
  html body[data-portal-design] :is(.owner-tabs,.archive-tabs,#provider-tabs) :is(a,button) {min-height:44px;padding:11px 10px}
  html body[data-portal-design] :is(.owner-tools,.client-footer,.head-actions,.staff-edit-actions,.filter-actions) {flex-wrap:wrap;gap:8px}
  html body[data-portal-design] :is(.owner-tools,.client-footer,.head-actions) :is(a,button) {min-height:44px;white-space:normal}
  html body[data-portal-design] .client-record {grid-template-columns:minmax(0,1fr) auto}
  html body[data-portal-design] .client-actions {max-width:8.5rem}
  html body[data-portal-design] .client-actions .manage-client {min-width:76px}
  html body[data-portal-design] .billing-metrics {gap:10px 12px}
  html body[data-portal-design] .billing-metrics > div {min-width:0}
  html body[data-portal-design] :is(.report-dates,.report-filters,.delivery-tools,.score-controls,#relations-controls,.ticket-tools) > label {min-width:0;max-width:100%}
  html body[data-portal-design] .delivery-tools > label {flex:1 1 12rem}
  html body[data-portal-design] .activity-page {width:100%;min-width:0;padding:20px var(--gutter,16px) 32px}
  html body[data-portal-design] .activity-page form {gap:12px}
  html body[data-portal-design] .activity-page form label {min-width:0;flex:1 1 13rem;max-width:100%;margin:0}
  html body[data-portal-design] .activity-page :is(select,input) {width:100%;max-width:100%}
  html body[data-portal-design] .activity-page section {min-width:0;padding:14px}
  html body[data-portal-design] .activity-page h1 {font-size:clamp(1.9rem,7vw,2.65rem)}
  html body[data-portal-design] .day-axis {font-size:11px}
  html body[data-portal-design] .day-segment {overflow-wrap:anywhere}

  /* Wide data tables scroll locally, without widening or clipping the whole page. */
  html body[data-portal-design] :is(.archive-table,.qc-table,.payroll-scroll,.delivery-table-wrap,.mobile-table-scroll) {
    min-width:0;
    max-width:100%;
    overflow:auto;
    overscroll-behavior-x:contain;
    -webkit-overflow-scrolling:touch;
  }
  html body[data-portal-design] .mobile-table-scroll table {min-width:420px}
  html body[data-portal-design] .mobile-table-scroll :is(td,th) {overflow-wrap:anywhere}
  html body[data-portal-design] .mobile-scroll-hint {margin:6px 0;color:var(--muted,#646b6e);font-size:12px;line-height:1.5}
  html body[data-portal-design] .delivery-table tr > :first-child {position:static}
  html body[data-portal-design] :is(.archive-table,.qc-table) :is(.seller,.qc-record) {padding-block:6px}

  /* Owner CRM list/detail already has a dedicated mobile switch. */
  html body[data-portal-design] #prospect-view .lead-controls {gap:10px;padding:12px}
  html body[data-portal-design] #prospect-view .lead-controls .lead-search {flex:1 1 100%}
  html body[data-portal-design] #prospect-view .mode-switch {width:100%}
  html body[data-portal-design] #prospect-view .mode-switch button {flex:1}
  html body[data-portal-design] #prospect-view :is(button,.crm-btn) {min-height:44px}
  html body[data-portal-design] #prospect-view .lead-controls :is(input,select) {font-size:16px;min-height:44px}
  html body[data-portal-design] #lead-editor :is(input,select,textarea) {font-size:16px;min-width:0;max-width:100%}
  html body[data-portal-design] #lead-editor :is(input,select) {min-height:44px}
  html body[data-portal-design] #lead-editor button {min-height:44px}
  html body[data-portal-design] :is(#relations-controls,#relations-edit) :is(input,select,textarea) {font-size:16px;min-height:44px}
  html body[data-portal-design] #lead-editor #cancel-edit {min-width:44px}
  html body[data-portal-design] #prospect-view .detail-tabs {gap:4px 16px}
  html body[data-portal-design] #prospect-view .detail-tabs button {padding-inline:5px}
  html body[data-portal-design] #prospect-view :is(.crm-points,.lead-fields) {grid-template-columns:minmax(0,1fr);gap:4px}
  html body[data-portal-design] #prospect-view :is(.crm-points,.lead-fields) dd {margin-bottom:10px}
  html body[data-portal-design] #prospect-view .crm-call audio {min-width:0;width:100%}

  /* Employee forms, rosters and compact management panels. */
  html body[data-portal-design] .staff-directory {grid-template-columns:minmax(0,1fr)}
  html body[data-portal-design] .staff-directory header {flex-wrap:wrap}
  html body[data-portal-design] :is(.directory-filters,.team-filters) {min-width:0;max-width:100%;flex-wrap:wrap}
  html body[data-portal-design] .directory-filters > * {min-width:0;max-width:100%}
  html body[data-portal-design] .staff-enrollment li {flex-wrap:wrap;align-items:flex-start;gap:8px}
  html body[data-portal-design] .staff-enrollment li > div:first-child {flex:1 1 10rem}
  html body[data-portal-design] .staff-enrollment .staff-row-actions {flex:1 1 100%;justify-content:flex-start}
  html body[data-portal-design] :is(.staff-directory .staff-message,.staff-enrollment button,.department-chats button,.caller-selection button) {min-height:44px}
  html body[data-portal-design] .caller-selection {flex-wrap:wrap}
  html body[data-portal-design] .staff-directory li {flex-wrap:wrap;gap:8px}
  html body[data-portal-design] .staff-directory li > div {flex:1 1 8rem}
  html body[data-portal-design] .chat-admin li {flex-wrap:wrap}
  html body[data-portal-design] .chat-admin li > span {min-width:0;overflow-wrap:anywhere}
  html body[data-portal-design] .lead-intake-help summary {min-height:44px}
  html body[data-portal-design] #lead-form-host {min-height:24rem}
  html body[data-portal-design] .delivery-sort li {grid-template-columns:1.3rem minmax(0,1fr) auto auto;gap:6px;padding:10px 6px}
  html body[data-portal-design] .delivery-sort li > :is(div,span) {min-width:0;overflow-wrap:anywhere}
  html body[data-portal-design] .delivery-sort .secondary {min-width:44px;padding:6px}
  html body[data-portal-design] :is(.pay-lines,.score-counts) :is(dt,dd) {min-width:0;overflow-wrap:anywhere}

  /* Dialogs use the visible viewport; their own content remains scrollable. */
  html body[data-portal-design] dialog {
    box-sizing:border-box;
    max-width:calc(100vw - 24px);
    max-height:calc(100vh - 24px);
    max-height:calc(var(--mobile-visible-height,100dvh) - 24px);
    overflow:auto;
    overscroll-behavior:contain;
  }
  html body[data-portal-design] dialog:not(.client-funding-dialog) {padding:18px}
  html body[data-portal-design] dialog :is(.detail-head,.edit-head,.funding-heading) {gap:10px;align-items:flex-start}
  html body[data-portal-design] dialog :is(h2,h3,p) {overflow-wrap:anywhere}
  html body[data-portal-design] dialog :is(input:not([type="checkbox"],[type="radio"],[type="range"]),select,textarea) {font-size:16px;min-width:0;max-width:100%}
  html body[data-portal-design] dialog :is(button,.secondary,.primary) {min-height:44px}
  html body[data-portal-design] dialog :is([aria-label^="Close"],#cancel-edit,.funding-close) {min-width:44px;flex-shrink:0}
  html body[data-portal-design] .client-funding-dialog .funding-amount input {font-size:1.3rem}
  html body[data-portal-design] .client-funding-dialog .funding-close {width:44px;height:44px}
  html body[data-portal-design] .client-funding-dialog form {padding:20px}
  html body[data-portal-design] .account-menu {max-height:calc(var(--mobile-visible-height,100dvh) - 100px);overflow:auto;overscroll-behavior:contain}
  html body[data-portal-design] .account-menu :is(a,button,summary) {min-height:44px}

  /* Chat tools get a separate row, leaving the message field usable on narrow phones. */
  html body[data-portal-design][data-chat-open] {height:var(--mobile-visible-height,100dvh)}
  html body[data-portal-design][data-chat-open] .employee-shell {margin-block:0;padding:0}
  html body[data-portal-design] #chat-panel .chat-head {flex-wrap:wrap;padding:8px;gap:4px}
  html body[data-portal-design] #chat-panel .thread-heading {flex:1 1 7rem}
  html body[data-portal-design] #chat-panel .chat-head .icon-button {width:44px;height:44px}
  html body[data-portal-design] #chat-panel .chat-body {padding-inline:12px}
  html body[data-portal-design] #chat-panel .chat-compose {padding:8px 10px max(10px,env(safe-area-inset-bottom))}
  html body[data-portal-design] #chat-panel .compose-row {display:flex;flex-wrap:wrap;gap:4px;align-items:center}
  html body[data-portal-design] #chat-panel .compose-row textarea {order:-1;flex:1 0 100%;width:100%;min-height:46px;font-size:16px;max-height:88px}
  html body[data-portal-design] #chat-panel :is(.msg-tool,.chat-emoji-toggle,#chat-send) {width:44px;height:44px;min-width:44px;flex-shrink:0}
  html body[data-portal-design] #chat-panel #chat-send {margin-left:auto}
  html body[data-portal-design] #chat-panel .chat-line {max-width:92%}
  html body[data-portal-design] #chat-panel .chat-bubble {font-size:15px;line-height:1.5}
  html body[data-portal-design] #chat-panel .msg-actions {flex-wrap:wrap;gap:4px}
  html body[data-portal-design] #chat-panel .msg-actions button {min-width:44px;min-height:44px;height:auto}
  html body[data-portal-design] #chat-panel .contact-row {min-height:56px}
  html body[data-portal-design] :is(.rtc-prompt,.rtc-stage,.rtc-invites) button {min-height:44px}
  html body[data-portal-design] .rtc-stage {z-index:95;max-height:calc(var(--mobile-visible-height,100dvh) - 24px)}
  html body[data-portal-design] .rtc-invites {z-index:96}
}
@media (max-width:520px) {
  html body[data-portal-design] :is(.score-form,.provider-body .provider-grid,.caller-times) {grid-template-columns:minmax(0,1fr)}
  html body[data-portal-design] :is(.archive-shell,.qc-shell) dl > div {grid-template-columns:minmax(0,1fr);gap:4px}
  html body[data-portal-design] .archive-shell dl > div dd {padding-bottom:8px}
  html body[data-portal-design] .desk-hero-actions {grid-template-columns:minmax(0,1fr)}
  html body[data-portal-design] #activity-filters > button {width:100%}
  html body[data-portal-design] .day-axis span:nth-child(2n):not(:last-child) {visibility:hidden}
}
@media (max-width:420px) {
  html body[data-portal-design] .lead-filters {grid-template-columns:minmax(0,1fr);grid-template-areas:"search" "campaign" "status" "action"}
  html body[data-portal-design] :is(.filter-grid,.qc-filters) {grid-template-columns:minmax(0,1fr)}
  html body[data-portal-design] :is(.filter-grid .wide,.qc-wide) {grid-column:auto}
  html body[data-portal-design] .client-record {grid-template-columns:minmax(0,1fr)}
  html body[data-portal-design] .client-record :is(.client-ident,.client-source,.client-stage,.activity,.client-billing) {grid-column:1;grid-row:auto}
  html body[data-portal-design] .client-record .client-actions {grid-column:1;grid-row:auto;display:flex;max-width:none;justify-items:start;flex-wrap:wrap;align-items:center;gap:12px}
  html body[data-portal-design] .desk-emblem {width:40px;height:40px}
  html body[data-portal-design] .desk-emblem img {width:26px;height:26px}
  html body[data-portal-design] .desk-identity {gap:10px}
}
