/* Full-screen map shell: map, chips' placement, popovers, graph dock, video view.
   Separation is spacing and tint, never a border or shadow.
   Shared pieces live in components.css (chips, progress bar, FAQ). */

body.is-map {
  min-height: 0;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

body.is-map .topbar {
  flex-shrink: 0;
  height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
}

body.is-map .topbar-inner {
  max-width: none;
}

.topbar-tools {
  display: flex;
  align-items: center;
  margin-left: auto;
}

.topbar-tools[hidden] {
  display: none;
}

.topbar-inner:has(.topbar-tools:not([hidden])) .site-nav,
.topbar-inner:has(.topbar-tools:not([hidden])) .nav-burger {
  margin-left: 0.35rem;
}

.view-switch {
  position: absolute;
  z-index: 6;
  top: 0.75rem;
  left: 0.75rem;
  display: inline-flex;
  align-items: center;
  padding: 0.15rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  pointer-events: auto;
}

.view-switch[hidden] {
  display: none;
}

.map-app:has(#view-switch:not([hidden])) .leaflet-top.leaflet-left {
  top: 4.5rem;
}

.map-app:has(#view-switch:not([hidden])) .video-metrics:not(.is-column) {
  left: 12.5rem;
}

.view-switch button {
  appearance: none;
  margin: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1;
  min-height: 2.25rem;
  padding: 0.35rem 0.9rem;
  cursor: pointer;
}

.view-switch button[aria-pressed="true"] {
  background: var(--brand);
  color: #fff;
}

[data-theme="dark"] .view-switch button[aria-pressed="true"] {
  color: #042f2e;
}

body.is-map .map-app,
body.is-map .chip,
body.is-map .chip-static,
body.is-map .empty-card,
body.is-map .empty-state,
body.is-map .file-overlay,
body.is-map .map-popover,
body.is-map .graph-dock,
body.is-map .dock-handle,
body.is-map .dock-pane,
body.is-map .leaflet-bar,
body.is-map .leaflet-bar a,
body.is-map .leaflet-touch .leaflet-bar,
body.is-map .leaflet-container .leaflet-control-attribution {
  border: 0;
  box-shadow: none;
}

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

.map-app[hidden] {
  display: none;
}

.map-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: var(--bg);
}

#map {
  position: absolute;
  inset: 0;
  z-index: 0;
}

body.is-map .leaflet-container {
  background: var(--bg);
  font-family: var(--font-sans);
}

body.is-map .leaflet-bar {
  background: transparent;
}

body.is-map .leaflet-bar a,
body.is-map .leaflet-touch .leaflet-bar a {
  width: 2.25rem;
  height: 2.25rem;
  line-height: 2.25rem;
  margin-bottom: 0.35rem;
  border-radius: 8px;
  background: var(--tint);
  color: var(--text);
}

body.is-map .leaflet-bar a:last-child {
  margin-bottom: 0;
}

body.is-map .leaflet-bar a:hover,
body.is-map .leaflet-bar a:focus {
  background: var(--tint-strong);
}

body.is-map .leaflet-container .leaflet-control-attribution {
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  color: var(--text);
  margin: 0;
  padding: 0.15rem 0.45rem;
  font-size: 0.75rem;
  line-height: 1.35;
  max-width: min(70vw, 28rem);
}

body.is-map .leaflet-control-attribution a {
  color: var(--link);
}

.map-chips {
  position: absolute;
  z-index: 3;
  top: 0.75rem;
  right: 0.75rem;
  left: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
  max-width: calc(100% - 4.75rem);
  pointer-events: none;
}

.chip-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.4rem;
  pointer-events: none;
}

.map-chips .chip,
.map-chips .map-popover,
.chip-bar .chip {
  pointer-events: auto;
}

#file-name {
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unit-switch,
.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.popover-note {
  margin-top: 0.45rem;
  font-size: 0.92rem;
  line-height: 1.4;
}

.stat-list {
  margin: 0.75rem 0 0;
}

.stat-list div {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.18rem 0;
}

.stat-list dt {
  font-weight: 650;
}

.stat-list dd {
  margin: 0;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.map-progress {
  position: absolute;
  z-index: 5;
  top: 0.75rem;
  left: 50%;
  width: min(18rem, calc(100% - 8rem));
  transform: translateX(-50%);
  padding: 0.85rem 1rem;
  border-radius: 12px;
  background: var(--tint);
  pointer-events: auto;
}

.map-progress:not([hidden]) {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.55rem;
}

.map-progress p {
  margin: 0;
  font-weight: 650;
  line-height: 1.35;
}

.map-popover {
  width: min(16rem, 100%);
  padding: 0.85rem 1rem;
  border-radius: 12px;
  background: var(--tint);
  pointer-events: auto;
}

#stats-panel,
#export-panel {
  width: min(20rem, 100%);
}

#edit-panel {
  width: min(22rem, calc(100vw - 1.5rem));
  max-height: min(70vh, 36rem);
  overflow: auto;
}

.edit-field {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  margin-top: 0.45rem;
  font-weight: 650;
}

.edit-readout {
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.edit-block {
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

.edit-block input[type="range"] {
  display: block;
  width: 100%;
  margin: 0.35rem 0 0;
  accent-color: var(--brand);
}

.range-pair {
  position: relative;
  height: 2.75rem;
  margin-top: 0.35rem;
}

.range-pair::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 4px;
  margin-top: -2px;
  border-radius: 999px;
  background: var(--line);
}

.range-pair-fill {
  position: absolute;
  top: 50%;
  height: 4px;
  margin-top: -2px;
  border-radius: 999px;
  background: var(--brand);
  pointer-events: none;
}

.range-pair input[type="range"] {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 2.75rem;
  margin: 0;
  background: transparent;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
}

.range-pair input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: transparent;
}

.range-pair input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  pointer-events: auto;
  width: 1.15rem;
  height: 1.15rem;
  margin-top: -0.45rem;
  border-radius: 50%;
  background: var(--brand);
  border: 2px solid #fff;
  cursor: pointer;
}

.range-pair input[type="range"]::-moz-range-track {
  height: 4px;
  background: transparent;
  border: 0;
}

.range-pair input[type="range"]::-moz-range-thumb {
  pointer-events: auto;
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 50%;
  background: var(--brand);
  border: 2px solid #fff;
  cursor: pointer;
}

.edit-actions,
.edit-parts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.65rem;
}

.map-popover p {
  margin: 0;
}

.map-popover p + p {
  margin-top: 0.35rem;
}

.graph-menu,
.video-toggles {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
}

.graph-menu {
  margin-top: 0.7rem;
}

.graph-menu .chip,
.video-toggles .chip {
  width: 100%;
  text-align: left;
}

#graphs-panel,
.video-menu {
  width: min(16rem, calc(100vw - 1.5rem));
  max-height: min(70vh, 28rem);
  overflow: auto;
}

.popover-kicker {
  font-weight: 700;
}

#edit-parts[hidden],
.map-popover[hidden],
.empty-state[hidden],
.empty-error[hidden],
.file-overlay[hidden],
.map-progress[hidden],
.graph-dock[hidden],
.chip[hidden],
.video-stage[hidden],
.video-wait[hidden],
.video-minimap-frame[hidden],
.video-menu[hidden],
.metric[hidden] {
  display: none;
}

.empty-state {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  pointer-events: none;
}

.empty-card {
  width: min(26rem, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
  padding: 1.35rem 1.25rem 1.15rem;
  border-radius: 16px;
  background: var(--tint);
  text-align: center;
  pointer-events: auto;
}

.empty-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.25;
}

.empty-lead {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
  line-height: 1.35;
}

.empty-note {
  margin: 0;
  color: color-mix(in srgb, var(--text) 72%, transparent);
  font-size: 0.95rem;
  line-height: 1.45;
}

.empty-error {
  margin: 0;
  color: #b91c1c;
  font-weight: 650;
  line-height: 1.4;
}

[data-theme="dark"] .empty-error {
  color: #f87171;
}

.empty-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.45rem;
}

.empty-privacy {
  color: var(--brand);
}

.file-overlay {
  position: absolute;
  z-index: 4;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: color-mix(in srgb, var(--brand) 32%, var(--bg));
  pointer-events: none;
}

.map-stage.is-dragover .file-overlay {
  background: color-mix(in srgb, var(--brand) 42%, var(--bg));
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.graph-dock {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  min-height: 120px;
  max-height: 45vh;
  background: var(--tint);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.dock-handle {
  flex: 0 0 2rem;
  height: 2rem;
  min-height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--tint-strong);
  cursor: ns-resize;
  touch-action: none;
  user-select: none;
}

.dock-handle::before {
  content: "";
  width: 2.75rem;
  height: 0.28rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--text) 38%, transparent);
}

body.is-resizing .dock-handle {
  background: color-mix(in srgb, var(--accent) 24%, var(--surface));
}

body.is-resizing {
  user-select: none;
}

body.is-resizing #map {
  pointer-events: none;
}

.dock-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.55rem 0.75rem 0.35rem;
}

.dock-panes {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 0.15rem 1rem 0.85rem;
}

.dock-pane:not([hidden]) {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.dock-summary {
  margin: 0 0 0.35rem;
  min-height: 1.4em;
  font-size: 0.875rem;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dock-chart {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

.dock-chart canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.dock-placeholder {
  margin: 0;
}

@media (max-width: 900px) {
  body.is-map .nav-toggle:focus-visible + .nav-burger {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
    border-radius: 6px;
  }

  body.is-map .nav-burger {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    margin-left: auto;
    min-height: 2.25rem;
    padding: 0 0.35rem;
    color: var(--text);
    font-size: 0.8rem;
    letter-spacing: 0.02em;
    cursor: pointer;
    user-select: none;
  }

  body.is-map .nav-burger-bar,
  body.is-map .nav-burger-bar::before,
  body.is-map .nav-burger-bar::after {
    display: block;
    width: 1.05rem;
    height: 2px;
    background: var(--brand);
    position: relative;
    content: "";
  }

  body.is-map .nav-burger-bar::before {
    position: absolute;
    top: -5px;
  }

  body.is-map .nav-burger-bar::after {
    position: absolute;
    top: 5px;
  }

  body.is-map .site-nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin: 0;
    padding: 0.35rem;
    flex-direction: column;
    align-items: stretch;
    background: var(--tint);
    border: 0;
    box-shadow: none;
  }

  body.is-map .nav-toggle:checked ~ .site-nav {
    display: flex;
  }

  body.is-map .nav-link {
    padding: 0.65rem 0.75rem;
    white-space: normal;
  }

  body.is-map .nav-group > .nav-link::after,
  body.is-map .nav-sub::before {
    display: none;
  }

  body.is-map .nav-sub {
    position: static;
    display: flex;
    flex-direction: column;
    flex-wrap: nowrap;
    width: auto;
    max-width: none;
    min-width: 0;
    gap: 0;
    padding: 0 0 0.25rem 0.85rem;
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  body.is-map .nav-sublink {
    display: block;
    flex: none;
    width: auto;
    min-width: 0;
    max-width: none;
    padding: 0.45rem 0.75rem;
    background: transparent;
    border-radius: 6px;
  }

  body.is-map .nav-sublink-note {
    display: none;
  }
}

@media (max-width: 720px) {

  .map-chips {
    top: auto;
    right: 0.6rem;
    left: 0.6rem;
    bottom: calc(0.65rem + env(safe-area-inset-bottom, 0px));
    max-width: none;
    align-items: stretch;
  }

  .map-app:has(.graph-dock:not([hidden])) .map-chips {
    bottom: 0.65rem;
  }

  .chip-bar {
    justify-content: flex-start;
  }

  .graph-dock {
    max-height: 40vh;
  }

  body.is-map .leaflet-bottom.leaflet-right {
    top: 0;
    bottom: auto;
  }

  .video-minimap .leaflet-bottom.leaflet-right {
    top: auto;
    bottom: 0;
  }
}

.map-app.is-video .map-stage,
.map-app.is-video .graph-dock {
  display: none;
}

.video-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #000;
}

.video-player {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.video-overlays {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.video-wait {
  position: absolute;
  z-index: 500;
  left: 0.45rem;
  right: 0.45rem;
  top: 50%;
  transform: translateY(-50%);
  margin: 0;
  padding: 0.45rem 0.55rem;
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
  pointer-events: none;
}

.video-metrics {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  right: 24rem;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 0.4rem;
  pointer-events: none;
}

.video-metrics.is-column {
  top: 4.2rem;
  right: 0.75rem;
  bottom: auto;
  left: auto;
  width: max-content;
  max-height: calc(100% - 7.6rem - env(safe-area-inset-bottom, 0px));
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: stretch;
  overflow: auto;
  pointer-events: auto;
}

.video-metrics.is-column .metric-label,
.video-metrics.is-column .metric-value {
  white-space: nowrap;
}

.metric {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 5.5rem;
  padding: 0.45rem 0.7rem;
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  color: var(--text);
}

.metric-label {
  font-size: 0.75rem;
  font-weight: 650;
  line-height: 1.2;
}

.metric-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 1rem;
  font-weight: 650;
  line-height: 1.2;
}

.video-minimap-frame {
  position: absolute;
  left: 0.75rem;
  bottom: calc(3.4rem + env(safe-area-inset-bottom, 0px));
  width: min(16rem, 46vw);
  height: min(13rem, 34vh);
  min-width: 9rem;
  min-height: 8rem;
  z-index: 3;
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--bg);
  pointer-events: auto;
}

.video-minimap-body {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

.video-minimap,
.video-minimap .leaflet-container {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  font-family: var(--font-sans);
  background: var(--bg);
}

.video-minimap .leaflet-control-attribution {
  margin-right: 2.2rem !important;
  max-width: calc(100% - 2.6rem);
}

.video-minimap-drag {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 600;
  width: 2.75rem;
  height: 2.75rem;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: grab;
  touch-action: none;
}

.video-minimap-drag:active {
  cursor: grabbing;
}

.video-minimap-drag::before {
  content: "";
  position: absolute;
  left: 0.55rem;
  top: 0.5rem;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--text);
  box-shadow:
    7px 0 0 0 var(--text),
    0 7px 0 0 var(--text),
    7px 7px 0 0 var(--text),
    0 14px 0 0 var(--text),
    7px 14px 0 0 var(--text),
    0 0 0 1px #fff,
    7px 0 0 1px #fff,
    0 7px 0 1px #fff,
    7px 7px 0 1px #fff,
    0 14px 0 1px #fff,
    7px 14px 0 1px #fff;
}

.video-minimap-resize {
  position: absolute;
  right: 0;
  bottom: 0;
  z-index: 600;
  width: 2.75rem;
  height: 2.75rem;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: nwse-resize;
  touch-action: none;
}

.video-minimap-resize::before {
  content: "";
  position: absolute;
  right: 0.45rem;
  bottom: 0.45rem;
  width: 0.7rem;
  height: 0.7rem;
  border-right: 2px solid var(--text);
  border-bottom: 2px solid var(--text);
}

.video-toolbar {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 4;
  display: flex;
  flex-flow: row wrap;
  justify-content: flex-end;
  align-items: flex-start;
  gap: 0.4rem;
  max-width: calc(100% - 12rem);
  pointer-events: auto;
}

.video-menu-wrap {
  position: relative;
}

.video-menu {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.75rem;
  border-radius: 12px;
  background: var(--tint);
}

.video-menu .unit-switch .chip {
  flex: 1 1 auto;
}

#video-fullscreen,
.video-menu-wrap > .chip {
  min-height: 2.75rem;
}

.video-stage:fullscreen,
.video-stage:-webkit-full-screen {
  width: 100%;
  height: 100%;
  background: #000;
}

@media (max-width: 720px) {
  .video-toolbar {
    top: 0.5rem;
    right: 0.5rem;
    max-width: calc(100% - 11.5rem);
  }

  .view-switch {
    top: 0.5rem;
    left: 0.5rem;
  }

  .map-app:has(#view-switch:not([hidden])) .video-metrics:not(.is-column) {
    top: 7.4rem;
    left: 0.5rem;
    right: 0.5rem;
  }

  .video-metrics {
    top: 0.5rem;
    left: 0.5rem;
    right: 11rem;
  }

  .video-metrics.is-column {
    top: 7.4rem;
    right: 0.5rem;
    left: auto;
    max-height: calc(100% - 10.8rem - env(safe-area-inset-bottom, 0px));
  }

  .video-minimap-frame {
    width: min(12rem, 62vw);
    height: min(11rem, 32vh);
  }

  .metric {
    min-width: 4.6rem;
    padding: 0.35rem 0.5rem;
  }
}
