/*
 * Split-view preview in the Filament panel: while it is open, the editor
 * becomes a narrow column next to the front-end.
 */
html.filament-preview-open {
    --filament-preview-editor-width: 36rem;
}

html.filament-preview-open .fi-sidebar,
html.filament-preview-open .fi-sidebar-close-overlay,
html.filament-preview-open .fi-topbar-ctn,
html.filament-preview-open .fi-page .fi-header {
    display: none;
}

/* An editor opened in the overlay of another preview shows only the page, without links elsewhere. */
html.filament-preview-embedded .fi-sidebar,
html.filament-preview-embedded .fi-sidebar-close-overlay,
html.filament-preview-embedded .fi-topbar-ctn,
html.filament-preview-embedded .fi-breadcrumbs {
    display: none;
}

html.filament-preview-embedded .fi-main-ctn {
    width: 100%;
}

html.filament-preview-open .fi-layout {
    width: var(--filament-preview-editor-width);
}

html.filament-preview-open .fi-main-ctn {
    width: 100%;
}

/*
 * Form grids respond to the viewport, which stays wide, so stack them by hand.
 * Filament sets the column counts inline, hence !important.
 */
html.filament-preview-open .fi-main .fi-grid {
    grid-template-columns: minmax(0, 1fr) !important;
}

html.filament-preview-open .fi-main .fi-grid-col {
    grid-column: 1 / -1 !important;
}

/*
 * Keep the save buttons in reach while scrolling the narrow editor. They are
 * the last child of the page form, styled like Filament's sticky actions.
 * overflow-x: hidden on html or body turns it into a scroll container that
 * never scrolls, which stops sticky from working; clip doesn't.
 */
html.filament-preview-open,
html.filament-preview-open body {
    overflow-x: clip;
}

html.filament-preview-open form#form > .fi-sc:last-child {
    position: sticky;
    bottom: 1rem;
    z-index: 10;
    padding: 1rem;
    border-radius: 0.75rem;
    background-color: white;
    box-shadow:
        0 0 0 1px color-mix(in oklab, var(--gray-950) 5%, transparent),
        0 10px 15px -3px rgb(0 0 0 / 0.1),
        0 4px 6px -4px rgb(0 0 0 / 0.1);
}

/* The form field that is being edited in the preview. */
.filament-preview-active-field {
    outline: 2px solid var(--primary-500);
    outline-offset: 0.375rem;
    border-radius: 0.5rem;
}

/* Below Filament's modals (z-index 40), which the form opens, such as the attachment library. */
.filament-preview-panel {
    position: fixed;
    inset-block: 0;
    inset-inline: var(--filament-preview-editor-width) 0;
    z-index: 30;
    display: flex;
    flex-direction: column;
    border-inline-start: 1px solid var(--gray-200);
    background-color: white;
    container-type: inline-size;
}

/* Close on the side of the editor, the devices in the middle. */
.filament-preview-toolbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--gray-200);
}

.filament-preview-toolbar-start {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    justify-self: start;
    min-width: 0;
}

/* Whether the preview is refreshing, or just was. Keeps its room, so nothing moves when it shows. */
.filament-preview-status {
    min-width: 1rem;
}

.filament-preview-status > span {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    color: var(--gray-500);
    font-size: 0.875rem;
    line-height: 1.25rem;
    white-space: nowrap;
}

.filament-preview-status svg {
    flex-shrink: 0;
    width: 1rem;
    height: 1rem;
}

.filament-preview-status .filament-preview-status-refreshed {
    color: var(--success-600);
}

.filament-preview-toolbar-empty {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-self: end;
    color: var(--gray-950);
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.25rem;
    white-space: nowrap;
    cursor: pointer;
}

.filament-preview-toolbar-devices {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.filament-preview-toolbar-separator {
    width: 1px;
    height: 1.25rem;
    margin-inline: 0.5rem;
    background-color: var(--gray-200);
}

.filament-preview-toolbar .fi-icon-btn.filament-preview-toolbar-active,
.filament-preview-format .fi-icon-btn.filament-preview-toolbar-active {
    background-color: var(--gray-100);
    color: var(--primary-600);
}

.filament-preview-stage {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.filament-preview-stage-loading {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gray-400);
    pointer-events: none;
}

.filament-preview-stage-loading svg {
    width: 2rem;
    height: 2rem;
}

.filament-preview-device {
    position: absolute;
    top: 50%;
    left: 50%;
    translate: -50% -50%;
}

.filament-preview-device-screen {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* Rendered at the size of the device and scaled to fit, see viewport() in the panel. */
.filament-preview-panel-frame {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    display: block;
    border: 0;
    transform-origin: 0 0;
    background-color: white;
}

/* The next version of the preview, rendering behind the shown one. Not hidden, which would keep it from rendering. */
.filament-preview-panel-frame-loading {
    z-index: 0;
    opacity: 0;
    pointer-events: none;
}

/* A tablet, phone or responsive view: centred on a background, with room around it. */
.filament-preview-stage:not([data-device='desktop']) {
    background-color: var(--gray-100);
}

.filament-preview-stage:not([data-device='desktop']) .filament-preview-device-screen {
    border-radius: 1rem;
    box-shadow:
        0 0 0 1px color-mix(in oklab, var(--gray-950) 10%, transparent),
        0 20px 25px -5px rgb(0 0 0 / 0.1),
        0 8px 10px -6px rgb(0 0 0 / 0.1);
}

/* The frame would take the pointer while an edge is dragged over it. */
.filament-preview-resizing .filament-preview-panel-frame {
    pointer-events: none;
}

.filament-preview-resizing {
    user-select: none;
}

/* Grips on the right edge, the bottom edge and the corner of the responsive view. */
.filament-preview-handle {
    position: absolute;
    z-index: 1;
    border-radius: 9999px;
    background-color: var(--gray-400);
    touch-action: none;
}

.filament-preview-handle:hover,
.filament-preview-resizing .filament-preview-handle {
    background-color: var(--primary-500);
}

.filament-preview-handle-x {
    top: 50%;
    left: calc(100% + 0.375rem);
    width: 0.375rem;
    height: 3rem;
    translate: 0 -50%;
    cursor: ew-resize;
}

.filament-preview-handle-y {
    top: calc(100% + 0.375rem);
    left: 50%;
    width: 3rem;
    height: 0.375rem;
    translate: -50% 0;
    cursor: ns-resize;
}

.filament-preview-handle-xy {
    top: calc(100% + 0.25rem);
    left: calc(100% + 0.25rem);
    width: 0.75rem;
    height: 0.75rem;
    cursor: nwse-resize;
}

.filament-preview-toolbar-size {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    margin-inline-start: 0.5rem;
    color: var(--gray-500);
}

.filament-preview-toolbar-size .fi-input-wrp {
    width: 5.5rem;
}

/* The toolbar of a rich text being edited in the preview, next to that text. */
.filament-preview-format {
    position: absolute;
    z-index: 2;
    padding: 0.375rem 0.625rem;
    border-radius: 0.5rem;
    background-color: white;
    box-shadow:
        0 0 0 1px color-mix(in oklab, var(--gray-950) 10%, transparent),
        0 10px 15px -3px rgb(0 0 0 / 0.1),
        0 4px 6px -4px rgb(0 0 0 / 0.1);
}

.filament-preview-format-buttons,
.filament-preview-format-link {
    display: flex;
    align-items: center;
    gap: 0.625rem;
}

.filament-preview-format-link .fi-input-wrp {
    width: 16rem;
}

/* The blocks to choose from for an item added in the preview, next to its button. */
.filament-preview-picker {
    position: absolute;
    z-index: 2;
    width: 16rem;
    max-height: 20rem;
    overflow-y: auto;
    border-radius: 0.5rem;
    background-color: white;
    box-shadow:
        0 0 0 1px color-mix(in oklab, var(--gray-950) 10%, transparent),
        0 10px 15px -3px rgb(0 0 0 / 0.1),
        0 4px 6px -4px rgb(0 0 0 / 0.1);
}

.filament-preview-picker-heading {
    padding: 0.625rem 0.75rem 0.25rem;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--gray-500);
}

.filament-preview-picker-block {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.filament-preview-picker-icon {
    display: contents;
    color: var(--gray-400);
}

/* A narrow preview keeps everything on one line: close shows its icon only. */
@container (max-width: 40rem) {
    .filament-preview-toolbar {
        grid-template-columns: auto 1fr auto;
    }

    .filament-preview-toolbar-devices {
        justify-self: center;
    }

    .filament-preview-toolbar-close-label,
    .filament-preview-status-label {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }

    .filament-preview-toolbar-size .fi-input-wrp {
        width: 4.5rem;
    }
}

/* Too narrow for the label of the empty fields toggle as well. */
@container (max-width: 32rem) {
    .filament-preview-toolbar-empty-label {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }
}

/* The editor of another record, opened by clicking it in the preview. */
.filament-preview-entry {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    padding: 4rem 2rem 2rem;
    background-color: color-mix(in oklab, var(--gray-950) 50%, transparent);
}

.filament-preview-entry-dialog {
    flex: 1;
    overflow: hidden;
    border-radius: 0.75rem;
    background-color: white;
    box-shadow:
        0 20px 25px -5px rgb(0 0 0 / 0.1),
        0 8px 10px -6px rgb(0 0 0 / 0.1);
}

.filament-preview-entry-frame {
    width: 100%;
    height: 100%;
    border: 0;
}

.filament-preview-entry-close {
    position: absolute;
    top: 1rem;
    inset-inline-end: 2rem;
    border-radius: 9999px;
    background-color: white;
}

html.dark.filament-preview-open form#form > .fi-sc:last-child,
.dark .filament-preview-entry-dialog,
.dark .filament-preview-entry-close {
    background-color: var(--gray-900);
}

.dark .filament-preview-panel,
.dark .filament-preview-toolbar {
    border-color: color-mix(in oklab, white 10%, transparent);
}

.dark .filament-preview-panel {
    background-color: var(--gray-900);
}

.dark .filament-preview-toolbar-empty {
    color: white;
}

.dark .filament-preview-status > span {
    color: var(--gray-400);
}

.dark .filament-preview-status .filament-preview-status-refreshed {
    color: var(--success-400);
}

.dark .filament-preview-toolbar-separator {
    background-color: color-mix(in oklab, white 10%, transparent);
}

.dark .filament-preview-toolbar .fi-icon-btn.filament-preview-toolbar-active,
.dark .filament-preview-format .fi-icon-btn.filament-preview-toolbar-active {
    background-color: color-mix(in oklab, white 5%, transparent);
    color: var(--primary-400);
}

.dark .filament-preview-stage:not([data-device='desktop']) {
    background-color: var(--gray-950);
}

.dark .filament-preview-format {
    background-color: var(--gray-900);
    box-shadow:
        0 0 0 1px color-mix(in oklab, white 10%, transparent),
        0 10px 15px -3px rgb(0 0 0 / 0.3);
}

.dark .filament-preview-picker {
    background-color: var(--gray-900);
    box-shadow:
        0 0 0 1px color-mix(in oklab, white 10%, transparent),
        0 10px 15px -3px rgb(0 0 0 / 0.3);
}

.dark .filament-preview-picker-heading {
    color: var(--gray-400);
}

.dark .filament-preview-picker-icon {
    color: var(--gray-500);
}

.dark .filament-preview-handle {
    background-color: var(--gray-600);
}

.dark .filament-preview-handle:hover,
.dark .filament-preview-resizing .filament-preview-handle {
    background-color: var(--primary-400);
}
