:root {
  color-scheme: light dark;
  --bg: #f5f6f3;
  --side: #eaece6;
  --surface: #ffffff;
  --ink: #1c2430;
  --muted: #667080;
  --line: #d9dcd4;
  --accent: #1f6f5c;
  --on-accent: #ffffff;
  --mark: #ffe37a;
  --danger: #b3261e;
  --hover: rgba(28, 36, 48, .06);
  --font: "Segoe UI Variable Text", "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181a;
    --side: #0f1213;
    --surface: #1d2326;
    --ink: #e7ebe8;
    --muted: #97a19c;
    --line: #2c3437;
    --accent: #62c4a8;
    --on-accent: #0f1213;
    --mark: #6a5810;
    --danger: #ff8a80;
    --hover: rgba(231, 235, 232, .07);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 var(--font);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
svg { display: block; width: 100%; height: 100%; }

.link { color: var(--muted); font-size: 14px; padding: 8px 6px; border-radius: 6px; }
.link:hover { color: var(--ink); background: var(--hover); }
.link.danger:hover { color: var(--danger); }

/* ---------- Anmeldung ---------- */

#auth {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
}
#authform { width: 100%; max-width: 340px; display: grid; gap: 14px; }
#authform h1 { margin: 0; font-size: 40px; line-height: 1; letter-spacing: -.03em; }
#authform p { margin: 0 0 6px; color: var(--muted); }
#authform label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
#authform input {
  width: 100%;
  padding: 12px;
  font-size: 16px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}
#authform #autherr { margin: 0; color: var(--danger); }
.primary {
  padding: 12px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}
.primary:disabled { opacity: .6; }
#a-switch { justify-self: center; }

/* ---------- Gerüst ---------- */

#app {
  height: 100%;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}
body.has-detail #app { grid-template-columns: 280px minmax(0, 1fr) 360px; }

#side {
  background: var(--side);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  padding: calc(20px + env(safe-area-inset-top)) 10px calc(10px + env(safe-area-inset-bottom)) calc(10px + env(safe-area-inset-left));
}
.brand { font-size: 22px; font-weight: 700; letter-spacing: -.02em; padding: 0 10px 14px; }

#smart { padding-bottom: 8px; margin-bottom: 8px; border-bottom: 1px solid var(--line); }

.item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 10px;
  border-radius: 8px;
  flex: 1;
  min-width: 0;
}
.item:hover { background: var(--hover); }
.item.active { background: var(--surface); font-weight: 600; }
.item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { color: var(--muted); font-size: 13px; font-weight: 400; font-variant-numeric: tabular-nums; }
.count.warn { color: var(--danger); }

.row { display: flex; align-items: center; border-radius: 8px; }

.grip {
  flex: none;
  width: 28px;
  height: 42px;
  padding: 12px 8px;
  color: var(--muted);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  opacity: .55;
}
.drag { position: relative; z-index: 2; background: var(--surface); box-shadow: 0 6px 18px rgba(0, 0, 0, .18); }
.drag .grip { cursor: grabbing; }

#newlist { margin-top: 6px; }
#newlist input, #newtask input {
  width: 100%;
  padding: 11px 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: transparent;
}
#newlist input:focus, #newtask input:focus {
  outline: none;
  border-style: solid;
  border-color: var(--accent);
  background: var(--surface);
}
::placeholder { color: var(--muted); opacity: 1; }

#side footer {
  margin-top: auto;
  padding: 16px 10px 4px;
  display: grid;
  gap: 2px;
  font-size: 13px;
  color: var(--muted);
}
#status.off { color: var(--danger); }
#account { overflow: hidden; text-overflow: ellipsis; }
#logout { justify-self: start; margin-left: -6px; font-size: 13px; }

/* ---------- Aufgaben ---------- */

#main {
  min-height: 0;
  overflow-y: auto;
  padding: calc(20px + env(safe-area-inset-top)) clamp(16px, 4vw, 40px) calc(40px + env(safe-area-inset-bottom));
}
#main > * { max-width: 720px; }
#main header { display: flex; align-items: center; gap: 4px; margin-bottom: 14px; }
#back { display: none; flex: none; width: 36px; height: 36px; padding: 8px; margin-left: -10px; border-radius: 8px; }
#title {
  flex: 1;
  min-width: 0;
  padding: 2px 4px;
  margin-left: -4px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -.025em;
  line-height: 1.2;
  text-overflow: ellipsis;
}
#title:not([readonly]):hover { background: var(--hover); }
#title:not([readonly]):focus { outline: none; background: var(--surface); box-shadow: 0 0 0 2px var(--accent); }
#title[readonly] { outline: none; cursor: default; }

#newtask { margin-bottom: 10px; }

.group h2 { margin: 22px 0 2px; font-size: 14px; font-weight: 600; color: var(--muted); }
.group:first-child h2 { margin-top: 8px; }
.group h2.overdue, .overdue { color: var(--danger); }

.task {
  display: flex;
  align-items: flex-start;
  border-bottom: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
}
.task:hover, .task.sel { background: var(--hover); }
.task .body { flex: 1; min-width: 0; padding: 12px 6px; display: grid; gap: 2px; }
.ttl { overflow-wrap: anywhere; }
.task.star .ttl > span {
  background-image: linear-gradient(transparent 58%, var(--mark) 58%, var(--mark) 94%, transparent 94%);
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
.task.done .ttl { color: var(--muted); text-decoration: line-through; }
.meta { display: flex; flex-wrap: wrap; gap: 0 12px; font-size: 13px; color: var(--muted); }

.check {
  flex: none;
  width: 46px;
  height: 46px;
  padding: 12px;
  color: transparent;
  position: relative;
}
.check svg {
  border: 1.5px solid var(--muted);
  border-radius: 7px;
  padding: 2px;
  transition: background-color .12s, border-color .12s;
}
.check:hover svg { border-color: var(--accent); color: var(--accent); }
.done > .check svg, .done .d-head > .check svg {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.starbtn { flex: none; width: 42px; height: 46px; padding: 13px 11px; color: var(--muted); }
.starbtn svg { fill: none; }
.starbtn:hover { color: var(--ink); }
.starbtn[aria-pressed="true"] { color: var(--ink); }
.starbtn[aria-pressed="true"] svg { fill: var(--mark); }
.task .grip { height: 46px; padding: 14px 8px; }

.donetoggle {
  margin: 18px 0 4px;
  padding: 6px 10px 6px 4px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  border-radius: 6px;
}
.donetoggle::before { content: "›"; display: inline-block; width: 16px; transition: transform .12s; }
.donetoggle[aria-expanded="true"]::before { transform: rotate(90deg); }
.donetoggle:hover { background: var(--hover); color: var(--ink); }

.empty { color: var(--muted); margin: 28px 0; max-width: 34ch; }

/* ---------- Einzelne Aufgabe ---------- */

#detail {
  background: var(--surface);
  border-left: 1px solid var(--line);
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: calc(12px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) 16px;
}
#detail header { display: flex; justify-content: space-between; margin: 0 -6px; }
.d-head { display: flex; align-items: flex-start; margin: 0 -12px; }
#d-title {
  flex: 1;
  min-width: 0;
  margin-top: 8px;
  padding: 2px 0;
  border: 0;
  background-color: transparent;
  resize: none;
  overflow: hidden;
  font-size: 20px;
  font-weight: 600;
  line-height: 1.3;
}
#d-title:focus { outline: none; }
#detail.done #d-title { color: var(--muted); text-decoration: line-through; }

.field { display: grid; gap: 6px; }
.field.grow { flex: 1; grid-template-rows: auto 1fr; min-height: 180px; }
.field label { font-size: 13px; color: var(--muted); }
.duerow { display: flex; flex-wrap: wrap; gap: 8px; }
#d-due, #d-note {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}
#d-due { min-height: 44px; flex: 1 1 150px; }
#d-note { width: 100%; resize: none; line-height: 1.45; }
#d-due:focus, #d-note:focus { outline: none; border-color: var(--accent); }
.chip {
  padding: 0 12px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
}
.chip:hover { background: var(--hover); }
#d-created { margin: 0; font-size: 13px; color: var(--muted); }

/* ---------- Statistik ---------- */

.st { max-width: 760px; margin: 0 auto; padding: calc(20px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left)); }
.st-head { display: flex; align-items: center; gap: 4px; margin-bottom: 16px; }
.st-head a { flex: none; width: 36px; height: 36px; padding: 8px; margin-left: -10px; border-radius: 8px; }
.st-head a:hover { background: var(--hover); }
.st-head h1 { margin: 0; font-size: 30px; letter-spacing: -.025em; line-height: 1.2; }
.st h2 { margin: 32px 0 8px; font-size: 16px; }
.st-filters { display: flex; flex-wrap: wrap; gap: 12px; }
.st-filters label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); flex: 1 1 160px; max-width: 260px; }
.st-filters select { min-height: 44px; padding: 0 10px; font-size: 16px; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.st-msg { color: var(--muted); margin: 28px 0; }
.st-msg a { color: var(--accent); text-decoration: underline; }

.st-kpis { display: flex; flex-wrap: wrap; gap: 8px 36px; margin: 24px 0 8px; }
.st-kpis div { display: grid; }
.st-kpis dt { font-size: 13px; color: var(--muted); }
.st-kpis dd { margin: 0; font-size: 30px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }

.st-chart { display: flex; align-items: flex-end; gap: 2px; height: 190px; margin-top: 16px; overflow-x: auto; border-bottom: 1px solid var(--line); }
.st-bar { flex: 1 0 26px; max-width: 64px; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: stretch; border-radius: 6px 6px 0 0; }
.st-bar:hover { background: var(--hover); }
.st-bar .n { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; padding-bottom: 3px; }
.st-bar .fill { background: var(--accent); opacity: .5; border-radius: 4px 4px 0 0; min-height: 2px; }
.st-bar[aria-pressed="true"] .fill { opacity: 1; }
.st-bar[aria-pressed="true"] .n { color: var(--ink); font-weight: 600; }
.st-axis { display: flex; gap: 2px; overflow: hidden; }
.st-axis span { flex: 1 0 26px; max-width: 64px; text-align: center; font-size: 11px; color: var(--muted); padding-top: 4px; font-variant-numeric: tabular-nums; }

.st-rows { display: grid; grid-template-columns: minmax(0, auto) minmax(40px, 1fr) auto; gap: 8px 12px; align-items: center; }
.st-rows .bar { height: 8px; border-radius: 0 4px 4px 0; background: var(--accent); opacity: .5; min-width: 2px; }
.st-rows .num { font-variant-numeric: tabular-nums; text-align: right; }
.st-rows .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-gone { color: var(--muted); }

.st-day { margin: 14px 0 2px; font-size: 13px; color: var(--muted); }
.st-item { display: flex; justify-content: space-between; gap: 16px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.st-item .ttl { min-width: 0; }
.st-item .lst { flex: none; max-width: 40%; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Schmale Bildschirme: eine Ansicht aufs Mal ---------- */

@media (max-width: 760px) {
  #app, body.has-detail #app { grid-template-columns: minmax(0, 1fr); }
  body[data-pane="main"] #side { display: none; }
  body[data-pane="side"] #main { display: none; }
  #side { padding-right: calc(10px + env(safe-area-inset-right)); }
  .brand { font-size: 30px; padding-bottom: 18px; }
  .item { min-height: 48px; }
  .item.active { background: transparent; font-weight: 400; }
  #back { display: block; }
  #title { font-size: 26px; }
  #detail {
    position: fixed;
    inset: 0;
    z-index: 5;
    border-left: 0;
    padding-left: calc(16px + env(safe-area-inset-left));
  }
  .grip { opacity: .7; }
}

@media (hover: hover) and (min-width: 761px) {
  .row .grip, .task .grip { opacity: 0; }
  .row:hover .grip, .task:hover .grip, .drag .grip { opacity: .7; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
