/* ============================================================
   East Montreal Community Org Map
   Palette derived from the user's reference legend:
   Faith=maroon, Poverty=pink, Youth=navy, Cultural=hollow, Env=green
   ============================================================ */

:root {
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.8125rem);
  --text-sm: clamp(0.8125rem, 0.78rem + 0.2vw, 0.875rem);
  --text-base: clamp(0.9375rem, 0.9rem + 0.2vw, 1rem);
  --text-lg: clamp(1.0625rem, 1rem + 0.4vw, 1.25rem);
  --text-xl: clamp(1.25rem, 1.1rem + 0.8vw, 1.625rem);

  --space-1: 0.25rem; --space-2: 0.5rem; --space-3: 0.75rem;
  --space-4: 1rem; --space-5: 1.25rem; --space-6: 1.5rem;
  --space-8: 2rem; --space-10: 2.5rem; --space-12: 3rem;

  --r-sm: 0.375rem; --r-md: 0.5rem; --r-lg: 0.75rem; --r-full: 9999px;

  --font-body: 'Inter', system-ui, sans-serif;
  --font-display: 'Fraunces', Georgia, serif;
  --transition-interactive: 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

:root, [data-theme='light'] {
  --color-bg:            #f6f3ec;
  --color-surface:       #fbf8f1;
  --color-surface-2:     #ffffff;
  --color-surface-offset:#ece7dc;
  --color-border:        #d8d2c4;
  --color-divider:       #e3ddd0;

  --color-text:          #1f2429;
  --color-text-muted:    #5e6b75;
  --color-text-faint:    #8e9aa3;
  --color-text-inverse:  #fbf8f1;

  --color-primary:       #1a5d63;
  --color-primary-hover: #144a4f;
  --color-primary-soft:  #d8e6e6;

  /* Category palette — matched to the legend reference */
  --c-faith:    #8a1f2a;  /* deep maroon */
  --c-poverty:  #f0a3b4;  /* dusty pink */
  --c-youth:    #1f3a6b;  /* navy */
  --c-culture:  #e0a82e;  /* warm yellow */
  --c-env:      #2c6e3f;  /* forest green */
  --c-other:    #8a8378;  /* muted taupe */

  --shadow-sm: 0 1px 2px rgba(31,36,41,0.06);
  --shadow-md: 0 6px 16px rgba(31,36,41,0.08);
  --shadow-lg: 0 16px 32px rgba(31,36,41,0.12);
}

[data-theme='dark'] {
  --color-bg:            #161a1d;
  --color-surface:       #1c2126;
  --color-surface-2:     #232930;
  --color-surface-offset:#1a1f24;
  --color-border:        #2d343b;
  --color-divider:       #262c33;

  --color-text:          #e7e5e1;
  --color-text-muted:    #9aa3ad;
  --color-text-faint:    #6a737d;
  --color-text-inverse:  #161a1d;

  --color-primary:       #5fb0b6;
  --color-primary-hover: #7ec3c8;
  --color-primary-soft:  #1f3438;

  /* Slightly brightened categories for dark surfaces */
  --c-faith:    #c2455a;
  --c-poverty:  #e8a5b3;
  --c-youth:    #5c80c0;
  --c-culture:  #f0c14b;  /* warm yellow (dark theme) */
  --c-env:      #4e9a64;
  --c-other:    #a8a098;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 6px 16px rgba(0,0,0,0.4);
  --shadow-lg: 0 16px 32px rgba(0,0,0,0.5);
}

/* Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility; }
body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
button { background: none; border: none; cursor: pointer; font: inherit; color: inherit; }
input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; border-radius: var(--r-sm); }
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.875em; background: var(--color-surface-offset); padding: 0.1em 0.3em; border-radius: 3px; }

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-6);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}
.topbar__brand { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.logo {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border-radius: var(--r-md);
  flex-shrink: 0;
}
.logo svg { width: 22px; height: 22px; }
.topbar__titles { min-width: 0; }
.topbar h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-lg);
  line-height: 1.2;
  letter-spacing: -0.01em;
}
.subtitle {
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  margin-top: 2px;
}
.topbar__actions { display: flex; align-items: center; gap: var(--space-3); flex-shrink: 0; }
.counter {
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
  color: var(--color-text-muted);
  padding: var(--space-1) var(--space-3);
  background: var(--color-surface-offset);
  border-radius: var(--r-full);
  white-space: nowrap;
}
.theme-toggle {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: var(--r-md);
  color: var(--color-text-muted);
  transition: background var(--transition-interactive), color var(--transition-interactive);
}
.theme-toggle:hover { background: var(--color-surface-offset); color: var(--color-text); }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  flex: 1;
  min-height: 0;
}
@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { max-height: 45vh; }
  .topbar { padding: var(--space-2) var(--space-3); gap: var(--space-2); }
  .topbar h1 { font-size: var(--text-base); }
  .subtitle { display: none; }
  .counter { display: none; }
}

/* Sidebar */
.sidebar {
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.panel {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--r-lg);
  padding: var(--space-4);
}
.panel--muted { background: var(--color-surface-offset); }
.panel__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-base);
  margin-bottom: var(--space-3);
  letter-spacing: -0.005em;
}

.filter-group { margin-bottom: var(--space-4); }
.filter-group:last-of-type { margin-bottom: 0; }
.filter-label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-2);
}

#search {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--r-md);
  font-size: var(--text-sm);
  transition: border-color var(--transition-interactive);
}
#search:focus { outline: none; border-color: var(--color-primary); }
#search::placeholder { color: var(--color-text-faint); }

.chip-row { display: flex; flex-wrap: wrap; gap: var(--space-1); }
.chip-col { display: flex; flex-direction: column; gap: var(--space-1); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  font-size: var(--text-xs);
  font-weight: 500;
  background: var(--color-surface);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--r-full);
  transition: all var(--transition-interactive);
  white-space: nowrap;
}
.chip:hover { color: var(--color-text); border-color: var(--color-text-faint); }
.chip[data-active="true"] {
  background: var(--color-text);
  color: var(--color-text-inverse);
  border-color: var(--color-text);
}
.chip[data-active="false"] { opacity: 0.55; }
.chip--wide {
  justify-content: flex-start;
  padding: 6px 12px;
  white-space: normal;
  text-align: left;
  line-height: 1.3;
  font-size: 11px;
  border-radius: var(--r-md);
  width: 100%;
}
.chip-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Tenure glyphs in chips & legend */
.tenure-glyph {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}
.tenure-glyph--owner {
  background: currentColor;
}
.tenure-glyph--tenant {
  background: transparent;
  border: 2px solid currentColor;
}

.check {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  cursor: pointer;
}
.check input { width: 14px; height: 14px; accent-color: var(--color-primary); cursor: pointer; }
.check:hover { color: var(--color-text); }

.filter-actions { margin-top: var(--space-4); display: flex; gap: var(--space-2); }
.btn {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  font-weight: 600;
  border-radius: var(--r-md);
  transition: all var(--transition-interactive);
}
.btn--ghost {
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
}
.btn--ghost:hover { color: var(--color-text); border-color: var(--color-text-faint); background: var(--color-surface-offset); }

/* Legend */
.legend-heading {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-2);
  margin-top: var(--space-3);
}
.legend-heading:first-of-type { margin-top: 0; }

.legend {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.legend li {
  display: grid;
  grid-template-columns: 16px 1fr auto;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
}
.legend-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
}
.legend-dot--outlined {
  border: 1.5px solid var(--color-text);
}
.legend li strong { font-weight: 500; color: var(--color-text); }
.legend-count {
  font-variant-numeric: tabular-nums;
  color: var(--color-text-faint);
  font-size: 11px;
}
.legend-note {
  margin-top: var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  line-height: 1.5;
}
.legend-note strong { color: var(--color-text-muted); font-weight: 600; }

.prose {
  font-size: var(--text-xs);
  line-height: 1.6;
  color: var(--color-text-muted);
  margin-bottom: var(--space-2);
}
.prose:last-child { margin-bottom: 0; }
.prose.meta { color: var(--color-text-faint); font-style: italic; }
.prose strong { color: var(--color-text); font-weight: 600; }

/* Map */
.map-wrap { position: relative; }
#map { width: 100%; height: 100%; background: var(--color-surface-offset); }

/* Custom marker style — color = category, fill/ring = tenure */
.org-marker {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 120ms ease-out;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.org-marker:hover { transform: scale(1.3); z-index: 1000; }
/* OWNER: filled disk with subtle dark border for legibility on light tiles */
.org-marker--owner {
  border: 1.5px solid rgba(0,0,0,0.35);
}
/* TENANT: hollow ring with white center for clear contrast */
.org-marker--tenant {
  background: var(--color-surface-2) !important;
  border: 3px solid currentColor;
  /* category color is set inline as background; we override with surface for the centre */
}
/* Wrapper hack: we set background-color to the category color but for tenant we want
   the colour as the BORDER not the fill. So we use a CSS custom-property trick. */
.org-marker--low-precision { opacity: 0.7; border-style: dashed !important; }
[data-theme='dark'] .org-marker--tenant { background: var(--color-surface-2) !important; }

/* Popup */
.leaflet-popup-content-wrapper {
  background: var(--color-surface-2);
  color: var(--color-text);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  padding: 0;
}
.leaflet-popup-content {
  margin: 0;
  padding: var(--space-4);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  line-height: 1.5;
  width: 280px !important;
}
.leaflet-popup-tip { background: var(--color-surface-2); }

.popup__type {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-1);
}
.popup__name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-base);
  line-height: 1.25;
  margin-bottom: var(--space-2);
  color: var(--color-text);
}
.popup__badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: var(--space-3);
}
.popup__badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: var(--r-full);
  background: var(--color-surface-offset);
  color: var(--color-text);
}
.popup__badge .tenure-glyph { width: 9px; height: 9px; }
.popup__badge--owner  { background: color-mix(in srgb, var(--c-faith) 14%, transparent); color: var(--color-text); }
.popup__badge--tenant { background: color-mix(in srgb, var(--c-other) 18%, transparent); color: var(--color-text); }
.popup__badge--review { background: color-mix(in srgb, #c98a14 18%, transparent); color: #8a5f0e; }
[data-theme='dark'] .popup__badge--review { color: #e3b35a; }
.popup__badge--cat {
  background: color-mix(in srgb, var(--cat-color, var(--c-other)) 18%, transparent);
  color: var(--color-text);
}
.popup__badge--cat::before {
  content: '';
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--cat-color, var(--c-other));
  border: 1px solid color-mix(in srgb, var(--color-text) 30%, transparent);
}

.popup__row {
  display: flex;
  gap: var(--space-2);
  font-size: var(--text-xs);
  margin-bottom: var(--space-1);
}
.popup__row dt {
  color: var(--color-text-muted);
  min-width: 78px;
  flex-shrink: 0;
}
.popup__row dd { color: var(--color-text); word-break: break-word; }
.popup__rationale {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-divider);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  line-height: 1.5;
}
.popup__links {
  margin-top: var(--space-2);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  font-size: var(--text-xs);
}
.popup__links a { font-weight: 500; }

/* Cluster overrides */
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
  background: color-mix(in srgb, var(--color-primary) 25%, transparent);
}
.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
  background: var(--color-primary);
  color: var(--color-text-inverse);
  font-family: var(--font-body);
  font-weight: 600;
}

/* Leaflet attribution tweaks */
.leaflet-control-attribution {
  background: color-mix(in srgb, var(--color-surface) 90%, transparent) !important;
  color: var(--color-text-muted) !important;
  font-size: 10px !important;
}
.leaflet-control-attribution a { color: var(--color-primary) !important; }
.leaflet-bar a {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-bottom: 1px solid var(--color-border) !important;
}
.leaflet-bar a:hover { background: var(--color-surface-offset) !important; }

/* Dark-mode tile filter */
[data-theme='dark'] .leaflet-tile {
  filter: brightness(0.7) invert(1) contrast(0.95) hue-rotate(190deg) saturate(0.4) brightness(0.95);
}
