/* Dark theme variables inspired by Radix/Linear */
:root {
  /* Typography */
  --font-mono: Consolas, Menlo, Monaco, 'Courier New', monospace;

  /* Base surfaces */
  --bg: #11131F;
  --panel: #141726;
  --panel-elevated: #182449;
  --surface: #141726;
  --border-color: #253974;
  --box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  --box-shadow-up: 0 -6px 20px rgba(0, 0, 0, 0.45);

  /* Text */
  --text: #eaeaf2;
  --text-muted: #9aa0a6;

  /* Accents */
  --accent: #3b82f6;
  --accent-hover: #2f6fe4;
  --accent-alt: #8b5cf6;
  --accent-green: #22c55e;
  --accent-cyan: #06b6d4;
  --link: #4ea1ff;
  --focus: #6ea8fe;

  /* Semantic aliases (edit these to theme app entities) */
  --highlight: var(--accent);
  --position-marker: #EC6142;
  --data-marker: #EC5A72;

  --poi-bookcases-color: var(--accent-alt);
  --poi-nature-color: var(--accent-green);
  --poi-restrooms-color: var(--accent-cyan);

  --gpx-track-1: var(--accent);
  --gpx-track-2: var(--accent-alt);
  --gpx-track-3: var(--accent-green);
  --gpx-track-4: var(--accent-cyan);

  /* Regions and history */
  --walking-polygon: #112b48;
  --tracklog: #9EB1FF;

  /* Leaflet tile filtering */
  --tile-filter-default: none;
  --tile-filter-invert: invert(0.0) hue-rotate(10deg) saturate(0.6) brightness(0.9) contrast(0.75);
  --tile-filter-darken: brightness(0.8) contrast(1.1);
}

/* Force monospace fonts across the app */
html,
body,
#map,
.leaflet-container,
.leaflet-control-refresh,
.leaflet-popup-content,
.poi-popup {
  font-family: var(--font-mono);
}

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

/* App background */
html, body { background-color: var(--bg); color: var(--text); }

/* Apply CSS filters to raster tiles via CSS variables */
.leaflet-tile {
  filter: var(--tile-filter, var(--tile-filter-default));
  transition: filter 200ms ease;
  will-change: filter;
}

/* Opt-in tile filter modes via class on the map container */
#map.map-filter-invert {
  --tile-filter: var(--tile-filter-invert);
}

#map.map-filter-darken {
  --tile-filter: var(--tile-filter-darken);
}

.leaflet-control-refresh {
  background-color: var(--panel);
  background-clip: padding-box;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  box-shadow: var(--box-shadow);
  cursor: pointer;
  font-size: 12px;
  padding: 5px;
  text-align: center;
  color: var(--text);
}

.leaflet-control-refresh:hover { background-color: var(--surface); }

/* POI popup styling */
.poi-popup h3 {
  margin: 0;
  font-size: 1.2em;
  font-weight: bold;
  color: var(--text);
}

.poi-popup p {
  margin: 0.3em 0;
  font-size: 0.9em;
  color: var(--text-muted);
}

.poi-popup a {
  color: var(--link);
  text-decoration: none;
}

.poi-popup a:hover { text-decoration: underline; color: var(--text); }

/* Add colored dot style for POI layer control */
.poi-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}

/* Leaflet default controls: zoom, layers, attribution */
.leaflet-control-zoom a,
.leaflet-bar a,
.leaflet-control a {
  background-color: var(--panel);
  border: 1px solid var(--border-color);
  color: var(--text);
  box-shadow: var(--box-shadow);
}

.leaflet-control-zoom a:hover,
.leaflet-bar a:hover,
.leaflet-control a:hover {
  background-color: var(--surface);
  color: var(--text);
}

.leaflet-control-attribution,
.leaflet-control-scale {
  background-color: var(--panel) !important;
  color: var(--text-muted) !important;
  border: 1px solid var(--border-color) !important;
  box-shadow: var(--box-shadow) !important;
}

/* In case attribution uses inner span or anchor */
.leaflet-control-attribution a,
.leaflet-control-attribution span {
  color: var(--text) !important;
}

.leaflet-control-layers {
  background-color: var(--panel);
  color: var(--text);
  border: 1px solid var(--border-color);
  box-shadow: var(--box-shadow);
}

.leaflet-control-layers-expanded {
  background-color: var(--panel-elevated);
  color: var(--text);
  border: 1px solid var(--border-color);
  box-shadow: var(--box-shadow);
}

.leaflet-control-layers-list,
.leaflet-control-layers-overlays label,
.leaflet-control-layers-base label {
  color: var(--text);
}

.leaflet-control-layers input[type="checkbox"] + span,
.leaflet-control-layers input[type="radio"] + span {
  color: var(--text);
}

#docked-pane {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  max-height: 50%;
  background-color: var(--panel-elevated);
  box-shadow: var(--box-shadow-up);
  overflow-y: auto;
  display: none;
  z-index: 1000;
  padding: 10px;
  border-top: 1px solid var(--border-color);
}

/* GPX upload control styling */
.leaflet-control-gpx {
  background-color: var(--panel);
  background-clip: padding-box;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  box-shadow: var(--box-shadow);
  max-height: 26px;
  height: 26px;
  overflow: hidden;
  clear: both;
  width: auto;
  margin: 0;
  box-sizing: border-box;
  color: var(--text);
  font-family: var(--font-mono);
}

.leaflet-control-gpx .gpx-header {
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  margin: 0;
  padding: 0;
  width: auto;
  height: 26px;
  box-sizing: border-box;
  color: var(--text);
}

.leaflet-control-gpx .gpx-toggle {
  cursor: pointer;
  background: none;
  border: none;
  font-size: 12px;
  padding: 5px;
  text-align: center;
  height: 26px;
  width: 100%;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  color: var(--text);
  font-family: var(--font-mono);
}

.leaflet-control-gpx .gpx-toggle:hover { background-color: var(--surface); }

.leaflet-control-gpx.expanded .gpx-toggle {
  justify-content: flex-start;
}

.leaflet-control-gpx .gpx-upload {
  cursor: pointer;
  background: none;
  border: none;
  font-size: 12px;
  padding: 5px;
  display: none;
  height: 26px;
  box-sizing: border-box;
  color: var(--text);
}

.leaflet-control-gpx.expanded {
  max-height: 80vh;
  height: auto;
  overflow-y: auto;
  min-width: 150px;
  z-index: 1001;
}

.leaflet-control-gpx.expanded .gpx-upload {
  display: flex;
  align-items: center;
}

.leaflet-control-gpx input[type="file"] {
  display: none;
}

.leaflet-control-gpx .gpx-tracks {
  margin-top: 10px;
  padding: 0;
  display: none;
  width: 100%;
  box-sizing: border-box;
}

.leaflet-control-gpx.expanded .gpx-tracks {
  display: block;
  padding: 0 5px;
  color: var(--text);
}

/* Override any inherited styles */
.leaflet-left .leaflet-control {
  margin-left: 10px;
}

.leaflet-top .leaflet-control {
  margin-top: 10px;
}

/* Layer control (bookcases / nature / restrooms) */
.leaflet-control-layers .leaflet-control-layers-list {
  color: var(--text);
}

.leaflet-control-layers .leaflet-control-layers-selector {
  accent-color: var(--accent);
}

.gpx-track {
  margin-bottom: 10px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 5px;
  background-color: var(--panel);
}

.gpx-track:last-child {
  margin-bottom: 0;
}

.gpx-track-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
}

.gpx-track-name {
  font-weight: bold;
  flex-grow: 1;
  cursor: pointer;
  color: var(--text-muted);
  padding: 2px 0;
}

.gpx-track-name.active { color: var(--text); }

.gpx-track-actions {
  display: flex;
  gap: 5px;
}

.gpx-track-actions button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 5px;
  color: var(--text-muted);
}

.gpx-track-actions button:hover { color: var(--text); background: var(--surface); }

.gpx-stats {
  font-size: 0.8em;
  color: var(--text-muted);
  padding-left: 5px;
}

.gpx-stats div {
  margin: 2px 0;
}

@media (max-width: 600px) {
  .leaflet-control-gpx {
    min-width: 15px;
    max-width: calc(100vw - 20px);
  }
}

.leaflet-control-gps {
  background-color: var(--panel);
  background-clip: padding-box;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  box-shadow: var(--box-shadow);
  cursor: pointer;
  font-size: 12px;
  padding: 5px;
  text-align: center;
  max-height: 26px;
  height: 26px;
  overflow: hidden;
  clear: both;
  width: auto;
  margin: 0;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  color: var(--text);
  font-family: var(--font-mono);
}

.leaflet-control-gps:hover { background-color: var(--surface); }