/* ═══════════════════════════════════════════════════
   Helium Network Map — Dark Theme UI
   Matches: world.helium.com/en/network/mobile + /iot
   ═══════════════════════════════════════════════════ */

/* ── Reset ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html.helium-page,
html.helium-page body {
  margin: 0; padding: 0;
  width: 100%; height: 100dvh;
  overflow: hidden;
  background: #060b18;
  color: #e8edf8;
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ── Map wrapper ─────────────────────────────────── */
#helium-map-root {
  position: fixed; inset: 0; z-index: 0;
}
#helium-map {
  width: 100%; height: 100%;
}
.maplibregl-canvas { outline: none; }

/* ── MapLibre control overrides ──────────────────── */
.maplibregl-ctrl-group {
  background: rgba(8,12,28,0.88) !important;
  border: 1px solid rgba(255,255,255,0.09) !important;
  border-radius: 10px !important;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5) !important;
  backdrop-filter: blur(14px);
  overflow: hidden;
}
.maplibregl-ctrl-group button {
  color: #8899cc !important;
  border-bottom: 1px solid rgba(255,255,255,0.07) !important;
  width: 36px !important; height: 36px !important;
  transition: background 0.15s, color 0.15s;
}
.maplibregl-ctrl-group button:last-child { border-bottom: none !important; }
.maplibregl-ctrl-group button:hover {
  background: rgba(255,255,255,0.07) !important;
  color: #c8d6ff !important;
}
.maplibregl-ctrl-group button span {
  filter: invert(60%) sepia(30%) saturate(200%) hue-rotate(200deg);
}
.maplibregl-ctrl-attrib {
  background: rgba(6,11,24,0.7) !important;
  color: #3a4060 !important;
  font-size: 10px !important;
  border-radius: 4px !important;
}
.maplibregl-ctrl-attrib a { color: #3a4060 !important; }
.maplibregl-ctrl-scale {
  background: rgba(6,11,24,0.7) !important;
  border: 1px solid rgba(255,255,255,0.12) !important;
  color: #667 !important;
  font-size: 10px !important;
}
.maplibregl-popup-content {
  background: rgba(8,12,28,0.96) !important;
  border: 1px solid rgba(255,255,255,0.12) !important;
  border-radius: 12px !important;
  padding: 14px 16px !important;
  box-shadow: 0 8px 40px rgba(0,0,0,0.7) !important;
  min-width: 190px;
}
.maplibregl-popup-tip { display: none !important; }
.maplibregl-popup-close-button {
  color: #556 !important;
  font-size: 18px !important;
  line-height: 1;
  right: 8px !important; top: 6px !important;
  padding: 0;
}
.maplibregl-popup-close-button:hover { color: #aab !important; background: none !important; }

/* ── Navigation bar ──────────────────────────────── */
#helium-nav {
  position: fixed; top: 0; left: 0; right: 0;
  z-index: 100;
  height: 58px;
  display: flex; align-items: center;
  padding: 0 18px;
  gap: 14px;
  background: linear-gradient(180deg,
    rgba(4,8,20,0.97) 0%,
    rgba(4,8,20,0.75) 70%,
    transparent 100%
  );
  pointer-events: none;
}
#helium-nav > * { pointer-events: auto; }

/* Logo */
.helium-logo {
  display: flex; align-items: center; gap: 9px;
  text-decoration: none; color: #dde5ff;
  font-weight: 700; font-size: 14px;
  letter-spacing: -0.2px;
  transition: opacity 0.2s;
}
.helium-logo:hover { opacity: 0.82; }
.helium-logo svg { width: 28px; height: 28px; flex-shrink: 0; }

/* Network switcher pill */
.network-switcher {
  display: flex; align-items: center;
  background: rgba(8,12,28,0.85);
  border: 1px solid rgba(255,255,255,0.11);
  border-radius: 100px;
  padding: 3px 3px;
  gap: 2px;
  backdrop-filter: blur(14px);
  box-shadow: 0 2px 12px rgba(0,0,0,0.4);
}
.network-btn {
  display: flex; align-items: center; gap: 7px;
  padding: 7px 16px;
  border-radius: 100px;
  border: none;
  background: transparent;
  color: #677099;
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
  user-select: none;
}
.network-btn .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background 0.2s;
}
.network-btn.mobile .dot { background: #0094ff; }
.network-btn.iot    .dot { background: #00d4a8; }

.network-btn.active {
  background: rgba(255,255,255,0.09);
  color: #e8edf8;
}
.network-btn:hover:not(.active) {
  background: rgba(255,255,255,0.05);
  color: #b0bcdc;
}

/* ── Sidebar (stats panel) ───────────────────────── */
#helium-sidebar {
  position: fixed;
  top: 70px; left: 14px;
  z-index: 90;
  width: 294px;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
#helium-sidebar > * { pointer-events: auto; }

.helium-card {
  background: rgba(6,10,24,0.9);
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 14px;
  padding: 16px 18px;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
}
.helium-card-title {
  font-size: 10.5px;
  font-weight: 600;
  color: #3e4e70;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 14px;
}

/* Stat rows */
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 8px;
  padding: 11px 0;
  border-bottom: 1px solid rgba(255,255,255,0.055);
}
.stat-row:last-of-type { border-bottom: none; padding-bottom: 0; }
.stat-row:first-of-type { padding-top: 0; }

.stat-label {
  font-size: 11.5px;
  color: #4a5878;
  line-height: 1.3;
  margin-bottom: 3px;
}
.stat-value {
  font-size: 22px;
  font-weight: 700;
  color: #e8edf8;
  letter-spacing: -0.8px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.stat-change {
  font-size: 11px;
  color: #4a5878;
  margin-top: 3px;
  display: flex; align-items: center; gap: 2px;
  font-variant-numeric: tabular-nums;
}
.stat-change.positive { color: #22c55e; }
.stat-change.negative { color: #f87171; }

/* Sparkline */
.sparkline-wrap {
  margin-top: 14px;
  height: 50px;
  position: relative;
}
.sparkline-wrap svg { width: 100%; height: 100%; overflow: visible; }
.sparkline-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
}
.sparkline-meta span {
  font-size: 10px;
  color: #2d3852;
  font-variant-numeric: tabular-nums;
}

/* ── Layer controls ──────────────────────────────── */
#helium-layers {
  position: fixed;
  bottom: 36px; left: 14px;
  z-index: 90;
  display: flex; flex-direction: column; gap: 6px;
}

.layer-toggle {
  display: flex; align-items: center; gap: 10px;
  background: rgba(6,10,24,0.88);
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 9px;
  padding: 9px 13px;
  cursor: pointer;
  backdrop-filter: blur(14px);
  user-select: none;
  transition: border-color 0.2s, background 0.2s;
  min-width: 190px;
}
.layer-toggle:hover {
  border-color: rgba(255,255,255,0.18);
  background: rgba(10,16,34,0.92);
}
.layer-toggle:focus-visible {
  outline: 2px solid #0094ff;
  outline-offset: 2px;
}

.layer-toggle-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}
.layer-toggle-label {
  font-size: 12px;
  color: #8899cc;
  font-weight: 500;
  flex: 1;
}

/* Switch track */
.layer-toggle-switch {
  width: 30px; height: 17px;
  background: rgba(255,255,255,0.1);
  border-radius: 100px;
  position: relative;
  flex-shrink: 0;
  transition: background 0.22s;
}
.layer-toggle-switch::after {
  content: '';
  position: absolute;
  top: 2.5px; left: 2.5px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #445;
  transition: transform 0.22s, background 0.22s;
}

/* ON state – Mobile */
.layer-toggle.on .layer-toggle-switch { background: rgba(0,148,255,0.4); }
.layer-toggle.on .layer-toggle-switch::after {
  transform: translateX(13px);
  background: #0094ff;
}
.layer-toggle.on .layer-toggle-label { color: #c8d6ff; }

/* ON state – IoT */
.layer-toggle.on.iot-layer .layer-toggle-switch { background: rgba(0,212,168,0.35); }
.layer-toggle.on.iot-layer .layer-toggle-switch::after { background: #00d4a8; }
.layer-toggle.on.iot-layer .layer-toggle-label { color: #b0f0e4; }

/* ── Loading screen ──────────────────────────────── */
#helium-loading {
  position: fixed; inset: 0;
  z-index: 200;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: #060b18;
  gap: 18px;
  transition: opacity 0.55s ease;
}
#helium-loading.hidden { opacity: 0; pointer-events: none; }

.loading-spinner {
  width: 40px; height: 40px;
  border: 2.5px solid rgba(0,148,255,0.15);
  border-top-color: #0094ff;
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}
.loading-spinner.iot {
  border-color: rgba(0,212,168,0.15);
  border-top-color: #00d4a8;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
  font-size: 13px;
  color: #3a4e70;
  letter-spacing: 0.2px;
}
.loading-progress {
  width: 160px; height: 2px;
  background: rgba(255,255,255,0.06);
  border-radius: 2px;
  overflow: hidden;
}
.loading-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #0094ff, #00d4a8);
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* ── Popup content ───────────────────────────────── */
.popup-title {
  font-size: 13px; font-weight: 600;
  color: #dde5ff;
  margin-bottom: 8px;
}
.popup-stat {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: #5a6a90;
  margin-bottom: 4px;
}
.popup-stat:last-child { margin-bottom: 0; }
.popup-stat span:last-child { color: #b8c4e0; font-weight: 500; }
.popup-active   { color: #22c55e !important; }
.popup-inactive { color: #445 !important; }

/* ── Error banner ────────────────────────────────── */
#helium-error {
  position: fixed;
  bottom: 44px; left: 50%;
  transform: translateX(-50%);
  z-index: 150;
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.3);
  color: #fca5a5;
  padding: 10px 18px;
  border-radius: 9px;
  font-size: 12.5px;
  display: none;
  text-align: center;
  backdrop-filter: blur(12px);
  max-width: min(400px, 90vw);
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

/* ── Attribution ─────────────────────────────────── */
#helium-attribution {
  position: fixed;
  bottom: 6px; left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  font-size: 9.5px;
  color: rgba(255,255,255,0.18);
  white-space: nowrap;
  pointer-events: none;
  letter-spacing: 0.2px;
}

/* ── MapLibre controls position ──────────────────── */
.maplibregl-ctrl-top-right { top: 66px !important; right: 12px !important; }
.maplibregl-ctrl-bottom-left { bottom: 30px !important; left: 14px !important; }

/* ── Responsive ──────────────────────────────────── */

/* Tablet */
@media (max-width: 900px) {
  #helium-sidebar { width: 270px; }
}

/* Mobile landscape / small tablet */
@media (max-width: 768px) {
  #helium-sidebar {
    top: auto;
    bottom: 70px;
    left: 8px; right: 8px;
    width: auto;
    max-height: 42vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  #helium-sidebar::-webkit-scrollbar { display: none; }

  .helium-card { padding: 13px 14px; }
  .stat-value  { font-size: 19px; }

  #helium-layers {
    bottom: 8px; left: 8px;
    flex-direction: row; flex-wrap: wrap; gap: 5px;
  }
  .layer-toggle { padding: 7px 11px; min-width: unset; }
  .layer-toggle-label { font-size: 11px; }

  #helium-nav { height: 50px; padding: 0 12px; gap: 10px; }
  .network-btn { padding: 6px 12px; font-size: 12.5px; }

  .maplibregl-ctrl-top-right { top: 58px !important; }
}

/* Small phone */
@media (max-width: 420px) {
  .helium-logo span { display: none; }
  .stat-value { font-size: 18px; }
  .helium-card-title { font-size: 9.5px; }
  .network-btn { padding: 5px 10px; }
  .network-btn span:not(.dot) { font-size: 12px; }
}

/* Very small */
@media (max-width: 360px) {
  #helium-sidebar { max-height: 38vh; }
  .layer-toggle-label { display: none; }
}
