/* =====================================================
   Chronolines — Stylesheet v4
   Theme: Linear / Vercel / Raycast — modern dark
   ===================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

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

:root {
  /* Backgrounds */
  --bg-primary:   #0d0d0d;
  --bg-surface:   #141414;
  --bg-elevated:  #1a1a1a;
  --bg-hover:     #1f1f1f;

  /* Text */
  --text-primary:   rgba(255,255,255,0.92);
  --text-secondary: rgba(255,255,255,0.55);
  --text-muted:     rgba(255,255,255,0.3);

  /* Borders */
  --border:       rgba(255,255,255,0.08);
  --border-hover: rgba(255,255,255,0.15);

  /* Accent */
  --accent:       #4f8ef7;
  --accent-hover: #6ba3ff;

  /* Shadows — glow style for dark bg */
  --shadow-card:    0 0 0 1px rgba(255,255,255,0.06), 0 4px 16px rgba(0,0,0,0.4);
  --shadow-tooltip: 0 0 0 1px rgba(255,255,255,0.1), 0 8px 32px rgba(0,0,0,0.6);
  --shadow-panel:   0 0 0 1px rgba(255,255,255,0.06), 0 12px 40px rgba(0,0,0,0.7);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-mid:  200ms ease;
  --transition-slow: 250ms ease;

  /* Layout */
  --header-height:      56px;
  --filter-height:      40px;
  --yearbar-height:     32px;
  --axis-height:        40px;
  --sidebar-width:      120px;
  --track-height:       192px;
  --ruler-height:       8px;
  --track-line-offset:  60px;

  /* Font */
  --font: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* =====================
   Scrollbars
   ===================== */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.22); }
* { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.12) transparent; }

/* =====================
   App Header
   ===================== */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  z-index: 200;
}

.header-left {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-shrink: 0;
}

.app-title {
  font-family: var(--font);
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.app-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}

.app-hint {
  font-size: 10px;
  color: var(--text-muted);
  opacity: 0.6;
  font-weight: 400;
  letter-spacing: 0.2px;
}

.header-center {
  flex: 1;
  display: flex;
  justify-content: center;
}

.year-range-display {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px;
  background: var(--bg-elevated);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.year-range-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.year-range-value {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.5px;
  font-variant-numeric: tabular-nums;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Level selector */
.level-controls {
  display: flex;
  gap: 2px;
  align-items: center;
  margin-right: 4px;
}

.level-btn {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
  user-select: none;
  white-space: nowrap;
}

.level-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-hover);
}

.level-btn.active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  font-weight: 600;
}

.search-box {
  position: relative;
}

.search-input {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font);
  padding: 5px 12px;
  width: 180px;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.search-input::placeholder { color: var(--text-muted); }

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(79,142,247,0.15);
  background: var(--bg-surface);
}

.zoom-controls { display: flex; gap: 4px; }

.ctrl-btn {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 11px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
  user-select: none;
  font-family: var(--font);
}

.ctrl-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-hover);
}

.ctrl-btn:active {
  background: rgba(255,255,255,0.06);
  transform: scale(0.97);
}

/* =====================
   Filter Bar
   ===================== */
.filter-bar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  height: var(--filter-height);
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  z-index: 190;
  overflow-x: auto;
  overflow-y: hidden;
}

.filter-bar::-webkit-scrollbar { height: 0; }

.filter-section {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.filter-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 12px;
  flex-shrink: 0;
}

.filter-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
  letter-spacing: 0.2px;
}

.tag-chips, .category-chips {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

/* Tag chips */
.tag-chip {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 9999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-fast);
  line-height: 1.4;
}

.tag-chip:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-hover);
}

.tag-chip.active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  font-weight: 600;
}

/* Category chips */
.cat-chip {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 9999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-fast);
  line-height: 1.4;
}

.cat-chip:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-hover);
}

.cat-chip.active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  font-weight: 600;
}


/* =====================
   Main Layout
   ===================== */
/* =====================
   Year Bar
   ===================== */
:root {
  --yearbar-height: 40px;
}

.year-bar {
  position: fixed;
  top: calc(var(--header-height) + var(--filter-height));
  left: 0;
  right: 0;
  height: var(--yearbar-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  z-index: 185;
  pointer-events: none;
}

/* Floating pill — absolutely positioned, follows mouse X */
.year-bar-hover-pill {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  background: rgba(79,142,247,0.12);
  border: 1px solid rgba(79,142,247,0.45);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 5px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.3px;
  white-space: nowrap;
  pointer-events: none;
}


.main-layout {
  position: fixed;
  top: calc(var(--header-height) + var(--filter-height) + var(--yearbar-height));
  left: 0;
  right: 0;
  bottom: var(--axis-height);
  display: flex;
  overflow-y: auto;
  overflow-x: hidden;
}

/* =====================
   Sidebar
   ===================== */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  position: relative;
  /* Height auto — grows with SVG total height */
}

/* Full-height track card in sidebar */
.sidebar-label {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition-fast);
  user-select: none;
  will-change: transform;
  overflow: hidden;
}

/* Tinted background via --track-color set inline */
.sidebar-label::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--track-color, transparent);
  opacity: 0.06;
  pointer-events: none;
}

/* Left accent bar */
.sidebar-label::after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--track-color, rgba(255,255,255,0.2));
  opacity: 0.8;
  border-radius: 0 2px 2px 0;
}

.sidebar-label:hover {
  background: rgba(255,255,255,0.03);
}

/* =====================
   Drag Handle — full-height strip
   ===================== */
.drag-handle {
  position: absolute;
  left: 3px;   /* just after the accent bar */
  top: 0;
  bottom: 0;
  width: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  z-index: 1;
}

/* Six-dot grip icon made with CSS */
.drag-handle::before,
.drag-handle::after {
  content: '';
  display: block;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  box-shadow:
    0 5px 0 rgba(255,255,255,0.25),
    0 10px 0 rgba(255,255,255,0.25),
    5px 0 0 rgba(255,255,255,0.25),
    5px 5px 0 rgba(255,255,255,0.25),
    5px 10px 0 rgba(255,255,255,0.25);
  transition: background var(--transition-fast),
              box-shadow var(--transition-fast);
}

.drag-handle:hover::before,
.drag-handle:hover::after {
  background: rgba(255,255,255,0.7);
  box-shadow:
    0 5px 0 rgba(255,255,255,0.7),
    0 10px 0 rgba(255,255,255,0.7),
    5px 0 0 rgba(255,255,255,0.7),
    5px 5px 0 rgba(255,255,255,0.7),
    5px 10px 0 rgba(255,255,255,0.7);
}

.drag-handle:active,
.drag-ghost .drag-handle {
  cursor: grabbing;
}

/* Country name + dot inside card */
.sidebar-card-body {
  position: absolute;
  left: 28px;   /* after drag handle */
  right: 0;
  top: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  padding: 0 10px 0 4px;
  gap: 6px;
}

.sidebar-label-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.sidebar-label-name {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  line-height: 1.2;
}

/* Ghost element created during drag */
.drag-ghost {
  user-select: none;
  cursor: grabbing !important;
  border-left: 3px solid var(--track-color, rgba(255,255,255,0.4)) !important;
}

/* =====================
   Canvas Wrapper
   ===================== */
.canvas-wrapper {
  flex: 1;
  overflow: hidden;
  position: relative;
  cursor: grab;
  background: var(--bg-primary);
}

.canvas-wrapper.dragging {
  cursor: grabbing;
  user-select: none;
}

#timeline-svg {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  user-select: none;
  overflow: visible;
}

/* =====================
   Bottom Time Axis
   ===================== */
.time-axis {
  position: fixed;
  bottom: 0;
  left: var(--sidebar-width);
  right: 0;
  height: var(--axis-height);
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  z-index: 180;
  overflow: hidden;
}

#axis-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* =====================
   SVG Elements (CSS classes)
   ===================== */
.track-band {
  pointer-events: none;
}

.ruler-bar-segment {
  cursor: pointer;
  transition: opacity 120ms ease;
}

.ruler-bar-segment:hover {
  opacity: 1 !important;
}

.track-center-line {
  pointer-events: none;
}

.event-dot {
  cursor: pointer;
  transition: r 150ms ease;
}

.event-dot.search-faded {
  opacity: 0.08;
}

.event-dot.tag-faded {
  opacity: 0.08;
}

.event-duration-bar {
  pointer-events: none;
}

.event-cluster-g {
  cursor: pointer;
}

.event-label-text {
  pointer-events: none;
  font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  dominant-baseline: auto;
}

.event-label-line {
  pointer-events: none;
}

.figure-bar {
  pointer-events: all;
  cursor: pointer;
  transition: opacity 120ms ease;
}

.figure-bar:hover {
  opacity: 1 !important;
}

.arc-path {
  fill: none;
  stroke-width: 1;
  opacity: 0.45;
  stroke-dasharray: 4 3;
  pointer-events: none;
}

.hover-band {
  pointer-events: none;
}

/* =====================
   Tooltip
   ===================== */
.tooltip {
  position: fixed;
  background: var(--bg-elevated);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  padding: 0;
  width: 280px;
  pointer-events: none;
  z-index: 1000;
  box-shadow: var(--shadow-tooltip);
  overflow: hidden;
  animation: tooltip-in 120ms ease forwards;
}

@keyframes tooltip-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.tt-header {
  padding: 12px 16px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.tt-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.tt-year {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.2px;
}

.tt-track-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
}

.tt-track-name {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.2px;
}

.tt-title {
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.4;
  letter-spacing: -0.1px;
}

.tt-body {
  padding: 10px 16px 12px;
}

.tt-summary {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 8px;
}

.tt-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tt-tag {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 9999px;
}

.tt-figures {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}

.tt-figures-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-right: 4px;
}

/* Ruler tooltip */
.tt-ruler-name {
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 3px;
  letter-spacing: -0.1px;
}

.tt-ruler-title {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

.tt-ruler-years {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

/* Cluster tooltip */
.tt-cluster-item {
  font-size: 12px;
  color: var(--text-secondary);
  padding: 4px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  line-height: 1.4;
}

.tt-cluster-item:last-child { border-bottom: none; }

/* Figure tooltip */
.tt-figure-name {
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.1px;
}

.tt-figure-cat {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 9999px;
  margin-left: 6px;
  vertical-align: middle;
}

.tt-figure-years {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin: 4px 0;
}

.tt-figure-summary {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.55;
}

/* =====================
   Detail Panel
   ===================== */
.detail-panel {
  position: fixed;
  right: 0;
  top: calc(var(--header-height) + var(--filter-height));
  bottom: var(--axis-height);
  width: 320px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  z-index: 500;
  box-shadow: var(--shadow-panel);
  display: flex;
  flex-direction: column;
  transition: transform var(--transition-slow), opacity var(--transition-slow);
}

.detail-panel.hidden {
  transform: translateX(100%);
  opacity: 0;
  pointer-events: none;
}

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-elevated);
}

.detail-header-track {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 9999px;
}

.detail-close {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.detail-close:hover {
  background: rgba(255,255,255,0.1);
  color: var(--text-primary);
}

.detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 18px;
}

.detail-year {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
  letter-spacing: 0.2px;
}

.detail-title {
  font-family: var(--font);
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 14px;
  line-height: 1.3;
  letter-spacing: -0.4px;
}

.detail-summary {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.75;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.detail-detail {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.8;
  margin-bottom: 16px;
  white-space: pre-wrap;
}

.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 16px;
}

.detail-tag {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 9999px;
}

.detail-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.6px;
  text-transform: uppercase;
  margin-bottom: 8px;
  margin-top: 16px;
}

.detail-figure-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 12px;
}

.detail-figure-chip {
  font-size: 12px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 9999px;
  background: rgba(255,255,255,0.05);
  color: var(--text-secondary);
  border: 1px solid rgba(255,255,255,0.1);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.detail-figure-chip:hover {
  background: rgba(79,142,247,0.12);
  color: var(--accent);
  border-color: rgba(79,142,247,0.3);
}

.detail-related-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.detail-related-item {
  font-size: 13px;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: rgba(79,142,247,0.3);
  line-height: 1.5;
  transition: text-decoration-color var(--transition-fast);
}

.detail-related-item:hover {
  text-decoration-color: var(--accent);
}
