/* ============================================================
   SAVE Act Graph Explorer — Styles
   Art direction: Technical / developer / data
   Dark-first, analytical, evidence-focused
   ============================================================ */

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

:root {
  --font-body: 'General Sans', 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', 'Menlo', monospace;

  /* Type scale */
  --text-xs:   clamp(0.6875rem, 0.65rem + 0.2vw, 0.75rem);
  --text-sm:   clamp(0.75rem, 0.72rem + 0.15vw, 0.8125rem);
  --text-base: clamp(0.8125rem, 0.78rem + 0.17vw, 0.875rem);
  --text-lg:   clamp(0.9375rem, 0.88rem + 0.28vw, 1.0625rem);
  --text-xl:   clamp(1.125rem, 1rem + 0.5vw, 1.375rem);

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --transition: 150ms ease;
}

/* ---- Color Themes ---- */
:root, [data-theme="light"] {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #f9f8f6;
  --border: #d8d5cf;
  --border-subtle: #e8e6e1;
  --text: #1a1917;
  --text-muted: #6b6965;
  --text-faint: #a5a29d;
  --accent: #0d5e63;
  --accent-hover: #094549;
  --accent-surface: #e0efef;

  /* Node type colors */
  --node-person: #2563eb;
  --node-organization: #7c3aed;
  --node-bill: #0891b2;
  --node-claim: #d97706;
  --node-poll: #059669;
  --node-factcheck: #dc2626;
  --node-study: #4f46e5;
  --node-vote: #be185d;

  --pro: #b45309;
  --con: #1d4ed8;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
}

[data-theme="dark"] {
  --bg: #0f0f0e;
  --surface: #1a1918;
  --surface-2: #222120;
  --border: #333230;
  --border-subtle: #2a2928;
  --text: #d4d2cd;
  --text-muted: #8a8884;
  --text-faint: #5a5856;
  --accent: #4db8be;
  --accent-hover: #6dd0d5;
  --accent-surface: #1a2e2f;

  --node-person: #60a5fa;
  --node-organization: #a78bfa;
  --node-bill: #22d3ee;
  --node-claim: #fbbf24;
  --node-poll: #34d399;
  --node-factcheck: #f87171;
  --node-study: #818cf8;
  --node-vote: #f472b6;

  --pro: #f59e0b;
  --con: #60a5fa;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #f5f4f0;
    --surface: #ffffff;
    --surface-2: #f9f8f6;
    --border: #d8d5cf;
    --border-subtle: #e8e6e1;
    --text: #1a1917;
    --text-muted: #6b6965;
    --text-faint: #a5a29d;
    --accent: #0d5e63;
    --accent-hover: #094549;
    --accent-surface: #e0efef;
    --node-person: #2563eb;
    --node-organization: #7c3aed;
    --node-bill: #0891b2;
    --node-claim: #d97706;
    --node-poll: #059669;
    --node-factcheck: #dc2626;
    --node-study: #4f46e5;
    --node-vote: #be185d;
    --pro: #b45309;
    --con: #1d4ed8;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  }
}

/* ---- Base ---- */
html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* ---- Header ---- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-4);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
  height: 48px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.logo { color: var(--accent); }

.header-title h1 {
  font-size: var(--text-lg);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.header-subtitle {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.stats-bar {
  display: flex;
  gap: var(--space-4);
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.stats-bar .stat-num {
  color: var(--accent);
  font-weight: 600;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  background: none;
  border: none;
  transition: background var(--transition), color var(--transition);
}
.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

/* ---- Main Layout ---- */
.main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ---- Sidebar ---- */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.sidebar-section { }

.sidebar-heading {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-2);
  font-family: var(--font-mono);
}

.search-input {
  width: 100%;
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-sm);
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
  font-family: var(--font-body);
  transition: border-color var(--transition);
}
.search-input:focus {
  border-color: var(--accent);
}
.search-input::placeholder {
  color: var(--text-faint);
}

.search-results {
  max-height: 180px;
  overflow-y: auto;
  margin-top: var(--space-1);
}

.search-result-item {
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-xs);
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  transition: background var(--transition);
}
.search-result-item:hover {
  background: var(--accent-surface);
}
.search-result-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.search-result-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Filter items */
.filter-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.filter-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 2px 0;
  cursor: pointer;
  font-size: var(--text-xs);
}
.filter-item input[type="checkbox"] {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  cursor: pointer;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.filter-chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.filter-chip .count {
  color: var(--text-faint);
  font-family: var(--font-mono);
  margin-left: 4px;
}

.filter-chip--pro { color: var(--pro); }
.filter-chip--con { color: var(--con); }

/* Controls */
.controls-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.ctrl-btn {
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-xs);
  font-family: var(--font-body);
  font-weight: 500;
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  text-align: center;
}
.ctrl-btn:hover {
  background: var(--accent-surface);
  border-color: var(--accent);
}
.ctrl-btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.ctrl-btn.primary:hover {
  background: var(--accent-hover);
}

/* ---- Graph Container ---- */
.graph-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

#graph-svg {
  width: 100%;
  height: 100%;
  cursor: grab;
}
#graph-svg:active {
  cursor: grabbing;
}

/* Graph elements */
.node-circle {
  cursor: pointer;
  transition: opacity 100ms ease;
}
.node-circle:hover {
  filter: brightness(1.2);
}

.node-label {
  pointer-events: none;
  fill: var(--text);
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 500;
  text-anchor: middle;
  dominant-baseline: central;
  user-select: none;
}

.edge-line {
  stroke-opacity: 0.25;
  transition: stroke-opacity 100ms ease;
}
.edge-line:hover {
  stroke-opacity: 0.7;
  cursor: pointer;
}

.edge-label {
  font-family: var(--font-mono);
  font-size: 8px;
  fill: var(--text-faint);
  pointer-events: none;
  user-select: none;
}

/* Zoom controls */
.zoom-controls {
  position: absolute;
  bottom: var(--space-4);
  right: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.zoom-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
}
.zoom-btn:hover {
  background: var(--accent-surface);
}

/* Tooltip */
.graph-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  max-width: 280px;
  display: none;
  line-height: 1.4;
}
.tooltip-type {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 2px;
}
.tooltip-label {
  font-weight: 600;
  font-size: var(--text-sm);
}
.tooltip-meta {
  color: var(--text-muted);
  margin-top: 2px;
}

/* ---- Detail Panel ---- */
.detail-panel {
  width: 340px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: var(--space-4);
}

.detail-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: var(--space-3);
  color: var(--text-faint);
  text-align: center;
  font-size: var(--text-sm);
}

.detail-content { }

.detail-header {
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
}

.detail-type-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 6px;
  border-radius: 3px;
  font-weight: 600;
  margin-bottom: var(--space-1);
}

.detail-label {
  font-size: var(--text-xl);
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: var(--space-1);
}

.detail-meta {
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1.5;
}

.detail-body {
  margin-bottom: var(--space-4);
}

.detail-section {
  margin-bottom: var(--space-3);
}

.detail-section-title {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-1);
  font-family: var(--font-mono);
}

.detail-text {
  font-size: var(--text-sm);
  line-height: 1.6;
  color: var(--text);
}

.detail-quote {
  font-size: var(--text-xs);
  font-style: italic;
  color: var(--text-muted);
  border-left: 2px solid var(--accent);
  padding-left: var(--space-2);
  margin: var(--space-1) 0;
}

.rating-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: var(--text-xs);
  font-weight: 600;
  font-family: var(--font-mono);
}
.rating-badge.true { background: #16a34a20; color: #16a34a; }
.rating-badge.mostly-true { background: #65a30d20; color: #65a30d; }
.rating-badge.half-true { background: #ca8a0420; color: #ca8a04; }
.rating-badge.misleading { background: #ea580c20; color: #ea580c; }
.rating-badge.mostly-false { background: #dc262620; color: #dc2626; }
.rating-badge.false { background: #dc262620; color: #dc2626; }
.rating-badge.contested { background: #8b5cf620; color: #8b5cf6; }

.direction-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: var(--text-xs);
  font-weight: 600;
  font-family: var(--font-mono);
}
.direction-badge.pro { background: color-mix(in srgb, var(--pro) 15%, transparent); color: var(--pro); }
.direction-badge.con { background: color-mix(in srgb, var(--con) 15%, transparent); color: var(--con); }

/* Citations */
.detail-citations {
  margin-bottom: var(--space-4);
}

.citation-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.citation-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  font-size: var(--text-xs);
  padding: var(--space-1) 0;
}

.citation-icon {
  flex-shrink: 0;
  color: var(--text-faint);
  margin-top: 1px;
}

.citation-item a {
  color: var(--accent);
  word-break: break-all;
  line-height: 1.4;
}

/* Connected edges list */
.detail-edges { }

.edge-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.edge-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  font-size: var(--text-xs);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  line-height: 1.4;
}
.edge-item:hover {
  background: var(--accent-surface);
}

.edge-type-label {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-faint);
  text-transform: uppercase;
  white-space: nowrap;
  min-width: 70px;
}

.edge-target-label {
  color: var(--text);
  font-weight: 500;
}

.edge-citation-link {
  margin-left: auto;
  flex-shrink: 0;
  color: var(--accent);
  font-size: 10px;
}

/* ---- Cypher Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: min(90vw, 720px);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}
.modal-header h2 {
  font-size: var(--text-lg);
  font-weight: 600;
}
.modal-close {
  font-size: 20px;
  width: 28px;
  height: 28px;
}

.modal-body {
  padding: var(--space-4);
  overflow-y: auto;
}

.modal-desc {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-3);
  line-height: 1.5;
}
.modal-desc code {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  background: var(--surface-2);
  padding: 1px 4px;
  border-radius: 3px;
}

.cypher-textarea {
  width: 100%;
  height: 300px;
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  resize: vertical;
  line-height: 1.5;
}

/* ---- Footer ---- */
.app-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-1) var(--space-4);
  font-size: var(--text-xs);
  color: var(--text-faint);
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  height: 28px;
}

/* ---- Highlighted/selected state ---- */
.node-highlighted .node-circle {
  stroke: var(--accent);
  stroke-width: 3;
}
.node-dimmed {
  opacity: 0.15;
}
.edge-dimmed {
  opacity: 0.05 !important;
}
.edge-highlighted {
  stroke-opacity: 0.8 !important;
  stroke-width: 2.5 !important;
}

/* ---- Responsive: collapse panels on small screens ---- */
@media (max-width: 1024px) {
  .sidebar { width: 200px; }
  .detail-panel { width: 280px; }
}

@media (max-width: 768px) {
  .main-layout { flex-direction: column; }
  .sidebar { 
    width: 100%; 
    max-height: 120px; 
    flex-direction: row; 
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .detail-panel {
    width: 100%;
    max-height: 40vh;
    border-left: none;
    border-top: 1px solid var(--border);
  }
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }
