/* =========================================================================
   Appointment modals wear their booking status.

   The four booking modals (employee/modals/appointment_view, _view_ipc,
   appointment_edit, _edit_ipc) pass their status to the record ID bar
   (modals/_modal_idbar.html.twig), which prints a flat badge
   .idbar-status.appt-st-<status> just under the hero. This file keys off
   that badge so the whole modal reads the status at a glance:

     - the modal card is washed in a tint of the status color
       (Confirmed = blue, Completed = green, Cancelled = red…)
     - the badge is a flat, solid fill of the status color — no gloss, and
       on the light body rather than the navy hero, where a blue status
       was blue-on-blue

   Colors come from the global --status-* vars (app.css / sas_base.html.twig),
   the same ones the calendar blocks use, so modal and calendar always agree.
   The tint is mixed toward white, never used raw, so body text keeps its
   contrast whatever the status color is. Must load AFTER frosted-modal.css.
   ========================================================================= */

.modal.bit-modal .modal-content:has(.appt-st-draft)       { --appt-status: var(--status-draft, #bdbdbd); }
.modal.bit-modal .modal-content:has(.appt-st-available)   { --appt-status: var(--status-available, #2f6b55); }
.modal.bit-modal .modal-content:has(.appt-st-partial)     { --appt-status: var(--status-partial, #dcab15); }
.modal.bit-modal .modal-content:has(.appt-st-pending)     { --appt-status: var(--status-pending, #d63384); }
.modal.bit-modal .modal-content:has(.appt-st-confirmed)   { --appt-status: var(--status-confirmed, #28447c); }
.modal.bit-modal .modal-content:has(.appt-st-in-progress) { --appt-status: var(--status-in-progress, #ff8c00); }
.modal.bit-modal .modal-content:has(.appt-st-completed)   { --appt-status: var(--status-completed, #076911); }
.modal.bit-modal .modal-content:has(.appt-st-cancelled)   { --appt-status: var(--status-cancelled, #931c40); }
.modal.bit-modal .modal-content:has(.appt-st-unavailable) { --appt-status: var(--status-unavailable, #6c757d); }

/* The card: frosted-modal.css bakes a blue/violet/mint page gradient in here; a
   status modal swaps it for a wash of its own color — strong enough to be read as
   "this is the Confirmed blue", still light enough for dark body text. */
.modal.bit-modal .modal-content:has(.idbar-status[class*="appt-st-"]) {
    background:
        radial-gradient(900px 520px at 6% -10%, color-mix(in srgb, var(--appt-status) 48%, transparent), transparent 62%),
        radial-gradient(760px 520px at 100% 108%, color-mix(in srgb, var(--appt-status) 38%, transparent), transparent 58%),
        linear-gradient(160deg,
            color-mix(in srgb, var(--appt-status) 38%, #fff) 0%,
            color-mix(in srgb, var(--appt-status) 26%, #fff) 50%,
            color-mix(in srgb, var(--appt-status) 34%, #fff) 100%) !important;
}

/* The badge: flat and solid, in the status color itself. Its text follows one rule,
   worked out from the color so it holds for any status color:
     - a DARK color (navy, green, red, gray…)  -> white text
     - a LIGHT color (light blue, orange…)     -> a dark shade of that SAME color
     - yellow, and near-white/gray             -> black
   Fallback first (fixed lists, for browsers without relative colors), then the
   computed version. */
.modal.bit-modal .modal-idbar .idbar-status {
    display: inline-flex;
    align-items: center;
    padding: 4px 14px;
    border-radius: 999px;
    font-size: .74rem;
    font-weight: 800;
    letter-spacing: .04em;
    text-transform: uppercase;
    white-space: nowrap;
    background: var(--appt-status);
    color: #fff;
}
.modal.bit-modal .modal-idbar .idbar-status:is(.appt-st-draft, .appt-st-partial) { color: #000; }
.modal.bit-modal .modal-idbar .idbar-status.appt-st-in-progress { color: #5c2c00; }

@supports (color: oklch(from red l c h)) {
    .modal.bit-modal .modal-idbar .idbar-status,
    .modal.bit-modal .modal-idbar .idbar-status:is(.appt-st-draft, .appt-st-partial, .appt-st-in-progress) {
        /* 1 when the color is light (too light for white text), else 0 */
        --ink-light: clamp(0, (l - .64) * 1000, 1);
        /* 0 inside the yellow hue band (about 79-115deg) or for a colorless
           white/gray, else 1 — those two take plain black */
        --ink-hued: calc(clamp(0, (max(h - 97, 97 - h) - 18) * 1000, 1) * clamp(0, (c - .03) * 1000, 1));
        color: oklch(from var(--appt-status)
            /* white on dark; a dark shade on light; black on yellow */
            calc(1 - var(--ink-light) * (.66 + (1 - var(--ink-hued)) * .34))
            /* keep the color's own hue strength only for that dark shade */
            calc(min(c, .16) * var(--ink-light) * var(--ink-hued))
            h);
    }
}

/* =========================================================================
   Resend Notifications — the booking modals' hero action
   (employee/modals/_appointment_resend_button.html.twig). Green so it stands
   apart from the navy hero and from the status color; fixed colors, never the
   org theme. Sits at the right of the hero, just left of the close button.
   ========================================================================= */
.modal.bit-modal .modal-header .appt-hero-action {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-left: auto;
    padding: 8px 16px;
    border: 1px solid rgba(255, 255, 255, .55);
    border-radius: 999px;
    background: #17803d;
    color: #fff;
    font-size: .8rem;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color .15s ease, transform .15s ease;
}
.modal.bit-modal .modal-header .appt-hero-action:hover { background: #0f6b31; transform: translateY(-1px); }
.modal.bit-modal .modal-header .appt-hero-action:disabled { background: #4b5b52; cursor: progress; transform: none; }
.modal.bit-modal .modal-header .appt-hero-action .bi { font-size: .95rem; color: #fff; }
/* the button takes the auto margin, so the close button just follows it */
.modal.bit-modal .modal-header .appt-hero-action + .btn-close { margin-left: 12px !important; }
@media (max-width: 575.98px) {
    .modal.bit-modal .modal-header .appt-hero-action { padding: 8px 11px; font-size: 0; gap: 0; }
    .modal.bit-modal .modal-header .appt-hero-action .bi { font-size: 1rem; }
}
