/* ==========================================================================
   Leaflet theming — controls, attribution and custom markers must follow
   the application theme. Map TILES stay provider-styled on purpose; the
   basemap choice is independent from the light/dark appearance.
   ========================================================================== */

.leaflet-container {
  font: inherit;
  background: var(--surface-muted);
}

/* The zoom pair keeps Leaflet's single two-anchor bar — the bordered
   vertical column with the internal divider, unchanged in structure and
   size. Its COLORS are not decided here: js/map/mapView.js puts the shared
   .btn/.btn-elevated classes on the two anchors — the same component
   classes that color the #map-fit column — so both themes always follow
   one source (hover border deepen, :active, the 120ms transition all ride
   along). This file owns only the bar's geometry and frame.
   vendor/leaflet/leaflet.css sits in @layer leaflet, so these unlayered
   rules win the vendor cascade regardless of specificity — the
   .leaflet-touch variants (30px boxes, 2px radii, touch shadow) included,
   which used to out-rank the un-important geometry on touch machines. */
.leaflet-control-zoom {
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-1);
  /* 不用 overflow:hidden 裁锚点：那会连触屏热区扩展一起裁掉，
     首尾锚点自己圆到组的圆角（Leaflet 原生只有 4px，跟不上令牌）。 */
}

/* Hovering either anchor deepens the shared frame — the group-frame
   equivalent of .btn:hover's border-color. */
.leaflet-control-zoom:has(.btn:hover) {
  border-color: var(--border-strong);
}

/* The zoom bar's right edge lines up with the #map-fit button column above
   (both 12px off the pane edge); Leaflet's default margin is 10px. */
.leaflet-bottom.leaflet-right .leaflet-control-zoom {
  margin-inline-end: 12px;
}

/* Geometry only: the frame owns the border and radius, and the anchors keep
   the vendor 32px squares (.btn's 34px height, padding, inline-flex display
   and per-button border do not apply inside the bar). Leaflet's glyphs are
   bold monospace text characters — font-size 0 vacates them (and the
   .leaflet-touch 22px bump) for the ::before masks below. Flex centering is
   load-bearing: a block anchor would let the ::before's vertical margins
   collapse through it (no padding/border to stop them) and blow an 8px
   transparent gap under the group's top border — the map shows through.
   box-shadow: none strips .btn-elevated's per-anchor halo, which would smear
   around each square inside the column; upstream clips child shadows with
   the group's overflow:hidden, which the coarse hit-area extension forbids
   here — the frame carries the one shadow. */
.leaflet-control-zoom .btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  font-size: 0;
}

/* The outer corners round to the group's token radius. The divider is the
   one border an anchor carries, so it rides here to out-rank the
   geometry's border: 0 above. */
.leaflet-control-zoom a.leaflet-control-zoom-in {
  border-start-start-radius: var(--radius-m);
  border-start-end-radius: var(--radius-m);
}

.leaflet-control-zoom a.leaflet-control-zoom-out {
  border-end-start-radius: var(--radius-m);
  border-end-end-radius: var(--radius-m);
  border-block-start: 1px solid var(--border);
}

/* The zoom glyphs join the app's Lucide icon family (plus/minus, 24-grid,
   2px stroke — same set the #map-fit buttons use) via a mask so they take
   the themed `color`. The stroke color in the data URI is inert — a mask
   only reads alpha. ::after stays free for the coarse hit-area extension. */
.leaflet-control-zoom a::before {
  content: "";
  display: block;
  width: 16px;
  height: 16px;
  background-color: currentColor;
}

.leaflet-control-zoom a.leaflet-control-zoom-in::before {
  -webkit-mask: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12h14'/%3E%3Cpath d='M12 5v14'/%3E%3C/svg%3E") center / 16px 16px no-repeat;
  mask: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12h14'/%3E%3Cpath d='M12 5v14'/%3E%3C/svg%3E") center / 16px 16px no-repeat;
}

.leaflet-control-zoom a.leaflet-control-zoom-out::before {
  -webkit-mask: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12h14'/%3E%3C/svg%3E") center / 16px 16px no-repeat;
  mask: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12h14'/%3E%3C/svg%3E") center / 16px 16px no-repeat;
}

/* 触屏热区扩展：32px 缩放钮加 7px 透明边距到 46px（≥44px 触屏惯例，inset
   相对 padding box，几何化后锚点自身不带边框），视觉不变；后绘的
   zoom-out 自身盒子压过 zoom-in 的扩展区，接缝命中不互换。 */
@media (hover: none) and (pointer: coarse) {
  .leaflet-control-zoom a { position: relative; }
  .leaflet-control-zoom a::after { content: ""; position: absolute; inset: -7px; }
}

.leaflet-control-attribution {
  background: color-mix(in srgb, var(--surface-elevated) 86%, transparent) !important;
  color: var(--foreground-faint) !important;
  font-size: 10.5px !important;
  padding: 2px 7px !important;
  border-start-start-radius: var(--radius-s);
  /* Upstream's MapLibre attribution inherits the body's 1.45 line-height
     (its vendor css pins none on the element), so the zoom bar stacked above
     it sits at a fixed offset from the pane bottom. Leaflet's vendor pins 1.4
     right here (leaflet.css .leaflet-control-attribution rule) — at the shared
     10.5px font that shrank the line box by 0.525px and sat the whole corner
     stack visibly lower. Match the body value. */
  line-height: 1.45;
}

.leaflet-control-attribution a { color: var(--foreground-muted) !important; }

.leaflet-control-scale-line {
  background: color-mix(in srgb, var(--surface-elevated) 80%, transparent) !important;
  border-color: var(--border-strong) !important;
  color: var(--foreground-muted) !important;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: var(--surface-elevated);
  color: var(--foreground);
  box-shadow: var(--shadow-1);
}

.leaflet-popup-content { margin: 10px 14px; font: inherit; }

/* Sector boundary handles ---------------------------------------------------- */

.map-handle-icon { background: none; border: none; touch-action: none; }

.map-handle {
  width: 22px;
  height: 22px;
  border-radius: 8px;
  background: var(--handle-color, var(--accent));
  border: 2.5px solid var(--map-handle-border);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
}

.map-handle:active { cursor: grabbing; }

/* Enlarged invisible hit area for touch. */
.map-handle::after {
  content: "";
  position: absolute;
  inset: -14px;
}

.map-handle-grip {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--handle-core);
}

.leaflet-marker-icon.map-handle-icon:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* Hover dot (profile ⇄ map sync) --------------------------------------------- */

.hover-dot-icon { background: none; border: none; }

.hover-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 2.5px solid var(--map-handle-border);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25), 0 1px 4px rgba(0, 0, 0, 0.3);
}

/* Waypoints (GPX <wpt>) ------------------------------------------------------- */

.map-waypoint-icon { background: none; border: none; }

.map-waypoint {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--waypoint-color, var(--accent));
  border: 2.5px solid var(--map-handle-border);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25), 0 1px 4px rgba(0, 0, 0, 0.3);
}

/* The pinned waypoint (js/map/mapView.js adds a lucide pin glyph when the
   profile reports the pin): the glyph OVERLAYS the circle — the circle
   keeps its full styling — with its purple fill and its outline + needle
   in the waypoint border color, no extra ring or shadow of its own. The
   needle is elongated so the body clears the circle's top edge by 3px, and
   the whole glyph is enlarged for a chunkier body. It anchors at its
   bottom tip: the needle's round-capped tip sits at (50%, 96.15%) of the
   20×26 box, so the translate plants that point (not the box center)
   exactly on the 50%/50% origin — the circle's center; symmetric borders
   keep the 50% origin on the center at any width. */
.map-waypoint-icon.is-pinned .map-waypoint {
  position: relative;
}

.map-waypoint-icon.is-pinned .map-waypoint svg {
  position: absolute;
  display: block;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -96.1538%);
}

/* Enlarged invisible hit area for touch, so the tooltip is reachable. */
.map-waypoint::after {
  content: "";
  position: absolute;
  inset: -12px;
}

/* Waypoint markers are keyboard buttons (Tab + Enter/Space, js/map/mapView.js):
   focus wears the app's focus ring like the map handles; the name tooltip
   itself opens from the focus handler. */
.leaflet-marker-icon.map-waypoint-icon:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* The waypoint name tooltip follows the theme like every other floating
   surface — Leaflet's stock plate is hard-coded white with #222 text and
   ignores the dark theme (the geometry, shadow and caret stay Leaflet's).
   The caret takes the plate's background so the V descends seamlessly in
   both themes; tooltip-top is the only direction in use (the sole
   bindTooltip call). */
.leaflet-tooltip {
  background-color: var(--surface-elevated);
  border: 1px solid var(--border);
  color: var(--foreground);
}

.leaflet-tooltip-top:before {
  border-top-color: var(--surface-elevated);
}

/* Cooperative-gestures hint (touch devices): one finger scrolls the page,
   two fingers move the map. Purely informational — never blocks touches. */

.map-gesture-hint {
  position: absolute;
  inset-block-start: 50%;
  inset-inline: 0;
  margin-inline: auto;
  transform: translateY(-50%);
  width: fit-content;
  max-width: min(88%, 320px);
  z-index: var(--z-overlay);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-1);
  color: var(--foreground);
  font-size: 13px;
  font-weight: 550;
  pointer-events: none;
}

.map-gesture-hint .icon { width: 16px; height: 16px; color: var(--accent); flex: none; }
