:root {
  --accent: #5e6ec4;
  --accent-text: #4152ac;
  --bg: #ffffff;
  --side: #ffffff;
  --panel: #faf9f8;
  --card: #ffffff;
  --text: #252423;
  --muted: #6b6967;
  --line: #e6e4e2;
  --hover: #f3f2f1;
  --active: #e8ebfa;
  --danger: #b3261e;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --accent-text: #a9b4f0;
    --bg: #1b1a19;
    --side: #252423;
    --panel: #201f1e;
    --card: #2b2a29;
    --text: #f3f2f1;
    --muted: #b3b0ad;
    --line: #3b3a39;
    --hover: #323130;
    --active: #393c52;
    --danger: #ff8a80;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.4 "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

#login { height: 100%; overflow-y: auto; padding: 6vh 16px 24px; }
#login form { max-width: 340px; margin: 0 auto; display: flex; flex-direction: column; gap: 12px; text-align: center; }
#login img { align-self: center; }
#login h1 { margin: 0; font-size: 22px; }
#login p { margin: 0; }
#login .qr { width: 220px; height: 220px; background: #fff; border-radius: 6px; }
#login code { font-size: 15px; overflow-wrap: anywhere; user-select: all; }
.field { display: flex; flex-direction: column; gap: 4px; text-align: left; color: var(--muted); }
.field input, .stack input, dialog input[name="name"] {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--card);
  color: var(--text);
}
.remember { display: flex; gap: 10px; align-items: flex-start; text-align: left; padding: 4px 0; }
.remember input { margin-top: 3px; }
.primary { background: var(--accent); color: #fff; border-radius: 4px; padding: 10px 16px; }
.primary:disabled { opacity: .6; }
.error { color: var(--danger); min-height: 1.4em; }
pre { background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 10px; text-align: left; white-space: pre-wrap; user-select: all; }

#app { display: flex; height: 100%; height: 100dvh; }

/* ---------- Seitenleiste ---------- */
#sidebar {
  width: 270px;
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--side);
  border-right: 1px solid var(--line);
  padding: 12px 8px;
  overflow-y: auto;
}
#search {
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
}
#sidebar hr { border: 0; border-top: 1px solid var(--line); margin: 8px; width: calc(100% - 16px); }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 4px;
  text-align: left;
  border-left: 3px solid transparent;
}
.nav-item:hover, .side-action:hover { background: var(--hover); }
.nav-item.active { background: var(--active); border-left-color: var(--accent); font-weight: 600; }
.nav-item .ico { width: 20px; text-align: center; flex: none; }
.nav-item .dot { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.nav-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .count { color: var(--muted); font-size: 12px; font-weight: 400; }
.side-action { text-align: left; padding: 10px 12px; border-radius: 4px; color: var(--accent-text); }
#new-list { margin-top: 4px; }
.nav-item .shared { font-size: 12px; opacity: .8; }
.side-foot { margin-top: auto; padding-top: 12px; display: flex; flex-direction: column; flex: none; }
.side-foot strong { padding: 4px 12px; }
.side-foot .side-action { color: var(--muted); padding: 7px 12px; }
#status { margin: 0 0 4px; padding: 4px 12px; font-size: 12px; color: var(--muted); border-radius: 4px; }
#status.off { background: #a8620f; color: #fff; }

/* ---------- Hauptbereich ---------- */
#main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--theme, var(--accent));
}
#main header { display: flex; align-items: flex-end; gap: 8px; padding: 20px 24px 12px; color: #fff; }
.heading { flex: 1; min-width: 0; }
#title { margin: 0; font-size: 26px; font-weight: 600; overflow-wrap: anywhere; }
#subtitle { margin: 0; opacity: .9; }
#subtitle:empty { display: none; }
.icon-btn { width: 34px; height: 34px; border-radius: 4px; font-size: 18px; flex: none; }
#main header .icon-btn:hover { background: #ffffff30; }
#share { filter: brightness(0) invert(1); }
#sort {
  max-width: 45%;
  height: 34px;
  background: #00000030;
  color: #fff;
  border: 0;
  border-radius: 4px;
  padding: 0 6px;
}
#sort option { background: var(--card); color: var(--text); }
#menu { display: none; }

#tasks { flex: 1; overflow-y: auto; padding: 0 24px 8px; }
.task {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border-radius: 5px;
  padding: 10px 14px;
  margin-bottom: 3px;
  min-height: 52px;
  box-shadow: 0 1px 2px #0003;
  cursor: pointer;
}
.task:hover { background: var(--hover); }
.task.selected { background: var(--active); }
.task.drag-over { box-shadow: 0 -3px 0 #fff; }
.task .body { flex: 1; min-width: 0; }
.task .name { overflow-wrap: anywhere; }
.task.done .name { text-decoration: line-through; color: var(--muted); }
.meta { display: flex; flex-wrap: wrap; column-gap: 10px; font-size: 12px; color: var(--muted); }
.meta .overdue { color: var(--danger); }
.meta .today { color: var(--accent-text); }

.check {
  width: 20px;
  height: 20px;
  flex: none;
  border-radius: 50%;
  border: 2px solid var(--accent-text);
  display: grid;
  place-items: center;
  font-size: 12px;
  line-height: 1;
  color: transparent;
}
.check:hover { color: var(--accent-text); }
.check.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.star { font-size: 20px; line-height: 1; color: var(--muted); flex: none; width: 28px; height: 28px; }
.star.on { color: var(--accent-text); }

.group-toggle {
  background: #000000a6;
  color: #fff;
  border-radius: 4px;
  padding: 5px 12px;
  margin: 10px 0 8px;
  font-weight: 600;
}
.empty { color: #fff; text-align: center; margin-top: 12vh; text-shadow: 0 1px 2px #0008; }

#add {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 24px 20px;
  margin-bottom: max(20px, env(safe-area-inset-bottom));
  background: var(--card);
  border-radius: 5px;
  padding: 6px 14px;
  box-shadow: 0 2px 6px #0004;
}
#add > span { color: var(--accent-text); font-size: 20px; }
#add-title { flex: 1; min-width: 0; border: 0; background: none; padding: 9px 0; outline: none; }
#add:focus-within { outline: 2px solid #fff; }
#add-due { border: 0; background: none; color: var(--muted); width: 135px; }

/* ---------- Detailbereich ---------- */
#detail {
  width: 340px;
  flex: none;
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.detail-scroll { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.box { background: var(--card); border: 1px solid var(--line); border-radius: 5px; flex: none; }
.row { display: flex; align-items: center; gap: 10px; padding: 8px 12px; min-height: 44px; }
.row + .row { border-top: 1px solid var(--line); }
.row input[type="text"], .row textarea {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  resize: none;
  padding: 2px 0;
}
.row textarea.task-title { font-size: 17px; font-weight: 600; field-sizing: content; }
.row input.step-done { text-decoration: line-through; color: var(--muted); }
.row label { flex: 1; color: var(--muted); }
.row input[type="date"], .row select {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 4px 6px;
  width: 170px;
}
.row .grow { flex: 1; text-align: left; color: var(--muted); }
.row .grow.on { color: var(--accent-text); font-weight: 600; }
.x { color: var(--muted); width: 24px; height: 24px; flex: none; border-radius: 4px; }
.x:hover { background: var(--hover); color: var(--danger); }
.note {
  width: 100%;
  min-height: 140px;
  resize: vertical;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 10px 12px;
  flex: none;
}
.detail-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  padding: 8px 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  color: var(--muted);
  font-size: 12px;
}
.detail-foot button { font-size: 14px; padding: 6px 8px; border-radius: 4px; }
.detail-foot button:hover { background: var(--hover); }
.detail-foot .del { color: var(--danger); }

/* ---------- Menü, Dialog, Hinweis ---------- */
#context {
  position: fixed;
  z-index: 30;
  min-width: 200px;
  max-height: 70vh;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 8px 24px #0005;
  padding: 4px;
}
#context button { display: block; width: 100%; text-align: left; padding: 8px 12px; border-radius: 4px; }
#context button:hover { background: var(--hover); }
#context button.danger { color: var(--danger); }

dialog {
  width: min(360px, calc(100% - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 20px;
}
dialog::backdrop { background: #0007; }
dialog h2 { margin: 0 0 14px; font-size: 18px; }
dialog h3 { margin: 18px 0 8px; font-size: 14px; }
#panel-dialog { width: min(440px, calc(100% - 32px)); }
#panel-dialog .buttons { margin-top: 16px; }
#panel-dialog > .primary { margin-top: 8px; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.people { list-style: none; margin: 0; padding: 0; }
.people li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.people small { display: block; color: var(--muted); }
.link { color: var(--accent-text); padding: 4px 6px; }
.link.danger { color: var(--danger); }
.hint { color: var(--muted); font-size: 12px; }
dialog input[name="name"] { width: 100%; }
#colors { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
#colors input { appearance: none; width: 28px; height: 28px; border-radius: 50%; margin: 0; cursor: pointer; }
#colors input:checked { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--text); }
.buttons { display: flex; justify-content: flex-end; gap: 8px; }
.buttons button { padding: 8px 14px; border-radius: 4px; }

#toast {
  position: fixed;
  z-index: 40;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  background: #323130;
  color: #fff;
  padding: 10px 16px;
  border-radius: 6px;
  max-width: calc(100% - 32px);
}

/* ---------- Schmale Bildschirme ---------- */
@media (max-width: 1000px) {
  #detail { position: fixed; z-index: 20; top: 0; right: 0; bottom: 0; width: min(360px, 100%); box-shadow: -4px 0 20px #0004; }
}
@media (max-width: 700px) {
  #detail { width: 100%; }
  #menu { display: block; }
  #sidebar {
    position: fixed;
    z-index: 15;
    inset: 0 auto 0 0;
    width: min(290px, 85%);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform .2s, visibility .2s;
  }
  #app.menu-open #sidebar { transform: none; visibility: visible; box-shadow: 0 0 0 100vmax #0006; }
  #main header { padding: 12px 12px 10px; align-items: center; }
  #title { font-size: 21px; }
  #sort { max-width: 120px; }
  #tasks { padding: 0 10px 8px; }
  #add { margin-left: 10px; margin-right: 10px; }
  #add-due { width: 40px; overflow: hidden; }
  input, textarea, select { font-size: 16px; }
}
