:root {
  --bg: #f3f4f7;
  --panel: #ffffff;
  --card: #f8f9fb;
  --text: #1a1f29;
  --muted: #6b7280;
  --border: #e3e6eb;
  --accent: #d0261d;
  --accent-soft: #fdecea;
  --accent-text: #ffffff;
  --chip: #eef0f4;
  --focus: #2563eb;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 12px rgba(16,24,40,.06);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111418; --panel: #181c22; --card: #1f242c; --text: #e7eaf0; --muted: #98a1ae;
    --border: #2c323c; --chip: #262c35; --accent-soft: #3a1d1b;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 12px rgba(0,0,0,.25);
  }
}
:root[data-theme="dark"] {
  --bg: #111418; --panel: #181c22; --card: #1f242c; --text: #e7eaf0; --muted: #98a1ae;
  --border: #2c323c; --chip: #262c35; --accent-soft: #3a1d1b;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 12px rgba(0,0,0,.25);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
#app { display: flex; height: 100vh; height: 100dvh; }

/* ---------- Seitenleiste ---------- */
#sidebar { width: 400px; max-width: 100%; display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--border); overflow: hidden; z-index: 1001; box-shadow: 2px 0 12px rgba(0,0,0,.05); }
#search-ui, #no-search { flex: 1; overflow-y: auto; min-height: 0; }

.sheet-handle { display: none; }
.topbar { padding: 12px 14px 10px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 34px; height: 34px; border-radius: 10px; background: var(--accent); display: grid; place-items: center; font-size: 18px; flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; flex: 1; min-width: 0; }
.brand-text strong { font-size: 16px; }
.brand-text span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.search-select { width: 100%; font-weight: 600; }

.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 240px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 6px; z-index: 3000; }
.menu-item { display: block; width: 100%; text-align: left; background: none; border: none; padding: 9px 10px; border-radius: 7px; font-size: 13px; color: var(--text); cursor: pointer; margin: 0; }
.menu-item:hover { background: var(--chip); }
.menu-item.danger { color: #dc2626; }

.empty { padding: 40px 24px; text-align: center; color: var(--muted); }
.empty-icon { font-size: 44px; }
.empty h2 { color: var(--text); font-size: 17px; margin: 8px 0; }

.status-card { margin: 12px 14px 0; padding: 10px 12px; border-radius: var(--radius); background: linear-gradient(135deg, #fff7ed, #ffedd5); color: #7a3a00; border: 1px solid #fed7aa; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .id-pill { background: rgba(0,0,0,.3); } :root:not([data-theme="light"]) .status-card { background: linear-gradient(135deg, #2f2216, #3a2611); color: #ffd8a8; border-color: #5a3a14; } }
.status-head { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.id-pill { font-size: 13px; font-weight: 700; letter-spacing: .5px; background: rgba(255,255,255,.6); padding: 2px 8px; border-radius: 6px; user-select: all; color: inherit; }
.radius-info { font-size: 13px; }

/* Reiter */
.tabs { position: sticky; top: 0; z-index: 5; box-shadow: 0 -12px 0 var(--panel), 0 6px 10px -6px rgba(0,0,0,.15); display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin: 12px 14px 0; padding: 4px; background: var(--chip); border-radius: 12px; }
.tab { position: relative; display: flex; flex-direction: column; align-items: center; gap: 1px; border: none; background: none; padding: 6px 4px; border-radius: 9px; font-size: 16px; color: var(--muted); cursor: pointer; }
.tab span { font-size: 11px; font-weight: 600; }
.tab.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.badge { position: absolute; top: 2px; right: 6px; font-style: normal; font-size: 10px; font-weight: 700; background: var(--accent); color: #fff; border-radius: 8px; padding: 0 5px; line-height: 15px; }
.badge:empty { display: none; }

.panes { padding: 12px 14px 16px; }
.pane { display: none; }
.pane.active { display: block; animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }
.card h3 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.loc { font-size: 13px; padding: 4px 0; }

/* Formulare */
label { display: block; font-size: 12px; font-weight: 500; color: var(--muted); margin-top: 8px; }
label > input, label > select, label > textarea { display: block; width: 100%; margin-top: 3px; }
.lbl { display: block; font-size: 12px; font-weight: 500; color: var(--muted); margin-top: 8px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
textarea { resize: vertical; }
.row { display: flex; gap: 6px; align-items: center; margin-top: 8px; }
.row > input, .row > select { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 8px; margin-top: 4px; }
.grid2 > input, .grid2 > select { margin-top: 4px; min-width: 0; }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

label.switch { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 13px; cursor: pointer; }
label.switch input { display: none; }
label.switch span { width: 38px; height: 22px; border-radius: 11px; background: var(--border); position: relative; flex: none; transition: background .15s; }
label.switch span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
label.switch input:checked + span { background: #16a34a; }
label.switch input:checked + span::after { transform: translateX(16px); }

/* Buttons */
button { font: inherit; cursor: pointer; color: var(--text); }
.btn, .list button:not(.x), #area-detail button, #map-banner button, .leaflet-popup-content button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  color: var(--text); background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px; white-space: nowrap; text-decoration: none; font-size: 13px; font-weight: 500;
  transition: background .15s, transform .05s, box-shadow .15s;
}
.btn:hover, #area-detail button:hover { background: var(--chip); }
.btn:active { transform: translateY(1px); }
button:disabled, .btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn.primary-soft { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 700; }
.btn.primary-soft:hover { background: var(--accent-soft); filter: brightness(.97); }
.btn.accent-soft { background: #e8f5ec; color: #166534; border-color: #bbe5c8; font-weight: 600; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.accent-soft { background: #15301f; color: #9be2b3; border-color: #234d33; } }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--chip); color: var(--text); }
.btn.icon { width: 34px; height: 34px; padding: 0; font-size: 18px; }
.btn.sm { padding: 6px 10px; font-size: 12px; }
.btn.xs { padding: 3px 8px; font-size: 12px; }
.btn.block { width: 100%; margin-top: 8px; }
.btn.big { padding: 11px 14px; font-size: 15px; font-weight: 700; }
.btn.danger, #area-detail button.danger { color: #dc2626; }
.btn.active { outline: 2px solid var(--accent); }

/* Listen */
.list { list-style: none; margin: 8px 0 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 9px 10px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 6px; cursor: pointer; transition: box-shadow .15s, border-color .15s; }
.list li:hover { box-shadow: var(--shadow); }
.list li.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.list li .grow { flex: 1; min-width: 0; }
.list li .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list li .sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list li .x { background: none; border: none; color: var(--muted); padding: 4px 6px; border-radius: 6px; }
.list li .x:hover { background: var(--chip); color: #dc2626; }
.areano { display: inline-flex; min-width: 32px; height: 32px; align-items: center; justify-content: center; border-radius: 9px; color: #fff; font-weight: 800; flex: none; }
.chip { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11px; color: #fff; }
.overdue { color: #dc2626; font-weight: 600; }

/* Übersicht Suchgebiete */
.summary { display: flex; flex-wrap: wrap; gap: 5px; }
.sumchip { font-size: 12px; padding: 4px 10px; border-radius: 14px; border: 1px solid var(--border); background: var(--panel); color: var(--text); cursor: pointer; }
.sumchip b { color: var(--c); margin-left: 2px; }
.sumchip:hover { border-color: var(--c); }
.sumchip.on { background: var(--c); border-color: var(--c); color: #fff; }
.sumchip.on b { color: #fff; }
.progress { position: relative; width: 100%; height: 22px; border-radius: 11px; background: var(--chip); overflow: hidden; margin-top: 4px; }
.progress > div { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, #22c55e, #16a34a); opacity: .6; }
.progress > span { position: relative; font-size: 11px; font-weight: 600; padding-left: 10px; line-height: 22px; }
.toolbar-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; }
label.inline { display: flex; align-items: center; gap: 6px; margin: 0; }
label.inline > select { width: auto; display: inline-block; margin: 0; padding: 4px 8px; font-size: 12px; }
.list li.area-item { border-left: 5px solid var(--c); }
.list li.area-item.done { opacity: .6; }
.list li.group-head { cursor: default; background: transparent; border: none; box-shadow: none; padding: 10px 2px 4px; margin: 4px 0 0; font-weight: 700; font-size: 13px; border-bottom: 2px solid var(--border); border-radius: 0; }
.list li.group-head:hover { box-shadow: none; }
.merge-bar { position: sticky; top: 68px; z-index: 4; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; padding: 8px 10px; border-radius: 10px; background: #f3e8ff; color: #4c1d95; border: 1px solid #ddd6fe; font-size: 12px; font-weight: 600; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .merge-bar { background: #2e1a47; color: #e9d5ff; border-color: #4c2a7a; } }
.list li.picked { border-color: #7c3aed; box-shadow: 0 0 0 2px #ddd6fe; }
.list li .pick { width: 18px; height: 18px; margin: 0; accent-color: #7c3aed; pointer-events: none; }
.status-select { font-size: 11px; padding: 4px 6px; max-width: 124px; border-radius: 7px; }

/* Detail Suchgebiet */
#area-detail .detail-head { position: sticky; top: 64px; z-index: 4; display: flex; align-items: center; gap: 10px; margin: -4px -2px 10px; padding: 6px 2px; background: var(--panel); }
#area-detail h3 { margin: 0; font-size: 18px; display: flex; align-items: center; gap: 8px; flex: 1; }
#area-detail .kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; margin: 0; }
#area-detail .kv dt { color: var(--muted); }
#area-detail .kv dd { margin: 0; }
#area-detail .btns { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; }
#area-detail .btns .wide { grid-column: span 2; }
.transit { font-size: 12px; }
.transit ul { margin: 2px 0 6px; padding-left: 18px; }

/* Fußzeile */
#sidebar-footer { padding: 10px 14px 12px; border-top: 1px solid var(--border); background: var(--panel); box-shadow: 0 -4px 12px rgba(0,0,0,.04); }
.open-info { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
#open-info[data-loading]::after { content: ' · ⏳ Kartendaten werden vorgeladen …'; }
.footer-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.footer-top .open-info { margin-bottom: 0; }
.auto-chip { font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 12px; border: 1px solid var(--border); background: var(--chip); color: var(--muted); white-space: nowrap; }
.auto-chip.on { background: #e8f5ec; color: #166534; border-color: #bbe5c8; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .auto-chip.on { background: #15301f; color: #9be2b3; border-color: #234d33; } }
.auto-chip.on.paused { background: #fff7ed; color: #9a3412; border-color: #fed7aa; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .auto-chip.on.paused { background: #3a2611; color: #fdba74; border-color: #5a3a14; } }
.addrow { display: flex; gap: 6px; }
.addrow .big { flex: 1; }

/* Teilen / Beitreten / Sync */
.share-btn { margin-left: auto; }
.sync-row { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.sync-state { font-size: 11px; font-weight: 600; }
.sync-state.live { color: #15803d; }
.sync-state.err { color: #c2410c; }
.sync-state.local { color: #6b7280; }
.join-box { margin-top: 24px; text-align: left; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.join-box input { text-transform: uppercase; font-family: ui-monospace, monospace; }
.modal { position: fixed; inset: 0; z-index: 6000; background: rgba(15,18,24,.55); display: grid; place-items: center; padding: 16px; }
.modal-box { width: min(420px, 100%); background: var(--panel); color: var(--text); border-radius: 16px; padding: 18px; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { margin: 0; font-size: 18px; }
.qr { display: grid; place-items: center; margin: 12px 0 6px; }
.qr img, .qr canvas { background: #fff; padding: 8px; border-radius: 10px; }
.share-id { text-align: center; font-size: 18px; font-weight: 800; letter-spacing: .6px; margin-bottom: 4px; }
.share-id code { user-select: all; }

/* ---------- Karte ---------- */
#map-wrap { flex: 1; position: relative; min-height: 0; }
#map { position: absolute; inset: 0; }
#map.picking { cursor: crosshair; }
#map-banner { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 1000; background: var(--accent); color: #fff; padding: 9px 14px; border-radius: 10px; box-shadow: var(--shadow); font-weight: 600; }
#map-banner button { margin-left: 10px; padding: 4px 10px; }
/* Hinweis-Chip unten links oberhalb des Maßstabs – kollidiert nicht mit Lizenzzeile/Knöpfen */
#map-status { position: absolute; bottom: 44px; left: 10px; z-index: 1000; max-width: calc(100% - 20px); background: rgba(255,255,255,.95); color: #222; padding: 5px 10px; border-radius: 8px; font-size: 12px; box-shadow: var(--shadow); pointer-events: none; }
/* Meldungen oben über der Karte (verdecken keine Knöpfe der Seitenleiste) */
/* Meldungen unten mittig im Kartenbereich – über Hinweis/Maßstab, nie über Knöpfen der Seitenleiste */
#toast { position: absolute; bottom: 84px; left: 50%; transform: translateX(-50%); background: #1f2933; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 1500; width: max-content; max-width: min(520px, calc(100% - 24px)); box-shadow: 0 8px 24px rgba(0,0,0,.25); font-size: 13px; pointer-events: none; animation: toast-in .18s ease; text-align: center; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translate(-50%, 0); } }
.leaflet-control-attribution { font-size: 10px !important; max-width: 70%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.leaflet-control-attribution:hover { white-space: normal; }
.leaflet-control-layers-list { max-height: min(60vh, 460px); overflow-y: auto; }
.leaflet-bottom.leaflet-left .leaflet-control-scale { margin-bottom: 18px; }

.leaflet-control-layers.legend { border-radius: 10px; box-shadow: var(--shadow); border: 1px solid rgba(0,0,0,.15); overflow: hidden; }
.legend-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px 4px 10px; font-weight: 700; font-size: 12px; color: #333; border-bottom: 1px solid #eee; }
.legend-close { border: none; background: #f1f3f6; border-radius: 6px; width: 24px; height: 22px; font-size: 16px; line-height: 1; cursor: pointer; color: #333; }
.legend-close:hover { background: #e3e6eb; }
.legend-open { display: none; border: none; background: #fff; color: #222; padding: 7px 10px; font-size: 13px; font-weight: 600; cursor: pointer; }
.legend.legend-hidden .leaflet-control-layers-list, .legend.legend-hidden .legend-head { display: none; }
.legend.legend-hidden .legend-open { display: block; }
.emoji-icon { font-size: 20px; line-height: 24px; text-align: center; filter: drop-shadow(0 0 2px #fff); }
.emoji-icon.big { font-size: 26px; }
.area-label { background: rgba(255,255,255,.92); border: 2px solid #333; border-radius: 6px; font-weight: 800; font-size: 13px; padding: 0 6px; color: #111; }
.area-label::before { display: none; }
.area-label.area-label-sel { font-size: 18px; padding: 2px 10px; background: #111827; color: #fff; border-color: #fff; box-shadow: 0 0 0 3px rgba(17,24,39,.35), 0 4px 12px rgba(0,0,0,.35); z-index: 900 !important; }
.area-selected { animation: area-pulse 1.4s ease-in-out infinite; }
@keyframes area-pulse { 0%, 100% { stroke-opacity: 1; stroke-width: 5px; } 50% { stroke-opacity: .55; stroke-width: 8px; } }
@media (prefers-reduced-motion: reduce) { .area-selected { animation: none; } }
.ring-label { background: transparent; border: none; box-shadow: none; color: #b45309; font-weight: 700; font-size: 11px; text-shadow: 0 0 3px #fff; }
.ring-label::before { display: none; }
.leaflet-popup-content { font-size: 13px; }
.leaflet-popup-content button { margin-top: 6px; }

@media (max-width: 760px) {
  #app { flex-direction: column-reverse; }
  /* Bottom-Sheet mit drei Höhen: klein (nur Knöpfe), halb, ganz */
  #sidebar { width: 100%; height: 52dvh; border-right: none; border-top: 1px solid var(--border); border-radius: 16px 16px 0 0; box-shadow: 0 -6px 20px rgba(0,0,0,.15); transition: height .2s ease; }
  #sidebar[data-sheet="full"] { height: 88dvh; }
  #sidebar[data-sheet="mini"] { height: auto; }
  #sidebar[data-sheet="mini"] .topbar, #sidebar[data-sheet="mini"] #search-ui, #sidebar[data-sheet="mini"] #no-search { display: none !important; }
  .sheet-handle { display: flex; flex-direction: column; align-items: center; gap: 2px; width: 100%; border: none; background: transparent; padding: 6px 0 2px; cursor: pointer; color: var(--muted); flex: none; }
  .sheet-handle span { width: 42px; height: 5px; border-radius: 3px; background: var(--border); }
  .sheet-handle em { font-style: normal; font-size: 10px; font-weight: 600; }
  /* kompakter Kopf */
  .topbar { padding: 4px 12px 8px; gap: 6px; }
  .logo { width: 28px; height: 28px; font-size: 15px; border-radius: 8px; }
  .brand-text span { display: none; }
  .brand-text strong { font-size: 15px; }
  .status-card { margin: 8px 12px 0; padding: 8px 10px; }
  .radius-info .small { display: none; }
  .tabs { margin: 8px 12px 0; }
  .tab { padding: 4px 2px; font-size: 15px; }
  .tab span { font-size: 10px; }
  .panes { padding: 10px 12px 14px; }
  #area-detail .detail-head, .merge-bar { top: 56px; }
  #sidebar-footer { padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); }
  .footer-top { margin-bottom: 6px; }
  .btn.big { padding: 10px 12px; font-size: 14px; }
  #toast { bottom: 72px; font-size: 12px; }
  /* halb geöffnet: Kopf/Suchauswahl ausblenden – erst „ganz“ zeigt alles */
  #sidebar[data-sheet="mid"] .topbar { display: none; }
  #map-banner { top: 12px; max-width: calc(100vw - 24px); font-size: 13px; }
  #map-status { bottom: 40px; font-size: 11px; }
  .leaflet-control-attribution { max-width: 92%; }
}
