:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1b1f24;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #1f6feb;
  --otodom: #00b3a4;
  --olx: #002f34;
  --chip: #eef2f7;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 12px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --card: #181c22; --text: #e6e8eb; --muted: #9aa3ad;
    --line: #2a2f37; --chip: #232932; --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: inherit; }
header {
  padding: 22px 18px 8px; max-width: 1280px; margin: 0 auto;
}
h1 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.backlink { color: var(--accent); text-decoration: none; margin-left: 10px; }
.backlink:hover { text-decoration: underline; }
.stats { margin-top: 6px; font-size: 13px; color: var(--muted); }
.stats b { color: var(--text); }

.controls {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: 10px 18px; max-width: 1280px; margin: 0 auto;
  display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center;
}
.group { display: inline-flex; gap: 4px; align-items: center; }
.group > label { font-size: 12px; color: var(--muted); margin-right: 2px; }
.seg { display: inline-flex; background: var(--chip); border-radius: 8px; padding: 2px; }
.seg button {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  padding: 5px 10px; border-radius: 6px; font-size: 13px;
}
.seg button.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
input.num, input.txt, select {
  background: var(--card); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 8px; font-size: 13px;
}
input.num { width: 92px; }
input.txt { width: 180px; }
.spacer { flex: 1 1 auto; }

main { max-width: 1280px; margin: 14px auto 60px; padding: 0 18px; }
.grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
}
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  overflow: hidden; box-shadow: var(--shadow); cursor: pointer;
  display: flex; flex-direction: column; transition: transform .08s ease;
}
.card:hover { transform: translateY(-2px); }
.thumb { aspect-ratio: 4 / 3; background: var(--chip); position: relative; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .noimg {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--muted); font-size: 13px;
}
.badges { position: absolute; top: 8px; left: 8px; display: flex; gap: 5px; }
.badge {
  font-size: 11px; font-weight: 600; color: #fff; padding: 2px 7px; border-radius: 999px;
}
.badge.otodom { background: var(--otodom); }
.badge.olx { background: var(--olx); }
.badge.gratka { background: #ff5a1f; }
.badge.morizon { background: #2b4c7e; }
.badge\.nieruchomosci-online,
.badge.nieruchomosci-online { background: #2e7d32; }
.tag-priv {
  position: absolute; top: 8px; right: 8px; font-size: 11px; font-weight: 600;
  background: rgba(0,0,0,.62); color: #fff; padding: 2px 7px; border-radius: 999px;
}
.body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; }
.price { font-size: 18px; font-weight: 700; letter-spacing: -.01em; }
.price .cheap { color: #1a7f37; }
@media (prefers-color-scheme: dark) { .price .cheap { color: #4ade80; } }
.price .pmax { font-size: 12px; color: var(--muted); font-weight: 500; margin-left: 7px; }
.offers .best { background: #1a7f37; color: #fff; font-size: 10px; font-weight: 700;
  padding: 1px 6px; border-radius: 999px; margin: 0 4px; }
.ppm { font-size: 12px; color: var(--muted); font-weight: 500; }
.facts { font-size: 13px; color: var(--text); }
.title { font-size: 12.5px; color: var(--muted); display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.loc { font-size: 12.5px; color: var(--muted); }
.also { margin-top: 4px; font-size: 12px; }
.also a { color: var(--accent); text-decoration: none; }
.offers { margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--line); }
.offers-h { font-size: 11px; color: var(--muted); font-weight: 600; margin-bottom: 1px;
  cursor: pointer; list-style: none; }
.offers-h::before { content: "▸ "; }
.offers[open] .offers-h::before { content: "▾ "; }
.offers-body { display: flex; flex-direction: column; gap: 2px; margin-top: 2px; }
.offers a { color: var(--accent); text-decoration: none; font-size: 12px; }
.offers a:hover { text-decoration: underline; }
.lz { color: var(--muted); font-size: 12px; }
.hist { margin-top: 5px; font-size: 12px; color: var(--muted);
  display: flex; flex-wrap: wrap; gap: 3px 8px; align-items: center; }
.hist .relist { background: #b45309; color: #fff; font-weight: 700;
  font-size: 10px; padding: 1px 6px; border-radius: 999px; }
.hist .trail { color: var(--text); }
.hist .since { opacity: .75; }
.empty { text-align: center; color: var(--muted); padding: 60px 0; }
/* town multi-select */
.ms { position: relative; }
.ms-btn {
  background: var(--card); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 26px 6px 10px; font-size: 13px; cursor: pointer;
  max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ms-btn::after { content: "▾"; position: absolute; right: 9px; color: var(--muted); }
.ms-btn.has-sel { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.ms-pop {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 20; width: 280px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); padding: 8px; display: flex; flex-direction: column; gap: 6px;
}
.ms-pop input[type="search"] {
  width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 7px; padding: 6px 8px; font-size: 13px;
}
.ms-list { max-height: 260px; overflow: auto; display: flex; flex-direction: column; }
.ms-item {
  display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px;
  font-size: 13px; cursor: pointer;
}
.ms-item:hover { background: var(--chip); }
.ms-item span { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-item b { color: var(--muted); font-weight: 500; font-size: 11px; }
.ms-empty { color: var(--muted); font-size: 13px; padding: 8px 6px; }
.ms-foot { display: flex; justify-content: flex-end; border-top: 1px solid var(--line); padding-top: 6px; }
.ms-foot button { background: transparent; border: 0; color: var(--accent); font-size: 12px; cursor: pointer; }

/* active-filter chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; background: var(--chip);
  color: var(--text); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 10px; font-size: 12.5px; cursor: pointer;
}
.chip:hover { border-color: var(--accent); }
.chip .x { color: var(--muted); font-size: 11px; }
.chip.reset { background: transparent; color: var(--muted); font-weight: 600; }
.chip.reset:hover { color: var(--accent); }

footer { text-align: center; color: var(--muted); font-size: 12px; padding: 20px; }

/* ---- property lifetime timeline + archive (sold/withdrawn) ---- */
.tl { margin-top: 7px; border-top: 1px dashed var(--line); padding-top: 6px; }
.tl summary { cursor: pointer; font-size: 12px; color: var(--accent); font-weight: 600;
  list-style: none; }
.tl summary::before { content: "▸ "; }
.tl[open] summary::before { content: "▾ "; }
.tl-body { margin-top: 5px; display: flex; flex-direction: column; gap: 3px; }
.tl-row { display: flex; gap: 8px; font-size: 12px; align-items: baseline; }
.tl-date { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.tl-what { color: var(--text); }
.tl-sale { color: #1a7f37; }
.tl-photos { margin-top: 4px; font-size: 12px; color: var(--muted); }
.tl-photos a { color: var(--accent); text-decoration: none; margin-right: 2px; }
.soldline { margin-top: 5px; font-size: 12.5px; color: #1a7f37; font-weight: 600; }
.goneline { margin-top: 5px; font-size: 12.5px; color: #b45309; font-weight: 600; }
.pastsale { margin-top: 4px; font-size: 12px; color: var(--text); }
.card.gone .thumb img { filter: grayscale(60%); opacity: .85; }
.tag-gone { position: absolute; bottom: 8px; left: 8px; background: #6b7280; color: #fff;
  font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 6px;
  text-transform: uppercase; letter-spacing: .03em; }
.tag-gone.sold { background: #1a7f37; }

/* ---- chunked grid rendering ---- */
.card { content-visibility: auto; contain-intrinsic-size: 420px; }
.sentinel { height: 1px; grid-column: 1 / -1; }

/* ---- developer new-builds ---- */
.tag-dev { position: absolute; top: 8px; right: 8px; background: #6d28d9; color: #fff;
  font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 6px;
  text-transform: uppercase; letter-spacing: .03em; }

/* [hidden] must win over display rules (lost in an earlier file truncation —
   .ms-pop sets display:flex which otherwise overrides the UA hidden style) */
[hidden] { display: none !important; }

/* ---- pin-address form on cards ---- */
.pinbox { margin-top: 6px; }
.pinbox summary { cursor: pointer; font-size: 12px; color: var(--muted); list-style: none; }
.pinbox summary:hover { color: var(--accent); }
.pin-form { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.pin-form input { background: var(--chip); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: 4px 7px; font-size: 12px; }
.pin-ul { flex: 1 1 120px; min-width: 110px; }
.pin-nr { width: 52px; }
.pin-x { width: 78px; }
.pin-copy { background: var(--accent); color: #fff; border: 0; border-radius: 6px;
  padding: 5px 9px; font-size: 12px; font-weight: 600; cursor: pointer; }
.pin-hint { flex-basis: 100%; font-size: 11px; color: var(--muted); }

/* ---- in-browser RCN check results ---- */
.pin-check { background: #1a7f37; color: #fff; border: 0; border-radius: 6px;
  padding: 5px 9px; font-size: 12px; font-weight: 600; cursor: pointer; }
.pin-check:disabled { opacity: .6; cursor: wait; }
.pin-results { flex-basis: 100%; font-size: 12px; margin-top: 4px; color: var(--text); }
.pin-deeds { margin-top: 4px; display: flex; flex-direction: column; gap: 2px; }
.pin-links { margin-top: 3px; }
.pin-links a { color: var(--accent); text-decoration: none; font-size: 12px; }
.pin-links a:hover { text-decoration: underline; }
.tl-src { color: var(--muted); font-size: 11px; }
.tl-src a { color: var(--accent); text-decoration: none; }
.hist .drop { background: #166534; color: #fff; font-weight: 700; font-size: 11px;
  padding: 1px 6px; border-radius: 6px; }

/* ---- cena vs transakcje RCN + negotiation arguments ---- */
.vsrcn { font-size: 12px; color: var(--muted); }
.vsrcn b { font-weight: 700; }
.vsrcn.over b { color: #b91c1c; }
.vsrcn.under b { color: #1a7f37; }
@media (prefers-color-scheme: dark) {
  .vsrcn.over b { color: #f87171; }
  .vsrcn.under b { color: #4ade80; }
}
.vsrcn-med { font-size: 11px; opacity: .8; }
.nego { margin-top: 7px; border-top: 1px dashed var(--line); padding-top: 6px; }
.nego summary { cursor: pointer; font-size: 12px; color: var(--accent); font-weight: 600;
  list-style: none; }
.nego summary::before { content: "▸ "; }
.nego[open] summary::before { content: "▾ "; }
.nego-body { margin-top: 5px; display: flex; flex-direction: column; gap: 4px; }
.nego-row { font-size: 12px; color: var(--text); }

/* ---- map view ---- */
.mapbtn { background: var(--card); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 12px; font-size: 13px; cursor: pointer; }
.mapbtn.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }
#map { height: 68vh; border: 1px solid var(--line); border-radius: 12px;
  margin: 0 0 14px; z-index: 1; background: var(--chip); }
.map-legend { background: var(--card); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: var(--shadow); padding: 7px 10px;
  font-size: 12px; line-height: 1.7; }
.map-legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  margin: 0 4px 0 6px; vertical-align: -1px; }
.map-legend .dot:first-of-type { margin-left: 0; }
.map-pop { font: 13px/1.4 inherit; max-width: 260px; }
.map-pop img { width: 100%; max-height: 140px; object-fit: cover; border-radius: 8px;
  margin-bottom: 5px; }
.map-pop .price { font-weight: 700; font-size: 15px; }
.map-pop .facts { color: var(--muted); font-size: 12px; margin-top: 2px; }
.map-pop .t { font-size: 12px; margin-top: 3px; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.map-pop .approx { color: var(--muted); font-size: 11px; margin-top: 3px; }
.map-pop a { color: var(--accent); text-decoration: none; font-size: 12px;
  display: inline-block; margin-top: 4px; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--card); color: var(--text); }
.leaflet-container { font: inherit; }
@media (prefers-color-scheme: dark) {
  .leaflet-tile { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.9) saturate(.65); }
  .leaflet-control-attribution { background: rgba(24,28,34,.8); color: var(--muted); }
}
