/* ─────────────────────────────────────────────────────────────────────────
   Finder postcode picker — "list beside map" (redesign 1b)
   Load after tokens.css + main.css. Replaces the inline <style> block that
   used to sit in finder.html's head_extra.

   Design rules this file encodes:
   · The camera is never moved by styling/layout — see postcode-picker.js.
   · Sand ramp = listing density. Accent green = selection, and nothing else.
   · Chrome (head / search / footer) never shrinks; the map absorbs it.
   ───────────────────────────────────────────────────────────────────────── */

/* ── Trigger button in the Location filter ─────────────────────────────── */
body.v2 .ak-fnd-pcmap-trigger {
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border: 1px solid var(--c-rule);
  border-radius: var(--r-sm);
  background: var(--c-panel);
  color: var(--c-ink2);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
body.v2 .ak-fnd-pcmap-trigger:hover {
  background: var(--c-bg2);
  color: var(--c-accent);
  border-color: var(--c-accent);
}

/* ── Modal shell ───────────────────────────────────────────────────────── */
body.v2 #ak-fnd-pcmap-modal .ak-modal {
  max-width: 1160px;
  max-height: none;
  height: min(86vh, 800px);
  display: flex;
  flex-direction: column;
  background: var(--c-bg);
}
body.v2 #ak-fnd-pcmap-modal .ak-modal-head {
  flex-shrink: 0;
  padding: 16px 20px;
  gap: 20px;
}
body.v2 #ak-fnd-pcmap-modal .ak-modal-head p {
  margin: 3px 0 0;
  font-size: 13px;
  color: var(--c-muted);
}
body.v2 .ak-pcm-close {
  background: transparent;
  border: 0;
  padding: 6px;
  cursor: pointer;
  color: var(--c-muted);
  line-height: 0;
  border-radius: var(--r-sm);
}
body.v2 .ak-pcm-close:hover { color: var(--c-ink); }

/* ── Two-pane body ─────────────────────────────────────────────────────── */
body.v2 .ak-pcm-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 344px minmax(0, 1fr);
}

/* ── Left column: search + grouped list ────────────────────────────────── */
body.v2 .ak-pcm-list-pane {
  border-right: 1px solid var(--c-rule);
  background: var(--c-panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
body.v2 .ak-pcm-search-wrap {
  padding: 12px 14px;
  border-bottom: 1px solid var(--c-rule2);
  flex-shrink: 0;
}
body.v2 .ak-pcm-search {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 11px;
  border: 1px solid var(--c-rule);
  border-radius: var(--r-md);
  background: var(--c-panel);
}
body.v2 .ak-pcm-search:focus-within { border-color: var(--c-accent); }
body.v2 .ak-pcm-search svg { flex-shrink: 0; }
body.v2 .ak-pcm-search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  padding: 0;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  color: var(--c-ink);
}
body.v2 .ak-pcm-search-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 9px;
}
body.v2 .ak-pcm-visible-count {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--c-dim);
}
body.v2 .ak-pcm-filter-toggle {
  background: transparent;
  border: 0;
  min-height: 32px;
  padding: 4px 0;
  cursor: pointer;
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--c-muted);
  white-space: nowrap;
}
body.v2 .ak-pcm-filter-toggle[aria-pressed="true"] { color: var(--c-accent); }
body.v2 .ak-pcm-filter-toggle[aria-pressed="true"]::before { content: "\2713\00a0"; }

body.v2 .ak-pcm-list {
  position: relative; /* offsetTop reference for reveal-on-map-click */
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  min-height: 0;
  scrollbar-width: thin;
}
body.v2 .ak-pcm-list::-webkit-scrollbar { width: 10px; }
body.v2 .ak-pcm-list::-webkit-scrollbar-thumb {
  background: var(--c-rule);
  border: 3px solid var(--c-panel);
  border-radius: 999px;
}
body.v2 .ak-pcm-empty {
  padding: 28px 16px;
  text-align: center;
  font-size: 12.5px;
  color: var(--c-muted);
}

/* Group (suurpiiri) header — sticks while its rows scroll past. */
body.v2 .ak-pcm-grouphead {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--c-bg);
  border-top: 1px solid var(--c-rule2);
  border-bottom: 1px solid var(--c-rule2);
}
body.v2 .ak-pcm-groupbtn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
}
body.v2 .ak-pcm-group-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--c-ink);
}
body.v2 .ak-pcm-group-count {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--c-dim);
}
body.v2 .ak-pcm-zoom {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  flex-shrink: 0;
  border: 1px solid var(--c-rule);
  border-radius: 5px;
  background: var(--c-panel);
  color: var(--c-muted);
  cursor: pointer;
}
body.v2 .ak-pcm-zoom:hover { color: var(--c-accent); border-color: var(--c-accent); }

/* Rows */
body.v2 .ak-pcm-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  border-bottom: 1px solid var(--c-bg);
  background: var(--c-panel);
}
body.v2 .ak-pcm-row[data-sel="true"]   { background: #F4F8F3; }
body.v2 .ak-pcm-row[data-hover="true"] { background: var(--c-bg2); }
body.v2 .ak-pcm-rowbtn {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
}
body.v2 .ak-pcm-pc {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--c-ink2);
  flex-shrink: 0;
}
body.v2 .ak-pcm-name {
  font-size: 12.5px;
  color: var(--c-ink2);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
body.v2 .ak-pcm-badge {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  flex-shrink: 0;
  background: var(--c-bg2);
  color: var(--c-dim);
}
body.v2 .ak-pcm-badge[data-has="true"] {
  background: var(--c-accent-soft);
  color: var(--c-accent);
}

/* Checkbox */
body.v2 .ak-pcm-box {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  flex-shrink: 0;
  display: inline-grid;
  place-items: center;
  border: 1.5px solid #C9C7BF;
  background: var(--c-panel);
  transition: background 0.1s, border-color 0.1s;
}
body.v2 .ak-pcm-box svg { opacity: 0; }
body.v2 [aria-checked="true"] .ak-pcm-box {
  border-color: var(--c-accent);
  background: var(--c-accent);
}
body.v2 [aria-checked="true"] .ak-pcm-box svg { opacity: 1; }
/* Group partially selected — hairline instead of a tick. */
body.v2 [aria-checked="mixed"] .ak-pcm-box {
  border-color: var(--c-accent);
  background: var(--c-panel);
  position: relative;
}
body.v2 [aria-checked="mixed"] .ak-pcm-box::after {
  content: "";
  width: 7px;
  height: 2px;
  border-radius: 1px;
  background: var(--c-accent);
}

/* ── Right column: map ─────────────────────────────────────────────────── */
body.v2 .ak-pcm-map-pane {
  position: relative;
  background: #E8E6DF;
  min-height: 0;
  /* Leaflet panes otherwise extend past the container and swallow clicks
     on the footer buttons. */
  overflow: hidden;
}
/* Leaflet puts .leaflet-container on this element itself, not on a child, so
   the descendant selector this block used to carry never matched anything and
   the map quietly kept Leaflet's own #ddd backdrop and Helvetica stack. The
   backdrop is what shows through anywhere a tile has not painted, so it has
   to be the pane's own sand, not a grey that reads as a broken tile. */
body.v2 #ak-fnd-pcmap-leaflet {
  position: absolute;
  inset: 0;
  background: #E8E6DF;
  font-family: var(--font-sans);
}
/* Closes the hairline grid that shows through between tiles.
   Leaflet writes width:256px on each tile inline and spaces them 256px apart,
   but a fractional devicePixelRatio (Windows display scaling at 110%, 125%
   and so on) resolves that 256px to 255.99px while keeping the 256px spacing.
   The missing hundredth of a pixel rounds up to a one-device-pixel line of
   backdrop between every pair of tiles: Chromium bug 600120.

   Leaflet ships its own workaround for that bug, mix-blend-mode: plus-lighter
   on img.leaflet-tile, which relies on neighbouring tiles abutting exactly so
   their anti-aliased edges sum back to opaque. It does not survive a
   fractional ratio here, and it actively fights the obvious fix: under
   additive blending any overlap sums two opaque tiles and turns the seam
   white instead of hiding it.

   So drop the additive blending and overlap the tiles by half a pixel
   instead. Both layers are opaque where it matters, so the overlap is
   invisible. !important on all three: each competes with a style Leaflet
   sets inline on the tile or in its own stylesheet. */
body.v2 #ak-fnd-pcmap-leaflet img.leaflet-tile {
  mix-blend-mode: normal !important;
  width: 256.5px !important;
  height: 256.5px !important;
}
body.v2 #ak-fnd-pcmap-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--c-bg2);
  z-index: 600;
  color: var(--c-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 1px;
  text-align: center;
  padding: 20px;
}
body.v2 .ak-pcm-reset {
  position: absolute;
  right: 14px;
  top: 14px;
  z-index: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  background: var(--c-panel);
  border: 1px solid var(--c-rule);
  border-radius: 7px;
  box-shadow: 0 4px 14px -6px rgba(14, 18, 19, 0.25);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--c-ink2);
  cursor: pointer;
  white-space: nowrap;
}
body.v2 .ak-pcm-reset:hover { color: var(--c-accent); border-color: var(--c-accent); }

body.v2 .ak-pcm-legend {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 11px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--c-rule);
  border-radius: var(--r-md);
}
body.v2 .ak-pcm-legend-label {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--c-dim);
  font-weight: 600;
}
body.v2 .ak-pcm-ramp { display: flex; align-items: center; gap: 2px; }
body.v2 .ak-pcm-ramp i {
  width: 18px;
  height: 9px;
  display: block;
}
body.v2 .ak-pcm-ramp i:nth-child(1) { background: #F3F1E9; border: 1px solid #E0DDD1; }
body.v2 .ak-pcm-ramp i:nth-child(2) { background: #E3DFCF; border: 1px solid #D4D0C0; }
body.v2 .ak-pcm-ramp i:nth-child(3) { background: #D0CAB2; border: 1px solid #C2BCA4; }
body.v2 .ak-pcm-ramp i:nth-child(4) { background: #B9B294; border: 1px solid #ABA486; }
body.v2 .ak-pcm-ramp i:nth-child(5) { background: #9E9673; border: 1px solid #8F8866; }
body.v2 .ak-pcm-legend-div { width: 1px; height: 12px; background: var(--c-rule); }
body.v2 .ak-pcm-legend-sel {
  width: 18px;
  height: 9px;
  display: block;
  background: var(--c-accent);
  border: 1.5px solid var(--c-accent-ink);
}
body.v2 .ak-pcm-legend-sel-label { font-size: 11px; color: var(--c-muted); }

/* Leaflet tooltip */
body.v2 .ak-fnd-pcmap-tooltip {
  background: rgba(14, 18, 19, 0.95);
  color: #fff;
  border: 0;
  border-radius: 6px;
  padding: 7px 11px;
  font-size: 12px;
  line-height: 1.45;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}
body.v2 .ak-fnd-pcmap-tooltip::before { border-top-color: rgba(14, 18, 19, 0.95); }

/* ── Footer ────────────────────────────────────────────────────────────── */
body.v2 #ak-fnd-pcmap-footer {
  position: relative;
  z-index: 2;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  border-top: 1px solid var(--c-rule);
  background: var(--c-panel);
}
body.v2 .ak-pcm-tally {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
  white-space: nowrap;
}
body.v2 .ak-pcm-tally-n {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.5px;
  color: var(--c-ink);
}
body.v2 .ak-pcm-tally-label { font-size: 13px; color: var(--c-muted); }
body.v2 .ak-pcm-actions { display: flex; gap: 8px; align-items: center; }
body.v2 #ak-fnd-pcmap-clear {
  padding: 8px 14px;
  border: 1px solid var(--c-rule);
  border-radius: 7px;
  background: var(--c-panel);
  color: var(--c-ink2);
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
}
body.v2 #ak-fnd-pcmap-clear:hover { background: var(--c-bg2); }
body.v2 #ak-fnd-pcmap-apply {
  padding: 8px 18px;
  border: 0;
  border-radius: 7px;
  background: var(--c-accent);
  color: #fff;
  font-size: 12.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
body.v2 #ak-fnd-pcmap-apply:hover { background: var(--c-accent-ink); }

/* ── Pane switcher — only rendered/used on narrow screens ──────────────── */
body.v2 .ak-pcm-tabs { display: none; }

/* ── Narrow: stack the panes behind a List / Map switch ────────────────── */
@media (max-width: 900px) {
  body.v2 #ak-fnd-pcmap-modal .ak-modal { height: min(92vh, 900px); }
  body.v2 .ak-pcm-tabs {
    display: flex;
    flex-shrink: 0;
    gap: 6px;
    padding: 10px 14px;
    background: var(--c-panel);
    border-bottom: 1px solid var(--c-rule);
  }
  body.v2 .ak-pcm-tab {
    flex: 1;
    min-height: 40px;
    border: 1px solid var(--c-rule);
    border-radius: 7px;
    background: var(--c-panel);
    color: var(--c-ink2);
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
  }
  body.v2 .ak-pcm-tab[aria-selected="true"] {
    background: var(--c-accent);
    border-color: var(--c-accent);
    color: #fff;
  }
  body.v2 .ak-pcm-body { grid-template-columns: minmax(0, 1fr); }
  body.v2 .ak-pcm-list-pane { border-right: 0; }
  body.v2 #ak-fnd-pcmap-modal[data-pane="map"]  .ak-pcm-list-pane { display: none; }
  body.v2 #ak-fnd-pcmap-modal[data-pane="list"] .ak-pcm-map-pane  { display: none; }
}

/* ── Phone: chrome fixed, map absorbs the shrink, 44px targets ─────────── */
@media (max-width: 640px) {
  body.v2 .ak-modal-bg { padding: 0; }
  body.v2 #ak-fnd-pcmap-modal .ak-modal {
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }
  body.v2 #ak-fnd-pcmap-modal .ak-modal-head { padding: 12px 14px; }
  body.v2 #ak-fnd-pcmap-modal .ak-modal-head p { font-size: 12px; }
  body.v2 .ak-pcm-close { padding: 11px; margin: -11px -8px -11px 0; }
  body.v2 .ak-pcm-tab { min-height: 44px; }
  body.v2 .ak-pcm-search { padding: 11px; }
  body.v2 .ak-pcm-search input { font-size: 16px; } /* no iOS zoom-on-focus */
  body.v2 .ak-pcm-row { padding: 0 14px; }
  body.v2 .ak-pcm-rowbtn { min-height: 44px; }
  body.v2 .ak-pcm-grouphead { padding: 10px 14px; }
  body.v2 .ak-pcm-zoom { width: 32px; height: 32px; }
  body.v2 .ak-pcm-legend { left: 10px; bottom: 10px; padding: 7px 9px; gap: 6px; }
  body.v2 .ak-pcm-legend-label, body.v2 .ak-pcm-legend-sel-label { display: none; }
  body.v2 #ak-fnd-pcmap-footer { padding: 10px 14px; gap: 10px; }
  body.v2 .ak-pcm-tally-n { font-size: 17px; }
  body.v2 .ak-pcm-tally-label { font-size: 12px; }
  body.v2 #ak-fnd-pcmap-clear,
  body.v2 #ak-fnd-pcmap-apply { min-height: 44px; padding-left: 18px; padding-right: 18px; }
}

/* ── Focus visibility (keyboard) ───────────────────────────────────────── */
body.v2 #ak-fnd-pcmap-modal button:focus-visible,
body.v2 #ak-fnd-pcmap-modal input:focus-visible {
  outline: 2px solid var(--c-accent);
  outline-offset: 2px;
}

/* Reduced motion: kill the picker's own transitions only. A blanket `*` here
   also hits .leaflet-zoom-animated / .leaflet-proxy, and Leaflet commits an
   animated zoom inside its transitionend handler — with no transition the
   zoom is silently discarded and every camera control dies. */
@media (prefers-reduced-motion: reduce) {
  body.v2 #ak-fnd-pcmap-modal
    :not(.leaflet-zoom-animated):not(.leaflet-proxy):not(.leaflet-pane):not(.leaflet-container) {
    transition: none !important;
  }
}
