/* ---------- Farbtoken ---------- */
:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --surface-hover: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --on-accent: #ffffff;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --doing: #d97706;
  --doing-soft: #fef3c7;
  --open-soft: #e0e7ff;
  --open-strong: #4338ca;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.1);
  --radius: 12px;
  --header-h: 60px;
  --sidebar-w: 260px;
  color-scheme: light;
}

:root[data-theme='dark'] {
  --bg: #0b1220;
  --surface: #131c2e;
  --surface-2: #1b2740;
  --surface-hover: #24334f;
  --text: #e8eefc;
  --text-muted: #94a3b8;
  --border: #24334f;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --on-accent: #ffffff;
  --danger: #f87171;
  --danger-soft: #45191c;
  --ok: #4ade80;
  --ok-soft: #14351f;
  --doing: #fbbf24;
  --doing-soft: #40300c;
  --open-soft: #1e2a4a;
  --open-strong: #93b4fd;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; }

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Kopfzeile ---------- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: calc(var(--header-h) + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  display: flex;
  align-items: center;
  gap: 10px;
  padding-inline: 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.appbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
  margin-right: auto;
}

.brand-mark {
  width: 32px; height: 32px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--on-accent);
  display: grid;
  place-items: center;
  font-size: 1rem;
}

.icon-btn {
  width: 38px; height: 38px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  display: grid;
  place-items: center;
  font-size: 1.1rem;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

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

/* ---------- Grundlayout ---------- */
/* Volle Fensterbreite: die Seitenleiste sitzt buendig am linken Rand */
.layout {
  display: flex;
  align-items: flex-start;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  padding: 18px 12px 30px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: calc(var(--header-h) + env(safe-area-inset-top));
  height: calc(100vh - var(--header-h) - env(safe-area-inset-top));
  overflow-y: auto;
}

/* Kopfzeile der Schublade - nur auf Mobile sichtbar */
.drawer-head {
  display: none;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.filter-group { margin-bottom: 20px; }

.filter-group h2 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 0 0 6px 10px;
  font-weight: 600;
}

.filter-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  text-align: left;
  margin-bottom: 2px;
}
.filter-btn:hover { background: var(--surface-2); }
.filter-btn[aria-pressed='true'] {
  background: var(--open-soft);
  color: var(--open-strong);
  font-weight: 600;
}
.filter-btn .count {
  margin-left: auto;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.filter-btn[aria-pressed='true'] .count { color: inherit; }

.sidebar select {
  width: 100%;
  margin: 0;
}

main {
  flex: 1;
  min-width: 0;
  padding: 18px 16px calc(96px + env(safe-area-inset-bottom));
}

.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
}

.search-wrap { position: relative; flex: 1; }
.search-wrap .search-icon {
  position: absolute;
  left: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
.search-wrap input {
  margin: 0;
  padding-left: 36px;
}

.btn {
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 10px 14px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-block { width: 100%; justify-content: center; }
.btn-danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

/* ---------- Aufgabenkarten ---------- */
.section-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 22px 2px 10px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}
.section-head:first-child { margin-top: 0; }

.task-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}

.task-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  display: flex;
  gap: 11px;
  align-items: flex-start;
  text-align: left;
  width: 100%;
  color: inherit;
}
.task-card:hover { border-color: var(--accent); }
.task-card.is-done { opacity: 0.65; }

.check-btn {
  width: 26px; height: 26px;
  flex-shrink: 0;
  margin-top: 2px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  color: transparent;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
}
.check-btn:hover { border-color: var(--ok); color: var(--ok); }
.check-btn.is-done { background: var(--ok); border-color: var(--ok); color: #fff; }

.task-main { flex: 1; min-width: 0; }

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 7px;
}

.badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}
.badge::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge.plain::before { display: none; }

.badge-offen { background: var(--open-soft); color: var(--open-strong); }
.badge-in_arbeit { background: var(--doing-soft); color: var(--doing); }
.badge-erledigt { background: var(--ok-soft); color: var(--ok); }
.badge-hoch { background: var(--danger-soft); color: var(--danger); }
.badge-mittel { background: var(--doing-soft); color: var(--doing); }
.badge-niedrig { background: var(--surface-2); color: var(--text-muted); }
.badge-cat { background: var(--surface-2); color: var(--text-muted); }

.task-title {
  font-weight: 600;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.task-card.is-done .task-title { text-decoration: line-through; }

.task-notes {
  color: var(--text-muted);
  font-size: 0.87rem;
  margin-top: 3px;
  overflow-wrap: anywhere;
}

.task-foot {
  display: flex;
  align-items: center;
  gap: 6px 10px;
  margin-top: 11px;
  font-size: 0.78rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.task-foot .foot-left,
.task-foot .foot-right {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

/* Bleibt rechts, auch wenn die Fusszeile auf zwei Zeilen umbricht */
.task-foot .foot-right { margin-left: auto; }

.task-foot .overdue { color: var(--danger); font-weight: 600; }

.progress-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 2px 8px;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 48px 20px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ---------- Formulare ---------- */
label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
}

input, select, textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 12px;
  color: var(--text);
  margin-bottom: 12px;
}
input::placeholder, textarea::placeholder { color: var(--text-muted); }
textarea { resize: vertical; font-family: inherit; }

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.pill-group { display: flex; gap: 6px; margin-bottom: 12px; }
.pill-group button {
  flex: 1;
  padding: 9px 6px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.85rem;
}
.pill-group button[aria-pressed='true'] {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--open-soft);
  font-weight: 600;
}

.error-text { color: var(--danger); font-size: 0.85rem; margin: -6px 0 10px; }
.hint-text { color: var(--text-muted); font-size: 0.8rem; margin: -6px 0 12px; }

/* ---------- Dialog ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.dialog {
  background: var(--surface);
  width: 100%;
  max-width: 520px;
  border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(24px + env(safe-area-inset-bottom));
  max-height: 90vh;
  overflow-y: auto;
}

.dialog-head {
  display: flex;
  align-items: center;
  margin-bottom: 16px;
}
.dialog-head h2 { margin: 0; font-size: 1.15rem; margin-right: auto; }

/* Einkaufsliste im Dialog */
.shopping-editor {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 12px;
  background: var(--surface-2);
}
.shopping-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 0;
}
.shopping-row .text { flex: 1; overflow-wrap: anywhere; }
.shopping-row .text.checked { text-decoration: line-through; color: var(--text-muted); }
.shopping-add { display: flex; gap: 8px; margin-top: 6px; }
.shopping-add input { margin: 0; }

.tick {
  width: 22px; height: 22px;
  flex-shrink: 0;
  border-radius: 6px;
  border: 2px solid var(--border);
  background: transparent;
  color: transparent;
  display: grid;
  place-items: center;
  font-size: 0.72rem;
}
.tick.checked { background: var(--ok); border-color: var(--ok); color: #fff; }

/* ---------- Mobile ---------- */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(15, 23, 42, 0.5);
}

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  font-size: 1.6rem;
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.4);
  z-index: 25;
}

@media (max-width: 820px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    height: 100%;
    z-index: 41;
    width: 290px;
    padding-top: calc(18px + env(safe-area-inset-top));
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.3);
  }
  main { padding-inline: 14px; }
  .task-grid { grid-template-columns: 1fr; }
  .drawer-head { display: flex; }
  .new-label { display: none; }
}

@media (min-width: 821px) {
  .fab { display: none; }
  .drawer-backdrop { display: none; }
  .backdrop { align-items: center; }
  .dialog { border-radius: 16px; }
}

/* ---------- Anmeldung ---------- */
.auth-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 24px;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  width: 100%;
  max-width: 400px;
}
.auth-screen h1 { margin: 0 0 4px; text-align: center; }
.auth-screen .subtitle { text-align: center; color: var(--text-muted); margin: 0 0 22px; }

.code-input {
  font-size: 1.9rem;
  letter-spacing: 10px;
  text-align: center;
  font-weight: 700;
  padding: 12px;
}

.invite-code {
  font-size: 1.35rem;
  letter-spacing: 3px;
  font-weight: 700;
  text-align: center;
  padding: 12px;
  background: var(--surface-2);
  border-radius: 10px;
  margin-bottom: 10px;
}

.member-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}
.member-row:last-child { border-bottom: none; }
.member-row .email { color: var(--text-muted); font-size: 0.82rem; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.panel h2 { margin: 0 0 12px; font-size: 1rem; }
