:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f0f3f9;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #dbeafe;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --success: #16a34a;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 6px 20px rgba(15, 23, 42, .06);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-2: #273449;
    --border: #334155;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --primary-soft: #1e3a5f;
    --danger: #ef4444;
    --danger-soft: #3b1d1d;
    --shadow: 0 1px 3px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

#app { min-height: 100%; display: flex; flex-direction: column; }

/* ---------- Auth screens (Login / Setup) ---------- */
.auth-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: calc(24px + var(--safe-top));
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
}
.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}
.brand-logo {
  width: 64px; height: 64px; border-radius: 18px;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  display: grid; place-items: center;
  box-shadow: 0 6px 16px rgba(59,130,246,.35);
}
.brand-logo svg { width: 36px; height: 36px; }
.brand h1 { font-size: 1.35rem; margin: 0; }
.brand p { margin: 0; color: var(--text-muted); font-size: .9rem; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label {
  display: block; font-size: .82rem; font-weight: 600;
  color: var(--text-muted); margin-bottom: 6px;
}
input[type=text], input[type=password], input[type=email], select {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
input[type=color] {
  width: 48px; height: 40px; padding: 2px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface); cursor: pointer;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
  padding: 12px 16px;
  font-size: 1rem; font-weight: 600;
  border: none; border-radius: var(--radius-sm);
  background: var(--primary); color: #fff;
  cursor: pointer;
  transition: background .15s, transform .05s;
}
.btn:hover { background: var(--primary-dark); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { filter: brightness(.92); }
.btn-sm { width: auto; padding: 8px 14px; font-size: .88rem; }
.btn-ghost { background: transparent; color: var(--primary); width: auto; padding: 8px; }

.msg { font-size: .88rem; padding: 10px 12px; border-radius: var(--radius-sm); margin-bottom: 14px; }
.msg-error { background: var(--danger-soft); color: var(--danger); }
.msg-success { background: #dcfce7; color: var(--success); }
@media (prefers-color-scheme: dark) { .msg-success { background: #14331f; } }

/* ---------- App shell ---------- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + var(--safe-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.appbar .title { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; }
.appbar .title .dot { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg,#3b82f6,#6366f1); display:grid; place-items:center; }
.appbar .title .dot svg { width: 18px; height: 18px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: .9rem;
  cursor: pointer; border: none;
}

.content { flex: 1; padding: 16px; padding-bottom: 96px; max-width: 720px; width: 100%; margin: 0 auto; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
}
.card h2 { margin: 0 0 4px; font-size: 1.05rem; }
.card .sub { color: var(--text-muted); font-size: .88rem; margin: 0 0 12px; }

.section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin: 20px 4px 8px; font-weight: 700; }

.greeting { font-size: 1.5rem; font-weight: 700; margin: 6px 4px 2px; }
.greeting-sub { color: var(--text-muted); margin: 0 4px 8px; }

.feature-card { display: flex; align-items: center; gap: 14px; }
.feature-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; flex-shrink: 0; }
.feature-icon svg { width: 24px; height: 24px; }
.feature-body { flex: 1; }
.feature-body h3 { margin: 0; font-size: 1rem; }
.feature-body p { margin: 2px 0 0; color: var(--text-muted); font-size: .85rem; }
.badge { font-size: .7rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-muted); }
.badge-soon { background: var(--primary-soft); color: var(--primary-dark); }
@media (prefers-color-scheme: dark){ .badge-soon{ color:#93c5fd; } }

/* ---------- User list ---------- */
.user-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.user-row:last-child { border-bottom: none; }
.user-badge { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; flex-shrink: 0; }
.user-info { flex: 1; min-width: 0; }
.user-info .name { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.user-info .meta { font-size: .8rem; color: var(--text-muted); }
.pill { font-size: .68rem; font-weight: 700; padding: 2px 7px; border-radius: 999px; }
.pill-admin { background: var(--primary-soft); color: var(--primary-dark); }
.pill-inactive { background: var(--danger-soft); color: var(--danger); }
@media (prefers-color-scheme: dark){ .pill-admin{ color:#93c5fd; } }

/* ---------- Bottom navigation ---------- */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; justify-content: space-around;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}
.bottomnav button {
  flex: 1; border: none; background: none; cursor: pointer;
  padding: 10px 4px; color: var(--text-muted);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: .68rem; font-weight: 600;
}
.bottomnav button svg { width: 24px; height: 24px; }
.bottomnav button.active { color: var(--primary); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(15,23,42,.5);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease;
}
@media (min-width: 560px) { .modal-backdrop { align-items: center; } }
.modal {
  width: 100%; max-width: 480px;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 22px 20px calc(22px + var(--safe-bottom));
  box-shadow: var(--shadow);
  animation: slideup .2s ease;
  max-height: 90vh; overflow-y: auto;
}
@media (min-width: 560px) { .modal { border-radius: var(--radius); animation: fade .15s ease; } }
.modal h2 { margin: 0 0 16px; font-size: 1.15rem; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { flex: 1; }
@keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.mt { margin-top: 12px; }
.center { text-align: center; }
.muted { color: var(--text-muted); }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.link { color: var(--primary); cursor: pointer; text-decoration: none; font-weight: 600; }
.hidden { display: none !important; }
.checkbox-row { display: flex; align-items: center; gap: 10px; }
.checkbox-row input { width: auto; }

/* ---------- Empty states ---------- */
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty-state .icon { width: 56px; height: 56px; margin: 0 auto 12px; opacity: .5; }
.empty-state .icon svg { width: 56px; height: 56px; }
.empty-state h3 { margin: 0 0 6px; color: var(--text); }
.empty-state p { margin: 0 0 14px; font-size: .9rem; }

/* ---------- Filter bar (Aufgaben) ---------- */
.filter-bar { display: flex; gap: 8px; overflow-x: auto; padding: 2px 4px 10px; margin: 0 -2px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.filter-bar::-webkit-scrollbar { display: none; }
.fchip { flex-shrink: 0; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: 7px 14px; font-size: .85rem; font-weight: 600; cursor: pointer; white-space: nowrap; }
.fchip:hover { border-color: var(--primary); }
.fchip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- Familien-Projekt-Auswahl (Einstellungen) ---------- */
.fam-list { display: flex; flex-direction: column; gap: 2px; }
.fam-check { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.fam-check:last-child { border-bottom: none; }
.fam-check input { width: 20px; height: 20px; flex-shrink: 0; accent-color: var(--primary); }

/* ---------- Group headings ---------- */
.group-head { font-size: .8rem; font-weight: 700; color: var(--text-muted); margin: 18px 4px 8px; text-transform: uppercase; letter-spacing: .03em; display: flex; align-items: center; gap: 8px; }
.group-head .count { background: var(--surface-2); color: var(--text-muted); border-radius: 999px; padding: 1px 8px; font-size: .72rem; }
.group-head.overdue { color: var(--danger); }

/* ---------- To-do items ---------- */
.todo-item { display: flex; align-items: flex-start; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.todo-item:last-child { border-bottom: none; }
.todo-check {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--border);
  flex-shrink: 0; cursor: pointer; margin-top: 1px; background: var(--surface);
  display: grid; place-items: center; transition: all .15s;
}
.todo-check svg { width: 14px; height: 14px; opacity: 0; color: #fff; }
.todo-check.done { background: var(--success); border-color: var(--success); }
.todo-check.done svg { opacity: 1; }
.todo-main { flex: 1; min-width: 0; }
.todo-title { font-weight: 500; line-height: 1.35; }
.todo-item.is-done .todo-title { text-decoration: line-through; color: var(--text-muted); }
.todo-meta { display: flex; align-items: center; gap: 8px; margin-top: 4px; flex-wrap: wrap; font-size: .8rem; color: var(--text-muted); }
.chip { font-size: .7rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.chip-due { background: var(--surface-2); color: var(--text-muted); }
.chip-due.over { background: var(--danger-soft); color: var(--danger); }
.prio { font-size: .7rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.chip-proj { background: var(--surface-2); color: var(--text-muted); display: inline-flex; align-items: center; gap: 3px; }
.chip-proj svg { width: 11px; height: 11px; }
.todo-edit { color: var(--text-muted); align-self: center; opacity: .5; cursor: pointer; }
.todo-edit svg { width: 18px; height: 18px; }
.reschedule { display: flex; flex-wrap: wrap; gap: 8px; margin: -4px 0 14px; }
.rs-chip { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: 7px 14px; font-size: .85rem; font-weight: 600; cursor: pointer; }
.rs-chip:hover { border-color: var(--primary); }
.rs-chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.prio-Hoch { background: var(--danger-soft); color: var(--danger); }
.prio-Normal { background: var(--primary-soft); color: var(--primary-dark); }
.prio-Niedrig { background: #dcfce7; color: var(--success); }
@media (prefers-color-scheme: dark){ .prio-Normal{color:#93c5fd;} .prio-Niedrig{background:#14331f;} }

/* ---------- Calendar ---------- */
.cal-day-head { display: flex; align-items: baseline; gap: 8px; margin: 18px 4px 8px; }
.cal-day-head .wd { font-weight: 700; font-size: 1rem; }
.cal-day-head .dt { color: var(--text-muted); font-size: .85rem; }
.cal-day-head.today .wd { color: var(--primary); }
.cal-event { display: flex; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.cal-event:last-child { border-bottom: none; }
.cal-time { width: 58px; flex-shrink: 0; font-size: .82rem; color: var(--text-muted); font-variant-numeric: tabular-nums; padding-top: 1px; }
.cal-time .allday { font-size: .7rem; }
.cal-bar { width: 3px; border-radius: 3px; background: var(--primary); flex-shrink: 0; }
.cal-body { flex: 1; min-width: 0; }
.cal-body .t { font-weight: 500; line-height: 1.3; }
.cal-body .loc { font-size: .8rem; color: var(--text-muted); margin-top: 2px; display: flex; align-items: center; gap: 4px; }
.cal-body .loc svg { width: 13px; height: 13px; flex-shrink: 0; }

/* ---------- Toggle switch ---------- */
.switch { position: relative; display: inline-block; width: 46px; height: 28px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: var(--border); border-radius: 999px; transition: .2s; cursor: pointer; }
.switch .slider::before { content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(18px); }

/* ---------- Settings ---------- */
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }
.settings-row .label { font-weight: 600; }
.settings-row .desc { font-size: .8rem; color: var(--text-muted); margin-top: 2px; }
details.adv { margin-top: 6px; }
details.adv summary { cursor: pointer; color: var(--primary); font-weight: 600; font-size: .88rem; padding: 6px 0; }
textarea { width: 100%; padding: 12px 14px; font-size: .95rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font-family: inherit; resize: vertical; min-height: 76px; }
textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

/* ---------- Menu list (Mehr) ---------- */
.menu-item { display: flex; align-items: center; gap: 14px; padding: 15px 4px; border-bottom: 1px solid var(--border); cursor: pointer; }
.menu-item:last-child { border-bottom: none; }
.menu-item .mi-icon { width: 24px; height: 24px; color: var(--text-muted); flex-shrink: 0; }
.menu-item .mi-icon svg { width: 24px; height: 24px; }
.menu-item .mi-label { flex: 1; font-weight: 600; }
.menu-item .mi-arrow { color: var(--text-muted); }
.pull-status { text-align:center; font-size:.75rem; color:var(--text-muted); padding: 8px; }

/* ---------- 5-Tab Nav enger ---------- */
.bottomnav button { font-size: .64rem; padding: 9px 2px; gap: 2px; }
.bottomnav button svg { width: 22px; height: 22px; }

/* ---------- Woche-Navigation ---------- */
.week-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 4px 4px; }
.wn-btn { width: 40px; height: 40px; border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius-sm); color: var(--text); cursor: pointer; display: grid; place-items: center; }
.wn-btn svg { width: 20px; height: 20px; }
.wn-center { text-align: center; }
.wn-range { font-weight: 700; }
.wn-center .link { font-size: .78rem; }

/* ---------- Pickup rows ---------- */
.dot-sm { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; display: inline-block; }
.pk-row { padding: 12px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.pk-row:last-child { border-bottom: none; }
.pk-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.pk-name { font-weight: 700; }
.pk-lines { display: flex; flex-direction: column; gap: 6px; padding-left: 20px; }
.pk-assign-line { display: flex; align-items: center; gap: 8px; font-size: .9rem; }
.pk-al-icon { width: 18px; height: 18px; color: var(--text-muted); flex-shrink: 0; }
.pk-al-icon svg { width: 18px; height: 18px; }
.pk-al-label { width: 62px; color: var(--text-muted); font-size: .82rem; flex-shrink: 0; }
.pk-al-val { font-weight: 500; padding: 2px 10px; border: 1.5px solid var(--border); border-radius: 999px; }
.pk-note { margin: 8px 0 0 20px; font-size: .82rem; color: var(--text-muted); }

/* Dashboard mini pickup rows */
.pk-mini { display: flex; align-items: center; gap: 8px; font-size: .9rem; }
.pk-mini-name { font-weight: 600; flex: 1; }
.pk-mini-hol { display: flex; align-items: center; gap: 5px; color: var(--text); }
.pk-mini-hol svg { width: 16px; height: 16px; color: var(--text-muted); }

input[type=time] { width: 100%; padding: 12px 10px; font-size: 1rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); }
input[type=time]:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
