@import url('https://fonts.googleapis.com/css2?family=Space+Mono:ital,wght@0,400;0,700;1,400&family=Syne:wght@400;600;700;800&display=swap');

:root {
  --bg: #0e0f13;
  --panel: #16181f;
  --panel2: #1e2029;
  --border: #2a2d3a;
  --accent: #d4940f;
  --accent2: #4f9cf9;
  --night: #8b5cf6;
  --special: #34d399;
  --text: #e8eaf0;
  --muted: #6b7280;
  --red: #f87171;
  --map-tile-filter: brightness(0.7) saturate(0.5);
  --stop-fill: #0e0f13;
}

:root.light {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel2: #eef0f4;
  --border: #d1d5db;
  --accent: #c47f00;
  --accent2: #2563eb;
  --night: #7c3aed;
  --special: #059669;
  --text: #111827;
  --muted: #6b7280;
  --red: #dc2626;
  --map-tile-filter: brightness(1) saturate(1);
  --stop-fill: #ffffff;
}

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

body {
  font-family: 'Syne', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* HEADER */
header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  height: 52px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 1000;
}

.logo {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--accent);
}
.logo span { color: var(--text); font-weight: 400; }

.tabs {
  display: flex;
  gap: 2px;
  margin-left: auto;
  background: var(--bg);
  border-radius: 8px;
  padding: 3px;
}
.tab {
  padding: 5px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--muted);
  transition: all .15s;
  font-family: 'Syne', sans-serif;
}
.tab.active { background: var(--panel2); color: var(--text); }
.tab:hover:not(.active) { color: var(--text); }

/* MAIN LAYOUT */
.main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* SIDEBAR */
.sidebar {
  width: 300px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.search-box {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
.search-box input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text);
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  outline: none;
}
.search-box input:focus { border-color: var(--accent); }
.search-box input::placeholder { color: var(--muted); }

.route-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.route-list::-webkit-scrollbar { width: 4px; }
.route-list::-webkit-scrollbar-track { background: transparent; }
.route-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.route-group-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--muted);
  padding: 8px 6px 4px;
  text-transform: uppercase;
}

.route-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .1s;
  border: 1px solid transparent;
}
.route-item:hover { background: var(--panel2); }
.route-item.active {
  background: var(--panel2);
  border-color: var(--border);
}

.route-badge {
  min-width: 40px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
.badge-normal { background: var(--accent); color: #000; }
.badge-night { background: var(--night); color: #fff; }
.badge-special { background: var(--special); color: #000; }

.route-meta { flex: 1; min-width: 0; }
.route-name { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.route-freq-bar {
  display: flex;
  gap: 3px;
  margin-top: 3px;
}
.freq-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--border);
}
.freq-dot.active { background: var(--accent); }

/* MAP */
#map-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#map {
  flex: 1;
  min-height: 80px;
}

/* Resizer */
.map-resizer {
  height: 6px;
  background: var(--border);
  cursor: ns-resize;
  flex-shrink: 0;
  display: none;
  position: relative;
  transition: background .15s;
}
.map-resizer::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 32px;
  height: 2px;
  border-radius: 2px;
  background: var(--muted);
  transition: background .15s;
}
.map-resizer.visible { display: block; }
.map-resizer:hover, .map-resizer.dragging { background: var(--accent); }
.map-resizer:hover::after, .map-resizer.dragging::after { background: #000; }

/* DETAIL PANEL */
.detail-panel {
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 0;
  display: none;
  flex-direction: column;
  height: 220px;
  min-height: 80px;
  max-height: 70vh;
  flex-shrink: 0;
}
.detail-panel.open { display: flex; }

.detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.detail-title { font-size: 16px; font-weight: 800; }
.detail-headsign { font-size: 13px; color: var(--muted); }

.dir-tabs {
  display: flex;
  gap: 6px;
  margin-left: auto;
}
.dir-tab {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-family: 'Syne', sans-serif;
  transition: all .15s;
}
.dir-tab.active { background: var(--accent); color: #000; border-color: var(--accent); }
.dir-tab:hover:not(.active) { border-color: var(--accent); color: var(--accent); }

.close-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
  line-height: 1;
}
.close-btn:hover { color: var(--text); }

.detail-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.stops-panel {
  width: 220px;
  padding: 10px;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}
.stops-panel::-webkit-scrollbar { width: 3px; }
.stops-panel::-webkit-scrollbar-thumb { background: var(--border); }

.stop-line-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 6px;
  cursor: pointer;
  transition: background .1s;
  border: 1px solid transparent;
}
.stop-line-item:hover { background: var(--panel2); }
.stop-line-item.active-stop {
  background: var(--panel2);
  border-color: var(--accent);
}
.stop-line-item.stop-end .stop-line-name { font-weight: 700; }

.stop-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: var(--bg);
  flex-shrink: 0;
}
.stop-dot.first { background: var(--accent); }
.stop-line-name { font-size: 11px; color: var(--text); }

.depart-subtitle {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.depart-subtitle.stop-selected { color: var(--accent); }

.no-data { color: var(--muted); font-size: 12px; padding-top: 4px; }

.depart-panel {
  flex: 1;
  padding: 10px 14px;
  overflow-y: auto;
}
.depart-panel::-webkit-scrollbar { width: 3px; }
.depart-panel::-webkit-scrollbar-thumb { background: var(--border); }

.day-type-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 6px;
}

.depart-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 14px;
}
.dep-chip {
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 5px;
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);
}
.dep-chip.past { color: var(--muted); }
.dep-chip.next { background: var(--accent); color: #000; border-color: var(--accent); font-weight: 700; }

/* STATS VIEW */
#stats-view {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: none;
}
#stats-view.visible { display: block; }

.stats-title {
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 4px;
}
.stats-sub { color: var(--muted); font-size: 13px; margin-bottom: 24px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}
.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}
.stat-card-label { font-size: 11px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.stat-card-value { font-size: 36px; font-weight: 800; color: var(--accent); font-family: 'Space Mono', monospace; }
.stat-card-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

.freq-chart-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 16px;
}
.freq-chart {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.freq-row {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.freq-row:hover .freq-bar { opacity: 0.8; }
.freq-label {
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  width: 42px;
  flex-shrink: 0;
  text-align: right;
}
.freq-bars {
  display: flex;
  gap: 2px;
  flex: 1;
  height: 20px;
  align-items: stretch;
}
.freq-bar {
  border-radius: 3px;
  transition: width .4s ease;
  min-width: 2px;
}
.freq-bar.P { background: var(--accent); }
.freq-bar.R { background: var(--accent2); }
.freq-bar.S { background: var(--muted); }
.freq-count {
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  color: var(--muted);
  width: 60px;
}

.legend-freq {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

/* STOP SEARCH */
#stop-view {
  flex: 1;
  display: none;
  flex-direction: column;
}
#stop-view.visible { display: flex; }
.stop-search-bar {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-shrink: 0;
}
.stop-search-bar input {
  width: 100%;
  max-width: 500px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  color: var(--text);
  font-size: 14px;
  font-family: 'Space Mono', monospace;
  outline: none;
}
.stop-search-bar input:focus { border-color: var(--accent); }
.stop-search-bar input::placeholder { color: var(--muted); }

.stop-results {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
}
.stop-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .1s;
}
.stop-result-item:hover { background: var(--panel); border-color: var(--border); }
.stop-result-item.active { background: var(--panel); border-color: var(--accent); }
.stop-code-badge {
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  background: var(--panel2);
  padding: 3px 8px;
  border-radius: 4px;
  color: var(--muted);
  flex-shrink: 0;
}
.stop-result-name { font-size: 13px; font-weight: 600; }
.stop-result-routes { font-size: 11px; color: var(--muted); margin-top: 2px; }
.stop-zone { font-size: 10px; color: var(--muted); margin-left: auto; }

/* Leaflet overrides */
.leaflet-container { background: var(--bg); }
.leaflet-tile { filter: var(--map-tile-filter); transition: filter 0.3s; }

/* Kontrolka warstw */
.leaflet-control-layers {
  background: var(--panel) !important;
  border: 1px solid var(--border) !important;
  border-radius: 8px !important;
  box-shadow: 0 4px 12px rgba(0,0,0,.4) !important;
  color: var(--text) !important;
}
.leaflet-control-layers-toggle {
  background-color: var(--panel) !important;
  border-radius: 8px !important;
  width: 36px !important;
  height: 36px !important;
}
.leaflet-control-layers-expanded {
  padding: 8px 12px !important;
  font-family: 'Syne', sans-serif !important;
  font-size: 13px !important;
  min-width: 160px;
}
.leaflet-control-layers label {
  display: flex !important;
  align-items: center !important;
  gap: 6px !important;
  padding: 4px 0 !important;
  cursor: pointer !important;
  color: var(--text) !important;
}
.leaflet-control-layers label:hover { color: var(--accent) !important; }
.leaflet-control-layers input[type=radio] { accent-color: var(--accent); }

/* Theme toggle */
.theme-toggle {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  color: var(--text);
  transition: background .15s, border-color .15s;
  flex-shrink: 0;
  margin-left: 8px;
}
.theme-toggle:hover { border-color: var(--accent); }

/* Data aktualizacji w logo */
.update-date {
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  letter-spacing: 0;
  margin-left: 4px;
}

/* Stop popup */
.stop-popup {
  font-family: 'Syne', sans-serif;
  padding: 2px 0;
}
.stop-popup-name {
  font-size: 13px;
  font-weight: 700;
  color: #111;
  line-height: 1.3;
  margin-bottom: 3px;
  word-break: break-word;
}
.stop-popup-meta {
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  color: #888;
  margin-bottom: 6px;
}
.stop-popup-routes {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stop-popup-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: #888;
}
.stop-popup-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}
.stop-popup-badge {
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  font-weight: 700;
  background: #f0b429;
  color: #000;
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.stop-popup-badge:hover {
  background: #d4940f;
  transform: scale(1.08);
}

/* ── PLANNER ─────────────────────────────────────────────────────────────── */
#planner-view {
  flex: 1;
  display: none;
  flex-direction: column;
  overflow: hidden;
}
#planner-view.visible { display: flex; }

.planner-form {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  flex-shrink: 0;
}

.planner-fields {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.planner-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 160px;
}
.planner-field-sm { flex: 0 0 120px; min-width: 100px; }

.planner-field label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
}

.planner-field input[type=text],
.planner-field input[type=time],
.planner-field select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text);
  font-family: 'Syne', sans-serif;
  font-size: 13px;
  outline: none;
  width: 100%;
}
.planner-field input:focus,
.planner-field select:focus { border-color: var(--accent); }

.stop-autocomplete { position: relative; }

.autocomplete-list {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
  z-index: 2000;
  max-height: 240px;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.ac-item {
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}
.ac-item:hover { background: var(--panel); color: var(--accent); }
.ac-code {
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  background: var(--border);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--muted);
  flex-shrink: 0;
}

.swap-btn {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 18px;
  padding: 7px 10px;
  align-self: flex-end;
  transition: all .15s;
  flex-shrink: 0;
}
.swap-btn:hover { border-color: var(--accent); color: var(--accent); }

.plan-btn {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #000;
  cursor: pointer;
  font-family: 'Syne', sans-serif;
  font-size: 14px;
  font-weight: 700;
  padding: 9px 20px;
  align-self: flex-end;
  transition: opacity .15s;
  flex-shrink: 0;
}
.plan-btn:hover { opacity: .85; }

/* Results */
.planner-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}
.planner-body::-webkit-scrollbar { width: 4px; }
.planner-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.plan-loading { color: var(--muted); font-size: 14px; padding: 24px 0; }
.plan-error {
  color: var(--red);
  font-size: 13px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--red);
  border-radius: 8px;
  margin-top: 8px;
}

.plan-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.plan-route-label { font-size: 16px; font-weight: 800; }
.plan-meta { font-size: 12px; color: var(--muted); }

.plan-route {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color .15s;
}
.plan-route:hover { border-color: var(--accent); }

.plan-route-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  border-left: 4px solid var(--accent);
  flex-wrap: wrap;
}
.plan-route-times { display: flex; align-items: center; gap: 6px; }
.plan-depart { font-family: 'Space Mono', monospace; font-size: 18px; font-weight: 700; }
.plan-arrive { font-family: 'Space Mono', monospace; font-size: 18px; color: var(--muted); }
.plan-arrow { color: var(--muted); font-size: 14px; }

.plan-route-meta { display: flex; flex-direction: column; gap: 2px; }
.plan-duration { font-size: 14px; font-weight: 700; }
.plan-transfers { font-size: 11px; color: var(--muted); }

.plan-lines { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.plan-line-badge {
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  font-weight: 700;
  color: #000;
  padding: 3px 8px;
  border-radius: 5px;
}
.plan-line-sep { color: var(--muted); font-size: 12px; }

.plan-route-body { padding: 0 16px 12px; }

.leg { margin-top: 12px; }
.leg-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.leg-badge {
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  font-weight: 700;
  color: #000;
  padding: 2px 8px;
  border-radius: 5px;
}
.leg-headsign { font-size: 12px; color: var(--muted); flex: 1; }
.leg-duration { font-family: 'Space Mono', monospace; font-size: 11px; color: var(--muted); }

.leg-timeline {
  border-left: 2px solid var(--border);
  margin-left: 10px;
  padding-left: 12px;
}
.leg-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 3px 0;
  position: relative;
}
.leg-row::before {
  content: '';
  position: absolute;
  left: -17px;
  top: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  border: 2px solid var(--panel);
}
.leg-row-first::before { background: var(--accent); }
.leg-row-last::before  { background: var(--accent); }

.leg-time {
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  min-width: 40px;
  flex-shrink: 0;
}
.leg-stop-name { font-size: 12px; }

.leg-stops-toggle {
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  padding: 3px 0;
  user-select: none;
}
.leg-stops-toggle:hover { color: var(--accent); }
.leg-stops-list { display: none; padding-bottom: 4px; }
.leg-stops-list.open { display: block; }
.leg-stop-item {
  display: flex;
  gap: 10px;
  font-size: 11px;
  color: var(--muted);
  padding: 1px 0;
}
.leg-stop-time {
  font-family: 'Space Mono', monospace;
  min-width: 40px;
  flex-shrink: 0;
}

.transfer-badge {
  font-size: 11px;
  color: var(--muted);
  padding: 6px 0 2px 22px;
}

.plan-elapsed {
  font-size: 10px;
  color: var(--border);
  text-align: right;
  margin-top: 8px;
}

/* ══════════════════════════════════════════════════════════════════════
   RESPONSIVE — mobile (≤ 768px)
   ══════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ── Header ── */
  header {
    padding: 0 10px;
    height: auto;
    min-height: 52px;
    flex-wrap: wrap;
    gap: 8px;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .logo { font-size: 15px; }
  .update-date { display: none; }   /* za mało miejsca */

  .tabs {
    order: 3;
    width: 100%;
    justify-content: stretch;
    margin-left: 0;
    border-radius: 6px;
  }

  .tab {
    flex: 1;
    padding: 6px 4px;
    font-size: 11px;
    text-align: center;
    /* Skróć etykiety na mobile */
  }

  .theme-toggle { margin-left: auto; }

  /* ── Main layout — sidebar chowa się pod mapę ── */
  .main { flex-direction: column; }

  .sidebar {
    width: 100%;
    height: 220px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }

  /* Kiedy mapa jest aktywna, sidebar jest wąski */
  #map-view { min-height: 0; }

  /* ── Detail panel — pełna szerokość, pionowy układ ── */
  .detail-panel {
    height: 260px;
    max-height: 55vh;
  }

  .detail-header {
    padding: 8px 12px;
    flex-wrap: wrap;
    gap: 6px;
  }

  .detail-title { font-size: 14px; }

  .dir-tabs {
    width: 100%;
    flex-wrap: wrap;
    gap: 4px;
  }

  .dir-tab { font-size: 10px; padding: 3px 8px; }

  .detail-content { flex-direction: column; }

  .stops-panel {
    width: 100%;
    height: 90px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }

  .depart-panel { flex: 1; padding: 8px 12px; }

  /* ── Stops view ── */
  .stop-search-bar { padding: 10px 12px; }
  .stop-search-bar input { font-size: 13px; }

  .stop-result-item { padding: 8px 10px; }
  .stop-result-name { font-size: 12px; }

  /* ── Stats view ── */
  #stats-view { padding: 16px 12px; }
  .stats-title { font-size: 18px; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-card-value { font-size: 26px; }

  .freq-label { width: 30px; font-size: 10px; }
  .freq-bars { max-width: 120px; }
  .freq-count { width: 50px; font-size: 9px; }

  /* ── Planner view ── */
  .planner-form { padding: 10px 12px; }

  .planner-fields {
    flex-direction: column;
    gap: 8px;
  }

  .planner-field { min-width: unset; width: 100%; }
  .planner-field-sm { flex: unset; width: 100%; }

  .swap-btn {
    align-self: center;
    transform: rotate(0deg);  /* pionowy ⇅ jest OK */
  }

  .plan-btn { width: 100%; text-align: center; padding: 10px; }

  .plan-route-header {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
  }

  .plan-depart, .plan-arrive { font-size: 15px; }

  .plan-lines { margin-left: 0; width: 100%; }

  .planner-body { padding: 10px 12px; }

  /* ── Leaflet kontrolki ── */
  .leaflet-control-layers-expanded { font-size: 12px; min-width: 130px; }
  .leaflet-right .leaflet-control { margin-right: 6px; }
  .leaflet-top .leaflet-control { margin-top: 6px; }
}

/* ── Bardzo małe ekrany (≤ 400px) ── */
@media (max-width: 400px) {
  .tab { font-size: 10px; padding: 5px 2px; }
  .stats-grid { grid-template-columns: 1fr; }
  .plan-depart, .plan-arrive { font-size: 14px; }
}

/* ── Hamburger i szuflada (mobile) ── */
.hamburger {
  display: none;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 18px;
  padding: 5px 10px;
  line-height: 1;
  flex-shrink: 0;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 500;
}
.sidebar-overlay.visible { display: block; }

@media (max-width: 768px) {
  .hamburger { display: block; }

  /* Sidebar jako szuflada wysuwana z lewej */
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 280px;
    height: 100% !important;
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 600;
    border-right: 1px solid var(--border);
    box-shadow: 4px 0 20px rgba(0,0,0,.4);
  }
  .sidebar.drawer-open { transform: translateX(0); }

  /* Ukryj sidebar style z showView — na mobile jest fixed */
  #map-view { width: 100%; }
}

/* Pole tekstowe z przyciskiem lokalizacji */
.input-with-btn {
  display: flex;
  gap: 6px;
}
.input-with-btn input {
  flex: 1;
  min-width: 0;
}
.locate-btn {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 16px;
  padding: 0 10px;
  flex-shrink: 0;
  transition: border-color .15s;
  line-height: 1;
}
.locate-btn:hover { border-color: var(--accent); }
.locate-btn:disabled { opacity: .5; cursor: wait; }

.ac-locate-item .ac-code {
  background: var(--accent);
  color: #000;
  min-width: 48px;
  text-align: center;
}
