/* NxlCodeEditor (and NxlExpressionEdit). Global, not scoped: the completion list, signature help and
   hover are added to <body> by the editor's script. Colours come from the DevExpress design tokens, so
   the editor follows the theme mode and accent. The coloured copy (.nxl-ce-highlight) and the textarea
   (.nxl-ce-input) must keep identical metrics: change fonts, padding and wrapping on both or neither,
   and never make a token class change the width of text (no bold). */

.nxl-code-editor {
    --nxl-ce-font: var(--nxl-code-font, ui-monospace, "Cascadia Mono", Consolas, "Liberation Mono", Menlo, monospace);
    --nxl-ce-font-size: 0.8125rem;
    --nxl-ce-line-height: 1.5;
    --nxl-ce-padding-y: 0.3125rem;
    --nxl-ce-padding-x: 0.5rem;
    --nxl-ce-text: var(--dxds-color-content-neutral-default-rest);
    --nxl-ce-subdued: var(--dxds-color-content-neutral-subdued-rest);
    --nxl-ce-primary: var(--dxds-color-content-primary-default-rest);
    --nxl-ce-danger: var(--dxds-color-content-danger-default-rest);
    --nxl-ce-warning: var(--dxds-color-content-warning-default-rest);
    --nxl-ce-success: var(--dxds-color-content-success-default-rest);
    --nxl-ce-info: var(--dxds-color-content-info-default-rest);

    display: flex;
    align-items: flex-start;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    border: 1px solid var(--dxds-color-border-neutral-default-rest);
    border-radius: var(--nxl-radius-sm, 4px);
    background: var(--dxds-color-surface-neutral-default-rest);
    transition: border-color 0.1s, box-shadow 0.1s;
}

.nxl-code-editor:focus-within {
    border-color: var(--nxl-ce-primary);
    box-shadow: inset 0 -1px 0 var(--nxl-ce-primary);
}

.nxl-code-editor.nxl-ce-has-errors {
    border-color: var(--nxl-ce-danger);
}

.nxl-code-editor.nxl-ce-disabled {
    opacity: 0.6;
}

.nxl-ce-box {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
}

.nxl-ce-highlight,
.nxl-ce-input {
    display: block;
    box-sizing: border-box;
    margin: 0;
    border: 0;
    padding: var(--nxl-ce-padding-y) var(--nxl-ce-padding-x);
    font-family: var(--nxl-ce-font);
    font-size: var(--nxl-ce-font-size);
    font-weight: normal;
    font-style: normal;
    line-height: var(--nxl-ce-line-height);
    letter-spacing: normal;
    tab-size: 4;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: normal;
    text-align: start;
}

.nxl-ce-highlight {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    color: var(--nxl-ce-text);
    background: transparent;
}

.nxl-ce-input {
    position: relative;
    width: 100%;
    min-height: 0;
    resize: none;
    overflow: hidden;
    outline: none;
    color: transparent;
    caret-color: var(--nxl-ce-text);
    background: transparent;
}

/* Until the script has coloured the copy, the textarea shows its own text. */
.nxl-code-editor:not([data-nxl-ce-ready]) .nxl-ce-input {
    color: var(--nxl-ce-text);
}

.nxl-ce-input::placeholder {
    color: var(--nxl-ce-subdued);
    opacity: 1;
}

.nxl-ce-input:disabled {
    cursor: not-allowed;
}

.nxl-ce-addons {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 2px;
    padding: 1px 2px;
}

/* ── Document layout: line numbers, no wrapping, a fixed height that scrolls ── */

.nxl-code-editor.nxl-ce-document {
    align-items: stretch;
    overflow: hidden;
}

.nxl-ce-document .nxl-ce-box {
    height: 100%;
}

.nxl-ce-document .nxl-ce-highlight,
.nxl-ce-document .nxl-ce-input {
    white-space: pre;
    overflow-wrap: normal;
}

.nxl-ce-document .nxl-ce-input {
    height: 100%;
    overflow: auto;
}

/* The script sets its height to the textarea's visible height, so both scroll the same range. */
.nxl-ce-gutter {
    flex: 0 0 auto;
    align-self: flex-start;
    box-sizing: content-box;
    min-width: calc(var(--nxl-ce-gutter-digits, 2) * 1ch);
    margin: 0;
    border: 0;
    border-inline-end: 1px solid var(--dxds-color-border-neutral-default-rest);
    padding: var(--nxl-ce-padding-y) 0.5rem var(--nxl-ce-padding-y) 0.625rem;
    overflow: hidden;
    font-family: var(--nxl-ce-font);
    font-size: var(--nxl-ce-font-size);
    line-height: var(--nxl-ce-line-height);
    white-space: pre;
    text-align: end;
    color: var(--nxl-ce-subdued);
    background: color-mix(in srgb, var(--nxl-ce-subdued) 6%, transparent);
    user-select: none;
}

.nxl-ce-gutter-error { color: var(--nxl-ce-danger); }
.nxl-ce-gutter-warning { color: var(--nxl-ce-warning); }

/* ── Tokens ─────────────────────────────────────────────────────────────── */

.nxl-ce-t-number { color: var(--nxl-ce-success); }
.nxl-ce-t-text,
.nxl-ce-t-date { color: var(--nxl-ce-warning); }
.nxl-ce-t-parameter { color: var(--nxl-ce-info); }
.nxl-ce-t-function,
.nxl-ce-t-keyword,
.nxl-ce-t-constant { color: var(--nxl-ce-primary); }
.nxl-ce-t-operator,
.nxl-ce-t-punctuation { color: var(--nxl-ce-subdued); }
.nxl-ce-t-literal { color: var(--nxl-ce-text); }
.nxl-ce-t-delimiter { color: var(--nxl-ce-primary); }
.nxl-ce-t-invalid { color: var(--nxl-ce-danger); }
.nxl-ce-t-comment,
.nxl-ce-t-markup { color: var(--nxl-ce-subdued); }

/* An expression hole (or a template tag) in literal text, set off from the text around it. */
.nxl-ce-s-hole,
.nxl-ce-s-tag,
.nxl-ce-t-delimiter {
    background: color-mix(in srgb, var(--nxl-ce-primary) 9%, transparent);
}

/* ── Problems ───────────────────────────────────────────────────────────── */

.nxl-ce-error,
.nxl-ce-warning {
    text-decoration-line: underline;
    text-decoration-style: wavy;
    text-decoration-skip-ink: none;
    text-underline-offset: 3px;
}

.nxl-ce-error { text-decoration-color: var(--nxl-ce-danger); }
.nxl-ce-warning { text-decoration-color: var(--nxl-ce-warning); }

/* A problem at a position (nothing to underline): a small wedge under it, taking no room. */
.nxl-ce-mark {
    position: relative;
    text-decoration: none;
}

.nxl-ce-mark::after {
    content: "";
    position: absolute;
    left: -3px;
    bottom: -3px;
    border: 3px solid transparent;
    border-bottom-color: var(--nxl-ce-danger);
}

.nxl-ce-mark.nxl-ce-warning::after {
    border-bottom-color: var(--nxl-ce-warning);
}

/* ── Popups (completion, signature help, hover) ─────────────────────────── */

.nxl-ce-popup {
    position: fixed;
    z-index: 20000;
    box-sizing: border-box;
    max-width: min(480px, calc(100vw - 16px));
    border: 1px solid var(--dxds-color-border-neutral-default-rest);
    border-radius: var(--nxl-radius-md, 6px);
    background: var(--dxds-color-surface-neutral-default-rest);
    box-shadow: var(--nxl-shadow-md, 0 4px 12px rgb(0 0 0 / 18%));
    color: var(--dxds-color-content-neutral-default-rest);
    font-size: 0.8125rem;
    line-height: 1.4;
}

.nxl-ce-list {
    min-width: 260px;
    max-height: 240px;
    overflow-y: auto;
    padding: 2px 0;
}

.nxl-ce-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 8px;
    cursor: pointer;
    white-space: nowrap;
}

.nxl-ce-item:hover {
    background: color-mix(in srgb, var(--dxds-color-content-neutral-default-rest) 6%, transparent);
}

.nxl-ce-item.nxl-ce-selected {
    background: color-mix(in srgb, var(--dxds-color-content-primary-default-rest) 14%, transparent);
}

.nxl-ce-badge {
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    border-radius: 3px;
    font: 600 10px/16px var(--nxl-code-font, ui-monospace, Consolas, monospace);
    text-align: center;
    color: var(--dxds-color-content-neutral-default-inverted-rest, #fff);
    background: var(--dxds-color-content-neutral-subdued-rest);
}

.nxl-ce-badge-function { background: var(--dxds-color-content-primary-default-rest); }
.nxl-ce-badge-parameter { background: var(--dxds-color-content-info-default-rest); }
.nxl-ce-badge-value { background: var(--dxds-color-content-warning-default-rest); }
.nxl-ce-badge-keyword,
.nxl-ce-badge-constant { background: var(--dxds-color-content-success-default-rest); }

.nxl-ce-label {
    font-family: var(--nxl-code-font, ui-monospace, Consolas, monospace);
}

.nxl-ce-detail {
    margin-left: auto;
    padding-left: 16px;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--dxds-color-content-neutral-subdued-rest);
}

.nxl-ce-doc {
    border-top: 1px solid var(--dxds-color-border-neutral-default-rest);
    padding: 6px 8px;
    white-space: normal;
    color: var(--dxds-color-content-neutral-subdued-rest);
}

.nxl-ce-doc-group {
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--dxds-color-content-neutral-subdued-rest);
}

.nxl-ce-signature {
    padding: 4px 8px;
}

.nxl-ce-signature .nxl-ce-doc {
    margin: 4px -8px -4px;
}

.nxl-ce-signature-label {
    font-family: var(--nxl-code-font, ui-monospace, Consolas, monospace);
}

.nxl-ce-signature-label b {
    color: var(--dxds-color-content-primary-default-rest);
}

.nxl-ce-tooltip {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 6px 8px;
}

.nxl-ce-tip-title {
    font-family: var(--nxl-code-font, ui-monospace, Consolas, monospace);
}

.nxl-ce-tip-doc {
    color: var(--dxds-color-content-neutral-subdued-rest);
}

.nxl-ce-tip-error { color: var(--dxds-color-content-danger-default-rest); }
.nxl-ce-tip-warning { color: var(--dxds-color-content-warning-default-rest); }

/* ── NxlExpressionEdit ──────────────────────────────────────────────────── */

.nxl-code-editor .nxl-ee-expand {
    opacity: 0.55;
}

.nxl-code-editor:hover .nxl-ee-expand,
.nxl-code-editor:focus-within .nxl-ee-expand {
    opacity: 1;
}

.nxl-ee-dialog-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(220px, 320px);
    gap: var(--nxl-space-4, 1rem);
    min-height: 480px;
}

@media (max-width: 720px) {
    .nxl-ee-dialog-body {
        grid-template-columns: minmax(0, 1fr);
    }
}

.nxl-ee-main,
.nxl-ee-side {
    display: flex;
    flex-direction: column;
    gap: var(--nxl-space-2, 0.5rem);
    min-width: 0;
}

.nxl-ee-hint {
    color: var(--dxds-color-content-neutral-subdued-rest);
    font-size: 0.75rem;
}

.nxl-ee-status {
    display: flex;
    flex-wrap: wrap;
    gap: var(--nxl-space-3, 0.75rem);
    align-items: center;
}

.nxl-ee-result {
    font-weight: 600;
}

.nxl-ee-ok {
    color: var(--dxds-color-content-success-default-rest);
}

.nxl-ee-problems {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nxl-ee-problems li {
    display: flex;
    gap: 6px;
    align-items: baseline;
}

.nxl-ee-error { color: var(--dxds-color-content-danger-default-rest); }
.nxl-ee-warning { color: var(--dxds-color-content-warning-default-rest); }

.nxl-ee-reference {
    height: 400px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.nxl-ee-group {
    position: sticky;
    top: 0;
    padding: 6px 4px 2px;
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--dxds-color-content-neutral-subdued-rest);
    background: var(--dxds-color-surface-neutral-default-rest);
}

.nxl-ee-item {
    display: flex;
    flex-direction: column;
    gap: 1px;
    width: 100%;
    padding: 4px;
    border: 0;
    border-radius: var(--nxl-radius-sm, 4px);
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: start;
    cursor: pointer;
}

.nxl-ee-item:hover,
.nxl-ee-item:focus-visible {
    background: color-mix(in srgb, var(--dxds-color-content-primary-default-rest) 10%, transparent);
    outline: none;
}

.nxl-ee-item-head {
    display: flex;
    gap: 8px;
    align-items: baseline;
    min-width: 0;
}

.nxl-ee-item-label {
    font-family: var(--nxl-code-font, ui-monospace, Consolas, monospace);
    font-size: 0.8125rem;
    overflow-wrap: anywhere;
}

.nxl-ee-item-detail {
    margin-left: auto;
    color: var(--dxds-color-content-neutral-subdued-rest);
    font-size: 0.75rem;
}

.nxl-ee-item-doc {
    color: var(--dxds-color-content-neutral-subdued-rest);
    font-size: 0.75rem;
}
