:root {
  --bg: #f2f5f4;
  --surface: #ffffff;
  --ink: #1e2b29;
  --muted: #74837f;
  --primary: #0f6b63;
  --primary-dark: #0a4f49;
  --line: #dde6e4;
  --danger: #a11d1d;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(0,0,0,.08);
  --shadow-lg: 0 10px 40px rgba(0,0,0,.25);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--ink); line-height: 1.45;
}
.hidden { display: none !important; }
.no-scroll { overflow: hidden; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-weight: 600; border: none; border-radius: 12px;
  padding: 12px 18px; cursor: pointer; transition: filter .15s, background .15s;
}
.btn-block { display: block; width: 100%; margin-top: 10px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-ghost { background: #e4ecea; color: var(--ink); }
.btn-ghost:hover { filter: brightness(.97); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-ghost { background: #f7e3e1; color: var(--danger); }
.btn-small { padding: 7px 12px; font-size: .9rem; text-decoration: none; display: inline-block; }

/* ---------- Topbar ---------- */
.app { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--primary);
  color: #fff; padding-top: var(--safe-top); box-shadow: var(--shadow);
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px 8px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.15rem; }
.brand-icon { font-size: 1.3rem; }
.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
  background: rgba(255,255,255,.15); color: #fff; border: none; width: 38px; height: 38px;
  border-radius: 10px; font-size: 1.2rem; font-weight: 700; cursor: pointer;
}
.icon-btn:hover { background: rgba(255,255,255,.28); }
#btn-notfall { background: rgba(255,255,255,.9); color: var(--danger); }
.searchbar { padding: 0 16px 10px; }
.searchbar input {
  width: 100%; border: none; border-radius: 12px; padding: 11px 14px;
  font: inherit; background: rgba(255,255,255,.95);
}
.filters { display: flex; align-items: center; gap: 8px; padding: 0 16px 12px; overflow-x: auto; }
.chip {
  border: none; border-radius: 999px; padding: 6px 14px; font: inherit; font-size: .9rem;
  background: rgba(255,255,255,.2); color: #fff; cursor: pointer; white-space: nowrap;
}
.chip-active { background: #fff; color: var(--primary); font-weight: 600; }
.count { margin-left: auto; font-size: .85rem; opacity: .85; white-space: nowrap; }

/* ---------- Liste ---------- */
.content { flex: 1; padding: 14px 16px calc(90px + var(--safe-bottom)); }
.liste { display: flex; flex-direction: column; gap: 10px; }
.eintrag {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 14px; cursor: pointer; display: flex; gap: 12px; align-items: stretch;
}
.eintrag:hover { filter: brightness(.99); }
/* Farbiger Balken links = Schweregrad. Das ist die Information, die man
   beim Durchscrollen zuerst braucht. */
.grad-balken { width: 6px; border-radius: 3px; flex: none; }
.eintrag-body { flex: 1; min-width: 0; }
.eintrag-titel { font-weight: 700; }
.eintrag-sub { color: var(--muted); font-size: .9rem; }
.eintrag-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.badge {
  font-size: .78rem; padding: 3px 9px; border-radius: 999px;
  background: #e4ecea; color: #3d514d; white-space: nowrap;
}
.badge-grad { color: #fff; }
.badge-fehlt { background: #fdf1dc; color: #8a5a10; }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }

/* Sicherungs-Hinweis. Gedaempft statt alarmierend - er steht oft da, und
   was staendig schreit, wird weggeklickt statt gelesen. */
.sicherung {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: #fdf1dc; color: #6f4a0c; border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 12px;
}
.sicherung-text { flex: 1; min-width: 160px; font-size: .9rem; }

.fab {
  position: fixed; right: 20px; bottom: calc(20px + var(--safe-bottom));
  width: 58px; height: 58px; border-radius: 50%; border: none;
  background: var(--primary); color: #fff; font-size: 2rem; line-height: 1;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); cursor: pointer; z-index: 30;
}

/* ---------- Menue ---------- */
.menu {
  position: fixed; right: 14px; top: calc(58px + var(--safe-top)); z-index: 40;
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg);
  overflow: hidden; min-width: 220px;
}
.menu button {
  display: block; width: 100%; text-align: left; padding: 13px 18px;
  background: none; border: none; font: inherit; cursor: pointer;
}
.menu button:hover { background: #eef3f2; }
.menu-danger { color: var(--danger); border-top: 1px solid var(--line); }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.modal-sheet {
  position: relative; background: var(--bg); width: 100%; max-height: 94%;
  border-radius: 20px 20px 0 0; overflow-y: auto; padding-bottom: var(--safe-bottom);
}
.modal-top { display: flex; align-items: center; padding: 8px 10px; position: sticky; top: 0; background: var(--bg); z-index: 2; }
.modal-back {
  border: none; background: #e4ecea; width: 40px; height: 40px; border-radius: 12px;
  font-size: 1.6rem; line-height: 1; cursor: pointer; color: var(--ink);
}
.modal-handle { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto; }
.modal-top-spacer { width: 40px; }

.detail { padding: 4px 18px 26px; }
.detail-titel { font-size: 1.5rem; margin-bottom: 2px; }
.detail-sub { color: var(--muted); margin-bottom: 14px; }
.zeile { display: flex; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.zeile-label { color: var(--muted); flex: none; width: 46%; }
.zeile-wert { flex: 1; }
.abschnitt { margin-top: 22px; font-weight: 700; }

.doc {
  display: flex; align-items: center; gap: 10px; background: var(--surface);
  border-radius: 12px; padding: 10px 12px; margin-top: 8px;
}
.doc-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-sub { color: var(--muted); font-size: .82rem; }
.doc-icon { font-size: 1.4rem; }

/* ---------- Formular ---------- */
.form { padding: 4px 18px 26px; }
.feld { margin-top: 14px; }
.feld label { display: block; font-size: .88rem; color: var(--muted); margin-bottom: 4px; }
.feld input, .feld select, .feld textarea {
  width: 100%; font: inherit; padding: 11px 13px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--surface); color: var(--ink);
}
.feld textarea { min-height: 78px; resize: vertical; }
.feld-hinweis { font-size: .82rem; color: var(--muted); margin-top: 4px; }
.form-aktionen { display: flex; gap: 10px; margin-top: 22px; }
.form-aktionen .btn { flex: 1; }

/* ---------- Notfall-Ansicht ---------- */
.notfall {
  position: fixed; inset: 0; z-index: 60; background: #fff; overflow-y: auto;
  padding: calc(18px + var(--safe-top)) 18px calc(18px + var(--safe-bottom));
}
.notfall-inner { max-width: 620px; margin: 0 auto; }
.notfall h1 { font-size: 1.3rem; color: var(--danger); letter-spacing: .04em; text-transform: uppercase; }
.notfall-person { font-size: 1.15rem; font-weight: 700; margin-top: 4px; }
.notfall-hinweis { background: #fdecec; color: #7d1616; border-radius: 12px; padding: 12px 14px; margin-top: 12px; }
.notfall-gruppe { margin-top: 20px; }
.notfall-gruppe h2 { font-size: 1rem; letter-spacing: .03em; text-transform: uppercase; color: var(--muted); }
.notfall-zeile {
  display: flex; align-items: baseline; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line);
  font-size: 1.25rem; font-weight: 700;
}
.notfall-text { flex: 1; min-width: 0; }
/* Der Zusatz steht bewusst in einer eigenen Zeile: Beim schnellen Draufschauen
   soll das Allergen allein stehen, nicht mit der Beschreibung verschmelzen. */
.notfall-text small { display: block; font-size: .82rem; font-weight: 400; color: var(--muted); }
.notfall-punkt { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.notfall-fuss { color: var(--muted); font-size: .85rem; margin-top: 22px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(90px + var(--safe-bottom)); z-index: 70;
  background: #1e2b29; color: #fff; padding: 12px 18px; border-radius: 12px;
  box-shadow: var(--shadow-lg); max-width: 88%; text-align: center;
}

.notfall-aktionen { display: flex; gap: 10px; margin-top: 24px; }
.notfall-aktionen .btn { flex: 1; }

/* ---------- Druck ---------- */
/* Gedruckt wird ausschliesslich die Notfall-Ansicht - ein Blatt fuer die
   Brieftasche oder zum Dalassen beim Arzt. Die Liste auf Papier waere
   sinnlos, deshalb verschwindet der Rest der App komplett.
   Der Druckdialog beider Handy-Systeme kann auch "als PDF sichern"; ein
   eigener PDF-Export eruebrigt sich damit. */
@media print {
  .app, .modal, .toast, .fab, .menu, .notfall-aktionen { display: none !important; }

  body { background: #fff; }
  .notfall {
    position: static; overflow: visible; padding: 0;
  }
  .notfall-inner { max-width: none; }

  /* Auf Papier trennt Farbe nicht zuverlaessig - die Schweregrade brauchen
     deshalb einen Rand, der auch im Schwarzweissdruck stehen bleibt. */
  .notfall-hinweis { background: none; color: #000; border: 2px solid #000; }
  .notfall-punkt { border: 1px solid #000; }

  /* Ein Eintrag soll nicht ueber den Seitenumbruch zerrissen werden. */
  .notfall-gruppe, .notfall-zeile { break-inside: avoid; page-break-inside: avoid; }
  .notfall h1, .notfall-gruppe h2 { color: #000; }
}

@page { margin: 14mm; }
