/*!
 * imsmapper.css — part of imsmapper.
 *
 * BSD 2-Clause License
 *
 * Copyright (c) 2026, VideoPlatform Contributors
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * OSM tile data served through this stylesheet's default tile URL is
 * separately governed by the OpenStreetMap Foundation ODbL license.
 */

/*
 * imsmapper.css — Phase 2a viewport styling.
 *
 * Conventions:
 *   - every class is om- prefixed
 *   - theming via --om-* custom properties (overridable by the host page)
 *   - no !important anywhere
 *
 * Shipped as dist/imsmapper.css by the package build (copy step; tsup cannot
 * bundle CSS). Import it alongside imsmapper or include it via <link>.
 */

:root {
  --om-background: #eef1f4;
  --om-checker-a: #d3dbe3;
  --om-checker-b: #ffffff;
  --om-grid-line: rgba(35, 49, 66, 0.35);
  --om-cursor: grab;
  --om-cursor-active: grabbing;
  --om-font-family: system-ui, "Segoe UI", sans-serif;
  --om-control-background: #ffffff;
  --om-control-foreground: #1f2937;
  --om-control-border: rgba(35, 49, 66, 0.18);
  --om-control-shadow: 0 1px 4px rgba(15, 23, 42, 0.22);
  --om-control-radius: 6px;
  --om-accent: #2563eb;
  --om-popup-gap: 8px;
  --om-popup-max-width: 280px;
  --om-tooltip-background: rgba(17, 24, 39, 0.92);
  --om-tooltip-foreground: #f9fafb;
}

/* The user container once the map boots inside it. */
.om-map {
  position: relative;
  overflow: hidden;
  background: var(--om-background);
  font-family: var(--om-font-family);
  cursor: var(--om-cursor);
  touch-action: none; /* pointer events own every gesture */
  user-select: none;
  -webkit-user-select: none;
  outline-offset: -2px;
}

.om-map--dragging {
  cursor: var(--om-cursor-active);
}

/* Renderer canvases live below every overlay band. */
.om-canvas-host {
  position: absolute;
  inset: 0;
  z-index: 100;
  pointer-events: none;
}

/* Parent of the z-indexed band containers. */
.om-overlay-host {
  position: absolute;
  inset: 0;
  z-index: 200;
  pointer-events: none;
}

/* One z-band container (z-index assigned inline from the ZBand registry). */
.om-band {
  position: absolute;
  inset: 0;
}

.om-band > * {
  pointer-events: auto;
}

.om-canvas {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
}

/* Temporary M1 placeholder compositor surface. */
.om-canvas--placeholder {
  pointer-events: none;
}

/* Hidden markers keep their DOM state (visibility toggle via class). */
.om-marker--hidden {
  display: none;
}

/* Draggable markers claim their pointer gesture: no browser pan/scroll or
   text selection may fight the drag (see layers/marker-layer.ts). */
.om-marker {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.om-marker--draggable {
  cursor: grab;
}

.om-marker--dragging {
  cursor: grabbing;
}

/* -----------------------------------------------------------------------
 * Phase 4 — control dock (typed corner slots, above every z-band)
 * --------------------------------------------------------------------- */

.om-control-corner {
  position: absolute;
  z-index: 900; /* above Popups (700): controls stay operable */
  display: flex;
  gap: 8px;
  pointer-events: none;
}

.om-control-corner > * {
  pointer-events: auto;
}

.om-control-corner--topleft {
  top: 10px;
  left: 10px;
  flex-direction: column;
  align-items: flex-start;
}

.om-control-corner--topright {
  top: 10px;
  right: 10px;
  flex-direction: column;
  align-items: flex-end;
}

.om-control-corner--bottomleft {
  bottom: 10px;
  left: 10px;
  flex-direction: column;
  align-items: flex-start;
}

.om-control-corner--bottomright {
  bottom: 10px;
  right: 10px;
  flex-direction: column;
  align-items: flex-end;
}

.om-control {
  background: var(--om-control-background);
  color: var(--om-control-foreground);
  border: 1px solid var(--om-control-border);
  border-radius: var(--om-control-radius);
  box-shadow: var(--om-control-shadow);
  font-size: 13px;
  line-height: 1.3;
}

/* Zoom control: stacked +/− buttons. */
.om-control--zoom {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
}

.om-zoom-button {
  width: 32px;
  height: 32px;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 18px;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.om-zoom-button + .om-zoom-button {
  border-top: 1px solid var(--om-control-border);
}

.om-zoom-button:hover {
  background: rgba(37, 99, 235, 0.08);
}

.om-zoom-button:focus-visible {
  outline: 2px solid var(--om-accent);
  outline-offset: -2px;
}

.om-zoom-button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Scale control: bar width arrives via --om-scale-width (only write). */
.om-control--scale {
  padding: 2px 6px;
}

.om-scale-bar {
  width: var(--om-scale-width, 80px);
  border: 2px solid var(--om-control-foreground);
  border-top: 0;
  height: 6px;
  box-sizing: content-box;
}

.om-scale-label {
  display: block;
  font-size: 11px;
  text-align: center;
  transform: translateY(-1px);
}

/* Attribution control: inert text + validated anchors only. */
.om-control--attribution {
  padding: 2px 8px;
  font-size: 11px;
  max-width: 60%;
}

.om-attribution-separator {
  opacity: 0.6;
}

.om-control--attribution a {
  color: var(--om-accent);
  text-decoration: none;
}

.om-control--attribution a:hover {
  text-decoration: underline;
}

/* Layers switcher: checkbox list of named layers. */
.om-control--layers {
  padding: 6px 10px;
  min-width: 120px;
}

.om-layers-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.om-layers-item {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 1px 0;
}

.om-layers-item input {
  accent-color: var(--om-accent);
}

/* -----------------------------------------------------------------------
 * Phase 4 — box zoom rubber band (geometry via --om-box-* custom props)
 * --------------------------------------------------------------------- */

.om-boxzoom {
  position: absolute;
  left: var(--om-box-x, 0px);
  top: var(--om-box-y, 0px);
  width: var(--om-box-w, 0px);
  height: var(--om-box-h, 0px);
  border: 2px dashed var(--om-accent);
  background: rgba(37, 99, 235, 0.1);
  box-sizing: border-box;
  z-index: 800;
  pointer-events: none;
}

/* -----------------------------------------------------------------------
 * Phase 4 — popup (anchored card; position via --om-x/--om-y batched
 * writes; bottom-center anchored, --om-popup-gap above the anchor)
 * --------------------------------------------------------------------- */

.om-popup {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(var(--om-x, 0px), var(--om-y, 0px))
    translate(-50%, calc(-100% - var(--om-popup-gap)));
  background: var(--om-control-background);
  color: var(--om-control-foreground);
  border: 1px solid var(--om-control-border);
  border-radius: 8px;
  box-shadow: var(--om-control-shadow);
  max-width: var(--om-popup-max-width);
  padding: 10px 12px;
  font-size: 13px;
}

.om-popup__close {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  border-radius: 4px;
}

.om-popup__close:hover {
  background: rgba(35, 49, 66, 0.08);
}

.om-popup__close:focus-visible {
  outline: 2px solid var(--om-accent);
}

.om-popup__content {
  overflow-wrap: anywhere;
}

.om-popup__content a {
  color: var(--om-accent);
}

/* -----------------------------------------------------------------------
 * Phase 4 — tooltip (hover-following; fades in via class toggle)
 * --------------------------------------------------------------------- */

.om-tooltip {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(var(--om-x, 0px), var(--om-y, 0px));
  background: var(--om-tooltip-background);
  color: var(--om-tooltip-foreground);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  max-width: 220px;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 120ms ease;
}

.om-tooltip--visible {
  opacity: 1;
  visibility: visible;
}
