/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1f17;
  --bg2: #162b1f;
  --bg3: #1e3a2a;
  --surface: #1a3225;
  --surface2: #223d2e;
  --border: #2d5040;
  --accent: #4caf78;
  --accent2: #38926a;
  --accent-dim: rgba(76,175,120,0.15);
  --danger: #e05555;
  --danger-dim: rgba(224,85,85,0.15);
  --warn: #e0a030;
  --warn-dim: rgba(224,160,48,0.15);
  --text: #e8f2ec;
  --text2: #9dbfad;
  --text3: #6a9a7a;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --topbar-h: 56px;
  --bottomnav-h: 64px;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ===== SCREENS ===== */
.screen { position: fixed; inset: 0; display: none; }
.screen.active { display: flex; }

/* ===== LOGIN ===== */
#login-screen {
  background: var(--bg);
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}
.login-logo .logo-icon {
  font-size: 48px;
  display: block;
  margin-bottom: 8px;
}
.login-logo h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.5px;
}
.login-logo p {
  color: var(--text2);
  font-size: 14px;
}

/* ===== FORMS ===== */
.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}
.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  border-color: var(--accent);
}
.form-group textarea { resize: vertical; min-height: 80px; }
.form-group input[type="file"] {
  padding: 8px;
  cursor: pointer;
}

/* ===== BUTTONS ===== */
.btn-primary, .btn-secondary, .btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  font-family: inherit;
}
.btn-primary { background: var(--accent); color: #0f1f17; }
.btn-primary:hover { background: #5ec98a; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg3); }
.btn-danger { background: var(--danger-dim); color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover { background: var(--danger); color: white; }
.full-width { width: 100%; }

.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: background 0.2s;
  line-height: 1;
}
.icon-btn:hover { background: var(--surface2); }

/* ===== TOPBAR ===== */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  z-index: 900;
}
.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
}
.topbar-title {
  font-weight: 700;
  font-size: 18px;
  color: var(--accent);
  letter-spacing: -0.3px;
  margin-left: 4px;
}

/* ===== KARTE ===== */
#karte {
  position: fixed;
  top: var(--topbar-h);
  left: 0; right: 0;
  bottom: var(--bottomnav-h);
  z-index: 100;
}

/* ===== LAYER PANEL ===== */
.side-panel {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  bottom: var(--bottomnav-h);
  width: 280px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  z-index: 500;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  overflow: hidden;
}
.side-panel.visible {
  transform: translateX(0);
}
.side-panel.hidden { display: flex; }

.panel-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 15px;
}
.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}
.panel-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
}

.layer-group { margin-bottom: 20px; }
.layer-group-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
  padding-left: 4px;
}
.layer-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 14px;
  transition: background 0.15s;
}
.layer-toggle:hover { background: var(--surface2); }
.layer-toggle input { accent-color: var(--accent); cursor: pointer; }
.layer-icon { font-size: 16px; }
.color-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  display: inline-block;
}
.color-dot.green { background: #4caf78; }
.color-dot.blue { background: #4a90d9; }
.color-dot.orange { background: #e09050; }
.color-dot.yellow { background: #d4c040; }
.color-dot.cyan { background: #40b0d0; }
.color-dot.darkgreen { background: #2d7a4a; }

/* ===== BOTTOM NAV ===== */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bottomnav-h);
  background: var(--bg2);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 900;
}
.nav-btn {
  flex: 1;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text3);
  font-family: inherit;
  position: relative;
  transition: color 0.2s;
}
.nav-btn.active { color: var(--accent); }
.nav-icon { font-size: 20px; line-height: 1; }
.nav-label { font-size: 11px; font-weight: 500; }
.nav-badge {
  position: absolute;
  top: 6px; right: 20%;
  background: var(--danger);
  color: white;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ===== VIEWS ===== */
.view {
  position: fixed;
  top: var(--topbar-h);
  left: 0; right: 0;
  bottom: var(--bottomnav-h);
  overflow-y: auto;
  z-index: 200;
  background: var(--bg);
}
.view.hidden { display: none; }
.view.active { display: block; }

#view-karte { background: transparent; pointer-events: none; }

.view-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  position: sticky;
  top: 0;
  z-index: 10;
}
.view-header h2 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 10px;
}
.filter-row {
  display: flex;
  gap: 8px;
}
.filter-row select {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
}

/* ===== KARTEN-KARTEN ===== */
.card-liste { padding: 12px; display: flex; flex-direction: column; gap: 10px; }

.mangel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  transition: border-color 0.2s;
}
.mangel-card:hover { border-color: var(--accent); }
.mangel-card.kritisch { border-left: 3px solid var(--danger); }
.mangel-card.hoch { border-left: 3px solid var(--warn); }
.mangel-card.mittel { border-left: 3px solid var(--accent); }
.mangel-card.niedrig { border-left: 3px solid var(--text3); }

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.card-titel { font-weight: 600; font-size: 15px; }
.prio-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 20px;
  white-space: nowrap;
  text-transform: uppercase;
}
.prio-badge.kritisch { background: var(--danger-dim); color: var(--danger); }
.prio-badge.hoch { background: var(--warn-dim); color: var(--warn); }
.prio-badge.mittel { background: var(--accent-dim); color: var(--accent); }
.prio-badge.niedrig { background: var(--surface2); color: var(--text2); }

.card-meta { font-size: 13px; color: var(--text2); }
.card-ueberfaellig { color: var(--danger); font-size: 12px; font-weight: 600; margin-top: 4px; }

/* ===== MODALS ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 1500;
  display: flex;
  align-items: flex-end;
  padding: 0;
}
.modal.hidden { display: none; }

.modal-content {
  background: var(--bg2);
  border-radius: var(--radius) var(--radius) 0 0;
  border-top: 1px solid var(--border);
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}
.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}
.modal-footer button { flex: 1; }

.close-btn {
  background: none;
  border: none;
  color: var(--text2);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}
.close-btn:hover { color: var(--text); }

/* ===== OBJEKT DETAIL ===== */
.objekt-detail-typ {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent-dim);
  color: var(--accent);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 16px;
}
.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.detail-row:last-child { border-bottom: none; }
.detail-label { color: var(--text2); }
.detail-value { font-weight: 500; text-align: right; }
.wartung-ueberfaellig { color: var(--danger) !important; }

/* ===== PROFIL ===== */
.profil-box {
  padding: 20px;
}
.profil-name {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
}
.profil-rolle {
  display: inline-flex;
  background: var(--accent-dim);
  color: var(--accent);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ===== LEAFLET OVERRIDES ===== */
.leaflet-container { background: var(--bg2); }
.leaflet-popup-content-wrapper {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.leaflet-popup-tip { background: var(--surface); }
.leaflet-popup-content { margin: 12px 14px; }

/* ===== UTILS ===== */
.hidden { display: none !important; }
.error-msg {
  color: var(--danger);
  font-size: 13px;
  margin-top: 10px;
  text-align: center;
}
.hint-box {
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 16px;
}
.coords-display {
  font-size: 12px;
  color: var(--text3);
  padding: 8px;
  background: var(--bg3);
  border-radius: var(--radius-sm);
  font-family: monospace;
}
.foto-preview img {
  width: 100%;
  border-radius: var(--radius-sm);
  margin-top: 8px;
  max-height: 200px;
  object-fit: cover;
}

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: calc(var(--bottomnav-h) + 16px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  z-index: 2000;
  box-shadow: var(--shadow);
  white-space: nowrap;
}
.toast.success { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.toast.error { background: var(--danger-dim); border-color: var(--danger); color: var(--danger); }

/* ===== CUSTOM MARKER ===== */
.bauhof-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid rgba(255,255,255,0.3);
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.bauhof-marker .inner {
  transform: rotate(45deg);
  font-size: 16px;
  line-height: 1;
}
.marker-bank { background: #4a7c59; }
.marker-muell { background: #5a5a2a; }
.marker-schacht { background: #3a4a5a; }
.marker-laterne { background: #7a6a20; }
.marker-spielgeraet { background: #6a3a7a; }
.marker-sonstiges { background: #4a4a4a; }

/* ===== FAB ===== */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(var(--bottomnav-h) + 20px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #0f1f17;
  font-size: 28px;
  font-weight: 300;
  border: none;
  cursor: pointer;
  z-index: 1200;
  box-shadow: 0 4px 16px rgba(76,175,120,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
  line-height: 1;
}
.fab:hover { transform: scale(1.08); box-shadow: 0 6px 24px rgba(76,175,120,0.5); }
.fab:active { transform: scale(0.95); }

/* ===== KARTEN-CONTROLS ===== */
.karten-controls {
  position: fixed;
  left: 12px;
  bottom: calc(var(--bottomnav-h) + 20px);
  z-index: 1200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.karten-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  transition: background 0.2s;
}
.karten-btn:hover { background: var(--surface2); }
.karten-btn.active { border-color: var(--accent); color: var(--accent); }

/* ===== LIVE STANDORT ===== */
.standort-marker {
  position: relative;
  width: 20px;
  height: 20px;
}
.standort-dot {
  width: 14px;
  height: 14px;
  background: #4a90d9;
  border: 2px solid white;
  border-radius: 50%;
  position: absolute;
  top: 3px; left: 3px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}
.standort-pulse {
  width: 20px;
  height: 20px;
  background: rgba(74,144,217,0.3);
  border-radius: 50%;
  position: absolute;
  top: 0; left: 0;
  animation: pulse 2s ease-out infinite;
}
@keyframes pulse {
  0% { transform: scale(0.5); opacity: 1; }
  100% { transform: scale(2.5); opacity: 0; }
}

/* Objekt-Foto beim Anlegen */
.objekt-foto-preview img {
  width: 100%;
  border-radius: var(--radius-sm);
  margin-top: 8px;
  max-height: 180px;
  object-fit: cover;
}

/* ===== LAYER DROPDOWN ===== */
.layer-dropdown {
  position: fixed;
  left: 12px;
  bottom: calc(var(--bottomnav-h) + 72px);
  width: 220px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 700;
  padding: 12px;
  max-height: 70vh;
  overflow-y: auto;
}
.layer-dropdown.hidden { display: none; }

.layer-dropdown-header {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.layer-section-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 6px;
}
.layer-dropdown .layer-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  cursor: pointer;
  border-radius: 6px;
  font-size: 13px;
  transition: background 0.15s;
}
.layer-dropdown .layer-toggle:hover { background: var(--surface2); }
.layer-dropdown .layer-toggle input { accent-color: var(--accent); cursor: pointer; }
.layer-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.layer-dot.green { background: #4caf78; }
.layer-dot.blue { background: #4a90d9; }
.layer-dot.orange { background: #e09050; }
.layer-dot.yellow { background: #d4c040; }
.layer-dot.cyan { background: #40b0d0; }
.layer-dot.darkgreen { background: #2d7a4a; }

/* ===== KARTEN KONTEXTMENÜ ===== */
.karten-kontextmenu {
  position: fixed;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 2000;
  min-width: 200px;
  overflow: hidden;
}
.kontextmenu-item {
  padding: 10px 14px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s;
  display: flex;
  align-items: center;
  gap: 8px;
}
.kontextmenu-item:hover { background: var(--surface2); }
.kontextmenu-item:not(:last-child) { border-bottom: 1px solid var(--border); }
.kontextmenu-item:last-child { color: var(--text3); font-size: 11px; font-family: monospace; cursor: default; }
.kontextmenu-item:last-child:hover { background: none; }

/* ===== KARTENTYP DROPDOWN ===== */
.kartentyp-dropdown {
  position: fixed;
  left: 12px;
  bottom: calc(var(--bottomnav-h) + 120px);
  width: 200px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 1200;
  overflow: hidden;
}
.kartentyp-dropdown.hidden { display: none; }
.kartentyp-titel {
  font-size: 11px;
  font-weight: 700;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 10px 12px 6px;
}
.kartentyp-option {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
  border-top: 1px solid var(--border);
}
.kartentyp-option:hover { background: var(--surface2); }
.kartentyp-option.active { color: var(--accent); background: var(--accent-dim); }

/* Höhenlinien Tooltip */
.hoehen-tooltip {
  background: rgba(30,50,40,0.85);
  border: 1px solid #8B4513;
  color: #e8c89a;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
}

/* ===== MANGEL-RING (roter Rand bei offenem Mangel) ===== */
.mangel-ring {
  box-shadow: 0 0 0 3px #e05555, 0 0 8px rgba(224,85,85,0.6);
  animation: mangel-pulse 2s ease-in-out infinite;
}
@keyframes mangel-pulse {
  0%, 100% { box-shadow: 0 0 0 3px #e05555, 0 0 8px rgba(224,85,85,0.4); }
  50% { box-shadow: 0 0 0 4px #e05555, 0 0 14px rgba(224,85,85,0.8); }
}

/* ===== OBJEKT BEARBEITEN MODAL ===== */
.edit-section {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.edit-section:last-child { border-bottom: none; }
.edit-section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 10px;
}
