/* ============================================================
   Sonitrace Stadtatlas Darmstadt - UI
   ============================================================ */

:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --border: #e3e6ec;
  --border-strong: #c8cdd5;
  --text: #15181d;
  --text-soft: #58606b;
  --text-mute: #8a92a0;
  --accent: #2d6cdf;
  --accent-soft: #e7efff;
  --accent-strong: #1f4fb5;
  --warn: #d36a1f;
  --warn-soft: #fdf0e2;
  --shadow-sm: 0 1px 2px rgba(15, 22, 33, 0.05);
  --shadow-md: 0 4px 16px rgba(15, 22, 33, 0.08);
  --radius: 8px;
  --radius-sm: 5px;
  --sidebar-w: 360px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", system-ui,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

body {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-areas: "side map";
  height: 100vh;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */

#sidebar {
  grid-area: side;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
  z-index: 1000;
}

.sidebar-header {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.sidebar-header h1 span { color: var(--accent); font-weight: 500; }
.sidebar-header .subtitle {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--text-mute);
}

/* ---------- Suchfeld ---------- */

.search-wrap {
  position: relative;
  padding: 12px 16px 8px;
}
#search {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  font-size: 14px;
  outline: none;
  transition: border-color 120ms, background 120ms;
}
#search:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
#search-results {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  max-height: 260px;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  position: absolute;
  left: 16px; right: 16px; top: 100%;
  z-index: 10;
  display: none;
}
#search-results.open { display: block; }
#search-results li {
  padding: 9px 12px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
#search-results li:last-child { border-bottom: none; }
#search-results li:hover, #search-results li.focus { background: var(--accent-soft); }
#search-results li .meta { display: block; font-size: 11px; color: var(--text-mute); margin-top: 2px; }
#search-results li.empty { color: var(--text-mute); cursor: default; }

/* ---------- Active-Bar ---------- */

.active-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 12px;
  color: var(--text-mute);
  border-bottom: 1px solid var(--border);
}
.active-bar #active-count {
  font-weight: 600;
  color: var(--accent);
  padding: 1px 8px;
  background: var(--accent-soft);
  border-radius: 999px;
}
.active-bar.warn #active-count { color: var(--warn); background: var(--warn-soft); }
.active-bar #clear-active {
  margin-left: auto;
  font-size: 11px;
  background: none;
  border: 1px solid var(--border-strong);
  color: var(--text-soft);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.active-bar #clear-active:hover { background: var(--surface-2); }

/* ---------- Layer-Baum ---------- */

#layer-tree {
  flex: 1;
  overflow: auto;
  padding: 8px 0 12px;
}

.group {
  border-bottom: 1px solid var(--border);
}
.group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 16px;
  background: none;
  border: none;
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.group-head:hover { background: var(--surface-2); }
.group-head .chev {
  transition: transform 160ms;
  color: var(--text-mute);
  font-size: 11px;
  width: 12px;
  display: inline-block;
}
.group.open .group-head .chev { transform: rotate(90deg); }
.group-head .group-count {
  margin-left: auto;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-mute);
}
.group-body { display: none; padding: 2px 0 8px; }
.group.open .group-body { display: block; }

.layer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px 6px 32px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.layer-row:hover { background: var(--surface-2); }
.layer-row input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
}
.layer-row .layer-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.layer-row.active { background: var(--accent-soft); }
.layer-row .layer-count {
  font-size: 11px;
  color: var(--text-mute);
  background: var(--surface-2);
  padding: 0 6px;
  border-radius: 999px;
  flex-shrink: 0;
}
.layer-row.active .layer-count {
  background: var(--accent);
  color: white;
}
.layer-row .layer-info {
  font-size: 11px;
  color: var(--text-mute);
  cursor: help;
  width: 16px;
  text-align: center;
}
.layer-row .layer-info.warn { color: var(--warn); font-weight: 700; }
.layer-row .layer-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ---------- Footer ---------- */

.sidebar-footer {
  padding: 10px 16px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.sidebar-footer p {
  margin: 0;
  font-size: 11px;
  color: var(--text-mute);
  line-height: 1.5;
}
.sidebar-footer button {
  margin-top: 6px;
  font-size: 11px;
  background: none;
  border: 1px solid var(--border-strong);
  color: var(--text-soft);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.sidebar-footer button:hover { background: var(--surface); }

/* ---------- Map ---------- */

#map-wrap {
  grid-area: map;
  position: relative;
}
#map { width: 100%; height: 100%; background: #e3e8ee; }

#toggle-sidebar, #geolocate {
  position: absolute;
  z-index: 999;
  width: 38px;
  height: 38px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: 16px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  color: var(--text);
}
#toggle-sidebar { top: 12px; left: 12px; display: none; }
#geolocate { bottom: 24px; right: 12px; }
#toggle-sidebar:hover, #geolocate:hover { background: var(--surface-2); }

/* ---------- Modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 22, 33, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 24px;
}
.modal[hidden] { display: none; }
.modal-inner {
  background: var(--surface);
  border-radius: var(--radius);
  max-width: 640px;
  width: 100%;
  max-height: 80vh;
  overflow: auto;
  padding: 24px;
  position: relative;
  box-shadow: var(--shadow-md);
}
.modal-inner h2 { margin: 0 0 12px; font-size: 18px; }
.modal-inner h3 { margin: 16px 0 4px; font-size: 14px; }
.modal-inner p { margin: 4px 0; font-size: 13px; line-height: 1.5; }
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-mute);
  line-height: 1;
}
.modal-close:hover { color: var(--text); }
.license-block {
  padding: 10px 12px;
  margin-top: 8px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent);
}
.license-block.warn { border-left-color: var(--warn); background: var(--warn-soft); }
.license-block a { color: var(--accent); }

/* ---------- Popup-Styling ---------- */

.leaflet-popup-content-wrapper {
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow-md);
  font-family: inherit;
}
.leaflet-popup-content {
  margin: 12px 14px !important;
  font-size: 13px;
  line-height: 1.5;
}
.popup-name {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 6px;
}
.popup-meta {
  font-size: 11px;
  color: var(--text-mute);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.popup-meta .src-pill {
  display: inline-block;
  padding: 1px 6px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-radius: 999px;
  text-transform: none;
  letter-spacing: 0;
}
.popup-meta .src-pill.warn { background: var(--warn-soft); color: var(--warn); }
.popup-fields { margin: 0; padding: 0; list-style: none; }
.popup-fields li { font-size: 12px; padding: 1px 0; color: var(--text-soft); }
.popup-fields li b { color: var(--text); font-weight: 500; }
.popup-link { font-size: 12px; color: var(--accent); display: inline-block; margin-top: 6px; }

/* ---------- Toast ---------- */

#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: var(--shadow-md);
  z-index: 2500;
  opacity: 0;
  transition: opacity 200ms;
}
#toast.show { opacity: 1; }

/* ---------- Cluster-Style override ---------- */

.marker-cluster-small {
  background-color: rgba(45, 108, 223, 0.25);
}
.marker-cluster-small div { background-color: rgba(45, 108, 223, 0.7); color: white; }
.marker-cluster-medium {
  background-color: rgba(45, 108, 223, 0.3);
}
.marker-cluster-medium div { background-color: rgba(45, 108, 223, 0.8); color: white; }
.marker-cluster-large {
  background-color: rgba(31, 79, 181, 0.35);
}
.marker-cluster-large div { background-color: rgba(31, 79, 181, 0.9); color: white; }

/* ---------- Mobil ---------- */

@media (max-width: 768px) {
  body {
    grid-template-columns: 1fr;
    grid-template-areas: "map";
  }
  #sidebar {
    position: fixed;
    inset: 0 0 0 0;
    transform: translateX(-100%);
    transition: transform 240ms ease;
    width: 100%;
    max-width: 360px;
    box-shadow: var(--shadow-md);
  }
  body.sidebar-open #sidebar { transform: translateX(0); }
  #toggle-sidebar { display: block; }
}
