:root {
  --bg: #f2f4f7;
  --surface: #ffffff;
  --surface-2: #f6f7f9;
  --text: #15202b;
  --muted: #5b6673;
  --faint: #8b95a1;
  --line: #e2e6eb;
  --accent: #1e5aa8;
  --accent-text: #ffffff;
  --accent-soft: #e4edf9;
  --green: #1d8a4e;
  --green-soft: #e1f3e8;
  --danger: #c0392b;
  --warn-soft: #fff4dc;
  --warn-text: #7a5300;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  --tabbar: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --surface: #182029;
    --surface-2: #1f2933;
    --text: #e8edf2;
    --muted: #a3adb8;
    --faint: #75808c;
    --line: #2a3540;
    --accent: #5d9cf0;
    --accent-text: #0b1520;
    --accent-soft: #1b2e48;
    --green: #4cc382;
    --green-soft: #173527;
    --danger: #f0776a;
    --warn-soft: #3a2f14;
    --warn-text: #f3cf7a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 24px);
}

a { color: var(--accent); text-decoration: none; }
h1, h2 { margin: 0; font-weight: 650; }
h2 { font-size: 1.05rem; margin-bottom: 10px; }
p { margin: 0 0 8px; }
img { max-width: 100%; display: block; }

.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.mono, .reg { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.pre { white-space: pre-wrap; }
.grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.split { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }

/* Kopfzeile */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 1.1rem; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 8px; }
.icon-btn {
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 2rem;
  line-height: 1;
  padding: 0 8px 4px 0;
  cursor: pointer;
}

/* Reiter */
.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  height: calc(var(--tabbar) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-top: 1px solid var(--line);
}
.tabs a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--faint);
  font-size: 0.72rem;
}
.tabs a svg { width: 24px; height: 24px; }
.tabs a.active { color: var(--accent); }

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px;
  outline: none;
}

@media (min-width: 900px) {
  body { padding-bottom: 40px; }
  .tabs {
    position: sticky;
    top: 52px;
    bottom: auto;
    height: 48px;
    padding: 0;
    justify-content: center;
    border-top: 0;
    border-bottom: 1px solid var(--line);
  }
  .tabs a { flex: 0 0 auto; flex-direction: row; gap: 8px; padding: 0 18px; font-size: 0.95rem; }
  .tabs a svg { width: 20px; height: 20px; }
  .fab { bottom: 32px !important; }
}
@media (max-width: 899px) {
  .hide-mobile { display: none; }
}

/* Schaltflächen */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 34px; padding: 4px 12px; font-size: 0.9rem; }
.btn.block { width: 100%; }

.fab {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 18px);
  z-index: 25;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 2rem;
  line-height: 1;
  box-shadow: 0 6px 18px rgba(30, 90, 168, 0.35);
}
.fab[hidden] { display: none; }

/* Formulare */
input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* verhindert Zoom auf iOS */
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: grid; gap: 6px; font-size: 0.9rem; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 10px; color: var(--text); }
label.check input { width: 20px; min-height: 20px; height: 20px; }
.reg-input {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 1.6rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.stack { display: grid; gap: 12px; }
.grid2 { display: grid; gap: 12px; }
@media (min-width: 600px) { .grid2 { grid-template-columns: 1fr 1fr; } }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
.row-end { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.file { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.file-btn { display: inline-flex; color: var(--text); font-size: 1rem; }
.editor .card > * + * { margin-top: 12px; }
.sticky-actions {
  position: sticky;
  bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 8px);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 10px;
  margin-top: 8px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
@media (min-width: 900px) { .sticky-actions { bottom: 16px; } }
.sticky-actions .btn { flex: 1; max-width: 220px; }

/* Bausteine */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.card.flush { padding: 0; overflow: hidden; }
.card.head { display: flex; gap: 14px; align-items: center; }
.summary { margin: 4px 2px 14px; }
.summary .big { font-size: 2.4rem; font-weight: 750; letter-spacing: -0.02em; }
.toolbar { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.toolbar input { flex: 1 1 220px; }
.toolbar select { flex: 0 1 190px; width: auto; }

.list { list-style: none; margin: 0 0 12px; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list.flat { border: 0; border-radius: 0; background: none; margin: 0 -4px 12px; }
.list li + li { border-top: 1px solid var(--line); }
.item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  color: inherit;
  min-height: 56px;
}
a.item:hover { background: var(--surface-2); }
.item.static { padding: 0; }
.list.flat .item { padding: 10px 4px; }
.chev { color: var(--faint); font-size: 1.4rem; }
.reg { font-weight: 650; }
.reg.xl { font-size: 1.7rem; }

.thumb {
  position: relative;
  flex: 0 0 64px;
  width: 64px;
  height: 48px;
  border-radius: 8px;
  background: var(--surface-2);
  overflow: hidden;
  display: grid;
  place-items: center;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-flag { position: absolute; right: 2px; bottom: 0; font-size: 0.9rem; }
.thumb:not(:has(img)) .thumb-flag { position: static; font-size: 1.6rem; }
.flag-l { font-size: 1.9rem; line-height: 1; }
.flag-xl { font-size: 3rem; line-height: 1; }
.flag-xxl { font-size: 4.5rem; line-height: 1.1; }
.big-mono { font-size: 1.3rem; margin: 4px 0; }

.hero { margin: -16px -16px 14px; background: var(--surface-2); }
.hero { position: relative; }
.hero img { width: 100%; max-height: 360px; object-fit: cover; }
.credit {
  position: absolute;
  right: 8px;
  bottom: 8px;
  max-width: calc(100% - 16px);
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.credit-inline { display: block; margin-top: 2px; }
@media (min-width: 792px) { .hero { margin: 0 0 14px; border-radius: var(--radius); overflow: hidden; } }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 650;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
  margin-left: 6px;
}
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.blue { background: var(--accent-soft); color: var(--accent); }

.note { background: var(--warn-soft); color: var(--warn-text); padding: 10px 12px; border-radius: 10px; font-size: 0.92rem; }
.alert { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); padding: 10px 12px; border-radius: 10px; }

.info { display: grid; grid-template-columns: minmax(110px, 38%) 1fr; gap: 8px 14px; margin: 0 0 8px; }
.info dt { color: var(--muted); }
.info dd { margin: 0; overflow-wrap: anywhere; }

.choice {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.choice.selected { border-color: var(--accent); background: var(--accent-soft); }
.choice .radio { color: var(--accent); font-size: 1.3rem; }
.choices { display: grid; gap: 8px; max-height: 60vh; overflow: auto; }
.info-card { display: flex; gap: 12px; align-items: flex-start; flex: 1; min-width: 0; }

.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.segmented button { border: 0; background: none; color: var(--muted); font: inherit; padding: 7px 12px; border-radius: 8px; cursor: pointer; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }

.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 6px; }
.progress span { display: block; min-width: 8px; height: 100%; background: var(--accent); border-radius: 999px; }
.region-row + .region-row { margin-top: 14px; }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 600px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.tile-value { font-size: 1.8rem; font-weight: 750; font-variant-numeric: tabular-nums; }

.bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; height: 170px; align-items: end; }
.bar { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar-fill { width: 70%; max-width: 28px; min-height: 2px; background: var(--accent); border-radius: 4px 4px 0 0; }
.bar-value { font-size: 0.72rem; color: var(--muted); }
.bar-label { font-size: 0.68rem; color: var(--faint); margin-top: 4px; }

.rank { margin: 0; padding-left: 1.4em; }
.rank li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.rank li:last-child { border-bottom: 0; }

.table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.table th, .table td { padding: 9px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
.table th.num, .table td.num { text-align: right; }
.table tr.me td { background: var(--accent-soft); }
.table .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.card:has(.table) { overflow-x: auto; }

.map { height: calc(100vh - 52px - var(--tabbar) - 80px); min-height: 360px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.mini-map { height: 220px; }
.popup { display: grid; gap: 2px; min-width: 160px; }
.leaflet-container { font: inherit; }

.photo-preview img { border-radius: 10px; max-height: 320px; object-fit: contain; }

.loading { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); padding: 48px 0; }
.loading.inline { justify-content: flex-start; padding: 4px 0; }
.spin { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; padding: 48px 16px; }
.empty-icon { font-size: 3rem; color: var(--accent); }
.empty h2 { font-size: 1.3rem; margin: 8px 0; }
.empty .btn { margin-top: 12px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 90px);
  transform: translate(-50%, 20px);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-weight: 550;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.dialog {
  border: 0;
  border-radius: 16px;
  padding: 20px;
  width: min(420px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}
.dialog.wide { width: min(620px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(10, 15, 20, 0.45); }

/* Login */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-card form { display: grid; gap: 14px; margin-top: 18px; text-align: left; }
.login-logo { margin: 0 auto 10px; border-radius: 16px; }
.login-card h1 { font-size: 1.5rem; }
