:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --text: #1c2233;
  --muted: #667089;
  --border: #dde2ee;
  --primary: #4f7cff;
  --primary-text: #ffffff;
  --success: #1f9d61;
  --success-bg: #e2f6ec;
  --warning: #b86e00;
  --warning-bg: #fff2dc;
  --danger: #d23c3c;
  --danger-bg: #fde7e7;
  --info-bg: #e7eeff;
  --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 4px 16px rgba(20, 30, 60, .06);
  --radius: 14px;
  --nav-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151d;
    --surface: #1b1f2a;
    --surface-2: #252a37;
    --text: #e8ebf3;
    --muted: #98a0b5;
    --border: #2f3544;
    --primary: #6d93ff;
    --success: #4cc98b;
    --success-bg: #173327;
    --warning: #f0a940;
    --warning-bg: #3a2c14;
    --danger: #ff6b6b;
    --danger-bg: #3d1d1f;
    --info-bg: #1e2a4a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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;
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; margin: 24px 0 10px; }
h3 { font-size: 1rem; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.splash { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }

/* ---------- Layout ---------- */

.shell { min-height: 100vh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
}
.topbar .brand { font-weight: 700; font-size: 1.1rem; flex: 1; }
.main { max-width: 860px; margin: 0 auto; padding: 4px 16px 16px; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .72rem; position: relative;
}
.nav a .ico { font-size: 1.35rem; line-height: 1; }
.nav a.active { color: var(--primary); font-weight: 600; }

@media (min-width: 900px) {
  .shell { padding-bottom: 24px; padding-left: 220px; }
  .nav {
    top: 0; right: auto; width: 220px; height: auto; flex-direction: column; justify-content: flex-start;
    padding: 76px 12px 12px; border-top: 0; border-right: 1px solid var(--border);
  }
  .nav a { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px 14px; border-radius: 10px; font-size: .95rem; }
  .nav a.active { background: var(--info-bg); }
  .topbar { padding-left: 24px; }
}

.badge-dot {
  position: absolute; top: 6px; right: calc(50% - 20px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: .7rem; font-weight: 700;
  display: grid; place-items: center;
}
@media (min-width: 900px) { .badge-dot { position: static; margin-left: auto; } }

/* ---------- Bausteine ---------- */

.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 12px;
}
.card.flat { box-shadow: none; border: 1px solid var(--border); }

.hero {
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: #fff; border-radius: var(--radius); padding: 20px; margin: 8px 0 16px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.hero .big { font-size: 2.4rem; font-weight: 800; line-height: 1; }
.hero .grow { flex: 1; min-width: 160px; }
.hero .money { background: rgba(255, 255, 255, .18); padding: 8px 14px; border-radius: 12px; font-weight: 700; font-size: 1.15rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: .875rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { border: 0; background: none; color: var(--text); font-size: 1.3rem; padding: 6px; cursor: pointer; border-radius: 8px; position: relative; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn .badge-dot { top: -2px; right: -4px; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }

.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px;
  font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.pill.open { background: var(--info-bg); color: var(--primary); }
.pill.reported { background: var(--warning-bg); color: var(--warning); }
.pill.approved { background: var(--success-bg); color: var(--success); }
.pill.rejected, .pill.overdue { background: var(--danger-bg); color: var(--danger); }
.pill.free { background: var(--surface-2); color: var(--text); border: 1px dashed var(--muted); }
.pts { font-weight: 700; color: var(--primary); white-space: nowrap; }

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

/* Aufgaben-Zeile */
.task {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border-radius: 12px; padding: 12px 14px; margin-bottom: 8px;
  box-shadow: var(--shadow); border-left: 5px solid var(--c, var(--primary));
}
.task .body { flex: 1; min-width: 0; }
.task .title { font-weight: 600; }
.task .meta { font-size: .85rem; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 2px; }
.task.done .title { text-decoration: line-through; color: var(--muted); }
.task .actions { display: flex; gap: 6px; flex: none; }
.task.clickable { cursor: pointer; }
.empty { text-align: center; color: var(--muted); padding: 20px 12px; }

/* Kalender */
.cal-head { display: flex; align-items: center; gap: 8px; margin: 8px 0 12px; }
.cal-head h1 { flex: 1; font-size: 1.25rem; }
.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px;
  padding: 6px 12px; font: inherit; font-size: .875rem; cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip .dot { width: 10px; height: 10px; border-radius: 50%; }

.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .wd { text-align: center; font-size: .75rem; color: var(--muted); font-weight: 600; padding: 4px 0; }
.cal .day {
  min-height: 64px; background: var(--surface); border-radius: 10px; padding: 4px; cursor: pointer;
  border: 2px solid transparent; display: flex; flex-direction: column; gap: 2px; overflow: hidden; text-align: left;
  font: inherit; color: inherit;
}
.cal .day.other { opacity: .4; }
.cal .day.today .num { background: var(--primary); color: #fff; }
.cal .day.sel { border-color: var(--primary); }
.cal .num { font-size: .8rem; font-weight: 600; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; }
.cal .ev {
  font-size: .7rem; line-height: 1.25; padding: 1px 4px; border-radius: 4px; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal .ev.done { opacity: .45; text-decoration: line-through; }
.cal .more { font-size: .68rem; color: var(--muted); padding-left: 4px; }
.cal .dots { display: none; gap: 3px; flex-wrap: wrap; padding: 2px 4px; }
.cal .dots i { width: 7px; height: 7px; border-radius: 50%; }
@media (max-width: 600px) {
  .cal .day { min-height: 52px; align-items: center; }
  .cal .ev, .cal .more { display: none; }
  .cal .dots { display: flex; justify-content: center; }
}

/* Formulare */
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 5px; color: var(--muted); }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.weekdays { display: flex; gap: 6px; flex-wrap: wrap; }
.weekdays label { cursor: pointer; }
.weekdays input { display: none; }
.weekdays span {
  display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid var(--border); font-weight: 600; font-size: .85rem;
}
.weekdays input:checked + span { background: var(--primary); color: #fff; border-color: var(--primary); }
.colors { display: flex; gap: 8px; flex-wrap: wrap; }
.colors input { display: none; }
.colors span { display: block; width: 36px; height: 36px; border-radius: 50%; cursor: pointer; border: 3px solid transparent; }
.colors input:checked + span { border-color: var(--text); }
.error { background: var(--danger-bg); color: var(--danger); padding: 10px 12px; border-radius: 10px; margin-bottom: 12px; font-size: .9rem; }

/* Anmeldung */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: 100%; max-width: 380px; padding: 28px 24px; }
.auth .logo { font-size: 3rem; text-align: center; }
.auth h1 { text-align: center; margin: 6px 0 4px; }
.auth p { text-align: center; margin: 0 0 20px; }

/* Tabs */
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; margin: 8px 0 16px; }
.tabs button { flex: 1; border: 0; background: none; padding: 9px; border-radius: 9px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.tabs button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* Listen */
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-item .body { flex: 1; min-width: 0; }
.delta { font-weight: 700; white-space: nowrap; }
.delta.plus { color: var(--success); }
.delta.minus { color: var(--danger); }
.notif.unread { background: var(--info-bg); margin: 0 -16px; padding: 12px 16px; }

.balances { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.balance-card .points { font-size: 1.8rem; font-weight: 800; }
.banner { display: flex; gap: 12px; align-items: center; background: var(--info-bg); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.banner .grow { flex: 1; }

/* Dialog */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(10, 14, 25, .5);
  display: flex; align-items: flex-end; justify-content: center;
}
.dialog {
  background: var(--bg); width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
}
.dialog .head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.dialog .foot { display: flex; gap: 8px; margin-top: 8px; }
.dialog .foot .btn { flex: 1; }
@media (min-width: 600px) {
  .overlay { align-items: center; }
  .dialog { border-radius: 20px; padding: 24px; }
}

#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom)); z-index: 60;
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 12px; font-weight: 600;
  transition: .2s; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%); }
