:root {
  color-scheme: light dark;
  --bg: #f5f4ef;
  --surface: #ffffff;
  --surface-2: #efede6;
  --text: #1e2421;
  --muted: #5f6a64;
  --line: #dedbd1;
  --accent: #2f6f5e;
  --accent-text: #ffffff;
  --accent-weak: #e1eee9;
  --danger: #b03a28;
  --danger-weak: #f8e4df;
  --warn: #8a5a12;
  --warn-weak: #f6ead2;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 14px rgb(0 0 0 / 5%);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151917;
    --surface: #1e2421;
    --surface-2: #262d29;
    --text: #e7ebe8;
    --muted: #9aa69f;
    --line: #323a36;
    --accent: #69bda2;
    --accent-text: #0e1a16;
    --accent-weak: #21342d;
    --danger: #ee8672;
    --danger-weak: #3a2420;
    --warn: #e2b565;
    --warn-weak: #382e1a;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.5rem; line-height: 1.2; text-wrap: balance; }
h2 { font-size: 0.95rem; font-weight: 650; display: flex; align-items: center; gap: 0.5rem; }
h3 { font-size: 0.82rem; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); font-size: 0.875rem; }
.error { color: var(--danger); min-height: 1.4em; font-size: 0.9rem; }

/* ---------- Bedienelemente ---------- */

.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 0.5rem 0.85rem;
  min-height: 2.5rem;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn.quiet:hover { background: var(--surface-2); color: var(--text); }
.btn.small { padding: 0.25rem 0.6rem; min-height: 2rem; font-size: 0.85rem; align-self: flex-start; }
.btn.danger-quiet { border-color: transparent; background: transparent; color: var(--danger); }
.btn.danger-quiet.armed { background: var(--danger); color: #fff; }
.icon-btn {
  border: 0; background: transparent; cursor: pointer; border-radius: 6px;
  width: 1.75rem; height: 1.75rem; font-size: 1.2rem; line-height: 1; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.field { display: flex; flex-direction: column; gap: 0.25rem; min-width: 0; }
.field > span { font-size: 0.8rem; color: var(--muted); }
.field.inline { flex-direction: row; align-items: center; gap: 0.4rem; }
.field.grow { flex: 1 1 14rem; }
.field.grow input { width: 100%; }
input[type="text"], input[type="url"], input[type="password"], input[type="date"], input[type="search"], select, textarea {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
  min-height: 2.5rem;
  max-width: 100%;
}
textarea { resize: vertical; width: 100%; }

.chip {
  display: inline-flex; align-items: center;
  font-size: 0.78rem; line-height: 1.3;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
}
.chip.project { color: var(--text); max-width: 14rem; overflow: hidden; text-overflow: ellipsis; }
.chip.project::before { content: ""; width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--c); margin-right: 0.35rem; flex: none; }
.chip.due.today { background: var(--warn-weak); color: var(--warn); }
.chip.due.overdue { background: var(--danger-weak); color: var(--danger); }
.chip.type-message { background: var(--accent-weak); color: var(--accent); }
.chip.type-decision { background: var(--warn-weak); color: var(--warn); }
.chip.filter { cursor: pointer; border-color: var(--line); background: transparent; min-height: 1.9rem; padding-inline: 0.7rem; }
.chip.filter.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.count {
  font-size: 0.75rem; font-weight: 600; color: var(--muted);
  background: var(--surface-2); border-radius: 999px; padding: 0 0.45rem; min-width: 1.3rem; text-align: center;
  font-variant-numeric: tabular-nums;
}
.count:empty { display: none; }

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

.center-screen { min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem; }
.login-card {
  width: min(22rem, 100%); display: flex; flex-direction: column; gap: 0.9rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 1.75rem; box-shadow: var(--shadow);
}

/* ---------- Grundaufbau ---------- */

#app { display: grid; grid-template-columns: 16rem minmax(0, 1fr); min-height: 100dvh; }
#sidebar {
  position: sticky; top: 0; height: 100dvh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 0.25rem;
  padding: 1rem 0.75rem; border-right: 1px solid var(--line); background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 700; font-size: 1.05rem; color: var(--text); text-decoration: none; padding: 0.25rem 0.5rem 0.9rem; }
.mainnav { display: flex; flex-direction: column; gap: 2px; }
.mainnav a, .side-projects a {
  display: flex; align-items: center; gap: 0.5rem; justify-content: space-between;
  padding: 0.5rem 0.6rem; border-radius: 8px; color: var(--text); text-decoration: none; min-height: 2.4rem;
}
.mainnav a:hover, .side-projects a:hover { background: var(--surface-2); }
.mainnav a.on, .side-projects a.on { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.side-title { display: flex; align-items: center; justify-content: space-between; margin-top: 1.1rem; padding: 0 0.3rem 0 0.6rem; font-size: 0.78rem; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.side-projects { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.side-projects a { justify-content: flex-start; }
.side-projects .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 0.65rem; height: 0.65rem; border-radius: 50%; background: var(--c, var(--accent)); flex: none; }
.side-footer { margin-top: auto; padding-top: 1rem; display: flex; flex-direction: column; gap: 0.6rem; align-items: flex-start; }
.side-footer select { min-height: 2.1rem; padding-block: 0.2rem; }
.sync-status { font-size: 0.82rem; color: var(--muted); padding-left: 1.1rem; position: relative; }
.sync-status::before, .sync-dot {
  content: ""; width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--accent);
}
.sync-status::before { position: absolute; left: 0.2rem; top: 0.42rem; }
.sync-status[data-state="offline"]::before, .sync-dot[data-state="offline"] { background: var(--danger); }
.sync-status[data-state="syncing"]::before, .sync-dot[data-state="syncing"] { background: var(--warn); }

#main { min-width: 0; padding: 1.25rem clamp(1rem, 4vw, 2.5rem) 4rem; }
#main > * { max-width: 50rem; margin-inline: auto; }
#topbar { display: none; }
#bottomnav { display: none; }

/* ---------- Schnellerfassung ---------- */

.capture {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 0.6rem; box-shadow: var(--shadow); position: sticky; top: 0.75rem; z-index: 5;
}
.capture:focus-within { border-color: var(--accent); }
.cap-row { display: flex; gap: 0.5rem; align-items: flex-start; }
#cap-text { border: 0; background: transparent; resize: none; min-height: 2.75rem; padding: 0.6rem 0.5rem; font-size: 1.05rem; overflow-y: auto; }
#cap-text:focus { outline: none; }
.mic {
  flex: none; width: 2.75rem; height: 2.75rem; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); cursor: pointer; display: grid; place-items: center;
}
.mic:hover { border-color: var(--accent); color: var(--accent); }
.mic.on { background: var(--danger); border-color: var(--danger); color: #fff; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--danger) 22%, transparent); } }
.cap-details { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; align-items: center; padding: 0.5rem 0.25rem 0.15rem; border-top: 1px solid var(--line); margin-top: 0.4rem; }
.capture:not(.open):not(.has-text):not(.listening) .cap-details { display: none; }
.cap-details select, .cap-details input { min-height: 2.25rem; padding-block: 0.25rem; }
.cap-message { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; flex: 1 1 100%; }
#cap-save { margin-left: auto; }

.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.segmented label { cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: 0.35rem 0.7rem; font-size: 0.9rem; border-right: 1px solid var(--line); }
.segmented label:last-child span { border-right: 0; }
.segmented input:checked + span { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---------- Ansichten ---------- */

#view { outline: none; padding-top: 1.5rem; }
.view { display: flex; flex-direction: column; gap: 1.25rem; }
.view-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.6rem 1rem; }
.view-head .actions { display: flex; gap: 0.5rem; }
.lead { color: var(--muted); max-width: 65ch; }
.project-title { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.project-title .dot { width: 0.9rem; height: 0.9rem; }
.group { display: flex; flex-direction: column; gap: 0.6rem; }
.group.overdue h2 { color: var(--danger); }
details.group > summary { cursor: pointer; color: var(--muted); font-size: 0.95rem; padding: 0.3rem 0; }
details.group[open] > summary { margin-bottom: 0.5rem; }
.empty { color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 1rem; }
.filters { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.search-input { width: 100%; font-size: 1.05rem; }
.results { display: flex; flex-direction: column; gap: 1.25rem; }

.entries { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.entries > li + li { border-top: 1px solid var(--line); }
.entry { display: flex; gap: 0.7rem; align-items: flex-start; padding: 0.65rem 0.8rem; }
.entry-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.3rem; }
.entry-text {
  all: unset; cursor: pointer; display: block; width: 100%;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.entry-text:hover { color: var(--accent); }
.entry-text:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.entry.done .entry-text { color: var(--muted); text-decoration: line-through; }
.meta { display: flex; flex-wrap: wrap; gap: 0.3rem 0.5rem; align-items: center; font-size: 0.82rem; color: var(--muted); }
.meta:empty { display: none; }
.meta-link { all: unset; cursor: pointer; color: var(--accent); text-decoration: underline; text-underline-offset: 2px; overflow-wrap: anywhere; }
.meta-link.done { color: var(--muted); }
.meta-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.time { font-variant-numeric: tabular-nums; margin-left: auto; white-space: nowrap; }
.check {
  flex: none; width: 1.6rem; height: 1.6rem; margin-top: 0.05rem; border-radius: 50%;
  border: 2px solid var(--muted); background: transparent; cursor: pointer;
  display: grid; place-items: center; font-size: 0.9rem; font-weight: 700; color: var(--accent-text); padding: 0;
}
.check:hover { border-color: var(--accent); }
.check[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.marker { flex: none; width: 1.6rem; height: 1.6rem; display: grid; place-items: center; }
.marker::before { content: ""; width: 0.55rem; height: 0.55rem; border-radius: 2px; background: var(--muted); }
.type-message .marker::before { background: var(--accent); border-radius: 50%; }
.type-decision .marker::before { background: var(--warn); transform: rotate(45deg); }
.assign select { min-height: 2.1rem; padding-block: 0.2rem; font-size: 0.88rem; }

.event { display: flex; gap: 0.7rem; align-items: center; padding: 0.4rem 0.8rem; font-size: 0.88rem; color: var(--muted); background: var(--surface-2); }
.event-mark { flex: none; width: 1.6rem; text-align: center; font-weight: 700; }
.kind-task-done .event-mark { color: var(--accent); }
.event-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }

.trail { display: flex; flex-direction: column; gap: 1.1rem; }
.trail-day { display: flex; flex-direction: column; gap: 0.4rem; }

.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 0.75rem; }
.project-card {
  display: flex; flex-direction: column; gap: 0.3rem; padding: 0.9rem 1rem;
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--c);
  border-radius: var(--radius); color: var(--text); text-decoration: none;
}
.project-card:hover { border-color: var(--c); }
.project-card .desc { color: var(--muted); font-size: 0.9rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- Dialog, Hinweis ---------- */

dialog {
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--text);
  padding: 0; width: min(38rem, calc(100vw - 1.5rem)); box-shadow: 0 20px 50px rgb(0 0 0 / 25%);
}
dialog::backdrop { background: rgb(0 0 0 / 45%); }
.dialog-form { display: flex; flex-direction: column; gap: 0.9rem; padding: 1.25rem; }
.dialog-form h2 { font-size: 1.15rem; }
.form-row { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.form-row .field { flex: 1 1 9rem; }
.form-row .field.grow { flex-basis: 100%; }
.form-row select, .form-row input, .dialog-form .field > input { width: 100%; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.spacer { flex: 1; }
.swatches { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.swatches label { cursor: pointer; }
.swatches input { position: absolute; opacity: 0; }
.swatches span { display: block; width: 2rem; height: 2rem; border-radius: 50%; background: var(--c); border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--line); }
.swatches input:checked + span { box-shadow: 0 0 0 3px var(--text); }
.swatches input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 4px; }

#toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translate(-50%, 1rem);
  background: var(--text); color: var(--bg); padding: 0.6rem 1rem; border-radius: 999px;
  font-size: 0.9rem; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 50;
  max-width: calc(100vw - 2rem); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Schmale Bildschirme (Smartphone) ---------- */

@media (max-width: 860px) {
  #app { display: block; }
  #sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(19rem, 86vw); z-index: 30;
    transform: translateX(-100%); transition: transform 0.2s; box-shadow: var(--shadow);
    padding-top: calc(1rem + env(safe-area-inset-top));
  }
  #app.menu-open #sidebar { transform: none; }
  #main { padding: 0 0.75rem calc(5.5rem + env(safe-area-inset-bottom)); }
  #topbar {
    display: flex; align-items: center; gap: 0.6rem;
    padding: calc(0.6rem + env(safe-area-inset-top)) 0.25rem 0.5rem;
  }
  #topbar-title { font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sync-dot { display: inline-block; flex: none; }
  #menu-btn { margin-left: auto; }
  .capture { top: 0.5rem; }
  #view { padding-top: 1rem; }
  .view > h1, .view-head > h1:not(.project-title) { display: none; }
  .time { margin-left: 0; }
  #bottomnav {
    display: grid; grid-template-columns: repeat(4, 1fr);
    position: fixed; inset: auto 0 0 0; z-index: 20;
    background: var(--surface); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  #bottomnav a {
    display: flex; align-items: center; justify-content: center; gap: 0.35rem;
    min-height: 3.4rem; color: var(--muted); text-decoration: none; font-size: 0.88rem;
  }
  #bottomnav a.on { color: var(--accent); font-weight: 650; box-shadow: inset 0 2px 0 var(--accent); }
  #toast { bottom: calc(4.5rem + env(safe-area-inset-bottom)); }
  .cap-details { gap: 0.5rem; }
  .segmented { width: 100%; }
  .segmented label { flex: 1; text-align: center; }
  .segmented span { padding-inline: 0.3rem; }
}

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