/* 04_VISUAL/xwui/xwui-lib/xwui-lib-basic/src/forms/XWUIRichBody/XWUIRichBody.css */
/*
 * Tokens only. Every px value lives in a custom-property definition, so a page retunes the body with
 * `.page .xwui-rich-body { --xwui-rich-body-gap: ... }` (a doubled chain, because the component sheet loads after the
 * page's). Direction: logical properties only, so RTL mirrors with no extra rule; each block carries dir="auto" and takes
 * the direction of its own first strong letter.
 */

/* WHY :where(): zero specificity for the structural rules, so a page utility on the same element wins. */
:where(.xwui-rich-body) {
  --xwui-rich-body-font: 14px;
  --xwui-rich-body-line: 1.7;
  --xwui-rich-body-gap: 12px;
  --xwui-rich-body-min-height: 96px;
  --xwui-rich-body-pad-block: 0;
  --xwui-rich-body-pad-inline: 0;
  --xwui-rich-body-list-indent: 1.5em;
  --xwui-rich-body-focus-w: 2px;
  --xwui-rich-body-focus-offset: 2px;
  --xwui-rich-body-ink: var(--text-secondary, inherit);
  --xwui-rich-body-placeholder: var(--text-tertiary, inherit);
  --xwui-rich-body-link: var(--control-active, var(--accent-primary, currentcolor));
  --xwui-rich-body-radius: var(--radius-sm, 6px);

  position: relative;
  display: block;
  box-sizing: border-box;
  min-inline-size: 0;
  font-size: var(--xwui-rich-body-font);
  line-height: var(--xwui-rich-body-line);
  color: var(--xwui-rich-body-ink);
}

.xwui-rich-body .xwui-rich-body__surface {
  box-sizing: border-box;
  min-block-size: var(--xwui-rich-body-min-height);
  padding-block: var(--xwui-rich-body-pad-block);
  padding-inline: var(--xwui-rich-body-pad-inline);
  margin: 0;
  border: 0;
  border-radius: var(--xwui-rich-body-radius);
  background: transparent;
  color: inherit;
  font: inherit;
  /* pre-wrap: the surface's text nodes map one to one to the model, so spaces must be real spaces, not collapsed. */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: normal;
  outline: none;
  cursor: text;
}
.xwui-rich-body .xwui-rich-body__surface[contenteditable="false"] {
  cursor: default;
}

.xwui-rich-body .xwui-rich-body__surface:focus-visible {
  outline: var(--xwui-rich-body-focus-w) solid var(--control-active, currentcolor);
  outline-offset: var(--xwui-rich-body-focus-offset);
}

/* ---------- blocks ---------- */
.xwui-rich-body .xwui-rich-body__surface p {
  margin: 0;
}
.xwui-rich-body .xwui-rich-body__surface p + p,
.xwui-rich-body .xwui-rich-body__surface p + ul,
.xwui-rich-body .xwui-rich-body__surface p + ol,
.xwui-rich-body .xwui-rich-body__surface ul + p,
.xwui-rich-body .xwui-rich-body__surface ol + p,
.xwui-rich-body .xwui-rich-body__surface ul + ul,
.xwui-rich-body .xwui-rich-body__surface ul + ol,
.xwui-rich-body .xwui-rich-body__surface ol + ul,
.xwui-rich-body .xwui-rich-body__surface ol + ol {
  margin-block-start: var(--xwui-rich-body-gap);
}
.xwui-rich-body .xwui-rich-body__surface ul,
.xwui-rich-body .xwui-rich-body__surface ol {
  margin: 0;
  padding-block: 0;
  padding-inline: var(--xwui-rich-body-list-indent) 0;
}
.xwui-rich-body .xwui-rich-body__surface ul {
  list-style: disc;
}
.xwui-rich-body .xwui-rich-body__surface ol {
  list-style: decimal;
}
.xwui-rich-body .xwui-rich-body__surface li {
  margin: 0;
}

/* ---------- marks ---------- */
.xwui-rich-body .xwui-rich-body__surface b,
.xwui-rich-body .xwui-rich-body__surface strong {
  font-weight: 700;
}
.xwui-rich-body .xwui-rich-body__surface i,
.xwui-rich-body .xwui-rich-body__surface em {
  font-style: italic;
}
.xwui-rich-body .xwui-rich-body__surface u {
  text-decoration: underline;
}
.xwui-rich-body .xwui-rich-body__surface a {
  color: var(--xwui-rich-body-link);
  text-decoration: underline;
  cursor: text;
}

/* ---------- placeholder: laid over the empty first line, never part of the text ---------- */
.xwui-rich-body .xwui-rich-body__placeholder {
  position: absolute;
  inset-block-start: var(--xwui-rich-body-pad-block);
  inset-inline: var(--xwui-rich-body-pad-inline);
  color: var(--xwui-rich-body-placeholder);
  pointer-events: none;
  -webkit-user-select: none;
          user-select: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* High-contrast mode drops author colours: keep the focus ring and the links visible. */
@media (forced-colors: active) {
  .xwui-rich-body .xwui-rich-body__surface:focus-visible {
    outline-color: Highlight;
  }
  .xwui-rich-body .xwui-rich-body__surface a {
    color: LinkText;
  }
  .xwui-rich-body .xwui-rich-body__placeholder {
    color: GrayText;
  }
}
