/* CSS Variables for Theme Colors */
:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #e2e8f0;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --border-color: #e2e8f0;
  --accent-primary: #3b82f6;
  --accent-hover: #2563eb;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --shadow: rgba(0, 0, 0, 0.1);
  --shadow-hover: rgba(0, 0, 0, 0.15);
}

/* Dark Mode Variables */
body.dark {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --border-color: #334155;
  --accent-primary: #60a5fa;
  --accent-hover: #3b82f6;
  --success: #34d399;
  --danger: #f87171;
  --warning: #fbbf24;
  --shadow: rgba(0, 0, 0, 0.3);
  --shadow-hover: rgba(0, 0, 0, 0.4);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  transition: background-color 0.3s ease, color 0.3s ease;
  overflow-x: hidden;
}

/* Top Bar */
.top-bar {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 0 2rem;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 1px 3px var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-size: 1.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-primary), #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 0.5px;
}

.top-controls {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.github-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  transition: all 0.2s ease;
  border: 1px solid var(--border-color);
}

.github-link:hover {
  color: var(--accent-primary);
  background: var(--bg-tertiary);
  transform: translateY(-1px);
}

/* Theme Toggle Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--border-color);
  transition: 0.3s;
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
  box-shadow: 0 1px 3px var(--shadow);
}

input:checked+.slider {
  background-color: var(--accent-primary);
}

input:checked+.slider:before {
  transform: translateX(26px);
}

/* Main Container */
.main-container {
  display: flex;
  height: calc(100vh - 60px);
  gap: 1px;
  background: var(--border-color);
}

/* Left Panel */
.left-panel {
  width: 300px;
  background: var(--bg-secondary);
  padding: 2rem;
  overflow-y: auto;
  border-right: 1px solid var(--border-color);
}

.left-panel label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.9rem;
}

.left-panel select,
.left-panel input {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
  transition: all 0.2s ease;
}

.left-panel select:focus,
.left-panel input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Buttons */
button {
  background: var(--accent-primary);
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 0.5rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.9rem;
  box-shadow: 0 2px 4px var(--shadow);
}

button:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px var(--shadow-hover);
}

button:active {
  transform: translateY(0);
}

#compute-btn {
  width: 100%;
  margin-bottom: 2rem;
  background: linear-gradient(135deg, var(--accent-primary), #8b5cf6);
}

/* Output Box */
.output-box {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 1.5rem;
  min-height: 200px;
  font-family: 'Fira Code', 'Monaco', monospace;
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text-secondary);
  white-space: pre-wrap;
  overflow-y: auto;
}

/* Right Panel */
.right-panel {
  flex: 1;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  padding: 2rem;
}

/* Graph Controls */
.graph-controls {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.graph-controls button {
  padding: 0.6rem 1.2rem;
  font-size: 0.85rem;
}

#clear-graph {
  background: var(--danger);
}

#clear-graph:hover {
  background: #dc2626;
}

#info-btn {
  background: var(--warning);
}

#info-btn:hover {
  background: #d97706;
}

/* Graph Area */
.graph-area {
  flex: 1;
  background: var(--bg-primary);
  border: 2px solid var(--border-color);
  border-radius: 0.75rem;
  margin-bottom: 1.5rem;
  overflow: hidden;
  box-shadow: inset 0 2px 4px var(--shadow);
  position: relative;
}

.graph-area svg {
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

/* SVG Styles */
.vertex {
  stroke: var(--bg-primary);
  stroke-width: 3px;
  cursor: pointer;
}

.vertex:hover {
  stroke-width: 2px;
  stroke: var(--text-primary);
  filter: brightness(1.1);
  transition: stroke-width 0.1s ease, filter 0.1s ease;
}

.edge {
  stroke: var(--text-primary);
  stroke-width: 2px;
  cursor: pointer;
}

.edge:hover {
  stroke: var(--accent-primary);
  stroke-width: 3px;
  transition: stroke 0.1s ease, stroke-width 0.1s ease;
}

.edge-weight {
  font-family: 'Fira Code', 'Monaco', monospace;
  font-size: 14px;
  font-weight: bold;
  fill: var(--accent-primary);
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  user-select: none;
}

.edge-weight-bg {
  fill: var(--bg-primary);
  stroke: var(--border-color);
  stroke-width: 1px;
  pointer-events: none;
}

.dragLine {
  stroke: var(--accent-primary);
  stroke-width: 2px;
  stroke-dasharray: 5, 5;
  opacity: 0.7;
}

.dragLine.hidden {
  display: none;
}

/* Vertex Info */
.svg-info {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 1.5rem;
  min-height: 120px;
  font-family: 'Fira Code', 'Monaco', monospace;
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text-secondary);
  overflow-y: auto;
}

.theme-toggle-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.mode-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  transition: all 0.3s ease;
}

.mode-icon {
  font-size: 1rem;
  transition: all 0.3s ease;
}

.source-selector {
  margin-bottom: 1.5rem;
}

.weight-selector {
  margin-bottom: 1.5rem;
}

#source-select,
#edge-weight {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.9rem;
  transition: all 0.2s ease;
}

#source-select:focus,
#edge-weight:focus {
  outline: none;
  border-color: var(--success);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

#source-select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: var(--bg-tertiary);
}

.vertex.source-node {
  stroke: var(--success);
  stroke-width: 4px;
}

/* Weight input styling */
#edge-weight {
  text-align: center;
  font-weight: 600;
}

.weight-info {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
  text-align: center;
}

/* Responsive Design */
@media (max-width: 1024px) {
  .main-container {
    flex-direction: column;
  }

  .left-panel {
    width: 100%;
    padding: 1.5rem;
  }

  .right-panel {
    padding: 1.5rem;
  }

  .graph-area {
    height: 400px;
  }
}

@media (max-width: 768px) {
  .top-bar {
    padding: 0 1rem;
  }

  .top-controls {
    gap: 1rem;
  }

  .left-panel,
  .right-panel {
    padding: 1rem;
  }

  .graph-controls {
    flex-direction: column;
  }

  .graph-controls button {
    width: 100%;
  }
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.output-box,
.svg-info {
  animation: fadeIn 0.3s ease;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: var(--text-secondary);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent-primary);
}

/* Focus States */
button:focus,
select:focus,
input:focus {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

/* Enhanced Graph Area with Grid Pattern */
.graph-area::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image:
    radial-gradient(circle, var(--border-color) 1px, transparent 1px);
  background-size: 20px 20px;
  opacity: 0.3;
  pointer-events: none;
}