/* ================================================================== */
/*  Chronocarto — styles                                              */
/* ================================================================== */

:root {
  /* Palette — dark cinematic */
  --bg:           #0f0f1a;
  --surface:      rgba(15, 15, 30, 0.88);
  --surface-solid:#16162a;
  --border:       rgba(255, 255, 255, 0.08);
  --text:         #e8e8ec;
  --text-muted:   #8888a0;
  --accent:       #e94560;
  --accent-dim:   rgba(233, 69, 96, 0.35);

  /* Conflict-type colours */
  --c-interstate:  #e94560;
  --c-civil:       #f5a623;
  --c-religious:   #9b59b6;
  --c-insurgency:  #3498db;
  --c-genocide:    #ff2d2d;
  --c-colonial:    #1abc9c;
  --c-raid:        #95a5a6;
  --c-succession:  #e67e22;

  /* Typography */
  --font-heading: "Space Grotesk", system-ui, sans-serif;
  --font-body:    "IBM Plex Sans", system-ui, sans-serif;

  /* Layout */
  --panel-radius: 10px;
  --panel-blur:   20px;
  --panel-pad:    14px;
  --timeline-h:   110px;
}

/* ── Reset ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg);
}
button { font-family: inherit; cursor: pointer; }

/* ── Map ────────────────────────────────────────────────────────── */
#map {
  position: absolute;
  inset: 0;
  z-index: 0;
}

/* ── Glass panel mixin ──────────────────────────────────────────── */
.glass,
#filters-panel,
#era-presets,
#detail-panel,
#timeline,
#legend {
  background: var(--surface);
  backdrop-filter: blur(var(--panel-blur));
  -webkit-backdrop-filter: blur(var(--panel-blur));
  border: 1px solid var(--border);
  border-radius: var(--panel-radius);
}

/* ── Title bar ──────────────────────────────────────────────────── */
#title-bar {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  text-align: center;
  pointer-events: none;
}
#title-bar h1 {
  font-family: var(--font-heading);
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text);
  text-shadow: 0 2px 12px rgba(0,0,0,0.6);
}
#title-bar .subtitle {
  font-size: 0.7rem;
  font-weight: 300;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ── Search ─────────────────────────────────────────────────────── */
#search-box {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 15;
  width: 260px;
}
#search-input {
  width: 100%;
  padding: 8px 14px;
  border-radius: var(--panel-radius);
  border: 1px solid var(--border);
  background: var(--surface);
  backdrop-filter: blur(var(--panel-blur));
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.8rem;
  outline: none;
  transition: border-color 0.15s;
}
#search-input::placeholder { color: var(--text-muted); }
#search-input:focus { border-color: var(--accent); }

#search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: var(--panel-radius);
  max-height: 320px;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
#search-results.hidden { display: none; }

.search-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background 0.1s;
}
.search-item:hover { background: rgba(255,255,255,0.05); }
.search-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.search-name {
  flex: 1;
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-date {
  font-size: 0.65rem;
  color: var(--text-muted);
  flex-shrink: 0;
}
.search-empty {
  padding: 12px;
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
}

/* ── Filters panel ──────────────────────────────────────────────── */
#filters-panel {
  position: absolute;
  top: 58px;
  left: 16px;
  z-index: 10;
  padding: var(--panel-pad);
  width: 210px;
  max-height: calc(100vh - 200px);
  overflow-y: auto;
}
#filters-panel details {
  margin-bottom: 10px;
}
#filters-panel summary {
  font-family: var(--font-heading);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
#filters-panel summary::before {
  content: "▸";
  transition: transform 0.15s;
}
#filters-panel details[open] > summary::before {
  transform: rotate(90deg);
}

/* Filter toggle row */
#filter-toggle {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  margin-bottom: 4px;
}
.filter-action {
  font-size: 0.65rem;
  font-weight: 500;
  padding: 2px 10px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  transition: all 0.15s;
}
.filter-action:hover {
  background: rgba(255,255,255,0.08);
  color: var(--text);
}

.chip-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin-top: 6px;
}
.chip {
  font-size: 0.7rem;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  transition: all 0.15s;
  text-transform: capitalize;
}
.chip.active {
  color: #fff;
  border-color: transparent;
}
.chip:hover { opacity: 0.85; }

.range-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}
.range-row input[type="range"] { flex: 1; accent-color: var(--accent); }
.range-row span {
  font-size: 0.7rem;
  color: var(--text-muted);
  min-width: 50px;
  text-align: right;
}

/* ── Era presets ────────────────────────────────────────────────── */
#era-presets {
  position: absolute;
  top: 70px;
  right: 16px;
  z-index: 10;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
#era-presets button {
  font-size: 0.7rem;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  text-align: left;
  transition: all 0.15s;
  white-space: nowrap;
}
#era-presets button:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text);
}
#era-presets button.active {
  background: var(--accent-dim);
  color: #fff;
  border-color: var(--accent);
}

/* ── Detail panel ───────────────────────────────────────────────── */
#detail-panel {
  position: absolute;
  top: 70px;
  right: 16px;
  z-index: 20;
  width: 340px;
  max-height: calc(100vh - 200px);
  overflow-y: auto;
  padding: 20px;
  transition: transform 0.25s ease, opacity 0.25s ease;
}
#detail-panel.hidden {
  transform: translateX(360px);
  opacity: 0;
  pointer-events: none;
}
#detail-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  font-size: 1.3rem;
  color: var(--text-muted);
  line-height: 1;
}
#detail-close:hover { color: var(--text); }

#detail-name {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 12px;
  padding-right: 24px;
  line-height: 1.3;
}
.detail-section {
  margin-bottom: 10px;
}
.detail-section .label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 3px;
}
.detail-section .value {
  font-size: 0.82rem;
  line-height: 1.5;
}
#detail-summary {
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--text);
  margin-bottom: 10px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.tag {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 12px;
  background: rgba(255,255,255,0.06);
  color: var(--text-muted);
  margin: 2px 2px;
}
.type-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 12px;
  color: #fff;
  text-transform: capitalize;
}

/* ── Timeline ───────────────────────────────────────────────────── */
#timeline {
  position: absolute;
  bottom: 16px;
  left: 16px;
  right: 16px;
  z-index: 10;
  height: var(--timeline-h);
  padding: 12px 16px 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

#timeline-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
#play-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.05);
  color: var(--text);
  font-size: 0.85rem;
  display: grid;
  place-items: center;
  transition: background 0.15s;
}
#play-btn:hover { background: var(--accent-dim); }
#play-btn.playing { color: var(--accent); }
#speed-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

#timeline-track {
  flex: 1;
  position: relative;
  height: 50px;
  min-width: 200px;
}

/* Sparkline */
#sparkline {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 24px;
  pointer-events: none;
  z-index: 0;
}

/* Custom dual-thumb slider */
#track-bg {
  position: absolute;
  top: 14px;
  left: 0;
  right: 0;
  height: 4px;
  border-radius: 2px;
  background: rgba(255,255,255,0.12);
  z-index: 1;
}

#range-highlight {
  position: absolute;
  top: 14px;
  height: 4px;
  border-radius: 2px;
  background: var(--accent);
  opacity: 0.6;
  z-index: 2;
  pointer-events: none;
}

.thumb {
  position: absolute;
  top: 7px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  cursor: grab;
  z-index: 3;
  transform: translateX(-50%);
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
  transition: transform 0.08s;
}
.thumb:hover {
  transform: translateX(-50%) scale(1.2);
}
.thumb:active {
  cursor: grabbing;
  transform: translateX(-50%) scale(1.15);
}
.thumb.merged {
  width: 6px;
  height: 22px;
  border-radius: 3px;
  border-width: 1px;
}
.thumb.merged + .thumb.merged {
  opacity: 0;
}

/* Tick labels */
#timeline-labels {
  position: absolute;
  top: 28px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}
#timeline-labels span {
  font-size: 0.6rem;
  color: var(--text-muted);
}

#timeline-readout {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-heading);
  font-size: 0.9rem;
  font-weight: 600;
  min-width: 180px;
  justify-content: center;
}
.readout-sep { color: var(--text-muted); font-weight: 300; }

#event-count {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: right;
  min-width: 120px;
}
#count-num {
  font-family: var(--font-heading);
  font-weight: 600;
  color: var(--accent);
}

/* ── Legend ──────────────────────────────────────────────────────── */
#legend {
  position: absolute;
  bottom: calc(var(--timeline-h) + 32px);
  left: 16px;
  z-index: 10;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.65rem;
  color: var(--text-muted);
}
.swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Scrollbar ──────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ── Loading state ──────────────────────────────────────────────── */
#map.loading::after {
  content: "Loading conflict data…";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-heading);
  font-size: 1rem;
  color: var(--text-muted);
  background: var(--bg);
  z-index: 100;
}

/* ── Detail panel links ─────────────────────────────────────────── */
.wiki-link {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--accent);
  text-decoration: none;
  padding: 4px 0;
  transition: opacity 0.15s;
}
.wiki-link:hover { opacity: 0.75; text-decoration: underline; }
.source-note {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-style: italic;
  margin-top: 6px;
}

/* ── Contested ground button ────────────────────────────────────── */
#contested-btn {
  position: absolute;
  top: 16px;
  right: 56px;
  z-index: 10;
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  backdrop-filter: blur(var(--panel-blur));
  color: var(--text-muted);
  font-family: var(--font-heading);
  font-size: 0.7rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
#contested-btn:hover { background: rgba(255,60,60,0.15); color: var(--text); }
#contested-btn.active {
  background: rgba(255, 60, 60, 0.25);
  border-color: rgba(255, 60, 60, 0.5);
  color: #ff6666;
}

/* ── Info button & panel ───────────────────────────────────────── */
#info-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 10;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  backdrop-filter: blur(var(--panel-blur));
  color: var(--text-muted);
  font-family: Georgia, serif;
  font-size: 0.85rem;
  font-style: italic;
  font-weight: 700;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all 0.15s;
}
#info-btn:hover { background: var(--accent-dim); color: #fff; }

#info-panel {
  position: absolute;
  top: 56px;
  right: 16px;
  z-index: 25;
  width: 360px;
  max-height: calc(100vh - 200px);
  overflow-y: auto;
  padding: 20px;
  background: var(--surface);
  backdrop-filter: blur(var(--panel-blur));
  border: 1px solid var(--border);
  border-radius: var(--panel-radius);
  transition: transform 0.25s ease, opacity 0.25s ease;
}
#info-panel.hidden {
  transform: translateX(380px);
  opacity: 0;
  pointer-events: none;
}
#info-panel h2 {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 10px;
}
#info-panel h3 {
  font-family: var(--font-heading);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  margin-top: 14px;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
#info-panel p {
  font-size: 0.8rem;
  line-height: 1.6;
  color: var(--text);
  margin-bottom: 6px;
}
#info-panel ul {
  font-size: 0.78rem;
  line-height: 1.6;
  color: var(--text);
  padding-left: 18px;
  margin-bottom: 8px;
}
#info-panel li { margin-bottom: 4px; }
#info-panel li strong { color: var(--accent); font-weight: 600; }
#info-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  font-size: 1.3rem;
  color: var(--text-muted);
  line-height: 1;
  cursor: pointer;
}
#info-close:hover { color: var(--text); }
.info-footer {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ── MapLibre popup (tooltip) — dark theme ─────────────────────── */
.maplibregl-popup-content {
  background: var(--surface-solid) !important;
  color: var(--text) !important;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-family: var(--font-body);
  font-size: 0.78rem;
  line-height: 1.5;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  max-width: 280px;
}
.maplibregl-popup-content strong {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.85rem;
}
.maplibregl-popup-tip {
  border-top-color: var(--surface-solid) !important;
}
.maplibregl-popup-anchor-bottom .maplibregl-popup-tip {
  border-top-color: var(--surface-solid) !important;
}
.maplibregl-popup-anchor-top .maplibregl-popup-tip {
  border-bottom-color: var(--surface-solid) !important;
}
.maplibregl-popup-anchor-left .maplibregl-popup-tip {
  border-right-color: var(--surface-solid) !important;
}
.maplibregl-popup-anchor-right .maplibregl-popup-tip {
  border-left-color: var(--surface-solid) !important;
}

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 768px) {
  #search-box { width: 180px; left: 8px; top: 10px; }
  #search-input { padding: 6px 10px; font-size: 0.7rem; }
  #title-bar { display: none; }
  #title-bar h1 { font-size: 1rem; }
  #title-bar .subtitle { font-size: 0.6rem; }

  #filters-panel {
    top: 60px;
    left: 8px;
    width: 160px;
    padding: 8px;
    max-height: calc(100vh - 170px);
  }
  .chip { font-size: 0.6rem; padding: 3px 7px; }
  .chip-group { grid-template-columns: 1fr 1fr; gap: 4px; }

  #era-presets { display: none; }

  #detail-panel {
    top: auto;
    bottom: calc(var(--timeline-h) + 24px);
    right: 8px;
    left: 8px;
    width: auto;
    max-height: 50vh;
    padding: 14px;
  }
  #detail-panel.hidden { transform: translateY(100%); }

  #info-panel {
    top: auto;
    bottom: 140px;
    right: 8px;
    left: 8px;
    width: auto;
    max-height: 50vh;
  }
  #info-panel.hidden { transform: translateY(100%); }
  #contested-btn { top: 10px; right: 44px; font-size: 0.6rem; padding: 4px 10px; }
  #info-btn { top: 10px; right: 8px; width: 28px; height: 28px; font-size: 0.75rem; }

  #legend { display: none; }

  #timeline {
    left: 8px;
    right: 8px;
    bottom: 8px;
    height: 80px;
    padding: 8px 10px 6px;
    gap: 6px;
  }
  #timeline-readout { min-width: auto; font-size: 0.75rem; gap: 4px; }
  #event-count { display: none; }
  #play-btn { width: 30px; height: 30px; font-size: 0.75rem; }
  #speed-label { font-size: 0.6rem; }
  .thumb { width: 14px; height: 14px; }
}

@media (max-width: 480px) {
  #filters-panel { width: 140px; }
  .chip-group { grid-template-columns: 1fr; }
  #title-bar .subtitle { display: none; }
}
