/**
 * SQL Plan Explainer - Visual Plan Tree Styles
 * Handles the interactive flow tree, operator cards, connectors, and zoom canvas.
 */

.tree-view-wrapper {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 700px;
}

.tree-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.25rem;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border-color);
  z-index: 10;
}

.toolbar-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.toolbar-buttons {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.tree-canvas-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
  background-color: var(--bg-app);
  background-image: radial-gradient(var(--border-color) 1px, transparent 1px);
  background-size: 20px 20px;
  cursor: grab;
}

.tree-canvas {
  position: absolute;
  top: 0;
  left: 0;
  padding: 40px;
  transform-origin: 0 0;
  transition: transform 0.05s ease-out;
  display: inline-block;
  white-space: nowrap;
}

.statement-tree-wrapper {
  margin-bottom: 3rem;
}

.statement-tree-header {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--border-color);
}

/* Tree Structure Layout (Right-to-Left or Tree Hierarchy) */
.tree-node-hierarchy {
  display: inline-flex;
  align-items: center;
}

.op-tree-branch {
  display: inline-flex;
  align-items: center;
  position: relative;
}

.op-children-container {
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  margin-left: 45px;
  position: relative;
  gap: 20px;
}

/* Connector lines between parent and children */
.op-children-container::before {
  content: '';
  position: absolute;
  left: -25px;
  top: 20px;
  bottom: 20px;
  width: 2px;
  background-color: var(--border-hover);
}

.op-tree-branch::before {
  content: '';
  position: absolute;
  left: -25px;
  top: 50%;
  width: 25px;
  height: 2px;
  background-color: var(--border-hover);
}

/* For the root node, don't show incoming left connector */
.tree-node-hierarchy > .op-tree-branch::before {
  display: none;
}

/* Connect parent output right connector */
.op-tree-branch:has(> .op-children-container)::after {
  content: '←';
  position: absolute;
  right: -25px;
  top: calc(50% - 10px);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: bold;
  pointer-events: none;
}

/* Operator Card Node */
.op-card {
  width: 220px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  user-select: none;
  transition: all 0.15s ease;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.op-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--color-primary);
}

.op-card.selected {
  border: 2px solid var(--color-primary) !important;
  box-shadow: 0 0 0 3px var(--color-primary-subtle);
  background-color: var(--color-primary-subtle);
}

.op-card.high-cost {
  border-color: var(--color-danger);
}

.op-card.medium-cost {
  border-color: var(--color-warning);
}

.op-card.has-warnings {
  box-shadow: 0 0 0 2px var(--color-warning-subtle);
}

.op-card.has-spill {
  border-color: var(--color-danger);
}

/* Card Elements */
.op-card-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.op-icon {
  font-size: 1.1rem;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
}

.op-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.op-warn-badge {
  font-size: 0.85rem;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.op-target {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0.15rem 0.35rem;
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
}

.op-metrics {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.2rem;
}

.op-cost-pill {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.1rem 0.35rem;
  border-radius: var(--radius-sm);
}

.cost-high { background: var(--color-danger-subtle); color: var(--color-danger); }
.cost-medium { background: var(--color-warning-subtle); color: var(--color-warning); }
.cost-normal { background: var(--bg-subtle); color: var(--text-secondary); }

.op-rows-pill {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.op-cost-bar {
  width: 100%;
  height: 4px;
  background: var(--bg-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-top: 0.2rem;
}

.op-cost-fill {
  height: 100%;
  border-radius: var(--radius-full);
}

.fill-high { background: var(--color-danger); }
.fill-medium { background: var(--color-warning); }
.fill-normal { background: var(--color-primary); }
