/* ── Design tokens (Palantir-inspired) ────────── */
:root {
  --bg-darkest: #111418;
  --bg-panel: #1c2127;
  --border-subtle: #2f343c;
  --accent: #2d72d2;
  --accent-hover: #215db0;
  --accent-highlight: #8abbff;
  --text-primary: #f6f7f9;
  --text-muted: #738091;
  --text-secondary: #abb3bf;
  --overlay-bg: rgba(17, 20, 24, 0.92);
  --mono: "SF Mono", "Consolas", monospace;
}

/* ── Reset & base ─────────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  font-family: "Inter", -apple-system, system-ui, sans-serif;
  background: var(--bg-darkest);
  color: var(--text-primary);
}

/* ── Layout ──────────────────────────────────────── */
#map-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 300px;
  bottom: 0;
}

#side-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: 300px;
  height: 100%;
  background: var(--bg-panel);
  border-left: 1px solid var(--border-subtle);
  padding: 16px;
  overflow-y: auto;
  box-shadow: -2px 0 8px rgba(0, 0, 0, 0.3);
}

#side-panel h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent-highlight);
}

#side-panel .subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

/* ── Time controls bar ───────────────────────────── */
#time-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 300px;
  height: 48px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  z-index: 10;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.3);
}

#map-container {
  bottom: 48px;
}

#btn-play {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  min-width: 64px;
}

#btn-play:hover {
  background: var(--accent-hover);
}

#select-speed {
  background: var(--bg-darkest);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 13px;
  cursor: pointer;
}

#slider-time {
  flex: 1;
  accent-color: var(--accent);
}

#label-time {
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 700;
  color: var(--accent-highlight);
  min-width: 52px;
  text-align: right;
}

/* ── KPI panel ───────────────────────────────────── */
.kpi-section {
  margin-bottom: 14px;
}

.kpi-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.mode-bar {
  display: flex;
  height: 14px;
  border-radius: 4px;
  overflow: hidden;
}

.mode-seg {
  min-width: 4px;
  transition: width 0.3s;
}

.mode-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.mode-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-secondary);
}

.chip-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.hist-svg {
  display: block;
  margin-top: 4px;
}

/* ── Map legend ──────────────────────────────────── */
#legend {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 15;
  background: var(--overlay-bg);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 11px;
  line-height: 1.6;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

#legend .leg-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

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

#legend .leg-label {
  color: var(--text-secondary);
}

/* ── Loading overlay ─────────────────────────────── */
#loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 300px;
  bottom: 0;
  background: rgba(17, 20, 24, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  transition: opacity 0.4s;
}

#loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border-subtle);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ── Tooltip ─────────────────────────────────────── */
#tooltip {
  position: absolute;
  z-index: 20;
  pointer-events: none;
  background: var(--overlay-bg);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-primary);
  max-width: 220px;
  display: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

#tooltip .tip-name {
  font-weight: 700;
  color: var(--accent-highlight);
  margin-bottom: 2px;
}

#tooltip .tip-status {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ── Mode-choice speech bubble ───────────────────── */
#mode-bubble {
  position: absolute;
  z-index: 25;
  pointer-events: none;
  background: var(--overlay-bg);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 10px 14px;
  max-width: 270px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-primary);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  transform: translateX(-50%) translateY(calc(-100% - 14px));
}
/* downward tail */
#mode-bubble::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 8px solid transparent;
  border-top-color: var(--overlay-bg);
}
#mode-bubble.hidden { display: none; }

/* ── Agent detail panel ──────────────────────────── */
#detail-area {
  margin-top: 12px;
}

#detail-area .detail-header {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent-highlight);
  margin-bottom: 6px;
}

#detail-area .detail-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

#detail-area .detail-persona {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  margin: 8px 0;
  line-height: 1.4;
}

#detail-area .timeline {
  list-style: none;
  border-left: 2px solid var(--border-subtle);
  padding-left: 14px;
  margin-top: 10px;
}

#detail-area .timeline li {
  position: relative;
  padding: 4px 0;
  font-size: 12px;
  line-height: 1.4;
}

#detail-area .timeline li::before {
  content: "";
  position: absolute;
  left: -19px;
  top: 9px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border-subtle);
}

#detail-area .timeline li.active::before {
  background: var(--accent);
}

#detail-area .timeline .tl-time {
  font-family: var(--mono);
  color: var(--accent-highlight);
  font-weight: 600;
  margin-right: 6px;
}

#detail-area .timeline .tl-label {
  color: var(--text-secondary);
}

#detail-area .timeline .tl-mode {
  display: inline-block;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: 4px;
  color: #fff;
  font-weight: 600;
}

/* ── deck.gl canvas ──────────────────────────────── */
#map-container canvas {
  outline: none;
}

/* ── About overlay ─────────────────────────────────────── */

#panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

#social-links { display: flex; gap: 8px; padding-top: 4px; }
#social-links a { display: flex; align-items: center; color: var(--text-muted);
  transition: color 0.15s; }
#social-links a:hover { color: var(--accent-highlight); }
#social-links svg { width: 18px; height: 18px; fill: currentColor; }

#btn-about {
  width: 100%;
  margin-bottom: 14px;
  background: transparent;
  color: var(--accent-highlight);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: "Inter", system-ui, sans-serif;
  transition: background 0.15s;
}
#btn-about:hover { background: rgba(45, 114, 210, 0.15); }

#about-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--overlay-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s;
  opacity: 1;
}
#about-overlay.hidden { opacity: 0; pointer-events: none; }

#about-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  width: min(760px, 90vw);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}

#about-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
#about-header h2 { font-size: 16px; font-weight: 700; color: var(--accent-highlight); }

#btn-close-about {
  background: none; border: none;
  color: var(--text-muted); font-size: 22px; line-height: 1;
  cursor: pointer; padding: 0 4px;
}
#btn-close-about:hover { color: var(--text-primary); }

#about-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
  line-height: 1.65;
  color: var(--text-secondary);
}

/* Markdown typography */
#about-body h1, #about-body h2, #about-body h3 {
  color: var(--text-primary); font-weight: 700;
  margin-top: 24px; margin-bottom: 8px;
}
#about-body h1 { font-size: 20px; margin-top: 0; }
#about-body h2 { font-size: 16px; }
#about-body h3 { font-size: 14px; }
#about-body p { margin-bottom: 12px; font-size: 14px; }
#about-body ul, #about-body ol { padding-left: 20px; margin-bottom: 12px; font-size: 14px; }
#about-body li { margin-bottom: 4px; }
#about-body a { color: var(--accent-highlight); text-decoration: none; }
#about-body a:hover { text-decoration: underline; }
#about-body code {
  font-family: var(--mono); font-size: 12px;
  background: var(--bg-darkest); border: 1px solid var(--border-subtle);
  border-radius: 3px; padding: 1px 5px; color: var(--accent-highlight);
}
#about-body pre {
  background: var(--bg-darkest); border: 1px solid var(--border-subtle);
  border-radius: 4px; padding: 12px 16px; overflow-x: auto; margin-bottom: 12px;
}
#about-body pre code { background: none; border: none; padding: 0; font-size: 13px; }
#about-body hr { border: none; border-top: 1px solid var(--border-subtle); margin: 20px 0; }
