:root {
  --bg: #0b1220;
  --panel-bg: rgba(28, 40, 65, 0.94);
  --text: #eef2ff;
  --muted: rgba(238, 242, 255, 0.75);
  --border: rgba(238, 242, 255, 0.15);
  --active: #4d90fe;
  --active-glow: rgba(77, 144, 254, 0.25);
  --danger: #f44336;
  --shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
  --radius: 14px;
  --transition-speed: 0.3s;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

/* Better behavior on iOS/iPadOS with dynamic address bars */
@supports (height: 100dvh) {
  html,
  body {
    height: 100dvh;
  }
}

/* Safe-area padding for notched devices */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body.measuring {
  cursor: crosshair;
}

/* When measuring, hide extra Leaflet UI (scale bar + status bar) */
body.measuring .leaflet-control-scale {
  display: none !important;
}

body.measure-open .leaflet-control-scale {
  display: none !important;
}

/* Scale bar: pin to the very bottom edge (respect safe area) */
.leaflet-bottom.leaflet-left .leaflet-control-scale {
  margin-left: 10px;
  margin-bottom: var(--safe-bottom);
}

/* Scale bar: segmented / ticked ruler look */
.leaflet-control-scale {
  border: 0;
  background: transparent;
  box-shadow: none;
  padding: 0;
  overflow: visible;
}

.leaflet-control-scale-line {
  position: relative;
  background: transparent;
  border: 0;
  border-radius: 0;
  margin: 0;
  padding: 0 2px 10px 2px;
  height: 22px;
  color: rgba(255, 255, 255, 0.98);
  font-weight: 700;
  line-height: 16px;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.75), 0 0 10px rgba(0, 0, 0, 0.45);
  overflow: visible;
}

.leaflet-control-scale-line::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 2px;
  height: 2px;
  background: rgba(255, 255, 255, 0.95);
}

.leaflet-control-scale-line::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 2px;
  height: 10px;
  /* Two layers:
     1) repeating ticks
     2) a right-edge cap so the last segment doesn't look "missing" after width recalcs on zoom */
  background:
    linear-gradient(
      to right,
      transparent calc(100% - 2px),
      rgba(255, 255, 255, 0.95) calc(100% - 2px),
      rgba(255, 255, 255, 0.95) 100%
    ),
    repeating-linear-gradient(
      to right,
      rgba(255, 255, 255, 0.95) 0px,
      rgba(255, 255, 255, 0.95) 2px,
      transparent 2px,
      transparent 18px
    );
}

body.measuring .status-bar {
  display: none;
}

.touch-only {
  display: none;
}

body.is-touch-only .touch-only {
  display: inline-flex;
}

/* Touch-only measuring uses a crosshair + our live overlay.
   Hide Leaflet.draw's internal vertex icons while actively drawing to avoid
   confusing "moving" points during pan/zoom gestures. */
body.is-touch-only.measure-drawing .leaflet-marker-pane .leaflet-editing-icon {
  display: none !important;
}

#map {
  height: 100%;
  width: 100%;
  background: #0a0f1a;
}

@supports (height: 100dvh) {
  #map {
    height: 100dvh;
  }
}

/* Search Bar */
.search-container {
  position: absolute;
  top: calc(0px + var(--safe-top));
  right: calc(63px + var(--safe-right));
  left: auto;
  bottom: auto;
  width: min(360px, calc(100vw - 12px));
  z-index: 1000;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel-bg);
  backdrop-filter: blur(10px);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 10px 15px;
}

.search-icon {
  color: var(--muted);
  font-size: 16px;
}

#search-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  outline: none;
}

#search-input::placeholder {
  color: var(--muted);
}

.search-clear {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: color var(--transition-speed);
}

.search-clear:hover {
  color: white;
}

.search-results {
  margin-top: 8px;
  background: var(--panel-bg);
  backdrop-filter: blur(10px);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  max-height: 300px;
  overflow-y: auto;
}

.search-result-item {
  padding: 12px 15px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background-color var(--transition-speed);
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.search-result-name {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
}

.search-result-address {
  font-size: 12px;
  color: var(--muted);
}

/* Navigation Controls */
.nav-controls {
  position: absolute;
  bottom: calc(100px + var(--safe-bottom));
  right: calc(15px + var(--safe-right));
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}

.nav-btn {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-bg);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background-color var(--transition-speed), transform var(--transition-speed);
  display: grid;
  place-items: center;
}

.nav-btn:hover {
  background-color: rgba(255, 255, 255, 0.15);
  transform: scale(1.05);
}

.nav-btn:active {
  transform: scale(0.95);
}

.compass-btn {
  position: relative;
}

#compass-icon {
  transition: transform 0.5s ease;
}

/* Coordinates Display */
.coords-display {
  position: absolute;
  top: calc(0px + var(--safe-top));
  right: calc(63px + var(--safe-right));
  bottom: auto;
  left: auto;
  background: transparent;
  backdrop-filter: none;
  border-radius: 0;
  box-shadow: none;
  border: 0;
  padding: 0;
  font-size: 22px;
  font-weight: 900;
  color: #000;
  -webkit-text-stroke: 0.6px rgba(255, 255, 255, 0.92);
  text-shadow:
    0 0 2px rgba(255, 255, 255, 0.95),
    1px 0 2px rgba(255, 255, 255, 0.95),
    -1px 0 2px rgba(255, 255, 255, 0.95),
    0 1px 2px rgba(255, 255, 255, 0.95),
    0 -1px 2px rgba(255, 255, 255, 0.95);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0;
  line-height: 1.05;
  white-space: pre-line;
  z-index: 998;
  transition: opacity var(--transition-speed);
  pointer-events: auto;
  cursor: pointer;
  user-select: none;
}

.coords-display i {
  display: none;
}

/* Ruler */
.ruler {
  position: absolute;
  bottom: calc(85px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  z-index: 1001;
  pointer-events: none;
}

.ruler-bar {
  height: 6px;
  min-width: 80px;
  max-width: 220px;
  width: 160px;
  background: linear-gradient(90deg, rgba(255,255,255,0.25) 0%, rgba(255,255,255,0.55) 50%, rgba(255,255,255,0.25) 100%);
  border-radius: 6px;
}

.ruler-label {
  font-size: 13px;
  color: var(--text);
}

/* Crosshair */
.crosshair {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1002;
  display: grid;
  place-items: center;
}

.crosshair::before,
.crosshair::after {
  content: '';
  position: absolute;
  background: #ffc107;
}

.crosshair::before {
  width: 28px;
  height: 2px;
}

.crosshair::after {
  width: 2px;
  height: 28px;
}

/* Floating Toolbar */
.map-toolbar {
  position: absolute;
  top: calc(0px + var(--safe-top));
  right: calc(0px + var(--safe-right));
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1002;
}

.toolbar-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel-bg);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background-color var(--transition-speed), transform var(--transition-speed), box-shadow var(--transition-speed);
  display: grid;
  place-items: center;
}

.toolbar-btn:hover {
  transform: translateY(-2px);
  background-color: rgba(255, 255, 255, 0.15);
}

.toolbar-btn.active {
  background-color: var(--active);
  color: white;
  box-shadow: 0 0 0 4px var(--active-glow);
  transform: scale(1.05);
}

/* Floating Panels */
.floating-panel {
  position: absolute;
  top: calc(0px + var(--safe-top));
  right: calc(63px + var(--safe-right));
  width: 320px;
  max-height: calc(100% - var(--safe-top));
  background: var(--panel-bg);
  backdrop-filter: blur(10px);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  z-index: 1001;
  padding: 15px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: opacity var(--transition-speed) ease, transform var(--transition-speed) ease;
  transform: translateX(10px);
  opacity: 0;
  pointer-events: auto;
}

.floating-panel[hidden] {
  display: flex; /* Keep it in layout for transition */
  visibility: hidden;
  opacity: 0;
  transform: translateX(10px);
  pointer-events: none;
}

.floating-panel:not([hidden]) {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.floating-panel h3 {
  margin: 0 0 15px;
  font-size: 18px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
  font-weight: 600;
}

/* Basemap Panel - List Style */
.floating-panel#basemap-panel {
  width: auto;
  max-width: 260px;
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
  overflow: visible;
}

#basemap-panel h3 {
  display: none;
}

#basemap-panel .basemap-gallery {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 10px;
  padding: 8px 10px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  scrollbar-width: none;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  backdrop-filter: none;
  align-items: flex-start;
}

#basemap-panel .basemap-gallery::-webkit-scrollbar {
  width: 0;
  height: 0;
}

/* Bubble animation */
#basemap-panel .basemap-item {
  opacity: 0;
  transform: translateX(10px) scale(0.85);
  transition: opacity 220ms ease, transform 260ms ease;
  transition-delay: calc(var(--i, 0) * 24ms);
}

#basemap-panel:not([hidden]) .basemap-item {
  opacity: 1;
  transform: translateX(0) scale(1);
}

.basemap-gallery {
  display: flex;
  flex-direction: row;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px 2px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  scrollbar-width: none;
}

.basemap-gallery::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.wayback-panel {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.wayback-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.wayback-title {
  font-size: 14px;
  font-weight: 600;
}

.wayback-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  user-select: none;
}

.wayback-toggle input {
  width: 16px;
  height: 16px;
}

.wayback-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.wayback-row {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 10px;
}

.wayback-label {
  font-size: 12px;
  color: var(--muted);
}

.wayback-value {
  font-size: 12px;
  color: var(--text);
  text-align: right;
}

.wayback-row input[type='range'] {
  width: 100%;
}

.wayback-snapshot {
  font-size: 12px;
  color: var(--muted);
  padding: 8px 10px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
}

.basemap-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  cursor: pointer;
  border-radius: 12px;
  padding: 6px;
  width: 96px;
  min-height: 84px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  transition: background-color var(--transition-speed), border-color var(--transition-speed), transform var(--transition-speed);
  scroll-snap-align: start;
  user-select: none;
}

/* In the basemap panel, render sources as translucent circular bubbles */
#basemap-panel .basemap-item {
  width: 72px;
  min-height: 78px;
  height: auto;
  padding: 0;
  gap: 6px;
  border-radius: 16px;
  background: transparent;
  border: 0;
  box-shadow: none;
  scroll-snap-align: start;
}

#basemap-panel .basemap-item:hover {
  transform: translateY(-1px) scale(1.02);
}

#basemap-panel .basemap-item span {
  display: block;
  font-size: 11px;
  line-height: 1.1;
  text-align: center;
  color: rgba(255, 255, 255, 0.92);
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  max-width: 72px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#basemap-panel .basemap-thumb {
  width: 56px;
  height: 56px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(238, 242, 255, 0.18);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.35);
}

#basemap-panel .basemap-thumb img {
  border-radius: 999px;
}

#basemap-panel .basemap-thumb-text {
  font-size: 12px;
}

.basemap-item:hover {
  background-color: rgba(255, 255, 255, 0.08);
  transform: translateY(-1px);
}

.basemap-thumb {
  width: 80px;
  height: 50px;
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.basemap-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.basemap-thumb.missing img {
  display: none;
}

.basemap-item span {
  font-size: 11px;
  font-weight: 500;
  line-height: 1.2;
  text-align: center;
}

.wayback-controls-host {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transform: translateY(-6px);
  visibility: hidden;
  pointer-events: none;
  transition: max-height 260ms ease, opacity 220ms ease, transform 220ms ease, visibility 0s linear 260ms;
}

.wayback-controls-host.is-open {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  max-height: 220px;
  opacity: 1;
  transform: translateY(0);
  visibility: visible;
  pointer-events: auto;
  transition: max-height 260ms ease, opacity 220ms ease, transform 220ms ease, visibility 0s linear 0s;
}

/* Keep Wayback controls consistent with the bubble menu */
#basemap-panel .wayback-controls-host.is-open {
  margin-top: 8px;
  padding: 10px;
  border-radius: 14px;
  background: rgba(28, 40, 65, 0.84);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.basemap-item.active {
  border-color: var(--active);
  background-color: var(--active-glow);
}

/* Measure Panel */
.measure-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.measure-btn {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font-size: 15px;
  transition: background-color var(--transition-speed);
}

.measure-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.measure-btn[aria-pressed="true"] {
  border-color: var(--active);
  background: var(--active-glow);
}

.measure-btn[aria-pressed="true"] i {
  color: var(--active);
}

.measure-btn i {
  font-size: 20px;
  width: 22px;
  text-align: center;
  color: var(--muted);
}

.measure-row {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
  padding: 6px 8px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
}

.measure-row label {
  font-size: 13px;
  color: var(--muted);
}

.measure-row select {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
}

.measure-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 4px 0;
}

/* Files Panel */
.dropzone {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 14px;
  text-align: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
  margin-bottom: 12px;
}

.dropzone.dragover {
  border-color: var(--active);
  background: var(--active-glow);
  color: var(--text);
}

.layer-list {
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.layer-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
}

.layer-item .layer-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.layer-item .layer-title {
  font-size: 14px;
  font-weight: 600;
}

.layer-item .layer-sub {
  font-size: 12px;
  color: var(--muted);
}

.layer-actions {
  display: flex;
  gap: 8px;
}

.chip-btn {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
  transition: background-color var(--transition-speed);
}

.chip-btn.primary {
  background: var(--active);
  border-color: var(--active);
  color: #ffffff;
  font-weight: 700;
  padding: 10px 14px;
  font-size: 14px;
}

.chip-btn.danger {
  background: rgba(244, 67, 54, 0.18);
  border-color: rgba(244, 67, 54, 0.35);
}

.chip-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

/* Status & Result Display */
.status-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.7), transparent);
  color: var(--muted);
  font-size: 13px;
  padding: 15px;
  padding-bottom: calc(15px + var(--safe-bottom));
  z-index: 999;
  text-align: center;
  pointer-events: none; /* Allow clicks to pass through */
  transition: opacity var(--transition-speed);
}

/* Faster-feeling taps on mobile */
button,
.toolbar-btn,
.nav-btn,
.chip-btn,
.measure-btn {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.result-display {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  min-width: 280px;
  background: var(--panel-bg);
  backdrop-filter: blur(10px);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  z-index: 1002;
  padding: 15px 20px;
  font-size: 16px;
  line-height: 1.5;
  transition: opacity var(--transition-speed), transform var(--transition-speed);
}

.result-display[hidden] {
  display: block;
  visibility: hidden;
  opacity: 0;
  transform: translate(-50%, 10px);
}

.close-btn {
  position: absolute;
  top: 5px;
  right: 8px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 24px;
  cursor: pointer;
  transition: color var(--transition-speed);
}

.close-btn:hover {
  color: white;
}

/* Leaflet Draw Customization */
.leaflet-draw-toolbar {
  display: none !important; /* Hide default toolbar */
}

/* Leaflet.draw edit handles (vertex markers) */
.leaflet-marker-icon.leaflet-div-icon.leaflet-editing-icon,
.leaflet-div-icon.leaflet-editing-icon {
  width: 14px !important;
  height: 14px !important;
  margin-left: -7px !important;
  margin-top: -7px !important;
  border-radius: 999px !important;
  background: #ffc107 !important;
  border: 2px solid rgba(0, 0, 0, 0.55) !important;
  box-shadow: 0 0 0 3px rgba(255, 193, 7, 0.25) !important;
}

.leaflet-marker-icon.leaflet-div-icon.leaflet-editing-icon:hover {
  box-shadow: 0 0 0 4px rgba(255, 193, 7, 0.32) !important;
}

/* Responsive */
@media (max-width: 600px) {
  .search-container {
    left: calc(0px + var(--safe-left));
    right: calc(0px + var(--safe-right));
    width: auto;
    top: calc(0px + var(--safe-top));
  }

  .floating-panel {
    top: calc(0px + var(--safe-top));
    right: calc(0px + var(--safe-right));
    left: calc(0px + var(--safe-left));
    width: auto;
    max-height: 45%;
  }

  .map-toolbar {
    top: calc(0px + var(--safe-top));
    left: calc(0px + var(--safe-left));
    right: auto;
    flex-direction: row;
    background: var(--panel-bg);
    padding: 5px;
    border-radius: 30px;
  }

  .toolbar-btn {
    width: 42px;
    height: 42px;
    box-shadow: none;
  }

  .nav-controls {
    bottom: 80px;
  }

  .coords-display {
    top: calc(0px + var(--safe-top));
    right: calc(0px + var(--safe-right));
    left: auto;
    bottom: auto;
    justify-content: flex-end;
    font-size: 21px;
  }

  /* Basemap bubble menu: place under the top toolbar row */
  .floating-panel#basemap-panel {
    top: calc(52px + var(--safe-top));
    left: calc(0px + var(--safe-left));
    right: auto;
    max-width: calc(100vw - var(--safe-left) - var(--safe-right));
  }
}

/* Touch-only: Measure panel as a horizontal bar */
body.is-touch-only #measure-tools.floating-panel {
  left: calc(12px + var(--safe-left));
  right: calc(12px + var(--safe-right));
  /* Default (tablet/large): place under the vertical toolbar column */
  top: calc(250px + var(--safe-top));
  width: auto;
  max-height: none;
  padding: 10px;
}

body.is-touch-only #measure-tools.floating-panel h3 {
  display: none;
}

body.is-touch-only #measure-tools .measure-controls {
  flex-direction: row;
  gap: 10px;
}

body.is-touch-only #measure-tools .measure-btn {
  flex: 1;
  justify-content: center;
  text-align: center;
  padding: 9px 8px;
  font-size: 13px;
  gap: 10px;
}

body.is-touch-only #measure-tools .measure-btn i {
  font-size: 16px;
  width: 18px;
}

/* On phones (toolbar becomes horizontal), put measure bar directly under it */
@media (max-width: 600px) {
  body.is-touch-only #measure-tools.floating-panel {
    left: 15px;
    right: 15px;
    top: calc(128px + var(--safe-top));
    padding: 8px;
  }
}

/* Touch-only: keep Measure menu compact (only toggles) */
body.is-touch-only #measure-tools .measure-row,
body.is-touch-only #measure-tools .measure-actions,
body.is-touch-only #measure-tools #btn-clear-measure {
  display: none;
}

/* Bottom Add/End bar (touch-only measuring) */
.measure-mobile-bar {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(78px + var(--safe-bottom));
  z-index: 1004;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 10px;
  border-radius: 0;
  border: 0;
  background: transparent;
  backdrop-filter: none;
  box-shadow: none;
  width: calc(100% - 24px);
  max-width: 560px;
  align-items: center;
}

/* Bubble-style buttons (match basemap source circles) */
.measure-mobile-bar .chip-btn {
  width: 56px;
  height: 56px;
  border-radius: 999px;
  padding: 0;
  display: grid;
  place-items: center;
  text-align: center;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.05;
  color: #000;
  -webkit-text-stroke: 0.6px rgba(255, 255, 255, 0.92);
  text-shadow:
    0 0 2px rgba(255, 255, 255, 0.95),
    1px 0 2px rgba(255, 255, 255, 0.95),
    -1px 0 2px rgba(255, 255, 255, 0.95),
    0 1px 2px rgba(255, 255, 255, 0.95),
    0 -1px 2px rgba(255, 255, 255, 0.95);
  letter-spacing: 0.2px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(238, 242, 255, 0.18);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.measure-mobile-bar .chip-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

/* Override variant styles inside the mobile bar only */
.measure-mobile-bar .chip-btn.primary,
.measure-mobile-bar .chip-btn.danger {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(238, 242, 255, 0.18);
  color: #000;
  font-weight: 900;
}

.measure-mobile-bar #btn-measure-add {
  grid-column: 1 / -1;
  justify-self: center;
  width: 76px;
  height: 76px;
  font-size: 13px;
  font-weight: 900;
}

.measure-mobile-bar #btn-measure-clear-mobile {
  font-weight: 900;
}

.measure-mobile-bar #btn-measure-end,
.measure-mobile-bar #btn-measure-undo-mobile,
.measure-mobile-bar #btn-measure-clear-mobile {
  justify-self: center;
}

.measure-mobile-bar[hidden] {
  display: none;
}

/* Avoid overlap with the bottom bar on touch-only */
body.is-touch-only.measuring .nav-controls {
  bottom: calc(160px + var(--safe-bottom));
}

body.is-touch-only.measuring .ruler {
  bottom: calc(160px + var(--safe-bottom));
}

/* Hide status bar while measuring handled globally via body.measuring */

/* Final tooltip label styling */
.leaflet-tooltip.measure-final-tooltip {
  background: var(--panel-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  padding: 8px 10px;
  font-weight: 800;
  font-size: 13px;
}

.leaflet-tooltip.measure-final-tooltip:before {
  display: none;
}

/* Live measurement label over geometry */
.measure-live-label-wrap {
  pointer-events: none;
}

.measure-live-label-wrap.is-clickable {
  pointer-events: auto;
  cursor: pointer;
}

.measure-live-label-wrap.is-clickable .measure-live-label {
  pointer-events: auto;
}

.measure-live-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-bg);
  color: var(--text);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

/* Custom measurement (v2) point markers: start / mid / end */
.measure-v2-pt-wrap {
  width: 12px;
  height: 12px;
}

.measure-v2-pt-wrap .measure-v2-pt {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

.measure-v2-start .measure-v2-pt {
  background: var(--active);
}

.measure-v2-mid .measure-v2-pt {
  background: #ffc107;
}

.measure-v2-end .measure-v2-pt {
  background: var(--danger);
}
