:root {
  --ink: #0f2740;
  --ink-soft: #4a5b6e;
  --brand: #0b6e8c;
  --brand-deep: #084a5e;
  --accent: #e08a1e;
  --bg: #f6f9fb;
  --surface: #ffffff;
  --line: #dde6ec;

  --c0: #d7ecef;
  --c1: #a9d6df;
  --c2: #74bccb;
  --c3: #3f9cb4;
  --c4: #1f7d99;
  --c5: #0b5e78;
  --c6: #073f52;
  --c-na: #e9eef2;

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
  --shadow: 0 1px 2px rgba(15, 39, 64, .06), 0 4px 16px rgba(15, 39, 64, .06);
  --radius: 10px;
}

* { box-sizing: border-box; }
/* [hidden] musi wygrać z regułami display na selektorach ID (#layout{display:flex}) */
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  font-size: .9rem;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.mono, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------- Header ---------- */
.site-header {
  background: linear-gradient(180deg, var(--brand-deep), #06394a);
  color: #eaf4f7;
  border-bottom: 3px solid var(--accent);
}
.header-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: .85rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .7rem; }
.brand-mark {
  display: grid; place-items: center;
  width: 42px; height: 42px;
  border-radius: 11px;
  background: rgba(255,255,255,.09);
  color: #bfe6ef;
  border: 1px solid rgba(255,255,255,.14);
}
.brand-text h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -.01em;
  color: #fff;
}
.brand-text p {
  margin: .1rem 0 0;
  font-size: .82rem;
  color: #a7c9d3;
}
.source-badge {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-size: .76rem;
  color: #bfe0e8;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.12);
  padding: .35rem .65rem;
  border-radius: 999px;
}
.source-badge .num, #stat-count { font-family: var(--mono); color: #fff; }

/* ---------- Layout ---------- */
#layout {
  flex: 1 1 auto;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  display: flex;
  gap: 1rem;
  min-height: 0;
}

.map-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  background: var(--surface);
}
#map {
  position: absolute;
  inset: 0;
  background: #eef4f7;
}
.leaflet-container { background: #eef4f7; font-family: var(--sans); }

/* ---------- Legend ---------- */
.legend {
  position: absolute;
  left: 14px; bottom: 14px;
  z-index: 500;
  background: rgba(255,255,255,.96);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .6rem .7rem;
  box-shadow: var(--shadow);
  max-width: min(340px, calc(100% - 28px));
}
.legend-title {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-soft);
  margin-bottom: .4rem;
  font-weight: 600;
}
.legend-scale { display: flex; height: 12px; border-radius: 3px; overflow: hidden; }
.legend-scale span { flex: 1 1 0; }
.legend-labels {
  display: flex;
  justify-content: space-between;
  margin-top: .25rem;
  font-family: var(--mono);
  font-size: .68rem;
  color: var(--ink-soft);
}
.legend-na {
  display: flex; align-items: center; gap: .4rem;
  margin-top: .45rem;
  font-size: .72rem;
  color: var(--ink-soft);
}
.legend-na-swatch {
  width: 14px; height: 12px; border-radius: 3px;
  background: var(--c-na);
  border: 1px solid var(--line);
}

/* ---------- Tooltip ---------- */
.map-tooltip {
  position: absolute;
  z-index: 600;
  pointer-events: none;
  background: var(--ink);
  color: #fff;
  padding: .3rem .55rem;
  border-radius: 6px;
  font-size: .78rem;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
  transform: translate(-50%, -130%);
  white-space: nowrap;
}
.map-tooltip .tt-name { font-weight: 600; }
.map-tooltip .tt-price { font-family: var(--mono); color: #bfe6ef; }

/* ---------- Panel ---------- */
#panel {
  flex: 0 0 360px;
  width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.15rem 1.15rem 1.3rem;
  overflow-y: auto;
}

.empty-state {
  height: 100%;
  min-height: 260px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--ink-soft);
  padding: 2rem 1rem;
}
.empty-state svg { color: #9fb6c4; margin-bottom: .8rem; }
.empty-title { margin: 0; font-weight: 600; color: var(--ink); }
.empty-sub { margin: .3rem 0 0; font-size: .82rem; max-width: 22ch; }

.panel-head { border-bottom: 1px solid var(--line); padding-bottom: .8rem; margin-bottom: .9rem; }
.panel-head h2 {
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.25;
  color: var(--ink);
}
.panel-woj {
  margin: .2rem 0 0;
  font-size: .8rem;
  color: var(--ink-soft);
  display: inline-flex; align-items: center; gap: .35rem;
}
.teryt-chip {
  font-family: var(--mono);
  font-size: .7rem;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  padding: .05rem .35rem;
  border-radius: 4px;
}

.price-block {
  background: linear-gradient(180deg, #f0f7f9, #e7f1f4);
  border: 1px solid #cfe3e9;
  border-radius: 8px;
  padding: .8rem .9rem;
  margin-bottom: 1rem;
}
.price-label {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--brand-deep); font-weight: 600;
}
.price-main {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 2rem;
  font-weight: 700;
  color: var(--brand-deep);
  line-height: 1.1;
  margin-top: .15rem;
}
.price-main .unit { font-size: .95rem; font-weight: 500; color: var(--brand); }
.price-net { font-family: var(--mono); font-size: .8rem; color: var(--ink-soft); margin-top: .2rem; }

.section-label {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-soft); font-weight: 600; margin: 0 0 .35rem;
}

.operator-row { margin-bottom: 1rem; }
.operator-name { font-weight: 600; color: var(--ink); }

.owner-btn, .btn {
  display: inline-flex; align-items: center; gap: .4rem;
  font-family: var(--sans); font-size: .82rem; font-weight: 600;
  cursor: pointer;
  border-radius: 7px;
  border: 1px solid var(--brand);
  background: var(--surface);
  color: var(--brand-deep);
  padding: .55rem .8rem;
  min-height: 40px;
  transition: background .18s ease, color .18s ease, border-color .18s ease;
}
.owner-btn { margin-top: .5rem; width: 100%; justify-content: center; }
.owner-btn:hover { background: var(--brand); color: #fff; }

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  min-height: 44px;
  padding: .55rem 1rem;
}
.btn-primary:hover { background: var(--brand-deep); border-color: var(--brand-deep); }

/* Calculator */
.calc {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}
.calc-row { display: flex; gap: .5rem; align-items: flex-end; }
.calc-field { flex: 1 1 auto; }
.calc-field label { display: block; font-size: .72rem; color: var(--ink-soft); margin-bottom: .25rem; }
.calc-field input {
  width: 100%;
  font-family: var(--mono);
  font-size: .95rem;
  padding: .5rem .6rem;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: var(--surface);
}
.calc-field input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(11,110,140,.18); }
.calc-result {
  margin-top: .7rem;
  font-family: var(--mono);
  font-size: 1.05rem;
  color: var(--ink);
}
.calc-result strong { color: var(--brand-deep); }
.calc-result .sub { font-size: .8rem; color: var(--ink-soft); }

/* Owners */
.owners { margin-top: .8rem; }
.owners-firm { font-size: .78rem; color: var(--ink-soft); margin-bottom: .5rem; }
.owner-list { list-style: none; margin: 0; padding: 0; }
.owner-item {
  display: flex; justify-content: space-between; align-items: center; gap: .5rem;
  padding: .45rem 0;
  border-bottom: 1px solid var(--line);
}
.owner-item:last-child { border-bottom: 0; }
.owner-item .o-name { color: var(--ink); }
.owner-item .o-share { font-family: var(--mono); font-weight: 600; color: var(--brand-deep); }
.owner-share-bar {
  height: 5px; border-radius: 3px; background: var(--c-na);
  margin-top: .5rem; overflow: hidden;
}
.owner-share-bar i { display: block; height: 100%; background: var(--brand); }

.notice {
  font-size: .8rem;
  color: var(--ink-soft);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: .6rem .7rem;
  margin-top: .7rem;
}
.notice.warn { border-color: #eacfa1; background: #fdf6ea; color: #7a5410; }

.meta-row { display: flex; flex-wrap: wrap; gap: .3rem .9rem; margin-top: .7rem; }
.meta-row div { font-size: .76rem; color: var(--ink-soft); }
.meta-row b { font-family: var(--mono); color: var(--ink); font-weight: 600; }

/* Skeleton */
.sk { border-radius: 6px; background: linear-gradient(90deg,#eef3f6 25%,#e2ebf0 37%,#eef3f6 63%); background-size: 400% 100%; animation: sk 1.3s ease infinite; }
.sk-title { height: 22px; width: 70%; margin-bottom: .5rem; }
.sk-line { height: 12px; margin-bottom: .5rem; }
.sk-line.w60 { width: 60%; } .sk-line.w40 { width: 40%; }
.sk-block { height: 74px; margin: .8rem 0; }
@keyframes sk { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* ---------- Taryfy szczegółowe ---------- */
.taryfy-sekcja {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}
.taryfa-blok {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .75rem .8rem .8rem;
  margin-bottom: .8rem;
  background: var(--surface);
}
.taryfa-blok:last-child { margin-bottom: 0; }

.taryfa-head {
  margin-bottom: .6rem;
  padding-bottom: .5rem;
  border-bottom: 1px dashed var(--line);
}
.taryfa-obszar {
  font-weight: 600;
  color: var(--ink);
  display: flex; align-items: center; gap: .45rem; flex-wrap: wrap;
}
.badge-akt, .badge-arch {
  font-size: .64rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: .12rem .4rem;
  border-radius: 999px;
  line-height: 1.4;
}
.badge-akt { background: #e5f3ea; color: #1a7a45; border: 1px solid #b7e0c6; }
.badge-arch { background: var(--bg); color: var(--ink-soft); border: 1px solid var(--line); }

.taryfa-meta {
  margin-top: .4rem;
  display: flex; align-items: center; gap: .5rem .8rem; flex-wrap: wrap;
}
.taryfa-nr { font-size: .7rem; color: var(--ink-soft); word-break: break-all; }
.pdf-link {
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: .74rem; font-weight: 600;
  color: var(--brand-deep);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .25rem .5rem;
  transition: background .18s ease, border-color .18s ease;
}
.pdf-link:hover { background: var(--bg); border-color: var(--brand); }

/* Grupa referencyjna – wyeksponowana */
.grupa-ref {
  background: linear-gradient(180deg, #f0f7f9, #e7f1f4);
  border: 1px solid #cfe3e9;
  border-radius: 7px;
  padding: .6rem .7rem;
}
.grupa-ref .grupa + .grupa { margin-top: .6rem; padding-top: .6rem; border-top: 1px solid #cfe3e9; }
.grupa-ref .okres-cena { font-size: 1.15rem; color: var(--brand-deep); }

.grupa-head {
  display: flex; align-items: center; gap: .4rem; flex-wrap: wrap;
  margin-bottom: .35rem;
}
.grupa-kod {
  font-family: var(--mono);
  font-weight: 700;
  font-size: .82rem;
  color: var(--ink);
}
.typ-chip {
  font-size: .62rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  padding: .08rem .35rem; border-radius: 4px;
}
.typ-woda { background: #e4f1f6; color: var(--brand-deep); border: 1px solid #c4e0e9; }
.typ-scieki { background: #f3ede4; color: #7a5410; border: 1px solid #e6d6bd; }
.grupa-opis { font-size: .74rem; color: var(--ink-soft); }

.okres-list { list-style: none; margin: 0; padding: 0; }
.okres {
  display: flex; align-items: baseline; gap: .3rem .6rem; flex-wrap: wrap;
  padding: .3rem 0;
}
.okres + .okres { border-top: 1px solid var(--line); }
.okres-cena {
  font-weight: 700;
  font-size: .95rem;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.okres-unit { font-size: .72rem; font-weight: 500; color: var(--ink-soft); }
.abon { font-size: .72rem; color: var(--ink-soft); }
.okres-daty {
  font-family: var(--mono);
  font-size: .68rem;
  color: var(--ink-soft);
  margin-left: auto;
  white-space: nowrap;
}

/* Sekcja zwijana – pozostałe grupy */
.grupy-extra { margin-top: .6rem; }
.grupy-extra > summary {
  cursor: pointer;
  list-style: none;
  font-size: .76rem; font-weight: 600;
  color: var(--brand-deep);
  padding: .45rem .55rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg);
  display: flex; align-items: center; gap: .4rem;
  transition: background .18s ease, border-color .18s ease;
}
.grupy-extra > summary::-webkit-details-marker { display: none; }
.grupy-extra > summary::before {
  content: "▸";
  font-size: .7rem;
  color: var(--brand);
  transition: transform .15s ease;
}
.grupy-extra[open] > summary::before { content: "▾"; }
.grupy-extra > summary:hover { background: #eef4f7; border-color: var(--brand); }
.grupy-extra-body {
  padding: .6rem .1rem .1rem;
  display: flex; flex-direction: column; gap: .55rem;
}
.grupy-extra-body .grupa {
  padding: .5rem .55rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.footer-inner {
  max-width: 1440px; margin: 0 auto;
  padding: .8rem 1.5rem;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
}
.footer-src { margin: 0; font-size: .74rem; color: var(--ink-soft); max-width: 62ch; }
.footer-links { display: flex; gap: .6rem; flex-wrap: wrap; }
.footer-links a {
  display: inline-flex; align-items: center; gap: .35rem;
  font-family: var(--mono);
  font-size: .76rem;
  color: var(--brand-deep);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .35rem .55rem;
  transition: background .18s ease, border-color .18s ease;
}
.footer-links a:hover { background: var(--bg); border-color: var(--brand); }

/* ---------- Focus / a11y ---------- */
a:focus-visible, button:focus-visible, input:focus-visible, summary:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
.leaflet-interactive:focus-visible { outline: 3px solid var(--accent); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  #layout { flex-direction: column; padding: .75rem; }
  .map-wrap { flex: none; height: 55vh; min-height: 340px; }
  #panel { flex: none; width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}

/* ================= Nawigacja widoków ================= */
.header-right { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; }
.view-tabs {
  display: inline-flex;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 999px;
  padding: 2px;
}
.view-tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: #bfe0e8;
  font: inherit;
  font-size: .82rem;
  padding: .35rem .95rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.view-tab:hover { color: #fff; }
.view-tab.is-active { background: var(--accent); color: #1a1204; font-weight: 600; }
.view-tab:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* ================= Widok analityki ================= */
#analityka-view {
  flex: 1 1 auto;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.4rem 1.5rem 2rem;
}
.anl-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.2rem;
}
.anl-title { margin: 0; font-size: 1.4rem; letter-spacing: -.01em; }
.anl-sub { margin: .25rem 0 0; color: var(--ink-soft); font-size: .86rem; max-width: 46ch; }
.anl-picker { display: flex; flex-direction: column; gap: .25rem; }
.anl-picker label { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); }
#op-select, .abon-okres-sel {
  font: inherit;
  padding: .4rem .6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  min-width: 220px;
}
.abon-okres-sel { min-width: auto; padding: .2rem .4rem; font-size: .78rem; margin-left: .5rem; }

.anl-op-head {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.1rem;
  position: relative;
}
.anl-op-head h3 { margin: 0; font-size: 1.15rem; }
.anl-op-meta { margin-top: .3rem; font-size: .78rem; color: var(--ink-soft); }
.btn-csv {
  position: absolute; top: 1rem; right: 1.1rem;
  display: inline-flex; align-items: center; gap: .35rem;
  font-size: .78rem; color: var(--brand);
  border: 1px solid var(--line); border-radius: 8px;
  padding: .35rem .7rem; text-decoration: none; background: var(--bg);
  transition: background .15s, border-color .15s;
}
.btn-csv:hover { background: #eef5f8; border-color: var(--brand); }

.anl-section { margin-bottom: 1.4rem; }
.anl-hint { margin: .1rem 0 .7rem; font-size: .78rem; color: var(--ink-soft); max-width: 62ch; }

/* Dynamika — karty */
.dyn-grid { display: flex; gap: .8rem; flex-wrap: wrap; }
.dyn-card {
  flex: 1 1 220px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .85rem 1rem;
  box-shadow: var(--shadow);
}
.dyn-okres { font-size: .78rem; color: var(--ink-soft); font-family: var(--mono); margin-bottom: .55rem; }
.dyn-rows > div { display: flex; justify-content: space-between; align-items: baseline; padding: .2rem 0; border-top: 1px dashed var(--line); }
.dyn-rows > div:first-child { border-top: 0; }
.dyn-lbl { font-size: .82rem; color: var(--ink-soft); }
.dyn-up { color: #c0392b; font-weight: 700; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.dyn-down { color: #1e7d4f; font-weight: 700; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.dyn-flat, .dyn-na { color: var(--ink-soft); font-family: var(--mono); }

/* Tabela profilu */
.anl-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.anl-table { width: 100%; border-collapse: collapse; font-size: .84rem; }
.anl-table th, .anl-table td { padding: .55rem .7rem; text-align: right; white-space: nowrap; }
.anl-table th:first-child, .anl-table td:first-child { text-align: left; }
.anl-table thead th {
  background: #eef4f7; color: var(--ink-soft);
  font-weight: 600; font-size: .74rem; text-transform: uppercase; letter-spacing: .03em;
  border-bottom: 1px solid var(--line);
}
.anl-table tbody tr:nth-child(even) { background: #f8fbfc; }
.anl-table td.num, .anl-table td.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* Wykres abonamentów — poziome słupki */
#abon-chart { display: flex; flex-direction: column; gap: .3rem; max-width: 640px; }
.abon-row { display: grid; grid-template-columns: 5.5rem 1fr 2rem; align-items: center; gap: .6rem; }
.abon-stawka { font-size: .8rem; text-align: right; color: var(--ink); }
.abon-bar { height: 16px; background: #eef4f7; border-radius: 4px; overflow: hidden; }
.abon-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--c3), var(--c5)); border-radius: 4px; }
.abon-count { font-size: .78rem; color: var(--ink-soft); text-align: right; }

.anl-empty { padding: 3rem 1rem; }

@media (max-width: 640px) {
  .anl-head { flex-direction: column; align-items: stretch; }
  .btn-csv { position: static; margin-top: .7rem; display: inline-flex; }
  .anl-op-head { padding-bottom: .8rem; }
}
