/* Altach Gesundheitswelt – Design-System
   Klinisch-präzise, ruhig, datenzentriert. Ein Akzent (Blau), sonst Schwarz/Weiß/Grau. */

:root {
  /* Farbwelt SCRA Gesundheitswelt: Anthrazit/Weiß/Grau (wie die Website). */
  --ink-900: #1C1C1C;
  --ink-700: #4F4F4F;
  --ink-400: #8A8A8A;
  --line:    #E4E4E4;
  --paper:   #FFFFFF;
  --mist:    #F4F4F4;

  /* Akzent = Anthrazit (Buttons, aktive Navigation), Text darauf ist weiß. */
  --accent:        #333333;
  --accent-strong: #1C1C1C;
  --accent-ink:    #FFFFFF;
  --accent-050:    #EFEFEF;

  --blue-600:#1C1C1C;
  --blue-500:#4F4F4F;
  --blue-050:#EFEFEF;

  --ok:   #2F855A;
  --warn: #B7791F;
  --alert:#C53030;

  --radius: 12px;
  --radius-sm: 8px;
  --nav-width: 240px;
  --space: 8px;

  --shadow-soft: 0 1px 2px rgba(20,20,20,.04), 0 2px 6px rgba(20,20,20,.05);
  --shadow-hover: 0 6px 20px rgba(20,20,20,.10);

  --font-ui: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, monospace;
}

/* Selbst gehostete Schrift (Geist) – same-origin, kein CDN. Variabel 100–900. */
@font-face {
  font-family: "Geist";
  src: url("/fonts/Geist-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Geist Mono";
  src: url("/fonts/GeistMono-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink-900);
  background: var(--mist);
  font-weight: 400;
  /* Variable Geist sauber rendern: optische Größe, geglättet, Ligaturen. */
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
  /* Ein Akzent gilt auch für native Steuerelemente (Checkboxen/Radios), nicht OS-Blau. */
  accent-color: var(--ink-900);
}

h1, h2, h3 { color: var(--ink-900); font-weight: 600; line-height: 1.2; margin: 0 0 var(--space) 0; text-wrap: balance; }
h1 { font-size: 26px; letter-spacing: -0.025em; }
h2 { font-size: 20px; letter-spacing: -0.018em; }
h3 { font-size: 16px; letter-spacing: -0.01em; }
p { text-wrap: pretty; }
p  { margin: 0 0 12px 0; }
small, .caption { font-size: 12px; color: var(--ink-400); }

a { color: var(--blue-600); text-decoration: none; }
a:hover { color: var(--blue-500); text-decoration: underline; }

/* ---------- Feinschliff: ruhige, markenkonforme Details ---------- */
/* Textauswahl in Anthrazit statt OS-Blau. */
::selection { background: rgba(28, 28, 28, .14); color: var(--ink-900); }

/* Schlanke, neutrale Scrollbalken in Scroll-Regionen (Chrome tritt zurück). */
.table-wrap, .content.fill { scrollbar-width: thin; scrollbar-color: #C9C9C9 transparent; }
.table-wrap::-webkit-scrollbar, .content.fill::-webkit-scrollbar { width: 10px; height: 10px; }
.table-wrap::-webkit-scrollbar-thumb, .content.fill::-webkit-scrollbar-thumb {
  background: #D0D0D0; border-radius: 999px; border: 2px solid var(--paper); background-clip: padding-box;
}
.table-wrap::-webkit-scrollbar-thumb:hover, .content.fill::-webkit-scrollbar-thumb:hover { background: #B8B8B8; }
.table-wrap::-webkit-scrollbar-track, .content.fill::-webkit-scrollbar-track { background: transparent; }

/* Nur wirklich interaktive Karten heben leicht ab (nutzt --shadow-hover). */
a.card, .card.is-link { transition: box-shadow 120ms ease, border-color 120ms ease, transform 120ms ease; }
a.card:hover, .card.is-link:hover { box-shadow: var(--shadow-hover); border-color: #D6D6D6; text-decoration: none; }
a.card:active, .card.is-link:active { transform: translateY(1px); }

/* Klinische Zahlen: gleiche Breite + geschlitzte Null (0 vs. O eindeutig). */
.num { font-variant-numeric: tabular-nums slashed-zero; }

/* Tastatur-Sprunglink (Barrierefreiheit) */
.skip-link { position: absolute; left: -9999px; top: 8px; z-index: 200;
  background: var(--accent); color: var(--accent-ink); padding: 10px 14px;
  border-radius: var(--radius-sm); font-weight: 600; }
.skip-link:focus { left: 12px; text-decoration: none; }

/* ---------- App-Shell: feste linke Navigation ---------- */
.app { display: grid; grid-template-columns: var(--nav-width) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--paper);
  border-right: 1px solid var(--line);
  padding: 20px 12px;
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 4px;
}
.brand { padding: 6px 10px 18px; display: block; }
.brand-logo { display: block; height: 46px; width: auto; max-width: 100%; }
.brand .mark { font-weight: 600; font-size: 15px; color: var(--ink-900); display: block; }
.brand .sub  { font-size: 12px; color: var(--ink-400); }

.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 6px;
  color: var(--ink-700); font-weight: 500;
  border: 1px solid transparent;
  transition: background-color 120ms ease, color 120ms ease;
}
.nav-link:hover { background: var(--mist); text-decoration: none; color: var(--ink-900); }
.nav-link.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.nav-link.active:hover { background: var(--accent-strong); color: var(--accent-ink); }
.nav-link svg { width: 17px; height: 17px; flex: none; stroke: currentColor; }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-400); padding: 16px 10px 6px; }
.sidebar .spacer { flex: 1; }
.sidebar .foot { font-size: 11px; color: var(--ink-400); padding: 8px 10px; border-top: 1px solid var(--line); }

/* Benutzer/Abmelden am Fuß der Navigation */
.sidebar-user { border-top: 1px solid var(--line); padding: 10px 6px 8px; display: flex; flex-direction: column; gap: 8px; }

.content { padding: 28px 32px 64px; }
/* Dezenter Inhalts-Fade beim Seitenwechsel. Unter prefers-reduced-motion global
   deaktiviert (siehe reduced-motion-Block am Dateiende). Nur Opacity → kein Layout-Shift. */
@keyframes content-in { from { opacity: 0; } to { opacity: 1; } }
.content { animation: content-in 160ms ease-out both; }

/* „Fill"-Seiten (Patient:innen-Liste, Vergleich): Tabelle füllt die Resthöhe und
   scrollt im Tabellenkörper, statt die ganze Seite scrollen zu lassen. Nur Desktop. */
@media (min-width: 901px) {
  .content.fill { height: 100vh; display: flex; flex-direction: column; overflow: hidden; padding-bottom: 28px; }
  .content.fill > .fill-region,
  .content.fill > .card-fill { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; margin-bottom: 0; }
  .content.fill > .fill-region > .table-wrap,
  .content.fill > .card-fill > .table-wrap { flex: 1 1 auto; min-height: 0; max-height: none; }
}
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-head .lead { color: var(--ink-400); font-size: 13px; margin-top: 2px; }

/* ---------- Karten ---------- */
.card {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-soft);
  padding: 22px; margin-bottom: 16px;
}
.card h3 { margin-bottom: 4px; }
/* Luft zwischen Kartentitel und direkt folgender Tabelle (Kopfzeile nicht kleben lassen) */
.card h3 + .table-wrap { margin-top: 16px; }
/* einheitlicher Abstand zwischen allen Blöcken (Karte↔Karte, Karte↔Raster, Raster↔Raster) */
.card-grid { display: grid; gap: 16px; align-items: stretch; margin-bottom: 16px; }
/* Karten im Raster: kein Eigenabstand, volle Zellenhöhe → gleiche Höhen */
.card-grid > .card { margin-top: 0; margin-bottom: 0; height: 100%; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* KPI-Kachel: einheitliche Höhe, vertikal zentriert */
.kpi { display: flex; flex-direction: column; gap: 6px; justify-content: center; }
.card.kpi { min-height: 108px; }
.kpi .label { font-size: 12px; color: var(--ink-400); font-weight: 500; }
.kpi .value { font-family: var(--font-mono); font-size: 26px; font-weight: 600; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums slashed-zero; }
.kpi .hint  { font-size: 12px; color: var(--ink-400); }

/* ---------- Tabellen ---------- */
/* Scrollen innerhalb der Tabelle (Kopfzeile bleibt sticky), statt die ganze Seite zu scrollen */
.table-wrap { overflow: auto; max-height: 68vh; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); }
table.data thead th { background: var(--mist); color: var(--ink-400); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; position: sticky; top: 0; z-index: 1; box-shadow: inset 0 -1px 0 var(--line); white-space: nowrap; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--mist); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums slashed-zero; white-space: nowrap; }
table.data td.num { font-family: var(--font-mono); font-size: 12.5px; }
table.data td.strong { font-weight: 600; }
table.data tr.clickable { cursor: pointer; }
.table-empty { padding: 40px; text-align: center; color: var(--ink-400); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 500; font-size: 13px;
  padding: 9px 16px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink-900);
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease, box-shadow 120ms ease;
}
.btn:hover { background: var(--mist); border-color: #C9C9C9; text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--accent-ink); }
.btn:active { transform: translateY(1px); }
.btn-primary:disabled, .btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:disabled:active { transform: none; }
.btn-sm { padding: 6px 11px; font-size: 12px; }
.btn-danger { color: var(--alert); }
.btn-danger:hover { color: var(--alert); border-color: #e8b4b4; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Formulare ---------- */
label.field { display: block; margin-bottom: 12px; }
label.field .lbl { display: block; font-size: 11px; color: var(--ink-400); margin-bottom: 5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
input[type=text], input[type=search], input[type=date], input[type=email], input[type=password], input[type=number], select {
  width: 100%; font: inherit; font-size: 13px; padding: 9px 11px; height: 38px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--paper); color: var(--ink-900);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
select { -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23767676' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 16px; padding-right: 32px; cursor: pointer; }
input:hover, select:hover { border-color: #C9C9C9; }
input:focus, select:focus, .btn:focus-visible, .nav-link:focus-visible, a:focus-visible, button:focus-visible {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(28,28,28,.18);
}

/* Kompakte, moderne Suchleiste (nur Name) */
.searchbar { display: inline-flex; align-items: center; gap: 8px; background: var(--paper);
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 4px 4px 14px; box-shadow: var(--shadow-soft);
  transition: border-color 120ms ease, box-shadow 120ms ease; }
.searchbar:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(28,28,28,.18); }
.searchbar svg { width: 16px; height: 16px; flex: none; stroke: var(--ink-400); }
.searchbar input[type=search] { border: none; box-shadow: none !important; outline: none; height: auto; padding: 6px 4px; width: 220px; background: transparent; }
.searchbar .btn { border-radius: 999px; }
/* Auswahl (z. B. Kennzahl) im gleichen kompakten Stil wie die Suche */
.searchbar select { border: none; box-shadow: none !important; background-color: transparent;
  height: auto; padding: 6px 26px 6px 4px; min-width: 200px; cursor: pointer; }
.head-tools { display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Aktive Filter als Chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip { display: inline-flex; align-items: center; gap: 8px; font-size: 13px;
  background: var(--mist); border: 1px solid var(--line); border-radius: 999px; padding: 5px 6px 5px 12px; color: var(--ink-700); }
.chip a { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px;
  border-radius: 999px; background: var(--ink-900); color: #fff; font-size: 13px; line-height: 1; text-decoration: none; }
.chip a:hover { background: #000; text-decoration: none; }

/* Filterleiste: sauberes, ausgerichtetes Raster statt zerfranster Flex-Reihe */
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px 16px; align-items: end; }
.filters label.field { margin-bottom: 0; min-width: 0; }
.filters .btn-row { grid-column: 1 / -1; justify-content: flex-end; border-top: 1px solid var(--line); padding-top: 14px; margin-top: 2px; }

/* ---------- Badges / Ampel ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500;
  padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink-700); background: var(--paper); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot-ok { background: var(--ok); } .dot-warn { background: var(--warn); } .dot-alert { background: var(--alert); }
.txt-ok { color: var(--ok); } .txt-warn { color: var(--warn); } .txt-alert { color: var(--alert); }
.badge-blue { background: var(--accent-050); color: var(--ink-900); border-color: #D6D6D6; }

/* ---------- Alerts ---------- */
.alert { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; font-size: 13px; background: var(--paper); margin-bottom: 16px; }
.alert-info { background: var(--blue-050); border-color: #D6D6D6; color: var(--ink-900); }
.alert-warn { border-color: #F0E2C6; background: #FCF7ED; color: var(--ink-900); }
.alert-error { border-color: #F3D2D2; background: #FDF1F1; color: var(--ink-900); }
.alert-ok { border-color: #CFE8DA; background: #F0F8F3; color: var(--ink-900); }

/* ---------- Diverses ---------- */
.muted { color: var(--ink-400); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.pill-group { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.pill-group a { padding: 6px 12px; font-size: 12px; color: var(--ink-700); border-right: 1px solid var(--line); transition: background-color 120ms ease; }
.pill-group a:last-child { border-right: none; }
.pill-group a.active { background: var(--blue-050); color: var(--blue-600); }
.pill-group a:hover { text-decoration: none; background: var(--mist); }

.chart-box { position: relative; height: 300px; }
.chart-box.tall { height: 380px; }

/* Aufklappbare Testung direkt auf der Patient:innen-Seite (kein Seitenwechsel) */
.session-panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-soft); margin-bottom: 16px; overflow: hidden; }
.session-panel > summary {
  position: relative;
  display: grid; grid-template-columns: 120px 1fr auto auto; align-items: center; gap: 16px;
  padding: 16px 22px 16px 44px; cursor: pointer; list-style: none; font-weight: 500;
}
.session-panel > summary::-webkit-details-marker { display: none; }
.session-panel > summary::before { content: "▸"; color: var(--ink-400); position: absolute; left: 22px; top: 16px; }
.session-panel[open] > summary::before { content: "▾"; }
.session-panel > summary:hover { background: var(--mist); }
.session-panel > summary .sp-val { font-variant-numeric: tabular-nums slashed-zero; font-weight: 600; }
.session-panel[open] > summary { border-bottom: 1px solid var(--line); }
.session-panel-body { padding: 22px; }
/* verschachtelte Karten im Panel ohne eigenen Schatten (kein doppelter Schatten) */
.session-panel-body .card { box-shadow: none; }

/* ---------- Session-Karten (Patient:innen-Detail) ---------- */
.session-card { display: flex; flex-direction: column; gap: 8px; text-decoration: none; color: inherit; }
.session-card:hover { text-decoration: none; color: inherit; }
.session-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.session-card-test { font-size: 12px; color: var(--ink-400); font-weight: 500; }
.session-card-value { margin: 4px 0 0; line-height: 1; }
.session-card-value .num { font-family: var(--font-mono); font-size: 42px; font-weight: 600; letter-spacing: -.03em; font-variant-numeric: tabular-nums slashed-zero; }
.session-card-value .unit { font-size: 16px; color: var(--ink-400); font-weight: 400; margin-left: 4px; }
.session-card-label { font-size: 11px; color: var(--ink-400); text-transform: uppercase; letter-spacing: .05em; }
.session-card-sides { font-size: 12px; color: var(--ink-700); font-family: var(--font-mono); font-variant-numeric: tabular-nums; margin-top: 2px; }
.session-card-footer { display: flex; align-items: center; justify-content: space-between; margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); }
.grid-sessions { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }

/* ---------- Geräte-Umschalter (Maschine pro Patient:in) ---------- */
.machine-switch { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.machine-tab {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 600;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink-700);
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}
.machine-tab:hover { text-decoration: none; background: var(--mist); color: var(--ink-900); }
.machine-tab.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.machine-tab .count { font-size: 11px; font-weight: 500; opacity: .8;
  background: rgba(0,0,0,.08); border-radius: 999px; padding: 1px 7px; }
.machine-tab.active .count { background: rgba(255,255,255,.24); }

.dropzone {
  border: 1.5px dashed var(--line); border-radius: var(--radius); padding: 36px 24px; text-align: center;
  background: var(--mist); transition: border-color 120ms ease, background-color 120ms ease; cursor: pointer;
}
.dropzone.drag { border-color: var(--blue-500); background: var(--blue-050); }
.dropzone .hint { color: var(--ink-400); font-size: 13px; margin-top: 6px; }

.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--ink-400); align-items: center; }
.legend .swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; margin-right: 6px; vertical-align: middle; }

/* ---------- Bericht / Druck ---------- */
.report { max-width: 900px; margin: 0 auto; padding: 24px; background: var(--paper); }
.report-toolbar { position: sticky; top: 0; background: var(--paper); border-bottom: 1px solid var(--line); padding: 12px 0; margin-bottom: 20px; display: flex; gap: 16px; flex-wrap: wrap; align-items: center; z-index: 5; }
.report-toolbar .spacer { flex: 1; }
.report-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid var(--ink-900); padding-bottom: 12px; margin-bottom: 20px; }
.report-head .org { font-weight: 700; font-size: 15px; letter-spacing: -.01em; }
.report-head .caption { margin-top: 2px; }
.report-summary { font-size: 13px; color: var(--ink-700); margin: 0 0 20px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.report-summary strong { color: var(--ink-900); font-family: var(--font-mono); font-variant-numeric: tabular-nums slashed-zero; }
.report-footer { font-size: 11px; color: var(--ink-400); margin-top: 20px; padding-top: 12px; border-top: 1px solid var(--line); }

/* Jeder Abschnitt = Überschrift + Chart direkt darunter */
.chart-section { margin-bottom: 12px; }
.chart-section > h3 { font-size: 13px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase; color: var(--ink-400); border-bottom: 1px solid var(--line); padding-bottom: 6px; margin: 0 0 14px; }
.report .chart-box { height: auto; margin: 0 0 8px; }
.report canvas[data-chartsrc] { display: block; width: 100% !important; height: auto !important; max-width: 100%; }

/* Zeilenauswahl (nur Bildschirm) */
.col-select { width: 34px; text-align: center; }
.rowsel { width: 16px; height: 16px; cursor: pointer; }
tr.row-off td:not(.col-select) { opacity: .35; text-decoration: line-through; }
.selection-table { margin-bottom: 24px; }
.selection-table .table-wrap { max-height: 260px; }

@media print {
  .report-toolbar, .no-print, .col-select, tr.row-off { display: none !important; }
  body { background: #fff; }
  .report { max-width: none; margin: 0; padding: 0; font-size: 11pt; }
  a { color: var(--ink-900); text-decoration: none; }

  /* Überschriften niemals allein am Seitenende */
  .report h2, .report h3, .report-head, .report-summary { break-after: avoid; page-break-after: avoid; }

  /* Kurze Abschnitte (LR-Chart, Balken mit wenigen Zeilen) komplett auf einer Seite */
  .chart-section { break-inside: avoid; page-break-inside: avoid; margin-bottom: 16px; }

  /* Hohe Abschnitte (Rangliste mit vielen Patient:innen) dürfen über Seiten fließen,
     starten aber nie auf einer neuen Seite wenn noch Platz ist */
  .chart-section.tall { break-inside: auto; page-break-inside: auto; }
  .chart-section.tall > h3 { break-after: avoid; page-break-after: avoid; }
  .chart-section.tall > .chart-box { break-before: avoid; page-break-before: avoid; }

  canvas[data-chartsrc] { width: 100% !important; height: auto !important; max-width: 100%;
    -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ---------- Animationen ------------------------------------------------ */
/* Tabellen-Zeilen: sanftes Einblenden des Hover-Fills statt harter Kante */
table.data tbody tr { transition: background-color 100ms ease; }

/* Clickable rows: kurze Press-Verdunklung als taktiles Echo */
table.data tr.clickable:active td { background: #EBEBEB; }

/* Alerts: kurzes Einblenden von oben – macht Feedback spürbar ohne abzulenken */
@keyframes alert-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.alert { animation: alert-in 200ms ease-out both; }

/* Modal: Backdrop fade + Karte scale-up (dezent, klinisch) */
@keyframes overlay-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes modal-in {
  from { opacity: 0; transform: scale(.97) translateY(6px); }
  to   { opacity: 1; transform: scale(1)   translateY(0); }
}
.modal-overlay { animation: overlay-in 160ms ease-out both; }
.modal-card    { animation: modal-in 220ms cubic-bezier(.22,.68,0,1.15) both; box-shadow: var(--shadow-hover); margin-bottom: 0; }

/* Session-Panel body: Inhalt blendet beim Öffnen sanft ein */
.session-panel-body { animation: content-in 180ms ease-out both; }

/* Chip ×-Button: gleiche Timing-Sprache */
.chip a { transition: background-color 100ms ease; }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ================================================================
   Desktop: sidebar-bar und sidebar-nav sind Layout-transparent –
   ihre Kinder nehmen direkt an der Sidebar-Flex-Column teil.
   ================================================================ */
@media (min-width: 901px) {
  .sidebar-bar {
    display: flex; align-items: center;
    padding: 0 0 2px;        /* minimaler Abstand unter dem Logo */
  }
  .sidebar-nav {
    display: flex; flex-direction: column; gap: 4px;
    flex: 1;                 /* füllt die Sidebar-Höhe → spacer drückt sidebar-user nach unten */
  }
  .nav-toggle { display: none; }
}

/* ================================================================
   Mobil / Tablet (≤ 900 px): Hamburger-Navigation
   ================================================================ */
@media (max-width: 900px) {
  /* Shell: eine Spalte statt Grid */
  .app { grid-template-columns: 1fr; }

  /* Sidebar wird zur klebrigen Top-Bar */
  .sidebar {
    position: sticky; top: 0; z-index: 50;
    flex-direction: column; gap: 0; height: auto; padding: 0;
    border-right: none; border-bottom: 1px solid var(--line);
    background: var(--paper);
  }

  /* Obere Leiste: Logo + Hamburger-Button */
  .sidebar-bar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 12px; height: 48px; flex-shrink: 0; overflow: hidden;
  }
  .brand { padding: 0; line-height: 0; }
  .brand-logo { height: 28px; }

  /* Hamburger-Button */
  .nav-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 44px; height: 44px; padding: 0; flex-shrink: 0;
    border: 1px solid var(--line); border-radius: var(--radius-sm);
    background: var(--paper); cursor: pointer; color: var(--ink-900);
    transition: background-color 120ms ease;
  }
  .nav-toggle:hover { background: var(--mist); }
  .nav-toggle svg { width: 20px; height: 20px; }
  .nav-toggle .icon-close { display: none; }
  .sidebar.open .nav-toggle .icon-menu  { display: none; }
  .sidebar.open .nav-toggle .icon-close { display: block; }

  /* Nav-Panel: standardmäßig versteckt, beim Öffnen als Fixed-Overlay */
  .sidebar-nav {
    display: none;
    flex-direction: column; gap: 2px;
    position: fixed; top: 49px; left: 0; right: 0;
    background: var(--paper); border-bottom: 1px solid var(--line);
    padding: 8px 12px 16px; box-shadow: var(--shadow-hover);
    z-index: 49;
    max-height: calc(100dvh - 49px); overflow-y: auto;
  }
  /* Animation läuft beim Öffnen, nicht beim Seitenlade (display:none → display:flex) */
  .sidebar.open .sidebar-nav { display: flex; animation: modal-in 200ms ease-out both; }

  /* Nav-Links: größere Touch-Ziele */
  .nav-link { padding: 12px 10px; font-size: 15px; }

  /* Spacer entfällt auf Mobil */
  .spacer { display: none; }

  /* Sidebar-User im aufgeklappten Panel */
  .sidebar-user {
    border-top: 1px solid var(--line);
    padding: 12px 0 4px; margin-top: 4px;
  }
  .sidebar-user .btn,
  .sidebar-user form .btn { min-height: 44px; font-size: 14px; }

  /* Inhaltsbereich */
  .content { padding: 12px 12px 40px; }

  /* Karten: weniger Padding auf Mobil */
  .card { padding: 12px; }

  /* Seitenkopf: Titel und Aktion übereinander; weniger Abstand nach unten */
  .page-head {
    flex-direction: column; align-items: flex-start; gap: 8px; margin-bottom: 12px;
  }

  /* Buttons: 44 px Touch-Ziel */
  .btn     { min-height: 44px; }
  .btn-sm  { min-height: 40px; font-size: 13px; }

  /* Tabellen: kompaktere Zellen */
  table.data th,
  table.data td { padding: 10px 10px; font-size: 12px; }

  /* Suchleiste: volle Breite */
  .searchbar { width: 100%; }
  .searchbar input[type=search] { width: auto; flex: 1; }

  /* Filter-Raster: zwei Spalten */
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr 1fr; }

  /* Modal: Karte darf scrollen wenn Inhalt groß */
  .modal-card { max-height: calc(100dvh - 48px); overflow-y: auto; }

  /* Dropzone: kompaktere Höhe auf Mobil */
  .dropzone { padding: 20px 16px; }
}

/* ================================================================
   Klein-Mobil (≤ 560 px)
   ================================================================ */
@media (max-width: 560px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }

  /* Nur Icons ohne Text in der Nav wäre zu unklar → Nav-Link-Text bleibt,
     dafür wird die Schrift etwas kleiner */
  .nav-link { font-size: 14px; }

  /* Tabellenzellen noch kompakter */
  table.data th,
  table.data td { padding: 8px; }
}
