:root {
  /* Palette — a Budapest transit-signage identity, not a map default.
     Green = mechanical/available, Volt amber = electric, Ink on Paper chrome. */
  --ink: #16241c;
  --ink-soft: #47564d;
  --paper: #f7f8f3;
  --paper-edge: #e7eae0;
  --green: #1f9d57;
  --green-deep: #157a43;
  --volt: #f2a51c;
  --volt-deep: #d98a00;
  --empty: #9aa7a0;
  --user: #2b6fe0;
  --brand-lime: #afcc4e; /* from the MOL Bubi / OpenBubi mark */

  --shadow: 0 6px 24px rgba(12, 26, 18, 0.18);
  --shadow-sm: 0 2px 8px rgba(12, 26, 18, 0.14);
  --radius: 16px;

  --sheet-collapsed: 118px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: "Barlow", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

#map {
  position: fixed;
  inset: 0;
  height: 100dvh;
  width: 100vw;
  background: #dfe4da;
  z-index: 0;
}

/* ---- Loading veil --------------------------------------------------------- */
.veil {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: center;
  background: var(--paper);
  transition: opacity 0.4s ease;
}
.veil.hidden { opacity: 0; pointer-events: none; }
.veil-mark {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: "Barlow Semi Condensed", sans-serif;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink-soft);
}
.veil-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(31, 157, 87, 0.5);
  animation: pulse 1.3s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(31, 157, 87, 0.5); }
  70% { box-shadow: 0 0 0 14px rgba(31, 157, 87, 0); }
  100% { box-shadow: 0 0 0 0 rgba(31, 157, 87, 0); }
}

/* ---- Find-me button ------------------------------------------------------- */
.locate {
  position: fixed;
  right: 14px;
  bottom: calc(var(--sheet-collapsed) + var(--safe-b) + 16px);
  z-index: 900;
  width: 52px; height: 52px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1), background 0.2s, color 0.2s;
}
.locate:active { transform: scale(0.92); }
.locate svg { width: 26px; height: 26px; fill: currentColor; }
.locate.locating { color: var(--user); }
.locate.locating svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Bottom sheet --------------------------------------------------------- */
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 1000;
  background: var(--paper);
  border-top-left-radius: 22px;
  border-top-right-radius: 22px;
  box-shadow: var(--shadow);
  padding-bottom: var(--safe-b);
  transform: translateY(0);
  transition: transform 0.42s cubic-bezier(0.16, 1, 0.3, 1);
  max-width: 560px;
  margin: 0 auto;
}
.sheet.collapsed { transform: translateY(calc(100% - var(--sheet-collapsed) - var(--safe-b))); }

.handle {
  width: 100%;
  padding: 10px 0 4px;
  background: none;
  border: none;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.grip {
  width: 42px; height: 5px;
  border-radius: 999px;
  background: var(--paper-edge);
  display: block;
}

.sheet-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 20px 12px;
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand-chip {
  width: 20px; height: 20px;
  border-radius: 6px;
  background:
    radial-gradient(circle at 50% 42%, #e4002b 0 32%, transparent 33%),
    var(--brand-lime);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.06);
}
.brand-name {
  font-family: "Barlow Semi Condensed", sans-serif;
  font-weight: 700;
  font-size: 1.28rem;
  letter-spacing: 0.01em;
}
.tally {
  font-family: "Barlow Semi Condensed", sans-serif;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--ink-soft);
  white-space: nowrap;
}
.tally span { color: var(--ink); }

.sheet-body { padding: 0 20px 20px; }

.field { margin-bottom: 16px; }
.field-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 8px;
}

/* Segmented control */
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: #eceee6;
  border-radius: 13px;
}
.seg {
  appearance: none;
  border: none;
  border-radius: 10px;
  background: transparent;
  padding: 11px 6px;
  min-height: 44px;
  font-family: "Barlow Semi Condensed", sans-serif;
  font-weight: 600;
  font-size: 0.98rem;
  color: var(--ink-soft);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: background 0.18s, color 0.18s, box-shadow 0.18s;
}
.seg .bolt { width: 15px; height: 15px; fill: currentColor; }
.seg.is-active {
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}
.seg[data-type="electric"].is-active { color: var(--volt-deep); }

/* Toggle */
.toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  cursor: pointer;
  user-select: none;
}
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.track {
  flex: 0 0 auto;
  width: 46px; height: 28px;
  border-radius: 999px;
  background: #d4d8cd;
  position: relative;
  transition: background 0.2s;
}
.thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}
.toggle input:checked + .track { background: var(--green); }
.toggle input:checked + .track .thumb { transform: translateX(18px); }
.toggle input:focus-visible + .track { outline: 2px solid var(--user); outline-offset: 2px; }
.toggle-text { font-size: 0.98rem; }

/* Legend */
.legend {
  display: flex;
  gap: 16px;
  margin: 16px 0 12px;
  font-size: 0.82rem;
  color: var(--ink-soft);
}
.key { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 12px; border-radius: 4px; display: inline-block; }
.sw-mech { background: var(--green); }
.sw-elec { background: var(--volt); }
.sw-empty { background: var(--empty); }

.attribution {
  margin: 4px 0 0;
  font-size: 0.72rem;
  line-height: 1.4;
  color: var(--ink-soft);
}

/* ---- Custom markers ------------------------------------------------------- */
.pin {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 11px 11px 11px 3px;
  transform: rotate(-45deg);
  color: #fff;
  box-shadow: var(--shadow-sm);
  border: 2px solid #fff;
}
.pin span {
  transform: rotate(45deg);
  font-family: "Barlow Semi Condensed", sans-serif;
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1;
}
.pin-mech { background: var(--green); }
.pin-elec { background: var(--volt); }
.pin-empty {
  background: #eef0ea;
  color: var(--empty);
  border-color: #fff;
  width: 26px; height: 26px;
  border-radius: 9px 9px 9px 3px;
}
.pin-empty span { font-size: 0.8rem; }
/* small volt badge for stations that also have e-bikes (in 'both' view) */
.pin-badge { position: relative; }
.pin-badge::after {
  content: "";
  position: absolute;
  top: -4px; right: -4px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--volt);
  border: 2px solid #fff;
  transform: rotate(45deg);
}

/* Cluster bubbles */
.cluster {
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(31, 157, 87, 0.92);
  color: #fff;
  border: 3px solid #fff;
  box-shadow: var(--shadow-sm);
  font-family: "Barlow Semi Condensed", sans-serif;
  font-weight: 700;
}

/* User location */
.user-dot {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--user);
  border: 3px solid #fff;
  box-shadow: 0 0 0 4px rgba(43, 111, 224, 0.25);
}

/* ---- Popups --------------------------------------------------------------- */
.leaflet-popup-content-wrapper {
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.leaflet-popup-content { margin: 14px 16px; }
.pop-name {
  font-family: "Barlow Semi Condensed", sans-serif;
  font-weight: 700;
  font-size: 1.06rem;
  margin: 0 0 8px;
  line-height: 1.15;
}
.pop-counts { display: flex; gap: 18px; margin-bottom: 10px; }
.pop-count { display: flex; flex-direction: column; gap: 1px; }
.pop-count b {
  font-family: "Barlow Semi Condensed", sans-serif;
  font-size: 1.5rem;
  line-height: 1;
}
.pop-count.elec b { color: var(--volt-deep); }
.pop-count.mech b { color: var(--green-deep); }
.pop-count small { font-size: 0.72rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.06em; }
.pop-meta { font-size: 0.8rem; color: var(--ink-soft); margin-bottom: 10px; }
.pop-dir {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 9px;
  background: var(--ink);
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.88rem;
}
.pop-closed { color: #b23b3b; font-weight: 600; }

/* ---- iOS hint ------------------------------------------------------------- */
.ios-hint {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(var(--sheet-collapsed) + var(--safe-b) + 16px);
  z-index: 1100;
  background: var(--ink);
  color: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.86rem;
  box-shadow: var(--shadow);
  max-width: 520px;
  margin: 0 auto;
}
.ios-hint .share { width: 16px; height: 16px; fill: #fff; vertical-align: -3px; }
.ios-hint button {
  margin-left: auto;
  background: none; border: none; color: #fff;
  font-size: 1.4rem; line-height: 1;
  cursor: pointer; padding: 0 4px;
}

/* Keep Leaflet's own controls clear of the sheet + safe areas */
.leaflet-bottom { margin-bottom: calc(var(--sheet-collapsed) + var(--safe-b)); }
.leaflet-control-attribution { font-size: 10px; }

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

@media (min-width: 640px) {
  :root { --sheet-collapsed: 130px; }
  .sheet { bottom: 16px; right: 16px; left: auto; margin: 0; width: 380px; border-radius: 20px; }
  .sheet.collapsed { transform: translateY(calc(100% - var(--sheet-collapsed) + 16px)); }
  .locate { right: calc(380px + 32px); }
}

/* ==== Additions: contrast fix, language switcher, e-bike battery list ==== */

/* Ensure the iOS hint's `hidden` attribute wins over display:flex. */
.ios-hint[hidden] { display: none; }

/* Directions button: override Leaflet's default link color (#0078A8),
   which otherwise wins on specificity and kills contrast on the dark button. */
.leaflet-container a.pop-dir,
.leaflet-container a.pop-dir:hover { color: #fff; }

/* Language switcher */
.lang { position: relative; margin-left: 8px; }
.lang-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 5px;
  border: 1px solid var(--paper-edge);
  border-radius: 8px;
  background: var(--paper);
  cursor: pointer;
  line-height: 0;
}
.lang-flag {
  width: 22px; height: 15px;
  border-radius: 3px;
  overflow: hidden;
  display: inline-block;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}
.lang-flag svg { display: block; width: 100%; height: 100%; }
.lang-btn .caret { width: 11px; height: 11px; fill: var(--ink-soft); }

.lang-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--paper);
  border-radius: 12px;
  box-shadow: var(--shadow);
  min-width: 168px;
  z-index: 1200;
}
.lang-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: none;
  border-radius: 8px;
  background: none;
  cursor: pointer;
  font: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  text-align: left;
}
.lang-item:hover { background: #eef0ea; }
.lang-item.is-active { background: #e7efe6; font-weight: 600; }

/* E-bike battery list inside a station popup */
.pop-detail {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 10px;
  max-height: 132px;
  overflow-y: auto;
}
.pop-detail-empty {
  display: block;
  font-size: 0.84rem;
  color: var(--ink-soft);
  background: #f1f3ec;
  border-radius: 8px;
  padding: 8px 10px;
}
.ebike {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: #f1f3ec;
  border-radius: 8px;
  padding: 4px 9px;
  font-size: 0.82rem;
}
.batt {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.batt-ico { width: 24px; height: 12px; }
.ebike-km { color: var(--ink-soft); }

/* ==== E-bike pins (flex-parked individual e-bikes) ==== */
.ebike-pin {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 24px;
  padding: 0 8px 0 5px;
  border-radius: 12px;
  color: #fff;
  font-family: "Barlow Semi Condensed", sans-serif;
  font-weight: 700;
  font-size: 0.82rem;
  line-height: 1;
  border: 2px solid #fff;
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
}
.ebike-pin svg { width: 13px; height: 13px; fill: #fff; }

.cluster-ebike { background: rgba(242, 165, 28, 0.94); }

.sw-ebike { background: var(--volt); border-radius: 999px; }

.pop-ebike-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.pop-ebike-row .batt { font-size: 1.05rem; }
.pop-ebike-row .batt-ico { width: 30px; height: 15px; }
