@import 'payload/dist/admin/scss/vars';

.visual-editor {
    display: flex;

    &.iframe {
        display: grid;
        grid-template-columns: 1fr var(--preview-width);

        >.document-fields {
            .document-fields__edit {
                padding-right: calc(var(--base) * 1.5);
            }

            .tabs-field__content-wrap {
                padding-right: calc(var(--base) * 2);
            }
        }
    }

    &.iframe,
    &.none {
        .document-fields {
            display: flex;
            flex-direction: column;

            &__edit {
                border: none !important;
            }
        }
    }

    >* {
        overflow: hidden;
    }

    .document-fields__sidebar-wrap {
        background: var(--theme-elevation-50);
        padding-top: var(--base);
    }
}

@media (max-width: $breakpoint-m-width) {
    .visual-editor {
        display: block;

        >.document-fields {
            width: 100%;
        }

        >.preview-container {
            display: none !important;
        }
    }
}

.preview-container {
    position: sticky;
    top: var(--doc-controls-height);
    height: calc(100vh - var(--doc-controls-height));
    padding: calc(var(--base) * 1.5);
    background: var(--theme-elevation-100);

    &.sidebar {
        padding: calc(var(--base) / 2);
        display: flex;
        flex-direction: column;
        text-align: center;
        background: var(--theme-elevation-0);
        border-left: 1px solid var(--theme-elevation-100);

        >h5 {
            font-size: 1em;
            margin: 0 0 base(.25) 0;
        }

        >button {
            background: none;
            padding: base(.25);
            margin: 0 0 base(.25) 0;
            line-height: 0;

            color: var(--theme-elevation-800);

            svg {
                width: base(1);
                height: base(.75);
            }
        }
    }

    .live-preview-container {
        width: 100%;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .live-preview-resize-container {
        position: relative;
        display: grid;
        grid-template-rows: auto 1fr;
        width: 100%;
        max-width: 100%;
        min-width: 100px;
        height: 100%;
        max-height: 100%;
        min-height: 150px;
        border: none;
        padding: 0;
        overflow: hidden;

        &.responsive {
            resize: both;
        }

        >.live-preview-settings {
            display: flex;
            justify-content: center;
            background: var(--theme-elevation-50);
            color: var(--theme-elevation-500);
            height: base(1.5);

            .selectMenu {
                position: relative;

                >.backdrop {
                    position: fixed;
                    inset: 0;
                    z-index: 1;
                }

                >button {
                    position: relative;
                    border: none;
                    background: none;
                    appearance: none;
                    padding: 0;
                    cursor: pointer;
                    height: 100%;
                    padding: 0 base(.95) 0 base(.5);

                    .icon {
                        content: "";
                        display: block;
                        position: absolute;
                        right: 0.25em;
                        top: 0;
                        height: 100%;

                        .icon--chevron {
                            transition: transform .25s ease;

                            .stroke {
                                fill: none;
                                stroke: var(--theme-elevation-800);
                                stroke-width: 1.5px;
                            }
                        }
                    }

                    &[aria-expanded="true"] {
                        .icon .icon--chevron {
                            transform: rotate(180deg);
                        }
                    }
                }

                >.menu {
                    position: absolute;
                    z-index: 1;
                    background: var(--theme-elevation-100);

                    display: grid;
                    grid-template-rows: 0fr;
                    transition: grid-template-rows 0.25s ease;

                    &[aria-expanded="true"] {
                        grid-template-rows: 1fr;
                    }

                    >ul {
                        list-style: none;
                        padding: 0;
                        margin: 0;
                        overflow: hidden;

                        >li {
                            >button {
                                border: none;
                                background: none;
                                appearance: none;
                                cursor: pointer;
                                padding: base(0.5);
                                color: var(--theme-elevation-800);
                                white-space: nowrap;

                                &:hover {
                                    color: var(--theme-elevation-1000);
                                    text-decoration: underline;
                                }
                            }
                        }
                    }
                }

                &.size .menu {
                    min-width: 7.5rem;
                }
            }

            >.rotate {
                border: none;
                background: none;
                appearance: none;
                cursor: pointer;
                font-size: 1.5em;
                height: 100%;

                >svg {
                    width: base(.5);
                    margin-bottom: 3px;
                    transition: transform .25s ease;
                }

                &:active>svg {
                    transform: rotate(180deg);
                }
            }

            >.size-display {
                align-self: center;
                white-space: nowrap;
                padding: 0 base(.25);
            }

            >.elemsRight {
                margin-left: auto;
                padding-right: base(.15);

                >button {
                    border: none;
                    background: none;
                    appearance: none;
                    padding: 0;
                    cursor: pointer;
                    height: 100%;
                    padding: base(.25);

                    >svg {
                        width: base(.85);
                        height: base(.85);
                    }

                    &.closeVisualEditor {
                        >.icon--close-menu>.fill {
                            fill: var(--theme-elevation-600);
                        }
                    }

                    &.openInWindow {
                        color: var(--theme-elevation-600);
                    }
                }
            }
        }

        >iframe {
            width: 100%;
            height: 100%;

            background-color: #fff;
            border: none;

            transform-origin: top left;

            ::-webkit-scrollbar {
                width: 10px;
            }

            ::-webkit-scrollbar-track {
                background: #f1f1f1;
            }

            ::-webkit-scrollbar-thumb {
                background: #888;
            }

            ::-webkit-scrollbar-thumb:hover {
                background: #555;
            }
        }
    }
}
