/*
 * Copyright (c) 2026 Allen Ellison-Saavedra
 * All rights reserved.
 *
 * PROPRIETARY AND CONFIDENTIAL
 *
 * Unauthorized copying, modification, distribution, disclosure,
 * or use of this software is strictly prohibited without prior
 * written permission from the copyright holder.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
 * NONINFRINGEMENT.
 *
 * TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THE COPYRIGHT
 * HOLDER SHALL NOT BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER
 * LIABILITY, WHETHER IN CONTRACT, TORT, OR OTHERWISE, ARISING
 * FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR ITS USE.
 */

/* Map component. Markup and options are described in map.js.
   Colors follow the site's tokens when it has them. */

.map {
  --map-ink: var(--color-text, #1d2433);
  --map-surface: var(--color-surface, #ffffff);
  --map-line: var(--color-border, #d5dbe3);
  --map-accent: var(--color-primary, #1f5fbf);
  --map-ground: #d7e6ee;
  --map-grid: #b7c9d4;
  --map-radius: var(--radius, 10px);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  height: 100%;
  min-height: 22rem;
  margin: 1.5rem 0;
  color: var(--map-ink);
}

@media (min-width: 48rem) {
  .map { flex-direction: row; align-items: stretch; min-height: 32rem; }
  .map-list { flex: 0 1 18rem; max-height: none; align-self: stretch; }
}

.map-stage {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  position: relative;
}

.map .map-canvas {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  min-height: 16rem;
  border: 1px solid var(--map-line);
  border-radius: var(--map-radius);
  overflow: hidden;
}

/* The page gives this map a box. The picture fills that box, including the
   width and height left beside a scrolling list. */
.map[data-fill="on"] {
  min-height: 0;
  margin: 0;
  gap: 0;
}
.map[data-fill="on"] .map-canvas {
  position: absolute;
  inset: 0;
  width: auto;
  height: auto;
  min-height: 0;
}
.map[data-fill="on"] .map-controls {
  position: absolute;
  z-index: 500;
  top: 0.5rem;
  left: 0.5rem;
  margin: 0;
  max-width: calc(100% - 1rem);
}
.map[data-fill="on"] .map-status {
  position: absolute;
  z-index: 500;
  left: 0.5rem;
  right: 0.5rem;
  bottom: 1.6rem;
  margin: 0;
  min-height: 0;
}
.map[data-list="off"] { flex-direction: column; }
.map[data-list="off"] .map-list { display: none; }

.map-canvas .leaflet-container {
  height: 100%;
  width: 100%;
  background: var(--map-ground);
  font: inherit;
}

.map-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.map-controls button {
  cursor: pointer;
  font: inherit;
  color: inherit;
  background: var(--map-surface);
  border: 1px solid var(--map-line);
  border-radius: 0.4rem;
  padding: 0.35rem 0.7rem;
}

.map-controls button:hover { background: #f3efe4; }
.map-controls button:active { background: #e6e0d2; }
.map-controls button:focus-visible { outline: 2px solid var(--map-accent); outline-offset: 2px; }
.map-controls button:disabled { cursor: default; opacity: 0.7; }

.map-controls button.is-busy::before {
  content: "";
  display: inline-block;
  width: 0.8em;
  height: 0.8em;
  margin-right: 0.4em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  vertical-align: -0.1em;
  animation: map-spin 0.7s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .map-controls button.is-busy::before { animation: none; }
}

.leaflet-marker-icon.map-pin {
  border-radius: 50%;
  border: 2px solid #fff;
  cursor: pointer;
}

.map-cluster {
  background: var(--map-accent);
  color: #fff;
}

.map-pin:hover,
.map-cluster:hover { filter: brightness(1.08); }
.map-pin:active,
.map-cluster:active { filter: brightness(0.92); }
.map-pin:focus-visible,
.map-cluster:focus-visible { outline: 2px solid var(--map-accent); outline-offset: 2px; }
.map-pin.is-selected { box-shadow: 0 0 0 3px var(--map-accent); }

.map-cat-0 { background: #1f6f8b; }
.map-cat-1 { background: #c05621; }
.map-cat-2 { background: #2f6b3a; }
.map-cat-3 { background: #6b3fa0; }
.map-cat-4 { background: #a33b4a; }
.map-cat-5 { background: #8a6a12; }
.map-cat-6 { background: #1d4e89; }
.map-cat-7 { background: #3d6b62; }
.map-cat-visitor,
.map-pin.map-cat-visitor { background: #d64545; }

.map-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 28rem;
  overflow: auto;
  border: 1px solid var(--map-line);
  border-radius: var(--map-radius);
  background: var(--map-surface);
}

@media (min-width: 48rem) {
  .map-list { max-height: none; }
}

.map-item { margin: 0; }

.map-choice {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  text-align: left;
  text-decoration: none;
  color: inherit;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--map-line);
  padding: 0.65rem 0.8rem;
  cursor: pointer;
  font: inherit;
}

.map-choice:hover { background: #f3efe4; }
.map-choice:active { background: #e6e0d2; }
.map-choice:focus-visible { outline: 2px solid var(--map-accent); outline-offset: -2px; }
.map-choice.is-selected { background: #e7f0f6; }

.map-swatch {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  flex: none;
}

.map-status { margin: 0; min-height: 1.2em; }

.map.is-dark,
.map.is-dark .map-list {
  --map-ink: #e7eef2;
  --map-surface: #152028;
  --map-line: #31424c;
  --map-ground: #1b2830;
  --map-grid: #31424c;
}

.map.is-light {
  --map-ink: #1d2433;
  --map-surface: #ffffff;
  --map-line: #d5dbe3;
  --map-ground: #d7e6ee;
  --map-grid: #b7c9d4;
}

@media (prefers-color-scheme: dark) {
  .map:not(.is-light) {
    --map-ink: #e7eef2;
    --map-surface: #152028;
    --map-line: #31424c;
    --map-ground: #1b2830;
    --map-grid: #31424c;
  }
  .map:not(.is-light) .map-basemap-light { display: none; }
  .map:not(.is-light) .map-basemap-dark { display: block; }
  .map:not(.is-light) .map-choice.is-selected { background: #243640; }
}

.map.is-dark .map-basemap-light { display: none; }
.map.is-dark .map-basemap-dark { display: block; }
.map.is-light .map-basemap-dark { display: none; }
.map.is-light .map-basemap-light { display: block; }
.map.is-dark .map-choice.is-selected { background: #243640; }
