:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #6b7280;
  --border: #e3e1dc;
  --accent: #4f7cff;
  --accent-text: #ffffff;
  --success: #2f9e5b;
  --danger: #d1453b;
  --warn: #c7811a;
  --overdue: #d1453b;
  --today: #c7811a;
  --soon: #3b82f6;
  --hover: #efede8;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181b;
    --surface: #212327;
    --text: #e8e9eb;
    --muted: #9aa0a8;
    --border: #33363c;
    --accent: #7096ff;
    --hover: #2a2d32;
    --overdue: #f0766c;
    --today: #e9a646;
    --soon: #7aa7ff;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
h3 { font-size: .95rem; margin: 1rem 0 .4rem; }
code { background: var(--hover); padding: .1em .35em; border-radius: 4px; font-size: .9em; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hint { color: var(--muted); font-size: .82rem; margin: .4rem 0 0; }
.empty { color: var(--muted); padding: 2rem 0; text-align: center; }

/* Formulare */
input[type=text], input[type=search], input[type=password], input[type=date], input[type=time],
input[type=datetime-local], input[type=number], select, textarea {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .45rem .6rem;
  min-width: 0;
}
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
textarea { width: 100%; resize: vertical; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .9rem; }
input[type=color] { width: 2.4rem; height: 2.2rem; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
label { display: block; font-size: .85rem; color: var(--muted); }
label > input, label > select { display: block; width: 100%; margin-top: .2rem; color: var(--text); }
label.inline { display: inline-flex; align-items: center; gap: .3rem; color: var(--text); font-size: .9rem; }
fieldset { border: 0; padding: 0; margin: .8rem 0; }
legend { font-size: .85rem; color: var(--muted); padding: 0; margin-bottom: .3rem; }

.btn {
  display: inline-block;
  font: inherit;
  font-weight: 500;
  padding: .45rem .9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--hover); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.danger:hover { background: var(--danger); color: #fff; }
.btn.wide { width: 100%; margin-top: .8rem; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 1rem; padding: .2rem .45rem; border-radius: 6px; }
.icon-btn:hover { background: var(--hover); color: var(--danger); }

.row { display: flex; gap: .5rem; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row .grow, .grow { flex: 1 1 12rem; }
.narrow { width: 5rem; }
.stack > * + * { margin-top: .7rem; }
.narrow-form { max-width: 24rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.card + .card, section.card { margin-top: 1rem; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; }

.notice { padding: .6rem .8rem; border-radius: 8px; margin: 0 0 1rem; border: 1px solid; }
.notice.ok { border-color: var(--success); color: var(--success); }
.notice.error { border-color: var(--danger); color: var(--danger); }
.notice.warn { border-color: var(--warn); color: var(--warn); }

.badge { display: inline-block; font-size: .75rem; padding: 0 .45rem; border-radius: 99px; border: 1px solid var(--border); color: var(--muted); margin-left: .3rem; }
.badge.ok { color: var(--success); border-color: var(--success); }
.badge.error { color: var(--danger); border-color: var(--danger); }
.badge.warn { color: var(--warn); border-color: var(--warn); }

/* Layout */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1rem;
  padding: .55rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .45rem; font-weight: 700; font-size: 1.1rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.search { margin-left: auto; }
.search input { width: 16rem; max-width: 45vw; }
.menu-btn { display: none; font-size: 1.3rem; color: var(--text); }

.layout { display: flex; min-height: calc(100vh - 53px); }
.sidebar {
  width: 250px; flex-shrink: 0;
  padding: 1rem .7rem;
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex; flex-direction: column;
}
.sidebar h3 { margin: 1.2rem .5rem .3rem; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; }
.sidebar h3 a { color: var(--muted); }
.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-list a { display: flex; align-items: center; gap: .5rem; padding: .3rem .5rem; border-radius: 7px; color: var(--text); }
.nav-list a:hover, .nav-list a.active { background: var(--hover); text-decoration: none; }
.nav-list li.small { padding: .3rem .5rem; }
.count { margin-left: auto; color: var(--muted); font-size: .8rem; }
.count.alert { color: var(--overdue); font-weight: 600; }
.nav-footer { margin-top: auto; padding: 1rem .5rem 0; display: flex; justify-content: space-between; align-items: center; font-size: .9rem; }
.dot { display: inline-block; width: .65rem; height: .65rem; border-radius: 50%; flex-shrink: 0; }
.dot.big { width: .9rem; height: .9rem; margin-right: .5rem; vertical-align: middle; }
.dot.hollow { border: 1.5px solid var(--muted); }
.hash { font-weight: 700; width: .65rem; text-align: center; }

.content { flex: 1; min-width: 0; padding: 1.3rem clamp(1rem, 3vw, 2.5rem) 3rem; max-width: 1100px; }
.page-head { display: flex; align-items: baseline; gap: .8rem; margin-bottom: 1rem; }

/* Taskliste */
.quick-add { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; padding: .6rem; }
.filters { display: flex; flex-wrap: wrap; gap: .8rem; align-items: flex-end; margin: 1rem 0 .5rem; }
.filters label { display: flex; align-items: center; gap: .35rem; }
.filters select { width: auto; margin: 0; padding: .25rem .4rem; font-size: .88rem; }
.group h2 { margin: 1.3rem 0 .4rem; font-size: .95rem; }
.group h2 .muted { font-weight: 400; font-size: .85rem; }
.task-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.task { display: flex; align-items: flex-start; gap: .6rem; padding: .55rem .8rem; border-top: 1px solid var(--border); }
.task:first-child { border-top: 0; }
.task:hover { background: var(--hover); }
.task-main { flex: 1; min-width: 0; color: var(--text); display: block; }
.task-main:hover { text-decoration: none; }
.task-title { display: block; overflow-wrap: anywhere; }
.task.done .task-title { text-decoration: line-through; color: var(--muted); }
.task-meta { display: flex; flex-wrap: wrap; gap: .25rem .55rem; font-size: .8rem; color: var(--muted); margin-top: .1rem; }
.task-meta:empty { display: none; }
.check {
  width: 1.3rem; height: 1.3rem; margin-top: .12rem;
  border: 2px solid var(--muted); border-radius: 50%;
  background: transparent; color: #fff; cursor: pointer;
  font-size: .75rem; line-height: 1; padding: 0;
  display: grid; place-items: center;
}
.check:hover { border-color: var(--success); background: color-mix(in srgb, var(--success) 15%, transparent); }
.task.done .check { background: var(--success); border-color: var(--success); }
.due { font-weight: 500; }
.overdue { color: var(--overdue); }
.today { color: var(--today); }
.soon { color: var(--soon); }
.chip { display: inline-flex; align-items: center; gap: .3rem; }
.chip.label { color: var(--c, var(--muted)); }
.icon { white-space: nowrap; }

.recent-done h2 { color: var(--muted); }
.recent-done .task-list { opacity: .85; }
.check.plopped { background: var(--success); border-color: var(--success); transform: scale(1.15); transition: transform .12s; }

.date-wrap { position: relative; display: inline-block; }
.date-wrap input { width: 100%; display: block; }
.date-ph { display: none; }
.date-wrap.is-empty .date-ph {
  display: flex; align-items: center;
  position: absolute; inset: 1px 2rem 1px 1px; padding-left: .6rem;
  background: var(--surface); color: var(--muted);
  border-radius: 8px; pointer-events: none;
}
.date-wrap.is-empty:focus-within .date-ph { display: none; }

/* Detail */
.detail-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.title-input { width: 100%; font-size: 1.4rem !important; font-weight: 600; padding: .5rem .7rem !important; margin-bottom: 1rem; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1rem; align-items: start; margin-bottom: 1rem; }
.detail-grid > .card { margin-top: 0; }
.detail-grid + .detail-grid { grid-template-columns: 1fr 1fr; }
.side > * + * { margin-top: .8rem; }
.side .row { align-items: flex-end; }
.due-text { font-size: .85rem; margin: .3rem 0 0; }
.label-picks { display: flex; flex-wrap: wrap; gap: .3rem; margin-bottom: .5rem; }
.pick { display: inline-flex; align-items: center; gap: .25rem; padding: .15rem .55rem; border: 1px solid var(--border); border-radius: 99px; color: var(--c, var(--text)); cursor: pointer; font-size: .85rem; }
.pick:has(input:checked) { border-color: var(--c, var(--accent)); background: color-mix(in srgb, var(--c, var(--accent)) 14%, transparent); }
.pick input { margin: 0; }
.side fieldset input[type=text] { width: 100%; }
.plain-list { list-style: none; margin: 0 0 .8rem; padding: 0; }
.plain-list li { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .35rem 0; border-bottom: 1px solid var(--border); }
.plain-list li:last-child { border-bottom: 0; }
.plain-list li > a, .plain-list li > span { overflow-wrap: anywhere; }
.danger-zone { margin-top: 2rem; text-align: right; }

.markdown { overflow-wrap: anywhere; }
.markdown:empty::before { content: "Keine Beschreibung"; color: var(--muted); }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown h1, .markdown h2, .markdown h3 { font-size: 1.05rem; margin: 1rem 0 .4rem; }
.markdown pre { background: var(--hover); padding: .6rem; border-radius: 6px; overflow-x: auto; }
.markdown blockquote { margin: .5rem 0; padding-left: .8rem; border-left: 3px solid var(--border); color: var(--muted); }
.markdown table { border-collapse: collapse; }
.markdown td, .markdown th { border: 1px solid var(--border); padding: .25rem .5rem; }
.markdown img { max-width: 100%; }

/* Verwaltung */
.manage-list { list-style: none; padding: 0; margin: 1rem 0 0; }
.manage-list > li.card { display: flex; align-items: center; gap: .5rem; padding: .6rem; margin-top: .5rem; }
.manage-list > li.card > form:first-child { flex: 1; }
.manage-list > li.archived { opacity: .6; }
.kv th { text-align: left; color: var(--muted); font-weight: 400; padding-right: 1rem; }
.kv { margin-bottom: .8rem; }

/* Login */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.login-card { width: 100%; max-width: 22rem; }
.login-card input[type=password] { width: 100%; margin-top: .2rem; }
.login-brand { display: flex; align-items: center; gap: .6rem; margin-bottom: 1.2rem; }

/* Mobil */
@media (max-width: 800px) {
  .menu-btn { display: block; }
  .sidebar {
    position: fixed; top: 53px; bottom: 0; left: 0; z-index: 20;
    transform: translateX(-100%); transition: transform .2s;
    box-shadow: 0 0 30px rgba(0,0,0,.2); overflow-y: auto;
  }
  body.nav-open .sidebar { transform: none; }
  .detail-grid, .detail-grid + .detail-grid { grid-template-columns: 1fr; }
  .quick-add { gap: .4rem; }
  .quick-add .grow { flex: 1 1 100%; }
  .quick-add select { flex: 1 1 0; min-width: 0; }
  .quick-add .date-wrap { flex: 0 0 7.3rem; width: 7.3rem; }
  .quick-add .date-wrap input { padding-left: .4rem; padding-right: .3rem; }
  .quick-add .btn { flex: 0 0 auto; padding: .45rem .7rem; }
  .filters { flex-wrap: nowrap; gap: .4rem; }
  .filters label { flex: 1 1 0; min-width: 0; font-size: 0; gap: 0; }
  .filters select { width: 100%; font-size: .82rem; padding: .25rem .3rem; }
  .filters > a.small { flex: 0 0 auto; font-size: .75rem; }
  .search input { width: 10rem; }
  .content { padding-top: 1rem; }
}
