:root {
  color-scheme: light;
  --ink: #17212b;
  --muted: #5d6977;
  --panel: #ffffff;
  --paper: #edf0e7;
  --accent: #7b238f;
  --accent-strong: #531367;
  --teal: #0c7c84;
  --line: #d8dddf;
  --shadow: 0 18px 44px rgba(30, 42, 50, 0.18);
}

* {
  box-sizing: border-box;
}

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

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

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  height: 100vh;
  min-height: 620px;
}

.panel {
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px;
  background: var(--panel);
  box-shadow: var(--shadow);
  width: 340px;
  min-width: 0;
  overflow: hidden;
  transition: width 0.28s ease;
}

.app-shell.panel-hidden .panel {
  width: 0;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 13px;
  height: 44px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--accent), var(--teal));
}

h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.05;
  letter-spacing: 0;
}

p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.controls {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: #2d3843;
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  color: var(--ink);
  background: #f8faf7;
}

input:focus,
select:focus {
  outline: 2px solid rgba(12, 124, 132, 0.22);
  border-color: var(--teal);
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  color: white;
  background: var(--accent-strong);
  font-weight: 800;
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stats div {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8faf7;
}

.stats strong,
.stats span {
  display: block;
}

.stats strong {
  overflow-wrap: anywhere;
  font-size: 18px;
  line-height: 1.15;
}

.stats span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
}

.status {
  min-height: 72px;
  padding: 12px;
  border-left: 4px solid var(--teal);
  color: #263341;
  background: #eef7f5;
  font-size: 13px;
  line-height: 1.45;
}

.legend {
  display: grid;
  gap: 10px;
  margin-top: auto;
  color: #34424f;
  font-size: 13px;
}

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

.line {
  width: 34px;
  height: 0;
  border-top: 5px solid;
}

.line.road {
  border-color: var(--accent);
}

.road-badge {
  z-index: 460;
  cursor: pointer;
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  border-radius: 7px;
  padding: 2px 8px;
  color: #fff;
  font-family: inherit;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.2px;
  line-height: 1.35;
  white-space: nowrap;
  box-shadow: 0 2px 7px rgba(20, 30, 40, 0.4);
  transition: transform 0.08s ease;
}

.road-badge:hover {
  transform: scale(1.14);
}

.road-badge.europa {
  background: #1f7a34;
}

.road-badge.riks {
  background: #34424f;
}

.badge-swatch {
  flex: none;
  padding: 1px 6px;
  border-radius: 6px;
  background: #1f7a34;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
}

.line.spine {
  border-color: rgba(47, 52, 64, 0.5);
  border-top-style: dashed;
}

.line.bar {
  height: 7px;
  border-top: 0;
  border-radius: 2px;
  background: linear-gradient(
    90deg,
    rgb(59, 130, 189),
    rgb(38, 166, 154),
    rgb(242, 181, 61),
    rgb(214, 64, 56)
  );
}

.map-wrap {
  position: relative;
  overflow: hidden;
  min-width: 0;
  height: 100vh;
  min-height: 620px;
}

#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: auto;
  background: #dde7ec;
}

#chartOverlay {
  position: absolute;
  inset: 0;
  z-index: 450;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.chart-spine {
  fill: none;
  stroke: rgba(37, 41, 50, 0.7);
  stroke-width: 1.8;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.guide-curve {
  fill: none;
  stroke: rgba(37, 41, 50, 0.4);
  stroke-width: 1;
}

.guide-text {
  fill: #20242c;
  font-size: 11px;
  font-weight: 700;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.9);
  stroke-width: 3;
}

.density-bin {
  fill: rgba(123, 35, 143, 0.62);
  stroke: rgba(123, 35, 143, 0.52);
  stroke-width: 0.6;
}

.panel-toggle {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 500;
  width: 40px;
  min-height: 40px;
  height: 40px;
  padding: 0;
  border-radius: 10px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
}

.view-toggle {
  position: absolute;
  top: 16px;
  left: 66px;
  z-index: 500;
  width: 54px;
  min-height: 40px;
  height: 40px;
  padding: 0;
  border-radius: 10px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.92);
  font-size: 15px;
  font-weight: 800;
  box-shadow: var(--shadow);
}

.view-toggle.active {
  color: #fff;
  background: var(--accent-strong);
}

.year-selector {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 500;
  width: 188px;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 8px 32px rgba(20, 30, 40, 0.14), 0 1px 4px rgba(20, 30, 40, 0.08);
}

.year-title,
.time-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: var(--muted);
}

.year-road-name {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.2px;
  line-height: 1.35;
  color: #fff;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(20, 30, 40, 0.3);
  text-transform: none;
}

.year-road-name.europa {
  background: #1f7a34;
}

.year-road-name.riks {
  background: #34424f;
}

#yearButtons {
  display: grid;
  gap: 3px;
}

.year-btn {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.year-btn:hover {
  background: rgba(123, 35, 143, 0.06);
  color: var(--ink);
}

.year-btn.active {
  border-color: rgba(123, 35, 143, 0.18);
  background: rgba(123, 35, 143, 0.09);
  color: var(--ink);
}

.year-dot {
  justify-self: center;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--accent), var(--teal));
}

.year-label {
  font-size: 12px;
}

.year-count {
  color: var(--ink);
  font-size: 11px;
  font-weight: 800;
  opacity: 0.75;
}

.year-btn.active .year-count {
  opacity: 1;
}

.time-dial {
  position: absolute;
  bottom: 16px;
  left: 16px;
  z-index: 500;
  width: 168px;
  padding: 12px 12px 6px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.dial-svg {
  width: 144px;
  height: 144px;
  touch-action: none;
}

.dial-track {
  fill: none;
  stroke: var(--line);
  stroke-width: 6;
}

.dial-arc {
  fill: none;
  stroke: var(--accent);
  stroke-width: 6;
  stroke-linecap: round;
}

.dial-tick {
  stroke: rgba(93, 105, 119, 0.55);
  stroke-width: 1;
}

.dial-tick.major {
  stroke: var(--muted);
  stroke-width: 1.6;
}

.dial-hour {
  fill: var(--muted);
  font-size: 9px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: middle;
}

.dial-handle {
  fill: #ffffff;
  stroke: var(--accent-strong);
  stroke-width: 2.5;
  cursor: grab;
}

.dial-value {
  fill: var(--ink);
  font-size: 15px;
  font-weight: 800;
  text-anchor: middle;
}

.dial-value-sub {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-anchor: middle;
}

.road-info-overlay {
  position: absolute;
  bottom: 46px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  padding: 7px 20px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  font-size: 17px;
  font-weight: 800;
  color: var(--ink);
  pointer-events: none;
  white-space: nowrap;
  letter-spacing: 0.3px;
}

.source {
  position: absolute;
  right: 14px;
  bottom: 14px;
  z-index: 500;
  max-width: min(520px, calc(100% - 28px));
  padding: 7px 10px;
  border-radius: 6px;
  color: #263341;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 8px 20px rgba(30, 42, 50, 0.14);
  font-size: 12px;
}

.leaflet-popup-content {
  margin: 12px 14px;
  min-width: 190px;
}

.popup-title {
  margin-bottom: 6px;
  font-weight: 800;
}

.popup-row {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  color: #34424f;
  font-size: 12px;
}

.popup-row span:last-child {
  color: #111a22;
  font-weight: 700;
  text-align: right;
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(420px, 1fr);
    height: auto;
    min-height: 100vh;
  }

  .panel {
    position: relative;
    width: auto;
    padding: 16px;
  }

  .map-wrap {
    height: 68vh;
    min-height: 420px;
  }

  .controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .controls button {
    grid-column: 1 / -1;
  }

  .legend {
    margin-top: 0;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .legend div {
    align-items: flex-start;
  }
}

@media (max-width: 560px) {
  .controls,
  .stats,
  .legend {
    grid-template-columns: 1fr;
  }
}
