:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --text: #1c1d22;
  --muted: #6b7280;
  --border: #e3e5ea;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --pos: #16a34a;
  --neg: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181c;
    --surface: #212228;
    --surface-2: #2a2c33;
    --text: #eceef2;
    --muted: #9aa0ab;
    --border: #33353d;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  background: var(--primary); color: #fff;
}
.topbar h1 { font-size: 1.15rem; margin: 0; flex: 1; font-weight: 650;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  background: rgba(255,255,255,.15); border: 0; color: #fff;
  width: 34px; height: 34px; border-radius: 10px; font-size: 1.5rem;
  line-height: 1; cursor: pointer; flex: none;
}
.text-btn { background: none; border: 0; color: #fff; font-size: .9rem;
  cursor: pointer; opacity: .9; flex: none; }

main { max-width: 680px; margin: 0 auto; padding: 16px 14px 96px; }

/* Karten & Listen */
.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--border);
}
.section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); margin: 22px 4px 8px; font-weight: 650; }

.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 14px; border-bottom: 1px solid var(--border);
}
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .grow .sub { font-size: .82rem; color: var(--muted); margin-top: 2px; }
.row-title { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clickable { cursor: pointer; }
.clickable:active { background: var(--surface-2); }

.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: grid; place-items: center; color: #fff; font-weight: 650; font-size: .85rem;
}

.amount { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.amount-col { display: flex; flex-direction: column; align-items: flex-end; flex: none; }
.per-person { font-size: .72rem; color: var(--muted); white-space: nowrap;
  font-variant-numeric: tabular-nums; margin-top: 1px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.muted { color: var(--muted); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 11px 16px; border-radius: 11px; font-size: .95rem; font-weight: 550;
  cursor: pointer; text-decoration: none;
}
.btn:active { transform: scale(.99); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:active { background: var(--primary-dark); }
.btn.danger { color: var(--neg); }
.btn.block { width: 100%; }
.btn.small { padding: 7px 11px; font-size: .85rem; border-radius: 9px; }
.icon-del { background: none; border: 0; color: var(--muted); font-size: 1.1rem;
  cursor: pointer; padding: 6px; flex: none; }

/* Floating Add */
.fab {
  position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%; border: 0;
  background: var(--primary); color: #fff; font-size: 1.9rem; line-height: 1;
  box-shadow: 0 4px 14px rgba(79,70,229,.45); cursor: pointer; z-index: 20;
}

/* Formulare */
label { display: block; font-size: .85rem; color: var(--muted); margin: 12px 2px 5px; font-weight: 550; }
input, select {
  width: 100%; padding: 12px 13px; border: 1px solid var(--border);
  border-radius: 11px; font-size: 1rem; background: var(--surface); color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 13px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); font-size: .9rem; cursor: pointer; user-select: none;
}
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.chips-tools { display: flex; gap: 14px; margin-top: 8px; }
.chips-tools button { background: none; border: 0; color: var(--primary);
  font-size: .82rem; cursor: pointer; padding: 0; }

/* Abrechnung */
.settle-row { display: flex; align-items: center; gap: 10px; padding: 13px 14px;
  border-bottom: 1px solid var(--border); }
.settle-row:last-child { border-bottom: 0; }
.settle-row .arrow { color: var(--muted); }
.pill { padding: 2px 10px; border-radius: 999px; background: var(--surface-2);
  font-size: .82rem; font-weight: 550; }

/* Empty state */
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty .big { font-size: 2.6rem; margin-bottom: 6px; }

/* Overlays */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; justify-content: center; padding: 0;
}
/* hidden-Attribut muss display:flex schlagen, sonst sind Overlays immer sichtbar */
.overlay[hidden] { display: none; }
@media (min-width: 560px) { .overlay { align-items: center; padding: 20px; } }
.modal-card, .login-card {
  width: 100%; max-width: 520px; padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  border-radius: 20px 20px 0 0; max-height: 92vh; overflow-y: auto;
}
@media (min-width: 560px) { .modal-card, .login-card { border-radius: 20px; } }
.modal-card h2 { margin: 0 0 4px; font-size: 1.2rem; }

/* Login ist kein Eingabe-Sheet: mittig auf dem Schirm statt am unteren Rand. */
#loginOverlay { align-items: center; padding: 20px; }
.login-card {
  max-width: 340px; border-radius: 20px;
  padding: 24px 20px; text-align: center;
}
.login-card h2 { margin: 0 0 16px; font-size: 1.25rem; }
.login-card input { text-align: center; }
.login-card .btn { width: 100%; margin-top: 14px; }

.form-actions { display: flex; gap: 10px; margin-top: 20px; }
.form-actions .btn { flex: 1; }

.error { color: var(--neg); font-size: .85rem; margin: 8px 0 0; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%); background: #1f2937; color: #fff;
  padding: 10px 16px; border-radius: 10px; font-size: .9rem; z-index: 80;
  box-shadow: 0 4px 14px rgba(0,0,0,.3); max-width: 90%;
}
