:root {
  --paper: #faf8f4;
  --ink: #1b2335;
  --ink2: #5b6678;
  --ink3: #9aa0ad;
  --card: #fff;
  --line: #e4e1d9;
  --line2: #d0cdc5;
  --accent: #1c2541;
  --green: #22c55e;
  --green-bg: #f0fdf4;
  --red: #ef4444;
  --red-bg: #fef2f2;
  --orange: #f59e0b;
  --orange-bg: #fffbeb;
  --blue: #3b82f6;
  --purple: #8b5cf6;
  --sig-brownfield: #ff9500;
  --sig-abandoned: #ff4444;
  --sig-disused: #8888aa;
  --sig-auction: #8b5cf6;
  --sig-municipal: #22c55e;
  --sig-portal: #3b82f6;
  --sidebar-w: 220px;
  --header-h: 56px;
  --detail-w: 420px;
  --radius: 14px;
  --radius-sm: 8px;
}

/* Dark mode disabled — Phil wants all-white professional look */

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background-color: var(--paper);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ──────────────────────────────────── */
#app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--header-h) 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────── */
.sidebar {
  grid-row: 1 / -1;
  background: var(--accent);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 0 20px 20px;
  font-size: 20px;
  font-weight: 700;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  margin-bottom: 12px;
}

.sidebar-brand small {
  display: block;
  font-size: 12px;
  font-weight: 400;
  color: rgba(255,255,255,0.5);
  margin-top: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  color: rgba(255,255,255,0.65);
  text-decoration: none;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-item.active { background: rgba(255,255,255,0.12); color: #fff; }

.nav-item .icon {
  width: 20px;
  text-align: center;
  font-size: 18px;
}

.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.user-select {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  color: #fff;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 14px;
  width: 100%;
  cursor: pointer;
}

/* ── Header ──────────────────────────────────── */
.header {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
}

.header-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
}

.header-stats {
  display: flex;
  gap: 16px;
  font-size: 13px;
  color: var(--ink2);
  font-variant-numeric: tabular-nums;
  margin-left: auto;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  min-height: 44px;
}

.btn:hover { border-color: var(--ink3); background: var(--paper); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { opacity: 0.9; }

/* ── Views ──────────────────────────────────── */
.view {
  overflow: auto;
  position: relative;
}

.view[hidden] { display: none !important; }

#view-mapa {
  display: grid;
  grid-template-columns: 1fr 420px;
  grid-template-rows: 1fr;
  overflow: hidden;
  height: 100%;
}

@media (min-width: 1400px) {
  #view-mapa { grid-template-columns: 1fr 520px; }
}

@media (max-width: 1100px) {
  #view-mapa { grid-template-columns: 1fr 360px; }
}

@media (max-width: 900px) {
  #view-mapa {
    grid-template-columns: 1fr;
    grid-template-rows: 45vh 1fr;
  }
  .right-panel { border-left: none; border-top: 1px solid var(--line); }
}

/* Detail panel is now a popup overlay — right panel always visible */

#map-container {
  position: relative;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

#map {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
}

/* ── Right Panel (filters + card list) ───────── */
.right-panel {
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--line);
  background: var(--paper);
  overflow: hidden;
}

.filter-bar {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
  flex-wrap: wrap;
}

.filter-select {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  min-height: 38px;
  cursor: pointer;
  flex: 1;
  min-width: 100px;
}

.filter-search {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  min-height: 38px;
  flex: 2;
  min-width: 120px;
}

.filter-search::placeholder { color: var(--ink3); }

.right-stats {
  display: flex;
  gap: 12px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--ink2);
  border-bottom: 1px solid var(--line);
  background: var(--card);
  font-variant-numeric: tabular-nums;
}

.right-stats b { color: var(--ink); }

/* ── Featured section ──────────────────────── */
.featured-section {
  padding: 12px;
  border-bottom: 2px solid var(--line);
  background: linear-gradient(180deg, #f8fdf5 0%, var(--paper) 100%);
}

.featured-header {
  font-size: 13px;
  font-weight: 700;
  color: var(--green);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.featured-card {
  background: var(--card);
  border: 2px solid #e8f5e0;
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  display: flex;
  gap: 12px;
}

.featured-card:hover {
  border-color: var(--green);
  box-shadow: 0 2px 12px rgba(34,197,94,0.12);
}

.featured-img {
  width: 100px;
  height: 70px;
  border-radius: 8px;
  background-size: cover;
  background-position: center;
  background-color: var(--line);
  flex-shrink: 0;
}

.featured-body { flex: 1; min-width: 0; }

/* ── Cards ──────────────────────────────────── */
.card-with-thumb {
  display: flex;
  gap: 12px;
}

.card-thumb {
  width: 80px;
  min-width: 80px;
  height: 60px;
  border-radius: 6px;
  background-size: cover;
  background-position: center;
  background-color: var(--line);
  flex-shrink: 0;
}

.card-body { flex: 1; min-width: 0; }

.card-list {
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.candidate-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.candidate-card:hover {
  border-color: var(--line2);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.candidate-card.selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(59,130,246,0.15);
}

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

.card-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  flex: 1;
}

.card-score {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.score-hot { background: var(--green-bg); color: var(--green); }
.score-warm { background: var(--orange-bg); color: var(--orange); }
.score-cold { background: var(--paper); color: var(--ink3); }

.card-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 6px;
  font-size: 12px;
  color: var(--ink2);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge-signal { color: #fff; }

.card-margin {
  margin-top: 6px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.margin-pos { color: var(--green); font-weight: 600; }
.margin-neg { color: var(--red); font-weight: 600; }
.margin-roi { color: var(--ink2); margin-left: 8px; }

.dq-badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--orange-bg);
  color: var(--orange);
}

/* ── Legend ──────────────────────────────────── */
.legend {
  position: absolute;
  bottom: 16px;
  left: 16px;
  z-index: 1000;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.legend-chip.off { opacity: 0.4; }

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

/* ── Stat tiles ──────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  padding: 16px;
}

.stat-tile {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.stat-tile .label {
  font-size: 12px;
  color: var(--ink2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-tile .value {
  font-size: 24px;
  font-weight: 700;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

/* ── Detail Popup Modal ─────────────────────── */
.detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 8000;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.detail-overlay[hidden] { display: none !important; }

/* ── Detail Panel ──────────────────────────────── */
.detail-panel {
  width: 480px;
  max-width: 95vw;
  height: 100vh;
  background: var(--card);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 20px rgba(0,0,0,0.12);
}

.detail-header {
  padding: 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.detail-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--ink3);
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.detail-tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}

.detail-tab {
  padding: 12px 16px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink2);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}

.detail-tab.active {
  color: var(--ink);
  border-bottom-color: var(--blue);
}

.detail-content {
  padding: 16px;
  flex: 1;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.detail-row .label { color: var(--ink2); }
.detail-row .value { font-weight: 600; text-align: right; }

.detail-big {
  text-align: center;
  padding: 20px;
  margin-bottom: 12px;
}

.detail-big .number {
  font-size: 32px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.detail-big .sub {
  font-size: 13px;
  color: var(--ink2);
  margin-top: 4px;
}

.detail-links {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.detail-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--blue);
  text-decoration: none;
  font-weight: 500;
  min-height: 44px;
}

.detail-link:hover { border-color: var(--blue); }

/* ── Slider ──────────────────────────────────── */
.slider-row {
  margin-bottom: 16px;
}

.slider-row label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--ink2);
  margin-bottom: 4px;
}

.slider-row label .val {
  font-weight: 600;
  color: var(--ink);
}

.slider-row input[type="range"] {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--line);
  border-radius: 3px;
  outline: none;
}

.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--blue);
  cursor: pointer;
}

/* ── Onboarding ──────────────────────────────── */
.onboarding {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.onboarding[hidden] { display: none !important; }

.onboarding-card {
  background: var(--card);
  border-radius: 20px;
  padding: 36px 28px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.onboarding-card h2 {
  font-size: 22px;
  margin-bottom: 12px;
}

.onboarding-card p {
  font-size: 15px;
  color: var(--ink2);
  line-height: 1.6;
  margin-bottom: 24px;
}

.onboarding-card .btn {
  font-size: 16px;
  padding: 14px 32px;
  min-height: 48px;
}

/* ── Tooltip ──────────────────────────────────── */
.tip-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--line);
  color: var(--ink2);
  font-size: 11px;
  font-weight: 700;
  cursor: help;
  margin-left: 4px;
  vertical-align: middle;
}

.tip-popup {
  position: fixed;
  z-index: 10001;
  background: var(--accent);
  color: #fff;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  max-width: 300px;
  line-height: 1.5;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  pointer-events: none;
}

/* ── Mobile ──────────────────────────────────── */
@media (max-width: 900px) {
  :root {
    --sidebar-w: 0px;
    --detail-w: 100%;
  }

  body { font-size: 18px; }

  #app {
    grid-template-columns: 1fr;
    grid-template-rows: var(--header-h) 1fr auto;
  }

  .sidebar {
    position: fixed;
    left: -260px;
    top: 0;
    bottom: 0;
    width: 260px;
    z-index: 9000;
    transition: left 0.25s ease;
  }

  .sidebar.open { left: 0; }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 8999;
  }

  .detail-panel {
    width: 100vw;
    max-width: 100vw;
    height: 60vh;
    position: fixed;
    bottom: 0;
    border-radius: 20px 20px 0 0;
  }

  .detail-overlay {
    align-items: flex-end;
    justify-content: center;
  }

  .mobile-nav {
    display: flex;
    background: var(--card);
    border-top: 1px solid var(--line);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 4000;
  }

  .mobile-nav .nav-item {
    flex: 1;
    flex-direction: column;
    padding: 8px 4px;
    font-size: 11px;
    text-align: center;
    color: var(--ink3);
    gap: 2px;
  }

  .mobile-nav .nav-item.active { color: var(--blue); }
  .mobile-nav .icon { font-size: 20px; }

  .legend { bottom: 64px; }
}

/* ── Leaflet overrides ──────────────────────────── */
.leaflet-popup-content {
  font: inherit;
  font-size: 13px;
  line-height: 1.5;
  margin: 10px 14px;
}

.leaflet-popup-content b { color: var(--ink); font-weight: 700; }
.leaflet-popup-content .popup-margin { font-weight: 600; }
.leaflet-popup-content .popup-margin.pos { color: var(--green); }
.leaflet-popup-content .popup-margin.neg { color: var(--red); }

.leaflet-control-zoom a {
  width: 36px !important;
  height: 36px !important;
  line-height: 36px !important;
  font-size: 18px !important;
}
