:root {
  --paper: #f4efe6;
  --paper-2: #fffdf8;
  --ink: #1d1914;
  --muted: #6f675d;
  --line: #e3d7c6;
  --gap: #b42318;
  --gap-fill: #e11d2e;
  --header: #1d1914;
  --shadow: 0 18px 50px rgba(48, 32, 14, 0.16);
  --sans: "Outfit", "Avenir Next", "Segoe UI", sans-serif;
  --serif: "Fraunces", "Iowan Old Style", Georgia, serif;
  --panel: 408px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
}

button, input, select { font: inherit; color: inherit; }

button { cursor: pointer; }

.app {
  height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 22px;
  background: var(--header);
  color: #f7f1e6;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.mark {
  width: 18px;
  height: 18px;
  border: 2px solid #e7c27a;
  border-radius: 50%;
  box-shadow: inset 0 0 0 4px #1d1914, inset 0 0 0 6px #e7c27a;
  flex: none;
}

.eyebrow {
  margin: 0 0 2px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #e7c27a;
}

.topbar h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 560;
  letter-spacing: -0.03em;
}

.topbar-note {
  margin: 0;
  max-width: 280px;
  text-align: right;
  color: #d9cbb8;
  font-size: 13px;
}

.workspace {
  display: grid;
  grid-template-columns: var(--panel) minmax(0, 1fr);
  min-height: 0;
}

.panel {
  overflow: auto;
  padding: 18px 18px 32px;
  background: var(--paper);
  border-right: 1px solid var(--line);
}

.stats {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 8px;
}

.stat {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 12px 10px;
}

.stat strong {
  display: block;
  font-family: var(--serif);
  font-size: 30px;
  line-height: 1;
  letter-spacing: -0.04em;
}

.stat span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.stat.is-gap {
  background: #fff6f3;
  border-color: #f0c2b8;
}

.stat.is-gap strong { color: var(--gap); }

.method {
  margin: 14px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.45;
}

.method summary {
  cursor: pointer;
  color: var(--ink);
  font-weight: 600;
}

.method p { margin: 8px 0 0; }

.sources { font-size: 12px; }

.search {
  display: grid;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.search input, .row-controls select {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--paper-2);
  border-radius: 10px;
  padding: 10px 12px;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
  font-size: 15px;
  color: var(--ink);
}

.search input:focus, .row-controls select:focus, button:focus-visible {
  outline: 2px solid #1d4e89;
  outline-offset: 2px;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0;
}

.radius {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  padding: 12px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.radius span {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  font-weight: 650;
}

.radius strong {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 560;
}

.radius input {
  width: 100%;
  accent-color: #1d1914;
}

.radius small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.filters button, .map-tools button, .text-btn, .detail button.ghost {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 600;
}

.filters button.is-on, .map-tools button.is-on {
  background: var(--ink);
  color: #f7f1e6;
  border-color: var(--ink);
}

.row-controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 16px;
}

.row-controls label, .check {
  display: grid;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.check {
  grid-auto-flow: column;
  align-items: center;
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
  font-weight: 500;
  padding-bottom: 8px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin: 8px 0;
}

.section-head h2 {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.text-btn {
  padding: 4px 8px;
  color: #1d4e89;
  border-color: transparent;
}

.churches { display: grid; gap: 8px; }

.church {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: start;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--paper-2);
  border-radius: 14px;
  padding: 10px;
}

.church.is-focus {
  border-color: var(--c);
  box-shadow: inset 3px 0 0 var(--c);
}

.church.is-off { opacity: 0.55; }

.swatch {
  width: 12px;
  height: 12px;
  margin-top: 4px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 18%, white);
}

.church h3 {
  margin: 0;
  font-size: 15px;
}

.church p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.35;
}

.church .actions {
  display: grid;
  gap: 4px;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 14px;
}

.icon-btn[aria-pressed="false"] {
  background: #f1ebe3;
  color: var(--muted);
}

.note {
  margin-top: 6px;
  color: #7a4b12;
  font-size: 12px;
  line-height: 1.35;
}

.list-lead {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
}

.groups details {
  border-top: 1px solid var(--line);
  padding: 6px 0;
}

.groups summary {
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-weight: 650;
  font-size: 14px;
  padding: 6px 0;
}

.groups summary em {
  font-style: normal;
  color: var(--muted);
  font-weight: 500;
}

.barrio {
  display: grid;
  grid-template-columns: 10px 1fr;
  gap: 8px;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 10px;
  padding: 7px 6px;
}

.barrio:hover, .barrio.is-on { background: rgba(255, 255, 255, 0.8); }

.barrio i {
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--c, var(--gap));
}

.barrio strong { display: block; font-size: 14px; font-weight: 600; }

.barrio small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

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

.map-wrap { position: relative; min-height: 0; }

#map { height: 100%; width: 100%; background: #d5dde4; }

.focus-banner, .map-tools, .legend, .detail, .busy {
  position: absolute;
  z-index: 800;
}

.focus-banner {
  top: 12px;
  left: 58px;
  right: 390px;
  width: auto;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  background: var(--paper-2);
  border-radius: 14px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
}

.focus-banner p { margin: 0; font-size: 14px; }

.map-tools {
  top: 12px;
  right: 12px;
  display: flex;
  gap: 6px;
  background: rgba(255, 253, 248, 0.92);
  padding: 6px;
  border-radius: 999px;
  box-shadow: var(--shadow);
}

body:has(#detail:not([hidden])) .legend { visibility: hidden; }

.legend {
  left: 12px;
  bottom: 12px;
  width: min(280px, calc(100% - 24px));
  background: rgba(255, 253, 248, 0.94);
  border-radius: 14px;
  padding: 12px;
  box-shadow: var(--shadow);
  font-size: 12.5px;
}

.legend h2 {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.legend div {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 5px;
}

.legend i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex: none;
}

.legend i.line {
  border-radius: 2px;
  background: transparent;
  border: 2px dashed #1d1914;
}

.detail {
  right: 12px;
  bottom: 12px;
  width: min(360px, calc(100% - 24px));
  max-height: min(52vh, 460px);
  overflow: auto;
  background: var(--paper-2);
  border-radius: 16px;
  padding: 14px 14px 12px;
  box-shadow: var(--shadow);
}

.detail header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: start;
}

.detail h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 26px;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.kicker {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gap);
}

.kicker.is-ok { color: #0f7a4a; }

.meta {
  margin: 8px 0;
  color: var(--muted);
  font-size: 13px;
}

.cover-row { margin: 10px 0; }

.cover-row p {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 4px;
  font-size: 13px;
}

.bar {
  height: 7px;
  border-radius: 99px;
  background: #efe7db;
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  background: var(--c);
}

.detail .close {
  border: 0;
  background: #f1ebe3;
  width: 28px;
  height: 28px;
  border-radius: 50%;
}

.sede-flag {
  margin: 0 0 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #f3f7f2;
  font-size: 13px;
}

.busy {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--ink);
  color: white;
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 13px;
}

.boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--paper);
  z-index: 2000;
  font-family: var(--serif);
  font-size: 22px;
}

.boot.is-gone { display: none; }

.leaflet-container { font-family: var(--sans); }

.leaflet-container .leaflet-interactive:focus,
.leaflet-container .leaflet-interactive:focus-visible {
  outline: none;
}

.sede-icon { background: transparent; border: none; }

.sede-marker {
  display: flex;
  align-items: center;
  gap: 6px;
  width: max-content;
}

.sede-marker i {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--c);
  border: 2px solid white;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--c) 70%, black), 0 4px 10px rgba(0, 0, 0, 0.25);
  flex: none;
}

.sede-marker b {
  background: white;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.16);
  white-space: nowrap;
}

.sede-marker.is-off { opacity: 0.45; }
.sede-marker.is-dim { opacity: 0.4; }
.sede-marker.is-moved b { outline: 1px dashed #7a4b12; }

.tip {
  font-family: var(--sans);
  font-weight: 600;
}

.name-label {
  background: transparent;
  border: 0;
  font-size: 11px;
  font-weight: 700;
  color: #1d1914;
  text-shadow: 0 1px 0 white, 0 -1px 0 white, 1px 0 0 white, -1px 0 0 white;
}

@media (max-width: 860px) {
  .app { height: auto; min-height: 100vh; }
  .topbar { align-items: flex-start; flex-direction: column; gap: 6px; }
  .topbar h1 { font-size: 20px; }
  .topbar-note { text-align: left; max-width: none; }
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: 58vh auto;
  }
  .map-wrap { grid-row: 1; height: 58vh; }
  .panel { grid-row: 2; border-right: 0; border-top: 1px solid var(--line); }
  .map-tools {
    top: 12px;
    left: 54px;
    right: 8px;
    max-width: none;
    flex-wrap: wrap;
    justify-content: flex-end;
  }
  .focus-banner {
    left: 12px;
    right: 12px;
    top: auto;
    bottom: 64px;
    width: auto;
  }
  .legend { display: none; }
}
