:root {
  --bg: #F4F5F1;
  --surface: #FFFFFF;
  --ink: #1B1E23;
  --ink-soft: #5B6169;
  --line: #E2E4DE;
  --accent: #0B7261;
  --accent-ink: #085548;
  --today: #B45309;
  --danger: #B3362B;
  --p1: #C4372B;
  --p2: #C07A10;
  --p3: #2C6BB2;
  --p4: #B9BDB4;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ---------- Layout ---------- */
#app { display: none; min-height: 100dvh; }
#app.ready { display: grid; grid-template-columns: 200px 1fr; }
.rail {
  border-right: 1px solid var(--line);
  padding: 18px 12px calc(12px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 4px;
  background: var(--surface);
  position: sticky; top: 0; height: 100dvh;
}
.brand {
  font-weight: 700; letter-spacing: 0.02em; font-size: 17px;
  padding: 4px 10px 14px; display: flex; align-items: baseline; gap: 8px;
}
.brand .dot { color: var(--accent); }
.navbtn {
  display: flex; justify-content: space-between; align-items: center;
  border: 0; background: none; text-align: left;
  padding: 9px 10px; border-radius: 8px; color: var(--ink); width: 100%;
}
.navbtn .count { font-family: var(--mono); font-size: 12px; color: var(--ink-soft); }
.navbtn:hover { background: var(--bg); }
.navbtn.active { background: var(--accent); color: #fff; }
.navbtn.active .count { color: #d7ece7; }
.rail .spacer { flex: 1; }

main { padding: 20px clamp(14px, 3vw, 36px) 90px; max-width: 1080px; width: 100%; }

/* ---------- Quick add ---------- */
.quickadd {
  display: flex; gap: 8px; margin-bottom: 22px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 6px;
}
.quickadd input {
  flex: 1; border: 0; background: none; outline: none; padding: 8px 10px; min-width: 0;
}
.quickadd button {
  border: 0; background: var(--accent); color: #fff;
  border-radius: 7px; padding: 8px 16px; font-weight: 600;
}
.quickadd button:hover { background: var(--accent-ink); }
.hint { color: var(--ink-soft); font-size: 12.5px; margin: -14px 4px 20px; }
.hint code { font-family: var(--mono); background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }

/* ---------- Task rows ---------- */
.group h3 {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--ink-soft); margin: 26px 0 8px 2px; font-weight: 600;
  display: flex; gap: 8px; align-items: baseline;
}
.group h3 .n { font-family: var(--mono); font-weight: 400; }
.group h3.overdue { color: var(--danger); }
.group h3.today { color: var(--today); }

.task {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: 6px;
  box-shadow: inset 3px 0 0 var(--pc, transparent);
  cursor: pointer;
}
.task[data-p="1"] { --pc: var(--p1); }
.task[data-p="2"] { --pc: var(--p2); }
.task[data-p="3"] { --pc: var(--p3); }
.task.done { opacity: 0.55; }
.task.done .t-title { text-decoration: line-through; }
.task:hover { border-color: #c9ccc4; }
.t-body { flex: 1; min-width: 0; }
.t-title { font-weight: 500; overflow-wrap: anywhere; }
.t-meta { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 3px; font-size: 12.5px; color: var(--ink-soft); font-family: var(--mono); }
.t-meta .over { color: var(--danger); }
.t-meta .today { color: var(--today); }

.check {
  width: 20px; height: 20px; border-radius: 50%;
  border: 1.8px solid var(--pc, #b9bdb4); background: none;
  flex: none; margin-top: 1px; padding: 0; position: relative;
}
.check:hover { background: var(--bg); }
.task.done .check, .check.on { background: var(--accent); border-color: var(--accent); }
.task.done .check::after, .check.on::after {
  content: ""; position: absolute; left: 5.5px; top: 2.5px;
  width: 4px; height: 8px; border: solid #fff; border-width: 0 2px 2px 0;
  transform: rotate(42deg);
}

/* ---------- Kalender ---------- */
.cal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.cal-head h2 { margin: 0; font-size: 19px; flex: 1; }
.cal-head button {
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 7px; padding: 6px 12px;
}
.cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px;
}
.cal-dow { text-align: center; font-size: 11.5px; color: var(--ink-soft); font-family: var(--mono); padding: 4px 0; }
.cal-day {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  min-height: 96px; padding: 5px; display: flex; flex-direction: column; gap: 3px;
}
.cal-day.dim { opacity: 0.45; }
.cal-day.drop { border-color: var(--accent); background: #eef6f4; }
.cal-num { font-family: var(--mono); font-size: 12px; color: var(--ink-soft); padding: 1px 3px; align-self: flex-start; border-radius: 5px; }
.cal-day.today .cal-num { background: var(--today); color: #fff; }
.cal-task {
  font-size: 11.5px; border-radius: 5px; padding: 2.5px 5px;
  background: var(--bg); border-left: 3px solid var(--pc, var(--p4));
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: grab;
}
.cal-task[data-p="1"] { --pc: var(--p1); }
.cal-task[data-p="2"] { --pc: var(--p2); }
.cal-task[data-p="3"] { --pc: var(--p3); }
.cal-task.done { text-decoration: line-through; opacity: 0.5; }
.cal-more { font-size: 11px; color: var(--ink-soft); font-family: var(--mono); }

/* ---------- Board ---------- */
.board { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; align-items: start; }
.col {
  background: #EDEFE9; border-radius: var(--radius); padding: 8px;
  min-height: 140px;
}
.col.drop { outline: 2px solid var(--accent); }
.col h3 {
  margin: 2px 4px 10px; font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--ink-soft); display: flex; justify-content: space-between;
}
.col h3 .n { font-family: var(--mono); font-weight: 400; }
.col .task { margin-bottom: 7px; }
.col .task:active { cursor: grabbing; }

/* ---------- Modal ---------- */
dialog {
  border: 0; border-radius: 14px; padding: 0;
  width: min(620px, calc(100vw - 24px)); background: var(--surface); color: var(--ink);
  box-shadow: 0 24px 60px rgba(20, 24, 20, 0.25);
}
dialog::backdrop { background: rgba(24, 28, 24, 0.35); }
.m-inner { padding: 20px; display: flex; flex-direction: column; gap: 14px; max-height: 86dvh; overflow: auto; }
.m-inner input[type="text"], .m-inner input[type="date"], .m-inner input[type="time"],
.m-inner select, .m-inner textarea, .m-inner input[type="email"], .m-inner input[type="password"] {
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; width: 100%; background: #fff;
}
.m-title { font-size: 17px; font-weight: 600; }
.m-row { display: flex; gap: 10px; flex-wrap: wrap; }
.m-row > label { flex: 1; min-width: 120px; font-size: 12.5px; color: var(--ink-soft); display: flex; flex-direction: column; gap: 4px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; background: none; padding: 7px 12px; color: var(--ink-soft); border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--ink); border-color: var(--accent); }
textarea#f-notes { min-height: 130px; font-family: var(--mono); font-size: 13.5px; resize: vertical; }
.md { line-height: 1.55; }
.md :first-child { margin-top: 0; }
.md pre { background: var(--bg); padding: 10px; border-radius: 8px; overflow: auto; font-size: 13px; }
.md code { font-family: var(--mono); font-size: 0.92em; background: var(--bg); padding: 0 3px; border-radius: 4px; }
.md pre code { background: none; padding: 0; }
.md blockquote { border-left: 3px solid var(--line); margin: 0; padding-left: 12px; color: var(--ink-soft); }
.md img { max-width: 100%; }
.md input[type="checkbox"] { accent-color: var(--accent); }

.atts { display: flex; flex-direction: column; gap: 6px; }
.att {
  display: flex; align-items: center; gap: 8px; font-size: 13.5px;
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
}
.att .sz { font-family: var(--mono); font-size: 11.5px; color: var(--ink-soft); }
.att a { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-decoration: none; color: var(--ink); }
.att button, .tok button { border: 0; background: none; color: var(--danger); padding: 2px 4px; font-size: 13px; }

.m-actions { display: flex; gap: 8px; align-items: center; }
.m-actions .spacer { flex: 1; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 14px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.link { border: 0; color: var(--accent); background: none; padding: 8px 6px; }

/* ---------- Tokens / Einstellungen ---------- */
.tok { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13.5px; }
.tok .name { flex: 1; }
.tok .meta { font-family: var(--mono); font-size: 11.5px; color: var(--ink-soft); }
.tokenreveal {
  font-family: var(--mono); font-size: 12.5px; background: var(--bg);
  border: 1px dashed var(--accent); border-radius: 8px; padding: 10px; word-break: break-all;
}

/* ---------- Auth ---------- */
#authview {
  min-height: 100dvh; display: grid; place-items: center; padding: 20px;
}
.authcard {
  width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 26px; display: flex; flex-direction: column; gap: 12px;
}
.authcard h1 { margin: 0 0 4px; font-size: 22px; }
.authcard h1 .dot { color: var(--accent); }
.authcard input { border: 1px solid var(--line); border-radius: 8px; padding: 10px 11px; }
.err { color: var(--danger); font-size: 13.5px; min-height: 1em; }

.empty { color: var(--ink-soft); padding: 30px 4px; }
.toast {
  position: fixed; bottom: calc(76px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; border-radius: 9px; padding: 9px 16px;
  font-size: 13.5px; z-index: 60; opacity: 0; transition: opacity 0.2s;
  pointer-events: none;
}
.toast.on { opacity: 1; }

/* ---------- Mobil ---------- */
@media (max-width: 760px) {
  #app.ready { grid-template-columns: 1fr; }
  .rail {
    position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: auto; z-index: 50;
    flex-direction: row; border-right: 0; border-top: 1px solid var(--line);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  }
  .brand, .rail .spacer { display: none; }
  .navbtn { flex-direction: column; gap: 1px; font-size: 12px; padding: 6px 2px; text-align: center; align-items: center; justify-content: center; }
  .navbtn .count { display: none; }
  main { padding-bottom: 110px; }
  .board { grid-template-columns: 1fr; }
  .cal-day { min-height: 64px; }
  .cal-task { display: none; }
  .cal-day .cal-dots { display: flex; gap: 2px; flex-wrap: wrap; }
}
@media (min-width: 761px) { .cal-dots { display: none; } }
.cal-dots i { width: 6px; height: 6px; border-radius: 2px; background: var(--p4); }
.cal-dots i.p1 { background: var(--p1); } .cal-dots i.p2 { background: var(--p2); } .cal-dots i.p3 { background: var(--p3); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- Projekte & Filter ---------- */
.rail-projects { margin-top: 14px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.rail-projects .plabel {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--ink-soft); padding: 4px 10px 6px; display: flex; justify-content: space-between; align-items: center;
}
.rail-projects .plabel button { border: 0; background: none; color: var(--ink-soft); font-size: 15px; padding: 0 2px; line-height: 1; }
.projbtn { gap: 8px; justify-content: flex-start; font-size: 14px; }
.projbtn .pdot { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.projbtn.active .pdot { outline: 2px solid rgba(255,255,255,0.6); }
.filterbar { display: none; gap: 6px; margin: -6px 0 16px; flex-wrap: wrap; align-items: center; }
.filterbar .chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 4px 12px; font-size: 13px; display: inline-flex; gap: 6px; align-items: center;
}
.filterbar .chip .pdot { width: 8px; height: 8px; border-radius: 3px; }
.filterbar .chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.searchbox {
  display: flex; align-items: center; gap: 6px; margin: 0 0 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 2px 10px;
}
.searchbox input { border: 0; background: none; outline: none; padding: 7px 0; flex: 1; min-width: 0; }
.searchbox .clear { border: 0; background: none; color: var(--ink-soft); padding: 2px 4px; }
.t-meta .proj { display: inline-flex; align-items: center; gap: 5px; }
.t-meta .pdot { width: 7px; height: 7px; border-radius: 2px; display: inline-block; }
.t-meta .recur::before { content: "↻ "; }

/* ---------- Mein Tag ---------- */
.day-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 4px; }
.day-head h2 { margin: 0; font-size: 19px; }
.day-load { font-family: var(--mono); font-size: 13px; color: var(--ink-soft); }
.day-load.full { color: var(--danger); }
.suggest { margin-top: 30px; }
.suggest .task { opacity: 0.85; }
.addday {
  border: 1px solid var(--line); background: var(--surface); color: var(--today);
  border-radius: 7px; padding: 4px 9px; font-size: 12.5px; flex: none; margin-top: 1px;
}

/* ---------- Woche ---------- */
.week-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; align-items: start; }
.week-day { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px; min-height: 180px; }
.week-day.today { border-color: var(--today); }
.week-day.drop { border-color: var(--accent); background: #eef6f4; }
.week-day h4 { margin: 2px 2px 8px; font-size: 11.5px; font-family: var(--mono); font-weight: 400; color: var(--ink-soft); }
.week-day.today h4 { color: var(--today); font-weight: 700; }
.week-day .cal-task { white-space: normal; margin-bottom: 4px; }
.week-day .wt-time { color: var(--ink-soft); font-family: var(--mono); }
.segbtns { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.segbtns button { border: 0; background: var(--surface); padding: 6px 12px; }
.segbtns button.on { background: var(--ink); color: #fff; }

/* ---------- Unteraufgaben ---------- */
.subs { display: flex; flex-direction: column; gap: 4px; }
.sub { display: flex; align-items: center; gap: 8px; padding: 5px 2px; border-bottom: 1px solid var(--line); }
.sub:last-child { border-bottom: 0; }
.sub .check { width: 17px; height: 17px; }
.sub .check.on::after { left: 4.5px; top: 1.5px; }
.sub span { flex: 1; overflow-wrap: anywhere; }
.sub.done span { text-decoration: line-through; color: var(--ink-soft); }
.sub button.del { border: 0; background: none; color: var(--ink-soft); }
.subadd { display: flex; gap: 6px; }
.subadd input { flex: 1; border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; }

/* ---------- Rückblick ---------- */
.stat-cards { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 22px; }
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; flex: 1; min-width: 130px; }
.stat-card .big { font-family: var(--mono); font-size: 26px; font-weight: 700; }
.stat-card .lbl { color: var(--ink-soft); font-size: 12.5px; margin-top: 2px; }
.bars { display: flex; gap: 8px; align-items: flex-end; height: 130px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; height: 100%; justify-content: flex-end; }
.bar i { width: 100%; max-width: 42px; background: var(--accent); border-radius: 5px 5px 0 0; min-height: 2px; }
.bar.today i { background: var(--today); }
.bar b { font-family: var(--mono); font-size: 12px; font-weight: 400; }
.bar span { font-family: var(--mono); font-size: 11px; color: var(--ink-soft); }

/* Drag-Sortierung */
.task.dragover { border-top: 2px solid var(--accent); }
.task .drag { color: var(--ink-soft); cursor: grab; flex: none; margin-top: 2px; font-size: 13px; opacity: 0; }
.task:hover .drag { opacity: 0.7; }

@media (max-width: 760px) {
  .rail-projects { display: none; }
  .filterbar { display: flex; }
  .task .drag { display: none; }
  .week-grid { grid-template-columns: 1fr; }
  .week-day { min-height: 0; }
}
@media (min-width: 761px) { .filterbar { display: none !important; } }
#authview[hidden] { display: none; }
