:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --text: #0f1f2a;
  --muted: #5b6b78;
  --border: #e3e8ee;
  --brand: #0b3b4f;
  --brand-2: #7dd3fc;
  --accent: #0e7490;
  --accent-soft: #e6f6fa;
  --danger: #c62828;
  --danger-soft: #fdecec;
  --warn: #b45309;
  --warn-soft: #fef3e2;
  --ok: #15803d;
  --ok-soft: #e8f7ee;
  --shadow: 0 1px 2px rgba(15, 31, 42, .06), 0 4px 16px rgba(15, 31, 42, .06);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b141b;
    --surface: #111c25;
    --surface-2: #15232e;
    --text: #e6edf2;
    --muted: #93a4b1;
    --border: #22323f;
    --brand: #0b3b4f;
    --accent: #38bdf8;
    --accent-soft: #0e2a38;
    --danger: #f87171;
    --danger-soft: #2a1414;
    --warn: #f59e0b;
    --warn-soft: #2b2110;
    --ok: #4ade80;
    --ok-soft: #0f2a1a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
button { font: inherit; color: inherit; }

/* ——— top bar ——— */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) 10px max(20px, env(safe-area-inset-left));
  background: var(--brand); color: #fff; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 36px; height: 36px; flex-shrink: 0; border-radius: 9px; }
button, .chip, .btn, .list li { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.topbar h1 { font-size: 17px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.tagline { margin: 0; font-size: 12px; color: rgba(255, 255, 255, .7); }

.segmented {
  display: inline-flex; padding: 3px; gap: 2px;
  background: rgba(255, 255, 255, .1); border-radius: 10px;
}
.segmented button {
  border: 0; background: transparent; color: rgba(255, 255, 255, .8);
  padding: 6px 14px; border-radius: 8px; cursor: pointer; font-weight: 500;
}
.segmented button[aria-checked="true"] { background: #fff; color: var(--brand); }

.me { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.lic { display: flex; align-items: center; gap: 8px; font-size: 12px; color: rgba(255, 255, 255, .75); }
.lic[hidden] { display: none; }
.lic select {
  font: inherit; font-size: 13px; color: var(--brand); background: #fff; border: 0;
  border-radius: 8px; padding: 6px 8px; cursor: pointer;
}

/* ——— layout ——— */
.layout { flex: 1; display: flex; min-height: 0; }
.panel {
  width: 420px; flex-shrink: 0; display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border-right: 1px solid var(--border);
}
.panel-head { padding: 14px 16px 10px; border-bottom: 1px solid var(--border); display: grid; gap: 10px; }
.panel-body { flex: 1; overflow-y: auto; padding: 12px 16px 20px; }
.map-wrap { flex: 1; position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--surface-2); }

/* ——— search & chips ——— */
.search {
  display: flex; align-items: center; gap: 8px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2);
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search svg { width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2; flex-shrink: 0; }
.search input { flex: 1; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; padding: 9px 0; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  padding: 4px 10px; border-radius: 99px; cursor: pointer; font-size: 12.5px; font-weight: 500;
}
.chip.on { color: var(--text); border-color: currentColor; background: var(--surface-2); }
.chip .dot { opacity: .35; }
.chip.on .dot { opacity: 1; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.chip.mine { color: var(--ok); }
.chip.mine.on { background: var(--ok-soft); }
.chip[hidden] { display: none; }

/* ——— list ——— */
.list-head { font-size: 12px; color: var(--muted); margin: 4px 2px 6px; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.list li {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  padding: 9px 10px; border-radius: 10px; cursor: pointer;
}
.list li:hover { background: var(--surface-2); }
.list li.selected { background: var(--accent-soft); }
.list li:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.list .name { font-weight: 600; }
.list .meta { font-size: 12px; color: var(--muted); }
.list .price { font-size: 12px; color: var(--muted); text-align: right; white-space: nowrap; }
.list .price b { display: block; color: var(--text); font-size: 13px; }
.list .price.ban b { color: var(--danger); }
.list .price.ok b { color: var(--ok); }
.empty { color: var(--muted); padding: 16px 4px; }

/* ——— details ——— */
.details {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px;
}
.d-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.details h2 { font-size: 18px; margin: 0; letter-spacing: -.01em; }
.close {
  border: 0; background: var(--surface-2); width: 30px; height: 30px; border-radius: 8px;
  cursor: pointer; font-size: 18px; line-height: 1; color: var(--muted); flex-shrink: 0;
}
.close:hover { color: var(--text); }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 10px; }
.badge {
  font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 6px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
  display: inline-flex; align-items: center; gap: 5px;
}
.badge.gorska { color: #0369a1; border-color: #bae6fd; background: #f0f9ff; }
@media (prefers-color-scheme: dark) { .badge.gorska { color: #7dd3fc; border-color: #0c4a6e; background: #082f49; } }
.lead { margin: 0 0 12px; color: var(--muted); }

.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 4px 0 12px; }
.total { background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; }
.total .lbl { font-size: 11.5px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.total .val { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.total .sub { font-size: 11.5px; color: var(--muted); }

.sec { margin-top: 14px; }
.sec h3 { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 6px; }
.rows { list-style: none; margin: 0; padding: 0; }
.rows li { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.rows li:last-child { border-bottom: 0; }
.rows .amt { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.rows .hint { display: block; font-size: 12px; color: var(--muted); }
.rows li.sum { font-weight: 700; border-top: 2px solid var(--border); border-bottom: 0; }

table.periods { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.periods th, .periods td { padding: 6px 4px; text-align: right; border-bottom: 1px solid var(--border); }
.periods th { font-size: 12px; color: var(--muted); font-weight: 500; }
.periods th:first-child, .periods td:first-child { text-align: left; }
.periods tr:last-child td { border-bottom: 0; }

.notes { margin: 0; padding-left: 18px; color: var(--text); }
.notes li { margin: 4px 0; }
.muted { color: var(--muted); font-size: 12.5px; }
.ban-box { background: var(--danger-soft); color: var(--danger); border-radius: 10px; padding: 10px 12px; font-weight: 600; }
.badge.nokill { color: var(--danger); border-color: currentColor; background: var(--danger-soft); }

.cover { display: flex; gap: 10px; align-items: flex-start; border-radius: 10px; padding: 10px 12px; margin: 4px 0 8px; }
.cover p { margin: 2px 0 0; }
.cover.ok { background: var(--ok-soft); }
.cover.warn { background: var(--warn-soft); }
.cover.info { background: var(--accent-soft); }
.cov-ico {
  width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center;
  font-weight: 700; font-size: 13px; color: #fff; background: var(--accent);
}
.cover.ok .cov-ico { background: var(--ok); }
.cover.warn .cov-ico { background: var(--warn); }

.docs { list-style: none; margin: 0 0 6px; padding: 0; display: grid; gap: 6px; }
.docs li { display: flex; gap: 8px; align-items: flex-start; }
.docs .hint { display: block; font-size: 12px; color: var(--muted); }
.chk { color: var(--ok); font-weight: 700; }

.tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tag { font-size: 12px; padding: 2px 9px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none; font-weight: 600; font-size: 13px;
  padding: 8px 12px; border-radius: 9px; border: 1px solid var(--border); color: var(--text); background: var(--surface);
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #062231; } }
.source { margin-top: 12px; font-size: 12px; color: var(--muted); }

/* ——— guide & footer ——— */
.guide { margin-top: 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.guide summary { cursor: pointer; padding: 12px 14px; font-weight: 600; }
.guide-body { padding: 0 14px 12px; }
.guide h4 { margin: 10px 0 2px; font-size: 13px; }
.guide p, .guide ul { margin: 0 0 6px; color: var(--muted); }
.guide ul { padding-left: 18px; }
.foot { margin-top: 16px; font-size: 12px; color: var(--muted); }
.foot p { margin: 0 0 6px; }

/* ——— map ui ——— */
.pin {
  width: 26px; height: 26px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
  display: grid; place-items: center;
}
.pin span { transform: rotate(45deg); color: #fff; font-size: 12px; font-weight: 700; line-height: 1; }
.pin.sel { outline: 3px solid rgba(14, 116, 144, .45); outline-offset: 2px; }
.pin.ok { border-color: #22c55e; }
.legend .dash { width: 14px; border-top: 3px dashed var(--muted); display: inline-block; }
.legend {
  position: absolute; left: 12px; bottom: 24px; z-index: 500;
  background: var(--surface); color: var(--text); border-radius: 10px; box-shadow: var(--shadow);
  padding: 8px 10px; font-size: 12px; display: grid; gap: 3px;
}
.legend div { display: flex; align-items: center; gap: 6px; }
.locate {
  position: absolute; right: 12px; top: 12px; z-index: 500; width: 36px; height: 36px;
  border: 0; border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); cursor: pointer;
  display: grid; place-items: center;
}
.locate svg { width: 20px; height: 20px; fill: none; stroke: var(--text); stroke-width: 2; }
.leaflet-tooltip { font: 600 12px Inter, system-ui, sans-serif; }

.btn.show-map { display: none; }

/* ——— telefony ——— */
@media (max-width: 820px) {
  html, body { height: auto; }
  body { font-size: 15px; }
  .topbar {
    gap: 10px;
    padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
  }
  .topbar h1 { font-size: 16px; }
  .tagline { display: none; }
  .logo { width: 32px; height: 32px; border-radius: 8px; }
  .me { width: 100%; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; padding: 9px 10px; }
  .lic { width: 100%; justify-content: space-between; }
  .lic select { flex: 1; max-width: 62%; font-size: 16px; padding: 8px; }

  .layout { flex-direction: column; }
  .map-wrap { flex: none; height: 44vh; height: 44svh; order: -1; }
  .panel { width: 100%; border-right: 0; }
  .panel-head { padding: 12px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)); }
  .panel-body {
    overflow: visible;
    padding: 12px max(16px, env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }
  .search input { font-size: 16px; padding: 11px 0; } /* 16px – iOS nie przybliża strony przy wpisywaniu */
  .chip { padding: 7px 12px; font-size: 13px; }
  .list li { padding: 12px 10px; }
  .btn { padding: 11px 14px; font-size: 14px; flex: 1 1 auto; justify-content: center; }
  .btn.show-map { display: inline-flex; }
  .details { padding: 14px; }
  .totals .val { font-size: 20px; }
  .legend { display: none; }
  .locate { width: 40px; height: 40px; }
  .leaflet-touch .leaflet-bar a { width: 36px; height: 36px; line-height: 36px; }
}
