/* Moving several visits at once (#1214): the "Move several visits" entry in Calendar settings, the selection
   bar ("All" + one chip per visit on screen, in the visit's own calendar colours), the mark on picked visits,
   the "Move to another day" dialog and the "Inform the customers?" popup after a move. Black-and-white like
   the rest of the calendar; every rule is scoped under .cp-move-* / .cp-mn-* or [data-cp-move-selected].
   Works from 360px wide (the dialogs are bottom sheets on phones). */

/* ---- entry in Calendar settings (reuses the icon-key card .cp-cal-legend) ---- */
.cp-move-settings-entry .cp-cal-legend-toggle {
    background: #fff;
}

.cp-move-settings-entry .cp-cal-legend-toggle:hover {
    background: #F9FAFB;
}

.cp-move-settings-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: #222222;
    color: #fff;
}

.cp-move-settings-icon svg {
    width: 20px;
    height: 20px;
}

/* The long-press tip is for phones; desktop has the header button instead. */
.cp-move-settings-tip {
    display: none;
    margin-top: 3px;
    font-size: 12px;
    font-weight: 600;
    color: #111827;
}

@media (max-width: 639px) {
    .cp-move-settings-tip {
        display: block;
    }
}

/* ---- header button (desktop only: phones use Calendar settings and the long press) ---- */
.cp-move-header-btn {
    color: #374151;
}

.cp-move-header-btn.is-active {
    background: #222222;
    color: #fff;
}

.cp-move-header-btn.is-active:hover {
    background: #000;
}

@media (max-width: 639px) {
    .cp-move-header-btn {
        display: none !important;
    }
}

/* ---- picked visits on the calendar: a dark ring and a small black tick ---- */
[data-cp-move-selected="true"] {
    outline: 2px solid #111 !important;
    outline-offset: -2px;
    box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.85) !important;
}

/* Calendar tiles are absolutely positioned already; the tray and "+n more" rows need a box for the tick. */
.cp-unplanned-tray-item[data-cp-move-selected="true"],
.cp-slotmodal-item[data-cp-move-selected="true"] {
    position: relative;
}

[data-cp-move-selected="true"]::after {
    content: "";
    position: absolute;
    inset: 3px 3px auto auto;
    width: 16px;
    height: 16px;
    border-radius: 999px;
    background: #111 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4.5 8.2l2.2 2.2 4.8-4.8' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 14px no-repeat;
    box-shadow: 0 0 0 1.5px #fff;
    pointer-events: none;
    animation: none;
    z-index: 2;
}

/* A long press must not select text or open the phone's callout menu. */
[data-cp-order-id],
[data-cp-move-start] {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* In selection mode every visit that can be picked shows an empty circle where the tick goes. */
.cp-move-selecting [data-cp-order-id]:not([data-cp-move-selected="true"]) {
    cursor: pointer;
}

.cp-move-selecting .cp-unplanned-tray-item[data-cp-order-id]:not([data-cp-move-selected="true"]) {
    position: relative;
}

.cp-move-selecting [data-cp-order-id]:not([data-cp-move-selected="true"])::after {
    content: "";
    position: absolute;
    inset: 3px 3px auto auto;
    width: 16px;
    height: 16px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: inset 0 0 0 1.5px #6B7280;
    pointer-events: none;
    animation: none;
    z-index: 2;
}

/* ---- selection bar ---- */
.cp-move-select-bar {
    margin: 6px 0 4px;
    padding: 6px 8px 8px;
    border: 1px solid #E5E7EB;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.cp-move-select-bar.is-collapsed {
    padding-bottom: 6px;
}

.cp-move-select-head {
    display: flex;
    align-items: center;
    gap: 6px;
}

.cp-move-select-fold {
    appearance: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 36px;
    padding: 0 8px;
    margin-right: auto;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: #111827;
}

.cp-move-select-fold:hover {
    background: #F3F4F6;
}

.cp-move-select-count {
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
}

.cp-move-select-fold-chevron {
    width: 12px;
    height: 12px;
    color: #6B7280;
    transition: transform 0.2s ease;
}

.cp-move-select-bar.is-collapsed .cp-move-select-fold-chevron {
    transform: rotate(-90deg);
}

/* Folded (the default): "N selected ▾" is a grey pill whose chevron nudges down a few times, so it reads
   as something that unfolds. Replayed whenever the bar folds again (the element is re-created). */
.cp-move-select-bar.is-collapsed .cp-move-select-fold {
    background: #F3F4F6;
    border-radius: 9999px;
    padding: 0 12px;
    animation: cp-move-fold-pulse 1.6s ease-out 0.2s 2;
}

.cp-move-select-bar.is-collapsed .cp-move-select-fold-chevron {
    transform: none;
    color: #111827;
    animation: cp-move-fold-nudge 0.8s ease-in-out 0.2s 4;
}

@keyframes cp-move-fold-nudge {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(3px); }
}

@keyframes cp-move-fold-pulse {
    0% { box-shadow: 0 0 0 0 rgba(17, 17, 17, 0.25); }
    70% { box-shadow: 0 0 0 7px rgba(17, 17, 17, 0); }
    100% { box-shadow: 0 0 0 0 rgba(17, 17, 17, 0); }
}

.cp-move-select-bar:not(.is-collapsed) .cp-move-select-fold-chevron {
    transform: rotate(180deg);
}

@media (prefers-reduced-motion: reduce) {
    .cp-move-select-bar.is-collapsed .cp-move-select-fold,
    .cp-move-select-bar.is-collapsed .cp-move-select-fold-chevron {
        animation: none;
    }
}

.cp-move-select-cancel {
    appearance: none;
    border: 0;
    background: transparent;
    color: #4B5563;
    font-size: 14px;
    min-height: 36px;
    padding: 0 8px;
    border-radius: 9999px;
    white-space: nowrap;
}

.cp-move-select-cancel:hover {
    background: #F3F4F6;
}

.cp-move-select-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-height: min(40vh, 240px);
    overflow-y: auto;
    padding: 2px;
}

/* A chip looks like the visit's tile: its inline style carries the tile's background, text colour and border. */
.cp-move-select-chip {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 30px;
    max-width: 100%;
    padding: 0 10px 0 6px;
    border: 1px solid #E5E7EB;
    border-radius: 9px;
    background: #fff;
    color: #111827;
    font-size: 12.5px;
    line-height: 1.2;
    cursor: pointer;
    margin: 0;
}

.cp-move-select-chip-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* The real checkbox stays for keyboards and screen readers; the round tick is what is seen. */
.cp-move-select-chip input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    margin: 0;
    pointer-events: none;
}

.cp-move-select-tick {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: inset 0 0 0 1.5px #6B7280;
}

.cp-move-select-chip.is-selected {
    box-shadow: 0 0 0 2px #fff, 0 0 0 3.5px #111;
}

.cp-move-select-chip.is-selected .cp-move-select-tick,
.cp-mn-check input:checked + .cp-move-select-tick {
    background: #111 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4.5 8.2l2.2 2.2 4.8-4.8' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 14px no-repeat;
    box-shadow: 0 0 0 1.5px #fff;
}

.cp-move-select-chip input:focus-visible + .cp-move-select-tick,
.cp-mn-check input:focus-visible + .cp-move-select-tick {
    outline: 2px solid #111;
    outline-offset: 2px;
}

.cp-move-select-chip--all {
    font-weight: 600;
}

.cp-move-select-hint {
    margin: 0 4px;
    font-size: 12px;
    color: #6B7280;
}

.cp-move-select-go,
.cp-move-btn {
    appearance: none;
    min-height: 44px;
    padding: 0 18px;
    border-radius: 9999px;
    font-size: 14px;
    font-weight: 600;
    border: 1px solid #D1D5DB;
    background: #fff;
    color: #111;
    white-space: nowrap;
}

.cp-move-select-go {
    min-height: 36px;
    padding: 0 14px;
    background: #222222;
    border-color: #222222;
    color: #fff;
}

.cp-move-select-go:hover:not(:disabled),
.cp-move-btn--primary:hover:not(:disabled) {
    background: #000;
}

.cp-move-select-go:disabled,
.cp-move-btn:disabled {
    opacity: 0.5;
}

/* ---- dialogs: "Move to another day" and "Inform the customers?" ---- */
.cp-move-dialog-backdrop {
    position: fixed;
    inset: 0;
    z-index: 4500;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.cp-move-dialog {
    width: 100%;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.18);
}

@media (min-width: 640px) {
    .cp-move-dialog-backdrop {
        align-items: center;
        padding: 16px;
    }

    .cp-move-dialog {
        max-width: 520px;
        max-height: 90vh;
        border-radius: 16px;
    }
}

.cp-move-dialog-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 16px 8px;
}

.cp-move-dialog-head h3 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    color: #111827;
    line-height: 1.3;
}

.cp-move-dialog-close {
    appearance: none;
    border: 0;
    background: transparent;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.cp-move-dialog-close:hover {
    background: #F3F4F6;
}

.cp-move-dialog-close svg {
    width: 16px;
    height: 16px;
    stroke: #111;
    stroke-width: 1.8;
    stroke-linecap: round;
}

.cp-move-dialog-body {
    padding: 4px 16px 12px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cp-move-mode {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    padding: 4px;
    background: #F3F4F6;
    border-radius: 999px;
}

.cp-move-mode button {
    appearance: none;
    border: 0;
    min-height: 38px;
    border-radius: 999px;
    background: transparent;
    font-size: 14px;
    font-weight: 500;
    color: #374151;
}

.cp-move-mode button.active {
    background: #222222;
    color: #fff;
}

.cp-move-label {
    font-size: 13px;
    font-weight: 600;
    color: #374151;
}

.cp-move-input {
    width: 100%;
    min-height: 44px;
    padding: 0 12px;
    border: 1px solid #D1D5DB;
    border-radius: 10px;
    background: #fff;
    font-size: 16px;
}

.cp-move-week {
    display: flex;
    align-items: center;
    gap: 8px;
}

.cp-move-week-step {
    appearance: none;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border: 1px solid #D1D5DB;
    border-radius: 999px;
    background: #fff;
    font-size: 22px;
    line-height: 1;
}

.cp-move-week-step:disabled {
    opacity: 0.4;
}

.cp-move-week-label {
    flex: 1;
    text-align: center;
    font-weight: 600;
    font-size: 16px;
    display: flex;
    flex-direction: column;
}

.cp-move-week-label small {
    font-weight: 400;
    font-size: 12px;
    color: #6B7280;
}

.cp-move-note {
    margin: 0;
    font-size: 12px;
    color: #6B7280;
}

/* One line per visit, so 20 fit on screen; the dialog body scrolls when there are more. */
.cp-move-preview {
    list-style: none;
    margin: 0;
    padding: 0;
    border: 1px solid #F0F0F0;
    border-radius: 12px;
}

.cp-move-preview li {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 30px;
    padding: 4px 10px;
    font-size: 12.5px;
    line-height: 1.25;
    border-bottom: 1px solid #F5F5F5;
}

.cp-move-preview li:last-child {
    border-bottom: 0;
}

.cp-move-preview li.is-skipped {
    color: #9CA3AF;
    flex-wrap: wrap;
}

.cp-move-preview-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cp-move-preview-dates {
    flex-shrink: 0;
    white-space: nowrap;
}

.cp-move-preview-dates em {
    margin-left: 6px;
    font-style: normal;
    color: #B45309;
}

.cp-move-dialog-foot {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    border-top: 1px solid #F0F0F0;
}

.cp-move-dialog-foot .cp-move-btn {
    flex: 1;
}

@media (min-width: 640px) {
    .cp-move-dialog-foot .cp-move-btn {
        flex: 0 0 auto;
    }
}

.cp-move-btn--primary {
    background: #222222;
    border-color: #222222;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

/* ---- "Inform the customers about the move?" (VisitUpdateNotificationModal in move mode) ---- */
.cp-mn-backdrop {
    z-index: 5000;
}

@media (min-width: 640px) {
    .cp-mn {
        max-width: 640px;
    }
}

/* Reason and channels: two short rows. */
.cp-mn-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 0 16px 10px;
    border-bottom: 1px solid #F0F0F0;
}

.cp-mn-reason {
    display: flex;
    gap: 6px;
    align-items: center;
}

.cp-mn-reason select {
    flex: 1;
    min-width: 0;
    min-height: 40px;
    font-size: 14px;
}

.cp-mn-link {
    appearance: none;
    border: 0;
    background: transparent;
    color: #111827;
    font-size: 13px;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
    padding: 0 4px;
    min-height: 40px;
    white-space: nowrap;
}

.cp-mn-link:disabled {
    opacity: 0.4;
    text-decoration: none;
}

.cp-mn-channels {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.cp-mn-label {
    font-size: 13px;
    color: #6B7280;
    margin-right: 2px;
}

/* Email / SMS as pills that are black when on. */
.cp-mn-pill {
    position: relative;
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    padding: 0 14px;
    margin: 0;
    border: 1px solid #D1D5DB;
    border-radius: 9999px;
    background: #fff;
    color: #374151;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
}

.cp-mn-pill input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    margin: 0;
    pointer-events: none;
}

.cp-mn-pill.is-on {
    background: #222222;
    border-color: #222222;
    color: #fff;
}

.cp-mn-pill:focus-within {
    outline: 2px solid #111;
    outline-offset: 2px;
}

/* SMS when it cannot be used: greyed, but it can still be picked to see why. */
.cp-mn-pill--unavailable {
    appearance: none;
    border-style: dashed;
    color: #9CA3AF;
    background: #F9FAFB;
}

.cp-mn-sms-note {
    font-size: 12px;
    font-weight: 600;
    color: #92400E;
}

.cp-mn-pill--small {
    min-height: 28px;
    padding: 0 12px;
    font-size: 12px;
}

.cp-mn-hint {
    margin: 0;
    font-size: 12px;
    color: #6B7280;
}

.cp-mn-cost {
    font-size: 12px;
    color: #B45309;
}

.cp-mn-listhead {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 2px 8px;
    padding: 8px 16px 4px;
    font-size: 12.5px;
    color: #374151;
}

.cp-mn-listhead strong {
    color: #111827;
}

.cp-mn-quick {
    display: inline-flex;
    gap: 2px;
}

.cp-mn-quick button {
    appearance: none;
    border: 0;
    background: transparent;
    color: #111827;
    font-size: 12.5px;
    padding: 4px 6px;
    border-radius: 8px;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.cp-mn-quick button:hover {
    background: #F3F4F6;
}

.cp-mn-body {
    overflow-y: auto;
    min-height: 0;
    flex: 1;
    padding: 0 16px 8px;
}

/* One line per customer, so about 20 fit on screen. */
.cp-mn-list {
    list-style: none;
    margin: 0;
    padding: 0;
    border: 1px solid #F0F0F0;
    border-radius: 12px;
}

.cp-mn-row + .cp-mn-row {
    border-top: 1px solid #F3F4F6;
}

.cp-mn-row-main {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 32px;
    padding: 2px 4px 2px 8px;
    font-size: 13px;
}

.cp-mn-row:not(.is-on) .cp-mn-name,
.cp-mn-row:not(.is-on) .cp-mn-dates {
    color: #9CA3AF;
}

.cp-mn-check {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    margin: 0;
    cursor: pointer;
    min-height: 28px;
}

.cp-mn-check input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    margin: 0;
}

/* PR #1239 review: a customer who can get a message has a strong black ring; one who cannot has a faint
   dashed, filled circle, so the two never look alike. */
.cp-mn-row.can-send .cp-mn-check input:not(:checked) + .cp-move-select-tick {
    background: #fff;
    box-shadow: inset 0 0 0 2px #111;
}

.cp-mn-check input:disabled + .cp-move-select-tick {
    background: #F3F4F6;
    box-shadow: none;
    border: 1.5px dashed #D1D5DB;
    box-sizing: border-box;
}

.cp-mn-row.can-send:not(.is-on) .cp-mn-name {
    color: #374151;
}

.cp-mn-row.cannot-send .cp-mn-check {
    cursor: not-allowed;
}

.cp-mn-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #111827;
    font-weight: 500;
}

.cp-mn-dates {
    flex-shrink: 0;
    white-space: nowrap;
    font-size: 12px;
    color: #4B5563;
}

.cp-mn-tag {
    flex-shrink: 0;
    white-space: nowrap;
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    padding: 4px 7px;
    border-radius: 9999px;
    background: #F3F4F6;
    color: #6B7280;
}

.cp-mn-tag--told {
    background: #E8F6EE;
    color: #166534;
}

/* The automatic reminder can no longer go out for the new date: an update is recommended. */
.cp-mn-tag--passed {
    background: #FEF3C7;
    color: #92400E;
}

/* One short line per status in the list, above it. */
.cp-mn-legend {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 8px;
}

.cp-mn-legend:empty {
    display: none;
}

.cp-mn-legend .cp-mn-tag {
    display: inline-block;
    margin-right: 4px;
}

.cp-mn-expand {
    appearance: none;
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: #6B7280;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.cp-mn-expand:hover {
    background: #F3F4F6;
}

.cp-mn-expand svg {
    width: 12px;
    height: 12px;
    transition: transform 0.2s ease;
}

.cp-mn-expand[aria-expanded="true"] svg {
    transform: rotate(180deg);
}

.cp-mn-row-note {
    margin: 0;
    padding: 0 12px 6px 32px;
    font-size: 12px;
    color: #B45309;
}

/* The details of one customer: channels, full-width previews (no inner scrolling) and edit buttons. */
.cp-mn-details {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 6px 12px 12px;
    background: #FAFAFA;
    border-top: 1px solid #F3F4F6;
}

.cp-mn-details-channels {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.cp-mn-details label.cp-mn-preview-label {
    display: block;
    margin: 0 0 2px;
    font-size: 12px;
    font-weight: 600;
    color: #374151;
}

.cp-mn-preview-subject {
    font-size: 12px;
    color: #6B7280;
    margin-bottom: 2px;
}

.cp-mn-details pre {
    margin: 0;
    padding: 8px 10px;
    font: 12.5px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    white-space: pre-wrap;
    word-break: break-word;
    background: #fff;
    border: 1px solid #E5E7EB;
    border-radius: 10px;
    color: #111827;
}

.cp-mn-edited {
    font-size: 11px;
    font-weight: 600;
    color: #166534;
}

.cp-mn-details-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.cp-mn-details-actions button {
    appearance: none;
    min-height: 32px;
    padding: 0 12px;
    border: 1px solid #D1D5DB;
    border-radius: 9999px;
    background: #fff;
    font-size: 12.5px;
    font-weight: 500;
    color: #111827;
}

.cp-mn-details-actions button:disabled {
    opacity: 0.5;
}

/* "Edit template for this" opens above the popup. */
.cp-mn-backdrop--top {
    z-index: 5100;
}

.cp-mn-template-foot .cp-move-btn {
    flex: 1;
    white-space: normal;
    line-height: 1.2;
    padding: 6px 14px;
}

.cp-mn-meta {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* Phones: name on the first line, dates and status under it (rows stay about 38px high). */
@media (max-width: 519px) {
    .cp-mn-row-main {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr) auto;
        grid-template-areas:
            "check name expand"
            "check meta expand";
        column-gap: 8px;
        row-gap: 1px;
        padding-top: 4px;
        padding-bottom: 4px;
    }

    .cp-mn-check { grid-area: check; }
    .cp-mn-name { grid-area: name; }
    .cp-mn-meta { grid-area: meta; justify-content: space-between; min-width: 0; }
    .cp-mn-expand { grid-area: expand; }
}

.cp-mn-check {
    position: relative;
}
