:root {
  --bg: #ffffff;
  --fg: #1d2330;
  --muted: #667085;
  --line: #e4e7ec;
  --accent: #1f6feb;
  --warn: #b54708;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--fg);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
#map { position: absolute; inset: 0; }

#panel {
  position: absolute; top: 12px; left: 12px; bottom: 12px; width: 340px;
  background: var(--bg); border-radius: var(--radius);
  box-shadow: 0 4px 24px rgba(16, 24, 40, .18);
  display: flex; flex-direction: column; z-index: 2; overflow: hidden;
  transition: transform .2s ease;
}
#panel.collapsed { transform: translateX(calc(-100% + 44px)); }
#panel.collapsed .panel-body, #panel.collapsed footer { visibility: hidden; }
#panel header { display: flex; align-items: center; gap: 8px; padding: 12px 12px 8px 16px; border-bottom: 1px solid var(--line); }
#panel h1 { font-size: 16px; margin: 0; flex: 1; }
.panel-body { overflow-y: auto; padding: 12px 16px; flex: 1; }
#panel footer { display: flex; justify-content: space-between; gap: 8px; padding: 8px 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.admin-link { color: var(--muted); }

h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 16px 0 6px; }
section:first-of-type h2 { margin-top: 12px; }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 0; min-height: 1em; }

button { font: inherit; cursor: pointer; }
button.icon { border: 0; background: none; font-size: 20px; line-height: 1; padding: 4px 8px; color: var(--muted); }

#search { display: flex; gap: 6px; }
#search input { flex: 1; min-width: 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
#search button, .btn { padding: 8px 12px; border: 0; border-radius: 8px; background: var(--accent); color: #fff; }
#search-results { margin-top: 6px; }
#search-results button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 6px 4px; border-radius: 6px; color: var(--fg); }
#search-results button:hover { background: #f2f4f7; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 11px; color: var(--fg); }
.chips button.active { background: var(--fg); border-color: var(--fg); color: #fff; }
.chips button:disabled { opacity: .4; cursor: not-allowed; }

.toggles label { display: flex; align-items: center; gap: 8px; margin: 6px 0; }

#legend .row { display: flex; align-items: center; gap: 8px; margin: 3px 0; font-size: 13px; }
#legend .sw { width: 14px; height: 14px; border-radius: 3px; flex: none; }
#legend .ramp { height: 12px; border-radius: 3px; }
#legend .ramp-labels { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: 2px; }
#legend .note { color: var(--muted); font-size: 12px; margin-top: 6px; }

#nearest { padding-left: 0; list-style: none; margin: 0; }
#nearest li { display: flex; align-items: center; gap: 10px; padding: 7px 4px; border-radius: 6px; cursor: pointer; }
#nearest li:hover { background: #f2f4f7; }
#nearest .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
#nearest .what { flex: 1; min-width: 0; }
#nearest .what b { display: block; }
#nearest .what span { color: var(--muted); font-size: 12px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#nearest .val { font-variant-numeric: tabular-nums; text-align: right; }
#nearest .val small { display: block; color: var(--muted); font-size: 11px; }

/* dymki */
.maplibregl-popup-content { padding: 12px 14px; border-radius: var(--radius); min-width: 260px; font-size: 13px; }
.pop h3 { margin: 0 0 2px; font-size: 15px; }
.pop .addr { color: var(--muted); margin-bottom: 8px; }
.pop .badge { display: inline-block; padding: 2px 8px; border-radius: 999px; color: #fff; font-size: 12px; margin-bottom: 8px; }
.pop table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.pop td { padding: 2px 0; }
.pop td:last-child { text-align: right; }
.pop td small { color: var(--muted); }
.pop .warn { background: #fffaeb; color: var(--warn); padding: 6px 8px; border-radius: 6px; margin: 8px 0 0; }
.pop .meta { color: var(--muted); font-size: 12px; margin-top: 8px; }
.pop svg { display: block; width: 100%; height: 56px; margin-top: 8px; }
.pop .chart-label { color: var(--muted); font-size: 11px; display: flex; justify-content: space-between; }

/* podsumowanie i statystyki */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 12px; }
.summary div { background: #f5f6f8; border-radius: 8px; padding: 6px 8px; }
.summary b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }
.summary span { color: var(--muted); font-size: 11px; }
.links { white-space: nowrap; }
.links a, .linkbtn { color: var(--muted); }
.linkbtn { border: 0; background: none; padding: 0; text-decoration: underline; font-size: 12px; }

.modal { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); z-index: 10; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-box { background: var(--bg); border-radius: var(--radius); width: min(860px, 100%); max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 12px 48px rgba(16,24,40,.3); }
.modal-box header { display: flex; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.modal-box header h2 { flex: 1; margin: 0; font-size: 16px; text-transform: none; letter-spacing: 0; color: var(--fg); }
#stats-body { overflow-y: auto; padding: 14px 18px 18px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.kpis div { background: #f5f6f8; border-radius: 8px; padding: 10px 12px; }
.kpis b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.kpis span { color: var(--muted); font-size: 12px; }
.bar { display: flex; height: 18px; border-radius: 4px; overflow: hidden; margin: 6px 0 4px; }
.bar div { height: 100%; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.stat-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 13px; }
.stat-table td, .stat-table th { padding: 4px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.stat-table th { color: var(--muted); font-weight: 500; font-size: 12px; }
.stat-table td.num { text-align: right; }
.stat-table tr.click { cursor: pointer; }
.stat-table tr.click:hover { background: #f2f4f7; }
.trend svg { width: 100%; height: 90px; display: block; }
.muted { color: var(--muted); font-size: 12px; }

@media (max-width: 640px) {
  .cols { grid-template-columns: 1fr; }
  #panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 55vh; border-radius: var(--radius) var(--radius) 0 0; }
  #panel.collapsed { transform: translateY(calc(100% - 48px)); }
  #panel-toggle { transform: rotate(-90deg); }
  #panel.collapsed #panel-toggle { transform: rotate(90deg); }
}
