.app { display: flex; min-height: 100%; }

.rail {
  width: var(--rail);
  flex: 0 0 var(--rail);
  background: var(--charcoal);
  color: #f4f5f4;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 30;
}
.brand { display: block; padding: 18px 16px 8px; }
.brand img { display: block; width: 160px; height: auto; }
.rail-label {
  margin: 14px 18px 6px;
  font-size: 11px;
  letter-spacing: 0.12em;
  color: #8e9094;
  font-weight: 600;
}
.rail-nav { display: flex; flex-direction: column; gap: 2px; padding: 0 10px; }
.rail-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: #e6e7e8;
  border-radius: 8px;
  padding: 9px 10px;
  font-weight: 500;
}
.rail-nav a svg { flex: 0 0 auto; }
.rail-nav a:hover { background: #2d3034; }
.rail-nav a[aria-current="page"] {
  background: var(--charcoal-2);
  box-shadow: inset 3px 0 0 var(--lime);
  color: white;
}
.badge {
  margin-left: auto;
  font-size: 10px;
  letter-spacing: 0.06em;
  border: 1px solid #6a6c70;
  color: #c8c9cc;
  border-radius: 999px;
  padding: 1px 6px;
}
.rail-spacer { flex: 1; }
.site-card {
  margin: 8px 12px;
  background: #1d1f22;
  border-radius: 10px;
  padding: 10px 12px;
}
.site-card strong { display: block; font-size: 13px; }
.site-card p { margin: 4px 0 0; color: #b7b9bc; font-size: 12px; }
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--good);
  margin-right: 6px;
}
.rail-foot {
  padding: 4px 16px 14px;
  color: #8e9094;
  font-size: 11px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.tenant-switch { margin: 8px 12px 0; }
.tenant-switch[hidden] { display: none; }
.tenant-switch label { display: block; color: #b7b9bc; font-size: 11px; }
.tenant-switch select {
  width: 100%;
  margin-top: 4px;
  background: #121416;
  color: #f4f5f4;
  border: 1px solid #3a3c40;
  border-radius: 8px;
  padding: 6px;
}
.demo-banner {
  background: #3a2a08;
  color: #ffe7a3;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  padding: 6px 12px;
}
.demo-banner[hidden] { display: none; }
.tenant-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  background: var(--paper);
}

.workspace { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: white;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--top);
}
[data-go] { cursor: pointer; }
.nav-toggle {
  display: none;
  border: 1px solid var(--line);
  background: white;
  border-radius: 8px;
  width: 36px;
  height: 36px;
}
#section-title {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 26px;
  letter-spacing: 0.04em;
  line-height: var(--top);
  min-width: 0;
}
.tabs {
  display: flex;
  align-items: stretch;
  gap: 2px;
  height: 36px;
  margin: 0 -16px;
  padding: 0 16px;
  overflow-x: auto;
}
.tabs:empty { display: none; }
.tabs a, .tabs span {
  flex: 0 0 auto;
  text-decoration: none;
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
  padding: 0 10px;
  line-height: 33px;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--lime); }
.tabs span { opacity: 0.55; }
.top-tools { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.sample-chip {
  border: 1px solid var(--amber);
  color: #8a5a00;
  background: #fff8eb;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
}
.seg { display: flex; background: var(--paper); border-radius: 8px; padding: 2px; }
.seg button {
  border: 0;
  background: transparent;
  border-radius: 6px;
  padding: 4px 8px;
  color: var(--muted);
}
.seg button[aria-pressed="true"] { background: var(--charcoal); color: white; }
.fresh {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: white;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
}
.fresh .dot.amber { background: var(--amber); }
.fresh .dot.grey { background: var(--stale); }
.icon-btn {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: white;
}
.icon-btn .count {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--bad);
  color: white;
  border-radius: 999px;
  font-size: 10px;
  min-width: 16px;
  height: 16px;
  line-height: 16px;
  padding: 0 4px;
}
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0;
  background: var(--charcoal);
  color: var(--lime);
  font-weight: 700;
}
.pop {
  position: relative;
}
.pop-panel {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  min-width: 240px;
  padding: 10px 12px;
  box-shadow: 0 8px 24px rgba(29, 31, 34, 0.08);
  z-index: 25;
}
.pop-panel.open { display: block; }
.pop-panel p { margin: 6px 0; }
.dates { display: flex; gap: 6px; align-items: center; }
.dates input { border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; background: white; }

#view { padding: 16px 18px 28px; }

.card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
}
.card h2, .card h3 {
  margin: 0 0 8px;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.kpi { padding: 12px 14px; }
.kpi b {
  display: block;
  font-family: var(--display);
  font-size: 34px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.02em;
  margin: 4px 0;
}
.kpi span, .kpi small { color: var(--muted); font-size: 12px; }
.kpi.bad { box-shadow: inset 3px 0 0 var(--bad); }
.kpi.warn { box-shadow: inset 3px 0 0 var(--amber); }
.kpi.ok { box-shadow: inset 3px 0 0 var(--excellent); }
.grid-3 { display: grid; grid-template-columns: 1.05fr 1.25fr 0.9fr; gap: 12px; margin-top: 12px; }
.grid-2 { display: grid; grid-template-columns: 1.55fr 0.9fr; gap: 12px; margin-top: 12px; }
.stack { display: flex; height: 14px; border-radius: 4px; overflow: hidden; background: #eee; }
.stack i { display: block; height: 100%; }
.stack .excellent { background: var(--excellent); }
.stack .good { background: var(--good); }
.stack .fair { background: var(--fair); }
.stack .poor { background: var(--poor); }
.stack .bad { background: var(--bad); }
.stack .stale { background: var(--stale); }
.legend { display: flex; flex-wrap: wrap; gap: 8px 12px; margin-top: 8px; font-size: 11px; color: var(--muted); }
.swatch { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; }
.swatch.hollow { background: transparent; box-shadow: inset 0 0 0 1.5px #8D9095; }
.band-block + .band-block { margin-top: 12px; }
.band-head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.trend { width: 100%; height: auto; }
.trend .snr { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.trend .weak { fill: none; stroke: var(--amber); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.trend text { fill: var(--muted); font-size: 10px; font-family: var(--sans); }
.trend text.note { font-size: 9px; }
.map-key { margin-top: 8px; }
.map-key .node-sample { background: #f4f5f4; border: 1px solid #1d1f22; }
.alert { display: flex; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 13px; }
.alert:first-of-type { border-top: 0; }
.alert i { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; flex: 0 0 auto; }
.alert i.bad { background: var(--bad); }
.alert i.warn { background: var(--amber); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.linkish { background: none; border: 0; color: var(--ink); font-weight: 600; padding: 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  padding: 8px 8px 8px 0;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 8px 8px 8px 0; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
.tag {
  display: inline-block;
  min-width: 52px;
  text-align: center;
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 12px;
  font-weight: 650;
}
.tag.excellent { background: var(--excellent); color: white; }
.tag.good { background: var(--good); color: #14301c; }
.tag.fair { background: var(--fair); color: #1d1f22; }
.tag.poor { background: var(--poor); color: #1d1f22; }
.tag.bad { background: var(--bad); color: white; }
.tag.stale { background: var(--stale); color: white; }
.tag.sample { background: #dfe6c8; color: #1d1f22; }
.mini, .btn, .btn-lime {
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 600;
}
.mini { border: 1px solid var(--line); background: white; }
.mini:hover { border-color: var(--ink); }
.btn { border: 1px solid var(--ink); background: var(--ink); color: white; padding: 8px 12px; }
.btn-lime { border: 0; background: var(--lime); color: var(--ink); padding: 8px 12px; }
.btn:disabled, .btn-lime:disabled { opacity: 0.45; cursor: not-allowed; }
.actions { display: flex; gap: 6px; }
.topo { background: #1d1f22; border-radius: 10px; overflow: hidden; }
.topo svg.app-map { display: block; width: 100%; height: auto; min-height: 280px; }
.node-label { display: none; fill: #f4f5f4; font-size: 12px; font-family: Inter, sans-serif; paint-order: stroke; stroke: #1d1f22; stroke-width: 3px; }
.hit:hover .node-label, .hit.on .node-label { display: block; }
.foot-note { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 12px; margin-top: 8px; }
.survey-summary { margin-top: 12px; }
.basemap-switch { display: flex; flex-wrap: wrap; gap: 6px; }
.basemap-switch button[aria-pressed="true"] {
  background: var(--charcoal);
  border-color: var(--charcoal);
  color: white;
}
.opacity-row { display: flex; align-items: center; gap: 8px; margin: 8px 0; font-size: 13px; }
.opacity-row input { flex: 1; }
.leaflet-host { width: 100%; height: 100%; min-height: 280px; background: #2a2c30; }
.leaflet-host[data-ground="none"] { background: #141516; }
.topo-leaflet { height: 280px; min-height: 280px; }
.leaflet-container { background: #2a2c30; font-family: var(--sans); }
.leaflet-control-attribution { font-size: 11px; }
.login-body { min-height: 100%; display: grid; place-items: center; padding: 24px; background: var(--charcoal); }
.login-wrap { width: min(420px, 100%); }
.login-logo { display: block; width: min(240px, 100%); height: auto; margin: 0 auto 18px; }
.login-card { width: 100%; background: white; border-radius: 16px; padding: 28px 28px 24px; box-shadow: 0 12px 40px rgba(29, 31, 34, 0.08); }
.login-card h1 { font-family: var(--display); font-weight: 600; letter-spacing: 0; text-transform: none; font-size: 32px; margin: 12px 0 4px; }
.stack-form { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.stack-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 500; }
.stack-form input, .stack-form select, .table-wrap input, .table-wrap select { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: white; }
.form-error { color: var(--bad); margin: 0; font-size: 13px; }
.token-once { display: flex; flex-direction: column; gap: 6px; background: #f7f8e8; border-radius: 8px; padding: 10px 12px; margin: 12px 0; }
.token-once[hidden] { display: none; }
.leaflet-pane > svg path.link-hit { stroke-opacity: 0 !important; pointer-events: stroke; }
.token-once input { width: 100%; font-family: var(--mono); font-size: 12px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.survey-summary .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.maps { display: grid; grid-template-columns: 250px 1fr; gap: 12px; align-items: stretch; height: calc(100dvh - 248px); min-height: 360px; }
.app:has(.timeline) { height: 100dvh; overflow: hidden; }
.app:has(.timeline) .workspace { height: 100dvh; min-height: 0; overflow: hidden; }
#view:has(.timeline) {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
  overflow: hidden;
  padding-bottom: 12px;
}
#view:has(.timeline) .maps { flex: 1 1 auto; height: auto; min-height: 0; overflow: hidden; grid-template-rows: minmax(0, 1fr); }
.maps .leaflet-container { width: 100%; height: 100% !important; }
#view:has(.timeline) .survey-fold,
#view:has(.timeline) .timeline { flex: 0 0 auto; }
.map-stage {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  background: #2a2c30;
  border-radius: 12px;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}
.map-stage.has-inspector { grid-template-columns: minmax(0, 1fr) auto; }
.map-stage svg.app-map { display: block; width: 100%; height: 100%; min-height: 0; grid-column: 1; grid-row: 1; min-width: 0; }
.maps .leaflet-host { min-height: 0; height: 100%; }
.survey-fold { margin-top: 12px; }
.survey-fold > summary { cursor: pointer; font-weight: 600; }
.survey-fold .survey-summary { margin-top: 8px; }
.map-hint {
  position: absolute;
  z-index: 1100;
  top: 12px;
  left: 54px;
  margin: 0;
  color: #f4f5f4;
  background: rgba(29, 31, 34, 0.88);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
}
.hex-card {
  width: max-content;
  max-width: min(280px, 70vw);
  background: white;
  color: var(--ink);
  border-radius: 12px;
  padding: 12px 14px;
}
.hex-pop {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1100;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}
.hex-card h3 { margin: 0; letter-spacing: 0; text-transform: none; color: var(--ink); font-size: 16px; font-family: var(--display); font-weight: 600; }
.hex-leaflet .leaflet-popup-content-wrapper { padding: 0; border-radius: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18); }
.hex-leaflet .leaflet-popup-content { margin: 0; width: auto !important; }
.plan .card svg.app-map { width: 100%; min-height: 420px; height: calc(100dvh - 280px); }
.coverage-stage { position: relative; }
.coverage-host { height: calc(100dvh - 340px); min-height: 420px; background: #d9ddd8; border-radius: 10px; }
.coverage-controls { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: center; margin: 8px 0; font-size: 13px; }
.coverage-controls label { display: inline-flex; gap: 6px; align-items: center; }
.coverage-nodes { display: flex; flex-wrap: wrap; gap: 8px 14px; margin: 4px 0 8px; font-size: 13px; }
.coverage-nodes label { display: inline-flex; gap: 6px; align-items: center; }
.leaflet-tooltip.coverage-label {
  background: rgba(29, 31, 34, 0.88);
  color: white;
  border: 0;
  border-radius: 6px;
  padding: 1px 5px;
  font-size: 11px;
  box-shadow: none;
}
.leaflet-tooltip.coverage-label::before { display: none; }
.layers label { display: flex; gap: 8px; align-items: flex-start; padding: 4px 0; font-size: 13px; }
.layers .group { margin: 10px 0 4px; font-size: 11px; letter-spacing: 0.08em; color: #8e9094; }
.layers small { display: block; color: #8e9094; margin-left: 22px; }
.inspector {
  position: relative;
  grid-column: 2;
  grid-row: 1;
  width: 280px;
  max-height: 100%;
  overflow: auto;
  margin: 12px;
  background: white;
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}
.inspector h3 { margin: 0; letter-spacing: 0; text-transform: none; color: var(--ink); font-size: 18px; font-family: var(--display); font-weight: 600; }
.kv { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.spark { width: 100%; height: 36px; }
.spark polyline { fill: none; stroke: var(--bad); stroke-width: 2; }
.map-legend, .timeline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  color: #d5d6d8;
  font-size: 12px;
}
.map-legend {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 800;
  background: rgba(29, 31, 34, 0.88);
  border-radius: 8px;
  padding: 6px 10px;
}
.scale {
  position: absolute;
  right: 12px;
  bottom: 12px;
  color: #d5d6d8;
  font-size: 12px;
}
.timeline { margin-top: 12px; background: white; border: 1px solid var(--line); border-radius: 10px; padding: 8px; color: var(--ink); }
.timeline button[aria-pressed="true"] { background: var(--lime); border-color: var(--lime); }

.plan { display: grid; grid-template-columns: 250px minmax(0, 1fr) 270px; gap: 12px; }
.run {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 10px;
  padding: 8px;
  margin-bottom: 6px;
}
.run[aria-pressed="true"] { background: var(--charcoal); color: white; }
.run small { display: block; color: var(--muted); }
.run[aria-pressed="true"] small,
.run[aria-pressed="true"] .muted { color: #c8c9cc; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { background: var(--paper); border-radius: 8px; padding: 8px; }
.stat b { display: block; font-family: var(--display); font-size: 26px; line-height: 1; }
.hist { display: flex; align-items: flex-end; gap: 3px; height: 88px; }
.hist i { flex: 1; background: #2F6FD6; border-radius: 2px 2px 0 0; display: block; }
.error-key { margin-top: 8px; }
.wizard ol { margin: 0; padding-left: 18px; }
.wizard li { margin: 8px 0; }
.wizard label { display: flex; gap: 8px; align-items: center; margin: 4px 0; }
.note { background: #f7f7f6; border-radius: 8px; padding: 10px 12px; }

.banner {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  background: var(--charcoal);
  color: white;
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 12px;
}
.banner p { margin: 4px 0 0; color: #d5d6d8; }
.pill { display: inline-block; background: var(--lime); color: var(--ink); font-weight: 700; font-size: 11px; letter-spacing: 0.04em; border-radius: 999px; padding: 3px 8px; }
.flow { color: #d5d6d8; font-size: 13px; white-space: nowrap; }
.preview { opacity: 0.92; }
.sensor-map { min-height: 420px; background: #2a2c30; border-radius: 10px; overflow: hidden; }
.sensor-map svg.app-map { display: block; width: 100%; height: 100%; min-height: 420px; }
.meter { display: inline-block; width: 72px; height: 8px; background: #eee; border-radius: 99px; overflow: hidden; vertical-align: middle; margin-right: 6px; }
.meter i { display: block; height: 100%; }
.live-pill { background: var(--excellent); color: white; border-radius: 999px; font-size: 11px; font-weight: 700; padding: 3px 8px; }

.settings { display: block; }

.drawer-back { position: fixed; inset: 0; background: rgba(29, 31, 34, 0.35); z-index: 40; }
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: min(400px, 100%);
  background: white;
  z-index: 41;
  padding: 16px 18px;
  overflow: auto;
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.08);
}
.drawer header { display: flex; justify-content: space-between; align-items: center; }
.noscript { padding: 24px; }

@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-3, .plan, .maps { grid-template-columns: 1fr; }
  .map-stage, .map-stage.has-inspector { grid-template-columns: 1fr; }
  #view:has(.timeline) .maps { grid-template-rows: auto minmax(0, 1fr); }
  .map-stage svg.app-map { grid-row: 1; min-height: 420px; }
  .inspector { position: static; width: auto; margin: 12px; grid-column: 1; grid-row: 2; }
}
#view, .card, .kpis > *, .grid-2 > *, .grid-3 > *, .maps > *, .plan > *, .settings > * { min-width: 0; }

@media (max-width: 860px) {
  .app { display: block; }
  .nav-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .rail {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(var(--rail), 86vw);
    transform: translateX(-100%);
    transition: transform 0.18s ease;
    z-index: 40;
  }
  .rail.open { transform: translateX(0); }
  .workspace { width: 100%; }
  .kpis, .grid-2, .settings, .survey-summary .kpis { grid-template-columns: 1fr; }
  .maps { height: auto; min-height: 0; }
  .layers { max-height: 28dvh; overflow: auto; }
  .map-stage, .map-stage svg.app-map, .maps .leaflet-host, .coverage-host { min-height: 280px; height: 52dvh; }
  #view:has(.timeline) .survey-fold { max-height: 42dvh; overflow: auto; }
  .topbar { padding: 0 12px; }
  .topbar-row { min-height: 0; padding-top: 8px; flex-wrap: wrap; }
  #section-title { font-size: 22px; line-height: 36px; }
  .tabs { margin: 0 -12px; padding: 0 12px; }
  .tabs a, .tabs span { padding: 0 8px; }
  .top-tools { width: 100%; margin-left: 0; justify-content: flex-start; }
}
