@import url("/assets/lexxy-variables-890c2b00.css");

:where(lexxy-editor) {
    --lexxy-editor-padding: 1ch;
    --lexxy-editor-rows: 8lh;

    @supports (min-block-size: attr(rows lh)) {
        --lexxy-editor-rows: attr(rows lh, 8lh);
    }

    --lexxy-toolbar-gap: 2px;

    border: 1px solid var(--lexxy-color-ink-lighter);
    border-radius: calc(var(--lexxy-radius) + var(--lexxy-toolbar-gap));
    background-color: var(--lexxy-color-canvas);
    display: block;
    overflow: visible;
    position: relative;
    transition: opacity 150ms;

    input,
    button,
    summary {
        &:focus-visible {
            outline: var(--lexxy-focus-ring-size) solid var(--lexxy-focus-ring-color);
            outline-offset: var(--lexxy-focus-ring-offset);
        }
    }

    button,
    summary {
        -webkit-appearance: none;
        appearance: none;
        background: var(--lexxy-color-canvas);
        border: none;
        border-radius: var(--lexxy-radius);
        cursor: pointer;
        font-size: inherit;
        inline-size: auto;
        padding: 0;

        @media(any-hover: hover) {
            &:hover:not([aria-disabled="true"]) {
                background: var(--lexxy-color-ink-lightest);
            }
        }
    }

    .node--selected {

        &:has(img) img,
        &:not(:has(img)) {
            outline: var(--lexxy-focus-ring-size) solid var(--lexxy-focus-ring-color);
            outline-offset: var(--lexxy-focus-ring-offset);
        }
    }

    table {

        th,
        td {
            &.table-cell--selected {
                background-color: var(--lexxy-color-table-cell-selected-bg);
            }

            &.lexxy-content__table-cell--selected {
                background-color: var(--lexxy-color-table-cell-selected-bg);
                border-color: var(--lexxy-color-table-cell-selected-border);
            }
        }

        &.lexxy-content__table--selection {
            ::selection {
                background: transparent;
            }
        }
    }

    action-text-attachment {
        cursor: pointer;
    }
}

/* Placeholder */
:where(.lexxy-editor--empty) {
    .lexxy-editor__content:not(:has(ul, ol))::before {
        content: attr(placeholder);
        color: currentColor;
        cursor: text;
        opacity: 0.66;
        pointer-events: none;
        position: absolute;
        white-space: pre-line;
    }
}

:where(.lexxy-editor__content) {
    min-block-size: var(--lexxy-editor-rows);
    outline: 0;
    padding: var(--lexxy-editor-padding);
}

:where(.lexxy-editor--drag-over) {
    background-color: var(--lexxy-color-selected);
    border-radius: var(--lexxy-radius);
    outline: 2px dashed var(--lexxy-color-selected-dark);
}

:where([data-lexical-cursor]) {
    animation: blink 1s infinite;
    block-size: 1lh;
    border-inline-start: 1.5px solid currentColor;
    line-height: inherit;
    margin-block: 0 var(--lexxy-content-margin);
}

@keyframes blink {
    0% {
        opacity: 1;
    }

    60% {
        opacity: 1;
    }

    100% {
        opacity: 0;
    }
}

/* Toolbar
/* -------------------------------------------------------------------------- */

:where(lexxy-toolbar) {
    --lexxy-toolbar-icon-size: 1em;

    border-block-end: 1px solid var(--lexxy-color-ink-lighter);
    color: currentColor;
    display: flex;
    font-size: inherit;
    gap: var(--lexxy-toolbar-gap);
    max-inline-size: 100%;
    padding: 2px;
    position: relative;

    &[data-attachments="false"] button[name="upload"] {
        display: none;
    }
}

:where(.lexxy-editor__toolbar-button) {
    aspect-ratio: 1;
    block-size: 2lh;
    color: currentColor;
    display: grid;
    place-items: center;

    &:is(:active):not([aria-disabled="true"]),
    &[aria-pressed="true"] {
        background-color: var(--lexxy-color-selected);

        &:hover {
            background-color: var(--lexxy-color-selected-hover);
        }
    }

    &[aria-disabled="true"] {
        cursor: default;
        opacity: 0.3;
    }

    svg {
        -webkit-touch-callout: none;
        block-size: var(--lexxy-toolbar-icon-size);
        fill: currentColor;
        grid-area: 1/1;
        inline-size: var(--lexxy-toolbar-icon-size);
        user-select: none;
    }
}

:where(.lexxy-editor__toolbar-spacer) {
    flex: 1;
}

/* Make sure spacer is only displayed if there's another button before it */
*+ :where(.lexxy-editor__toolbar-spacer) {
    min-inline-size: 1lh;
}

:where(.lexxy-editor__toolbar-overflow) {
    display: none;
    justify-self: flex-end;
    position: relative;
    z-index: 1;

    summary {
        list-style: none;

        &::-webkit-details-marker {
            display: none;
        }

        [open] & {
            background-color: var(--lexxy-color-ink-lightest);
        }
    }
}

:where(.lexxy-editor__toolbar-overflow-menu) {
    background-color: var(--lexxy-color-canvas);
    border-radius: calc(var(--lexxy-radius) + var(--lexxy-toolbar-gap));
    box-shadow: var(--lexxy-shadow);
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--lexxy-toolbar-gap);
    inset-inline-end: 0;
    padding: var(--lexxy-toolbar-gap);
    position: absolute;

    .lexxy-editor__toolbar-spacer {
        display: none;
    }

    *+.lexxy-editor__toolbar-spacer+button {
        margin-left: 0.5lh;
    }
}

/* Dropdowns
/* -------------------------------------------------------------------------- */

:where(.lexxy-editor__toolbar-dropdown) {
    position: relative;
    user-select: none;
    -webkit-user-select: none;

    :where(.lexxy-editor__toolbar-dropdown-content) {
        --dropdown-padding: 1ch;
        --dropdown-gap: calc(var(--dropdown-padding) / 2);

        background-color: var(--lexxy-color-canvas);
        border: 2px solid var(--lexxy-color-selected-hover);
        border-radius: var(--lexxy-radius);
        border-start-start-radius: 0;
        box-sizing: border-box;
        color: var(--lexxy-color-ink);
        display: flex;
        gap: var(--dropdown-gap);
        inset-block-start: 2lh;
        inset-inline-start: 0;
        max-inline-size: 40ch;
        margin: 0;
        padding: var(--dropdown-padding);
        position: absolute;
        z-index: 3;
    }

    &:is([open]) .lexxy-editor__toolbar-button {
        background-color: var(--lexxy-color-selected-hover);
        border-end-end-radius: 0;
        border-end-start-radius: 0;

        &:hover {
            background-color: var(--lexxy-color-selected-hover);
        }
    }

    [overflowing] & {
        position: static;

        .lexxy-editor__toolbar-dropdown-content {
            --dropdown-padding: 0.5ch;
            inset-inline-end: var(--dropdown-padding);
            inset-inline-start: var(--dropdown-padding);
        }
    }
}

/* Link dropdown
/* -------------------------------------------------------------------------- */

:where(lexxy-link-dropdown) {

    >* {
        flex: 1;
    }

    .lexxy-editor__toolbar-dropdown-actions {
        display: flex;
        font-size: var(--lexxy-text-small);
        flex: 1 1 0%;
        gap: 1ch;
        margin-block-start: 1ch;
    }

    input[type="url"],
    button {
        line-height: 1.5lh;
        padding-inline: 1ch;
    }

    input[type="url"] {
        background-color: var(--lexxy-color-canvas);
        border: 1px solid var(--lexxy-color-ink-lighter);
        border-radius: var(--lexxy-radius);
        color: var(--lexxy-color-text);
        box-sizing: border-box;
        inline-size: 100%;
        min-inline-size: 40ch;

        [overflowing] & {
            min-inline-size: 0;
        }
    }

    button {
        background-color: var(--lexxy-color-ink-lightest);
        color: var(--lexxy-color-text);
        inline-size: 100%;
        justify-content: center;
    }

    button[type="submit"] {
        background-color: var(--lexxy-color-accent-dark);
        color: var(--lexxy-color-ink-inverted);

        &:hover {
            background-color: var(--lexxy-color-accent-medium);
        }
    }
}

/* Color dropdown
/* -------------------------------------------------------------------------- */

:where(lexxy-highlight-dropdown) {
    display: flex;
    flex-direction: column;

    [data-button-group] {
        display: flex;
        justify-items: flex-start;
        flex-direction: row;
        gap: var(--dropdown-gap);

        button {
            aspect-ratio: 1 / 1;
            inline-size: var(--button-size);
            min-inline-size: var(--button-size);
            max-inline-size: var(--button-size);

            &:after {
                align-self: center;
                content: "Aa";
                display: inline-block;
                font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
                position: absolute;
                inset-block-start: 0;
                inset-block-end: 0;
                inset-inline-end: 0;
                inset-inline-start: 0;
            }
        }
    }

    button {
        --button-size: 2lh;

        color: var(--lexxy-color-text);
        flex: 1;
        min-block-size: var(--button-size);
        position: relative;

        &:hover {
            opacity: 0.8;
        }

        &[aria-pressed="true"] {
            box-shadow: 0 0 0 2px currentColor inset;

            &:after {
                content: "✓";
            }
        }
    }

    .lexxy-editor__toolbar-dropdown-reset[disabled] {
        display: none;
    }

    [overflowing] & {
        inline-size: fit-content;

        [data-button-group] {
            flex-wrap: wrap;

            button {
                --button-size: 1.6lh;

                &:after {
                    font-size: 0.9em;
                }
            }
        }
    }
}

/* Table handle buttons
/* -------------------------------------------------------------------------- */

:where(lexxy-table-handler) {
    --button-size: 2.5lh;

    color: var(--lexxy-color-ink-inverted);
    display: none;
    flex-direction: row;
    font-size: var(--lexxy-text-small);
    gap: 0.25ch;
    line-height: 1;
    position: absolute;
    transform: translate(-50%, -120%);
    z-index: 2;

    .lexxy-table-control {
        align-items: center;
        background-color: var(--lexxy-color-ink);
        border-radius: 0.75ch;
        display: flex;
        flex-direction: row;
        gap: 1ch;
        padding: 2px;
        white-space: nowrap;

        button,
        summary {
            aspect-ratio: 1 / 1;
            align-items: center;
            background-color: transparent;
            border-radius: var(--lexxy-radius);
            border: 0;
            color: var(--lexxy-color-ink-inverted);
            cursor: pointer;
            display: flex;
            font-weight: bold;
            justify-content: center;
            line-height: 1;
            list-style: none;
            min-block-size: var(--button-size);
            min-inline-size: var(--button-size);
            padding: 0;
            user-select: none;
            -webkit-user-select: none;

            &:hover {
                background-color: var(--lexxy-color-ink-medium);
            }

            &:focus-visible {
                outline-color: var(--lexxy-focus-ring-color);
            }

            svg {
                block-size: 1em;
                inline-size: 1em;
                fill: currentColor;
            }

            span {
                display: none;
            }
        }
    }

    .lexxy-table-control__more-menu {
        gap: 0;
        padding: 0.25ch;
        position: relative;

        summary {
            &::-webkit-details-marker {
                display: none;
            }
        }

        .lexxy-table-control__more-menu-details {
            display: flex;
            flex-direction: column;
            gap: 0.25ch;
            inset-block-start: 105%;
            inset-inline-start: 0;
            padding: 0;
            position: absolute;

            .lexxy-table-control__more-menu-section {
                background: var(--lexxy-color-ink);
                border-radius: 0.75ch;
                display: flex;
                flex-direction: column;
                padding: 0.25ch;
            }

            button {
                aspect-ratio: unset;
                align-items: center;
                display: flex;
                flex-direction: row;
                font-weight: normal;
                gap: 1ch;
                justify-content: flex-start;
                padding: 0.5ch 2ch;
                padding-inline-start: 1ch;
                white-space: nowrap;

                span {
                    display: inline-block;
                }

                svg {
                    block-size: 1.3lh;
                    inline-size: 1.3lh;
                    fill: currentColor;
                }
            }
        }
    }
}


/* Language picker
/* -------------------------------------------------------------------------- */

:where(lexxy-code-language-picker) {
    inset-inline-end: var(--lexxy-editor-padding);
    position: absolute;

    select {
        -webkit-appearance: none;
        appearance: none;
        background-color: var(--lexxy-color-canvas);
        background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='m12 19.5c-.7 0-1.3-.3-1.7-.8l-9.8-11.1c-.7-.8-.6-1.9.2-2.6.8-.6 1.9-.6 2.5.2l8.6 9.8c0 .1.2.1.4 0l8.6-9.8c.7-.8 1.8-.9 2.6-.2s.9 1.8.2 2.6l-9.8 11.1c-.4.5-1.1.8-1.7.8z' fill='%23000'/%3E%3C/svg%3E");
        background-position: center right 1ch;
        background-repeat: no-repeat;
        background-size: 1ch;
        block-size: 1.5lh;
        border: 1px solid var(--lexxy-color-ink-lighter);
        border-radius: var(--lexxy-radius);
        color: var(--lexxy-color-ink);
        font-family: var(--lexxy-font-base);
        font-size: var(--lexxy-text-small);
        font-weight: normal;
        margin: 0.5ch 0.5ch 0 -0.5ch;
        padding: 0 2ch 0 1ch;
        text-align: start;

        @media (prefers-color-scheme: dark) {
            background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='m12 19.5c-.7 0-1.3-.3-1.7-.8l-9.8-11.1c-.7-.8-.6-1.9.2-2.6.8-.6 1.9-.6 2.5.2l8.6 9.8c0 .1.2.1.4 0l8.6-9.8c.7-.8 1.8-.9 2.6-.2s.9 1.8.2 2.6l-9.8 11.1c-.4.5-1.1.8-1.7.8z' fill='%23fff'/%3E%3C/svg%3E");
        }
    }
}

/* Prompt
/* ------------------------------------------------------------------------ */

:where(.lexxy-prompt-menu) {
    --lexxy-prompt-avatar-size: 24px;
    --lexxy-prompt-min-width: 20ch;
    --lexxy-prompt-padding: 0.5ch;

    background-color: var(--lexxy-color-canvas);
    border-radius: calc(var(--lexxy-prompt-padding) * 2);
    box-shadow: var(--lexxy-shadow);
    color: var(--lexxy-color-ink);
    font-family: var(--lexxy-font-base);
    font-size: var(--lexxy-text-small);
    list-style: none;
    margin: 0;
    max-block-size: 200px;
    min-inline-size: var(--lexxy-prompt-min-width);
    overflow: auto;
    padding: var(--lexxy-prompt-padding);
    visibility: hidden;
    z-index: var(--lexxy-z-popup);
}

:where(.lexxy-prompt-menu--visible) {
    visibility: initial;
}

:where(.lexxy-prompt-menu__item) {
    align-items: center;
    border-radius: var(--lexxy-radius);
    cursor: pointer;
    display: flex;
    gap: var(--lexxy-prompt-padding);
    padding: var(--lexxy-prompt-padding);
    white-space: nowrap;

    &:hover {
        background-color: var(--lexxy-color-ink-lightest);
    }

    &[aria-selected] {
        background-color: var(--lexxy-color-selected);
    }

    img {
        block-size: var(--lexxy-prompt-avatar-size);
        border-radius: 50%;
        flex-shrink: 0;
        inline-size: var(--lexxy-prompt-avatar-size);
        margin: 0;
    }

    +& {
        margin-top: 2px;
    }
}

:where(.lexxy-prompt-menu__item--empty) {
    color: var(--lexxy-color-ink-medium);
    padding: var(--lexxy-prompt-padding);
}