/* Owner: C (frame and reading). The app frame (spec §3): sidebar / rail on the frame colour, the content panel
   (container "haupt"), the page head and grid, the reading pane beside the content (container "lesen") – a modal
   sheet from 760 to 1023 px and a full-screen dialog below –, the phone header with its drawer, the command palette's
   trigger and the shortcut sheet. Tokens only; states only via attributes (data-leiste, data-lesen, data-menue,
   data-titel, data-zustand, aria-*). Reference: W/design/final/mockup/css/layout.css. Print rules at the end. */
@layer layout {
  /* ── Frame: sidebar | content panel | (reading pane) ──
     --lesebreite is the pane's share of the area right of the navigation (0.3 … 0.7, default 0.5), set via CSSOM. */
  .rahmen {
    --leiste-b: var(--leiste);
    display: grid; grid-template-columns: var(--leiste-b) minmax(0, 1fr); min-height: 100vh; min-height: 100dvh;
  }
  .rahmen[data-leiste="rail"] { --leiste-b: var(--rail); }
  .rahmen[data-lesen="offen"] {
    --leiste-b: var(--rail);
    /* the column holds the pane (>= 420 px) and the gutter right of it */
    grid-template-columns: var(--leiste-b) minmax(0, 1fr) minmax(calc(420px + var(--rand)), calc((100% - var(--leiste-b)) * var(--lesebreite)));
  }
  @media (min-width: 1600px) {
    .rahmen[data-lesen="offen"]:not([data-leiste="rail"]) { --leiste-b: var(--leiste); }
  }
  @media (max-width: 1279px) { .rahmen { --leiste-b: var(--rail); } }

  /* Height of the sticky phone header: sticky heads of the pages sit below it (top: var(--kopf-hoehe)). */
  :root { --kopf-hoehe: 0px; }
  .appkopf { grid-column: 1; grid-row: 1; min-width: 0; }
  .mobilkopf { display: none; }
  .druckkopf { display: none; }           /* print only (print.css) */

  /* ── Sidebar on the frame: one markup for sidebar and rail – its own width decides (container "leiste") ── */
  .leiste {
    container: leiste / inline-size;
    position: sticky; top: 0; height: 100vh; height: 100dvh; display: flex; flex-direction: column;
    padding: 10px 8px 8px; overflow-y: auto; overflow-x: hidden; scrollbar-width: none; background: var(--bg);
  }
  .leiste__kopf { display: flex; align-items: center; gap: 4px; min-height: 40px; padding: 0 0 0 4px; margin-bottom: 8px; }
  .logo { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; height: 36px; padding: 0 4px; border-radius: var(--r-sm); color: var(--text); text-decoration: none; }
  .logo:hover { background: var(--nav-hover); }
  .logo__text { display: grid; min-width: 0; }
  .logo__name { font-size: var(--fs-14); line-height: 18px; font-weight: 650; letter-spacing: -0.014em; }
  .logo__titel { font-size: var(--fs-12); line-height: 16px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .leiste__umschalter { color: var(--text-3); }
  .leiste__umschalter .icon-panel-left-open { display: none; }
  .leiste .ikon:hover { background: var(--nav-hover); }
  .leiste__zu { display: none; }

  .springen { display: block; margin-bottom: 12px; }
  .springen__feld {
    display: flex; align-items: center; gap: 8px; height: var(--h-md); padding: 0 5px 0 9px; cursor: text;
    border: 1px solid var(--border-input); border-radius: var(--r-sm); background: var(--surface); color: var(--text-3);
  }
  .springen__feld:hover { border-color: var(--text-3); }
  .springen__feld:focus-within { outline: 2px solid var(--focus); outline-offset: -1px; border-color: var(--focus); }
  .springen__feld input { flex: 1; min-width: 0; height: 100%; padding: 0; border: 0; outline: 0; background: transparent; font-size: var(--fs-14); color: var(--text); }
  .springen__feld .kbd { background: var(--surface-2); height: 20px; }
  .springen__knopf { display: none; }

  .nav { display: grid; gap: 2px; }
  .nav__liste { display: grid; gap: 1px; list-style: none; }
  .nav__punkt {
    position: relative; display: flex; align-items: center; gap: 10px; height: var(--h-md); padding: 0 8px;
    border-radius: var(--r-sm); color: var(--text-2); font-weight: 500; text-decoration: none; white-space: nowrap;
  }
  .nav__punkt .icon { color: var(--text-3); }
  .nav__punkt:hover { background: var(--nav-hover); color: var(--text); }
  .nav__punkt[aria-current="page"] { background: var(--nav-aktiv); color: var(--text); }
  .nav__punkt[aria-current="page"] .icon { color: var(--accent-text); }
  .nav__punkt[aria-current="page"]::before {
    content: ""; position: absolute; left: -8px; top: 7px; bottom: 7px; width: 3px; border-radius: 0 3px 3px 0;
    background: var(--accent-line);
  }
  .nav__punkt:focus-visible, .logo:focus-visible, .nutzer:focus-visible, .archivstatus:focus-visible { outline-offset: -2px; }
  .nav__text { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .nav__gruppe { margin: 18px 8px 6px; font-size: var(--fs-12); line-height: 16px; font-weight: 500; color: var(--text-3); }
  /* Deadline counter: neutral; red tint with an outline as soon as a deadline is overdue or due soon */
  .zaehler {
    margin-left: auto; min-width: 20px; height: 18px; padding: 0 6px; border-radius: var(--r-full);
    display: inline-grid; place-items: center; background: var(--chip); color: var(--text-2);
    font-size: var(--fs-12); line-height: 1; font-weight: 600; font-variant-numeric: tabular-nums;
  }
  .zaehler:is([data-zustand="ueberfaellig"], [data-zustand="bald"]) {
    background: var(--danger-subtle); color: var(--danger-text); box-shadow: inset 0 0 0 1px var(--danger-border);
  }
  /* Admins: proposals of the language model that wait at "Chronik" – info tint (open, to decide), never the deadline red */
  .zaehler--vorschlaege { background: var(--info-subtle); color: var(--info-text); box-shadow: inset 0 0 0 1px var(--info-border); }

  .leiste__fuss { margin-top: auto; display: grid; gap: 2px; padding-top: 12px; }
  .archivstatus {
    display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; min-height: 28px; padding: 4px 8px; border-radius: var(--r-sm);
    font-size: var(--fs-12); line-height: 16px; color: var(--text-3); text-decoration: none;
  }
  a.archivstatus:hover { background: var(--nav-hover); color: var(--text-2); }
  .archivstatus .punkt { margin: 0 2px; }
  .archivstatus__text { min-width: 0; }
  /* "seit 2 Tagen": the stale archive says it in words, never by colour alone */
  .archivstatus__alter {
    display: inline-flex; align-items: center; height: 18px; padding: 0 6px; border-radius: var(--r-xs);
    background: var(--danger-subtle); color: var(--danger-text); box-shadow: inset 0 0 0 1px var(--danger-border);
    font-weight: 600; white-space: nowrap;
  }
  .nutzer { display: flex; align-items: center; gap: 10px; width: 100%; height: 44px; padding: 0 8px; border-radius: var(--r-sm); text-align: left; color: var(--text); }
  .nutzer:hover, .nutzer[aria-expanded="true"] { background: var(--nav-hover); }
  .nutzer__text { display: grid; min-width: 0; flex: 1; }
  .nutzer__name { font-size: var(--fs-13); line-height: 18px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .nutzer__rolle { font-size: var(--fs-12); line-height: 16px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .nutzer > .icon { color: var(--text-3); }

  /* Rail (56 px): words stay as names (visually hidden), tooltips name the target; the toggle stays visible */
  @container leiste (max-width: 120px) {
    .leiste__kopf { flex-direction: column; justify-content: center; gap: 6px; padding: 0; }
    .logo { flex: none; justify-content: center; width: 40px; padding: 0; }
    .leiste__umschalter .icon-panel-left-close { display: none; }
    .leiste__umschalter .icon-panel-left-open { display: block; }
    .nav__gruppe, .nutzer > .icon { display: none; }
    .nav__text, .logo__text, .archivstatus__text, .archivstatus__alter, .nutzer__text {
      position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
    }
    .springen__feld { display: none; }
    .springen__knopf { display: inline-grid; margin: 0 auto; }
    .springen { display: flex; justify-content: center; }
    .nav__punkt { justify-content: center; width: 40px; height: 36px; margin: 0 auto; padding: 0; }
    .nav__liste + .nav__gruppe + .nav__liste { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
    .zaehler { position: absolute; top: 2px; right: 0; min-width: 16px; height: 16px; padding: 0 4px; margin: 0; font-size: var(--fs-12); }
    .archivstatus { justify-content: center; padding: 0; }
    .nutzer { justify-content: center; padding: 0; width: 40px; margin: 0 auto; }
  }

  /* 1024–1279 (and with the reading pane up to 1599): the full sidebar opens as an overlay above the content */
  .rahmen[data-leiste="overlay"] .leiste {
    position: fixed; inset: 0 auto 0 0; z-index: var(--z-sheet); width: var(--leiste); background: var(--bg);
    border-right: 1px solid var(--border-strong); box-shadow: var(--shadow-dialog);
  }
  .rahmen[data-leiste="overlay"]::after { content: ""; position: fixed; inset: 0; z-index: var(--z-scrim); background: var(--scrim); }

  /* ── Content panel: inset sheet on the frame. The document scrolls, not the panel. Bound to main: the old
        primary buttons ("knopf haupt") must not get panel rules (komponenten.md §6.5). ── */
  main.haupt {
    grid-column: 2; grid-row: 1; min-width: 0; margin: var(--rand) var(--rand) var(--rand) 0; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--r-lg); container: haupt / inline-size;
    min-height: calc(100vh - 2 * var(--rand)); min-height: calc(100dvh - 2 * var(--rand));
  }
  main.haupt:focus { outline: none; }
  .seite { --pad: 32px; max-width: calc(var(--inhalt-max) + 2 * var(--pad)); margin: 0 auto; padding: 0 var(--pad) 64px; }
  .seite--schmal { max-width: calc(1040px + 2 * var(--pad)); }
  @container haupt (max-width: 900px) { .seite { --pad: 24px; } }
  @container haupt (max-width: 600px) { .seite { --pad: 16px; } }

  /* ── Page head: breadcrumb (detail pages), H1 = navigation name, meta line, actions right ── */
  .seitenkopf { display: grid; gap: 6px; padding: 26px 0 22px; }
  .seitenkopf--kompakt { padding: 20px 0 16px; }
  .seitenkopf__zeile { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 12px 24px; }
  /* the title column keeps 480 px before the actions sit beside it – a narrower panel puts them below the title */
  .seitenkopf__titel { flex: 1 1 480px; min-width: 0; }
  /* fit-content: the focus ring after a route change rings the heading, not the empty width of the column */
  .seitenkopf h1 { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; width: fit-content; max-width: 100%; font-size: var(--fs-22); line-height: 30px; letter-spacing: -0.019em; overflow-wrap: anywhere; }
  .seitenkopf h1:focus { outline: none; }
  .seitenkopf h1:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; }
  .seitenkopf__aktionen { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
  .seitenkopf__aktionen:empty { display: none; }
  /* Narrow panel: the actions get a row of their own below the title, and the first one (ghost or icon button)
     stands flush with the content edge – its icon, not its padding, on the edge (spec §2.6) */
  @container haupt (max-width: 600px) {
    .seitenkopf__aktionen { flex-basis: 100%; }
    .seitenkopf__aktionen > .knopf--ghost:first-child { margin-left: -15px; }
    .seitenkopf__aktionen > .knopf--ghost.knopf--klein:first-child { margin-left: -11px; }
    .seitenkopf__aktionen > .knopf--ghost.knopf--mini:first-child { margin-left: -9px; }
    .seitenkopf__aktionen > .ikon:first-child { margin-left: -8px; }
  }
  /* Page toolbar (mail, attachment): labelled actions in one row below the meta line */
  .werkzeugleiste { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-top: 10px; }
  .werkzeugleiste__rechts { margin-left: auto; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
  .werkzeugleiste__rechts:empty { display: none; }
  @container haupt (max-width: 640px) {
    .werkzeugleiste { gap: 4px; }
    .werkzeugleiste .knopf--ghost:has(.knopf__text) { width: var(--h-md); padding: 0; }
    .werkzeugleiste .knopf--ghost .knopf__text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
  }

  /* Meta line: parts separated by a dot that sits in the gap. A part that starts a new line has its dot left of the
     line start, where overflow clips it – so no line ever begins with a separator. */
  .meta {
    display: flex; flex-wrap: wrap; align-items: center; column-gap: 17px; row-gap: 2px; margin-top: 4px;
    font-size: var(--fs-13); line-height: 20px; color: var(--text-2); overflow: clip; overflow-clip-margin: 4px;
  }
  .meta:empty { display: none; }
  .meta > * { position: relative; display: block; min-width: 0; overflow-wrap: anywhere; }
  /* short parts ("Stand 14.11.2026", a date range) never break inside – they move to the next line as a whole */
  .meta > .meta--ganz { white-space: nowrap; }
  .meta > * > .icon:first-child, .meta > * > .punkt:first-child { display: inline-block; vertical-align: -0.2em; margin-right: 5px; }
  .meta > * > .punkt:first-child { vertical-align: 0.05em; }
  .meta > * + *::before {
    content: ""; position: absolute; left: -10px; top: 50%; width: 3px; height: 3px; margin-top: -1.5px;
    border-radius: 50%; background: var(--text-3);
  }
  .meta .icon { color: var(--text-3); width: 14px; height: 14px; }
  .meta__zahl { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
  .meta-teil { display: inline-flex; align-items: center; gap: 5px; }
  .meta-teil .icon { color: var(--text-3); }
  a.meta-teil .icon { color: currentColor; opacity: 0.75; }

  /* ── Generic page grid: main column + 300 px side column from 1000 px container width ── */
  .zweispaltig { display: grid; gap: 32px; }
  .zweispaltig > * { min-width: 0; }
  @container haupt (min-width: 1000px) {
    .zweispaltig { grid-template-columns: minmax(0, 1fr) 300px; gap: 40px; align-items: start; }
    .zweispaltig__seite { position: sticky; top: 16px; }
  }
  .seitenspalte { display: grid; gap: 24px; align-content: start; }
  .seitenspalte h2 { font-size: var(--fs-13); line-height: 20px; font-weight: 600; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
  .seitenspalte h2 .zahl { color: var(--text-3); font-weight: 500; }
  .seitenspalte h2 .icon { color: var(--text-3); width: 14px; height: 14px; }
  .seitenspalte__leer { font-size: var(--fs-13); color: var(--text-3); }

  /* ── Reading pane: region beside the content (>= 1024), modal sheet (760–1023), full screen (< 760) ── */
  .lesefenster {
    container: lesen / inline-size;
    grid-column: 3; grid-row: 1; align-self: start; position: sticky; top: var(--rand); z-index: var(--z-pane);
    height: calc(100vh - 2 * var(--rand)); height: calc(100dvh - 2 * var(--rand));
    margin: var(--rand) var(--rand) var(--rand) 0; display: flex; flex-direction: column;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); min-width: 0;
    transition: opacity var(--dur-3) var(--ease-out), translate var(--dur-3) var(--ease-out);
  }
  @starting-style { .lesefenster { opacity: 0; translate: 16px 0; } }
  /* The 8 px gutter left of the pane is the width handle (role=separator): drag, arrow keys, double click = 50 % */
  .lesefenster__griff {
    position: absolute; left: calc(-1 * var(--rand) - 1px); top: 0; bottom: 0; width: var(--rand); z-index: var(--z-handle);
    cursor: col-resize; display: grid; place-items: center; border-radius: var(--r-sm); touch-action: none;
  }
  .lesefenster__griff::before {
    content: ""; width: 4px; height: 36px; border-radius: 2px; background: var(--border-strong);
    transition: height var(--dur-2) var(--ease-out), background-color var(--dur-1) var(--ease-out);
  }
  .lesefenster__griff:hover::before, .lesefenster__griff:focus-visible::before, .lesefenster__griff[data-aktiv]::before { height: 56px; background: var(--accent-line); }
  .lesefenster__griff:focus-visible { outline: 2px solid var(--focus); outline-offset: -1px; }
  .lesefenster__kopf { flex: none; background: var(--surface); border-bottom: 1px solid var(--border); border-radius: calc(var(--r-lg) - 1px) calc(var(--r-lg) - 1px) 0 0; }
  .lesefenster__leiste { display: flex; align-items: center; gap: 2px; height: 44px; padding: 0 8px; min-width: 0; }
  /* only the evidence trail and the way back give way when the row gets tight – the tools never leave the pane */
  .lesefenster__leiste > * { flex: none; }
  .lesefenster__leiste > .belegspur { flex: 0 1 auto; }
  /* the way back is never cut ("Zurück zu Beleg 2"): in a jump the evidence trail and the J/K hints make room */
  .lesefenster__zurueck { flex: none; margin-right: 4px; }
  .lesefenster__leiste[data-sprung] .belegspur, .lesefenster__leiste[data-sprung] .schritte .kbd { display: none; }
  .schritte { display: flex; align-items: center; gap: 2px; min-width: 0; }
  .schritte__text { margin: 0 8px 0 6px; font-size: var(--fs-13); font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; }
  .schritte__text span { color: var(--text-3); font-weight: 500; }
  .schritte__text--still { color: var(--text-2); font-weight: 500; }
  /* a jump out of the sequence: "Außerhalb der Belege" – quiet, never like "Beleg 2 von 5" */
  .schritte__text--aussen { font-weight: 500; }
  .schritte__text--aussen span { color: var(--text-2); }
  .schritte__kurz { display: none; }
  /* Evidence trail: every source of the answer in reading order; the open one is ringed; a click jumps */
  .belegspur { display: flex; align-items: center; gap: 4px; margin-left: 6px; padding-left: 10px; border-left: 1px solid var(--border); min-width: 0; overflow: hidden; padding-block: 4px; }
  .belegspur .marke { margin: 0; flex: none; }
  .belegspur .marke[aria-current="true"] { outline: 2px solid var(--focus); outline-offset: 1px; }
  .belegspur__mehr { flex: none; height: 18px; padding: 0 6px; border-radius: var(--r-full); font-size: var(--fs-12); font-weight: 600; color: var(--text-2); background: var(--chip); }
  .belegspur__mehr:hover { background: var(--chip-hover); color: var(--text); }
  .lesefenster__leiste .werkzeuge { margin-left: auto; }
  .lesefenster__kontext {
    display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 12px 0 14px; border-top: 1px solid var(--border);
    background: var(--surface-2); font-size: var(--fs-13); color: var(--text-2); white-space: nowrap; overflow: hidden;
  }
  .lesefenster__kontext > .icon { color: var(--text-3); }
  .lesefenster__kontext .personen { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .lesefenster__kontext .datei { min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--text); font-weight: 500; }
  .lesefenster__kontext .seitenzahl { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
  .markierungen { margin-left: auto; display: flex; align-items: center; gap: 2px; padding-left: 12px; color: var(--text-2); }
  .markierungen__text { font-size: var(--fs-12); font-weight: 500; margin-right: 4px; font-variant-numeric: tabular-nums; white-space: nowrap; }
  .lesefenster__koerper {
    flex: 1; min-height: 0; overflow-y: auto; background: var(--paper-well); scroll-padding-block: 24px 48px;
    border-radius: 0 0 calc(var(--r-lg) - 1px) calc(var(--r-lg) - 1px);
  }
  .lesefenster__koerper:focus { outline: none; }
  .lesefenster__koerper:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
  .lesefenster__laden { display: grid; gap: 16px; padding: 24px; }
  .lesefenster__laden .skelett--titel { height: 22px; }
  .lesefenster__fehler { padding: 24px; }
  @container lesen (max-width: 600px) { .schritte .kbd { display: none; } }
  /* with the evidence trail, a pane under 720 px gives the trail the room of the J/K hints and of "von 6" */
  @container lesen (max-width: 720px) {
    .lesefenster__leiste:has(> .belegspur:not([hidden])) .schritte .kbd, .lesefenster__leiste:has(> .belegspur:not([hidden])) .schritte__von { display: none; }
    .lesefenster__leiste:has(> .belegspur:not([hidden])) .schritte__kurz { display: inline; }
  }
  /* a jump in a narrow pane: "kein Beleg" instead of "Außerhalb der Belege"; at the narrowest the line above the
     subject says it alone (the way back and the tools keep their room) */
  @container lesen (max-width: 560px) {
    .lesefenster__leiste[data-sprung] .schritte__von { display: none; }
    .lesefenster__leiste[data-sprung] .schritte__kurz { display: inline; }
  }
  @media (min-width: 760px) {
    @container lesen (max-width: 460px) { .lesefenster__leiste[data-sprung] .schritte__text { display: none; } }
  }
  @container lesen (max-width: 540px) { .belegspur { display: none; } }
  @container lesen (max-width: 480px) { .lesefenster__kontext .personen { display: none; } }

  .nur-schmal { display: none; }

  /* ── 760–1023 and phone: the pane lives in a modal <dialog> (top layer, inert background, Esc) ── */
  .lesedialog {
    position: fixed; inset: 8px 8px 8px auto; width: min(720px, calc(100vw - 72px)); height: auto;
    max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: transparent; color: var(--text); overflow: visible;
  }
  .lesedialog[open] { display: flex; }
  .lesedialog::backdrop { background: var(--scrim); }
  /* the height follows the insets of the dialog, not the content: the body scrolls inside */
  .lesedialog .lesefenster { position: relative; top: auto; flex: 1; align-self: stretch; height: auto; min-height: 0; margin: 0; box-shadow: var(--shadow-dialog); border-color: var(--border-strong); }
  .lesedialog .lesefenster__griff { display: none; }
  @media (max-width: 1023px) {
    .rahmen[data-lesen="offen"] { grid-template-columns: var(--leiste-b) minmax(0, 1fr); }
  }

  /* ── Phone < 760: 48 px header, modal drawer, full-screen reading dialog with a one-line head ── */
  .drawer {
    position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); height: 100%; max-width: none; max-height: none;
    margin: 0; padding: 0; border: 0; border-right: 1px solid var(--border-strong); background: var(--bg); color: var(--text);
    box-shadow: var(--shadow-dialog); overflow: hidden;
  }
  .drawer::backdrop { background: var(--scrim); }
  .drawer .leiste { position: static; display: flex; width: 100%; height: 100%; }
  .drawer .leiste__umschalter, .drawer .springen__feld .kbd { display: none; }
  .drawer .leiste__zu { display: inline-grid; }
  @starting-style { .drawer[open] { translate: -16px 0; opacity: 0; } }
  .drawer { transition: translate var(--dur-3) var(--ease-out), opacity var(--dur-3) var(--ease-out); }

  @media screen and (max-width: 759px) {
    :root { --kopf-hoehe: 48px; }
    body { background: var(--surface); }
    .rahmen, .rahmen[data-lesen="offen"] { display: block; }
    .appkopf { position: sticky; top: 0; z-index: var(--z-header); }
    .mobilkopf {
      display: flex; align-items: center; gap: 2px; height: 48px; padding: 0 2px; background: var(--surface);
      border-bottom: 1px solid var(--border);
    }
    .mobilkopf .logo { flex: 1; height: 40px; }
    .mobilkopf__titel { display: none; flex: 1; min-width: 0; padding: 0 6px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .mobilkopf[data-titel="seite"] .logo { display: none; }
    .mobilkopf[data-titel="seite"] .mobilkopf__titel { display: block; }
    .mobilkopf .ikon { width: 44px; height: 44px; }
    .mobilkopf .ikon .icon { width: 20px; height: 20px; }
    .mobilkopf .ikon__zahl { top: 6px; right: 4px; }
    .appkopf > .leiste { display: none; }
    main.haupt { margin: 0; border: 0; border-radius: 0; min-height: calc(100vh - 48px); min-height: calc(100dvh - 48px); }
    .seitenkopf { padding: 18px 0 16px; }
    .seitenkopf h1 { font-size: var(--fs-20); line-height: 28px; }

    .nur-schmal { display: inline-flex; }
    .lesedialog { inset: 0; width: 100%; height: 100%; }
    .lesedialog .lesefenster { border-radius: 0; border: 0; box-shadow: none; }
    .lesefenster__kopf, .lesefenster__koerper { border-radius: 0; }
    .lesefenster__leiste { gap: 0; padding: 0 2px; height: 52px; }
    .lesefenster__leiste .werkzeuge > :not(.nur-schmal):not(.immer) { display: none; }
    .lesefenster__leiste .ikon { width: 44px; height: 44px; }
    .lesefenster__leiste > .mailref { margin: 0 4px; }
    .lesefenster__zurueck { display: none; }
    .lesefenster .schritte .kbd { display: none; }
    .lesefenster .schritte__text { order: -1; margin: 0 2px 0 6px; }
    .lesefenster .schritte__von { display: none; }
    .lesefenster .schritte__kurz { display: inline; }
    .zurueck {
      align-items: center; gap: 2px; height: 44px; padding: 0 8px 0 2px; border-radius: var(--r-sm); flex: none;
      font-weight: 500; color: var(--accent-text);
    }
    .zurueck .icon { width: 18px; height: 18px; }
    /* The context row folds away (date and sender stand in the mail head below); its marker navigation floats above
       the bottom edge, and the body keeps the target clear of it. */
    .lesefenster__kontext { display: contents; }
    .lesefenster__kontext > :not(.markierungen) { display: none; }
    .markierungen {
      position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 2; margin: 0; padding: 4px 4px 4px 14px;
      border-radius: var(--r-full); background: var(--tip-bg); color: var(--tip-text); box-shadow: var(--shadow-pop);
    }
    .markierungen[hidden] { display: none; }
    .markierungen__text { font-size: var(--fs-13); }
    .markierungen .ikon { width: 40px; height: 40px; color: var(--tip-text); border-radius: var(--r-full); }
    .markierungen .ikon:hover { background: color-mix(in srgb, var(--tip-text) 14%, transparent); }
    .lesefenster__koerper { scroll-padding-block: 16px 96px; padding-bottom: 72px; }
  }
  @media screen and (max-width: 359px) {
    .zurueck { padding: 0; width: 44px; justify-content: center; }
    .zurueck__text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
  }
  @media (max-width: 759px) and (max-height: 559px) {
    :root { --kopf-hoehe: 0px; }
    .appkopf { position: static; }
  }
  @media (pointer: coarse) {
    .lesefenster__leiste .ikon--klein { width: var(--h-xl); height: var(--h-xl); }
    /* the drawer on touch: navigation, "Menü schließen" and the jump field are 44-px targets (audit §6.1/§6.7) */
    .drawer .nav__punkt { height: var(--h-xl); }
    .drawer .leiste__kopf { min-height: var(--h-xl); }
    .drawer .leiste__zu { width: var(--h-xl); height: var(--h-xl); }
    .drawer .springen__feld { height: var(--h-xl); }
  }

  /* ── Shortcut sheet (the "?" dialog) ── */
  .kuerzel { display: grid; gap: 18px; }
  .kuerzel__gruppe h3 { font-size: var(--fs-12); line-height: 16px; font-weight: 600; color: var(--text-3); margin-bottom: 6px; }
  .kuerzel__liste { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 16px; align-items: center; font-size: var(--fs-13); color: var(--text-2); }
  .kuerzel__liste dt { display: flex; flex-wrap: wrap; gap: 2px; }
  .kuerzel__liste dd { min-width: 0; }
  .kuerzel__aus { font-size: var(--fs-13); color: var(--text-2); }
  .palette__hinweis { padding: 10px 16px 0; font-size: var(--fs-13); color: var(--text-2); }

  @media (forced-colors: active) {
    .nav__punkt[aria-current="page"] { outline: 2px solid Highlight; outline-offset: -2px; }
    .meta > * + *::before { background: CanvasText; forced-color-adjust: none; }
    .zaehler, .archivstatus__alter { border: 1px solid CanvasText; }
    .belegspur .marke[aria-current="true"] { outline: 2px solid Highlight; }
    .lesefenster, .lesedialog .lesefenster, .drawer { border: 1px solid CanvasText; }
  }
}

/* ── Print (spec §8): the frame never prints; the head of the page does, without its controls ── */
@media print {
  @layer print {
    .rahmen { display: block; }
    .lesedialog, .lesedialog[open], .drawer, .drawer[open], .mobilkopf, .leiste { display: none; }
    main.haupt { margin: 0; border: 0; border-radius: 0; min-height: 0; container-type: normal; }
    .seitenkopf h1 { font-size: 16pt; line-height: 1.3; }
    .meta { overflow: visible; }
    .meta > * + *::before { background: var(--text-2); }
  }
}
