:root {
  --bg: #f6f5f1;
  --panel: #ffffff;
  --ink: #1f2522;
  --muted: #6b726d;
  --line: #e4e2dc;
  --soft: #f0efe9;
  --accent: #2f5d3a;
  --accent-ink: #ffffff;
  --danger: #c0392b;
  --new: #e8590c;
  --shadow: 0 8px 30px rgba(20, 30, 25, .18);
  --radius: 14px;
  --panel-w: 400px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141816;
    --panel: #1b201d;
    --ink: #e8ebe8;
    --muted: #9aa39d;
    --line: #2c332f;
    --soft: #232a26;
    --accent: #7fbf8e;
    --accent-ink: #10150f;
    --danger: #ff7b6b;
    --new: #ff922b;
    --shadow: 0 8px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141816; --panel: #1b201d; --ink: #e8ebe8; --muted: #9aa39d; --line: #2c332f;
  --soft: #232a26; --accent: #7fbf8e; --accent-ink: #10150f; --danger: #ff7b6b; --new: #ff922b;
  --shadow: 0 8px 30px rgba(0, 0, 0, .5); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
h1 { font-size: 1.35rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Anmeldung ---------- */
.login {
  min-height: 100%; display: grid; place-items: center; padding: 24px 16px;
  background: linear-gradient(160deg, #2f5d3a 0%, #557c46 55%, #a3a45a 100%);
}
.login-card {
  max-width: 380px; width: 100%; background: var(--panel); border-radius: 20px;
  padding: 32px 28px; text-align: center; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 1.6rem; }
.login-card p { margin: 8px 0 0; }
.login-icon { color: var(--accent); margin-bottom: 8px; }
#login-msg { margin-top: 20px; }
#login-msg.error { color: var(--danger); }

/* ---------- Layout ---------- */
.app { position: fixed; inset: 0; }
.map { position: absolute; inset: 0; background: #cfd8cf; }
.panel {
  position: absolute; z-index: 1000; background: var(--panel); box-shadow: var(--shadow);
  display: flex; flex-direction: column; overflow: hidden;
}
.view { overflow-y: auto; overscroll-behavior: contain; padding: 18px 18px 24px; flex: 1; }

@media (min-width: 900px) {
  .panel { top: 12px; left: 12px; bottom: 12px; width: var(--panel-w); border-radius: var(--radius); }
  .sheet-handle { display: none; }
  .leaflet-left { left: calc(var(--panel-w) + 12px); }
}
@media (max-width: 899px) {
  .panel {
    left: 0; right: 0; bottom: 0; height: 38vh; border-radius: 18px 18px 0 0;
    transition: height .25s ease; padding-bottom: env(safe-area-inset-bottom);
  }
  .panel.expanded { height: 82vh; }
  .panel.collapsed { height: 118px; }
  .sheet-handle {
    border: 0; background: transparent; padding: 8px 0 2px; width: 100%; flex: none;
  }
  .sheet-handle span { display: block; width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto; }
  .view { padding-top: 6px; }
  .leaflet-bottom { bottom: 38vh; transition: bottom .25s ease; }
  .app.sheet-expanded .leaflet-bottom { bottom: 82vh; }
  .app.sheet-collapsed .leaflet-bottom { bottom: 118px; }
  .leaflet-control-attribution { font-size: 9px; line-height: 1.25; max-width: 70vw; }
}

/* ---------- Liste ---------- */
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.panel-head p { margin: 2px 0 0; font-size: .9rem; }
.user { text-align: right; font-size: .85rem; line-height: 1.3; }
.user-name { display: block; font-weight: 600; }
.link-btn { background: none; border: 0; padding: 0; color: var(--muted); text-decoration: underline; font-size: .8rem; }

.search { position: relative; margin: 14px 0 10px; }
.search svg { position: absolute; left: 11px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%); color: var(--muted); }
.search input {
  width: 100%; font: inherit; color: var(--ink); background: var(--soft);
  border: 1px solid transparent; border-radius: 10px; padding: 10px 12px 10px 36px; font-size: 16px;
}
.search input:focus { outline: none; border-color: var(--accent); background: var(--panel); }

.filters { display: grid; gap: 8px; margin-bottom: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px;
  padding: 4px 11px; font-size: .85rem; display: inline-flex; align-items: center; gap: 6px;
}
.chip.on { background: var(--ink); color: var(--panel); border-color: var(--ink); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.colormode { display: flex; align-items: center; gap: 8px; font-size: .85rem; }
.seg { display: inline-flex; background: var(--soft); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: transparent; padding: 3px 10px; border-radius: 6px; font-size: .82rem; }
.seg button.on { background: var(--panel); box-shadow: 0 1px 3px rgba(0,0,0,.15); font-weight: 600; }

.note {
  font-size: .82rem; background: #fff4e0; color: #7a4a00; border-radius: 10px; padding: 8px 10px; margin: 0 0 10px;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .note { background: #3a2c12; color: #ffd38a; } }
:root[data-theme="dark"] .note { background: #3a2c12; color: #ffd38a; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { border-bottom: 1px solid var(--line); }
.list button {
  width: 100%; text-align: left; background: none; border: 0; padding: 10px 4px;
  display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: center;
}
.list button:hover { background: var(--soft); }
.list button.active { background: var(--soft); }
.nr-badge {
  width: 30px; height: 30px; border-radius: 50%; color: #fff; font-weight: 700; font-size: .85rem;
  display: grid; place-items: center; box-shadow: inset 0 0 0 2px rgba(255,255,255,.35);
}
.li-title { font-weight: 600; display: block; }
.li-sub { font-size: .82rem; color: var(--muted); display: block; }
.li-meta { text-align: right; font-size: .8rem; color: var(--muted); white-space: nowrap; }
.li-meta .cc { display: inline-flex; align-items: center; gap: 3px; }
.li-meta .new-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--new); display: inline-block; }
.empty { padding: 18px 4px; color: var(--muted); }
.attrib { font-size: .72rem; margin-top: 14px; }

/* ---------- Detail ---------- */
.detail-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.back { display: inline-flex; align-items: center; gap: 2px; border: 0; background: none; padding: 4px 0; color: var(--accent); font-weight: 600; }
.back svg { width: 20px; height: 20px; }
.prevnext button {
  width: 34px; height: 30px; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; font-size: 1.2rem; line-height: 1;
}
.d-head { display: flex; gap: 12px; align-items: center; }
.d-head .nr-badge { width: 42px; height: 42px; font-size: 1.05rem; }
.d-head h2 { font-size: 1.25rem; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 12px; }
.tag { font-size: .78rem; border-radius: 6px; padding: 2px 8px; background: var(--soft); display: inline-flex; align-items: center; gap: 5px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 0 0 14px; font-size: .9rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.hinweis { font-size: .88rem; background: var(--soft); border-left: 3px solid var(--accent); padding: 8px 10px; border-radius: 4px; margin: 0 0 14px; white-space: pre-wrap; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 18px; }
.actions a, .actions button {
  display: flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 10px; padding: 9px 8px; font-size: .88rem; font-weight: 500;
}
.actions .primary-link { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.actions svg { width: 18px; height: 18px; flex: none; }

.section-title { margin: 4px 0 10px; padding-top: 14px; border-top: 1px solid var(--line); }
.comments { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 12px; }
.comment { background: var(--soft); border-radius: 12px; padding: 10px 12px; }
.comment.is-new { box-shadow: inset 3px 0 0 var(--new); }
.c-head { display: flex; justify-content: space-between; gap: 8px; font-size: .8rem; color: var(--muted); margin-bottom: 4px; }
.c-head b { color: var(--ink); font-size: .88rem; }
.c-text { white-space: pre-wrap; word-wrap: break-word; }
.c-photos { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.c-photos button { border: 0; padding: 0; background: none; border-radius: 8px; overflow: hidden; }
.c-photos img { display: block; width: 96px; height: 96px; object-fit: cover; }
.c-del { border: 0; background: none; color: var(--muted); font-size: .78rem; text-decoration: underline; padding: 0; }
.no-comments { color: var(--muted); font-size: .9rem; }

.comment-form textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--ink); background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px; resize: vertical;
}
.comment-form textarea:focus { outline: none; border-color: var(--accent); }
.form-row { display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; }
.photo-btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; cursor: pointer; font-size: .9rem;
}
.photo-btn input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.photo-btn svg { width: 18px; height: 18px; }
.primary { border: 0; background: var(--accent); color: var(--accent-ink); border-radius: 10px; padding: 8px 20px; font-weight: 600; }
.primary:disabled { opacity: .55; cursor: default; }
.photo-preview { display: flex; gap: 6px; flex-wrap: wrap; }
.photo-preview:not(:empty) { margin-top: 8px; }
.photo-preview div { position: relative; }
.photo-preview img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; display: block; }
.photo-preview button {
  position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 0;
  background: var(--ink); color: var(--panel); font-size: 14px; line-height: 1;
}
.form-msg { font-size: .85rem; min-height: 1.2em; margin: 6px 0 0; }
.form-msg.error { color: var(--danger); }

/* ---------- Karte ---------- */
.nr-label {
  background: transparent; border: 0;
}
.nr-label span {
  display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  color: #fff; font: 700 12px/1 system-ui, sans-serif; border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.45); transition: transform .15s;
}
.nr-label.sel span { transform: scale(1.35); }
.zoom-far .nr-label span { width: 14px; height: 14px; font-size: 0; border-width: 2px; }
.zoom-far .nr-label.sel span { transform: scale(1.5); }

.alkis-on-photo { filter: invert(1) brightness(1.4); }

.leaflet-control.map-btn a {
  width: 34px; height: 34px; display: grid; place-items: center; color: #333; background: #fff;
}
.leaflet-control.map-btn a svg { width: 20px; height: 20px; }
.leaflet-control.map-btn a.active { color: #1971c2; }
.leaflet-control.map-btn a.busy svg { animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.leaflet-control-layers { font: inherit; font-size: .85rem; }

.me-dot {
  width: 18px; height: 18px; border-radius: 50%; background: #1c7ed6; border: 3px solid #fff;
  box-shadow: 0 0 0 2px rgba(28,126,214,.35), 0 1px 5px rgba(0,0,0,.4);
}

.leaflet-tooltip.parcel-tip { font: 600 12px system-ui, sans-serif; }

/* ---------- Toast & Lightbox ---------- */
.toast {
  position: absolute; z-index: 1100; left: 50%; top: 14px; transform: translateX(-50%);
  background: var(--ink); color: var(--panel); padding: 9px 16px; border-radius: 999px;
  font-size: .9rem; box-shadow: var(--shadow); max-width: calc(100% - 32px); text-align: center;
}
@media (min-width: 900px) { .toast { left: calc(50% + var(--panel-w) / 2); } }

.lightbox {
  position: fixed; inset: 0; z-index: 2000; background: rgba(0,0,0,.9);
  display: grid; place-items: center; padding: 16px;
}
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox-close {
  position: absolute; top: 10px; right: 14px; width: 44px; height: 44px; border: 0;
  background: rgba(255,255,255,.15); color: #fff; font-size: 28px; border-radius: 50%;
}
