/* ── Reset & Base ──────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg:        #0f1117;
  --surface:   rgba(18, 20, 30, 0.92);
  --surface2:  rgba(28, 32, 48, 0.95);
  --border:    rgba(255,255,255,0.07);
  --text:      #e8eaf0;
  --muted:     #7a8099;
  --accent:    #4a90d9;
  --green:     #22c55e;
  --orange:    #f59e0b;
  --red:       #ef4444;
  --radius:    14px;
  --blur:      blur(10px);
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ── Map ───────────────────────────────────────────────────────── */
#map {
  position: fixed;
  inset: 0;
  height: 100%;
  width: 100%;
  z-index: 0;
}

/* ── Search Bar ────────────────────────────────────────────────── */
#search-bar {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  align-items: center;
  width: calc(100% - 120px);
  max-width: 540px;
  background: var(--surface);
  backdrop-filter: var(--blur);
  border: 1px solid var(--border);
  border-radius: 50px;
  padding: 6px 6px 6px 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.45);
}

#search-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 15px;
  min-width: 0;
}

#search-input::placeholder { color: var(--muted); }

#search-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.15s;
}

#search-btn:hover { background: #3a7fc0; }
#search-btn:active { transform: scale(0.92); }

/* ── Floating Controls ──────────────────────────────────────────── */
#controls {
  position: fixed;
  top: 80px;
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#controls button {
  width: 46px;
  height: 46px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  backdrop-filter: var(--blur);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 12px rgba(0,0,0,0.35);
  transition: background 0.15s, transform 0.15s;
}

#controls button:hover { background: var(--surface2); }
#controls button:active { transform: scale(0.9); }

/* ── Layer Toggle ──────────────────────────────────────────────── */
.layer-btn {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  background: var(--surface);
  backdrop-filter: var(--blur);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  box-shadow: 0 2px 12px rgba(0,0,0,0.35);
  user-select: none;
  transition: background 0.15s;
}

.layer-btn:hover { background: var(--surface2); }

.layer-btn .chevron {
  transition: transform 0.2s;
}

.layer-btn.open .chevron {
  transform: rotate(180deg);
}

#layer-indicator {
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#layer-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--surface2);
  backdrop-filter: var(--blur);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
  min-width: 260px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.layer-menu.hidden { display: none; }

.layer-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.12s;
}

.layer-menu-item:hover { background: rgba(255,255,255,0.06); }

.layer-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.layer-menu-info { flex: 1; min-width: 0; }

.layer-menu-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.layer-menu-desc {
  font-size: 11px;
  color: var(--muted);
  margin-top: 1px;
}

.layer-menu-badge {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 20px;
  background: rgba(74, 144, 217, 0.2);
  color: var(--accent);
  white-space: nowrap;
}

.layer-menu-badge.locked {
  background: rgba(122, 128, 153, 0.2);
  color: var(--muted);
}

/* ── Legend ────────────────────────────────────────────────────── */
#legend {
  position: fixed;
  bottom: 56px;
  left: 16px;
  z-index: 1000;
  background: var(--surface);
  backdrop-filter: var(--blur);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 12px;
  line-height: 1.8;
  box-shadow: 0 2px 12px rgba(0,0,0,0.35);
  min-width: 180px;
}

#legend.hidden { display: none; }

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
}

.legend-separator {
  height: 1px;
  background: var(--border);
  margin: 8px 0;
}

.legend-note {
  font-size: 10px;
  color: var(--muted);
  line-height: 1.4;
}

/* ── Data Source Banner ─────────────────────────────────────────── */
#data-source-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(15, 17, 23, 0.88);
  backdrop-filter: blur(6px);
  padding: 8px 14px;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  z-index: 1000;
  border-top: 1px solid var(--border);
}

/* ── Loading ───────────────────────────────────────────────────── */
#loading {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface);
  backdrop-filter: var(--blur);
  padding: 14px 28px;
  border-radius: 50px;
  font-size: 15px;
  z-index: 2000;
  border: 1px solid var(--border);
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
}

#loading.hidden { display: none; }

/* ── Toast ──────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  top: 80px;
  left: 16px;
  right: 16px;
  background: rgba(30, 30, 50, 0.95);
  backdrop-filter: var(--blur);
  color: var(--text);
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  z-index: 3000;
  text-align: center;
  border: 1px solid var(--border);
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  transition: opacity 0.3s;
}

#toast.hidden {
  opacity: 0;
  pointer-events: none;
  display: block; /* keep in DOM for opacity transition */
}

/* ── Parcel Info Panel ─────────────────────────────────────────── */
#parcel-info {
  position: fixed;
  bottom: 48px;
  left: 12px;
  right: 12px;
  background: rgba(16, 18, 28, 0.96);
  backdrop-filter: var(--blur);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 16px;
  font-size: 14px;
  z-index: 1000;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.5);
  border: 1px solid var(--border);
  border-bottom: none;
  max-height: 45vh;
  overflow-y: auto;
  transform: translateY(0);
  transition: transform 0.25s ease, opacity 0.25s ease;
}

#parcel-info.hidden {
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
}

#parcel-info h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
  padding-right: 30px;
}

#parcel-info .close-info {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  line-height: 1;
}

#parcel-info .close-info:hover { background: rgba(255,255,255,0.06); color: var(--text); }

#parcel-info table {
  width: 100%;
  border-collapse: collapse;
}

#parcel-info td {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

#parcel-info td:first-child {
  color: var(--muted);
  width: 42%;
  padding-right: 12px;
}

#parcel-info td:last-child {
  color: var(--text);
  text-align: right;
}

.data.disclaimer {
  margin-top: 12px;
  padding: 10px 12px;
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.2);
  border-radius: 10px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

/* ── Leaflet Overrides ─────────────────────────────────────────── */
.leaflet-control-zoom a {
  background: var(--surface) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
  backdrop-filter: var(--blur);
}

.leaflet-control-zoom a:hover { background: var(--surface2) !important; }

.leaflet-control-attribution { display: none !important; }

.leaflet-popup-content-wrapper {
  background: var(--surface2) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  backdrop-filter: var(--blur);
  box-shadow: 0 4px 20px rgba(0,0,0,0.5) !important;
}

.leaflet-popup-tip { background: var(--surface2) !important; }

.leaflet-popup-content { margin: 12px 14px !important; font-size: 13px !important; line-height: 1.6 !important; }

.leaflet-popup-close-button { color: var(--muted) !important; }

/* ── Mobile Adjustments ─────────────────────────────────────────── */
@media (max-width: 480px) {
  #search-bar {
    top: 12px;
    width: calc(100% - 80px);
    max-width: none;
  }

  .layer-btn { right: 12px; }

  #controls {
    top: 72px;
    right: 12px;
  }

  #controls button { width: 42px; height: 42px; }

  #parcel-info {
    left: 8px;
    right: 8px;
    bottom: 44px;
    max-height: 50vh;
  }

  #legend {
    bottom: 52px;
    left: 8px;
    font-size: 11px;
  }
}
