/* ============================================================
   timeline_v2.css — Timery 2.0 dark theme for timeline pages
   Loaded AFTER timeline.css to override light-theme defaults
   ============================================================ */

/* ── CSS Variables ───────────────────────────────────────── */
:root {
  --bg: #0c0f0a;
  --bg-elevated: #161a12;
  --bg-card: #1c2218;
  --bg-card-hover: #252e1f;
  --border: #2a3324;
  --border-light: #333e2c;
  --text: #e8ece4;
  --text-dim: #8a9a7a;
  --text-muted: #5a6a4a;
  --accent: #a8cc6e;
  --accent-dim: #6a8a3a;
  --accent-bright: #c4e888;
  --radius: 10px;
  --radius-lg: 14px;
}

/* ── Force dark theme ────────────────────────────────────── */
[data-theme="dark"] body,
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, sans-serif;
}

/* ── Icon base ───────────────────────────────────────────── */
.icon { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.icon svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm svg { width: 15px; height: 15px; }
.icon-lg svg { width: 22px; height: 22px; }

/* ── Page layout ─────────────────────────────────────────── */
.tl-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-bottom: 48px; /* space for bottom bar */
}

/* ══════════════════════════════════════════════════════════
   TOPBAR
   ══════════════════════════════════════════════════════════ */
.tl-topbar {
  display: flex;
  align-items: center;
  padding: 0 20px;
  height: 48px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  gap: 16px;
  flex-shrink: 0;
  z-index: 50;
}
.tl-topbar-left { display: flex; align-items: center; gap: 14px; }
.tl-logo {
  font-size: 18px; font-weight: 900; color: var(--text);
  letter-spacing: -.5px; display: flex; align-items: center; gap: 7px; text-decoration: none;
}
.tl-logo .icon svg { width: 22px; height: 22px; stroke-width: 2.2; color: var(--accent); }
.tl-nav-icons { display: flex; align-items: center; gap: 2px; }
.tl-nav-icon {
  width: 34px; height: 34px; border-radius: 8px; background: none; border: none;
  color: var(--text-muted); cursor: pointer; display: flex; align-items: center;
  justify-content: center; transition: all .12s; text-decoration: none;
}
.tl-nav-icon:hover { color: var(--text); background: var(--bg-card); }
.tl-nav-icon.active { color: var(--text); background: var(--bg-elevated); }

.tl-topbar-center { flex: 1; max-width: 480px; margin: 0 auto; }
.tl-search-wrap {
  display: flex; align-items: center; background: var(--bg-elevated);
  border: 1px solid var(--border); border-radius: 24px; height: 38px;
  padding: 0 6px 0 16px; min-width: 0; flex: 1;
}
.tl-search-wrap .icon { color: var(--text-muted); margin-right: 8px; }
.tl-search-input {
  flex: 1; background: none; border: none; color: var(--text);
  font-size: 13px; outline: none; min-width: 0;
}
.tl-search-input::placeholder { color: var(--text-muted); }

.tl-topbar-right { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.tl-topbar-btn {
  width: 34px; height: 34px; border-radius: 50%; background: none; border: none;
  color: var(--text-dim); cursor: pointer; display: flex; align-items: center;
  justify-content: center; transition: all .12s;
}
.tl-topbar-btn:hover { color: var(--text); }
.tl-topbar-text {
  color: var(--text-dim); font-size: 12.5px; font-weight: 600;
  cursor: pointer; padding: 0 8px;
}
.tl-topbar-text:hover { color: var(--text); }
.tl-topbar-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--accent-dim);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  text-decoration: none;
}

/* Settings dropdown */
.tl-settings-wrap { position: relative; }
.tl-settings-dropdown {
  display: none; position: absolute; top: 44px; right: 0; width: 240px;
  background: var(--bg-elevated); border: 1px solid var(--border-light);
  border-radius: var(--radius-lg); padding: 6px 0;
  box-shadow: 0 10px 30px rgba(0,0,0,.5); z-index: 200;
}
.tl-settings-dropdown.open { display: block; }
.tl-settings-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 16px;
  font-size: 12.5px; color: var(--text); cursor: pointer; transition: background .1s;
}
.tl-settings-item:hover { background: var(--bg-card); }
.tl-settings-item .icon { color: var(--text-dim); }
.tl-settings-label { flex: 1; }
.tl-settings-value { font-size: 11px; color: var(--text-dim); }
.tl-settings-arrow { color: var(--text-muted); font-size: 11px; }
.tl-settings-divider { height: 1px; background: var(--border); margin: 4px 0; }

/* ══════════════════════════════════════════════════════════
   TIMELINE HEADER
   ══════════════════════════════════════════════════════════ */
.tl-header {
  text-align: center;
  padding: 18px 20px 8px;
}
.tl-title {
  font-size: clamp(24px, 4vw, 40px);
  font-weight: 900;
  letter-spacing: -1px;
  margin-bottom: 12px;
  color: var(--text);
}
.tl-breadcrumbs {
  font-size: 12px; color: var(--text-muted); margin-bottom: 12px;
}
.tl-breadcrumbs a { color: var(--accent-dim); text-decoration: none; }
.tl-breadcrumbs a:hover { color: var(--accent); }
.tl-bc-sep { opacity: .4; margin: 0 4px; }
.tl-subtitle {
  font-size: 11px; color: var(--text-muted); margin-bottom: 22px;
}
.tl-actions {
  display: flex; justify-content: center; gap: 10px; margin-bottom: 22px;
}
.tl-action-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 20px; border-radius: 22px;
  border: 1px solid var(--border); background: var(--bg-elevated);
  color: var(--text-dim); font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all .15s; text-decoration: none;
  font-family: inherit;
}
.tl-action-btn:hover {
  border-color: var(--text-dim); color: var(--text); background: var(--bg-card);
}
.tl-action-btn .icon svg { width: 16px; height: 16px; }
.tl-desc {
  font-size: 11px; color: var(--text-dim); max-width: 700px;
  margin: 0 auto; line-height: 1.5;
  /* Wraps rather than clamping to one line. The clamp cost nothing in height
     but cut every description mid-sentence; collapsing the header already
     hides this paragraph outright, so there is nothing for it to protect. */
}

/* ══════════════════════════════════════════════════════════
   RELATED TIMELINES DROPDOWN
   ══════════════════════════════════════════════════════════ */
.tl-related-wrap { position: relative; display: inline-flex; }

.tl-related-dd {
  position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  z-index: 9000; min-width: 260px; max-width: 380px;
  max-height: min(60vh, 420px); overflow-y: auto;
  background: var(--bg-elevated, var(--panel, #16161a));
  border: 1px solid var(--border, rgba(255,255,255,0.12));
  border-radius: 10px; box-shadow: 0 12px 32px rgba(0,0,0,0.45);
  padding: 4px; display: none; text-align: left;
}
.tl-related-dd.open { display: block; }

.tl-related-group {
  padding: 8px 10px 4px; font: 600 10px/1 var(--font, sans-serif);
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-dim, #8a8a80);
}

.tl-related-opt {
  display: block; padding: 7px 10px; border-radius: 7px;
  font: 400 13px/1.35 var(--font, sans-serif);
  color: var(--text, #e8e6df); text-decoration: none;
}
.tl-related-opt:hover { background: var(--bg-card-hover, rgba(255,255,255,0.07)); }
.tl-related-opt .t { display: block; min-width: 0; }
/* Descriptions are a full paragraph in the database — one line here, or the
   dropdown becomes taller than the timeline it is sitting on. */
.tl-related-opt .sub {
  display: block; font-size: 11px; color: var(--text-dim, #8a8a80);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ══════════════════════════════════════════════════════════
   RELATIVE TIMELINE LEGEND — tracks and life stages
   ══════════════════════════════════════════════════════════ */
/* relative_v2.php builds its own legend instead of legend.php: the category
   palette means nothing on a timeline whose rows are castes and whose bands
   are life stages. Colours come from the database as inline styles, so these
   rules only supply layout — never set a background on .rel-legend-dot. */
.rel-legend {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 26px 16px 22px;
}
.rel-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  font-family: 'Inter', -apple-system, sans-serif;
  white-space: nowrap;
}
.rel-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
}
/* Divider between the track group and the stage group */
.rel-legend-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 4px;
  flex: 0 0 auto;
}

@media (max-width: 700px) {
  .rel-legend { gap: 6px; padding: 16px 10px 14px; }
  .rel-legend-item { padding: 5px 12px; font-size: 11px; }
}

/* ══════════════════════════════════════════════════════════
   LEGEND / FILTER PILLS — override existing legend.php
   ══════════════════════════════════════════════════════════ */
.legend {
  display: flex !important;
  justify-content: center;
  gap: 8px;
  padding: 26px 16px 22px;
  flex-wrap: wrap;
  background: none;
  border: none;
  margin: 0;
}
.leg-btn {
  display: inline-flex !important;
  align-items: center;
  gap: 6px;
  padding: 7px 16px !important;
  border-radius: 20px !important;
  border: 1px solid var(--border) !important;
  background: var(--bg-elevated) !important;
  color: var(--text-dim) !important;
  font-size: 12px !important;
  font-weight: 600 !important;
  cursor: pointer;
  transition: all .12s;
  font-family: 'Inter', -apple-system, sans-serif !important;
}
.leg-btn:hover {
  border-color: var(--text-dim) !important;
  color: var(--text) !important;
}
.leg-btn.off {
  opacity: .45;
}
.leg-dot {
  width: 8px !important;
  height: 8px !important;
  border-radius: 50% !important;
}
/* Defensive: timeline.css may style .leg-btn span generically for the
   colour dot, which would collapse this icon span. Override hard. */
.leg-btn .leg-icon {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  width: auto !important;
  height: auto !important;
  min-width: 0 !important;
  background: none !important;
  border: none !important;
  border-radius: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  flex-shrink: 0;
  color: currentColor;
  opacity: .85;
}
.leg-btn .leg-icon svg {
  display: block;
  width: 14px !important;
  height: 14px !important;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.leg-btn:hover .leg-icon { opacity: 1; }

/* Category accent on the pill icon — replaces the old colour dot.
   Mirrors the C_DARK override in curated_v2.php; keep the two in sync. */
.leg-btn.cat-person    .leg-icon { color: #b8b1ff !important; }
.leg-btn.cat-event     .leg-icon { color: #5ed99c !important; }
.leg-btn.cat-conflicts .leg-icon { color: #f56d6d !important; }
.leg-btn.cat-crisis    .leg-icon { color: #fc9c4c !important; }
.leg-btn.cat-science   .leg-icon { color: #6ac0f9 !important; }
.leg-btn.cat-culture   .leg-icon { color: #e685d0 !important; }
.leg-btn.cat-companies .leg-icon { color: #49d0d0 !important; }
.leg-btn.cat-countries .leg-icon { color: #ecd45b !important; }
/* Old colour dot — superseded by the tinted icon */
.leg-btn .ld { display: none !important; }

/* ══════════════════════════════════════════════════════════
   AXIS — override existing axis styles
   ══════════════════════════════════════════════════════════ */
#axisWrap {
  background: var(--bg) !important;
  border-bottom: 1px solid var(--border) !important;
}
.ax-bar {
  background: none !important;
  border: none !important;
}
.ax-dec {
  border-left: 1px solid rgba(255,255,255,.08) !important;
  color: var(--text-muted) !important;
}
.ax-dec.hov {
  background: rgba(255,255,255,.04) !important;
}
.ax-year {
  color: var(--text-dim) !important;
  font-family: 'Inter', -apple-system, sans-serif !important;
  font-weight: 600 !important;
}
.ax-major {
  color: var(--text) !important;
}
/* Years outside the zoom selection — readable but recessive */
.ax-out .ax-year  { color: var(--text-muted) !important; opacity: .55; }
.ax-out .ax-major { color: var(--text-muted) !important; opacity: .7; }
.ax-out { border-left-color: rgba(255,255,255,.04) !important; }
.ax-year { transition: opacity .12s ease, color .12s ease; }

.ax-hint {
  color: var(--text-muted) !important;
  font-family: 'Inter', -apple-system, sans-serif !important;
}
.ax-sublabel {
  color: var(--text-muted) !important;
  font-family: 'Inter', -apple-system, sans-serif !important;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.ax-nav {
  color: var(--text-dim) !important;
  background: var(--bg-elevated) !important;
}
.ax-nav:hover {
  color: var(--text) !important;
  background: var(--bg-card) !important;
}

/* ══════════════════════════════════════════════════════════
   HEADER COLLAPSE
   ══════════════════════════════════════════════════════════ */
.tl-headerzone { position: relative; }

.tl-collapse-btn {
  position: absolute;
  top: 14px;
  right: 20px;
  z-index: 6;
  width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-dim);
  cursor: pointer;
  transition: all .15s;
}
.tl-collapse-btn:hover {
  border-color: var(--text-dim); color: var(--text); background: var(--bg-card);
}
.tl-collapse-chevron {
  font-size: 13px; line-height: 1;
  transform: translateY(2px);
  transition: transform .25s ease;
}

/* ── Collapsed: one row — title, actions, then pills on the right ── */
.tl-headerzone.collapsed {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 62px 8px 20px;
  border-bottom: 1px solid var(--border);
}
.tl-headerzone.collapsed .tl-collapse-btn { top: 50%; transform: translateY(-50%); }
.tl-headerzone.collapsed .tl-collapse-chevron { transform: translateY(-2px) rotate(180deg); }

.tl-headerzone.collapsed .tl-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0;
  text-align: left;
  flex: 0 1 auto;
  min-width: 0;
}
.tl-headerzone.collapsed .tl-title {
  font-size: 17px;
  margin: 0;
  letter-spacing: -.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Hidden in the collapsed row */
.tl-headerzone.collapsed .tl-subtitle,
.tl-headerzone.collapsed .tl-desc,
.tl-headerzone.collapsed .tl-breadcrumbs { display: none; }

.tl-headerzone.collapsed .tl-actions { margin: 0; gap: 6px; flex: 0 0 auto; }
.tl-headerzone.collapsed .tl-action-btn { padding: 4px 12px; font-size: 11px; }
.tl-headerzone.collapsed .tl-action-btn .icon svg { width: 13px; height: 13px; }

/* Pills pushed right and scaled down */
.tl-headerzone.collapsed .tl-legend-row {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.tl-headerzone.collapsed .legend {
  --leg-icon-size: 11px;
  padding: 0;
  gap: 4px;
  justify-content: flex-end;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}
.tl-headerzone.collapsed .legend::-webkit-scrollbar { display: none; }
.tl-headerzone.collapsed .leg-btn {
  padding: 3px 9px !important;
  font-size: 10.5px !important;
  gap: 4px;
  white-space: nowrap;
}
/* Reset / Save stay reachable — inline at the end of the row */
.tl-headerzone.collapsed #rangeTools {
  position: static;
  transform: none;
  flex: 0 0 auto;
}
.tl-headerzone.collapsed #rangeTools .range-tool {
  padding: 3px 10px;
  font-size: 10.5px;
}

/* Collapsed row is tight — Favourite / Compare / Reset / Save drop their
   labels and keep only the icon. The title attribute carries the meaning. */
.tl-headerzone.collapsed .tl-action-btn .btn-label,
.tl-headerzone.collapsed #rangeTools .range-tool .btn-label { display: none; }
.tl-headerzone.collapsed .tl-action-btn { padding: 4px 9px; gap: 0; }
.tl-headerzone.collapsed #rangeTools .range-tool { padding: 3px 8px; gap: 0; }

/* ══════════════════════════════════════════════════════════
   RANGE TOOLS — reset / save, above the scrubber axis
   ══════════════════════════════════════════════════════════ */
/* Absolutely positioned inside the pill row, so showing/hiding them
   never shifts the canvas. Fades in rather than popping. */
.tl-legend-row { position: relative; }
#rangeTools {
  position: absolute;
  top: 26px;
  right: 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  transform: translateY(-5px);
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
}
#rangeTools.visible {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
.range-tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-dim);
  font: 600 12px 'Inter', -apple-system, sans-serif;
  cursor: pointer;
  transition: all .15s;
}
.range-tool:hover {
  border-color: var(--text-dim);
  color: var(--text);
  background: var(--bg-card);
}
.range-tool .icon svg { width: 14px; height: 14px; }
.range-tool-glyph { font-size: 14px; line-height: 1; }

/* ══════════════════════════════════════════════════════════
   ZOOM AXIS — live scale for the selected range
   ══════════════════════════════════════════════════════════ */
#axisZoomWrap {
  position: relative;
  height: 26px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.axz-bar { position: absolute; top: 0; bottom: 0; }
.axz-tick { position: absolute; top: 0; height: 100%; }
.axz-tick i {
  position: absolute; left: 0; top: 0;
  width: 1px; height: 7px;
  background: var(--accent-dim);
}
.axz-tick b {
  position: absolute; top: 9px; left: 0;
  transform: translateX(-50%);
  font: 600 11px 'Inter', -apple-system, sans-serif;
  color: var(--accent);
  white-space: nowrap;
}
/* Edge labels sit inside the range instead of straddling it */
.axz-start { left: 0; }
.axz-start b { transform: translateX(0); color: var(--accent-bright); }
.axz-end b  { transform: translateX(-100%); color: var(--accent-bright); }

/* ══════════════════════════════════════════════════════════
   ERA BANDS
   ══════════════════════════════════════════════════════════ */
#eraBandWrap {
  background: var(--bg) !important;
  border-bottom: 1px solid var(--border);
}
.era-band-seg {
  opacity: 0.6 !important;
}
.era-band-seg:hover {
  opacity: 0.85 !important;
}

/* ══════════════════════════════════════════════════════════
   CANVAS AREA
   ══════════════════════════════════════════════════════════ */
#canvasWrap {
  background: var(--bg) !important;
}
/* The canvas is viewport-sized and sticks to the top of the scroll container;
   #canvasSpacer carries the full content height so the scrollbar is correct.
   Keeps the canvas under the browser's GPU-acceleration size limit. */
#canvasSpacer {
  position: relative;
  width: 100%;
}
#canvasWrap #canvasSpacer > canvas#tl {
  position: sticky;
  top: 0;
  display: block;
}
canvas {
  background: transparent !important;
}

/* ══════════════════════════════════════════════════════════
   RANGE HANDLES
   ══════════════════════════════════════════════════════════ */
.range-handle {
  background: var(--accent) !important;
  border-color: var(--accent-bright) !important;
}
.range-overlay {
  background: rgba(0,0,0,.3) !important;
}
.handle-year-tip {
  background: var(--bg-elevated) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  font-family: 'Inter', -apple-system, sans-serif !important;
}

/* ══════════════════════════════════════════════════════════
   INSTRUCTIONS
   ══════════════════════════════════════════════════════════ */
.tl-instructions {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  padding: 12px 0;
  opacity: .6;
}

/* ══════════════════════════════════════════════════════════
   BOTTOM BAR
   ══════════════════════════════════════════════════════════ */
.tl-bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 20px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  z-index: 100;
}
.tl-zoom-controls { display: flex; align-items: center; gap: 4px; }
.tl-zoom-btn {
  width: 32px; height: 32px; border-radius: 8px;
  background: none; border: 1px solid var(--border);
  color: var(--text-dim); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .12s; font-family: inherit;
}
.tl-zoom-btn:hover { border-color: var(--text-dim); color: var(--text); }
.tl-zoom-level {
  font-size: 12px; font-weight: 600; color: var(--text-dim);
  min-width: 48px; text-align: center;
  font-family: 'Inter', -apple-system, sans-serif;
}
.tl-zoom-fit {
  padding: 4px 14px; border-radius: 8px;
  background: none; border: 1px solid var(--border);
  color: var(--text-dim); font-size: 12px; font-weight: 600;
  cursor: pointer; margin-left: 4px; font-family: inherit;
}
.tl-zoom-fit:hover { border-color: var(--text-dim); color: var(--text); }

.tl-density-controls { display: flex; align-items: center; gap: 8px; }
.tl-density-label {
  font-size: 11px; color: var(--text-muted); font-weight: 600;
  font-family: 'Inter', -apple-system, sans-serif;
}
.tl-density-btns { display: flex; gap: 2px; }
.tl-density-btn {
  width: 32px; height: 32px; border-radius: 8px;
  background: none; border: 1px solid var(--border);
  color: var(--text-muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .12s; font-family: inherit;
}
.tl-density-btn:hover { border-color: var(--text-dim); color: var(--text); }
.tl-density-btn.active {
  background: var(--bg-card); color: var(--text); border-color: var(--accent-dim);
}

/* ══════════════════════════════════════════════════════════
   PANEL (click-expanded card actions) — dark overrides
   ══════════════════════════════════════════════════════════ */
.period-toast {
  background: var(--bg-elevated) !important;
  border: 1px solid var(--border) !important;
  color: var(--text) !important;
}
.period-toast a { color: var(--accent) !important; }

/* ══════════════════════════════════════════════════════════
   HISTORY PANEL — dark overrides
   ══════════════════════════════════════════════════════════ */
.history-panel {
  background: var(--bg-elevated) !important;
  border: 1px solid var(--border) !important;
  color: var(--text) !important;
}

/* ══════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════ */
@media (max-width: 700px) {
  .tl-topbar { padding: 0 12px; gap: 10px; height: 50px; }
  .tl-logo { font-size: 16px; }
  .tl-nav-icons { gap: 0; }
  .tl-nav-icon { width: 30px; height: 30px; }
  .tl-search-wrap { height: 34px; }
  .tl-search-input { font-size: 12px; }
  .tl-topbar-text { display: none; }

  .tl-header { padding: 14px 12px 4px; }
  .tl-title { font-size: 24px; margin-bottom: 8px; }
  .tl-subtitle { margin-bottom: 14px; }
  .tl-actions { gap: 6px; margin-bottom: 14px; }
  .tl-action-btn { padding: 6px 16px; font-size: 12px; }

  /* Same treatment as the collapsed header: icon only, label gone */
  .tl-action-btn .btn-label,
  .range-tool .btn-label { display: none; }
  .tl-action-btn { padding: 6px 11px; gap: 0; }
  .range-tool { padding: 7px 11px; gap: 0; }

  .legend { padding: 16px 10px 14px; gap: 5px; }
  #rangeTools { top: 16px; right: 12px; }
  .leg-btn { padding: 4px 10px !important; font-size: 11px !important; }

  .tl-bottom-bar { height: 44px; padding: 0 12px; }
  .tl-zoom-btn { width: 28px; height: 28px; }
  .tl-zoom-level { font-size: 11px; min-width: 40px; }
  .tl-zoom-fit { font-size: 11px; padding: 3px 10px; }
  .tl-density-btn { width: 28px; height: 28px; }
}

@media (max-width: 480px) {
  .tl-nav-icons { display: none; }
  .tl-topbar-center { max-width: none; }
  .tl-header { padding: 10px 10px 4px; }
  .tl-title { font-size: 20px; margin-bottom: 6px; }
  .tl-subtitle { margin-bottom: 12px; }
  .tl-actions { margin-bottom: 12px; }
  .legend { padding: 14px 10px 12px; }
  #rangeTools { top: 14px; right: 10px; }
  .tl-subtitle { font-size: 11px; }
  .tl-desc { font-size: 11px; }
  .tl-density-label { display: none; }
}

/* ══════════════════════════════════════════════════════════
   OVERRIDE old topbar / header — hide them
   ══════════════════════════════════════════════════════════ */
.topbar-old, .top-bar, body > nav:first-of-type {
  display: none !important;
}
header h1:not(.tl-title) {
  display: none !important;
}
header .subtitle {
  display: none !important;
}

/* ── Hide old emoji icons in legend, keep just the dot + text ── */
.leg-btn .leg-icon {
  display: none !important;
}
.expand-arrow {
  color: var(--text-muted) !important;
  font-size: 10px !important;
  margin-left: 2px;
}

/* ── Sub-legend dark overrides ── */
.sub-legend {
  background: var(--bg-elevated) !important;
  border: 1px solid var(--border) !important;
}
.sub-btn {
  background: var(--bg-card) !important;
  color: var(--text-dim) !important;
  border-color: var(--border) !important;
}
.sub-btn:hover {
  color: var(--text) !important;
}

/* ── Remove old topbar padding ── */
body {
  padding-top: 0 !important;
}

/* ── Kill ALL old spacing/padding/margins ── */
body {
  margin: 0 !important;
  padding: 0 !important;
}
.tl-page {
  margin: 0 !important;
  padding: 0 !important;
}
/* Hide history panel if it adds space */
#historyPanel, .history-panel-toggle, .history-wrap {
  position: fixed !important;
}

/* ── Override old header margins ── */
header {
  margin-top: 0 !important;
  margin-bottom: 0 !important;
}

/* ── Legend pill colors — dark mode overrides ── */
.leg-btn[data-cat="person"] { color: #b0a8ff !important; }
.leg-btn[data-cat="event"] { color: #50d4a0 !important; }
.leg-btn[data-cat="conflicts"] { color: #f06060 !important; }
.leg-btn[data-cat="crisis"] { color: #f09050 !important; }
.leg-btn[data-cat="science"] { color: #60b8f0 !important; }
.leg-btn[data-cat="culture"] { color: #c080e0 !important; }
.leg-btn[data-cat="companies"] { color: #50b080 !important; }
.leg-btn[data-cat="countries"] { color: #f0b040 !important; }
.leg-btn[data-cat="personal"] { color: #f0c060 !important; }
.leg-btn .leg-dot[style*="person"] { background: #b0a8ff !important; }
.leg-btn .leg-dot[style*="event"] { background: #50d4a0 !important; }
.leg-btn .leg-dot[style*="conflicts"] { background: #f06060 !important; }
.leg-btn .leg-dot[style*="crisis"] { background: #f09050 !important; }
.leg-btn .leg-dot[style*="science"] { background: #60b8f0 !important; }
.leg-btn .leg-dot[style*="culture"] { background: #c080e0 !important; }
.leg-btn .leg-dot[style*="companies"] { background: #50b080 !important; }
.leg-btn .leg-dot[style*="countries"] { background: #f0b040 !important; }
