:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #15201d;
  --muted: #5d6b67;
  --line: #e2e8e6;
  --accent: #0f766e;
  --accent-soft: #d6efec;
  --accent-text: #ffffff;
  --plus: #15803d;
  --minus: #c2410c;
  --warn-soft: #fff3d6;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 2px 8px rgb(0 0 0 / 0.04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1513;
    --card: #17211e;
    --text: #e7efec;
    --muted: #93a49f;
    --line: #26332f;
    --accent: #2dd4bf;
    --accent-soft: #123b36;
    --accent-text: #04201c;
    --plus: #4ade80;
    --minus: #fb923c;
    --warn-soft: #3a2f12;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
#app { max-width: 640px; margin: 0 auto; min-height: 100dvh; padding-bottom: 96px; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.05rem; margin: 22px 16px 8px; color: var(--muted); font-weight: 600; }
.loading, .empty { padding: 40px 16px; text-align: center; color: var(--muted); }

/* Kopfzeile */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: var(--bg);
}
.top h1 { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  border: 0; background: transparent; color: var(--text);
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center; font-size: 1.3rem; cursor: pointer; text-decoration: none;
}
.icon-btn:active { background: var(--line); }

/* Karten und Listen */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); margin: 0 12px 10px; }
.card.pad { padding: 14px 16px; }
.list { list-style: none; margin: 0 12px; padding: 0; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list > li + li { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; color: inherit; text-decoration: none; }
a.row:active, button.row:active { background: var(--line); }
button.row { width: 100%; border: 0; background: none; font: inherit; text-align: left; cursor: pointer; }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { color: var(--muted); font-size: 0.86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .end { text-align: right; white-space: nowrap; }
.avatar {
  flex: none; width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center; font-size: 1.3rem; background: var(--accent-soft);
}
.avatar.round { border-radius: 50%; font-size: 0.95rem; font-weight: 700; color: var(--accent); }
.plus { color: var(--plus); }
.minus { color: var(--minus); }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.date-head { margin: 14px 16px 6px; font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* Gesamtsaldo */
.hero { padding: 18px 16px; margin: 4px 12px 14px; border-radius: var(--radius); background: var(--accent); color: var(--accent-text); }
.hero .label { opacity: 0.85; font-size: 0.9rem; }
.hero .big { font-size: 2rem; font-weight: 700; letter-spacing: -0.01em; }
.hero .sub { opacity: 0.85; font-size: 0.9rem; margin-top: 2px; }

/* Tabs */
.tabs { display: flex; gap: 4px; margin: 0 12px 12px; padding: 4px; background: var(--line); border-radius: 12px; overflow-x: auto; }
.tabs a {
  flex: 1; text-align: center; padding: 8px 10px; border-radius: 9px;
  color: var(--muted); text-decoration: none; font-weight: 600; font-size: 0.92rem; white-space: nowrap;
}
.tabs a.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

/* Knöpfe */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 11px; padding: 11px 16px; min-height: 44px;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  background: var(--accent); color: var(--accent-text);
}
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.danger { background: transparent; color: var(--minus); }
.btn.small { min-height: 34px; padding: 6px 12px; font-size: 0.88rem; border-radius: 9px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.paypal { background: #ffc439; color: #111; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.fab {
  position: fixed; right: max(16px, calc(50vw - 304px)); bottom: calc(18px + env(safe-area-inset-bottom));
  border-radius: 18px; padding: 0 20px; height: 56px; font-size: 1rem;
  box-shadow: 0 6px 18px rgb(0 0 0 / 0.2); z-index: 10;
}

/* Formulare */
form.stack, .stack { display: grid; gap: 14px; padding: 4px 16px 16px; }
label.field { display: grid; gap: 6px; font-size: 0.9rem; color: var(--muted); font-weight: 600; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--card);
  border: 1.5px solid var(--line); border-radius: 11px; padding: 11px 12px; width: 100%; min-height: 46px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
input.amount { font-size: 2rem; font-weight: 700; text-align: center; padding: 10px; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline > * { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1.5px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 0.9rem; cursor: pointer;
}
.chip.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.seg { display: flex; background: var(--line); border-radius: 11px; padding: 3px; }
.seg button { flex: 1; border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted); padding: 8px; border-radius: 9px; cursor: pointer; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.split-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.split-row + .split-row { border-top: 1px solid var(--line); }
.split-row label { flex: 1; display: flex; align-items: center; gap: 10px; font-weight: 500; cursor: pointer; }
.split-row input[type='checkbox'] { width: 22px; height: 22px; min-height: 0; accent-color: var(--accent); }
.split-row input.num { width: 96px; flex: none; text-align: right; min-height: 40px; padding: 8px 10px; }
.split-row .share { width: 84px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.hint { font-size: 0.86rem; color: var(--muted); }
.hint.err { color: var(--minus); }
.error-box { margin: 0 16px; padding: 10px 12px; border-radius: 10px; background: var(--warn-soft); }

/* Salden */
.bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; border-radius: 4px; }
.transfer { display: flex; align-items: center; gap: 8px; font-weight: 600; flex-wrap: wrap; }
.transfer .amt { margin-left: auto; font-size: 1.1rem; }
.badge { display: inline-block; font-size: 0.75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--line); color: var(--muted); }
.badge.offen { background: var(--warn-soft); color: var(--minus); }
.badge.bezahlt { background: var(--accent-soft); color: var(--accent); }
.badge.bestaetigt { background: var(--accent-soft); color: var(--plus); }

#toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: #1f2a27; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 0.92rem;
  opacity: 0; pointer-events: none; transition: 0.2s; max-width: calc(100vw - 32px); z-index: 20;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

dialog { border: 0; border-radius: 18px; padding: 0; background: var(--card); color: var(--text); width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
dialog .stack { padding: 18px; }

/* Kassenzettel */
.scan { position: relative; min-height: 52px; }
.receipt { display: flex; align-items: center; gap: 12px; padding: 10px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.receipt img { width: 56px; height: 72px; object-fit: cover; border-radius: 8px; display: block; }
.receipt .main { flex: 1; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.8s linear infinite; flex: none; margin: 0 14px; }
@keyframes spin { to { transform: rotate(360deg); } }
.item-row { padding: 8px 0; display: grid; gap: 6px; }
.item-row + .item-row { border-top: 1px solid var(--line); }
.item-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.mini { padding: 3px 10px; font-size: 0.82rem; }
.item-sum { margin-top: 8px; padding-top: 8px; border-top: 2px solid var(--line); display: grid; gap: 4px; }

/* Statistik */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0 12px 4px; }
.tile { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; min-width: 0; }
.tile .k { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.tile .v { font-size: 1.25rem; font-weight: 700; margin-top: 2px; }
.tile .h { font-size: 0.8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cols { display: flex; align-items: flex-end; gap: 4px; height: 170px; padding-top: 18px; }
.col { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; }
.col i { display: block; width: 100%; max-width: 38px; background: var(--accent); border-radius: 5px 5px 2px 2px; }
.col .val { font-size: 0.68rem; color: var(--muted); white-space: nowrap; margin-bottom: 3px; }
.col .lab { font-size: 0.7rem; color: var(--muted); height: 16px; margin-top: 4px; white-space: nowrap; }
.hbar + .hbar { margin-top: 10px; }
.bar.thin { height: 6px; margin-top: 4px; }
.legend { display: flex; gap: 14px; font-size: 0.8rem; color: var(--muted); margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }
details.person { padding: 8px 0; }
details.person + details.person { border-top: 1px solid var(--line); }
details.person summary { list-style: none; cursor: pointer; }
details.person summary::-webkit-details-marker { display: none; }

/* Betrag mit Währung */
.amount-row { display: flex; gap: 8px; }
.amount-row .amount { flex: 1; min-width: 0; }
.amount-row .cur { flex: none; width: 92px; font-weight: 700; text-align: center; }
.fx { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 11px; background: var(--accent-soft); margin-top: -6px; }
.fx .num { width: 110px; min-height: 38px; padding: 6px 10px; text-align: right; }
.toggle { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; }
.toggle input { width: 22px; height: 22px; min-height: 0; margin-top: 2px; accent-color: var(--accent); flex: none; }
.fx[hidden] { display: none; }

/* Offline-Hinweis */
.offline { position: sticky; top: 0; z-index: 20; display: flex; gap: 10px; align-items: center; justify-content: space-between;
  padding: 8px 14px; background: var(--warn-soft); color: var(--text); font-size: 0.86rem; }
.offline[hidden] { display: none; }
.offline .btn { flex: none; }

/* Fortschrittsbalken (Budget, Sparziel) */
.progress { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; margin-top: 8px; }
.progress > span { display: block; height: 100%; border-radius: 4px; background: var(--accent); }
.hero .budget { margin-top: 10px; }
.hero .progress { background: rgb(255 255 255 / 0.3); }
.hero .progress > span { background: currentColor; }
.hero .budget.warn .progress > span { background: #fde68a; }
.hero .budget.over .progress > span { background: #fdba74; }

/* Kasse */
.pot-head { display: flex; gap: 12px; align-items: center; }
.pot-head .main { flex: 1; min-width: 0; }
.pot-sum { font-size: 1.15rem; flex: none; }
.pot.closed { opacity: 0.65; }
.pot-members { margin-top: 10px; display: grid; gap: 4px; }
.pot-members > div { display: flex; justify-content: space-between; gap: 8px; }
.pot details { margin-top: 10px; }
.pot summary { cursor: pointer; color: var(--accent); }
.entries { list-style: none; padding: 0; margin: 6px 0 0; }
.entries li { display: flex; gap: 8px; align-items: center; padding: 6px 0; border-top: 1px solid var(--line); }
.entries li > span { flex: 1; }
.entries .icon-btn { width: 32px; height: 32px; font-size: 0.85rem; color: var(--muted); }

/* Kommentare */
.comments { margin: 0 12px 90px; display: grid; gap: 8px; }
.comment { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px 12px; max-width: 88%; }
.comment.mine { justify-self: end; background: var(--accent-soft); }
.comment .ctext { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 2px; }
.comment img { display: block; max-width: 100%; max-height: 260px; border-radius: 10px; margin-top: 6px; }
.comment-form { display: flex; gap: 6px; align-items: center; margin-top: 4px; }
.comment-form input[name='text'] { flex: 1; min-width: 0; }
.comment-form .btn { flex: none; }
.link-btn { border: 0; background: none; color: var(--minus); font: inherit; font-size: 0.8rem; padding: 0 0 0 6px; cursor: pointer; }

/* GiroCode */
.giro img { width: 220px; height: 220px; margin: 0 auto; display: block; background: #fff; border-radius: 12px; padding: 6px; }
.copy-row { display: flex; gap: 8px; align-items: center; justify-content: space-between; overflow-wrap: anywhere; }
.copy-row .btn { flex: none; }
