/* ==========================================================================
   Typography
   --------------------------------------------------------------------------
   01. Headings: all levels look the same, size via .fs-* (RTE "Schriftgröße")
   02. Eyebrow / lead
   03. Rich text (.richtext): everything the RTE can produce
       (Configuration/RTE/Default.yaml). Backend look: Backend/Css/rte.css
   ========================================================================== */


/* ==========================================================================
   01. HEADINGS
   Every level (h1–h6) has the same look: Roboto Serif, --fs-heading (50px).
   The level is only the meaning (document outline for SEO / screen readers),
   the size is chosen in the RTE dropdown "Schriftgröße":
   <h3><span class="fs-m">…</span></h3>. The heading takes the size of that
   span (:has), so line height and spacing fit the chosen size.
   :where() so components (e.g. header slider) can override them.
   ========================================================================== */
:where(h1, h2, h3, h4, h5, h6) {
  font-family: var(--ff-heading);
  font-size: var(--fs-heading);
  font-weight: var(--fw-regular);
  line-height: var(--lh-heading);
  text-wrap: balance;
  overflow-wrap: break-word;
  hyphens: manual;
}

/* Heading sizes only work in headings (outside: no effect) */
:is(h1, h2, h3, h4, h5, h6):has(.fs-m) { font-size: var(--fs-m); }
:is(h1, h2, h3, h4, h5, h6):has(.fs-l) { font-size: var(--fs-l); }
:is(h1, h2, h3, h4, h5, h6):has(.fs-xl) { font-size: var(--fs-xl); }
:is(h1, h2, h3, h4, h5, h6):has(.fs-xxl) { font-size: var(--fs-xxl); }
:is(h1, h2, h3, h4, h5, h6) [class^="fs-"] { font-size: 1em; }

/* Long German compound words: only hyphenate where the screen is narrow */
@media (max-width: 47.99rem) {
  :where(h1, h2, h3, h4, h5, h6) {
    hyphens: auto;
    hyphenate-limit-chars: 10 4 4;
  }
}


/* ==========================================================================
   02. EYEBROW / LEAD
   ========================================================================== */
/* Small line above a heading (field "Dachzeile") */
.eyebrow {
  display: flex;
  align-items: center;
  gap: 0.75em;
  font-size: var(--fs-small);
  font-weight: var(--fw-medium);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.eyebrow::before {
  content: "";
  flex-shrink: 0;
  width: 2rem;
  height: 2px;
  background: var(--c-primary);
}

/* Follows the alignment of the next line (heading centered in the RTE = eyebrow centered) */
.eyebrow:has(+ .text-center) { justify-content: center; }
.eyebrow:has(+ .text-end) { justify-content: flex-end; }


/* ==========================================================================
   03. RICH TEXT
   .richtext           wrapper of RTE content
   ========================================================================== */
.richtext {
  --flow: 1em;
  --line: color-mix(in srgb, currentColor 18%, transparent);   /* hairlines on any background */
  overflow-wrap: break-word;
}

/* ---- Flow: space between blocks ---- */
.richtext > * + *,
.bodytext-columns-col > * + * { margin-top: var(--flow); }

.richtext > * + :is(h1, h2, h3, h4, h5, h6),
.bodytext-columns-col > * + :is(h1, h2, h3, h4, h5, h6) { margin-top: max(1.5rem, 0.9em); }

.richtext > :is(h1, h2, h3, h4, h5, h6) + *,
.bodytext-columns-col > :is(h1, h2, h3, h4, h5, h6) + * { margin-top: clamp(0.75rem, 1.5vw, 1.25rem); }

/* Eyebrow belongs to the heading below it */
.richtext > .eyebrow + :is(h1, h2, h3, h4, h5, h6) { margin-top: 0.625rem; }

/* Tables and columns: more space, they are blocks of their own */
.richtext > * + :is(figure.table, .bodytext-columns),
.richtext > :is(figure.table, .bodytext-columns) + * { margin-top: max(1.5rem, 1.5em); }

/* Buttons: more space above, like the layout */
.richtext > * + p:has(> :is(.link-button, .link-arrow)) { margin-top: clamp(1.5rem, 3vw, 2.5rem); }

/* Line length of running text: ~90 characters by default.
   Options of the element (textmedia "Textbreite"): .richtext--readable (~70), .richtext--full */
.richtext > :is(p, ul, ol, blockquote) { max-width: var(--measure-wide); }
.richtext--readable > :is(p, ul, ol, blockquote) { max-width: var(--measure); }
.richtext--full > :is(p, ul, ol, blockquote) { max-width: none; }

/* ---- Links ---- */
.richtext a:not([class]) {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  transition: text-decoration-thickness var(--transition), color var(--transition);
}
.richtext a:not([class]):hover { text-decoration-thickness: 2px; }

/* Row of buttons (one paragraph, several "Button" links) */
.richtext p:has(> .link-button) {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
}
.richtext p.text-center:has(> .link-button) { justify-content: center; }
.richtext p.text-end:has(> .link-button) { justify-content: flex-end; }

/* Text link with arrow (RTE style "Link mit Pfeil") */
.link-arrow {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  font-weight: var(--fw-medium);
  text-decoration: none;
}
.link-arrow::after {
  content: "";
  flex-shrink: 0;
  width: 1.25em;
  height: 1.25em;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M4 12h15m-5-5 5 5-5 5' fill='none' stroke='black' stroke-width='1.75'/></svg>") center / contain no-repeat;
  mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M4 12h15m-5-5 5 5-5 5' fill='none' stroke='black' stroke-width='1.75'/></svg>") center / contain no-repeat;
  transition: translate var(--transition);
}
.link-arrow:hover::after { translate: 0.25em 0; }
/* Colored link text (RTE "Schriftfarbe"): CKEditor puts the color on a span inside the link,
   the arrow belongs to the link. The link takes the color of that span, so the arrow matches.
   Colors of the picker. */
.link-arrow:has([style*="--c-primary"]) { color: var(--c-primary); }
.link-arrow:has([style*="--c-secondary"]) { color: var(--c-secondary); }
.link-arrow:has([style*="--c-tertiary"]) { color: var(--c-tertiary); }

/* ---- Lists ---- */
.richtext li + li { margin-top: 0.35em; }
.richtext ul:not(.check-list) > li::marker { color: var(--c-primary); }
.richtext ol > li::marker { font-variant-numeric: tabular-nums; }
.richtext li > :is(ul, ol) { margin-top: 0.35em; }

/* RTE style "Checkbox Liste" */
.richtext ul.check-list {
  padding-inline-start: 0;
  list-style: none;
}
.richtext ul.check-list > li {
  position: relative;
  padding-inline-start: 2em;
}
.richtext ul.check-list > li::before {
  content: "";
  position: absolute;
  top: calc((1lh - 1.25em) / 2);
  left: 0;
  width: 1.25em;
  height: 1.25em;
  background: var(--c-primary);
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='m5 12.5 4.5 4.5L19 7.5' fill='none' stroke='black' stroke-width='2'/></svg>") center / contain no-repeat;
  mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='m5 12.5 4.5 4.5L19 7.5' fill='none' stroke='black' stroke-width='2'/></svg>") center / contain no-repeat;
}

/* ---- Alignment (RTE buttons "Links / Zentriert / Rechts") ---- */
.richtext .text-start { text-align: start; }
.richtext .text-center { text-align: center; }
.richtext .text-end { text-align: end; }
.richtext > :is(p, h1, h2, h3, h4, h5, h6).text-center { margin-inline: auto; }
.richtext > p.text-end { margin-inline-start: auto; }

/* ---- Text size (RTE "Schriftgröße": Text klein 16px / groß 24px; heading sizes .fs-*: section 01)
        and color (RTE "Schriftfarbe") ---- */
.richtext .text-small { font-size: var(--fs-text-small); }
.richtext .text-big { font-size: var(--fs-lead); }
/* Text sizes only work in text, not in headings */
.richtext :is(h1, h2, h3, h4, h5, h6) :is(.text-small, .text-big) { font-size: inherit; }

/* RTE color picker ("Schriftfarbe"): the brand colors primary / secondary / tertiary (theme.css,
   Css/Brands/*.css), stored as var(--c-…) in the text. Note: light brand colors (e.g. Leibbrand
   orange 2.4:1, yellow 1.5:1) are below the WCAG contrast of 4.5:1 as text on white: best for
   large headings, accents or on the dark background. */

/* ---- Font (RTE "Schriftart"), for headings and text. Standard: headings serif, text sans ---- */
.ff-sans { font-family: var(--ff-base); }
.ff-serif { font-family: var(--ff-heading); }

/* ---- Quote, line, tables ---- */
.richtext blockquote {
  padding-inline-start: 1.25em;
  border-inline-start: 2px solid var(--c-primary);
  font-family: var(--ff-heading);
  font-size: var(--fs-lead);
}

/* ---- Info box (RTE style "Infobox" on paragraphs): larger light text between two lines ----
   Colors follow the background: text = text color of the section, a bit softer (dark grey on
   white, light grey on the dark background), lines = text color. Text colored completely with
   the RTE color picker: the lines take that color. Several info box paragraphs in a row = one box
   (lines only above the first and below the last). */
.richtext .info-box {
  padding-block: 0.875em;
  color: color-mix(in srgb, currentColor 80%, transparent);
  font-size: var(--fs-lead);
  font-weight: 300;
  line-height: 1.5;
  border-block: 1px solid currentColor;
}
.richtext > :not(.info-box) + .info-box { margin-top: calc(var(--flow) * 2); }
.richtext > .info-box + :not(.info-box) { margin-top: calc(var(--flow) * 2); }
.richtext .info-box + .info-box {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}
.richtext .info-box:has(+ .info-box) {
  padding-bottom: 0.5em;
  border-bottom: 0;
}
.richtext .info-box:has(> [style*="--c-primary"]:only-child) { border-color: var(--c-primary); }
.richtext .info-box:has(> [style*="--c-secondary"]:only-child) { border-color: var(--c-secondary); }
.richtext .info-box:has(> [style*="--c-tertiary"]:only-child) { border-color: var(--c-tertiary); }

/* Text sizes in the info box: one step below / above the box (24 px), not the general 16 / 24 px
   ("Text groß" would be the size of the box itself). Text klein 20 px, Text groß 28 px at 1360.
   Whole text in one size (also inside a color span): the box follows, so line spacing and the
   space to the lines fit the text */
.richtext .info-box .text-small { font-size: var(--fs-body); }
.richtext .info-box .text-big { font-size: var(--fs-m); }
.richtext .info-box:has(> .text-small:only-child, > :only-child > .text-small:only-child) { font-size: var(--fs-body); }
.richtext .info-box:has(> .text-big:only-child, > :only-child > .text-big:only-child) { font-size: var(--fs-m); }

/* ---- Number in a circle (RTE style "Nummer im Kreis" on selected text): steps of a process.
        PDF: 68 px circle, 36 px number at 1360 px (24 px number on phones). Two digits: wider (pill).
        Centered paragraph (RTE "Zentriert") = centered circle ---- */
.richtext .number-circle {
  display: inline-grid;
  place-items: center;
  box-sizing: border-box;
  min-width: 1.89em;
  height: 1.89em;
  padding-inline: 0.35em;
  border-radius: 999px;
  background: var(--c-badge);
  color: var(--c-white);
  font-family: var(--ff-base);
  font-size: clamp(1.5rem, 1.1rem + 1.35vw, 2.25rem);
  font-weight: var(--fw-regular);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  vertical-align: middle;
}

.richtext hr {
  margin-block: calc(var(--flow) * 2);
  border-top: 1px solid var(--line);
}

/* CKEditor wraps tables in <figure class="table">: scrolls sideways on small screens */
.richtext figure.table {
  overflow-x: auto;
  max-width: 100%;
}
.richtext table {
  width: 100%;
  font-size: 0.9375em;
  font-variant-numeric: tabular-nums;
}
.richtext :is(th, td) {
  padding: 0.65em 0.9em;
  border-bottom: 1px solid var(--line);
  text-align: start;
  vertical-align: top;
}
.richtext :is(th, td):first-child { padding-inline-start: 0; }
.richtext :is(th, td):last-child { padding-inline-end: 0; }
.richtext th { font-weight: var(--fw-medium); }
.richtext thead th { border-bottom: 2px solid currentColor; }
.richtext figure.table > figcaption {
  margin-top: 0.75em;
  font-size: var(--fs-small);
  opacity: 0.8;
}

/* ---- Columns (RTE button "Spalten", Backend/CKEditor/Plugins/columns) ----
   Text columns share the width (min. 16rem, then they wrap). A column with only a button
   (one paragraph with a "Button" / "Link mit Pfeil") is as wide as the button, so buttons
   in neighbouring columns sit next to each other like buttons in one line. */
.richtext .bodytext-columns {
  display: flex;
  flex-wrap: wrap;
  gap: var(--flow) clamp(1.5rem, 3vw, 3rem);
}
.richtext .bodytext-columns-col {
  flex: 1 1 0;
  min-width: min(16rem, 100%);
}
.richtext .bodytext-columns-col:has(> p:only-child > :is(.link-button, .link-arrow)) {
  flex: 0 0 auto;
  min-width: 0;
  max-width: 100%;
}
/* The button's min-width is "min(100%, …)": in a column as wide as its content, 100% would
   shrink it to the text. Here the column is sized by the button, so use the width directly. */
.richtext .bodytext-columns-col > p:only-child > .link-button { min-width: clamp(12rem, 18vw, 15.5rem); }
.richtext .bodytext-columns:has(> .bodytext-columns-col > p:only-child > :is(.link-button, .link-arrow)) {
  align-items: center;
  column-gap: 1rem;                                   /* like buttons in one line */
}
/* Buttons centered / right in the RTE: the button columns follow */
.richtext .bodytext-columns:has(> .bodytext-columns-col > p.text-center:only-child > :is(.link-button, .link-arrow)) { justify-content: center; }
.richtext .bodytext-columns:has(> .bodytext-columns-col > p.text-end:only-child > :is(.link-button, .link-arrow)) { justify-content: flex-end; }
