/* #1233: Arrival's finish sheet, the Edit time sheet and the coin burst (js/finishCoins.js).
   The sheet's main invoice button sits exactly where the Stop button was (same place as .arrival-action-bar),
   so finishing is two taps on the same spot. Everything is scoped under .cp-finish-* / .cp-coin*. */

.cp-finish-overlay {
    position: fixed;
    inset: 0;
    z-index: 1050;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    background: rgba(17, 17, 17, 0.45);
    overscroll-behavior: contain;
    animation: cp-finish-fade 0.18s ease-out;
}

@keyframes cp-finish-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* The sheet ends above the primary button bar (5rem button + 6rem menu bar on phones). */
.cp-finish-sheet {
    position: relative;
    width: min(100%, 480px);
    max-height: calc(100dvh - 12rem - env(safe-area-inset-bottom, 0px));
    margin: 0 0.5rem calc(12rem + env(safe-area-inset-bottom, 0px));
    padding: 22px 18px 16px;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-radius: 26px;
    background: #fff;
    color: #111;
    box-shadow: 0 18px 44px rgba(0, 0, 0, 0.22);
    font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    text-align: center;
    animation: cp-finish-up 0.22s ease-out;
}

@keyframes cp-finish-up {
    from { transform: translateY(18px); opacity: 0; }
    to { transform: none; opacity: 1; }
}

.cp-finish-close {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 50%;
    background: #f3f4f6;
    color: #111;
    cursor: pointer;
}

.cp-finish-close svg { width: 18px; height: 18px; }

.cp-finish-title {
    margin: 0 0 2px;
    font-size: clamp(22px, 5vw, 26px);
    font-weight: 800;
    line-height: 1.15;
}

.cp-finish-duration {
    margin-left: 4px;
    color: #22c55e;
}

.cp-finish-duration.is-warning { color: #ef4444; }

.cp-finish-customer {
    margin: 0 0 14px;
    color: #6b7280;
    font-size: 14px;
    font-weight: 600;
}

/* Active hourly revenue on this customer + faster / slower than last time. */
.cp-finish-stats {
    display: grid;
    gap: 8px;
    margin-bottom: 14px;
    padding: 14px 16px;
    border-radius: 18px;
    background: #111;
    color: #fff;
    text-align: left;
}

.cp-finish-stat-label {
    color: rgba(255, 255, 255, 0.6);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.cp-finish-stat-value {
    font-size: clamp(26px, 8vw, 34px);
    font-weight: 800;
    line-height: 1.05;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
}

.cp-finish-stat-value small {
    margin-left: 4px;
    color: rgba(255, 255, 255, 0.65);
    font-size: 15px;
    font-weight: 700;
}

.cp-finish-pace {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 700;
}

.cp-finish-pace-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
}

.cp-finish-pace-chip.is-faster { background: rgba(34, 197, 94, 0.2); color: #86efac; }
.cp-finish-pace-chip.is-slower { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }
.cp-finish-pace-chip.is-record { background: #f5c542; color: #3b2a00; }

.cp-finish-subtitle {
    margin: 4px 0 10px;
    color: #4b5563;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.cp-finish-options {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
}

/* The existing pill styles from Arrival.razor are reused inside the sheet; make them full width. */
.cp-finish-options .finish-modal-pill,
.cp-finish-options .finish-modal-manual {
    width: 100%;
    max-width: none;
}

.cp-finish-options .finish-modal-or { align-self: center; }

.cp-finish-edit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    margin-top: 12px;
    padding: 10px 14px;
    border: 1px solid #e5e7eb;
    border-radius: 999px;
    background: #f9fafb;
    color: #111;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
}

.cp-finish-edit.is-warning { border-color: #fecaca; background: #fef2f2; color: #b91c1c; }
.cp-finish-edit svg { width: 16px; height: 16px; }

/* The main invoice button: the same box as the Stop / pause row of .arrival-action-bar. */
.cp-finish-primary-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(6rem + env(safe-area-inset-bottom, 0px));
    z-index: 1051;
    display: flex;
    justify-content: center;
    padding: 0 1rem;
    pointer-events: none;
}

.cp-finish-primary {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    max-width: 48rem;
    height: 5rem;
    padding: 0 4.5rem;
    border: 0;
    border-radius: 999px;
    background: #000;
    color: #fff;
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: 0.01em;
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.32);
    cursor: pointer;
    pointer-events: auto;
    animation: cp-finish-pop 0.25s ease-out;
}

.cp-finish-primary:active { transform: scale(0.98); }
.cp-finish-primary:disabled { opacity: 0.75; cursor: default; }

@keyframes cp-finish-pop {
    from { transform: scale(0.96); }
    to { transform: none; }
}

.cp-finish-primary-logo {
    position: absolute;
    left: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 3.5rem;
    height: 3.5rem;
    border-radius: 50%;
    background: #fff;
}

.cp-finish-primary-logo img { width: 2.25rem; height: 2.25rem; object-fit: contain; }

@media (min-width: 640px) {
    .cp-finish-overlay { align-items: flex-end; }

    .cp-finish-sheet {
        margin-left: var(--main-margin-left, 0px);
        margin-bottom: 7.5rem;
        max-height: calc(100dvh - 9rem);
    }

    .cp-finish-primary-bar {
        left: var(--main-margin-left, 300px);
        bottom: 1.5rem;
    }
}

/* From 768px the Stop pill is 16rem + the 4rem pause button (and 4rem tall), centred. */
@media (min-width: 768px) {
    .cp-finish-sheet { margin-bottom: 6.5rem; }

    .cp-finish-primary {
        max-width: calc(16rem + 0.5rem + 4rem);
        height: 4rem;
        font-size: 1.1rem;
    }

    .cp-finish-primary-logo { width: 2.75rem; height: 2.75rem; left: 0.6rem; }
    .cp-finish-primary-logo img { width: 1.8rem; height: 1.8rem; }
}

/* ---- Edit time (same look as the finish sheet) ---- */

.cp-edit-time-sheet {
    margin-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    max-height: calc(100dvh - 2rem);
    text-align: left;
}

.cp-edit-time-sheet .cp-finish-title { text-align: center; }

.cp-edit-time-now {
    margin: 4px 0 14px;
    color: #6b7280;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
}

.cp-edit-time-fields {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.cp-edit-time-field {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 6px 8px;
    border-radius: 18px;
    background: #f3f4f6;
}

.cp-edit-time-field input {
    width: 100%;
    border: 0;
    background: transparent;
    color: #111;
    font-size: 30px;
    font-weight: 800;
    text-align: center;
    font-variant-numeric: tabular-nums;
    -moz-appearance: textfield;
}

.cp-edit-time-field input:focus { outline: none; }
.cp-edit-time-field:focus-within { box-shadow: inset 0 0 0 2px #111; }

.cp-edit-time-field span {
    color: #6b7280;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.cp-edit-time-new {
    margin: 12px 0 0;
    padding: 10px 14px;
    border-radius: 14px;
    background: #ecfdf5;
    color: #065f46;
    font-size: 15px;
    font-weight: 700;
    text-align: center;
}

.cp-edit-time-chip {
    display: block;
    margin: 10px auto 0;
    padding: 8px 14px;
    border: 1px dashed #9ca3af;
    border-radius: 999px;
    background: #fff;
    color: #111;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.cp-edit-time-jobs { margin-top: 16px; }

.cp-edit-time-jobs h4 {
    margin: 0 0 6px;
    font-size: 14px;
    font-weight: 700;
}

.cp-edit-time-job {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 0;
    border-top: 1px solid #f3f4f6;
}

.cp-edit-time-job-name { flex: 1 1 140px; min-width: 0; }
.cp-edit-time-job-name b { display: block; overflow: hidden; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.cp-edit-time-job-name small { color: #6b7280; font-size: 12px; }

.cp-edit-time-job label {
    display: flex;
    flex-direction: column;
    color: #6b7280;
    font-size: 11px;
    font-weight: 600;
}

.cp-edit-time-job input {
    width: 4.5rem;
    min-height: 44px;
    padding: 6px 8px;
    border: 1px solid #d1d5db;
    border-radius: 12px;
    font-size: 16px;
}

.cp-edit-time-hint { margin: 6px 0 0; color: #6b7280; font-size: 12px; }

.cp-edit-time-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 18px;
}

.cp-edit-time-actions button {
    min-height: 52px;
    border-radius: 999px;
    font-size: 16px;
    font-weight: 800;
    cursor: pointer;
}

.cp-edit-time-cancel { border: 1px solid #e5e7eb; background: #fff; color: #111; }
.cp-edit-time-save { border: 0; background: #000; color: #fff; }

@media (min-width: 640px) {
    .cp-edit-time-sheet { margin-bottom: 1.5rem; }
}

/* ---- The coin burst ---- */

.cp-coins-layer {
    position: fixed;
    inset: 0;
    z-index: 2000;
    overflow: hidden;
    pointer-events: none;
}

.cp-coin,
.cp-confetti {
    position: absolute;
    animation: cp-coin-fly 1.35s cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
    will-change: transform, opacity;
}

.cp-coin {
    width: 22px;
    height: 22px;
    margin: -11px 0 0 -11px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #fff6c9 0 18%, #f5c542 19% 62%, #c98d12 63% 100%);
    box-shadow: inset 0 0 0 2px #e0a823, 0 2px 4px rgba(0, 0, 0, 0.18);
}

.cp-coin::after {
    content: "";
    position: absolute;
    inset: 6px;
    border-radius: 50%;
    border: 1.5px solid rgba(201, 141, 18, 0.7);
}

.cp-confetti {
    width: 7px;
    height: 11px;
    margin: -5px 0 0 -3px;
    border-radius: 2px;
}

@keyframes cp-coin-fly {
    0% { transform: translate(0, 0) rotate(0) scale(0.6); opacity: 0; }
    12% { opacity: 1; }
    55% { transform: translate(var(--dx), var(--dy)) rotate(calc(var(--spin) * 0.6)) scale(1); opacity: 1; }
    100% { transform: translate(var(--dx), calc(var(--dy) + var(--fall))) rotate(var(--spin)) scale(0.9); opacity: 0; }
}
