:root{
  --navy:#183b7a;
  --navy-dark:#102b5c;
  --solar:#f4a62a;
  --blue:#2f6fe4;
  --red:#d94242;
  --purple:#6a4ef2;
  --green:#22a35a;
  --text:#1f2d3d;
  --muted:#6b7a90;
  --line:#dbe4ef;
  --panel:#ffffff;
  --bg:#edf3f9;
  --shadow:0 12px 28px rgba(15,23,42,.10);
  --shadow-soft:0 8px 20px rgba(15,23,42,.08);
}

*{
  box-sizing:border-box;
}

html, body{
  margin:0;
  padding:0;
  height:100%;
  font-family:"Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  background:var(--bg);
  color:var(--text);
}

body{
  overflow:hidden;
}

.topbar{
  height:82px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:0 20px;
  background:linear-gradient(90deg,var(--navy-dark),var(--navy));
  color:#c6eb0b;
  box-shadow:0 6px 18px rgba(0,0,0,.16);
  position:relative;
  z-index:1000;
}

.topbar-left{
  min-width:0;
}

.topbar-title{
  font-size:28px;
  font-weight:800;
  line-height:1.05;
}

.topbar-subtitle{
  margin-top:6px;
  font-size:13px;
  color:rgba(255,255,255,.88);
}

.topbar-pill{
  padding:10px 14px;
  border-radius:999px;
  background:rgba(255,255,255,.14);
  border:1px solid rgba(255,255,255,.22);
  font-size:12px;
  font-weight:700;
  backdrop-filter:blur(8px);
}

.dashboard{
  display:grid;
  grid-template-columns:280px 1fr;
  gap:12px;
  padding:12px;
  height:calc(100vh - 82px);
}

.sidebar{
  overflow-y:auto;
  padding-right:2px;
}

.sidebar::-webkit-scrollbar{
  width:8px;
}

.sidebar::-webkit-scrollbar-thumb{
  background:#cad5e4;
  border-radius:999px;
}

.panel{
  background:var(--panel);
  border:1px solid var(--line);
  border-radius:18px;
  box-shadow:var(--shadow);
  overflow:hidden;
  margin-bottom:12px;
}

.panel-header{
  padding:13px 15px;
  border-bottom:1px solid var(--line);
  background:linear-gradient(180deg,#f9fbff,#f3f7fd);
  color:var(--navy-dark);
  font-size:12px;
  font-weight:800;
  text-transform:uppercase;
  letter-spacing:.55px;
}

.panel-body{
  padding:13px;
}

.metric-grid{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:10px;
}

.metric-card{
  border:1px solid var(--line);
  border-radius:16px;
  padding:13px;
  box-shadow:var(--shadow-soft);
  background:linear-gradient(180deg,#ffffff,#f9fbff);
}

.metric-card.solar{
  background:linear-gradient(180deg,#fffaf2,#fff2da);
}

.metric-card.ev{
  background:linear-gradient(180deg,#f7faff,#eaf1ff);
}

.metric-card.charger{
  background:linear-gradient(180deg,#f4fff7,#e5f6eb);
}

.metric-card.primary{
  background:linear-gradient(180deg,#faf9ff,#f0edff);
}

.metric-label{
  font-size:11px;
  font-weight:700;
  color:var(--muted);
  margin-bottom:8px;
}

.metric-value{
  font-size:30px;
  font-weight:800;
  line-height:1;
  color:var(--navy-dark);
}

.metric-value.metric-small{
  font-size:17px;
  line-height:1.2;
}

.metric-note{
  margin-top:8px;
  font-size:11px;
  line-height:1.45;
  color:var(--muted);
}

.toggle-group{
  display:grid;
  gap:10px;
}

.toggle-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  padding:10px 10px;
  border:1px solid #e4edf7;
  border-radius:12px;
  background:#f8fbff;
}

.toggle-left{
  display:flex;
  align-items:center;
  gap:10px;
  min-width:0;
}

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

.dot-solar{ background:var(--solar); }
.dot-ev{ background:var(--blue); }
.dot-hotspot{ background:var(--red); }
.dot-lisa{ background:var(--purple); }
.dot-boundary{ background:var(--navy); }

.toggle-label{
  font-size:13px;
  font-weight:800;
  color:var(--text);
}

.switch{
  position:relative;
  display:inline-block;
  width:46px;
  height:26px;
  flex:0 0 auto;
}

.switch input{
  opacity:0;
  width:0;
  height:0;
}

.slider{
  position:absolute;
  inset:0;
  border-radius:999px;
  background:#ccd6e5;
  cursor:pointer;
  transition:.25s ease;
}

.slider:before{
  content:"";
  position:absolute;
  width:20px;
  height:20px;
  left:3px;
  top:3px;
  background:#fff;
  border-radius:50%;
  transition:.25s ease;
  box-shadow:0 2px 6px rgba(0,0,0,.18);
}

.switch input:checked + .slider{
  background:linear-gradient(180deg,var(--navy),var(--blue));
}

.switch input:checked + .slider:before{
  transform:translateX(20px);
}

.sidebar-note{
  margin-top:12px;
  padding:10px 12px;
  border-radius:12px;
  border:1px solid #e6edf6;
  background:#f8fbff;
  color:var(--muted);
  font-size:11px;
  line-height:1.55;
}

.info-box{
  padding:12px;
  border:1px solid #e5edf7;
  border-radius:13px;
  background:#fbfdff;
  margin-bottom:10px;
}

.info-title{
  font-size:12px;
  font-weight:800;
  color:var(--navy-dark);
  margin-bottom:6px;
}

.info-text{
  font-size:11px;
  line-height:1.55;
  color:var(--muted);
}

.chart-button-stack{
  display:grid;
  gap:9px;
}

.chart-btn{
  width:100%;
  border:none;
  border-radius:12px;
  padding:11px 12px;
  cursor:pointer;
  font-size:13px;
  font-weight:700;
  text-align:left;
  color:#fff;
  background:linear-gradient(180deg,#5c6f89,#465a73);
  box-shadow:0 8px 18px rgba(15,23,42,.08);
  transition:transform .15s ease, filter .15s ease;
}

.chart-btn:hover{
  transform:translateY(-1px);
  filter:brightness(.98);
}

.chart-btn-light{
  color:var(--navy-dark);
  background:#eef3fb;
  border:1px solid #d7e2f0;
}

.map-shell{
  position:relative;
  height:100%;
  border-radius:22px;
  overflow:hidden;
  border:1px solid var(--line);
  box-shadow:var(--shadow);
  background:#fff;
}

#map{
  width:100%;
  height:100%;
}

.map-title-box{
  position:absolute;
  top:15px;
  left:15px;
  z-index:900;
  min-width:320px;
  padding:13px 15px;
  border-radius:16px;
  background:rgba(255,255,255,.97);
  border:1px solid #e4ebf3;
  box-shadow:0 10px 24px rgba(0,0,0,.14);
  backdrop-filter:blur(6px);
}

.map-title-main{
  font-size:18px;
  font-weight:800;
  color:var(--navy-dark);
  margin-bottom:4px;
}

.map-title-sub{
  font-size:11px;
  color:var(--muted);
}

.map-badge-stack{
  position:absolute;
  top:15px;
  right:15px;
  z-index:900;
  display:flex;
  gap:8px;
}

.map-badge{
  padding:8px 12px;
  border-radius:999px;
  background:rgba(255,255,255,.96);
  border:1px solid #e4ebf3;
  box-shadow:0 8px 18px rgba(0,0,0,.10);
  font-size:11px;
  font-weight:700;
  color:var(--navy-dark);
}

/* RIGHT SUMMARY PANEL */
.analysis-panel{
  position:absolute;
  top:72px;
  right:16px;
  z-index:930;
  width:220px;
  max-width:calc(100% - 32px);
  max-height:calc(100% - 110px);
  overflow-y:auto;

  background:rgba(255,255,255,.97);
  border:1px solid #e4ebf3;
  border-radius:16px;
  box-shadow:0 12px 28px rgba(0,0,0,.16);
  padding:12px;
  backdrop-filter:blur(6px);

  display:flex;
  flex-direction:column;
  align-items:stretch;
  gap:8px;
}

.analysis-panel::-webkit-scrollbar{
  width:6px;
}

.analysis-panel::-webkit-scrollbar-thumb{
  background:#cad5e4;
  border-radius:999px;
}

.analysis-title{
  font-size:16px;
  font-weight:800;
  color:var(--navy-dark);
  margin-bottom:0;
}

.analysis-subtitle{
  font-size:11px;
  color:var(--muted);
  margin-bottom:2px;
}

.analysis-list{
  display:grid;
  grid-template-columns:1fr;
  gap:8px;
}

.analysis-stat{
  border:1px solid #e5edf7;
  border-radius:12px;
  padding:8px 10px;
  background:#fbfdff;
}

.analysis-stat-label{
  font-size:10px;
  font-weight:700;
  color:var(--muted);
  margin-bottom:6px;
}

.analysis-stat-value{
  font-size:17px;
  font-weight:800;
  color:var(--navy-dark);
  line-height:1.1;
}

.analysis-insight{
  padding:9px 10px;
  border-radius:12px;
  border:1px solid #e6edf6;
  background:#f8fbff;
  color:var(--muted);
  font-size:10px;
  line-height:1.45;
  margin-bottom:2px;
}

/* EMBEDDED LEGEND BELOW INSIGHT */
.embedded-legend{
  display:block;
  position:sticky;
  bottom:0;
  margin-top:4px;
  padding:7px 8px;
  border-radius:12px;
  background:#f8fbff;
  border:1px solid #e4ebf3;
  width:100%;
}

.embedded-legend .legend-title{
  font-size:10px;
  font-weight:800;
  color:var(--navy-dark);
  margin-bottom:4px;
}

.legend-title{
  font-size:10px;
  font-weight:800;
  color:var(--navy-dark);
  margin-bottom:4px;
}

.legend-gradient{
  height:5px;
  border-radius:999px;
  border:1px solid #d7dde6;
  margin-bottom:4px;
}

.solar-gradient{
  background:linear-gradient(
    to right,
    #fff8e1 0%,
    #ffe7a3 16%,
    #ffc66d 32%,
    #ff9c51 48%,
    #f06a3d 64%,
    #d9432f 78%,
    #b51f1f 90%,
    #7f0000 100%
  );
}

.legend-labels{
  display:flex;
  justify-content:space-between;
  font-size:8px;
  font-weight:700;
  color:var(--muted);
  margin-bottom:3px;
}

.legend-note{
  margin-top:2px;
  font-size:8px;
  line-height:1.25;
  color:var(--muted);
}

/* CHART PANEL */
.chart-panel{
  position:absolute;
  left:18px;
  bottom:18px;
  z-index:950;
  width:360px;
  max-width:calc(100% - 36px);
  background:rgba(255,255,255,.98);
  border:1px solid #e4ebf3;
  border-radius:16px;
  box-shadow:0 16px 32px rgba(0,0,0,.18);
  padding:12px;
  display:none;
}

.chart-panel-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  margin-bottom:10px;
}

.chart-panel-title{
  font-size:14px;
  font-weight:800;
  color:var(--navy-dark);
}

.chart-close-btn{
  width:28px;
  height:28px;
  border:none;
  border-radius:8px;
  cursor:pointer;
  background:#eef3fb;
  color:var(--navy-dark);
  font-size:18px;
  line-height:1;
  font-weight:700;
}

.chart-close-btn:hover{
  filter:brightness(.97);
}

.chart-panel img{
  display:block;
  width:100%;
  border-radius:12px;
  border:1px solid #e5ebf2;
}

/* FOOTER */
.footer-note{
  position:absolute;
  left:16px;
  bottom:10px;
  z-index:900;
  padding:6px 8px;
  border-radius:10px;
  background:rgba(255,255,255,.94);
  border:1px solid #e5ebf2;
  box-shadow:0 4px 10px rgba(0,0,0,.08);
  font-size:9px;
  color:var(--muted);
}

/* LEAFLET OVERRIDES */
.leaflet-bottom.leaflet-right{
  display:flex;
  flex-direction:column;
  align-items:flex-end;
  gap:8px;
}

.leaflet-control{
  margin-bottom:0 !important;
}

.leaflet-control-zoom{
  border:none !important;
  border-radius:12px !important;
  overflow:hidden;
  box-shadow:0 8px 18px rgba(0,0,0,.14) !important;
}

.leaflet-control-zoom a{
  width:34px !important;
  height:34px !important;
  line-height:34px !important;
  font-size:18px !important;
  color:var(--navy-dark) !important;
}

.leaflet-popup-content-wrapper{
  border-radius:14px;
  box-shadow:0 10px 24px rgba(0,0,0,.18);
}

.leaflet-popup-content{
  margin:12px 14px;
}

/* RESPONSIVE */
@media (max-width:1100px){
  body{
    overflow:auto;
  }

  .dashboard{
    grid-template-columns:1fr;
    height:auto;
  }

  .map-shell{
    height:72vh;
    min-height:560px;
  }
}

@media (max-width:820px){
  .analysis-panel{
    width:200px;
    top:68px;
  }

  .chart-panel{
    width:300px;
  }
}

@media (max-width:680px){
  .topbar{
    padding:0 14px;
  }

  .topbar-title{
    font-size:22px;
  }

  .topbar-right{
    display:none;
  }

  .metric-grid{
    grid-template-columns:1fr;
  }

  .map-title-box{
    min-width:unset;
    width:calc(100% - 30px);
  }

  .map-badge-stack{
    display:none;
  }

  .analysis-panel{
    display:none;
  }

  .chart-panel{
    width:calc(100% - 36px);
  }
}