/* Owner: C (frame and reading). One reading component for the pane (?lesen=…) and the pages #/mail/<nr> and
   #/anhang/<id> (spec §4.3, §5.10, §5.11): mail head, the "why it is open" line, head data, relations, file rows,
   the document paper (warm "night reading" sheet in dark), the text in lines with the passage marked, page rulers,
   the quoted history, the marking strip, the attachment bar, the relations (Vorgänge, thread). Tokens only.
   Reference: W/design/final/mockup/css/lesen.css. Print rules at the end. */
@layer pages {
  /* ── Document view ── */
  .mailansicht { --papier-rand: 24px; display: grid; gap: 16px; padding: 20px 24px 40px; min-width: 0; }
  .mailkopf { display: grid; gap: 12px; min-width: 0; }
  /* Why this document is open: "Frage 1 · Beleg zur Aussage in Absatz 1 und 2" (jumps back to the statement) */
  .lesen__bezug { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin-bottom: -6px; font-size: var(--fs-12); line-height: 16px; color: var(--text-3); font-weight: 500; }
  .lesen__bezug .icon { color: var(--text-3); }
  .lesen__bezug .link { font-size: inherit; color: var(--accent-text); }
  /* opened by a jump: "#39 ist kein Beleg dieser Antwort." – stronger, so it is not overlooked (D4) */
  .lesen__bezug[data-art="aussen"] { color: var(--text-2); font-size: var(--fs-13); line-height: 20px; }
  .lesen__bezug[data-art="aussen"] .icon { color: var(--text-2); }
  /* fit-content: the focus ring rings the subject, not the empty width beside it */
  .mailkopf__betreff { width: fit-content; max-width: 100%; font-size: var(--fs-18); line-height: 26px; letter-spacing: -0.014em; overflow-wrap: anywhere; }
  .mailkopf__betreff:focus { outline: none; }
  .mailkopf__betreff:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 2px; }
  .mailkopf__aktionen { flex-wrap: wrap; gap: 4px 8px; }
  .kopfdaten { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 4px 12px; font-size: var(--fs-13); line-height: 20px; }
  .kopfdaten dt { color: var(--text-3); }
  .kopfdaten dd { color: var(--text); min-width: 0; overflow-wrap: anywhere; }
  .kopfdaten .adresse { color: var(--text-2); }
  .kopfdaten time { font-variant-numeric: tabular-nums; }
  .kopfdaten .tag { vertical-align: 1px; }
  .kopfdaten--technik { grid-template-columns: 96px minmax(0, 1fr); padding: 4px 0 4px 32px; }
  .bezug { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; font-size: var(--fs-13); line-height: 20px; color: var(--text-2); }
  .bezug > .icon { color: var(--text-3); }
  .bezug__teil { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px; }
  .bezug__trenner { color: var(--text-3); }
  .bezug--leer { color: var(--text-3); }
  /* The relation line of a mail flows as text: "↩ Antwort auf #50 · beantwortet in #55 · weitergeleitet aus …" breaks
     between its parts and inside long names, but a label never parts from its first reference (spec §5.10) */
  .bezug--fluss { display: block; }
  .bezug--fluss .bezug__teil { display: inline; }
  .bezug--fluss .bezug__trenner { margin: 0 8px; }
  .bezug__paar { white-space: nowrap; }
  .bezug__paar > span:not(.mailref) { white-space: normal; }
  .bezug__paar > .icon { display: inline-block; vertical-align: -2px; margin-right: 6px; color: var(--text-3); }

  /* ── Attachments as file rows: type icon, name (a link to the attachment page), meta, actions ── */
  .dateien { list-style: none; display: grid; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); min-width: 0; }
  .dateizeile { display: grid; grid-template-columns: 20px minmax(0, 1fr) auto; gap: 2px 10px; align-items: center; min-height: var(--row); padding: 6px 8px 6px 12px; }
  .dateizeile + .dateizeile { border-top: 1px solid var(--border); }
  .dateizeile--zip { padding-left: 28px; }
  .dateizeile__icon { display: grid; place-items: center; color: var(--text-3); }
  .dateizeile__text { display: grid; min-width: 0; }
  .dateizeile__name { font-weight: 500; color: var(--text); overflow-wrap: anywhere; }
  a.dateizeile__name:hover { text-decoration: underline; text-underline-offset: 3px; }
  .dateizeile__meta { font-size: var(--fs-12); line-height: 16px; color: var(--text-3); font-variant-numeric: tabular-nums; }
  .dateizeile__aktionen { gap: 0; }
  @container (max-width: 480px) { .dateizeile { grid-template-columns: 20px minmax(0, 1fr); } .dateizeile__aktionen { grid-column: 2; } }

  /* ── Paper: the document sheet (e1 shadow; warm "night reading" sheet in dark) ── */
  .papier {
    position: relative; background: var(--paper); border: 1px solid var(--paper-border); border-radius: var(--r-md);
    box-shadow: var(--shadow-paper); padding: 26px 32px 28px 40px; min-width: 0;
  }
  .papier__marke {
    display: flex; align-items: center; gap: 6px; margin: -12px 0 14px -16px; font-size: var(--fs-12); line-height: 16px;
    color: var(--text-3); font-weight: 500;
  }
  .papier__marke .icon { color: var(--text-3); }
  .papier__leer, .papier__hinweis { font-size: var(--fs-13); line-height: 20px; color: var(--text-2); }
  .papier__hinweis { margin-top: 16px; }
  .papier__fuss { margin-top: 18px; display: flex; align-items: flex-start; gap: 8px; font-size: var(--fs-12); line-height: 16px; color: var(--text-3); }
  .papier__fuss .icon { flex: none; }
  /* Reading text: serif 17/27 (phones 16/26), every source line a line, paragraphs a blank line apart. No automatic
     hyphens – an inserted hyphen would look like original text. */
  .dokument {
    font-family: var(--font-text); font-weight: var(--text-weight); font-size: var(--fs-17); line-height: 27px;
    font-variant-numeric: lining-nums; letter-spacing: 0; color: var(--paper-text); max-width: 70ch;
    white-space: pre-wrap; overflow-wrap: anywhere; hyphens: manual;
  }
  .dokument > p + p, .dokument > p + .seitenlineal + p { margin-top: 27px; }
  .dokument .zeile, .dokument .stelle-block { display: block; }
  .dokument .stelle-block { scroll-margin-block: 96px; }
  .zitatverlauf { margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--border); }
  .zitatverlauf > summary { font-family: var(--font-ui); }
  /* who wrote the quoted text and when: "Herr Brandt, Do, 19.03.2026, 01:05 – weitergeleitet" */
  .zitatverlauf__wer { margin-left: 8px; color: var(--text-3); font-weight: 400; font-variant-numeric: tabular-nums; }
  .zitatverlauf .klappe__inhalt { padding-top: 8px; }
  .papier__marke + .zitatverlauf { margin-top: 0; border-top: 0; padding-top: 0; }

  /* Narrow (pane or page < 640 px): the paper loses its card frame and runs edge to edge – more characters per line.
     The reading size stays 17 px; only phones (< 760 px viewport) use 16/26. */
  @container (max-width: 640px) {
    .papier {
      margin-inline: calc(-1 * var(--papier-rand)); border-inline: 0; border-radius: 0; box-shadow: none;
      padding: 20px var(--papier-rand) 24px calc(var(--papier-rand) + 12px);
    }
    .papier__marke { margin: -4px 0 12px -12px; }
  }
  @media screen and (max-width: 759px) {
    .mailansicht { --papier-rand: 16px; padding: 16px 16px 32px; }
    .dokument { font-size: var(--fs-16); line-height: 26px; }
    .dokument > p + p, .dokument > p + .seitenlineal + p { margin-top: 26px; }
    .dokument .stelle-block { margin-left: -15px; padding-left: 12px; }
  }

  /* Marking context on the mail page (opened from an answer or a search): one neutral strip, never amber */
  .markiert {
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 6px 8px 6px 12px;
    border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-2);
    font-size: var(--fs-13); line-height: 20px; color: var(--text-2);
  }
  .markiert > .icon { color: var(--text-3); }
  .markiert b { color: var(--text); font-weight: 600; }
  .markiert__aktion { margin-left: auto; }
  /* A handed-over passage that the mail text does not contain – where it stands instead (an attachment) */
  .fundort { min-width: 0; }

  /* ── Page rulers in attachment text: "— Seite 2 —" becomes a strong divider ── */
  .seitenlineal {
    display: flex; align-items: center; gap: 10px; margin: 26px 0 18px; font-family: var(--font-ui); white-space: normal;
    font-size: var(--fs-12); line-height: 16px; font-weight: 600; color: var(--text-3); font-variant-numeric: tabular-nums;
    scroll-margin-top: 56px;
  }
  .seitenlineal::before, .seitenlineal::after { content: ""; flex: 1; height: 1px; background: var(--border-strong); }
  .seitenlineal:first-child { margin-top: 0; }
  .lesefenster .seitenlineal { scroll-margin-top: 16px; }
  /* Sticky file bar of the attachment page: name, page counter (follows scrolling), original PDF page */
  .anhang-leiste {
    position: sticky; top: var(--kopf-hoehe, 0px); z-index: var(--z-sticky); display: flex; flex-wrap: wrap; align-items: center;
    gap: 4px 10px; min-height: 40px; padding: 4px 8px 4px 14px; border: 1px solid var(--border); border-radius: var(--r-md);
    background: var(--surface-2); font-size: var(--fs-13); color: var(--text-2);
  }
  .anhang-leiste > .icon { color: var(--text-3); }
  .anhang-leiste__name { min-width: 0; overflow-wrap: anywhere; color: var(--text); font-weight: 500; }
  .anhang-leiste__seite { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }
  .anhang-leiste .werkzeuge { margin-left: auto; }

  /* ── Relations of a mail (pane: below the paper; page: side column) ── */
  .bezuege { display: grid; gap: 20px; padding-top: 4px; }
  .bezuege h3 { display: flex; align-items: center; gap: 8px; font-size: var(--fs-13); line-height: 20px; font-weight: 600; margin-bottom: 8px; }
  .bezuege h3 .zahl { color: var(--text-3); font-weight: 500; font-variant-numeric: tabular-nums; }
  :is(.bezuege, .seitenspalte) .vorgangsliste { display: grid; gap: 2px; list-style: none; }
  :is(.bezuege, .seitenspalte) .vorgangsliste a.zeile {
    display: flex; align-items: center; gap: 8px; min-height: 36px; padding: 6px 10px; border-radius: var(--r-sm);
    color: var(--text); font-weight: 500; text-decoration: none;
  }
  :is(.bezuege, .seitenspalte) .vorgangsliste a.zeile:hover { background: var(--surface-hover); }
  :is(.bezuege, .seitenspalte) .vorgangsliste a.zeile:focus-visible { outline-offset: -2px; }
  :is(.bezuege, .seitenspalte) .vorgangsliste a.zeile[aria-current="true"] { background: var(--accent-subtle); box-shadow: inset 2px 0 0 var(--accent-line); }
  :is(.bezuege, .seitenspalte) .vorgangsliste .pille { margin-left: auto; flex: none; }
  :is(.bezuege, .seitenspalte) .vorgangsliste .zeile .icon { color: var(--text-3); flex: none; }
  .zeile__titel { min-width: 0; overflow-wrap: anywhere; }
  :is(.bezuege, .seitenspalte) .klappe { margin-top: 4px; }

  /* ── Thread (Mailverlauf). One markup everywhere: knot · line (MailRef, time, „diese Mail“) · Von → An.
        Wide: one line; narrow (.verlauf--schmal or container ≤ 520 px): two lines, so „diese Mail“ is never cut off.
        The current mail carries aria-current – accent, never yellow ── */
  .verlauf { list-style: none; position: relative; display: grid; gap: 0; }
  .verlauf::before { content: ""; position: absolute; left: 15px; top: 14px; bottom: 14px; width: 1px; background: var(--border-strong); }
  .verlauf__eintrag { position: relative; }
  .verlauf__eintrag a {
    position: relative; display: grid; grid-template-columns: 22px auto minmax(0, 1fr) auto auto; align-items: center; gap: 0 8px;
    min-height: 36px; padding: 6px 10px; border-radius: var(--r-sm); color: var(--text-2); text-decoration: none;
    font-size: var(--fs-13);
  }
  .verlauf__eintrag a:hover { background: var(--surface-hover); }
  .verlauf__eintrag a:focus-visible { outline-offset: -2px; }
  .verlauf__knoten { grid-column: 1; grid-row: 1; width: 11px; height: 11px; border-radius: 50%; background: var(--surface); border: 2px solid var(--border-input); justify-self: center; position: relative; z-index: 1; }
  .verlauf__zeile { display: contents; }
  .verlauf__zeile > .mailref { grid-column: 2; grid-row: 1; }
  .verlauf__wer { grid-column: 3; grid-row: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .verlauf__wer b { color: var(--text); font-weight: 500; }
  .diese { grid-column: 4; grid-row: 1; font-size: var(--fs-12); font-weight: 600; color: var(--accent-text); white-space: nowrap; }
  .verlauf__zeit { grid-column: 5; grid-row: 1; color: var(--text-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
  .verlauf__anh { display: inline-flex; align-items: center; gap: 2px; color: var(--text-3); font-variant-numeric: tabular-nums; }
  .verlauf__anh .icon { color: var(--text-3); }
  .verlauf__eintrag a[aria-current="true"] { background: var(--accent-subtle); color: var(--text); box-shadow: inset 2px 0 0 var(--accent-line); }
  .verlauf__eintrag a[aria-current="true"] .verlauf__knoten { border-color: var(--accent-line); background: var(--accent-line); }
  .verlauf__mehr { margin-top: 4px; }
  .verlauf--schmal .verlauf__eintrag a { grid-template-columns: 22px minmax(0, 1fr); row-gap: 2px; align-items: start; padding: 7px 8px 7px 10px; }
  .verlauf--schmal .verlauf__knoten { margin-top: 4px; }
  .verlauf--schmal .verlauf__zeile { display: flex; flex-wrap: wrap; grid-column: 2; grid-row: 1; align-items: center; gap: 2px 8px; min-width: 0; }
  .verlauf--schmal .verlauf__wer { grid-column: 2; grid-row: 2; }
  .verlauf--schmal .diese { margin-left: auto; }
  @container (max-width: 520px) {
    .verlauf__eintrag a { grid-template-columns: 22px minmax(0, 1fr); row-gap: 2px; align-items: start; padding: 7px 8px 7px 10px; }
    .verlauf__knoten { margin-top: 4px; }
    .verlauf__zeile { display: flex; flex-wrap: wrap; grid-column: 2; grid-row: 1; align-items: center; gap: 2px 8px; min-width: 0; }
    .verlauf__wer { grid-column: 2; grid-row: 2; }
    .diese { margin-left: auto; }
  }

  /* ── Mail and attachment page ── */
  .seitenkopf h1.h1-mail { font-size: var(--fs-20); line-height: 28px; letter-spacing: -0.014em; gap: 4px 10px; }
  .h1-mail__betreff { min-width: 0; overflow-wrap: anywhere; }
  .mailseite, .anhangseite { min-width: 0; }
  .zweispaltig__haupt { display: grid; gap: 16px; align-content: start; }
  .zweispaltig__haupt > .papier { max-width: none; }
  .seite { --papier-rand: var(--pad); }
  .mailkarte { min-width: 0; }
  .kopfdaten--karte { padding: 14px 16px; grid-template-columns: 72px minmax(0, 1fr); font-size: var(--fs-14); gap: 6px 12px; }
  .kopfdaten--karte dt { font-size: var(--fs-13); }
  .mailkarte__fuss { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; padding: 6px 16px; border-top: 1px solid var(--border); background: var(--surface-2); }
  .mailkarte__fuss .bezug { flex: 1 1 260px; }
  .mailkarte__fuss .mailtechnik { margin-left: auto; }
  .mailkarte__fuss .mailtechnik[open] { flex-basis: 100%; }
  /* narrow: "Technische Angaben" below the relation line starts at the same edge, not alone on the right */
  @container (max-width: 640px) { .mailkarte__fuss .mailtechnik { margin-left: 0; } }
  .mailkarte__fuss .klappe > summary { margin: 0; }
  .seitenliste a.zeile { font-variant-numeric: tabular-nums; }
  .aus-mail { display: grid; gap: 4px; }
  .aus-mail .seitenspalte__leer { padding: 0 10px; }
  .mailseite__sprung { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; justify-content: center; text-align: left; margin-top: 8px; }
  .mailseite__sprung .feld-gruppe { width: min(220px, 100%); }
  .anhangseite__weiter { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
  /* E's transition scaffold uses :where(); this keeps the side headings of the reading pages as spec §3.6 says */
  .zweispaltig__seite.seitenspalte h2 { border-bottom: 0; padding-bottom: 0; }

  @media (forced-colors: active) {
    .verlauf__eintrag a[aria-current="true"], :is(.bezuege, .seitenspalte) .vorgangsliste a.zeile[aria-current="true"] { outline: 2px solid Highlight; outline-offset: -2px; }
    .papier { border: 1px solid CanvasText; }
  }
}

/* ── Print (spec §8): the mail and the attachment print as documents – complete, without controls; the page
      rulers stay, the bar that follows the page goes ── */
@media print {
  @layer print {
    .mailansicht { padding: 0; }
    .anhang-leiste, .dateizeile__aktionen, .mailseite__sprung, .fundort .hinweis__aktion { display: none; }
    .dokument { max-width: none; font-size: 11pt; line-height: 1.5; }
    .dokument > p + p, .dokument > p + .seitenlineal + p { margin-top: 0.75em; }
    .seitenlineal { break-after: avoid; margin: 1.2em 0 0.6em; }
    .zitatverlauf { break-before: auto; }
    .markiert { break-inside: avoid; }
    .kopfdaten--karte { padding: 0 0 3mm; }
    .mailkarte__fuss { display: block; padding: 1.5mm 0; background: none; }
    .mailkarte__fuss .mailtechnik > summary { display: block; margin-top: 1.5mm; }
    .kopfdaten--technik { padding-left: 0; }
    .verlauf__eintrag a { padding: 1mm 0; min-height: 0; }
    .verlauf::before, .verlauf__knoten { display: none; }
    .verlauf__eintrag a { grid-template-columns: auto minmax(0, 1fr) auto auto; }
    .dateien { border: 0; }
    .dateizeile { padding: 1mm 0; min-height: 0; }
  }
}
