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

:root {
  --bg-primary: #06080f;
  --bg-secondary: #0c1020;
  --bg-card: rgba(15, 20, 40, 0.7);
  --bg-card-hover: rgba(20, 28, 55, 0.8);
  --border: rgba(255, 255, 255, 0.06);
  --border-focus: rgba(0, 210, 255, 0.4);
  --text-primary: #e8ecf4;
  --text-secondary: #8892a8;
  --text-muted: #4a5568;
  --accent: #00d2ff;
  --accent-glow: rgba(0, 210, 255, 0.15);
  --coral: #ff6b6b;
  --purple: #a29bfe;
  --gold: #ffd93d;
  --emerald: #6bcb77;
  --orange: #ff8c42;
  --pink: #fd79a8;
  --sidebar-width: 340px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
  --radius: 12px;
  --radius-sm: 8px;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── Landing ──────────────────────────────────────────────────────── */
.landing {
  position: relative;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.landing-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.grid-overlay {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(0,210,255,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,210,255,0.03) 1px, transparent 1px);
  background-size: 60px 60px;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 50%, black 20%, transparent 70%);
}

.glow-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.4;
  animation: orbFloat 12s ease-in-out infinite;
}
.glow-orb-1 { width: 500px; height: 500px; background: rgba(0,210,255,0.12); top: -10%; left: 20%; }
.glow-orb-2 { width: 400px; height: 400px; background: rgba(162,155,254,0.1); bottom: -5%; right: 15%; animation-delay: -4s; }
.glow-orb-3 { width: 350px; height: 350px; background: rgba(255,107,107,0.08); top: 40%; right: 30%; animation-delay: -8s; }

@keyframes orbFloat {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(30px, -20px) scale(1.05); }
  66% { transform: translate(-20px, 15px) scale(0.95); }
}

.landing-content {
  position: relative;
  z-index: 1;
  text-align: center;
  max-width: 720px;
  width: 100%;
  padding: 0 24px;
  animation: fadeInUp 0.8s ease-out;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}

.logo-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 6px 16px 6px 8px;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 24px;
  backdrop-filter: blur(20px);
}
.logo-icon { width: 28px; height: 28px; }

.hero-title {
  font-size: clamp(48px, 8vw, 80px);
  font-weight: 800;
  letter-spacing: -2px;
  line-height: 1;
  margin-bottom: 16px;
}

.title-gradient {
  background: linear-gradient(135deg, #00d2ff 0%, #a29bfe 50%, #ff6b6b 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-subtitle {
  font-size: 17px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 40px;
  font-weight: 300;
}

/* ── Input Container ──────────────────────────────────────────────── */
.input-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.3s, box-shadow 0.3s;
  backdrop-filter: blur(20px);
}
.input-container:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 4px var(--accent-glow), 0 8px 40px rgba(0,0,0,0.3);
}

#textInput {
  width: 100%;
  padding: 20px 20px 12px;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  resize: none;
  outline: none;
}
#textInput::placeholder { color: var(--text-muted); }

.input-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

.char-count {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--mono);
}

.btn-analyze {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 24px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: #fff;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: 100px;
  cursor: pointer;
  transition: all 0.3s;
  opacity: 0.5;
  pointer-events: none;
}
.btn-analyze:not(:disabled) {
  opacity: 1;
  pointer-events: all;
}
.btn-analyze:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(0,210,255,0.3);
}
.btn-analyze svg { width: 14px; height: 14px; }

/* ── Example Chips ────────────────────────────────────────────────── */
.examples-section {
  margin-top: 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.examples-label {
  font-size: 13px;
  color: var(--text-muted);
}
.example-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.chip {
  padding: 8px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 100px;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  backdrop-filter: blur(10px);
}
.chip:hover {
  border-color: var(--border-focus);
  color: var(--text-primary);
  background: var(--bg-card-hover);
}

/* ── Workspace Layout ─────────────────────────────────────────────── */
.workspace {
  display: flex;
  height: 100vh;
  background: var(--bg-primary);
}
.workspace.hidden { display: none; }

.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.08) transparent;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-secondary);
  z-index: 10;
}

.logo-small {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: opacity 0.2s;
}
.logo-small:hover { opacity: 0.7; }
.logo-small svg { width: 28px; height: 28px; }
.logo-text {
  font-size: 16px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.btn-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}
.btn-icon:hover { border-color: var(--border-focus); color: var(--text-primary); }
.btn-icon svg { width: 16px; height: 16px; }

.sidebar-section {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.section-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 8px;
  line-height: 1.4;
}

.section-subtitle {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.section-text {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 12px;
}

/* Stats */
.stats-row {
  display: flex;
  gap: 12px;
}
.stat {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  text-align: center;
}
.stat-num {
  display: block;
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  font-family: var(--mono);
}
.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Legend */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--bg-card);
  border-radius: 100px;
  font-size: 11px;
  color: var(--text-secondary);
}
.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

/* Node Detail */
.detail-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
}
.detail-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}
.detail-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 6px;
}
.detail-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 12px;
}
.detail-connections {
  margin-bottom: 12px;
}
.detail-conn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 12px;
  color: var(--text-secondary);
}
.detail-conn-arrow {
  color: var(--text-muted);
  font-family: var(--mono);
}

.detail-actions {
  display: flex;
  gap: 8px;
}
.btn-sm {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.2s;
}
.btn-sm svg { width: 13px; height: 13px; }

.btn-explore {
  background: var(--accent-glow);
  color: var(--accent);
  border-color: rgba(0,210,255,0.2);
}
.btn-explore:hover {
  background: rgba(0,210,255,0.25);
  border-color: var(--accent);
}

/* Ask Section */
.ask-container {
  display: flex;
  gap: 8px;
}
#askInput {
  flex: 1;
  padding: 8px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}
#askInput:focus { border-color: var(--border-focus); }
.btn-ask {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  border-color: transparent;
  color: #fff;
}
.btn-ask:hover { opacity: 0.9; }

.ask-answer {
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  display: none;
}
.ask-answer.visible {
  display: block;
  animation: fadeInUp 0.3s ease-out;
}

.btn-text {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 0;
  transition: color 0.2s;
}
.btn-text:hover { color: var(--text-secondary); }
.btn-text svg { width: 14px; height: 14px; }

/* ── Graph Area ───────────────────────────────────────────────────── */
.graph-main {
  flex: 1;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(ellipse at center, rgba(0,210,255,0.02) 0%, transparent 70%),
    var(--bg-primary);
}

.graph-container {
  width: 100%;
  height: 100%;
}

#graphSvg {
  width: 100%;
  height: 100%;
  cursor: grab;
}
#graphSvg:active { cursor: grabbing; }

/* Loading */
.loading-overlay {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(6,8,15,0.85);
  backdrop-filter: blur(8px);
  z-index: 20;
}
.loading-overlay.visible {
  display: flex;
}

.loading-spinner {
  position: relative;
  width: 60px;
  height: 60px;
  margin-bottom: 20px;
}
.spinner-ring {
  position: absolute;
  inset: 0;
  border: 2px solid transparent;
  border-radius: 50%;
  animation: spin 1.5s linear infinite;
}
.spinner-ring:nth-child(1) { border-top-color: var(--accent); }
.spinner-ring:nth-child(2) { inset: 6px; border-right-color: var(--purple); animation-duration: 2s; animation-direction: reverse; }
.spinner-ring:nth-child(3) { inset: 12px; border-bottom-color: var(--coral); animation-duration: 2.5s; }

@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
  font-size: 14px;
  color: var(--text-secondary);
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* Graph toolbar */
.graph-toolbar {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(20px);
  z-index: 10;
}
.toolbar-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}
.toolbar-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}
.toolbar-btn svg { width: 18px; height: 18px; }
.toolbar-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

/* ── Modal ────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-overlay.visible { display: flex; }

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 90%;
  max-width: 640px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  animation: fadeInUp 0.3s ease-out;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-close {
  width: 32px; height: 32px;
  font-size: 20px;
}
.modal-body {
  padding: 20px;
  overflow-y: auto;
}
.modal-body pre {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── D3 Graph Styles ──────────────────────────────────────────────── */
.graph-edge {
  stroke-opacity: 0.25;
  transition: stroke-opacity 0.3s;
}
.graph-edge.highlighted {
  stroke-opacity: 0.8;
}

.edge-label {
  font-family: var(--font);
  font-size: 10px;
  fill: var(--text-muted);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}
.edge-label.visible { opacity: 1; }

.graph-node {
  cursor: pointer;
}

.node-circle {
  transition: filter 0.3s, r 0.1s;
}
.node-circle.highlighted {
  filter: brightness(1.3);
}
.node-circle.dimmed {
  opacity: 0.2;
}

.node-label {
  font-family: var(--font);
  font-size: 11px;
  font-weight: 500;
  fill: var(--text-primary);
  text-anchor: middle;
  pointer-events: none;
  paint-order: stroke;
  stroke: var(--bg-primary);
  stroke-width: 3px;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.node-label.dimmed { opacity: 0.2; }

.graph-node.selected .node-circle {
  stroke-width: 3px;
  stroke: #fff;
}

/* ── Responsive ───────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    min-width: 100%;
    height: auto;
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .workspace { flex-direction: column; }
  .graph-main { min-height: 60vh; }
  .hero-title { font-size: 40px; }
  .example-chips { flex-direction: column; }
}
