:root {
  --bg: #ffffff;
  --text: #1c2b1f;
  --muted: #5f6f63;
  --accent: #2e7d32;
  --border: rgba(0, 0, 0, 0.08);
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.14);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #eef1ee;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#map { position: fixed; inset: 0; }

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 14px; }

.panel {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  z-index: 1000;
  background: var(--bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  width: 270px;
  max-width: calc(100vw - 24px);
}

.panel h1 {
  font-size: 16px;
  margin: 0 0 10px;
  font-weight: 700;
  color: #1b5e20;
}

.counters { display: flex; gap: 10px; margin-bottom: 8px; }
.counter {
  flex: 1;
  background: #f1f7f1;
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
}
.counter .value { font-size: 26px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.counter .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.status-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-top: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.dot-ok { background: #2e7d32; box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.18); }
.dot-wait { background: #f9a825; }
.dot-err { background: #c62828; box-shadow: 0 0 0 3px rgba(198, 40, 40, 0.18); }
.dot-live { background: #1e88e5; animation: blink 1.6s infinite; }

@keyframes blink { 50% { opacity: 0.35; } }

/* Tree detail card */
.card {
  position: fixed;
  z-index: 1000;
  right: max(12px, env(safe-area-inset-right));
  top: max(12px, env(safe-area-inset-top));
  width: 320px;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  background: var(--bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, 0.9);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  z-index: 2;
}
.card img { width: 100%; display: block; border-radius: var(--radius) var(--radius) 0 0; max-height: 260px; object-fit: cover; background: #ddd; }
.card .content { padding: 14px 16px 16px; }
.card h2 { font-size: 17px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.card dl { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; margin: 0 0 14px; font-size: 14px; }
.card dt { color: var(--muted); }
.card dd { margin: 0; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.badge { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; color: #fff; }

.btn {
  display: block;
  text-align: center;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  padding: 11px 14px;
  border-radius: 10px;
}
.btn:hover { filter: brightness(1.08); }
.card .actions { display: flex; gap: 8px; }
.card .actions .btn { flex: 1; }
.btn.disabled { background: #b8c4ba; pointer-events: none; }

/* Pulsing ring for newly appeared trees */
.pulse { animation: pulse 1.2s ease-out 3; transform-origin: center; transform-box: fill-box; }
@keyframes pulse {
  0% { stroke-width: 2; stroke-opacity: 1; }
  70% { stroke-width: 22; stroke-opacity: 0; }
  100% { stroke-width: 2; stroke-opacity: 1; }
}

.device-label {
  background: #1e88e5;
  color: #fff;
  border: 0;
  border-radius: 6px;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}
.device-label::before { border-top-color: #1e88e5 !important; }

.heading-icon { pointer-events: none; }

@media (max-width: 640px) {
  .panel { width: auto; right: 12px; padding: 10px 12px; }
  .panel h1 { font-size: 15px; margin-bottom: 8px; }
  .counter .value { font-size: 22px; }
  .card {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 70vh;
    border-radius: var(--radius) var(--radius) 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .leaflet-bottom.leaflet-right { margin-bottom: env(safe-area-inset-bottom); }
}

/* Soften OSM tiles into a light, low-contrast basemap */
.basemap { filter: grayscale(0.75) brightness(1.06) contrast(0.92); }

/* DBH reliability label in the tree card */
.muted { color: #6b7280; font-weight: 400; }
.quality { display: inline-block; margin-top: 2px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.quality.ok { background: #e3f2e5; color: #1b5e20; }
.quality.warn { background: #fff4d6; color: #8a5a00; }
.quality.bad { background: #fde2e1; color: #a1251b; }

/* Tree card: visual review */
.small { font-size: 12px; }
.obs { margin: 8px 0; font-size: 13px; line-height: 1.4; }
.list-link { display: inline-block; margin: 8px 0 2px; font-weight: 600; color: #1b5e20; text-decoration: none; }
