:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #1d2624;
  --muted: #66736f;
  --line: #e1e7e5;
  --primary: #0f6b63;
  --primary-ink: #ffffff;
  --primary-soft: #e3f1ef;
  --red: #c0392b;
  --red-soft: #fbe9e7;
  --orange: #c56a00;
  --orange-soft: #fdf1e1;
  --blue: #2463a6;
  --blue-soft: #e5eef8;
  --green: #2e8b57;
  --grey: #8a9592;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 2px 8px rgba(0, 0, 0, .04);
  --nav-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111615;
    --card: #1b2220;
    --text: #e7eeec;
    --muted: #93a19d;
    --line: #2c3633;
    --primary: #3fb3a6;
    --primary-ink: #0b1513;
    --primary-soft: #19302d;
    --red: #ef7b6c;
    --red-soft: #3a1f1c;
    --orange: #f0a34a;
    --orange-soft: #382a17;
    --blue: #79aee8;
    --blue-soft: #1a2737;
    --green: #5cc58a;
    --grey: #7d8a87;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}
body.bare { padding-bottom: 24px; }
a { color: var(--primary); }
h1 { font-size: 1.45rem; margin: .4rem 0 .8rem; line-height: 1.2; }
h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .3rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
code { font-size: .85rem; word-break: break-all; }

.topbar {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { display: block; line-height: 0; }
.brand img { width: 104px; height: 104px; }
.who { position: absolute; right: 16px; bottom: 10px; color: var(--muted); font-size: .85rem; }

.wrap { max-width: 720px; margin: 0 auto; padding: 12px 16px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  padding: 14px;
  margin-bottom: 12px;
}

.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 10px; font-size: .95rem; }
.flash-ok { background: var(--primary-soft); color: var(--primary); }
.flash-err { background: var(--red-soft); color: var(--red); }
.flash-info { background: var(--blue-soft); color: var(--blue); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-height: 42px; padding: 8px 14px;
  border: 1px solid var(--line); border-radius: 11px;
  background: var(--card); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--red); }
.btn-blue { background: var(--blue-soft); color: var(--blue); border-color: transparent; }
.btn-out { background: var(--primary-soft); color: var(--primary); border-color: transparent; min-height: 54px; font-size: 1.05rem; flex: 1; }
.btn-sm { min-height: 34px; padding: 4px 10px; font-size: .88rem; }
.btn-lg { min-height: 54px; padding: 12px 24px; font-size: 1.1rem; }
.btn-block { width: 100%; }
.btnrow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.big-btns form { flex: 1; display: flex; }
.big-btns .btn { width: 100%; }
form.inline { display: inline; margin: 0; }
.linkbtn { background: none; border: 0; color: var(--red); font: inherit; font-size: .85rem; cursor: pointer; padding: 0 0 8px; }

/* Forms */
.form label { display: block; margin-bottom: 12px; font-size: .9rem; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  display: block; width: 100%; margin-top: 4px;
  min-height: 44px; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text);
  font: inherit; font-size: 16px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; }
.check { display: flex !important; align-items: center; gap: 8px; color: var(--text) !important; }
.check input { width: 20px; height: 20px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.input-with-btn { display: flex; gap: 8px; margin-top: 4px; }
.input-with-btn input { margin-top: 0; }
.code-input { text-align: center; font-size: 1.6rem !important; letter-spacing: .3em; margin-bottom: 12px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.seg label { border: 1px solid var(--line); border-radius: 10px; padding: 10px; color: var(--text); margin: 0; cursor: pointer; }
.seg label:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.seg small { color: var(--muted); }
.photo-field { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.photo-field label.btn { margin: 0; color: var(--text); }
.row-form { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; }
.row-form input { margin: 0; }
.row-form .sort { width: 64px; flex: none; }
.row-del { text-align: right; margin: 0 0 6px; }
.sticky-save { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px); }

/* Filter */
.filters { margin-bottom: 12px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 6px 13px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--line);
  color: var(--text); text-decoration: none; font-size: .92rem;
}
.chip.on { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.tabs { margin-bottom: 12px; }
.filter-row { display: flex; gap: 8px; }
.filter-row input { flex: 1.4; margin: 0; }
.filter-row select { flex: 1; margin: 0; }

/* Hinweise */
.alerts h2, .section { display: flex; align-items: center; gap: 8px; }
.count { background: var(--line); border-radius: 999px; padding: 1px 8px; font-size: .8rem; font-weight: 600; }
.alerts ul, .problems { list-style: none; margin: 0; padding: 0; }
.alerts li a { display: block; padding: 8px 0 8px 12px; border-top: 1px solid var(--line); color: var(--text); text-decoration: none; }
.alerts li span { display: block; font-size: .88rem; color: var(--muted); }
.alerts li, .problems li { border-left: 4px solid var(--orange); margin: 6px 0; }
.problems li { padding: 6px 10px; background: var(--orange-soft); border-radius: 0 8px 8px 0; font-size: .9rem; }
li.is-red { border-left-color: var(--red); }
.problems li.is-red { background: var(--red-soft); }
li.alert-ordered { border-left-color: var(--blue); }
.problems li.alert-ordered { background: var(--blue-soft); }

/* Medikamentenliste */
.medlist { list-style: none; margin: 0; padding: 0; }
.med { margin-bottom: 8px; }
.med > a {
  display: flex; gap: 12px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--green);
  border-radius: var(--radius); padding: 10px 12px;
  color: var(--text); text-decoration: none; box-shadow: var(--shadow);
}
.lvl-red > a { border-left-color: var(--red); }
.lvl-orange > a { border-left-color: var(--orange); }
.lvl-blue > a { border-left-color: var(--blue); }
.lvl-grey > a { border-left-color: var(--grey); }
.thumb { width: 54px; height: 54px; border-radius: 10px; object-fit: cover; flex: none; background: var(--primary-soft); }
.thumb-empty { display: inline-flex; align-items: center; justify-content: center; font-weight: 700; color: var(--primary); font-size: 1.3rem; }
.med-body { min-width: 0; flex: 1; }
.med-title { display: flex; gap: 6px; align-items: baseline; justify-content: space-between; }
.med-title .name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.med-meta { font-size: .88rem; color: var(--muted); }
.med-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.badge { flex: none; font-size: .75rem; background: var(--primary-soft); color: var(--primary); padding: 1px 8px; border-radius: 999px; font-weight: 600; }
.tag { font-size: .74rem; padding: 1px 7px; border-radius: 6px; background: var(--line); color: var(--muted); font-weight: 600; }
.tag-red { background: var(--red-soft); color: var(--red); }
.tag-orange { background: var(--orange-soft); color: var(--orange); }
.tag-blue { background: var(--blue-soft); color: var(--blue); }
.tag-grey { background: var(--line); color: var(--muted); }
.tag-green { background: var(--primary-soft); color: var(--green); }
.txt-red { color: var(--red); font-weight: 600; }
.txt-orange { color: var(--orange); font-weight: 600; }

/* Detail */
.med-head { display: flex; gap: 14px; align-items: center; margin-bottom: 12px; }
.med-head h1 { margin: 0 0 4px; }
.hero { width: 92px; height: 92px; border-radius: 14px; object-fit: cover; flex: none; background: var(--primary-soft); cursor: zoom-in; }
.hero.thumb-empty { font-size: 2rem; cursor: default; }
.stock { border-top: 5px solid var(--green); }
.stock.lvl-red { border-top-color: var(--red); }
.stock.lvl-orange { border-top-color: var(--orange); }
.stock.lvl-blue { border-top-color: var(--blue); }
.stock.lvl-grey { border-top-color: var(--grey); }
.stock-main { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.label { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; margin-top: 8px; }
.big { font-size: 1.2rem; font-weight: 700; }
.reach { text-align: right; }
.amount-form { display: flex; gap: 8px; margin-top: 8px; }
.amount-form input { margin: 0; max-width: 140px; }
.scanbox { background: var(--primary-soft); border-color: transparent; }
.pkg-head { display: flex; justify-content: space-between; gap: 8px; }
.pkg-meta { font-size: .88rem; color: var(--muted); margin-top: 2px; }
details { margin-top: 10px; }
summary { cursor: pointer; color: var(--primary); font-size: .9rem; }
details .form { margin-top: 10px; }
.info dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: .92rem; }
.info dt { color: var(--muted); }
.info dd { margin: 0; }
.notes { white-space: normal; font-size: .92rem; border-top: 1px solid var(--line); padding-top: 8px; }
.history { list-style: none; margin: 0; padding: 0; }
.history li { display: grid; grid-template-columns: 82px 1fr auto; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); font-size: .92rem; align-items: start; }
.history li:first-child { border-top: 0; }
.footer-actions { justify-content: center; margin: 16px 0; }
.pick { padding-left: 18px; }
.pick li { margin: 6px 0; }
.report h3 { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.cron-url { display: block; background: var(--bg); padding: 8px; border-radius: 8px; user-select: all; }

/* Login */
.auth { max-width: 400px; margin: 6vh auto 0; }
.auth h1 { text-align: center; }
.auth-logo { display: block; margin: 0 auto 8px; border-radius: 16px; }
.steps { padding-left: 20px; font-size: .95rem; }
.qr { display: inline-block; padding: 10px; background: #fff; border-radius: 10px; margin: 6px 0; }
.qr img, .qr canvas { display: block; }
.secret { font-size: 1rem; letter-spacing: .05em; }

/* Untere Navigation */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .72rem; font-weight: 600;
}
.tabbar svg { width: 26px; height: 26px; }
.tabbar a.on { color: var(--primary); }

/* Scanner */
.scanner { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .88); display: flex; align-items: center; justify-content: center; padding: 16px; }
.scanner[hidden] { display: none; }
.scanner-inner { width: 100%; max-width: 480px; }
#reader { width: 100%; border-radius: 12px; overflow: hidden; background: #000; }
#reader video { width: 100% !important; }
.scanner-hint { color: #ddd; font-size: .9rem; text-align: center; }
.scanner-error { color: #ffb4a8; text-align: center; }

/* Lightbox (iPhone-Home-App: Bilder nie direkt öffnen) */
.lightbox { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .92); display: flex; align-items: center; justify-content: center; padding: 16px; }
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }
.lb-close { position: absolute; top: calc(env(safe-area-inset-top) + 10px); right: 14px; width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .15); color: #fff; font-size: 1.8rem; line-height: 1; cursor: pointer; }

.empty { text-align: center; }
[data-kind][hidden] { display: none !important; }

@media (max-width: 380px) {
  .grid2 { grid-template-columns: 1fr; }
}
