:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #17212b;
  --muted: #667085;
  --line: #d9e0e7;
  --accent: #1f5f8b;
  --accent-soft: #e9f1f7;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.10);
  --sidebar-width: 370px;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; }
body {
  overflow: hidden;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select { font: inherit; }
button, input[type="checkbox"], input[type="range"] { accent-color: var(--accent); }

#app {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#sidebar {
  position: relative;
  z-index: 1000;
  height: 100%;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  box-shadow: 4px 0 18px rgba(15, 23, 42, 0.06);
}
.sidebar-inner { padding: 22px 22px 26px; }
.brand { padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.brand h1 {
  margin: 0;
  font-size: 1.42rem;
  line-height: 1.22;
  letter-spacing: -0.025em;
}
.brand .subtitle {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.90rem;
  line-height: 1.45;
}
.brand .description {
  margin: 12px 0 0;
  font-size: 0.83rem;
  line-height: 1.55;
}

.control-section {
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}
.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.section-title h2 {
  margin: 0;
  color: #344054;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.section-title .value {
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 730;
  text-align: right;
}
label {
  display: block;
  margin: 0 0 7px;
  color: #344054;
  font-size: 0.82rem;
  font-weight: 650;
}
select {
  width: 100%;
  min-height: 39px;
  padding: 8px 10px;
  border: 1px solid #cdd5df;
  border-radius: 8px;
  outline: none;
  color: var(--ink);
  background: #fff;
  font-size: 0.87rem;
}
select:focus {
  border-color: #7aa7c7;
  box-shadow: 0 0 0 3px rgba(31, 95, 139, 0.12);
}
.field + .field { margin-top: 17px; }
.range-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.range-head label { margin-bottom: 5px; }
.range-value {
  color: var(--accent);
  font-size: 0.80rem;
  font-weight: 730;
  font-variant-numeric: tabular-nums;
}
input[type="range"] { width: 100%; margin: 2px 0 0; }
.range-row {
  display: flex;
  justify-content: space-between;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.70rem;
}
.inline-check {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 13px 0 0;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
}
.inline-check input { flex: 0 0 auto; margin: 0; }
.inline-check span { line-height: 1.35; }
.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 15px;
}
button {
  min-height: 37px;
  padding: 7px 10px;
  border: 1px solid #cdd5df;
  border-radius: 8px;
  color: #344054;
  background: #fff;
  font-size: 0.78rem;
  font-weight: 680;
  cursor: pointer;
}
button:hover { border-color: #98a2b3; background: #f8fafc; }
button.primary { border-color: var(--accent); color: #fff; background: var(--accent); }
button.primary:hover { background: #194e72; }

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}
.stat-card {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fbfcfd;
}
.stat-card .label {
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.25;
  letter-spacing: 0.045em;
  text-transform: uppercase;
}
.stat-card .number {
  margin-top: 5px;
  font-size: 1rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}
.coverage {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.5;
}
.colour-note { display: flex; align-items: center; gap: 8px; }
.colour-swatch {
  flex: 0 0 auto;
  width: 31px;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, #18aebd, #ef8a72, #e1bd3e, #5ca66f, #c56bb1);
}
.footer {
  padding-top: 18px;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.55;
}
.footer p { margin: 0; }
.footer .links { display: flex; gap: 14px; margin-top: 8px; }
.footer a { color: var(--accent); text-decoration: none; }
.footer a:hover { text-decoration: underline; }

#error-box {
  display: none;
  margin-top: 13px;
  padding: 10px 11px;
  border: 1px solid #f0b8b5;
  border-radius: 8px;
  color: #8a1c17;
  background: #fff1f0;
  font-size: 0.76rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

#network-wrap {
  position: relative;
  min-width: 0;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(circle at 56% 48%, rgba(255,255,255,0.98), rgba(244,247,249,0.96) 62%, #edf1f4 100%);
}
#network-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}
#network-canvas.dragging { cursor: grabbing; }
#network-canvas.node-hover { cursor: pointer; }

#network-summary {
  position: absolute;
  z-index: 500;
  top: 14px;
  left: 50%;
  max-width: min(720px, calc(100% - 160px));
  padding: 9px 14px;
  transform: translateX(-50%);
  border: 1px solid rgba(255,255,255,0.80);
  border-radius: 9px;
  color: #344054;
  background: rgba(255,255,255,0.92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  font-size: 0.79rem;
  font-weight: 650;
  text-align: center;
  pointer-events: none;
}
#canvas-help {
  position: absolute;
  z-index: 400;
  left: 50%;
  bottom: 14px;
  max-width: calc(100% - 190px);
  padding: 7px 10px;
  transform: translateX(-50%);
  border-radius: 7px;
  color: #667085;
  background: rgba(255,255,255,0.78);
  font-size: 0.70rem;
  text-align: center;
  pointer-events: none;
}
.zoom-controls {
  position: absolute;
  z-index: 520;
  top: 14px;
  right: 14px;
  display: grid;
  overflow: hidden;
  border: 1px solid #cdd5df;
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}
.zoom-controls button {
  width: 38px;
  min-height: 36px;
  padding: 0;
  border: 0;
  border-bottom: 1px solid #e2e7ec;
  border-radius: 0;
  font-size: 1.05rem;
}
.zoom-controls button:last-child { border-bottom: 0; font-size: 0.95rem; }

#tooltip {
  position: absolute;
  z-index: 800;
  display: none;
  min-width: 155px;
  padding: 9px 10px;
  border: 1px solid rgba(217,224,231,0.9);
  border-radius: 8px;
  color: #344054;
  background: rgba(255,255,255,0.97);
  box-shadow: 0 6px 20px rgba(15,23,42,0.14);
  font-size: 0.74rem;
  line-height: 1.45;
  pointer-events: none;
}
.tooltip-title { margin-bottom: 4px; color: var(--ink); font-weight: 760; }
.tooltip-grid { display: grid; grid-template-columns: auto auto; gap: 2px 13px; }
.tooltip-grid span:nth-child(even) { text-align: right; font-variant-numeric: tabular-nums; }

#loading {
  position: absolute;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(245,247,250,0.84);
  backdrop-filter: blur(3px);
}
#loading.hidden { display: none; }
.loading-card {
  min-width: 230px;
  padding: 19px 23px;
  border-radius: 11px;
  background: #fff;
  box-shadow: var(--shadow);
  font-size: 0.84rem;
  text-align: center;
}
.spinner {
  width: 28px;
  height: 28px;
  margin: 0 auto 11px;
  border: 3px solid #d9e2ea;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#mobile-toggle {
  display: none;
  position: absolute;
  z-index: 1400;
  top: 12px;
  left: 12px;
  min-height: 36px;
  box-shadow: var(--shadow);
}
#sidebar-scrim { display: none; }

@media (max-width: 850px) {
  #app { display: block; }
  #sidebar {
    position: absolute;
    width: min(var(--sidebar-width), calc(100% - 34px));
    transform: translateX(-105%);
    transition: transform 0.22s ease;
  }
  #sidebar.open { transform: translateX(0); }
  #network-wrap { width: 100%; height: 100%; }
  #mobile-toggle { display: inline-flex; }
  #sidebar-scrim {
    position: absolute;
    inset: 0;
    z-index: 900;
    display: block;
    visibility: hidden;
    opacity: 0;
    background: rgba(15,23,42,0.22);
    transition: opacity 0.2s ease, visibility 0.2s ease;
  }
  #sidebar-scrim.visible { visibility: visible; opacity: 1; }
  #network-summary { top: 60px; max-width: calc(100% - 32px); }
  .zoom-controls { top: 12px; right: 12px; }
  #canvas-help { max-width: calc(100% - 28px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
