:root {
  --bg: #f2f5f9;
  --flaeche: #ffffff;
  --flaeche-2: #e8eef6;
  --rand: #d3dce8;
  --text: #16202d;
  --text-2: #5a6779;
  --akzent: #1d4f91;          /* Blau des Buchumschlags */
  --akzent-text: #ffffff;
  --akzent-hell: #e1ebf8;
  --warn: #8a5300;
  --warn-hell: #fff4dc;
  --gefahr: #b3261e;
  --haupt: #1d4f91;
  --obligat: #2f7d4f;
  --optional: #7a5aa6;
  --schatten: 0 1px 2px rgba(20, 35, 60, .06), 0 3px 12px rgba(20, 35, 60, .06);
  --radius: 10px;
  --schrift: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --tabbar: 62px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10151c; --flaeche: #19202a; --flaeche-2: #222b37; --rand: #303b4a;
    --text: #e5eaf1; --text-2: #9ba8b9; --akzent: #8db7f0; --akzent-text: #0b1a2e; --akzent-hell: #1c2c44;
    --warn: #e6b05a; --warn-hell: #33280f; --gefahr: #f08a80;
    --haupt: #8db7f0; --obligat: #74c597; --optional: #bda3e6;
    --schatten: 0 1px 2px rgba(0, 0, 0, .3), 0 3px 12px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 var(--schrift); }
.hidden { display: none !important; }
a { color: var(--akzent); }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.25; }
h1 { font-size: 1.3rem; }
h2 { font-size: 1.12rem; }
h3 { font-size: 1rem; }
.klein { font-size: .85em; color: var(--text-2); }
.leer { color: var(--text-2); padding: 1.5rem 0; text-align: center; }
.fehler { color: var(--gefahr); }

/* ---------- Kopf und Tab-Leiste ---------- */
.kopf {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1rem;
  padding: 8px 16px; background: var(--flaeche); border-bottom: 1px solid var(--rand);
}
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.logo img { border-radius: 8px; }
.logo span { display: flex; flex-direction: column; line-height: 1.15; }
.logo small { color: var(--text-2); font-size: .78rem; }
.tabs { display: flex; gap: 2px; margin-left: auto; }
.tabs a {
  display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 8px;
  color: var(--text-2); text-decoration: none; font-weight: 500;
}
.tabs a:hover { background: var(--flaeche-2); }
.tabs a.aktiv { color: var(--akzent); background: var(--akzent-hell); }
.tabs .ico { font-size: 1.05rem; line-height: 1; }

.inhalt { max-width: 1200px; margin: 0 auto; padding: 16px; }

@media (max-width: 760px) {
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; height: calc(var(--tabbar) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom); background: var(--flaeche); border-top: 1px solid var(--rand); gap: 0;
  }
  .tabs a { flex: 1; flex-direction: column; justify-content: center; gap: 2px; font-size: .72rem; border-radius: 0; padding: 6px 2px; }
  .tabs a.aktiv { background: none; }
  .tabs .ico { font-size: 1.3rem; }
  .inhalt { padding: 12px 12px calc(var(--tabbar) + 24px + env(safe-area-inset-bottom)); }
}

/* ---------- Formularelemente ---------- */
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--rand); border-radius: 8px; background: var(--flaeche);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--akzent); outline-offset: -1px; border-color: transparent; }
label { display: block; font-size: .82rem; color: var(--text-2); }
label > input, label > select { margin-top: 3px; font-size: .95rem; color: var(--text); }
.formular { display: grid; gap: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35em; padding: 8px 14px;
  border: 1px solid var(--rand); border-radius: 8px; background: var(--flaeche); cursor: pointer;
  text-decoration: none; color: var(--text); white-space: nowrap; font-size: .92rem; line-height: 1.25;
}
.btn:hover { background: var(--flaeche-2); }
.btn.primaer { background: var(--akzent); border-color: var(--akzent); color: var(--akzent-text); }
.btn.primaer:hover { filter: brightness(1.08); }
.btn.klein { padding: 4px 9px; font-size: .82rem; }
.btn.aktiv { background: var(--akzent-hell); border-color: var(--akzent); color: var(--akzent); }
.btn:disabled { opacity: .5; cursor: default; }
.knopfleiste { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 12px 0; }

/* ---------- Karten ---------- */
.karte { background: var(--flaeche); border: 1px solid var(--rand); border-radius: var(--radius); box-shadow: var(--schatten); padding: 16px; margin-bottom: 16px; }
.karte > h2:first-child, .karte > h3:first-child { margin-top: 0; }
@media (max-width: 560px) { .karte { padding: 12px; } }

/* ---------- Suche ---------- */
.suchfeld { position: relative; }
.suchfeld input { font-size: 1.05rem; padding: 11px 14px 11px 40px; border-radius: 10px; }
.suchfeld::before { content: "⌕"; position: absolute; left: 13px; top: 50%; transform: translateY(-52%); font-size: 1.35rem; color: var(--text-2); pointer-events: none; }
.filter { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.filter select { width: auto; max-width: 100%; flex: 1 1 180px; font-size: .9rem; padding: 6px 8px; }
.filter select.feld { flex: 0 1 220px; }
.ergebnis-info { color: var(--text-2); font-size: .88rem; margin: 12px 2px 8px; display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; }

.treffer { list-style: none; margin: 0; padding: 0; }
.treffer li { border-bottom: 1px solid var(--rand); }
.treffer li:last-child { border-bottom: 0; }
.treffer a { display: grid; grid-template-columns: 8.5em 1fr auto; gap: 2px 14px; padding: 10px 6px; color: inherit; text-decoration: none; }
.treffer a:hover { background: var(--flaeche-2); }
.treffer .code { font-family: ui-monospace, Consolas, monospace; font-size: .82rem; color: var(--text-2); padding-top: 2px; }
.treffer .name { font-weight: 600; }
.treffer .icd { font-family: ui-monospace, Consolas, monospace; font-size: .82rem; color: var(--akzent); text-align: right; white-space: nowrap; max-width: 14em; overflow: hidden; text-overflow: ellipsis; }
.treffer .zeile2 { grid-column: 2 / 4; font-size: .87rem; color: var(--text-2); }
.treffer .zeile2 b { color: var(--text); font-weight: 500; }
.treffer .zeile3 { grid-column: 2 / 4; font-size: .78rem; color: var(--text-2); }
.treffer mark { background: #ffe58a; color: inherit; border-radius: 2px; padding: 0 1px; }
@media (prefers-color-scheme: dark) { .treffer mark { background: #6b5a12; } }
@media (max-width: 600px) {
  .treffer a { grid-template-columns: 1fr auto; padding: 10px 2px; }
  .treffer .code { grid-row: 1; grid-column: 1; }
  .treffer .icd { grid-row: 1; grid-column: 2; }
  .treffer .name { grid-column: 1 / 3; }
  .treffer .zeile2, .treffer .zeile3 { grid-column: 1 / 3; }
}

/* ---------- Detail ---------- */
.zurueck { display: inline-block; margin-bottom: 8px; text-decoration: none; font-size: .9rem; }
.kopfzeile { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; align-items: baseline; }
.kopfzeile .code { font-family: ui-monospace, Consolas, monospace; color: var(--text-2); }
.kopfzeile h1 { margin: 0; overflow-wrap: anywhere; min-width: 0; }
@media (max-width: 600px) { .kopfzeile { grid-template-columns: 1fr; } }
.kopfdaten dd, .treffer .name, .treffer .zeile2 { overflow-wrap: anywhere; min-width: 0; }
.kopfdaten { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 12px 0 0; font-size: .93rem; }
.kopfdaten dt { color: var(--text-2); }
.kopfdaten dd { margin: 0; }
.kopfdaten .icd { font-family: ui-monospace, Consolas, monospace; }
.pfad { font-size: .85rem; color: var(--text-2); }
.pfad a { color: var(--text-2); }
.quellzeile { font-size: .82rem; color: var(--text-2); margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--rand); }

.hinweis { background: var(--warn-hell); border-left: 4px solid var(--warn); padding: 10px 12px; border-radius: 6px; margin: 0 0 16px; }
.hinweis b { color: var(--warn); }
.warnung { font-size: .8rem; color: var(--text-2); border: 1px solid var(--rand); border-radius: 8px; padding: 8px 10px; margin: 16px 0; }

.ansicht { display: inline-flex; background: var(--flaeche-2); border-radius: 9px; padding: 3px; gap: 2px; }
.ansicht button { border: 0; background: none; padding: 6px 14px; border-radius: 7px; cursor: pointer; color: var(--text-2); font-weight: 500; }
.ansicht button.aktiv { background: var(--flaeche); color: var(--text); box-shadow: var(--schatten); }

.zyklus-reiter { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }

.block { margin-bottom: 18px; }
.block h3 { display: flex; align-items: center; gap: 8px; font-size: .95rem; }
.block h3::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--haupt); }
.block.obligat h3::before { background: var(--obligat); }
.block.optional h3::before, .block.bedarf h3::before, .block.begleit h3::before { background: var(--optional); }

.tabelle-wrap { overflow-x: auto; }
table.med { border-collapse: collapse; width: 100%; font-size: .9rem; }
table.med th, table.med td { padding: 6px 7px; text-align: left; border-bottom: 1px solid var(--rand); vertical-align: top; }
table.med th { font-size: .72rem; color: var(--text-2); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; white-space: nowrap; background: var(--flaeche-2); }
table.med td.tag { white-space: nowrap; font-variant-numeric: tabular-nums; }
table.med td.sub { font-weight: 600; }
table.med td.dosis { white-space: nowrap; font-variant-numeric: tabular-nums; }
table.med td.trg { min-width: 8em; }
table.med td.bem { font-size: .82rem; color: var(--text-2); min-width: 16em; }
.block.haupt table.med td.sub { color: var(--haupt); }
table.med td.mobil { display: none; }
@media (max-width: 700px) {
  table.med thead { display: none; }
  table.med, table.med tbody, table.med tr, table.med td { display: block; width: auto; }
  table.med tr { display: grid; grid-template-columns: auto 1fr auto; gap: 0 10px; padding: 8px 2px; border-bottom: 1px solid var(--rand); }
  table.med td { border: 0; padding: 1px 0; }
  table.med td.tag { grid-column: 1; grid-row: 1; color: var(--text-2); }
  table.med td.sub { grid-column: 2; grid-row: 1; }
  table.med td.dosis { grid-column: 3; grid-row: 1; text-align: right; }
  table.med td.misc { display: none; }
  table.med td.mobil { display: block; grid-column: 1 / 4; font-size: .84rem; color: var(--text); }
  table.med td.bem { grid-column: 1 / 4; min-width: 0; }
  table.med td:empty { display: none; }
}

.infos { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; font-size: .92rem; }
.infos dt { font-weight: 600; color: var(--text-2); }
.infos dd { margin: 0; }
@media (max-width: 600px) { .infos { grid-template-columns: 1fr; gap: 2px; } .infos dd { margin-bottom: 8px; } }

/* ---------- Therapieblatt-Download ---------- */
.tb-form p { margin: 4px 0 10px; }
.tb-felder { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.tb-felder label:first-child { width: 9em; }
.schalter { display: inline-flex; align-items: center; gap: 6px; font-size: .9rem; color: var(--text); cursor: pointer; padding-bottom: 8px; }
.schalter input { width: auto; margin: 0; accent-color: var(--akzent); }

/* ---------- PDF-Ansicht ---------- */
.pdf-leiste { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.pdf-seiten { display: flex; flex-direction: column; gap: 12px; align-items: center; overflow-x: auto; }
.pdf-seiten canvas { max-width: none; background: #fff; box-shadow: var(--schatten); border: 1px solid var(--rand); }
.pdf-seiten .lade { color: var(--text-2); padding: 2rem; }

/* ---------- Gliederung ---------- */
.baum { list-style: none; margin: 0; padding: 0; }
.baum details { border-bottom: 1px solid var(--rand); }
.baum summary { cursor: pointer; padding: 10px 4px; font-weight: 600; display: flex; gap: 8px; align-items: baseline; }
.baum summary .n, .baum a .n { margin-left: auto; font-weight: 400; color: var(--text-2); font-size: .85rem; }
.baum ul { list-style: none; margin: 0 0 8px; padding: 0 0 0 18px; }
.baum li a { display: flex; gap: 8px; padding: 6px 4px; text-decoration: none; color: var(--text); border-radius: 6px; }
.baum li a:hover { background: var(--flaeche-2); }
.baum li a.ober { font-weight: 500; }
.baum ul ul { padding-left: 16px; }
.baum ul ul a { font-size: .9rem; color: var(--text-2); }

/* ---------- Dialog und Meldungen ---------- */
.meldung {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar) + 16px); z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; box-shadow: var(--schatten); max-width: calc(100vw - 32px);
}
.meldung.fehler { background: var(--gefahr); color: #fff; }
@media (min-width: 761px) { .meldung { bottom: 24px; } }

.login { max-width: 360px; margin: 8vh auto; }
.info-text p { max-width: 75ch; }
.quell-daten { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: .92rem; }
.quell-daten dt { color: var(--text-2); }
.quell-daten dd { margin: 0; }

/* ---------- Druck ---------- */
@media print {
  .kopf, .tabs, .knopfleiste, .nicht-drucken, .zurueck { display: none !important; }
  body { background: #fff; color: #000; font-size: 10pt; }
  .inhalt { padding: 0; max-width: none; }
  .karte { border: 0; box-shadow: none; padding: 0; }
  table.med th { background: none; }
}
