:root {
  --ink: #1c2430;
  --muted: #5c6b7a;
  --line: #d5dde6;
  --paper: rgba(255, 255, 255, 0.94);
  --accent: #0f6f6a;
}

* { box-sizing: border-box; }

html, body, #viewDiv {
  margin: 0;
  height: 100%;
  width: 100%;
  font-family: "Segoe UI", sans-serif;
  color: var(--ink);
}

.topbar {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 2;
  display: grid;
  grid-template-columns: 1fr minmax(280px, 440px) 1fr;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(20, 32, 48, 0.12);
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-self: start;
  min-width: 0;
}

.brand-logo {
  height: 36px;
  width: auto;
  max-width: 220px;
  object-fit: contain;
  flex: 0 0 auto;
  display: block;
}

.brand h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0;
  white-space: nowrap;
}

.help-btn {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
}

.stats {
  display: flex;
  align-items: stretch;
  justify-self: end;
  justify-content: flex-end;
  gap: 20px;
  margin: 0;
}

.stats p {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-width: 76px;
}

.stats b {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--ink);
}

.stats span {
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.stats .stat-fecha {
  font-size: 18px;
  letter-spacing: -0.02em;
}

.search {
  position: relative;
  grid-column: 2;
  width: 100%;
  min-width: 0;
  max-width: none;
}

.search input {
  width: 100%;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  font: inherit;
  font-size: 14px;
  background: #fff;
}

.search input:focus {
  outline: 2px solid rgba(15, 111, 106, 0.35);
  border-color: var(--accent);
}

.search-list {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(20, 32, 48, 0.14);
  max-height: min(480px, 60vh);
  overflow: auto;
}

.search-list button {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  font: inherit;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.search-list button:hover,
.search-list button.active {
  background: #e7f3f2;
}

.search-list small {
  display: block;
  color: var(--muted);
  margin-top: 2px;
}

#btnArea.is-active,
#btnArea.is-active:hover,
#btnStreet.is-active,
#btnStreet.is-active:hover {
  background: var(--accent);
  color: #fff;
}

.btn-street .pegman-icon {
  width: 18px;
  height: 18px;
  display: block;
}

body.street-mode .esri-view-surface {
  cursor: crosshair;
}

.view-toggle {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.area-panel {
  position: absolute;
  right: 12px;
  bottom: 28px;
  z-index: 2;
  width: 280px;
  padding: 12px 14px;
  background: var(--paper);
  border: 2px solid #ff6a00;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(20, 32, 48, 0.12);
}

.chat-panel {
  position: absolute;
  right: 12px;
  bottom: 28px;
  z-index: 3;
  width: min(380px, calc(100vw - 24px));
  max-height: min(72vh, 560px);
  display: flex;
  flex-direction: column;
  padding: 12px 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(20, 32, 48, 0.14);
}

.chat-panel[hidden] { display: none !important; }

.chat-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.chat-sub {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.35;
}

.chat-log {
  flex: 1 1 auto;
  min-height: 160px;
  max-height: 280px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 2px 8px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.chat-bubble {
  max-width: 92%;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.chat-bubble.user {
  align-self: flex-end;
  background: #e7f3f2;
  color: var(--ink);
}

.chat-bubble.bot {
  align-self: flex-start;
  background: #f4f6f8;
  color: var(--ink);
}

.chat-bubble.bot strong {
  font-weight: 650;
}

.chat-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 8px;
}

.chat-chip {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 5px 10px;
  font: inherit;
  font-size: 11px;
  line-height: 1.3;
  cursor: pointer;
  text-align: left;
}

.chat-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.chat-form input {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  font: inherit;
  font-size: 13px;
}

.chat-form input:focus {
  outline: 2px solid rgba(15, 111, 106, 0.25);
  border-color: var(--accent);
}

.chat-send {
  height: 36px;
  padding: 0 12px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.chat-send:hover { filter: brightness(1.05); }

.btn-chat.is-active {
  color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.area-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.area-actions {
  display: flex;
  gap: 6px;
}

.area-clear {
  height: 28px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.area-clear:hover { border-color: var(--accent); color: var(--accent); }

.area-panel dl {
  margin: 8px 0 0;
}

.area-panel dl div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  border-top: 1px solid var(--line);
}

.area-panel dt {
  font-size: 13px;
  color: var(--muted);
}

.area-panel dd {
  margin: 0;
  font-size: 18px;
  font-weight: 650;
}

.legend {
  position: absolute;
  left: 12px;
  bottom: 40px;
  z-index: 2;
  width: 230px;
  padding: 12px 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(20, 32, 48, 0.12);
}

.legend-title {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 650;
}

.legend ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
  font-size: 13px;
}

.legend li { display: flex; align-items: center; gap: 6px; }

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.s1 { background: #3b82f6; }
.s2 { background: #14b8a6; }
.s3 { background: #eab308; }
.s4 { background: #f97316; }
.s5 { background: #ef4444; }
.sblock { background: #0f6f6a; width: 14px; height: 14px; border-radius: 0; }
.sinc {
  background: #c2410c;
  width: 9px;
  height: 9px;
  border-radius: 1px;
  transform: rotate(45deg);
}

.legend-block {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 8px 0 0;
  font-size: 13px;
}

.hint {
  margin: 10px 0 0;
  font-size: 12px;
  line-height: 1.35;
  color: var(--muted);
}

.loading {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(244, 247, 250, 0.82);
}

.loading p { margin: 0; font-size: 15px; }

.loading.hidden { display: none; }

.popup-card .catastro-extra {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #9aabba;
}
.popup-card .popup-link {
  display: block;
  margin-top: 12px;
}
.floors {
  margin: 0;
  padding: 0;
  border: 0;
  max-height: none;
  overflow: visible;
}
.floors details,
.floors .floor-group { border-bottom: 1px solid #eef2f6; }
.floors details[open] > .floor-dwellings {
  max-height: var(--floor-open-max, min(32vh, 260px));
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  margin: 0 0 6px;
  padding: 0 0 0 10px;
  border-left: 2px solid #d7e3ec;
}
.floors summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 7px 0;
  cursor: pointer;
  list-style: none;
  font-size: 13px;
}
.floors summary::-webkit-details-marker { display: none; }
.floors summary::marker { content: ""; }
.floors summary .floor-label { color: var(--ink); font-weight: 650; }
.floors summary .floor-label::before { content: "▸ "; color: #5c6b7a; font-weight: 500; }
.floors details[open] summary .floor-label::before { content: "▾ "; }
.floors summary .floor-meta { color: var(--muted); font-size: 12px; white-space: nowrap; text-align: right; }
.floors summary .floor-meta b { color: var(--ink); font-weight: 650; font-size: 12px; }
.floors ul,
.floors .floor-dwellings { list-style: none; margin: 0 0 6px; padding: 0 0 0 14px; }
.floors li {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 0;
  font-size: 12px;
  border-bottom: 1px solid #f1f5f9;
}
.floors li:last-child { border-bottom: 0; }
.floors li .floor-main {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 4px 10px;
}
.floors li .floor-ref { flex: 1 1 auto; word-break: break-word; }
.floors li .portal-tag {
  font-style: normal;
  font-weight: 700;
  color: var(--accent);
}
.floors li .floor-res { color: var(--ink); font-weight: 650; white-space: nowrap; }
.floors li .floor-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  width: 100%;
}
.floors li .floor-chips .chip {
  font-size: 11px;
  padding: 2px 7px;
}
/* Botonera compacta por vivienda (no pantallas enteras) */
.floors li .floor-actions,
.breakdown .floor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  width: 100%;
}
.floors li .floor-actions .btn-padron,
.floors li .floor-actions .btn-catastro,
.breakdown .floor-actions .btn-padron,
.breakdown .floor-actions .btn-catastro,
.floors li .floor-actions .btn-padron-sm,
.floors li .floor-actions .btn-catastro-sm {
  width: auto;
  flex: 1 1 calc(50% - 4px);
  min-width: 0;
  height: 26px;
  font-size: 11px;
  font-weight: 650;
  border-radius: 7px;
  margin: 0;
  padding: 0 8px;
}
.floors .catastro-link,
.popup-card .catastro-link {
  color: #1d4ed8;
  font-weight: 650;
  text-decoration: none;
  white-space: nowrap;
}
.floors .catastro-link:hover,
.popup-card .catastro-link:hover { text-decoration: underline; }
.popup-card h2 { margin: 0 0 8px; font-size: 14px; }
.popup-card p { margin: 0 0 4px; display: flex; justify-content: space-between; gap: 16px; }
.popup-card span { color: var(--muted); }
.popup-note { margin-top: 8px !important; display: block !important; color: var(--muted); font-size: 12px; }
.popup-note.incidencia { color: #9a3412; font-weight: 650; margin-top: 0 !important; margin-bottom: 8px; }
.popup-card .breakdown-title {
  display: block !important;
  margin: 10px 0 0 !important;
  font-size: 12px;
  font-weight: 650;
  color: var(--ink);
}
.breakdown {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  max-height: 220px;
  overflow: auto;
  border-top: 1px solid var(--line);
}
.breakdown li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 0;
  font-size: 12px;
  border-bottom: 1px solid #eef2f6;
}
.breakdown span { color: var(--muted); }

.esri-ui-top-right { top: 72px; }
.esri-popup__main-container {
  border-radius: 10px;
  width: min(300px, calc(100vw - 24px));
  min-width: 260px;
  max-width: min(420px, calc(100vw - 16px));
  min-height: 180px;
  max-height: min(78vh, 720px);
  overflow: hidden;
  resize: none;
  display: flex !important;
  flex-direction: column !important;
  position: relative;
}
.esri-popup__header {
  flex: 0 0 auto !important;
  position: relative;
  z-index: 5;
  min-height: 40px;
  background: #fff;
}
.esri-popup__header-container,
.esri-popup__button {
  z-index: 6;
}
.esri-popup__content {
  flex: 1 1 auto !important;
  max-height: min(68vh, 600px) !important;
  min-height: 0 !important;
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
}

.esri-view .esri-popup {
  z-index: 4;
}

/* Asa inferior: estirar el emergente hacia abajo (no hacia arriba). */
.popup-resize-handle {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 16px;
  z-index: 2;
  cursor: ns-resize;
  touch-action: none;
  background: linear-gradient(to top, rgba(15, 111, 106, 0.08), transparent);
}
.popup-resize-handle::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 5px;
  width: 36px;
  height: 4px;
  margin-left: -18px;
  border-radius: 999px;
  background: #9aabba;
}
.popup-resize-handle:hover::after,
.popup-resize-handle:active::after {
  background: var(--accent);
}

.intro-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(20, 32, 48, 0.45);
  backdrop-filter: blur(2px);
}

.intro-overlay[hidden] { display: none; }

.intro-card {
  width: min(480px, 100%);
  max-height: min(92vh, 720px);
  overflow: auto;
  padding: 22px 22px 18px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 16px 40px rgba(20, 32, 48, 0.22);
}

.intro-logo {
  display: block;
  height: 48px;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  margin: 0 0 14px;
}

.intro-card h2 {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 700;
}

.intro-lead {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.intro-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.intro-list li {
  position: relative;
  margin: 0 0 10px;
  padding-left: 16px;
  font-size: 14px;
  line-height: 1.45;
}

.intro-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.55em;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

.intro-list strong { color: var(--ink); font-weight: 650; }

.intro-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 16px 0 14px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.intro-check input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.intro-btn {
  width: 100%;
  height: 42px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 15px;
  font-weight: 650;
  cursor: pointer;
}

.intro-btn:hover { filter: brightness(1.05); }

body.mobile-2d .view-toggle {
  display: none !important;
}

@media (max-width: 980px) {
  .topbar {
    top: max(8px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "brand stats"
      "search search";
    gap: 10px 12px;
    padding: 10px 12px;
  }
  .brand { grid-area: brand; }
  .brand-logo { height: 30px; max-width: 160px; }
  .brand h1 { font-size: 13px; white-space: normal; line-height: 1.2; }
  .intro-logo { height: 40px; }
  .stats {
    grid-area: stats;
    gap: 10px;
  }
  .stats p { min-width: 0; }
  .stats b { font-size: 15px; }
  .stats span { font-size: 10px; }
  .search { grid-area: search; grid-column: auto; }
  .search input { height: 40px; font-size: 16px; }
  .search-list { max-height: min(42vh, 320px); }
  .legend {
    left: max(8px, env(safe-area-inset-left));
    bottom: max(36px, calc(28px + env(safe-area-inset-bottom)));
    width: min(200px, calc(100% - 16px));
    padding: 10px 12px;
  }
  .legend-title { font-size: 11px; }
  .legend ul,
  .legend-block { font-size: 12px; }
  .area-panel,
  .chat-panel {
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    width: auto;
    max-width: none;
  }
  .chat-panel {
    max-height: min(70vh, 520px);
  }
  .chat-log {
    min-height: 120px;
    max-height: min(36vh, 240px);
  }
  .chat-chip {
    font-size: 12px;
    padding: 7px 11px;
  }
  .esri-ui-top-right { top: 118px; right: max(8px, env(safe-area-inset-right)); }
  .esri-ui-top-left { top: 118px; left: max(8px, env(safe-area-inset-left)); }
  .esri-popup__main-container {
    max-width: calc(100vw - 16px) !important;
    width: calc(100vw - 16px) !important;
    min-width: 0 !important;
    max-height: min(62vh, 560px) !important;
  }
  .floors { min-height: 100px; }
  .esri-view .esri-popup {
    z-index: 6;
  }
  body.popup-open .legend,
  body.popup-open .area-panel,
  body.popup-open .chat-panel {
    visibility: hidden;
    pointer-events: none;
  }
  .floors details[open] > .floor-dwellings {
    max-height: var(--floor-open-max, min(28vh, 220px));
  }
  .esri-popup__content { max-height: min(52vh, 480px) !important; }
  .breakdown { max-height: 28vh; }
  .intro-overlay {
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    align-items: flex-start;
    overflow: auto;
  }
  .intro-card {
    padding: 18px 16px 14px;
    margin: auto 0;
    max-height: none;
  }
  .intro-card h2 { font-size: 18px; }
  .popup-stat {
    column-gap: 8px;
  }
  .popup-stat-ico {
    width: 40px;
    height: 40px;
  }
  .popup-stat-label { font-size: 13px; }
  .popup-stat-count { font-size: 30px; }
  .popup-meta {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .popup-chips { gap: 5px; }
  .chip {
    font-size: 11px;
    padding: 6px 9px;
  }
}

@media (max-width: 560px) {
  .topbar {
    grid-template-columns: 1fr;
    grid-template-areas:
      "brand"
      "search"
      "stats";
    gap: 8px;
    padding: 8px 10px;
  }
  .stats {
    justify-self: stretch;
    justify-content: space-between;
    width: 100%;
    gap: 6px;
    padding-top: 2px;
    border-top: 1px solid var(--line);
  }
  .stats p { align-items: center; flex: 1 1 0; min-width: 0; }
  .stats b { font-size: 14px; }
  .stats .stat-fecha { font-size: 13px; }
  .stats span {
    font-size: 9px;
    white-space: normal;
    line-height: 1.15;
  }
  .brand h1 { font-size: 13px; }
  .brand-logo { height: 26px; max-width: 120px; }
  .legend {
    width: auto;
    max-width: calc(100% - 56px);
    right: auto;
    padding: 7px 9px;
    bottom: max(28px, calc(20px + env(safe-area-inset-bottom)));
  }
  .legend ul {
    grid-template-columns: repeat(3, auto);
    gap: 4px 8px;
  }
  .legend-block { margin-top: 6px; }
  .esri-ui-top-right,
  .esri-ui-top-left { top: 168px; }
  .esri-widget--button,
  .view-toggle {
    width: 40px;
    height: 40px;
  }
  .esri-ui-top-right .esri-component {
    margin-bottom: 6px;
  }
  .popup-card p {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }
  .floors summary {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }
  .floors summary .floor-meta { text-align: left; white-space: normal; }
  .popup-card--sticky .popup-actions .btn-padron,
  .popup-card--sticky .popup-actions .btn-catastro,
  .btn-padron,
  .btn-catastro {
    height: 40px;
    font-size: 14px;
  }
  .chat-panel {
    max-height: min(78vh, 560px);
    border-radius: 14px 14px 10px 10px;
  }
  .chat-form input { height: 40px; font-size: 16px; }
  .chat-send { height: 40px; padding: 0 12px; }
}

/* —— Popup más legible —— */
.esri-popup__main-container {
  border-radius: 14px !important;
  resize: none !important;
  overflow: hidden !important;
  padding-bottom: 14px;
}
.esri-popup__header-title { font-size: 15px !important; font-weight: 700 !important; }
.esri-popup__content svg.popup-ico,
.popup-card svg.popup-ico {
  overflow: visible !important;
  max-width: none !important;
  max-height: none !important;
}
.popup-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 220px;
  box-sizing: border-box;
  padding-bottom: 8px;
}
.popup-card--sticky {
  gap: 0;
  min-height: 0;
  height: 100%;
  max-height: 100%;
}
.popup-sticky {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 2px 2px 10px;
  margin-bottom: 0;
  background: #fff;
  border-bottom: 1px solid var(--line);
  z-index: 2;
}
.popup-scroll {
  flex: 1 1 auto;
  min-height: 0;
  max-height: var(--floors-max, min(42vh, 360px));
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 8px 0 4px;
}
.popup-card--sticky .popup-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 2px;
}
.popup-card--sticky .popup-actions:has(:only-child) {
  grid-template-columns: 1fr;
}
.popup-card--sticky .popup-actions .btn-padron,
.popup-card--sticky .popup-actions .btn-catastro {
  height: 32px;
  font-size: 12px;
  border-radius: 8px;
}
.popup-hero {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 10px;
  padding: 14px 12px;
  border-radius: 12px;
  background: linear-gradient(145deg, #f0faf8 0%, #e8f4f2 55%, #f7faf9 100%);
  border: 1px solid #d7ebe7;
}
.popup-hero-badge {
  display: flex;
  justify-content: center;
  width: 100%;
}
.popup-stat {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  column-gap: 12px;
  width: 100%;
}
.popup-stat-ico {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  color: var(--accent);
  box-shadow: 0 1px 2px rgba(15, 111, 106, 0.12);
}
.popup-stat-ico .popup-ico { width: 24px; height: 24px; }
.popup-stat-label {
  min-width: 0;
  font-size: 15px;
  color: #3d4a57;
  font-weight: 650;
  line-height: 1.25;
  text-align: left;
}
.popup-stat-count {
  font-size: 36px;
  font-weight: 750;
  line-height: 1;
  color: var(--accent);
  letter-spacing: -0.02em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.popup-meta .meta-tipo dd {
  margin: 0;
}
.popup-ico {
  display: block;
  flex: 0 0 auto;
  overflow: visible;
  vertical-align: middle;
}
.popup-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 11px;
  border-radius: 999px;
  background: #eef6f5;
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  overflow: visible;
  box-sizing: border-box;
  min-height: 30px;
}
.chip > span {
  line-height: 1.15;
  display: inline-block;
}
.chip .popup-ico {
  width: 16px !important;
  height: 16px !important;
  min-width: 16px;
  min-height: 16px;
  overflow: visible !important;
}
.chip.chip-m { background: #fce7f3; color: #9d174d; }
.chip.chip-h { background: #dbeafe; color: #1e40af; }
.chip.chip-age { background: #fef3c7; color: #92400e; }
.chip.chip-tipo {
  background: #fff;
  border: 1px solid #d7ebe7;
  color: var(--accent);
  font-weight: 700;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.chip.chip-tipo-pluri {
  border-color: #c7d2fe;
  color: #3730a3;
  background: #eef2ff;
}
.popup-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  margin: 0;
  padding: 2px 0;
}
.popup-meta > div { display: flex; flex-direction: column; gap: 2px; }
.popup-meta > div:only-child { grid-column: 1 / -1; }
.popup-meta dt { margin: 0; font-size: 11px; color: var(--muted); }
.popup-meta dd { margin: 0; font-size: 13px; font-weight: 650; word-break: break-word; }
.popup-actions { display: flex; flex-direction: column; gap: 6px; margin-top: 2px; }
.btn-padron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  box-sizing: border-box;
}
a.btn-padron:hover { filter: brightness(1.05); color: #fff; }
.btn-padron.is-disabled,
.btn-padron:disabled { opacity: 0.55; cursor: default; pointer-events: none; }
.btn-padron-sm,
.btn-catastro-sm {
  width: auto;
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
  border-radius: 8px;
  flex: 0 0 auto;
}
.btn-catastro {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: #1d4ed8;
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  box-sizing: border-box;
}
a.btn-catastro:hover { filter: brightness(1.08); color: #fff; }
.breakdown li {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 0;
}
.breakdown li .floor-main {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}
.btn-barrios.is-active {
  background: var(--accent);
  color: #fff;
}
.padron-table .doc-cell { font-variant-numeric: tabular-nums; white-space: nowrap; }
.padron-table .doc-type {
  display: inline-block;
  margin-right: 4px;
  padding: 1px 5px;
  border-radius: 6px;
  background: #eef2ff;
  color: #3730a3;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}
.popup-card .catastro-extra { margin-top: 4px; padding-top: 10px; width: 100%; }
.popup-card .catastro-extra .breakdown-title { margin-top: 0; }
.popup-actions .catastro-extra { order: -1; }
.catastro-rc {
  display: inline-block;
  margin-left: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
}
.popup-card .popup-link { margin-top: 0; }
.popup-card p.legacy-row {
  margin: 0;
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

/* —— Interfaz padrón (pantalla completa) —— */
.padron-panel {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  background: #eef3f6;
  overflow: hidden;
}
.padron-panel[hidden] { display: none !important; }
.padron-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: min(760px, 100%);
  margin: 0 auto;
  background: #fff;
  box-shadow: 0 0 0 1px var(--line), 0 20px 50px rgba(20, 32, 48, 0.12);
  overflow: hidden;
}
.padron-head {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #f3faf9 0%, #fff 100%);
}
.padron-back {
  align-self: flex-start;
  height: 34px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
  color: var(--ink);
}
.padron-back:hover { border-color: var(--accent); color: var(--accent); }
.padron-kicker {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--accent);
}
.padron-head h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.25;
}
.padron-sub { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.padron-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px 14px;
  margin: 12px 0 0;
}
.padron-meta[hidden] { display: none !important; }
.padron-meta div { display: flex; flex-direction: column; gap: 1px; }
.padron-meta dt {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.padron-meta dd {
  margin: 0;
  font-size: 14px;
  font-weight: 650;
  word-break: break-word;
}
.padron-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
}
.padron-stat {
  padding: 12px 8px;
  border-radius: 12px;
  background: #f4f7fa;
  text-align: center;
}
.padron-stat b { display: block; font-size: 22px; }
.padron-stat span { font-size: 12px; color: var(--muted); }
.padron-body {
  flex: 1;
  overflow: auto;
  padding: 8px 16px 24px;
}
.padron-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.padron-table th {
  text-align: left;
  font-size: 11px;
  color: var(--muted);
  font-weight: 700;
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: #fff;
}
.padron-table td {
  padding: 8px 6px;
  border-bottom: 1px solid #eef2f6;
  vertical-align: top;
}
.padron-table tr:hover td { background: #f7fbfa; }
.sex-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
}
.sex-dot.h { background: #3b82f6; }
.sex-dot.m { background: #ec4899; }
.ramp {
  display: flex;
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 6px;
}
.ramp i { flex: 1; }

body.padron-open .topbar,
body.padron-open .legend,
body.padron-open .esri-ui {
  visibility: hidden;
  pointer-events: none;
}
@media (max-width: 720px) {
  .padron-kicker { font-size: 16px; }
  .padron-head h2 { font-size: 18px; }
  .padron-meta { grid-template-columns: 1fr 1fr; }
  .padron-summary { gap: 8px; padding: 12px 14px; }
  .padron-stat b { font-size: 18px; }
}
