/* ═══════════════════════════════════════════════════════════
   MommyBaby — store locator (map page)
   Warm clay & paper. Unbounded (display) + Onest (UI).

   Tokens, the brand header and the social links live in
   base.css, which every page loads before this file.
   ═══════════════════════════════════════════════════════════ */

html, body {
  height: 100%;
  overscroll-behavior: none;

  /* The app is a fixed, viewport-sized layout — only .sheet-scroll may scroll.
     'clip' rather than 'hidden': hidden still creates a scroll container that
     scrollIntoView() and friends can shove around programmatically, which is
     exactly how the collapsed sheet's transform used to drag the layout out
     of place. 'hidden' first as a fallback for older engines. */
  overflow: hidden;
  overflow: clip;
}

/* ── layout ─────────────────────────────────────────────── */

.app {
  display: grid;
  grid-template-columns: var(--panel-w) 1fr;

  /* This page carries no site header — see the note in map.html — so the
     grid owns the whole viewport. */
  height: 100dvh;

  /* See the note on html/body: 'clip' leaves nothing for stray programmatic
     scrolling to grab hold of. The collapsed sheet's transform gives this
     element ~600px of scroll range under plain 'hidden'. */
  overflow: hidden;
  overflow: clip;
}

.panel {
  position: relative;
  z-index: 500;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--paper);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow-md);
}

/* faint paper grain, keeps the flat cream from looking like dead CSS */
.panel::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .5;
  background-image: var(--grain);
}

.panel > * { position: relative; z-index: 1; }

/* ── chosen region (returns to the picker) ──────────────── */

/* Replaces the static "Где купить" tagline once a region is chosen, and
   doubles as the way back — the picker is the app's entry point, so the
   header line naming the current region is where people look for it. */
.brand__region {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin: 2px 0 0;
  padding: 3px 8px 3px 7px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  transition: color .15s, border-color .15s, background .15s;
}
.brand__region svg { width: 13px; height: 13px; flex: none; }
.brand__region span {
  max-width: 24ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.brand__region .brand__region-caret { color: var(--faint); }

.brand__region:hover {
  color: var(--clay);
  background: var(--clay-tint);
  border-color: var(--clay-tint);
}
.brand__region:hover .brand__region-caret { color: var(--clay); }

.brand__region:focus-visible {
  outline: 2px solid var(--clay);
  outline-offset: 2px;
}

/* ── selected-branch detail (mobile pin tap) ────────────── */

/* Only ever shown in the sheet's 'detail' stop, which mobile enters when a
   map pin is tapped. Scrolling the list to the tapped branch cannot work:
   the last cards can never reach the top of the scroller, so they end up
   mostly below the fold. A dedicated card has no such limit. */
.detail { display: none; }

body.sheet-detail .detail { display: block; }
body.sheet-detail .controls,
body.sheet-detail .sheet-scroll,
body.sheet-detail .foot { display: none; }

.detail {
  position: relative;
  /* Bottom inset keeps the route button clear of the iPhone home indicator. */
  padding: 16px 18px calc(18px + env(safe-area-inset-bottom));
}

.detail__close {
  position: absolute;
  top: 12px; right: 14px;
  width: 30px; height: 30px;
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--muted);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
  transition: color .15s, background .15s;
}
.detail__close svg { width: 15px; height: 15px; }
.detail__close:hover { color: var(--ink); background: var(--line); }

.detail__name {
  margin: 0 40px 0 0;
  font-family: "Unbounded", "Onest", sans-serif;
  font-weight: 500;
  font-size: 16px;
  line-height: 1.3;
  letter-spacing: -.015em;
}

.detail__addr {
  margin: 7px 0 0;
  font-size: 14px;
  line-height: 1.45;
  color: var(--muted);
}

.detail__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  min-height: 0;
}
.detail__meta:empty { display: none; }

.detail__route {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
  padding: 13px 16px;
  font-weight: 600;
  font-size: 15px;
  color: var(--surface);
  text-decoration: none;
  background: var(--clay);
  border-radius: var(--r-md);
  box-shadow: 0 2px 8px rgba(228,103,75,.30);
  transition: background .16s, box-shadow .16s, transform .16s var(--ease);
}
.detail__route svg { width: 17px; height: 17px; }
.detail__route:hover { background: var(--clay-dark); }
.detail__route:active { transform: scale(.985); }

.panel__grab { display: none; }

/* ── controls ───────────────────────────────────────────── */

.controls { padding: 16px 22px 12px; }

/* Removed outright when there is nothing loaded to search or measure against;
   spelled out because [hidden] loses to any later display rule. */
.controls[hidden] { display: none; }

.btn-locate {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 13px 16px;
  font: inherit;
  font-weight: 600;
  font-size: 14.5px;
  color: var(--surface);
  background: var(--clay);
  border: 0;
  border-radius: var(--r-md);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(228,103,75,.30);
  transition: transform .18s var(--ease), box-shadow .18s var(--ease), background .18s;
}
.btn-locate svg { width: 18px; height: 18px; flex: none; }
.btn-locate:hover { background: var(--clay-dark); box-shadow: 0 4px 16px rgba(228,103,75,.38); }
.btn-locate:active { transform: scale(.985); }
.btn-locate[data-state="loading"] { background: var(--faint); box-shadow: none; cursor: progress; }
.btn-locate[data-state="loading"] svg { animation: spin 1.1s linear infinite; }
.btn-locate[data-state="done"] { background: var(--moss); box-shadow: 0 2px 8px rgba(47,93,80,.28); }

@keyframes spin { to { transform: rotate(360deg); } }

.search {
  position: relative;
  margin-top: 10px;
}

.search__icon {
  position: absolute;
  left: 13px; top: 50%;
  transform: translateY(-50%);
  width: 17px; height: 17px;
  color: var(--faint);
  pointer-events: none;
}

.search input {
  width: 100%;
  padding: 12px 36px 12px 38px;
  font: inherit;
  font-size: 14.5px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  outline: none;
  transition: border-color .16s, box-shadow .16s;
}
.search input::placeholder { color: var(--faint); }
.search input:focus {
  border-color: var(--clay);
  box-shadow: 0 0 0 3px var(--clay-tint);
}
.search input::-webkit-search-cancel-button { display: none; }

.search__clear {
  position: absolute;
  right: 8px; top: 50%;
  transform: translateY(-50%);
  width: 24px; height: 24px;
  display: grid; place-items: center;
  font-size: 19px; line-height: 1;
  color: var(--faint);
  background: none; border: 0;
  border-radius: 50%;
  cursor: pointer;
}
.search__clear:hover { color: var(--ink); background: var(--line); }

/* Sits between the carousel and the list, so it reads as the list's heading. */
.count {
  margin: 14px 0 2px;
  padding: 0 16px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--faint);
}

/* ── list ───────────────────────────────────────────────── */

/* The promo strip and the shop list share one scroller, so the promo scrolls
   away as you browse instead of permanently eating sheet height. */
.sheet-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line-2) transparent;
  overscroll-behavior: contain;
}
.sheet-scroll::-webkit-scrollbar { width: 8px; }
.sheet-scroll::-webkit-scrollbar-thumb {
  background: var(--line-2);
  border: 2px solid var(--paper);
  border-radius: 4px;
}

.list {
  margin: 0;
  padding: 6px 14px 18px;
  list-style: none;
}

/* ── promo carousel ─────────────────────────────────────── */

.promo { padding: 4px 14px 0; }

.promo__frame { position: relative; }

.promo__track {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  scrollbar-width: none;
  outline: none;
  border-radius: var(--r-md);
}
.promo__track::-webkit-scrollbar { display: none; }
.promo__track:focus-visible { box-shadow: 0 0 0 3px var(--clay-tint); }

/* Slides stop short of full width so a sliver of the next one shows —
   the clearest signal that the strip scrolls. */
.promo__slide {
  flex: 0 0 86%;
  width: 86%;
  aspect-ratio: 1672 / 941;
  height: auto;
  object-fit: cover;
  border-radius: var(--r-md);
  scroll-snap-align: start;
  scroll-snap-stop: always;
  background: var(--line);
  box-shadow: var(--shadow-sm);
  -webkit-user-drag: none;
  user-select: none;
}

/* ── carousel arrows (desktop only) ─────────────────────── */

.promo__nav { display: none; }

@media (min-width: 861px) {
  .promo__nav {
    position: absolute;
    top: 50%;
    z-index: 2;
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    padding: 0;
    color: var(--ink);
    background: rgba(255,255,255,.90);
    border: 1px solid var(--line);
    border-radius: 50%;
    box-shadow: var(--shadow-md);
    cursor: pointer;
    opacity: .8;
    transform: translateY(-50%);
    transition: opacity .16s, background .16s, transform .16s var(--ease);
  }
  .promo__nav svg { width: 16px; height: 16px; }

  /* display:grid above would otherwise defeat the hidden attribute that
     app.js sets at the first and last slide. */
  .promo__nav[hidden] { display: none; }

  .promo__nav:hover { opacity: 1; background: #fff; }
  .promo__nav--prev:hover { transform: translateY(-50%) scale(1.08); }
  .promo__nav--next:hover { transform: translateY(-50%) scale(1.08); }
  .promo__nav:active { transform: translateY(-50%) scale(.94); }

  .promo__nav--prev { left: 8px; }
  .promo__nav--next { right: 8px; }

  .promo__nav:focus-visible {
    opacity: 1;
    outline: 2px solid var(--clay);
    outline-offset: 2px;
  }
}

.promo__dots {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 5px;
  margin: 9px 0 2px;
}

.promo__dot {
  width: 6px;
  height: 6px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--line-2);
  cursor: pointer;
  transition: width .22s var(--ease), background .22s;
}
.promo__dot.is-active { width: 18px; background: var(--clay); }

.card {
  position: relative;
  padding: 13px 14px 13px 15px;
  margin-bottom: 7px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: border-color .16s, box-shadow .16s, transform .16s var(--ease);
  animation: rise .42s var(--ease) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(7px); }
  to   { opacity: 1; transform: none; }
}

.card:hover {
  border-color: var(--line-2);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.card.is-active {
  border-color: var(--clay);
  box-shadow: 0 0 0 3px var(--clay-tint), var(--shadow-sm);
}

.card__top {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.card__name {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-weight: 600;
  font-size: 14.5px;
  line-height: 1.32;
  letter-spacing: -.005em;
}

.card__dist {
  flex: none;
  font-family: "Unbounded", sans-serif;
  font-weight: 500;
  font-size: 11.5px;
  color: var(--moss);
  background: var(--moss-tint);
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.card__addr {
  margin: 5px 0 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
}

.card__meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.tag {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .02em;
  padding: 3px 8px;
  border-radius: 6px;
  color: var(--muted);
  background: var(--paper);
  border: 1px solid var(--line);
}
.tag--approx { color: #8A6A2F; background: #FBF2DF; border-color: #F0E2C4; }

.card__route {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--clay);
  text-decoration: none;
  background: var(--clay-tint);
  border-radius: 8px;
  transition: background .15s, color .15s;
}
.card__route svg { width: 13px; height: 13px; }
.card__route:hover { background: var(--clay); color: var(--surface); }

.empty {
  padding: 34px 18px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}
.empty strong { display: block; margin-bottom: 4px; color: var(--ink); font-size: 15px; }

/* The "not mapped yet" state gets a mark, so an empty region reads as a
   deliberate message rather than as a list that failed to render. */
.empty__mark {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin: 0 auto 14px;
  color: var(--clay);
  background: var(--clay-tint);
  border-radius: 50%;
  box-shadow: 0 0 0 8px rgba(228,103,75,.06);
}
.empty__mark svg { width: 26px; height: 26px; }
.empty a {
  color: var(--clay);
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px solid var(--clay-tint);
}
.empty a:hover { border-color: var(--clay); }

/* ── footer ─────────────────────────────────────────────── */

.foot {
  padding: 12px 22px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--paper);
}
.foot p { margin: 0; font-size: 11.5px; color: var(--faint); line-height: 1.5; }

/* ── map ────────────────────────────────────────────────── */

.map-wrap { position: relative; min-width: 0; }

#map {
  width: 100%;
  height: 100%;
  background: #EEE7DE;
}

.leaflet-container { font-family: "Onest", sans-serif; }

.leaflet-control-zoom a {
  color: var(--ink) !important;
  border-color: var(--line) !important;
}

/* branch pin */
.pin {
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  border-radius: 50% 50% 50% 4px;
  transform: rotate(-45deg);
  background: var(--clay);
  border: 2.5px solid var(--surface);
  box-shadow: 0 2px 7px rgba(36,30,26,.32);
  transition: transform .2s var(--ease), background .2s;
}
.pin.is-active {
  background: var(--moss);
  transform: rotate(-45deg) scale(1.28);
  z-index: 1000 !important;
}

/* cluster bubble */
.cluster {
  display: grid;
  place-items: center;
  font-family: "Unbounded", sans-serif;
  font-weight: 500;
  font-size: 13px;
  color: var(--surface);
  background: var(--clay);
  border: 3px solid var(--surface);
  border-radius: 50%;
  box-shadow: 0 3px 12px rgba(36,30,26,.28);
  transition: transform .18s var(--ease);
}
.cluster:hover { transform: scale(1.07); }

.marker-cluster { background: none; }

/* "you are here" */
.me {
  width: 18px; height: 18px;
  margin: -9px 0 0 -9px;
  border-radius: 50%;
  background: #2E7BE4;
  border: 3px solid var(--surface);
  box-shadow: 0 0 0 6px rgba(46,123,228,.20), 0 2px 6px rgba(36,30,26,.3);
  animation: pulse 2.4s ease-out infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 5px rgba(46,123,228,.26), 0 2px 6px rgba(36,30,26,.3); }
  70%  { box-shadow: 0 0 0 17px rgba(46,123,228,0), 0 2px 6px rgba(36,30,26,.3); }
  100% { box-shadow: 0 0 0 5px rgba(46,123,228,0), 0 2px 6px rgba(36,30,26,.3); }
}

/* popup */
.leaflet-popup-content-wrapper {
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: 2px;
}
.leaflet-popup-content { margin: 12px 14px; font-size: 13.5px; line-height: 1.5; }
.leaflet-popup-content b {
  display: block;
  font-size: 14.5px;
  font-weight: 600;
  margin-bottom: 4px;
  letter-spacing: -.005em;
}
.leaflet-popup-content span { color: var(--muted); }
.leaflet-popup-content a {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 9px;
  padding: 6px 11px;
  font-weight: 600;
  font-size: 12.5px;
  color: var(--surface);
  text-decoration: none;
  background: var(--clay);
  border-radius: 8px;
}
.leaflet-popup-content a:hover { background: var(--clay-dark); }

/* mobile map/list toggle */
.map-toggle { display: none; }

/* ── mobile ─────────────────────────────────────────────── */

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }

  .map-wrap {
    grid-area: 1 / 1;
    height: 100dvh;
  }

  /* how much of the sheet stays on screen in map mode: header + main action.
     Lives on :root because the attribution control is positioned off it too. */
  :root { --peek: 136px; }

  .panel {
    /* Leaflet's controls sit at z-index 1000; the sheet must paint above them
       or the attribution bleeds through over the search field. */
    z-index: 1100;

    grid-area: 1 / 1;
    align-self: end;

    /* Tall enough that the "full" snap point covers nearly the whole screen;
       the other two states just sit further down. */
    height: 92dvh;

    border-right: 0;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    box-shadow: var(--shadow-lg);
    transition: transform .34s var(--ease);

    /* Starting position, so there is no full-screen flash before JS runs.
       A percentage resolves against the panel itself, unlike dvh in calc().
       From here on the offset is driven from app.js, which snaps between
       three points: peek, half and full. */
    transform: translateY(calc(100% - var(--peek)));
  }

  .brand { padding: 8px 18px 12px; }

  /* The handle is a wide invisible grab strip; only the pill is painted.
     A 4px-tall target is unhittable with a thumb. */
  .panel__grab {
    display: block;
    position: absolute;
    top: 0; left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 240px;
    height: 28px;
    padding: 0;
    background: none;
    border: 0;
    cursor: grab;
    touch-action: none;
  }

  .panel__grab::before {
    content: "";
    position: absolute;
    top: 8px; left: 50%;
    transform: translateX(-50%);
    width: 40px; height: 4px;
    background: var(--line-2);
    border-radius: 2px;
    transition: width .18s var(--ease), background .18s;
  }

  .panel__grab:hover::before { background: var(--faint); }

  /* The whole header doubles as a drag surface, as on a native sheet. */
  .brand { touch-action: none; cursor: grab; }

  .panel.is-dragging,
  .panel.is-dragging ~ * { transition: none !important; }
  .panel.is-dragging { cursor: grabbing; }
  .panel.is-dragging .panel__grab { cursor: grabbing; }
  .panel.is-dragging .panel__grab::before { width: 54px; background: var(--faint); }

  .controls { padding: 12px 18px 10px; }
  .list { padding: 4px 12px 14px; }
  .foot { display: none; }

  /* Nothing to scroll while the sheet is tucked away — stops a swipe over
     the collapsed sheet from silently scrolling hidden content. */
  body.map-mode .sheet-scroll { overflow: hidden; }

  /* Pinch-zoom covers this on touch, and the buttons sit right on top of
     the sheet's primary action. */
  .leaflet-control-zoom { display: none; }

  /* Attribution must stay legible, so park it above whatever the sheet
     currently covers rather than letting the sheet bury it. */
  /* --attr-bottom tracks how much of the screen the sheet covers; app.js
     updates it whenever the sheet settles. */
  .leaflet-control-attribution { font-size: 10px; }
  .leaflet-bottom {
    bottom: var(--attr-bottom, var(--peek));
    transition: bottom .34s var(--ease);
  }

  .map-toggle {
    display: block;
    position: absolute;
    top: 14px; right: 14px;
    z-index: 1200;
    padding: 9px 15px;
    font: inherit;
    font-weight: 600;
    font-size: 13px;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line-2);
    border-radius: 999px;
    box-shadow: var(--shadow-md);
    cursor: pointer;
  }
  /* The label names where the button takes you, not where you are. */
  .map-toggle__list { display: none; }              /* list mode -> "Карта"  */
  body.map-mode .map-toggle__map  { display: none; }
  body.map-mode .map-toggle__list { display: inline; } /* map mode -> "Список" */
}

/* Narrow phones: keep the primary action on a single line so the collapsed
   sheet's peek height stays predictable. */
@media (max-width: 400px) {
  .btn-locate {
    font-size: 13px;
    padding: 12px 10px;
    gap: 7px;
    white-space: nowrap;
  }
  .btn-locate svg { width: 16px; height: 16px; }
  .brand { padding-left: 16px; padding-right: 16px; }
  .controls { padding-left: 16px; padding-right: 16px; }
}

@media (max-width: 340px) {
  /* The region chip stays — it is the only way back to the picker. */
  .brand__region { font-size: 11.5px; padding: 2px 7px 2px 6px; }
  .brand__region span { max-width: 15ch; }
  .btn-locate { font-size: 12.5px; }
}
