:root {
  --bg: #f4f4f5;
  --fg: #111114;
  --muted: #6b6b73;
  --card: #ffffff;
  --line: #e2e2e6;
  --dark: #18181b;
  --accent: #d0261d;
  --accent-press: #a81d16;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: 400; }

.view { position: fixed; inset: 0; display: flex; flex-direction: column; }

header {
  display: flex; align-items: center; gap: 4px;
  padding: calc(var(--safe-top) + 10px) 8px 10px 16px;
  background: var(--dark); color: #fff; flex: none;
}
header h1 {
  flex: 1; margin: 0; font-size: 19px; font-weight: 650;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#view-project header { padding-left: 4px; }
.icon-btn {
  background: none; border: 0; color: inherit; font-size: 24px; line-height: 1;
  min-width: 44px; min-height: 44px; border-radius: 10px; cursor: pointer;
}
.icon-btn:active { background: rgba(255,255,255,.12); }
#btn-back { font-size: 34px; }

.scroll { flex: 1; overflow-y: auto; padding: 16px 16px calc(var(--safe-bottom) + 24px); }

.btn {
  border: 0; border-radius: 12px; padding: 12px 16px; font: inherit; font-weight: 600;
  cursor: pointer; min-height: 46px;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-press); }
.btn.primary:disabled { background: #9c9ca3; }
.btn.ghost { background: transparent; color: inherit; border: 1.5px solid currentColor; }
.btn.big { width: 100%; font-size: 18px; min-height: 56px; }
.btn.small { min-height: 34px; padding: 6px 12px; font-size: 14px; }
.btn.danger { background: #fff; color: var(--accent); border: 1.5px solid var(--accent); }

.card { background: var(--card); border-radius: 14px; padding: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.new-project { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.new-project input {
  flex: 1; min-width: 0; font: inherit; font-size: 16px; padding: 10px 12px;
  border: 1.5px solid var(--line); border-radius: 10px;
}

.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 10px; background: var(--card);
  border-radius: 14px; padding: 12px 12px 12px 16px; box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.item .main { flex: 1; min-width: 0; cursor: pointer; }
.item .title { font-weight: 650; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.item .del {
  background: none; border: 0; color: var(--muted); font-size: 20px;
  min-width: 44px; min-height: 44px; border-radius: 10px; cursor: pointer;
}
.item .del:active { background: #f1d4d2; color: var(--accent); }
.empty { color: var(--muted); text-align: center; margin-top: 32px; }

/* ---------- Karte ---------- */
.map-wrap { position: relative; flex: 1; min-height: 0; }
#map { position: absolute; inset: 0; background: #ddd; }
.hud {
  position: absolute; top: 10px; left: 10px; right: 60px; z-index: 500;
  background: rgba(255,255,255,.96); border-radius: 12px; padding: 10px 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,.15); font-size: 14px; line-height: 1.35;
}
.hud b { font-size: 15px; }
.hud .warn { color: #a15c00; margin-top: 4px; }
.hud button { margin-top: 6px; margin-right: 6px; }
.map-btn {
  position: absolute; right: 10px; top: 10px; z-index: 500;
  width: 44px; height: 44px; border-radius: 12px; border: 0;
  background: #fff; font-size: 22px; box-shadow: 0 2px 8px rgba(0,0,0,.2); cursor: pointer;
}
.map-btn.second { top: 62px; }

.panel { background: var(--card); border-top: 1px solid var(--line); flex: none; }
.panel summary { padding: 12px 16px; font-weight: 600; cursor: pointer; list-style: none; }
.panel summary::-webkit-details-marker { display: none; }
.panel summary::after { content: " ▴"; color: var(--muted); }
.panel[open] summary::after { content: " ▾"; }
.panel .list { max-height: 34vh; overflow-y: auto; padding: 0 12px 12px; }
.list.compact .item { box-shadow: none; border: 1px solid var(--line); padding: 8px 8px 8px 12px; }
.swatch { width: 14px; height: 14px; border-radius: 50%; flex: none; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.25); }

.bottom-bar { flex: none; background: var(--card); padding: 8px 16px calc(var(--safe-bottom) + 12px); border-top: 1px solid var(--line); }
.status-row { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.gps-status.bad, .calib-status.bad { color: #a15c00; }
.calib-status.ok { color: #2f7d32; }

.leaflet-popup-content { font-size: 14px; line-height: 1.4; margin: 12px 14px; }
.leaflet-popup-content .pop-title { font-weight: 700; font-size: 15px; margin-bottom: 2px; }
.leaflet-popup-content .pop-note { margin-top: 4px; white-space: pre-wrap; }
.leaflet-popup-content .btn { margin-top: 8px; }
.est-icon { font-size: 30px; line-height: 30px; text-align: center; color: #111; text-shadow: 0 0 3px #fff, 0 0 3px #fff; }

/* ---------- Kamera ---------- */
.camera { background: #000; color: #fff; }
.camera video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.camera .nocam-hint { display: none; }
.camera.nocam video, .camera.nocam .reticle { display: none; }
.camera.nocam .nocam-hint {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  position: absolute; inset: 0; text-align: center; padding: 0 32px; color: #ccc;
}
.nocam-hint .arrow { font-size: 64px; color: var(--accent); margin-bottom: 120px; }
.reticle {
  position: absolute; top: 0; bottom: 0; left: 50%; width: 3px; margin-left: -1.5px;
  background: rgba(255,40,30,.95); box-shadow: 0 0 0 1px rgba(255,255,255,.7);
  pointer-events: none;
}
.reticle .tick {
  position: absolute; top: 50%; left: -20px; width: 43px; height: 3px; margin-top: -1.5px;
  background: rgba(255,40,30,.95); box-shadow: 0 0 0 1px rgba(255,255,255,.7);
}
.cam-top {
  position: absolute; top: 0; left: 0; right: 0;
  padding: calc(var(--safe-top) + 14px) 16px 18px;
  background: linear-gradient(rgba(0,0,0,.75), rgba(0,0,0,0)); text-align: center;
}
.cam-heading { font-size: 46px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .5px; }
.cam-sub { font-size: 15px; opacity: .9; margin-top: 2px; }
.cam-warn {
  display: inline-block; margin-top: 10px; background: rgba(255,170,0,.95); color: #111;
  border-radius: 10px; padding: 6px 10px; font-size: 14px; font-weight: 600;
}
.cam-bottom {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; gap: 12px;
  padding: 18px 16px calc(var(--safe-bottom) + 18px);
  background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,.75));
}
.cam-bottom .btn { flex: 1; min-height: 58px; font-size: 17px; }
.cam-bottom .btn.ghost { flex: .6; color: #fff; }

/* ---------- Dialog ---------- */
dialog {
  border: 0; border-radius: 16px; padding: 0; width: min(440px, calc(100vw - 32px));
  box-shadow: 0 10px 40px rgba(0,0,0,.35);
}
dialog::backdrop { background: rgba(0,0,0,.5); }
dialog form { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
dialog h2 { margin: 0; font-size: 20px; }
dialog p { margin: 0; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 14px; }
dialog input, dialog textarea {
  font: inherit; font-size: 16px; font-weight: 400; padding: 10px 12px;
  border: 1.5px solid var(--line); border-radius: 10px; resize: vertical;
}
.dlg-actions { display: flex; gap: 10px; margin-top: 4px; }
.dlg-actions .btn { flex: 1; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 110px); transform: translateX(-50%);
  background: rgba(20,20,22,.92); color: #fff; padding: 10px 16px; border-radius: 12px;
  font-size: 14px; z-index: 2000; max-width: calc(100vw - 32px); text-align: center;
}

/* ---------- Abgleich / Einstellungen ---------- */
.pick-bar {
  position: absolute; left: 10px; right: 62px; top: 10px; z-index: 600;
  background: #18181b; color: #fff; border-radius: 12px; padding: 12px;
  display: flex; gap: 10px; align-items: center; font-size: 14px; line-height: 1.35;
  box-shadow: 0 4px 16px rgba(0,0,0,.3);
}
.pick-bar .btn.ghost { color: #fff; flex: none; }
.map-wrap.picking #map { cursor: crosshair; }
.cam-mode {
  display: inline-block; background: #ffd23c; color: #111; font-weight: 700;
  border-radius: 10px; padding: 5px 10px; margin-bottom: 6px; font-size: 14px;
}
dialog h3 { margin: 6px 0 0; font-size: 15px; }
dialog .small, .small { font-size: 13px; }
dialog label.check { flex-direction: row; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; }
dialog label.check input { width: 22px; height: 22px; margin: 0; }
dialog .row { display: flex; gap: 8px; flex-wrap: wrap; }
.dlg-actions.col { flex-direction: column; }
.btn.link { background: none; color: var(--muted); min-height: 40px; }
.warn-text { color: #a15c00; font-weight: 600; }
