:root {
  --bg: #f2f4f7;
  --card: #ffffff;
  --text: #111418;
  --muted: #5d6673;
  --line: #d9dee5;
  --accent: #0b4fb3;
  --accent-soft: #e3edfc;
  --ok: #1d8a3c;
  --warn: #b25e00;
  --warn-soft: #fff3e0;
  --danger: #c62828;
  --marker: #ffe600;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); min-height: 1.4em; }
h3 { margin: 26px 0 10px; font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

.view { display: none; min-height: 100%; padding-bottom: calc(110px + var(--safe-bottom)); }
.view.active { display: block; }

/* Kopfzeile */
.bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 6px;
  padding: calc(8px + var(--safe-top)) 10px 8px;
  background: rgba(255,255,255,.95); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.bar-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.bar-title strong { font-size: 18px; }
.icon-btn {
  border: 0; background: none; font-size: 24px; min-width: 44px; height: 44px; border-radius: 10px; color: var(--accent);
}
.icon-btn:active { background: var(--accent-soft); }
#form-back { font-size: 36px; line-height: 1; }
.chip-status { font-size: 13px; padding: 5px 9px; border-radius: 99px; background: #eceff3; white-space: nowrap; }
.chip-status.good { background: #def3e3; color: var(--ok); }
.chip-status.bad { background: var(--warn-soft); color: var(--warn); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; text-align: center;
  min-height: 48px; padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--accent); font: inherit; font-weight: 600; text-decoration: none;
}
.btn:active { filter: brightness(.93); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.big { width: 100%; min-height: 56px; font-size: 18px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; }
.link-btn { border: 0; background: none; color: var(--accent); font: inherit; font-weight: 600; padding: 6px 0; }

/* Login */
.login-box { max-width: 420px; margin: 0 auto; padding: calc(60px + var(--safe-top)) 24px 24px; text-align: center; }
.login-logo { width: 84px; height: 84px; border-radius: 20px; }
.login-box h1 { font-size: 22px; }
.login-box input { margin-bottom: 12px; text-align: center; }

/* Liste */
.banner { margin: 10px 12px 0; padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-size: 15px; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.entry-list { list-style: none; margin: 0; padding: 8px 12px; }
.entry {
  display: flex; gap: 12px; align-items: center; padding: 10px; margin-bottom: 8px;
  background: var(--card); border-radius: 14px; border: 1px solid var(--line);
}
.entry:active { background: #f7f9fc; }
.entry-num {
  flex: none; min-width: 44px; height: 44px; padding: 0 6px; border-radius: 8px; display: grid; place-items: center;
  border: 3px solid var(--marker); font-weight: 800; font-size: 18px; background: #fff;
}
.entry-thumb { flex: none; width: 56px; height: 56px; border-radius: 8px; object-fit: cover; background: #e6e9ee; }
.entry-main { flex: 1; min-width: 0; }
.entry-main .t1 { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-main .t2 { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag { display: inline-block; font-size: 12px; padding: 1px 7px; border-radius: 99px; margin-right: 4px; }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.sync { background: var(--accent-soft); color: var(--accent); }
.tag.ok { background: #def3e3; color: var(--ok); }
.empty { text-align: center; color: var(--muted); margin-top: 60px; }
.fab {
  position: fixed; left: 12px; right: 12px; bottom: calc(14px + var(--safe-bottom)); z-index: 20;
  height: 60px; border: 0; border-radius: 16px; background: var(--accent); color: #fff;
  font: inherit; font-size: 19px; font-weight: 700; box-shadow: 0 6px 20px rgba(11,79,179,.35);
}
.fab:active { filter: brightness(.92); }

/* Formular */
.form-body { padding: 12px 14px; max-width: 640px; margin: 0 auto; }
.id-label { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; white-space: nowrap; }
.id-label input.id-input { width: 84px; padding: 6px 8px; font-size: 20px; font-weight: 800; text-align: center; border: 3px solid var(--marker); border-radius: 8px; }
input[type=text], input[type=password], input[type=number] {
  width: 100%; font: inherit; font-size: 17px; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text);
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field { margin: 18px 0; }
.field-head { display: flex; justify-content: space-between; align-items: center; font-weight: 600; margin-bottom: 6px; }
.hint { font-size: 14px; margin: 6px 0 0; }
.hint.warn { color: var(--warn); }
.photos { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.photo-tile { display: flex; flex-direction: column; align-items: stretch; }
.photo-btn {
  position: relative; display: grid; place-items: center; aspect-ratio: 3 / 4; border-radius: 14px; overflow: hidden;
  background: var(--card); border: 2px dashed #b8c1cd; text-align: center; color: var(--muted);
}
.photo-btn.has { border: 2px solid var(--ok); }
.photo-ph { font-size: 15px; line-height: 1.35; }
.photo-ph b { color: var(--text); font-size: 17px; }
.photo-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.lib-link { text-align: center; font-size: 14px; color: var(--accent); padding: 8px 0 0; }
.gps-box { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 11px 14px; font-size: 15px; }
.gps-box.good { color: var(--text); }
.gps-box.warn { background: var(--warn-soft); color: var(--warn); border-color: #f1d3a8; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 10px 15px; font: inherit; font-size: 16px; color: var(--text);
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.plan-preview {
  position: relative; display: block; width: 100%; aspect-ratio: 1.613; border-radius: 14px; overflow: hidden; border: 1px solid var(--line);
  background: #ccc center / cover no-repeat; padding: 0; font: inherit;
}
.plan-preview-label {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); white-space: nowrap;
  background: rgba(255,255,255,.95); color: var(--accent); font-weight: 700; padding: 8px 14px; border-radius: 99px;
}
.plan-dot {
  position: absolute; width: 16px; height: 16px; margin: -8px 0 0 -8px; border-radius: 50%;
  background: #e53935; border: 3px solid #fff; box-shadow: 0 0 0 2px #e53935;
}
.form-actions { display: grid; gap: 10px; margin-top: 10px; }
#form-missing:empty { display: none; }

/* Plan-Ansicht */
.plan-view { position: relative; overflow: hidden; touch-action: none; background: #2b2f36; user-select: none; -webkit-user-select: none; }
.plan-view img { position: absolute; left: 0; top: 0; transform-origin: 0 0; max-width: none; pointer-events: none; -webkit-user-drag: none; }
.plan-view svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.plan-zoom { position: absolute; right: 10px; top: 10px; display: flex; flex-direction: column; gap: 6px; z-index: 2; }
.plan-zoom button { width: 44px; height: 44px; border-radius: 10px; border: 0; background: rgba(255,255,255,.95); font-size: 22px; font-weight: 700; color: var(--text); }
.view-map.active { display: flex; flex-direction: column; height: 100%; padding-bottom: 0; }
.view-map .plan-view { flex: 1; }
.picker { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; background: #000; }
.picker .plan-view { flex: 1; }
.picker-tools { background: var(--card); padding: 10px 12px calc(10px + var(--safe-bottom)); display: grid; gap: 10px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: #e9edf2; border-radius: 12px; padding: 3px; }
.seg-btn { border: 0; background: none; padding: 11px; border-radius: 10px; font: inherit; font-weight: 600; color: var(--muted); }
.seg-btn.active { background: #fff; color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.15); }

/* Einstellungen */
.ground-list { list-style: none; padding: 0; margin: 0; background: var(--card); border-radius: 12px; border: 1px solid var(--line); }
.ground-list li { display: flex; align-items: center; padding: 6px 6px 6px 14px; border-bottom: 1px solid var(--line); }
.ground-list li:last-child { border-bottom: 0; }
.ground-list li span { flex: 1; }
.ground-list button { border: 0; background: none; font-size: 18px; width: 44px; height: 40px; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translateX(-50%); z-index: 100;
  background: rgba(20,24,30,.92); color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 15px; max-width: 90vw; text-align: center;
}

/* In-App-Dialog (ersetzt confirm/prompt, die manche Browser unterdrücken) */
.dialog { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 20px; background: rgba(10,14,20,.5); }
.dialog-box { width: 100%; max-width: 420px; background: var(--card); border-radius: 16px; padding: 20px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.dialog-box p { margin: 0 0 16px; white-space: pre-line; font-size: 17px; }
.dialog-box input { margin-bottom: 16px; }
.btn.danger-fill { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn[disabled] { opacity: .6; }

/* Vorlagen laden */
.setup-list { list-style: none; padding: 0; margin: 18px 0; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.setup-list li { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.setup-list li:last-child { border-bottom: 0; }
.setup-check { flex: none; width: 26px; height: 26px; border-radius: 50%; border: 2px solid #b8c1cd; }
.setup-list li.ok .setup-check { border-color: var(--ok); background: var(--ok); box-shadow: inset 0 0 0 4px #fff; }
#view-setup .btn.big { cursor: pointer; }

/* Sicherung */
.restore-link { display: inline-block; margin-top: 6px; cursor: pointer; }
#backup-status:empty, #storage-info:empty, #export-status:empty { display: none; }
