/* ============================================
   Stepping — Event Emission Calculator
   Light Mode Design System (BOTEDA Style)
   ============================================ */

:root {
  /* Colors — Light Theme */
  --bg-primary: #f5f3ef;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f8f7f4;
  --bg-card: #ffffff;
  --bg-hover: #f0eee9;
  --bg-glass: rgba(255, 255, 255, 0.9);
  
  --border: #e5e2db;
  --border-light: #ece9e3;
  --border-glow: rgba(52, 211, 153, 0.3);
  
  --text-primary: #1a1a1a;
  --text-secondary: #5c5c5c;
  --text-muted: #8c8c8c;
  --text-accent: #16a34a;
  
  /* Node Type Colors */
  --node-input: #3b82f6;
  --node-input-bg: rgba(59, 130, 246, 0.08);
  --node-table: #8b5cf6;
  --node-table-bg: rgba(139, 92, 246, 0.08);
  --node-emission: #10b981;
  --node-emission-bg: rgba(16, 185, 129, 0.08);
  --node-mapper: #f59e0b;
  --node-mapper-bg: rgba(245, 158, 11, 0.08);
  --node-result: #ef4444;
  --node-result-bg: rgba(239, 68, 68, 0.08);
  
  /* Reduction Chain Node Colors */
  --node-rd-input: #0891b2;
  --node-rd-input-bg: rgba(8, 145, 178, 0.06);
  --node-rd-calc: #7c3aed;
  --node-rd-calc-bg: rgba(124, 58, 237, 0.06);
  --node-rd-result: #059669;
  --node-rd-result-bg: rgba(5, 150, 105, 0.06);
  
  /* Accent */
  --accent: #16a34a;
  --accent-hover: #15803d;
  --accent-glow: rgba(22, 163, 74, 0.15);
  
  /* Sizing */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.1);
  --shadow-glow: 0 0 20px var(--accent-glow);
  
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============ Top Bar ============ */
#top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  flex-shrink: 0;
}

.top-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-text {
  font-weight: 700;
  font-size: 16px;
  background: linear-gradient(135deg, #34d399, #06b6d4);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.divider {
  width: 1px;
  height: 24px;
  background: var(--border);
}

.project-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  outline: none;
  transition: var(--transition);
}

.project-name:hover, .project-name:focus {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.top-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.pipeline-steps {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

.step {
  padding: 4px 10px;
  border-radius: 12px;
  color: var(--text-muted);
  font-weight: 500;
  transition: var(--transition);
  cursor: pointer;
}

.step:hover { color: var(--text-secondary); }

.step.active {
  background: var(--accent-glow);
  color: var(--accent);
}

.step.completed {
  color: var(--accent);
}

.step-arrow {
  color: var(--text-muted);
  font-size: 10px;
}

.top-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ============ Buttons ============ */
.btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.btn-primary {
  background: linear-gradient(135deg, #059669, #0d9488);
  color: white;
  box-shadow: 0 2px 8px rgba(5, 150, 105, 0.3);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #047857, #0f766e);
  box-shadow: 0 4px 16px rgba(5, 150, 105, 0.4);
  transform: translateY(-1px);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-light);
}

.btn-sm {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.btn-sm:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ============ Main Canvas ============ */
#main-container {
  flex: 1;
  display: flex;
  position: relative;
  overflow: hidden;
}

#drawflow-canvas {
  flex: 1;
  min-width: 200px;
  height: 100%;
  background: 
    radial-gradient(circle at 50% 50%, rgba(52, 211, 153, 0.03) 0%, transparent 50%),
    linear-gradient(var(--bg-primary), var(--bg-primary));
  background-size: 100% 100%, 30px 30px;
}

/* Drawflow dot grid pattern */
#drawflow-canvas::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle, var(--border) 1px, transparent 1px);
  background-size: 30px 30px;
  pointer-events: none;
  opacity: 0.3;
}

/* ============ Resize Handle ============ */
.resize-handle {
  width: 6px;
  cursor: col-resize;
  background: var(--border);
  position: relative;
  z-index: 60;
  flex-shrink: 0;
  transition: background 0.15s;
}

.resize-handle:hover,
.resize-handle.dragging {
  background: var(--accent);
}

.resize-handle.hidden {
  display: none;
}

.resize-grip {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 4px;
  height: 32px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
}

.resize-grip::before,
.resize-grip::after {
  content: '';
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.15s;
}

.resize-handle:hover .resize-grip::before,
.resize-handle:hover .resize-grip::after,
.resize-handle.dragging .resize-grip::before,
.resize-handle.dragging .resize-grip::after {
  background: white;
}

/* ============ Drawflow Overrides ============ */
.drawflow .drawflow-node {
  border: none;
  background: transparent;
  padding: 0;
  width: auto;
  min-width: 260px;
}

.drawflow .drawflow-node.selected .node-body {
  box-shadow: 0 0 0 2px var(--accent), var(--shadow-glow);
}

.drawflow .drawflow-node .inputs,
.drawflow .drawflow-node .outputs {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}

.drawflow .drawflow-node .input,
.drawflow .drawflow-node .output {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border-light);
  background: var(--bg-secondary);
  transition: var(--transition);
}

.drawflow .drawflow-node .input:hover,
.drawflow .drawflow-node .output:hover {
  border-color: var(--accent);
  background: var(--accent-glow);
  box-shadow: 0 0 8px var(--accent-glow);
}

.drawflow .connection .main-path {
  stroke: var(--accent) !important;
  stroke-width: 2.5 !important;
  opacity: 0.6;
  stroke-dasharray: none;
}

.drawflow .connection .main-path:hover {
  opacity: 1;
}

/* Connection flow animation */
@keyframes flowAnimation {
  0% { stroke-dashoffset: 20; }
  100% { stroke-dashoffset: 0; }
}

.drawflow .connection.active .main-path {
  stroke-dasharray: 10, 5;
  animation: flowAnimation 1s linear infinite;
  opacity: 0.9;
}

/* ============ Node Bodies ============ */
.node-body {
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: var(--transition);
  box-shadow: var(--shadow-md);
}

.node-body:hover {
  border-color: var(--border-light);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.node-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 13px;
}

.node-icon {
  font-size: 16px;
}

.node-content {
  padding: 14px 16px;
  min-height: 80px;
}

.node-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
}

.node-status {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--text-muted);
  font-weight: 500;
}

.node-status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
}

.node-status.active::before { background: var(--accent); animation: pulse 2s infinite; }
.node-status.completed::before { background: var(--accent); }
.node-status.error::before { background: #ef4444; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Node type borders */
.node-type-input { border-left: 3px solid var(--node-input); }
.node-type-input .node-header { background: var(--node-input-bg); }

.node-type-table { border-left: 3px solid var(--node-table); }
.node-type-table .node-header { background: var(--node-table-bg); }

.node-type-emission { border-left: 3px solid var(--node-emission); }
.node-type-emission .node-header { background: var(--node-emission-bg); }

.node-type-mapper { border-left: 3px solid var(--node-mapper); }
.node-type-mapper .node-header { background: var(--node-mapper-bg); }

.node-type-result { border-left: 3px solid var(--node-result); }
.node-type-result .node-header { background: var(--node-result-bg); }

/* ============ Upload Zone ============ */
.upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 20px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
}

.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--node-input);
  background: var(--node-input-bg);
  color: var(--node-input);
}

.upload-zone p {
  font-size: 13px;
  font-weight: 600;
}

.upload-hint {
  font-size: 10px;
  opacity: 0.7;
}

.file-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  font-size: 12px;
}

.file-name {
  color: var(--text-primary);
  font-weight: 500;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-status {
  color: var(--accent);
  font-weight: 600;
  font-size: 11px;
}

/* ============ Mini Table ============ */
.mini-table {
  min-height: 60px;
}

.table-placeholder, .tag-placeholder, .mapper-placeholder, .result-placeholder {
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
  padding: 16px;
}

.item-count {
  text-align: center;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  margin-top: 6px;
}

.mini-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  margin-bottom: 3px;
}

.mini-row .item-name {
  flex: 1;
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-row .item-qty {
  color: var(--accent);
  font-weight: 600;
}

/* ============ Emission Tags ============ */
.emission-tags {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.emission-tag-row {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.emission-tag-name {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-primary);
  min-width: 60px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
}

.tag-upstream { background: rgba(59, 130, 246, 0.15); color: #60a5fa; }
.tag-core { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.tag-downstream { background: rgba(239, 68, 68, 0.15); color: #f87171; }

/* ============ Mapper Summary ============ */
.mapper-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  background: var(--bg-tertiary);
  margin-bottom: 3px;
}

.mapper-row .label { color: var(--text-secondary); }
.mapper-row .value { color: var(--accent); font-weight: 600; }

/* ============ Result Summary ============ */
.result-total {
  text-align: center;
  padding: 12px;
}

.result-total .total-value {
  font-size: 28px;
  font-weight: 800;
  background: linear-gradient(135deg, #34d399, #06b6d4);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.result-total .total-unit {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.result-breakdown {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.breakdown-item {
  flex: 1;
  text-align: center;
  padding: 6px;
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
}

.breakdown-item .bd-label {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
}

.breakdown-item .bd-value {
  font-size: 13px;
  font-weight: 700;
  margin-top: 2px;
}

.bd-upstream .bd-value { color: #60a5fa; }
.bd-core .bd-value { color: #fbbf24; }
.bd-downstream .bd-value { color: #f87171; }

/* ============ Side Panel ============ */
#side-panel {
  width: var(--panel-width, 520px);
  min-width: 320px;
  max-width: 70vw;
  height: 100%;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  z-index: 50;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  box-shadow: -4px 0 20px rgba(0,0,0,0.3);
}

#side-panel.hidden {
  display: none;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-header h2 {
  font-size: 15px;
  font-weight: 700;
}

/* Panel Tabs */
.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  padding: 0 12px;
  gap: 2px;
  background: var(--bg-tertiary);
}

.panel-tab {
  padding: 10px 16px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: var(--transition);
}

.panel-tab:hover {
  color: var(--text-secondary);
}

.panel-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Tab Panes */
.tab-pane {
  display: none;
  height: 100%;
}

.tab-pane.active {
  display: flex;
  flex-direction: column;
}

.panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

/* Panel scrollbar */
.panel-content::-webkit-scrollbar { width: 4px; }
.panel-content::-webkit-scrollbar-track { background: transparent; }
.panel-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* PDF Viewer */
.pdf-viewer-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
}

.pdf-viewer-frame {
  width: 100%;
  flex: 1;
  border: none;
  background: #1a1a2e;
  min-height: 400px;
}

.pdf-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 40px;
}

.pdf-placeholder p {
  font-size: 13px;
}

.pdf-placeholder.hidden {
  display: none;
}

/* Raw Data Tab */
#tab-raw-data, #tab-parsed-items {
  padding: 16px;
  overflow-y: auto;
}

.raw-section {
  margin-bottom: 20px;
}

.raw-section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.raw-section-title .badge {
  font-size: 9px;
}

.raw-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.raw-table th {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-weight: 600;
  padding: 6px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.raw-table td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  word-break: break-all;
}

.raw-table tr:hover td {
  background: var(--bg-hover);
}

.raw-text-block {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 11px;
  line-height: 1.6;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 300px;
  overflow-y: auto;
  font-family: 'SF Mono', 'Fira Code', monospace;
}

/* Parsed items comparison */
.compare-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  transition: var(--transition);
}

.compare-row:hover {
  border-color: var(--accent);
}

.compare-num {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-glow);
  color: var(--accent);
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
}

.compare-detail {
  flex: 1;
  font-size: 11px;
}

.compare-detail .compare-name {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 3px;
}

.compare-detail .compare-meta {
  color: var(--text-muted);
  font-size: 10px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.compare-detail .compare-meta span {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.compare-tag {
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 9px;
  font-weight: 700;
}

.compare-tag-auto {
  background: rgba(52, 211, 153, 0.12);
  color: var(--accent);
}

.compare-tag-manual {
  background: rgba(245, 158, 11, 0.12);
  color: #fbbf24;
}

/* ============ Modal ============ */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s;
}

#modal-overlay.hidden {
  display: none;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 90%;
  max-width: 900px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(20px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 16px;
  font-weight: 700;
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

/* ============ Data Table (in modal/panel) ============ */
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
}

.data-table thead th {
  position: sticky;
  top: 0;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-weight: 600;
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table thead th:first-child { border-radius: var(--radius-sm) 0 0 0; }
.data-table thead th:last-child { border-radius: 0 var(--radius-sm) 0 0; }

.data-table tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  vertical-align: middle;
}

.data-table tbody tr:hover td {
  background: var(--bg-hover);
}

.data-table tbody td input,
.data-table tbody td select {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 12px;
  padding: 4px 8px;
  outline: none;
  transition: var(--transition);
}

.data-table tbody td input:focus,
.data-table tbody td select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

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

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 700;
}

.badge-auto { background: rgba(52, 211, 153, 0.15); color: var(--accent); }
.badge-manual { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.badge-error { background: rgba(239, 68, 68, 0.15); color: #f87171; }

/* Loading spinner */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Section headers in panels */
.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 16px 0 8px 0;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.section-title:first-child { margin-top: 0; }

/* ============ Connection Labels (Card Style) ============ */
.connection-label {
  position: absolute;
  z-index: 10;
  transform: translate(-50%, 0);
  pointer-events: auto;
  cursor: default;
  width: 240px;
}

.conn-card {
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.conn-card:hover {
  border-color: var(--accent);
  border-left-color: var(--accent);
  box-shadow: 0 0 16px var(--accent-glow), var(--shadow-md);
  transform: translateY(-2px);
}

.conn-card-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(52, 211, 153, 0.05);
}

.conn-card-icon {
  font-size: 13px;
}

.conn-card-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.01em;
}

.conn-card-body {
  padding: 8px 12px;
  font-size: 10.5px;
  line-height: 1.65;
  color: var(--text-secondary);
  word-break: keep-all;
}

.conn-card-body strong {
  color: var(--text-primary);
  font-weight: 600;
}

.conn-card-body code {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 9.5px;
  color: var(--accent);
  background: rgba(52, 211, 153, 0.08);
  padding: 1px 5px;
  border-radius: 3px;
  white-space: nowrap;
}

.conn-example {
  display: block;
  margin-top: 4px;
  padding: 4px 8px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  font-size: 9.5px;
  color: var(--text-muted);
  font-style: italic;
}

/* ============ LLM Modal ============ */
#llm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

#llm-overlay.hidden { display: none; }

.llm-modal {
  width: 720px;
  max-height: 85vh;
}

.llm-section {
  margin-bottom: 16px;
}

.llm-section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.llm-settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.llm-settings-grid > .llm-field:first-child {
  grid-column: 1 / -1;
}

.llm-field label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.llm-field input,
.llm-field select {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 12px;
  transition: var(--transition);
}

.llm-field input:focus,
.llm-field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.llm-prompt {
  width: 100%;
  padding: 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 11.5px;
  line-height: 1.6;
  resize: vertical;
  transition: var(--transition);
}

.llm-prompt:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.llm-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.llm-cost-hint {
  font-size: 11px;
  color: var(--text-muted);
}

.llm-usage {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 400;
  background: var(--bg-tertiary);
  padding: 2px 8px;
  border-radius: 8px;
}

/* LLM Result cards */
.llm-result-item {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  font-size: 11px;
  transition: var(--transition);
}

.llm-result-item:hover {
  border-color: var(--accent);
}

.llm-result-num {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-glow);
  color: var(--accent);
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
}

.llm-result-detail {
  flex: 1;
}

.llm-result-name {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.llm-result-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.llm-result-tags .tag {
  font-size: 9px;
}

.llm-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ============================================
   Reduction Chain — 감축량 산정 체인
   ============================================ */

/* Chain Section Label */
.chain-label {
  position: absolute;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  user-select: none;
}

.chain-label .chain-icon {
  font-size: 16px;
}

.chain-label .chain-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 8px;
  background: rgba(5, 150, 105, 0.1);
  color: #059669;
}

/* Reduction Node Type Borders */
.node-type-rd-input { border-left: 3px solid var(--node-rd-input); }
.node-type-rd-input .node-header { background: var(--node-rd-input-bg); }

.node-type-rd-calc { border-left: 3px solid var(--node-rd-calc); }
.node-type-rd-calc .node-header { background: var(--node-rd-calc-bg); }

.node-type-rd-result { border-left: 3px solid var(--node-rd-result); }
.node-type-rd-result .node-header { background: var(--node-rd-result-bg); }

/* ============ kWh Slider Input ============ */
.rd-input-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rd-slider-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rd-slider-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
}

.rd-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--bg-tertiary) 0%, var(--bg-tertiary) 100%);
  outline: none;
  cursor: pointer;
}

.rd-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: linear-gradient(135deg, #06b6d4, #34d399);
  box-shadow: 0 0 8px rgba(6, 182, 212, 0.4);
  cursor: grab;
  transition: box-shadow 0.2s;
}

.rd-slider::-webkit-slider-thumb:hover {
  box-shadow: 0 0 10px rgba(8, 145, 178, 0.4);
}

.rd-slider::-webkit-slider-thumb:active {
  cursor: grabbing;
}

.rd-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #06b6d4, #34d399);
  box-shadow: 0 0 8px rgba(6, 182, 212, 0.4);
  cursor: grab;
}

.rd-value-display {
  text-align: center;
  font-size: 24px;
  font-weight: 800;
  background: linear-gradient(135deg, #0891b2, #059669);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.2;
}

.rd-value-unit {
  font-size: 12px;
  font-weight: 600;
  -webkit-text-fill-color: var(--text-muted);
}

.rd-number-input {
  display: flex;
  align-items: center;
  gap: 6px;
}

.rd-number-input input {
  width: 80px;
  padding: 6px 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  transition: var(--transition);
}

.rd-number-input input:focus {
  outline: none;
  border-color: var(--node-rd-input);
  box-shadow: 0 0 0 2px rgba(8, 145, 178, 0.2);
}

.rd-number-input span {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

/* ============ Comparison Cards (Diesel vs ESS) ============ */
.rd-comparison {
  display: flex;
  gap: 8px;
}

.rd-card {
  flex: 1;
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  text-align: center;
}

.rd-card-diesel {
  background: rgba(239, 68, 68, 0.05);
  border-color: rgba(239, 68, 68, 0.2);
}

.rd-card-ess {
  background: rgba(16, 185, 129, 0.05);
  border-color: rgba(16, 185, 129, 0.2);
}

.rd-card-icon {
  font-size: 18px;
  margin-bottom: 4px;
}

.rd-card-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
}

.rd-card-value {
  font-size: 16px;
  font-weight: 800;
  line-height: 1.2;
}

.rd-card-diesel .rd-card-value {
  color: #dc2626;
}

.rd-card-ess .rd-card-value {
  color: #059669;
}

.rd-card-sub {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
}

.rd-card-unit {
  font-size: 10px;
  font-weight: 500;
}

/* ============ Reduction Result ============ */
.rd-result-box {
  text-align: center;
  padding: 12px;
}

.rd-result-value {
  font-size: 28px;
  font-weight: 800;
  background: linear-gradient(135deg, #059669, #0891b2);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.rd-result-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
  font-weight: 500;
}

/* Progress Bar */
.rd-progress-wrap {
  margin-top: 12px;
}

.rd-progress-header {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  margin-bottom: 6px;
}

.rd-progress-header .label {
  color: var(--text-secondary);
  font-weight: 500;
}

.rd-progress-header .value {
  color: var(--accent);
  font-weight: 700;
}

.rd-progress-bar {
  width: 100%;
  height: 8px;
  border-radius: 4px;
  background: var(--bg-tertiary);
  overflow: hidden;
}

.rd-progress-fill {
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, #059669, #0891b2);
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 0 6px rgba(5, 150, 105, 0.3);
}

/* ============ Reduction Detail Modal ============ */
.rd-modal {
  max-width: 800px;
}

.rd-modal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.rd-param-section {
  padding: 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.rd-param-section.diesel-section {
  border-top: 3px solid #ef4444;
}

.rd-param-section.ess-section {
  border-top: 3px solid #10b981;
}

.rd-param-title {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.rd-param-title.diesel-title { color: #dc2626; }
.rd-param-title.ess-title { color: #059669; }

.rd-param-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid rgba(0,0,0,0.06);
  font-size: 12px;
}

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

.rd-param-row .param-label {
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
}

.rd-param-row .param-unit {
  font-size: 10px;
  color: var(--text-muted);
}

.rd-param-row input {
  width: 90px;
  padding: 4px 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 12px;
  text-align: right;
  transition: var(--transition);
}

.rd-param-row input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

/* Calculation Steps Table */
.rd-steps-section {
  margin-bottom: 20px;
}

.rd-steps-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 10px;
}

.rd-steps-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.rd-step-card {
  padding: 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.rd-step-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 11px;
  border-bottom: 1px solid rgba(0,0,0,0.05);
}

.rd-step-row:last-child { border-bottom: none; }
.rd-step-row .step-label { color: var(--text-secondary); }
.rd-step-row .step-value { color: var(--text-primary); font-weight: 600; }
.rd-step-row.step-result .step-value { font-weight: 800; font-size: 13px; }
.rd-step-row.step-result.diesel .step-value { color: #dc2626; }
.rd-step-row.step-result.ess .step-value { color: #059669; }

/* Summary banner */
.rd-summary-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 20px;
  background: linear-gradient(135deg, rgba(5, 150, 105, 0.06), rgba(8, 145, 178, 0.06));
  border: 1px solid rgba(5, 150, 105, 0.15);
  border-radius: var(--radius-md);
  margin-bottom: 20px;
}

.rd-summary-item {
  text-align: center;
}

.rd-summary-item .summary-value {
  font-size: 24px;
  font-weight: 800;
}

.rd-summary-item .summary-value.diesel-val { color: #dc2626; }
.rd-summary-item .summary-value.ess-val { color: #059669; }
.rd-summary-item .summary-value.reduction-val {
  background: linear-gradient(135deg, #059669, #0891b2);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.rd-summary-item .summary-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.rd-summary-arrow {
  font-size: 24px;
  color: var(--text-muted);
}

/* Chart area */
.rd-chart-section {
  margin-bottom: 16px;
}

.rd-chart-container {
  max-height: 220px;
  display: flex;
  justify-content: center;
}

/* Modal actions */
.rd-modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* Placeholder for empty reduction state */
.rd-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 16px;
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
}

/* Top bar reduction pipeline steps */
.pipeline-section {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pipeline-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 8px;
}

.step.rd-step.active {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
}

.step.rd-step.completed {
  color: #34d399;
}

/* Number animation */
@keyframes countUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.rd-animated {
  animation: countUp 0.4s ease-out;
}
