/*
 * SESAM map control panels.
 *
 * Shared global styles for the map settings dropdown panels rendered
 * by the analyzer/editor map views. All classes already use the
 * `sesam-map-*` prefix. At the end: the attribution text of all MapLibre maps.
 */

/* Section label shared by all panels. */
.sesam-map-control-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--bs-gray-600);
  margin-top: 0;
  margin-bottom: 4px;
}

.sesam-map-settings-panel {
  position: absolute;
  /* The height ends above the bottom of the map (MapSettingsControl._fitPanel); the rest scrolls in the panel */
  overflow-y: auto;
  overscroll-behavior: contain;
  background: #fff;
  padding: 8px 10px;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 1;
  font-size: 13px;
}

/* The panels of the controls at the top of a map (display settings, Locate) open over it and lie above the scale and
   the attribution at its bottom, on every map (issue #587): MapLibre gives its four corners one layer (z-index 2), so
   the bottom corners, later in the page, would cover a panel that reaches down to them. With the class of the map in
   front: maplibre-gl.css loads after this file. */
.maplibregl-map .maplibregl-ctrl-top-left,
.maplibregl-map .maplibregl-ctrl-top-right {
  z-index: 3;
}

.sesam-map-settings-panel--below {
  top: 36px;
  right: 0;
}

.sesam-map-settings-panel--left {
  top: 0;
  right: calc(100% + 8px);
}

/* Controls on the left side of the map (Builder, Editor): the panel opens to the right of its button. */
.sesam-map-settings-panel--right {
  top: 0;
  left: calc(100% + 8px);
}

.sesam-map-settings-empty {
  opacity: 0.7;
  padding: 4px 0;
}

.sesam-map-settings-option-row {
  gap: 0.5rem;
  cursor: pointer;
  padding: 4px 0;
}

.sesam-map-settings-option-row .form-check-label {
  font-size: 13px;
  color: #8f93a3;
}

.sesam-map-settings-option-input {
  cursor: pointer;
  accent-color: #e1effe;
  position: static;
  margin: 0;
  flex: 0 0 auto;
}

.sesam-map-settings-group-spacer {
  height: 4px;
}

/* Locate (lookup-control.js): a search for map element ids in a panel beside its button. The results use the rows of
   the overlap picker below. */
/* The panel is placed against the control (.sesam-map-settings-panel--left/--right/--below). */
.sesam-map-lookup-ctrl {
  position: relative;
}

.sesam-map-lookup-toggle {
  color: #000;
}

.sesam-map-lookup {
  max-width: calc(100vw - 64px);
  padding: 10px 12px 12px;
  border-radius: 8px;
  font-family: "Inter", system-ui, sans-serif;
}

.sesam-map-lookup__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.sesam-map-lookup__header .sesam-map-control-section-title {
  margin: 0;
}

/* MapLibre sizes every button of a control group (29 px, display: block, a line between neighbors); the buttons and
   rows inside the panel undo that with the group in their selector. */
.maplibregl-ctrl-group .sesam-map-lookup__close {
  width: 1.25rem;
  height: 1.25rem;
  padding: 0;
  border-radius: 4px;
  background-size: 0.625rem;
}

/* The magnifier inside on the left, the clear button inside on the right. */
.sesam-map-lookup__field {
  position: relative;
}

.sesam-map-lookup__field-icon {
  position: absolute;
  top: 50%;
  left: 0.625rem;
  transform: translateY(-50%);
  color: var(--sesam-gray-500);
  font-size: 0.75rem;
  pointer-events: none;
}

.sesam-map-lookup__input.form-control {
  padding-right: 2rem;
  padding-left: 1.875rem;
  color: var(--sesam-heading-color);
}

.sesam-map-lookup__clear {
  position: absolute;
  top: 50%;
  right: 0.375rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.375rem;
  height: 1.375rem;
  padding: 0;
  transform: translateY(-50%);
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--sesam-gray-500);
  font-size: 0.75rem;
}

.sesam-map-lookup__clear:hover,
.sesam-map-lookup__clear:focus-visible {
  background: var(--bs-gray-200);
  color: var(--sesam-heading-color);
}

.maplibregl-ctrl-group .sesam-map-lookup__clear {
  display: inline-flex;
  width: 1.375rem;
  height: 1.375rem;
}

.sesam-map-lookup__results:not(:empty) {
  max-height: 240px;
  margin: 6px -12px -12px;
  border-top: 1px solid var(--bs-gray-200);
  overflow-y: auto;
}

/* The rows of the overlap picker; the one chosen with the arrow keys or the mouse is tinted. */
.maplibregl-ctrl-group .sesam-map-lookup__row {
  display: flex;
  width: 100%;
  height: auto;
  padding: 4px 12px;
  border-top: 0;
}

.sesam-map-lookup__row.is-active {
  background: rgba(var(--sesam-blue-rgb), 0.08);
}

.sesam-map-lookup__row:last-child {
  border-radius: 0 0 8px 8px;
}

.sesam-map-lookup__empty {
  padding: 10px 12px;
  color: var(--sesam-gray-600);
  font-size: 12px;
}

/* Overlap picker: compact list at the click position when several map elements lie under the click. */
.sesam-map-overlap-picker {
  position: absolute;
  z-index: 10;
  min-width: 200px;
  max-width: min(320px, calc(100% - 16px));
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  font:
    13px/1.4 "Inter",
    system-ui,
    sans-serif;
  outline: none;
  overflow: hidden;
}

.sesam-map-overlap-picker__header {
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--bs-gray-600);
  background: var(--bs-gray-100);
  border-bottom: 1px solid var(--bs-gray-200);
}

.sesam-map-overlap-picker__list {
  max-height: min(240px, 40vh);
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
}

/* Rows are at least 36px high so they are comfortable touch targets. */
.sesam-map-overlap-picker__row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 36px;
  padding: 4px 10px;
  border: 0;
  background: transparent;
  color: var(--bs-gray-700);
  text-align: left;
  cursor: pointer;
}

.sesam-map-overlap-picker__row:hover,
.sesam-map-overlap-picker__row:focus-visible {
  background: var(--bs-gray-100);
  outline: none;
}

.sesam-map-overlap-picker__icon {
  flex: 0 0 auto;
  width: 1.1em;
  text-align: center;
  color: var(--bs-gray-600);
}

.sesam-map-overlap-picker__type {
  flex: 0 0 auto;
}

.sesam-map-overlap-picker__title {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--bs-font-monospace);
}

/*
 * Text buttons in MapLibre control groups (the "3D" toggle of the Editor), sized like the icon buttons next to them.
 * The selector includes the MapLibre group class to win over its default button styles.
 */
.maplibregl-ctrl-group button.sesam-map-ctrl-text {
  font-size: 12px;
  font-weight: 700;
  color: #000;
}

/*
 * A switched-on toggle button of a map control. The hover selector repeats the specificity of MapLibre's
 * `.maplibregl-ctrl button:not(:disabled):hover` (plus the group class), which would otherwise lighten the button.
 */
.maplibregl-ctrl-group button.sesam-map-ctrl-active,
.maplibregl-ctrl.maplibregl-ctrl-group button.sesam-map-ctrl-active:not(:disabled):hover {
  background-color: var(--bs-primary);
  color: #fff;
}

/*
 * Loading indicator over a network map (template fragments/map_loading_indicator.html, see
 * static/js/map/loading_progress.js): a title and a progress bar. It is part of the template, so it shows at once,
 * also while the scripts are still loading.
 */
.sesam-map-loading {
  position: absolute;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(2px);
  transition: opacity 0.3s ease;
}

/* Fades out once the map is drawn (the element is hidden after the transition). */
.sesam-map-loading.is-finished {
  opacity: 0;
  pointer-events: none;
}

.sesam-map-loading__card {
  width: 300px;
  max-width: 100%;
  box-shadow: var(--sesam-shadow-soft);
}

.sesam-map-loading__title {
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.sesam-map-loading__progress {
  height: 6px;
}

/* The bar starts with a sliver, so it is visible before the first step reports. */
.sesam-map-loading__progress .progress-bar {
  width: 3%;
  transition: width 0.25s ease;
}

/* Attribution of the base map (OpenMapTiles, OpenStreetMap) on every map: a little smaller and slimmer than MapLibre's
   12px/20px, so it takes less room on small maps. It must stay legible (OSM attribution guidelines, see AGENTS.md). */
.maplibregl-ctrl.maplibregl-ctrl-attrib {
  font-size: 11px;
  line-height: 15px;
}

/* One pixel more below than above: the line box of Helvetica reserves room for descenders, which the attribution
   hardly has, so the text would otherwise look low in its box. :not() outweighs MapLibre's own padding (its stylesheet
   loads later) and leaves the compact attribution with its (i) button alone. */
.maplibregl-ctrl.maplibregl-ctrl-attrib:not(.maplibregl-compact) {
  padding: 1px 6px 2px;
}
