/*
 * Totemia GIS — the Layers control (gis-layers.js) and the map's corners.
 *
 * Corners: search and the place column own the top left, Layers the bottom
 * left, zoom and scale the bottom right, the coordinate readout the top right.
 */

.gis-layers {
  position: absolute;
  left: 16px;
  bottom: 24px;
  z-index: 38;
  font-family: var(--gis-font);
  color: var(--gis-ink);
  transition: transform var(--duration) var(--ease-drawer);
}

/* Step aside from an open place column instead of sitting under it. */
.gis-has-place:not(.gis-place-collapsed) .gis-layers {
  transform: translateX(var(--gis-place-width, 408px));
}

.gis-layers-button {
  position: relative;
  display: block;
  width: 68px;
  height: 68px;
  padding: 0;
  overflow: hidden;
  border: 2px solid var(--gis-paper);
  border-radius: 8px;
  outline: 2px solid var(--gis-line);
  background: var(--gis-paper);
  cursor: pointer;
  transition: transform var(--duration-fast) var(--ease-out);
}

.gis-layers-button:active {
  transform: scale(0.97);
}

.gis-layers-button:focus-visible {
  outline-color: var(--gis-gold);
}

.gis-layers-button .gis-layers-thumb {
  width: 100%;
  height: 100%;
}

.gis-layers-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 3px 0 4px;
  background: rgba(20, 23, 26, 0.72);
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
}

.gis-layers-thumb {
  display: block;
  width: 60px;
  height: 60px;
  overflow: hidden;
  border-radius: 6px;
}

.gis-layers-thumb svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* Opens upward from the button it belongs to. */
.gis-layers-popover {
  position: absolute;
  left: 0;
  bottom: calc(100% + 10px);
  width: 296px;
  max-width: calc(100vw - 32px);
  padding: 14px 14px 12px;
  box-sizing: border-box;
  border: 2px solid var(--gis-line);
  border-radius: 10px;
  background: var(--gis-paper);
  transform-origin: bottom left;
  transition:
    opacity var(--duration-fast) var(--ease-out),
    transform var(--duration-fast) var(--ease-out);
}

.gis-layers-popover[hidden] {
  display: block;
  visibility: hidden;
  opacity: 0;
  transform: scale(0.96) translateY(4px);
  pointer-events: none;
  transition:
    opacity var(--duration-fast) var(--ease-out),
    transform var(--duration-fast) var(--ease-out),
    visibility 0s linear var(--duration-fast);
}

.gis-layers-group[hidden],
.gis-layers-links[hidden] {
  display: none;
}

.gis-layers-group + .gis-layers-group {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--gis-line);
}

.gis-layers-heading {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 800;
}

.gis-layers-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px 6px;
}

.gis-layers-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--gis-ink);
  font: inherit;
  cursor: pointer;
}

.gis-layers-tile .gis-layers-thumb {
  width: 56px;
  height: 56px;
  border: 2px solid transparent;
  outline: 1px solid var(--gis-line);
  transition:
    border-color var(--duration-fast) var(--ease-out),
    transform var(--duration-fast) var(--ease-out);
}

.gis-layers-tile:active .gis-layers-thumb {
  transform: scale(0.96);
}

.gis-layers-tile[aria-pressed="true"] .gis-layers-thumb {
  border-color: var(--gis-green);
  outline-color: var(--gis-green);
}

.gis-layers-tile[aria-pressed="true"] .gis-layers-label {
  color: var(--gis-green);
  font-weight: 800;
}

.gis-layers-tile:focus-visible {
  outline: 0;
}

.gis-layers-tile:focus-visible .gis-layers-thumb {
  outline: 2px solid var(--gis-gold);
}

.gis-layers-tile.is-busy {
  cursor: progress;
}

.gis-layers-tile.is-busy .gis-layers-thumb {
  opacity: 0.55;
}

.gis-layers-label {
  max-width: 100%;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
  overflow-wrap: anywhere;
}

.gis-layers-links {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--gis-line);
}

.gis-layers-link {
  color: var(--gis-green);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

@media (hover: hover) and (pointer: fine) {
  .gis-layers-link:hover {
    text-decoration: underline;
  }
}

/* ── Map corners ──────────────────────────────────────────────────────────── */

/* Zoom leaves the top left to the search field. */
html.map-viewer-root #map .ol-zoom {
  top: auto;
  left: auto;
  right: 12px;
  bottom: 48px;
}

html.map-viewer-root #map .ol-scale-bar,
html.map-viewer-root #map .ol-scale-line {
  left: auto;
  right: 52px;
  bottom: 12px;
}

@media (max-width: 720px) {
  .gis-layers {
    left: max(12px, env(safe-area-inset-left, 0px));
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }

  /* On a phone the sheet rises from the bottom; there is no column to step
     aside from. */
  .gis-has-place:not(.gis-place-collapsed) .gis-layers {
    transform: none;
  }

  .gis-layers-button {
    width: 56px;
    height: 56px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .gis-layers,
  .gis-layers-button,
  .gis-layers-popover,
  .gis-layers-popover[hidden],
  .gis-layers-tile .gis-layers-thumb {
    transition: none;
  }

  .gis-layers-button:active,
  .gis-layers-tile:active .gis-layers-thumb {
    transform: none;
  }
}

body.map-viewer-solo .gis-layers {
  display: none;
}
