/* Timeline Knowledge Graph — Stylesheet
   Inherits theme variables from /platform/css/textbook.css:
     --color-bg, --color-bg-alt, --color-text, --color-border,
     --color-accent, --color-text-secondary
     --font-body, --font-heading
   Theme selectors: [data-theme="dark"], [data-theme="reading"]
*/

/* ============================================================
   Body override — timeline is full-viewport, not textbook layout
   ============================================================ */
body {
  max-width: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

/* ============================================================
   Custom Properties
   ============================================================ */
:root {
  --tl-header-h: 48px;
  --tl-filter-h: 52px;
}

/* ============================================================
   Layout — Header
   ============================================================ */
.tl-header {
  display: flex;
  align-items: center;
  padding: 8px 24px;
  border-bottom: 1px solid var(--color-border);
  height: var(--tl-header-h);
  gap: 12px;
  background: var(--color-bg);
}

.tl-home-link {
  text-decoration: none;
  font-weight: 700;
  color: var(--color-text);
  font-family: var(--font-heading);
  font-size: 0.95em;
}

.tl-home-link:hover {
  color: var(--color-accent);
}

.tl-breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85em;
  color: var(--color-text-secondary);
}

.tl-breadcrumb a {
  color: var(--color-text-secondary);
  text-decoration: none;
}

.tl-breadcrumb a:hover {
  color: var(--color-accent);
}

.tl-sep {
  color: var(--color-text-secondary);
  opacity: 0.4;
  user-select: none;
}

.tl-header-controls {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ============================================================
   Layout — Filter Bar
   ============================================================ */
.tl-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 24px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg-alt);
  align-items: center;
  min-height: var(--tl-filter-h);
}

.tl-filter-pill {
  border-radius: 16px;
  padding: 4px 12px;
  font-size: 0.8em;
  cursor: pointer;
  transition: opacity 0.2s;
  border: 1.5px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-body);
  line-height: 1.4;
  user-select: none;
}

.tl-filter-pill:hover {
  border-color: var(--color-accent);
}

.tl-filter-pill[aria-pressed="false"] {
  opacity: 0.4;
}

.tl-filter-pill[aria-pressed="true"] {
  opacity: 1;
}

.tl-filter-pill svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.tl-filters-category {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  align-items: center;
}

.tl-filters-era {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  align-items: center;
}

/* ============================================================
   Layout — Search
   ============================================================ */
.tl-search {
  display: flex;
  align-items: center;
  position: relative;
  flex: 1;
  min-width: 140px;
  max-width: 280px;
}

.tl-search-input {
  width: 100%;
  padding: 4px 28px 4px 10px;
  border: 1px solid var(--color-border);
  border-radius: 16px;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 0.8em;
  outline: none;
  transition: border-color 0.2s;
}

.tl-search-input::placeholder {
  color: var(--color-text-secondary);
  opacity: 0.6;
}

.tl-search-input:focus {
  border-color: var(--color-accent);
}

.tl-search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--color-text-secondary);
  cursor: pointer;
  font-size: 1.1em;
  padding: 2px 4px;
  line-height: 1;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tl-search-clear:hover {
  color: var(--color-text);
  background: var(--color-bg-alt);
}

/* ============================================================
   Layout — Filter Count & Reset
   ============================================================ */
.tl-filter-count {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8em;
  color: var(--color-text-secondary);
  white-space: nowrap;
  margin-left: auto;
}

.tl-filter-reset {
  font-size: 0.75em;
  padding: 2px 8px;
  border-radius: 8px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  cursor: pointer;
  color: var(--color-text);
  font-family: var(--font-body);
  display: none;
}

.tl-filter-reset.is-visible {
  display: inline-block;
}

.tl-filter-reset:hover {
  color: var(--color-accent);
  border-color: var(--color-accent);
}

/* ============================================================
   Layout — Main Area
   ============================================================ */
.tl-main {
  display: flex;
  height: calc(100vh - var(--tl-header-h, 48px) - var(--tl-filter-h, 52px));
}

.tl-graph-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--color-bg);
}

.tl-graph {
  width: 100%;
  height: 100%;
  background: var(--color-bg);
}

/* ============================================================
   Card Panel
   ============================================================ */
.tl-card-panel {
  width: 340px;
  border-left: 1px solid var(--color-border);
  overflow-y: auto;
  background: var(--color-bg);
  transition: transform 0.2s ease-out, width 0.2s ease-out, padding 0.2s ease-out;
  padding: 20px;
  display: flex;
  flex-direction: column;
  position: relative;
}

.tl-card-panel[hidden] {
  display: block;
  transform: translateX(100%);
  width: 0;
  padding: 0;
  border: none;
  overflow: hidden;
}

.tl-card-panel.is-open {
  transform: translateX(0);
  display: flex;
  width: 340px;
  padding: 20px;
  border-left: 1px solid var(--color-border);
}

.tl-card-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  font-size: 1.4em;
  cursor: pointer;
  color: var(--color-text-secondary);
  z-index: 2;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tl-card-close:hover {
  color: var(--color-text);
}

.tl-card-back {
  display: inline-block;
  font-size: 0.85em;
  color: var(--color-accent);
  text-decoration: none;
  margin-bottom: 12px;
  cursor: pointer;
}

.tl-card-back:hover {
  text-decoration: underline;
}

.tl-card-content {
  flex: 1;
  overflow-y: auto;
  line-height: 1.6;
  font-family: var(--font-body);
  color: var(--color-text);
}

/* ============================================================
   Card Content — Details
   ============================================================ */
.tl-card-name {
  font-size: 1.3em;
  font-weight: bold;
  margin: 0 0 4px;
  font-family: var(--font-heading);
  color: var(--color-text);
  padding-right: 32px; /* room for close button */
}

.tl-card-dates {
  font-size: 0.85em;
  color: var(--color-text-secondary);
}

.tl-card-era-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.75em;
  font-weight: 600;
  color: white;
  margin: 8px 0;
}

.tl-card-claim,
.tl-card-thesis,
.tl-card-impact {
  font-size: 0.95em;
  line-height: 1.5;
  margin: 12px 0;
  font-style: italic;
}

.tl-card-claim {
  padding-left: 12px;
  border-left: 3px solid var(--color-accent);
}

.tl-card-section-title {
  font-size: 0.8em;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-secondary);
  margin: 16px 0 8px;
  font-weight: 600;
  font-family: var(--font-heading);
}

.tl-card-connections {
  list-style: none;
  padding: 0;
  margin: 0;
}

.tl-card-connections li {
  padding: 6px 0;
  border-bottom: 1px solid var(--color-border);
}

.tl-card-connections li:last-child {
  border-bottom: none;
}

.tl-card-connection-link {
  cursor: pointer;
  color: var(--color-accent);
  font-weight: 500;
  text-decoration: none;
}

.tl-card-connection-link:hover {
  text-decoration: underline;
}

.tl-card-connection-type {
  font-size: 0.75em;
  color: var(--color-text-secondary);
  margin-left: 4px;
}

.tl-card-connection-desc {
  font-size: 0.8em;
  color: var(--color-text-secondary);
  margin-top: 2px;
  display: block;
}

.tl-card-chapter-links {
  list-style: none;
  padding: 0;
}

.tl-card-chapter-links a {
  display: block;
  padding: 4px 0;
  color: var(--color-accent);
  font-size: 0.85em;
  text-decoration: none;
}

.tl-card-chapter-links a:hover {
  text-decoration: underline;
}

/* ============================================================
   Graph SVG — Nodes
   ============================================================ */
.tl-node {
  cursor: pointer;
  transition: opacity 0.3s;
}

.tl-node:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.tl-node--thinker circle,
.tl-node--school polygon,
.tl-node--work polygon,
.tl-node--crisis polygon {
  transition: fill 0.2s, stroke 0.2s;
}

.tl-node--external circle {
  fill: transparent;
  stroke-dasharray: 4 2;
}

.tl-node.is-focused {
  filter: drop-shadow(0 0 6px var(--color-accent));
}

.tl-node.is-prev-focused {
  filter: drop-shadow(0 0 4px var(--color-accent));
  opacity: 0.7;
}

.tl-node.is-dimmed {
  opacity: 0.1;
  pointer-events: none;
}

.tl-node-label {
  font-size: 10px;
  font-family: var(--font-body);
  fill: var(--color-text);
  text-anchor: middle;
  pointer-events: none;
}

/* Label hiding at low zoom (toggled by JS) */
.tl-labels-hidden .tl-node-label {
  display: none;
}

/* ============================================================
   Graph SVG — Edges
   ============================================================ */
.tl-edge {
  fill: none;
  stroke-width: 1.5;
  transition: opacity 0.3s;
}

.tl-edge--influenced {
  stroke: var(--color-text-secondary);
  stroke-opacity: 0.5;
}

.tl-edge--opposed {
  stroke: #ef4444;
  stroke-dasharray: 6 3;
  stroke-opacity: 0.6;
}

.tl-edge--catalyzed {
  stroke: #f59e0b;
  stroke-width: 3;
  stroke-opacity: 0.7;
}

.tl-edge--founded {
  stroke: var(--color-text-secondary);
  stroke-dasharray: 2 4;
  stroke-opacity: 0.4;
}

.tl-edge--authored {
  stroke: var(--color-text-secondary);
  stroke-width: 1;
  stroke-opacity: 0.3;
}

.tl-edge--contributed {
  stroke: var(--color-text-secondary);
  stroke-dasharray: 3 3;
  stroke-opacity: 0.3;
}

.tl-edge.is-dimmed {
  opacity: 0;
}

.tl-edge-arrow {
  fill: currentColor;
}

/* ============================================================
   Graph SVG — Era Labels
   ============================================================ */
.tl-era-label {
  font-size: 13px;
  font-family: var(--font-heading);
  opacity: 0.6;
  pointer-events: none;
}

/* ============================================================
   Tooltip
   ============================================================ */
.tl-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.8em;
  z-index: 10;
  max-width: 240px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  line-height: 1.4;
  font-family: var(--font-body);
  color: var(--color-text);
}

.tl-tooltip[hidden] {
  display: none;
}

.tl-tooltip-name {
  font-weight: bold;
  display: block;
  margin-bottom: 2px;
}

.tl-tooltip-meta {
  color: var(--color-text-secondary);
  font-size: 0.9em;
}

/* ============================================================
   Legend
   ============================================================ */
.tl-legend {
  position: absolute;
  bottom: 16px;
  left: 16px;
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  max-width: 220px;
  z-index: 5;
  overflow: hidden;
  transition: max-height 0.3s;
  font-family: var(--font-body);
  color: var(--color-text);
}

.tl-legend.is-collapsed .tl-legend-content {
  display: none;
}

.tl-legend-toggle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  cursor: pointer;
  font-size: 1em;
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: -36px;
  left: 0;
  color: var(--color-text-secondary);
  font-family: var(--font-body);
}

.tl-legend-toggle:hover {
  color: var(--color-text);
}

.tl-legend-content {
  padding: 12px;
  font-size: 0.8em;
}

.tl-legend-section {
  margin-bottom: 10px;
}

.tl-legend-section:last-child {
  margin-bottom: 0;
}

.tl-legend-section-title {
  font-weight: 600;
  font-size: 0.85em;
  margin-bottom: 4px;
  font-family: var(--font-heading);
  color: var(--color-text-secondary);
}

.tl-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
}

.tl-legend-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.tl-legend-swatch {
  width: 16px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* ============================================================
   First-Visit Overlay
   ============================================================ */
.tl-first-visit {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--color-bg-alt);
  border: 1px solid var(--color-accent);
  border-radius: 12px;
  padding: 16px 24px;
  z-index: 20;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  max-width: 360px;
  text-align: center;
  font-size: 0.9em;
  line-height: 1.5;
  font-family: var(--font-body);
  color: var(--color-text);
}

.tl-first-visit[hidden] {
  display: none;
}

.tl-first-visit h3 {
  font-family: var(--font-heading);
  font-size: 1.1em;
  margin: 0 0 8px 0;
}

.tl-first-visit p {
  margin: 0;
  line-height: 1.5;
  color: var(--color-text-secondary);
}

.tl-first-visit button {
  background: var(--color-accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 18px;
  font-size: 0.9em;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-body);
  margin-top: 12px;
}

.tl-first-visit button:hover {
  opacity: 0.85;
}

/* ============================================================
   Responsive — Tablet (<=1023px)
   ============================================================ */
@media (max-width: 1023px) {
  .tl-main {
    flex-direction: column;
  }

  .tl-card-panel {
    width: 100%;
    height: 40%;
    border-left: none;
    border-top: 1px solid var(--color-border);
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
  }

  .tl-card-panel[hidden] {
    transform: translateY(100%);
    width: 100%;
    height: 0;
    border: none;
  }

  .tl-card-panel.is-open {
    width: 100%;
    transform: translateY(0);
    border-left: none;
    border-top: 1px solid var(--color-border);
    z-index: 15;
  }

  .tl-legend {
    position: static;
    margin: 8px;
  }
}

/* ============================================================
   Responsive — Mobile (<=767px)
   ============================================================ */
@media (max-width: 767px) {
  .tl-filter-bar {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .tl-filter-bar::-webkit-scrollbar {
    display: none;
  }

  .tl-filter-pill {
    white-space: nowrap;
    flex-shrink: 0;
    min-height: 44px;
    min-width: 44px;
    justify-content: center;
  }

  .tl-search {
    min-width: 100px;
  }

  .tl-card-panel {
    height: 100%;
    width: 100%;
    top: 0;
    z-index: 30;
    position: fixed;
    border: none;
    border-radius: 0;
  }

  .tl-card-panel.is-open {
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 30;
    border: none;
    transform: translateX(0);
  }

  .tl-card-panel[hidden] {
    transform: translateX(100%);
    width: 0;
  }

  .tl-card-close {
    width: 44px;
    height: 44px;
  }

  .tl-legend-toggle {
    min-width: 44px;
    min-height: 44px;
  }

  /* Legend content as centered modal */
  .tl-legend-content {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 25;
    max-width: 280px;
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  }

  /* Search collapses to icon-only until focused */
  .tl-search {
    width: 36px;
    overflow: hidden;
    transition: width 0.2s;
    flex: none;
  }

  .tl-search:focus-within {
    width: 160px;
    flex: 1;
  }

  .tl-search-input {
    opacity: 0;
    transition: opacity 0.2s;
  }

  .tl-search:focus-within .tl-search-input {
    opacity: 1;
  }
}

/* ============================================================
   Responsive — Small Mobile (<=320px)
   ============================================================ */
@media (max-width: 320px) {
  /* Icon-only pills: hide text label */
  .tl-filter-pill .tl-pill-text {
    display: none;
  }

  .tl-filters-category .tl-filter-pill {
    padding: 4px 8px;
  }

  /* Era pills: hidden (managed by dropdown in JS) */
  .tl-filters-era {
    display: none;
  }

  /* Node labels hidden at default zoom (JS checks zoom level) */
  .tl-node-label {
    display: none;
  }

  /* Minimum touch target enforcement */
  .tl-filter-pill,
  .tl-card-close,
  .tl-legend-toggle,
  .tl-card-back,
  .tl-card-connection-link {
    min-height: 44px;
    min-width: 44px;
  }

  .tl-header {
    padding: 8px 12px;
    gap: 8px;
  }

  .tl-filter-bar {
    padding: 8px 12px;
  }
}

/* ============================================================
   Theme Adaptation Notes
   ============================================================
   All colors flow through CSS custom properties inherited from
   textbook.css. Light, dark, and reading themes adapt
   automatically via --color-bg, --color-bg-alt, --color-text,
   --color-border, --color-accent, --color-text-secondary.

   Era colors are set by JS as inline styles sourced from
   graph.json per-theme values.
   ============================================================ */
