:root {
  --bg: #eef2f7;
  --panel-bg: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --header-bg: #0f172a;
  --accent: #2563eb;
  --green: #4d7c0f;
  --green-dark: #3f6b0a;
  --radius-sm: 8px;
  --radius-md: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 1px rgba(15, 23, 42, .04);
  --shadow-md: 0 10px 30px rgba(15, 23, 42, .18);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}
input[type="checkbox"] { accent-color: var(--green); width: 17px; height: 17px; flex-shrink: 0; }

#app { position: relative; height: 100dvh; overflow: hidden; }

/* --- Full-width glass header (blur fades out at the bottom, no hard edge) --- */
header {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  padding: calc(12px + var(--safe-top)) 16px 14px;
  color: #fff;
}
header::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0; bottom: -20px;
  z-index: -1;
  background: linear-gradient(to bottom, rgba(15, 23, 42, .58) 0%, rgba(15, 23, 42, .34) 55%, rgba(15, 23, 42, 0) 100%);
  backdrop-filter: blur(14px) saturate(145%);
  -webkit-backdrop-filter: blur(14px) saturate(145%);
  -webkit-mask-image: linear-gradient(to bottom, #000 52%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 52%, transparent 100%);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-logo {
  width: 46px; height: 46px;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 1px 4px rgba(0, 0, 0, .55));
}
.brand-text { min-width: 0; }
.brand-text h1 {
  font-size: 15.5px; margin: 0; font-weight: 700; letter-spacing: .01em;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .45);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.subtitle {
  display: block; font-size: 11px; margin-top: 1px;
  color: rgba(255, 255, 255, .82);
  text-shadow: 0 1px 2px rgba(0, 0, 0, .4);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
@media (max-width: 400px) { .subtitle { display: none; } }

/* --- Layout --- */
#main { position: absolute; inset: 0; }
#map { position: absolute; inset: 0; height: 100%; }

/* keep Leaflet top controls clear of the floating header */
.leaflet-top { top: calc(74px + var(--safe-top)); }

/* --- Sidebar: mobile bottom sheet by default --- */
#sidebar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 1200;
  background: var(--panel-bg);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow-md);
  max-height: 72vh;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.32, .72, 0, 1);
  padding-bottom: var(--safe-bottom);
}
#sidebar.open { transform: translateY(0); }

.sheet-handle { flex-shrink: 0; padding: 10px 16px 8px; cursor: pointer; }
.handle-bar { display: block; width: 42px; height: 5px; border-radius: 3px; background: #cbd5e1; margin: 0 auto 12px; }
.sheet-title-row { display: flex; align-items: center; justify-content: space-between; }
.sheet-title-row h2 { margin: 0; font-size: 16px; font-weight: 700; }
#sidebar-close {
  border: none; background: #f1f5f9; color: var(--text-muted);
  width: 32px; height: 32px; border-radius: 50%; font-size: 15px; cursor: pointer;
}
#sidebar-close:active { background: #e2e8f0; }

.layer-list { flex: 1; overflow-y: auto; padding: 6px 14px 18px; -webkit-overflow-scrolling: touch; }

/* --- FAB (mobile) --- */
#sidebar-fab {
  position: absolute;
  right: 14px;
  bottom: calc(16px + var(--safe-bottom));
  z-index: 1150;
  display: flex; align-items: center; gap: 7px;
  background: var(--header-bg); color: #fff;
  border: none; border-radius: 999px;
  padding: 13px 20px;
  font-size: 14px; font-weight: 600;
  box-shadow: 0 6px 20px rgba(15, 23, 42, .35);
  cursor: pointer;
  transition: transform .12s ease;
}
#sidebar-fab:active { transform: scale(.95); }
#sidebar.open ~ #sidebar-fab { display: none; }

/* --- Category / layer list --- */
.cat-block {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 11px 13px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
}
.cat-header { display: flex; align-items: center; gap: 11px; font-weight: 600; font-size: 14.5px; cursor: pointer; min-height: 32px; }
.swatch {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%; font-size: 14px; flex-shrink: 0;
  box-shadow: 0 0 0 2px #fff, 0 0 0 3px rgba(0, 0, 0, .06);
}
.sub-list { margin: 8px 0 0 39px; display: flex; flex-direction: column; gap: 2px; }
.sub-item {
  font-size: 13.5px; color: var(--text); display: flex; align-items: center; gap: 9px;
  cursor: pointer; font-weight: 400; padding: 7px 6px; border-radius: 8px; min-height: 34px;
}
.sub-item:active { background: #f1f5f9; }
@media (hover: hover) { .sub-item:hover { background: #f8fafc; } }
.dot { width: 11px; height: 11px; border-radius: 50%; flex-shrink: 0; box-shadow: 0 0 0 2px rgba(0, 0, 0, .05); }

/* --- Coordinate readout --- */
.coord-readout {
  background: rgba(15, 23, 42, .8);
  color: #e2e8f0;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
  font-family: "Consolas", monospace;
  margin: 0 0 8px 8px;
}
@media (max-width: 600px) { .coord-readout { display: none; } }

/* --- Markers: glowing category-colored dot --- */
.pin-icon { background: transparent; border: none; }
.pin-dot {
  --c: #16a34a;
  position: relative;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--c);
  border: 2.5px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .4), 0 0 10px 1px color-mix(in srgb, var(--c) 55%, transparent);
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s ease;
}
.pin-dot::after {
  content: "";
  position: absolute;
  top: 3px; left: 5px;
  width: 8px; height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .45);
  filter: blur(1px);
}
.pin-glyph { position: relative; z-index: 2; font-size: 13px; line-height: 1; }
.pin-pulse {
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 2px solid var(--c);
  opacity: .6;
  animation: pinpulse 2.4s ease-out infinite;
}
@keyframes pinpulse {
  0% { transform: scale(.65); opacity: .55; }
  70% { transform: scale(1.9); opacity: 0; }
  100% { transform: scale(1.9); opacity: 0; }
}
.leaflet-marker-icon:hover .pin-dot { transform: scale(1.18); }
@media (prefers-reduced-motion: reduce) { .pin-pulse { animation: none; } }

/* --- Label area (RT) --- */
.area-label { background: transparent; border: none; display: flex; align-items: center; justify-content: center; }
.area-label span {
  font-size: 12px;
  font-weight: 700;
  color: #1e293b;
  background: rgba(255, 255, 255, .82);
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  text-shadow: 0 1px 1px rgba(255, 255, 255, .6);
}

/* --- Popups --- */
.leaflet-popup-content-wrapper { border-radius: var(--radius-md); box-shadow: var(--shadow-md); }
.leaflet-popup-content { margin: 12px 14px; }
.popup { width: 220px; max-width: 62vw; }
.pp-photo {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 10px;
  overflow: hidden;
  background: #eef2f7;
  margin-bottom: 10px;
}
.pp-photo-placeholder {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: #94a3b8; font-size: 11.5px; text-align: center;
}
.pp-photo-icon { font-size: 24px; }
.pp-photo img {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: cover;
}
.popup h3 { margin: 0 0 6px; font-size: 14.5px; color: var(--text); }
.pp-row { font-size: 12.5px; margin: 2px 0; color: var(--text-muted); }
.popup .pp-directions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 10px;
  padding: 9px 10px;
  background: var(--green);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  border-radius: 9px;
  box-shadow: 0 2px 8px rgba(77, 124, 15, .38);
  transition: background .15s ease, transform .12s ease;
}
.popup .pp-directions:hover { background: var(--green-dark); color: #fff; }
.popup .pp-directions:active { transform: scale(.97); }

/* --- Desktop layout --- */
@media (min-width: 860px) {
  #sidebar {
    position: absolute;
    top: 0; left: 0; bottom: 0; right: auto;
    width: 330px;
    max-height: none;
    height: 100%;
    border-radius: 0;
    border-right: 1px solid var(--border);
    box-shadow: 2px 0 16px rgba(15, 23, 42, .06);
    transform: none !important;
    background: #f8fafc;
    z-index: 1050;
  }
  .handle-bar, #sidebar-close { display: none; }
  .sheet-handle { cursor: default; padding: 18px 18px 6px; }
  .sheet-title-row h2 { text-transform: uppercase; letter-spacing: .05em; font-size: 12.5px; color: var(--text-muted); }
  .layer-list { padding: 6px 16px 18px; }

  /* map + glass header sit to the right of the sidebar */
  #map { left: 330px; }
  header { left: 330px; right: 0; }
  .leaflet-top { top: calc(74px + var(--safe-top)); }

  #sidebar-fab { display: none; }
}
