:root {
  --ink: #17202a;
  --muted: #66727f;
  --paper: #f4f1ea;
  --panel: #fffdf8;
  --line: #ddd8cc;
  --navy: #16324a;
  --navy-2: #234d68;
  --coral: #e65f45;
  --green: #2c735e;
  --amber: #9a6517;
  --red: #a83a35;
  --shadow: 0 14px 40px rgba(23, 32, 42, .14);
  --radius: 12px;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid rgba(230, 95, 69, .26);
  outline-offset: 2px;
}

.topbar {
  height: 70px;
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 0 24px;
  color: #fff;
  background: var(--navy);
  border-bottom: 1px solid rgba(255,255,255,.14);
  position: relative;
  z-index: 1100;
}
.brand { display: flex; gap: 11px; align-items: center; color: inherit; text-decoration: none; }
.brand-mark {
  width: 38px; height: 38px; display: grid; place-items: center;
  border: 1px solid rgba(255,255,255,.48); border-radius: 4px;
  font-weight: 800; letter-spacing: -.06em;
}
.brand strong { display: block; font-size: 18px; letter-spacing: -.02em; }
.brand small { display: block; color: #b9c8d2; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.coverage {
  display: flex; align-items: center; gap: 12px; margin-left: auto;
  color: #c7d4dc; font-size: 13px;
}
.coverage b { color: #fff; font-size: 15px; }
.coverage .divider { width: 1px; height: 24px; background: rgba(255,255,255,.2); }

.button {
  border: 0; border-radius: 6px; padding: 10px 15px;
  font-weight: 700; background: var(--coral); color: #fff;
}
.button:hover { background: #cf5039; }
.button.secondary { background: transparent; border: 1px solid rgba(255,255,255,.36); }
.button.secondary:hover { background: rgba(255,255,255,.1); }
.button.compact { padding: 8px 13px; }
.icon-button { min-width: 44px; min-height: 44px; border: 0; background: transparent; color: inherit; font-size: 24px; padding: 4px; cursor: pointer; }
.mobile-only { display: none; }

.workspace { height: calc(100% - 70px); display: grid; grid-template-columns: 390px minmax(0, 1fr); }
.sidebar {
  min-height: 0; overflow-y: auto; background: var(--panel);
  border-right: 1px solid var(--line); padding: 22px 22px 30px;
  position: relative; z-index: 1000;
}
.panel-head, .municipality-heading, .section-title { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.eyebrow { margin: 0 0 4px; color: var(--coral); text-transform: uppercase; letter-spacing: .1em; font-size: 11px; font-weight: 800; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 18px; font-family: Georgia, serif; font-size: 27px; font-weight: 600; letter-spacing: -.03em; }
h2 { margin-bottom: 4px; font-family: Georgia, serif; font-size: 24px; }
h3 { margin: 0; font-size: 14px; }
label { display: block; margin-bottom: 7px; font-size: 12px; color: var(--muted); font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }

.search-field { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 0 11px; background: #fff; }
.search-field:focus-within { border-color: var(--coral); box-shadow: 0 0 0 3px rgba(230,95,69,.1); }
.search-field input { width: 100%; border: 0; outline: 0; padding: 11px 0; background: transparent; }
.region-tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin: 10px 0; }
.region-tab { border: 0; border-bottom: 2px solid transparent; padding: 8px 2px; background: transparent; color: var(--muted); font-size: 11px; }
.region-tab small { display: block; margin-top: 2px; font-size: 10px; }
.region-tab.active { color: var(--navy); border-color: var(--coral); font-weight: 800; }

.municipality-results { max-height: 236px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.municipality-results:empty { display: none; }
.municipality-result {
  width: 100%; display: flex; justify-content: space-between; align-items: center;
  padding: 9px 11px; border: 0; border-bottom: 1px solid #eeeae2; background: transparent; text-align: left;
}
.municipality-result:last-child { border-bottom: 0; }
.municipality-result:hover, .municipality-result.selected { background: #f4eee4; }
.municipality-result strong { font-size: 13px; }
.municipality-result small { color: var(--muted); font-size: 10px; }
.coverage-dot { width: 8px; height: 8px; border-radius: 50%; background: #aeb5b8; flex: 0 0 auto; }
.coverage-dot.available { background: var(--green); }
.coverage-dot.catalogue { background: var(--amber); }

.location-block { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.inline-form { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 7px; }
.inline-form input, .filter-input, select {
  min-width: 0; border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; background: #fff; color: var(--ink);
}
.hint { margin: 6px 0 0; color: var(--muted); font-size: 10px; line-height: 1.45; }

.selection-panel { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--line); }
.empty-state { padding: 28px 16px; text-align: center; color: var(--muted); }
.empty-state h2 { color: var(--ink); font-size: 19px; }
.empty-state p { margin: 0; font-size: 12px; line-height: 1.55; }
.empty-symbol { display: block; margin-bottom: 10px; color: var(--coral); font-size: 30px; }
.status-badge { align-self: center; border-radius: 999px; padding: 5px 8px; font-size: 10px; font-weight: 800; white-space: nowrap; }
.status-badge.map_available { color: #1e5b49; background: #dceee8; }
.status-badge.catalogue_only { color: #7b4d0c; background: #f3e7cc; }
.status-badge.regional_adapter_pending { color: #6c3d39; background: #f4dedb; }
.municipality-meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin: 14px 0 20px; }
.municipality-meta div { padding: 9px; border: 1px solid var(--line); border-radius: 7px; }
.municipality-meta dt { color: var(--muted); font-size: 9px; text-transform: uppercase; }
.municipality-meta dd { margin: 3px 0 0; font-size: 12px; font-weight: 800; }
.section-title { align-items: center; margin: 14px 0 8px; }
.section-title span { color: var(--muted); font-size: 11px; }

.source-list { display: grid; gap: 7px; }
.source-card { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: #fff; text-align: left; }
.source-card:hover { border-color: #9aa8b1; }
.source-card.active { border-color: var(--navy-2); box-shadow: inset 3px 0 var(--navy-2); }
.source-card:disabled { cursor: default; color: inherit; opacity: .72; }
.source-card strong { display: block; font-size: 12px; line-height: 1.35; }
.source-card small { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }
.legal-chip { display: inline-block; margin-bottom: 5px; padding: 3px 6px; border-radius: 3px; color: #fff; background: var(--green); font-size: 8px; text-transform: uppercase; letter-spacing: .08em; }
.legal-chip.consultation { background: var(--amber); }
.legal-chip.official { background: var(--navy-2); }

#service-section { margin-top: 14px; }
#service-section select { width: 100%; }
.layer-title { margin-top: 18px; }
.filter-input { width: 100%; margin-bottom: 7px; }
.layer-state { color: var(--muted); font-size: 11px; padding: 9px 0; }
.layer-state.error { color: var(--red); }
.layer-list { max-height: 280px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.layer-row { display: grid; grid-template-columns: auto minmax(0,1fr); gap: 8px; align-items: start; padding: 9px 10px; border-bottom: 1px solid #eeeae2; }
.layer-row:last-child { border-bottom: 0; }
.layer-row input { margin-top: 2px; accent-color: var(--coral); }
.layer-row label { margin: 0; color: var(--ink); font-size: 11px; line-height: 1.35; text-transform: none; letter-spacing: 0; cursor: pointer; }
.layer-row small { display: block; color: var(--muted); font-weight: 400; }
.opacity-control { margin-top: 14px; }
.opacity-control div { display: flex; justify-content: space-between; }
.opacity-control output { font-size: 11px; color: var(--muted); }
.opacity-control input { width: 100%; accent-color: var(--coral); }
.source-note { margin-top: 14px; padding: 10px 11px; border-left: 3px solid var(--amber); background: #f7f0df; color: #5f4a24; font-size: 10px; line-height: 1.5; }

.map-shell { min-width: 0; position: relative; background: #d7ddd8; }
#map { width: 100%; height: 100%; z-index: 1; }
.map-toolbar {
  position: absolute; z-index: 500; top: 14px; right: 14px;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; max-width: 360px; padding: 8px 9px;
  border: 1px solid rgba(23,32,42,.16); border-radius: 8px; background: rgba(255,253,248,.96); box-shadow: var(--shadow);
}
.map-toolbar label { margin: 0; }
.map-toolbar select { padding: 6px 8px; }
.toolbar-group { display: flex; align-items: center; gap: 8px; }
.context-toggles { display: flex; align-items: center; gap: 8px; margin: 0; padding: 0 0 0 8px; border: 0; border-left: 1px solid var(--line); }
.context-toggles legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.context-toggles label { display: flex; align-items: center; gap: 3px; color: var(--ink); font-size: 10px; letter-spacing: .05em; }
.context-toggles input { accent-color: var(--coral); }
#context-note { flex-basis: 100%; max-width: 330px; color: var(--muted); font-size: 9px; line-height: 1.35; }
.crus-legend {
  position: absolute; z-index: 500; left: 10px; bottom: 50px; width: min(280px, calc(100% - 20px));
  padding: 8px 10px; border: 1px solid rgba(23,32,42,.16); border-radius: 8px;
  background: rgba(255,253,248,.96); box-shadow: var(--shadow); color: var(--ink); font-size: 10px;
}
.crus-legend summary { cursor: pointer; font-weight: 700; }
.crus-legend-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px 9px; margin: 8px 0; }
.crus-legend-grid span { display: flex; align-items: center; gap: 5px; }
.crus-legend-grid i { width: 14px; height: 11px; flex: 0 0 auto; border: 1px solid #808080; background: var(--swatch); }
.crus-legend small { color: var(--muted); line-height: 1.3; }
.map-status {
  position: absolute; z-index: 500; left: 50%; bottom: 32px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px; max-width: min(620px, 80%); padding: 9px 13px;
  border-radius: 6px; color: #fff; background: rgba(22,50,74,.92); box-shadow: var(--shadow); font-size: 11px;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #d5e8df; }
.map-status.loading .status-dot { background: #f5be55; animation: pulse 1s infinite; }
.map-status.error .status-dot { background: #f27f70; }
@keyframes pulse { 50% { opacity: .35; } }
.map-caveat { position: absolute; z-index: 500; right: 9px; bottom: 22px; padding: 3px 6px; background: rgba(255,253,248,.84); color: #4d5961; font-size: 9px; }
.toast { position: fixed; z-index: 2000; right: 20px; top: 82px; padding: 10px 14px; border-radius: 6px; color: #fff; background: var(--navy); box-shadow: var(--shadow); font-size: 12px; opacity: 0; pointer-events: none; transform: translateY(-8px); transition: .18s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.leaflet-control-attribution { font-size: 9px; }

@media (max-width: 760px) {
  .mobile-only { display: inline-grid; place-items: center; }
  .topbar { height: 60px; padding: 0 12px; gap: 10px; }
  .brand small, .coverage { display: none; }
  .topbar .button.secondary { margin-left: auto; padding: 8px 10px; font-size: 11px; }
  .brand-mark { width: 34px; height: 34px; }
  .workspace { height: calc(100% - 60px); display: block; }
  .sidebar {
    position: fixed; z-index: 1200; top: 60px; bottom: 0; left: 0; width: min(92vw, 390px);
    transform: translateX(-103%); transition: transform .22s ease; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .map-shell { width: 100%; height: 100%; }
  .map-toolbar { top: 10px; right: 10px; left: 54px; width: auto; max-width: none; }
  .map-toolbar > .toolbar-group > label {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
  }
  .context-toggles label { display: flex; }
  .crus-legend { bottom: 100px; width: min(250px, calc(100% - 20px)); }
  .map-status { bottom: 50px; max-width: calc(100% - 28px); width: max-content; }
  .map-caveat { bottom: 22px; max-width: calc(100% - 70px); text-align: right; }
  .region-tabs { grid-template-columns: repeat(2, 1fr); }
}
