/* Eine schmale Spalte wie ein Bierdeckel-Protokoll: Tag oben, Eingabe direkt darunter, Auswertung danach. */
:root {
  --bg: #f1f4f3;
  --surface: #ffffff;
  --ink: #15211f;
  --muted: #586864;
  --line: #d3dbd8;
  --accent: #0f6b63;
  --accent-ink: #ffffff;
  --accent-soft: #dbeae7;
  --kcal: #9a5200;
  --danger: #b3261e;
  --good: #1f7a3a;
  --bad: #b25e00;
  --font-display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", sans-serif;
  --font-body: "IBM Plex Sans", "Helvetica Neue", Arial, sans-serif;
  --font-data: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1514; --surface: #182120; --ink: #e7efed; --muted: #94a5a1; --line: #2b3937;
    --accent: #4fc3b5; --accent-ink: #06211e; --accent-soft: #1c3532; --kcal: #f0a94a; --danger: #ff8a80; --good: #6fd08c; --bad: #f0a94a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); -webkit-tap-highlight-color: transparent; color: var(--ink); font-family: var(--font-body); font-size: 16px; line-height: 1.45; }
.page { max-width: 680px; margin: 0 auto; padding-inline: max(16px, env(safe-area-inset-left, 0px)); padding-block: calc(20px + env(safe-area-inset-top, 0px)) calc(96px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 28px; }
h1, h2 { font-family: var(--font-display); margin: 0; text-wrap: balance; }
h1 { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; font-weight: 500; }
.label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.num { font-family: var(--font-data); font-variant-numeric: tabular-nums; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
:root { accent-color: var(--accent); caret-color: var(--accent); }
::selection { background: var(--accent-soft); color: var(--ink); }
.num .unit { font-family: var(--font-body); font-size: 0.85em; color: var(--muted); margin-left: 0.25em; text-transform: none; letter-spacing: 0; }

header { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 16px; }
header p { margin: 0; color: var(--muted); font-size: 0.9rem; }

section { display: flex; flex-direction: column; gap: 12px; }
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; }
.section-head span { color: var(--muted); font-size: 0.9rem; }

/* Tag */
.daynav { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.daynav .title { flex: 1 1 100%; min-width: 0; font-family: var(--font-display); font-size: 1.15rem; font-weight: 500; }
.icon-btn, .ghost { background: transparent; border: 1px solid var(--line); border-radius: 8px; min-height: 40px; padding: 0 12px; }
.icon-btn { min-width: 40px; display: inline-grid; place-items: center; padding: 0; color: var(--ink); }
.icon-btn svg { display: block; }
.icon-btn:disabled, .ghost:disabled { opacity: 0.4; cursor: default; }
#day { flex: 1 1 auto; min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; min-height: 40px; padding: 0 8px; max-width: 100%; }

.day { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.figures { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.figure { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.figure .num { font-size: 1.75rem; font-weight: 500; line-height: 1.1; }
.figure.kcal .num { color: var(--kcal); }
.figure small { color: var(--muted); font-size: 0.8rem; }
.tally { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-height: 28px; color: var(--accent); border-top: 1px dashed var(--line); padding-top: 12px; }
.tally svg { display: block; }
.tally .empty { color: var(--muted); font-size: 0.9rem; }

/* Eingabe */
.presets { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
@media (max-width: 460px) { .presets { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.preset { background: var(--accent-soft); border: 1px solid transparent; border-radius: 10px; padding: 10px 12px; text-align: left; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.preset:hover { border-color: var(--accent); }
.preset:active { transform: translateY(1px); }
.preset strong { font-weight: 600; }
.preset span { font-size: 0.78rem; color: var(--muted); }
.preset:disabled, .primary:disabled { opacity: 0.5; cursor: default; }

details { border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; }
summary { cursor: pointer; padding: 10px 0; font-weight: 500; list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; }
summary::-webkit-details-marker { display: none; }
summary::after { content: ""; width: 8px; height: 8px; margin-right: 4px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: translateY(-2px) rotate(45deg); }
details[open] summary::after { transform: translateY(2px) rotate(-135deg); }
@media (prefers-reduced-motion: no-preference) { summary::after { transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1); } }
form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding-bottom: 12px; }
form .wide { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 0.8rem; color: var(--muted); }
.field input, .field select { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; min-height: 40px; padding: 0 10px; width: 100%; }
.primary { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px; min-height: 42px; padding: 0 16px; font-weight: 600; }
.form-error { color: var(--danger); font-size: 0.85rem; margin: 0; }

/* Balken */
.bars { display: grid; gap: 4px; align-items: end; }
.bars.week { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.bars.weeks { grid-template-columns: repeat(12, minmax(0, 1fr)); }
.bars.months { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.col .val.dry { color: var(--accent); font-weight: 600; }
.col { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; background: transparent; border: 0; padding: 0; }
.col .val { font-family: var(--font-data); font-size: 0.7rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.col .track { width: 100%; height: 110px; display: flex; align-items: flex-end; border-bottom: 1px solid var(--line); }
.col .bar { width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 0; }
.col .lab { font-size: 0.75rem; color: var(--muted); }
.col.future { opacity: 0.35; }
.col.selected .lab { color: var(--ink); font-weight: 600; }
.col.selected .track { border-bottom: 2px solid var(--ink); }
.col.current .lab { color: var(--ink); font-weight: 600; }
button.col:hover .bar { filter: brightness(1.12); }
.note { color: var(--muted); font-size: 0.82rem; margin: 0; }
.bars.kcal .bar { background: var(--kcal); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 3px; align-self: flex-start; background: var(--surface); }
.seg button { background: transparent; border: 0; border-radius: 7px; min-height: 36px; padding: 0 14px; color: var(--muted); font-weight: 500; }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--ink); }
.seg button[data-metric="kcal"][aria-pressed="true"] { box-shadow: inset 0 -2px 0 var(--kcal); }
.seg button[data-metric="grams"][aria-pressed="true"] { box-shadow: inset 0 -2px 0 var(--accent); }

/* Liste */
.list { display: flex; flex-direction: column; gap: 14px; }
.group { display: flex; flex-direction: column; }
.group .label { padding-bottom: 4px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 8px; }
.row { display: grid; grid-template-columns: minmax(0, 1fr) 4.6rem 5.4rem 36px; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.row .name { min-width: 0; overflow-wrap: anywhere; }
.row .name small { display: block; color: var(--muted); font-size: 0.78rem; }
.row .num { font-size: 0.85rem; text-align: right; white-space: nowrap; }
.group .label .num { letter-spacing: 0; }
.row .kc { color: var(--kcal); }
.row .kc .unit { color: inherit; opacity: 0.75; }
.del { background: transparent; border: 0; color: var(--muted); min-width: 36px; min-height: 36px; border-radius: 8px; display: inline-grid; place-items: center; padding: 0; }
.del svg { display: block; }
.del:hover { color: var(--danger); background: var(--accent-soft); }
.state { color: var(--muted); border: 1px dashed var(--line); border-radius: 10px; padding: 16px; margin: 0; }

.toast { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)); display: flex; justify-content: center; pointer-events: none; }
.toast div { pointer-events: auto; background: var(--ink); color: var(--bg); border-radius: 10px; padding: 10px 14px; display: flex; align-items: center; gap: 14px; max-width: 100%; font-size: 0.92rem; }
.toast button { background: transparent; border: 0; color: inherit; font-weight: 600; text-decoration: underline; padding: 4px; }
@media (prefers-reduced-motion: no-preference) { .col .bar { transition: height 0.25s ease; } }

/* Daten & Updates */
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.update { position: fixed; left: 0; right: 0; top: 0; padding: calc(8px + env(safe-area-inset-top, 0px)) 16px 8px; display: flex; justify-content: center; }
.update div { background: var(--accent); color: var(--accent-ink); border-radius: 10px; padding: 8px 14px; display: flex; gap: 12px; align-items: center; }
.update button { background: transparent; border: 0; color: inherit; font-weight: 600; text-decoration: underline; padding: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Alkoholfreie Tage */
.dry-btn { background: var(--accent-soft); color: var(--ink); border: 1px dashed var(--accent); border-radius: 8px; min-height: 40px; padding: 0 14px; font-weight: 500; }
.dry-btn:disabled { opacity: 0.5; cursor: default; }
.dry-ok { color: var(--accent); font-weight: 600; }
.link { background: transparent; border: 0; color: var(--muted); text-decoration: underline; padding: 6px 4px; font-size: 0.88rem; }
.streak { margin: 0; color: var(--accent); font-weight: 500; font-size: 0.92rem; }

/* Vergleich */
.compare { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: 0.88rem; }
.compare .cmp-label, .compare .cmp-dry { color: var(--muted); }
.compare .cmp-vals { display: inline-flex; align-items: baseline; gap: 6px; }
.compare .num { font-size: 0.85rem; }
.compare .cmp-vs { color: var(--muted); }
.pct { border-radius: 999px; padding: 1px 8px; font-weight: 600; font-size: 0.8rem; border: 1px solid currentColor; }
.pct.good { color: var(--good); }
.pct.bad { color: var(--bad); }
.pct.same { color: var(--muted); }

/* Kalender */
.calnav { display: flex; align-items: center; gap: 8px; }
.calnav h2 { flex: 1 1 auto; min-width: 0; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; --tone: var(--accent); }
.cal.kcal { --tone: var(--kcal); }
.cal-head { text-align: center; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding-bottom: 2px; }
.cal-day { aspect-ratio: 1 / 1.05; max-width: 100%; min-width: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); padding: 4px; display: flex; flex-direction: column; justify-content: space-between; align-items: flex-start; text-align: left; color: var(--ink); }
.cal-day .d { font-size: 0.78rem; color: var(--muted); }
.cal-day .v { align-self: flex-end; font-family: var(--font-data); font-size: 0.78rem; font-variant-numeric: tabular-nums; }
.cal-day[data-level="1"] { background: color-mix(in srgb, var(--tone) 18%, var(--surface)); border-color: transparent; }
.cal-day[data-level="2"] { background: color-mix(in srgb, var(--tone) 38%, var(--surface)); border-color: transparent; }
.cal-day[data-level="3"] { background: color-mix(in srgb, var(--tone) 62%, var(--surface)); border-color: transparent; }
.cal-day[data-level="4"] { background: var(--tone); border-color: transparent; }
.cal-day[data-level="3"] .d, .cal-day[data-level="4"] .d { color: inherit; }
.cal-day[data-level="4"] { color: var(--accent-ink); }
.cal-day.dry { border: 1px dashed var(--accent); }
.cal-day.dry .v { color: var(--accent); font-weight: 600; }
.cal-day.future { opacity: 0.4; }
.cal-day.today .d { font-weight: 700; color: var(--ink); }
.cal-day.today[data-level="3"] .d, .cal-day.today[data-level="4"] .d { color: inherit; }
.cal-day.selected { outline: 2px solid var(--ink); outline-offset: 1px; }
button.cal-day:hover { filter: brightness(0.97); }
@media (prefers-color-scheme: dark) {
  .cal-day[data-level="3"] { background: color-mix(in srgb, var(--tone) 76%, var(--surface)); color: var(--accent-ink); }
}
.cal-summary { margin: 0; font-size: 0.9rem; }
