/* Zypexa Mobile UI Polish — Stage 10 Pass 1 — critical real-device layout corrections. */
:root {
    --zxp-mobile-visual-polish-layer: stage10-pass1;
    --zxp-mobile-visual-polish-edge-gap: 8px;
    --zxp-mobile-visual-polish-voice-width: 238px;
}

/* A hidden quick-search panel must never leave an empty bordered strip below the topbar. */
.zxp-global-search__panel[hidden] {
    display: none !important;
}

@media (max-width: 760px) {
    /* Keep all five primary destinations authoritative and fully available on phones. */
    body[data-zxp-app-surface="workspace"][data-zxp-mobile-bottom-nav="enabled"] .zxp-mobile-bottom-nav {
        grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
        width: 100%;
        max-width: 100vw;
        min-width: 0;
    }

    body[data-zxp-app-surface="workspace"][data-zxp-mobile-bottom-nav="enabled"] .zxp-mobile-bottom-nav__item,
    body[data-zxp-app-surface="workspace"][data-zxp-mobile-bottom-nav="enabled"] .zxp-mobile-bottom-nav__slot {
        min-width: 0;
    }

    /*
     * The collapsed Voice control is a floating utility, not a navigation destination.
     * Keep it above the five-column bottom navigation even if the softphone mobile JS
     * layer is still initializing. Active/incoming collapsed calls retain their larger
     * compact-call footprint; only the idle Voice pill receives the 74px reserve.
     */
    body[data-zxp-app-surface="workspace"][data-zxp-mobile-bottom-nav="enabled"]:has([data-softphone-root].softphone-collapsed:not([data-softphone-mode="active"]):not([data-softphone-mode="incoming"])) {
        --zxp-mobile-softphone-height: 74px;
    }

    body[data-zxp-app-surface="workspace"] [data-softphone-root].softphone-collapsed {
        right: max(var(--zxp-mobile-visual-polish-edge-gap, 8px), var(--zxp-mobile-safe-right, 0px)) !important;
        bottom: calc(
            var(--zxp-mobile-bottom-nav-height, var(--zxp-mobile-bottom-nav-base-height, 68px))
            + var(--zxp-mobile-safe-bottom, 0px)
            + var(--zxp-mobile-visual-polish-edge-gap, 8px)
        ) !important;
        left: auto !important;
        max-width: calc(
            var(--zxp-mobile-viewport-width, 100vw)
            - var(--zxp-mobile-safe-left, 0px)
            - var(--zxp-mobile-safe-right, 0px)
            - 16px
        ) !important;
    }

    body[data-zxp-app-surface="workspace"] [data-softphone-root].softphone-collapsed:not([data-softphone-mode="active"]):not([data-softphone-mode="incoming"]) {
        width: min(
            var(--zxp-mobile-visual-polish-voice-width, 238px),
            calc(
                var(--zxp-mobile-viewport-width, 100vw)
                - var(--zxp-mobile-safe-left, 0px)
                - var(--zxp-mobile-safe-right, 0px)
                - 16px
            )
        ) !important;
        max-height: 74px;
    }

    body[data-zxp-app-surface="workspace"] [data-softphone-root].softphone-collapsed[data-softphone-mode="active"],
    body[data-zxp-app-surface="workspace"] [data-softphone-root].softphone-collapsed[data-softphone-mode="incoming"] {
        width: min(
            390px,
            calc(
                var(--zxp-mobile-viewport-width, 100vw)
                - var(--zxp-mobile-safe-left, 0px)
                - var(--zxp-mobile-safe-right, 0px)
                - 16px
            )
        ) !important;
    }

    body[data-zxp-app-surface="workspace"] [data-softphone-root].softphone-collapsed:not([data-softphone-mode="active"]):not([data-softphone-mode="incoming"]) .softphone-header {
        min-height: 58px;
        padding: 8px 10px;
    }

    /*
     * Constrain the expanded phone to the visual viewport rather than the layout
     * viewport. This prevents iOS focus/keyboard panning from pushing the phone off
     * the right side of the screen.
     */
    body[data-zxp-app-surface="workspace"] [data-softphone-root]:not(.softphone-collapsed) {
        box-sizing: border-box;
        right: auto !important;
        left: calc(
            var(--zxp-mobile-viewport-offset-left, 0px)
            + var(--zxp-mobile-safe-left, 0px)
            + var(--zxp-mobile-visual-polish-edge-gap, 8px)
        ) !important;
        width: calc(
            var(--zxp-mobile-viewport-width, 100vw)
            - var(--zxp-mobile-safe-left, 0px)
            - var(--zxp-mobile-safe-right, 0px)
            - var(--zxp-mobile-visual-polish-edge-gap, 8px)
            - var(--zxp-mobile-visual-polish-edge-gap, 8px)
        ) !important;
        max-width: calc(
            var(--zxp-mobile-viewport-width, 100vw)
            - var(--zxp-mobile-safe-left, 0px)
            - var(--zxp-mobile-safe-right, 0px)
            - var(--zxp-mobile-visual-polish-edge-gap, 8px)
            - var(--zxp-mobile-visual-polish-edge-gap, 8px)
        ) !important;
        max-height: calc(
            var(--zxp-mobile-viewport-height, 100dvh)
            - var(--zxp-mobile-safe-top, 0px)
            - var(--zxp-mobile-safe-bottom, 0px)
            - var(--zxp-mobile-visual-polish-edge-gap, 8px)
            - var(--zxp-mobile-visual-polish-edge-gap, 8px)
        ) !important;
    }

    body[data-zxp-app-surface="workspace"].zxp-mobile-keyboard-open [data-softphone-root]:not(.softphone-collapsed),
    body[data-zxp-app-surface="workspace"].zxp-softphone-mobile-keyboard-open [data-softphone-root]:not(.softphone-collapsed) {
        top: calc(
            var(--zxp-mobile-viewport-offset-top, 0px)
            + var(--zxp-mobile-visual-polish-edge-gap, 8px)
        ) !important;
        bottom: auto !important;
        max-height: calc(
            var(--zxp-mobile-viewport-height, 100dvh)
            - var(--zxp-mobile-visual-polish-edge-gap, 8px)
            - var(--zxp-mobile-visual-polish-edge-gap, 8px)
        ) !important;
    }

    /* iOS Safari should not auto-zoom the phone when the dial field receives focus. */
    body[data-zxp-app-surface="workspace"] [data-softphone-root] :where(input, textarea, select) {
        min-width: 0;
        max-width: 100%;
        box-sizing: border-box;
        font-size: 16px !important;
    }

    body[data-zxp-app-surface="workspace"] [data-softphone-root] .softphone-custom-call-form {
        min-width: 0;
    }

    body[data-zxp-app-surface="workspace"].zxp-mobile-keyboard-open [data-softphone-notifications],
    body[data-zxp-app-surface="workspace"].zxp-mobile-keyboard-open [data-softphone-root] .softphone-notifications,
    body[data-zxp-app-surface="workspace"].zxp-softphone-mobile-keyboard-open [data-softphone-notifications],
    body[data-zxp-app-surface="workspace"].zxp-softphone-mobile-keyboard-open [data-softphone-root] .softphone-notifications {
        display: none !important;
    }

    /* Remove the desktop flex-basis that turns the Contacts header into a tall blank block. */
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace .zxp-list-heading-copy,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace .zxp-list-actions {
        flex: 0 1 auto !important;
        min-width: 0;
        max-width: 100%;
    }

    body[data-zxp-app-surface="workspace"] .zxp-list-workspace .zxp-list-header {
        gap: 12px;
    }

    body[data-zxp-app-surface="workspace"] .zxp-list-workspace .zxp-list-heading-copy p {
        margin-bottom: 0;
    }

    body[data-zxp-app-surface="workspace"] .zxp-list-workspace .zxp-list-actions {
        align-items: center;
        justify-content: flex-start;
        gap: 8px;
    }

    body[data-zxp-app-surface="workspace"] .zxp-list-workspace .zxp-list-actions .button,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace .zxp-list-actions button {
        width: auto;
        max-width: 100%;
        min-height: 42px;
        flex: 0 1 auto;
    }

    /* Harden the authentication form against iOS focus zoom and horizontal reflow. */
    body.login-page {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        overflow-x: hidden;
        -webkit-text-size-adjust: 100%;
    }

    body.login-page .app-shell,
    body.login-page .main-shell,
    body.login-page .content-wrap,
    body.login-page .login-shell,
    body.login-page .login-panel,
    body.login-page .login-card,
    body.login-page .zxp-auth-form {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        box-sizing: border-box;
    }

    body.login-page .login-shell {
        grid-template-columns: minmax(0, 1fr);
    }

    body.login-page .zxp-auth-form :where(input, select, textarea, button, .button) {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        box-sizing: border-box;
    }

    body.login-page .zxp-auth-form :where(input, select, textarea) {
        font-size: 16px !important;
    }
}

/* Stage 10 Pass 2 — mobile density and visual hierarchy polish. */
:root {
    --zxp-mobile-density-polish-layer: stage10-pass2;
    --zxp-mobile-density-touch-target: 42px;
    --zxp-mobile-density-card-gap: 0.6rem;
}

@media (max-width: 760px) {
    /* Contacts: keep primary tools reachable without spending a full screen on controls. */
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-list-header {
        gap: 8px;
    }

    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-list-actions {
        display: flex;
        flex-wrap: nowrap;
        gap: 6px;
        overflow-x: auto;
        padding: 1px 0 3px;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }

    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-list-actions::-webkit-scrollbar {
        display: none;
    }

    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-list-actions .button,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-list-actions button {
        flex: 0 0 auto;
        min-height: 38px;
        padding: 0.42rem 0.66rem;
        border-radius: 12px;
        font-size: 0.78rem;
        white-space: nowrap;
    }

    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-list-filter-panel {
        gap: 0.5rem;
        padding: 0.65rem;
        border-radius: 15px;
    }

    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-list-filter-grid,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-table-meta-row {
        gap: 0.45rem;
    }

    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .contacts-toolbar {
        margin-block: 0.55rem;
        padding: 0.6rem;
        border-radius: 14px;
    }

    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .contacts-page-size {
        gap: 0.3rem;
    }

    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .contacts-page-size select {
        min-height: var(--zxp-mobile-density-touch-target, 42px);
    }

    .contact-mobile-card-list[data-stage5-contact-cards="stage5-pass1"] {
        gap: var(--zxp-mobile-density-card-gap, 0.6rem);
    }

    .contact-mobile-sort-form {
        gap: 0.45rem;
        padding: 0.6rem;
        border-radius: 14px;
    }

    .contact-mobile-sort-form label {
        gap: 0.22rem;
    }

    .contact-mobile-sort-form select,
    .contact-mobile-sort-form .button {
        min-height: var(--zxp-mobile-density-touch-target, 42px);
    }

    .contact-mobile-card {
        gap: 0.52rem;
        padding: 0.72rem;
        border-radius: 16px;
        box-shadow: 0 8px 20px rgba(15, 23, 42, 0.055);
    }

    .contact-mobile-card-header {
        gap: 0.5rem;
    }

    .contact-mobile-card-heading {
        gap: 0.18rem;
    }

    .contact-mobile-card-name {
        font-size: 1rem;
    }

    .contact-mobile-card-account {
        gap: 0.18rem 0.35rem;
        font-size: 0.82rem;
    }

    .contact-mobile-card-edit {
        min-height: 36px;
        padding: 0.36rem 0.56rem;
    }

    .contact-mobile-card-contact-grid,
    .contact-mobile-card-selected-details {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.38rem;
    }

    .contact-mobile-card-field,
    .contact-mobile-card-detail {
        gap: 0.16rem;
        padding: 0.48rem;
        border-radius: 11px;
    }

    .contact-mobile-card-field > span,
    .contact-mobile-card-account > span,
    .contact-mobile-card-detail dt {
        font-size: 0.67rem;
        letter-spacing: 0.035em;
    }

    .contact-mobile-card-field strong,
    .contact-mobile-card-detail dd {
        font-size: 0.84rem;
        line-height: 1.24;
    }

    .contact-mobile-card-status-row,
    .contact-mobile-card-tags {
        gap: 0.24rem;
        font-size: 0.82rem;
        line-height: 1.22;
    }

    .contact-mobile-card-actions {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 0.38rem;
        padding-top: 0;
    }

    .contact-mobile-card-actions .button,
    .contact-mobile-card-actions button {
        min-height: var(--zxp-mobile-density-touch-target, 42px);
        padding: 0.4rem 0.3rem;
        border-radius: 12px;
        font-size: 0.77rem;
    }

    /* Contact Profile: keep phone-first actions dominant while reducing utility chrome. */
    body[data-zxp-app-surface="workspace"] .profile-hero.zxp-record-hero {
        margin-bottom: 10px;
        padding: 16px;
    }

    body[data-zxp-app-surface="workspace"] .contact-mobile-communication-actions[data-stage4-contact-actions="stage4-pass2"] {
        gap: 0.42rem;
        padding: 0.62rem;
        border-radius: 16px;
        box-shadow: 0 8px 22px rgba(15, 23, 42, 0.065);
    }

    body[data-zxp-app-surface="workspace"] .contact-mobile-action-context {
        gap: 0.45rem;
        font-size: 0.76rem;
    }

    body[data-zxp-app-surface="workspace"] .contact-mobile-action-row {
        gap: 0.38rem;
    }

    body[data-zxp-app-surface="workspace"] .contact-mobile-action-button {
        min-height: var(--zxp-mobile-density-touch-target, 42px);
    }

    body[data-zxp-app-surface="workspace"] .contact-mobile-action-helper {
        font-size: 0.74rem;
        line-height: 1.32;
    }

    body[data-zxp-app-surface="workspace"] .record-layout-toolbar {
        gap: 0.42rem;
        margin: 0.55rem 0 0.7rem;
        padding: 0.6rem 0.68rem;
        border-radius: 15px;
    }

    body[data-zxp-app-surface="workspace"] .record-layout-toolbar-copy {
        gap: 1px;
    }

    body[data-zxp-app-surface="workspace"] .record-layout-toolbar-summary {
        font-size: 0.75rem;
        line-height: 1.25;
    }

    body[data-zxp-app-surface="workspace"] .record-layout-toolbar-actions {
        display: flex;
        flex-wrap: nowrap;
        gap: 6px;
        overflow-x: auto;
        padding-bottom: 2px;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }

    body[data-zxp-app-surface="workspace"] .record-layout-toolbar-actions::-webkit-scrollbar {
        display: none;
    }

    body[data-zxp-app-surface="workspace"] .record-layout-toolbar-button,
    body[data-zxp-app-surface="workspace"] .record-view-toggle {
        width: auto !important;
        flex: 0 0 auto;
        min-height: 36px;
        padding: 0.36rem 0.56rem;
        font-size: 0.75rem;
        white-space: nowrap;
    }

    body[data-zxp-app-surface="workspace"] .profile-card.zxp-record-work-card {
        padding: 14px;
    }

    body[data-zxp-app-surface="workspace"] .contact-crm-actions-card.zxp-record-work-card,
    body[data-zxp-app-surface="workspace"] .contact-crm-tasks-card.zxp-record-work-card {
        gap: 0.72rem;
    }

    body[data-zxp-app-surface="workspace"] .contact-crm-action-pills {
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
        gap: 0.4rem;
    }

    body[data-zxp-app-surface="workspace"] .contact-crm-action-pill {
        min-height: 62px;
        padding: 0.54rem 0.58rem;
    }

    body[data-zxp-app-surface="workspace"] .contact-crm-action-pill strong {
        font-size: 0.82rem;
    }

    body[data-zxp-app-surface="workspace"] .contact-crm-action-pill span {
        font-size: 0.7rem;
        line-height: 1.2;
    }

    body[data-zxp-app-surface="workspace"] .contact-crm-action-form {
        gap: 0.72rem;
        padding: 0.78rem;
        border-radius: 16px;
    }

    /* Dashboard: convert three oversized summary cards into a compact mobile metric strip. */
    body[data-zxp-app-surface="workspace"] .zxp-dashboard-workspace {
        gap: 10px;
    }

    body[data-zxp-app-surface="workspace"] .zxp-dashboard-hero {
        padding: 18px;
        border-radius: 20px;
    }

    body[data-zxp-app-surface="workspace"] .zxp-dashboard-stats {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
    }

    body[data-zxp-app-surface="workspace"] .zxp-dashboard-stats .zxp-dashboard-stat {
        display: flex;
        min-height: 86px;
        justify-content: center;
        flex-direction: column;
        padding: 9px;
        border-radius: 15px;
    }

    body[data-zxp-app-surface="workspace"] .zxp-dashboard-stats .zxp-dashboard-stat h3 {
        margin: 0 0 5px;
        font-size: 0.63rem;
        line-height: 1.18;
        letter-spacing: 0.04em;
    }

    body[data-zxp-app-surface="workspace"] .zxp-dashboard-stats .zxp-dashboard-stat strong,
    body[data-zxp-app-surface="workspace"] .zxp-dashboard-stats .zxp-dashboard-stat p {
        margin: 0;
        font-size: 1.2rem;
        line-height: 1.05;
    }

    body[data-zxp-app-surface="workspace"] .zxp-setup-summary-card.zxp-dashboard-card {
        padding: 14px;
    }

    body[data-zxp-app-surface="workspace"] .zxp-setup-summary-header,
    body[data-zxp-app-surface="workspace"] .zxp-setup-summary-actions {
        gap: 8px;
    }

    body[data-zxp-app-surface="workspace"] .zxp-setup-next-action {
        gap: 8px;
        padding: 10px;
        border-radius: 14px;
    }

    body[data-zxp-app-surface="workspace"] .zxp-setup-readiness-grid {
        gap: 8px;
    }
}

@media (max-width: 420px) {
    /* Preserve useful side-by-side facts on common iPhone widths. */
    .contact-mobile-card-contact-grid,
    .contact-mobile-card-selected-details {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    .contact-mobile-card-actions {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    body[data-zxp-app-surface="workspace"] .zxp-dashboard-stats .zxp-dashboard-stat {
        min-height: 80px;
        padding: 8px 6px;
    }

    body[data-zxp-app-surface="workspace"] .zxp-dashboard-stats .zxp-dashboard-stat strong,
    body[data-zxp-app-surface="workspace"] .zxp-dashboard-stats .zxp-dashboard-stat p {
        font-size: 1.08rem;
    }
}

@media (max-width: 340px) {
    .contact-mobile-card-contact-grid,
    .contact-mobile-card-selected-details {
        grid-template-columns: 1fr !important;
    }

    body[data-zxp-app-surface="workspace"] .contact-crm-action-pills {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}

/* Stage 10 Pass 4 — iOS viewport reflow and zero-horizontal-overflow hotfix. */
:root {
    --zxp-mobile-viewport-reflow-layer: stage10-pass4;
}

@media (max-width: 760px) {
    /*
     * Keep the document and authoritative shell pinned to the layout viewport.
     * Safari may move/scale the visual viewport while a form control is focused;
     * no ordinary workspace descendant should be allowed to widen the document.
     */
    html[data-zxp-viewport-size="mobile"],
    body.zxp-mobile-browser,
    body.login-page {
        inline-size: 100%;
        max-inline-size: 100%;
        min-inline-size: 0;
        overflow-x: hidden !important;
        overscroll-behavior-x: none;
    }

    body.zxp-mobile-browser :where(
        .app-shell,
        .zxp-app-shell,
        .main-shell,
        .content-wrap,
        .zxp-page-shell,
        .zxp-page-stack,
        .zxp-workspace-page,
        .zxp-dashboard-workspace,
        .zxp-dashboard-card,
        .zxp-setup-summary-card,
        .zxp-setup-summary-header,
        .zxp-setup-next-action,
        .zxp-setup-readiness-grid,
        .readiness-item
    ) {
        min-inline-size: 0 !important;
        max-inline-size: 100% !important;
    }

    body.zxp-mobile-browser .content-wrap {
        inline-size: 100% !important;
        overflow-x: hidden !important;
    }

    /* Setup/readiness copy from the screenshots must wrap rather than establish page width. */
    body.zxp-mobile-browser .zxp-setup-readiness-grid {
        grid-template-columns: minmax(0, 1fr) !important;
        inline-size: 100%;
    }

    body.zxp-mobile-browser .zxp-setup-readiness-grid .readiness-item,
    body.zxp-mobile-browser .zxp-setup-readiness-grid .readiness-item > :where(strong, span),
    body.zxp-mobile-browser .zxp-setup-next-action,
    body.zxp-mobile-browser .zxp-setup-next-action > *,
    body.zxp-mobile-browser .zxp-setup-next-action :where(strong, p) {
        min-inline-size: 0;
        max-inline-size: 100%;
        white-space: normal;
        overflow-wrap: anywhere;
        word-break: normal;
    }

    /* Fixed navigation follows the currently visible Safari viewport when it is offset. */
    body[data-zxp-app-surface="workspace"][data-zxp-mobile-bottom-nav="enabled"] .zxp-mobile-bottom-nav {
        right: auto !important;
        left: var(--zxp-mobile-viewport-offset-left, 0px) !important;
        inline-size: var(--zxp-mobile-viewport-width, 100%) !important;
        max-inline-size: var(--zxp-mobile-viewport-width, 100%) !important;
        min-inline-size: 0;
    }

    /* Every softphone layer must shrink within its fixed viewport box. */
    body[data-zxp-app-surface="workspace"] [data-softphone-root],
    body[data-zxp-app-surface="workspace"] [data-softphone-root] :where(
        .softphone-header,
        .softphone-body,
        .softphone-card,
        .softphone-custom-call-form,
        .softphone-custom-call-row,
        .softphone-active-call,
        .softphone-notifications
    ) {
        min-inline-size: 0;
        max-inline-size: 100%;
        box-sizing: border-box;
    }

    body[data-zxp-app-surface="workspace"] [data-softphone-root]:not(.softphone-collapsed) {
        overflow-x: hidden !important;
    }

    /*
     * Use a comfortably-above-threshold input size on iOS. This prevents Safari's
     * focus auto-zoom without disabling user pinch zoom or changing viewport policy.
     */
    body.login-page .zxp-auth-form :where(input, select, textarea),
    body[data-zxp-app-surface="workspace"] [data-softphone-root] :where(input, select, textarea) {
        font-size: 18px !important;
        line-height: 1.35;
        touch-action: manipulation;
    }

    body.login-page .content-wrap,
    body.login-page .login-shell,
    body.login-page .login-panel,
    body.login-page .login-card,
    body.login-page .zxp-auth-form,
    body.login-page .zxp-auth-form > *,
    body.login-page .zxp-auth-form :where(input, select, textarea, button, .button) {
        min-inline-size: 0 !important;
        max-inline-size: 100% !important;
        box-sizing: border-box;
    }

    body.login-page .content-wrap {
        inline-size: 100% !important;
        overflow-x: hidden !important;
    }

    body.login-page .login-card :where(h1, h2, p, label, a) {
        max-inline-size: 100%;
        overflow-wrap: anywhere;
    }
}

/* Stage 10 Pass 5 — Contacts mobile containment hotfix. */
:root {
    --zxp-mobile-contacts-containment-layer: stage10-pass5;
}

@media (max-width: 760px) {
    /*
     * Keep the Contacts workspace itself inside the phone viewport. Older list-layout
     * flex bases and intrinsic grid sizes must not be allowed to widen this card.
     */
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts {
        inline-size: 100% !important;
        max-inline-size: 100% !important;
        min-inline-size: 0 !important;
        box-sizing: border-box;
    }

    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts > *,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-list-header,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-list-heading-copy,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-list-filter-panel,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-list-filter-grid,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-table-meta-row,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .contacts-toolbar,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .contact-mobile-sort-form,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .contact-mobile-card-list,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .contact-mobile-card {
        inline-size: 100% !important;
        max-inline-size: 100% !important;
        min-inline-size: 0 !important;
        box-sizing: border-box;
    }

    /* Reset desktop flex-basis values after the list header becomes a mobile column. */
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-list-heading-copy,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-list-actions {
        flex: 0 0 auto !important;
    }

    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-list-heading-copy p {
        min-inline-size: 0;
        max-inline-size: 100%;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    /*
     * The action row is the only Contacts region intentionally allowed to overflow
     * horizontally. It scrolls independently while the document remains width-locked.
     */
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-list-actions {
        display: flex !important;
        flex-wrap: nowrap !important;
        inline-size: 100% !important;
        max-inline-size: 100% !important;
        min-inline-size: 0 !important;
        overflow-x: auto !important;
        overflow-y: hidden;
        overscroll-behavior-x: contain;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-x;
        scrollbar-width: none;
    }

    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-list-actions .button,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-list-actions button {
        flex: 0 0 auto !important;
        inline-size: auto !important;
        width: auto !important;
        max-inline-size: none !important;
        min-inline-size: 0;
        white-space: nowrap;
    }

    /* Search/filter controls must shrink with the card instead of defining its width. */
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-list-filter-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-list-primary-filter {
        grid-column: 1 / -1 !important;
    }

    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-list-filter-grid > *,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .crm-filter-field,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-mobile-filter-drawer,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-mobile-filter-trigger,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-mobile-search-submit,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts #contact-search,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts input,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts select {
        min-inline-size: 0 !important;
        max-inline-size: 100% !important;
        box-sizing: border-box;
    }

    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts #contact-search,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-mobile-search-submit,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-mobile-filter-drawer,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-mobile-filter-trigger {
        inline-size: 100% !important;
        width: 100% !important;
    }

    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .contacts-toolbar,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .contacts-page-size,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .contact-mobile-sort-form,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .contact-mobile-sort-form > * {
        min-inline-size: 0 !important;
        max-inline-size: 100% !important;
    }
}

@media (max-width: 360px) {
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-list-filter-grid {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-mobile-search-submit,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-mobile-filter-drawer {
        grid-column: 1 / -1 !important;
    }
}


/* Stage 10 Pass 6 — mobile app header, navigation, and action hierarchy polish. */
:root {
    --zxp-mobile-app-hierarchy-layer: stage10-pass6;
}

/* Preserve the existing desktop Contacts action presentation. */
@media (min-width: 761px) {
    .zxp-contact-mobile-actions-menu,
    .zxp-contact-mobile-actions-menu__panel {
        display: contents;
    }

    .zxp-contact-mobile-actions-menu__summary {
        display: none;
    }

    .zxp-contact-mobile-actions-menu:not([open]) > .zxp-contact-mobile-actions-menu__panel,
    .zxp-contact-mobile-actions-menu[open] > .zxp-contact-mobile-actions-menu__panel {
        display: contents;
    }
}

@media (max-width: 760px) {
    /* Keep one compact app context row; lower-frequency utilities now live in More. */
    body[data-zxp-app-surface="workspace"] .zxp-topbar {
        min-height: 48px;
        align-items: center;
        padding: 8px max(14px, var(--zxp-mobile-safe-right, 0px)) 8px max(14px, var(--zxp-mobile-safe-left, 0px));
    }

    body[data-zxp-app-surface="workspace"] .zxp-topbar .topbar-eyebrow,
    body[data-zxp-app-surface="workspace"] .zxp-topbar .zxp-global-search,
    body[data-zxp-app-surface="workspace"] .zxp-topbar .zxp-topbar-actions {
        display: none !important;
    }

    body[data-zxp-app-surface="workspace"] .zxp-topbar .topbar-context {
        inline-size: 100%;
        min-inline-size: 0;
        margin: 0;
    }

    body[data-zxp-app-surface="workspace"] .zxp-topbar .topbar-page-context {
        margin: 0;
        color: #0f172a;
        font-size: 1rem;
        font-weight: 850;
        line-height: 1.2;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* More now owns mobile search, communication utilities, account context, and logout. */
    .zxp-mobile-more-sheet__section-label {
        grid-column: 1 / -1;
        margin: 4px 2px -2px;
        color: #64748b;
        font-size: 0.66rem;
        font-weight: 900;
        letter-spacing: 0.08em;
        text-transform: uppercase;
    }

    .zxp-mobile-more-account {
        display: grid;
        gap: 10px;
        margin-top: 12px;
        padding: 13px;
        border: 1px solid #dbe5ef;
        border-radius: 16px;
        background: #f8fbff;
    }

    .zxp-mobile-more-account__identity {
        display: grid;
        gap: 2px;
        min-inline-size: 0;
    }

    .zxp-mobile-more-account__identity > span {
        color: #64748b;
        font-size: 0.66rem;
        font-weight: 900;
        letter-spacing: 0.08em;
        text-transform: uppercase;
    }

    .zxp-mobile-more-account__identity strong,
    .zxp-mobile-more-account__identity small {
        min-inline-size: 0;
        overflow-wrap: anywhere;
    }

    .zxp-mobile-more-account__identity strong {
        color: #0f172a;
        font-size: 0.92rem;
    }

    .zxp-mobile-more-account__identity small {
        color: #64748b;
        font-size: 0.72rem;
        line-height: 1.3;
    }

    .zxp-mobile-more-account__switcher {
        display: grid;
        gap: 5px;
        min-inline-size: 0;
        margin: 0;
    }

    .zxp-mobile-more-account__switcher label {
        color: #475569;
        font-size: 0.7rem;
        font-weight: 800;
    }

    .zxp-mobile-more-account__switcher select,
    .zxp-mobile-more-account__logout {
        inline-size: 100%;
        min-inline-size: 0;
        min-height: 44px;
        margin: 0;
    }

    .zxp-mobile-more-account__logout {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Route state, not the prior tap/focus state, is the only blue navigation state. */
    .zxp-mobile-bottom-nav__item:not(.is-active):not(.is-disabled),
    .zxp-mobile-bottom-nav__more:not(.is-active)[aria-expanded="false"] {
        background: transparent;
        color: #52647a;
        box-shadow: none;
        transform: none;
    }

    .zxp-mobile-bottom-nav__item:not(.is-active):not(.is-disabled):focus:not(:focus-visible) {
        outline: none;
        background: transparent;
        box-shadow: none;
    }

    .zxp-mobile-bottom-nav__badge--more {
        left: calc(50% + 7px);
    }

    /* Contacts keeps one obvious primary action; secondary administration lives in More Actions. */
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-list-actions {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) auto !important;
        gap: 8px !important;
        overflow: visible !important;
        touch-action: manipulation;
    }

    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-contact-primary-action {
        inline-size: 100% !important;
        width: 100% !important;
        min-inline-size: 0;
        justify-content: center;
        white-space: nowrap;
    }

    .zxp-contact-mobile-actions-menu {
        position: relative;
        display: block;
        min-inline-size: 0;
        margin: 0;
    }

    .zxp-contact-mobile-actions-menu__summary {
        display: inline-flex;
        min-height: 44px;
        align-items: center;
        justify-content: center;
        margin: 0;
        list-style: none;
        white-space: nowrap;
        cursor: pointer;
        touch-action: manipulation;
    }

    .zxp-contact-mobile-actions-menu__summary::-webkit-details-marker {
        display: none;
    }

    .zxp-contact-mobile-actions-menu__summary::after {
        margin-left: 6px;
        content: "⋯";
        font-size: 1rem;
        line-height: 1;
    }

    .zxp-contact-mobile-actions-menu:not([open]) > .zxp-contact-mobile-actions-menu__panel {
        display: none;
    }

    .zxp-contact-mobile-actions-menu[open] {
        grid-column: 1 / -1;
    }

    .zxp-contact-mobile-actions-menu[open] > .zxp-contact-mobile-actions-menu__summary {
        inline-size: 100% !important;
        width: 100% !important;
        background: #eef6ff;
        color: #0b4f93;
    }

    .zxp-contact-mobile-actions-menu__panel {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: 7px;
        inline-size: 100%;
        min-inline-size: 0;
        margin-top: 8px;
        padding: 9px;
        border: 1px solid #dbe5ef;
        border-radius: 14px;
        background: #f8fbff;
    }

    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-contact-mobile-actions-menu__panel .button,
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-contact-mobile-actions-menu__panel button {
        inline-size: 100% !important;
        width: 100% !important;
        max-inline-size: 100% !important;
        min-inline-size: 0;
        justify-content: center;
        white-space: normal;
    }

    /* Give the expanded phone a clearer foreground treatment without changing call behavior. */
    body[data-zxp-app-surface="workspace"] [data-softphone-root][data-softphone-mobile-expanded="true"] {
        border-color: rgba(79, 126, 184, 0.38);
        box-shadow: 0 30px 80px rgba(15, 23, 42, 0.28);
    }
}

@media (max-width: 390px) {
    body[data-zxp-app-surface="workspace"] .zxp-list-workspace--contacts .zxp-list-actions {
        grid-template-columns: minmax(0, 1fr);
    }

    .zxp-contact-mobile-actions-menu__summary {
        inline-size: 100% !important;
        width: 100% !important;
    }
}
