:root {
  --bg: #f4f6f4;
  --card: #ffffff;
  --text: #17201a;
  --muted: #64706a;
  --line: #e1e6e2;
  --accent: #16a34a;
  --accent-soft: #dcfce7;
  --warn: #dc2626;
  --warn-soft: #fee2e2;
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1411;
    --card: #182019;
    --text: #e8efe9;
    --muted: #93a198;
    --line: #2a352d;
    --accent: #22c55e;
    --accent-soft: #163a22;
    --warn: #f87171;
    --warn-soft: #3b1a1a;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 12px) 16px 8px;
}

header h1 { margin: 0 auto; font-size: 22px; max-width: 608px; }

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 8px 16px calc(96px + env(safe-area-inset-bottom));
}

nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}

nav button {
  flex: 1;
  border: 0;
  background: none;
  color: var(--muted);
  padding: 8px 0 10px;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
}

nav button .ico { font-size: 22px; filter: grayscale(1); opacity: .7; }
nav button.active { color: var(--accent); font-weight: 600; }
nav button.active .ico { filter: none; opacity: 1; }

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

.card h2 { margin: 0 0 12px; font-size: 17px; }
.card h3 { margin: 16px 0 8px; font-size: 15px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }
.stack > * + * { margin-top: 10px; }

button, .btn {
  font: inherit;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 14px;
  cursor: pointer;
}

button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.danger { color: var(--warn); }
button.ghost { border-color: transparent; background: none; }
button.icon { padding: 6px 10px; }
button.full { width: 100%; }
button:disabled { opacity: .5; }

input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
}

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.daynav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.daynav strong { font-size: 15px; }

.budget { display: flex; align-items: center; gap: 18px; }
.ring { position: relative; width: 132px; height: 132px; flex-shrink: 0; }
.ring svg { transform: rotate(-90deg); }
.ring .inner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.ring .big { font-size: 28px; font-weight: 700; line-height: 1; }
.over .big { color: var(--warn); }
.macros { display: flex; gap: 14px; margin-top: 12px; font-size: 13px; }
.macros b { display: block; font-size: 16px; }

.message {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--accent-soft);
  font-size: 14px;
  margin-top: 12px;
}
.message.warn { background: var(--warn-soft); }

.meal { border-top: 1px solid var(--line); padding: 10px 0; }
.meal:first-of-type { border-top: 0; }
.meal-head { display: flex; justify-content: space-between; align-items: center; }
.meal-head strong { font-size: 15px; }
.entry { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; font-size: 14px; gap: 8px; }
.entry .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.list-item:last-child { border-bottom: 0; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 7px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 14px;
  cursor: pointer;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; }
.tabs .chip { white-space: nowrap; }

.switch { position: relative; width: 46px; height: 28px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span {
  position: absolute;
  inset: 0;
  background: var(--line);
  border-radius: 999px;
  transition: .2s;
}
.switch span::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: .2s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { left: 21px; }

.stat { font-size: 26px; font-weight: 700; }

#sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; }
#sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  z-index: 21;
  max-width: 640px;
  margin: 0 auto;
}
#sheet .sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
#sheet .sheet-head h2 { margin: 0; font-size: 18px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 12px;
  z-index: 30;
  font-size: 14px;
  max-width: calc(100% - 32px);
}

video.scan { width: 100%; border-radius: 12px; background: #000; max-height: 50vh; object-fit: cover; }

.chart { width: 100%; height: auto; }
.chart .dot { fill: var(--muted); opacity: .6; }
.chart .trend { fill: none; stroke: var(--accent); stroke-width: 3; }
.chart .goal { stroke: var(--warn); stroke-dasharray: 6 6; stroke-width: 1.5; }
.chart text { fill: var(--muted); font-size: 12px; }
.chart .grid { stroke: var(--line); }

.auth { max-width: 380px; margin: 10vh auto 0; }

.routine.complete { border-color: var(--accent); }
.progress { height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; margin: 2px 0 6px; }
.progress span { display: block; height: 100%; background: var(--accent); transition: width .3s; }

.check {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  font-size: 16px;
  color: var(--text);
  margin: 0;
  cursor: pointer;
}
.check:last-child { border-bottom: 0; }
.check input { position: absolute; opacity: 0; pointer-events: none; }
.check .box {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 2px solid var(--muted);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: .15s;
}
.check.done .box { background: var(--accent); border-color: var(--accent); }
.check.done .box::after { content: "✓"; color: #fff; font-weight: 700; }
.check.done .grow { color: var(--muted); text-decoration: line-through; }

.list-click { cursor: pointer; }
.history { display: flex; gap: 4px; margin: 12px 0 8px; }
.history .dot { flex: 1; height: 10px; border-radius: 3px; background: var(--line); }
.history .dot.voll { background: var(--accent); }
.history .dot.teil { background: var(--accent); opacity: .4; }
.history .dot.leer { background: var(--warn); opacity: .5; }
.history .dot.frei { background: transparent; border: 1px dashed var(--line); }
.history .dot.offen { background: transparent; border: 2px solid var(--accent); }

.routine-head { cursor: pointer; }
.routine-head h2 { margin-bottom: 8px; }
.routine.collapsed .progress { margin-bottom: 0; }

.step-row { margin-bottom: 6px; }

.task { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.task:last-child { border-bottom: 0; }
.task .grow { cursor: pointer; }
.task.overdue .small { color: var(--warn); }
.tick {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--muted);
  background: none;
  padding: 0;
  flex-shrink: 0;
}
.task.overdue .tick { border-color: var(--warn); }
.tick.ticked { background: var(--accent); border-color: var(--accent); }

#toast { display: flex; align-items: center; gap: 12px; width: max-content; }
#toast span { flex: 1; }
#toast .toast-action { color: var(--accent); padding: 0; font-weight: 600; border: 0; background: none; }
.step-row button { flex-shrink: 0; }

table.users { width: 100%; border-collapse: collapse; font-size: 14px; }
table.users td { padding: 8px 4px; border-bottom: 1px solid var(--line); }
