:root {
  color-scheme: dark;
  --bg: #050914;
  --panel: rgba(7, 12, 24, 0.88);
  --panel-strong: rgba(10, 18, 34, 0.96);
  --border: rgba(151, 176, 214, 0.18);
  --text: #e9f0fb;
  --muted: #8fa2bd;
  --blue: #6aa7ff;
  --cyan: #28e0d0;
  --amber: #f5b84b;
  --red: #ff5d6c;
  --green: #38d996;
  --purple: #c084fc;
}

* {
  box-sizing: border-box;
}

html,
body,
#map {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}

#map {
  position: fixed;
  inset: 0;
}

.maplibregl-ctrl-bottom-left,
.maplibregl-ctrl-bottom-right,
.leaflet-control-attribution {
  display: none;
}

.leaflet-container {
  background: #06101f;
  font: inherit;
}

.leaflet-control-zoom a {
  background: rgba(11, 18, 32, 0.94);
  border-bottom-color: rgba(148, 163, 184, 0.18);
  color: #e9f0fb;
}

.leaflet-control-zoom a:hover {
  background: rgba(31, 42, 62, 0.98);
  color: #ffffff;
}

.leaflet-tooltip {
  background: rgba(8, 13, 24, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.28);
  color: #e9f0fb;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
}

.flow-arrow {
  background: transparent;
  border: 0;
  color: #f8fafc;
  font-size: 24px;
  font-weight: 900;
  line-height: 24px;
  text-align: center;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
}

.leaflet-overlay-pane path.flow-line {
  stroke-linecap: round;
  animation: flow-dash 1.05s linear infinite;
  filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.18));
}

.leaflet-overlay-pane path.flow-import {
  animation-duration: 0.95s;
}

.leaflet-overlay-pane path.flow-export {
  animation-duration: 1.15s;
}

@keyframes flow-dash {
  to {
    stroke-dashoffset: -26;
  }
}

.panel {
  position: fixed;
  top: 18px;
  left: 18px;
  width: min(390px, calc(100vw - 36px));
  max-height: calc(100vh - 36px);
  overflow: auto;
  background: linear-gradient(180deg, var(--panel-strong), var(--panel));
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 22px 80px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(18px);
  padding: 16px;
}

.brand {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.eyebrow,
.section-title,
.label {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1 {
  margin: 2px 0 0;
  font-size: 30px;
  line-height: 1;
  letter-spacing: 0;
}

.health {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 9px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.health.ok {
  color: var(--cyan);
  border-color: rgba(40, 224, 208, 0.35);
}

.now {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 14px 0 16px;
}

.now > div,
.details,
.layer {
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.now > div {
  padding: 12px;
}

.metric {
  display: block;
  font-size: 25px;
  font-weight: 800;
  line-height: 1;
}

.section-title {
  margin: 16px 0 8px;
}

.layers {
  display: grid;
  gap: 8px;
}

.layer {
  width: 100%;
  display: grid;
  grid-template-columns: 18px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.layer:hover {
  background: rgba(255, 255, 255, 0.075);
}

.layer.inactive {
  opacity: 0.52;
}

.layer.inactive .dot {
  background: transparent !important;
  border: 1px solid currentColor;
  box-shadow: none;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 14px currentColor;
}

.layer-name {
  display: block;
  font-size: 14px;
  font-weight: 800;
}

.layer-desc {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
  line-height: 1.25;
}

.layer-meta {
  display: block;
  color: rgba(143, 162, 189, 0.74);
  font-size: 11px;
  line-height: 1.25;
  margin-top: 5px;
}

.layer-legend {
  display: grid;
  gap: 6px;
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px solid rgba(151, 176, 214, 0.12);
  color: #c5d4ea;
  font-size: 11px;
  font-weight: 750;
}

.layer-legend div {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.refresh-badge {
  border: 1px solid rgba(40, 224, 208, 0.22);
  border-radius: 999px;
  padding: 4px 7px;
  color: #9feee7;
  background: rgba(40, 224, 208, 0.07);
  font-size: 10px;
  font-weight: 900;
  white-space: nowrap;
}

.badge.live {
  color: var(--cyan);
  border-color: rgba(40, 224, 208, 0.35);
}

.layer-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.switch {
  min-width: 34px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 7px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  font-size: 10px;
  font-weight: 900;
  text-align: center;
  text-transform: uppercase;
}

.layer.inactive .switch {
  color: var(--muted);
  background: transparent;
}

.details {
  min-height: 122px;
  padding: 12px;
  font-size: 13px;
  line-height: 1.45;
}

.details h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.details dl {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 5px 10px;
  margin: 0;
}

.details dt {
  color: var(--muted);
}

.details dd {
  margin: 0;
}

.muted {
  color: var(--muted);
}

.sourcebar {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sourcebar span {
  padding: 7px 9px;
  background: rgba(7, 12, 24, 0.78);
  border: 1px solid var(--border);
  border-radius: 999px;
  backdrop-filter: blur(14px);
}

.map-legend {
  position: fixed;
  right: 18px;
  top: 18px;
  z-index: 5;
  display: grid;
  gap: 8px;
  min-width: 168px;
  padding: 12px;
  background: rgba(7, 12, 24, 0.84);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
  backdrop-filter: blur(14px);
  box-shadow: 0 18px 54px rgba(0, 0, 0, 0.36);
}

.map-legend div {
  display: flex;
  align-items: center;
  gap: 9px;
}

.legend-muted {
  color: var(--muted);
  font-weight: 700;
}

.legend-line {
  width: 30px;
  height: 0;
  border-top: 4px solid var(--green);
  border-radius: 999px;
}

.legend-line.import {
  border-color: var(--green);
}

.legend-line.export {
  border-color: var(--amber);
}

.legend-line.power {
  border-color: #ff8bd1;
}

.legend-line.data {
  border-color: #4cc9ff;
  border-top-style: dashed;
}

.legend-line.traffic-critical {
  border-color: var(--red);
}

.legend-line.traffic-delay {
  border-color: var(--amber);
}

.legend-line.high-voltage {
  border-color: #d6e4ff;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--amber);
  border: 1px solid rgba(255, 255, 255, 0.8);
}

.legend-dot.energy {
  background: var(--cyan);
}

.legend-dot.plant,
.legend-dot.incident {
  background: var(--red);
}

.legend-dot.solar,
.legend-dot.asset {
  background: #facc15;
}

.legend-dot.wind,
.legend-dot.fiber-good {
  background: var(--green);
}

.legend-dot.internet {
  background: var(--purple);
}

.legend-dot.fiber-mid,
.legend-dot.grid,
.legend-dot.port,
.legend-dot.air,
.legend-dot.weather {
  background: #4cc9ff;
}

.legend-dot.fiber-low {
  background: var(--red);
}

.legend-dot.high-voltage {
  width: 8px;
  height: 8px;
  background: #d6e4ff;
}

.marker {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.8);
  background: var(--cyan);
  box-shadow: 0 0 0 5px rgba(40, 224, 208, 0.14), 0 0 22px rgba(40, 224, 208, 0.45);
  cursor: pointer;
}

.fiber-marker {
  background: transparent;
  border: 0;
}

.fiber-bubble {
  width: 32px;
  height: 32px;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  background: var(--marker-color, var(--cyan));
  color: #06101c;
  box-shadow: 0 0 0 5px rgba(255, 255, 255, 0.12), 0 10px 26px rgba(0, 0, 0, 0.38);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  font: inherit;
  font-size: 10px;
  font-weight: 900;
}

.fiber-bubble {
  pointer-events: none;
}

@media (max-width: 720px) {
  .panel {
    top: 10px;
    left: 10px;
    width: calc(100vw - 20px);
    max-height: 58vh;
    padding: 12px;
  }

  h1 {
    font-size: 25px;
  }

  .sourcebar {
    left: 10px;
    right: 10px;
    bottom: 10px;
    justify-content: center;
  }
}
