/* 04_VISUAL/xwui/xwui-lib/xwui-lib-basic/src/text/XWUISandboxedHtml/XWUISandboxedHtml.css */
/*
 * Tokens only. The message itself is drawn INSIDE the iframe from a stylesheet the component writes into the srcdoc
 * (colours read from this host at mount), so nothing here styles message content. What this sheet owns is the box: its
 * height rule, the frame, the plain-text fallback and the visually hidden text twin.
 *
 * Height: the frame is an opaque origin (sandbox with no flags), so its document height cannot be measured from here.
 * A number maxHeight is therefore a fixed height with an internal scroll; `auto` fills the container (give the
 * container a height) and never goes below --xwui-sandboxed-html-min-height. A page retunes either with
 * `.page .xwui-sandboxed-html { --xwui-sandboxed-html-min-height: ... }` (a doubled chain, library sheets load later).
 * Direction: logical properties only; the frame carries its own dir in the srcdoc.
 */

/* WHY :where(): zero specificity for the structural rules, so a page utility on the same element wins. */
:where(.xwui-sandboxed-html) {
  --xwui-sandboxed-html-unit: 1px;
  --xwui-sandboxed-html-min-height: 12rem;
  --xwui-sandboxed-html-max: 0;
  --xwui-sandboxed-html-hidden-size: 1px;
  --xwui-sandboxed-html-hidden-pull: -1px;

  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  position: relative;
  inline-size: 100%;
  min-inline-size: 0;
  margin: 0;
  padding: 0;
  color: inherit;
}

.xwui-sandboxed-html[data-height="auto"] {
  block-size: 100%;
  min-block-size: var(--xwui-sandboxed-html-min-height);
}
.xwui-sandboxed-html[data-height="fixed"] {
  block-size: calc(var(--xwui-sandboxed-html-max) * var(--xwui-sandboxed-html-unit));
}
/* Text and empty states size to their content: only the frame needs a given height. */
.xwui-sandboxed-html[data-mode="text"],
.xwui-sandboxed-html[data-mode="empty"] {
  block-size: auto;
  min-block-size: 0;
}

.xwui-sandboxed-html .xwui-sandboxed-html__frame {
  display: block;
  flex: 1 1 auto;
  inline-size: 100%;
  min-block-size: 0;
  border: 0;
  margin: 0;
  padding: 0;
  background: transparent;
}
.xwui-sandboxed-html[data-height="auto"] .xwui-sandboxed-html__frame {
  min-block-size: var(--xwui-sandboxed-html-min-height);
}

/* ---------- plain-text fallback (doubled chains: the typography sheet loads after ours) ---------- */
.xwui-sandboxed-html .xwui-sandboxed-html__text {
  min-inline-size: 0;
}
.xwui-sandboxed-html .xwui-sandboxed-html__text .xwui-sandboxed-html__text-body,
.xwui-sandboxed-html .xwui-sandboxed-html__text .xwui-typography {
  margin: 0;
  color: inherit;
  font: inherit;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ---------- the text twin: present for assistive tech, invisible to everyone else ---------- */
.xwui-sandboxed-html .xwui-sandboxed-html__twin {
  position: absolute;
  inline-size: var(--xwui-sandboxed-html-hidden-size);
  block-size: var(--xwui-sandboxed-html-hidden-size);
  margin: var(--xwui-sandboxed-html-hidden-pull);
  padding: 0;
  border: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* A frame that failed its sandbox check is withheld by the adapter; this keeps an empty box from reading as content. */
.xwui-sandboxed-html .xwui-sandboxed-html__frame[data-sandbox-violation] {
  display: none;
}
