/* Shared styling for the RML WYSIWYG editing surface and the annotation chips rendered inside it.

   These rules used to live in RmlDesigner.razor.css, but Blazor CSS isolation scoped them to the
   RmlDesigner component. The list item editor (RmlItemReportEditor, mounted from the Properties
   panel) renders the same Telerik editor and the same RmlHtmlConverter output, and a hand-copied
   subset drifted out of step. Everything keyed on .rml-wysiwyg-editor is global so both surfaces
   look identical. Component chrome (toolbar, status, pickers) stays in the isolated files. */

.rml-wysiwyg-editor {
    /* Telerik writes the Height parameter as an inline style, so the height itself comes from
       Height="100%" on the TelerikEditor; this only covers the brief window before that is applied. */
    height: 100%;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* The editor body is the ONLY thing that scrolls, so the toolbar above it stays put. */
.rml-wysiwyg-editor .k-editor-content {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    /* The first section band (HEADER) sits flush against the top of the content area, and its 1px
       border plus padding was being clipped by the formatting bar directly above. A little breathing
       room at the top of the scroll container lets the badge render whole. */
    padding-top: 6px;
}

/* Formatting bar collapsed. Hiding Telerik's generated toolbar with CSS keeps the editor instance
   (and therefore the ProseMirror document, selection and undo stack) completely untouched —
   removing the tools from the Tools list instead would re-render and reset it.
   Both classes are matched: the element carries the generic .k-toolbar base class plus the
   editor-specific .k-editor-toolbar, and which one is present has varied across theme versions.
   Three classes deep, so it outranks the theme's single-class .k-toolbar display rule. */
.rml-formatting-hidden .rml-wysiwyg-editor .k-editor-toolbar,
.rml-formatting-hidden .rml-wysiwyg-editor .k-toolbar {
    display: none;
}

/* The editing surface has a hardcoded white background, but its text colour is INHERITED from the
   page. In dark mode that inherits white, so both the text and the blinking caret became white on
   white and the caret was invisible. Pin the colour to the surface rather than the page theme, and
   set caret-color explicitly so it is never washed out. */
.rml-wysiwyg-editor .k-editor-content,
.rml-wysiwyg-editor .k-editor-content .ProseMirror,
.rml-wysiwyg-editor .k-editor-content [contenteditable="true"] {
    color: #1f2328;
    caret-color: #1f2328;
    background: #fff;
}

/* A thicker caret is easier to spot amongst the annotation chips. */
.rml-wysiwyg-editor .k-editor-content .ProseMirror:focus,
.rml-wysiwyg-editor .k-editor-content [contenteditable="true"]:focus {
    outline: none;
    caret-color: #0d6efd;
}


/* ========================================
   Annotation chips
   ======================================== */

.rml-wysiwyg-editor .rml-annotation {
    display: inline-block;
    padding: 2px 6px;
    margin: 0 2px;
    border-radius: 3px;
    font-size: inherit;
    line-height: inherit;
    cursor: pointer;
    /* "all" rather than "none": the chip is still indivisible (it can only ever be selected whole),
       but unlike "none" the browser actually paints the selection highlight over it, so dragging
       across a worksheet value / template / report value visibly includes it. */
    user-select: all;
    -webkit-user-select: all;
    vertical-align: baseline;
    border: 1px solid transparent;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    /* Belt-and-braces with the JS repair pass: the editor strips contenteditable="false" on parse, and
       between the strip and the repair the caret could otherwise land inside a chip and split it. */
    -webkit-user-modify: read-only;
    white-space: nowrap;
}

/* A chip is a single atomic token — never a container the user can type into. */
.rml-wysiwyg-editor .rml-annotation * {
    user-select: all;
    -webkit-user-select: all;
}

/* The chip backgrounds are strongly tinted, so the default selection colour can disappear against
   them. Forcing an opaque highlight keeps "is this chip included in my selection?" unambiguous. */
.rml-wysiwyg-editor .rml-annotation::selection,
.rml-wysiwyg-editor .rml-annotation *::selection {
    background: #1976d2;
    color: #fff;
}

.rml-wysiwyg-editor .rml-annotation:hover {
    border-color: rgba(0, 0, 0, 0.2);
}

/* The selected-chip highlight is declared after the per-type tints below, which set their own
   border colours at the same specificity. */

/* The output field is an EDITABLE CONTAINER, not a chip: the user types the value inside it and that
   content is what serialises into rmlSonoOutputField.SonoElements and reaches PowerScribe.

   It carries .rml-annotation so click/selection still finds it, but that rule makes chips atomic
   (user-select:none, -webkit-user-modify:read-only, white-space:nowrap, display:inline-block). Those
   are exactly what stopped text being typed or dropped inside the field, so they are all reversed
   here. Only the ::before/::after bracket decoration stays unselectable. */
.rml-wysiwyg-editor .rml-output-field {
    background: #e8f5e9;
    color: #2e7d32;
    font-weight: 600;
    display: inline;
    user-select: text;
    -webkit-user-select: text;
    -webkit-user-modify: read-write;
    white-space: normal;
    cursor: text;
    /* An empty field must stay wide enough to click into, otherwise it collapses to zero width and the
       caret can never be placed inside it. Mirrors SonoReview's CheckOutputFieldSpace guard. */
    min-width: 1ch;
}

/* Undo the blanket ".rml-annotation *" selection lock for the field's contents, so worksheet values
   and conditional runs nested inside an output field stay interactive. */
.rml-wysiwyg-editor .rml-output-field * {
    user-select: text;
    -webkit-user-select: text;
}

/* Nested chips (an inserted worksheet value inside a combo-bound output field) must remain atomic —
   they are still chips even though their container is editable. */
.rml-wysiwyg-editor .rml-output-field .rml-annotation {
    user-select: all;
    -webkit-user-select: all;
    -webkit-user-modify: read-only;
}

/* Brackets are drawn as generated content rather than emitted as text, because any literal "[Name]"
   inside an editable region is indistinguishable from something the user typed and would be
   re-parsed into the document on every round-trip. */
.rml-wysiwyg-editor .rml-output-field::before,
.rml-wysiwyg-editor .rml-output-field::after {
    color: #2e7d32;
    opacity: 0.7;
    font-weight: 700;
    user-select: none;
    -webkit-user-select: none;
    -webkit-user-modify: read-only;
}

.rml-wysiwyg-editor .rml-output-field::before {
    content: "[";
}

.rml-wysiwyg-editor .rml-output-field::after {
    content: "]";
}

/* Output field variants. The type drives entirely different runtime behaviour (a combo resolves a
   pick list, a merge pulls an external value), so they are tinted apart rather than all reading as
   an identical green [Name] chip. */
.rml-wysiwyg-editor .rml-output-field.rmloftype-combo {
    background: #e3f2fd;
    color: #1565c0;
    border-color: rgba(21, 101, 192, 0.25);
}

.rml-wysiwyg-editor .rml-output-field.rmloftype-merge {
    background: #f3e5f5;
    color: #6a1b9a;
    border-color: rgba(106, 27, 154, 0.25);
}

.rml-wysiwyg-editor .rml-input-field {
    background: #fff3e0;
    /* Darker than Material orange 900 (#e65100, 3.4:1) so the chip label meets WCAG AA 4.5:1 on its tint. */
    color: #b34000;
    font-weight: 600;
}

.rml-wysiwyg-editor .rml-list {
    background: #e3f2fd;
    color: #1565c0;
    font-weight: 600;
}

.rml-wysiwyg-editor .rml-multi {
    background: #f3e5f5;
    color: #7b1fa2;
    font-weight: 600;
}

/* Selected chip. Matches the specificity of :hover and the combo/merge tints (two classes plus the
   so selection wins by source order.
   The class is only ever added to .rml-annotation elements (rmlDesignerInterop.highlightAnnotation). */
.rml-wysiwyg-editor .rml-annotation.rml-annotation-selected {
    border-color: #1976d2;
    box-shadow: 0 0 0 2px rgba(25, 118, 210, 0.3);
}

.rml-wysiwyg-editor .rml-image {
    background: #fce4ec;
    color: #c62828;
    font-weight: 600;
}

.rml-wysiwyg-editor .rml-template {
    background: #e0f2f1;
    color: #00695c;
    font-weight: 600;
}


/* ========================================
   Condition wraps
   ======================================== */

/* A conditioned TEMPLATE expands to block-level content in the preview, so its wrap is emitted as a
   <div> rather than the inline <span> used for a conditioned run of text (block content inside an
   inline element gets unwrapped by the browser, orphaning the highlight). Same visual language, but
   laid out as a block so the whole imported template reads as conditional — matching the runtime,
   where ImportTemplatesPhrase composes the condition into every phrase it imports. */
.rml-wysiwyg-editor div.rml-condition-wrap {
    display: block;
    padding: 2px 6px;
    margin: 2px 0;
    border-left: 3px solid rgba(0, 180, 0, 0.5);
    border-bottom: none;
}

.rml-wysiwyg-editor div.rml-condition-wrap.rml-condition-collapse {
    border-left-style: dashed;
}

/* The green condition tint sits under the selection highlight; force the same opaque highlight so
   conditional runs read as selected rather than merely green. */
.rml-wysiwyg-editor .rml-condition-wrap::selection,
.rml-wysiwyg-editor .rml-condition-wrap *::selection {
    background: #1976d2;
    color: #fff;
}

/* Condition Wrap Overlay (green translucent, matching WPF SonoReportDesignerHighlightLayer) */
.rml-wysiwyg-editor .rml-condition-wrap {
    background: rgba(0, 200, 0, 0.08);
    border-bottom: 2px solid rgba(0, 180, 0, 0.5);
    border-radius: 2px;
    position: relative;
    cursor: pointer;
    transition: background 0.15s ease;
}

.rml-wysiwyg-editor .rml-condition-wrap:hover {
    background: rgba(0, 200, 0, 0.16);
}

.rml-wysiwyg-editor .rml-condition-wrap.rml-condition-selected {
    background: #8dff6b;
    box-shadow: 0 0 0 2px #39c43f, 0 0 10px 2px rgba(80, 230, 90, 0.75);
    border-bottom-color: #39c43f;
    border-radius: 2px;
}

.rml-wysiwyg-editor .rml-condition-wrap.rml-condition-selected,
.rml-wysiwyg-editor .rml-condition-wrap.rml-condition-selected * {
    color: #10310f;
}

.rml-wysiwyg-editor div.rml-condition-wrap.rml-condition-selected {
    border-left-color: #39c43f;
}

.rml-wysiwyg-editor .rml-condition-wrap.rml-condition-selected:hover {
    background: #7cff55;
}

/* The name label is hover-only by default; for the selected region it stays up so the user can
   see which condition they are editing without keeping the pointer in place. It is also given the
   ring's colouring so the label and the region read as one marked unit rather than two greens. */
.rml-wysiwyg-editor .rml-condition-wrap.rml-condition-selected::after {
    opacity: 1;
    color: #fff;
    background: #1b6b20;
    font-weight: 700;
}

.rml-wysiwyg-editor .rml-condition-wrap::after {
    content: attr(data-rml-condition-name);
    position: absolute;
    top: -18px;
    left: 0;
    font-size: 9px;
    color: #2e7d32;
    background: rgba(232, 245, 233, 0.95);
    padding: 1px 4px;
    border-radius: 2px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.rml-wysiwyg-editor .rml-condition-wrap:hover::after {
    opacity: 1;
}

/* Annotation chips that carry a condition (dashed green outline + branch marker) */
.rml-wysiwyg-editor .rml-has-condition {
    box-shadow: inset 0 -2px 0 rgba(60, 200, 70, 0.9);
}

.rml-wysiwyg-editor .rml-has-condition::before {
    content: "\f126"; /* fa-code-branch */
    /* sans-serif terminates the stack so the glyph still degrades to a system font if no Font Awesome
       version is loaded, rather than falling back to the browser's unspecified default. */
    font-family: "Font Awesome 6 Free", "Font Awesome 5 Free", FontAwesome, sans-serif;
    font-weight: 900;
    font-size: 9px;
    color: #2e7d32;
    margin-right: 3px;
    vertical-align: baseline;
}

/* A wrap set to collapse when inactive reads as a dashed edge, distinguishing it from one that
   merely blanks out. */
.rml-wysiwyg-editor .rml-condition-wrap.rml-condition-collapse {
    border-bottom-style: dashed;
}


/* ========================================
   Report sections (header / body / footer)
   ======================================== */

/* SonoReview draws each section as a labelled, shaded region (SonoReportDesignerHighlightLayer
   UpdateSectionHighlight → "Header"/"Body"/"Footer"). KailoFlow cannot draw a box AROUND content
   inside ProseMirror — the divider is a sibling of the content, not a parent — so the same reading
   is achieved with a labelled band that starts each region, rather than a bare dashed rule that
   only said "something changes here" without saying what. */
.rml-wysiwyg-editor .rml-section {
    user-select: none;
    pointer-events: none;
    margin: 18px 0 0 0;
    padding: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.rml-wysiwyg-editor .rml-section:first-child {
    /* Not zero: a flush-top badge gets its border clipped against the edge of the scroll container. */
    margin-top: 2px;
}

/* The label text is generated, never a real text node, so it can never reach the saved RML. */
.rml-wysiwyg-editor .rml-section-label {
    display: inline-block;
    flex-shrink: 0;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.9px;
    text-transform: uppercase;
    /* 9px counts as small text, so it needs the full 4.5:1. The previous #7a7a7a managed only ~3.4:1
       on this band; #595959 clears it at ~5.3:1 while still reading as a muted, secondary label
       against the tinted body variant below. */
    color: #595959;
    background: #f0f0f0;
    border: 1px solid #e0e0e0;
    border-radius: 3px;
    padding: 2px 8px;
    line-height: 1.4;
}

/* Rule to the right of the label, completing the band across the page. */
.rml-wysiwyg-editor .rml-section::after {
    content: "";
    flex: 1;
    height: 1px;
    background: #e0e0e0;
}

.rml-wysiwyg-editor .rml-section.rmlsection-header .rml-section-label::before { content: "Header"; }
.rml-wysiwyg-editor .rml-section.rmlsection-body .rml-section-label::before { content: "Body"; }
.rml-wysiwyg-editor .rml-section.rmlsection-footer .rml-section-label::before { content: "Footer"; }

/* Body is the section authors spend nearly all their time in, so it is the one tinted. */
.rml-wysiwyg-editor .rml-section.rmlsection-body .rml-section-label {
    color: #0f6cbd;
    background: #eaf3fb;
    border-color: #cfe4f7;
}

[data-theme="dark"] .rml-wysiwyg-editor .rml-section-label {
    color: #bbb;
    background: #2d2d2d;
    border-color: #444;
}

[data-theme="dark"] .rml-wysiwyg-editor .rml-section::after {
    background: #444;
}

[data-theme="dark"] .rml-wysiwyg-editor .rml-section.rmlsection-body .rml-section-label {
    color: #69bae4;
    background: #14364f;
    border-color: #1d4a6b;
}
