* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-panel: rgba(10, 10, 30, 0.88);
  --bg-panel-header: rgba(15, 15, 40, 0.97);
  --border: rgba(255, 255, 255, 0.08);
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-label: #58a6ff;
  --accent: #00d4ff;
  --accent-dim: rgba(0, 212, 255, 0.15);
  --jet-blue: #3399ff;
  --jet-monitor: #4c47e6;
  --radius: 12px;
  --panel-width: 248px;
}

html, body {
  width: 100%;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #0a0a1a;
  color: var(--text-primary);
  overflow: hidden;
}

#map {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* ── Panels ── */
.panel {
  position: fixed;
  top: 16px;
  z-index: 10;
  width: var(--panel-width);
  background: var(--bg-panel);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  /* Prevent text selection while dragging */
  user-select: none;
}

.panel > #lang-switcher,
.panel > #panel-city-body,
.panel > #panel-menu-body {
  border-radius: inherit;
}

.panel-left  { left: 16px; }
.panel-right { right: 16px; }

/* ── Collapsed state ── */
.panel.collapsed {
  width: 44px !important;
  min-height: 44px;
}

.panel.collapsed .panel-title,
.panel.collapsed .panel-logo,
.panel.collapsed #lang-switcher,
.panel.collapsed #panel-city-body,
.panel.collapsed #panel-menu-body,
.panel.collapsed .resize-handle {
  display: none;
}

/* ── Floating collapse button ── */
.btn-collapse {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--text-secondary);
  background: rgba(20, 20, 40, 0.92);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  z-index: 11;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: all 0.15s ease;
  line-height: 1;
  padding: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.35);
}

.btn-collapse:hover {
  color: var(--text-primary);
  background: rgba(40, 40, 70, 0.98);
  border-color: rgba(255,255,255,0.3);
}

.btn-collapse-left  { right: -11px; }
.btn-collapse-right { left:  -11px; }

.panel.collapsed .btn-collapse {
  top: 50%;
  left: 50%;
  right: auto;
  transform: translate(-50%, -50%);
  width: 26px;
  height: 26px;
  font-size: 11px;
}

.panel.collapsed .panel-header {
  padding: 10px;
  justify-content: center;
  border-bottom: none;
}

/* ── Panel header — grab cursor for drag ── */
.panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  background: var(--bg-panel-header);
  border-bottom: 1px solid var(--border);
  cursor: grab;
}

.panel-header:active {
  cursor: grabbing;
}

.panel-logo {
  font-size: 13px;
  font-weight: 900;
  color: var(--accent);
  letter-spacing: 1px;
  flex-shrink: 0;
}

.panel-title {
  flex: 1;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.menu-title {
  font-size: 14px;
  font-weight: 900;
  color: var(--accent);
  letter-spacing: 1px;
}

/* ── City panel body ── */
#panel-city-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field-label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-label);
  margin-bottom: 6px;
}

.select {
  width: 100%;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s;
}

.select:hover,
.select:focus {
  border-color: var(--accent);
}

.select option {
  background: #0f0f2a;
  color: var(--text-primary);
}

/* ── Stats grid ── */
#city-stats {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stats-section {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.stats-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent);
  padding-left: 2px;
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
}

.live-schedule-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 9px;
  color: var(--text-secondary);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: live-pulse 1.8s infinite;
}

@keyframes live-pulse {
  0%   { box-shadow: 0 0 0 0   rgba(16, 185, 129, 0.65); }
  70%  { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0);    }
  100% { box-shadow: 0 0 0 0   rgba(16, 185, 129, 0);    }
}

.mode-btn.is-live {
  position: relative;
  box-shadow: inset 0 0 0 1px rgba(16, 185, 129, 0.55);
}

.mode-btn.is-live::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.9);
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}

.stat-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 6px;
  text-align: center;
}

.stat-value {
  font-size: 15px;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}

.stat-card-full {
  grid-column: 1 / -1;
}

.stat-label {
  font-size: 10px;
  color: var(--text-secondary);
  margin-top: 3px;
}

.stat-pct {
  opacity: 0.7;
  margin-left: 2px;
}

/* ── Collapsible status card (negative) ── */
.stat-card-details {
  padding: 0;
  overflow: hidden;
}

.stat-card-details > summary {
  list-style: none;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  align-items: center;
  padding: 6px 10px 6px 6px;
  cursor: pointer;
  text-align: center;
  position: relative;
}

.stat-card-details > summary::-webkit-details-marker { display: none; }

.stat-card-details > summary .stat-value {
  grid-column: 1 / 3;
  grid-row: 1;
}

.stat-card-details > summary .stat-label {
  grid-column: 1 / 3;
  grid-row: 2;
}

.stat-chevron {
  position: absolute;
  top: 50%;
  right: 8px;
  width: 10px;
  height: 6px;
  transform: translateY(-50%);
  color: var(--text-secondary);
  transition: transform 0.15s ease;
}

.stat-card-details[open] .stat-chevron {
  transform: translateY(-50%) rotate(180deg);
}

.stat-card-negative .stat-value {
  color: #f87171;
}

.stat-card-idle-24 .stat-value { color: #f97316; }
.stat-card-idle-48 .stat-value { color: #ef4444; }
.stat-card-off-parking .stat-value { color: #a78bfa; }

.stat-breakdown {
  border-top: 1px solid var(--border);
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: rgba(248, 113, 113, 0.04);
}

.stat-sub-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  font-size: 11px;
}

.stat-sub-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #f87171;
  opacity: 0.7;
}

.stat-sub-dot-accent {
  background: var(--accent);
}

.stat-sub-dot-info {
  background: var(--text-secondary);
  opacity: 0.5;
}

.stat-sub-row-info {
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px dashed rgba(255,255,255,0.08);
  opacity: 0.75;
}

.stat-sub-row-pending {
  margin-bottom: 4px;
  padding-bottom: 6px;
  border-bottom: 1px dashed rgba(255,255,255,0.08);
  opacity: 0.55;
}

.stat-sub-dot-pending {
  background: #facc15;
  opacity: 0.6;
}

.stat-sub-pending-note {
  font-style: italic;
  color: var(--text-secondary);
  font-size: 10px;
}

.stat-breakdown-neutral {
  background: rgba(255, 255, 255, 0.03);
}

.stat-sub-label {
  color: var(--text-secondary);
  text-align: left;
}

.stat-sub-count {
  color: var(--text-primary);
  font-weight: 600;
}

.stat-sub-pct {
  color: var(--text-secondary);
  font-weight: 400;
  margin-left: 2px;
  opacity: 0.75;
}

.stat-sub-empty {
  color: var(--text-secondary);
  font-size: 11px;
  text-align: center;
}

/* ── Loading bar ── */
.loading-bar {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.loading-bar-inner {
  height: 3px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
}

.loading-bar-inner::after {
  content: '';
  position: absolute;
  left: -40%;
  top: 0;
  width: 40%;
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  animation: loading-slide 1.2s ease-in-out infinite;
}

@keyframes loading-slide {
  0%   { left: -40%; }
  100% { left: 100%; }
}

.loading-text {
  font-size: 11px;
  color: var(--text-secondary);
  text-align: center;
}

/* ── Menu panel body ── */
#panel-menu-body {
  padding: 10px 0;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}

#panel-menu-body::-webkit-scrollbar {
  width: 4px;
}
#panel-menu-body::-webkit-scrollbar-track { background: transparent; }
#panel-menu-body::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
}

.menu-section-label {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
  padding: 8px 14px 4px;
}

/* ── Layer items ── */
.layer-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.15s;
  user-select: none;
}

.layer-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.layer-item.hidden {
  opacity: 0.38;
}

.layer-item.hidden .layer-name {
  text-decoration: line-through;
}

.layer-name {
  font-size: 12px;
  color: var(--text-primary);
  white-space: nowrap;
}

/* ── Bike status filter ── */
.bsf-toggle-all {
  margin-left: auto;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.05);
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  line-height: 1;
}

.bsf-toggle-all:hover {
  background: rgba(255,255,255,0.1);
  color: var(--text-primary);
}

.bsf-toggle-all[data-state="off"] {
  border-color: rgba(16,185,129,0.4);
  color: #10b981;
}

.bsf-toggle-all[data-state="on"] {
  border-color: rgba(239,68,68,0.35);
  color: #f87171;
}

#bike-status-filter,
#ebike-status-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 4px 14px 8px 42px;
}

.bike-status-btn,
.ebike-status-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px 3px 5px;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04);
  cursor: pointer;
  transition: all 0.15s;
  opacity: 0.4;
}

.bike-status-btn.active,
.ebike-status-btn.active {
  opacity: 1;
  border-color: var(--dot-color);
  background: rgba(255,255,255,0.06);
}

.bsf-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dot-color);
  flex-shrink: 0;
}

.bsf-label {
  font-size: 10px;
  color: var(--text-primary);
  white-space: nowrap;
}

/* ── Layer icons ── */
.layer-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-badge {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 900;
  border: 1px solid transparent;
}

.icon-circle {
  border-radius: 50% !important;
}

.icon-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  margin: 0 7px;
}

.icon-line {
  width: 28px;
  height: 4px;
  border-radius: 2px;
  margin: 0 0;
}


/* ── Panel toggle button ── */
.btn-icon {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.07);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 10px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-icon:hover {
  background: var(--accent-dim);
  color: var(--accent);
}

/* ── Resize handle ── */
.resize-handle {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 22px;
  height: 22px;
  cursor: se-resize;
  z-index: 20;
  background: linear-gradient(
    135deg,
    transparent 40%,
    rgba(255,255,255,0.06) 40%,
    rgba(255,255,255,0.10) 60%,
    transparent 60%,
    transparent 70%,
    rgba(255,255,255,0.06) 70%,
    rgba(255,255,255,0.10) 85%,
    transparent 85%
  );
  border-radius: 0 0 var(--radius) 0;
}

/* ── Mapbox overrides ── */
.maplibregl-ctrl-attrib {
  background: rgba(10,10,30,0.7) !important;
  color: var(--text-secondary) !important;
}

.maplibregl-ctrl-attrib a {
  color: var(--text-label) !important;
}

.maplibregl-popup-content {
  background: rgba(10, 10, 30, 0.95) !important;
  backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: 10px !important;
  color: var(--text-primary) !important;
  padding: 14px 16px !important;
  font-family: inherit;
  min-width: 200px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5) !important;
}

.maplibregl-popup-tip {
  display: none !important;
}

.maplibregl-popup-close-button {
  color: var(--text-secondary) !important;
  font-size: 18px !important;
  right: 8px !important;
  top: 6px !important;
}

/* ── Popups ── */
.popup-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
  padding-right: 16px;
}

.popup-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  margin-bottom: 8px;
}

.popup-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-secondary);
  padding: 3px 0;
  border-bottom: 1px solid var(--border);
}

.popup-row:last-child { border-bottom: none; }

.popup-row span:last-child {
  color: var(--text-primary);
  font-weight: 600;
}

.popup-nav-buttons {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

.popup-btn {
  flex: 1;
  padding: 6px 4px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.06);
  color: var(--text-primary);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  transition: background 0.15s;
}

.popup-btn:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Bike status dot ── */
.bike-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
  vertical-align: middle;
}

/* ── Legend ── */
.map-legend {
  position: fixed;
  bottom: 56px;
  left: 16px;
  z-index: 10;
  width: 220px;
  background: var(--bg-panel);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  user-select: none;
}

.legend-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-panel-header);
  border-bottom: 1px solid var(--border);
  cursor: grab;
}

.legend-header:active {
  cursor: grabbing;
}

.legend-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-label);
}

#legend-body {
  padding: 10px 14px 12px;
  max-height: 360px;
  overflow-y: auto;
}

#legend-body::-webkit-scrollbar { width: 4px; }
#legend-body::-webkit-scrollbar-track { background: transparent; }
#legend-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }

#legend-body.collapsed { display: none; }

/* When legend is collapsed, remove bottom border from header */
.map-legend:has(#legend-body.collapsed) .legend-header {
  border-bottom: none;
  border-radius: var(--radius);
}

.legend-section {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
  padding: 8px 0 4px;
}

.legend-section:first-child { padding-top: 2px; }

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0;
}

.legend-label {
  font-size: 11px;
  color: var(--text-primary);
  line-height: 1.3;
}

.legend-hint {
  font-size: 10px;
  color: var(--text-secondary);
  padding: 2px 0 4px;
  font-style: italic;
}

.legend-circle {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  color: white;
}

.legend-badge {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 900;
  color: white;
}

.legend-dot-sm {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.5);
  margin: 0 5px;
}

.legend-line {
  flex-shrink: 0;
  width: 22px;
  height: 3px;
  border-radius: 2px;
  margin: 0 0;
}

/* ── Language switcher ── */
#lang-switcher {
  display: flex;
  gap: 4px;
  padding: 6px 14px;
  background: rgba(255,255,255,0.03);
  border-bottom: 1px solid var(--border);
}

.lang-btn {
  flex: 1;
  padding: 3px 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: rgba(255,255,255,0.35);
  cursor: pointer;
  transition: all 0.15s;
}

.lang-btn:hover {
  color: rgba(255,255,255,0.7);
  background: rgba(255,255,255,0.06);
}

.lang-btn.active {
  background: var(--accent);
  color: #000e1a;
  border-color: transparent;
}

/* ── 2D / 3D toggle ── */
.mode-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.mode-toggle {
  display: flex;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}

.mode-btn {
  padding: 5px 10px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
  white-space: nowrap;
}

.mode-btn.active {
  background: var(--accent);
  color: #000e1a;
  box-shadow: 0 0 10px rgba(0, 212, 255, 0.4);
}

.mode-btn:not(.active):hover {
  color: var(--text-primary);
  background: rgba(255,255,255,0.06);
}

/* ── Full-width toggle (day filter) ── */
.mode-toggle-full {
  width: 100%;
}

.mode-toggle-full .mode-btn {
  flex: 1;
  text-align: center;
  padding: 5px 4px;
}

.mode-btn-stacked {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
  gap: 2px;
  padding: 4px 2px 3px;
}

.mode-btn-stacked .mbtn-emoji {
  font-size: 14px;
}

.mode-btn-stacked .mbtn-caption {
  font-size: 9px;
  font-weight: 600;
  opacity: 0.75;
  letter-spacing: 0.3px;
  min-height: 10px;
}

.mode-btn-stacked.active .mbtn-caption {
  opacity: 1;
}

/* ── Responsive ── */
@media (max-width: 600px) {
  :root { --panel-width: calc(100vw - 32px); }
  .panel-right { display: none; }
  .map-legend  { display: none; }
}
