:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --ink: #1f2328;
  --muted: #6b7078;
  --line: #e3e1da;
  --accent: #2f6f5e;
  --accent-ink: #ffffff;
  --chip: #ebe9e2;
  --red: #b3261e;
  --orange: #a35a00;
  --radius: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17191c; --card: #202328; --ink: #e8e6e1; --muted: #9aa0a8; --line: #30343a;
    --accent: #6fbfa6; --accent-ink: #0f1a17; --chip: #2b2f35; --red: #ff8a80; --orange: #f0b45a;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px 14px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--red); }
input { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 9px 11px; min-width: 0; }
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.err { color: var(--red); min-height: 1.2em; margin: 6px 0 0; font-size: 14px; }

#app { max-width: 720px; margin: 0 auto; padding: 0 14px 90px; }

/* Anmeldung */
.login { max-width: 320px; margin: 18vh auto 0; padding: 0 20px; text-align: center; }
.login-icon { width: 64px; height: 64px; }
.login h1 { margin: 8px 0 20px; }
.login form { display: grid; gap: 10px; }

/* Kopf */
.top { display: flex; align-items: center; justify-content: space-between; padding: 14px 0 8px; }
.top h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
.icon-btn { border: none; background: none; font-size: 22px; padding: 4px 8px; color: var(--muted); }

/* Eingabe */
.add { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; }
.add-row { display: flex; gap: 8px; }
.add-row input { flex: 1; border: none; background: transparent; padding: 8px 6px; }
.add-row input:focus-visible { outline: none; }
.add-row button { padding: 6px 14px; font-size: 18px; }
.add-more { display: flex; flex-wrap: wrap; gap: 8px 14px; padding: 6px 6px 2px; border-top: 1px solid var(--line); margin-top: 6px; }
.add-more label { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }
.add-more input { padding: 5px 8px; font-size: 14px; }

/* Filter-Chips */
.chips { display: flex; flex-direction: column; gap: 6px; margin: 12px 0 6px; }
.chip-group { display: flex; align-items: center; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chip-group::-webkit-scrollbar { display: none; }
.chip-label { font-size: 12px; color: var(--muted); width: 50px; flex: none; }
.chip { flex: none; border: 1px solid transparent; background: var(--chip); border-radius: 999px; padding: 5px 12px; font-size: 14px; white-space: nowrap; }
.chip small { color: var(--muted); font-size: 12px; }
.chip.on { background: var(--accent); color: var(--accent-ink); }
.chip.on small { color: inherit; opacity: 0.8; }

/* Liste */
.list { list-style: none; margin: 8px 0 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list:empty { display: none; }
.todo { display: flex; align-items: flex-start; gap: 4px; border-top: 1px solid var(--line); }
.todo:first-child { border-top: none; }
.check { width: 22px; height: 22px; margin: 13px 4px 13px 14px; accent-color: var(--accent); flex: none; cursor: pointer; }
.todo .body { flex: 1; min-width: 0; text-align: left; border: none; background: none; border-radius: 0; padding: 11px 6px; display: flex; flex-direction: column; gap: 3px; }
.title { overflow-wrap: anywhere; }
.todo.done .title { text-decoration: line-through; color: var(--muted); }
.meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 13px; color: var(--muted); }
.due.today { color: var(--orange); font-weight: 600; }
.due.overdue { color: var(--red); font-weight: 600; }
.src { background: var(--chip); border-radius: 6px; padding: 0 6px; }
.key { font-family: ui-monospace, monospace; font-size: 12px; max-width: 12em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.open-src { flex: none; align-self: center; text-decoration: none; color: var(--accent); font-size: 20px; padding: 8px 14px; }
.empty { text-align: center; color: var(--muted); margin-top: 40px; }

/* Dialoge */
dialog { border: none; border-radius: 16px; background: var(--card); color: var(--ink); width: min(440px, calc(100vw - 20px)); padding: 16px; }
dialog::backdrop { background: rgb(0 0 0 / 0.35); }
dialog h2 { margin: 0 0 12px; font-size: 18px; }
dialog form > label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); margin-bottom: 10px; }
dialog form > label input { color: var(--ink); font-size: 16px; }
dialog fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 0 0 10px; padding: 8px 12px; }
dialog legend { font-size: 14px; color: var(--muted); padding: 0 4px; }
#set-days { width: 6em; }
.checks { display: grid; gap: 6px; }
.check-row { display: flex; align-items: center; gap: 8px; }
.check-row input { width: 18px; height: 18px; accent-color: var(--accent); }
.meta-info { font-size: 13px; color: var(--muted); margin: 0; overflow-wrap: anywhere; }
.dlg-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; margin-top: 14px; align-items: center; }
.dlg-actions button { padding: 8px 10px; font-size: 15px; }
.dlg-actions button.danger { border: none; background: none; padding: 8px 2px; }
.spacer { flex: 1; }

/* Hinweis unten */
.toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); border-radius: 12px; padding: 10px 14px;
  display: flex; gap: 14px; align-items: center; box-shadow: 0 6px 24px rgb(0 0 0 / 0.2); max-width: calc(100vw - 24px);
}
.toast button { background: none; border: none; color: var(--bg); font-weight: 700; padding: 0; text-decoration: underline; }
