:root {
  --free-green: #2BA84A;
  --free-orange: #F28C28;
  --free-red: #D93025;
  --no-data: #98A2B3;
  --out-of-service: #5b6475;
  --ink: #1d2433;
  --muted: #5b6475;
  --bg: #ffffff;
  --line: #e3e6ec;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

/* ---------- Tabs: fixed bar on top, one view below it ---------- */
:root { --tabs-h: 44px; --top: calc(var(--tabs-h) + env(safe-area-inset-top)); }
.tabs {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1100;
  display: flex;
  height: var(--top);
  padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
  background: var(--ink);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
}
.tabs a {
  display: flex;
  align-items: center;
  padding: 0 14px;
  border-bottom: 3px solid transparent;
  color: rgba(255, 255, 255, .7);
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  white-space: nowrap;
}
.tabs a:hover { color: #fff; }
.tabs a { gap: 7px; }
.tab-icon { flex: none; display: block; }
/* Narrow screens: icons only (the label stays for screen readers, the title shows on hover) */
@media (max-width: 640px) {
  .tabs a { padding: 0 16px; }
  .tab-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

/* Language dropdown, right end of the tab bar */
.lang {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  padding-left: 8px;
  color: rgba(255, 255, 255, .75);
}
.lang svg { flex: none; display: block; }
.lang select {
  height: 30px;
  padding: 0 6px;
  border: 1px solid rgba(255, 255, 255, .3);
  border-radius: 6px;
  background: transparent;
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.lang select:focus-visible { outline: 2px solid #6d95e6; outline-offset: 1px; }
.lang option { color: var(--ink); background: #fff; }
.tabs a[aria-current="page"] { color: #fff; border-bottom-color: #6d95e6; }
.view[hidden] { display: none; }

.map { position: fixed; top: var(--top); left: 0; right: 0; bottom: 0; }

/* ---------- Car park badge: colour = share of free spaces, number = free spaces ---------- */
.pk {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 26px;
  padding: 0 7px;
  border: 2px solid #fff;
  border-radius: 13px;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
  transform: translate(-50%, -50%);
  white-space: nowrap;
}
.pk.green { background: var(--free-green); }
.pk.orange { background: var(--free-orange); }
.pk.red { background: var(--free-red); }
.pk.nodata { background: var(--no-data); }
.pk.oos { background: var(--out-of-service); }
.pk.closed { opacity: .55; }
.leaflet-marker-icon.pk-icon { background: none; border: 0; }

/* Colour helpers (classes instead of inline styles: the CSP blocks style attributes) */
.bg-green { background: var(--free-green); }
.bg-orange { background: var(--free-orange); }
.bg-red { background: var(--free-red); }
.bg-nodata { background: var(--no-data); }
.bg-oos { background: var(--out-of-service); }
.bg-avg { background: #98A2B3; }
.bg-today { background: #3366cc; }
/* Today's line in the legend colours (chart of free shares) */
.bg-bands { background: linear-gradient(90deg, var(--free-red), var(--free-orange), var(--free-green)); }
.fg-green { color: var(--free-green); }
.fg-orange { color: var(--free-orange); }
.fg-red { color: var(--free-red); }
.fg-nodata { color: var(--no-data); }
.fg-oos { color: var(--out-of-service); }

/* ---------- Legend & status ---------- */
.legend {
  background: rgba(255, 255, 255, .95);
  padding: 8px 10px;
  border-radius: 8px;
  box-shadow: 0 1px 5px rgba(0, 0, 0, .3);
  font-size: 13px;
  line-height: 1.7;
}
.legend i {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 6px;
  border-radius: 50%;
  vertical-align: -1px;
}

.status {
  position: fixed;
  top: calc(var(--top) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  padding: 6px 12px;
  border-radius: 16px;
  background: rgba(29, 36, 51, .9);
  color: #fff;
  font-size: 13px;
  pointer-events: none;
}
.status:empty { display: none; }

/* Popups above all map controls (own pane, see app.js) */
.leaflet-popupTop-pane { z-index: 1100; }

/* Locate button: a map control (inside .leaflet-bottom, which ignores pointer events) at a fixed spot */
.locate {
  position: fixed;
  right: 12px;
  bottom: calc(110px + env(safe-area-inset-bottom));
  z-index: 1000;
  pointer-events: auto;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 5px rgba(0, 0, 0, .35);
  cursor: pointer;
  /* Centre the icon: mobile browsers add their own button padding and align SVGs to the text baseline */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  -webkit-appearance: none;
  appearance: none;
}
.locate svg { display: block; }

/* While locating: a spinning ring around the button, icon dimmed */
.locate.locating { cursor: progress; }
.locate.locating svg { opacity: .45; }
.locate.locating::after {
  content: "";
  position: absolute;
  inset: -3px;
  border: 3px solid transparent;
  border-top-color: #3366cc;
  border-right-color: #3366cc;
  border-radius: 50%;
  animation: locate-spin .8s linear infinite;
}
@keyframes locate-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .locate.locating::after { animation: locate-pulse 1.2s ease-in-out infinite; border-color: #3366cc; }
  @keyframes locate-pulse { 50% { opacity: .3; } }
}

/* ---------- Popup ---------- */
.leaflet-popup-content { margin: 12px 14px; width: min(300px, 78vw) !important; }
.pp h2 { margin: 0 0 2px; font-size: 16px; }
/* Name left, navigate button right; room on the right for Leaflet's close button */
.pp .head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; padding-right: 18px; }
.pp .nav {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex: none;
  height: 32px;
  margin-top: -3px;
  padding: 0 13px 0 10px;
  border-radius: 16px;
  background: #3366cc;
  box-shadow: 0 1px 3px rgba(29, 36, 51, .25);
  color: #fff !important;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.pp .nav svg { display: block; }
.pp .nav:hover { background: #2d5bb8; }
.pp .nav:active { background: #274f9e; }
.pp .sub { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.pp .now { display: flex; gap: 14px; margin-bottom: 10px; }
.pp .now b { display: block; font-size: 20px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.pp .now span { color: var(--muted); font-size: 12px; }
.pp h3 { margin: 10px 0 2px; font-size: 13px; }
.pp .chart { width: 100%; height: auto; display: block; }
.pp .key { font-size: 12px; color: var(--muted); }
.pp .key i { display: inline-block; width: 14px; height: 3px; margin: 0 4px 3px 0; vertical-align: middle; }
.pp .key i.bg-today, .pp .key i.bg-bands { margin-left: 8px; }
.pp .more { display: inline-block; margin-top: 8px; }
.pp .msg { color: var(--muted); font-size: 13px; }
/* Charging location details: label | value rows */
.pp .facts { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 0 0 6px; font-size: 12px; }
.pp .facts dt { color: var(--muted); }
.pp .facts dd { margin: 0; }
/* Charging points by kind: "2× CCS · 150 kW" left, availability right */
.pp .points { list-style: none; margin: 0 0 8px; padding: 0; font-size: 12px; }
.pp .points li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 10px; padding: 4px 0; border-top: 1px solid var(--line); }
.pp .points li:last-child { border-bottom: 1px solid var(--line); }
.pp .points .avail { font-weight: 600; text-align: right; }
.pp .points li.off { opacity: .45; }
/* Restricted access (charging locations) */
.pp .reliability { font-size: 13px; margin: 2px 0 4px; }
.pp .reliability span { color: var(--muted); font-size: 12px; }
.pp .warn { margin: 0 0 8px; padding: 5px 8px; border-radius: 6px; background: #fff4e5; color: #8a4b00; font-size: 12px; }
/* ‹ n / m › : step through nearby car parks; vertical scrolling stays with the browser */
.pp { touch-action: pan-y; }
.pp .pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); }
.pp .pager span { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.pp .pager button {
  width: 44px;
  height: 30px;
  border: 0;
  border-radius: 15px;
  background: #eef1f6;
  color: var(--ink);
  font: inherit;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 0 0 2px;
  -webkit-appearance: none;
  appearance: none;
}
.pp .pager button:active { background: #dde2ea; }
.pp .pager button:disabled { opacity: .35; cursor: default; }

/* ---------- Bubbles: several car parks; colour = combined share of free spaces ---------- */
.bubble {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px solid rgba(255, 255, 255, .9);
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 1px 5px rgba(0, 0, 0, .35);
  transform: translate(-50%, -50%);
  cursor: pointer;
}
.bubble.s { width: 36px; height: 36px; font-size: 13px; }
.bubble.m { width: 46px; height: 46px; font-size: 15px; }
.bubble.l { min-width: 56px; height: 56px; padding: 0 8px; border-radius: 28px; font-size: 16px; }
.bubble.green { background: var(--free-green); }
.bubble.orange { background: var(--free-orange); }
.bubble.red { background: var(--free-red); }
.bubble.nodata { background: var(--no-data); }
.legend .legend-note { margin-top: 2px; color: var(--muted); font-size: 12px; line-height: 1.3; max-width: 170px; }

/* Legend can be hidden (default): then only a "Legende" button; shown: × in the top right corner */
.legend { position: relative; padding-right: 30px; }
.legend-toggle {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.legend-toggle:hover { color: var(--ink); background: #eef1f6; }
.legend.collapsed { padding: 0; }
.legend.collapsed .legend-toggle {
  position: static;
  width: auto;
  height: auto;
  padding: 6px 12px;
  border-radius: 8px;
  color: #3366cc;
  font-size: 13px;
}
.legend.collapsed .legend-body { display: none; }

/* ---------- Filter lists (charging networks, plugs, power; top right) ---------- */
.netfilter {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 5px rgba(0, 0, 0, .35);
  font-size: 13px;
}
.netfilter-toggle {
  display: block;
  width: 100%;
  min-height: 36px;
  padding: 6px 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.netfilter-panel { width: min(260px, 70vw); padding: 0 10px 8px; border-top: 1px solid var(--line); }
.netfilter-panel[hidden] { display: none; }
.netfilter-actions { display: flex; gap: 6px; padding: 8px 0 6px; }
.netfilter-actions button {
  padding: 4px 10px;
  border: 0;
  border-radius: 12px;
  background: #eef1f6;
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.netfilter-list { max-height: 45vh; overflow-y: auto; overscroll-behavior: contain; }
.netfilter-list label { display: flex; align-items: center; gap: 6px; padding: 3px 0; cursor: pointer; }
.netfilter-list span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.netfilter-list small { color: var(--muted); font-variant-numeric: tabular-nums; }
.netfilter .msg { color: var(--muted); padding: 4px 0; }

/* ---------- Rest areas: badge colour by kind, capability overview in the popup ---------- */
:root { --k-service: #3366cc; --k-rest: #0f8b8d; --k-truck: #7b4fc9; --k-other: #5b6475; --k-coach: #c2410c; }
.pk.k-service_area, .bg-k-service_area { background: var(--k-service); }
.pk.k-rest_area, .bg-k-rest_area { background: var(--k-rest); }
.pk.k-truck_parking, .bg-k-truck_parking { background: var(--k-truck); }
.pk.k-other, .bg-k-other { background: var(--k-other); }
.pk.k-coach_parking, .bg-k-coach_parking { background: var(--k-coach); }
/* Bubbles of one kind each */
.bubble.k-service_area { background: var(--k-service); }
.bubble.k-rest_area { background: var(--k-rest); }
.bubble.k-truck_parking { background: var(--k-truck); }
.bubble.k-other { background: var(--k-other); }
.bubble.k-coach_parking { background: var(--k-coach); }
.pp .note { margin: 0 0 8px; color: var(--muted); font-size: 12px; }
.bubble.k-bubble { background: #44506a; }

.pp .caps { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; list-style: none; margin: 0 0 8px; padding: 0; }
.pp .caps li { display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 6px; font-size: 12px; line-height: 1.2; }
.pp .caps li.on { background: #eaf3ee; color: var(--ink); font-weight: 600; }
.pp .caps li.off { color: #98A2B3; }
.pp .caps li.off .ico { filter: grayscale(1); opacity: .45; }
.pp .caps .ico { flex: none; width: 18px; text-align: center; font-size: 15px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Info button (far right of the tab bar) and overlay ---------- */
.info-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  align-self: center;
  width: 34px;
  height: 34px;
  margin-left: 6px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: rgba(255, 255, 255, .8);
  cursor: pointer;
}
.info-btn:hover { color: #fff; background: rgba(255, 255, 255, .1); }
.info-btn svg { display: block; }

/* Over everything (tabs 1100, map popups 1100); the overlay itself scrolls */
.info-overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: rgba(29, 36, 51, .55);
}
.info-overlay[hidden] { display: none; }
.info-card {
  position: relative;
  max-width: 560px;
  margin: 24px auto;
  padding: 20px 22px 18px;
  border-radius: 12px;
  background: var(--bg);
  box-shadow: 0 8px 30px rgba(0, 0, 0, .3);
  font-size: 14px;
}
.info-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}
.info-close:hover { background: #eef1f6; color: var(--ink); }
.info-body h2 { margin: 0 36px 10px 0; font-size: 19px; }
.info-body h3 { margin: 18px 0 4px; font-size: 15px; }
.info-body p { margin: 0 0 8px; }
.info-body a { color: #3366cc; }
.info-body .speeds { list-style: none; margin: 4px 0 10px; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.info-body .speeds li { padding: 8px 10px; border-radius: 8px; background: #f3f5f9; font-size: 13px; }
.info-body .speeds b { display: block; font-size: 17px; }

/* ---------- Traffic reports: badge colour by kind, jam lines, Gotthard box ---------- */
:root { --t-queue: #D93025; --t-accident: #b54708; --t-closure: #1d2433; --t-roadworks: #c27c0e; --t-conditions: #3366cc; --t-other: #5b6475; }
.pk.t-queue, .bg-t-queue { background: var(--t-queue); }
.pk.t-accident, .bg-t-accident { background: var(--t-accident); }
.pk.t-closure, .bg-t-closure { background: var(--t-closure); }
.pk.t-roadworks, .bg-t-roadworks { background: var(--t-roadworks); }
.pk.t-conditions, .bg-t-conditions { background: var(--t-conditions); }
.pk.t-other, .bg-t-other { background: var(--t-other); }
/* Bubbles of one kind each */
.bubble.t-queue { background: var(--t-queue); }
.bubble.t-accident { background: var(--t-accident); }
.bubble.t-closure { background: var(--t-closure); }
.bubble.t-roadworks { background: var(--t-roadworks); }
.bubble.t-conditions { background: var(--t-conditions); }
.bubble.t-other { background: var(--t-other); }
.t-line-casing { stroke: #fff; stroke-width: 10; stroke-opacity: .9; stroke-linecap: round; stroke-linejoin: round; fill: none; }
.t-line { stroke: var(--t-queue); stroke-width: 6; stroke-linecap: round; stroke-linejoin: round; fill: none; }
/* Direction of travel along a jam: own pane between the lines (overlay pane, 400) and the markers (600) */
.leaflet-lineArrows-pane { z-index: 450; pointer-events: none; }
.leaflet-marker-icon.t-arrow { background: none; border: 0; }
.t-arrow svg { display: block; overflow: visible; }
.t-arrow path { fill: #fff; stroke: #7a1610; stroke-width: 1.2; stroke-linejoin: round; }
.pp .ttext { margin: 0 0 6px; font-size: 13px; line-height: 1.45; }

.gotthard {
  display: block;
  max-width: 60vw;
  padding: 6px 10px;
  border: 0;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 1px 5px rgba(0, 0, 0, .35);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.gotthard.jam { background: var(--t-queue); color: #fff; }

/* ---------- Driving mode: list of the nearest items instead of the map ---------- */
.drive-toggle {
  position: fixed;
  right: 12px;
  bottom: calc(56px + env(safe-area-inset-bottom));
  z-index: 1000;
  pointer-events: auto;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 5px rgba(0, 0, 0, .35);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  -webkit-appearance: none;
  appearance: none;
}
.drive-toggle svg { display: block; }
.drive-toggle .icon-map, .driving .drive-toggle .icon-list { display: none; }
.driving .drive-toggle .icon-map { display: block; }
.driving .drive-toggle { background: #3366cc; color: #fff; }

/* The list lies over the map (under its controls, 1000; over the map panes, up to 700) */
.drive-list {
  position: absolute;
  inset: 0;
  z-index: 900;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg);
  padding: 8px 12px calc(120px + env(safe-area-inset-bottom));
  cursor: auto;
}
.drive-list[hidden] { display: none; }
/* Map-only parts hidden; the filters (top right) in a row above the list */
.driving .leaflet-control-zoom, .driving .leaflet-bottom.leaflet-left, .driving .gotthard,
.driving .leaflet-control-attribution { display: none; }
.driving .leaflet-top.leaflet-right { left: 0; display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: flex-start; }
.driving .leaflet-top.leaflet-right .leaflet-control { float: none; clear: none; margin: 8px 8px 0 0; }

.drive-head { margin: 4px 4px 6px; color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.drive-msg { margin: 24px 8px; color: var(--muted); font-size: 15px; }
.drive-items { list-style: none; margin: 0; padding: 0; }
.drive-items li { border-bottom: 1px solid var(--line); }
.di {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 10px 4px;
  color: var(--ink) !important;
  text-decoration: none;
  cursor: pointer;
}
.di:active { background: #f3f5f9; }
.di-main { flex: 1; min-width: 0; }
.di-main b { display: block; font-size: 17px; line-height: 1.25; }
.di-meta, .di-line { display: block; margin-top: 2px; color: var(--muted); font-size: 13px; }
.di-icons { font-size: 15px; letter-spacing: 2px; }
.di .warn { margin: 6px 0 0; padding: 4px 8px; border-radius: 6px; background: #fff4e5; color: #8a4b00; font-size: 12px; }
.di-big { flex: none; min-width: 64px; text-align: right; font-size: 24px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.di-big small { display: block; color: var(--muted); font-size: 11px; font-weight: 600; }
