:root {
  --kmk: #0059a9;
  --kmk-dark: #00294f;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: system-ui, -apple-system, 'Segoe UI', sans-serif; }
#map { position: absolute; inset: 0; }

#panel {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 5;
  width: 290px;
  max-height: calc(100% - 24px);
  overflow: auto;
  background: rgba(255, 255, 255, 0.96);
  border-radius: 12px;
  box-shadow: 0 4px 18px rgba(0, 30, 70, 0.25);
  padding: 14px 16px;
}
#panel h1 {
  margin: 0;
  font-size: 17px;
  line-height: 1.25;
  color: var(--kmk-dark);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
#panel .sub { margin: 6px 0 10px; font-size: 12.5px; color: #445; }
.chip {
  display: inline-block;
  background: var(--kmk);
  color: #fff;
  font-weight: 700;
  border-radius: 5px;
  padding: 1px 7px;
  border: 2px solid transparent;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.chip.active { border-color: #16202c; box-shadow: 0 0 0 2px #fff inset; }
.legend label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.legend input { margin: 0; }
.hint { margin: 6px 0 0; font-size: 11.5px; color: #667; }
#footer { font-size: 11.5px; color: #667; margin-top: 8px; border-top: 1px solid #e3e8f0; padding-top: 8px; }
.labelsize {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  border-top: 1px solid #e3e8f0;
  padding-top: 9px;
  font-size: 12.5px;
  color: #223;
}
.labelsize .lbl { flex: 1 1 auto; font-weight: 600; color: var(--kmk-dark); }
.labelsize button {
  flex: 0 0 auto;
  width: 30px;
  padding: 3px 0;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: var(--kmk);
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}
.labelsize button:hover { background: var(--kmk-dark); }
.labelsize button:disabled { opacity: 0.4; cursor: default; }
#label-size-val, #street-size-val, #density-val { flex: 0 0 40px; text-align: center; font-variant-numeric: tabular-nums; color: #445; }
.export { display: grid; gap: 6px; margin-top: 10px; }
.export button {
  display: block;
  width: 100%;
  padding: 6px 10px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: #fff;
  background: var(--kmk);
  border: 0;
  border-radius: 7px;
  cursor: pointer;
}
.export button:hover { background: var(--kmk-dark); }
.export button:disabled { opacity: 0.65; cursor: default; }
#area-box {
  position: absolute;
  display: none;
  z-index: 4;
  border: 2px dashed var(--kmk);
  background: rgba(0, 89, 169, 0.12);
  pointer-events: none;
}
#area-hint {
  position: absolute;
  display: none;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 8px;
  box-shadow: 0 3px 14px rgba(0, 30, 70, 0.3);
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--kmk-dark);
  pointer-events: none;
}
.legend { list-style: none; margin: 0 0 10px; padding: 0; font-size: 12.5px; color: #223; }
.legend li { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.sw { flex: 0 0 auto; }
.sw.line { width: 26px; height: 5px; background: var(--kmk); border-radius: 3px; box-shadow: 0 0 0 2px #fff, 0 0 0 3px #ccd; }
.sw.line.tram { background: #d6212b; }
.sw.line.mline { background: #e8a000; }
/* metro swatch: the five Metrorex line colors side by side */
.sw.line.metro { background: linear-gradient(90deg, #0000BB 0 33%, #BB0000 33% 66%, #a518a3 66% 100%); }
.sublegend { font-size: 11.5px; color: #445; padding-left: 26px; }
/* sublegends mix text with inline color chips — flex would scatter them */
.legend li.sublegend { display: block; }
.sublegend .mini { display: inline-block; width: 12px; height: 5px; border-radius: 3px; margin: 0 3px 0 7px; vertical-align: 2px; }
.sublegend .mini:first-child { margin-left: 0; }
.mini.trolley { background: #149a3f; }
/* Metrorex official line colors */
.mini.m1 { background: #0000BB; }
.mini.m2 { background: #BB0000; }
.mini.s1 { background: #E84A4B; }
.mini.s2 { background: #2E8EC8; }
.mini.s3 { background: #FFAC01; }
.mini.s4 { background: #2F7B20; }
.mini.wkd { background: #a518a3; }
.sw.stop { width: 11px; height: 11px; border-radius: 50%; background: #fff; border: 2.5px solid var(--kmk); }
.sw.terminus { width: 13px; height: 13px; border-radius: 50%; background: var(--kmk); border: 2.5px solid var(--kmk-dark); }
details.lines { border-top: 1px solid #e3e8f0; padding-top: 8px; margin-bottom: 4px; font-size: 12.5px; color: #223; }
details.lines summary { cursor: pointer; color: var(--kmk-dark); font-weight: 600; }
.chip-cloud { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0; }
/* twelve operators on one sheet, and they share numbers: the line list is
   grouped by operator, so Pruszków's 1 and Łomianki's 1 sit under their own
   headings and each chip prints the number its own stop flag prints */
.chip-head {
  display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap;
  margin: 12px 0 0; font-size: 12px; font-weight: 700; color: var(--kmk-dark);
}
.chip-head:first-child { margin-top: 6px; }
.chip-head .n {
  font-weight: 600; font-size: 11px; color: #556;
  background: #eef1f6; border-radius: 999px; padding: 0 6px;
}
.chip-sub {
  margin: 7px 0 2px; font-size: 10px; font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; color: #7b828c;
}
.debug { display: block; margin-top: 10px; font-size: 11.5px; color: #667; cursor: pointer; }
.debug input { vertical-align: -2px; margin-right: 4px; }

.maplibregl-popup-content {
  font-family: inherit;
  font-size: 12.5px;
  border-radius: 8px;
  box-shadow: 0 3px 14px rgba(0, 30, 70, 0.3);
  padding: 8px 12px;
}
.maplibregl-popup-content strong { color: var(--kmk-dark); }

@media (max-width: 560px) {
  #panel { width: calc(100% - 24px); max-height: 45%; }
}

/* City switcher (family navigation) */
.city-switch { margin: 6px 0 4px; font-size: 12.5px; }
.city-switch summary {
  cursor: pointer;
  color: var(--kmk);
  font-weight: 600;
  padding: 2px 9px;
  border: 1px solid #ccd6e4;
  border-radius: 7px;
  background: #f4f7fb;
  display: inline-block;
  user-select: none;
  list-style: none;
}
.city-switch summary::-webkit-details-marker { display: none; }
.city-switch summary::after { content: ' \25be'; font-size: 10px; }
.city-switch[open] summary::after { content: ' \25b4'; }
.city-switch nav {
  display: grid;
  gap: 2px;
  margin-top: 6px;
  padding: 6px;
  background: #f4f7fb;
  border: 1px solid #e0e7f1;
  border-radius: 9px;
}
.city-switch nav a, .city-switch nav .current {
  display: block;
  padding: 3px 8px;
  border-radius: 6px;
  font-weight: 600;
  color: #223;
  text-decoration: none;
}
.city-switch nav a:hover { background: var(--kmk); color: #fff; }
.city-switch nav .current { background: #dfe8f4; color: var(--kmk-dark); cursor: default; }
.city-switch nav a.all { margin-top: 3px; padding-top: 6px; border-top: 1px solid #dbe3ef; color: var(--kmk); }
/* Journey planner (beta) — its own floating element top-centre of the map */
#jp {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  font-size: 12.5px;
  color: #223;
}
#jp-toggle {
  display: block;
  font: inherit;
  font-weight: 700;
  color: var(--kmk-dark);
  background: rgba(255, 255, 255, 0.96);
  border: 0;
  border-radius: 999px;
  box-shadow: 0 4px 18px rgba(0, 30, 70, 0.25);
  padding: 8px 16px;
  cursor: pointer;
  white-space: nowrap;
}
#jp-toggle:hover { color: #fff; background: var(--kmk); }
#jp-card {
  width: min(360px, calc(100vw - 24px));
  background: rgba(255, 255, 255, 0.97);
  border-radius: 12px;
  box-shadow: 0 4px 18px rgba(0, 30, 70, 0.25);
  padding: 10px 12px 12px;
  max-height: calc(100vh - 90px);
  overflow: auto;
}
.jp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  color: var(--kmk-dark);
}
.jp-head button {
  width: 28px;
  height: 24px;
  padding: 0;
  font: inherit;
  font-size: 15px;
  line-height: 1;
  font-weight: 700;
  color: var(--kmk-dark);
  background: #f4f7fb;
  border: 1px solid #ccd6e4;
  border-radius: 7px;
  cursor: pointer;
}
.jp-head button:hover { background: var(--kmk); border-color: var(--kmk); color: #fff; }
#jp .hint { margin: 6px 0 0; }
#jp .beta,
details.journey .beta {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #fff;
  background: #d6212b;
  border-radius: 4px;
  padding: 1px 5px;
  vertical-align: 1px;
}
.jrow { display: flex; gap: 6px; margin-top: 7px; position: relative; }
/* own suggestion dropdown: iOS Safari never shows <datalist> options */
.jsug {
  position: absolute;
  top: calc(100% + 3px);
  left: 0;
  right: 0;
  z-index: 7;
  background: #fff;
  border: 1px solid #ccd6e4;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0, 30, 70, 0.22);
  max-height: 190px;
  overflow: auto;
}
.jsug div { padding: 7px 10px; cursor: pointer; }
.jsug div:hover { background: #e6eff9; }
/* fonts under 16 px make iOS zoom the whole PAGE on input focus */
@media (pointer: coarse) {
  #jp .jrow input { font-size: 16px; }
}
.jrow input {
  flex: 1 1 auto;
  min-width: 0;
  font: inherit;
  padding: 5px 8px;
  border: 1px solid #ccd6e4;
  border-radius: 7px;
  background: #fff;
  color: #223;
}
.jrow input:focus { outline: 2px solid var(--kmk); outline-offset: -1px; }
.jrow button {
  flex: 0 0 auto;
  font: inherit;
  font-weight: 600;
  padding: 5px 10px;
  border: 1px solid #ccd6e4;
  border-radius: 7px;
  background: #f4f7fb;
  color: var(--kmk-dark);
  cursor: pointer;
}
.jrow button:hover { background: var(--kmk); border-color: var(--kmk); color: #fff; }
.jrow button.jgo { flex: 1 1 auto; background: var(--kmk); border-color: var(--kmk); color: #fff; }
.jrow button.jgo:hover { background: var(--kmk-dark); }
#j-results { list-style: none; margin: 8px 0 0; padding: 0; }
#j-results li {
  padding: 6px 8px;
  margin-top: 4px;
  border: 1px solid #e0e7f1;
  border-radius: 8px;
  background: #f8fafd;
  cursor: pointer;
  line-height: 1.35;
}
#j-results li:hover { border-color: var(--kmk); }
#j-results li.active { border-color: var(--kmk); background: #e6eff9; }
#j-results .jl {
  display: inline-block;
  background: var(--kmk);
  color: #fff;
  font-weight: 700;
  border-radius: 4px;
  padding: 0 5px;
}
#j-results .jl.tram { background: #d6212b; }
#j-results .jkm { color: #667; font-size: 11.5px; }

/* Collapsible panel */
#panel-toggle {
  position: sticky;
  top: 0;
  z-index: 3;
  display: block;
  width: 30px;
  height: 26px;
  margin: -4px -6px -22px auto;
  padding: 0;
  font: inherit;
  font-size: 15px;
  line-height: 1;
  font-weight: 700;
  color: var(--kmk-dark);
  background: #f4f7fb;
  border: 1px solid #ccd6e4;
  border-radius: 7px;
  cursor: pointer;
}
#panel-toggle:hover { background: var(--kmk); border-color: var(--kmk); color: #fff; }
#panel h1 { padding-right: 30px; }
#panel.collapsed {
  width: auto;
  min-width: 0;
  padding: 8px;
  overflow: hidden;
}
#panel.collapsed > *:not(#panel-toggle) { display: none; }
#panel.collapsed #panel-toggle {
  position: static;
  width: 34px;
  height: 30px;
  margin: 0;
  font-size: 16px;
}

#base-switch { display: flex; margin: 0 0 8px; border: 1px solid #9aa4b1; border-radius: 7px; overflow: hidden; }
#base-switch button { flex: 1 1 0; padding: 5px 0; font: inherit; font-size: 12.5px; font-weight: 600; color: #4a5158; background: #fff; border: 0; cursor: pointer; }
#base-switch button + button { border-left: 1px solid #9aa4b1; }
#base-switch button:hover { background: #f0f1f3; }
#base-switch button.on { background: #6f757e; color: #fff; }

/* VIEW SWITCH: two segments, the active one filled. The map has two ways of
   drawing the same network — one stroke per roadway, or one stroke per line —
   and this is the only control that changes what the strokes MEAN. */
.viewsw { display: flex; gap: 0; margin: 0 0 8px; border: 1px solid var(--kmk); border-radius: 7px; overflow: hidden; }
.viewsw button {
  flex: 1 1 0; padding: 5px 0; font: inherit; font-size: 12.5px; font-weight: 600;
  color: var(--kmk); background: #fff; border: 0; cursor: pointer;
}
.viewsw button + button { border-left: 1px solid var(--kmk); }
.viewsw button:hover { background: #eef4fb; }
.viewsw button.on { background: var(--kmk); color: #fff; }
#base-switch { margin-top: -4px; }
.viewhint { margin: 0 0 8px; }
/* each view shows only its own legend rows and its own one-line explanation */
.lines-only, .legend li.lines-only { display: none; }  /* .legend li is (0,1,1) — a bare .lines-only never beats it */
body.lines-view .corridor-only { display: none; }
body.lines-view li.lines-only { display: flex; }
body.lines-view p.lines-only { display: block; }
/* the lines legend swatch IS the map's own rule: four coloured strands side by
   side, and the one grey stroke that replaces a busier bundle */
.sw.bundle { display: flex; flex-direction: column; gap: 1.5px; width: 26px; }
.sw.bundle i { display: block; height: 2.5px; border-radius: 2px; }
.sw.bundle i:nth-child(1) { background: #08859d; }
.sw.bundle i:nth-child(2) { background: #b0045c; }
.sw.bundle i:nth-child(3) { background: #b59607; }
.sw.bundle i:nth-child(4) { background: #126804; }
.sw.trunk { width: 26px; height: 7px; background: #6f757e; border-radius: 3px; }
/* the second deliverable of this map: the automatic network diagram */
.modelink { display: inline-block; margin: 0 0 8px; padding: 4px 10px; border: 1px solid #ccd6e4; border-radius: 7px; background: #f4f7fb; color: var(--kmk); font-weight: 600; font-size: 12.5px; text-decoration: none; }
.modelink:hover { background: var(--kmk); color: #fff; }

/* City-switch filter — type a city instead of scrolling the list */
.city-switch nav .city-filter {
  display: block;
  width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 4px 8px;
  margin-bottom: 3px;
  border: 1px solid #ccd6e4;
  border-radius: 6px;
  background: #fff;
  color: #223;
}
.city-switch nav .city-filter:focus { outline: none; border-color: var(--kmk); box-shadow: 0 0 0 2px rgba(0, 89, 169, 0.2); }
@media (pointer: coarse) { .city-switch nav .city-filter { font-size: 16px; } }
