/* Stadt Leipzig corporate design — base overrides for third-party apps.
 *
 * theming-base-version: 1.2.0 (needs tokens.css 1.2.0 or later)
 *
 * The first layer of a theme for an app the city does not build itself
 * (LimeSurvey, Zammad, Moodle, Wiki.js, GitLab, Grafana …). It fixes what
 * every host gets wrong in the same way and leaves the app's own look to the
 * theme file that follows it. Procedure, per-app notes: references/theming.md.
 *
 * Load order (one <link> each, or concatenated in this order where the app
 * takes a single CSS field):
 *
 *     tokens.css            assets/tokens.css, unchanged
 *     base-overrides.css    this file, unchanged
 *     <app>-theme.css       your rules for the app's own classes, last
 *
 * Fonts: section 1 loads Leipzig Sans from ../fonts/web/ — keep `fonts/web/`
 * as a sibling of the folder that holds this file (the skill's layout, D93).
 * A url() resolves against the stylesheet the browser fetched, not the file
 * it was written in, so CONCATENATING this file into a bundle (branding.css)
 * or pasting it into an app's CSS field breaks the paths unless you either
 *   1. copy the fonts next to the bundle in the same layout: the bundle in a
 *      folder (theming/branding.css), fonts/web/ beside that folder — the
 *      layout nginx-inject.conf.template serves; or
 *   2. rewrite the three url()s while concatenating, to the font folder
 *      relative to the bundle (flat folder: sed 's#\.\./fonts/web/#fonts/#g').
 *      CSS the app inlines into a <style> element resolves against each
 *      page's address: there use the proxy path from the site root
 *      (/cd-branding/fonts/…), the one exception, named in the hand-over.
 * Check: the font requests answer 200 font/woff2; check_layout T3/T4.
 * Never a third-party CDN. Details: references/theming.md §8.
 *
 * Scopes. Three kinds of rules, in this order:
 *   §2 Floor, not scoped: root 100 %, font-synthesis, the focus ring. They
 *      must reach every page the file is loaded on, as in leipzig.css (D21,
 *      D93, D101). Do not load the file where they must not apply.
 *   §3 Theme scope `.cd-theme` or `[data-cd-theme]` on <html> or <body>:
 *      Leipzig Sans on all text, monospace kept, no italics. Set it in the
 *      app's layout template, or let nginx add the attribute
 *      (nginx-inject.conf.template). An app that only takes CSS cannot set it:
 *      replace `.cd-theme, [data-cd-theme]` with `html` (one search, every
 *      occurrence).
 *   §4–§6 Opt-in classes `cd-*` for templates you control, and the content
 *      scope `.cd-content, [data-cd-content]` for author content (Word
 *      pastes). Where you cannot add a class, replace `.cd-content,
 *      [data-cd-content]` with the app's own content selectors, e.g.
 *      `.question-text, .survey-welcome` (LimeSurvey) or `.contents` (Wiki.js).
 *
 * Specificity. Hosts style with classes and Bootstrap utilities that carry
 * !important. Rules here therefore sit at one class (0,1,x) or more and win
 * by source order, because the file loads after the app's CSS. !important is
 * used only where the opponent is an inline style (Word) or a host
 * !important utility (.mb-3), and is commented there.
 *
 * Values come only from tokens.css. check_style.py reports 0 findings.
 */

/* --- 1. Fonts (D31, D93) ---------------------------------------------------- */
/* The city's official web files, unchanged (never convert, D31). The licence
   covers the city's and the leipzig.schule / MPZ services (customer decision
   A2): serve them from the same host as the app, next to this file. */
@font-face {
  font-family: 'Leipzig Sans';
  src: url('../fonts/web/LeipzigSans-Regular.woff2') format('woff2'),
       url('../fonts/web/LeipzigSans-Regular.woff') format('woff');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Leipzig Sans';
  src: url('../fonts/web/LeipzigSans-Medium.woff2') format('woff2'),
       url('../fonts/web/LeipzigSans-Medium.woff') format('woff');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Leipzig Sans';
  src: url('../fonts/web/LeipzigSans-Bold.woff2') format('woff2'),
       url('../fonts/web/LeipzigSans-Bold.woff') format('woff');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* --- 2. Floor (not scoped) -------------------------------------------------- */
/* Root 16 px (customer decision 2026-09-25, D101). Hosts shrink it:
   Bootstrap 5 builds such as LimeSurvey set --bs-root-font-size to 14 px,
   leipzig.de's own build and Passbolt use 62.5 % (1 rem = 10 px). Every rem
   token would shrink with it. :root:root (0,2,0) beats `html` and `:root`.
   A host whose own chrome is built on a 10 px root grows by 1.6 with this
   rule: restyle that chrome in tokens, or record the exception
   (references/theming.md §4.1). */
:root:root {
  --bs-root-font-size: 100%;   /* Bootstrap 5 reads it for :root { font-size } */
  font-size: 100%;
  font-synthesis: none;        /* a missing face renders as the nearest real one, never faux bold (D93) */
}

/* Focus (D21): 2 px black ring + 2 px white halo on every focusable element.
   Hosts remove the outline on :focus, or swap it for a coloured glow on
   .btn:focus-visible, with up to two classes; the ring is the accessibility
   floor, so it wins with !important. */
:focus-visible {
  outline: var(--focus-ring-width) solid var(--color-focus) !important;   /* floor: beats host `outline: 0` */
  outline-offset: var(--focus-ring-offset) !important;
  box-shadow: var(--shadow-focus-halo) !important;                        /* replaces coloured host glows */
}

/* --- 3. Theme scope: type ----------------------------------------------------- */
/* Leipzig Sans on every text node (T3), except code and icon fonts. The :not()
   list keeps icon fonts that are set on the element itself (Font Awesome,
   Material Design Icons, Material Symbols, Remix, Bootstrap Icons — on <i>
   and <span> only, so a button whose class says "icon" still gets the brand
   font on its label) and aria-hidden decorations. Add the app's own icon
   class to the list. */
:is(.cd-theme, [data-cd-theme]),
:is(.cd-theme, [data-cd-theme]) :not(code, kbd, pre, samp, tt, [aria-hidden="true"], .material-icons, [class*="material-symbols"], .fa, .fas, .far, .fab, :is(i, span)[class*="icon"], :is(i, span)[class*="mdi"], :is(i, span)[class*="fa-"], :is(i, span)[class*="ri-"], :is(i, span)[class*="bi-"]) {
  font-family: var(--font-sans);
}
/* Body text 16 px (task mode, D88). A host built on a 10 px root sizes its body
   in rem (1.4rem means 14 px there) and would read 22.4 px after §2. */
:is(.cd-theme, [data-cd-theme]) body,
body:is(.cd-theme, [data-cd-theme]) {
  font-size: var(--text-body);
  line-height: var(--leading-normal);
}
:is(.cd-theme, [data-cd-theme]) :is(code, kbd, pre, samp, tt) {
  font-family: var(--font-mono);   /* fixed width is right for code (T3 skips it) */
}
:is(.cd-theme, [data-cd-theme]) :is(em, i, cite, dfn, address, var):not([class]) {
  font-style: normal;              /* no italics (Barrierefrei p.2); emphasis is Bold */
}
:is(.cd-theme, [data-cd-theme]) :is(em, cite, dfn):not([class]) {
  font-weight: var(--weight-bold);
}
:is(.cd-theme, [data-cd-theme]) :is(h1, h2, h3, h4, h5, h6, p, li, td, th, dd, dt, label, legend) {
  hyphens: manual;                 /* never hyphenate (Barrierefrei p.2, D40) */
}
/* Browser defaults that every host page inherits where the app sets nothing:
   form controls at 13.33 px (T2) and Bold headings (R8: Medium). :where()
   keeps these at zero specificity, so any rule of the app or its theme wins. */
:where(.cd-theme, [data-cd-theme]) :where(button, input, select, textarea) {
  font-size: inherit;
}
:where(.cd-theme, [data-cd-theme]) :where(h1, h2, h3, h4, h5, h6) {
  font-weight: var(--weight-medium);
}
/* Line breaks without breaking words (D50: a heading stays at two lines or fewer;
   D94: words are never split). Balanced headings do not leave one word alone on a
   second line; running text avoids a lone last word. Zero specificity, like above. */
:where(.cd-theme, [data-cd-theme]) :where(h1, h2, h3) {
  text-wrap: balance;
}
:where(.cd-theme, [data-cd-theme]) :where(p, li, dd, blockquote, figcaption) {
  text-wrap: pretty;
}

/* --- 4. Links (D96) ------------------------------------------------------------ */
/* Prose links — links in author content and `.cd-link`: --color-link
   (data-leitfarbe sets it: Blau on Blau pages, black otherwise), underline
   1 px, 3 px on hover and focus, colour never changes, visited = link colour.
   A link with a class is a host component (button, tab, menu row) and keeps
   the theme's own rule. */
:is(.cd-content, [data-cd-content]) a:not([class]),
.cd-link {
  color: var(--color-link);
  text-decoration-line: underline;
  text-decoration-thickness: var(--link-underline);
  text-underline-offset: var(--link-underline-offset);
  text-decoration-skip-ink: auto;
}
:is(.cd-content, [data-cd-content]) a:not([class]):visited,
.cd-link:visited {
  color: var(--color-link-visited);
}
:is(.cd-content, [data-cd-content]) a:not([class]):is(:hover, :focus-visible),
.cd-link:is(:hover, :focus-visible) {
  color: var(--color-link);
  text-decoration-thickness: var(--link-underline-hover);
}

/* --- 5. Layout helpers (opt-in classes) --------------------------------------- */
/* One column (D89): put .cd-column on the header inner, the main wrapper and
   the footer inner alike, so every left edge is the same. Task pages
   (forms, surveys, logins) take --ui-column 40rem; add .cd-column--wide for
   lists, dashboards and reading pages (72rem). */
.cd-column {
  box-sizing: border-box;
  inline-size: 100%;
  max-inline-size: calc(var(--cd-column, var(--ui-column)) + 2 * var(--ui-gutter));
  margin-inline: auto;
  padding-inline: var(--ui-gutter);
}
.cd-column--wide {
  --cd-column: var(--ui-column-wide);
}

/* Nested framework containers: hosts stack .container > .row (negative
   margins) > .col (padding) several levels deep, and each level moves the
   left edge. .cd-flat on an ancestor flattens every level below it; the one
   .cd-column above it sets the edge. Not for real multi-column grids (it also
   removes the gap between columns): put .cd-flat below the grid, or not at all. */
.cd-flat :is(.container, .container-fluid, .container-sm, .container-md, .container-lg, .container-xl, .container-xxl) {
  max-inline-size: none;
  inline-size: auto;
  margin-inline: 0;
  padding-inline: 0;
}
.cd-flat .row {
  --bs-gutter-x: 0;                /* Bootstrap 5: the gutter is a variable on the row */
  margin-inline: 0;
}
.cd-flat :is(.col, [class^="col-"], [class*=" col-"]) {
  padding-inline: 0;
}

/* Stacked spacing: core CSS adds margin-bottom, `.mb-3` and empty help or
   validation blocks with margins, and the gaps add up differently in every
   card. .cd-stack makes the element one flex column with one gap and zeroes
   the children's block margins. --cd-stack-gap picks the role (web.md §0.2 C:
   16 inside a card, 24 intro → first card, 32 between sections). */
.cd-stack {
  display: flex;
  flex-direction: column;
  gap: var(--cd-stack-gap, var(--space-4));
}
.cd-stack > * {
  margin-block: 0 !important;      /* beats Bootstrap's !important spacing utilities (.mb-3, .my-2) */
}
/* gap still counts an empty child: hide the ones without any content. Only
   :empty here — `:not(:has(*))` would also hide a <div> that holds plain
   text, so use it only on containers you know hold elements (validation
   slots), in the app theme. */
.cd-stack > :is(div, p, span, section):empty {
  display: none;
}

/* --- 6. Author content (Word pastes) ----------------------------------------- */
/* Text pasted from Word carries Calibri at 12 pt, a line height, a colour,
   an 11 px bottom margin and empty <p>&nbsp;</p> as inline styles. CSS can override the styles; only strip-word-paste.js can remove
   the empty paragraphs (CSS cannot see &nbsp;) and the styles themselves. */
:is(.cd-content, [data-cd-content]) {
  font-family: var(--font-sans);
  overflow-wrap: break-word;       /* last resort for a single word wider than the line (D94) */
}
:is(.cd-content, [data-cd-content]) :not(code, kbd, pre, samp, tt):is([style*="font-family"], font[face]) {
  font-family: var(--font-sans) !important; /* beats the inline style */
}
:is(.cd-content, [data-cd-content]) :not(h1, h2, h3, h4, h5, h6):is([style*="font-size"], font[size]) {
  font-size: inherit !important;   /* Word's 12pt → the surrounding token size */
}
:is(.cd-content, [data-cd-content]) h2[style*="font-size"] { font-size: var(--text-h2) !important; }
:is(.cd-content, [data-cd-content]) h3[style*="font-size"] { font-size: var(--text-h3) !important; }
:is(.cd-content, [data-cd-content]) :is(h4, h5, h6)[style*="font-size"] { font-size: var(--text-h4) !important; }
:is(.cd-content, [data-cd-content]) [style*="line-height"] {
  line-height: inherit !important;
}
:is(.cd-content, [data-cd-content]) :not(a):is([style*="color"], font[color]) {
  color: inherit !important;       /* text is black or white (Farben p.14); Word's dark blue is not */
}
:is(.cd-content, [data-cd-content]) [style*="background"]:not(img, picture, video, svg) {
  background: transparent !important; /* Word highlights are off-palette */
}
:is(.cd-content, [data-cd-content]) :is(p, ul, ol, blockquote, table) {
  margin-block: 0 var(--space-4);
}
:is(.cd-content, [data-cd-content]) :is(p, li, div)[style*="margin"],
:is(.cd-content, [data-cd-content]) .MsoNormal {
  margin-block: 0 var(--space-4) !important; /* Word's inline 11 px bottom margin */
}
:is(.cd-content, [data-cd-content]) :is(p, ul, ol, blockquote, table):last-child,
:is(.cd-content, [data-cd-content]) :is(p, li, div)[style*="margin"]:last-child {
  margin-block-end: 0 !important;
}
:is(.cd-content, [data-cd-content]) :is(p, li, blockquote) {
  max-inline-size: var(--measure); /* 63–70 characters per line (D94) */
}
/* Code blocks end on the same measure as the paragraphs around them (D94) and
   scroll inside themselves. --cd-measure is registered as a length, so it is
   computed once on the content area (16 or 18 px body text) and <pre> inherits
   that width — `var(--measure)` itself is 33em and would resolve against the
   smaller monospace size of the <pre>. Without @property support the block is
   only a little narrower. Tables are not capped (D94). */
@property --cd-measure {
  syntax: '<length>';
  inherits: true;
  initial-value: 0;
}
:is(.cd-content, [data-cd-content]) {
  --cd-measure: var(--measure);
}
:is(.cd-content, [data-cd-content]) pre {
  max-inline-size: var(--cd-measure, var(--measure));
  overflow-x: auto;
}
:is(.cd-content, [data-cd-content]) :is(a[href*="://"], a[href^="mailto:"], code, .url) {
  overflow-wrap: anywhere;         /* a URL is not a word: it may break, prose never (D94) */
}
:is(.cd-content, [data-cd-content]) :is(img, video, iframe) {
  max-inline-size: 100%;
  block-size: auto;
}

/* Wide tables scroll inside their own box, never the page (D94, D100).
   strip-word-paste.js wraps content tables in .cd-table-scroll; in templates
   you control, write the wrapper yourself:
   <div class="cd-table-scroll" role="region" aria-label="Tabelle" tabindex="0">. */
.cd-table-scroll {
  max-inline-size: 100%;
  overflow-x: auto;
}
.cd-table-scroll > table {
  margin-block-end: 0;
}
/* Tables in author content (Word, a CMS editor): the browser draws them with
   2 px cell spacing and 1 px padding, so the text sits 3 px off the column
   edge (L1) and the grid lines are Word's. Same look as leipzig.css .table
   (D100): collapsed, 12/16 px cells, ui-line rules, Bold th, no vertical rules.
   strip-word-paste.js removes Word's inline borders and widths first. */
/* Words in cells are never split (D94). Hosts squeeze columns below their
   longest word with `table-layout: fixed` (an editor's "fixed width cells"
   option) or `word-break: break-word` / `break-all` on the cells, often with
   two classes (WordPress core: .wp-block-table .has-fixed-layout td), and a
   390 px phone then shows "gebührenfr|ei". Auto layout keeps every column at
   least one word wide; a table wider than the column scrolls in its box
   (.cd-table-scroll or the host's own scroll wrapper, D100). Both win with
   !important: the host rule has more classes than this file uses. */
:is(.cd-content, [data-cd-content]) table {
  table-layout: auto !important;   /* beats a host's two-class fixed layout (D94) */
  border-collapse: collapse;
  font-size: var(--text-ui);
  line-height: var(--leading-normal);
}
:is(.cd-content, [data-cd-content]) caption {
  caption-side: top;
  padding-block-end: var(--space-2);
  font-weight: var(--weight-medium);
  text-align: start;
}
:is(.cd-content, [data-cd-content]) :is(th, td) {
  padding: var(--space-3) var(--space-4);
  text-align: start;
  vertical-align: top;
  border: 0;
  border-block-end: var(--border-width) solid var(--color-ui-line);
  word-break: normal !important;   /* beats a host's two-class break-word / break-all (D94) */
}
/* In a cell, `overflow-wrap: anywhere` would lower the column's minimum width
   to one character: auto layout then squeezes the column and a URL or a code
   token stacks letter by letter. In cells they break only where they must
   (break-word keeps the minimum at the longest token) and the table scrolls
   in its box instead (D94, D100). */
:is(.cd-content, [data-cd-content]) :is(th, td) :is(a[href*="://"], a[href^="mailto:"], code, .url) {
  overflow-wrap: break-word;
}
:is(.cd-content, [data-cd-content]) th {
  font-weight: var(--weight-bold);
}
