:root {
  --bg: #0f1419;
  --panel: #161c23;
  --panel-2: #1d252e;
  --line: #2b3540;
  --fg: #e6edf3;
  --fg-2: #9aa7b4;
  --accent: #4ea1ff;
  --good: #3fb97a;
  --warn: #e0a83a;
  --bad: #ef5a4f;
  --relay: #ffd23c;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); }
body { font-size: 14px; line-height: 1.4; }
.hidden { display: none !important; }
[hidden] { display: none !important; }
.muted { color: var(--fg-2); }
.small { font-size: 12px; }
.err { color: var(--bad); margin: 8px 0 0; }
.spacer { flex: 1; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--fg-2); margin: 0; }

button, .button {
  font: inherit; color: var(--fg); background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 6px; padding: 7px 12px; cursor: pointer; text-decoration: none; display: inline-block;
}
button:hover, .button:hover { border-color: var(--accent); }
.primary { background: var(--accent); border-color: var(--accent); color: #06121f; font-weight: 600; }
.primary:hover { filter: brightness(1.08); }
.primary:disabled { opacity: .55; cursor: progress; }
.wide { width: 100%; margin-top: 12px; padding: 10px; }
.link-btn { background: none; border: none; color: var(--accent); padding: 4px 6px; }
.icon-btn { padding: 4px 9px; font-size: 16px; line-height: 1; display: inline-grid; place-items: center; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; border: 1px solid #000; margin: 0 4px 0 8px; vertical-align: -1px; }
.dot:first-child { margin-left: 0; }

input, select {
  font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--line);
  border-radius: 6px; padding: 7px 8px; width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
label { display: block; font-size: 12px; color: var(--fg-2); }
label > input, label > select, label > .unit { margin-top: 3px; }
.unit { display: flex; align-items: center; gap: 4px; color: var(--fg-2); }
.unit input { width: 100%; }
label.check { display: flex; align-items: center; gap: 6px; color: var(--fg); }
label.check input { width: auto; margin: 0; }

/* layout */
#app { position: fixed; inset: 0; }
#map { position: absolute; inset: 0; background: #222; }
#panel {
  position: absolute; z-index: 1000; top: 12px; left: 12px; bottom: 12px; width: 390px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  display: flex; flex-direction: column; box-shadow: 0 8px 30px rgba(0,0,0,.45);
}
.panel-head { display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.brand { font-size: 16px; letter-spacing: .02em; }
.panel-body { overflow-y: auto; padding: 12px 14px 18px; flex: 1; }
.mobile-only { display: none; }

.field { margin-bottom: 10px; position: relative; }
.field > label { margin-bottom: 3px; }
.place-row { display: flex; gap: 6px; }
.coords { font-size: 11px; min-height: 14px; margin-top: 2px; }
.suggest { position: absolute; z-index: 5; left: 0; right: 0; margin: 2px 0 0; padding: 4px 0; list-style: none;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; max-height: 240px; overflow-y: auto; }
.suggest li { padding: 6px 10px; cursor: pointer; font-size: 13px; }
.suggest li:hover, .suggest li.active { background: var(--line); }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1.3fr; gap: 8px; align-items: end; margin-bottom: 6px; }
.advanced { margin-top: 6px; border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; }
.advanced summary { cursor: pointer; color: var(--fg-2); font-size: 13px; }
.advanced .grid3 { margin-top: 8px; }

/* results */
#results { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }
#summary p { margin: 0 0 8px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 12px 0 6px; }
.warn-list { margin: 0; padding: 0; list-style: none; }
.warn-list li { color: var(--warn); font-size: 12px; margin-bottom: 4px; }
.chain-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; margin-bottom: 6px;
  cursor: pointer; display: flex; gap: 10px; align-items: center; background: var(--panel-2); }
.chain-card.active { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.chain-card .meta { flex: 1; }
.badge { font-size: 12px; font-weight: 600; padding: 2px 7px; border-radius: 10px; white-space: nowrap; }
.badge.good { background: rgba(63,185,122,.16); color: var(--good); }
.badge.warn { background: rgba(224,168,58,.16); color: var(--warn); }
.badge.bad { background: rgba(239,90,79,.16); color: var(--bad); }

.site, .hop { border-left: 3px solid var(--line); padding: 4px 0 4px 10px; margin: 8px 0; }
.site.relay { border-left-color: var(--relay); }
.hop { cursor: pointer; border-radius: 0 6px 6px 0; }
.hop:hover { background: var(--panel-2); }
.hop.good { border-left-color: var(--good); }
.hop.bad { border-left-color: var(--bad); }
.row { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.kv { font-size: 12px; color: var(--fg-2); }
.kv b { color: var(--fg); font-weight: 600; }
.links a { color: var(--accent); font-size: 12px; margin-right: 10px; }
.actions { margin: 14px 0 6px; display: flex; gap: 8px; flex-wrap: wrap; }
.plain-list { list-style: none; margin: 0 0 12px; padding: 0; }
.plain-list li { display: flex; align-items: center; gap: 6px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.plain-list li a { color: var(--fg); flex: 1; cursor: pointer; }
.plain-list li a:hover { color: var(--accent); }

/* profile drawer */
#profile {
  position: absolute; z-index: 1000; left: 414px; right: 12px; bottom: 12px; height: 240px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column;
  box-shadow: 0 8px 30px rgba(0,0,0,.45);
}
.profile-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.profile-wrap { position: relative; flex: 1; }
#profile-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#profile-tip { position: absolute; pointer-events: none; background: rgba(15,20,25,.92); border: 1px solid var(--line);
  border-radius: 6px; padding: 5px 8px; font-size: 12px; white-space: nowrap; }

#pick-hint { position: absolute; z-index: 1100; top: 14px; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--accent); border-radius: 20px; padding: 6px 14px; }
.map-pin { border-radius: 50%; border: 3px solid #000; display: grid; place-items: center; font-weight: 700;
  font-size: 12px; color: #000; box-shadow: 0 1px 6px rgba(0,0,0,.6); }
.map-pin.end { background: #fff; }
.map-pin.relay { background: var(--relay); }
.leaflet-container { font: inherit; }
.leaflet-popup-content { font-size: 13px; }

@media (max-width: 760px) {
  #panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; height: 46vh; border-radius: 14px 14px 0 0; }
  #panel.expanded { height: 88vh; }
  .mobile-only { display: inline-block; }
  #profile { left: 8px; right: 8px; bottom: calc(46vh + 8px); height: 190px; }
  #panel.expanded ~ #profile { display: none !important; }
  .grid3 { grid-template-columns: repeat(2, 1fr); }
  .panel-body { padding: 10px 16px 18px; }
}

.locate-btn { width: 34px; height: 34px; display: grid !important; place-items: center; background: #fff; color: #333; }
.locate-btn.on { color: var(--accent); }
.map-pin.relay.existing { background: var(--good); }
.map-pin.relay.structure { background: #c17cff; }
.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 0 6px; border-radius: 8px; margin-right: 4px; }
.tag.existing { background: rgba(63,185,122,.18); color: var(--good); }
.tag.tower { background: rgba(193,124,255,.18); color: #c17cff; }
.tag.hilltop { background: rgba(255,210,60,.16); color: var(--relay); }
.leaflet-popup-content a { color: #1f5fbf; }
#sites-note { position: absolute; z-index: 1000; bottom: 30px; right: 12px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 4px 10px; font-size: 12px; color: var(--fg-2); }
@media (max-width: 760px) { #sites-note { top: 12px; bottom: auto; left: 12px; right: auto; } }
