/* Branches page (docs/pages/branches.md). Shared components live in site.css. */

/* ---------- Head: the promise, then the three questions' tools ---------- */

.branches-head {
  padding-block: var(--space-6) 0;
}

/* The same Fredoka as every other title on the site, in the brand red. Noot was the only one of its kind here (D-066) */
.branches-head__title {
  font: 600 var(--text-xl) / 1.2 var(--font-ui);
  color: var(--color-brand-red);
  text-wrap: balance;
}

.finder {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-5);
}

.finder__row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.finder .search {
  flex: 1 1 220px;
}

.finder [aria-busy="true"] {
  cursor: progress;
}

/* M-12: while the browser looks for you, the face looks too: eyes to one side, then the other, the head tilting with them.
   The pin steps aside for it. It's the one movement on the site that repeats, and only because the wait is the visitor's:
   it starts with their click, lasts as long as the answer takes (the permission prompt, the first time) and stops with it (D-068) */
.near__face {
  display: none;
  width: 20px;
  height: auto;
}

[data-near][aria-busy="true"] svg:has(use[href="#i-pin"]) {
  display: none;
}

[data-near][aria-busy="true"] .near__face {
  display: block;
  animation: face-look 1.6s var(--ease-out) infinite;
}

/* Reduced motion: the face waits with its eyes to the side, still */
@media (prefers-reduced-motion: reduce) {
  [data-near][aria-busy="true"] .near__face {
    --look: 12px;
    animation: none;
  }
}

/* Phones scroll the chips sideways from edge to edge, like the rows on the home page */
.chips {
  margin-inline: calc(var(--gutter) * -1);
  padding-inline: var(--gutter);
}

.chips__gap {
  flex: none;
  width: 1px;
  margin-inline: var(--space-1);
  background: var(--color-line);
}

.chip--open::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-inline-end: 6px;
  border-radius: 50%;
  background: var(--color-open);
  vertical-align: 1px;
}

.chip--open[aria-pressed="true"]::before {
  background: var(--color-surface);
}

/* ---------- Layout (D-055, D-058). Phones: head, map, list, and the page scrolls.
   Desktop: one screen. The head runs the full width; under it the list (right) and the map (left) share the rest,
   and only the list scrolls ---------- */

.branches {
  display: grid;
  grid-template-areas: "head" "map" "list";
  gap: var(--space-4);
  width: min(100% - 2 * var(--gutter), var(--container));
  margin-inline: auto;
  padding-bottom: var(--space-7);
}

.branches-head { grid-area: head; }
.map { grid-area: map; }
.list { grid-area: list; }

@media (min-width: 900px) {
  /* This stylesheet is this page's only, so the body itself becomes the screen */
  body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100svh;
    overflow: hidden;
  }

  .site-footer {
    display: none; /* nothing to scroll down to here; the concept bar stays on top */
  }

  .branches {
    flex: 1;
    min-height: 0;
    grid-template-columns: minmax(340px, 400px) 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
      "head head"
      "list map";
    column-gap: var(--space-5);
    row-gap: var(--space-4);
    width: 100%;
    padding: var(--space-4) var(--gutter);
  }

  /* One band across the whole page, centred, with wide room at the sides:
     title, subtitle, search and "near me" in one row, the filters under them (D-058) */
  .branches-head {
    padding: var(--space-2) clamp(var(--space-6), 8vw, 160px) 0;
    text-align: center;
  }

  .branches-head__title {
    font-size: var(--text-2xl);
  }


  .finder {
    margin-top: var(--space-4);
  }

  .finder__row {
    flex-wrap: nowrap;
    width: min(100%, 720px); /* a search box as wide as the screen reads as a banner, not a field */
    margin-inline: auto;
  }

  .chips {
    flex-wrap: wrap;
    justify-content: center;
    margin-inline: 0;
    padding-inline: 0;
  }

  /* The list scrolls by itself and never moves the page.
     Positioned, so what's inside (visually hidden words too) stays inside it and adds nothing to the page's height */
  .list {
    position: relative;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    margin-inline-end: calc(var(--space-3) * -1);
    padding-inline-end: var(--space-3);
    scrollbar-width: thin;
  }

  .list__head {
    position: sticky;
    top: 0;
    z-index: 1;
    padding-bottom: var(--space-3);
    background: var(--color-bg);
  }

  .list__title {
    margin-bottom: 0;
  }

  .map {
    min-height: 0;
  }
}

/* ---------- Phones (M-22, D-069): one screen too. The map fills what's under the head,
   and the list is a drawer over it with three stops: a peek, half, and all of it. branches.js sets its height.
   Only with JavaScript: without it the page stays head, map, list, and scrolls ---------- */

.list__grip {
  display: none;
}

@media (max-width: 899px) {
  .js body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100svh;
    overflow: hidden;
  }

  .js .site-footer {
    display: none;
  }

  .js .branches {
    position: relative;
    flex: 1;
    min-height: 0;
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "head" "map";
    padding-bottom: 0;
  }

  .js .map,
  .js .map__frame {
    height: 100%;
  }

  .js .map__frame {
    border-end-start-radius: 0;
    border-end-end-radius: 0;
  }

  /* The drawer itself. Out of the grid, over the foot of the map, as wide as the map */
  .js .list {
    position: absolute;
    grid-area: auto;
    inset-inline: 0;
    bottom: 0;
    z-index: 2;
    height: var(--peek, 124px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0 var(--space-3) var(--space-4);
    border-radius: var(--radius-m) var(--radius-m) 0 0;
    background: var(--color-bg);
    box-shadow: var(--shadow-sheet);
  }

  /* It settles on a stop with a little spring, like the logo (M-22) */
  .js .list.is-settling {
    transition: height var(--duration-peak) var(--ease-spring);
  }

  /* The head stays on top while the cards scroll under it, and dragging it moves the drawer, not the page */
  .js .list__head {
    position: sticky;
    top: 0;
    z-index: 1;
    padding-bottom: var(--space-3);
    background: var(--color-bg);
    touch-action: none;
    cursor: grab;
    user-select: none;
  }

  .js .list.is-dragging .list__head {
    cursor: grabbing;
  }

  .js .list__title {
    margin-bottom: 0;
  }

  /* The grip: a short bar, in a target as wide as the drawer. A tap moves one stop up, or back down from the top */
  .js .list__grip {
    display: grid;
    place-items: center;
    width: 100%;
    height: 28px;
    padding: 0;
    border: 0;
    background: none;
    cursor: inherit;
  }

  .js .list__grip::before {
    content: "";
    width: 40px;
    height: 5px;
    border-radius: var(--radius-full);
    background: var(--color-line);
    transition: background-color var(--duration-fast), width var(--duration-base) var(--ease-spring);
  }

  .js .list__head:hover .list__grip::before {
    background: var(--color-muted);
    width: 48px;
  }

  /* The card of a chosen pin docks just above the drawer's peek */
  .js .pop.is-docked {
    bottom: calc(var(--peek, 124px) + var(--space-2));
  }

  /* The credit stays at the foot of what you see of the map: just above the drawer's peek */
  .js .map__canvas .maplibregl-ctrl-bottom-right {
    bottom: calc(var(--peek, 124px) + var(--space-1));
  }
}

/* ---------- The map: MapLibre on a quiet, filtered style (D-057) ---------- */

.map__frame {
  position: relative;
  isolation: isolate; /* the map's layers stack in here, never over the concept bar */
  height: min(62svh, 560px);
  overflow: hidden;
  border-radius: var(--radius-m);
  background: var(--color-sea);
  direction: ltr; /* a map is physical: east is right in any language */
}

@media (min-width: 900px) {
  .map,
  .map__frame {
    height: 100%;
  }
}

.map__canvas {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: var(--color-sea);
  font-family: var(--font-body);
}

.map__canvas:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: -3px;
}

.map__canvas .maplibregl-ctrl-bottom-right {
  right: var(--space-3);
  bottom: var(--space-2);
}

.map__canvas .maplibregl-ctrl-attrib {
  margin: 0;
  padding: 1px 8px;
  border-radius: var(--radius-full);
  background: color-mix(in srgb, var(--color-surface) 80%, transparent);
  font: 400 10px / 1.4 var(--font-body);
}

.map__canvas .maplibregl-ctrl-attrib a {
  color: var(--color-muted);
}

/* If the map can't load, the list still answers everything */
.map__frame.is-offline::after {
  content: "המפה לא נטענה. כל הסניפים ברשימה.";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--color-muted);
  direction: rtl;
}

/* The zoom buttons sit on the map's left, which on this RTL page is where reading ends */
.map__zoom {
  position: absolute;
  top: var(--space-3);
  left: var(--space-3);
  z-index: 1000;
  display: grid;
  gap: var(--space-1);
}

.map__zoom .icon-btn {
  background: var(--color-surface);
  box-shadow: var(--shadow-lift);
  color: var(--color-ink);
}

.map__zoom .icon-btn:hover {
  box-shadow: var(--shadow-lift), inset 0 0 0 1.5px var(--color-ink);
}

/* ---------- Pins: the A on a map pin (D-052). MapLibre places each one with its tip on the point ---------- */

/* MapLibre positions the marker with a transform on .pin itself, so nothing here may transform .pin:
   a scale on it would scale its distance from the map's corner too, and the pin would jump away from the pointer.
   Everything that moves, moves inside .pin__body */
.pin {
  display: grid;
  justify-items: center;
  align-items: end;
  width: 44px;
  height: 48px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  transition: opacity var(--duration-base);
}

.pin__body {
  display: grid;
  justify-items: center;
  transform-origin: 50% 100%;
  transition:
    translate var(--duration-base) var(--ease-spring),
    scale var(--duration-base) var(--ease-spring);
}

.pin__shape {
  grid-area: 1 / 1;
  width: 34px;
  height: 44px;
  overflow: visible;
  fill: var(--color-brand-red);
  stroke: var(--color-surface);
  stroke-width: 2;
  filter: drop-shadow(0 3px 3px var(--color-scrim));
}

/* Positioned, because the shape's drop shadow (a filter) would otherwise paint over it */
.pin__face {
  position: relative;
  z-index: 1;
  grid-area: 1 / 1;
  align-self: start;
  width: 18px;
  margin-top: 10px;
  transition: opacity var(--duration-fast);
}

.pin__face--wink {
  opacity: 0;
}

/* Mini Max: the same pin, inverted, with a red edge so yellow still reads on a light map */
.pin--mini .pin__shape {
  fill: var(--color-brand-yellow);
  stroke: var(--color-red-deep);
  stroke-width: 1.5;
}

.pin--mini .pin__face {
  color: var(--color-brand-red);
  --face-ink: var(--color-brand-yellow);
}

/* M-19: the pins land once, from north to south. Only when they first appear, not each time a zoom brings them back */
.pin.is-new .pin__body {
  animation: pin-land var(--duration-base) var(--ease-out) both;
  animation-delay: calc(var(--i) * 12ms);
}

@keyframes pin-land {
  from { opacity: 0; transform: translateY(-14px); }
  to { opacity: 1; transform: none; }
}

/* M-36: under the pointer the pin rises a little, and its card opens beside it */
.pin:is(:hover, :focus-visible) .pin__body {
  translate: 0 -3px;
}

/* M-20: the chosen pin grows and winks, and its card in the list lights up. It and the hovered pin come to the front */
.pin.is-current .pin__body {
  scale: 1.18;
}

.pin.is-current {
  z-index: 1000 !important;
}

.pin:hover {
  z-index: 999 !important;
}

.pin.is-current .pin__face:not(.pin__face--wink) { opacity: 0; }
.pin.is-current .pin__face--wink { opacity: 1; }

/* M-23: with "פתוח עכשיו" on, closed branches step back but stay on the map */
.pin.is-dim {
  opacity: 0.35;
}

/* Close branches gather into one count. A tap flies in to them (M-35).
   The same rule as the pins: the button is MapLibre's to place, the ring inside it is ours to move */
.cluster {
  display: grid;
  place-items: center;
  width: var(--size, 40px);
  height: var(--size, 40px);
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.cluster__ring {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border: 3px solid var(--color-brand-red);
  border-radius: 50%;
  background: var(--color-surface);
  box-shadow: var(--shadow-lift);
  color: var(--color-brand-red);
  font: 600 var(--text-m) / 1 var(--font-ui);
  transition: scale var(--duration-base) var(--ease-spring);
}

.cluster:is(:hover, :focus-visible) .cluster__ring {
  scale: 1.1;
}

.cluster.is-dim .cluster__ring {
  border-color: var(--color-closed);
  color: var(--color-closed);
}

/* You are here: ink, not red, so it never reads as a branch */
.me {
  width: 18px;
  height: 18px;
  border: 3px solid var(--color-surface);
  border-radius: 50%;
  background: var(--color-ink);
  box-shadow: var(--shadow-lift);
}

/* ---------- The card on the map. It opens by its pin and touches it, so the pointer can walk into it (M-36) ---------- */

.pop {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1001;
  width: min(300px, calc(100% - var(--space-4)));
  padding: var(--space-4);
  border-radius: var(--radius-m);
  background: var(--color-surface);
  box-shadow: var(--shadow-sheet);
  direction: rtl;
}

.pop[hidden] {
  display: none;
}

/* Phones: the card docks at the foot of the map */
.pop.is-docked {
  inset: auto var(--space-2) var(--space-2);
  width: auto;
  padding: var(--space-3) var(--space-4);
  translate: none !important;
}

.pop__close {
  position: absolute;
  top: var(--space-1);
  inset-inline-end: var(--space-1);
}

.pop:not(.is-pinned) .pop__close {
  display: none;
}

.pop__kicker {
  color: var(--color-muted);
  font: 500 var(--text-xs) / 1.2 var(--font-ui);
}

.pop__name {
  margin-top: 2px;
  padding-inline-end: var(--space-6);
  font: 600 var(--text-l) / 1.2 var(--font-ui);
}

.pop .branch__status {
  margin-top: var(--space-2);
}

.pop .branch__address {
  margin-top: var(--space-1);
}

.pop dl {
  margin-top: var(--space-3);
}

/* Docked on a phone the card keeps to the answer and the actions; the full week is in the list */
.pop.is-docked dl {
  display: none;
}

.pop .branch__actions {
  margin-top: var(--space-3);
}

/* ---------- The list ---------- */

.list__title {
  margin-bottom: var(--space-3);
  font: 600 var(--text-l) / 1.2 var(--font-ui);
}

.list__items {
  display: grid;
  gap: var(--space-3);
}

.list__empty {
  padding: var(--space-5);
  border-radius: var(--radius-m);
  background: var(--color-surface);
  color: var(--color-muted);
}

.branch {
  display: grid;
  gap: var(--space-1);
  padding: var(--space-4);
  border-radius: var(--radius-m);
  background: var(--color-surface);
  box-shadow: inset 0 0 0 2px transparent;
  transition: box-shadow var(--duration-base), opacity var(--duration-base);
  scroll-margin-block: calc(30px + var(--space-4)) var(--space-4);
}

.branch[hidden] {
  display: none;
}

/* M-20: the chosen branch's card lights up */
.branch.is-current {
  box-shadow: inset 0 0 0 2px var(--color-brand-red);
}

/* M-23 */
.branch.is-dim {
  opacity: 0.55;
}

.branch__name {
  font: 600 var(--text-l) / 1.2 var(--font-ui);
}

/* The name shows the branch on the map: a quiet button that looks like the heading it is */
.branch__show {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: start;
  cursor: pointer;
}

.branch__show:hover {
  text-decoration: underline;
  text-underline-offset: 4px;
}

/* The status is color and words: green "open", grey "closed", never red (red is the brand's) */
.branch__status {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font: 500 var(--text-s) / 1.3 var(--font-ui);
}

.branch__status::before {
  content: "";
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px var(--color-closed);
}

.branch__status.is-open {
  color: var(--color-open);
}

.branch__status.is-open::before {
  background: var(--color-open);
  box-shadow: none;
}

.branch__status.is-closed {
  color: var(--color-closed);
}

.branch__address {
  color: var(--color-muted);
  font-size: var(--text-s);
}

.branch__distance:not(:empty) {
  margin-inline-end: var(--space-2);
  color: var(--color-ink);
  font: 600 var(--text-s) / 1 var(--font-ui);
}

.branch__distance:not(:empty)::after {
  content: " ·";
  color: var(--color-muted);
}

.branch__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

/* The group button says whose group it is with WhatsApp's own mark (D-056). Design only (D-020) */
.btn--group {
  gap: 6px;
}

.btn--group .icon-whatsapp {
  width: 18px;
  height: 18px;
  fill: var(--color-whatsapp);
  stroke: none;
}

.branch__hours {
  margin-top: var(--space-1);
  font-size: var(--text-s);
}

.branch__hours summary {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  color: var(--color-muted);
  font: 500 var(--text-s) / 1 var(--font-ui);
  cursor: pointer;
}

.branch dl,
.pop dl {
  display: grid;
  gap: 2px;
  font-size: var(--text-s);
}

.branch dl div,
.pop dl div {
  display: grid;
  grid-template-columns: 4em 1fr;
  gap: var(--space-2);
}

.branch dt,
.pop dt {
  color: var(--color-muted);
}
