:root {
  /* Green palette: Deep Teal / Sea Green / Medium Jungle / Moss / Lemon Lime */
  --green: #4aad52; /* Medium Jungle — primary buttons */
  --green-dark: #507255; /* Deep Teal — headings, hover, strong text */
  --accent: #c5e063; /* Lemon Lime — focus rings / highlights */
  --ink: #28392f;
  --muted: #5b6b60;
  --line: #e2e7e3;
  --sidebar-width: 340px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}

/* Visually hidden but available to screen readers and crawlers. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---- Layout: sidebar + map ---- */
.app {
  display: flex;
  height: 100vh;
  width: 100%;
}

#map {
  flex: 1 1 auto;
  height: 100%;
}

.sidebar {
  flex: 0 0 var(--sidebar-width);
  width: var(--sidebar-width);
  height: 100%;
  overflow-y: auto;
  background: #fff;
  border-right: 1px solid var(--line);
  box-shadow: 2px 0 12px rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px;
  z-index: 2;
}

/* ---- Header ---- */
.sidebar-header h1 {
  margin: 0 0 6px;
  font-size: 20px;
  color: var(--green-dark);
}
.subtitle {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

/* ---- Panels ---- */
.panel {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}
.panel h2 {
  margin: 0 0 12px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

/* ---- Form fields ---- */
.field {
  display: block;
  border: 0;
  margin: 0 0 14px;
  padding: 0;
}
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 5px;
}
.field select,
.field input {
  width: 100%;
  height: 38px;
  padding: 0 10px;
  font-size: 14px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.field select:focus,
.field input:focus,
.btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
}

/* Tree search with auto-suggest */
.tree-search-field {
  position: relative;
}
.tree-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 20;
  margin: 4px 0 0;
  padding: 4px;
  list-style: none;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
  max-height: 264px;
  overflow-y: auto;
}
.tree-suggestions[hidden] {
  display: none;
}
.tree-suggestion {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.tree-suggestion:hover,
.tree-suggestion.is-active {
  background: #f1f6ee;
}
.ts-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}
.ts-sub {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--muted);
}

.year-field {
  margin-bottom: 14px;
}
.year-inputs {
  display: flex;
  align-items: center;
  gap: 8px;
}
.year-inputs input {
  width: 100%;
  text-align: center;
}

/* ---- Buttons ---- */
.actions {
  display: flex;
  gap: 8px;
}
.btn {
  flex: 1;
  height: 38px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
}
.btn-primary {
  background: var(--green);
  color: #fff;
}
.btn-primary:hover {
  background: var(--green-dark);
}
.btn-secondary {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}
.btn-secondary:hover {
  background: #f4f6f4;
}

/* ---- Collections (theme chips) ---- */
.collections {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.collection-chip {
  font-size: 13px;
  font-weight: 600;
  color: var(--green-dark);
  background: #f1f6ee;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.collection-chip:hover {
  background: #e8f1e6;
}
.collection-chip.is-active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}
.collection-chip:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
}

/* Treasure map toggle */
.treasure-btn {
  width: 100%;
  margin-top: 12px;
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 600;
  color: #6b4a00;
  background: linear-gradient(#fff7e0, #ffeeb8);
  border: 1px solid #e8cf8a;
  border-radius: 10px;
  cursor: pointer;
  transition: filter 0.12s;
}
.treasure-btn:hover {
  filter: brightness(0.97);
}
.treasure-btn.is-active {
  color: #fff;
  background: linear-gradient(#f4b400, #e09b00);
  border-color: #c98a00;
  box-shadow: 0 2px 8px rgba(224, 155, 0, 0.4);
}
.treasure-btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
}

/* Curiosities — expandable clickable list */
.curiosities {
  margin-top: 12px;
}
.curiosities summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--green-dark);
  background: #f1f6ee;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.curiosities summary::-webkit-details-marker {
  display: none;
}
.curiosities summary::after {
  content: "▸";
  float: right;
  color: var(--muted);
}
.curiosities[open] summary::after {
  content: "▾";
}
.curiosities summary:hover {
  background: #e8f1e6;
}
.curiosities-hint {
  margin: 10px 2px 6px;
  font-size: 11.5px;
  color: var(--muted);
}
.curiosities-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.curio-item {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  font-size: 13px;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
}
.curio-item:hover {
  background: #f1f6ee;
}
.curio-name {
  font-weight: 600;
}
.curio-count {
  flex: 0 0 auto;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

/* ---- Legend ---- */
.legend {
  font-size: 13px;
  line-height: 1.6;
}
.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.legend-swatch {
  display: inline-block;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  flex: 0 0 auto;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
}

/* ---- Tree popup ---- */
.maplibregl-popup-content {
  padding: 12px 30px 14px 14px;
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  max-width: 250px;
}
.tree-popup {
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink);
}
.tp-title {
  display: inline-block;
  font-size: 15px;
  font-weight: 700;
  color: var(--green-dark);
  text-decoration: none;
}
.tp-title:hover {
  text-decoration: underline;
}
.tp-lat {
  color: var(--muted);
  margin-top: 1px;
}
.tp-meta {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}
.tp-desc {
  margin: 9px 0 0;
}
.tp-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 10px;
}
.tp-tag {
  font-size: 11px;
  font-weight: 600;
  color: var(--green-dark);
  background: #e8f1e6;
  border-radius: 999px;
  padding: 2px 9px;
}
.maplibregl-popup-close-button {
  font-size: 18px;
  width: 24px;
  color: var(--muted);
}
.tp-event {
  margin-top: 11px;
  padding: 9px 10px;
  background: #f1f6ee;
  border-radius: 8px;
}
.tp-event-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--green-dark);
}
.tp-event-text {
  margin-top: 3px;
  font-size: 13px;
  line-height: 1.4;
}
.tp-event-link {
  display: inline-block;
  margin-top: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--green);
  text-decoration: none;
}
.tp-event-link:hover {
  text-decoration: underline;
}

/* ---- Footer ---- */
.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}
.tree-count {
  display: block;
  font-size: 15px;
  font-weight: 700;
  color: var(--green-dark);
}
.tree-count:empty {
  display: none;
}
.source {
  margin: 6px 0 0;
  font-size: 11px;
  color: var(--muted);
}
.facts-open-btn {
  width: 100%;
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 700;
  color: var(--green-dark);
  background: #eef6e6;
  border: 1px solid #cfe3bf;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.12s, box-shadow 0.12s;
}
.facts-open-btn:hover {
  background: #e3f0d6;
  box-shadow: 0 2px 8px rgba(74, 173, 82, 0.18);
}
.facts-open-btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
}

/* ---- Zahlen & Trends modal ---- */
.stats-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.stats-modal[hidden] {
  display: none;
}
.stats-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(40, 57, 47, 0.5);
}
.stats-dialog {
  position: relative;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
  width: min(560px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  padding: 24px 26px 28px;
}
.stats-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 32px;
  height: 32px;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
.stats-close:hover {
  background: #f1f6ee;
  color: var(--ink);
}
.stats-h1 {
  margin: 0 0 4px;
  font-size: 22px;
  color: var(--green-dark);
}
.stats-lead {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--muted);
}
.stats-section {
  margin-top: 30px;
  padding-top: 28px;
  border-top: 1px solid var(--line);
}
.stats-section h3 {
  margin: 0 0 14px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.stats-note {
  margin: -4px 0 12px;
  font-size: 12px;
  color: var(--muted);
}

/* Bar charts */
.stat-bars {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.stat-bar-row {
  display: grid;
  grid-template-columns: 92px 1fr auto;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.stat-bar-label {
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat-bar-track {
  background: #eef2ec;
  border-radius: 6px;
  height: 16px;
  overflow: hidden;
}
.stat-bar-fill {
  display: block;
  height: 100%;
  background: var(--green);
  border-radius: 6px;
}
.stat-bar-value {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--green-dark);
}

/* Trends */
.stats-trends {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
}
.stats-trend-head {
  margin: 0 0 8px;
  font-size: 13px;
}
.stats-trend-head.up {
  color: var(--green);
}
.stats-trend-head.down {
  color: #b23b3b;
}
.stat-trend-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.stat-trend-item {
  font-size: 13px;
  line-height: 1.3;
}
.stat-trend-arrow {
  font-size: 10px;
  margin-right: 4px;
}
.stat-trend-item.up .stat-trend-arrow {
  color: var(--green);
}
.stat-trend-item.down .stat-trend-arrow {
  color: #b23b3b;
}
.stat-trend-name {
  font-weight: 600;
}
.stat-trend-change {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-left: 14px;
}
.stat-trend-why {
  display: block;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--ink);
  margin: 3px 0 0 14px;
}

/* Kurioses & Rekorde */
.stats-curios ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 11px;
}
.stats-curios li {
  display: flex;
  gap: 10px;
  font-size: 13px;
  line-height: 1.5;
}
.stat-cur-icon {
  flex: 0 0 auto;
  font-size: 17px;
  line-height: 1.3;
}

/* Wussten Sie? */
.stats-facts ul {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.55;
}
.stats-facts li {
  margin-bottom: 11px;
}

@media (max-width: 760px) {
  .stats-trends {
    grid-template-columns: 1fr;
  }
}

/* ---- Mobile sidebar toggle ---- */
.sidebar-toggle {
  display: none;
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 3;
  height: 38px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: var(--green);
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

/* ---- Responsive: stack on narrow screens ---- */
@media (max-width: 760px) {
  .app {
    flex-direction: column;
  }
  .sidebar-toggle {
    display: block;
  }
  .sidebar {
    flex-basis: auto;
    width: 100%;
    max-height: 70vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding-top: 56px; /* clear the toggle button */
  }
  .sidebar[hidden] {
    display: none;
  }
  #map {
    flex: 1 1 auto;
    min-height: 50vh;
  }
}
