/* Export: Dialog, Bericht („Papier“) und Druck. Gehört zu public/export.js.
   Der Bericht ist bewusst hell, auch in der dunklen App: er wird gedruckt,
   als PDF gespeichert und als HTML-Datei weitergegeben. Alle Farben hängen an
   den --xr-*-Variablen von .xr-paper, damit die HTML-Datei ohne app-Styles
   (styles.css) eigenständig aussieht. */

/* ---------- Einstiegs-Buttons in den Listen ---------- */
.export-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 34px;
  padding: 0 0.8rem;
  border: 1px solid var(--border, #2e2e2e);
  border-radius: var(--radius-btn, 10px);
  background: transparent;
  color: var(--text-muted, #b0b0b0);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: var(--transition-ui);
}
/* Wie der Verlauf-Knopf daneben (.btn-view-log-history): Hover nur mit Maus, beim Drücken einsinken. */
html:not(.using-touch) .export-btn:hover { color: var(--text, #e8e8e8); border-color: rgba(255, 255, 255, 0.2); }
.export-btn:active {
  --press-opacity: 1; /* eigener Druckzustand statt der generischen Dimmung */
  transform: scale(0.97);
  background: rgba(255, 255, 255, 0.06);
  transition-duration: var(--motion-xs);
}
.export-btn-icon:active { transform: scale(0.94); }
.export-btn:focus-visible { outline: 2px solid var(--accent, #4caf82); outline-offset: 2px; }
/* Wie der Verlauf-Knopf daneben (.btn-view-log-history): 44 × 44, auch mit Maus. */
.export-btn-icon { width: var(--touch-target, 44px); min-height: var(--touch-target, 44px); padding: 0; justify-content: center; }
@media (pointer: coarse) {
  .export-btn { min-height: 44px; }
  .export-btn-icon { width: 44px; }
  /* The touch sizes of the dialog and report controls sit at the end of the file:
     their base rules are further down and, at equal specificity, would win here. */
}
/* Busy (setBtnBusy): the spinner of an icon-only button is centred, not pushed by the label gap. */
.export-btn-icon[aria-busy="true"] .entry-pending-spin { margin: 0; }

.export-inline { display: flex; justify-content: flex-end; margin: 0 0 0.6rem; }
/* Leihnehmer-Aktiv ist ab 1100 px ein Raster (styles.css): ohne diese Zeile wurde die Export-Zeile
   eine eigene, kartenhohe Spalte (Knopf 88×1250 px links neben den Karten). */
.export-inline-flow { grid-column: 1 / -1; align-self: start; }
#active-section { position: relative; }
@media (min-width: 700px) {
  /* Desktop: rechts neben der Überschrift statt in einer eigenen Zeile. */
  #active-section > .export-inline { position: absolute; top: 4px; right: 0; margin: 0; z-index: 1; }
}
.section-title-row { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 1rem; }
.section-title-row .section-title { margin-bottom: 0; }
.loan-card-header-date-wrap { display: flex; align-items: center; gap: 0.5rem; flex: none; }
/* Leihgeber-Karte mit Export- UND Verlauf-Knopf (Admin): Datum + zwei 44-px-Knöpfe sind ~175 px breit,
   die Platzreserve neben dem Namen (7.5rem, styles.css) reicht auf 320-380 px nicht — das Datum lief
   über die Vertrauens-Pille. Dort stehen die drei als eigene Zeile über dem Kopf (wie .history-card-actions). */
@media (max-width: 380px) {
  .loan-card-lender:has(.loan-card-header-meta .export-btn):has(.loan-card-header-meta .btn-view-log-history) .loan-card-header-meta {
    position: static; order: -1; flex: 1 1 100%; justify-content: flex-end;
  }
  .loan-card-lender:has(.loan-card-header-meta .export-btn):has(.loan-card-header-meta .btn-view-log-history) .loan-card-header-meta .loan-date { margin-right: auto; }
  .loan-card-lender:has(.loan-card-header-meta .export-btn):has(.loan-card-header-meta .btn-view-log-history) .loan-card-heading > .loan-kicker:first-child {
    padding-right: 0; min-height: 0;
  }
}

/* ---------- Dialog ---------- */
.xd-card { max-width: var(--modal-w-md, 540px); }
.xd-card form { padding-bottom: 0.5rem; }
/* Bottom sheet: the last row must clear the iPhone home indicator. */
/* (Safe-Area trägt jetzt die Fußleiste selbst.) */
.xd-intro { margin: 0.25rem 0 1.1rem; font-size: 0.9rem; line-height: 1.5; }
.xd-field { border: 0; margin: 0 0 1rem; padding: 0; min-width: 0; }
.xd-field legend { padding: 0; margin-bottom: 0.45rem; font-size: 0.78rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted, #b0b0b0); }
.xd-seg { display: flex; gap: 0.35rem; padding: 0.25rem; border-radius: 12px; background: var(--surface2, #242424); border: 1px solid var(--border, #2e2e2e); }
.xd-seg-item { flex: 1; position: relative; cursor: pointer; }
.xd-seg-item input { position: absolute; inset: 0; opacity: 0; cursor: pointer; margin: 0; }
.xd-seg-item span { display: flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 0.5rem; border-radius: 9px; font-size: 0.9rem; font-weight: 600; color: var(--text-muted, #b0b0b0); text-align: center; transition: background var(--motion-fast) var(--ease-standard), color var(--motion-fast) var(--ease-standard), transform var(--motion-xs) var(--ease-standard); }
html:not(.using-touch) .xd-seg-item input:not(:checked):hover + span { background: rgba(255, 255, 255, 0.06); color: var(--text, #e8e8e8); }
.xd-seg-item input:active + span { transform: scale(0.97); }
.xd-seg-item input:not(:checked):active + span,
html:not(.using-touch) .xd-seg-item input:not(:checked):active + span { background: rgba(255, 255, 255, 0.1); color: var(--text, #e8e8e8); } /* 2. Selektor: sonst gewinnt die Hover-Regel oben gegen den Druck */
.xd-seg-item input:checked + span { background: var(--accent-btn, #3a7f61); color: #fff; }
/* Gleitender Indikator (app.js syncSegIndicator, SEG_BAR_SELECTOR): ein ::before wandert zur gewählten Option bzw. Ansicht. */
.xd-seg, .xr-view { position: relative; isolation: isolate; }
.xd-seg.has-seg-indicator::before { background-color: var(--accent-btn, #3a7f61); border-radius: 9px; }
.xd-seg.has-seg-indicator .xd-seg-item input:checked + span { background: transparent; }
.xr-view.has-seg-indicator::before { background-color: var(--accent-btn, #3a7f61); border-radius: 8px; }
.xr-view.has-seg-indicator > .xr-view-btn[aria-pressed="true"] { background: transparent; }
.xd-seg-item input:focus-visible + span { outline: 2px solid var(--accent, #4caf82); outline-offset: 1px; }
.xd-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.xd-row.hidden, .xd-check.hidden, .xd-field.hidden { display: none; }
@media (max-width: 480px) { .xd-row { grid-template-columns: 1fr; gap: 0; } }
.xd-hint { display: block; margin: -0.25rem 0 1rem; }
.xd-options .xd-hint, .xd-csv .xd-hint { margin: 0; }
/* Dialog für eine einzelne Leihe: nur „Zusätzlich“ (Chat, Notizen) und der Bericht-Knopf. */
#export-form.is-single > fieldset:not(.xd-options), #export-form.is-single > .xd-row, #export-form.is-single > #xd-period-hint, #export-form.is-single .xd-csv-opts, #modal-export.is-single .xd-csv { display: none; }
.xd-csv .xd-csv-hint { flex-basis: 100%; }
.xd-options { display: grid; gap: 0.5rem; }
.xd-check { display: flex; align-items: center; gap: 0.6rem; min-height: 40px; cursor: pointer; font-size: 0.92rem; }
.xd-check input { width: 20px; height: 20px; accent-color: var(--accent, #4caf82); flex: none; }
/* B4: Fußleiste = .modal-actions (angeheftet, Safe-Area, Hintergrund wie überall); hier nur das Raster:
   „Bericht ansehen“ über die ganze Breite, darunter Beschriftung und die zwei CSV-Knöpfe. */
.modal-card .xd-actions { display: grid; gap: 0.5rem; }
.xd-actions > .xd-main { width: 100%; }
.xd-csv-opts { display: grid; gap: 0.6rem; margin: 0 0 1rem; }
.xd-main { width: 100%; min-height: 46px; display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; }
.xd-csv { display: grid; grid-template-columns: 1fr 1fr; align-items: center; gap: 0.4rem 0.5rem; }
.xd-csv-label { grid-column: 1 / -1; font-size: 0.8rem; line-height: 1.2; color: var(--text-muted, #b0b0b0); }
.xd-csv .btn-secondary { min-height: 40px; }
/* While one request runs, the other buttons of the dialog are visibly parked (same idea as .modal-actions in styles.css). */
.modal-card[data-modal-busy="true"] .xd-actions button:not([aria-busy="true"]) { opacity: var(--dim-disabled, 0.5); filter: saturate(0.6); pointer-events: none; }
.xd-csv-format { flex-basis: 100%; display: grid; gap: 0.25rem; font-size: 0.82rem; color: var(--text-muted, #b0b0b0); }
/* Wie die Auswahlfelder darüber (.form-group select in styles.css): ohne das stand hier das nackte System-Select. */
.xd-csv-format select { width: 100%; min-height: 44px; padding: 0.55rem 0.9rem; background: var(--surface2, #242424); border: 1px solid var(--border-input, #6f6f6f); border-radius: 8px; color: var(--text, #e8e8e8); font: inherit; font-size: 1rem; }
.xd-csv-format select:focus-visible { outline: 2px solid var(--accent, #4caf82); outline-offset: -2px; }
@media (pointer: coarse) { .xd-seg-item span, .xd-check, .xd-csv .btn-secondary { min-height: 44px; } }
/* Querformat (Höhe bis 430 px): zwei Zeilen fräßen die halbe Höhe – die Fußleiste bleibt angeheftet, aber einzeilig
   (drei Knöpfe nebeneinander, die Beschriftung „Als Tabelle (CSV):“ nur noch für Screenreader). */
@media (max-height: 430px) {
  .modal-card .xd-actions { grid-template-columns: 1.3fr 1fr 1fr; align-items: stretch; }
  .xd-actions > .xd-csv { display: contents; }
  .xd-actions .xd-csv-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .xd-actions > .xd-main { min-height: 44px; }
}

/* ---------- Bericht-Fenster ---------- */
.xr-card {
  max-width: min(1100px, 100vw);
  width: 100%;
  height: min(96dvh, 1200px);
  max-height: none;
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.xr-toolbar {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.65rem 1rem; flex: none;
  background: var(--surface, #1a1a1a);
  border-bottom: 1px solid var(--border, #2e2e2e);
}
/* Titel wie in den anderen Fenster-Köpfen (.modal-card h2). */
.xr-toolbar-title { font-size: 1.34rem; font-weight: 800; letter-spacing: -0.03em; line-height: 1.2; margin-right: auto; }
.xr-toolbar-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; justify-content: flex-end; }
.xr-close { margin-left: 0; flex: none; } /* keep position:relative: its ::after tap area hangs on it */
.xr-tool { white-space: nowrap; width: auto; flex: none; display: inline-flex; align-items: center; gap: 0.4rem; min-height: 36px; margin: 0; padding: 0 0.85rem; list-style: none; cursor: pointer; }
.xr-tool::-webkit-details-marker { display: none; }
.xr-view { display: inline-flex; padding: 0.2rem; gap: 0.2rem; border-radius: 10px; background: var(--surface2, #242424); border: 1px solid var(--border, #2e2e2e); }
.xr-view.hidden, .xr-tool.hidden { display: none; }
.xr-view-btn { border: 0; background: transparent; color: var(--text-muted, #b0b0b0); font: inherit; font-size: 0.85rem; font-weight: 600; min-height: 32px; padding: 0 0.7rem; border-radius: 8px; cursor: pointer; touch-action: manipulation; transition: background var(--motion-fast) var(--ease-standard), color var(--motion-fast) var(--ease-standard), transform var(--motion-xs) var(--ease-standard); }
html:not(.using-touch) .xr-view-btn[aria-pressed="false"]:hover { background: rgba(255, 255, 255, 0.06); color: var(--text, #e8e8e8); }
.xr-view-btn:active { --press-opacity: 1; transform: scale(0.96); }
.xr-view-btn[aria-pressed="true"] { background: var(--accent-btn, #3a7f61); color: #fff; }
.xr-menu { position: relative; }
.xr-menu-list { position: absolute; right: 0; top: calc(100% + 6px); z-index: 5; min-width: 230px; display: grid; padding: 0.35rem; border-radius: 12px; background: var(--surface2, #242424); border: 1px solid var(--border, #2e2e2e); box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5); }
.xr-menu-list button { text-align: left; border: 0; background: transparent; color: var(--text, #e8e8e8); font: inherit; font-size: 0.9rem; padding: 0.7rem 0.8rem; min-height: 44px; border-radius: 8px; cursor: pointer; touch-action: manipulation; transition: background var(--motion-fast) var(--ease-standard), transform var(--motion-xs) var(--ease-standard); }
/* Die „Teilen“-Einträge (nur wo die Web-Share-API Dateien kann) stehen abgesetzt unter den Speicher-Einträgen. */
.xr-menu-list .xr-menu-share { margin-top: 0.3rem; position: relative; }
.xr-menu-list .xr-menu-share::before { content: ''; position: absolute; left: 0.5rem; right: 0.5rem; top: -0.2rem; border-top: 1px solid var(--border, #2e2e2e); }
html:not(.using-touch) .xr-menu-list button:hover, .xr-menu-list button:focus-visible { background: rgba(255, 255, 255, 0.07); outline: none; }
.xr-menu-list button:active,
html:not(.using-touch) .xr-menu-list button:active { --press-opacity: 1; background: rgba(255, 255, 255, 0.12); transform: scale(0.98); } /* 2. Selektor: sonst gewinnt :hover gegen den Druck */
.xr-scroll { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; background: #14181a; padding: 1.25rem; }
/* Touch: Schließen-Knopf und Werkzeuge gleich hoch (44), sonst steht das ✕ (36) neben 44-px-Knöpfen. */
@media (pointer: coarse) {
  .xr-tool { min-height: 44px; }
  .xr-view-btn { min-height: 44px; }
  .xr-close { width: 44px; height: 44px; }
  .xr-close::after { inset: 0; }
}
/* The card clips (overflow: hidden) and the region fills it, so an outside ring would be cut off: draw it inside. */
.xr-scroll:focus-visible { outline-offset: -3px; }
.xr-menu-list button:focus-visible { outline: 2px solid var(--accent, #4caf82); outline-offset: -2px; }

@media (max-width: 820px) {
  .xr-card { height: 100dvh; max-height: none; border-radius: 0; border-top-width: 0; }
  /* Full screen for real: the generic overlay padding (16 px, or 60 px on top for a sheet) let the 100dvh card
     stick out and put the toolbar under the status bar / notch of an installed iPhone app. */
  #modal-export-report.modal-overlay { padding: 0 env(safe-area-inset-right, 0px) 0 env(safe-area-inset-left, 0px); align-items: stretch; }
  #modal-export-report .xr-card { height: 100%; }
  .xr-scroll { padding: 0; background: #fff; }
  .xr-scroll:focus-visible { outline-color: #1c7a53; }
  /* Zeile 1: Schließen, Auswahl, Drucken (füllt), Mehr. Zeile 2: Umschalter. */
  .xr-toolbar { padding: 0.5rem 0.65rem; gap: 0.45rem; flex-wrap: wrap; align-items: center; }
  .xr-toolbar-title { display: none; }
  .xr-toolbar-actions { display: contents; }
  .xr-close { order: 1; }
  .xr-tool[data-xr="change"] { order: 2; }
  .xr-tool[data-xr="print"] { order: 3; flex: 1; justify-content: center; }
  .xr-menu { order: 4; }
  .xr-view { order: 5; width: 100%; }
  .xr-view-btn { flex: 1; }
  .xr-tool span { display: none; }
  .xr-tool[data-xr="print"] span { display: inline; }
  .xr-tool { padding: 0 0.7rem; }
  .xr-menu-list { right: 0; }
}

/* ---------- Papier ---------- */
.xr-paper {
  --xr-ink: #18211e; --xr-muted: #5b6863; --xr-line: #dde4e0; --xr-soft: #f3f6f4; --xr-soft2: #e9efec;
  --xr-accent: #1c7a53; --xr-accent-soft: #e2f3ea; --xr-out: #3566b0; --xr-bad: #b0352c; --xr-bad-soft: #fbe9e7; --xr-warn: #8a5f00;
  box-sizing: border-box;
  max-width: 900px; margin: 0 auto;
  background: #fff; color: var(--xr-ink);
  padding: 2.25rem 2.5rem 2rem;
  border-radius: 6px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  text-align: left;
  overflow-wrap: anywhere; /* a long name or purpose without spaces must wrap, not push the report wider than a 320 px screen */
}
.xr-paper *, .xr-paper *::before, .xr-paper *::after { box-sizing: border-box; }
/* The app's light-green ring is 2.6:1 on white; the report's own green is 5.3:1. */
.xr-paper :focus-visible { outline: 2px solid var(--xr-accent); outline-offset: 2px; }
.xr-head h1:focus { outline: none; } /* focused by script when the report opens, not a control */
.xr-paper :where(h1, h2, h3, p, ol, ul, dl, dd) { margin: 0; padding: 0; }
.xr-paper :where(ol, ul) { list-style: none; }
.xr-paper :where(svg) { display: block; }
.xr-paper :where(small) { display: block; font-size: 0.78em; color: var(--xr-muted); font-weight: 400; }
.xr-muted { color: var(--xr-muted); }
.xr-bad { color: var(--xr-bad); }
.xr-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (max-width: 820px) { .xr-paper { border-radius: 0; box-shadow: none; padding: 1.25rem 1rem calc(1.5rem + env(safe-area-inset-bottom, 0px)); } }

.xr-head { display: flex; justify-content: space-between; gap: 1.5rem; align-items: flex-start; padding-bottom: 1.1rem; border-bottom: 2px solid var(--xr-ink); margin-bottom: 1.25rem; }
.xr-eyebrow { font-size: 0.75rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--xr-accent); }
.xr-head h1 { font-size: 1.75rem; line-height: 1.15; margin: 0.15rem 0 0.6rem; letter-spacing: -0.01em; }
.xr-stamp { font-size: 0.8rem; color: var(--xr-muted); text-align: right; flex: none; }
.xr-stamp strong { color: var(--xr-ink); font-weight: 600; }
@media (max-width: 560px) { .xr-head { flex-direction: column; gap: 0.75rem; } .xr-stamp { text-align: left; } .xr-head h1 { font-size: 1.4rem; } }

.xr-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.xr-chip { display: inline-block; padding: 0.15rem 0.6rem; border-radius: 999px; background: var(--xr-soft2); color: var(--xr-ink); font-size: 0.78rem; font-weight: 600; white-space: nowrap; }
.xr-chips .xr-chip { max-width: 100%; white-space: normal; } /* nowrap kept a chip with a long person name wider than the screen */
.xr-chip.st-active { background: var(--xr-accent-soft); color: var(--xr-accent); }
.xr-chip.st-closed { background: var(--xr-soft2); color: var(--xr-muted); }
.xr-chip.st-rejected, .xr-chip.st-withdrawn, .xr-chip.st-cancelled, .xr-chip.is-bad { background: var(--xr-bad-soft); color: var(--xr-bad); }

.xr-h2 { font-size: 1.05rem; text-transform: uppercase; letter-spacing: 0.08em; margin: 1.6rem 0 0.9rem; padding-bottom: 0.4rem; border-bottom: 1px solid var(--xr-line); display: flex; align-items: baseline; gap: 0.6rem; }
.xr-overview > .xr-h2 { margin-top: 0; }
.xr-count { font-size: 0.75rem; font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--xr-muted); }

.xr-note { display: flex; gap: 0.6rem; align-items: center; padding: 0.6rem 0.85rem; margin-bottom: 0.6rem; border-radius: 8px; background: var(--xr-soft); font-size: 0.9rem; }
.xr-note svg { flex: none; color: var(--xr-muted); }
.xr-note.is-bad { background: var(--xr-bad-soft); color: var(--xr-bad); }
.xr-note.is-bad svg { color: var(--xr-bad); }
/* Hinweis statt Fehler (Kürzung, übersprungene Leihen): Amber mit Icon und Rand – rot bleibt für „überfällig“. 5,3 : 1 auf dem Grund. */
.xr-note.is-warn { background: #fdf6e3; color: var(--xr-warn); border: 1px solid #e6cf94; }
.xr-note.is-warn svg { color: var(--xr-warn); }

/* Kontoauszug mit einer Person: Saldo in Worten, bei zwei Richtungen mit Netto-Zeile. */
.xr-balance { align-items: flex-start; }
.xr-balance svg { margin-top: 0.2rem; }
.xr-balance-line { display: block; }
.xr-balance.has-net .xr-balance-line:last-of-type { margin-top: 0.15rem; padding-top: 0.25rem; border-top: 1px solid var(--xr-line); }
.xr-balance-stand { display: block; margin-top: 0.25rem; }
.xr-side-block + .xr-side-block { margin-top: 1.25rem; }
.xr-side-title { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--xr-muted); margin-bottom: 0.5rem; }
.xr-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.6rem; }
.xr-kpi { padding: 0.8rem 0.9rem; border-radius: 10px; background: var(--xr-soft); display: grid; gap: 0.1rem; min-width: 0; }
.xr-kpi-label { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; color: var(--xr-muted); }
.xr-kpi strong { font-size: 1.35rem; line-height: 1.2; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.xr-kpi-sub { font-size: 0.78rem; color: var(--xr-muted); }
.xr-kpi.is-key { background: var(--xr-ink); color: #fff; }
.xr-kpi.is-key .xr-kpi-label, .xr-kpi.is-key .xr-kpi-sub { color: rgba(255, 255, 255, 0.72); }
.xr-kpi.is-good strong { color: var(--xr-accent); }
@media (max-width: 640px) { .xr-kpis { grid-template-columns: 1fr 1fr; } .xr-kpi strong { font-size: 1.15rem; } }

.xr-progress { height: 8px; border-radius: 99px; background: var(--xr-soft2); overflow: hidden; margin-top: 0.7rem; }
.xr-progress span { display: block; height: 100%; background: var(--xr-accent); border-radius: 99px; }
.xr-progress.is-slim { height: 6px; margin-top: 0.55rem; }

.xr-facts { display: flex; flex-wrap: wrap; gap: 0.35rem 1.1rem; margin-top: 0.9rem; font-size: 0.86rem; color: var(--xr-muted); }
.xr-facts strong { color: var(--xr-ink); }

.xr-panels { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1.1rem; }
.xr-panel { border: 1px solid var(--xr-line); border-radius: 10px; padding: 0.9rem 1rem; min-width: 0; break-inside: avoid; }
.xr-panel h3 { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--xr-muted); margin-bottom: 0.6rem; }
@media (max-width: 720px) { .xr-panels { grid-template-columns: 1fr; } }
.xr-table { width: 100%; border-collapse: collapse; }
.xr-table th, .xr-table td { padding: 0.45rem 0; text-align: left; vertical-align: middle; border-top: 1px solid var(--xr-line); font-weight: 400; }
.xr-table tr:first-child th, .xr-table tr:first-child td { border-top: 0; }
.xr-table th { font-weight: 600; padding-right: 0.6rem; overflow-wrap: anywhere; }
.xr-num { text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600 !important; }
.xr-bar-cell { width: 28%; padding: 0 0.6rem !important; }
.xr-bar { height: 8px; }
.xr-bar-total { display: block; height: 100%; min-width: 4px; background: var(--xr-soft2); border-radius: 99px; overflow: hidden; }
.xr-bar-total i { display: block; height: 100%; background: var(--xr-accent); }
.xr-bar-legend { margin-top: 0.4rem; font-size: 0.75rem; color: var(--xr-muted); }
.xr-more { margin-top: 0.5rem; font-size: 0.78rem; color: var(--xr-muted); }
.xr-more-btn { background: none; border: 0; padding: 0.35rem 0; min-height: 36px; font: inherit; color: inherit; text-decoration: underline; cursor: pointer; touch-action: manipulation; transition: color var(--motion-fast) var(--ease-standard); }
html:not(.using-touch) .xr-more-btn:hover { color: var(--xr-muted, #5b6863); }
/* „Kontoauszug“ unter dem Namen einer Person (Personen-Tabelle der Übersicht): Text-Knopf wie „Alle Personen anzeigen“. */
.xr-stmt-btn { display: block; min-height: 28px; padding: 0.1rem 0; font-size: 0.78rem; font-weight: 600; color: var(--xr-accent); text-decoration: none; transition: color var(--motion-fast) var(--ease-standard), transform var(--motion-xs) var(--ease-standard); }
html:not(.using-touch) .xr-stmt-btn:hover { color: var(--xr-ink); text-decoration: underline; }
.xr-stmt-btn:active { transform: scale(0.97); }
.xr-stmt-btn:focus-visible { outline: 2px solid var(--xr-accent); outline-offset: 2px; border-radius: 4px; }
.xr-table:not(.is-all) .xr-extra { display: none; }
.xr-scope-note, .xr-loan-period { margin: 0.5rem 0 0; font-size: 0.82rem; }
.xr-atts { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.4rem; }
.xr-atts a { display: block; min-width: 56px; min-height: 40px; background: var(--xr-soft); border-radius: 6px; overflow: hidden; border: 1px solid var(--xr-line); line-height: 0; }
.xr-atts img { display: block; max-height: 96px; max-width: 160px; width: auto; height: auto; object-fit: cover; }
.xr-chart { width: 100%; height: auto; }
.xr-grid { stroke: var(--xr-line); stroke-width: 1; }
.xr-axis { fill: var(--xr-muted); font-size: 11px; paint-order: stroke; stroke: #fff; stroke-width: 3px; stroke-linejoin: round; } /* white halo: the value labels sit over the bars */
.xr-bar-out { fill: var(--xr-out); background: var(--xr-out); }
.xr-bar-in { fill: var(--xr-accent); background: var(--xr-accent); }
/* Monat antippen / darüberfahren (export.js pickMonth): Band hinter den Balken + Werte unter dem Diagramm. */
.xr-chart { touch-action: pan-y; cursor: pointer; } /* horizontales Wischen wählt Monate, senkrechtes scrollt weiter */
.xr-band { fill: transparent; transition: fill var(--motion-fast) var(--ease-standard); }
.xr-slot.is-sel .xr-band { fill: var(--xr-soft2); }
.xr-chart-info { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.15rem 0.9rem; min-height: 2.6em; margin-top: 0.5rem; font-size: 0.84rem; }
.xr-chart-hint { font-size: 0.78rem; color: var(--xr-muted); }
.xr-legend { display: flex; gap: 1rem; margin-top: 0.5rem; font-size: 0.78rem; color: var(--xr-muted); }
.xr-legend i, .xr-chart-info i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 0.35rem; }

/* ---------- Leihen + Zeitleiste ---------- */
.xr-loan { border: 1px solid var(--xr-line); border-radius: 12px; padding: 1rem 1.1rem 0.6rem; margin-bottom: 1.1rem; }
.xr-loan-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; margin-bottom: 0.5rem; }
.xr-loan-who { font-size: 0.8rem; color: var(--xr-muted); }
.xr-loan-who strong { color: var(--xr-ink); }
.xr-loan-head h3 { font-size: 1.15rem; line-height: 1.25; overflow-wrap: anywhere; }
.xr-loan-span { font-size: 0.8rem; color: var(--xr-muted); text-align: right; white-space: nowrap; }
@media (max-width: 480px) { .xr-loan-head { flex-direction: column; gap: 0.25rem; } .xr-loan-span { text-align: left; white-space: normal; } }
.xr-loan-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; margin-top: 0.8rem; }
.xr-loan-stats div { min-width: 0; }
.xr-loan-stats dt { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--xr-muted); font-weight: 700; }
.xr-loan-stats dd { font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.xr-loan-stats .is-key dd { color: var(--xr-ink); }
@media (max-width: 560px) { .xr-loan-stats { grid-template-columns: 1fr 1fr; } }
.xr-loan-facts { margin-top: 0.6rem; font-size: 0.82rem; color: var(--xr-muted); }
.xr-loan-nocount { margin-top: 0.7rem; font-size: 0.88rem; }
.xr-sign-note { margin: -0.3rem 0 0.9rem; font-size: 0.8rem; color: var(--xr-muted); }
.xr-sign-note .xr-amt { font-size: 1em; }

/* Leihen im Überblick: Sprungmarken zu den Karten (ab 8 Leihen). */
.xr-toc { margin: 0 0 1rem; border: 1px solid var(--xr-line); border-radius: 10px; }
.xr-toc summary { display: flex; align-items: center; min-height: 40px; padding: 0 0.9rem; font-size: 0.85rem; font-weight: 700; cursor: pointer; list-style: none; touch-action: manipulation; transition: background var(--motion-fast) var(--ease-standard); border-radius: 10px; }
.xr-toc summary::-webkit-details-marker { display: none; }
.xr-toc summary::after { content: "▾"; margin-left: auto; padding-left: 0.6rem; color: var(--xr-muted); transition: transform var(--motion-fast) var(--ease-standard); }
.xr-toc[open] summary::after { transform: rotate(180deg); }
html:not(.using-touch) .xr-toc summary:hover { background: var(--xr-soft); }
.xr-toc summary:active { background: var(--xr-soft2); }
.xr-toc ol { max-height: min(50vh, 22rem); overflow: auto; border-top: 1px solid var(--xr-line); }
.xr-toc li + li { border-top: 1px solid var(--xr-line); }
.xr-toc a { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.1rem 0.8rem; min-height: 44px; align-items: center; padding: 0.35rem 0.9rem; color: inherit; text-decoration: none; transition: background var(--motion-fast) var(--ease-standard); }
html:not(.using-touch) .xr-toc a:hover { background: var(--xr-soft); }
.xr-toc a:active { background: var(--xr-soft2); }
.xr-toc-name { font-weight: 600; font-size: 0.88rem; }
.xr-toc-meta { font-size: 0.78rem; color: var(--xr-muted); }

.xr-inst { margin-top: 0.8rem; padding: 0.7rem 0.8rem; border-radius: 10px; background: var(--xr-soft); break-inside: avoid; }
.xr-inst-head { font-size: 0.8rem; font-weight: 600; margin-bottom: 0.5rem; }
.xr-rates { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 0.35rem; }
.xr-rates li { display: grid; justify-items: center; min-width: 0; padding: 0.3rem 0.25rem; border-radius: 8px; background: #fff; border: 1px solid var(--xr-line); line-height: 1.25; }
.xr-rates b { font-size: 0.85rem; }
.xr-rates span { font-size: 0.72rem; color: var(--xr-muted); }
.xr-rates em { font-style: normal; font-size: 0.72rem; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; } /* Betrag sichtbar – der title-Tooltip geht auf Touch nicht */
.xr-rates small { font-size: 0.66rem; }
.xr-rates .rate-paid { background: var(--xr-accent-soft); border-color: #bfe3cf; }
.xr-rates .rate-paid small { color: var(--xr-accent); }
.xr-rates .rate-overdue { background: var(--xr-bad-soft); border-color: #f0c2bd; }
.xr-rates .rate-overdue small { color: var(--xr-bad); }
.xr-rates .rate-due, .xr-rates .rate-soon { background: #fdf6e3; border-color: #e6cf94; }
.xr-rates .rate-due small, .xr-rates .rate-soon small { color: var(--xr-warn); font-weight: 600; }
.xr-rates .rate-partial { border-style: dashed; border-color: var(--xr-accent); }
.xr-rates .rate-waived { background: var(--xr-soft2); }

.xr-timeline { position: relative; margin-top: 1rem; }
.xr-loan.is-folded .xr-timeline { display: none; }
.xr-tl-bar { margin-top: 0.6rem; }
.xr-tl-toggle { display: inline-flex; align-items: center; gap: 0.4rem; max-width: 100%; min-height: 36px; padding: 0 0.8rem; border: 1px solid var(--xr-line); border-radius: 999px; background: var(--xr-soft); color: var(--xr-ink); font: inherit; font-size: 0.82rem; font-weight: 600; text-align: left; cursor: pointer; touch-action: manipulation; transition: background var(--motion-fast) var(--ease-standard), transform var(--motion-xs) var(--ease-standard); }
.xr-tl-toggle svg { flex: none; transition: transform var(--motion-fast) var(--ease-standard); }
.xr-tl-toggle[aria-expanded="true"] svg { transform: rotate(180deg); }
html:not(.using-touch) .xr-tl-toggle:hover { background: var(--xr-soft2); }
.xr-tl-toggle:active { --press-opacity: 1; background: var(--xr-soft2); transform: scale(0.98); }
.xr-loan:focus { outline: none; } /* Sprungziel (Leihen im Überblick), kein Bedienelement */
.xr-timeline::before { content: ""; position: absolute; left: 96px; top: 0.6rem; bottom: 0.6rem; width: 2px; background: var(--xr-line); }
.xr-ev { display: grid; grid-template-columns: 82px 30px minmax(0, 1fr) auto; column-gap: 0; align-items: start; padding: 0.35rem 0 0.55rem; break-inside: avoid; }
.xr-ev time { font-size: 0.78rem; font-weight: 600; text-align: right; padding-top: 0.15rem; font-variant-numeric: tabular-nums; }
.xr-ev time small { font-weight: 400; }
.xr-dot { justify-self: center; margin-top: 0.4rem; width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 3px solid var(--xr-muted); position: relative; z-index: 1; }
.xr-ev.tone-out .xr-dot { border-color: var(--xr-out); }
.xr-ev.tone-in .xr-dot, .xr-ev.tone-good .xr-dot { border-color: var(--xr-accent); }
.xr-ev.tone-bad .xr-dot { border-color: var(--xr-bad); }
.xr-ev.is-chat .xr-dot { border-width: 2px; width: 10px; height: 10px; margin-top: 0.45rem; border-style: dotted; }
.xr-ev-body { min-width: 0; padding-left: 0.2rem; }
.xr-ev-title { font-size: 0.92rem; }
.xr-by { overflow-wrap: anywhere; color: var(--xr-muted); font-size: 0.82rem; }
.xr-loan-tag { display: block; width: fit-content; max-width: 100%; margin-top: 0.2rem; padding: 0.05rem 0.55rem; border-radius: 8px; background: var(--xr-soft2); font-size: 0.72rem; line-height: 1.4; color: var(--xr-muted); overflow-wrap: anywhere; }
.xr-ev-detail { font-size: 0.84rem; color: var(--xr-muted); overflow-wrap: anywhere; }
.xr-ev.is-chat .xr-ev-detail { color: var(--xr-ink); font-style: italic; padding-left: 0.6rem; border-left: 2px solid var(--xr-line); margin-top: 0.2rem; }
.xr-ev.is-chat .xr-ev-detail.xr-muted { color: var(--xr-muted); font-style: normal; padding-left: 0; border-left: 0; margin-top: 0; } /* Hinweis (z. B. Bildzahl), nicht Nachrichtentext */
.xr-ev-amt { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; padding-left: 0.6rem; }
.xr-amt { font-weight: 700; font-size: 0.92rem; }
.xr-amt.tone-out { color: var(--xr-out); }
.xr-amt.tone-in, .xr-amt.tone-good { color: var(--xr-accent); }
.xr-amt.is-info { color: var(--xr-muted); font-weight: 600; }
@media (max-width: 560px) {
  .xr-timeline::before { left: 90px; }
  .xr-ev { grid-template-columns: 76px 30px minmax(0, 1fr); }
  .xr-ev time { font-size: 0.74rem; }
  .xr-ev-amt { grid-column: 3; text-align: left; padding: 0.15rem 0 0 0.2rem; }
  .xr-ev-amt small { display: inline; margin-left: 0.4rem; }
}
@media (max-width: 480px) {
  /* Schmal: Datum über dem Text statt in einer eigenen Spalte, damit Titel und Details die volle Breite haben. */
  .xr-timeline::before { left: 10px; }
  .xr-ev { grid-template-columns: 22px minmax(0, 1fr); }
  .xr-ev time { grid-column: 2; grid-row: 1; display: flex; gap: 0.45rem; align-items: baseline; text-align: left; padding-top: 0; font-size: 0.76rem; }
  .xr-dot { grid-column: 1; grid-row: 1; margin-top: 0.15rem; }
  .xr-ev.is-chat .xr-dot { margin-top: 0.2rem; }
  .xr-ev-body { grid-column: 2; grid-row: 2; padding-left: 0; }
  .xr-ev-amt { grid-column: 2; grid-row: 3; padding: 0.2rem 0 0; }
}
.xr-month { margin-bottom: 0.6rem; }
.xr-month-title { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--xr-muted); margin: 1.1rem 0 0.2rem; }
.xr-month .xr-timeline { margin-top: 0.4rem; }

.xr-empty { display: grid; justify-items: center; gap: 0.4rem; padding: 3rem 1rem; text-align: center; color: var(--xr-muted); }
.xr-foot { margin-top: 1.5rem; padding-top: 0.8rem; border-top: 1px solid var(--xr-line); font-size: 0.75rem; color: var(--xr-muted); }

/* ---------- Druck / PDF ---------- */
@page {
  size: A4; margin: 14mm 12mm 16mm;
  /* Seitenzahl unten (Chrome/Edge); andere Browser drucken ihre eigene Fußzeile. */
  @bottom-left { content: "Money-Bericht"; font: 8pt system-ui, "Segoe UI", sans-serif; color: #5b6863; }
  @bottom-right { content: "Seite " counter(page) " von " counter(pages); font: 8pt system-ui, "Segoe UI", sans-serif; color: #5b6863; }
}
@media print {
  /* The app is dark-only (color-scheme: dark); without this the page margins of a PDF print dark. */
  :root, html.modal-open { color-scheme: light !important; background: #fff !important; }
  html.modal-open, html.modal-open body, html.modal-soft-lock, html.modal-soft-lock body {
    position: static !important; top: auto !important; left: auto !important; right: auto !important;
    width: auto !important; height: auto !important; overflow: visible !important; background: #fff !important;
  }
  /* Nur der Bericht wird gedruckt – alles andere, auch Toasts, verschwindet. */
  /* Die gespeicherte HTML-Datei (body.xr-standalone) hat keinen Dialog: dort ist der Bericht selbst der Inhalt. */
  body:not(.xr-standalone) > *:not(#modal-export-report) { display: none !important; }
  body.xr-standalone { background: #fff !important; }
  #modal-export-report {
    position: static !important; display: block !important; background: none !important;
    backdrop-filter: none !important; animation: none !important; inset: auto !important; padding: 0 !important;
  }
  #modal-export-report .xr-card {
    position: static !important; display: block !important; height: auto !important; max-width: none !important; width: auto !important;
    overflow: visible !important; border: 0 !important; box-shadow: none !important; background: #fff !important;
    animation: none !important; transform: none !important; padding: 0 !important;
  }
  .xr-toolbar { display: none !important; }
  .xr-scroll { display: block !important; overflow: visible !important; padding: 0 !important; background: #fff !important; }
  .xr-paper { max-width: none; padding: 0; border-radius: 0; box-shadow: none; font-size: 12.5px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .xr-paper small, .xr-rates small { font-size: 0.84em; }
  /* Papierfreundlich: die dunkle Kennzahl wird umrandet statt schwarz gefüllt (spart Toner, bleibt auch ohne Hintergrunddruck lesbar). */
  .xr-kpi.is-key { background: #fff; color: var(--xr-ink); border: 2px solid var(--xr-ink); }
  .xr-kpi.is-key .xr-kpi-label, .xr-kpi.is-key .xr-kpi-sub { color: var(--xr-muted); }
  .xr-kpi, .xr-loan-stats > div, .xr-loan-head, .xr-table tr { break-inside: avoid; }
  .xr-head { break-after: avoid; }
  .xr-h2 { break-after: avoid; }
  .xr-loan { break-inside: auto; border-radius: 8px; }
  /* Kopf einer Leihe (Titel, Status, Kennzahlen, Fakten, Ratenplan) bleibt bei der ersten Zeile der Zeitleiste. */
  .xr-loan-head, .xr-loan-stats, .xr-chips, .xr-progress, .xr-loan-facts, .xr-loan-period, .xr-loan-nocount, .xr-inst { break-after: avoid; }
  .xr-ev { break-inside: avoid; }
  .xr-kpis { grid-template-columns: repeat(4, 1fr); }
  .xr-panels { grid-template-columns: 1fr 1fr; }
  /* Sonst springt die lange Personentabelle samt Diagramm komplett auf Seite 2 und lässt Seite 1 halb leer. */
  .xr-panels { align-items: start; }
  .xr-panel { break-inside: auto; }
  .xr-panel h3 { break-after: avoid; }
  .xr-chart, .xr-legend { break-inside: avoid; }
  .xr-loan-stats { grid-template-columns: repeat(4, 1fr); }
  .xr-month-title { break-after: avoid; }
  .xr-table .xr-extra { display: table-row !important; }
  .xr-more-btn { display: none !important; }
  /* Gedruckt und als Datei ist alles sichtbar: Zeitleisten ausgeklappt, Knöpfe und Sprungmarken weg. */
  .xr-loan.is-folded .xr-timeline { display: block !important; }
  .xr-tl-bar, .xr-toc, .xr-chart-hint { display: none !important; }
  .xr-chart-info { min-height: 0; }
  .xr-atts img { max-height: 70px; }
}

/* ---------- Kleine Bildschirme ---------- */
@media (max-width: 560px) {
  .xr-loan { overflow: hidden; }
  .xr-ev-body, .xr-ev-amt { min-width: 0; }
  .xr-ev-amt { white-space: normal; }
  .xr-ev-amt small { display: block; margin-left: 0; }
  .xr-rates small { font-size: 0.72rem; }
  .xr-bar-cell, .xr-bar-legend { display: none; }
}
@media (max-width: 380px) {
  .xr-toolbar { padding: 0.5rem 0.4rem; gap: 0.35rem; }
  .xr-tool { padding: 0 0.6rem; }
  .xr-tool[data-xr="print"] { min-width: 0; padding: 0 0.4rem; }
  .xr-loan-stats { gap: 0.6rem 0.4rem; }
  .xr-loan-stats dt { font-size: 0.62rem; letter-spacing: 0.02em; overflow-wrap: anywhere; }
  .xr-kpi { padding: 0.7rem 0.6rem; }
  .xr-kpi-label { font-size: 0.62rem; letter-spacing: 0; overflow-wrap: anywhere; }
  .xr-card { width: 100vw; max-width: 100vw; }
}
@media (min-width: 560px) and (max-width: 820px) { .xr-tool[data-xr="print"] { max-width: 320px; } }

/* Full-screen report: the toolbar clears the status bar / notch (its padding shorthands above would reset this if it sat earlier). */
@media (max-width: 820px) { .xr-toolbar { padding-top: calc(0.5rem + env(safe-area-inset-top, 0px)); } }

/* ---------- Touch, Bewegung ---------- */
/* Placed last on purpose: same specificity as the base rules above, so only the later one wins. */
@media (pointer: coarse) {
  .xr-tool { min-height: 44px; min-width: 44px; }
  .xr-view-btn { min-height: 44px; }
  .xd-seg-item span, .xd-check, .xd-csv .btn-secondary, .xd-csv-format select { min-height: 44px; }
  .xr-more-btn, .xr-tl-toggle, .xr-toc summary { min-height: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  .export-btn, .xd-seg-item span, .xr-view-btn, .xr-menu-list button, .xr-more-btn, .xr-tl-toggle, .xr-tl-toggle svg, .xr-toc summary, .xr-toc summary::after, .xr-toc a, .xr-band { transition: none; }
  .export-btn:active, .xd-seg-item input:active + span, .xr-view-btn:active, .xr-menu-list button:active, .xr-tl-toggle:active, html:not(.using-touch) .xr-menu-list button:active { transform: none; }
  .xr-stmt-btn { transition: none; }
  .xr-stmt-btn:active { transform: none; }
}
