:root {
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #1c2224;
  --muted: #667171;
  --line: #d9ded8;
  --line-strong: #b8c1bb;
  --teal-dark: #0f5f62;
  --teal: #2f897d;
  --teal-soft: #d8eee7;
  --rose: #b04c5a;
  --rose-soft: #f2d9dc;
  --amber: #c68b2e;
  --sand: #e9e3d5;
  --shadow: 0 14px 34px rgba(30, 42, 40, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

.app-header {
  display: grid;
  grid-template-columns: minmax(460px, 0.95fr) minmax(560px, 1.25fr);
  gap: 20px;
  padding: 22px 32px 14px;
  align-items: center;
}

.title-block h1 {
  margin: 0;
  max-width: 760px;
  font-size: clamp(25px, 2.4vw, 34px);
  line-height: 1.08;
  font-weight: 760;
}

.title-block p {
  margin: 8px 0 0;
  max-width: 760px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.kpi-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.kpi {
  min-height: 76px;
  padding: 13px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.kpi span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.kpi strong {
  display: block;
  margin-top: 7px;
  font-size: clamp(19px, 2vw, 28px);
  line-height: 1;
  font-weight: 780;
  white-space: nowrap;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(620px, 1fr) 360px;
  grid-template-areas:
    "map inspector"
    "analysis analysis";
  gap: 16px;
  padding: 0 32px 24px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.map-panel {
  grid-area: map;
  min-height: 640px;
}

.inspector {
  grid-area: inspector;
  min-height: 640px;
  display: flex;
  flex-direction: column;
}

.analysis-panel {
  grid-area: analysis;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--line);
}

.panel-heading.compact {
  display: block;
}

.panel-heading h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.panel-heading p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.control-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  align-content: start;
}

.segmented {
  display: inline-flex;
  height: 36px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f3f5f1;
}

.segmented button {
  min-width: 96px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 720;
  cursor: pointer;
}

.segmented button.is-active {
  background: var(--ink);
  color: #fff;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) 190px 180px minmax(260px, 1.35fr);
  gap: 12px;
  padding: 14px 20px 10px;
  align-items: end;
}

.search-field,
.select-field {
  display: grid;
  gap: 6px;
}

.search-field span,
.select-field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
  text-transform: uppercase;
}

.search-field input,
.select-field select {
  width: 100%;
  height: 38px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font-size: 14px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
  min-height: 38px;
  align-content: end;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
}

.legend-swatch {
  width: 17px;
  height: 10px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 2px;
}

.map-wrap {
  position: relative;
  padding: 0 16px 16px;
}

#mapSvg {
  width: 100%;
  height: auto;
  max-height: 620px;
  aspect-ratio: 1.45 / 1;
  display: block;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fafbf8;
}

.municipality {
  stroke: rgba(255, 255, 255, 0.84);
  stroke-width: 0.62;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
  transition: opacity 120ms ease, stroke-width 120ms ease;
}

.municipality.is-muted {
  opacity: 0.16;
}

.municipality.region-praha {
  stroke: rgba(28, 34, 36, 0.42);
  stroke-width: 0.85;
}

.municipality.is-selected {
  stroke: #111;
  stroke-width: 2.2;
}

.municipality:focus {
  outline: none;
  stroke: var(--amber);
  stroke-width: 2.4;
}

.prague-marker {
  fill: none;
  stroke: var(--amber);
  stroke-width: 3;
  vector-effect: non-scaling-stroke;
}

.prague-dot {
  fill: var(--amber);
}

.prague-label {
  fill: #6f4d16;
  font-size: 16px;
  font-weight: 760;
}

.tooltip {
  position: fixed;
  z-index: 10;
  max-width: 260px;
  padding: 10px 11px;
  background: rgba(28, 34, 36, 0.96);
  color: #fff;
  border-radius: var(--radius);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.24);
  pointer-events: none;
  font-size: 12px;
  line-height: 1.45;
}

.tooltip strong {
  display: block;
  margin-bottom: 3px;
  font-size: 13px;
}

.detail-body {
  padding: 18px 20px;
}

.detail-name {
  margin: 0;
  font-size: 28px;
  line-height: 1.04;
}

.detail-meta {
  margin: 8px 0 16px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.detail-stat {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfa;
}

.detail-stat span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
  text-transform: uppercase;
}

.detail-stat strong {
  display: block;
  margin-top: 8px;
  font-size: 23px;
  line-height: 1;
}

.detail-stat small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.top-list {
  margin-top: auto;
  padding: 0 20px 20px;
}

.top-list h3 {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--muted);
  text-transform: uppercase;
}

.top-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  width: 100%;
  margin: 0 0 7px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.top-row:hover,
.top-row.is-selected {
  border-color: var(--teal);
  background: var(--teal-soft);
}

.top-row strong {
  display: block;
  font-size: 13px;
}

.top-row span {
  color: var(--muted);
  font-size: 12px;
}

.top-row .value {
  align-self: center;
  color: var(--teal-dark);
  font-weight: 800;
}

.empty-state {
  margin: 0;
  padding: 12px 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.analysis-grid {
  display: grid;
  grid-template-columns: minmax(520px, 1fr) 360px;
  gap: 12px;
  padding: 16px 20px 20px;
}

.scatter-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfa;
  overflow: hidden;
}

#scatterSvg {
  display: block;
  width: 100%;
  height: 360px;
}

.axis,
.grid-line {
  stroke: #cbd2cd;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.grid-line {
  stroke-dasharray: 3 5;
}

.axis-label,
.tick-label {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.trend-line {
  stroke: var(--ink);
  stroke-width: 2.4;
  vector-effect: non-scaling-stroke;
}

.zero-line {
  stroke: #8d9792;
  stroke-width: 1;
  stroke-dasharray: 2 5;
  opacity: 0.55;
  vector-effect: non-scaling-stroke;
}

.scatter-point {
  opacity: 0.56;
  cursor: pointer;
  vector-effect: non-scaling-stroke;
}

.scatter-point.region-praha {
  opacity: 0.76;
  stroke: var(--ink);
  stroke-width: 1;
}

.scatter-point.is-positive {
  fill: var(--teal);
}

.scatter-point.is-negative {
  fill: var(--rose);
}

.scatter-point.is-zero {
  fill: var(--muted);
}

.scatter-point.is-selected {
  opacity: 1;
  stroke: var(--amber);
  stroke-width: 2.2;
}

.bands {
  display: grid;
  gap: 9px;
  align-content: start;
}

.bands-header {
  padding: 0 2px 3px;
}

.bands-header strong,
.bands-header span {
  display: block;
}

.bands-header strong {
  font-size: 13px;
}

.bands-header span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.band-row {
  display: grid;
  grid-template-columns: 62px minmax(36px, 1fr) minmax(154px, auto);
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.band-name {
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.band-track {
  height: 9px;
  border-radius: 999px;
  background: #edf0eb;
  overflow: hidden;
}

.band-fill {
  height: 100%;
  background: var(--teal);
}

.band-row.is-negative .band-fill {
  background: var(--rose);
}

.band-row.is-zero .band-fill {
  background: var(--muted);
}

.band-values {
  text-align: right;
}

.band-values strong,
.band-values small {
  display: block;
}

.band-values strong {
  font-size: 13px;
}

.band-values small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
  white-space: nowrap;
}

.source-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  padding: 0 32px 26px;
  color: var(--muted);
  font-size: 12px;
}

.source-footer a {
  color: var(--teal-dark);
  font-weight: 760;
  text-decoration: none;
}

.source-footer a:hover {
  text-decoration: underline;
}

@media (max-width: 1180px) {
  .app-header,
  .app-shell {
    grid-template-columns: 1fr;
  }

  .app-shell {
    grid-template-areas:
      "map"
      "inspector"
      "analysis";
  }

  .inspector {
    min-height: auto;
  }

  .analysis-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .app-header,
  .app-shell,
  .source-footer {
    padding-left: 14px;
    padding-right: 14px;
  }

  .kpi-strip {
    grid-template-columns: 1fr 1fr;
  }

  .toolbar {
    grid-template-columns: 1fr;
  }

  .legend {
    justify-content: flex-start;
  }

  .panel-heading {
    display: block;
  }

  .control-row {
    justify-content: flex-start;
    margin-top: 12px;
  }

  .segmented {
    width: 100%;
  }

  .segmented button {
    flex: 1;
    min-width: 0;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  #mapSvg {
    min-height: 0;
  }
}
