/* Maps (Leaflet fallback + shared marker / control chrome for both providers). Tokens only, flat colours, no gradients.
   Loaded through {% maps_scripts %}; the dark tile filter applies to the tile pane only (markers, routes and zones keep their colours). */

/* ---- container: a stacking context of its own, so panes (z-index up to 1000) can never climb over the sticky header, ribbon, bottom nav, sheets or toasts */
.leaflet-container, .bgm { position: relative; z-index: 0; isolation: isolate; background: var(--surface-2); font-family: var(--font, inherit); color: var(--ink); outline: 0; -webkit-tap-highlight-color: transparent; }
.bgm-min { min-height: 240px; }
.leaflet-container:focus-visible { outline: 2px solid var(--focus, var(--brand)); outline-offset: -2px; }
/* one finger scrolls the page over view-only maps (two fingers move the map); interactive pickers keep Leaflet's own touch handling */
.leaflet-container.bgm-coop.leaflet-touch-drag, .leaflet-container.bgm-coop.leaflet-touch-drag.leaflet-touch-zoom { touch-action: pan-x pan-y; }

/* ---- tiles in light theme: slightly softer than raw OpenStreetMap so the brand pin and zone colours stand out */
.leaflet-tile-pane { filter: saturate(.82) contrast(.97) brightness(1.02); }

/* ---- tiles in dark theme: invert + hue-rotate keeps water blue and roads light on a dark ground */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.9) saturate(.75); }
}
:root[data-theme="dark"] .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.9) saturate(.75); }

/* ---- controls: 44px tap targets, bottom-right zoom, bottom-left attribution */
.leaflet-touch .leaflet-bar, .leaflet-bar { border: 1px solid var(--line); border-radius: var(--r-m, 12px); box-shadow: 0 2px 8px rgba(0, 0, 0, .16); overflow: hidden; background: var(--surface); }
.leaflet-bar a, .leaflet-touch .leaflet-bar a { width: 44px; height: 44px; line-height: 44px; font-size: 22px; font-weight: 400; color: var(--ink); background: var(--surface); border-bottom: 1px solid var(--line); text-indent: 0; }
.leaflet-bar a:last-child { border-bottom: 0; }
.leaflet-bar a:hover, .leaflet-bar a:focus-visible { background: var(--surface-2); color: var(--ink); }
.leaflet-bar a.leaflet-disabled { color: var(--muted); background: var(--surface-2); cursor: default; }
.leaflet-bottom.leaflet-right .leaflet-control { margin-right: 12px; margin-bottom: 12px; }
.leaflet-bottom.leaflet-left .leaflet-control-attribution { margin: 0; }
.leaflet-container .leaflet-control-attribution { background: var(--surface); color: var(--muted); font-size: 11px; line-height: 1.5; padding: 1px 6px; white-space: nowrap; border-radius: 0 6px 0 0; opacity: .92; }
.leaflet-control-attribution a { color: var(--ink-2); text-decoration: underline; }
.leaflet-top.leaflet-left .leaflet-control { margin-top: 12px; margin-left: 12px; }

/* ---- markers (the Leaflet icon box has the real size and anchor; the inner element fills it) */
.bgm-ic { background: none; border: 0; }
.bgm-ic .pin, .bgm-ic .pmark, .bgm-ic .pdot { margin: 0; }
.bgm-ic-dot { display: grid; place-items: center; }
.bgm-ic .pin { filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .28)); }
.bgm-ic .pin.act { color: var(--ok); } .bgm-ic .pin.warn { color: var(--warn); } .bgm-ic .pin.bad { color: var(--bad); } .bgm-ic .pin.off { color: var(--muted); } .bgm-ic .pin.job { color: var(--brand); }
.pmark { box-shadow: 0 1px 4px rgba(0, 0, 0, .3); }
.pmark.act { background: var(--ok); color: var(--surface); } .pmark.warn { background: var(--warn); color: var(--surface); } .pmark.bad { background: var(--bad); color: var(--surface); } .pmark.off { background: var(--muted); color: var(--surface); }
.pmark .bgm-head { display: none; position: absolute; inset: -9px; pointer-events: none; transform: rotate(var(--heading, 0deg)); transition: transform .5s linear; }
.pmark[data-heading] .bgm-head { display: block; }
.pmark .bgm-head::before { content: ""; position: absolute; left: 50%; top: -1px; margin-left: -5px; border: 5px solid transparent; border-bottom: 8px solid var(--ink); border-top-width: 0; }
.pcluster { width: 46px; height: 46px; border-radius: 50%; background: var(--ink); color: var(--bg); border: 3px solid var(--surface); display: grid; place-items: center; font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; box-shadow: 0 1px 5px rgba(0, 0, 0, .3); cursor: pointer; }
.leaflet-marker-icon:focus-visible { outline: 2px solid var(--focus, var(--brand)); outline-offset: 2px; border-radius: 8px; }
.leaflet-marker-icon.bgm-ic-pin:focus-visible { border-radius: 14px 14px 4px 4px; }

/* ---- zone editor handles: visible dot 16px inside a 44px hit area */
.bgm-vtx i, .bgm-mid i { display: block; border-radius: 50%; box-sizing: border-box; }
.bgm-vtx i { width: 18px; height: 18px; margin: 13px; background: var(--brand); border: 3px solid var(--surface); box-shadow: 0 1px 4px rgba(0, 0, 0, .35); }
.bgm-mid i { width: 12px; height: 12px; margin: 16px; background: var(--surface); border: 2px solid var(--brand); }
.bgm-vtx:focus-visible i { outline: 2px solid var(--focus, var(--brand)); outline-offset: 2px; }
.leaflet-marker-draggable { cursor: grab; } .leaflet-marker-draggable:active { cursor: grabbing; }

/* ---- popups */
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--ink); box-shadow: 0 4px 16px rgba(0, 0, 0, .22); }
.leaflet-popup-content-wrapper { border-radius: var(--r-m, 12px); }
.leaflet-popup-content { margin: 12px 16px; font-size: 14px; line-height: 1.45; }
.leaflet-popup-content a { color: var(--brand); font-weight: 600; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); width: 36px; height: 36px; font-size: 20px; line-height: 36px; padding: 0; text-align: center; }

/* ---- floating UI inside the map: hints, notes, recenter, centre pin */
.bgm-hint { position: absolute; left: 50%; top: 50%; z-index: 1100; transform: translate(-50%, -50%); max-width: calc(100% - 32px); padding: 9px 16px; border-radius: 999px; background: var(--ink); color: var(--bg); font-size: 13.5px; font-weight: 600; text-align: center; opacity: 0; pointer-events: none; transition: opacity .15s; }
.bgm-hint.on { opacity: .96; }
.bgm-note { position: absolute; left: 50%; top: 10px; z-index: 1050; transform: translateX(-50%); max-width: calc(100% - 24px); padding: 5px 12px; border-radius: 999px; background: var(--surface); color: var(--ink-2); border: 1px solid var(--line); font-size: 12.5px; text-align: center; box-shadow: 0 1px 4px rgba(0, 0, 0, .14); pointer-events: none; }
.bgm-note:has(.bgm-note-btn) { pointer-events: auto; }
.bgm-note-btn { margin-left: 8px; padding: 0 2px; min-height: 28px; border: 0; background: transparent; color: var(--brand); font: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; }
.bgm-recenter { position: absolute; left: 12px; top: 12px; z-index: 1000; display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 16px 0 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink); font: inherit; font-size: 14px; font-weight: 600; box-shadow: 0 2px 8px rgba(0, 0, 0, .18); cursor: pointer; }
.bgm-recenter[hidden] { display: none; }
.bgm-recenter:hover { background: var(--surface-2); }
.bgm-recenter:focus-visible { outline: 2px solid var(--focus, var(--brand)); outline-offset: 2px; }
.bgm-cpin { position: absolute; left: 50%; top: 50%; z-index: 900; width: 34px; height: 42px; margin: -42px 0 0 -17px; color: var(--brand); pointer-events: none; transition: transform .16s ease-out; }
.bgm-cpin svg { display: block; width: 34px; height: 42px; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .28)); }
.bgm-cpin i { position: absolute; left: 50%; top: 100%; width: 12px; height: 5px; margin: -3px 0 0 -6px; border-radius: 50%; background: var(--ink); opacity: .28; transition: transform .16s ease-out, opacity .16s; }
.bgm-moving .bgm-cpin { transform: translateY(-10px); }
.bgm-moving .bgm-cpin i { transform: scale(.6); opacity: .18; }
/* the checkout / address pickers draw their own pin beside the map: lift it while the map is dragged */
.bk-pinwrap .bk-pin { transition: transform .16s ease-out; }
.bk-pinwrap:has(.bgm-moving) .bk-pin { transform: translate(-50%, calc(-100% - 10px)); }

/* ---- Google provider: keep its chrome clear of ours */
.bgm-google .gm-style .gm-style-cc { font-size: 10px; }

@media (prefers-reduced-motion: reduce) {
  .bgm-cpin, .bgm-cpin i, .bk-pinwrap .bk-pin, .bgm-hint, .pmark .bgm-head { transition: none; }
  .leaflet-fade-anim .leaflet-tile, .leaflet-zoom-anim .leaflet-zoom-animated { transition: none !important; }
}
@media (forced-colors: active) {
  .bgm-vtx i, .bgm-mid i, .pcluster { forced-color-adjust: none; }
}

/* ---- place-search combobox (BG.maps.combobox): used by checkout and the location sheet */
.bgcb-opt { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 8px 12px; border-radius: 10px; cursor: pointer; list-style: none; }
.bgcb-opt.on, .bgcb-opt:hover { background: var(--surface-2, rgba(128, 128, 128, .14)); }
.bgcb-opt .bgcb-ic { flex: none; width: 28px; text-align: center; opacity: .75; }
.bgcb-opt .bgcb-t { display: grid; min-width: 0; }
.bgcb-opt .bgcb-t b { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bgcb-opt .bgcb-t small { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bgcb-opt.recent .bgcb-ic { color: var(--brand); }
.bgcb-note { list-style: none; padding: 12px; font-size: 14px; color: var(--muted); }
.bgcb-opt .lsx-row { min-height: 0; padding: 0; pointer-events: none; }
@media (forced-colors: active) { .bgcb-opt.on { outline: 2px solid Highlight; } }

/* ---- place-search combobox: results list, rows with a place-type icon, recents */
.bgcb-host { position: relative; }
.bgcb-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 1200; margin: 0; padding: 6px; max-height: min(340px, 52vh); overflow: auto; list-style: none; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 10px 28px rgba(0, 0, 0, .24); overscroll-behavior: contain; }
.bgcb-list[hidden] { display: none; }
.bgcb-note { padding: 12px; color: var(--muted); font-size: 14px; list-style: none; }
.bgcb-opt .bgcb-ic { display: grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: 50%; background: var(--surface-2, rgba(128, 128, 128, .14)); color: var(--ink-2, var(--ink)); opacity: 1; }
.bgcb-opt .bgcb-ic .i { width: 18px; height: 18px; }
.bgcb-opt .bgcb-t small { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bgcb-opt .bgcb-kind { margin-left: 8px; padding: 1px 7px; border-radius: 999px; font-style: normal; font-weight: 600; font-size: 11px; letter-spacing: .02em; vertical-align: 1px; background: var(--surface-2, rgba(128, 128, 128, .14)); color: var(--muted); }
.bgcb-opt.recent .bgcb-ic { background: transparent; border: 1px dashed var(--line); }
/* place types get a tint so a bank, a hospital and a temple read apart at a glance (green / amber / red fall back to the brand colour until the palette tokens exist) */
.bgcb-k-health .bgcb-ic { color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, transparent); }
.bgcb-k-bank .bgcb-ic, .bgcb-k-shop .bgcb-ic { color: var(--warn); background: color-mix(in srgb, var(--warn) 16%, transparent); }
.bgcb-k-park .bgcb-ic, .bgcb-k-school .bgcb-ic, .bgcb-k-area .bgcb-ic { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.bgcb-k-gps .bgcb-ic { color: var(--brand); background: color-mix(in srgb, var(--brand) 14%, transparent); }

/* numbered pin (eg. the partner's request list): the number sits in the round head of the pin */
.pin { position: relative; }
.pin .pin-n { position: absolute; left: 0; right: 0; top: 7px; text-align: center; font: 800 13px/18px var(--font, system-ui, sans-serif); color: currentColor; pointer-events: none; font-variant-numeric: tabular-nums; }

/* ---- thumb-friendly controls: 48px targets on touch screens */
@media (pointer: coarse) {
  .leaflet-bar a, .leaflet-touch .leaflet-bar a { width: 48px; height: 48px; line-height: 48px; font-size: 24px; }
  .bgm-recenter { min-height: 48px; }
  .leaflet-container a.leaflet-popup-close-button { width: 44px; height: 44px; line-height: 44px; }
}

/* ---- full-screen map (view-only maps get a corner button; Escape or Close returns) */
.bgm-expand { position: absolute; right: 12px; top: 12px; z-index: 1000; display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px 0 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink); font: inherit; font-size: 14px; font-weight: 700; box-shadow: 0 2px 8px rgba(0, 0, 0, .16); cursor: pointer; white-space: nowrap; box-sizing: border-box; max-width: calc(100% - 24px); min-width: 44px; justify-content: center; }
.bgm-expand > span { overflow: hidden; text-overflow: ellipsis; }
.bgm-expand:hover { background: var(--surface-2); }
.bgm-expand:focus-visible { outline: 2px solid var(--focus, var(--brand)); outline-offset: 2px; }
@media (pointer: coarse) { .bgm-expand { min-height: 48px; } }
.bgm.bgm-full, .leaflet-container.bgm-full { position: fixed !important; inset: 0 !important; z-index: 2000 !important; width: 100% !important; height: 100% !important; max-height: none !important; border-radius: 0 !important; margin: 0 !important; }
.bgm-full .bgm-expand { top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); background: var(--ink); color: var(--bg); border-color: var(--ink); }
.bgm-full .leaflet-bottom.leaflet-right .leaflet-control { margin-bottom: max(16px, env(safe-area-inset-bottom)); }
html.bgm-lock { overflow: hidden; }

/* ---- high contrast tiles: greyscale + stronger contrast so roads and labels stand out (the toggle remembers; so does the system setting) */
.bgm-hc .leaflet-tile-pane { filter: grayscale(1) contrast(1.5) brightness(1.04) !important; }
:root[data-theme="dark"] .bgm-hc .leaflet-tile-pane { filter: grayscale(1) invert(1) contrast(1.35) brightness(.95) !important; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .bgm-hc .leaflet-tile-pane { filter: grayscale(1) invert(1) contrast(1.35) brightness(.95) !important; } }
@media (prefers-contrast: more) {
  .leaflet-tile-pane { filter: grayscale(1) contrast(1.5) brightness(1.04); }
  .leaflet-bar, .bgm-recenter, .bgm-expand { border: 2px solid var(--ink); }
}

/* ---- marker status is never colour alone: a glyph sits in the pin head (check = active, ! = needs attention, x = problem) */
.bgm-ic .pin { position: relative; }
.bgm-ic .pin.act::after, .bgm-ic .pin.warn::after, .bgm-ic .pin.bad::after { position: absolute; left: 50%; top: 39%; transform: translate(-50%, -50%); font: 800 11px/1 system-ui, sans-serif; color: currentColor; pointer-events: none; }
.bgm-ic .pin.act::after { content: "\2713"; } .bgm-ic .pin.warn::after { content: "!"; } .bgm-ic .pin.bad::after { content: "\00d7"; font-size: 14px; }
.pmark.act::after, .pmark.warn::after, .pmark.bad::after { position: absolute; right: -4px; top: -4px; width: 14px; height: 14px; border-radius: 50%; background: var(--surface); color: var(--ink); display: grid; place-items: center; font: 800 10px/14px system-ui, sans-serif; text-align: center; box-shadow: 0 0 0 1px var(--line); }
.pmark.act::after { content: "\2713"; } .pmark.warn::after { content: "!"; } .pmark.bad::after { content: "\00d7"; }
.pmark { position: relative; }
@media (forced-colors: active) { .bgm-expand, .bgm-recenter { border: 1px solid ButtonText; forced-color-adjust: auto; } .bgm-cpin svg { forced-color-adjust: none; } }

/* ---- map strips: never shorter than a usable map; the corner controls make room for each other */
.leaflet-container, .bgm { min-height: 180px; }
/* narrow or short maps (and phones): Full screen becomes an icon-only 44px button; the label returns in full-screen mode as "Close" */
.bgm-narrow:not(.bgm-full) > .bgm-expand { padding: 0; width: 44px; }
.bgm-narrow:not(.bgm-full) > .bgm-expand > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (max-width: 520px) {
  .leaflet-container:not(.bgm-full) > .bgm-expand { padding: 0; width: 44px; }
  .leaflet-container:not(.bgm-full) > .bgm-expand > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}
@media (max-width: 520px) and (pointer: coarse) { .leaflet-container:not(.bgm-full) > .bgm-expand { width: 48px; } }
/* maps that carry their own corner controls (home / tracking: address chip left, locate button right): sit beside the locate button, not under it */
.trk-map .bgm-expand { right: 68px; }
.trk-map .bgm-full .bgm-expand { right: max(12px, env(safe-area-inset-right)); }
.bgm-recenter { max-width: calc(100% - 24px); white-space: nowrap; box-sizing: border-box; }
.bgm-expand:active, .bgm-recenter:active { transform: scale(.97); }
