:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1d2321;
  --muted: #6b7471;
  --border: #e3e1da;
  --accent: #2f6f5e;
  --accent-soft: #e2efe9;
  --danger: #b4443a;
  --warn: #b7791f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121615;
    --surface: #1b211f;
    --text: #e7ecea;
    --muted: #8d9894;
    --border: #2a3230;
    --accent: #5fb39a;
    --accent-soft: #1f3530;
    --danger: #e0786e;
    --warn: #e0a84f;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); font-size: .9rem; }

/* Buttons */
.btn {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 10px; padding: .55rem 1rem; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; }
.icon-btn { border: 0; background: none; font-size: 1.3rem; cursor: pointer; color: var(--muted); padding: .4rem; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 340px; background: var(--surface); border-radius: var(--radius);
  padding: 2rem 1.5rem; box-shadow: var(--shadow); display: grid; gap: .9rem; text-align: center;
  justify-items: center;
}
.login-card h1 { margin: 0; font-size: 1.4rem; }
.login-card input, .login-card button { width: 100%; }
.error { color: var(--danger); margin: 0; }

/* Layout */
#app { max-width: 720px; margin: 0 auto; min-height: 100%; }
.topbar {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 14px) 16px 8px;
  display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
}
.topbar h1 { margin: 0; font-size: 1.6rem; letter-spacing: -.01em; }
.topbar #today-label { flex: 1; text-align: right; }
.topbar .icon-btn { align-self: center; }
main { padding: 0 16px calc(90px + env(safe-area-inset-bottom)); }

/* Kategorie-Filter */
.chips { display: flex; gap: .4rem; overflow-x: auto; padding: 4px 0 10px; scrollbar-width: none; }
.chips button {
  flex: none; border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: .25rem .8rem; font-size: .85rem; cursor: pointer;
}
.chips button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Aufgaben */
.task-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.group-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 12px 4px 0; }
.task {
  display: flex; gap: .75rem; align-items: flex-start; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem .9rem;
  box-shadow: var(--shadow); cursor: pointer;
}
.task.prio-1 { border-left: 4px solid var(--danger); }
.task.done .title { text-decoration: line-through; color: var(--muted); }
.check {
  flex: none; width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--accent);
  background: none; cursor: pointer; margin-top: 1px; display: grid; place-items: center;
  color: #fff; font-size: .9rem;
}
.check.checked { background: var(--accent); }
.task .body { flex: 1; min-width: 0; }
.task .title { font-weight: 500; overflow-wrap: anywhere; }
.task .meta { display: flex; flex-wrap: wrap; gap: .3rem .6rem; font-size: .82rem; color: var(--muted); margin-top: 2px; }
.task .meta .overdue { color: var(--danger); font-weight: 600; }
.badge { background: var(--accent-soft); color: var(--accent); border-radius: 6px; padding: 0 .4rem; }
.empty { text-align: center; color: var(--muted); padding: 3rem 0; }

/* FAB + Tabbar */
.fab {
  position: fixed; right: max(16px, calc(50% - 344px)); bottom: calc(76px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--accent); color: #fff;
  font-size: 2rem; line-height: 1; box-shadow: 0 6px 18px rgba(0,0,0,.2); cursor: pointer; z-index: 6;
}
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 7; background: var(--surface);
  border-top: 1px solid var(--border); display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; max-width: 144px; border: 0; background: none; padding: .5rem 0 .55rem; cursor: pointer;
  display: grid; justify-items: center; gap: 1px; font-size: .72rem; color: var(--muted);
}
.tabbar button span { font-size: 1.2rem; line-height: 1.2; }
.tabbar button.active { color: var(--accent); font-weight: 600; }

/* Chat */
.chat { display: flex; flex-direction: column; }
.chat-log { display: flex; flex-direction: column; gap: 10px; padding-bottom: 80px; }
.msg { max-width: 85%; padding: .6rem .85rem; border-radius: 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.pending { color: var(--muted); font-style: italic; }
.chat-hint { color: var(--muted); text-align: center; padding: 2rem 1rem; }
.chat-form {
  position: fixed; left: 0; right: 0; bottom: calc(58px + env(safe-area-inset-bottom)); z-index: 6;
  max-width: 720px; margin: 0 auto; padding: 8px 16px; background: var(--bg);
  display: flex; gap: .5rem; align-items: flex-end;
}
.chat-form textarea {
  flex: 1; min-width: 0; resize: none; max-height: 140px; border: 1px solid var(--border);
  border-radius: 12px; padding: .55rem .75rem; background: var(--surface);
}

/* Dialog */
dialog {
  width: min(520px, calc(100% - 32px)); border: 0; border-radius: var(--radius); padding: 0;
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
dialog::backdrop { background: rgba(0,0,0,.35); }
#task-form, .settings-form { padding: 1.2rem; display: grid; gap: .8rem; }
.settings-form h2 { margin: 0; font-size: 1.2rem; }
.settings-form h3 { margin: .2rem 0 0; font-size: 1rem; }
.settings-form label { display: grid; gap: .25rem; font-size: .85rem; color: var(--muted); }
.settings-form input {
  border: 1px solid var(--border); border-radius: 10px; padding: .5rem .65rem;
  background: var(--bg); color: var(--text); width: 100%;
}
.small { font-size: .8rem; margin: 0; }
#task-form h2 { margin: 0; font-size: 1.2rem; }
#task-form label { display: grid; gap: .25rem; font-size: .85rem; color: var(--muted); }
#task-form label.inline { display: flex; align-items: center; gap: .4rem; }
#task-form input, #task-form select, #task-form textarea {
  border: 1px solid var(--border); border-radius: 10px; padding: .5rem .65rem;
  background: var(--bg); color: var(--text); width: 100%; min-width: 0;
}
#task-form label.inline input { width: 4.5rem; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; align-items: end; }
fieldset { border: 1px solid var(--border); border-radius: 10px; padding: .6rem .7rem .7rem; margin: 0; display: grid; gap: .6rem; }
legend { font-size: .85rem; color: var(--muted); padding: 0 .3rem; }
.weekdays { display: flex; flex-wrap: wrap; gap: .3rem; }
#task-form .weekdays label {
  display: flex; align-items: center; gap: .2rem; color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: .2rem .45rem; font-size: .85rem;
}
#task-form .weekdays input { width: auto; }
.dialog-actions { display: flex; gap: .5rem; align-items: center; }
.spacer { flex: 1; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(150px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: .55rem 1rem; border-radius: 10px; z-index: 20;
  display: flex; gap: 1rem; align-items: center; max-width: calc(100% - 32px);
}
.toast button { background: none; border: 0; color: var(--accent-soft); font-weight: 600; cursor: pointer; }
