:root {
  --bg: #f3f5f7;
  --card: #fff;
  --side: #fafbfc;
  --text: #1c2329;
  --muted: #6b7680;
  --line: #e2e6ea;
  --hover: #eef2f5;
  --accent: #0b84c6;
  --accent-soft: #e3f2fb;
  --accent-text: #fff;
  --danger: #c62828;
  --star: #f5a623;
  --bar-h: 52px;
  --side-w: 290px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121518;
    --card: #1c2126;
    --side: #171b1f;
    --text: #e6eaee;
    --muted: #8d98a3;
    --line: #2b3238;
    --hover: #232a30;
    --accent: #3aa6e0;
    --accent-soft: #1b3443;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
a { color: var(--accent); }

/* ---------- Kopfzeile ---------- */
#bar {
  position: sticky; top: 0; z-index: 15;
  display: flex; align-items: center; gap: 2px;
  min-height: calc(var(--bar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 6px 0;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
#bar h1 { flex: 1; min-width: 0; margin: 0 8px; font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { font-size: 12px; color: var(--muted); white-space: nowrap; }
.bar-actions { display: flex; align-items: center; gap: 2px; }
.icon-btn { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; flex: none; }
.icon-btn:hover, .text-btn:hover { background: var(--hover); }
.icon-btn.on { color: var(--star); }
.icon-btn.on svg { fill: currentColor; }
.text-btn { padding: 8px 10px; border-radius: 10px; color: var(--accent); }
.primary { padding: 9px 16px; border-radius: 10px; background: var(--accent); color: var(--accent-text); font-weight: 600; }
.primary:disabled { opacity: .5; }
.danger-btn { padding: 9px 16px; border-radius: 10px; background: var(--danger); color: #fff; font-weight: 600; }
.ghost { padding: 9px 14px; border-radius: 10px; background: var(--hover); }

/* ---------- Grundlayout ---------- */
#shell { display: flex; min-height: calc(100vh - var(--bar-h)); }
#side {
  width: var(--side-w); flex: none;
  background: var(--side); border-right: 1px solid var(--line);
  padding: 10px 8px calc(20px + env(safe-area-inset-bottom));
  position: sticky; top: calc(var(--bar-h) + env(safe-area-inset-top));
  height: calc(100vh - var(--bar-h) - env(safe-area-inset-top)); overflow-y: auto;
}
#backdrop { display: none; }
main { flex: 1; min-width: 0; padding: 12px 14px calc(30px + env(safe-area-inset-bottom)); }
main > * { max-width: 860px; margin-left: auto; margin-right: auto; }

@media (max-width: 899px) {
  #side {
    position: fixed; left: 0; top: 0; bottom: 0; height: auto; z-index: 30;
    padding-top: calc(10px + env(safe-area-inset-top));
    transform: translateX(-105%); transition: transform .2s ease; box-shadow: 4px 0 20px rgba(0,0,0,.15);
  }
  body.drawer #side { transform: none; }
  body.drawer #backdrop { display: block; position: fixed; inset: 0; z-index: 25; background: rgba(0,0,0,.35); }
  main { padding-left: 10px; padding-right: 10px; }
}
@media (min-width: 900px) {
  #menu { display: none; }
  body.no-side #side { display: none; }
}
body.no-side #menu { display: none; }

/* ---------- Seitenleiste ---------- */
.side-search { display: flex; gap: 6px; margin: 2px 4px 10px; }
.side-search input { flex: 1; min-width: 0; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); }
.side-new { display: flex; width: calc(100% - 8px); margin: 0 4px 10px; justify-content: center; gap: 6px; align-items: center; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border-radius: 10px; color: var(--text); text-decoration: none; font-size: 15px;
}
.nav-item:hover { background: var(--hover); }
.nav-item.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .lbl { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-item .cnt { font-size: 13px; color: var(--muted); }
.nav-item svg { width: 19px; height: 19px; color: var(--muted); }
.nav-item.on svg { color: var(--accent); }
.nav-row { display: flex; align-items: center; }
.nav-row .nav-item { flex: 1; min-width: 0; }
.nav-row .more { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; color: var(--muted); opacity: .7; }
.nav-row .more:hover { background: var(--hover); opacity: 1; }
.nav-row .more svg { width: 18px; height: 18px; }
.nav-sub { padding-left: 18px; }
.nav-head {
  display: flex; align-items: center; margin: 14px 4px 4px 10px;
  font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600;
}
.nav-head span { flex: 1; }
.nav-head button { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; color: var(--muted); }
.nav-head button:hover { background: var(--hover); }
.nav-head button svg { width: 18px; height: 18px; }
.caret { transition: transform .15s; }
.collapsed .caret { transform: rotate(-90deg); }
.side-foot { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 8px; }

/* ---------- Karten / Listen ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; }
.login { max-width: 380px; margin: 10vh auto 0; padding: 20px; display: grid; gap: 14px; }
.login .lead { margin: 0; color: var(--muted); }
label.field { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.field input, .field select, .field textarea, input.text, select.text {
  padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); width: 100%;
}
.field textarea { min-height: 80px; resize: vertical; }
.error { margin: 0; color: var(--danger); font-size: 14px; }

.list-head { display: flex; align-items: center; gap: 8px; margin: 4px 2px 10px; flex-wrap: wrap; }
.list-head h2 { margin: 0; font-size: 20px; flex: 1; min-width: 0; }
.list-head .sub { color: var(--muted); font-size: 14px; }
.list { list-style: none; margin: 0; padding: 0; overflow: hidden; }
.list > li + li { border-top: 1px solid var(--line); }
.list a.row, .list .row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; color: inherit; text-decoration: none; }
.list a.row:hover { background: var(--hover); }
.list .grow { flex: 1; min-width: 0; }
.list .t { display: block; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .s { display: block; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .b { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 14px; color: var(--muted); margin-top: 2px; white-space: pre-line; }
.list img.th { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; background: var(--line); flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; background: var(--hover); font-size: 12px; color: var(--muted); }
.chip button { padding: 0; line-height: 1; color: var(--muted); font-size: 15px; }
.empty { padding: 34px 20px; text-align: center; color: var(--muted); }
.hint { color: var(--muted); font-size: 14px; }
.row-actions { display: flex; gap: 6px; flex: none; }
.small-btn { padding: 6px 10px; border-radius: 8px; background: var(--hover); font-size: 14px; }
.small-btn.danger { color: var(--danger); }
select.sort { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); font-size: 14px; }

/* ---------- Notiz-Editor ---------- */
.note-wrap { display: grid; gap: 10px; }
.note-title {
  width: 100%; border: 0; background: transparent; font-size: 24px; font-weight: 700; padding: 4px 2px; outline: none;
}
.note-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.note-meta select { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); max-width: 220px; }
.tag-input { border: 1px dashed var(--line); border-radius: 999px; padding: 3px 10px; background: transparent; font-size: 13px; width: 120px; }
.toolbar {
  position: sticky; top: calc(var(--bar-h) + env(safe-area-inset-top)); z-index: 5;
  display: flex; gap: 2px; flex-wrap: wrap; align-items: center;
  padding: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
}
.toolbar button, .toolbar label.tb { display: grid; place-items: center; min-width: 36px; height: 36px; border-radius: 8px; padding: 0 6px; cursor: pointer; }
.toolbar button:hover, .toolbar label.tb:hover { background: var(--hover); }
.toolbar svg { width: 19px; height: 19px; }
.toolbar .sep { width: 1px; height: 22px; background: var(--line); margin: 0 3px; }
.toolbar select { height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); padding: 0 6px; }
.toolbar input[type=color] { width: 0; height: 0; opacity: 0; position: absolute; }
.tb-letter { font-weight: 700; font-size: 16px; }
.color-dot { width: 16px; height: 16px; border-radius: 4px; border: 1px solid var(--line); }

.note-body {
  min-height: 50vh; padding: 16px 18px; outline: none; overflow-wrap: anywhere;
  font-size: 16px; line-height: 1.55;
}
.note-body:empty::before { content: "Text eingeben …"; color: var(--muted); }
.note-body img { max-width: 100%; height: auto; border-radius: 4px; }
.note-body img.syno-notestation-image-object { cursor: pointer; }
.note-body img.syno-notestation-image-object:hover { outline: 3px solid var(--accent-soft); }
.note-body table { border-collapse: collapse; max-width: 100%; }
.note-body td, .note-body th { border: 1px solid var(--line); padding: 4px 6px; }
.note-body input.syno-notestation-editor-checkbox { width: 18px; height: 18px; vertical-align: -3px; margin: 0 6px 0 0; cursor: pointer; }
.note-body blockquote { border-left: 3px solid var(--line); margin: 6px 0; padding-left: 12px; color: var(--muted); }
.note-body pre { background: var(--hover); padding: 10px; border-radius: 8px; overflow-x: auto; }
.note-body[contenteditable=false] { cursor: default; }
.section-title { margin: 18px 2px 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.att-ico { width: 40px; height: 40px; border-radius: 8px; background: var(--hover); display: grid; place-items: center; font-size: 11px; font-weight: 700; color: var(--muted); flex: none; text-transform: uppercase; }
.locked { padding: 30px; text-align: center; }

/* ---------- To-dos ---------- */
.todo-add { display: flex; gap: 8px; margin-bottom: 12px; }
.todo-add input { flex: 1; }
.todo { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.todo .chk { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--muted); flex: none; display: grid; place-items: center; }
.todo.done .chk { background: var(--accent); border-color: var(--accent); color: #fff; }
.todo.done .chk svg { width: 14px; height: 14px; stroke-width: 3; }
.todo.done .t { text-decoration: line-through; color: var(--muted); }
.todo .grow { cursor: pointer; }
.todo .due.over { color: var(--danger); font-weight: 600; }
.prio { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px; color: #fff; }
.prio.p300 { background: #e53935; } .prio.p200 { background: #fb8c00; } .prio.p100 { background: #43a047; }
.seg { display: inline-flex; background: var(--hover); border-radius: 10px; padding: 3px; }
.seg button { padding: 6px 12px; border-radius: 8px; font-size: 14px; }
.seg button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }

/* ---------- Dialoge ---------- */
#modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: end center; background: rgba(0,0,0,.4); padding: 10px; }
@media (min-width: 600px) { #modal { place-items: center; } }
.dlg { width: 100%; max-width: 440px; max-height: 85vh; overflow-y: auto; padding: 18px; display: grid; gap: 12px; margin-bottom: env(safe-area-inset-bottom); }
.dlg h3 { margin: 0; font-size: 18px; }
.dlg .btns { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.sheet { width: 100%; max-width: 440px; padding: 6px; margin-bottom: env(safe-area-inset-bottom); }
.sheet .sheet-title { padding: 10px 14px 6px; font-size: 13px; color: var(--muted); }
.sheet button { display: block; width: 100%; text-align: left; padding: 13px 14px; border-radius: 10px; font-size: 16px; }
.sheet button:hover { background: var(--hover); }
.sheet button.danger { color: var(--danger); }
.sheet button.cancel { text-align: center; color: var(--muted); }

#toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  max-width: 90vw; padding: 10px 16px; border-radius: 12px; background: #222; color: #fff; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Zeichen-Editor ---------- */
#editor { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; background: #2a2d31; }
.ed-stage { position: relative; flex: 1; overflow: hidden; touch-action: none; }
.ed-canvas-wrap { position: absolute; left: 0; top: 0; transform-origin: 0 0; box-shadow: 0 0 0 1px rgba(255,255,255,.15); }
.ed-canvas-wrap canvas { position: absolute; left: 0; top: 0; width: 100%; height: 100%; }
#ed-live { opacity: .35; }
.ed-tools {
  order: -1; background: var(--card); border-bottom: 1px solid var(--line);
  padding: max(6px, env(safe-area-inset-top)) 8px 6px;
}
.ed-row { display: flex; align-items: center; gap: 4px; }
.ed-row + .ed-row { margin-top: 4px; }
.ed-palette { flex-wrap: wrap; justify-content: center; row-gap: 6px; }
.ed-spacer { flex: 1; }
.ed-sep { width: 1px; height: 26px; background: var(--line); margin: 0 4px; flex: none; }
.tool { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; flex: none; }
.tool.on { background: var(--accent); color: var(--accent-text); }
.swatch { width: 30px; height: 30px; border-radius: 50%; flex: none; background: var(--c); border: 2px solid var(--line); margin: 0 2px; }
.swatch.on { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--accent); }
.size { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; flex: none; }
.size i { display: block; width: var(--s); height: var(--s); border-radius: 50%; background: currentColor; }
.size.on { background: var(--line); }
.ed-busy { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.45); color: #fff; font-weight: 600; }

/* Deploy-Dialog */
.code { width: 100%; box-sizing: border-box; font: 12px/1.4 ui-monospace, Consolas, monospace; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px; white-space: pre-wrap; word-break: break-all; margin: 0; max-height: 220px; overflow: auto; resize: none; color: inherit; }
.note-body img.uploading { opacity: .55; outline: 2px dashed var(--accent); outline-offset: 2px; }

/* Direkt in der Notiz zeichnen (Test A + B) */
.ink-host { position: relative; }
.ink-layer { position: absolute; left: 0; top: 0; width: 100%; height: auto; pointer-events: none; z-index: 2; }
.ink-layer.ink-active { pointer-events: auto; outline: 2px dashed var(--accent); outline-offset: -2px; border-radius: 14px; }
.ink-block { position: relative; margin: 8px 0; border-radius: 6px; overflow: hidden; background: #fff; outline: 2px solid var(--accent); }
.ink-block > canvas:first-child { display: block; width: 100%; height: auto;
  background-image: radial-gradient(circle, #c9d3da 1px, transparent 1.2px); background-size: 22px 22px; }
.ink-block > img { display: none; }
.ink-live { position: absolute; left: 0; top: 0; width: 100%; height: auto; pointer-events: none; opacity: .35; z-index: 3; }
.ink-active { cursor: crosshair; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.note-body img.skz-layer { display: none; }
.note-body p[contenteditable=false]:has(> img.skz-layer) { display: none; }
.note-body img.ink-saving { opacity: .8; outline: 2px dashed var(--accent); outline-offset: 2px; }
.ink-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: 4px; row-gap: 6px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px rgba(0,0,0,.12); }
.ink-bar[hidden] { display: none; }
.ink-bar .tool:disabled { opacity: .35; }
body.inking #view { padding-bottom: 160px; }
