/**
 * FusedMaps - Default Styles
 * https://github.com/milind-soni/fusedmaps
 * 
 * Matching the original map_utils.py design
 */

/* Theme tokens (copied from map_utils.py) */
:root{
  --ui-bg: #0b0d10;
  --ui-panel-bg: rgba(24,24,24,0.98);
  --ui-float-bg: rgba(26,26,26,0.95);
  --ui-float-bg-2: rgba(26,26,26,0.90);
  --ui-surface: rgba(40,40,40,0.60);
  --ui-border: #333;
  --ui-border-2: #424242;
  --ui-text: #f5f5f5;
  --ui-text-2: #ddd;
  --ui-muted: #aaa;
  --ui-muted-2: #999;
  --ui-muted-3: #666;
  --ui-shadow: rgba(0,0,0,0.30);
  --ui-shadow-2: rgba(0,0,0,0.50);
  --ui-accent: #E8FF59;
  --ui-elements: #E8FF59;
  --ui-category: #888;
  --ui-scroll-track: rgba(255,255,255,0.06);
  --ui-scroll-thumb: rgba(255,255,255,0.22);
  --ui-scroll-thumb-hover: rgba(255,255,255,0.30);
  --ui-input-bg: #1a1a1a;
  --ui-output-bg: #111;
  --ui-tooltip-bg: rgba(15,15,15,0.95);
  --ui-tooltip-border: rgba(255,255,255,0.10);
  --ui-tooltip-title: rgba(255,255,255,0.72);
  --ui-tooltip-key: rgba(255,255,255,0.60);
  --ui-tooltip-val: #fff;
}

html[data-theme="light"]{
  --ui-bg: #FFFFFF;
  --ui-panel-bg: rgba(255,255,255,0.98);
  --ui-float-bg: rgba(255,255,255,0.95);
  --ui-float-bg-2: rgba(255,255,255,0.92);
  --ui-surface: rgba(124,155,182,0.10);
  --ui-border: rgba(124,155,182,0.55);
  --ui-border-2: rgba(124,155,182,0.75);
  --ui-text: #23313b;
  --ui-text-2: #23313b;
  --ui-muted: rgba(73,104,131,0.85);
  --ui-muted-2: rgba(73,104,131,0.75);
  --ui-muted-3: rgba(73,104,131,0.95);
  --ui-shadow: rgba(73,104,131,0.16);
  --ui-shadow-2: rgba(73,104,131,0.24);
  --ui-accent: #7C9BB6;
  --ui-elements: #7C9BB6;
  --ui-category: #496883;
  --ui-scroll-track: rgba(124,155,182,0.12);
  --ui-scroll-thumb: rgba(73,104,131,0.30);
  --ui-scroll-thumb-hover: rgba(73,104,131,0.42);
  --ui-input-bg: rgba(255,255,255,0.98);
  --ui-output-bg: rgba(255,255,255,0.98);
  --ui-tooltip-bg: rgba(255,255,255,0.98);
  --ui-tooltip-border: rgba(124,155,182,0.55);
  --ui-tooltip-title: rgba(73,104,131,0.95);
  --ui-tooltip-key: rgba(73,104,131,0.90);
  --ui-tooltip-val: #23313b;
}

/* Base layout */
html, body {
  margin: 0;
  height: 100%;
  width: 100%;
  display: flex;
  overflow: hidden;
}

#map {
  flex: 1;
  height: 100%;
}

body { background: var(--ui-bg); }

/* Debug Panel (minimal) */
#debug-shell {
  position: fixed;
  left: 0;
  top: 0;
  height: 100%;
  z-index: 200;
  --debug-panel-w: 280px;
}
#debug-panel {
  position: fixed;
  left: 0;
  top: 0;
  width: 280px;
  min-width: 240px;
  max-width: 520px;
  height: 100%;
  background: var(--ui-panel-bg);
  border-right: 1px solid var(--ui-border);
  transform: translateX(0);
  transition: transform 0.2s ease;
  z-index: 199;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
#debug-panel, #debug-panel * { box-sizing: border-box; }
#debug-panel.collapsed { transform: translateX(-100%); }
#debug-toggle {
  position: fixed;
  top: 12px;
  width: 24px;
  height: 24px;
  background: var(--ui-float-bg-2);
  border: 1px solid var(--ui-border);
  border-left: none;
  border-radius: 0 6px 6px 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ui-muted);
  font-size: 14px;
  z-index: 200;
  transition: background 0.15s, color 0.15s;
  left: var(--debug-panel-w, 280px);
}
#debug-toggle:hover { background: var(--ui-float-bg); color: var(--ui-text); }
#debug-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--ui-scroll-thumb) var(--ui-scroll-track);
}
#debug-content::-webkit-scrollbar { width: 6px; }
#debug-content::-webkit-scrollbar-track { background: var(--ui-scroll-track); border-radius: 6px; }
#debug-content::-webkit-scrollbar-thumb { background: var(--ui-scroll-thumb); border-radius: 6px; }
#debug-content::-webkit-scrollbar-thumb:hover { background: var(--ui-scroll-thumb-hover); }
.debug-section { background: var(--ui-surface); border: 1px solid var(--ui-border); border-radius: 6px; padding: 10px; }
.debug-section-title { font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--ui-category); margin-bottom: 8px; }
.debug-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: 6px;
}
.debug-tab-btn {
  flex: 1 1 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 7px 10px;
  font-size: 11px;
  font-weight: 500;
  color: var(--ui-muted-2);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.debug-tab-btn:hover {
  background: rgba(255,255,255,0.06);
  color: var(--ui-text-2);
}
.debug-tab-btn.active {
  background: var(--ui-input-bg);
  border-color: var(--ui-border);
  color: var(--ui-text);
}
.debug-tab-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#debug-panel .CodeMirror {
  height: 180px;
  font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  background: var(--ui-input-bg);
  color: var(--ui-text-2);
  border: 1px solid var(--ui-border);
  border-radius: 6px;
}
#debug-panel .CodeMirror-focused { outline: none; }
#debug-panel .CodeMirror-gutters {
  background: var(--ui-input-bg);
  border-right: 1px solid var(--ui-border);
}
#debug-panel .CodeMirror-linenumber { color: var(--ui-muted-3); }
#debug-panel .CodeMirror-cursor { border-left: 2px solid var(--ui-text); }
#debug-panel .CodeMirror-selected { background: rgba(255,255,255,0.12); }
.debug-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: nowrap; }
.debug-row:last-child { margin-bottom: 0; }
.debug-label { font-size: 11px; color: var(--ui-muted-2); width: 84px; flex: 0 0 84px; }
.debug-toggles { display: flex; flex-wrap: wrap; gap: 8px 12px; }
.debug-checkbox { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--ui-muted-2); cursor: pointer; }
html[data-theme="dark"] .debug-checkbox input { width: 14px; height: 14px; cursor: pointer; accent-color: #666; }
html[data-theme="light"] .debug-checkbox input { width: 14px; height: 14px; cursor: pointer; accent-color: var(--ui-elements); }
.debug-select {
  flex: 1 1 auto;
  min-width: 0;
  width: auto;
  background: var(--ui-input-bg);
  border: 1px solid var(--ui-border);
  border-radius: 4px;
  padding: 5px 8px;
  font-size: 11px;
  color: var(--ui-text-2);
  outline: none;
  cursor: pointer;
}
.debug-select:focus { border-color: var(--ui-border-2); }
.pal-hidden { display: none; }
/* Palette dropdown (map_utils.py style: swatch-only) */
.pal-dd { flex: 1 1 auto; min-width: 0; width: 100%; position: relative; }
.pal-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  background: var(--ui-input-bg);
  border: 1px solid var(--ui-border);
  border-radius: 4px;
  padding: 0;
  color: var(--ui-text-2);
  font-size: 11px;
  cursor: pointer;
}
.pal-trigger:hover { border-color: var(--ui-border-2); }
.pal-name { display: none; }
.pal-swatch { width: 100%; height: 12px; border-radius: 3px; border: 1px solid var(--ui-border); background: linear-gradient(90deg, #555, #999); }
.pal-menu {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  background: var(--ui-output-bg);
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  max-height: 220px;
  overflow: auto;
  z-index: 9999;
  box-shadow: 0 8px 24px var(--ui-shadow-2);
  width: 100%;
  scrollbar-width: thin;
  scrollbar-color: var(--ui-scroll-thumb) var(--ui-scroll-track);
}
.pal-menu::-webkit-scrollbar { width: 6px; }
.pal-menu::-webkit-scrollbar-track { background: var(--ui-scroll-track); border-radius: 6px; }
.pal-menu::-webkit-scrollbar-thumb { background: var(--ui-scroll-thumb); border-radius: 6px; }
.pal-menu::-webkit-scrollbar-thumb:hover { background: var(--ui-scroll-thumb-hover); }
.pal-item { display: flex; align-items: center; justify-content: center; padding: 6px 0; cursor: pointer; }
.pal-item:hover { background: rgba(124,155,182,0.14); }
.pal-item-name { display: none; }
.pal-item-swatch { width: 100%; height: 12px; border-radius: 3px; border: 1px solid var(--ui-border); }
.debug-input-sm { flex: 0 0 56px; width: 56px; min-width: 56px; text-align: center; }
.debug-slider { flex: 1 1 auto; min-width: 0; height: 4px; background: var(--ui-border); border-radius: 2px; -webkit-appearance: none; cursor: pointer; }
html[data-theme="dark"] .debug-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; background: #888; border-radius: 50%; cursor: pointer; }
html[data-theme="dark"] .debug-slider::-webkit-slider-thumb:hover { background: #aaa; }
html[data-theme="light"] .debug-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; background: var(--ui-elements); border-radius: 50%; cursor: pointer; }
html[data-theme="light"] .debug-slider::-webkit-slider-thumb:hover { background: var(--ui-accent); }
.debug-color { width: 34px; height: 22px; padding: 0; border: 1px solid var(--ui-border); border-radius: 4px; background: transparent; cursor: pointer; }
.debug-color-label { font-size: 11px; color: var(--ui-muted-2); }
#debug-content { color-scheme: light dark; }

/* Dual-thumb range (map_utils style) */
.debug-dual-range { position: relative; flex: 1 1 auto; min-width: 0; height: 18px; }
.debug-dual-range::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 7px;
  height: 4px;
  background: var(--ui-border);
  border-radius: 2px;
}
.debug-dual-range input[type="range"] {
  position: absolute;
  left: 0;
  top: 7px;
  width: 100%;
  height: 4px;
  margin: 0;
  background: transparent;
  pointer-events: none;
  -webkit-appearance: none;
  z-index: 2;
}
.debug-dual-range input[type="range"]::-webkit-slider-runnable-track { height: 4px; background: transparent; border-radius: 2px; }
html[data-theme="dark"] .debug-dual-range input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  pointer-events: auto;
  width: 12px;
  height: 12px;
  margin-top: -4px;
  background: #888;
  border-radius: 50%;
  cursor: pointer;
  position: relative;
  z-index: 3;
}
html[data-theme="dark"] .debug-dual-range input[type="range"]::-webkit-slider-thumb:hover { background: #aaa; }
html[data-theme="light"] .debug-dual-range input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  pointer-events: auto;
  width: 12px;
  height: 12px;
  margin-top: -4px;
  background: var(--ui-elements);
  border-radius: 50%;
  cursor: pointer;
  position: relative;
  z-index: 3;
}
html[data-theme="light"] .debug-dual-range input[type="range"]::-webkit-slider-thumb:hover { background: var(--ui-accent); }
.debug-dual-range input[type="range"]::-moz-range-track { height: 4px; background: transparent; border-radius: 2px; }
html[data-theme="dark"] .debug-dual-range input[type="range"]::-moz-range-thumb {
  pointer-events: auto;
  width: 12px;
  height: 12px;
  background: #888;
  border-radius: 50%;
  cursor: pointer;
  border: none;
}
html[data-theme="light"] .debug-dual-range input[type="range"]::-moz-range-thumb {
  pointer-events: auto;
  width: 12px;
  height: 12px;
  background: var(--ui-elements);
  border-radius: 50%;
  cursor: pointer;
  border: none;
}
#debug-resize-handle { position: absolute; top: 0; right: 0; width: 8px; height: 100%; cursor: col-resize; background: transparent; }
#debug-resize-handle:hover { background: linear-gradient(to left, rgba(232,255,89,0.95) 0 2px, rgba(255,255,255,0.04) 2px 100%); }
.debug-input {
  flex: 1 1 auto;
  min-width: 0;
  background: var(--ui-input-bg);
  border: 1px solid var(--ui-border);
  border-radius: 4px;
  padding: 5px 8px;
  font-size: 11px;
  color: var(--ui-text-2);
  outline: none;
}
.debug-input:focus { border-color: var(--ui-border-2); }
.debug-output {
  width: 100%;
  height: 120px;
  background: var(--ui-output-bg);
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  padding: 8px;
  font-size: 11px;
  color: var(--ui-text-2);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  resize: vertical;
}
.debug-btn {
  background: var(--ui-float-bg);
  border: 1px solid var(--ui-border);
  color: var(--ui-text);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 11px;
  cursor: pointer;
}
.debug-btn:hover { border-color: var(--ui-border-2); }
.debug-btn-secondary {
  background: transparent;
  color: var(--ui-text-2);
}

/* Tooltip */
#tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--ui-tooltip-bg);
  color: var(--ui-text);
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 12px;
  display: none;
  z-index: 6;
  max-width: 320px;
  border: 1px solid var(--ui-tooltip-border);
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  font-family: Inter, 'SF Pro Display', 'Segoe UI', sans-serif;
}

#tooltip .tt-title {
  display: block;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  font-size: 11px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: var(--ui-tooltip-title);
}

#tooltip .tt-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  gap: 12px;
}

#tooltip .tt-key {
  color: var(--ui-tooltip-key);
  font-size: 11px;
}

#tooltip .tt-val {
  color: var(--ui-tooltip-val);
  font-weight: 500;
  text-align: right;
  max-width: 180px;
  word-break: break-word;
}

/* Widget Containers - horizontal icon bar */
.fm-widget-container {
  position: fixed;
  display: flex;
  flex-direction: row;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}
.fm-widget-container > * {
  pointer-events: auto;
}
.fm-widget-top-left {
  top: 12px;
  left: 12px;
  align-items: flex-start;
}
.fm-widget-top-right {
  top: 12px;
  right: 12px;
  align-items: flex-start;
  flex-direction: row-reverse; /* Icons appear left-to-right as added */
}
.fm-widget-bottom-left {
  bottom: 12px;
  left: 12px;
  align-items: flex-end;
  flex-direction: column;
}
.fm-widget-bottom-right {
  bottom: 12px;
  right: 12px;
  align-items: flex-end;
  flex-direction: column;
}
.fm-widget-top-center {
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  align-items: center;
}

/* Dropdown Widget (icon + expandable panel below) */
.fm-dropdown-widget {
  position: relative;
}

/* Dropdown Toggle Button (always visible) */
.fm-dropdown-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  background: var(--ui-float-bg);
  border: none;
  border-radius: 50%;
  color: var(--ui-text);
  cursor: pointer;
  transition: background 0.15s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.fm-dropdown-toggle:hover {
  background: #3a3a3a;
}
html[data-theme="light"] .fm-dropdown-toggle:hover {
  background: #e8e8e8;
}
.fm-dropdown-toggle svg {
  width: 16px;
  height: 16px;
  opacity: 0.8;
}
.fm-dropdown-widget:not(.collapsed) .fm-dropdown-toggle {
  background: #3a3a3a;
}
html[data-theme="light"] .fm-dropdown-widget:not(.collapsed) .fm-dropdown-toggle {
  background: #e8e8e8;
}

/* Dropdown Panel (expandable content) */
.fm-dropdown-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 180px;
  background: var(--ui-float-bg);
  border: 1px solid var(--ui-border-2);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  z-index: 110;
}

/* Panel positioning for different corners */
.fm-widget-top-left .fm-dropdown-panel {
  left: 0;
  right: auto;
}
.fm-widget-bottom-left .fm-dropdown-panel,
.fm-widget-bottom-right .fm-dropdown-panel {
  top: auto;
  bottom: calc(100% + 8px);
}

/* Hide panel when collapsed */
.fm-dropdown-widget.collapsed .fm-dropdown-panel {
  display: none;
}

/* Dropdown Header */
.fm-dropdown-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--ui-border);
}
.fm-dropdown-header-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ui-muted);
}
.fm-dropdown-header-icon svg {
  width: 16px;
  height: 16px;
}
.fm-dropdown-title {
  flex: 1;
  font-size: 13px;
  font-weight: 700;
  color: var(--ui-text);
}
.fm-dropdown-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 4px;
  color: var(--ui-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.fm-dropdown-close:hover {
  background: #3a3a3a;
  color: var(--ui-text);
}
html[data-theme="light"] .fm-dropdown-close:hover {
  background: #e8e8e8;
}
.fm-dropdown-close svg {
  width: 14px;
  height: 14px;
}

/* Location Search / Geocoder */
#location-search {
  width: 240px;
  z-index: 101;
}

#location-search input {
  width: 100%;
  padding: 10px 12px;
  background: var(--ui-float-bg);
  border: 1px solid var(--ui-border-2);
  border-radius: 8px;
  color: var(--ui-text);
  font-size: 13px;
  font-family: Inter, 'SF Pro Display', 'Segoe UI', sans-serif;
  outline: none;
  box-sizing: border-box;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

#location-search input::placeholder {
  color: var(--ui-muted-2);
}

#location-search input:focus {
  border-color: var(--ui-elements);
}

#location-search .search-results {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: var(--ui-float-bg);
  border: 1px solid var(--ui-border-2);
  border-radius: 8px;
  max-height: 280px;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

#location-search .search-results.visible {
  display: block;
}

#location-search .search-item {
  padding: 10px 12px;
  border-bottom: 1px solid var(--ui-border);
  cursor: pointer;
  transition: background 0.15s;
}

#location-search .search-item:last-child {
  border-bottom: none;
}

#location-search .search-item:hover {
  background: var(--ui-surface);
}

#location-search .search-item .place-name {
  font-weight: 500;
  color: var(--ui-text);
  font-size: 13px;
}

#location-search .search-item .place-context {
  font-size: 11px;
  color: var(--ui-muted);
  margin-top: 2px;
}

/* Layer Toggle Panel */
#layer-panel {
  font-family: Inter, 'SF Pro Display', 'Segoe UI', sans-serif;
  color: var(--ui-text);
}

#layer-panel .fm-dropdown-panel {
  min-width: 200px;
}

/* Layer list container */
#layer-list {
  max-height: 300px;
  overflow-y: auto;
}

/* Layer items - with gradient gutter on left edge */
.layer-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 8px 16px; /* text padding; gutter overlaps left 6px */
  border-bottom: 1px solid var(--ui-border);
  position: relative;
  cursor: pointer;
}

.layer-item:last-child {
  border-bottom: none;
}

/* Palette gradient gutter on the left edge - fully flush */
.layer-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  background: var(--layer-strip, rgba(255, 255, 255, 0.22));
}

/* Eye icon */
.layer-item .layer-eye {
  width: 18px;
  height: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ui-muted);
  font-size: 14px;
  transition: color 0.15s;
  user-select: none;
  margin-left: auto; /* push eye to the far right */
}

.layer-item .layer-eye:hover {
  color: var(--ui-text);
}

.layer-item.disabled .layer-eye {
  color: rgba(73, 104, 131, 0.45);
}

/* Layer name */
.layer-item .layer-name {
  flex: 1;
  font-size: 12px;
  color: var(--ui-text-2);
  transition: color 0.15s;
}

.layer-item.disabled .layer-name {
  color: rgba(73, 104, 131, 0.55);
}

/* Legend */
.color-legend {
  font-family: Inter, 'SF Pro Display', 'Segoe UI', sans-serif;
  color: var(--ui-text);
  font-size: 11px;
}

.color-legend .fm-dropdown-panel {
  min-width: 160px;
  /* Keep right alignment - since legend icon is left of layers icon, panels won't overlap */
  right: 0;
  left: auto;
}

/* Legend content */
#legend-content {
  padding: 10px 12px;
}

/* Bottom-left control padding (zoom/home + scale bar) */
.mapboxgl-ctrl-bottom-left .mapboxgl-ctrl {
  margin: 0 0 8px 20px;
}

.legend-layer {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--ui-border);
}

.legend-layer:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.legend-layer .legend-title {
  margin-bottom: 6px;
  font-weight: 500;
  font-size: 12px;
  color: var(--ui-text);
}

.legend-layer .legend-line {
  width: 20px;
  height: 3px;
  border-radius: 1px;
}

.legend-layer .legend-gradient {
  height: 10px;
  border-radius: 2px;
  margin-bottom: 4px;
  border: 1px solid var(--ui-border);
}

.legend-layer .legend-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--ui-muted);
}

.legend-layer .legend-categories {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
  max-height: 440px;
  overflow-y: scroll;
  padding-right: 4px;
}

.legend-layer .legend-categories::-webkit-scrollbar {
  width: 4px;
}

.legend-layer .legend-categories::-webkit-scrollbar-track {
  background: var(--ui-scroll-track);
  border-radius: 2px;
}

.legend-layer .legend-categories::-webkit-scrollbar-thumb {
  background: var(--ui-scroll-thumb);
  border-radius: 2px;
}

.legend-layer .legend-categories::-webkit-scrollbar-thumb:hover {
  background: var(--ui-muted-2);
}

.legend-layer .legend-cat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  flex-shrink: 0;
}

.legend-layer .legend-cat-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid var(--ui-border);
  flex-shrink: 0;
}

.legend-layer .legend-cat-label {
  color: var(--ui-text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

/* Tile loader */
#tile-loader {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 15, 15, 0.9);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 11px;
  color: #fff;
  display: none;
  align-items: center;
  gap: 8px;
  z-index: 200;
  border: 1px solid rgba(255, 255, 255, 0.1);
  font-family: Inter, 'SF Pro Display', 'Segoe UI', sans-serif;
}

#tile-loader.active {
  display: flex;
}

/* DuckDB (SQL) loader */
#sql-loader {
  position: fixed;
  top: 44px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 15, 15, 0.9);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 11px;
  color: #fff;
  display: none;
  align-items: center;
  gap: 8px;
  z-index: 200;
  border: 1px solid rgba(255, 255, 255, 0.1);
  font-family: Inter, 'SF Pro Display', 'Segoe UI', sans-serif;
}

#sql-loader.active {
  display: flex;
}

.loader-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--ui-elements);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Basemap switcher wrapper */
.fm-basemap-switcher {
  position: relative;
  margin: 0 0 8px 0;
  z-index: 50;
  pointer-events: auto;
  width: fit-content;
}
/* Right-side alignment */
.mapboxgl-ctrl-bottom-right .fm-basemap-switcher,
.mapboxgl-ctrl-top-right .fm-basemap-switcher {
  margin-left: auto;
}
/* Position-specific margins */
.mapboxgl-ctrl-bottom-left .fm-basemap-switcher {
  margin: 0 0 8px 20px;
}
.mapboxgl-ctrl-bottom-right .fm-basemap-switcher {
  margin: 0 10px 8px 0;
  margin-left: auto;
}
.mapboxgl-ctrl-top-left .fm-basemap-switcher {
  margin: 8px 0 0 10px;
}
.mapboxgl-ctrl-top-right .fm-basemap-switcher {
  margin: 8px 10px 0 0;
  margin-left: auto;
}

/* Trigger button - 28px circle with map icon */
.fm-basemap-trigger {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--ui-float-bg);
  cursor: pointer;
  pointer-events: auto;
  color: var(--ui-text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  transition: background 0.15s;
}
.fm-basemap-trigger:hover {
  background: #3a3a3a;
}
html[data-theme="light"] .fm-basemap-trigger:hover {
  background: #e8e8e8;
}
.fm-basemap-trigger svg {
  width: 16px;
  height: 16px;
  opacity: 0.8;
}
.fm-basemap-switcher.is-open .fm-basemap-trigger {
  background: #3a3a3a;
}
html[data-theme="light"] .fm-basemap-switcher.is-open .fm-basemap-trigger {
  background: #e8e8e8;
}

/* Options panel */
.fm-basemap-options {
  display: none;
  position: absolute;
  left: 0;
  bottom: 100%;
  margin-bottom: 6px;
  gap: 4px;
  padding: 4px;
  background: var(--ui-float-bg, rgba(20,20,20,0.95));
  border: 1px solid var(--ui-border, #333);
  border-radius: 6px;
  z-index: 100;
}
.fm-basemap-switcher.is-open .fm-basemap-options {
  display: flex;
}
/* Position-specific panel alignment */
.mapboxgl-ctrl-bottom-right .fm-basemap-options {
  left: auto;
  right: 0;
}
.mapboxgl-ctrl-top-left .fm-basemap-options {
  bottom: auto;
  top: 100%;
  margin-bottom: 0;
  margin-top: 6px;
}
.mapboxgl-ctrl-top-right .fm-basemap-options {
  left: auto;
  right: 0;
  bottom: auto;
  top: 100%;
  margin-bottom: 0;
  margin-top: 6px;
}
.fm-basemap-option {
  width: 52px;
  height: 36px;
  padding: 0;
  border-radius: 4px;
  border: 2px solid transparent;
  background: transparent;
  cursor: pointer;
  overflow: hidden;
  position: relative;
}
.fm-basemap-option:hover,
.fm-basemap-option.is-hover {
  border-color: rgba(255,255,255,0.3);
}
.fm-basemap-option.is-active {
  border-color: var(--ui-elements, #E8FF59);
}
.fm-basemap-option-thumb {
  position: absolute;
  inset: 0;
  border-radius: 2px;
}
.fm-basemap-option-label {
  position: absolute;
  left: 4px;
  bottom: 2px;
  font-size: 8px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
  pointer-events: none;
}

/* AI Prompt Row (minimal, in SQL tab) */
.ai-prompt-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 8px;
}

.ai-prompt-row input {
  flex: 1;
  font-size: 11px;
}

.ai-prompt-btn {
  padding: 5px 10px;
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  color: var(--ui-muted);
  border-radius: 4px;
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  flex-shrink: 0;
}

.ai-prompt-btn:hover {
  background: var(--ui-float-bg);
  border-color: var(--ui-border-2);
  color: var(--ui-text);
}

.ai-prompt-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ai-prompt-status {
  font-size: 10px;
  color: var(--ui-muted-2);
  flex-shrink: 0;
}
