/* FamilyPlanner — eigenes, warmes Design (bewusst KEIN EDATRON-CD).
   Mobile-first: Bottom-Tab-Bar am Smartphone, Top-Tabs ab 768 px. */
:root {
  --paper: #f7f3ec;
  --card: #ffffff;
  --ink: #33302b;
  --muted: #8a8378;
  --line: #e7e0d4;
  --accent: #d97a4e;          /* Terracotta */
  --accent-deep: #b95f37;
  --accent-soft: #f9e7dc;
  --sage: #6f8f6f;
  --header: #3c5140;          /* dunkles Salbeigrün, Header + Bottom-Nav */
  --header-ink: #f7f3ec;
  --green: #5d9e64;
  --yellow: #e0a63a;
  --red: #d9604f;
  --green-soft: #e2efe3;
  --yellow-soft: #f9eed3;
  --red-soft: #f9e0dc;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(60, 50, 40, .08);
  font-size: clamp(15.5px, 1vw + 11px, 17px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--paper);
  color: var(--ink);
  min-height: 100dvh;
  padding-bottom: calc(64px + env(safe-area-inset-bottom)); /* Platz für Bottom-Nav */
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-deep); }

/* ---------- Header ---------- */
header.app {
  position: sticky; top: 0; z-index: 30;
  background: var(--header); color: var(--header-ink);
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem .9rem;
  padding-top: calc(.55rem + env(safe-area-inset-top));
  box-shadow: 0 2px 12px rgba(40, 50, 40, .25);
}
.wordmark { font-weight: 700; font-size: 1.15rem; letter-spacing: .2px; display: flex; align-items: center; gap: .45rem; }
.wordmark .mark { width: 26px; height: 26px; }
.wordmark b { color: #f0c86a; font-weight: 700; }
header.app .spacer { flex: 1; }
.iconbtn {
  background: rgba(255, 255, 255, .12); border: 0; border-radius: 10px;
  width: 38px; height: 38px; display: grid; place-items: center;
  color: var(--header-ink); cursor: pointer; font-size: 1.05rem;
}
.iconbtn:active { background: rgba(255, 255, 255, .25); }
nav.tabs { display: none; gap: .15rem; margin-left: .8rem; }
nav.tabs button {
  background: none; border: 0; color: var(--header-ink); opacity: .75;
  padding: .45rem .7rem; border-radius: 9px; cursor: pointer; font-weight: 600;
}
nav.tabs button.active { background: rgba(255, 255, 255, .16); opacity: 1; }

/* ---------- Bottom-Nav (mobil) ---------- */
nav.bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--header);
  display: flex; justify-content: space-around;
  padding: .3rem .2rem calc(.3rem + env(safe-area-inset-bottom));
  box-shadow: 0 -2px 12px rgba(40, 50, 40, .25);
}
nav.bottom button {
  background: none; border: 0; color: var(--header-ink); opacity: .65;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: .68rem; padding: .25rem .55rem; border-radius: 10px; cursor: pointer;
  min-width: 56px;
}
nav.bottom button svg { width: 22px; height: 22px; }
nav.bottom button.active { opacity: 1; background: rgba(255, 255, 255, .14); }

/* ---------- Layout ---------- */
main { max-width: 1100px; margin: 0 auto; padding: 1rem .9rem 2rem; }
.view { display: none; }
.view.active { display: block; }
.viewhead { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin: .3rem 0 .9rem; }
.viewhead h2 { margin: 0; font-size: 1.35rem; }
.viewhead .spacer { flex: 1; }
h3 { font-size: 1.02rem; margin: 1.1rem 0 .5rem; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: .9rem; margin-bottom: .8rem; border: 1px solid var(--line);
}
.grid { display: grid; gap: .8rem; }
@media (min-width: 700px) { .grid.cols2 { grid-template-columns: 1fr 1fr; } }

/* ---------- Buttons ---------- */
.btn {
  background: var(--accent); color: #fff; border: 0; border-radius: 11px;
  padding: .55rem 1rem; font-weight: 650; cursor: pointer;
  display: inline-flex; align-items: center; gap: .4rem;
}
.btn:active { background: var(--accent-deep); }
.btn.secondary { background: #efe9dd; color: var(--ink); }
.btn.ghost { background: none; color: var(--accent-deep); padding: .55rem .6rem; }
.btn.danger { background: var(--red); }
.btn.small { padding: .32rem .65rem; font-size: .85rem; border-radius: 9px; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- Formulare ---------- */
label.field { display: block; margin-bottom: .7rem; }
label.field span { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .22rem; font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  padding: .55rem .65rem; background: #fff; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--sage); box-shadow: 0 0 0 3px rgba(111, 143, 111, .18); }
textarea { min-height: 110px; resize: vertical; }
.row { display: flex; gap: .6rem; align-items: end; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 0; }
.row > .fix { flex: 0 0 auto; }

/* ---------- Chips / Badges ---------- */
.chip {
  display: inline-flex; align-items: center; gap: .3rem;
  background: #efe9dd; border-radius: 999px; padding: .18rem .6rem;
  font-size: .78rem; font-weight: 600; color: #6b6355;
}
.chip.accent { background: var(--accent-soft); color: var(--accent-deep); }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto; }
.dot.red { background: var(--red); }
.dot.yellow { background: var(--yellow); }
.dot.green { background: var(--green); }
.dot.paused { background: #c8c2b6; }
.badge {
  border-radius: 999px; padding: .15rem .55rem; font-size: .75rem; font-weight: 700;
}
.badge.red { background: var(--red-soft); color: #a33b2d; }
.badge.yellow { background: var(--yellow-soft); color: #92660d; }
.badge.green { background: var(--green-soft); color: #38663d; }

/* ---------- Listen ---------- */
.list { display: flex; flex-direction: column; gap: .55rem; }
.item {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: .7rem .8rem;
  display: flex; align-items: center; gap: .7rem;
}
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 650; }
.item .sub { font-size: .8rem; color: var(--muted); margin-top: .12rem; }
.item.clickable { cursor: pointer; }
.item.checked .title { text-decoration: line-through; color: var(--muted); font-weight: 500; }

/* große Touch-Checkbox (Einkauf) */
.check {
  width: 30px; height: 30px; border-radius: 9px; border: 2px solid var(--line);
  background: #fff; display: grid; place-items: center; cursor: pointer; flex: 0 0 auto;
  font-size: 1rem; color: transparent;
}
.check.on { background: var(--green); border-color: var(--green); color: #fff; }

/* ---------- Dashboard-Kacheln ---------- */
.tiles { display: grid; gap: .8rem; grid-template-columns: 1fr 1fr; }
@media (min-width: 900px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line); border-top: 4px solid var(--sage);
  padding: .8rem; cursor: pointer;
}
.tile.wide { grid-column: 1 / -1; }
.tile h4 { margin: 0 0 .4rem; font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.tile .big { font-size: 1.7rem; font-weight: 750; }
.tile .sub { font-size: .8rem; color: var(--muted); }

/* ---------- Wochenplan ---------- */
.week { display: grid; gap: .7rem; }
@media (min-width: 900px) { .week { grid-template-columns: repeat(7, 1fr); } }
.day { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: .55rem; }
.day.today { border-color: var(--accent); border-width: 2px; }
.day .dayhead { font-weight: 700; font-size: .85rem; margin-bottom: .35rem; display: flex; justify-content: space-between; }
.slot { border-top: 1px dashed var(--line); padding: .35rem 0; }
.slot .slotname { font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.meal {
  background: var(--accent-soft); border-radius: 9px; padding: .32rem .5rem; margin-top: .25rem;
  font-size: .85rem; font-weight: 600; color: #7a4326; cursor: pointer;
  display: flex; align-items: center; gap: .3rem;
}
.meal.free { background: #eee9df; color: #6b6355; }
.addmeal {
  width: 100%; margin-top: .3rem; border: 1px dashed var(--line); background: none;
  border-radius: 9px; color: var(--muted); cursor: pointer; padding: .22rem; font-size: .85rem;
}

/* Monatsansicht */
.month { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.mday {
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  min-height: 64px; padding: .2rem .3rem; font-size: .7rem; cursor: pointer;
}
.mday .n { font-weight: 700; }
.mday.out { opacity: .35; }
.mday.today { border-color: var(--accent); border-width: 2px; }
.mday .m { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #7a4326; }

/* ---------- Rezepte ---------- */
.recipes { display: grid; gap: .8rem; grid-template-columns: 1fr; }
@media (min-width: 640px) { .recipes { grid-template-columns: 1fr 1fr; } }
@media (min-width: 980px) { .recipes { grid-template-columns: 1fr 1fr 1fr; } }
.recipe { display: flex; gap: .7rem; align-items: stretch; cursor: pointer; }
.recipe .thumb {
  width: 74px; min-height: 74px; border-radius: 10px; background: var(--accent-soft);
  flex: 0 0 auto; object-fit: cover; display: grid; place-items: center; font-size: 1.6rem;
}
img.thumb { display: block; }
.stars { color: var(--accent); font-size: .85rem; letter-spacing: 1px; }

/* Emoji-Rating */
.emojirate { display: flex; gap: .25rem; }
.emojirate button {
  background: none; border: 1px solid transparent; font-size: 1.35rem; cursor: pointer;
  border-radius: 9px; padding: .1rem .25rem; filter: grayscale(1); opacity: .55;
}
.emojirate button.on { filter: none; opacity: 1; background: var(--accent-soft); border-color: var(--accent); }

/* ---------- Ernährung ---------- */
.macros { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; }
@media (min-width: 700px) { .macros { grid-template-columns: repeat(3, 1fr); } }
.macro { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem .7rem; }
.macro .name { font-size: .74rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .4px; }
.macro .val { font-weight: 750; font-size: 1.15rem; margin: .15rem 0; }
.macro .val small { color: var(--muted); font-weight: 500; font-size: .75rem; }
.bar { height: 7px; background: #efe9dd; border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--sage); border-radius: 99px; }
.bar i.over { background: var(--red); }

/* ---------- Modal ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(40, 35, 28, .45); z-index: 50;
  display: grid; place-items: end center; padding: 0;
}
.sheet {
  background: var(--paper); width: 100%; max-width: 640px;
  border-radius: 18px 18px 0 0; max-height: 92dvh; overflow: auto;
  padding: 1rem .9rem calc(1rem + env(safe-area-inset-bottom));
  animation: up .18s ease-out;
}
@media (min-width: 700px) {
  .overlay { place-items: center; padding: 2rem; }
  .sheet { border-radius: 18px; max-height: 86dvh; }
}
@keyframes up { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet h3.title { margin: .1rem 0 .9rem; font-size: 1.15rem; color: var(--ink); text-transform: none; letter-spacing: 0; }
.sheet .actions { display: flex; gap: .6rem; margin-top: 1rem; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- Login ---------- */
#login {
  position: fixed; inset: 0; z-index: 60; background: var(--header);
  display: none; place-items: center; padding: 1.2rem;
}
#login.active { display: grid; }
#login .box { background: var(--paper); border-radius: 18px; padding: 1.4rem 1.2rem; width: 100%; max-width: 380px; }
#login .logo { text-align: center; font-size: 2.4rem; margin-bottom: .4rem; }
#login h1 { text-align: center; font-size: 1.25rem; margin: 0 0 1rem; }
#login .err { color: var(--red); font-size: .85rem; min-height: 1.2em; text-align: center; margin-top: .5rem; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 70;
  background: var(--ink); color: #fff; border-radius: 12px; padding: .55rem .95rem;
  font-size: .88rem; box-shadow: var(--shadow); opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
#toast.show { opacity: .96; }

/* ---------- Scanner ---------- */
#scanner { position: fixed; inset: 0; z-index: 65; background: #000; display: none; flex-direction: column; }
#scanner.active { display: flex; }
#scanner video { flex: 1; object-fit: cover; width: 100%; }
#scanner .hint { color: #fff; text-align: center; padding: .8rem; font-size: .9rem; }
#scanner .bar { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: end; padding: 1rem; background: none; height: auto; }

/* ---------- Tabellen (Statistik) ---------- */
.tastes { overflow-x: auto; }
.tastes table { border-collapse: collapse; font-size: .85rem; min-width: 100%; }
.tastes th, .tastes td { padding: .4rem .5rem; border-bottom: 1px solid var(--line); text-align: center; white-space: nowrap; }
.tastes td:first-child, .tastes th:first-child { text-align: left; position: sticky; left: 0; background: var(--card); }

/* ---------- Desktop ---------- */
@media (min-width: 768px) {
  body { padding-bottom: 2rem; }
  nav.bottom { display: none; }
  nav.tabs { display: flex; }
}
.empty { text-align: center; color: var(--muted); padding: 2.2rem 1rem; }
.empty .big { font-size: 2rem; }
.muted { color: var(--muted); }
.right { text-align: right; }

/* ---------- Modul Fit ---------- */
.segments { display: flex; gap: .3rem; background: #efe9dd; border-radius: 12px; padding: .25rem; margin-bottom: .9rem; }
.segments button {
  flex: 1; border: 0; background: none; padding: .45rem .3rem; border-radius: 9px;
  font-weight: 650; color: var(--muted); cursor: pointer; font-size: .88rem;
}
.segments button.active { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

/* Wassergläser (IKEA POKAL) */
.glasses { display: flex; flex-wrap: wrap; gap: .45rem; margin: .5rem 0; }
.glass {
  width: 44px; height: 54px; border: 0; background: none; cursor: pointer; padding: 0;
  display: grid; place-items: center; position: relative;
}
.glass svg { width: 38px; height: 50px; }
.glass .fill { transition: opacity .15s; }

.ampel { display: inline-flex; align-items: center; gap: .35rem; font-weight: 700; font-size: .8rem;
  border-radius: 999px; padding: .2rem .65rem; }
.ampel.green { background: var(--green-soft); color: #38663d; }
.ampel.yellow { background: var(--yellow-soft); color: #92660d; }
.ampel.red { background: var(--red-soft); color: #a33b2d; }

/* Workout-Logger */
.setrow { display: flex; align-items: center; gap: .45rem; padding: .3rem 0; }
.setrow .setno { width: 2rem; font-weight: 700; color: var(--muted); }
.setrow input[type=number] { width: 4.6rem; text-align: center; }
.setrow .prev { font-size: .75rem; color: var(--muted); min-width: 5.5rem; }
.setrow .ok {
  width: 42px; height: 38px; border-radius: 10px; border: 2px solid var(--line);
  background: #fff; cursor: pointer; font-size: 1rem; color: transparent; flex: 0 0 auto;
}
.setrow .ok.on { background: var(--green); border-color: var(--green); color: #fff; }

/* Rest-Timer-Leiste */
#resttimer {
  position: fixed; left: .6rem; right: .6rem; bottom: calc(70px + env(safe-area-inset-bottom));
  z-index: 40; background: var(--header); color: var(--header-ink);
  border-radius: 14px; padding: .6rem .9rem; display: none; align-items: center; gap: .8rem;
  box-shadow: 0 4px 18px rgba(40,50,40,.35);
}
#resttimer.active { display: flex; }
#resttimer .time { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; min-width: 4.2rem; }
#resttimer .bar2 { flex: 1; height: 6px; background: rgba(255,255,255,.2); border-radius: 99px; overflow: hidden; }
#resttimer .bar2 i { display: block; height: 100%; background: #f0c86a; }
#resttimer button { background: rgba(255,255,255,.15); border: 0; color: inherit; border-radius: 9px;
  padding: .35rem .6rem; font-weight: 700; cursor: pointer; }
@media (min-width: 768px) { #resttimer { bottom: 1rem; max-width: 640px; left: 50%; transform: translateX(-50%); right: auto; width: calc(100% - 2rem); } }

/* Schlaf-Qualität */
.qualityrow { display: flex; gap: .3rem; }
.qualityrow button { background: none; border: 1px solid transparent; font-size: 1.3rem; border-radius: 9px;
  padding: .1rem .3rem; cursor: pointer; filter: grayscale(1); opacity: .55; }
.qualityrow button.on { filter: none; opacity: 1; background: var(--accent-soft); border-color: var(--accent); }
