/* Home page map search (Pages/Index.cshtml, js/map-search.js): the legacy site's redesigned home page
   (whibdev/dcc #30-#40, StyleSheets/home.css there).

   The List and Legend buttons above the map open one panel at a time; with neither pressed only the map shows.
   Phones   (< 640px):  the panel shows instead of the map
   Tablets  (640-959):  map on top, the panel below it
   Desktops (>= 960px): the panel beside the map */

/* the footer follows straight after the map */
.home-page .site-main {
  padding-bottom: 0;
}

/* ---------- title and search ---------- */

.home-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0 12px;
}

.home-title-icon {
  flex: 0 0 64px;
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--plum);
  background: var(--lilac);
  border-radius: 50%;
}

.home-title h1 {
  margin: 0;
  font-size: 2rem;
}

.map-search {
  display: flex;
  width: 100%;
}

.map-search input {
  flex: 1 1 auto;
  min-width: 0;
  height: 44px;
  box-sizing: border-box;
  padding: 6px 12px;
  font: 1.1rem Verdana, Helvetica, sans-serif;
  color: var(--text);
  background: #fff;
  border: 2px solid var(--teal);
  border-right: 0;
  border-radius: 6px 0 0 6px;
  outline: none;
}

.map-search input::placeholder {
  color: #8A8A92;
}

.map-search input:focus {
  box-shadow: 0 0 0 3px rgba(15, 124, 128, 0.2);
}

.map-search button {
  flex: 0 0 auto;
  height: 44px;
  padding: 0 22px;
  font: 1.1rem Verdana, Helvetica, sans-serif;
  color: #fff;
  background: var(--teal);
  border: 2px solid var(--teal);
  border-radius: 0 6px 6px 0;
  cursor: pointer;
}

.map-search button:hover,
.map-search button:focus-visible {
  background: var(--teal-dark);
  border-color: var(--teal-dark);
}

.map-status {
  text-align: center;
  min-height: 1.6em;
  margin: 10px 0 8px;
  font-size: 0.8rem;
  color: var(--plum);
}

/* ---------- List and Legend buttons ---------- */

.map-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.map-chip {
  height: 40px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: bold 13px Verdana, Helvetica, sans-serif;
  color: var(--teal);
  background: #fff;
  border: 2px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
}

.map-chip:hover {
  border-color: var(--teal);
}

.map-chip.map-chip-on {
  color: #fff;
  background: var(--teal);
  border-color: var(--teal);
}

.map-chip svg {
  flex: 0 0 auto;
}

/* Legend is an icon only */
.map-chip.map-chip-icon {
  min-width: 52px;
  justify-content: center;
}

/* ---------- the panel and the map ---------- */

.map-layout {
  display: flex;
  gap: 16px;
  align-items: stretch;
  /* ends 16px above the bottom of the window: the header, title, search and buttons above it take about 330px */
  height: clamp(360px, calc(100vh - 330px), 860px);
  height: clamp(360px, calc(100dvh - 330px), 860px);
}

.map-panel {
  flex: 0 0 330px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* neither List nor Legend pressed: just the map */
.map-panel-closed .map-panel {
  display: none;
}

.map-panel-box {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.map-panel-box [hidden] {
  display: none;
}

.map-results {
  flex: 1 1 auto;
  min-height: 0;
  padding: 8px;
  overflow-y: auto;
}

.map-box {
  flex: 1 1 auto;
  min-width: 0;
  position: relative;
}

.map-canvas {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: 6px;
}

/* a small spinner over the map while results load; it shows only if they take more than 0.3s */
.map-box::after {
  content: "";
  position: absolute;
  top: 12px;
  left: 50%;
  z-index: 1050; /* above the map, below the phone cards */
  width: 30px;
  height: 30px;
  margin-left: -15px;
  box-sizing: border-box;
  background: #fff;
  border: 3px solid rgba(15, 124, 128, 0.2);
  border-top-color: var(--teal);
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0s linear 0.2s;
  animation: map-spin 0.8s linear infinite;
}

.map-box.map-loading::after {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.2s ease 0.3s, visibility 0s linear 0.3s;
}

/* ---------- the list ---------- */

.map-empty {
  margin: 4px;
  font-size: 0.85rem;
  color: var(--muted);
}

.map-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.map-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 5px;
  border-bottom: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
}

.map-item:hover,
.map-item-on {
  background: var(--lilac);
}

.map-item-body {
  flex: 1;
  min-width: 0;
}

.map-item-title {
  font-weight: bold;
  color: var(--plum);
}

a.map-item-title:hover {
  color: var(--plum);
}

.map-item-street {
  font-size: 0.8rem;
  font-weight: bold;
  color: var(--muted);
}

.map-item-description {
  font-size: 0.8rem;
  color: var(--muted);
  max-height: 4.5em;
  overflow: hidden;
}

/* the ad fills the width of the list */
.map-ad {
  margin: 10px 0;
  text-align: center;
}

/* fixed ad sizes: a size AdSense picks itself would also resize the layout around it */
.map-ad-unit {
  display: inline-block;
  width: 300px;
  height: 250px;
}

/* small phones: the list is narrower than 300px */
@media (max-width: 339px) {
  .map-ad-unit {
    width: 250px;
    height: 250px;
  }
}

/* tablets in landscape: the list under the map is wide enough for a leaderboard */
@media (min-width: 780px) and (max-width: 959px) {
  .map-ad-unit {
    width: 728px;
    height: 90px;
  }
}

/* ---------- the legend ---------- */

.map-legend {
  padding: 0 12px 12px;
}

.map-legend h2 {
  margin: 12px 0 8px;
}

.map-legend ul {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.9rem;
}

.map-legend li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 56px;
  padding: 0 5px;
}

.map-legend li:nth-child(odd) {
  background: var(--lilac);
}

.map-legend li > span {
  flex: none;
  margin: 0 5px;
}

/* ---------- round map points, also in the list, the cards and the legend ---------- */

/* the point's 44px tap area, with the visible dot centred in it */
.map-dot-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 0;
}

/* most info: teal dot; less info (map-dot-small): smaller white dot; selected (map-dot-on): plum */
.map-dot {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: bold 13px Verdana, Helvetica, sans-serif;
  color: #fff;
  background: var(--teal);
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.map-dot.map-dot-small {
  width: 28px;
  height: 28px;
  font-size: 11px;
  color: var(--teal);
  background: #fff;
  border-color: var(--teal);
}

/* in the list and on the cards the dots line up whatever their size */
.map-item .map-dot,
.map-card .map-dot {
  margin: 0 2px;
}

.map-item .map-dot-small,
.map-card .map-dot-small {
  margin: 2px 4px;
}

.map-dot.map-dot-on {
  width: 40px;
  height: 40px;
  font-size: 15px;
  color: #fff;
  background: var(--plum);
  border: 3px solid #fff;
  box-shadow: 0 0 0 4px rgba(91, 46, 87, 0.3), 0 2px 6px rgba(0, 0, 0, 0.35);
}

/* several points too close to tap apart */
.map-group {
  width: 46px;
  height: 46px;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: bold 16px Verdana, Helvetica, sans-serif;
  color: var(--plum);
  background: var(--lilac);
  border: 3px solid var(--plum);
  border-radius: 50%;
  box-shadow: 0 0 0 5px rgba(91, 46, 87, 0.18), 0 2px 6px rgba(0, 0, 0, 0.3);
}

.map-group.map-group-on {
  color: #fff;
  background: var(--plum);
  border-color: #fff;
}

/* ---------- map bubbles ---------- */

.map-popup-title {
  display: block;
  font-weight: bold;
  color: var(--plum);
}

.map-popup-street {
  font-size: 0.8rem;
  font-weight: bold;
  color: var(--muted);
}

.map-popup-description {
  font-size: 0.8rem;
  color: var(--muted);
  max-height: 8em;
  overflow: auto;
  margin: 0.25rem 0;
}

/* ---------- below the map: browse by province ---------- */

.home-browse {
  margin: 28px 0 32px;
}

.home-browse h2 {
  margin: 0 0 6px;
  font-size: 1.375rem;
}

.home-browse p {
  max-width: 70ch;
  margin: 0 0 14px;
  color: var(--muted);
}

.home-provinces {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.home-provinces a {
  display: block;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.home-provinces a:hover,
.home-provinces a:focus-visible {
  border-color: var(--teal);
  text-decoration: none;
}

/* ---------- only used on phones: swipe cards ---------- */

.map-cards {
  display: none;
}

/* ---------- smoother changes ---------- */

@keyframes map-spin {
  to { transform: rotate(360deg); }
}

@keyframes map-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes map-dot-in {
  from { opacity: 0; transform: scale(0.6); }
  to { opacity: 1; transform: none; }
}

/* a panel, or on phones the map, that has just appeared (map-search.js fadeIn) */
.map-fade-in {
  animation: map-fade 0.25s ease-out;
}

/* points and listings that weren't there before the map moved */
.map-dot-new .map-dot,
.map-dot-new .map-group {
  animation: map-dot-in 0.3s ease-out;
}

.map-item-new {
  animation: map-fade 0.3s ease-out;
}

/* desktops: the panel slides in and out beside the map instead of appearing at once */
@media (min-width: 960px) {
  .map-panel {
    overflow: hidden;
  }

  /* the panel keeps its width while it slides, so the list doesn't reflow */
  .map-panel-box {
    width: 330px;
    box-sizing: border-box;
  }

  .map-panel-closed .map-panel {
    display: flex;
    flex-basis: 0;
    margin-right: -16px; /* and the gap beside it */
    opacity: 0;
    visibility: hidden;
  }

  .map-anim .map-panel {
    transition: flex-basis 0.3s ease, margin-right 0.3s ease, opacity 0.3s ease, visibility 0s linear 0s;
  }

  .map-anim.map-panel-closed .map-panel {
    transition: flex-basis 0.3s ease, margin-right 0.3s ease, opacity 0.3s ease, visibility 0s linear 0.3s;
  }
}

@media (prefers-reduced-motion: reduce) {
  .map-fade-in,
  .map-dot-new .map-dot,
  .map-dot-new .map-group,
  .map-item-new {
    animation: none;
  }

  .map-anim .map-panel,
  .map-anim.map-panel-closed .map-panel {
    transition: none;
  }
}

/* ---------- tablets: map on top, the panel below it ---------- */

@media (max-width: 959px) {
  .map-layout {
    flex-direction: column;
    height: auto;
  }

  .map-box {
    order: -1;
    height: calc(100vh - 330px); /* ends above the bottom of the window */
    height: calc(100dvh - 330px);
    min-height: 320px;
    max-height: 600px;
  }

  .map-panel {
    flex: 0 0 auto;
  }

  /* the page scrolls instead of the list */
  .map-results {
    overflow: visible;
  }
}

/* ---------- phones: the map, or the list or legend instead of it ---------- */

@media (max-width: 639px) {
  .home-page .site-main {
    padding-top: 12px;
  }

  /* the heading stays for search engines and screen readers */
  .home-title {
    position: absolute;
    left: -9999px;
  }

  .map-search input,
  .map-search button {
    height: 48px;
    font-size: 1rem;
  }

  .map-search input {
    padding: 6px 8px;
  }

  .map-search button {
    padding: 0 14px;
  }

  .map-status {
    margin: 6px 0;
    min-height: 0;
  }

  .map-panel-box {
    border: 0;
  }

  .map-results,
  .map-legend {
    padding: 0;
  }

  /* the map fills the rest of the screen, edge to edge; a panel shows instead of it */
  .map-box {
    height: calc(100vh - 222px);
    height: calc(100dvh - 222px); /* the window without the browser's address bar */
    min-height: 320px;
    max-height: none;
    margin: 0 -16px;
  }

  .map-canvas {
    border-width: 1px 0 0;
    border-radius: 0;
  }

  .map-panel-open .map-box {
    display: none;
  }

  /* until map-search.js picks a panel, phones show just the map */
  .map-layout:not(.map-panel-open) .map-panel {
    display: none;
  }

  /* a swipeable row of cards, one per map point, along the bottom of the map */
  .map-cards.map-cards-on {
    display: flex;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 22px; /* clear of the map's OpenStreetMap credit */
    z-index: 1100; /* above the map's zoom buttons (1000) */
    gap: 10px;
    padding: 4px 16px 8px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-padding: 0 16px;
    scrollbar-width: none;
  }

  .map-cards::-webkit-scrollbar {
    display: none;
  }

  .map-card {
    flex: 0 0 250px;
    box-sizing: border-box;
    scroll-snap-align: start;
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 12px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
    cursor: pointer;
  }

  .map-card.map-card-on {
    padding: 11px;
    border: 2px solid var(--plum);
  }

  .map-card.map-card-on .map-dot {
    color: #fff;
    background: var(--plum);
    border-color: var(--plum);
  }

  .map-card-text {
    flex: 1;
    min-width: 0;
  }

  .map-card-title,
  .map-card-street {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .map-card-title {
    font-size: 0.9rem;
    font-weight: bold;
    color: var(--plum);
    margin-bottom: 2px;
  }

  .map-card-street {
    font-size: 0.75rem;
    color: var(--muted);
  }

  .map-card-more {
    display: inline-block;
    font-size: 0.9rem;
    line-height: 28px;
  }
}
