:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #ebe9e3;
  --text: #1c1b19;
  --muted: #6b6862;
  --line: #e0ddd5;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #d6efec;
  --danger: #b42318;
  --warn: #b45309;
  --ok: #15803d;
  --mark: #fde68a;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 10px rgba(0,0,0,.05);
  --r: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111315;
    --surface: #1b1e21;
    --surface-2: #262a2e;
    --text: #ecebe8;
    --muted: #9b998f;
    --line: #2d3136;
    --accent: #2dd4bf;
    --accent-ink: #052421;
    --accent-soft: #123b37;
    --danger: #f97066;
    --warn: #f5a524;
    --ok: #4ade80;
    --mark: #6b5a12;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg .fill { fill: currentColor; stroke: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.icon {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; border: 0; border-radius: 12px;
  background: transparent; color: var(--text);
}
.icon:active { background: var(--surface-2); }
.icon.small { width: 32px; height: 32px; }
.icon.small svg { width: 18px; height: 18px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn:active { filter: brightness(.95); }

/* ---------- Kopfbereich ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: calc(8px + var(--safe-t)) 12px 4px;
  border-bottom: 1px solid var(--line);
}
.searchrow { display: flex; align-items: center; gap: 4px; max-width: 760px; margin: 0 auto; }
.search {
  flex: 1; display: flex; align-items: center; gap: 8px;
  height: 48px; padding: 0 6px 0 14px; border-radius: 24px;
  background: var(--surface); border: 1px solid var(--line);
}
.search svg { width: 20px; height: 20px; color: var(--muted); }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 16px; height: 100%; }
.search input::-webkit-search-cancel-button { display: none; }
.search:focus-within { border-color: var(--accent); }

.syncbtn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 10px; border: 0; border-radius: 18px;
  background: transparent; color: var(--muted); font-size: 13px; white-space: nowrap;
}
.syncbtn .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); }
.syncbtn.pending .dot, .syncbtn.offline .dot { background: var(--warn); }
.syncbtn.offline { color: var(--warn); }
.syncbtn.syncing .dot { background: var(--accent); animation: pulse 1s infinite ease-in-out; }
@keyframes pulse { 50% { opacity: .3; } }

.chips {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  max-width: 760px; margin: 10px auto 0; padding: 0 2px 2px;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  --g: var(--muted);
  flex: none; display: inline-flex; align-items: center; gap: 7px;
  height: 38px; padding: 0 14px; border-radius: 19px;
  border: 1px solid var(--line); background: var(--surface); font-size: 15px; white-space: nowrap;
}
.chip .gdot { width: 10px; height: 10px; border-radius: 50%; background: var(--g); }
.chip .cnt { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip.on .cnt { color: inherit; opacity: .7; }
.chip.add { color: var(--accent); border-style: dashed; }

.filters { display: flex; gap: 18px; flex-wrap: wrap; max-width: 760px; margin: 6px auto 0; }
.toggle { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; font-size: 14px; color: var(--muted); cursor: pointer; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }

/* ---------- Liste ---------- */
main { max-width: 760px; margin: 0 auto; padding: 10px 12px calc(110px + var(--safe-b)); }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.note {
  display: flex; align-items: flex-start; gap: 2px;
  background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow);
  border: 1px solid var(--line);
  padding: 4px 14px 4px 4px;
}
.chk {
  flex: none; display: grid; place-items: center;
  width: 48px; height: 52px; border: 0; background: transparent; padding: 0;
}
.chk::before {
  content: ""; grid-area: 1/1; width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--muted); transition: background .15s, border-color .15s;
}
.chk svg { grid-area: 1/1; width: 16px; height: 16px; stroke-width: 3; color: var(--accent-ink); opacity: 0; }
.s-done .chk::before { background: var(--ok); border-color: var(--ok); }
.s-done .chk svg { opacity: 1; color: var(--surface); }
.chk.arch::before { display: none; }
.chk.arch svg { opacity: 1; color: var(--muted); width: 20px; height: 20px; stroke-width: 2; }

.nmain { flex: 1; min-width: 0; padding: 12px 0 10px; cursor: pointer; }
.nt { font-weight: 600; font-size: 17px; overflow-wrap: anywhere; }
.ns {
  color: var(--muted); font-size: 15px; margin-top: 2px; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.nm { display: flex; align-items: center; gap: 10px; margin-top: 6px; font-size: 13px; color: var(--muted); }
.gt { --g: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
.gt::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--g); }
.nm .pend { color: var(--warn); }
.nm .pend svg { width: 15px; height: 15px; vertical-align: -3px; }
.s-done .nt { text-decoration: line-through; color: var(--muted); font-weight: 500; }
.s-archived { opacity: .78; }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }

.sec { font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); padding: 6px 4px 0; }
.sec-arch { margin-top: 26px; padding-top: 16px; border-top: 2px dashed var(--line); }
.sec-hint button { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 8px 4px; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty strong { display: block; color: var(--text); font-size: 18px; margin-bottom: 6px; }

/* ---------- Neue-Notiz-Knopf ---------- */
.fab {
  position: fixed; z-index: 6;
  right: max(18px, calc((100vw - 760px) / 2 + 18px));
  bottom: calc(20px + var(--safe-b));
  display: inline-flex; align-items: center; gap: 8px;
  height: 64px; padding: 0 26px 0 20px; border: 0; border-radius: 32px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 18px; font-weight: 700;
  box-shadow: 0 6px 20px rgba(0,0,0,.22);
}
.fab svg { width: 28px; height: 28px; stroke-width: 2.6; }
.fab:active { transform: scale(.97); }

/* ---------- Editor ---------- */
.editor {
  position: fixed; inset: 0; z-index: 20;
  display: flex; flex-direction: column;
  background: var(--bg);
  padding: var(--safe-t) 0 var(--safe-b);
}
.editor > * { width: 100%; max-width: 760px; margin-left: auto; margin-right: auto; }
.ebar { display: flex; align-items: center; gap: 4px; padding: 6px 6px 0; }
.saved { flex: 1; text-align: center; color: var(--muted); font-size: 13px; }
.eopts { display: flex; flex-wrap: wrap; gap: 8px; padding: 6px 14px 8px; }
.eopts select, .newg input {
  height: 40px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); font-size: 15px; max-width: 100%;
}
.eopts select { flex: 1 1 140px; min-width: 0; }
.newg { flex: 1 1 220px; display: flex; gap: 6px; }
.newg input { flex: 1; min-width: 0; }
.newg .btn { min-height: 40px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); flex: none; }
.seg button { border: 0; background: transparent; height: 38px; padding: 0 12px; font-size: 14px; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-checked="true"] { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.seg button[data-st="done"][aria-checked="true"] { color: var(--ok); }

.etitle, .etext { border: 0; outline: 0; background: transparent; padding: 0 16px; }
.etitle { font-size: 22px; font-weight: 700; height: 48px; flex: none; }
.etext { flex: 1; min-height: 96px; resize: none; font-size: 17px; line-height: 1.5; padding-top: 6px; padding-bottom: 8px; }
.etitle::placeholder, .etext::placeholder { color: var(--muted); opacity: .7; }
.emeta { font-size: 12px; color: var(--muted); padding: 2px 16px 6px; }
.efoot { display: flex; gap: 10px; padding: 8px 12px 10px; border-top: 1px solid var(--line); }
.efoot .primary { flex: 1; font-size: 17px; min-height: 52px; }
.efoot .mic { min-height: 52px; }
.mic.rec { background: var(--danger); color: #fff; border-color: var(--danger); }
.mic.rec svg { animation: pulse 1s infinite; }
body.editing { overflow: hidden; }
body.editing .fab { display: none; }

/* ---------- Bottom Sheet ---------- */
.sheet { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.scrim { position: absolute; inset: 0; background: rgba(0,0,0,.4); }
.panel {
  position: relative; width: 100%; max-width: 560px; max-height: 88dvh; overflow: auto;
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 6px 16px calc(18px + var(--safe-b));
}
@media (min-width: 700px) {
  .sheet { align-items: center; }
  .panel { border-radius: 20px; }
}
.phead { display: flex; align-items: center; justify-content: space-between; }
.phead h2 { font-size: 18px; margin: 10px 4px; }
.menu { display: flex; flex-direction: column; }
.menu button {
  display: flex; align-items: center; gap: 14px; text-align: left;
  min-height: 54px; padding: 0 6px; border: 0; background: none; font-size: 16px; border-radius: 10px;
}
.menu button:active { background: var(--surface-2); }
.menu svg { color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; margin: 14px 4px 0; }

.glist { list-style: none; margin: 0 0 12px; padding: 0; }
.glist li { display: flex; align-items: center; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.gsw { --g: var(--muted); width: 44px; height: 44px; border: 0; background: none; display: grid; place-items: center; }
.gsw::before { content: ""; width: 22px; height: 22px; border-radius: 50%; background: var(--g); }
.gname { flex: 1; min-width: 0; height: 44px; border: 0; background: transparent; font-size: 16px; padding: 0 4px; border-radius: 8px; }
.gname:focus { background: var(--surface-2); outline: 0; }
.gc { color: var(--muted); font-size: 13px; min-width: 2ch; text-align: right; }
.gdel { color: var(--danger); }
.gdel.armed { width: auto; padding: 0 12px; background: var(--danger); color: #fff; font-weight: 600; font-size: 14px; }
.gadd { display: flex; gap: 8px; }
.gadd input { flex: 1; min-width: 0; height: 48px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); font-size: 16px; }

/* ---------- Login ---------- */
.login { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: grid; place-items: center; padding: 24px; }
.login .card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; align-items: stretch; text-align: center; }
.login img { align-self: center; border-radius: 14px; }
.login h1 { margin: 0 0 8px; font-size: 24px; }
.login input { height: 52px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 17px; }
.err { color: var(--danger); margin: 0; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; z-index: 50; left: 50%; transform: translateX(-50%);
  bottom: calc(96px + var(--safe-b));
  display: flex; align-items: center; gap: 14px;
  max-width: calc(100vw - 32px); padding: 8px 8px 8px 18px; min-height: 52px;
  background: #24272b; color: #f3f2ee; border-radius: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.3);
  font-size: 15px;
}
body.editing .toast { bottom: calc(84px + var(--safe-b)); }
.toast button { border: 0; background: none; color: #5eead4; font-weight: 700; min-height: 40px; padding: 0 12px; border-radius: 8px; }
.toast:not(:has(button)) { padding-right: 18px; }
