:root {
  --bg: #f5f1e8;
  --card: #fbf8f1;
  --text: #2a2622;
  --muted: #766e62;
  --line: #ddd5c4;
  --accent: #2f6b4f;
  --accent-soft: #e3ebe1;
  --danger: #a8402f;
  --radius: 8px;
  --nav-h: 60px;
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, "Times New Roman", serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1a17;
    --card: #252220;
    --text: #ece6da;
    --muted: #9a9285;
    --line: #38342d;
    --accent: #7fb596;
    --accent-soft: #2a3a31;
    --danger: #e08a78;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ---------- Navigation: mobil unten, am Desktop links ---------- */
#nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: var(--bg);
  border-top: 1px solid var(--line);
}
#nav .brand { display: none; }
#nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--muted); text-decoration: none; font-size: 11px;
}
#nav a svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
#nav a.active { color: var(--accent); font-weight: 600; box-shadow: inset 0 2px 0 var(--accent); }

#view {
  max-width: 720px; margin: 0 auto;
  padding: 22px 16px calc(var(--nav-h) + 28px + env(safe-area-inset-bottom));
}
@media (min-width: 900px) {
  #nav {
    top: 0; bottom: auto; right: auto; width: 220px; height: 100%;
    flex-direction: column; gap: 2px; padding: 28px 0;
    border-top: 0; border-right: 1px solid var(--line);
  }
  #nav .brand { display: block; font: 600 24px/1 var(--serif); padding: 0 24px 26px; }
  #nav a {
    flex: none; flex-direction: row; justify-content: flex-start; gap: 12px;
    font-size: 15px; padding: 10px 24px; box-shadow: none; border-left: 3px solid transparent;
  }
  #nav a.active { box-shadow: none; border-left-color: var(--accent); background: var(--accent-soft); }
  #view { margin-left: 220px; max-width: none; padding: 36px 44px 56px; }
  #view > * { max-width: 720px; }
  #view > .page.wide { max-width: 1060px; }
}

.page { animation: fade .12s ease-out both; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .page { animation: none; } }

h1 { font: 600 30px/1.2 var(--serif); margin: 0 0 4px; }
h2 { font: 600 18px/1.3 var(--serif); margin: 0; }
h3.group { font-size: 13px; font-weight: 600; color: var(--muted); margin: 14px 0 2px; }
h3.group:first-of-type { margin-top: 4px; }
.sub { color: var(--muted); margin: 0 0 20px; }
.muted { color: var(--muted); }

/* ---------- Karten / Listen ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 14px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.card-head a { color: var(--accent); font-size: 14px; }
.card-head .count { color: var(--muted); font-size: 14px; }
.grid { display: grid; gap: 14px; }
.grid > .card { margin-bottom: 0; }
.grid.two { margin-bottom: 14px; }
@media (min-width: 900px) { .grid.two { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1100px) { .grid.three { grid-template-columns: repeat(3, 1fr); align-items: start; } }

.stats { display: flex; gap: 36px; padding: 12px 0; margin-bottom: 18px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.stat b { display: inline-block; margin-right: 8px; font: 600 28px/1 var(--serif); }
.stat span { color: var(--muted); }

.dish { font: 20px/1.3 var(--serif); margin: 4px 0 2px; overflow-wrap: anywhere; }

.list { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-top: 1px solid var(--line); }
.list .row:first-child { border-top: 0; }
.row .label { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.row .label small { display: block; color: var(--muted); font-size: 12px; }
.row.done .label { text-decoration: line-through; color: var(--muted); }
.empty { color: var(--muted); padding: 6px 0; margin: 0; }
.done-sep { margin: 12px 0 0; padding-top: 10px; border-top: 1px dashed var(--line); display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 13px; }

.check {
  appearance: none; -webkit-appearance: none; flex: none; width: 22px; height: 22px; margin: 0;
  border: 1.5px solid var(--muted); border-radius: 5px; background: transparent; cursor: pointer;
  display: grid; place-content: center;
}
.check:checked { background: var(--accent); border-color: var(--accent); }
.check:checked::after { content: ""; width: 5px; height: 10px; border: solid var(--bg); border-width: 0 2px 2px 0; transform: rotate(45deg) translate(-1px, -1px); }
.check:focus-visible, button:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.icon-btn { flex: none; width: 34px; height: 34px; border: 0; background: transparent; color: var(--muted); border-radius: 6px; display: grid; place-content: center; }
.icon-btn:hover { color: var(--accent); background: var(--accent-soft); }
.icon-btn.danger:hover { color: var(--danger); background: transparent; }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Formulare ---------- */
.add { display: flex; gap: 8px; margin: 0 0 10px; }
input[type=text], input[type=password] {
  width: 100%; padding: 10px 12px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--bg); min-width: 0;
}
input[type=text]:focus, input[type=password]:focus { border-color: var(--accent); outline: none; }
.btn { border: 1px solid var(--accent); background: var(--accent); color: var(--bg); font-weight: 600; padding: 10px 16px; border-radius: 6px; white-space: nowrap; }
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--line); }
.btn.plus { padding: 6px 16px; font-size: 22px; line-height: 1.2; }
.btn.small { padding: 5px 10px; font-size: 13px; font-weight: 500; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.msg { min-height: 1.3em; font-size: 14px; margin: 8px 0 0; }
.msg.err { color: var(--danger); }
.msg.good { color: var(--accent); }
label.field { display: block; font-size: 14px; color: var(--muted); margin: 12px 0 5px; }

/* ---------- Essensplan ---------- */
.weeknav { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.weeknav .title { flex: 1; text-align: center; font: 600 17px/1.3 var(--serif); }
.weeknav .title .muted { font: 14px system-ui, sans-serif; }
.meal-list { padding: 0; overflow: hidden; }
.meal-row { display: flex; align-items: center; gap: 14px; padding: 10px 16px; border-top: 1px solid var(--line); border-left: 3px solid transparent; min-height: 58px; }
.meal-row:first-child { border-top: 0; }
.meal-row.today { border-left-color: var(--accent); background: var(--accent-soft); }
.meal-date { width: 104px; flex: none; line-height: 1.25; }
.meal-date b { display: block; font-weight: 600; }
.meal-date span { font-size: 13px; color: var(--muted); }
.meal-row button.meal { flex: 1; text-align: left; background: transparent; border: 0; padding: 6px 8px; border-radius: 6px; overflow-wrap: anywhere; font-family: var(--serif); font-size: 17px; }
.meal-row button.meal:hover { background: var(--accent-soft); }
.meal-row.today button.meal:hover { background: var(--bg); }
.meal-row button.meal.empty-slot { color: var(--muted); font-family: inherit; font-size: 15px; }
.meal-input { flex: 1; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; padding: 26px 24px; }
.login-card h1 { text-align: center; }
.login-card .sub { text-align: center; }
.login-card .btn { width: 100%; margin-top: 18px; padding: 12px; }
.logo { display: block; width: 52px; height: 52px; margin: 0 auto 12px; }

/* ---------- Hinweis ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 30;
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 6px;
  font-size: 14px; max-width: calc(100% - 32px);
}
@media (min-width: 900px) { .toast { bottom: 24px; } }

/* ---------- Rezepte ---------- */
textarea {
  width: 100%; padding: 10px 12px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--bg); font: inherit; resize: vertical; min-height: 150px;
}
textarea:focus { border-color: var(--accent); outline: none; }
.hint { font-size: 13px; margin: 6px 0 0; }
.recipe { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; }
.recipe summary { display: flex; align-items: center; gap: 10px; padding: 14px 16px; cursor: pointer; list-style: none; }
.recipe summary::-webkit-details-marker { display: none; }
.recipe summary::after {
  content: ""; flex: none; width: 8px; height: 8px; margin: -3px 2px 0 4px;
  border: solid var(--muted); border-width: 0 2px 2px 0; transform: rotate(45deg); transition: transform .15s;
}
.recipe[open] summary::after { transform: rotate(-135deg); margin-top: 3px; }
.recipe summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: var(--radius); }
.recipe .rname { flex: 1; min-width: 0; font: 600 18px/1.3 var(--serif); overflow-wrap: anywhere; }
.recipe .rcount { color: var(--muted); font-size: 13px; white-space: nowrap; }
.recipe-body { padding: 4px 18px 16px; border-top: 1px solid var(--line); }
ol.ingredients { margin: 12px 0 4px; padding-left: 26px; }
ol.ingredients li { padding: 2px 0 2px 4px; overflow-wrap: anywhere; }
.recipe-form .actions { margin-top: 14px; }
.to-shop { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); }
.to-shop h3 { font: 600 16px/1.3 var(--serif); margin: 0 0 6px; }
.quick { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 6px 0 4px; font-size: 14px; color: var(--muted); }
.to-shop .row .label { min-width: 0; }
.to-shop .row.off .label { color: var(--muted); }
.seg { display: flex; flex: none; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg label { position: relative; display: block; }
.seg input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.seg span { display: block; padding: 5px 10px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.seg label + label span { border-left: 1px solid var(--line); }
.seg input:checked + span { background: var(--accent); color: var(--bg); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Rezept im Essensplan waehlen */
.meal-cell { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; }
.recipe-link { color: var(--accent); font-size: 14px; white-space: nowrap; }
.picker { flex: 1; min-width: 0; }
.suggest { list-style: none; margin: 6px 0 0; padding: 0; }
.suggest:empty { display: none; }
.suggest-item { display: block; width: 100%; text-align: left; background: transparent; border: 0; padding: 8px 10px; border-radius: 6px; font: 16px var(--serif); }
.suggest-item:hover, .suggest-item:focus-visible { background: var(--bg); }
.meal-row.today .suggest-item:hover { background: var(--card); }

/* Zutaten im Essensplan, Mengen, Tagesauswahl */
.meal-ing { border-top: 1px solid var(--line); padding: 0 16px 0 19px; background: var(--card); }
.meal-ing summary { cursor: pointer; padding: 8px 0 8px 118px; font-size: 14px; color: var(--accent); }
.meal-ing-body { padding: 0 0 14px 118px; }
.meal-ing-body .to-shop { margin-top: 8px; }
.row .label small.onlist { color: var(--accent); }
.qty { font-weight: 700; color: var(--accent); white-space: nowrap; }
.btn.minus { padding: 2px 9px; }
.list.days .row { padding: 0; }
.day-pick { flex: 1; text-align: left; background: transparent; border: 0; padding: 11px 4px; font: inherit; color: inherit; cursor: pointer; border-radius: 6px; }
.day-pick:hover, .day-pick:focus-visible { background: var(--accent-soft); }
.day-pick small.taken { display: block; color: var(--muted); font-size: 12px; }
@media (max-width: 640px) {
  .meal-ing { padding-left: 16px; }
  .meal-ing summary, .meal-ing-body { padding-left: 0; }
}
