/* Phone-only overrides. Desktop markup, navigation and business rules retain
   their existing presentation. Keep this sheet scoped even if loaded directly. */
@media (max-width: 767px) {
  #app { --mobile-space: 12px; --mobile-control: 44px; }
  #app:not([data-view="customer-pool"]) .customer-pool-view { display: none !important; }
  #app button, #app input, #app select, #app textarea { -webkit-tap-highlight-color: transparent; }
  #app input:not([type="checkbox"]):not([type="radio"]), #app select, #app textarea { font-size: 16px; }
  #app .mobile-shell-header { min-width: 0; }
  #app #notification-button, #app #account-menu-button { min-width: 44px; min-height: 44px; }
  #app .conversation-search-wrap { display: block !important; padding: 8px 12px; }
  #app .conversation-search { min-height: 44px; box-shadow: none; }
  #app .conversation-search input { font-size: 16px; }
  #app .conversation-search-shortcut { display: none; }
  #app button[data-conversation-retry] { width: 100%; min-height: 44px; box-sizing: border-box; font-size: 14px; border: 0; border-top: 1px solid var(--line); border-radius: 0; background: var(--surface); color: var(--accent); }
  #app .phone-conversation-search-progress { padding: 8px 12px 12px; border-top: 1px solid var(--line); background: var(--surface); text-align: center; }
  #app .phone-conversation-search-progress > span { color: var(--muted); font-size: 13px; }
  #app button[data-conversation-search-more] { width: 100%; min-height: 44px; margin-top: 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--accent); font-size: 14px; }
  #app .customer-followup-sheet { top: var(--a6-visual-viewport-top,0px); bottom: auto; height: var(--a6-visual-viewport-height,100dvh); }
  #app .customer-search-field { display: flex !important; grid-column: 1 / -1; margin: 0; box-shadow: none; }
  #app .customer-search-row { grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
  #app .customer-search-field input { font-size: 16px; min-height: 44px; }
  #app .customer-instance-picker { grid-row: 2; }
  #app .customer-filter-open { grid-row: 2; min-width: 88px; }
  #app .customer-applied-filters:not(:empty) { display: flex !important; flex-wrap: wrap; gap: 6px; }
  #app .customer-mobile-card { border-radius: 10px; box-shadow: none; padding: 12px; }
  #app .customer-card-facts, #app .customer-card-requirement, #app .customer-card-preview { font-size: 14px; line-height: 1.5; }
  #app .customer-card-name { font-size: 16px; }
  #app .customer-card-requirement, #app .customer-card-preview { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

  /* The dashboard should show work before large presentation cards. */
  #app #dashboard .dashboard-unified-panel { display: flex !important; flex-direction: column; gap: 12px; }
  #app #dashboard .dashboard-quarter-strip, #app #dashboard .dashboard-analysis-grid { display: contents !important; }
  #app #dashboard .dashboard-kpi-grid { order: 0; gap: 8px; }
  #app #dashboard .dashboard-kpi-live, #app #dashboard .dashboard-kpi-ico { display: none; }
  #app #dashboard .dashboard-kpi-meta { min-width: 0; padding-right: 0; }
  #app #dashboard .kpi-label { font-size: 13px; line-height: 1.5; white-space: normal; }
  #app #dashboard .dashboard-kpi-card { min-height: 96px !important; padding: 12px; border-radius: 10px; box-shadow: none; }
  #app #dashboard .kpi-value { font-size: 27px; }
  #app #dashboard .kpi-sub { line-height: 1.45; white-space: normal; font-size: 12px; }
  #app #dashboard .dashboard-quarter-card--reminders { order: 1; min-height: 0 !important; padding: 12px; }
  #app #dashboard .dashboard-followup-panel { order: 2; }
  #app #dashboard .dashboard-quarter-card--target { order: 3; min-height: 0 !important; padding: 14px; }
  #app #dashboard .dashboard-quarter-card--countdown { order: 4; min-height: 0 !important; padding: 14px; }
  #app #dashboard .dashboard-grade-panel { order: 5; }
  #app #dashboard .dashboard-quarter-number { font-size: 28px; }
  #app #dashboard .dashboard-quarter-card--countdown .dashboard-quarter-main { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
  #app #dashboard .dashboard-quarter-card--countdown .dashboard-quarter-note { grid-column: 1 / -1; }
  #app #dashboard .dashboard-quarter-card--countdown .dashboard-quarter-icon { display: none; }
  #app #dashboard .dashboard-quarter-card { border-radius: 10px; box-shadow: none; }
  #app #dashboard .dashboard-followup-row { min-height: 52px; }
  #app #dashboard .dashboard-analysis-head { padding: 12px 14px; }
  #app #dashboard-controls .dashboard-range-button { min-height: 44px; font-size: 14px; }
  #app #task-reminders-card button { min-height: 44px; font-size: 14px; }
  #app #task-reminders-card .dashboard-quarter-reminder-nav { min-width: 32px; }
  #app #task-reminders-card .dashboard-quarter-reminder-day { min-width: 0; }

  /* A name and one compact, equal-width row of actions. Reuse the existing
     buttons and handlers; desktop layout and sending behavior stay unchanged. */
  #app[data-view="conversations"] .layout[data-mobile-pane="detail"] .chat-panel { grid-template-rows: auto auto minmax(0, 1fr) 0; }
  #app .layout[data-mobile-pane="detail"] .chat-head { min-height: 0; padding: calc(8px + var(--a6-safe-top, 0px)) 12px 8px; }
  #app .layout[data-mobile-pane="detail"] .chat-primary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  #app .layout[data-mobile-pane="detail"] :is(.chat-profile, .chat-identity, .mobile-chat-stage-actions, .chat-actions) { display: contents !important; }
  #app .layout[data-mobile-pane="detail"] .chat-name-line { grid-column: 1 / -1; grid-row: 1; min-width: 0; }
  #app .layout[data-mobile-pane="detail"] #chat-title { margin: 0; font-size: 16px; line-height: 24px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #app .layout[data-mobile-pane="detail"] :is(#chat-back-button, #mobile-chat-translate-all-button, #chat-profile-button):not([hidden]) {
    display: inline-flex !important; align-items: center; justify-content: center; box-sizing: border-box;
    width: 100%; min-width: 0; max-width: none; height: 44px; min-height: 44px; margin: 0; padding: 0 6px;
    border: 1px solid var(--line); border-radius: 8px; box-shadow: none; font-size: 13px; line-height: 1.2; font-weight: 600;
    white-space: nowrap; grid-row: 2;
  }
  #app .layout[data-mobile-pane="detail"] #chat-back-button { grid-column: 1; }
  #app .layout[data-mobile-pane="detail"] #mobile-chat-translate-all-button { grid-column: 2; }
  #app .layout[data-mobile-pane="detail"] #chat-profile-button { grid-column: 3; }
  #app[data-view="conversations"] :is(#chat-avatar, #chat-channel-state, #chat-subtitle, #mobile-chat-stage, .chat-secondary, #chat-translate-all-button, #chat-search-button, #chat-more-button, #chat-more-menu, .chat-actions .chat-menu-wrap, #message-count, #chat-composer, .message-translate-btn, .message-ai-reply-btn, .message-ai-reply-slot, .chat-media-add-file) { display: none !important; }
  #app[data-view="conversations"] #message-list { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  /* Media overlays must sit above the sticky chat header (layer 45), including Close. */
  #app[data-view="conversations"] #chat-media-viewer { z-index: 60; }
  #app .message-translation { font-size: 14px; line-height: 1.6; }
  #app .chat-composer textarea { font-size: 16px; }
  #app .message-media img { max-width: 100%; height: auto; }
  #app .message-row { content-visibility: auto; contain-intrinsic-size: auto 110px; }
  #app #customer-profile-drawer.chat-dossier-v2 { position: fixed; inset: var(--a6-visual-viewport-top, 0px) 0 auto; width: 100%; max-width: none; height: var(--a6-visual-viewport-height, 100dvh); z-index: 2400; background: var(--surface); }
  #app #customer-profile-drawer.chat-dossier-v2[hidden] { display: none !important; }
  #app #customer-profile-drawer .context-header { min-height: 56px; padding-top: var(--a6-safe-top, 0px); }
  #app #customer-profile-drawer .context-scroll { padding: 0 16px max(16px, env(safe-area-inset-bottom)); }
  #app #customer-profile-drawer .chat-dossier-field { grid-template-columns: 100px minmax(0, 1fr); }
  #app #customer-profile-drawer .dossier-field-form :is(input,select,textarea) { font-size: 16px; min-height: 44px; }
  #app #customer-profile-drawer [data-dossier-field-id] { min-height: 44px; display: flex; align-items: center; }
  #app #customer-profile-drawer [data-dossier-field-id].is-direct-editing { display: block; }
  #app #customer-profile-drawer .chat-dossier-field:focus-within { scroll-margin-block: 16px; }
  #app #customer-profile-drawer :is(.dossier-field-form, #conversation-followup-form) :is(input, select, textarea) { width: 100%; min-width: 0; max-width: 100%; box-sizing: border-box; font-size: 16px; }
  #app #customer-profile-drawer #conversation-followup-form textarea { min-height: 120px; }
  #app #customer-profile-drawer #conversation-followup-form .profile-form-actions { display: flex; flex-direction: column; align-items: stretch; gap: 8px; }
  #app #customer-profile-drawer #conversation-followup-form .detail-status { flex: 0 0 auto; }
  #app #customer-profile-drawer #conversation-followup-form .detail-status:empty { display: none; }
  #app #customer-profile-drawer #conversation-followup-form .profile-form-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
  #app #customer-profile-drawer #conversation-followup-form button { min-height: 44px; font-size: 14px; box-shadow: none; }
  #app #customer-profile-drawer #conversation-followup-form button[type="submit"] { flex: 1 1 auto; }
  #app #customer-profile-drawer :is([data-toggle-conversation-followup], [data-dossier-field-retry], [data-dossier-field-cancel]) { min-height: 44px; }
  #app #customer-profile-drawer :is([data-toggle-conversation-followup], [data-edit-full-profile]):not([hidden]) { display: inline-flex !important; align-items: center; }
  #app #customer-profile-drawer .dossier-field-form input:is([type="checkbox"], [type="radio"]) { width: 18px; height: 18px; min-height: 18px; min-width: 18px; flex: 0 0 18px; }

  /* Reuse the current dossier fields and save-on-blur behavior on phones. */
  #app[data-view="customer-detail"] #customer-detail-view { padding: 0 12px 18px; }
  #customer-detail.customer-dossier-v2 .customer-mobile-detail-appbar { margin: 0 -12px; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--line); }
  #customer-detail.customer-dossier-v2 .mobile-dossier-identity { padding: 12px 0; }
  #customer-detail.customer-dossier-v2 .mobile-dossier-identity .customer-profile-headcard { display: flex; align-items: flex-start; gap: 12px; border: 0; background: none; box-shadow: none; padding: 0; }
  #customer-detail.customer-dossier-v2 .mobile-dossier-identity .customer-detail-avatar { width: 40px; height: 40px; flex: 0 0 40px; }
  #customer-detail.customer-dossier-v2 .mobile-dossier-identity .customer-profile-head-main { min-width: 0; }
  #customer-detail.customer-dossier-v2 .mobile-dossier-identity .customer-profile-head-row1 { display: block; }
  #customer-detail.customer-dossier-v2 .mobile-dossier-identity h2 { font-size: 18px; line-height: 1.45; overflow-wrap: anywhere; }
  #customer-detail.customer-dossier-v2 .mobile-dossier-identity .customer-detail-quick-status { display: none; }
  #customer-detail.customer-dossier-v2 .customer-profile-head-row2 { font-size: 14px; gap: 4px 10px; }
  #customer-detail.customer-dossier-v2 .mobile-dossier-actions .customer-profile-actions { display: flex; flex-wrap: wrap; gap: 8px; }
  #customer-detail.customer-dossier-v2 .mobile-dossier-actions .detail-button { min-height: 44px; font-size: 14px; }
  #customer-detail.customer-dossier-v2 .mobile-dossier-actions .dossier-more-actions > summary { min-height: 44px; display: flex; align-items: center; box-sizing: border-box; }
  #customer-detail.customer-dossier-v2 .customer-detail-more-actions-hidden { display: none !important; }
  #customer-detail.customer-dossier-v2 .dossier-columns { display: flex; flex-direction: column; gap: 12px; }
  #customer-detail.customer-dossier-v2 .customer-profile-col-main, #customer-detail.customer-dossier-v2 .dossier-sidebar { width: 100%; margin: 0; gap: 12px; }
  #customer-detail.customer-dossier-v2 .customer-profile-col-main { order: 0; }
  #customer-detail.customer-dossier-v2 .dossier-sidebar { order: 1; }
  #customer-detail.customer-dossier-v2 .customer-profile-card { padding: 0; border-radius: 10px; box-shadow: none; }
  #customer-detail.customer-dossier-v2 .customer-profile-card-head { padding: 12px; min-height: 48px; gap: 8px; }
  #customer-detail.customer-dossier-v2 .customer-profile-card-head h3 { font-size: 17px; }
  #customer-detail.customer-dossier-v2 .customer-profile-card-body { padding: 0 12px 12px; }
  #customer-detail.customer-dossier-v2 .customer-overview-field { grid-template-columns: 96px minmax(0, 1fr); gap: 8px; min-height: 44px; align-items: center; padding: 7px 0; }
  #customer-detail.customer-dossier-v2 .customer-overview-label { font-size: 14px; }
  #customer-detail.customer-dossier-v2 .customer-overview-value { font-size: 16px; line-height: 1.6; }
  #customer-detail.customer-dossier-v2 [data-dossier-field-id] { min-height: 36px; display: flex; align-items: center; }
  #customer-detail.customer-dossier-v2 [data-dossier-field-id].is-direct-editing { display: block; }
  #customer-detail.customer-dossier-v2 .dossier-field-form :is(input,select,textarea) { font-size: 16px; min-height: 44px; }
  #customer-detail.customer-dossier-v2 .customer-profile-mini, #customer-detail.customer-dossier-v2 .dossier-meeting-button { min-height: 44px; font-size: 14px; }
  #customer-detail.customer-dossier-v2 .customer-profile-tl-text { font-size: 16px; }
  #customer-detail.customer-dossier-v2 .customer-profile-tl-meta { font-size: 13px; }
  #customer-detail.customer-dossier-v2 .customer-profile-modal[data-detail-tab="overview"] { display: none; }
  #customer-detail.customer-dossier-v2 .customer-profile-modal:not([data-detail-tab="overview"]) { display: flex; position: fixed; inset: 0; z-index: 2400; }
  #customer-detail.customer-dossier-v2 .customer-profile-modal-card { position: absolute; inset: 0; width: 100%; max-width: none; max-height: var(--a6-visual-viewport-height,100dvh); border-radius: 0; display: flex; flex-direction: column; }
  #customer-detail.customer-dossier-v2 .customer-profile-modal-body { flex: 1; overflow-y: auto; min-height: 0; padding-bottom: max(16px,env(safe-area-inset-bottom)); }
  #customer-detail.customer-dossier-v2 .customer-profile-modal-head { flex-shrink: 0; min-height: 56px; padding-top: var(--a6-safe-top,0px); }
  #customer-detail.customer-dossier-v2 .customer-profile-modal .cpm-t { display: none; }
  #customer-detail.customer-dossier-v2 .customer-profile-modal[data-detail-tab="followups"] .cpm-t-followups,
  #customer-detail.customer-dossier-v2 .customer-profile-modal[data-detail-tab="comments"] .cpm-t-comments,
  #customer-detail.customer-dossier-v2 .customer-profile-modal[data-detail-tab="files"] .cpm-t-files,
  #customer-detail.customer-dossier-v2 .customer-profile-modal[data-detail-tab="whatsapp-history"] .cpm-t-whatsapp-history { display: inline; }

  /* Quotation rows use the same fields/handlers as desktop, reflowed for touch. */
  #app[data-view="quotation-collaboration"] { grid-template-columns: minmax(0,1fr) !important; }
  #app .quotation-collaboration-view { min-width: 0; width: 100%; max-width: 100%; box-sizing: border-box; padding: 12px; overflow-x: hidden; }
  #app .quotation-collaboration-view :is(.quotation-card,.quotation-table-wrap,.quotation-head,.quotation-toolbar) { min-width: 0; max-width: 100%; box-sizing: border-box; }
  #app .quotation-head { gap: 12px; }
  #app .quotation-head h1 { font-size: 22px; }
  #app .quotation-head-actions { flex-wrap: wrap; }
  #app .quotation-head-actions button { min-height: 44px; }
  #app .quotation-toolbar { padding: 12px; gap: 10px; }
  #app .quotation-tabs { flex-wrap: nowrap; overflow-x: auto; width: 100%; }
  #app .quotation-tab { flex: none; min-height: 44px; font-size: 14px; }
  #app .quotation-search { min-height: 44px; font-size: 16px; }
  #app .quotation-table { min-width: 0; width: 100%; display: block; }
  #app .quotation-table thead { display: none; }
  #app .quotation-table tbody { display: block; }
  #app .quotation-table tr { display: grid; grid-template-columns: minmax(0,1fr) auto; padding: 14px 12px; gap: 6px 12px; border-top: 1px solid var(--line); }
  #app .quotation-table td { padding: 0; border: 0; min-width: 0; overflow-wrap: anywhere; font-size: 14px; }
  #app .quotation-table td:nth-child(1) { grid-column: 1; grid-row: 2; }
  #app .quotation-table td:nth-child(2) { grid-column: 1 / -1; grid-row: 1; font-size: 16px; }
  #app .quotation-table .quotation-sales-cell { grid-column: 1; grid-row: 3; }
  #app .quotation-table .quotation-sales-cell::before { content: '销售：'; color: var(--muted); }
  #app .quotation-table .quotation-assignee-cell { display: block; grid-column: 1 / -1; grid-row: 4; }
  #app .quotation-table .quotation-assignee-cell::before { content: '接单人：'; color: var(--muted); }
  #app .quotation-table .quotation-assignee-account { display: inline; margin-left: 6px; }
  #app .quotation-table .quotation-drawing-cell { grid-column: 1 / -1; grid-row: 5; width: auto; min-width: 0; }
  #app .quotation-table .quotation-drawing-cell::before { content: '有无图纸：'; color: var(--muted); }
  #app .quotation-table .quotation-submitted-cell { display: none; }
  #app .quotation-table .quotation-status-cell { display: block !important; grid-column: 2; grid-row: 2; }
  #app .quotation-table .quotation-action-cell { display: block !important; grid-column: 2; grid-row: 3; width: auto !important; }
  #app .quotation-table td[colspan] { display: block !important; grid-column: 1 / -1; text-align: center; padding: 20px 0; }
  #app .quotation-row-open { min-height: 44px; }

  /* Claimed list and detail are separate mobile panes, sharing the desktop data. */
  #app [data-mobile-customer="true"] [data-pool-pane="claimed"] .customer-pool-workspace-customers > header,
  #app [data-mobile-customer="true"] [data-pool-customer-search],
  #app [data-mobile-customer="true"] [data-pool-customer-list] { display: none; }
  #app .customer-pool-workspace-columns { display: block; }
  #app [data-pool-customer-back] { min-height: 44px; margin-bottom: 12px; }
  #app [data-pool-customer-title] { font-size: 19px; line-height: 1.5; }
  #app .customer-pool-workspace-customers { padding: 12px; }
  #app .customer-pool-workspace-customers > header p { margin: 8px 0; font-size: 14px; }
  #app .customer-pool-workspace-customers form { gap: 8px; }
  #app .customer-pool-workspace-customers input { font-size: 16px; min-height: 44px; }
  #app .customer-pool-button, #app .claimed-contact button { min-height: 44px; font-size: 14px; }
  #app .claimed-contact { padding: 14px; }
  #app .claimed-contact-heading input { font-size: 22px; }
  #app .claimed-contact-actions { display: grid; grid-template-columns: 1fr 1fr; width: 100%; gap: 8px; }
  #app [data-mobile-history="true"] [data-pool-history-slot] { position: fixed; inset: 0; z-index: 2400; display: flex; flex-direction: column; height: var(--a6-visual-viewport-height,100dvh); background: var(--surface); overflow: hidden; padding: max(8px,env(safe-area-inset-top)) 12px max(12px,env(safe-area-inset-bottom)); box-sizing: border-box; }
  #app [data-mobile-history="true"] .customer-whatsapp-history-shell { display: flex; flex: 1; min-height: 0; }
  #app [data-mobile-history="true"] .customer-whatsapp-history-layout { height: auto; flex: 1; min-height: 0; }
  #app [data-mobile-history="true"] .customer-whatsapp-history-channels { display: flex; flex-direction: row; align-items: stretch; flex: none; overflow-x: auto; overflow-y: hidden; max-height: 132px; gap: 8px; }
  #app [data-mobile-history="true"] .customer-whatsapp-history-channel { flex: 0 0 210px; min-width: 0; min-height: 88px; padding: 9px 10px; gap: 3px; }
  #app [data-mobile-history="true"] .customer-whatsapp-history-channel strong { font-size: 14px; line-height: 1.4; }
  #app [data-mobile-history="true"] .customer-whatsapp-history-channel small { font-size: 12px; line-height: 1.4; }
  #app [data-mobile-history="true"] .customer-whatsapp-history-channel-meta { display: none; }
  #app [data-mobile-history="true"] .customer-whatsapp-history-actions { display: flex; align-items: center; gap: 8px; }
  #app [data-mobile-history="true"] .customer-whatsapp-history-conversation-head button { width: auto; min-height: 44px; }
  #app [data-mobile-history="true"] .customer-whatsapp-history-conversation { height: auto; flex: 1; min-height: 0; }
  #app [data-mobile-history="true"] .customer-whatsapp-history-message-list { min-height: 0; flex: 1; }
  #app [data-pool-history-back] { min-height: 44px; flex-shrink: 0; align-self: flex-start; margin-bottom: 8px; }
  #app .customer-whatsapp-history-message { font-size: 16px; }
  #app .customer-whatsapp-history-translate { min-height: 44px; font-size: 14px; }
  .customer-project-doc-overlay { top: var(--project-doc-viewport-top,0px); bottom: auto; height: var(--project-doc-viewport-height,100dvh); }
  .project-doc-shell { min-height: 0; }
  .project-doc-header { display: grid; grid-template-columns: auto minmax(0,1fr); gap: 6px 10px; flex-shrink: 0; padding: 8px 12px; min-height: 0; }
  .project-doc-header h2 { font-size: 18px; }
  .project-doc-status { grid-column: 1 / -1; font-size: 12px; line-height: 1.5; }
  .project-doc-actions { grid-column: 1 / -1; min-width: 0; flex-wrap: nowrap; gap: 6px; overflow-x: auto; margin: 0; }
  .project-doc-actions > * { flex-shrink: 0; }
  .project-doc-actions button, .project-doc-toolbar button, .project-doc-toolbar select { min-height: 44px; font-size: 16px; }
  .project-doc-actions button { font-size: 14px; padding-inline: 6px; }
  .project-doc-format-menu { flex-shrink: 0; background: var(--surface); border-bottom: 1px solid var(--line); }
  .project-doc-format-menu > summary { cursor: pointer; padding: 11px 16px; min-height: 44px; box-sizing: border-box; color: var(--accent-strong); font-size: 14px; }
  .project-doc-format-menu:not([open]) .project-doc-toolbar { display: none; }
  .project-doc-paper { min-width: 0; width: 100%; max-width: 100%; box-sizing: border-box; padding: 18px 16px 32px; }
  .project-doc-title { font-size: 22px; }
  .project-doc-body { min-height: 240px; }
  .project-doc-body table { min-width: 0; width: 100%; table-layout: fixed; }
  .project-doc-body td, .project-doc-body th { min-width: 0; padding: 8px; overflow-wrap: anywhere; }
  .project-doc-toolbar { max-height: 132px; overflow-y: auto; }
  .project-doc-footer { flex-shrink: 0; font-size: 12px; line-height: 1.5; padding: 6px 12px; }
  .customer-project-doc-overlay.is-phone-keyboard .project-doc-actions,
  .customer-project-doc-overlay.is-phone-keyboard .project-doc-footer { display: none; }
}
