:root{
  --ink:#1a2a22;
  --line:#dfe3dd;
  --paper:#ffffff;
  --moss:#0f5132;
  --moss-dim:#0f513214;
  --terracotta:#c9612b;
  --terracotta-dim:#c9612b22;
  --text-dim:#6b756c;
  --mono:'SFMono-Regular',Consolas,monospace;
}
*{box-sizing:border-box;}
html,body{height:100%;margin:0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;color:var(--ink);}

/* ---- Overall layout: info/tools sidebar (left) — map (center) — Marked Rooftops (right) ---- */
.map-shell{display:flex;align-items:stretch;width:100%;height:100vh;}
.map-wrapper{position:relative;flex:1 1 auto;overflow:hidden;min-width:0;}
#map{width:100%;height:100%;background:#eef0ea;}

/* ---- Left sidebar: How This Works + the actual draw/edit/delete controls ---- */
.map-sidebar{
  flex:0 0 290px;
  width:290px;
  height:100vh;
  overflow-y:auto;
  background:var(--paper);
  border-right:1px solid var(--line);
  box-shadow:6px 0 18px rgba(20,30,20,0.06);
  padding:18px 16px 32px;
}
.sidebar-section{margin-bottom:22px;}
.sidebar-section:last-child{margin-bottom:0;}
.sidebar-title{font-size:11px;text-transform:uppercase;letter-spacing:0.5px;color:var(--text-dim);font-weight:700;margin:0 0 10px;}

/* Each guide row is a real button (except the static "after editing" note)
   so the icons double as the polygon/rectangle/edit/delete tools — no
   separate floating icon toolbar is drawn on top of the map. */
.guide-row{
  display:flex;width:100%;gap:10px;align-items:flex-start;text-align:left;
  padding:8px 6px;border-bottom:1px dashed var(--line);
  background:none;border-left:none;border-right:none;border-top:none;
  font:inherit;color:inherit;cursor:pointer;border-radius:8px;
}
.guide-row:last-child{border-bottom:none;}
.guide-row:hover{background:var(--moss-dim);}
.guide-row.active{background:var(--terracotta-dim);}
.guide-row.active .guide-icon{background:var(--terracotta);color:#fff;}
.guide-row-danger:hover{background:#b3261e14;}
.guide-row-danger:hover .guide-text b{color:#b3261e;}
.guide-row-static{cursor:default;}
.guide-row-static:hover{background:none;}

.guide-icon{flex-shrink:0;width:30px;height:30px;border-radius:8px;background:var(--moss-dim);color:var(--moss);display:flex;align-items:center;justify-content:center;font-size:15px;}
.guide-icon svg{width:16px;height:16px;}
.guide-text{display:flex;flex-direction:column;}
.guide-text b{display:block;font-size:12px;color:var(--ink);margin-bottom:2px;}
.guide-text p{margin:0;font-size:11.5px;color:var(--text-dim);line-height:1.5;}

/* ---- Map overlay controls that legitimately float on the map itself ---- */
#searchBar{position:absolute;top:16px;left:16px;right:230px;z-index:10;display:flex;gap:10px;}
#searchInput{flex:1;background:var(--paper);border:1px solid var(--line);border-radius:10px;padding:12px 16px;font-size:14px;color:var(--ink);box-shadow:0 4px 14px rgba(20,30,20,0.10);}
#searchInput:focus{outline:none;border-color:var(--moss);}
#searchBtn{background:var(--moss);color:#fff;border:none;border-radius:10px;padding:0 22px;font-size:14px;font-weight:600;cursor:pointer;box-shadow:0 4px 14px rgba(20,30,20,0.10);}
#searchBtn:hover{background:#0c3f27;}

#layerSwitch{position:absolute;top:16px;right:16px;z-index:10;background:var(--paper);border:1px solid var(--line);border-radius:10px;padding:12px 16px;box-shadow:0 4px 14px rgba(20,30,20,0.10);font-size:13px;}
.layer-opt{display:flex;align-items:center;gap:8px;padding:4px 0;cursor:pointer;}
.layer-opt input{accent-color:var(--moss);}

#hint{position:absolute;top:16px;left:50%;transform:translateX(-50%);z-index:20;background:var(--ink);color:#fff;padding:8px 16px;border-radius:20px;font-size:12px;display:none;box-shadow:0 6px 20px rgba(0,0,0,0.25);}

#loadError{position:absolute;inset:0;z-index:30;background:var(--paper);display:none;align-items:center;justify-content:center;text-align:center;padding:20px;}
#loadError p{max-width:360px;font-size:13px;color:var(--text-dim);line-height:1.6;}

#solarLegend{position:absolute;right:16px;bottom:16px;z-index:10;width:230px;background:#ffffff;border:1px solid var(--line);border-radius:10px;padding:12px 14px;box-shadow:0 4px 14px rgba(20,30,20,0.12);font-size:11px;}
.legend-title{font-weight:700;margin-bottom:8px;color:var(--ink);}
.legend-gradient{height:14px;border-radius:8px;background:linear-gradient(to right,#2166ac 0%,#67a9cf 25%,#d9ef8b 50%,#fdae61 75%,#d73027 100%);}
.legend-labels{display:flex;justify-content:space-between;margin-top:5px;font-family:var(--mono);color:var(--text-dim);font-size:9px;}
.legend-unit{margin-top:5px;color:var(--text-dim);text-align:center;font-size:9px;}

/* ---- Right sidebar: Marked Rooftops — a real column now, not an overlay ---- */
.roof-sidebar{
  flex:0 0 260px;
  width:260px;
  height:100vh;
  overflow-y:auto;
  background:var(--paper);
  border-left:1px solid var(--line);
  box-shadow:-6px 0 18px rgba(20,30,20,0.06);
  padding:18px 16px 32px;
  display:flex;
}
#roofPanel{
  position:static !important;
  top:auto !important;
  left:auto !important;
  right:auto !important;
  bottom:auto !important;
  z-index:auto !important;
  width:100% !important;
  max-height:none !important;
  display:flex;
  flex-direction:column;
  min-height:0;
}
#roofPanelHead{padding:0 0 12px;border-bottom:1px solid var(--line);display:flex;align-items:center;justify-content:space-between;cursor:pointer;margin-bottom:8px;}
#roofPanelHead h2{font-size:12px;text-transform:uppercase;letter-spacing:0.5px;margin:0;color:var(--text-dim);}
#roofPanelHead span{font-family:var(--mono);font-size:12px;color:var(--terracotta);font-weight:700;}
#roofList{overflow-y:auto;display:flex;flex-direction:column;gap:8px;}
#roofList.collapsed{display:none;}
.roof-card{border:1px solid var(--line);border-radius:8px;padding:10px 12px;cursor:pointer;transition:border-color .15s;}
.roof-card:hover{border-color:var(--terracotta);}
.roof-card.selected{border-color:var(--terracotta);background:var(--terracotta-dim);}
.roof-card-top{display:flex;justify-content:space-between;align-items:center;margin-bottom:2px;}
.roof-name{font-size:12.5px;font-weight:600;border:none;background:transparent;width:65%;color:var(--ink);}
.roof-name:focus{outline:none;border-bottom:1px dashed var(--terracotta);}
.roof-area{font-family:var(--mono);font-size:11px;color:var(--text-dim);}
.roof-area b{color:var(--terracotta);}

.solar-block{margin-top:8px;padding-top:8px;border-top:1px dashed var(--line);}
.solar-btn{width:100%;background:var(--moss-dim);color:var(--moss);border:1px solid var(--moss);border-radius:6px;padding:6px 8px;font-size:11.5px;font-weight:600;cursor:pointer;margin-top:6px;}
.solar-btn:first-child{margin-top:0;}
.solar-btn:hover{background:var(--moss);color:#fff;}
.solar-btn.report-btn{background:var(--terracotta-dim);color:var(--terracotta);border-color:var(--terracotta);}
.solar-btn.report-btn:hover{background:var(--terracotta);color:#fff;}
.solar-stats{display:flex;flex-direction:column;gap:2px;font-size:11px;color:var(--text-dim);}
.solar-stats b{color:var(--ink);font-family:var(--mono);}
.solar-error{font-size:11px;color:#b3261e;line-height:1.4;}
.solar-stale{font-size:10.5px;color:#a8641f;background:#c9612b14;border:1px solid #c9612b33;border-radius:6px;padding:5px 7px;margin-top:6px;line-height:1.4;}
.solar-btn.recalc-btn{background:#c9612b14;color:var(--terracotta);border-color:var(--terracotta);}
.solar-btn.recalc-btn:hover{background:var(--terracotta);color:#fff;}
.icon-btn{background:none;border:none;color:var(--text-dim);cursor:pointer;padding:2px;display:inline-flex;vertical-align:middle;}
.icon-btn svg{width:14px;height:14px;}
.icon-btn:hover{color:var(--terracotta);}
.icon-btn.del:hover{color:#b3261e;}
.empty-state{padding:14px 0;font-size:12px;color:var(--text-dim);line-height:1.5;}

/* ---- Report preview modal (the "next page" shown before download) ---- */
#reportPreviewOverlay{position:fixed;inset:0;z-index:60;background:rgba(15,25,20,0.55);display:none;align-items:center;justify-content:center;padding:20px;}
#reportPreviewOverlay.open{display:flex;}
.preview-card{width:100%;max-width:420px;background:var(--paper);border-radius:14px;overflow:hidden;box-shadow:0 20px 60px rgba(0,0,0,0.35);}
.preview-head{background:linear-gradient(135deg,#0f5132,#0a3a24);padding:20px 22px;color:#fff;position:relative;}
.preview-brand{display:flex;align-items:center;gap:10px;margin-bottom:14px;}
.preview-logo{width:30px;height:30px;border-radius:50%;background:#fff;color:#0f5132;display:flex;align-items:center;justify-content:center;font-size:15px;font-weight:700;flex-shrink:0;}
.preview-brand-name{font-size:13px;font-weight:700;letter-spacing:0.3px;}
.preview-brand-tagline{font-size:10px;color:#cfe3d5;margin-top:1px;}
.preview-head h3{font-size:17px;margin:0 0 3px;}
.preview-head p{font-size:11px;margin:0;color:#cfe3d5;}
.preview-close{position:absolute;top:14px;right:16px;background:none;border:none;color:#fff;font-size:18px;cursor:pointer;opacity:0.8;line-height:1;}
.preview-close:hover{opacity:1;}
.preview-body{padding:18px 22px;}
.preview-grid{display:grid;grid-template-columns:1fr 1fr;gap:10px;margin-bottom:16px;}
.preview-stat{background:var(--moss-dim);border:1px solid var(--line);border-radius:8px;padding:10px;}
.preview-stat .k{font-size:9.5px;color:var(--text-dim);text-transform:uppercase;letter-spacing:0.3px;margin-bottom:3px;}
.preview-stat .v{font-size:14px;font-weight:700;color:var(--ink);font-family:var(--mono);}
.preview-note{font-size:10.5px;color:var(--text-dim);line-height:1.5;margin-bottom:16px;}
.preview-actions{display:flex;gap:10px;}
.preview-btn{flex:1;border-radius:8px;padding:11px;font-size:13px;font-weight:700;cursor:pointer;border:none;}
.preview-btn.download{background:var(--moss);color:#fff;}
.preview-btn.download:hover{background:#0c3f27;}
.preview-btn.cancel{background:var(--paper);color:var(--text-dim);border:1px solid var(--line);}
.preview-btn.cancel:hover{border-color:var(--terracotta);color:var(--terracotta);}

/* ============================================================
   RESPONSIVE — tablet: stack everything. Map first (most useful),
   then the rooftops list, then the how-it-works guide.
============================================================ */
@media (max-width: 1100px){
  .map-shell{flex-direction:column;height:auto;min-height:100vh;}

  .map-wrapper{order:1;width:100%;height:60vh;min-height:380px;}

  .roof-sidebar{
    order:2;width:100%;flex:0 0 auto;height:auto;max-height:46vh;
    border-left:none;border-top:1px solid var(--line);
    box-shadow:0 -6px 18px rgba(20,30,20,0.06);
  }

  .map-sidebar{
    order:3;width:100%;flex:0 0 auto;height:auto;max-height:40vh;
    border-right:none;border-top:1px solid var(--line);
    box-shadow:0 -6px 18px rgba(20,30,20,0.06);
  }
}

/* ============================================================
   RESPONSIVE — phone: compact on-map controls, roomier tap targets
   for the guide/tool buttons and rooftop cards.
============================================================ */
@media (max-width: 640px){
  .map-wrapper{height:52vh;min-height:300px;}

  #searchBar{top:8px;left:8px;right:100px;gap:6px;}
  #searchInput{padding:9px 10px;font-size:13px;}
  #searchBtn{padding:0 12px;font-size:13px;}

  #layerSwitch{top:8px;right:8px;left:auto;padding:7px 9px;font-size:10px;border-radius:8px;}
  .layer-opt{padding:2px 0;gap:5px;}

  #hint{top:8px;max-width:calc(100vw - 32px);font-size:11px;padding:7px 12px;text-align:center;}

  #solarLegend{right:8px;bottom:8px;width:190px;padding:9px 10px;font-size:10px;}

  .roof-sidebar,.map-sidebar{padding:14px 12px 20px;}
  .roof-sidebar{max-height:38vh;}
  .map-sidebar{max-height:34vh;}

  .sidebar-title{font-size:10px;}
  .guide-row{padding:10px 6px;}
  .guide-icon{width:28px;height:28px;}
  .guide-text b{font-size:11.5px;}
  .guide-text p{font-size:11px;}

  .roof-card{padding:12px;}

  #reportPreviewOverlay{padding:12px;}
  .preview-card{max-width:100%;}
  .preview-head{padding:16px 18px;}
  .preview-body{padding:16px 18px;}
  .preview-grid{gap:8px;}
  .preview-actions{flex-direction:column;}
}