/* ===== CSS Variables (dark theme matching original) ===== */
:root {
  --bg:             hsl(224, 71%, 4%);
  --card:           hsl(224, 71%, 8%);
  --fg:             hsl(210, 40%, 98%);
  --fg-dim:         hsl(213, 31%, 91%);
  --muted:          hsl(215.4, 16.3%, 46.9%);
  --muted-fg:       hsl(215.4, 16.3%, 56.9%);
  --border:         hsl(217.2, 32.6%, 17.5%);
  --accent:         hsl(216, 34%, 17%);
  --primary:        hsl(210, 40%, 98%);
  --primary-fg:     hsl(222.2, 84%, 4.9%);

  --node-imported:       hsl(173, 58%, 39%);
  --node-promoted:       hsl(43, 74%, 66%);
  --node-assembled:      hsl(12, 76%, 61%);
  --node-assembled-into: hsl(197, 37%, 24%);
  --node-duplicated:     hsl(215.4, 16.3%, 46.9%);
  --node-error:          hsl(0, 84%, 60%);

  --radius:  0.5rem;
  --font:    ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--fg-dim);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ===== Header ===== */
#header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: 0.75rem; }
.logo-icon {
  width: 1.5rem; height: 1.5rem;
  background: var(--primary);
  border-radius: 0.25rem;
  display: flex; align-items: center; justify-content: center;
}
.logo-dot {
  width: 0.75rem; height: 0.75rem;
  border: 2px solid var(--primary-fg);
  border-radius: 50%;
}
#header h1 { font-size: 1.15rem; font-weight: 600; color: var(--fg); }
.subtitle { font-size: 0.875rem; color: var(--muted-fg); }

/* ===== Filter Panel ===== */
#filter-panel {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  flex-shrink: 0;
}
.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

/* Search */
.search-wrapper {
  flex: 1;
  min-width: 16rem;
  position: relative;
}
.search-icon {
  position: absolute; left: 0.75rem; top: 50%;
  transform: translateY(-50%);
  width: 1rem; height: 1rem;
  color: var(--muted-fg);
  pointer-events: none;
}
#search-input {
  width: 100%;
  padding: 0.5rem 2.5rem 0.5rem 2.5rem;
  background: var(--accent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg);
  font-size: 0.875rem;
  outline: none;
}
#search-input::placeholder { color: var(--muted-fg); }
#search-input:focus { border-color: var(--node-imported); box-shadow: 0 0 0 2px hsl(173 58% 39% / 0.2); }
.search-clear {
  position: absolute; right: 0.75rem; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--muted-fg); cursor: pointer;
  width: 1rem; height: 1rem; padding: 0;
}
.search-clear svg { width: 100%; height: 100%; }
.search-clear:hover { color: var(--fg); }

/* Slider */
.slider-group {
  display: flex; align-items: center; gap: 0.75rem; min-width: 12rem;
}
.slider-group label { font-size: 0.875rem; color: var(--muted-fg); white-space: nowrap; }
.slider-group input[type="range"] {
  flex: 1;
  accent-color: var(--node-imported);
}
.slider-group span { font-size: 0.875rem; width: 3rem; text-align: right; color: var(--fg); }
.slider-group select {
  flex: 1;
  min-width: 12rem;
  background: var(--accent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg);
  font-size: 0.8rem;
  padding: 0.35rem 0.45rem;
  outline: none;
}
.slider-group select:focus {
  border-color: var(--node-imported);
  box-shadow: 0 0 0 2px hsl(173 58% 39% / 0.2);
}

.toggle-label {
  display: flex; align-items: center; gap: 0.35rem;
  font-size: 0.8rem; color: var(--muted-fg); cursor: pointer; white-space: nowrap;
}
.toggle-label input[type="checkbox"] { accent-color: var(--node-imported); cursor: pointer; }

/* Zoom indicator */
.zoom-indicator {
  background: linear-gradient(135deg, var(--node-imported) 0%, var(--node-assembled-into) 100%);
  color: white;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
}

/* Active Filters */
.active-filters {
  display: flex; flex-wrap: wrap; gap: 0.5rem;
  margin-top: 0.5rem;
}
.filter-pill {
  background: var(--accent);
  border: 1px solid var(--border);
  border-radius: 9999px;
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
  display: flex; align-items: center; gap: 0.375rem;
  color: var(--fg-dim);
  transition: background 0.2s;
}
.filter-pill:hover { background: hsl(215.4, 16.3%, 26.9%); }
.filter-pill button {
  background: none; border: none; color: var(--muted-fg); cursor: pointer;
  padding: 0; line-height: 1;
}
.filter-pill button:hover { color: var(--node-error); }
.filter-pill button svg { width: 0.75rem; height: 0.75rem; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--fg-dim);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s;
}
.btn:hover { background: hsl(215.4, 16.3%, 26.9%); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-icon { width: 1rem; height: 1rem; }
.btn-icon-only {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.25rem; height: 2.25rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--fg-dim);
  cursor: pointer;
  transition: background 0.15s;
}
.btn-icon-only:hover { background: hsl(215.4, 16.3%, 26.9%); }
.btn-icon-only:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-icon-only svg { width: 1rem; height: 1rem; }
.btn-secondary { background: var(--accent); }
.btn-primary { background: var(--node-imported); color: white; border-color: var(--node-imported); }
.btn-primary:hover { background: hsl(173, 58%, 34%); }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.75rem; }

.badge {
  background: var(--primary); color: var(--primary-fg);
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
}

/* ===== Canvas Wrapper & Scroll ===== */
#canvas-wrapper {
  flex: 1;
  min-height: 0;             /* allow flex shrinking */
  position: relative;
  overflow: hidden;           /* wrapper clips overlays */
}
#canvas-scroll {
  width: 100%;
  height: 100%;
  overflow: auto;             /* native browser scroll for panning */
  background: var(--bg);
}
#canvas-spacer {
  position: relative;
  /* width/height set by JS to full content dimensions → creates scrollbars */
}
#graph-canvas {
  position: sticky;           /* stays at viewport corner while content scrolls */
  top: 0;
  left: 0;
  display: block;
  cursor: grab;
  background: hsl(224, 71%, 4%); /* fallback matches drawBackground */
}
#graph-canvas:active { cursor: grabbing; }

/* Overlays */
.overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: hsl(224 71% 4% / 0.8);
  color: var(--muted-fg);
  font-size: 1rem;
  z-index: 5;
}
.empty-title { font-size: 1.125rem; margin-bottom: 0.5rem; }
.empty-sub  { font-size: 0.875rem; }

/* ===== Panels (legend, zoom, session nav) ===== */
.panel {
  position: absolute;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  z-index: 10;
}

/* Legend Bar (horizontal) */
.legend-bar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0.375rem 1.5rem;
  flex-shrink: 0;
}
.legend-bar-items {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}
.legend-bar-item {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.75rem;
  color: var(--fg-dim);
}
.legend-bar-item.dimmed { opacity: 0.5; }
.action-dot {
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.legend-bar-sep {
  width: 1px;
  height: 0.875rem;
  background: var(--border);
}

/* Zoom Controls */
.sort-controls {
  bottom: 1.5rem; right: 5rem;
  display: flex; flex-direction: column; gap: 0.35rem;
  padding: 0.4rem;
}
.zoom-controls {
  bottom: 1.5rem; right: 1.5rem;
  display: flex; flex-direction: column; gap: 0.5rem;
  padding: 0.5rem;
}

/* Session Navigation */
.session-nav {
  bottom: 1.5rem; left: 1.5rem;
  padding: 0.75rem;
}
.session-nav-label { font-size: 0.875rem; color: var(--muted-fg); margin-bottom: 0.5rem; }
.session-nav-controls {
  display: flex; align-items: center; gap: 0.5rem;
}
#session-indicator { font-size: 0.875rem; font-weight: 500; padding: 0 0.5rem; color: var(--fg); }

/* ===== Tooltip ===== */
.tooltip {
  position: fixed;
  z-index: 50;
  padding: 1rem;
  max-width: 20rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 15px -3px rgba(0,0,0,0.3);
  pointer-events: none;
  color: var(--fg-dim);
}
.tooltip-name { font-weight: 600; color: var(--fg); margin-bottom: 0.5rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tooltip-row  { display: flex; justify-content: space-between; font-size: 0.75rem; margin-bottom: 0.25rem; }
.tooltip-label { color: var(--muted-fg); }
.tooltip-value { text-align: right; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.action-badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: var(--radius);
  font-size: 0.75rem;
  font-weight: 500;
  color: white;
}
.tooltip-tags { margin-top: 0.5rem; padding-top: 0.5rem; border-top: 1px solid var(--border); }
.tooltip-tags-label { font-size: 0.75rem; color: var(--muted-fg); margin-bottom: 0.25rem; }
.tooltip-tags-list { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.tag-chip {
  background: var(--accent);
  border: 1px solid var(--border);
  padding: 0.125rem 0.375rem;
  border-radius: var(--radius);
  font-size: 0.675rem;
}

/* ===== Tags Panel (slide-out right) ===== */
.tags-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 20rem;
  background: var(--card);
  border-left: 1px solid var(--border);
  z-index: 40;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}
.tags-panel.open { transform: translateX(0); }
.tags-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}
.tags-panel-header h3 { font-size: 1rem; font-weight: 600; color: var(--fg); }
.tags-search {
  margin: 0.75rem 1rem;
  padding: 0.5rem 0.75rem;
  background: var(--accent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg);
  font-size: 0.875rem;
  outline: none;
}
.tags-search::placeholder { color: var(--muted-fg); }
.tags-search:focus { border-color: var(--node-imported); }
.tags-actions {
  display: flex; gap: 0.5rem;
  padding: 0 1rem 0.5rem;
}
.tags-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 1rem;
}
.tag-row {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.375rem 0;
  font-size: 0.875rem;
  cursor: pointer;
}
.tag-row:hover { color: var(--fg); }
.tag-row input[type="checkbox"] { accent-color: var(--node-imported); }
.tag-count { margin-left: auto; font-size: 0.75rem; color: var(--muted-fg); }
.tags-panel-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
}
#tags-selected-count { font-size: 0.875rem; color: var(--muted-fg); }

/* ===== Status Bar ===== */
#status-bar {
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 0.375rem 1.5rem;
  font-size: 0.875rem;
  color: var(--muted-fg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.status-left { display: flex; gap: 1rem; }
.status-right { display: flex; align-items: center; gap: 0.5rem; }
.status-dot {
  width: 0.5rem; height: 0.5rem;
  background: var(--node-imported);
  border-radius: 50%;
}

/* ===== Session Comics List ===== */
.session-list-overlay {
  position: fixed; inset: 0;
  background: hsl(224 71% 4% / 0.85);
  z-index: 55;
  display: flex; align-items: center; justify-content: center;
}
.session-list-window {
  position: relative;
  width: 44rem; max-width: 92vw; max-height: 85vh;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.session-list-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.session-list-header h3 {
  font-size: 1rem; font-weight: 600; color: var(--fg);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.session-list-body {
  flex: 1; overflow-y: auto; padding: 0;
}
.session-list-row {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.45rem 1rem;
  border-bottom: 1px solid hsl(217.2, 32.6%, 12%);
  font-size: 0.8rem; cursor: pointer;
  transition: background 0.1s;
}
.session-list-row:hover { background: hsl(217, 33%, 14%); }
.session-list-dot {
  width: 0.5rem; height: 0.5rem; border-radius: 50%; flex-shrink: 0;
}
.session-list-name {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--fg-dim);
}
.session-list-artist {
  flex: 0 0 auto; max-width: 10rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--muted-fg); font-size: 0.75rem;
}
.session-list-action {
  flex: 0 0 auto;
  padding: 0.1rem 0.4rem; border-radius: var(--radius);
  font-size: 0.7rem; font-weight: 500; color: white;
}
.session-list-pages {
  flex: 0 0 3rem; text-align: right;
  color: var(--muted-fg); font-size: 0.75rem;
}

/* ===== Comic Detail Modal ===== */
.detail-overlay {
  position: fixed; inset: 0;
  background: hsl(224 71% 4% / 0.85);
  z-index: 60;
  display: flex; align-items: center; justify-content: center;
}
.detail-window {
  position: relative;
  width: 92vw; height: 90vh;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.detail-close {
  position: absolute; top: 0.5rem; right: 0.75rem; z-index: 3;
  background: none; border: none; color: var(--muted-fg);
  font-size: 1.75rem; cursor: pointer; z-index: 2;
  line-height: 1; padding: 0.25rem;
}
.detail-close:hover { color: var(--fg); }
.detail-content {
  display: flex; flex: 1; min-height: 0; overflow: hidden;
}

/* Left: image viewer */
.detail-left {
  flex: 0 0 50%; display: flex; flex-direction: column;
  border-right: 1px solid var(--border); min-width: 0;
}
.detail-main-image {
  flex: 1; min-height: 0; display: flex;
  align-items: center; justify-content: center;
  padding: 1rem; position: relative;
  background: hsl(224, 71%, 3%);
}
.detail-main-image img {
  max-width: 100%; max-height: 100%;
  object-fit: contain; border-radius: 0.25rem;
}
.detail-img-counter {
  position: absolute; bottom: 0.75rem; right: 1rem;
  background: hsl(224 71% 4% / 0.8); color: var(--fg-dim);
  padding: 0.2rem 0.6rem; border-radius: var(--radius);
  font-size: 0.75rem;
}
.detail-thumbstrip {
  flex: 0 0 auto; max-height: 40%;
  display: flex; flex-wrap: wrap;
  align-content: flex-start;
  gap: 0.25rem; padding: 0.5rem;
  overflow-y: auto; overflow-x: hidden;
  background: hsl(224, 71%, 3%);
  border-top: 1px solid var(--border);
}
.detail-thumbstrip img {
  width: 60px; height: 80px; object-fit: cover;
  border-radius: 0.2rem; cursor: pointer;
  border: 2px solid transparent; opacity: 0.6;
  transition: opacity 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.detail-thumbstrip img:hover { opacity: 0.9; }
.detail-thumbstrip img.active { opacity: 1; border-color: var(--node-imported); }

/* Right: history + details */
.detail-right {
  flex: 1; display: flex; flex-direction: column;
  min-width: 0; overflow-y: auto; padding: 1.25rem;
}
.detail-header { margin-bottom: 1rem; }
.detail-header-top {
  display: flex; align-items: center; gap: 0.75rem;
  padding-right: 2.5rem;
}
.detail-title {
  flex: 1; min-width: 0;
  font-size: 1.25rem; font-weight: 600; color: var(--fg);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.detail-subtitle { font-size: 0.85rem; color: var(--muted-fg); margin-top: 0.2rem; }
.detail-history-chart {
  flex-shrink: 0; height: 10rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: hsl(224, 71%, 3%); margin-bottom: 1rem;
  position: relative;
}
.detail-history-chart canvas { width: 100%; height: 100%; }
.detail-info { font-size: 0.85rem; color: var(--fg-dim); }
.detail-info-section {
  margin-bottom: 1rem;
}
.detail-info-section h4 {
  font-size: 0.75rem; color: var(--muted-fg);
  text-transform: uppercase; letter-spacing: 0.05em;
  margin-bottom: 0.5rem; padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
}
.detail-info-row {
  display: flex; justify-content: space-between;
  padding: 0.2rem 0; font-size: 0.8rem;
}
.detail-info-label { color: var(--muted-fg); }
.detail-info-value { color: var(--fg-dim); text-align: right; max-width: 65%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail-history-list { list-style: none; padding: 0; }
.detail-history-item {
  display: flex; gap: 0.75rem; padding: 0.5rem 0;
  border-bottom: 1px solid hsl(217.2, 32.6%, 12%);
  font-size: 0.8rem;
}
.detail-history-dot {
  width: 0.5rem; height: 0.5rem; border-radius: 50%;
  flex-shrink: 0; margin-top: 0.35rem;
}
.detail-history-body { flex: 1; min-width: 0; }
.detail-history-action { font-weight: 500; color: var(--fg); }
.detail-history-time { font-size: 0.7rem; color: var(--muted-fg); }
.detail-history-note { font-size: 0.75rem; color: var(--muted-fg); margin-top: 0.15rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail-history-delta { font-size: 0.75rem; color: hsl(173, 58%, 50%); margin-top: 0.1rem; }
.detail-history-reversed { color: var(--node-error); font-size: 0.7rem; }
.detail-history-section {
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px solid hsl(217.2, 32.6%, 12%);
  max-height: 22rem;
  overflow-y: auto;
}
.detail-history-loading,
.detail-history-empty {
  font-size: 0.75rem;
  color: var(--muted-fg);
  padding: 0.4rem 0;
}

/* ===== Utility ===== */
.hidden { display: none !important; }
