/*
 * The command palette.
 *
 * Filament's global search is a field in the corner of the topbar. Pressing its
 * shortcut only moves the caret into it, which on a wide screen is no visible
 * change at all: people press the keys, see nothing happen, and conclude the
 * shortcut is broken.
 *
 * Nothing here replaces that field. While the search is open the same element
 * is lifted out of the topbar and set down in the middle of the window over a
 * dimmed page, which is where the eye already is and where every other app has
 * taught people to expect it. Closing it puts it back. If the script driving
 * the class never runs, the field stays exactly where Filament put it and still
 * works.
 */
.fi-palette-open .fi-global-search-ctn {
    inset-inline: 0;
    margin-inline: auto;
    position: fixed;
    top: 12vh;
    width: min(40rem, calc(100vw - calc(var(--spacing) * 8)));

    /*
     * Ordered against the backdrop below, not against the page. The search
     * field is a child of the topbar, and the topbar is a stacking context of
     * its own, so no z-index here can lift the field out of it: whatever the
     * number, the field paints as part of the topbar. Both this and the
     * backdrop therefore live inside that same context and are ordered against
     * each other, which is why these numbers are small.
     */
    z-index: 2;
}

/*
 * The field grows into something worth typing a sentence into, rather than the
 * 200px it needs when it is only a corner affordance.
 */
.fi-palette-open .fi-global-search-field .fi-input {
    font-size: 1rem;
    padding-block: calc(var(--spacing) * 3);
}

/*
 * Filament sizes the results panel for the corner of the topbar, where it is
 * pinned to the end edge and capped at max-w-sm. Inside the palette that cap
 * would leave results at roughly half the width of the field above them, so
 * the panel is stretched across the container instead, matching the recently
 * viewed list below.
 */
.fi-palette-open .fi-global-search-ctn .fi-global-search-results-ctn {
    inset-inline: 0;
    max-height: min(28rem, 60vh);
    max-width: none;
    overflow-y: auto;
    width: auto;
}

/*
 * The backdrop hangs off the topbar, in the same stacking context as the search
 * field it sits behind, because that is the only place the two can be ordered
 * against each other at all.
 *
 * It still covers the page: Filament puts the topbar on 30 and the sidebar on
 * 20, and the content below both, so anything painted inside the topbar is
 * painted over all of them. Hung off the body instead, the backdrop would clear
 * the whole layout and take the search field down with it.
 */
.fi-palette-open .fi-topbar-ctn::after {
    background-color: color-mix(in oklab, var(--gray-950) 40%, transparent);
    content: '';
    inset: 0;
    position: fixed;
    z-index: 1;
}

/*
 * In dark mode Filament draws the field with a faint translucent wash, which
 * works against the topbar but lets the page show through the text once the
 * field is floated over it. It is made solid here, in the same grey as the
 * results panel that hangs below it.
 */
.dark .fi-palette-open .fi-global-search-field .fi-input-wrp {
    background-color: var(--gray-900);
}

/*
 * The shortcut is a hint for finding the field. Once the field is open and
 * filling the screen, it is just clutter.
 */
.fi-palette-open .fi-global-search-field .fi-input-wrp-suffix {
    display: none;
}

/*
 * A palette that jumped into place would read as a glitch at this size. It is
 * skipped for anyone who has asked their system for less movement.
 */
@media (prefers-reduced-motion: no-preference) {
    .fi-palette-open .fi-global-search-ctn {
        animation: fi-palette-in 120ms ease-out;
    }

    .fi-palette-open .fi-topbar-ctn::after {
        animation: fi-palette-fade 120ms ease-out;
    }
}

@keyframes fi-palette-in {
    from {
        opacity: 0;
        transform: translateY(calc(var(--spacing) * -2));
    }
}

@keyframes fi-palette-fade {
    from {
        opacity: 0;
    }
}

/*
 * On a narrow screen the topbar field is already hidden behind a button and
 * there is no room to float anything, so the palette fills the width it has.
 */
@media (max-width: 640px) {
    .fi-palette-open .fi-global-search-ctn {
        top: calc(var(--spacing) * 4);
        width: calc(100vw - calc(var(--spacing) * 4));
    }
}

/*
 * The recently viewed list, shown in place of results while the palette is
 * open and nothing has been typed.
 *
 * It hangs below the field rather than sitting beside it, because the search
 * container is a flex row and a block dropped into it would land next to the
 * input. Filament's own results panel solves that the same way, so the two
 * arrive in the same place and the list does not appear to jump when a search
 * replaces it.
 *
 * Hidden by default, so the field carries nothing under it in the topbar and
 * nothing at all if the script that opens the palette never runs.
 */
.fi-palette-recent {
    display: none;
}

/*
 * No animation of its own: this is inside the search container, which is
 * already animated into place when the palette opens, so the list arrives with
 * it.
 */
.fi-palette-open.fi-palette-empty .fi-palette-recent {
    background-color: var(--color-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: block;
    inset-inline: 0;
    margin-top: calc(var(--spacing) * 2);
    max-height: min(28rem, 60vh);
    overflow-y: auto;
    position: absolute;
    top: 100%;

    /* Matches the hairline Filament rings its own results panel with. */
    outline: 1px solid color-mix(in oklab, var(--gray-950) 5%, transparent);
    outline-offset: -1px;
}

.dark .fi-palette-open.fi-palette-empty .fi-palette-recent {
    background-color: var(--gray-900);
    outline-color: color-mix(in oklab, var(--color-white) 10%, transparent);
}

/*
 * The group headers in the results and in the recently viewed list are drawn
 * in the navy of the Temple wordmark with white text, so the groups stand out
 * from the results under them and the palette carries the brand. The navy
 * holds in dark mode too, where Filament's own grey would otherwise take over.
 *
 * Qualified by the results list so it outranks Filament's dark mode rule, which
 * matches the header on its own class.
 */
.fi-global-search-results .fi-global-search-result-group-header {
    background-color: var(--primary-600);
    border-color: var(--primary-600);
    color: var(--color-white);
}
