:root {
  --bg: #fdf3ee;
  --card: #ffffff;
  --text: #2c2224;
  --muted: #7d6c6f;
  --line: #ecdcd6;
  --accent: #d94a66;
  --accent-text: #ffffff;
  --soft: #fbe3e6;
  --mine: #fbd9df;
  --ok: #2f8f5b;
  --warn: #c0392b;
  --radius: 16px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f1a1b;
    --card: #2b2426;
    --text: #f5eaea;
    --muted: #b09ea1;
    --line: #40363a;
    --accent: #f0728a;
    --accent-text: #2a1318;
    --soft: #43292f;
    --mine: #5a2f39;
    --ok: #6fcf97;
    --warn: #ff8a7a;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
h1 { font-size: 1.4rem; margin: 12px 0 4px; }
h2 { font-size: 0.95rem; margin: 20px 4px 8px; color: var(--muted); font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.spacer { flex: 1; }
.empty { color: var(--muted); text-align: center; padding: 28px 12px; }

input, textarea, button { font: inherit; color: inherit; }
input:not([type=checkbox]):not([type=radio]), textarea {
  width: 100%;
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}
textarea { resize: none; }
input:focus-visible, textarea:focus-visible, button:focus-visible, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 16px; border: 0; border-radius: 12px; cursor: pointer;
  font-weight: 600; text-decoration: none; white-space: nowrap;
}
.btn.small { padding: 8px 12px; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-secondary { background: var(--soft); color: var(--text); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-block { display: flex; width: 100%; }
.btn.busy { opacity: 0.6; pointer-events: none; }
.icon-btn {
  flex: none; width: 36px; height: 36px; border: 0; border-radius: 50%;
  background: transparent; color: var(--muted); font-size: 1.3rem; line-height: 1; cursor: pointer;
}

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }

/* Anmeldung und Begrüßung */
.gate { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.gate-card { width: 100%; max-width: 360px; text-align: center; display: grid; gap: 12px; }
.gate-card img { margin: 0 auto; }
.field { display: grid; gap: 4px; text-align: left; }
.field > span { font-size: 0.85rem; color: var(--muted); }
.form-error { color: var(--warn); min-height: 1.2em; font-size: 0.9rem; }

/* Grundgerüst */
.app { height: 100dvh; display: flex; flex-direction: column; max-width: 720px; margin: 0 auto; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 45%;
  padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dot { width: 10px; height: 10px; border-radius: 50%; background: currentColor; flex: none; }
main { flex: 1; min-height: 0; }
.view { height: 100%; overflow-x: hidden; overflow-y: auto; padding: 4px 14px 20px; }

.tabs {
  display: grid; grid-template-columns: repeat(6, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  position: relative; display: grid; justify-items: center; gap: 1px;
  padding: 8px 0 7px; border: 0; background: none; cursor: pointer;
  font-size: 0.62rem; color: var(--muted); min-width: 0;
}
.tabs button span:nth-child(2) { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.tab-icon { font-size: 1.35rem; line-height: 1.2; filter: grayscale(0.7); opacity: 0.75; }
.tabs button.active { color: var(--accent); font-weight: 700; }
.tabs button.active .tab-icon { filter: none; opacity: 1; }
.badge {
  position: absolute; top: 3px; left: 54%;
  min-width: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: var(--accent-text); font-size: 0.7rem; font-weight: 700; line-height: 18px;
}

/* Namensfarben */
.c0 { color: #c2410c; } .c1 { color: #0f766e; } .c2 { color: #6d28d9; } .c3 { color: #b4236b; }
.c4 { color: #1d4ed8; } .c5 { color: #4d7c0f; } .c6 { color: #b45309; } .c7 { color: #0e7490; }
@media (prefers-color-scheme: dark) {
  .c0 { color: #fb923c; } .c1 { color: #5eead4; } .c2 { color: #c4b5fd; } .c3 { color: #f9a8d4; }
  .c4 { color: #93c5fd; } .c5 { color: #bef264; } .c6 { color: #fcd34d; } .c7 { color: #67e8f9; }
}

/* Chat */
.view-chat { display: flex; flex-direction: column; overflow: hidden; padding-bottom: 0; }
.push-hint {
  display: flex; align-items: center; gap: 8px; margin-bottom: 6px;
  padding: 8px 6px 8px 12px; background: var(--soft); border-radius: 12px;
}
.push-hint p { flex: 1; }
.messages { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 4px 2px 10px; }
.day-sep { text-align: center; margin: 8px 0 2px; }
.day-sep span { font-size: 0.75rem; color: var(--muted); background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; }
.msg {
  align-self: flex-start; max-width: 84%;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 16px 16px 16px 4px; padding: 7px 11px 5px;
}
.msg.mine { align-self: flex-end; background: var(--mine); border-color: transparent; border-radius: 16px 16px 4px 16px; }
.msg-author { font-size: 0.78rem; font-weight: 700; }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-time { font-size: 0.68rem; color: var(--muted); text-align: right; }
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 8px 0 10px; }
.composer textarea { border-radius: 20px; max-height: 140px; }
.composer .btn { border-radius: 50%; width: 46px; height: 46px; padding: 0; flex: none; }

/* Listen */
.add-form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; margin-bottom: 12px; }
.inline-field { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 10px; }
.count { margin: 0 4px 6px; }
.item {
  display: flex; align-items: center; gap: 4px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 6px 4px 6px 12px; margin-bottom: 6px;
}
.item-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 6px 0; cursor: pointer; }
div.item-main { cursor: default; }
.item-main input[type=checkbox] { width: 22px; height: 22px; flex: none; accent-color: var(--accent); }
.item-text { display: block; overflow-wrap: anywhere; }
.item-meta { display: block; font-size: 0.78rem; color: var(--muted); }
.item.done .item-text { text-decoration: line-through; color: var(--muted); }
.overdue { color: var(--warn); font-weight: 600; }

/* Trinken */
.drink-today { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; text-align: center; }
.drink-sum { font-size: 1.3rem; }
#drink-total { font-size: 2.6rem; font-weight: 800; color: var(--accent); }
progress { width: 100%; height: 12px; border: 0; border-radius: 6px; overflow: hidden; background: var(--soft); accent-color: var(--accent); appearance: none; -webkit-appearance: none; }
progress::-webkit-progress-bar { background: var(--soft); }
progress::-webkit-progress-value { background: var(--accent); border-radius: 6px; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 6px; }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.quick .btn { padding: 14px 0; }
.row-form { display: flex; gap: 8px; }
.row-form input { flex: 1; }
.row-form .btn { flex: none; }
.day-row { display: grid; grid-template-columns: 5.5em 1fr 4.5em; align-items: center; gap: 10px; padding: 6px 4px; }
.day-ml { text-align: right; font-variant-numeric: tabular-nums; }
.day-ml.reached { color: var(--ok); font-weight: 700; }
details.card { margin-top: 20px; }
details summary { cursor: pointer; color: var(--muted); }
details .row-form { margin-top: 10px; }

/* Logbuch */
.log-form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.kinds { display: flex; flex-wrap: wrap; gap: 6px; }
.kinds input { position: absolute; opacity: 0; pointer-events: none; }
.kinds span { display: inline-block; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; font-size: 0.85rem; cursor: pointer; }
.kinds input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.kinds input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.log { margin-bottom: 8px; padding: 8px 8px 10px 14px; }
.log header { display: flex; align-items: center; gap: 8px; }
.log-time { font-weight: 700; font-variant-numeric: tabular-nums; }
.tag { font-size: 0.78rem; background: var(--soft); border-radius: 999px; padding: 2px 9px; }
.log-text { white-space: pre-wrap; overflow-wrap: anywhere; margin: 2px 0 4px; }

/* Bilder */
.upload { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; margin-bottom: 12px; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.grid .empty { grid-column: 1 / -1; }
.thumb { aspect-ratio: 1; padding: 0; border: 0; border-radius: 8px; overflow: hidden; background: var(--soft); cursor: pointer; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(4, 1fr); } }

.lightbox { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: #000; color: #fff; }
.lightbox[open] { display: flex; flex-direction: column; }
.lightbox img { flex: 1; min-height: 0; width: 100%; object-fit: contain; }
.lightbox-bar { display: grid; gap: 8px; padding: 10px 14px calc(12px + env(safe-area-inset-bottom)); }
.lightbox-actions { display: flex; gap: 8px; justify-content: flex-end; }
.lightbox .btn-secondary { background: #333; color: #fff; }

/* Profil */
.sheet { width: min(420px, calc(100vw - 24px)); border: 0; border-radius: 20px; padding: 18px; background: var(--card); color: var(--text); }
.sheet::backdrop { background: rgba(0, 0, 0, 0.45); }
.sheet h2 { font-size: 1.15rem; color: var(--text); margin: 0 0 12px; }
.push-box { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-start; justify-content: space-between; margin: 14px 0; padding: 12px; background: var(--bg); border-radius: 12px; }
.push-buttons { display: grid; gap: 6px; flex: none; }
.sheet-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: flex-end; }
.sheet-actions .btn { padding: 10px 12px; }
.sheet-actions .spacer { flex: 1 1 0; min-width: 0; }
.sheet-actions #logout { padding-left: 0; }

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