/*
 * CONTENT BLOCK TEXT (cb_text)
 * Rich text of the RTE: headings, paragraphs, lists, links, quotes and tables.
 * The typography (sizes, weights, line heights) is defined in base.css.
 * Line length is limited for readability, vertical rhythm by the gap between the RTE elements.
 * The gaps are steps of the spacing scale (variables.css, _redesign/Abstaende.md), independent of the font size (rem,
 * not em): between paragraphs and lists 1rem, before an h2 large like between two content elements. Smaller headlines
 * (h3-h6, e.g. the criteria) are in the line height of the text, 2rem after the previous block and 0.5rem before
 * their text.
 */

.cb-text {
    --cb-text--flow           : var(--space--s);
    --cb-text--flow--headline : var(--space--xs);
    --cb-text--flow--section  : var(--content-element--gap--large);

    max-width: var(--content-element--measure);
}

.cb-text > * + * {
    margin-top: var(--cb-text--flow);
}

/*
 * Narrow text (mobile, aside, check lists in sections with 172px text width at 320px): long words are hyphenated, so
 * compound words like "Gewinnerzielungsabsicht" don't overflow (WCAG 1.4.10). The wide main column stays unhyphenated.
 */
@container content-element (max-width: 30rem) {
    .cb-text {
        hyphens: auto;
    }
}

.cb-text > :is(h2, h3, h4, h5, h6) + * {
    margin-top: var(--cb-text--flow--headline);
}

.cb-text > * + h2 {
    margin-top: var(--cb-text--flow--section);
}

.cb-text > * + :is(h3, h4, h5, h6) {
    margin-top: var(--space--m);
}

.cb-text > :is(h3, h4, h5, h6) {
    line-height: var(--line-height--text);
}


/* PARAGRAPHS: in the normal text size, the RTE style "Kleintext" (p.text--small) for small text (design A2) */

.cb-text p {
    font-size: var(--font-size--text);
    line-height: var(--line-height--text);
}

.cb-text p.text--small {
    font-size: var(--font-size--text-small);
    line-height: var(--line-height--text-small);
}


/* LINKS: underlined, as they must not be identified by color only (except the button link classes, see base.css) */

.cb-text a:not(.btn) {
    text-decoration: underline;
    text-underline-offset: .2em;
}


/* LISTS: in the normal text size like the paragraphs, indent 2.5rem, nested lists 2rem */

.cb-text :is(ul, ol) {
    padding-left: var(--space--l);
}

.cb-text li :is(ul, ol) {
    padding-left: var(--space--m);
}

.cb-text li {
    font-size: var(--font-size--text);
    line-height: var(--line-height--text);
}

/*
 * Items of bullet lists follow each other like lines of a paragraph (design), the list styles and ordered lists below
 * have the paragraph gap.
 * Blocks inside list items only: a margin of inline elements (e.g. <br> after <strong>) moves the line in Firefox.
 */
.cb-text li > :is(ul, ol),
.cb-text li > :is(p, blockquote, figure) + :is(p, blockquote, figure) {
    margin-top: var(--space--xs);
}


/*
 * LIST STYLES of the RTE (style dropdown, see Configuration/RTE/Default.yaml): check marks for requirements and
 * criteria, crosses for exclusions, icons of the icon set (1.5em, a bit larger than the line of 1.4em, at most 2rem) as
 * mask in the text color at the first line. The text is indented by 2.5rem like all lists, so the icon has at least
 * 0.5rem gap.
 * The icon is at the top of the item, the first line is centered to it by the padding of the item: independent of
 * the first element (text, strong, p), as the line height of the list items is known (--line-height--text).
 * Only the items of the styled list, nested lists keep their bullets. The icons are decorative, the meaning has to be
 * given by the text (e.g. "Nicht gefördert werden:" above the list with crosses).
 */

.cb-text ul:is(.list--check, .list--cross) {
    --cb-text--list-icon: var(--icon--check);
    --cb-text--list-icon-size: min(1.5em, var(--space--m));

    padding-left: 0;
    list-style: none;
}

.cb-text ul.list--cross {
    --cb-text--list-icon: var(--icon--cancel);
}

.cb-text ul:is(.list--check, .list--cross) > li {
    position: relative;
    min-height: var(--cb-text--list-icon-size);
    padding-top: calc((var(--cb-text--list-icon-size) - var(--line-height--text) * 1em) / 2);
    padding-left: var(--space--l);
}

.cb-text ul:is(.list--check, .list--cross) > li + li {
    margin-top: var(--cb-text--flow);
}

.cb-text ul:is(.list--check, .list--cross) > li::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: var(--cb-text--list-icon-size);
    height: var(--cb-text--list-icon-size);
    background-color: currentColor;
    mask: var(--cb-text--list-icon) center / contain no-repeat;
}

/* Backgrounds are replaced in forced colors mode, keep the icons in the text color */
@media (forced-colors: active) {
    .cb-text ul:is(.list--check, .list--cross) > li::before {
        forced-color-adjust: none;
        background-color: CanvasText;
    }
}


/*
 * ORDERED LISTS: the number in a circle without the dot, in the position of the icons of the list styles above, but
 * larger (2em, at most 2rem) for the number, the text indented by 2.5rem. No style of the RTE, all ordered lists. The counter "list-item" is the one of the
 * browser, so the attributes start, value and reversed of the RTE are kept.
 */

.cb-text ol {
    --cb-text--list-icon-size: min(2em, var(--space--m));

    padding-left: 0;
    list-style: none;
}

.cb-text ol > li {
    position: relative;
    min-height: var(--cb-text--list-icon-size);
    padding-top: calc((var(--cb-text--list-icon-size) - var(--line-height--text) * 1em) / 2);
    padding-left: var(--space--l);
}

.cb-text ol > li + li {
    margin-top: var(--cb-text--flow);
}

/* Empty alternative text, the list announces the position */
.cb-text ol > li::before {
    content: counter(list-item);
    content: counter(list-item) / "";

    position: absolute;
    top: 0;
    left: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--cb-text--list-icon-size);
    height: var(--cb-text--list-icon-size);
    border: var(--border-width--default) solid currentColor;
    border-radius: var(--border-radius--round);
    line-height: var(--line-height--single);
    font-variant-numeric: tabular-nums;
}


/* QUOTES */

.cb-text blockquote {
    padding-left: var(--space--s);
    border-left: 4px solid currentColor;
}


/* TABLES: scroll horizontally on small widths instead of overflowing the page */

.cb-text figure.table {
    overflow-x: auto;
}

.cb-text table {
    width: 100%;
    border-collapse: collapse;
}

.cb-text :is(th, td) {
    padding: var(--space--xs);
    border: 1px solid currentColor;
    text-align: left;
    vertical-align: top;
}
