:root {
  --sidebar-width: 320px;
  --accent: #0b6e99;
  --bg: #f7f8fa;
  --border: #dfe3e8;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; font-family: 'Segoe UI', Roboto, Arial, sans-serif; color: #1f2933; }

#app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: 56px 1fr;
  grid-template-areas:
    "topbar topbar"
    "sidebar map";
  height: 100vh;
}

#topbar {
  grid-area: topbar;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
}
#topbar h1 { font-size: 16px; font-weight: 600; margin: 0; }

#sidebar {
  grid-area: sidebar;
  background: #ffffff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
}

#sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 16px 16px;
}

.panel {
  border-bottom: 1px solid var(--border);
  padding-bottom: 16px;
  margin-bottom: 16px;
}
.panel h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: #616e7c; margin: 0 0 10px 0; }
.panel label { display: block; font-size: 14px; margin-bottom: 6px; }
.panel select { width: 100%; padding: 6px; border-radius: 6px; border: 1px solid var(--border); margin-bottom: 4px; }
.panel input[type="number"] { width: 100%; padding: 6px; border-radius: 6px; border: 1px solid var(--border); font-size: 14px; }

#kpi-list { margin: 0; }
#kpi-list dt { font-size: 12px; color: #616e7c; margin-top: 8px; }
#kpi-list dd { font-size: 18px; font-weight: 600; margin: 0; color: var(--accent); line-height: 1.3; }

#coverage-kpi-list dt { font-size: 12px; color: #616e7c; margin-top: 8px; }
#coverage-kpi-list dd { font-size: 24px; font-weight: 700; margin: 0; color: #a50f15; }
input[type="range"] { width: 100%; margin: 6px 0 12px 0; }

#map { grid-area: map; position: relative; }

#legend {
  position: absolute;
  bottom: 24px;
  left: calc(var(--sidebar-width) + 24px);
  background: rgba(255,255,255,0.95);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  z-index: 10;
}
#legend h3 { font-size: 12px; margin: 0 0 6px 0; }
#legend-gradient {
  width: 180px;
  height: 10px;
  border-radius: 5px;
  background: linear-gradient(to right, #fee5d9, #fcae91, #fb6a4a, #de2d26, #a50f15);
}
#legend-labels { display: flex; justify-content: space-between; font-size: 11px; color: #616e7c; margin-top: 2px; }

/* Picker-Widget (Klinik-/Regions-Auswahl) */
.picker-group { border: 1px solid var(--border); border-radius: 6px; margin-bottom: 6px; padding: 6px 8px; }
.picker-group summary { cursor: pointer; font-size: 13px; font-weight: 500; list-style: none; display: flex; align-items: center; gap: 6px; }
.picker-group summary::-webkit-details-marker { display: none; }
.picker-items { margin-top: 6px; padding-left: 20px; max-height: 220px; overflow-y: auto; }
.picker-item { display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 2px 0; }
.picker-scroll { max-height: 340px; overflow-y: auto; }
.slider-value { font-size: 12px; color: var(--accent); font-weight: 600; }

/* Landing-Page-Navigation */
#nav-landing { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: calc(100vh - 40px); gap: 24px; background: var(--bg); }
#nav-landing h1 { font-size: 22px; margin: 0; }
.nav-cards { display: flex; gap: 20px; }
.nav-card {
  display: block; width: 260px; padding: 24px; border-radius: 10px; border: 1px solid var(--border);
  background: #fff; text-decoration: none; color: #1f2933; box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.nav-card h2 { font-size: 16px; margin: 0 0 8px 0; color: var(--accent); }
.nav-card p { font-size: 13px; color: #616e7c; margin: 0; }
.lang-note { font-size: 12px; color: #9aa5b1; margin-top: 8px; }

#topbar nav { margin-left: auto; }
#topbar nav a { color: var(--accent); text-decoration: none; font-size: 13px; margin-left: 16px; }
#topbar nav a.active { font-weight: 700; }
#topbar nav a.lang-nav-btn {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2px 8px;
  font-weight: 700;
  margin-left: 12px;
}

#recalc-button {
  flex-shrink: 0;
  width: calc(100% - 32px);
  margin: 16px;
  padding: 10px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: #dfe3e8;
  color: #616e7c;
}
#recalc-button.dirty {
  background: var(--accent);
  color: #fff;
  animation: pulse 1.4s ease-in-out infinite;
}
#recalc-button:disabled { cursor: default; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.75; } }

.picker-hint { font-size: 11px; color: #616e7c; margin: 0 0 8px 0; line-height: 1.4; }

/* Lade-Overlay über der Karte */
#loading-overlay {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(31, 41, 51, 0.9);
  color: #fff;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  display: none;
  align-items: center;
  gap: 8px;
  z-index: 20;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
#loading-overlay.visible { display: flex; }

#loading-dim {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.5);
  z-index: 15;
  display: none;
}
#loading-dim.visible { display: block; }

#loading-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Impressum/Datenschutz */
#legal-page { min-height: 100vh; background: var(--bg); }
#legal-page #topbar { position: sticky; top: 0; z-index: 5; }
.legal-content { max-width: 720px; margin: 0 auto; padding: 32px 20px 60px 20px; line-height: 1.6; }
.legal-content h2 { font-size: 16px; margin: 28px 0 8px 0; color: var(--accent); }
.legal-content h2:first-child { margin-top: 0; }
.legal-content p, .legal-content ul { font-size: 14px; color: #1f2933; }
.legal-content a { color: var(--accent); }

#footer-legal { text-align: center; padding: 16px; font-size: 12px; color: #616e7c; }
#footer-legal a { color: #616e7c; margin: 0 8px; }

/* Impressum/Datenschutz-Modal */
#legal-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#legal-modal-overlay.visible { display: flex; }
#legal-modal {
  background: #ffffff;
  border-radius: 10px;
  max-width: 720px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
  padding: 36px 24px 24px 24px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
}
#legal-modal-close {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  color: #616e7c;
}
#legal-modal-close:hover { color: #1f2933; }
#legal-modal-body { line-height: 1.6; }
#legal-modal-body h2 { font-size: 16px; margin: 24px 0 8px 0; color: var(--accent); }
#legal-modal-body h2:first-child { margin-top: 0; }
#legal-modal-body p, #legal-modal-body ul { font-size: 14px; color: #1f2933; }
#legal-modal-body a { color: var(--accent); }

/* Karten-Umschalter (Beschriftungen, Klinik-Symbole) */
#map-controls {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 10;
  background: rgba(255, 255, 255, 0.95);
  padding: 8px 12px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#map-controls label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  margin: 0;
}

/* Sprachumschalter (nur Landing-Page) */
#lang-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 4px;
  background: #ffffff;
  border-radius: 20px;
  padding: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  z-index: 10;
}
.lang-btn {
  padding: 4px 12px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  color: #616e7c;
}
.lang-btn.active { background: var(--accent); color: #ffffff; }
