/* ========= TerraWatt dark theme ========= */
:root {
  --bg: #0b1118;
  --panel: rgba(13, 20, 30, 0.92);
  --panel-solid: #0d141e;
  --line: rgba(255, 255, 255, 0.08);
  --text: #e8edf4;
  --muted: #8b95a5;
  --accent: #22d3ee;
  --accent-dim: rgba(34, 211, 238, 0.15);
  --good: #30d158;
  --warn: #ff9f0a;
  --bad: #ff2d55;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  font-size: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif; }
#map { position: absolute; inset: 0; }
.hidden { display: none !important; }
.grow { flex: 1; }
.accent { color: var(--accent); }
.row { display: flex; gap: 8px; align-items: center; }
.space-between { justify-content: space-between; }
.hint { color: var(--muted); font-size: 12px; margin-top: 4px; line-height: 1.45; }
.hint-inline { color: var(--muted); font-size: 11px; }
.badge { background: var(--accent); color: #04252b; border-radius: 8px; padding: 0 6px; font-size: 11px; font-weight: 700; }

/* ========= Top bar ========= */
#topbar { position: absolute; top: 12px; left: 12px; right: 12px; display: flex; align-items: center;
  gap: 12px; z-index: 30; pointer-events: none; }
#topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: baseline; gap: 7px; background: var(--panel); backdrop-filter: blur(8px);
  padding: 9px 14px; border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow); }
.brand-bolt { font-size: 16px; }
.brand-name { font-weight: 800; font-size: 16px; letter-spacing: 0.2px; }
.brand-tag { color: var(--muted); font-size: 11px; }
.searchwrap { position: relative; width: min(420px, 34vw); }
#geocode { width: 100%; background: var(--panel); backdrop-filter: blur(8px); border: 1px solid var(--line);
  border-radius: var(--radius); color: var(--text); padding: 10px 14px; outline: none; box-shadow: var(--shadow); }
#geocode:focus { border-color: var(--accent); }
#geocode-results { position: absolute; top: 44px; left: 0; right: 0; background: var(--panel-solid);
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden; box-shadow: var(--shadow); }
#geocode-results .gr { padding: 9px 12px; cursor: pointer; font-size: 13px; border-bottom: 1px solid var(--line); }
#geocode-results .gr:hover { background: var(--accent-dim); }
.topbar-right { margin-left: auto; display: flex; gap: 8px; }
.chip { background: var(--panel); backdrop-filter: blur(8px); border: 1px solid var(--line); color: var(--text);
  border-radius: var(--radius); padding: 9px 13px; cursor: pointer; font-size: 13px; box-shadow: var(--shadow); }
.chip:hover { border-color: var(--accent); }

/* ========= Panels ========= */
.panel { position: absolute; z-index: 25; background: var(--panel); backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; overflow: hidden; }
#left-panel { top: 68px; left: 12px; width: 348px; max-height: calc(100% - 150px); }
#left-panel.collapsed { display: none; }
#right-panel { top: 68px; right: 12px; width: 292px; max-height: calc(100% - 150px); }
#right-panel.collapsed { display: none; }
.edge-btn { position: absolute; z-index: 24; top: 76px; background: var(--panel); border: 1px solid var(--line);
  color: var(--text); border-radius: 10px; padding: 8px 10px; cursor: pointer; box-shadow: var(--shadow); }
.edge-btn.left { left: 12px; }
.edge-btn.right { right: 12px; }

.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab { flex: 1; background: none; border: none; color: var(--muted); padding: 11px 8px; cursor: pointer;
  font-size: 13px; font-weight: 600; border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-collapse { background: none; border: none; color: var(--muted); padding: 0 12px; cursor: pointer; font-size: 16px; }
.tab-body { padding: 14px; overflow-y: auto; }
.empty-note { color: var(--muted); font-size: 13px; line-height: 1.5; padding: 8px 4px; }

.panel-head { display: flex; align-items: center; gap: 6px; padding: 11px 14px; border-bottom: 1px solid var(--line);
  font-size: 12px; letter-spacing: 1px; }
#layers-body { overflow-y: auto; padding: 4px 0 8px; }
.panel-foot { border-top: 1px solid var(--line); padding: 9px 14px; color: var(--muted); font-size: 12px; }
.mini { background: rgba(255,255,255,0.07); border: 1px solid var(--line); color: var(--muted); border-radius: 7px;
  padding: 2px 9px; font-size: 11px; cursor: pointer; }
.mini:hover { color: var(--text); border-color: var(--accent); }

/* layer sections */
.lsec { border-bottom: 1px solid var(--line); }
.lsec:last-child { border-bottom: none; }
.lsec-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px 8px;
  font-size: 11px; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted);
  cursor: pointer; user-select: none; }
.lsec-head:hover { color: var(--text); }
.lsec.closed .lsec-body { display: none; }
.lsec.closed .sec-caret { transform: rotate(-90deg); }
.sec-caret { transition: transform 0.15s; display: inline-block; }
.lsec-body { padding: 0 14px 10px; }
.lrow { display: flex; align-items: center; gap: 9px; padding: 4px 0; font-size: 13px; cursor: pointer; }
.lrow input { accent-color: var(--accent); margin: 0; }
.lrow.toggle { margin-top: 6px; border-top: 1px dashed var(--line); padding-top: 9px; }
.sub-legend { margin: 4px 0 2px 4px; padding-left: 8px; border-left: 2px solid var(--line); }
.swatch.line { width: 26px; height: 0; border-top: var(--w, 2px) solid var(--c, #999); border-radius: 2px; flex: none; }
.swatch.line.dashed { border-top-style: dashed; }
.swatch.dot { width: 11px; height: 11px; border-radius: 50%; background: var(--c, #999); flex: none; margin: 0 8px; }
.swatch.dot.ring { background: transparent; border: 2.5px solid var(--c, #999); }
.swatch.fill { width: 22px; height: 12px; border-radius: 3px; flex: none; margin: 0 2px;
  background: color-mix(in srgb, var(--c, #999) 25%, transparent); border: 1.5px dashed var(--c, #999); }
.sc-flag { display: flex; gap: 7px; align-items: baseline; font-size: 12.5px; padding: 6px 9px;
  border-radius: 8px; margin-top: 7px; line-height: 1.4; }
.sc-flag a { color: inherit; opacity: 0.8; }

/* ========= Buttons ========= */
.btn { border-radius: 9px; padding: 9px 14px; font-size: 13px; font-weight: 600; cursor: pointer; border: 1px solid var(--line); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #03252c; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; color: var(--text); }
.btn.ghost:hover { border-color: var(--accent); }
.btn.small { padding: 5px 10px; font-size: 12px; }

/* ========= Site card ========= */
.sc-score-hero { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.sc-ring { width: 78px; height: 78px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--ring-color, var(--accent)) calc(var(--pct, 0) * 1%), rgba(255,255,255,0.09) 0); }
.sc-ring > div { width: 62px; height: 62px; border-radius: 50%; background: var(--panel-solid); display: grid;
  place-items: center; font-size: 21px; font-weight: 800; }
.sc-verdict { font-weight: 700; font-size: 15px; }
.sc-coords { color: var(--muted); font-size: 11px; margin-top: 2px; }
.sc-sub { display: flex; justify-content: space-between; align-items: baseline; padding: 7px 0;
  border-bottom: 1px solid var(--line); font-size: 13px; gap: 8px; }
.sc-sub .k { color: var(--muted); }
.sc-sub .v { text-align: right; }
.sc-sub .pts { color: var(--muted); font-size: 11px; margin-left: 6px; }
.sc-actions { display: flex; gap: 8px; margin-top: 12px; }
.tierchip { display: inline-block; border-radius: 6px; padding: 1px 7px; font-size: 11px; font-weight: 800; }
.tier-A { background: rgba(48, 209, 88, 0.2); color: #30d158; }
.tier-B { background: rgba(167, 232, 56, 0.18); color: #a7e838; }
.tier-C { background: rgba(255, 214, 10, 0.16); color: #ffd60a; }
.tier-D { background: rgba(255, 159, 10, 0.18); color: #ff9f0a; }
.tier-F { background: rgba(255, 45, 85, 0.18); color: #ff2d55; }
.tier-U { background: rgba(142, 142, 147, 0.2); color: #aeaeb2; }

/* ========= Scout ========= */
#scout-query { width: 100%; background: rgba(255,255,255,0.05); border: 1px solid var(--line); border-radius: 9px;
  color: var(--text); padding: 9px 11px; font-family: inherit; font-size: 13px; resize: vertical; margin: 10px 0; }
#scout-query:focus { outline: none; border-color: var(--accent); }
.scout-intro { font-size: 13px; line-height: 1.5; }
.scout-chiprow { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.scout-crit { background: var(--accent-dim); border: 1px solid rgba(34,211,238,0.35); color: var(--accent);
  padding: 2px 9px; border-radius: 20px; font-size: 11.5px; }
.scout-hit { padding: 9px 10px; border: 1px solid var(--line); border-radius: 9px; margin-top: 8px; cursor: pointer; font-size: 12.5px; }
.scout-hit:hover { border-color: var(--accent); background: var(--accent-dim); }

/* ========= Pins ========= */
.pin-item { border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; margin-top: 9px; font-size: 12.5px; }
.pin-item .row { justify-content: space-between; }
.pin-name { font-weight: 700; cursor: pointer; }
.pin-name:hover { color: var(--accent); }
.pin-del { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; }
.pin-del:hover { color: var(--bad); }

/* ========= Area score ========= */
#area-score { position: absolute; z-index: 26; left: 50%; transform: translateX(-50%); bottom: 22px;
  background: var(--panel); backdrop-filter: blur(10px); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); width: min(520px, 90vw); overflow: hidden; }
#area-score-head { display: flex; align-items: center; gap: 12px; padding: 11px 18px; cursor: pointer; user-select: none; }
.as-label { font-size: 11px; letter-spacing: 1.5px; color: var(--muted); font-weight: 700; }
#as-value { font-size: 19px; font-weight: 800; }
#area-score-body { border-top: 1px solid var(--line); padding: 10px 18px 14px; max-height: 300px; overflow-y: auto; }
.as-owner { display: flex; align-items: center; gap: 10px; padding: 6px 8px; margin: 0 -8px; border-bottom: 1px solid var(--line);
  font-size: 12.5px; cursor: pointer; border-radius: 6px; }
.as-owner:last-child { border-bottom: none; }
.as-owner:hover { background: rgba(34, 211, 238, 0.08); }
.as-owner.pinned { background: var(--accent-dim); box-shadow: inset 2px 0 0 var(--accent); }
.as-owner .nm { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; outline: none; }
.as-owner:hover .nm, .as-owner .nm:focus { color: var(--accent); }
.as-owner .mi { color: var(--muted); font-size: 11px; white-space: nowrap; }
.as-score { min-width: 34px; text-align: center; border-radius: 6px; font-weight: 800; font-size: 12px; padding: 2px 0; }

/* ========= Popups ========= */
.maplibregl-popup-content { background: var(--panel-solid) !important; color: var(--text) !important;
  border: 1px solid var(--line); border-radius: 10px !important; box-shadow: var(--shadow) !important;
  padding: 12px 14px !important; font-family: inherit !important; max-width: 300px; }
.maplibregl-popup-close-button { color: var(--muted) !important; font-size: 16px !important; }
.maplibregl-popup-tip { border-top-color: var(--panel-solid) !important; border-bottom-color: var(--panel-solid) !important; }
.pop-title { font-weight: 800; font-size: 13.5px; margin-bottom: 6px; }
.pop-kv { display: flex; justify-content: space-between; gap: 10px; font-size: 12.5px; padding: 2.5px 0; }
.pop-kv .k { color: var(--muted); }
.pop-rationale { margin-top: 7px; padding-top: 7px; border-top: 1px solid var(--line); color: var(--muted);
  font-size: 12px; line-height: 1.45; }
.pop-actions { margin-top: 8px; display: flex; gap: 8px; }
.pop-link { color: var(--accent); font-size: 12px; cursor: pointer; text-decoration: none; }

/* ========= Modal ========= */
.modal { position: absolute; inset: 0; z-index: 50; background: rgba(0,0,0,0.55); display: grid; place-items: center; }
.modal-card { width: min(680px, 92vw); max-height: 80vh; overflow-y: auto; background: var(--panel-solid);
  border: 1px solid var(--line); border-radius: 14px; padding: 18px 22px; box-shadow: var(--shadow); }
#about-body { font-size: 13px; line-height: 1.55; color: var(--muted); }
#about-body h4 { color: var(--text); margin: 14px 0 4px; }
#about-body a { color: var(--accent); }
#about-body code { background: rgba(255,255,255,0.07); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* ========= Loading ========= */
.spinner { display: inline-block; width: 11px; height: 11px; border: 2px solid var(--muted);
  border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }
#load-indicator { margin-top: 4px; color: var(--accent); font-size: 11.5px; }

/* ========= Scrollbars ========= */
::-webkit-scrollbar { width: 9px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.14); border-radius: 5px; }
::-webkit-scrollbar-track { background: transparent; }

/* ========= Narrow screens ========= */
@media (max-width: 900px) {
  .brand-tag { display: none; }
  #left-panel, #right-panel { width: min(320px, 86vw); }
}
