html, body { height: 100%; margin: 0; }
#map { height: 100%; }

.panel {
  position: absolute; top: 10px; left: 10px; z-index: 1000;
  background: rgba(255,255,255,.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 10px 12px; border-radius: 10px;
  box-shadow: 0 2px 12px rgba(0,0,0,.18);
  font: 14px/1.2 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  width: min(440px, calc(100vw - 20px));
  max-height: calc(100vh - 20px);
  overflow: auto;
}
.panelHeader{ display:flex; align-items:center; justify-content:space-between; gap:10px; position: sticky; top: 0; background: rgba(255,255,255,.78); padding-bottom: 8px; }
.panelTitle { font-weight: 900; }
.panelSub { color:#666; font-weight:650; }
.headerBtns { display:flex; gap:8px; align-items:center; }
.collapseBtn, .legendBtn{
  border: 1px solid rgba(0,0,0,.15);
  background: rgba(250,250,250,.85);
  padding: 6px 10px;
  border-radius: 10px;
  cursor: pointer;
  user-select:none;
  font-weight:800;
  line-height: 1;
}
.collapseBtn:hover,.legendBtn:hover { background: rgba(240,240,240,.92); }
.panelBody { margin-top: 8px; }
.panel.collapsed { width: auto; max-width: 240px; overflow: hidden; }
.panel.collapsed .panelBody { display:none; }
.panel.collapsed .panelSub { display:none; }

.row { display: grid; grid-template-columns: 140px 1fr; gap: 8px; align-items: center; margin-top: 8px; }
label { font-weight: 650; }
select, input {
  width: 100%; padding: 6px 8px;
  border: 1px solid #ddd; border-radius: 8px;
  font: inherit;
  background: rgba(255,255,255,.9);
}
.toggles { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.btn {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid #ddd;
  border-radius: 10px;
  background: rgba(250,250,250,.9);
  cursor: pointer;
  user-select: none;
  text-align: center;
  font-weight: 800;
}
.btn.active { background: rgba(233,242,255,.92); border-color: rgba(183,212,255,.95); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  border: 1px solid #ddd;
  background: rgba(255,255,255,.9);
  border-radius: 999px;
  padding: 6px 10px;
  user-select: none;
}
.chip input { width: auto; }
.chip span { font-weight: 800; }

.muted { color: #666; font-size: 12px; margin-top: 8px; }
.stat { margin-top: 8px; font-size: 12px; color: #333; }
code { background: rgba(243,243,243,.92); padding: 1px 4px; border-radius: 6px; }

.rangeWrap { display: grid; grid-template-columns: 1fr; gap: 6px; }
.rangeLabel { font-size: 12px; color: #333; display:flex; justify-content:space-between; }
.dualRange { position: relative; height: 26px; }
.dualRange input[type="range"]{
  position: absolute; left: 0; right: 0; top: 0;
  width: 100%; margin: 0; padding: 0;
  background: transparent;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
  height: 26px;
}
.dualRange input[type="range"]::-webkit-slider-thumb{
  pointer-events: auto;
  -webkit-appearance: none;
  appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,.25);
  background: rgba(255,255,255,.98);
  box-shadow: 0 1px 4px rgba(0,0,0,.25);
}
.dualRange input[type="range"]::-moz-range-thumb{
  pointer-events: auto;
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,.25);
  background: rgba(255,255,255,.98);
  box-shadow: 0 1px 4px rgba(0,0,0,.25);
}
.dualRangeTrack{
  position:absolute; left:0; right:0;
  top: 50%; transform: translateY(-50%);
  height: 6px; border-radius: 999px;
  background: rgba(0,0,0,.12);
}
.dualRangeFill{
  position:absolute;
  top: 50%; transform: translateY(-50%);
  height: 6px; border-radius: 999px;
  background: rgba(120,170,255,.75);
  left: 0%; right: 0%;
}

.legendBox{
  margin-top: 8px;
  padding: 8px 10px;
  border: 1px dashed rgba(0,0,0,.25);
  border-radius: 10px;
  background: rgba(255,255,255,.7);
  font-size: 12px;
  color:#333;
  display:none;
}
.legendBox strong{ font-weight: 900; }
.legendBox ul{ margin: 8px 0 0 18px; padding: 0; }
.legendBox li{ margin: 2px 0; }

.modalOverlay{
  position: fixed; inset: 0;
  background: rgba(0,0,0,.25);
  z-index: 2000;
  display:none;
  align-items: center;
  justify-content: center;
  padding: 10px;
}
.modal{
  width: min(980px, calc(100vw - 20px));
  max-height: calc(100vh - 20px);
  overflow: auto;
  background: rgba(255,255,255,.98);
  border-radius: 14px;
  border: 1px solid rgba(0,0,0,.08);
  box-shadow: 0 18px 48px rgba(0,0,0,.18);
  padding: 14px 14px 10px;
  font: 14px/1.35 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}
.modalHeader{ display:flex; align-items:center; justify-content:space-between; gap:10px; position: sticky; top: 0; background: rgba(255,255,255,.98); padding-bottom: 10px; }
.modalTitle{ font-weight: 950; font-size: 16px; }
.modalBtns{ display:flex; gap:8px; flex-wrap: wrap; }
.smallBtn{
  padding: 8px 10px;
  border: 1px solid #ddd;
  border-radius: 10px;
  background: rgba(250,250,250,.96);
  cursor:pointer;
  font-weight: 850;
  user-select:none;
}
.smallBtn:hover{ background: rgba(240,240,240,.98); }
.progressLine{ margin: 10px 0; font-size: 12px; color:#333; }

table.report{ width:100%; border-collapse:collapse; margin-top:6px; font-size:13px; }
table.report th, table.report td{ padding:6px 6px; border-bottom:1px solid rgba(0,0,0,.08); vertical-align: top; }
table.report thead th{ border-bottom:1px solid rgba(0,0,0,.15); text-align:left; }
.pill{ display:inline-block; padding:2px 8px; border:1px solid rgba(0,0,0,.12); border-radius:999px; background:rgba(255,255,255,.7); }

/* Layer Legend Control (bottom right) */
.layer-legend-control {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 10px;
}

.legend-item {
  width: 40px;
  height: 40px;
  border: 2px solid rgba(0, 0, 0, 0.15);
  border-radius: 8px;
  background: rgba(250, 250, 250, 0.9);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  transition: all 0.2s ease;
  user-select: none;
  padding: 0;
}

.legend-item:hover {
  background: rgba(240, 240, 240, 1);
  border-color: rgba(0, 0, 0, 0.25);
  transform: scale(1.05);
}

.legend-item.active {
  background: rgba(233, 242, 255, 0.95);
  border-color: rgba(66, 135, 245, 0.8);
  box-shadow: 0 0 0 2px rgba(66, 135, 245, 0.2);
}

.legend-item.active:hover {
  background: rgba(220, 235, 255, 1);
}

.legend-item:not(.active) {
  opacity: 0.5;
  filter: grayscale(80%);
}

.legend-item:not(.active):hover {
  opacity: 0.7;
  filter: grayscale(50%);
}

.legend-icon {
  display: block;
  line-height: 1;
}