/* Mapa Inmuebles — glass UI, light/dark/system */

:root {
  --font: "DM Sans", system-ui, -apple-system, sans-serif;
  --font-display: "Outfit", var(--font);
  --header-h: 60px;
  --footer-h: 36px;
  --dock-h: 72px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --radius: 20px;
  --radius-sm: 14px;
  --blur: 24px;
  --accent: #0a84ff;
  --accent-soft: rgba(10, 132, 255, 0.14);
  --accent-hover: #0071e3;
  --ok: #30d158;
  --err: #ff453a;
  --text: #1c1c1e;
  --text-muted: rgba(60, 60, 67, 0.72);
  --glass-bg: rgba(255, 255, 255, 0.72);
  --glass-border: rgba(255, 255, 255, 0.55);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.08), 0 1px 0 rgba(255, 255, 255, 0.6) inset;
  --sheet-shadow: 0 -4px 40px rgba(0, 0, 0, 0.12);
  --backdrop: rgba(0, 0, 0, 0.35);
  --input-bg: rgba(255, 255, 255, 0.65);
  --pin-bg: #ffd60a;
  --pin-cut: #1c1c1e;
}

html[data-theme="dark"] {
  --text: #f5f5f7;
  --text-muted: rgba(235, 235, 245, 0.6);
  --accent: #64d2ff;
  --accent-soft: rgba(100, 210, 255, 0.16);
  --accent-hover: #7ad9ff;
  --err: #ff6961;
  --glass-bg: rgba(28, 28, 30, 0.72);
  --glass-border: rgba(255, 255, 255, 0.12);
  --glass-shadow: 0 8px 40px rgba(0, 0, 0, 0.45), 0 1px 0 rgba(255, 255, 255, 0.06) inset;
  --sheet-shadow: 0 -8px 48px rgba(0, 0, 0, 0.5);
  --backdrop: rgba(0, 0, 0, 0.55);
  --input-bg: rgba(44, 44, 46, 0.85);
  --pin-bg: #ffd60a;
  --pin-cut: #1c1c1e;
}

@media (prefers-color-scheme: dark) {
  html[data-theme="system"] {
    --text: #f5f5f7;
    --text-muted: rgba(235, 235, 245, 0.6);
    --accent: #64d2ff;
    --accent-soft: rgba(100, 210, 255, 0.16);
    --accent-hover: #7ad9ff;
    --err: #ff6961;
    --glass-bg: rgba(28, 28, 30, 0.72);
    --glass-border: rgba(255, 255, 255, 0.12);
    --glass-shadow: 0 8px 40px rgba(0, 0, 0, 0.45), 0 1px 0 rgba(255, 255, 255, 0.06) inset;
    --sheet-shadow: 0 -8px 48px rgba(0, 0, 0, 0.5);
    --backdrop: rgba(0, 0, 0, 0.55);
    --input-bg: rgba(44, 44, 46, 0.85);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--text);
  background: #000;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100vh;
  overflow: hidden;
}

.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--blur)) saturate(180%);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(180%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
}

.glass-bar {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--blur)) saturate(180%);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(180%);
  border-bottom: 1px solid var(--glass-border);
}

/* Header */
.header {
  position: relative;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: var(--header-h);
  padding: calc(8px + var(--safe-t)) calc(16px + var(--safe-r)) 8px calc(16px + var(--safe-l));
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
  min-width: 0;
}

.brand-icon { flex-shrink: 0; }
.brand-icon .pin-bg { fill: var(--pin-bg); }
.brand-icon .pin-cut { fill: var(--pin-cut); }
.brand-icon .pin-dot { fill: var(--pin-bg); }

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.125rem;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.brand-tag {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: 1px solid var(--glass-border);
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease;
}

.icon-btn:active { transform: scale(0.94); }

.region-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

.region-badge-warn {
  border-color: rgba(255, 69, 58, 0.35);
}

.region-flag { font-size: 1rem; line-height: 1; }

.region-warn {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--err);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.region-auto-label {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  font-size: 0.8125rem;
  color: var(--text-muted);
  cursor: pointer;
}

.region-auto-label input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.chip-disabled {
  opacity: 0.45;
}

.icon-sun,
.icon-moon {
  display: none;
}

html[data-theme="light"] .icon-moon,
html[data-theme="dark"] .icon-sun {
  display: block;
}

@media (prefers-color-scheme: light) {
  html[data-theme="system"] .icon-moon { display: block; }
}

@media (prefers-color-scheme: dark) {
  html[data-theme="system"] .icon-sun { display: block; }
}

/* Map */
.map-stage {
  position: relative;
  flex: 1;
  min-height: 0;
}

#map {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.leaflet-container { font-family: var(--font); background: #e8e8ed; }

html[data-theme="dark"] .leaflet-container,
html[data-theme="system"] .leaflet-container {
  /* dark tiles applied in JS */
}

/* HUD */
.hud {
  position: absolute;
  top: 12px;
  left: max(12px, var(--safe-l));
  right: max(12px, var(--safe-r));
  z-index: 1000;
  max-width: 420px;
  margin: 0 auto;
  padding: 14px 18px;
  border-radius: var(--radius);
  pointer-events: none;
}

@media (min-width: 640px) {
  .hud {
    right: auto;
    margin: 0;
    max-width: 360px;
  }
}

.hud-count {
  margin: 0;
  font-weight: 600;
  font-size: 0.9375rem;
  line-height: 1.35;
}

.hud-sub {
  margin: 6px 0 0;
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.hud-err {
  margin: 8px 0 0;
  font-size: 0.8125rem;
  color: var(--err);
  line-height: 1.4;
}

.hud-err a {
  color: var(--accent);
  pointer-events: auto;
}

/* Dock */
.dock {
  position: absolute;
  bottom: calc(12px + var(--safe-b));
  left: 50%;
  transform: translateX(-50%);
  z-index: 1100;
  display: flex;
  align-items: stretch;
  gap: 4px;
  padding: 6px;
  border-radius: 999px;
  max-width: calc(100vw - 24px);
}

.dock-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 72px;
  padding: 8px 12px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.6875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.dock-btn svg { opacity: 0.85; }

.dock-btn:hover,
.dock-btn[aria-expanded="true"] {
  background: var(--accent-soft);
  color: var(--accent);
}

.dock-btn-accent {
  background: var(--accent);
  color: #fff;
}

.dock-btn-accent:hover {
  background: var(--accent-hover);
  color: #fff;
}

/* Sheets */
.panel-backdrop {
  position: absolute;
  inset: 0;
  z-index: 1150;
  background: var(--backdrop);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}

.panel-backdrop.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  position: absolute;
  z-index: 1160;
  display: flex;
  flex-direction: column;
  max-height: min(72vh, calc(100% - var(--header-h) - var(--dock-h) - 40px));
  transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1), visibility 0.32s;
  visibility: hidden;
  pointer-events: none;
}

.sheet.is-open {
  visibility: visible;
  pointer-events: auto;
}

.sheet-handle {
  display: block;
  width: 36px;
  height: 5px;
  margin: 10px auto 4px;
  border-radius: 999px;
  background: var(--text-muted);
  opacity: 0.35;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 20px 12px;
  flex-shrink: 0;
}

.sheet-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.text-btn {
  border: none;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
}

.text-btn:hover { background: var(--accent-soft); }

.sheet-summary {
  margin: 0 20px 12px;
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.45;
  flex-shrink: 0;
}

.sheet-body {
  padding: 0 20px 20px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.filter-section { margin-bottom: 20px; }

.filter-section h3 {
  margin: 0 0 10px;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

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

.chip {
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

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

.chip.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Mobile: bottom sheets */
.sheet-left,
.sheet-right {
  left: 0;
  right: 0;
  bottom: calc(var(--dock-h) + var(--safe-b) + 8px);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--sheet-shadow);
  transform: translateY(110%);
}

.sheet-left.is-open,
.sheet-right.is-open {
  transform: translateY(0);
}

.city-list {
  list-style: none;
  margin: 0;
  padding: 0 12px 16px;
  overflow: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

.city-list li { margin: 0 0 6px; }

.city-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease;
}

.city-item:hover { background: var(--accent-soft); }

.city-item.is-active {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 2px var(--accent);
}

.city-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
}

.city-meta strong {
  color: var(--accent);
  font-weight: 700;
}

/* Desktop: side panels */
@media (min-width: 768px) {
  .sheet-handle { display: none; }

  .sheet-left {
    top: 12px;
    left: 12px;
    bottom: calc(var(--dock-h) + 24px);
    right: auto;
    width: min(320px, 36vw);
    max-height: none;
    border-radius: var(--radius);
    transform: translateX(calc(-100% - 24px));
  }

  .sheet-right {
    top: 12px;
    right: 12px;
    left: auto;
    bottom: calc(var(--dock-h) + 24px);
    width: min(320px, 36vw);
    max-height: none;
    border-radius: var(--radius);
    transform: translateX(calc(100% + 24px));
  }

  .sheet-left.is-open { transform: translateX(0); }
  .sheet-right.is-open { transform: translateX(0); }

  .dock {
    bottom: calc(20px + var(--safe-b));
  }
}

/* Footer */
.footer {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 10px;
  min-height: var(--footer-h);
  padding: 6px 16px calc(6px + var(--safe-b));
  font-size: 0.6875rem;
  color: var(--text-muted);
  border-top: 1px solid var(--glass-border);
}

.footer-sep { opacity: 0.4; }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: var(--backdrop);
  backdrop-filter: blur(6px);
}

.modal-dialog {
  position: fixed;
  z-index: 2001;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(400px, calc(100vw - 32px));
  max-height: min(90vh, 600px);
  overflow: auto;
  margin: 0;
  padding: 24px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  color: var(--text);
}

.modal-dialog::backdrop { background: transparent; }

.modal-dialog h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
}

.modal-dialog > p {
  margin: 0 0 20px;
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.lead-prop {
  margin: 0 0 16px !important;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--text) !important;
  font-weight: 500;
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field span {
  display: block;
  margin-bottom: 6px;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.field input,
.field textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
}

.field textarea { resize: vertical; min-height: 88px; }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 8px;
}

.btn {
  padding: 12px 20px;
  border-radius: 12px;
  border: none;
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-ghost {
  background: var(--input-bg);
  color: var(--text-muted);
}

.form-msg { margin: 12px 0 0; font-size: 0.875rem; }
.form-msg.err { color: var(--err); }

/* Leaflet popup */
.mi-popup .leaflet-popup-content-wrapper {
  border-radius: var(--radius-sm);
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
}

.mi-popup .leaflet-popup-content {
  margin: 12px 14px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
}

.mi-popup .leaflet-popup-tip { background: var(--glass-bg); }

.map-popup-photo {
  display: block;
  width: calc(100% + 28px);
  height: 130px;
  object-fit: cover;
  margin: -12px -14px 10px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.map-consult-btn {
  margin-top: 10px;
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
}

.mi-popup a { color: var(--accent); }

/* Map pins (SVG via divIcon) */
.leaflet-div-icon.mi-marker-wrap {
  background: transparent !important;
  border: none !important;
}

.mi-pin-svg {
  display: block;
  overflow: visible;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.28)) drop-shadow(0 6px 12px rgba(0, 0, 0, 0.18));
}

.mi-pin-body {
  fill: var(--accent);
  stroke: #fff;
  stroke-width: 2;
  stroke-linejoin: round;
}

.mi-pin-dot {
  fill: #fff;
}

.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
  background: var(--accent-soft) !important;
}

.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
  background: var(--accent) !important;
  color: #fff !important;
  font-weight: 700;
}
