/**
 * Focused Mobile Experience — phone-only presentation (≤767px + body.focused-mobile-experience).
 * Desktop/tablet UI is untouched; all rules are scoped to .focused-mobile-experience.is-mobile.
 */

@media (max-width: 767px) {
  /* Record detail already owns contextual actions; never float Create over its content. */
  body.is-mobile:has(.app-shell.contacts-v2-view.contact-detail-visible) .mobile-create-fab {
    display: none !important;
  }

  body.focused-mobile-experience.is-mobile {
    --fme-bottom-clearance: calc(88px + env(safe-area-inset-bottom, 0px));
    --fme-dock-height: 56px;
  }

  /* Hide competing chrome */
  body.focused-mobile-experience.is-mobile .ask-lite-edge-tab-wrap {
    display: none !important;
  }

  /* Collapsed Ask must leave the layout entirely — iOS Safari hit-tests fixed layers anyway */
  body.focused-mobile-experience.is-mobile #askLiteRoot.ask-lite-shelf--collapsed {
    display: none !important;
    pointer-events: none !important;
  }

  body.focused-mobile-experience.is-mobile #askLiteRoot.ask-lite-shelf--open {
    display: block !important;
    pointer-events: auto;
  }

  body.focused-mobile-experience.is-mobile #briefingShelfRoot.briefing-shelf--collapsed {
    display: none !important;
    pointer-events: none !important;
  }

  body.focused-mobile-experience.is-mobile .record-overview-mode-bar,
  body.focused-mobile-experience.is-mobile #contactOverviewModeBar,
  body.focused-mobile-experience.is-mobile #dealWorkspaceModeBar,
  body.focused-mobile-experience.is-mobile #invoiceOverviewModeBar,
  body.focused-mobile-experience.is-mobile #projectOverviewModeBar {
    display: none !important;
  }

  body.focused-mobile-experience.is-mobile .contact-action-deck,
  body.focused-mobile-experience.is-mobile .deal-nba-deck,
  body.focused-mobile-experience.is-mobile .mm-mobile-bar {
    display: none !important;
  }

  body.focused-mobile-experience.is-mobile #detailPanel .detailHeaderAiStrip,
  body.focused-mobile-experience.is-mobile .deal-sidebar,
  body.focused-mobile-experience.is-mobile .deal-ghost-toolbar,
  body.focused-mobile-experience.is-mobile .invoice-ghost-toolbar,
  body.focused-mobile-experience.is-mobile .quote-ghost-toolbar {
    display: none !important;
  }

  /* Ask FAB — single coordinated entry */
  body.focused-mobile-experience.is-mobile .mobile-ask-fab {
    position: fixed;
    left: 12px;
    bottom: calc(52px + env(safe-area-inset-bottom, 0px) + 8px);
    z-index: 1001;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 44px;
    padding: 0 14px;
    border: none;
    border-radius: 999px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.35);
  }

  body.focused-mobile-experience.is-mobile .mobile-create-fab {
    bottom: calc(52px + env(safe-area-inset-bottom, 0px) + 8px);
  }

  body.focused-mobile-experience.is-mobile.fme-record-detail-open .mobile-ask-fab,
  body.focused-mobile-experience.is-mobile.fme-record-detail-open .mobile-create-fab {
    display: none !important;
  }

  body.focused-mobile-experience.is-mobile.fme-email-composer-open .mobile-ask-fab,
  body.focused-mobile-experience.is-mobile.fme-email-composer-open .mobile-create-fab,
  body.focused-mobile-experience.is-mobile.fme-send-sheet-open .mobile-ask-fab,
  body.focused-mobile-experience.is-mobile.fme-send-sheet-open .mobile-create-fab,
  body.focused-mobile-experience.is-mobile.fme-more-sheet-open .mobile-ask-fab,
  body.focused-mobile-experience.is-mobile.ask-lite-open .mobile-ask-fab,
  body.focused-mobile-experience.is-mobile.mobile-more-sheet-open .mobile-ask-fab {
    display: none !important;
  }

  /* Action dock on record detail */
  body.focused-mobile-experience.is-mobile .fme-action-dock {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(52px + env(safe-area-inset-bottom, 0px));
    z-index: 999;
    display: grid;
    grid-template-columns: 1.2fr repeat(4, 1fr);
    gap: 4px;
    padding: 6px 8px;
    background: color-mix(in srgb, var(--surface-1, #fff) 92%, transparent);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border, rgba(0, 0, 0, 0.08));
  }

  body.focused-mobile-experience.is-mobile #detailPanel.active,
  body.focused-mobile-experience.is-mobile #dealWorkspaceMount .deal-workspace.visible {
    padding-bottom: calc(var(--fme-bottom-clearance) + var(--fme-dock-height) + 8px) !important;
  }

  body.focused-mobile-experience.is-mobile .fme-action-dock__btn {
    min-height: 44px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 10px;
    background: var(--surface-1, #fff);
    font-size: 11px;
    font-weight: 600;
    color: var(--text-primary, #111);
  }

  body.focused-mobile-experience.is-mobile .fme-action-dock__btn--primary {
    background: var(--primary, #2563eb);
    border-color: transparent;
    color: #fff;
    font-size: 12px;
  }

  body.focused-mobile-experience.is-mobile .fme-action-dock__btn--more {
    color: var(--text-secondary, #6b7280);
  }

  /* More sheet */
  body.focused-mobile-experience.is-mobile .fme-more-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1100;
    background: rgba(0, 0, 0, 0.35);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  body.focused-mobile-experience.is-mobile .fme-more-backdrop.open {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }

  body.focused-mobile-experience.is-mobile .fme-more-sheet {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1101;
    max-height: 50vh;
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px));
    border-radius: 16px 16px 0 0;
    background: var(--surface-1, #fff);
    transform: translateY(100%);
    transition: transform 0.25s ease;
    pointer-events: none;
  }

  body.focused-mobile-experience.is-mobile .fme-more-sheet.open {
    display: block;
    transform: translateY(0);
    pointer-events: auto;
  }

  body.focused-mobile-experience.is-mobile .fme-more-sheet__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
  }

  body.focused-mobile-experience.is-mobile .fme-more-sheet__item {
    display: block;
    width: 100%;
    min-height: 48px;
    margin-bottom: 8px;
    padding: 12px 14px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 10px;
    background: var(--surface-1, #fff);
    text-align: left;
    font-size: 15px;
  }

  /* Quick Add focused layout */
  body.focused-mobile-experience.is-mobile .fme-quick-add .quick-lead-modal {
    max-height: 92vh;
  }

  body.focused-mobile-experience.is-mobile .fme-quick-add__details-compact .quick-lead-field:not(:has(#qlLeadDate)):not(:has(#qlOwner)) {
    display: none;
  }

  body.focused-mobile-experience.is-mobile .fme-quick-add__deal-only .quick-lead-action:has(#qlSendInitialEmail),
  body.focused-mobile-experience.is-mobile .fme-quick-add__deal-only .quick-lead-action:has(#qlFollowUpTask) {
    display: none;
  }

  body.focused-mobile-experience.is-mobile .fme-quick-add__toggle {
    width: 100%;
    margin: 8px 0 0;
  }

  /* Email composer */
  body.focused-mobile-experience.is-mobile .fme-email-composer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 12000;
    background: var(--surface-0, #f8fafc);
    display: flex;
    flex-direction: column;
  }

  body.focused-mobile-experience.is-mobile .fme-email-composer {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: 100dvh;
  }

  body.focused-mobile-experience.is-mobile .fme-email-composer__head {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 10px;
    align-items: center;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 10px;
    border-bottom: 1px solid var(--border, #e5e7eb);
    background: var(--surface-1, #fff);
  }

  body.focused-mobile-experience.is-mobile .fme-email-composer__back,
  body.focused-mobile-experience.is-mobile .fme-email-composer__ai {
    min-width: 44px;
    min-height: 44px;
    border: none;
    border-radius: 10px;
    background: var(--surface-2, #f3f4f6);
    font-size: 14px;
  }

  body.focused-mobile-experience.is-mobile .fme-email-composer__body {
    flex: 1;
    overflow: auto;
    padding: 12px;
  }

  body.focused-mobile-experience.is-mobile .fme-email-composer__field {
    display: grid;
    gap: 6px;
    margin-bottom: 12px;
  }

  body.focused-mobile-experience.is-mobile .fme-email-composer__field input,
  body.focused-mobile-experience.is-mobile .fme-email-composer__field textarea {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 10px;
    font-size: 16px;
    font-family: inherit;
  }

  body.focused-mobile-experience.is-mobile .fme-email-composer__field--body textarea {
    min-height: 160px;
    resize: vertical;
  }

  body.focused-mobile-experience.is-mobile .fme-email-composer__foot {
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border, #e5e7eb);
    background: var(--surface-1, #fff);
  }

  body.focused-mobile-experience.is-mobile .fme-email-composer__send {
    width: 100%;
    min-height: 48px;
  }

  /* Send sheet */
  body.focused-mobile-experience.is-mobile .fme-send-sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 11500;
    display: flex;
    align-items: flex-end;
    background: rgba(0, 0, 0, 0.4);
  }

  body.focused-mobile-experience.is-mobile .fme-send-sheet {
    width: 100%;
    max-height: 85vh;
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px));
    border-radius: 16px 16px 0 0;
    background: var(--surface-1, #fff);
  }

  body.focused-mobile-experience.is-mobile .fme-send-sheet__field {
    display: grid;
    gap: 6px;
    margin: 12px 0;
  }

  body.focused-mobile-experience.is-mobile .fme-send-sheet__field input {
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 10px;
    font-size: 16px;
  }

  body.focused-mobile-experience.is-mobile .fme-send-sheet__foot {
    display: grid;
    gap: 8px;
    margin-top: 12px;
  }

  body.focused-mobile-experience.is-mobile .fme-send-sheet__foot .btn {
    min-height: 48px;
  }

  body.focused-mobile-experience.is-mobile .fme-send-sheet__error {
    color: #b91c1c;
    font-size: 13px;
  }

  /* Ask mobile */
  body.focused-mobile-experience.is-mobile.ask-lite-open #askLiteRoot.ask-lite-shelf {
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    width: 100% !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-height: none;
    border-radius: 0;
    box-shadow: none;
  }

  body.focused-mobile-experience.is-mobile .ask-lite-mobile-empty {
    padding: 12px 4px 8px;
  }

  body.focused-mobile-experience.is-mobile .ask-lite-mobile-empty__title {
    margin: 0 0 4px;
    font-size: 18px;
    font-weight: 700;
  }

  body.focused-mobile-experience.is-mobile .ask-lite-mobile-empty__sub {
    margin: 0 0 12px;
    color: var(--text-secondary, #6b7280);
    font-size: 13px;
  }

  body.focused-mobile-experience.is-mobile .ask-lite-bubble--mobile {
    padding: 12px;
  }

  body.focused-mobile-experience.is-mobile .ask-lite-bubble--mobile .ask-lite-cta {
    min-height: 44px;
    width: 100%;
    margin-top: 8px;
  }

  body.focused-mobile-experience.is-mobile .ask-lite-mobile-more summary {
    min-height: 44px;
    padding: 10px 0;
    cursor: pointer;
    color: var(--text-secondary, #6b7280);
  }

  body.focused-mobile-experience.is-mobile .ask-lite-mobile-handoff__title {
    margin: 0 0 6px;
    font-weight: 700;
  }

  body.focused-mobile-experience.is-mobile .bc-wizard__footer #bcPreviewDocBtn,
  body.focused-mobile-experience.is-mobile .bc-wizard__footer #bcCustomizeBtn,
  body.focused-mobile-experience.is-mobile .bc-wizard--focused-mobile .bc-wizard__footer #bcPreviewDocBtn,
  body.focused-mobile-experience.is-mobile .bc-wizard--focused-mobile .bc-wizard__footer #bcCustomizeBtn {
    display: none;
  }

  /* Contact overview KPI — align with phone polish (corner add, essentials grid) */
  body.focused-mobile-experience.is-mobile #detailPanel .crm-overview-hero--contact-command .crm-overview-hero__status-card-shell--client-room,
  body.focused-mobile-experience.is-mobile #detailPanel .crm-overview-hero--contact-command .crm-overview-hero__status-card-shell--projects {
    display: none !important;
  }

  body.focused-mobile-experience.is-mobile .app-shell.contacts-v2-view.contact-detail-visible #detailPanel .contact-overview-top .crm-overview-hero--contact-command .crm-overview-hero__status {
    gap: 6px !important;
  }

  /* Overview simplification */
  body.focused-mobile-experience.is-mobile #detailPanel [data-detail-tab="documents"],
  body.focused-mobile-experience.is-mobile #detailPanel [data-detail-tab="portal"],
  body.focused-mobile-experience.is-mobile #detailPanel [data-detail-tab="projects"],
  body.focused-mobile-experience.is-mobile #detailPanel [data-detail-tab="relationships"],
  body.focused-mobile-experience.is-mobile #detailPanel [data-detail-tab="tasks"] {
    display: none !important;
  }

  /* Deal workspace tabs use data-deal-section-tab (not data-section-anchor). Keep phone deal nav tabs visible. */
  body.focused-mobile-experience.is-mobile #dealWorkspaceMount .deal-section-tab {
    display: inline-flex !important;
  }

  body.focused-mobile-experience.is-mobile .fme-quick-add.quick-lead-backdrop {
    z-index: 10720 !important;
    padding: 0;
  }

  body.focused-mobile-experience.is-mobile.fme-quick-add-open .mobile-create-fab {
    visibility: hidden;
    pointer-events: none;
  }

  body.focused-mobile-experience.is-mobile .fme-quick-add__modal {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    display: flex;
    flex-direction: column;
  }

  body.focused-mobile-experience.is-mobile .fme-quick-add .quick-lead-modal__head,
  body.focused-mobile-experience.is-mobile .fme-quick-add .quick-lead-modal__foot {
    flex: 0 0 auto;
    position: relative;
    z-index: 3;
  }

  body.focused-mobile-experience.is-mobile .fme-quick-add .quick-lead-modal__body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  body.focused-mobile-experience.is-mobile .fme-quick-add .quick-lead-modal__head-actions .iconBtn,
  body.focused-mobile-experience.is-mobile .fme-quick-add .quick-lead-modal__foot .btn {
    min-width: 44px;
    min-height: 44px;
  }

  body.focused-mobile-experience.is-mobile .fme-quick-add #qlPresetLede {
    display: none;
  }

  body.focused-mobile-experience.is-mobile .ask-lite-saved-segments-bar,
  body.focused-mobile-experience.is-mobile .ask-lite-help-link {
    display: none;
  }

  body.focused-mobile-experience.is-mobile .ask-lite-mobile-empty__voice {
    margin: 0 0 10px;
    font-size: 12px;
    color: var(--text-secondary, #6b7280);
  }

  body.focused-mobile-experience.is-mobile .fme-email-composer__review,
  body.focused-mobile-experience.is-mobile .fme-send-sheet__review {
    display: grid;
    gap: 10px;
    margin: 0;
  }

  body.focused-mobile-experience.is-mobile .fme-email-composer__review dt,
  body.focused-mobile-experience.is-mobile .fme-send-sheet__review dt {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary, #6b7280);
  }

  body.focused-mobile-experience.is-mobile .fme-email-composer__review dd,
  body.focused-mobile-experience.is-mobile .fme-send-sheet__review dd {
    margin: 0 0 8px;
    font-size: 15px;
  }

  body.focused-mobile-experience.is-mobile .fme-email-composer__review-body {
    white-space: pre-wrap;
    max-height: 160px;
    overflow: auto;
  }

  body.focused-mobile-experience.is-mobile .fme-email-composer__foot,
  body.focused-mobile-experience.is-mobile .fme-send-sheet__foot {
    display: grid;
    gap: 8px;
  }

  body.focused-mobile-experience.is-mobile .fme-email-composer:not(.fme-email-composer--review) .fme-email-composer__foot,
  body.focused-mobile-experience.is-mobile .fme-send-sheet__foot:has(.btn:only-child) {
    grid-template-columns: 1fr;
  }

  body.focused-mobile-experience.is-mobile .fme-email-composer--review .fme-email-composer__foot,
  body.focused-mobile-experience.is-mobile .fme-send-sheet__foot:has([data-fme-send="back"]) {
    grid-template-columns: 1fr 1fr;
  }

  body.focused-mobile-experience.is-mobile .fme-send-sheet__lede,
  body.focused-mobile-experience.is-mobile .fme-send-sheet__hint {
    margin: 0 0 8px;
    color: var(--text-secondary, #6b7280);
    font-size: 14px;
    line-height: 1.45;
  }

  body.focused-mobile-experience.is-mobile .fme-send-sheet__head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
  }

  body.focused-mobile-experience.is-mobile .fme-send-sheet__close {
    min-width: 44px;
    min-height: 44px;
    border: none;
    border-radius: 10px;
    background: var(--surface-2, #f3f4f6);
  }

  body.focused-mobile-experience.is-mobile .ask-lite-mobile-table-note {
    margin: 8px 0 0;
    font-size: 12px;
    color: var(--text-secondary, #6b7280);
  }
}
