/* ── Analysis Views ────────────────────────────────────────────────
   Styles for the call graph, compare viewer, and complexity heatmap.
   ────────────────────────────────────────────────────────────────── */

/* ── Analysis Layout Container ────────────────────────────────── */
.analysis-layout {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto auto 1fr;
  gap: var(--sp-4);
  padding: var(--sp-4);
  height: calc(100vh - 56px - 32px);
}

/* ── Analysis Grid Layout ─────────────────────────────────────── */
.analysis-grid {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: var(--sp-4);
  min-height: 0;
}

@media (max-width: 1200px) {
  .analysis-grid { grid-template-columns: 1fr; }
}

.analysis-grid--full {
  grid-template-columns: 1fr;
}

/* ── Call Graph SVG ───────────────────────────────────────────── */
.call-graph {
  position: relative;
  min-height: 400px;
}

.call-graph__svg-wrap {
  width: 100%;
  height: calc(100% - 48px);
  overflow-x: auto;
  overflow-y: auto;
  min-width: 0;
}

.call-graph__svg-wrap svg {
  width: 100%;
  min-height: 350px;
}

.call-graph__controls {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  align-items: center;
  flex-wrap: wrap;
}

/* Graph node styling */
.cg-node {
  cursor: pointer;
  transition: opacity 0.2s;
}

.cg-node:hover {
  opacity: 0.85;
}

.cg-node__rect {
  rx: 6;
  ry: 6;
  stroke-width: 1.5;
}

.cg-node__label {
  font-family: var(--font-mono);
  font-size: 11px;
  fill: var(--text-primary);
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

.cg-node__score {
  font-family: var(--font-mono);
  font-size: 9px;
  fill: var(--text-muted);
  text-anchor: middle;
  pointer-events: none;
}

/* Edge styling by type */
.cg-edge {
  fill: none;
  stroke-width: 1.5;
}

.cg-edge--PERFORM {
  stroke: var(--success);
  stroke-dasharray: none;
}

.cg-edge--GOTO {
  stroke: var(--danger);
  stroke-dasharray: 6 3;
}

.cg-edge--ALTER {
  stroke: #f59e0b;
  stroke-dasharray: 3 3;
  stroke-width: 2;
}

.cg-edge--PERFORM_THRU {
  stroke: var(--info);
  stroke-dasharray: 8 4;
}

.cg-edge--FALL_THROUGH {
  stroke: var(--text-muted);
  stroke-dasharray: 2 4;
  stroke-width: 1;
}

/* Edge arrowheads */
.cg-arrow--PERFORM { fill: var(--success); }
.cg-arrow--GOTO { fill: var(--danger); }
.cg-arrow--ALTER { fill: #f59e0b; }
.cg-arrow--PERFORM_THRU { fill: var(--info); }
.cg-arrow--FALL_THROUGH { fill: var(--text-muted); }

/* Graph legend */
.cg-legend {
  display: flex;
  gap: var(--sp-4);
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--text-xs);
  color: var(--text-muted);
  flex-wrap: wrap;
}

.cg-legend__item {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid transparent;
  transition: opacity var(--transition-fast), border-color var(--transition-fast);
  user-select: none;
}

.cg-legend__item:hover {
  border-color: rgba(255, 255, 255, 0.15);
}

.cg-legend__item--off {
  opacity: 0.3;
}

.cg-legend__line {
  width: 20px;
  height: 2px;
  display: inline-block;
}

/* ── Compare Viewer ──────────────────────────────────────────── */
.compare-viewer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  height: 100%;
  background: var(--glass-border);
  border-radius: 8px;
  overflow: hidden;
}

.compare-pane {
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  min-height: 0;
}

.compare-pane__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--sp-2) var(--sp-3);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--glass-border);
  font-size: var(--text-sm);
  font-weight: 600;
}

.compare-pane__stats {
  display: flex;
  gap: var(--sp-3);
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-weight: 400;
}

.compare-pane__source {
  flex: 1;
  overflow: auto;
  padding: var(--sp-2) 0;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.5;
}

/* ── Complexity Heatmap ──────────────────────────────────────── */
.complexity-line {
  display: block;
  padding: 0 var(--sp-3);
  min-height: 1.5em;
  white-space: pre;
  transition: background-color 0.3s;
}

.complexity-line--clean {
  background: transparent;
}

.complexity-line--low {
  background: rgba(34, 197, 94, 0.08);
}

.complexity-line--medium {
  background: rgba(245, 158, 11, 0.12);
}

.complexity-line--high {
  background: rgba(239, 68, 68, 0.15);
}

.complexity-line--dead {
  background: rgba(100, 116, 139, 0.12);
  opacity: 0.6;
}

/* Paragraph score badge (inline) */
.complexity-score {
  display: inline-block;
  font-size: 9px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: var(--sp-2);
  vertical-align: middle;
}

.complexity-score--clean {
  background: rgba(34, 197, 94, 0.2);
  color: var(--success);
}

.complexity-score--moderate {
  background: rgba(245, 158, 11, 0.2);
  color: var(--warning);
}

.complexity-score--spaghetti {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
}

/* ── Analysis Summary Card ───────────────────────────────────── */
.analysis-summary {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
}

/* ── Analysis Select ─────────────────────────────────────────── */
.analysis-select {
  font-family: var(--font-mono);
  color: var(--text-primary);
}

.analysis-stat {
  text-align: center;
}

.analysis-stat__value {
  font-size: 1.5rem;
  font-weight: 700;
  font-family: var(--font-mono);
}

.analysis-stat__value--clean { color: var(--success); }
.analysis-stat__value--moderate { color: var(--warning); }
.analysis-stat__value--spaghetti { color: var(--danger); }

.analysis-stat__label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Execution Trace Card ────────────────────────────────────── */
#analysisDetailsCard {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

#execPathContainer {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-3);
}

/* ── Execution Path ──────────────────────────────────────────── */
.exec-path {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1);
  padding: var(--sp-3);
  align-items: center;
}

.exec-path__step {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 2px var(--sp-2);
  background: var(--bg-elevated);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  border: 1px solid var(--glass-border);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.exec-path__step:hover {
  border-color: rgba(59, 130, 246, 0.3);
  background: rgba(59, 130, 246, 0.1);
}

.exec-path__step--active {
  border-color: var(--text-accent);
  background: rgba(59, 130, 246, 0.15);
  color: var(--text-accent);
  font-weight: 600;
}

/* Loading indicator for auto-trace */
.exec-path__loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-style: italic;
}

.exec-path__arrow {
  color: var(--text-muted);
  font-size: 10px;
}

.exec-path__arrow--GOTO { color: var(--danger); }
.exec-path__arrow--ALTER { color: #f59e0b; }
.exec-path__arrow--ALTER_GOTO { color: #f59e0b; }
.exec-path__arrow--FALL_THROUGH { color: var(--text-muted); }
.exec-path__arrow--PERFORM { color: var(--success); }

/* ── Human vs AI Timer Badge ─────────────────────────────────── */
.analysis-timer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--sp-2) var(--sp-3);
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border);
}

.analysis-timer__ai {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--success);
}

.analysis-timer__human {
  font-size: 10px;
  color: var(--text-muted);
}

/* ── Cross-File Summary Table ──────────────────────────────────── */
.cross-file-summary {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.cross-file-summary th,
.cross-file-summary td {
  padding: var(--sp-2) var(--sp-3);
  text-align: left;
  border-bottom: 1px solid var(--glass-border);
}

.cross-file-summary th {
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: var(--text-2xs);
  letter-spacing: 0.04em;
}

.cross-file-summary td {
  color: var(--text-secondary);
}

/* ── Execution Path Groups (stacked traces) ───────────────────── */
.exec-path__group {
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  margin-bottom: var(--sp-2);
  overflow: hidden;
}

.exec-path__group-header {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-secondary);
}

.exec-path__group-header:hover {
  background: rgba(255, 255, 255, 0.05);
}

.exec-path__group-body {
  display: none;
  padding: var(--sp-2) var(--sp-3);
}

.exec-path__group-body--open {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1);
  align-items: center;
}

.exec-path__group--active {
  border-color: rgba(59, 130, 246, 0.4);
  background: rgba(59, 130, 246, 0.04);
}

.exec-path__group--active .exec-path__group-body {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1);
  align-items: center;
}

/* ── Selected Node in Call Graph ──────────────────────────────── */
.cg-node--selected .cg-node__hit {
  stroke-width: 3;
  stroke: var(--text-accent) !important;
  fill: transparent;
  rx: 6;
  ry: 6;
}

/* Background rect for selected node */
.cg-node__rect--selected {
  stroke-width: 3 !important;
  stroke: var(--text-accent) !important;
  filter: drop-shadow(0 0 4px rgba(59, 130, 246, 0.5));
}

/* Connected edges get slightly thicker stroke when a node is isolated */
.cg-edge--connected {
  stroke-width: 2 !important;
}

/* Smooth transition on edge opacity for isolation */
.cg-edge {
  transition: opacity 0.2s ease;
}

/* ── Cross-File Edge Types ────────────────────────────────────── */
.cg-edge--CALL_EXTERNAL {
  stroke: #22c55e;
  stroke-dasharray: none;
  stroke-width: 1.5;
}

.cg-edge--COPY_DEPENDENCY {
  stroke: #3b82f6;
  stroke-dasharray: 6 3;
  stroke-width: 1.5;
}

.cg-edge--SHARED_COPYBOOK {
  stroke: #f59e0b;
  stroke-dasharray: 3 3;
  stroke-width: 1.5;
}
