/* ── Design tokens ─────────────────────────────────────────────────────────── */
:root {
  --c-primary: #1d4ed8;
  --c-primary-dark: #1e3a8a;
  --c-primary-light: #eff6ff;
  --c-accent: #f97316;
  --c-bg: #f8fafc;
  --c-surface: #ffffff;
  --c-border: #e2e8f0;
  --c-text: #0f172a;
  --c-text-2: #64748b;
  --c-text-3: #94a3b8;
  --c-success: #059669;
  --c-danger: #dc2626;
  --c-warning: #d97706;

  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 10px 30px rgba(0,0,0,.08);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.07), 0 20px 60px rgba(0,0,0,.1);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  --font-mono: "Cascadia Code", "Fira Code", "Courier New", monospace;

  --max-w: 1160px;
  --header-h: 60px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --c-bg: #0f172a;
    --c-surface: #1e293b;
    --c-border: #334155;
    --c-text: #f1f5f9;
    --c-text-2: #94a3b8;
    --c-text-3: #64748b;
    --c-primary-light: #1e3a8a;
    --shadow: 0 1px 3px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.3);
    --shadow-md: 0 4px 6px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.4);
  }
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--c-bg);
  color: var(--c-text);
  line-height: 1.6;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
img { max-width: 100%; display: block; }
a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ─────────────────────────────────────────────────────────────────── */
.container { max-width: var(--max-w); margin: 0 auto; padding: 0 16px; }
@media (min-width: 640px) { .container { padding: 0 24px; } }

/* ── Header ─────────────────────────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  height: var(--header-h);
  backdrop-filter: blur(12px);
  background: rgba(255,255,255,.9);
}
@media (prefers-color-scheme: dark) {
  .site-header { background: rgba(30,41,59,.9); }
}
.header-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 100%;
}
.logo {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--c-text);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}
.logo-dot { color: var(--c-primary); }
.header-search { flex: 1; max-width: 480px; }

/* ── Hero ─────────────────────────────────────────────────────────────────── */
.hero {
  background: linear-gradient(135deg, var(--c-primary-dark) 0%, var(--c-primary) 60%, #6366f1 100%);
  padding: 72px 16px 80px;
  text-align: center;
  color: white;
}
.hero h1 {
  font-size: clamp(1.8rem, 5vw, 3rem);
  font-weight: 800;
  letter-spacing: -.03em;
  line-height: 1.15;
  margin-bottom: 12px;
}
.hero p {
  font-size: clamp(1rem, 2.5vw, 1.2rem);
  opacity: .85;
  margin-bottom: 36px;
  max-width: 540px;
  margin-left: auto;
  margin-right: auto;
}

/* ── Search ─────────────────────────────────────────────────────────────────── */
.search-wrap {
  position: relative;
  max-width: 600px;
  margin: 0 auto;
}
.search-input {
  width: 100%;
  padding: 16px 52px 16px 20px;
  font-size: 1.05rem;
  border: none;
  border-radius: var(--radius);
  outline: none;
  background: var(--c-surface);
  color: var(--c-text);
  box-shadow: var(--shadow-lg);
  transition: box-shadow .2s;
}
.search-input:focus { box-shadow: var(--shadow-lg), 0 0 0 3px rgba(99,102,241,.35); }
.search-input.sm {
  padding: 10px 44px 10px 14px;
  font-size: .95rem;
  border-radius: var(--radius-sm);
  box-shadow: none;
  border: 1.5px solid var(--c-border);
}
.search-input.sm:focus { box-shadow: 0 0 0 3px rgba(29,78,216,.2); border-color: var(--c-primary); }
.search-icon {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--c-text-2);
  pointer-events: none;
}
.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  background: var(--c-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--c-border);
  overflow: hidden;
  z-index: 200;
  max-height: 380px;
  overflow-y: auto;
}
.search-result-item {
  padding: 12px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background .1s;
  border-bottom: 1px solid var(--c-border);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover, .search-result-item.active { background: var(--c-primary-light); }
.search-result-icon { color: var(--c-primary); flex-shrink: 0; }
.search-result-main { font-weight: 500; color: var(--c-text); }
.search-result-sub { font-size: .85rem; color: var(--c-text-2); }

/* ── Stats bar ─────────────────────────────────────────────────────────────── */
.stats-bar {
  background: var(--c-surface);
  border-top: 1px solid var(--c-border);
  border-bottom: 1px solid var(--c-border);
}
.stats-bar-inner {
  display: flex;
  gap: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.stat-item {
  flex: 1;
  min-width: 140px;
  padding: 20px 24px;
  border-right: 1px solid var(--c-border);
  text-align: center;
}
.stat-item:last-child { border-right: none; }
.stat-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--c-primary);
  display: block;
  font-variant-numeric: tabular-nums;
}
.stat-label { font-size: .8rem; color: var(--c-text-2); text-transform: uppercase; letter-spacing: .05em; }

/* ── Main content ─────────────────────────────────────────────────────────── */
main { flex: 1; }
.page { padding: 32px 0 64px; }
.page-header { margin-bottom: 28px; }
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .85rem;
  color: var(--c-text-2);
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.breadcrumb a { color: var(--c-text-2); }
.breadcrumb a:hover { color: var(--c-primary); }
.breadcrumb-sep { color: var(--c-text-3); }
.page-title {
  font-size: clamp(1.5rem, 4vw, 2.2rem);
  font-weight: 800;
  letter-spacing: -.03em;
  color: var(--c-text);
}
.page-subtitle { font-size: 1rem; color: var(--c-text-2); margin-top: 4px; }
.page-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 12px;
  background: var(--c-surface);
  border: 1.5px solid var(--c-border);
  border-radius: 20px;
  font-size: .8rem;
  font-weight: 600;
  color: var(--c-text-2);
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
  margin-top: 8px;
}
.page-badge-addr { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.page-badge-dvf  { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.page-badge-pm     { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.page-badge-orange { background: #fff7ed; border-color: #fed7aa; color: #9a3412; }
.page-badge-green  { background: #f5f3ff; border-color: #ddd6fe; color: #5b21b6; }

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--c-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-title { font-size: 1rem; font-weight: 700; color: var(--c-text); }
.card-count {
  font-size: .8rem;
  padding: 2px 8px;
  background: var(--c-border);
  border-radius: 20px;
  color: var(--c-text-2);
  font-weight: 600;
}
.card-body { padding: 20px; }

/* ── Section ─────────────────────────────────────────────────────────────────── */
.section { margin-bottom: 32px; }
.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--c-text);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-icon { font-size: 1.1em; }

/* ── Address grid ─────────────────────────────────────────────────────────── */
.addr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
}
.addr-chip {
  padding: 6px 10px;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  font-size: .85rem;
  text-align: center;
  color: var(--c-text);
  transition: all .15s;
}
.addr-chip:hover { background: var(--c-primary-light); border-color: var(--c-primary); color: var(--c-primary); }

/* ── DVF stats ─────────────────────────────────────────────────────────────── */
.dvf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}
.dvf-card {
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}
.dvf-type {
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--c-text-2);
  margin-bottom: 6px;
}
.dvf-year { color: var(--c-text-3); font-size: .75rem; margin-bottom: 10px; }
.dvf-price {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--c-text);
  font-variant-numeric: tabular-nums;
}
.dvf-price-label { font-size: .75rem; color: var(--c-text-2); }
.dvf-meta {
  display: flex;
  gap: 12px;
  margin-top: 10px;
  font-size: .8rem;
  color: var(--c-text-2);
}
.dvf-tag {
  display: inline-block;
  padding: 2px 6px;
  background: var(--c-primary-light);
  color: var(--c-primary);
  border-radius: 4px;
  font-size: .75rem;
  font-weight: 600;
}

/* ── PM table ─────────────────────────────────────────────────────────────── */
.pm-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.pm-table th {
  padding: 8px 12px;
  text-align: left;
  background: var(--c-bg);
  color: var(--c-text-2);
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  border-bottom: 1px solid var(--c-border);
}
.pm-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--c-border);
  color: var(--c-text);
}
.pm-table tr:last-child td { border-bottom: none; }
.pm-table tr:hover td { background: var(--c-bg); }
.siren-code { font-family: var(--font-mono); font-size: .8rem; color: var(--c-text-2); }
.droit-badge {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: .75rem;
  font-weight: 600;
}
.droit-p { background: #dcfce7; color: #16a34a; }
.droit-u { background: #fef3c7; color: #d97706; }
.droit-other { background: var(--c-border); color: var(--c-text-2); }

/* ── Lists ─────────────────────────────────────────────────────────────────── */
.list-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}
.list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  color: var(--c-text);
  transition: all .15s;
  font-size: .9rem;
}
.list-item:hover {
  border-color: var(--c-primary);
  background: var(--c-primary-light);
  color: var(--c-primary);
  text-decoration: none;
}
.list-item-count { margin-left: auto; font-size: .8rem; color: var(--c-text-2); }

/* ── Map preview ─────────────────────────────────────────────────────────────── */
.map-preview {
  height: 280px;
  border-radius: var(--radius);
  overflow: hidden;
  background: #1a1a2e;
  margin-bottom: 24px;
}
.map-preview iframe { width: 100%; height: 100%; border: none; }
/* Leaflet overrides */
.map-preview .leaflet-container { border-radius: var(--radius); }
.map-preview .leaflet-tile-pane { filter: brightness(1.6); }
.map-preview .leaflet-control-attribution { font-size: .65rem; }

/* ── Transaction chart ──────────────────────────────────────────────────────── */
.chart-wrap { padding: 12px 8px 4px; }

/* ── Empty state ─────────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--c-text-2);
}
.empty-state-icon { font-size: 2.5rem; margin-bottom: 12px; }
.empty-state p { font-size: .95rem; }

/* ── Footer ─────────────────────────────────────────────────────────────────── */
.site-footer {
  background: var(--c-surface);
  border-top: 1px solid var(--c-border);
  padding: 32px 0;
  font-size: .85rem;
  color: var(--c-text-2);
}
.footer-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  align-items: center;
  justify-content: space-between;
}
.footer-links { display: flex; gap: 16px; flex-wrap: wrap; }
.footer-links a { color: var(--c-text-2); }
.footer-links a:hover { color: var(--c-primary); }

/* ── Sortable table ──────────────────────────────────────────────────────────── */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--c-primary); background: var(--c-primary-light); }
th.sort-asc::after  { content: " ↑"; color: var(--c-primary); font-size:.85em; }
th.sort-desc::after { content: " ↓"; color: var(--c-primary); font-size:.85em; }

/* ── Address chip filter ──────────────────────────────────────────────────────── */
.addr-chip.clickable { cursor: pointer; }
.addr-chip.active    { background: var(--c-primary); color: #fff; border-color: var(--c-primary); font-weight: 700; }
.filter-bar {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--c-primary-light);
  border-bottom: 1px solid var(--c-border);
  font-size: .85rem;
  color: var(--c-primary);
}
.filter-clear {
  margin-left: auto;
  padding: 3px 10px;
  border: 1.5px solid var(--c-primary);
  background: transparent;
  color: var(--c-primary);
  border-radius: 20px;
  cursor: pointer;
  font-size: .8rem;
  font-weight: 600;
}
.filter-clear:hover { background: var(--c-primary); color: #fff; }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .hero { padding: 48px 16px 56px; }
  .stat-item { padding: 14px 16px; min-width: 100px; }
  .dvf-grid { grid-template-columns: 1fr; }
  .list-grid { grid-template-columns: 1fr 1fr; }
}
