/* Mobile CRM overlays. Screen-only: document/PDF rendering keeps its print geometry. */
.mobile-panel-close, .mobile-companion-toggle { display: none; }
@media screen and (max-width: 1024px) {
  .modal-overlay {
    align-items: stretch;
    justify-content: stretch;
    padding: 0;
    overflow: hidden;
    overscroll-behavior: contain;
  }

  .modal-overlay > .modal {
    box-sizing: border-box;
    display: block;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh !important;
    margin: 0;
    padding: 0 16px;
    border-radius: 0;
    border: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: auto;
    scroll-padding-block: 80px 100px;
    -webkit-overflow-scrolling: touch;
  }

  .modal-overlay > .modal > .modal-title {
    position: sticky;
    top: 0;
    z-index: 10;
    min-height: 64px;
    gap: 12px;
    margin: 0 -16px 16px;
    padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
    background: #fff;
    border-bottom: 1px solid #dfeaf0;
    font-size: 18px;
    line-height: 1.4;
  }

  .modal-overlay > .modal > .modal-title > span { min-width: 0; overflow-wrap: anywhere; }
  .modal-overlay .modal-close { flex: 0 0 44px; width: 44px; height: 44px; border-radius: 12px; background: #f0f6f9; color: #25475b; }

  .modal-overlay > .modal > :is(.modal-footer, .confirm-modal-footer) {
    position: sticky;
    bottom: 0;
    z-index: 9;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin: 18px -16px 0;
    padding: 12px max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    background: #fff;
    border-top: 1px solid #dfeaf0;
    box-shadow: 0 -6px 20px #16374c08;
  }

  .modal-overlay .modal-footer > button,
  .modal-overlay .confirm-modal-footer > button { flex: 1 1 120px; min-width: 0; justify-content: center; white-space: normal; }

  /* The task form already provides a dedicated scrollable body. */
  #task-modal > .task-modal { display: flex; flex-direction: column; overflow: hidden; }
  #task-modal .task-modal-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 0 0 8px; scrollbar-gutter: auto; }
  #task-modal .modal-title { flex: 0 0 auto; }
  #task-modal .task-modal-footer { flex: 0 0 auto; margin-top: 0; }
  #task-modal .task-modal-footer-secondary { flex: 1 1 100%; justify-content: space-between; gap: 8px; }
  #task-modal .task-modal-footer-secondary > .btn-secondary { min-width: 92px; }
  #task-modal .task-form-section { padding: 12px 12px 0; border-radius: 12px; }
  #task-modal .task-form-section-head { align-items: flex-start; flex-direction: column; gap: 4px; }
  #task-modal .task-form-section-note { font-size: 12px; }
  #task-modal .task-time-hint.is-spacer { display: none; }

  .modal-overlay :is(.form-group, .form-input, .rich-editor, .task-relation-combobox, .task-lead-combobox) { min-width: 0; max-width: 100%; box-sizing: border-box; }
  .modal-overlay .form-label { font-size: 13px; line-height: 1.5; }
  .modal-overlay :is(.task-form-grid, .task-form-schedule-row--range, .customer-form-grid, .customer-contact-form-grid, .lead-conversion-contact-grid, .lead-conversion-copy-grid, .lead-conversion-contact-fields, .lead-conversion-checklist, .lead-document-agreement-fields, .quote-document-grid, .quote-autofill-grid, .quote-service-grid, .quote-hour-bank-fields, .task-completion-time-grid, .task-completion-report-grid, .hour-bank-entry-edit-grid, .hour-bank-report-period-grid, .email-compose-recipient-grid) {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 12px;
  }

  /* Older forms use inline two-column grids rather than reusable grid classes. */
  .modal-overlay .modal [style*="grid-template-columns"]:has(> .form-group) { grid-template-columns: minmax(0, 1fr) !important; }
  .modal-overlay :is(.form-group, .quote-hour-bank-box).wide,
  .modal-overlay :is(.customer-form-full, .customer-contact-form-full) { grid-column: 1 / -1; }
  .modal-overlay :is(.lead-conversion-intro, .lead-conversion-section-head, .email-signature-head, .email-signature-actions, .lead-document-file-box, .lead-document-kind) { flex-wrap: wrap; gap: 10px; }
  .modal-overlay :is(.lead-conversion-section, .quote-form-section, .quote-service-row) { min-width: 0; padding: 12px; }
  .modal-overlay .lead-conversion-agreement { grid-template-columns: auto minmax(0, 1fr); }
  .modal-overlay .lead-conversion-agreement-total { grid-column: 2; }
  .modal-overlay .quote-service-row-head { flex-wrap: wrap; }
  .modal-overlay .lead-document-file-copy { min-width: 0; flex: 1 1 180px; }
  .modal-overlay :is(.lead-document-file-name, .email-attachment-chip, .confirm-modal-name) { overflow-wrap: anywhere; }
  .modal-overlay .lead-document-kind-option { flex: 1 1 140px; min-height: 44px; }
  #email-compose-modal .email-compose-grid { overflow: visible; }
  #email-compose-modal .email-signature-preview { max-width: 100%; overflow-x: auto; }

  /* Keep native controls at 16px to prevent focus zoom and give touch targets room. */
  :is(.modal-overlay, .side-panel, #quote-linked-notes-panel, #pricebook-supplier-panel) :is(input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]):not(.panel-hidden-date-input), select, textarea, [contenteditable="true"]) {
    box-sizing: border-box;
    min-width: 0;
    max-width: 100%;
    font-size: 16px !important;
    line-height: 1.5;
    scroll-margin-block: 86px 100px;
  }

  :is(.modal-overlay, .side-panel, #quote-linked-notes-panel, #pricebook-supplier-panel) :is(input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]):not(.panel-hidden-date-input), select) { min-height: 44px; }
  :is(.modal-overlay, .side-panel, #quote-linked-notes-panel, #pricebook-supplier-panel) button { min-height: 44px !important; min-width: 44px; touch-action: manipulation; }
  :is(.modal-overlay, .side-panel, #quote-linked-notes-panel, #pricebook-supplier-panel) :is(input[type="checkbox"], input[type="radio"]) { flex-shrink: 0; width: 20px; height: 20px; }
  :is(.modal-overlay, .side-panel) :is(.check-inline, .quote-hour-bank-toggle) { min-height: 44px; line-height: 1.5; }
  :is(.modal-overlay, .side-panel) textarea { min-height: 100px; resize: vertical; }
  :is(.modal-overlay, .side-panel) .rich-toolbar { flex-wrap: wrap; gap: 5px; }
  :is(.modal-overlay, .side-panel) .rich-tool { flex: 0 0 44px; width: 44px; height: 44px; }
  :is(.modal-overlay, .side-panel) .rich-editor-area { overflow-wrap: anywhere; min-height: 150px; }
  :is(.modal-overlay, .side-panel) .rich-editor-area.project-desc-editor { height: 220px; min-height: 150px; max-height: 45dvh; }
  :is(.modal-overlay, .side-panel) .rich-editor-area :is(img, video) { max-width: 100%; height: auto; }
  :is(.modal-overlay, .side-panel) .rich-editor-area table { display: block; max-width: 100%; overflow-x: auto; }
  .modal-overlay :is(.task-relation-menu, .task-lead-menu) { max-width: 100%; }
  .modal-overlay :is(.task-relation-options, .task-lead-options) { max-height: 32dvh; overscroll-behavior: contain; }
  .modal-overlay :is(.task-relation-option, .task-lead-option) { min-height: 44px; }

  /* Preserve the existing 300/340/500 overlay ordering, including nested task forms. */
  .side-panel {
    box-sizing: border-box;
    inset: 0 !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0 !important;
    overflow: hidden !important;
    overscroll-behavior: contain;
  }

  .side-panel > .panel-header { flex: 0 0 auto; max-height: 48dvh; overflow-x: hidden; overflow-y: auto; }
  .side-panel > .panel-body { flex: 1 1 auto; min-height: 0; padding: 16px; padding-bottom: max(20px, env(safe-area-inset-bottom)); overflow-y: auto; overscroll-behavior: contain; }
  .side-panel .panel-hero { padding: max(14px, env(safe-area-inset-top)) 16px 12px; }
  .side-panel .panel-hero-top { gap: 12px; }
  .side-panel .panel-hero-top > div:first-child { min-width: 0; }
  .side-panel .panel-name { overflow-wrap: anywhere; }
  .side-panel .panel-close-btn { min-width: 44px; width: 44px; height: 44px; }
  .side-panel .panel-hero-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .side-panel .panel-hero-stat { min-width: 0; }
  .side-panel .panel-mini-select { max-width: 100%; }
  .side-panel :is(.detail-grid, .quote-detail-grid, .attachments-list) { grid-template-columns: minmax(0, 1fr); }
  .side-panel .detail-cell.wide { grid-column: 1; }
  .side-panel :is(.detail-cell-val, .attachment-name, .task-note-text, .panel-sub) { overflow-wrap: anywhere; }
  .side-panel :is(.attachments-toolbar, .task-panel-toolbar, .lead-quote-card-footer) { flex-wrap: wrap; }
  .side-panel .attachment-name { white-space: normal; }
  .side-panel .attachment-actions .icon-action { width: 44px; height: 44px; }

  :is(#lead-panel, #task-panel, #project-panel) > .panel-header { padding: 0; background: #fff; border-bottom: 1px solid #e1edf2; }
  :is(#lead-panel, #task-panel, #project-panel) :is(.lead-hero, .record-hero) { padding: max(12px, env(safe-area-inset-top)) 16px 10px; border-radius: 0; box-shadow: none; }
  :is(#lead-panel, #task-panel, #project-panel) .panel-hero-top { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 0; }
  :is(#lead-panel, #task-panel, #project-panel) .panel-hero-top > div:first-child { width: 100%; min-width: 0; padding-inline-end: 56px; }
  :is(#lead-panel, #task-panel, #project-panel) :is(.lead-panel-hero-actions, .record-hero-actions) { display: flex; width: 100%; gap: 8px; }
  :is(#lead-panel, #task-panel, #project-panel) .panel-name { font-size: 20px; line-height: 1.35; }
  :is(#lead-panel, #task-panel, #project-panel) .panel-sub { font-size: 12px; }
  :is(#lead-panel, #task-panel, #project-panel) .panel-close-btn { position: absolute; top: 0; left: 0; width: 44px; height: 44px; }
  :is(#lead-panel, #task-panel, #project-panel) :is(.lead-primary-action, .lead-ai-action, .record-primary-action, .record-secondary-action) { flex: 1; padding: 9px 8px; font-size: 13px; }

  /* A horizontal summary strip keeps every field available without filling the screen. */
  :is(#lead-panel, #task-panel, #project-panel) .panel-hero-stats {
    display: flex;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 12px;
    margin-top: 10px !important;
    padding: 8px 0 3px;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
    scrollbar-color: #cbdde5 transparent;
  }

  :is(#lead-panel, #task-panel, #project-panel) .panel-hero-stat,
  #lead-panel #lp-value-stat { flex: 0 0 150px; width: 150px; min-width: 0; margin: 0; padding: 0; }
  :is(#lead-panel, #task-panel, #project-panel) .panel-hero-stat-label { font-size: 11px; }
  #lead-panel #lp-lead-timing { flex-basis: 260px; width: 260px; }
  #lead-panel .lead-timing-row { flex-wrap: wrap; white-space: normal; gap: 4px 7px; }
  #lead-panel .lead-timing-label { font-size: 11px; }
  #lead-panel .lead-timing-value { font-size: 12px; }
  #lead-panel .lead-timing-meta, #lead-panel .lead-timing-alert { font-size: 11px; }
  #task-panel #tp-task-timing { flex-basis: 260px; width: 260px; }
  #task-panel .task-timing-row { flex-wrap: wrap; white-space: normal; gap: 4px 7px; }
  #task-panel .task-timing-label { font-size: 11px; }
  #task-panel .task-timing-value { font-size: 12px; }
  #lead-panel .lead-workspace-body,
  :is(#task-panel, #project-panel) .record-workspace-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 12px; padding-bottom: max(20px, env(safe-area-inset-bottom)); }

  /* Reset tablet grid placements explicitly; the original drawer files switch at 760px. */
  #lead-panel .lead-workspace-body > *,
  #lead-panel .lead-workspace-sidebar > *,
  :is(#task-panel, #project-panel) .record-workspace-body > * { grid-column: 1 !important; grid-row: auto !important; min-width: 0; }
  #lead-panel .lead-workspace-sidebar,
  #lead-panel.sales-ai-open .lead-workspace-sidebar { display: contents; }
  #lead-panel #sales-ai-panel { order: -1; }
  #lead-panel .lead-journey-card,
  :is(#task-panel, #project-panel) .record-journey-card { order: 0; }
  #lead-panel .lead-progress-section,
  :is(#task-panel, #project-panel) .record-progress-section { order: 1; }
  #lead-panel .lead-contact-section,
  :is(#task-panel, #project-panel) .record-details-section { order: 2; }
  #lead-panel .lead-call-quality-section { order: 3; }
  #lead-panel #lead-tasks-panel,
  #project-panel #project-tasks-panel { order: 3; }
  #lead-panel #lead-notes-panel,
  #task-panel #task-notes-panel,
  #project-panel #project-notes-panel { order: 4; }
  #lead-panel #lead-quote-panel,
  :is(#task-panel, #project-panel) .record-attachments-section { order: 5; }
  #lead-panel #lead-panel-actions,
  :is(#task-panel, #project-panel) .panel-actions { order: 6; }
  #lead-panel .lead-quote-list { grid-template-columns: minmax(0, 1fr); }
  #task-panel #task-notes-list,
  #project-panel :is(#project-notes-list, #project-tasks-list) { max-height: none; overflow: visible; }
  #lead-panel #lead-notes-list, #lead-panel #lead-tasks-list { max-height: none; overflow: visible; }
  #lead-panel .lead-contact-grid { grid-template-columns: minmax(0, 1fr); gap: 15px; }
  #lead-panel .lead-contact-item.wide { grid-column: 1; }
  :is(#lead-panel, #task-panel, #project-panel) .task-notes-panel-header { padding: 14px 16px; min-height: 72px; }
  :is(#lead-panel, #task-panel, #project-panel) .task-notes-panel-body { padding: 0 16px 14px; }
  :is(#lead-panel, #task-panel, #project-panel) .task-notes-panel-add { flex-basis: 44px; width: 44px; height: 44px; }
  :is(#lead-panel, #task-panel, #project-panel) .task-note-actions .icon-action { width: 44px; height: 44px; opacity: 1; }
  :is(#lead-panel, #task-panel, #project-panel) :is(.lead-text-action, .record-text-action) { padding: 8px 0; }
  #lead-panel .lead-editable { min-height: 36px; display: flex; align-items: center; }

  /* Quote notes and pricebook supplier details now remain inside their record. */
  :is(#quote-linked-notes-panel, #pricebook-supplier-panel) .task-notes-panel-header { padding: max(12px, env(safe-area-inset-top)) 16px 12px; flex: 0 0 auto; }
  :is(#quote-linked-notes-panel, #pricebook-supplier-panel) .task-notes-panel-body { min-height: 0; flex: 1 1 auto; padding: 12px 16px max(16px, env(safe-area-inset-bottom)); overflow-y: auto; overscroll-behavior: contain; }
  .mobile-panel-close { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 44px; width: 44px; height: 44px; border: 1px solid #dbe7ee; border-radius: 12px; background: #f0f6f9; color: #25475b; font: inherit; font-size: 24px; }
  .mobile-companion-toggle { display: inline-flex; align-items: center; justify-content: center; position: relative; z-index: 1; min-height: 44px; padding: 8px 14px; margin-top: 4px; border: 1px solid #ffffff40; border-radius: 10px; background: #ffffff15; color: #fff; font: inherit; font-size: 14px; }

  #sales-ai-panel { padding: 16px; }
  #sales-ai-panel :is(.sai-controls, .sai-control-buttons, .sai-metrics, .sai-chat-form) { flex-wrap: wrap; min-width: 0; }
  #sales-ai-panel .sai-controls { flex-basis: 100%; }
  #sales-ai-panel .sai-controls label { min-width: 0; flex: 1 1 100%; }
  #sales-ai-panel .sai-controls select { width: 100%; }
  #sales-ai-panel .sai-chat-form button { flex: 1 1 100%; }
  #sales-ai-panel #sai-question { flex: 1 1 100%; width: 100%; }
  #sales-ai-panel .sai-header { position: relative; flex-wrap: wrap; gap: 10px; }
  #sales-ai-panel .sai-title { flex: 1 1 100%; min-width: 0; padding-inline-end: 44px; }
  #sales-ai-panel .sai-proposal { flex-direction: column; align-items: flex-start; }
  #sales-ai-panel #sai-close { position: absolute; inset-inline-end: 0; top: 0; }
  #sales-ai-panel :is(.sai-answer, .sai-transcript) { max-height: 40dvh; overscroll-behavior: contain; }
  .quote-pdf-progress-card { box-sizing: border-box; max-width: calc(100vw - 24px); max-height: calc(100dvh - 24px); padding: 22px 18px; overflow-y: auto; }
  .quote-pdf-progress-title { font-size: 21px; }
  .quote-pdf-progress-actions { grid-template-columns: minmax(0, 1fr); }
}

@media screen and (max-width: 1024px) and (max-height: 500px) {
  .side-panel > .panel-header { max-height: 45dvh; }
  :is(#lead-panel, #task-panel, #project-panel) .panel-hero-top { flex-wrap: nowrap; align-items: center; }
  :is(#lead-panel, #task-panel, #project-panel) .panel-hero-top > div:first-child { width: auto; flex: 1; }
  :is(#lead-panel, #task-panel, #project-panel) :is(.lead-panel-hero-actions, .record-hero-actions) { width: auto; flex: 0 1 48%; }
  :is(#lead-panel, #task-panel, #project-panel) .panel-close-btn { position: static; }
  :is(#lead-panel, #task-panel, #project-panel) .panel-name { font-size: 17px; }
  #task-modal .task-modal-footer-secondary { flex: 1 1 180px; }
}

/* Phone-only refinements. Host selectors also win when companion CSS loads later. */
@media screen and (max-width: 760px) {
  .modal-overlay { top: var(--crm-viewport-top, 0px); bottom: auto; height: var(--crm-viewport-height, 100dvh); }
  .modal-overlay > .modal { height: 100%; max-height: 100% !important; padding-inline: 12px; }
  .modal-overlay > .modal > .modal-title { margin-inline: -12px; padding-inline: 12px; min-height: 58px; font-size: 17px; }
  .modal-overlay > .modal > :is(.modal-footer, .confirm-modal-footer) { margin-inline: -12px; padding-inline: 12px; }
  .modal-overlay .modal :is(.form-row, .form-grid, .email-compose-grid, .knowledge-editor-grid, .candidate-form-grid, .employee-form-grid) { grid-template-columns: minmax(0, 1fr); min-width: 0; }
  .modal-overlay .modal :is(.form-group, .form-row, .form-grid) > * { min-width: 0; }
  .modal-overlay .modal :is(.form-group, .form-input, .rich-editor) { width: 100%; }
  .modal-overlay .modal :is(.tabs, .modal-tabs, .email-compose-tabs) { max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; }
  .modal-overlay .modal :is(.modal-title, .modal-footer, .confirm-modal-footer) { flex-shrink: 0; }
  .modal-overlay .modal :is(.form-section-title, .form-help, .form-hint) { overflow-wrap: anywhere; }
  .modal-overlay .modal [style*="min-width"]:has(> .form-group) { min-width: 0 !important; }
  #task-modal .task-form-section { padding-inline: 10px; }
  #task-modal .task-modal-footer-primary { display: flex; flex-wrap: wrap; gap: 8px; width: 100%; }
  #task-modal .task-modal-footer-primary > button { flex: 1 1 120px; justify-content: center; }
  .side-panel { top: var(--crm-viewport-top, 0px) !important; bottom: auto !important; height: var(--crm-viewport-height, 100dvh); max-height: var(--crm-viewport-height, 100dvh); }
  .side-panel > .panel-body,
  #lead-panel .lead-workspace-body,
  :is(#task-panel, #project-panel) .record-workspace-body { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }

  /* Each launcher owns one half of the bottom dock; neither can cover the other. */
  body .ic-host { right: max(10px, env(safe-area-inset-right)); left: auto; bottom: max(10px, env(safe-area-inset-bottom)); width: max-content; max-width: calc(50vw - 16px); }
  body .vp-host { left: max(10px, env(safe-area-inset-left)); right: auto; bottom: max(10px, env(safe-area-inset-bottom)); width: max-content; max-width: calc(50vw - 16px); pointer-events: none; }
  .ic-host .ic-launcher,
  .vp-host .vp-launcher { min-height: 44px; max-width: calc(50vw - 16px); margin: 0; padding: 10px 12px; font-size: 12px; line-height: 1.4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; box-shadow: 0 3px 14px #173f5426; }
  .ic-host .ic-launcher { position: relative; right: auto; bottom: auto; }
  .vp-host .vp-launchers { position: relative; width: max-content; margin: 0; gap: 6px; justify-content: flex-start; max-width: calc(50vw - 16px); }
  .vp-host :is(.vp-launcher, .vp-ai-indicator, .vp-panel, .vp-ai-toggle) { pointer-events: auto; }
  .vp-host .vp-ai-indicator { position: absolute; left: 0; bottom: calc(100% + 8px); max-width: calc(100vw - 20px); width: max-content; }
  .vp-host :is(.vp-ai-details, .vp-ai-stop) { min-height: 40px; }
  /* openModal and record forms use inline display:flex; some dialogs use .open. */
  body:has(.modal-overlay:is(.open, [style*="display: flex"], [style*="display:flex"])) :is(.ic-host, .vp-host) { z-index: 450; }
  body:is(.mobile-nav-open, .mobile-agenda-open) :is(.ic-host, .vp-host) { visibility: hidden; }

  /* The conversation fills the available visual viewport above the two launchers. */
  .ic-host .ic-panel { position: fixed; top: calc(var(--crm-viewport-top, 0px) + max(6px, env(safe-area-inset-top))); right: max(6px, env(safe-area-inset-right)); left: max(6px, env(safe-area-inset-left)); bottom: auto; width: auto; max-width: none; height: calc(var(--crm-viewport-height, 100dvh) - 72px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); min-height: 0; margin: 0; border-radius: 16px; }
  .ic-host .ic-header { padding: 10px 12px; gap: 8px; }
  .ic-host .ic-heading h2 { font-size: 19px; }
  .ic-host .ic-eyebrow { display: none; }
  .ic-host .ic-header-actions { gap: 6px; }
  .ic-host :is(.ic-icon, .ic-send) { min-width: 44px; width: 44px; height: 44px; }
  .ic-host :is(.ic-button, .ic-create-group, .ic-contact-chip, .ic-older) { min-height: 44px; }
  .ic-host .ic-create-group { padding: 7px 10px; font-size: 12px; }
  .ic-host .ic-create-group svg { display: none; }
  .ic-host .ic-sidebar { width: 100%; min-width: 0; border-left: 0; }
  .ic-host .ic-thread { display: none; }
  .ic-host .ic-layout[data-mobile=thread] > .ic-sidebar,
  .ic-host .ic-layout[data-work=true] > .ic-sidebar { display: none; }
  .ic-host .ic-layout[data-mobile=thread] > .ic-thread,
  .ic-host .ic-layout[data-work=true] > .ic-thread { display: flex; }
  .ic-host .ic-back { display: inline-flex; }
  .ic-host .ic-search { margin: 10px 12px 6px; min-height: 44px; }
  .ic-host :is(.ic-search-input, .ic-input, .ic-field, .ic-work-content, .ic-work-completion-note) { font-size: 16px !important; min-width: 0; max-width: 100%; }
  .ic-host .ic-directory { min-height: 0; }
  .ic-host .ic-conversation { min-height: 64px; padding: 9px; }
  .ic-host .ic-conversation-copy strong { font-size: 14px; }
  .ic-host .ic-conversation-preview { font-size: 12px; }
  .ic-host .ic-thread-header { gap: 5px; padding: 8px; min-height: 62px; }
  .ic-host .ic-thread-identity { gap: 6px; }
  .ic-host .ic-thread-identity > .ic-avatar { width: 30px; height: 30px; }
  .ic-host .ic-thread-title h3 { font-size: 14px; }
  .ic-host .ic-thread-subtitle { font-size: 10px; }
  .ic-host .ic-stream { padding: 10px; }
  .ic-host .ic-message { max-width: 100%; }
  .ic-host .ic-message-text { font-size: 15px; line-height: 1.6; }
  .ic-host .ic-compose { padding: 8px; }
  .ic-host .ic-compose-row { gap: 7px; }
  .ic-host .ic-input { min-height: 48px; max-height: min(120px, 25dvh); padding: 9px; }
  .ic-host .ic-send { margin: 0; }
  .ic-host .ic-compose-hint { display: none; }
  .ic-host .ic-compose-toolbar { padding-top: 2px; }
  .ic-host .ic-message-actions { opacity: 1; transform: none; }
  .ic-host :is(.ic-message-action, .ic-reaction, .ic-emoji) { min-width: 32px; min-height: 32px; }
  .ic-host .ic-emoji-picker { right: 8px; left: 8px; bottom: 124px; grid-template-columns: repeat(7, minmax(0, 1fr)); max-width: none; padding: 7px; max-height: 45%; overflow-y: auto; }
  .ic-host .ic-contact-menu { top: 62px; max-height: calc(100% - 70px); }
  .ic-host .ic-contact-menu-actions .ic-button { white-space: normal; }
  .ic-host .ic-group-header { padding: 10px 12px; gap: 8px; }
  .ic-host .ic-group-header h3 { font-size: 18px; }
  .ic-host .ic-group-form { padding: 12px; gap: 12px; overscroll-behavior: contain; }
  .ic-host .ic-group-members { grid-template-columns: 1fr; height: 180px; }
  .ic-host .ic-group-member { min-height: 44px; }
  .ic-host .ic-group-actions { flex-wrap: wrap; }
  .ic-host .ic-group-actions > button { flex: 1; }

  /* Stack shared work on phones while keeping long task lists in their own scroll area. */
  .ic-host .ic-workspace-header { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); grid-template-rows: auto auto; align-items: center; gap: 6px; padding: 8px; }
  .ic-host .ic-workspace-header > .ic-icon { grid-column: 1; grid-row: 1; }
  .ic-host .ic-workspace-heading { grid-column: 2 / span 3; grid-row: 1; min-width: 0; }
  .ic-host .ic-workspace-heading h3 { font-size: 16px; }
  .ic-host .ic-workspace-heading span { display: none; }
  .ic-host .ic-workspace-header > .ic-button { width: 100%; min-width: 0; min-height: 44px; height: 100%; padding: 6px; gap: 5px; font-size: 12px !important; line-height: 1.35; white-space: normal; overflow-wrap: normal; }
  .ic-host .ic-work-people { grid-column: 5 / span 2; grid-row: 1; justify-self: end; order: 0; margin: 0; }
  .ic-host .ic-work-recent { grid-column: 1 / span 3; grid-row: 2; order: 0; }
  .ic-host .ic-work-add { grid-column: 4 / span 3; grid-row: 2; order: 0; }
  .ic-host .ic-work-recent-menu { top: calc(100% - 4px); right: 8px; left: 8px; width: auto; max-height: 40dvh; }
  .ic-host .ic-work-recent-item { min-height: 48px; }
  .ic-host .ic-workspace-body { display: flex; flex-direction: column; overflow-y: auto; overscroll-behavior: contain; }
  .ic-host .ic-work-tasks-pane { flex: 0 0 auto; min-height: 240px; height: min(360px, 48dvh); border-right: 0; border-bottom: 1px solid var(--ic-line); }
  .ic-host .ic-work-list-pane { padding: 0 8px; }
  .ic-host .ic-work-item { gap: 8px; padding-inline: 2px; }
  .ic-host .ic-work-item-check { width: 32px; height: 32px; margin-top: 10px; font-size: 16px; }
  .ic-host .ic-work-item-open { padding-block: 12px; min-height: 52px; }
  .ic-host .ic-work-item-copy strong { font-size: 15px; }
  .ic-host .ic-work-project-pane { flex: 0 0 auto; overflow: visible; min-height: 0; padding: 12px; }
  .ic-host .ic-workspace-body:has(.ic-work-editor:not([hidden])) { overflow: hidden; }
  .ic-host .ic-work-tasks-pane:has(.ic-work-editor:not([hidden])) { flex: 1; height: auto; min-height: 0; }
  .ic-host .ic-workspace-body:has(.ic-work-editor:not([hidden])) > .ic-work-project-pane { display: none; }
  .ic-host .ic-work-editor { padding: 12px; }
  .ic-host .ic-work-editor > * { flex-shrink: 0; }
  .ic-host .ic-work-editor-head { flex-wrap: wrap; }
  .ic-host .ic-work-toolbar { flex-wrap: wrap; gap: 3px; }
  .ic-host .ic-work-format { min-width: 40px; height: 40px; font-size: 14px !important; }
  .ic-host .ic-work-content { min-height: 150px; }
  .ic-host .ic-project-content { min-height: 170px; }
  .ic-host .ic-work-actions { margin-top: 4px; }
  .ic-host .ic-work-actions .ic-button { min-height: 44px; flex: 1 1 100px; font-size: 12px !important; }

  /* Phone controls use a horizontal rail, leaving the full screen width for each view. */
  .vp-host .vp-phone-shell { position: fixed; top: calc(var(--crm-viewport-top, 0px) + max(6px, env(safe-area-inset-top))); right: max(6px, env(safe-area-inset-right)); left: max(6px, env(safe-area-inset-left)); width: auto; height: calc(var(--crm-viewport-height, 100dvh) - 72px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); display: flex; flex-direction: column; min-height: 0; }
  .vp-host .vp-phone-shell > .vp-panel { flex: 1; width: 100%; height: auto; min-height: 0; border-radius: 16px; }
  .vp-host .vp-header { padding: 10px 12px; gap: 10px; }
  .vp-host .vp-header .vp-icon { min-width: 44px; width: 44px; height: 44px; }
  .vp-host .vp-eyebrow { display: none; }
  .vp-host .vp-connection-label { max-width: none; font-size: 11px; }
  .vp-host .vp-workspace { display: flex; flex-direction: column; }
  .vp-host .vp-tabs { flex: 0 0 auto; flex-direction: row; direction: rtl; justify-content: space-around; gap: 2px; padding: 5px 6px; border-right: 0; border-bottom: 1px solid #e5efed; overflow-x: auto; }
  .vp-host .vp-tab { width: 44px; height: 44px; padding: 10px; }
  .vp-host .vp-main { flex: 1; }
  .vp-host .vp-section { padding: 14px; }
  .vp-host .vp-person-card { margin-bottom: 12px; padding-bottom: 12px; }
  .vp-host .vp-message { padding: 8px 12px; overflow-wrap: anywhere; }
  .vp-host :is(.vp-input, input, select, textarea) { font-size: 16px !important; max-width: 100%; }
  .vp-host :is(.vp-input, select) { min-height: 44px; }
  .vp-host :is(.vp-button, .vp-small, .vp-contact-toggle, .vp-link, .vp-details summary) { min-height: 44px; }
  .vp-host .vp-contact-toggle { min-width: 44px; flex-basis: 44px; }
  .vp-host .vp-number-row .vp-number { font-size: 22px !important; }
  .vp-host .vp-dialpad .vp-key { height: 48px; }
  .vp-host .vp-answering-actions { flex-wrap: wrap; }
  .vp-host .vp-answering-actions > .vp-button { flex: 1 1 120px; }
  .vp-host .vp-extension-row { padding: 9px; gap: 8px; }
  .vp-host .vp-extension-row > div { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 7px; }
  .vp-host .vp-extension-row strong { flex-basis: 100%; }
  .vp-host .vp-extension-row :is(small, .vp-extension-state) { margin: 0; }
  .vp-host .vp-book-controls { flex-wrap: wrap; }
  .vp-host .vp-book-leads { min-height: 36px; }
  .vp-host .vp-ai-toggle { position: static; flex: 0 0 auto; writing-mode: horizontal-tb; width: 100%; min-height: 44px; height: 44px; margin-top: 6px; padding: 8px 12px; border: 1px solid #b7e4ed; border-radius: 10px; box-shadow: none; }
  .vp-host .vp-ai-companion { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 4; }
  .vp-host .vp-ai-surface { border-radius: 16px; }
  .vp-host .vp-ai-companion #sales-ai-panel { padding: 12px; }
  .vp-host .vp-ai-companion .sai-header { position: relative; flex-wrap: wrap; }
  .vp-host .vp-ai-companion .sai-title { flex: 1 1 calc(100% - 60px); padding-inline-end: 48px; }
  .vp-host .vp-ai-companion .sai-controls { flex: 1 1 100%; flex-wrap: wrap; }
  .vp-host .vp-ai-companion :is(#sai-mode, #sai-history) { width: 100%; flex: 1 1 100%; }
  .vp-host .vp-ai-companion :is(#sai-close, .vp-ai-fallback-close) { width: 44px; height: 44px; flex-basis: 44px; }
  .vp-host .vp-ai-companion :is(#sai-quality-grid:not(.sai-review-mode), .sai-feedback .sai-grid) { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .vp-host .vp-ai-companion .sai-quality { border-inline-end: 0; border-bottom: 1px solid var(--sai-line); padding: 0 0 14px; }
  .vp-host .vp-ai-companion .sai-chat-form { flex-wrap: wrap; }
  #sales-ai-panel :is(input, select, textarea) { font-size: 16px !important; min-height: 44px; }
  #sales-ai-panel :is(button, summary) { min-height: 44px; }
  #sales-ai-panel .sai-coaching-scales { gap: 12px; }
  #sales-ai-panel .sai-goal-button { flex-wrap: wrap; min-height: 44px; }
  #sales-ai-panel .sai-goal-button strong { max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
  #sales-ai-panel .sai-alert-dialog { width: calc(100vw - 24px); max-height: calc(var(--crm-viewport-height, 100dvh) - 24px); }
  #sales-ai-panel .sai-alert-dialog-content { padding: 18px; }
}

@media screen and (max-width: 760px) and (max-height: 500px) {
  .ic-host .ic-header, .vp-host .vp-header { padding-block: 5px; }
  .ic-host .ic-thread-header { padding-block: 4px; min-height: 52px; }
  .ic-host .ic-compose-toolbar { padding-top: 0; }
  .ic-host .ic-workspace-header { padding-block: 4px; }
  .vp-host .vp-connection-label { display: none; }
  .vp-host .vp-tabs { padding-block: 2px; }
}
