:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --panel-2: #f1f2f7;
  --text: #15171c;
  --muted: #6b7080;
  --line: #e4e6ee;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --warn: #c2410c;
  --ok: #16a34a;
  --star: #f59e0b;
  --outlook: #0a64c8;
  --shadow: 0 1px 2px rgba(16, 20, 40, .05), 0 4px 16px rgba(16, 20, 40, .06);
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel: #171a21;
    --panel-2: #1e222b;
    --text: #e8eaf0;
    --muted: #8a90a2;
    --line: #262b36;
    --accent: #818cf8;
    --accent-soft: #23264a;
    --accent-text: #0f1115;
    --danger: #f87171;
    --warn: #fb923c;
    --ok: #4ade80;
    --outlook: #5aa9ff;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.25);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.err { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 14px; }

.btn {
  border: 0; border-radius: 10px; padding: 10px 16px;
  background: var(--panel-2); font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.round { width: 44px; height: 44px; padding: 0; border-radius: 50%; font-size: 22px; line-height: 1; flex: none; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.link { background: none; border: 0; color: var(--muted); padding: 4px 0; text-decoration: underline; }
.icon-btn {
  width: 38px; height: 38px; border: 0; border-radius: 10px; background: transparent;
  font-size: 18px; display: grid; place-items: center; flex: none;
}
.icon-btn:hover { background: var(--panel-2); }
.chip {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px;
  padding: 4px 10px; font-size: 13px;
}
.chip:hover { border-color: var(--accent); }

/* ---------- Anmeldung ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: min(380px, 100%); background: var(--panel); border-radius: 20px; padding: 28px;
  box-shadow: var(--shadow); display: grid; gap: 14px;
}
.auth-card h1 { margin: 0; font-size: 22px; }
.auth-card p { margin: 0; }
.auth-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.auth-card input {
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; background: var(--bg); font-size: 16px;
}
.auth-logo img { width: 52px; height: 52px; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 260px 1fr auto; height: 100dvh; }
.sidebar {
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: calc(14px + var(--safe-t)) 10px 12px; gap: 6px; overflow-y: auto;
}
.side-head { display: flex; align-items: center; gap: 10px; padding: 4px 10px 12px; }
.side-logo { width: 28px; height: 28px; }
.side-title { font-weight: 700; font-size: 17px; }
.side-section { margin-top: 10px; }
.side-label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 6px 12px; }
.side-foot { margin-top: auto; padding: 12px; display: grid; gap: 4px; border-top: 1px solid var(--line); }
.nav { display: grid; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border: 0;
  border-radius: 10px; background: transparent; text-align: left;
}
.nav-item:hover { background: var(--panel-2); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .ico { width: 20px; text-align: center; flex: none; }
.nav-item .count { margin-left: auto; font-size: 12px; color: var(--muted); font-weight: 500; }
.nav-item.active .count { color: var(--accent); }
.add-list { color: var(--muted); }

.main { display: flex; flex-direction: column; min-width: 0; height: 100dvh; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: calc(14px + var(--safe-t)) 24px 10px;
}
.title-wrap { min-width: 0; flex: 1; }
.title-wrap h1 { margin: 0; font-size: 26px; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-wrap input {
  width: 220px; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 8px 12px;
}
.only-mobile { display: none; }
.banner { margin: 0 24px 8px; padding: 8px 12px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-size: 13px; }

.list-wrap { flex: 1; overflow-y: auto; padding: 4px 24px 24px; }
.todo-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.group-head {
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  padding: 14px 4px 4px; display: flex; justify-content: space-between; align-items: center;
}
.todo {
  display: flex; align-items: flex-start; gap: 12px; background: var(--panel); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow); cursor: pointer; border: 1px solid transparent;
  transition: transform .12s ease, opacity .2s ease;
}
.todo:hover { border-color: var(--line); }
.todo.selected { border-color: var(--accent); }
.todo.leaving { opacity: 0; transform: translateX(12px); }
.todo-main { flex: 1; min-width: 0; }
.todo-title { overflow-wrap: anywhere; }
.todo.done .todo-title { color: var(--muted); text-decoration: line-through; }
.todo-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 3px; font-size: 12.5px; color: var(--muted); }
.todo-meta .overdue { color: var(--danger); font-weight: 600; }
.todo-meta .today { color: var(--accent); font-weight: 600; }
.todo-meta .mail { color: var(--outlook); }
.todo-meta .pend { color: var(--warn); }
.check {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--muted); background: transparent;
  flex: none; margin-top: 1px; display: grid; place-items: center; padding: 0; position: relative;
}
.check::after { content: ""; position: absolute; inset: -10px; }
.check:hover { border-color: var(--accent); }
.check.on { background: var(--accent); border-color: var(--accent); }
.check.on::before { content: "✓"; color: var(--accent-text); font-size: 13px; font-weight: 700; }
.check.big { width: 26px; height: 26px; margin-top: 4px; }
.star { border: 0; background: none; font-size: 20px; color: var(--muted); padding: 0 2px; flex: none; line-height: 1; }
.star.on { color: var(--star); }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty .big { font-size: 40px; display: block; margin-bottom: 8px; }
.done-toggle { margin: 16px 0 8px; border: 0; background: var(--panel-2); border-radius: 999px; padding: 6px 14px; font-size: 13px; color: var(--muted); }
.done-list .todo { box-shadow: none; background: transparent; border-color: var(--line); }

.add-bar {
  position: relative; display: flex; gap: 10px; align-items: center;
  padding: 10px 24px calc(14px + var(--safe-b)); border-top: 1px solid var(--line); background: var(--bg);
}
.add-bar input {
  flex: 1; border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 12px 14px; font-size: 16px; min-width: 0;
}
.add-bar input:focus, .search-wrap input:focus, .detail input:focus, .detail textarea:focus, .auth-card input:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent;
}
.add-chips { position: absolute; left: 30px; bottom: calc(100% - 4px); display: flex; gap: 6px; }
.add-chips span { font-size: 12px; background: var(--accent-soft); color: var(--accent); padding: 2px 8px; border-radius: 999px; }

/* ---------- Detail ---------- */
.detail {
  width: 380px; background: var(--panel); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; height: 100dvh;
}
.detail-head { display: flex; align-items: center; gap: 8px; padding: calc(10px + var(--safe-t)) 12px 6px; }
.detail-body { flex: 1; overflow-y: auto; padding: 8px 20px 20px; display: grid; gap: 16px; align-content: start; }
.detail-title-row { display: flex; gap: 10px; align-items: flex-start; }
#dTitle {
  flex: 1; border: 0; background: transparent; font-size: 19px; font-weight: 600; resize: none; padding: 2px 0; overflow: hidden;
}
.field { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.field input, .field textarea {
  border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 9px 11px; color: var(--text); font-size: 15px;
}
.field textarea { resize: vertical; }
.due-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.due-row input { flex: 1 1 150px; }
.mail-box { background: var(--panel-2); border-radius: 12px; padding: 12px 14px; display: grid; gap: 4px; font-size: 13.5px; }
.mail-row { display: grid; grid-template-columns: 64px 1fr; gap: 8px; }
.mail-row span:last-child { overflow-wrap: anywhere; }
.mail-preview { margin-top: 8px; white-space: pre-wrap; max-height: 260px; overflow-y: auto; font-size: 13px; border-top: 1px solid var(--line); padding-top: 8px; }
.mail-box p { margin: 6px 0 0; }
.open-mail { margin-top: 10px; text-align: center; text-decoration: none; display: block; }
.detail-foot {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 10px 14px calc(12px + var(--safe-b)); border-top: 1px solid var(--line);
}

.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  box-shadow: var(--shadow); display: flex; gap: 14px; align-items: center; z-index: 50;
  width: max-content; max-width: calc(100% - 32px);
}
.toast button { background: none; border: 0; color: var(--accent); font-weight: 700; padding: 0; }
@media (prefers-color-scheme: light) { .toast button { color: #a5b4fc; } }

.sheet-dialog {
  border: 0; border-radius: 16px; padding: 8px; background: var(--panel); color: var(--text);
  box-shadow: var(--shadow); min-width: 260px;
}
.sheet-dialog::backdrop { background: rgba(0,0,0,.35); }
.sheet-dialog form { display: grid; gap: 2px; }
.sheet-dialog button { border: 0; background: none; text-align: left; padding: 12px 14px; border-radius: 10px; }
.sheet-dialog button:hover { background: var(--panel-2); }
.sheet-dialog .danger { color: var(--danger); }
.scrim { display: none; }

/* ---------- Handy ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .only-mobile { display: grid; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(300px, 85vw); z-index: 30;
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; }
  .topbar { padding: calc(10px + var(--safe-t)) 14px 6px; gap: 8px; flex-wrap: wrap; }
  .title-wrap h1 { font-size: 22px; }
  .search-wrap { order: 5; flex-basis: 100%; }
  .search-wrap input { width: 100%; }
  .list-wrap { padding: 4px 12px 20px; }
  .banner { margin: 0 12px 8px; }
  .add-bar { padding: 10px 12px calc(10px + var(--safe-b)); }
  .add-chips { left: 18px; }
  .detail {
    position: fixed; inset: 0; width: auto; z-index: 40; border-left: 0;
    animation: up .18s ease;
  }
  @keyframes up { from { transform: translateY(24px); opacity: .4; } to { transform: none; opacity: 1; } }
}
