/* The web map's page (web map spec §3, §5, §6; plan Tasks 3 and 5). Self-contained: the site's tokens (--surface, --ink,
   --muted, --line, --shadow, --focus, --navy, --ground) come from website.css, everything the map adds is here.
   The marks are the app's (plan C6, IncidentMTL/Theme/Expo67.swift), named --mk-* so they never meet site.css's own
   --cat-* figures palette. Nothing here moves by itself: no animation, and transitions go with reduced motion. */

:root {
  --mk-mischief: #0047BB;
  --mk-breakAndEnter: #1B48BD;
  --mk-vehicleTheft: #3649BE;
  --mk-theftFromVehicle: #514AC0;
  --mk-robbery: #6C4BC1;
  --mk-offenceCausingDeath: #E5239D;
  --mk-fire: #00707C;
  --mk-medical: #6B70A8;
  --mk-needle: #8A6A12;
  --mk-homelessness: #6E5F3C;
  --mk-press: #2E2E36;
  --mk-ring: #fff;
  --mk-float: 0 2px 10px rgba(14, 27, 60, .18);
}

@media (prefers-color-scheme: dark) {
  :root {
    --mk-mischief: #3D6DFF;
    --mk-breakAndEnter: #4C6FE8;
    --mk-vehicleTheft: #5F71E8;
    --mk-theftFromVehicle: #7273E4;
    --mk-robbery: #8A6EE0;
    --mk-offenceCausingDeath: #F23DB0;
    --mk-fire: #2FA3B0;
    --mk-medical: #9BA0DB;
    --mk-needle: #8F6E13;
    --mk-homelessness: #756542;
    --mk-press: #3C3C46;
    --mk-float: 0 2px 12px rgba(0, 0, 0, .45);
  }
}

.map-shell [hidden] { display: none !important; }

/* MARK: The title. The map page's h1 is a compact title, not the site's hero, so the map starts on the first screen
   (fix pass 2, item 5): header 92 px + search band 82 px + this 60 px puts the map's top near 234 px on a 1440 x 900
   desktop; 78 + 104 + 56 near 238 px on a 390 x 844 phone. It overrides the site's global h1 (website.css). */

.map-title {
  width: var(--page, min(100% - 40px, 1180px));
  margin: 0 auto;
  padding: 16px 0 12px;
}

.map-title h1 {
  max-width: none;
  margin: 0;
  color: var(--navy);
  font-size: 1.5rem;
  font-weight: 900;
  line-height: 1.15;
  letter-spacing: -.02em;
  text-align: left;
}

@media (min-width: 761px) {
  .map-title h1 { font-size: 1.75rem; white-space: nowrap; }
}

/* MARK: The box. Full width. On a phone (up to 760 px) it leaves a strip of the page below it on the screen, so a
   finger always has somewhere to scroll the page from (fix pass 2, item 6); on a desktop 70 % of the viewport. */

.map-shell {
  position: relative;
  width: 100%;
  margin: 0;
  background: var(--surface-soft, #f2eee8);
}

#map-canvas {
  position: relative;
  width: 100%;
  height: clamp(420px, 68vh, 640px);
  height: clamp(420px, 68svh, 640px);
}

@media (min-width: 761px) {
  #map-canvas { height: clamp(480px, 70vh, 760px); }
}

/* Without a map the box holds one sentence, not a screen of nothing. */
.map-shell.is-fallback #map-canvas { height: auto; }
@media (scripting: none) {
  #map-canvas { height: auto; }
}

.map-fallback {
  margin: 0;
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
}

/* MARK: Controls over the map's top: the chips in one scrolling row, the lens beside them. */

.map-controls {
  position: absolute;
  z-index: 3;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 10px 0;
  pointer-events: none;
}

.map-controls > * { pointer-events: auto; }

.map-chips {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  gap: 6px;
  /* room for the focus ring inside the scroller */
  padding: 4px;
  margin: -4px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.map-chips::-webkit-scrollbar { display: none; }

/* While the row has more chips to its right, its right edge fades out (map.js toggles .has-more; fix pass 2, item 8).
   A mask, not a painted gradient, so it is right in both colour schemes. */
.map-chips.has-more {
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
}

.map-chip,
.map-chip-menu,
.map-lens button {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  margin: 0;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 750;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: var(--mk-float);
  -webkit-tap-highlight-color: transparent;
  transition: background-color .15s ease, color .15s ease;
}

.map-chip {
  --chip: var(--mk-mischief);
  gap: 7px;
  padding: 0 14px 0 12px;
  border-radius: 999px;
}

.map-chip[data-layer="fire"] { --chip: var(--mk-fire); }
.map-chip[data-layer="medical"] { --chip: var(--mk-medical); }
.map-chip[data-layer="311"] { --chip: var(--mk-needle); }
.map-chip[data-layer="news"] { --chip: var(--mk-press); }

/* Off: the layer's colour as a dot. On: the chip filled in it. */
.map-chip::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--chip);
  box-shadow: 0 0 0 1.5px var(--surface);
}

.map-chip[aria-pressed="true"] {
  border-color: var(--chip);
  background: var(--chip);
  color: #fff;
}

.map-chip[aria-pressed="true"]::before { background: #fff; box-shadow: none; }

.map-chip-label { font-variant-numeric: tabular-nums; }

/* The crime chip's menu button sits against it. */
.map-chip[data-layer="crime"] { border-radius: 999px 6px 6px 999px; }
.map-chip-menu {
  width: 44px;
  min-width: 44px;
  margin-left: -4px;
  padding: 0;
  border-radius: 6px 999px 999px 6px;
}

.map-chip-menu svg { width: 18px; height: 18px; transition: transform .15s ease; }
.map-chip-menu[aria-expanded="true"] svg { transform: rotate(180deg); }

/* The six categories, under the chips. */
#map-categories {
  position: absolute;
  z-index: 4;
  /* positioned in #map-controls, the row it opens from */
  top: calc(100% + 6px);
  left: 10px;
  width: min(300px, calc(100% - 20px));
  max-height: min(372px, 55vh);
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

#map-categories label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
}

#map-categories label:hover { background: var(--surface-soft, rgba(0, 0, 0, .04)); }

#map-categories input {
  width: 20px;
  height: 20px;
  margin: 0;
  flex: none;
  accent-color: var(--mk-mischief);
}

#map-categories label span::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--dot, var(--mk-mischief));
  vertical-align: 1px;
}

#map-categories label:has([data-category="breakAndEnter"]) { --dot: var(--mk-breakAndEnter); }
#map-categories label:has([data-category="vehicleTheft"]) { --dot: var(--mk-vehicleTheft); }
#map-categories label:has([data-category="theftFromVehicle"]) { --dot: var(--mk-theftFromVehicle); }
#map-categories label:has([data-category="robbery"]) { --dot: var(--mk-robbery); }
#map-categories label:has([data-category="offenceCausingDeath"]) { --dot: var(--mk-offenceCausingDeath); }

/* The window lens: a two-part switch. */
.map-lens {
  flex: none;
  display: flex;
  border-radius: 999px;
  box-shadow: var(--mk-float);
}

.map-lens button {
  min-width: 48px;
  padding: 0 12px;
  box-shadow: none;
  font-variant-numeric: tabular-nums;
}

.map-lens button:first-child { border-radius: 999px 0 0 999px; }
.map-lens button:last-child { border-radius: 0 999px 999px 0; margin-left: -1px; }

.map-lens button[aria-checked="true"] {
  border-color: var(--navy);
  background: var(--navy);
  color: var(--ground);
}

/* MARK: My location and the note. Both stay clear of Apple's logo (bottom left) and legal line (bottom right). */

.map-locate {
  position: absolute;
  z-index: 3;
  right: 10px;
  bottom: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px 0 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 750;
  cursor: pointer;
  box-shadow: var(--mk-float);
}

.map-locate svg { width: 18px; height: 18px; color: var(--cobalt-text, #0047bb); }

.map-note {
  position: absolute;
  z-index: 5;
  top: 66px;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  margin: 0;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--navy);
  color: var(--ground);
  font-size: 14px;
  font-weight: 650;
  line-height: 1.35;
  text-align: center;
  box-shadow: var(--mk-float);
}

/* MARK: Markers, drawn by MapKit from map.js's elements. */

.mk-marker,
.mk-cluster {
  --tint: var(--mk-mischief);
  box-sizing: border-box;
  display: grid;
  place-items: center;
  color: #fff;
  cursor: pointer;
}

.mk-marker {
  width: 30px;
  height: 30px;
  border: 2px solid var(--mk-ring);
  border-radius: 50%;
  background: var(--tint);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
}

.mk-marker svg { width: 16px; height: 16px; }

/* Crime's position is approximate: a soft ring of its own hue says so. */
.mk-marker.mk-halo {
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--tint) 24%, transparent), 0 1px 3px rgba(0, 0, 0, .35);
}

.mk-marker[data-selected="true"] {
  box-shadow: 0 0 0 3px var(--mk-ring), 0 0 0 6px var(--tint), 0 2px 6px rgba(0, 0, 0, .35);
}

.mk-cluster {
  width: 34px;
  height: 34px;
  padding: 0 2px;
  border: 2px solid var(--mk-ring);
  border-radius: 10px;
  background: var(--tint);
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
  line-height: 1;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
}

/* "999+" in the same square. */
.mk-cluster[data-long="true"] { font-size: 10px; letter-spacing: -.04em; }

[data-tint="crime"], [data-tint="mischief"] { --tint: var(--mk-mischief); }
[data-tint="breakAndEnter"] { --tint: var(--mk-breakAndEnter); }
[data-tint="vehicleTheft"] { --tint: var(--mk-vehicleTheft); }
[data-tint="theftFromVehicle"] { --tint: var(--mk-theftFromVehicle); }
[data-tint="robbery"] { --tint: var(--mk-robbery); }
[data-tint="offenceCausingDeath"] { --tint: var(--mk-offenceCausingDeath); }
[data-tint="fire"] { --tint: var(--mk-fire); }
[data-tint="medical"] { --tint: var(--mk-medical); }
[data-tint="needle"] { --tint: var(--mk-needle); }
[data-tint="homelessness"] { --tint: var(--mk-homelessness); }
[data-tint="news"] { --tint: var(--mk-press); }

/* MARK: The record panel: a floating bottom sheet on a phone, a card at the left on a desktop. */

.map-panel {
  position: absolute;
  z-index: 6;
  left: 8px;
  right: 8px;
  bottom: 36px;
  max-height: 60%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 18px 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.map-panel:focus { outline: none; }
.map-panel:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

@media (min-width: 761px) {
  .map-panel {
    top: 70px;
    right: auto;
    bottom: auto;
    left: 12px;
    width: 340px;
    max-height: calc(100% - 70px - 44px);
  }
}

.map-panel-close {
  position: absolute;
  top: 6px;
  right: 6px;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.map-panel-close:hover { background: var(--surface-soft, rgba(0, 0, 0, .05)); color: var(--ink); }
.map-panel-close svg { width: 20px; height: 20px; }

.map-panel-back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
  margin: -10px 0 4px -10px;
  padding: 0 10px 0 6px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--cobalt-text, #0047bb);
  font: inherit;
  font-size: 14px;
  font-weight: 750;
  cursor: pointer;
}

.map-panel-back svg { width: 18px; height: 18px; }

.map-panel-title {
  margin: 0;
  padding-right: 40px;
  color: var(--navy);
  font-size: 18px;
  font-weight: 850;
  line-height: 1.3;
  letter-spacing: -.01em;
  text-wrap: pretty;
}

.map-panel-line {
  margin: 6px 0 0;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
}

.map-panel-title + .map-panel-line { margin-top: 8px; }

.map-panel-location {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.map-panel-emergency {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.map-panel .map-panel-link {
  min-height: 44px;
  margin-top: 6px;
  font-size: 15px;
}

/* The list of records on one corner. */
.map-stack {
  margin: 10px -8px 0;
  padding: 0;
  list-style: none;
}

.map-stack li + li { border-top: 1px solid var(--line); }

.map-stack-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  width: 100%;
  min-height: 52px;
  margin: 0;
  padding: 9px 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.map-stack-row:hover { background: var(--surface-soft, rgba(0, 0, 0, .04)); }
.map-stack-title { font-size: 15px; font-weight: 750; line-height: 1.35; }
.map-stack-meta { color: var(--muted); font-size: 13px; line-height: 1.4; }

/* MARK: Focus, under the map, and motion. */

.map-shell :is(button, a, input, [tabindex]):focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.map-fine {
  width: var(--content, min(1180px, calc(100% - 40px)));
  margin: 10px auto 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.map-figures .map-figures-category th { padding-left: 1.5rem; font-weight: 400; }
.map-figures td.num { font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) {
  .map-shell *,
  .map-shell *::before { transition: none !important; }
}
