:root {
  color-scheme: light;
  --bg: #eef2f6;
  --surface: #ffffff;
  --ink: #172033;
  --muted: #65758c;
  --line: #d8e0ea;
  --accent: #db1730;
  --accent-dark: #a80e22;
  --ok: #087c5f;
  --warn: #986400;
  --bad: #b42318;
}

/* Critical Leaflet layout fallback. If CDN CSS is blocked, tiles must still be clipped and positioned. */
.leaflet-container {
  position: relative;
  overflow: hidden;
  background: #dce6ee;
  outline: 0;
}

.leaflet-pane,
.leaflet-map-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  left: 0;
  top: 0;
}

.leaflet-container img.leaflet-tile {
  max-width: none;
  max-height: none;
}

.leaflet-marker-icon {
  transition: transform 900ms linear;
}

.leaflet-tile {
  border: 0;
  user-select: none;
}

.leaflet-control {
  position: relative;
  z-index: 800;
  pointer-events: auto;
}

.leaflet-top,
.leaflet-bottom {
  position: absolute;
  z-index: 1000;
  pointer-events: none;
}

.leaflet-top {
  top: 0;
}

.leaflet-right {
  right: 0;
}

.leaflet-bottom {
  bottom: 0;
}

.leaflet-left {
  left: 0;
}

.leaflet-control-zoom {
  margin: 0 12px 12px 0;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 10px 26px rgba(22, 32, 48, 0.18);
}

.leaflet-control-zoom a {
  display: block;
  width: 34px;
  height: 34px;
  background: #ffffff;
  color: var(--ink);
  font-size: 22px;
  font-weight: 850;
  line-height: 32px;
  text-align: center;
  text-decoration: none;
}

.leaflet-popup {
  position: absolute;
  text-align: center;
}

.leaflet-popup-content-wrapper {
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 12px 30px rgba(22, 32, 48, 0.22);
}

.leaflet-popup-content {
  margin: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  min-height: 40px;
  border: 1px solid rgba(23, 32, 51, 0.18);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

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

.map-panel {
  position: relative;
  min-height: 100vh;
  background: #dce6ee;
}

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

.toolbar {
  position: absolute;
  z-index: 500;
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.toolbar > div,
.toolbar button {
  pointer-events: auto;
}

.toolbar > div {
  max-width: min(460px, calc(100vw - 190px));
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 12px 36px rgba(22, 32, 48, 0.16);
  backdrop-filter: blur(10px);
}

.toolbar button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  box-shadow: 0 12px 36px rgba(22, 32, 48, 0.14);
}

.eyebrow {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(22px, 3.2vw, 36px);
  line-height: 1.02;
}

h2 {
  font-size: 24px;
  line-height: 1.1;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  border-left: 1px solid var(--line);
  background: var(--surface);
  box-shadow: -12px 0 40px rgba(22, 32, 48, 0.08);
}

.sidebar-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 18px 14px;
  border-bottom: 1px solid var(--line);
}

.field {
  display: grid;
  gap: 6px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}

.field span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.field select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #ffffff;
  color: var(--ink);
  font: inherit;
  font-weight: 850;
}

.pill {
  flex: 0 0 auto;
  min-width: 74px;
  border-radius: 999px;
  padding: 6px 9px;
  background: #edf2f7;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-align: center;
}

.pill.ok {
  background: #ddf7ee;
  color: var(--ok);
}

.pill.error {
  background: #fff0ed;
  color: var(--bad);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  margin: 0;
  background: var(--line);
  border-bottom: 1px solid var(--line);
}

.stats div {
  min-width: 0;
  padding: 12px;
  background: #fbfcfe;
}

.stats dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.stats dd {
  margin: 5px 0 0;
  overflow: hidden;
  font-size: 14px;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.error {
  margin: 12px;
  border: 1px solid #ffd5cf;
  border-radius: 8px;
  padding: 10px;
  background: #fff7f5;
  color: var(--bad);
  font-size: 13px;
  line-height: 1.35;
}

.vehicle-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 12px;
  overflow: auto;
  list-style: none;
}

.vehicle {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  background: #ffffff;
  cursor: pointer;
}

.vehicle:hover,
.vehicle.active {
  border-color: rgba(219, 23, 48, 0.45);
  box-shadow: 0 10px 24px rgba(219, 23, 48, 0.08);
}

.vehicle.stale {
  background: #f7f9fc;
}

.vehicle.stale .vehicle-id::after {
  content: "Gammel";
  display: inline-block;
  margin-left: 8px;
  border-radius: 999px;
  padding: 3px 6px;
  background: #edf2f7;
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  vertical-align: middle;
}

.vehicle-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.vehicle-id {
  font-size: 17px;
  font-weight: 950;
}

.direction {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 9px;
  color: var(--muted);
  font-size: 12px;
}

.meta strong {
  display: block;
  color: var(--ink);
  font-size: 13px;
}

.train-icon {
  position: relative;
  width: 34px;
  height: 34px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 8px 18px rgba(35, 41, 55, 0.24);
}

.train-icon::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 4px;
  width: 0;
  height: 0;
  border-right: 5px solid transparent;
  border-bottom: 11px solid #ffffff;
  border-left: 5px solid transparent;
  transform: translateX(-50%);
}

.train-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 12px;
  height: 8px;
  border-radius: 2px;
  background: #ffffff;
  transform: translate(-50%, -34%);
}

.train-icon.stale {
  background: #8a98aa;
  opacity: 0.72;
}

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

.popup-title {
  display: block;
  margin-bottom: 6px;
  color: var(--accent-dark);
  font-size: 16px;
  font-weight: 950;
}

.popup-row {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.popup-row strong {
  color: var(--ink);
}

@media (max-width: 780px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(55vh, 1fr) auto;
  }

  .map-panel {
    min-height: 58vh;
  }

  .sidebar {
    min-height: 42vh;
    max-height: 42vh;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .toolbar {
    top: 10px;
    left: 10px;
    right: 10px;
  }

  .toolbar > div {
    max-width: calc(100vw - 132px);
    padding: 10px;
  }

  .toolbar button span:last-child {
    display: none;
  }

  .stats dd {
    font-size: 12px;
  }
}
