* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  color: #333;
  background: #1a1a2e;
}

/* ─── Map container ─── */
#map {
  position: absolute;
  inset: 0;
}

/* ─── Top bar ─── */
#top-bar {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 60px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

#app-title {
  background: rgba(26, 26, 46, 0.92);
  color: #e0e0e0;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.3px;
  white-space: nowrap;
  pointer-events: auto;
}

/* ─── Timeline panel ─── */
#timeline-panel {
  position: absolute;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  width: min(680px, calc(100vw - 40px));
  z-index: 10;
  background: rgba(26, 26, 46, 0.92);
  border-radius: 10px;
  padding: 12px 18px 10px;
  backdrop-filter: blur(4px);
}

#timeline-label {
  text-align: center;
  font-size: 12px;
  color: #aaa;
  margin-bottom: 6px;
  user-select: none;
}

#timeline-date-display {
  color: #e0e0e0;
  font-weight: 600;
}

#timeline-track {
  position: relative;
  width: 100%;
  height: 4px;
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
  margin: 8px 0 4px;
  touch-action: none;
}

#timeline-fill {
  position: absolute;
  top: 0;
  height: 100%;
  background: linear-gradient(to right, rgba(93, 173, 226, 0.45), rgba(245, 176, 65, 0.45));
  border-radius: 2px;
  cursor: grab;
}

#timeline-fill:active {
  cursor: grabbing;
}

.timeline-handle {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 14px;
  height: 14px;
  border-radius: 50%;
  cursor: grab;
  touch-action: none;
}

#timeline-handle-start {
  background: #5dade2;
}

#timeline-handle-start:hover {
  background: #85c1e9;
}

#timeline-handle-end {
  background: #f5b041;
}

#timeline-handle-end:hover {
  background: #f8c471;
}

.timeline-handle:active {
  cursor: grabbing;
}

#timeline-range {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #888;
  margin-top: 4px;
  user-select: none;
}

/* ─── Filter panel ─── */
#filter-toggle {
  position: absolute;
  top: 10px;
  right: 60px;
  z-index: 11;
  background: rgba(26, 26, 46, 0.92);
  color: #e0e0e0;
  border: none;
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}

#filter-toggle:hover {
  background: rgba(40, 40, 70, 0.95);
}

#filter-panel {
  position: absolute;
  top: 44px;
  right: 60px;
  z-index: 10;
  background: rgba(26, 26, 46, 0.95);
  border-radius: 8px;
  padding: 12px 14px;
  min-width: 220px;
  display: none;
  backdrop-filter: blur(4px);
}

#filter-panel.open {
  display: block;
}

#filter-panel h3 {
  font-size: 12px;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.filter-item span {
  color: #fff;
}

.filter-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  cursor: pointer;
  user-select: none;
}

.filter-item input[type="checkbox"] {
  width: 15px;
  height: 15px;
  cursor: pointer;
  accent-color: #e67e22;
  flex-shrink: 0;
}

.category-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.filter-item label {
  color: #ccc;
  font-size: 13px;
  cursor: pointer;
  line-height: 1.3;
}

/* ─── Map attribution ─── */
.map-attribution {
  position: absolute;
  bottom: 8px;
  right: 8px;
  font-size: 10px;
  color: rgba(255,255,255,0.55);
  z-index: 5;
}

.map-attribution a {
  color: rgba(255,255,255,0.65);
  text-decoration: none;
}

/* ─── Event count badge ─── */
#event-count {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  background: rgba(26, 26, 46, 0.88);
  color: #aaa;
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 12px;
  pointer-events: none;
  white-space: nowrap;
}

/* ─── Empty state ─── */
#empty-state {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
  background: rgba(26, 26, 46, 0.9);
  color: #aaa;
  padding: 18px 28px;
  border-radius: 10px;
  text-align: center;
  pointer-events: none;
  display: none;
}

#empty-state.visible {
  display: block;
}

/* ─── MapLibre popup overrides ─── */
.maplibregl-popup-content {
  background: #1a1a2e;
  color: #e0e0e0;
  border-radius: 8px;
  padding: 12px 14px;
  max-width: 320px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  font-size: 13px;
  line-height: 1.5;
}

.maplibregl-popup-close-button {
  color: #aaa;
  font-size: 18px;
  right: 8px;
  top: 6px;
}

.maplibregl-popup-tip {
  border-top-color: #1a1a2e;
}

.popup-category {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 7px;
  border-radius: 4px;
  margin-bottom: 6px;
  color: #fff;
}

.popup-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 5px;
  color: #fff;
}

.popup-date {
  font-size: 11px;
  color: #888;
  margin-bottom: 8px;
}

.popup-description {
  margin-bottom: 10px;
  color: #ccc;
}

.popup-trajectory {
  font-size: 11px;
  color: #aaa;
  margin-bottom: 8px;
  padding: 5px 8px;
  background: rgba(255,255,255,0.05);
  border-radius: 4px;
}

.popup-sources {
  border-top: 1px solid rgba(255,255,255,0.1);
  padding-top: 8px;
  margin-top: 6px;
}

.popup-sources-label {
  font-size: 10px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.popup-source-link {
  display: block;
  color: #5b9de6;
  text-decoration: none;
  font-size: 12px;
  padding: 1px 0;
  word-break: break-word;
}

.popup-source-link:hover {
  text-decoration: underline;
}

/* ─── Approximate location indicator ─── */
.approx-marker-pulse {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px dashed #ccc;
  opacity: 0.6;
}

/* ─── Mobile responsive ─── */
@media (max-width: 600px) {
  #timeline-panel {
    bottom: 16px;
    left: 10px;
    right: 10px;
    transform: none;
    width: auto;
  }

  .timeline-handle {
    width: 18px;
    height: 18px;
  }

  #filter-panel {
    right: 10px;
    min-width: 190px;
  }

  #filter-toggle {
    right: 10px;
  }

  .maplibregl-popup-content {
    max-width: 260px;
  }
}

/* ─── WebGL error fallback ─── */
.map-webgl-error {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1a1a2e;
  color: #ccc;
  text-align: center;
  padding: 40px;
  z-index: 100;
}
