:root {
  --bg: #eef3f5;
  --surface: #ffffff;
  --surface-2: #f7fafb;
  --ink: #132027;
  --muted: #60717b;
  --line: #d9e3e7;
  --teal: #007d7a;
  --teal-dark: #075b5c;
  --gold: #d99a22;
  --danger: #c24a3a;
  --shadow: 0 18px 55px rgba(19, 32, 39, .12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 24px;
  background: #0f2f35;
  color: #fff;
  border-bottom: 4px solid var(--gold);
}

.agency {
  margin: 0 0 5px;
  color: #b7d7d8;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(24px, 3vw, 38px);
  line-height: 1.05;
  letter-spacing: 0;
}

.topbar__meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  max-width: 520px;
}

.topbar__meta span {
  border: 1px solid rgba(255, 255, 255, .2);
  border-radius: 999px;
  padding: 7px 10px;
  color: #e8f5f4;
  font-size: 12px;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(560px, 1fr) 420px;
  gap: 18px;
  padding: 18px;
  align-items: start;
  min-height: 0;
}

.map-panel,
.side-panel {
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.map-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  order: 0;
  position: sticky;
  top: 18px;
  align-self: start;
  height: calc(100vh - 36px);
  min-height: min(560px, calc(100vh - 36px));
  max-height: calc(100vh - 36px);
  overflow: hidden;
}

.side-panel {
  order: 1;
}

.map-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}

.metric {
  display: grid;
  gap: 2px;
  min-width: 145px;
}

.metric strong {
  color: var(--teal-dark);
  font-size: 24px;
  line-height: 1;
}

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

.ghost-button {
  margin-left: auto;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--teal-dark);
  border-radius: 6px;
  min-height: 36px;
  padding: 0 12px;
  font-weight: 700;
  cursor: pointer;
}

.ghost-button:hover {
  border-color: var(--teal);
  color: var(--teal);
}

.map-canvas {
  position: relative;
  min-height: 0;
  height: 100%;
  display: grid;
  place-items: start center;
  padding: 8px;
  overflow: auto;
  overscroll-behavior: contain;
  background:
    linear-gradient(#dfeaec 1px, transparent 1px),
    linear-gradient(90deg, #dfeaec 1px, transparent 1px),
    #edf5f5;
  background-size: 32px 32px;
}

.map-tooltip {
  position: absolute;
  z-index: 5;
  left: 0;
  top: 0;
  transform: translate(12px, -110%);
  display: none;
  pointer-events: none;
  border: 1px solid rgba(15, 47, 53, .18);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  box-shadow: 0 10px 30px rgba(19, 32, 39, .18);
  padding: 7px 9px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.map-tooltip.is-visible {
  display: block;
}

.regional-map {
  display: block;
  width: max(100%, 720px);
  height: auto;
  min-height: 0;
  aspect-ratio: 486 / 478;
  flex: 0 0 auto;
}

.municipality {
  stroke: #ffffff;
  stroke-width: 2;
  cursor: pointer;
  transition: opacity .18s ease, filter .18s ease, stroke-width .18s ease;
}

.municipality:focus-visible,
.municipality-count:focus-visible {
  outline: none;
}

.municipality:focus-visible {
  stroke: #0f2f35;
  stroke-width: 3.4;
}

.municipality:hover,
.municipality.is-active {
  filter: brightness(1.04) saturate(1.08);
  stroke: #0f2f35;
  stroke-width: 2.8;
}

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

.map-label {
  pointer-events: none;
  fill: #183137;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, .86);
  stroke-width: 3px;
  stroke-linejoin: round;
}

.map-label--small {
  font-size: 8.6px;
  stroke-width: 2.6px;
}

.map-label--tiny {
  font-size: 7.4px;
  stroke-width: 2.2px;
}

.school-marker {
  cursor: pointer;
  opacity: .78;
  stroke: #fff;
  stroke-width: .55;
  transition: r .15s ease, opacity .15s ease, transform .15s ease;
}

.school-marker:hover,
.school-marker.is-selected {
  opacity: 1;
  r: 4.8;
  stroke: #102a30;
  stroke-width: 1.1;
}

.school-marker.is-dim {
  opacity: .13;
  pointer-events: none;
}

.municipality-count {
  cursor: pointer;
}

.municipality-count circle {
  fill: #ffffff;
  stroke: #0f2f35;
  stroke-width: 1.4;
  filter: drop-shadow(0 4px 10px rgba(19, 32, 39, .22));
}

.municipality-count text {
  pointer-events: none;
  fill: #0f2f35;
  font-size: 10px;
  font-weight: 900;
}

.municipality-count:focus-visible circle {
  fill: #e7f4f2;
  stroke: var(--teal);
  stroke-width: 2.2;
}

.municipality-count:hover circle {
  fill: #e7f4f2;
  stroke: var(--teal);
}

.side-panel {
  display: grid;
  grid-template-rows: auto auto auto auto 1fr;
  gap: 14px;
  padding: 16px;
  overflow: hidden;
}

.search-block,
.filter-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 11px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(0, 125, 122, .13);
}

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

.filter-grid label:first-child {
  grid-column: 1 / -1;
}

.level-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.level-tab {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.level-tab.is-active {
  border-color: var(--teal);
  background: #e7f4f2;
  color: var(--teal-dark);
}

.detail-panel {
  min-height: 130px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 14px;
}

.empty-state {
  color: var(--muted);
  font-size: 14px;
}

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

.detail-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.detail-meta span {
  display: grid;
  gap: 2px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.detail-meta strong {
  color: var(--ink);
  font-size: 13px;
  text-transform: none;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  border-radius: 999px;
  padding: 5px 8px;
  background: #e8f4f3;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
}

.list-section {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
}

.list-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.list-header h2 {
  margin: 0;
  font-size: 18px;
}

#resultCount {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.school-list {
  min-height: 0;
  overflow: auto;
  border-top: 1px solid var(--line);
}

.school-row {
  width: 100%;
  display: grid;
  grid-template-columns: 10px 1fr;
  gap: 10px;
  padding: 11px 4px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.school-row:hover,
.school-row.is-selected {
  background: #f0f8f7;
}

.school-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 4px;
}

.school-row strong {
  display: block;
  margin-bottom: 3px;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.25;
}

.school-row span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.sourcebar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 10px 18px;
  background: #ffffff;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 1080px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .map-panel {
    position: static;
    top: auto;
    height: auto;
    min-height: 0;
    max-height: none;
  }

  .side-panel {
    min-height: 720px;
  }

  .regional-map {
    max-height: none;
  }
}

@media (max-width: 720px) {
  .topbar,
  .sourcebar {
    flex-direction: column;
    align-items: flex-start;
  }

  .workspace {
    padding: 10px;
  }

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

  .map-toolbar {
    display: grid;
  }

  .ghost-button {
    margin-left: 0;
  }

  .regional-map {
    min-height: 0;
  }

  .map-canvas {
    min-height: clamp(360px, 68vh, 560px);
    height: clamp(360px, 68vh, 560px);
  }

  .regional-map {
    width: max(100%, 560px);
  }
}
