:root {
  --accent: #db4c3f;
  --accent-hover: #c53727;
  --bg: #ffffff;
  --bg-soft: #fafafa;
  --sidebar: #fcfaf8;
  --surface: #ffffff;
  --border: #ebe8e5;
  --border-strong: #d6d2cd;
  --text: #202020;
  --text-soft: #666666;
  --text-faint: #999999;
  --hover: #f3f1ef;
  --active: #ffefe5;
  --active-text: #b23a1c;
  --p1: #d1453b;
  --p2: #eb8909;
  --p3: #246fe0;
  --p4: #999999;
  --overdue: #d1453b;
  --today: #058527;
  --soon: #692fc2;
  --shadow: 0 8px 30px rgba(0, 0, 0, .14);
  --radius: 10px;
  --sidebar-w: 280px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1e1e1e;
    --bg-soft: #232323;
    --sidebar: #262626;
    --surface: #282828;
    --border: #383838;
    --border-strong: #4a4a4a;
    --text: #e8e8e8;
    --text-soft: #b0b0b0;
    --text-faint: #808080;
    --hover: #313131;
    --active: #3d2a24;
    --active-text: #ff9a80;
    --p3: #5297ff;
    --today: #25b84c;
    --soon: #a970ff;
    --shadow: 0 8px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
a { color: var(--accent); }

/* ---------- Buttons & Formulare ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 6px 14px;
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface); color: var(--text); font-weight: 500;
}
.btn:hover { background: var(--hover); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { color: var(--overdue); border-color: transparent; background: transparent; }
.btn-danger:hover { background: rgba(209, 69, 59, .1); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; padding: 0;
  border: 0; border-radius: 8px; background: transparent; color: var(--text-soft);
  font-size: 18px; line-height: 1;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }

input[type=text], input[type=password], input[type=search], input[type=date], input[type=time], select, textarea {
  width: 100%; min-height: 38px; padding: 7px 10px;
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface);
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
label { display: block; font-size: 13px; color: var(--text-soft); font-weight: 500; }
label > input, label > select, label > textarea { margin-top: 4px; font-size: 15px; color: var(--text); font-weight: 400; }
.check-label { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); font-weight: 400; }
.check-label input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }

/* ---------- Anmeldung ---------- */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100%; padding: 16px; background: var(--bg-soft); }
.auth-card { width: 100%; max-width: 380px; padding: 28px 24px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 22px; margin: 18px 0 8px; }
.auth-card form { display: grid; gap: 14px; margin-top: 16px; }
.auth-logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.auth-hint { color: var(--text-soft); margin: 0; font-size: 14px; }
.auth-error { margin-top: 12px; padding: 10px 12px; border-radius: 8px; background: rgba(209, 69, 59, .12); color: var(--overdue); font-size: 14px; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100%; }
.sidebar {
  position: sticky; top: 0; flex: 0 0 var(--sidebar-w); width: var(--sidebar-w); height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; background: var(--sidebar); border-right: 1px solid var(--border);
  padding: 12px 10px calc(12px + env(safe-area-inset-bottom));
  overflow-y: auto;
}
.sidebar-head { display: flex; align-items: center; gap: 10px; padding: 6px 10px 14px; font-weight: 700; font-size: 16px; }
.nav { flex: 1; }
.nav-section { margin-top: 18px; }
.nav-section-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 4px 4px 10px; font-size: 13px; font-weight: 600; color: var(--text-soft);
}
.nav-section-head .icon-btn { width: 28px; height: 28px; font-size: 18px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 36px; padding: 6px 10px;
  border: 0; border-radius: 8px; background: transparent; text-align: left; color: var(--text);
}
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--active); color: var(--active-text); }
.nav-icon { width: 22px; text-align: center; flex: 0 0 22px; font-size: 16px; }
.nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-count { font-size: 12px; color: var(--text-faint); }
.nav-item .nav-edit { opacity: 0; width: 26px; height: 26px; font-size: 14px; }
.nav-item:hover .nav-edit, .nav-item:focus-within .nav-edit { opacity: 1; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: 0 0 10px; }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 8px; margin-top: 12px; }
.sidebar-foot form { margin: 0; }
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 40; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px;
  padding: 14px 32px; padding-top: calc(14px + env(safe-area-inset-top));
  background: var(--bg); border-bottom: 1px solid transparent;
}
.view-title { flex: 1; min-width: 0; margin: 0; font-size: 22px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.search input { width: 200px; min-height: 36px; }
.sort-select { width: auto; min-height: 36px; padding: 4px 8px; }
.menu-btn { display: none; }

.content { width: 100%; max-width: 860px; margin: 0 auto; padding: 8px 32px 120px; }

/* ---------- Schnelleingabe ---------- */
.quick-add {
  display: flex; align-items: center; gap: 8px; padding: 4px 6px 4px 12px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.quick-add:focus-within { border-color: var(--border-strong); box-shadow: 0 2px 10px rgba(0, 0, 0, .06); }
.quick-plus { color: var(--accent); font-size: 22px; line-height: 1; }
.quick-add input { flex: 1; border: 0; min-height: 40px; padding: 6px 0; background: transparent; outline: none; }
.quick-add input:focus { outline: none; }
.quick-preview { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 4px 0; font-size: 12px; }

/* ---------- Liste ---------- */
.list { margin-top: 16px; }
.group { margin-bottom: 22px; }
.group-head {
  display: flex; align-items: baseline; gap: 8px; padding: 6px 0;
  border-bottom: 1px solid var(--border); font-weight: 700; font-size: 14px;
}
.group-head .group-sub { font-weight: 400; color: var(--text-faint); font-size: 13px; }
.group-head .group-count { margin-left: auto; font-weight: 400; color: var(--text-faint); font-size: 12px; }
.group-head.overdue { color: var(--overdue); }
.tasks, .subtasks { list-style: none; margin: 0; padding: 0; }
.subtasks { padding-left: 28px; }
.task-row {
  position: relative; display: flex; align-items: flex-start; gap: 6px; padding: 9px 4px 9px 0;
  border-bottom: 1px solid var(--border);
}
.task-row:hover { background: linear-gradient(90deg, transparent, var(--bg-soft)); }
.collapse-btn {
  width: 20px; height: 22px; margin: 0; flex: 0 0 20px;
  border: 0; background: transparent; color: var(--text-faint); font-size: 11px; border-radius: 4px;
  transition: transform .15s;
}
.collapse-btn:hover { background: var(--hover); }
.collapse-btn.collapsed { transform: rotate(-90deg); }
.collapse-spacer { width: 20px; flex: 0 0 20px; }

.check {
  flex: 0 0 22px; width: 22px; height: 22px; margin-top: 0; padding: 0;
  border: 2px solid var(--p4); border-radius: 50%; background: transparent; position: relative;
}
.check::after {
  content: ""; position: absolute; left: 6px; top: 2px; width: 5px; height: 10px;
  border: solid currentColor; border-width: 0 2px 2px 0; transform: rotate(45deg); opacity: 0; color: var(--p4);
}
.check:hover::after { opacity: .7; }
.check.p1 { border-color: var(--p1); background: rgba(209, 69, 59, .1); }
.check.p1::after { color: var(--p1); }
.check.p2 { border-color: var(--p2); background: rgba(235, 137, 9, .1); }
.check.p2::after { color: var(--p2); }
.check.p3 { border-color: var(--p3); background: rgba(36, 111, 224, .1); }
.check.p3::after { color: var(--p3); }
.check.done { background: var(--p4); border-color: var(--p4); }
.check.done::after { opacity: 1; color: #fff; }
.check.done.p1 { background: var(--p1); }
.check.done.p2 { background: var(--p2); }
.check.done.p3 { background: var(--p3); }
.check.pop { animation: pop .3s ease; }
@keyframes pop { 50% { transform: scale(1.25); } }

.task-main { flex: 1; min-width: 0; padding-left: 6px; cursor: pointer; }
.task-title { word-wrap: break-word; overflow-wrap: anywhere; }
.task.is-done > .task-row .task-title { text-decoration: line-through; color: var(--text-faint); }
.task-notes { font-size: 13px; color: var(--text-soft); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-top: 3px; font-size: 12px; color: var(--text-soft); }
.task-meta:empty { display: none; }
.meta { display: inline-flex; align-items: center; gap: 4px; }
.meta-due.overdue { color: var(--overdue); }
.meta-due.today { color: var(--today); }
.meta-due.tomorrow { color: var(--p2); }
.meta-due.soon { color: var(--soon); }
.meta-project { margin-left: auto; color: var(--text-faint); }
.meta-label { color: var(--text-soft); }
.meta-parent { color: var(--text-faint); }
.task-actions { display: flex; gap: 2px; opacity: 0; }
.task-row:hover .task-actions, .task-row:focus-within .task-actions { opacity: 1; }
.task-actions .icon-btn { width: 30px; height: 30px; font-size: 15px; }

.empty { text-align: center; padding: 48px 16px; color: var(--text-soft); }
.empty-icon { font-size: 40px; }
.empty p { margin: 8px 0 0; }

.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px;
  border-radius: 99px; background: var(--hover); color: var(--text-soft); font-size: 12px;
}
.chip-toggle { border: 1px solid var(--border-strong); background: var(--surface); min-height: 30px; padding: 3px 11px; font-size: 13px; }
.chip-toggle.on { background: var(--active); color: var(--active-text); border-color: transparent; }

/* ---------- Dialoge ---------- */
.modal-wrap {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-start; justify-content: center;
  padding: 8vh 16px 16px; background: rgba(0, 0, 0, .45); overflow-y: auto;
}
.modal {
  width: 100%; max-width: 620px; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; max-height: 84vh;
}
.modal-sm { max-width: 440px; }
.modal-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px 10px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { flex: 1; margin: 0; font-size: 17px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-body { padding: 16px 20px; overflow-y: auto; display: grid; gap: 14px; }
.modal-foot {
  display: flex; align-items: center; gap: 8px; padding: 12px 20px; padding-bottom: calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}
.modal-foot .spacer { flex: 1; }
.breadcrumb { font-size: 13px; color: var(--text-soft); background: none; border: 0; padding: 0; text-align: left; }
.breadcrumb:hover { color: var(--accent); }
.title-input { font-size: 18px !important; font-weight: 600; border-color: transparent !important; padding-left: 0 !important; background: transparent !important; }
.title-input:focus { outline: none; border-bottom-color: var(--border-strong) !important; }
.notes-input { border-color: transparent !important; padding-left: 0 !important; background: transparent !important; min-height: 60px; }
.notes-input:focus { outline: none; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.section-title { font-size: 13px; font-weight: 600; color: var(--text-soft); margin: 4px 0 0; }
.sub-list { list-style: none; margin: 4px 0 0; padding: 0; border-top: 1px solid var(--border); }
.sub-list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.sub-list .check { flex: 0 0 20px; width: 20px; height: 20px; }
.sub-list .check::after { left: 5px; top: 1px; }
.sub-list .sub-title { flex: 1; min-width: 0; cursor: pointer; overflow-wrap: anywhere; }
.sub-list .sub-meta { font-size: 12px; color: var(--text-faint); }
.sub-list li.is-done .sub-title { text-decoration: line-through; color: var(--text-faint); }
.sub-add { display: flex; gap: 8px; margin-top: 8px; }
.sub-add input { flex: 1; }
.colors { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.color-opt { width: 30px; height: 30px; border-radius: 50%; border: 3px solid transparent; padding: 0; }
.color-opt.on { border-color: var(--text); box-shadow: inset 0 0 0 2px var(--surface); }
.form-error { color: var(--overdue); font-size: 14px; }
.form-ok { color: var(--today); font-size: 14px; }
.hint { font-size: 13px; color: var(--text-soft); margin: 0; }
.settings-section { border-top: 1px solid var(--border); padding-top: 14px; display: grid; gap: 10px; }
.settings-section:first-child { border-top: 0; padding-top: 0; }
.settings-section h3 { margin: 0; font-size: 15px; }
.radio-list { display: grid; gap: 6px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 200; display: flex; align-items: center; gap: 14px; max-width: calc(100% - 32px);
  padding: 10px 12px 10px 16px; border-radius: 10px; background: #2b2b2b; color: #fff; box-shadow: var(--shadow); font-size: 14px;
}
.toast button { border: 0; background: transparent; color: #ff9a80; font-weight: 600; padding: 4px 6px; }

/* ---------- FAB (nur mobil) ---------- */
.fab {
  display: none; position: fixed; right: 18px; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 30;
  width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--accent); color: #fff;
  font-size: 30px; line-height: 1; box-shadow: 0 6px 18px rgba(219, 76, 63, .45);
}

/* ---------- Mobil ---------- */
@media (max-width: 860px) {
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 50; transform: translateX(-100%);
    transition: transform .22s ease; max-width: 86vw;
  }
  .app.nav-open .sidebar { transform: none; box-shadow: var(--shadow); }
  .menu-btn { display: inline-flex; font-size: 20px; }
  .topbar { padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top)); gap: 6px; flex-wrap: wrap; border-bottom-color: var(--border); }
  .view-title { font-size: 19px; }
  .topbar-actions { width: 100%; order: 3; }
  .search { flex: 1; }
  .search input { width: 100%; }
  .content { padding: 10px 14px 120px; }
  .fab { display: inline-flex; align-items: center; justify-content: center; }
  .task-actions { display: none; }
  .nav-item .nav-edit { opacity: 1; }
  .hide-sm { display: none; }
  .task-row { padding: 11px 2px 11px 0; }
  .subtasks { padding-left: 22px; }
  .meta-project { margin-left: 0; }
  .modal-wrap { padding: 0; align-items: flex-end; }
  .modal { max-width: none; max-height: 94vh; max-height: 94dvh; border-radius: 16px 16px 0 0; }
  .grid-2 { grid-template-columns: 1fr; }
  input[type=text], input[type=password], input[type=search], input[type=date], input[type=time], select, textarea { font-size: 16px; }
}
