/* Map page v2 (/map/) - no canvas exists; built in the H language of the finished pages. Depends on tokens.css + components.css.
   Desktop: a 400px side panel beside a full-height map. Phones (<= 900px): the map fills the screen, the header goes,
   a round back button floats on the map and the panel becomes a bottom sheet (collapsed: count + Filters). Colours: tokens only. */

.cg-mapv2 { --cg-mp-header: 77px; --cg-mp-peek: calc(76px + env(safe-area-inset-bottom, 0px));
  position: relative; display: grid; grid-template-columns: 400px minmax(0, 1fr); height: calc(100vh - var(--cg-mp-header)); height: calc(100dvh - var(--cg-mp-header));
  min-height: 560px; background: var(--ground); }

/* ---- Side panel ------------------------------------------------------------------------------------ */
.cg-mp-panel { position: relative; z-index: 2; display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-right: 1px solid var(--border); }
.cg-mp-bar, .cg-mp-back { display: none; }
.cg-mp-body { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 18px; padding: 22px 20px 28px; }

.cg-mp-head { display: flex; flex-direction: column; gap: 4px; }
.cg-body a.cg-mp-head__city { display: inline-flex; align-items: center; align-self: flex-start; gap: 4px; min-height: 36px; margin: -6px 0 -2px -4px; padding: 0 8px 0 4px; border-radius: var(--radius-pill);
  font-size: 14px; font-weight: var(--w-strong); color: var(--ink-caption); }
.cg-body a.cg-mp-head__city:hover { color: var(--link); background: var(--surface-soft); }
.cg-mp-h1 { font: italic var(--w-regular) 38px/1.04 var(--font-display); letter-spacing: -.015em; overflow-wrap: anywhere; }
[data-theme="velvet"] .cg-mp-h1 { color: var(--heading); }
.cg-mp-count { margin: 0; font-size: 15px; font-weight: var(--w-strong); color: var(--ink-caption); }

/* City search */
.cg-mp-city { position: relative; display: flex; align-items: center; gap: 10px; flex: none; height: 46px; padding: 0 16px; border-radius: var(--radius-pill);
  border: 1.5px solid var(--border); background: var(--ground); color: var(--ink-caption); }
.cg-mp-city:focus-within { border-color: var(--accent); }
.cg-mp-city input { flex: 1; min-width: 0; height: 100%; border: 0; background: transparent; font: var(--w-strong) 15px/1 var(--font-sans); color: var(--ink); outline: none; }
.cg-mp-city input::placeholder { color: var(--ink-caption); font-weight: var(--w-regular); }
.cg-mp-cities { position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 20; list-style: none; margin: 0; padding: 6px; border-radius: var(--radius-m);
  background: var(--surface); box-shadow: var(--shadow-card); max-height: 50vh; overflow-y: auto; }
.cg-mp-cities li { display: flex; align-items: center; min-height: 44px; padding: 0 14px; border-radius: var(--radius-s); color: var(--ink); cursor: pointer; font-size: 15px; }
.cg-mp-cities li:hover, .cg-mp-cities li[aria-selected="true"] { background: var(--surface-soft); }

/* Category filters: checkboxes, like the category page's filters */
.cg-mp-filters { flex: none; }
.cg-mp-fold { border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.cg-mp-fold summary { display: flex; align-items: center; gap: 10px; min-height: 48px; cursor: pointer; list-style: none; font-size: 15px; }
.cg-mp-fold summary::-webkit-details-marker { display: none; }
.cg-mp-fold__t { flex: 1; font-weight: var(--w-strong); color: var(--ink); }
.cg-mp-fold__s { font-size: 13px; font-weight: var(--w-strong); color: var(--ink-caption); }
.cg-mp-fold summary .cg-icon { color: var(--ink-caption); transition: transform .15s; }
.cg-mp-fold[open] summary .cg-icon { transform: rotate(180deg); }
.cg-mp-checks { margin: 0; padding: 0 0 8px; border: 0; min-width: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.cg-mp-check { display: flex; align-items: center; gap: 10px; min-height: 38px; font-size: 15px; line-height: 1.25; cursor: pointer; min-width: 0; }
.cg-mp-check input { flex: none; width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
.cg-mp-check__t { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.cg-mp-check__n { flex: none; color: var(--ink-caption); font-size: 13px; font-weight: var(--w-strong); }
.cg-mp-filters__act { display: flex; align-items: center; gap: 14px; padding: 0 0 14px; }
.cg-body .cg-mp-apply { height: 44px; padding: 0 20px; font-size: 15px; }
body.cg-js .cg-mp-apply { display: none; }
.cg-body a.cg-mp-clear { display: inline-flex; align-items: center; min-height: 44px; font-size: 14px; font-weight: var(--w-strong); }

/* Place rows: compact, name over kind */
.cg-mp-list { display: flex; flex-direction: column; gap: 4px; }
.cg-mp-h2 { margin-bottom: 6px; font-size: 15px; font-weight: var(--w-strong); color: var(--ink-caption); }
.cg-mp-places { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.cg-mp-places li { position: relative; }
.cg-body a.cg-mp-row { display: flex; flex-direction: column; justify-content: center; gap: 1px; min-height: 52px; padding: 8px 52px 8px 12px; border-radius: var(--radius-s); color: var(--ink); }
.cg-body a.cg-mp-row:hover, .cg-mp-places li.is-hot > a.cg-mp-row { background: var(--surface-soft); color: var(--ink); }
.cg-mp-cities-list .cg-mp-places a.cg-mp-row { min-height: 46px; padding-right: 12px; }
.cg-mp-row__name { font-size: 16px; font-weight: var(--w-strong); line-height: 1.3; overflow-wrap: anywhere; }
.cg-mp-row__kind { font-size: 13px; color: var(--ink-caption); }
.cg-mp-row__go { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px;
  border: 0; border-radius: 50%; background: none; color: var(--ink-caption); }
.cg-mp-row__go:hover { background: var(--surface-soft); color: var(--accent); }
.cg-mp-more { margin: 4px 0 0; padding: 0 12px; font-size: 13px; line-height: 1.45; color: var(--ink-caption); }
.cg-mp-note { margin: 0; font-size: 13px; line-height: 1.5; color: var(--ink-caption); }
.cg-body .cg-mp-note a { font-weight: var(--w-strong); }
.cg-mp-empty { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; padding: 18px 20px; border-radius: var(--radius-l); background: var(--surface-warm); }
.cg-mp-empty p { margin: 0; font-size: 15px; }

/* ---- Map -------------------------------------------------------------------------------------------- */
.cg-mp-mapwrap { position: relative; min-width: 0; min-height: 0; background: var(--map); }
.cg-mp-map { position: absolute; inset: 0; }
.cg-mp-noscript { position: absolute; left: 16px; top: 16px; margin: 0; padding: 10px 16px; border-radius: var(--radius-pill); background: var(--surface); box-shadow: var(--shadow-card); font-size: 14px; }
.cg-mp-map .cg-npin { position: relative; }
.cg-mp-map .cg-npin::after { content: ""; position: absolute; inset: -10px; }
/* Clusters: a soft halo rather than a wall of solid discs; bigger groups a little larger and deeper. Sizes match the
   iconSize in map.js. ".cg-mp-map" in front because Leaflet's own .leaflet-marker-icon { display: block } would otherwise
   win and push the number into the top-left corner. */
.cg-mp-map .cg-mp-cluster { display: flex; align-items: center; justify-content: center; width: 30px !important; height: 30px !important; border-radius: 50%;
  background: rgba(208, 21, 122, .82); color: #fff; border: 0; box-shadow: 0 0 0 6px rgba(208, 21, 122, .22), 0 4px 10px rgba(61, 15, 36, .25);
  font: var(--w-strong) 13px/1 var(--font-sans); cursor: pointer; }
.cg-mp-map .cg-mp-cluster--m { width: 38px !important; height: 38px !important; font-size: 14px; background: rgba(190, 16, 110, .9);
  box-shadow: 0 0 0 8px rgba(208, 21, 122, .22), 0 4px 10px rgba(61, 15, 36, .25); }
.cg-mp-map .cg-mp-cluster--l { width: 46px !important; height: 46px !important; font-size: 15px; background: #a80f62;
  box-shadow: 0 0 0 10px rgba(208, 21, 122, .24), 0 4px 12px rgba(61, 15, 36, .3); }
/* A calmer, slightly warm base map, so the pink is the only strong colour on it. */
.cg-mp-map .leaflet-tile-pane { filter: saturate(.25) brightness(1.06) contrast(.92) sepia(.12); }
/* Hover cards (desktop): a pin's name and kind; a cluster's count by category. */
.cg-mp-map .leaflet-tooltip.cg-mp-tip { padding: 0; border: 0; border-radius: 14px; background: var(--surface); color: var(--ink);
  box-shadow: 0 14px 34px -12px rgba(61, 15, 36, .45); white-space: normal; }
.cg-mp-map .leaflet-tooltip-top.cg-mp-tip::before { border-top-color: var(--surface); }
.cg-mp-tipbox { display: flex; flex-direction: column; gap: 2px; min-width: 150px; max-width: 240px; padding: 10px 12px; font: 13px/1.35 var(--font-sans); }
.cg-mp-tipbox b { font-size: 14px; font-weight: var(--w-strong); color: var(--ink); }
.cg-mp-tipbox > span { color: var(--ink-caption); }
.cg-mp-tipbox .cg-mp-tipbox__n { font: italic var(--w-regular) 20px/1.1 var(--font-display); margin-bottom: 4px; }
.cg-mp-tipbox .cg-mp-tipbox__row { display: flex; justify-content: space-between; gap: 16px; }
.cg-mp-tipbox__row span:last-child { color: var(--ink); font-weight: var(--w-strong); }
.cg-mp-tipbox .cg-mp-tipbox__go { margin-top: 6px; color: var(--link); font-weight: var(--w-strong); }
.cg-mp-map .leaflet-popup-content-wrapper, .cg-mp-map .leaflet-popup-tip { background: var(--surface); color: var(--ink); }
.cg-mp-map .leaflet-popup-close-button { color: var(--ink-caption); }
.cg-mp-map .leaflet-popup-content .cg-mp-kind { display: block; font-size: 13px; color: var(--ink-caption); }

/* ---- Phones ----------------------------------------------------------------------------------------- */
@media (max-width: 900px) {
  body.cg-page-map .cg-top { display: none; }
  .cg-mapv2 { display: block; height: 100vh; height: 100dvh; min-height: 480px; overflow: hidden; }
  .cg-mp-mapwrap { position: absolute; inset: 0; }
  .cg-mp-map .leaflet-control-zoom { display: none; }
  .cg-mp-map .leaflet-bottom { bottom: var(--cg-mp-peek); }
  .cg-mp-map .leaflet-control-attribution { font-size: 10px; }

  .cg-body a.cg-mp-back { display: inline-flex; align-items: center; justify-content: center; position: absolute; z-index: 5; left: 12px; top: calc(12px + env(safe-area-inset-top, 0px));
    width: 44px; height: 44px; border-radius: 50%; background: var(--surface); color: var(--ink); box-shadow: var(--shadow-card); }

  /* Bottom sheet */
  .cg-mp-panel { position: absolute; left: 0; right: 0; bottom: 0; z-index: 6; height: min(86%, 680px); border-right: 0; border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: 0 -12px 36px -10px rgba(40, 8, 24, .45); transform: translateY(calc(100% - var(--cg-mp-peek))); transition: transform .25s ease; will-change: transform; }
  .cg-mp-panel.is-open { transform: none; }
  .cg-mp-panel:not(.is-open) .cg-mp-body { visibility: hidden; }
  .cg-mp-bar { display: flex; align-items: center; gap: 10px; flex: none; height: 76px; padding: 14px var(--gutter) 0; padding-bottom: env(safe-area-inset-bottom, 0px); }
  .cg-mp-panel.is-open .cg-mp-bar { height: 62px; padding-bottom: 0; }
  .cg-mp-bar__grab { position: relative; flex: 1; align-self: stretch; min-width: 0; padding: 12px 0 0; border: 0; background: none; text-align: left; }
  .cg-mp-bar__handle { position: absolute; left: 0; top: 0; width: 44px; height: 5px; border-radius: var(--radius-pill); background: var(--border); }
  .cg-mp-bar__count { display: block; font-size: 17px; font-weight: var(--w-strong); color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .cg-mp-bar__filters { flex: none; display: inline-flex; align-items: center; gap: 8px; height: 44px; padding: 0 16px; border-radius: var(--radius-pill);
    border: 1.5px solid var(--border); background: var(--surface); color: var(--ink); font-size: 15px; font-weight: var(--w-strong); white-space: nowrap; }
  .cg-mp-bar__n { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: var(--radius-pill); background: var(--ink); color: var(--surface); font-size: 13px; }

  .cg-mp-body { padding: 4px var(--gutter) calc(24px + env(safe-area-inset-bottom, 0px)); gap: 16px; }
  .cg-mp-h1 { font-size: 30px; }
  .cg-mp-head .cg-mp-count { display: none; } /* the sheet bar carries the count */
  .cg-mp-checks { grid-template-columns: 1fr; }
  .cg-mp-check { min-height: 44px; }
  .cg-mp-check input { width: 20px; height: 20px; }

  /* Without script there is no map: the panel is a plain page. */
  body:not(.cg-js) .cg-mapv2 { height: auto; overflow: visible; }
  body:not(.cg-js) .cg-mp-mapwrap, body:not(.cg-js) .cg-mp-back, body:not(.cg-js) .cg-mp-bar { display: none; }
  body:not(.cg-js) .cg-mp-panel { position: static; height: auto; transform: none; border-radius: 0; box-shadow: none; }
  body:not(.cg-js) .cg-mp-panel .cg-mp-body { visibility: visible; }
  body.cg-page-map .cg-footer .cg-wrap { padding-top: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .cg-mp-panel { transition: none; }
}
