/*
 * Only what a Tailwind utility cannot do. Each rule is scoped to
 * `.fi-bottom-sheet`, which the `x-bottom-sheet` directive puts on a modal
 * window only while its window type is the sheet.
 *
 * Filament's modal enter and leave classes scale and fade the window. A sheet
 * does not: the directive moves it up with a spring when it opens, and these
 * rules move it down when Filament closes it (Escape, a backdrop tap, a close
 * from the server).
 */
.fi-modal-window.fi-bottom-sheet:is(
        .fi-transition-enter,
        .fi-transition-enter-start,
        .fi-transition-enter-end,
        .fi-transition-leave,
        .fi-transition-leave-start,
        .fi-transition-leave-end
    ) {
    opacity: 1;
    scale: none;
}

.fi-modal-window.fi-bottom-sheet.fi-transition-enter {
    transition: none !important;
}

.fi-modal-window.fi-bottom-sheet.fi-transition-leave {
    transition: transform 280ms cubic-bezier(0.32, 0.72, 0, 1) !important;
}

.fi-modal-window.fi-bottom-sheet.fi-transition-leave-end {
    transform: translate3d(0, calc(100% + 2rem), 0) !important;
}

@media (prefers-reduced-motion: reduce) {
    .fi-modal-window.fi-bottom-sheet.fi-transition-leave {
        transition: none !important;
    }

    /* The backdrop of a sheet does not fade (`x-transition` of the modal). */
    .fi-modal:has(> .fi-modal-window-ctn > .fi-bottom-sheet)
        > .fi-modal-close-overlay {
        transition: none !important;
    }
}

/*
 * The footer of an action sheet. A Filament modal puts the space above its
 * footer in the body (the `py-6` of `.fi-modal-content`), and the footer has
 * a bottom padding only. In a sheet the body scrolls, so that space scrolls
 * away with the content, and the last field touches the buttons. The sheet
 * moves the space into the footer: the same 1.5rem as a Filament modal.
 */
.fi-modal-window.fi-bottom-sheet:has(> .fi-modal-footer) > .fi-modal-content {
    padding-bottom: 0;
}

.fi-modal-window.fi-bottom-sheet > .fi-modal-footer {
    position: relative;
    z-index: 1;
    margin-top: 0;
    border-top-width: 0;
    padding-top: 1.5rem;
    padding-bottom: 1.5rem;
}

/*
 * The header of an action sheet. It stays at the top while the body scrolls,
 * but a Filament modal header has no background and no bottom padding: the
 * scrolled content showed right under the heading text. The header has the
 * surface of the sheet and sits above the body. The sheet moves the space
 * under the header from the body (the `py-6` of `.fi-modal-content`) into the
 * header, so the content never scrolls under the heading.
 */
.fi-modal-window.fi-bottom-sheet:has(> .fi-modal-header) > .fi-modal-content {
    padding-top: 0;
}

.fi-modal-window.fi-bottom-sheet > .fi-modal-header {
    position: relative;
    z-index: 1;
    background-color: inherit;
    padding-bottom: 1.5rem;
}

/*
 * The edges, while the content scrolls: the directive sets
 * `data-bottom-sheet-scrolled-under` on the sheet until the body is at its
 * end (the top edge of the footer), and `data-bottom-sheet-scrolled` while
 * the body is not at its top (the bottom edge of the header). The line is a
 * shadow, so the header and the footer keep their height.
 */
.fi-bottom-sheet {
    --bottom-sheet-edge-rule: var(--gray-200, rgb(229 231 235));
    --bottom-sheet-edge-shadow: rgb(0 0 0 / 0.08);
}

:where(.dark) .fi-bottom-sheet {
    --bottom-sheet-edge-rule: rgb(255 255 255 / 0.1);
    --bottom-sheet-edge-shadow: rgb(0 0 0 / 0.4);
}

.fi-bottom-sheet > .fi-modal-header,
.fi-bottom-sheet > .fi-modal-footer,
.fi-bottom-sheet [data-bottom-sheet-footer] {
    transition: box-shadow 150ms ease-out;
}

.fi-bottom-sheet[data-bottom-sheet-scrolled-under] > .fi-modal-footer,
.fi-bottom-sheet[data-bottom-sheet-scrolled-under] [data-bottom-sheet-footer] {
    position: relative;
    z-index: 1;
    box-shadow:
        0 -1px 0 0 var(--bottom-sheet-edge-rule),
        0 -8px 16px -8px var(--bottom-sheet-edge-shadow);
}

.fi-bottom-sheet[data-bottom-sheet-scrolled] > .fi-modal-header {
    box-shadow:
        0 1px 0 0 var(--bottom-sheet-edge-rule),
        0 8px 16px -8px var(--bottom-sheet-edge-shadow);
}

@media (prefers-reduced-motion: reduce) {
    .fi-bottom-sheet > .fi-modal-header,
    .fi-bottom-sheet > .fi-modal-footer,
    .fi-bottom-sheet [data-bottom-sheet-footer] {
        transition: none;
    }
}
