@media (max-width: 760px) {
    html,
    body {
        max-width: 100%;
        overflow-x: hidden;
    }

    .modal-backdrop {
        width: 100vw;
        max-width: 100vw;
        overflow: hidden;
    }

    .modal-backdrop > form.sales-editor-form,
    .modal-backdrop > .quick-customer-form,
    .modal-backdrop > .quick-lead-form {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
    }

    .modal-backdrop .sales-editor-dev,
    .modal-backdrop .quick-customer-editor,
    .modal-backdrop .quick-lead-editor {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box;
    }

    .modal-backdrop .activity-form-body,
    .modal-backdrop .quick-customer-details-body,
    .modal-backdrop .quick-lead-details-body {
        min-width: 0;
        overflow-x: hidden;
    }

    .modal-backdrop .activity-form-section,
    .modal-backdrop .commercial-form-section,
    .modal-backdrop .activity-field-grid,
    .modal-backdrop .commercial-field-grid,
    .modal-backdrop .customer-quick-select,
    .modal-backdrop .service-target-field {
        min-width: 0;
        max-width: 100%;
    }

    .modal-backdrop .service-target-field {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
    }

    .modal-backdrop .service-new-lead {
        justify-self: start;
    }
}

/* On desktop, the agenda follows the calendar's measured height. The list,
   rather than the whole page, scrolls when a selected day has many items. */
@media (min-width: 951px) {
    .schedule-workspace.schedule-height-bound {
        align-items: start;
    }

    .schedule-workspace.schedule-height-bound .schedule-calendar {
        align-self: start;
    }

    .schedule-workspace.schedule-height-bound .schedule-agenda {
        display: flex;
        flex-direction: column;
        height: var(--schedule-calendar-height);
        min-height: 0;
        max-height: var(--schedule-calendar-height);
    }

    .schedule-workspace.schedule-height-bound .schedule-agenda > header,
    .schedule-workspace.schedule-height-bound .schedule-agenda > .form-error {
        flex: 0 0 auto;
    }

    .schedule-workspace.schedule-height-bound .schedule-list {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
        scrollbar-color: #b9c8c1 transparent;
        scrollbar-width: thin;
    }

    .schedule-workspace.schedule-height-bound .schedule-empty {
        flex: 1 1 auto;
        min-height: 0;
    }
}

/* Activity forms should favor one clean control per row on every phone and
   narrow tablet. This avoids a device-specific minimum width in the overview
   and schedule grids. */
@media (max-width: 960px) {
    .modal-backdrop .activity-field-grid,
    .modal-backdrop .activity-overview-fields,
    .modal-backdrop .activity-schedule-fields,
    .modal-backdrop .service-schedule-fields {
        grid-template-columns: minmax(0, 1fr) !important;
        grid-template-areas: none !important;
    }

    .modal-backdrop .activity-field-grid > *,
    .modal-backdrop .activity-overview-fields > *,
    .modal-backdrop .activity-schedule-fields > *,
    .modal-backdrop .service-schedule-fields > * {
        grid-area: auto !important;
        grid-column: 1 / -1 !important;
        min-width: 0 !important;
    }

    .modal-backdrop .customer-quick-select,
    .modal-backdrop .service-target-field {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: 10px;
    }

    .modal-backdrop .customer-quick-select > button,
    .modal-backdrop .service-new-lead {
        width: 100%;
        justify-self: stretch;
    }
}

/* Tablet layout: give the service customer lookup a complete row while
   retaining a comfortably sized New action beside the search control. */
@media (min-width: 761px) and (max-width: 960px) {
    .modal-backdrop .activity-field-grid > .service-target-field {
        display: grid !important;
        grid-column: 1 / -1 !important;
        grid-template-columns: minmax(0, 1fr) 116px !important;
        align-items: end;
        width: 100% !important;
        min-width: 0 !important;
        gap: 10px;
    }

    .modal-backdrop .service-target-field > .smart-lookup-field,
    .modal-backdrop .service-target-field .smart-lookup-input,
    .modal-backdrop .service-target-field .smart-lookup-input > input {
        width: 100% !important;
        min-width: 0 !important;
    }

    .modal-backdrop .service-target-field .smart-lookup-label {
        display: flex;
        align-items: baseline;
        gap: 7px;
        white-space: nowrap;
    }

    .modal-backdrop .service-target-field .smart-lookup-label em {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    .modal-backdrop .service-target-field .service-new-lead {
        width: 116px !important;
        min-width: 116px;
        min-height: 46px;
        justify-self: stretch;
        font-size: 14px;
    }
}

/* One shared action-button geometry keeps Cancel and Save visually balanced. */
.modal-backdrop .sales-editor-dev > footer .activity-editor-cancel,
.modal-backdrop .sales-editor-dev > footer .activity-editor-save {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    column-gap: 7px !important;
    width: 108px;
    min-width: 108px;
    height: 42px;
    min-height: 42px;
    padding: 0 14px !important;
    line-height: 1;
}

.activity-editor-action-icon {
    display: block;
    flex: 0 0 18px;
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.modal-backdrop .sales-editor-dev > footer .activity-editor-save.saving {
    cursor: wait;
    opacity: 1;
}

.modal-backdrop .sales-editor-dev > footer .activity-editor-save.saving .activity-editor-action-icon {
    display: none;
}

.modal-backdrop .sales-editor-dev > footer .activity-editor-save.saving::before {
    content: "";
    box-sizing: border-box;
    flex: 0 0 18px;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, .45);
    border-top-color: #fff;
    border-radius: 50%;
    animation: activity-save-spin .7s linear infinite;
}

@keyframes activity-save-spin {
    to { transform: rotate(360deg); }
}

.modal-backdrop .sales-editor-dev > footer .activity-editor-cancel .activity-editor-action-icon {
    display: none;
}

.modal-backdrop .sales-editor-dev > footer .activity-editor-cancel::before {
    content: "↶";
    font-size: 24px;
    font-weight: 400;
    line-height: 1;
}

/* Shared footer actions: concise labels on desktop, recognizable icons on phones. */
.editor-action-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-width: 96px;
}

.editor-action-button svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

@media (max-width: 760px) {
    .modal-backdrop .sales-editor-dev > footer .activity-editor-cancel,
    .modal-backdrop .sales-editor-dev > footer .activity-editor-save {
        display: inline-flex !important;
        flex: 0 0 46px !important;
        width: 46px !important;
        min-width: 46px !important;
        height: 44px;
        min-height: 44px;
        padding: 0 !important;
        column-gap: 0 !important;
    }

    .modal-backdrop .sales-editor-dev > footer .activity-editor-action-label {
        display: none;
    }

    .modal-backdrop .sales-editor-dev > footer .activity-editor-action-icon {
        flex-basis: 20px;
        width: 20px;
        height: 20px;
    }

    .modal-backdrop .sales-editor-dev > footer .activity-editor-delete {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        flex: 0 0 46px !important;
        width: 46px !important;
        min-width: 46px !important;
        height: 44px;
        min-height: 44px;
        margin-right: 0 !important;
        padding: 0 !important;
        font-size: 0;
    }

    .modal-backdrop .sales-editor-dev > footer .activity-editor-delete::before {
        content: "🗑";
        font-size: 18px;
        line-height: 1;
    }

    .modal-backdrop .editor-action-button {
        flex: 0 0 46px !important;
        width: 46px !important;
        min-width: 46px !important;
        height: 44px !important;
        min-height: 44px !important;
        padding: 0 !important;
        gap: 0 !important;
    }

    .modal-backdrop .editor-action-button > span {
        display: none;
    }

    .modal-backdrop .editor-action-button svg {
        width: 20px;
        height: 20px;
    }

    /* A service customer lookup is a full-width search control on phones.
       Keeping the lead button below it prevents the input from being reduced
       to a narrow flex column. */
    .modal-backdrop .activity-field-grid > .service-target-field {
        display: block !important;
        grid-column: 1 / -1 !important;
        width: 100% !important;
    }

    .modal-backdrop .service-target-field > .smart-lookup-field,
    .modal-backdrop .service-target-field .smart-lookup-input {
        width: 100% !important;
        min-width: 0 !important;
    }

    .modal-backdrop .service-target-field .smart-lookup-label {
        display: flex;
        align-items: baseline;
        gap: 6px;
        white-space: nowrap;
    }

    .modal-backdrop .service-target-field .smart-lookup-label em {
        flex: 0 1 auto;
        font-size: 11px;
        white-space: nowrap;
    }

    .modal-backdrop .service-target-field .service-new-lead {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 100% !important;
        min-height: 46px;
        margin-top: 10px;
        padding-right: 15px;
        padding-left: 15px;
        font-size: 14px;
    }
}
