/* Global Variables & Colors */
:root {
  --bg-primary: #0b0f17;
  --bg-secondary: #121824;
  --card-bg: rgba(18, 24, 38, 0.65);
  --card-border: rgba(255, 255, 255, 0.08);
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --accent-cyan: #06b6d4;
  --accent-cyan-hover: #0891b2;
  --accent-violet: #8b5cf6;
  --accent-violet-hover: #7c3aed;
  
  --traffic-low: #10b981;
  --traffic-med: #f59e0b;
  --traffic-high: #ef4444;
  
  --neon-shadow-cyan: rgba(6, 182, 212, 0.15);
  --neon-shadow-violet: rgba(139, 92, 246, 0.25);
  
  --font-sans: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

/* Reset & Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-primary);
  background-image: 
    radial-gradient(at 0% 0%, rgba(6, 182, 212, 0.07) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(139, 92, 246, 0.07) 0px, transparent 50%);
  color: var(--text-primary);
  font-family: var(--font-sans);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  line-height: 1.5;
}

.app-container {
  display: flex;
  flex-direction: column;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem;
  gap: 1.5rem;
  flex: 1;
}

/* Header & Live API Panel */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1.5rem;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(16px);
  padding: 1.25rem 2rem;
  border-radius: 1.25rem;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon {
  width: 2.25rem;
  height: 2.25rem;
  color: var(--accent-cyan);
}

.logo-area h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.logo-area .subtitle {
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--text-secondary);
}

.live-api-panel {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.search-container {
  position: relative;
  display: flex;
  align-items: center;
  border: 1px solid var(--card-border);
  background: rgba(15, 23, 42, 0.6);
  border-radius: 0.75rem;
  overflow: visible;
  width: 280px;
  transition: all 0.3s ease;
}

.search-container:focus-within {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 2px var(--neon-shadow-cyan);
}

.search-container input {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  padding: 0.625rem 1rem;
  width: 100%;
  outline: none;
}

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

.search-container button {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 0.625rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.search-container button:hover {
  color: var(--accent-cyan);
}

.search-icon {
  width: 1.1rem;
  height: 1.1rem;
}

.search-results-dropdown {
  position: absolute;
  top: 105%;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--card-border);
  border-radius: 0.75rem;
  max-height: 200px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

.search-result-item {
  padding: 0.625rem 1rem;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s ease;
}

.search-result-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--accent-cyan);
}

.city-badge {
  background: rgba(139, 92, 246, 0.15);
  border: 1px solid rgba(139, 92, 246, 0.3);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
  border-radius: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  box-shadow: 0 0 12px var(--neon-shadow-violet);
}

.badge-separator {
  color: rgba(139, 92, 246, 0.5);
}

.city-badge button {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.city-badge button:hover {
  color: var(--traffic-high);
}

/* Common Button Styles */
button.secondary-btn {
  background: transparent;
  border: 1px solid var(--card-border);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.625rem 1.25rem;
  border-radius: 0.75rem;
  cursor: pointer;
  transition: all 0.3s ease;
}

button.secondary-btn:hover {
  border-color: var(--text-secondary);
  color: var(--text-primary);
}

/* Main Workspace Layout */
.main-workspace {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1.5rem;
  flex: 1;
}

/* Graph Panel */
.graph-panel {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(16px);
  border-radius: 1.25rem;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 620px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.panel-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.instruction-text {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Canvas & Graph Nodes absolute layout */
.canvas-container {
  position: relative;
  width: 100%;
  flex: 1;
  background: rgba(10, 15, 30, 0.35);
  border-radius: 0.75rem;
  overflow: hidden;
}

.edges-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.edges-svg path {
  fill: none;
  stroke: #334155;
  stroke-width: 2;
  transition: stroke 0.3s ease, stroke-width 0.3s ease;
}

.edges-svg path.active {
  stroke: var(--accent-cyan);
  stroke-width: 3;
  filter: drop-shadow(0 0 2px var(--accent-cyan));
}

.nodes-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none; /* let SVG pointer events pass if any, but elements inside must restore it */
}

/* Graph Node Cards styles */
.node-card {
  position: absolute;
  width: 175px;
  background: rgba(17, 24, 39, 0.85);
  border: 1px solid var(--card-border);
  border-radius: 0.75rem;
  padding: 0.6rem 0.75rem;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  transform: translate(-50%, -50%);
  pointer-events: auto; /* enable click */
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
}

.node-card:hover {
  transform: translate(-50%, -55%) scale(1.03);
  border-color: var(--accent-cyan);
  box-shadow: 0 10px 20px -5px rgba(0, 0, 0, 0.6), 0 0 10px var(--neon-shadow-cyan);
}

.node-card.selected {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 12px var(--neon-shadow-cyan);
}

.node-card.has-evidence {
  border-color: var(--accent-violet);
  box-shadow: 0 0 15px var(--neon-shadow-violet);
}

.node-card h3 {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding-bottom: 0.2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.node-card .evidence-indicator {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-violet);
  box-shadow: 0 0 6px var(--accent-violet);
}

.node-states {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.state-row {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  cursor: pointer;
}

.state-label-bar {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  font-weight: 500;
}

.state-name {
  color: var(--text-primary);
  transition: color 0.2s ease;
}

.state-value {
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

.progress-container {
  width: 100%;
  height: 5px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent-cyan);
  border-radius: 2px;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1), background 0.4s ease;
}

.state-row:hover .state-name {
  color: var(--accent-cyan);
}

/* Node card states when evidence is locked */
.state-row.locked .state-name {
  color: var(--accent-violet);
  font-weight: 700;
}

.state-row.locked .progress-bar {
  background: var(--accent-violet);
}

/* Unique Positions for Nodes in aspect ratio 900x580 */
#node-D { left: 16.7%; top: 11%; }
#node-T { left: 50.0%; top: 11%; }
#node-W { left: 83.3%; top: 11%; }

#node-C { left: 11.1%; top: 38%; }
#node-BD { left: 35.6%; top: 38%; }
#node-A { left: 64.4%; top: 38%; }

#node-RC { left: 38.9%; top: 66%; }
#node-TC { left: 61.1%; top: 88%; }

/* Inspector Panels */
.inspector-panel {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(16px);
  border-radius: 1.25rem;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding-bottom: 0.6rem;
}

.card-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

.badge {
  font-size: 0.65rem;
  padding: 0.2rem 0.5rem;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  border-radius: 0.5rem;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 2rem 1rem;
  gap: 0.75rem;
  color: var(--text-muted);
}

.empty-state svg {
  width: 2.5rem;
  height: 2.5rem;
}

.empty-state p {
  font-size: 0.8rem;
}

/* CPT Inspector Styles */
.cpt-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow: hidden;
}

.cpt-meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.cpt-table-wrapper {
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--card-border);
  border-radius: 0.5rem;
}

.cpt-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
  text-align: left;
}

.cpt-table th, .cpt-table td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.cpt-table th {
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-secondary);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 10;
}

.cpt-table tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.cpt-input {
  width: 50px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--card-border);
  color: var(--text-primary);
  border-radius: 0.25rem;
  padding: 0.15rem 0.3rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-align: right;
  outline: none;
}

.cpt-input:focus {
  border-color: var(--accent-cyan);
}

.cpt-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.btn-primary {
  background: var(--accent-cyan);
  border: none;
  color: #000;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.4rem 0.8rem;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary:hover {
  background: var(--accent-cyan-hover);
}

.btn-danger {
  background: var(--traffic-high);
  border: none;
  color: #fff;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.4rem 0.8rem;
  border-radius: 0.5rem;
  cursor: pointer;
}

/* Summary Card Rows */
.prediction-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.prediction-row:last-child {
  border-bottom: none;
}

.prediction-row .label {
  color: var(--text-secondary);
}

.prediction-row .value {
  font-weight: 600;
}

.text-green { color: var(--traffic-low); }
.text-orange { color: var(--traffic-med); }
.text-red { color: var(--traffic-high); }

/* Bottom Educational Hub */
.educational-hub {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(16px);
  border-radius: 1.25rem;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.tabs-header {
  display: flex;
  border-bottom: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.02);
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 1rem 1.5rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.01);
}

.tab-btn.active {
  color: var(--accent-cyan);
  border-bottom-color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.04);
}

.tabs-content {
  padding: 1.5rem;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

/* Sandbox Styling */
.sandbox-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
}

.sandbox-instructions {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sandbox-instructions h3 {
  font-size: 1.1rem;
  font-weight: 600;
}

.sandbox-instructions p {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.sandbox-scenarios {
  display: flex;
  gap: 1rem;
  margin: 0.5rem 0;
}

.scenario-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--card-border);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  padding: 0.6rem 1rem;
  border-radius: 0.5rem;
  cursor: pointer;
  flex: 1;
  text-align: left;
  transition: all 0.3s ease;
}

.scenario-btn:hover:not(:disabled) {
  border-color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.05);
}

.scenario-btn.active {
  background: rgba(139, 92, 246, 0.15);
  border-color: var(--accent-violet);
  box-shadow: 0 0 8px var(--neon-shadow-violet);
}

.scenario-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.sandbox-tip {
  font-size: 0.75rem !important;
  border-left: 2px solid var(--accent-cyan);
  padding-left: 0.75rem;
}

.highlight {
  color: var(--accent-cyan);
}

.sandbox-console {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sandbox-console h4 {
  font-size: 0.8rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.console-output {
  background: #070a12;
  border: 1px solid var(--card-border);
  border-radius: 0.75rem;
  padding: 1rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-secondary);
  height: 150px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.console-line.system {
  color: var(--text-muted);
}

.console-line.query {
  color: var(--accent-cyan);
}

.console-line.result {
  color: #10b981;
}

/* Math Tab Styling */
.math-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
}

.math-formula-box h3, .math-live-calculation h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.math-formula-box p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.latex-equation {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--card-border);
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  overflow-x: auto;
  font-size: 0.75rem;
  text-align: center;
  margin-bottom: 1rem;
  color: var(--accent-cyan);
}

.live-calc-box {
  background: #070a12;
  border: 1px solid var(--card-border);
  border-radius: 0.75rem;
  padding: 1.25rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-secondary);
  min-height: 200px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.live-calc-box h4 {
  color: var(--text-primary);
  font-size: 0.8rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding-bottom: 0.25rem;
}

.live-calc-step {
  border-left: 2px solid var(--text-muted);
  padding-left: 0.75rem;
}

.live-calc-step.highlighted {
  border-left-color: var(--accent-violet);
}

.live-calc-formula {
  color: var(--accent-cyan);
  margin-top: 0.2rem;
}

/* Lessons Tab Styling */
.lessons-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.5rem;
}

.lesson-card {
  background: rgba(255, 255, 255, 0.015);
  border: 1px solid var(--card-border);
  border-radius: 0.75rem;
  padding: 1.25rem;
  position: relative;
  overflow: hidden;
  transition: border-color 0.3s ease;
}

.lesson-card:hover {
  border-color: var(--accent-cyan);
}

.lesson-num {
  font-size: 2.25rem;
  font-weight: 800;
  color: rgba(6, 182, 212, 0.08);
  position: absolute;
  top: -0.25rem;
  right: 0.5rem;
  user-select: none;
}

.lesson-card h4 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--accent-cyan);
}

.lesson-card p {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* Custom Scrollbar for sleek UI */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}
