:root {
  --bg: #f5f7f4; --card: #ffffff; --text: #1d2a22; --muted: #6a776f; --line: #e1e7e2;
  --accent: #2f7d4f; --accent-soft: #dff0e5; --accent-text: #ffffff;
  --b0: #8a94a0; --b12: #d9534f; --b345: #2f9e5b; --b67: #e0a030;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121714; --card: #1b221e; --text: #e7efe9; --muted: #92a198; --line: #2a342e;
    --accent: #4cb87a; --accent-soft: #23402f; --accent-text: #0c1a12;
    --b0: #7b8590; --b12: #e0605b; --b345: #3fb56f; --b67: #e0a838;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
main { max-width: 640px; margin: 0 auto; padding: 12px 12px calc(84px + env(safe-area-inset-bottom)); }
h1 { font-size: 1.25rem; margin: 4px 0 12px; }
h2 { font-size: 1rem; margin: 0 0 8px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); font-size: .88rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; }
button { font: inherit; color: inherit; cursor: pointer; }

/* tabs */
#tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
#tabs button { flex: 1; border: 0; background: none; padding: 8px 0 7px; font-size: .75rem; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px; }
#tabs button span { font-size: 1.3rem; line-height: 1; }
#tabs button.active { color: var(--accent); font-weight: 600; }

/* date nav */
.datenav { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.datenav .label { flex: 1; text-align: center; font-weight: 600; font-size: 1.1rem; position: relative; }
.datenav .label input { position: absolute; inset: 0; opacity: 0; width: 100%; }
.iconbtn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-size: 1.1rem; }
.todaybtn { border: 0; background: none; color: var(--accent); font-size: .85rem; }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: stretch; border: 1px solid var(--line); border-radius: 999px; background: var(--card); overflow: hidden; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); }
.chip-main { border: 0; background: none; padding: 9px 13px; min-height: 42px; }
.chip .cnt { align-self: center; background: var(--accent); color: var(--accent-text); border-radius: 999px;
  font-size: .78rem; font-weight: 700; padding: 1px 7px; margin-right: 2px; }
.chip .minus { border: 0; background: none; padding: 0 12px 0 8px; color: var(--accent); font-size: 1.2rem; font-weight: 700; }

details.cat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; }
details.cat > summary { padding: 12px; font-weight: 600; cursor: pointer; list-style: none; display: flex; justify-content: space-between; }
details.cat > summary::-webkit-details-marker { display: none; }
details.cat > summary .sel { color: var(--accent); font-weight: 500; font-size: .85rem; }
details.cat .chips { padding: 0 12px 12px; }

/* stool */
.stool-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.stool-row:first-of-type { border-top: 0; }
.badge { min-width: 34px; height: 34px; border-radius: 10px; color: #fff; display: inline-flex; align-items: center;
  justify-content: center; font-weight: 700; background: var(--b0); }
.badge.b0 { background: var(--b0); }
.badge.b1, .badge.b2 { background: var(--b12); }
.badge.b3, .badge.b4, .badge.b5 { background: var(--b345); }
.badge.b6, .badge.b7 { background: var(--b67); }
.badge.none { background: transparent; border: 1px dashed var(--line); color: var(--muted); font-weight: 400; }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 10px 14px; min-height: 44px; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--b12); }
.btn.small { min-height: 34px; padding: 5px 10px; font-size: .9rem; }
.x { border: 0; background: none; color: var(--muted); font-size: 1.1rem; padding: 6px 10px; }

/* dialog */
dialog { border: 0; border-radius: 18px; padding: 16px; width: min(560px, 94vw); background: var(--card); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.5); }
.bgrid { display: grid; gap: 6px; margin: 10px 0; }
.bopt { display: flex; align-items: center; gap: 10px; text-align: left; border: 2px solid var(--line); background: var(--card);
  border-radius: 12px; padding: 7px 10px; }
.bopt.sel { border-color: var(--accent); background: var(--accent-soft); }
.bopt small { color: var(--muted); display: block; }

textarea, input[type=text], select { width: 100%; font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; }
textarea { min-height: 60px; resize: vertical; }
label.row { display: flex; align-items: center; gap: 8px; margin: 6px 0; }

/* history grid */
.hgrid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.hcell { aspect-ratio: 1; border-radius: 9px; border: 0; background: var(--line); color: var(--muted); font-size: .8rem;
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.hcell b { font-size: 1rem; color: #fff; }
.hcell.b0 { background: var(--b0); color: #fff; }
.hcell.b1, .hcell.b2 { background: var(--b12); color: #fff; }
.hcell.b3, .hcell.b4, .hcell.b5 { background: var(--b345); color: #fff; }
.hcell.b6, .hcell.b7 { background: var(--b67); color: #fff; }
.hcell.dow { background: none; aspect-ratio: auto; font-size: .72rem; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: .8rem; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 4px; vertical-align: -1px; margin-right: 4px; }
.dayrow { display: flex; gap: 10px; align-items: flex-start; width: 100%; text-align: left; border: 0; background: none;
  padding: 10px 0; border-top: 1px solid var(--line); }
.dayrow:first-of-type { border-top: 0; }
.dayrow .d { width: 78px; flex: none; font-weight: 600; font-size: .9rem; }
.dayrow .t { flex: 1; font-size: .88rem; color: var(--muted); }

/* analysis */
.seg { display: flex; gap: 6px; margin: 6px 0 2px; }
.seg button { flex: 1; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px 0; }
.seg button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.arow { padding: 8px 0; border-top: 1px solid var(--line); }
.arow:first-of-type { border-top: 0; }
.arow .top { display: flex; justify-content: space-between; gap: 8px; }
.bar { height: 8px; border-radius: 4px; background: var(--line); margin-top: 5px; overflow: hidden; display: flex; }
.bar i { display: block; height: 100%; }
.bar .h { background: var(--b12); }
.bar .o { background: var(--b345); }
.warn { background: #fff4d8; color: #6b4a00; border-radius: 10px; padding: 10px; font-size: .9rem; margin-bottom: 12px; }
@media (prefers-color-scheme: dark) { .warn { background: #3a2f10; color: #f1d58a; } }
.fl { display: flex; gap: 8px; align-items: center; padding: 3px 0; }
.fl span.g { flex: 1; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }

/* Trink-Fortschritt */
.water { position: relative; height: 14px; border-radius: 7px; background: var(--line); margin: 8px 0 4px; overflow: visible; }
.water i { display: block; height: 100%; border-radius: 7px; background: linear-gradient(90deg, #4aa3e0, #2f7fd0); }
.water b { position: absolute; top: -3px; width: 2px; height: 20px; background: var(--text); opacity: .55; transform: translateX(-1px); }
