:root {
  --color-primary: #b3161c;
  --color-primary-dark: #7a0f14;
  --color-bg: #f4f1ea;
  --color-surface: #ffffff;
  --color-surface-2: #f0ede4;
  --color-text: #1a1a1a;
  --color-muted: #666660;
  --color-border: #ddd6c9;
  --color-success: #2e7d32;
  --color-success-bg: #e3f3e4;
  --color-warning: #9a6b00;
  --color-warning-bg: #fdf1d6;
  --color-danger: #b3161c;
  --color-danger-bg: #fbe4e4;
  --radius: 12px;
  --nav-height: 70px;
  --header-height: 56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #17171a;
    --color-surface: #232327;
    --color-surface-2: #2c2c31;
    --color-text: #f0f0ee;
    --color-muted: #a8a8a4;
    --color-border: #3a3a3f;
    --color-success-bg: #163a1c;
    --color-warning-bg: #40320a;
    --color-danger-bg: #401414;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}

body { overscroll-behavior-y: contain; }

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

h1, h2, h3 { margin: 0 0 8px 0; line-height: 1.25; }
p { margin: 0 0 8px 0; }

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Header */
#app-header {
  height: var(--header-height);
  min-height: var(--header-height);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: var(--color-primary);
  color: #fff;
  z-index: 20;
}
#app-header .title { font-weight: 700; font-size: 17px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#app-header .status-pill {
  display: flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,0.15);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 13px;
  white-space: nowrap;
}
#app-header .status-dot { width: 9px; height: 9px; border-radius: 50%; background: #9ee08a; }
#app-header .status-dot.offline { background: #f2c94c; }
#app-header .status-dot.error { background: #f26a4c; }
#app-header button.icon-btn {
  background: transparent; border: none; color: #fff; font-size: 22px; padding: 8px; cursor: pointer; border-radius: 8px;
}
#app-header button.icon-btn:active { background: rgba(255,255,255,0.2); }

/* Main content */
#app-view {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px calc(var(--nav-height) + 20px) 14px;
}
@media (min-width: 900px) {
  #app-view { max-width: 980px; margin: 0 auto; width: 100%; }
}

/* Bottom nav */
#app-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: var(--nav-height);
  display: flex;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  z-index: 20;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
#app-nav button {
  flex: 1;
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--color-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 6px 2px;
}
#app-nav button .nav-icon { font-size: 22px; }
#app-nav button.active { color: var(--color-primary); font-weight: 700; }

/* Cards & sections */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}
.card h2 { font-size: 18px; }
.section-title { font-size: 14px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--color-muted); margin: 18px 0 8px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: var(--color-surface-2);
  color: var(--color-text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--color-primary); color: #fff; }
.btn.primary:active { background: var(--color-primary-dark); }
.btn.success { background: var(--color-success); color: #fff; }
.btn.outline { background: transparent; border-color: var(--color-border); }
.btn.small { min-height: 40px; font-size: 14px; padding: 6px 12px; width: auto; }
.btn.danger { background: var(--color-danger-bg); color: var(--color-danger); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; min-width: 140px; }

/* Forms */
label { display: block; font-weight: 600; margin: 12px 0 4px; font-size: 14px; }
label:first-child { margin-top: 0; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=time],
input[type=datetime-local], input[type=tel], select, textarea {
  width: 100%;
  padding: 12px 12px;
  border-radius: 10px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  min-height: 48px;
}
textarea { min-height: 90px; resize: vertical; }
.form-row { margin-bottom: 4px; }
.checkbox-row { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.checkbox-row input[type=checkbox] { width: 22px; height: 22px; }
fieldset { border: 1px solid var(--color-border); border-radius: var(--radius); padding: 10px; margin: 10px 0; }
legend { padding: 0 6px; font-weight: 600; font-size: 14px; }

/* Badges */
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge.offen { background: var(--color-warning-bg); color: var(--color-warning); }
.badge.erledigt, .badge.abgeschlossen { background: var(--color-success-bg); color: var(--color-success); }
.badge.overdue { background: var(--color-danger-bg); color: var(--color-danger); }
.badge.pending { background: var(--color-surface-2); color: var(--color-muted); border: 1px dashed var(--color-border); }
.badge.conflict { background: var(--color-danger-bg); color: var(--color-danger); }

/* Lists */
.list-item { border-bottom: 1px solid var(--color-border); padding: 12px 0; }
.list-item:last-child { border-bottom: none; }
.list-item .row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.muted { color: var(--color-muted); font-size: 14px; }
.small { font-size: 13px; }

/* Task item */
.task-item { display: flex; align-items: flex-start; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--color-border); }
.task-item:last-child { border-bottom: none; }
.task-check {
  width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--color-border);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; cursor: pointer; font-size: 18px;
  background: var(--color-surface);
}
.task-check.done { background: var(--color-success); border-color: var(--color-success); color: #fff; }
.task-item.overdue .task-time { color: var(--color-danger); font-weight: 700; }
.task-time { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 48px; }

/* Login */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100%; padding: 20px; }
.login-box { max-width: 380px; width: 100%; }
.login-logo { text-align: center; margin-bottom: 18px; font-size: 40px; }
.user-tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px,1fr)); gap: 10px; margin: 14px 0; }
.user-tile { background: var(--color-surface-2); border-radius: var(--radius); padding: 14px 10px; text-align: center; cursor: pointer; border: 2px solid transparent; }
.user-tile.selected { border-color: var(--color-primary); }
.user-tile .role { font-size: 12px; color: var(--color-muted); }

/* Map */
#map-viewport { position: relative; overflow: hidden; border-radius: var(--radius); border: 1px solid var(--color-border); background: var(--color-surface-2); touch-action: none; height: 60vh; min-height: 320px; }
#map-canvas { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
#map-canvas img, #map-canvas object { display: block; user-select: none; -webkit-user-drag: none; }
.map-point-marker {
  position: absolute; width: 26px; height: 26px; margin-left: -13px; margin-top: -26px;
  cursor: pointer;
}
.map-point-marker svg { width: 100%; height: 100%; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5)); }
.map-controls { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.map-legend { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.map-legend button { border: 1px solid var(--color-border); background: var(--color-surface); border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; }
.map-legend button.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

/* Utility */
.flex { display: flex; }
.gap { gap: 10px; }
.between { justify-content: space-between; }
.center { align-items: center; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }
.hidden { display: none !important; }
.empty-state { text-align: center; padding: 30px 10px; color: var(--color-muted); }
.toast-container { position: fixed; top: calc(var(--header-height) + 8px); left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 50; pointer-events: none; }
.toast { background: #222; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; box-shadow: 0 2px 8px rgba(0,0,0,0.3); }
.toast.error { background: var(--color-danger); }
.toast.success { background: var(--color-success); }

a.tel-link { color: var(--color-primary); font-weight: 700; text-decoration: none; }
.fav-star { color: #d4a300; }

table.simple { width: 100%; border-collapse: collapse; }
table.simple th, table.simple td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--color-border); font-size: 14px; }

.diff-old { text-decoration: line-through; color: var(--color-muted); }
.diff-new { color: var(--color-success); font-weight: 600; }

.banner { border-radius: var(--radius); padding: 12px; margin-bottom: 14px; font-size: 14px; }
.banner.warning { background: var(--color-warning-bg); color: var(--color-warning); }
.banner.danger { background: var(--color-danger-bg); color: var(--color-danger); }
.banner.info { background: var(--color-surface-2); color: var(--color-text); }
