/* ============================================================
   Solar Grid Map — OpenGridWorks-style UI v2
   Palette: Cyan (#06b6d4) + Amber (#fbbf24) on #0b1220
   ============================================================ */

:root {
  --bg-body: #0b1220;
  --bg-panel: rgba(12, 19, 33, 0.95);
  --bg-panel-solid: rgb(12, 19, 33);
  --bg-input: #1e293b;
  --bg-input-hover: #334155;
  --border: rgba(148, 163, 184, 0.15);
  --border-strong: rgba(148, 163, 184, 0.3);
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --cyan: #06b6d4;
  --cyan-glow: rgba(6, 182, 212, 0.4);
  --amber: #fbbf24;
  --amber-glow: rgba(251, 191, 36, 0.4);
  --danger: #ef4444;
  --success: #22c55e;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.7);
  --radius: 10px;
  --radius-sm: 6px;

  /* Layout dimensions */
  --side-nav-width: 52px;
  --layers-panel-width: 320px;
  --list-panel-width: 340px;
  --layers-panel-left: 72px; /* side-nav-width + 20 */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg-body);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   Map containers
   ============================================================ */

#map, #globe {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

#map { background: var(--bg-body); }

#globe {
  display: none;
  background: radial-gradient(circle at 50% 50%, #050a14 0%, #000 100%);
  z-index: 1;
}

/* Leaflet overrides */
.leaflet-container {
  background: var(--bg-body) !important;
  font-family: inherit;
}

.leaflet-container[data-basemap="satellite"] .leaflet-tile {
  filter: brightness(0.75) saturate(1.2);
}

.leaflet-control-attribution {
  background: rgba(12, 19, 33, 0.85) !important;
  color: var(--text-muted) !important;
  font-size: 10px;
  padding: 2px 6px;
}

.leaflet-control-attribution a { color: var(--cyan) !important; }

/* Label visibility controlled by body data attributes (label settings) */
body[data-basemap-labels="0"] .leaflet-tile-pane { filter: grayscale(0.3) brightness(0.9); }
body[data-show-labels="0"] .leaflet-tooltip { display: none !important; }

/* Leaflet tooltip used as hover-popup */
.leaflet-tooltip.custom-tooltip {
  background: var(--bg-panel-solid) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-sm) !important;
  padding: 10px 14px !important;
  font-size: 12px;
  line-height: 1.45;
  min-width: 200px;
  max-width: 280px;
  box-shadow: var(--shadow);
  opacity: 1 !important;
  pointer-events: none;
  font-family: inherit;
}

.leaflet-tooltip.custom-tooltip::before { display: none; }

.leaflet-popup-content-wrapper {
  background: var(--bg-panel-solid) !important;
  color: var(--text) !important;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 !important;
  box-shadow: var(--shadow);
}

.leaflet-popup-content {
  margin: 12px 16px !important;
  font-size: 13px;
  line-height: 1.5;
  min-width: 200px;
}

.leaflet-popup-tip {
  background: var(--bg-panel-solid) !important;
}

.popup-title {
  font-weight: 700;
  font-size: 13px;
  color: var(--amber);
  margin-bottom: 6px;
}

.popup-row {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
  font-size: 11px;
  gap: 10px;
}

.popup-row .label {
  color: var(--text-muted);
}

.popup-row .value {
  color: var(--text);
  text-align: right;
  max-width: 60%;
  word-wrap: break-word;
}

.popup-row a { color: var(--cyan); text-decoration: none; }

/* ============================================================
   Side nav (leftmost column)
   ============================================================ */

.side-nav {
  position: absolute;
  top: 20px;
  left: 20px;
  bottom: 20px;
  width: var(--side-nav-width);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 0;
  background: var(--bg-panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 1100;
}

.side-nav-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.side-nav-btn:hover {
  background: rgba(6, 182, 212, 0.12);
  color: var(--cyan);
}

.side-nav-btn.active {
  background: rgba(251, 191, 36, 0.15);
  color: var(--amber);
}

.side-nav-spacer { flex: 1; }

.side-nav-divider {
  width: 24px;
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.side-nav-btn.nav-sidebar-toggle.active {
  background: rgba(251, 191, 36, 0.15);
  color: var(--amber);
}

/* ============================================================
   Always-open Layers sidebar
   ============================================================ */

.sidebar-panel {
  position: absolute;
  top: 20px;
  left: calc(var(--side-nav-width) + 32px);
  bottom: 20px;
  width: var(--layers-panel-width);
  background: var(--bg-panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1050;
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-panel.collapsed {
  transform: translateX(calc(-100% - var(--side-nav-width) - 52px));
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-header h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.2px;
}

.panel-header-actions {
  display: flex;
  gap: 4px;
}

.panel-icon-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.panel-icon-btn:hover {
  color: var(--amber);
  border-color: var(--amber);
  background: rgba(251, 191, 36, 0.08);
}

.panel-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.panel-close:hover {
  color: var(--text);
  background: rgba(148, 163, 184, 0.1);
}

#layers-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0 16px;
}

/* Custom scrollbar */
#layers-panel-content::-webkit-scrollbar,
.list-scroll::-webkit-scrollbar { width: 8px; }
#layers-panel-content::-webkit-scrollbar-track,
.list-scroll::-webkit-scrollbar-track { background: transparent; }
#layers-panel-content::-webkit-scrollbar-thumb,
.list-scroll::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.2);
  border-radius: 4px;
}
#layers-panel-content::-webkit-scrollbar-thumb:hover,
.list-scroll::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.35);
}

/* ============================================================
   Layers panel sections
   ============================================================ */

/* Accordion sections (power plants, transmission — items with sub-options) */
details.panel-section {
  padding: 0;
  border-bottom: 1px solid var(--border);
}

details.panel-section:last-child { border-bottom: none; }

details.panel-section summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  cursor: pointer;
  list-style: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  transition: background 0.12s ease;
  user-select: none;
}

details.panel-section summary::-webkit-details-marker { display: none; }

details.panel-section summary:hover {
  background: rgba(6, 182, 212, 0.06);
}

details.panel-section summary::after {
  content: "▾";
  color: var(--text-muted);
  font-size: 10px;
  transition: transform 0.2s ease;
  margin-left: 8px;
}

details.panel-section[open] summary::after {
  transform: rotate(180deg);
}

/* Flat sections (single-option items: substations, data centers, etc) */
.flat-section {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.flat-section:last-child { border-bottom: none; }

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.beta-badge {
  font-size: 9px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  background: rgba(251, 191, 36, 0.15);
  color: var(--amber);
  letter-spacing: 0.5px;
}

.panel-body {
  padding: 0 16px 14px;
}

.subsection-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  padding: 12px 0 6px;
  border-top: 1px dashed var(--border);
  margin-top: 6px;
}

/* Layer rows inside sections */
.layer-row,
.tech-row {
  display: flex;
  align-items: center;
  padding: 7px 0;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  color: var(--text);
  transition: color 0.12s ease;
  gap: 10px;
}

.flat-section .layer-row {
  padding: 2px 0 0;
}

.layer-row.master {
  font-weight: 600;
  padding: 8px 0;
}

.layer-row:hover,
.tech-row:hover {
  color: var(--cyan);
}

.layer-row input,
.tech-row input {
  accent-color: var(--amber);
  cursor: pointer;
  flex-shrink: 0;
}

.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.swatch.line {
  width: 16px;
  height: 3px;
  border-radius: 0;
}

.layer-label,
.tech-label {
  flex: 1;
}

.layer-count,
.tech-count {
  color: var(--text-dim);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  white-space: nowrap;
}

.tech-count .count-num {
  color: var(--text-muted);
}

.tech-count .count-gw {
  color: var(--text-dim);
}

.section-header-total {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  margin-left: auto;
  margin-right: 8px;
}

/* Size (MW) legend */
.size-legend-body {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.size-legend-svg {
  width: 140px;
  height: 140px;
}

.size-legend-info {
  display: flex;
  gap: 8px;
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

.size-legend-info .divider { color: var(--border-strong); }

/* Database stats section */
.stats-section { padding-top: 14px; }

#stats { font-size: 12px; }

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px dashed var(--border);
}

.stat-row:last-child { border-bottom: none; }

.stat-label { color: var(--text-muted); }

.stat-value {
  color: var(--amber);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   Top-center visit counter
   ============================================================ */

.visit-counter {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-panel);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-muted);
  z-index: 1000;
  box-shadow: var(--shadow);
  pointer-events: none;
  white-space: nowrap;
}

.counter-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.6);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.counter-num {
  color: var(--text);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   Top-right icon bar
   ============================================================ */

.icon-bar {
  position: absolute;
  top: 20px;
  right: 20px;
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 6px;
  background: var(--bg-panel);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  z-index: 1100;
  box-shadow: var(--shadow);
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
}

.icon-btn:hover:not(:disabled) {
  background: rgba(6, 182, 212, 0.1);
  color: var(--cyan);
}

.icon-btn.active {
  background: rgba(251, 191, 36, 0.15);
  color: var(--amber);
}

.icon-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.icon-btn.copied {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}

.icon-wrap {
  position: relative;
}

.icon-wrap:hover .dropdown-menu {
  display: block;
}

.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 280px;
  background: var(--bg-panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 1200;
}

.dropdown-header {
  padding: 10px 14px 8px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.label-menu {
  min-width: 300px;
}

.label-presets {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}

.label-preset-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s ease;
}

.label-preset-row.active {
  background: rgba(6, 182, 212, 0.1);
}

.label-preset-row:hover {
  background: rgba(6, 182, 212, 0.12);
}

.preset-label { font-weight: 500; }

.preset-active {
  font-size: 9px;
  color: var(--amber);
  font-weight: 700;
  letter-spacing: 1px;
}

/* Label toggles */
.label-toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.12s ease;
}

.label-toggle-row:hover {
  background: rgba(6, 182, 212, 0.06);
}

.label-toggle-row .toggle-state {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 2px 8px;
  border-radius: 10px;
}

.label-toggle-row .toggle-state.on {
  color: var(--cyan);
  background: rgba(6, 182, 212, 0.15);
}

.label-toggle-row .toggle-state.off {
  color: var(--text-dim);
  background: rgba(148, 163, 184, 0.1);
}

.label-sliders {
  padding: 4px 14px 8px;
  border-top: 1px solid var(--border);
  margin-top: 6px;
}

.label-slider-row {
  padding: 8px 0;
}

.label-slider-head {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text);
  margin-bottom: 6px;
}

.label-slider-head .slider-value {
  color: var(--cyan);
  font-variant-numeric: tabular-nums;
}

.label-slider-row input[type="range"] {
  width: 100%;
  accent-color: var(--cyan);
}

.label-borders {
  border-top: 1px solid var(--border);
  margin-top: 6px;
  padding: 4px 0;
}

/* ============================================================
   Bottom-left Map Type button
   ============================================================ */

.bottom-left {
  position: absolute;
  bottom: 20px;
  left: var(--layers-panel-left);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}

.corner-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-panel);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: var(--shadow);
  font-family: inherit;
}

.corner-btn:hover {
  border-color: var(--cyan);
  color: var(--cyan);
}

.corner-btn.active {
  border-color: var(--amber);
  color: var(--amber);
}

/* ============================================================
   Bottom-right mini-map
   ============================================================ */

.minimap-wrap {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid var(--border-strong);
  box-shadow: var(--shadow), 0 0 30px rgba(6, 182, 212, 0.15);
  z-index: 1000;
  cursor: pointer;
}

#minimap {
  width: 100%;
  height: 100%;
  background: var(--bg-body);
}

.minimap-wrap:hover {
  border-color: var(--cyan);
  box-shadow: var(--shadow), 0 0 40px var(--cyan-glow);
}

/* ============================================================
   Floating panels (Display, Map Type)
   ============================================================ */

.floating-panel {
  position: absolute;
  background: var(--bg-panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: none;
  flex-direction: column;
  z-index: 1200;
  max-height: calc(100vh - 120px);
  overflow: hidden;
}

.floating-panel.open {
  display: flex;
  animation: slideUp 0.25s ease-out;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.display-panel {
  top: 80px;
  right: 20px;
  width: 320px;
}

.map-type-panel {
  bottom: 80px;
  left: var(--layers-panel-left);
  width: 280px;
}

.panel-section {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.panel-section:last-child { border-bottom: none; }

.panel-section .section-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  margin-bottom: 10px;
  display: block;
}

/* Display panel specifics */
.projection-toggle,
.stats-mode-toggle {
  display: flex;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
  margin-bottom: 12px;
}

.projection-toggle button,
.stats-mode-toggle button {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  background: transparent;
  border: none;
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
}

.projection-toggle button.active,
.stats-mode-toggle button.active {
  background: rgba(6, 182, 212, 0.15);
  color: var(--cyan);
}

.checkbox-row {
  display: flex;
  align-items: center;
  padding: 6px 0;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}

.checkbox-row input {
  margin-right: 10px;
  accent-color: var(--cyan);
  cursor: pointer;
}

/* Map Type selector */
.map-type-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 14px 18px;
}

.map-type-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0;
  background: transparent;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  overflow: hidden;
  transition: all 0.15s ease;
  font-family: inherit;
}

.map-type-card:hover { border-color: var(--cyan); }
.map-type-card.active { border-color: var(--amber); }

.map-type-thumb {
  width: 100%;
  height: 60px;
}

.map-type-label {
  padding: 6px 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
}

/* ============================================================
   List View panel (right side)
   ============================================================ */

.list-panel {
  position: absolute;
  top: 20px;
  right: 20px;
  bottom: 20px;
  width: var(--list-panel-width);
  background: var(--bg-panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: none;
  flex-direction: column;
  z-index: 1150;
  overflow: hidden;
}

.list-panel.open {
  display: flex;
  animation: slideInRight 0.25s ease-out;
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(10px); }
  to { opacity: 1; transform: translateX(0); }
}

.list-count {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.list-tabs {
  display: flex;
  padding: 12px 16px 0;
  gap: 4px;
  border-bottom: 1px solid var(--border);
}

.list-tab {
  padding: 10px 14px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  gap: 6px;
}

.list-tab:hover { color: var(--text); }

.list-tab.active {
  color: var(--cyan);
  border-bottom-color: var(--cyan);
}

.tab-count {
  font-size: 10px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.list-search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}

#list-search {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  outline: none;
  transition: border-color 0.15s ease;
}

#list-search:focus {
  border-color: var(--cyan);
}

.list-scroll {
  flex: 1;
  overflow-y: auto;
}

.list-item {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.08);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  transition: background 0.12s ease;
}

.list-item:hover {
  background: rgba(6, 182, 212, 0.06);
}

.list-item-main {
  flex: 1;
  min-width: 0;
}

.list-item-name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-item-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.list-item-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
  text-transform: capitalize;
}

.list-item-value {
  font-size: 13px;
  font-weight: 700;
  color: var(--amber);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  align-self: center;
}

.list-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

/* ============================================================
   Clear-all flash animation
   ============================================================ */

.panel-icon-btn.flash {
  color: var(--success);
  border-color: var(--success);
}

/* ============================================================
   Big labels mode (label settings)
   ============================================================ */

body[data-big-labels="1"] .leaflet-tooltip.custom-tooltip {
  font-size: 14px;
  min-width: 240px;
  padding: 14px 18px !important;
}

body[data-big-labels="1"] .popup-title {
  font-size: 16px;
}

/* Enhanced visibility mode */
body[data-enhanced="1"] .leaflet-interactive {
  filter: drop-shadow(0 0 4px currentColor);
}

/* Basemap labels toggle — hide CARTO text labels from dark tiles */
body[data-basemap-labels="0"] .leaflet-tile-pane {
  filter: saturate(1.1) contrast(1.1);
}

/* Lines-only mode — hide all point markers */
body[data-lines-only="1"] .leaflet-marker-pane,
body[data-lines-only="1"] circle.leaflet-interactive {
  display: none !important;
}

/* ============================================================
   Globe.gl tooltip styling
   ============================================================ */

.scene-tooltip {
  background: var(--bg-panel-solid) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-sm) !important;
  padding: 10px 14px !important;
  font-size: 12px;
  line-height: 1.45;
  min-width: 200px;
  max-width: 280px;
  box-shadow: var(--shadow);
  font-family: inherit !important;
  pointer-events: none;
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 900px) {
  .visit-counter .counter-label { display: none; }
  .minimap-wrap { width: 120px; height: 120px; }
  .list-panel { width: calc(100vw - 40px); max-width: 340px; }
}

@media (max-width: 680px) {
  :root {
    --layers-panel-width: 260px;
    --side-nav-width: 44px;
  }
  .icon-bar .icon-btn { width: 32px; height: 32px; }
  .visit-counter { font-size: 11px; padding: 6px 12px; }
}

/* ============================================================
   Right-click context menu
   ============================================================ */

.context-menu {
  position: fixed;
  display: none;
  min-width: 260px;
  background: var(--bg-panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 2000;
  font-family: inherit;
}

.context-menu.open {
  display: block;
  animation: ctxFadeIn 0.14s ease-out;
}

@keyframes ctxFadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.ctx-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s ease, color 0.12s ease;
}

.ctx-item:hover {
  background: rgba(6, 182, 212, 0.1);
  color: var(--cyan);
}

.ctx-item svg {
  flex-shrink: 0;
  color: var(--text-muted);
}

.ctx-item:hover svg {
  color: var(--cyan);
}

.ctx-item.flash {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}

.ctx-item.flash svg {
  color: var(--success);
}

.ctx-coords {
  align-items: flex-start;
  padding: 10px 12px;
}

.ctx-coords svg {
  margin-top: 2px;
}

.ctx-coords-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.ctx-coords-val {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-family: "SFMono-Regular", Menlo, Consolas, monospace;
}

.ctx-coords-hint {
  font-size: 11px;
  color: var(--text-dim);
}

.ctx-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* ============================================================
   MOBILE-FIRST RESPONSIVE OVERHAUL
   Native iOS/Android feel: bottom nav, bottom sheets, gestures
   ============================================================ */

/* Safe area insets for iPhone notch + home indicator */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --bottom-nav-height: 64px;
  --bottom-nav-total: calc(var(--bottom-nav-height) + var(--safe-bottom));
}

/* Bottom nav — hidden on desktop */
.bottom-nav { display: none; }
.sheet-backdrop { display: none; }
.drag-handle { display: none; }

/* ──────────────────────────────────────────────────────────────
   TABLET (max-width: 768px)
   ────────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  :root {
    --layers-panel-width: 280px;
  }

  .minimap-wrap {
    width: 120px;
    height: 120px;
  }

  .visit-counter .counter-label { display: none; }

  .floating-panel {
    max-width: calc(100vw - 40px);
  }
}

/* ──────────────────────────────────────────────────────────────
   MOBILE (max-width: 480px)
   Full native-app-style layout
   ────────────────────────────────────────────────────────────── */

@media (max-width: 480px) {
  /* === HIDE DESKTOP CHROME === */
  .side-nav,
  .sidebar-panel:not(.mobile-sheet-active),
  .minimap-wrap,
  .bottom-left,
  .icon-bar,
  .leaflet-control-zoom,
  .leaflet-control-attribution {
    display: none !important;
  }

  /* === FULL-SCREEN MAP === */
  #map, #globe {
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: var(--bottom-nav-total) !important;
  }

  /* === TOP BAR — slim counter + 2 icons === */
  .visit-counter {
    top: calc(12px + var(--safe-top));
    left: 16px;
    transform: none;
    padding: 6px 12px;
    font-size: 11px;
    border-radius: 20px;
    gap: 6px;
    pointer-events: auto;
  }

  .counter-label { display: none !important; }
  .counter-dot { width: 6px; height: 6px; }

  /* === BOTTOM NAV BAR === */
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-total);
    padding-bottom: var(--safe-bottom);
    background: var(--bg-panel);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    z-index: 3500;
    align-items: stretch;
    justify-content: space-around;
    gap: 0;
  }

  .bnav-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 10px;
    font-weight: 600;
    font-family: inherit;
    letter-spacing: 0.3px;
    cursor: pointer;
    transition: color 0.15s ease;
    padding: 8px 4px;
    -webkit-tap-highlight-color: transparent;
    position: relative;
  }

  .bnav-tab svg {
    transition: transform 0.15s ease;
  }

  .bnav-tab:active svg {
    transform: scale(0.9);
  }

  .bnav-tab.active {
    color: var(--cyan);
  }

  .bnav-tab.active::before {
    content: "";
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 2px;
    background: var(--cyan);
    border-radius: 0 0 2px 2px;
  }

  /* Center "Map" tab — larger, raised */
  .bnav-center {
    flex: 1.3;
    padding-top: 4px;
  }

  .bnav-center-ring {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(6, 182, 212, 0.12);
    border: 2px solid var(--cyan);
    margin-top: -16px;
    transition: all 0.15s ease;
  }

  .bnav-center-ring svg {
    color: var(--cyan);
  }

  .bnav-tab.bnav-center:active .bnav-center-ring {
    background: rgba(6, 182, 212, 0.25);
    transform: scale(0.93);
  }

  /* === BACKDROP === */
  .sheet-backdrop {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0);
    z-index: 2900;
    pointer-events: none;
    transition: background 0.3s ease;
  }

  .sheet-backdrop.visible {
    background: rgba(0, 0, 0, 0.45);
    pointer-events: auto;
  }

  /* === BOTTOM SHEETS === */
  .drag-handle {
    display: block;
    width: 40px;
    height: 4px;
    background: var(--border-strong);
    border-radius: 2px;
    margin: 12px auto 8px;
    flex-shrink: 0;
  }

  /* Convert existing panels to bottom sheets on mobile */
  .mobile-sheet-active {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    width: 100% !important;
    max-width: none !important;
    max-height: 82vh !important;
    border-radius: 16px 16px 0 0 !important;
    z-index: 3100 !important;
    transform: translateY(0) !important;
    padding-bottom: var(--bottom-nav-total) !important;
    box-shadow: 0 -10px 60px rgba(0, 0, 0, 0.5) !important;
    animation: sheetSlideUp 0.35s cubic-bezier(0.32, 0.72, 0, 1) !important;
    overflow-y: auto !important;
    display: flex !important;
    flex-direction: column !important;
  }

  @keyframes sheetSlideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }

  /* Layers panel as bottom sheet */
  .sidebar-panel.mobile-sheet-active {
    border: none !important;
  }

  .sidebar-panel.mobile-sheet-active .panel-header-actions .panel-toggle {
    display: none; /* hide collapse button on mobile */
  }

  /* List panel as bottom sheet */
  .list-panel.mobile-sheet-active {
    top: auto !important;
    border: none !important;
  }

  /* Display panel as bottom sheet */
  .display-panel.mobile-sheet-active {
    top: auto !important;
    border: none !important;
  }

  /* More sheet (always a bottom sheet) */
  .bottom-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-panel);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 16px 16px 0 0;
    z-index: 3100;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
    padding-bottom: var(--bottom-nav-total);
    display: block;
  }

  .bottom-sheet.open {
    transform: translateY(0);
  }

  .sheet-header {
    padding: 4px 20px 14px;
    border-bottom: 1px solid var(--border);
  }

  .sheet-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
  }

  .sheet-body {
    padding: 8px 0;
  }

  .sheet-action {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 16px 20px;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 15px;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    transition: background 0.12s ease;
    -webkit-tap-highlight-color: transparent;
  }

  .sheet-action:active {
    background: rgba(6, 182, 212, 0.08);
  }

  .sheet-action svg {
    color: var(--text-muted);
    flex-shrink: 0;
  }

  .sheet-action span {
    flex: 1;
  }

  .sheet-action .chevron {
    color: var(--text-dim);
  }

  /* === FLOATING PANELS — Full width on mobile === */
  .floating-panel {
    left: 0 !important;
    right: 0 !important;
    width: auto !important;
    max-width: none !important;
    border-radius: 16px 16px 0 0 !important;
    bottom: 0 !important;
    top: auto !important;
    max-height: 70vh !important;
    z-index: 3200 !important;
  }

  /* Map Type panel as full-width bottom sheet */
  .map-type-panel.open {
    animation: sheetSlideUp 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  }

  .map-type-grid {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 16px 20px;
  }

  .map-type-thumb {
    height: 80px;
  }

  /* === CONTEXT MENU — Action Sheet on mobile === */
  .context-menu {
    left: 12px !important;
    right: 12px !important;
    bottom: calc(var(--bottom-nav-total) + 12px) !important;
    top: auto !important;
    width: auto !important;
    min-width: auto !important;
    border-radius: 14px !important;
    animation: sheetSlideUp 0.25s cubic-bezier(0.32, 0.72, 0, 1) !important;
  }

  .ctx-item {
    padding: 14px 16px;
    font-size: 15px;
    gap: 12px;
    min-height: 48px;
  }

  .ctx-coords-val {
    font-size: 15px;
  }

  .ctx-coords-hint {
    font-size: 12px;
  }

  /* === POPUPS/TOOLTIPS — larger touch targets === */
  .leaflet-tooltip.custom-tooltip {
    font-size: 13px;
    padding: 12px 16px !important;
    min-width: 180px;
    max-width: calc(100vw - 40px);
  }

  .popup-title {
    font-size: 14px;
  }

  .popup-row {
    padding: 4px 0;
    font-size: 12px;
  }

  /* === LAYER ROWS — bigger touch targets === */
  .mobile-sheet-active .layer-row,
  .mobile-sheet-active .tech-row {
    padding: 10px 0;
    min-height: 44px;
  }

  .mobile-sheet-active .layer-row input,
  .mobile-sheet-active .tech-row input {
    width: 20px;
    height: 20px;
  }

  .mobile-sheet-active .panel-body {
    padding: 0 20px 16px;
  }

  .mobile-sheet-active .panel-header {
    padding: 8px 20px 14px;
  }

  /* Stats in mobile sheet */
  .mobile-sheet-active .stats-section {
    padding: 16px 20px;
  }

  .mobile-sheet-active .stat-row {
    padding: 8px 0;
    font-size: 14px;
  }

  /* === LIST PANEL — mobile optimized === */
  .mobile-sheet-active .list-tabs {
    padding: 12px 20px 0;
  }

  .mobile-sheet-active .list-tab {
    padding: 12px 16px;
    font-size: 14px;
  }

  .mobile-sheet-active .list-search-wrap {
    padding: 12px 20px;
  }

  .mobile-sheet-active #list-search {
    padding: 12px 14px;
    font-size: 14px;
  }

  .mobile-sheet-active .list-item {
    padding: 14px 20px;
    min-height: 56px;
  }

  .mobile-sheet-active .list-item-name {
    font-size: 14px;
  }

  .mobile-sheet-active .list-item-sub {
    font-size: 12px;
    margin-top: 4px;
  }

  .mobile-sheet-active .list-item-value {
    font-size: 14px;
  }

  /* === DISPLAY PANEL — mobile bottom sheet === */
  .display-panel.mobile-sheet-active .panel-section {
    padding: 16px 20px;
  }

  .display-panel.mobile-sheet-active .projection-toggle button,
  .display-panel.mobile-sheet-active .stats-mode-toggle button {
    padding: 12px 16px;
    font-size: 14px;
  }

  .display-panel.mobile-sheet-active .checkbox-row {
    padding: 10px 0;
    font-size: 14px;
    min-height: 44px;
  }

  .display-panel.mobile-sheet-active .checkbox-row input {
    width: 20px;
    height: 20px;
    margin-right: 12px;
  }

  /* Globe.gl tooltip — action sheet style on mobile */
  .scene-tooltip {
    max-width: calc(100vw - 40px) !important;
    font-size: 13px !important;
  }
}

/* ──────────────────────────────────────────────────────────────
   VERY SMALL MOBILE (max-width: 360px) — iPhone SE, small Android
   ────────────────────────────────────────────────────────────── */

@media (max-width: 360px) {
  .bottom-nav {
    height: calc(56px + var(--safe-bottom));
  }

  .bnav-tab {
    font-size: 9px;
    gap: 2px;
    padding: 6px 2px;
  }

  .bnav-tab svg {
    width: 20px;
    height: 20px;
  }

  .bnav-center-ring {
    width: 40px;
    height: 40px;
    margin-top: -12px;
  }

  .mobile-sheet-active {
    max-height: 85vh !important;
  }

  .ctx-item {
    padding: 12px 14px;
    font-size: 14px;
  }
}

/* ──────────────────────────────────────────────────────────────
   LANDSCAPE MOBILE — limit sheet height
   ────────────────────────────────────────────────────────────── */

@media (max-width: 480px) and (orientation: landscape) {
  .mobile-sheet-active {
    max-height: 75vh !important;
  }

  .bottom-nav {
    height: calc(50px + var(--safe-bottom));
  }

  .bnav-tab span {
    display: none; /* icon-only in landscape */
  }

  .bnav-center-ring {
    margin-top: -8px;
    width: 38px;
    height: 38px;
  }
}

/* ──────────────────────────────────────────────────────────────
   DARK SCROLLBAR for mobile sheets
   ────────────────────────────────────────────────────────────── */

@media (max-width: 480px) {
  .mobile-sheet-active::-webkit-scrollbar {
    width: 4px;
  }

  .mobile-sheet-active::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 2px;
  }
}
