/* ============================================
   VERSION TREE VIEWER STYLES
   All styles scoped under ._versioncanvas_
   ============================================ */

/* Base Canvas Styles */
._versioncanvas_ {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* ============================================
   CANVAS CONTROLS
   ============================================ */
._versioncanvas_ .canvas-controls {
  position: absolute;
  width: min-content;
  top: 20px;
  left: 20px;
  display: flex;
  gap: 8px;
  z-index: 100;
  background: rgba(20, 20, 20, 0.95);
  padding: 8px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

._versioncanvas_ .control-btn {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  padding: 0;
}

._versioncanvas_ .control-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

._versioncanvas_ .control-btn:active {
  transform: translateY(0);
}

._versioncanvas_ .control-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

._versioncanvas_ .control-btn svg {
  width: 20px;
  height: 20px;
}

._versioncanvas_ .control-btn.is-spinning svg {
  animation: spin 1s linear infinite;
}

/* ============================================
   SEARCH CONTAINER
   ============================================ */
._versioncanvas_ .search-container {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 100;
  min-width: 300px;
  max-width: 400px;
}

._versioncanvas_ .search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  background: rgba(20, 20, 20, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 12px 16px;
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  gap: 10px;
}

._versioncanvas_ .search-icon {
  width: 18px;
  height: 18px;
  color: #a0a0a0;
  flex-shrink: 0;
}

._versioncanvas_ .search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #ffffff;
  font-size: 14px;
  padding: 0;
}

._versioncanvas_ .search-input::placeholder {
  color: #606060;
}

._versioncanvas_ .search-clear {
  width: 24px;
  height: 24px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  color: #a0a0a0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  padding: 0;
  flex-shrink: 0;
}

._versioncanvas_ .search-clear:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

._versioncanvas_ .search-clear svg {
  width: 14px;
  height: 14px;
}

/* ============================================
   SEARCH RESULTS
   ============================================ */
._versioncanvas_ .search-results {
  display: none;
  margin-top: 8px;
  background: rgba(20, 20, 20, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  max-height: 400px;
  overflow-y: auto;
  animation: slideDown 0.2s ease;
}

._versioncanvas_ .search-results::-webkit-scrollbar {
  width: 6px;
}

._versioncanvas_ .search-results::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 3px;
}

._versioncanvas_ .search-results::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
}

._versioncanvas_ .search-results::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

._versioncanvas_ .search-result-item {
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  transition: background 0.2s ease;
}

._versioncanvas_ .search-result-item:last-child {
  border-bottom: none;
}

._versioncanvas_ .search-result-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

._versioncanvas_ .search-result-item.active {
  background: rgba(59, 130, 246, 0.15);
  border-left: 3px solid #3b82f6;
}

._versioncanvas_ .search-result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

._versioncanvas_ .search-result-version {
  font-weight: 600;
  font-size: 14px;
  color: #ffffff;
}

._versioncanvas_ .search-result-desc {
  font-size: 12px;
  color: #a0a0a0;
  margin-bottom: 4px;
  line-height: 1.4;
}

._versioncanvas_ .search-result-status {
  font-size: 11px;
  color: #707070;
  text-transform: capitalize;
}

._versioncanvas_ .search-no-results {
  padding: 20px;
  text-align: center;
  color: #707070;
  font-size: 13px;
}

/* ============================================
   VERSION NODE STYLES
   ============================================ */
._versioncanvas_ .version-node {
  padding: 16px;
  min-width: 180px;
  max-width: 280px;
}

._versioncanvas_ .version-node-wrapper {
  position: relative;
}

/* Tooltip - Hidden by default */
._versioncanvas_ .version-tooltip {
  display: none;
}

/* Show tooltip when node is selected OR hovered */
._versioncanvas_ .drawflow-node.selected .version-tooltip,
._versioncanvas_ .drawflow-node:hover .version-tooltip {
  display: block;
}

._versioncanvas_ .version-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  max-width: 320px;
  min-width: 200px;
  padding: 12px 16px;
  background: #1f2937;
  color: #ffffff;
  font-size: 13px;
  line-height: 1.5;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  white-space: normal;
  word-wrap: break-word;
  animation: tooltipFadeIn 0.2s ease;
  pointer-events: none;
}

/* Tooltip arrow */
._versioncanvas_ .version-tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border-width: 6px;
  border-style: solid;
  border-color: #1f2937 transparent transparent transparent;
}

@keyframes tooltipFadeIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

._versioncanvas_ .version-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

._versioncanvas_ .version-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
  color: #ffffff;
}

._versioncanvas_ .version-title .status-icon {
  position: unset !important;
}

._versioncanvas_ .version-badge {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

._versioncanvas_ .badge-initial {
  background: rgba(168, 85, 247, 0.2);
  color: #c084fc;
  border: 1px solid rgba(168, 85, 247, 0.3);
}

._versioncanvas_ .badge-regenerate {
  background: rgba(59, 130, 246, 0.2);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

._versioncanvas_ .badge-branch {
  background: rgba(34, 197, 94, 0.2);
  color: #4ade80;
  border: 1px solid rgba(34, 197, 94, 0.3);
}

._versioncanvas_ .version-body {
  margin-bottom: 12px;
}

._versioncanvas_ .version-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #a0a0a0;
  margin-bottom: 8px;
  text-transform: capitalize;
}

._versioncanvas_ .status-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

._versioncanvas_ .status-completed {
  color: #4ade80;
}

._versioncanvas_ .status-generating {
  color: #60a5fa;
  animation: spin 1s linear infinite;
}

._versioncanvas_ .status-error {
  color: #f87171;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

._versioncanvas_ .version-description {
  font-size: 12px;
  color: #909090;
  margin-bottom: 6px;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.4;
  cursor: help;
}

._versioncanvas_ .version-time {
  font-size: 11px;
  color: #606060;
}

._versioncanvas_ .version-actions {
  display: flex;
  gap: 8px;
}

._versioncanvas_ .version-btn {
  flex: 1;
  padding: 8px 14px;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

._versioncanvas_ .btn-activate {
  background: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

._versioncanvas_ .btn-activate:hover {
  background: rgba(59, 130, 246, 0.25);
  border-color: rgba(59, 130, 246, 0.5);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

._versioncanvas_ .btn-activate:active {
  transform: translateY(0);
}

._versioncanvas_ .version-no-data {
  font-size: 12px;
  color: #606060;
  font-style: italic;
  padding: 8px 0;
}

._versioncanvas_ .active-indicator {
  position: absolute;
  top: -10px;
  right: -10px;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: white;
  padding: 5px 12px;
  border-radius: 16px;
  font-size: 10px;
  font-weight: 700;
  box-shadow: 0 4px 16px rgba(59, 130, 246, 0.5);
  animation: pulse 2s ease-in-out infinite;
  letter-spacing: 0.5px;
  z-index: 10;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.8;
    transform: scale(1.05);
  }
}

/* ============================================
   ACTIVE NODE STATE
   ============================================ */
._versioncanvas_ .version-node.active {
  border: 2px solid rgba(59, 130, 246, 0.5);
  box-shadow: 0 0 20px rgba(59, 130, 246, 0.3);
}

/* ============================================
   SEARCH HIGHLIGHT STATE
   ============================================ */
._versioncanvas_ .drawflow-node.search-highlight {
  animation: searchHighlight 1s ease-in-out infinite;
}

@keyframes searchHighlight {
  0%, 100% {
    box-shadow: 0 0 0 rgba(251, 191, 36, 0);
  }
  50% {
    box-shadow: 0 0 20px rgba(251, 191, 36, 0.6);
  }
}

._versioncanvas_ .drawflow-node.search-highlight .version-node {
  border-color: rgba(251, 191, 36, 0.5);
}

/* ============================================
   FOCUSED NODE STATE
   ============================================ */
._versioncanvas_ .drawflow-node.focused {
  animation: focusPulse 0.5s ease-in-out 3;
}

@keyframes focusPulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

/* ============================================
   LEGEND
   ============================================ */
._versioncanvas_ .legend {
  position: absolute;
  bottom: 20px;
  right: 20px;
  background: rgba(20, 20, 20, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 16px;
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  z-index: 50;
  min-width: 220px;
}

._versioncanvas_ .legend-title {
  font-weight: 600;
  margin-bottom: 12px;
  font-size: 13px;
  color: #ffffff;
  letter-spacing: 0.3px;
}

._versioncanvas_ .legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 12px;
  color: #a0a0a0;
}

._versioncanvas_ .legend-item:last-child {
  margin-bottom: 0;
}

/* ============================================
   DRAWFLOW OVERRIDES
   ============================================ */
._versioncanvas_ .drawflow-node {
  background: rgba(30, 30, 30, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
}

._versioncanvas_ .drawflow-node:hover {
  border-color: rgba(255, 255, 255, 0.2);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  transform: translateY(-2px);
}

._versioncanvas_ .drawflow-node.selected {
  border-color: rgba(59, 130, 246, 0.5);
  box-shadow: 0 8px 32px rgba(59, 130, 246, 0.3);
}

/* Connection Lines */
._versioncanvas_ .drawflow .connection {
  stroke: rgba(255, 255, 255, 0.3) !important;
  stroke-width: 2.5px !important;
  stroke-linecap: round !important;
  fill: none !important;
  pointer-events: stroke !important;
}

._versioncanvas_ .drawflow .connection.main-path {
  stroke: rgba(59, 130, 246, 0.5) !important;
  stroke-width: 3px !important;
}

._versioncanvas_ .drawflow .connection:hover {
  stroke: rgba(255, 255, 255, 0.6) !important;
  stroke-width: 3.5px !important;
}

/* Make sure connection points are present but visually hidden */
._versioncanvas_ .drawflow-node .input,
._versioncanvas_ .drawflow-node .output {
  width: 10px !important;
  height: 10px !important;
  opacity: 0 !important;
  pointer-events: none !important;
  background: transparent !important;
  border: none !important;
}

/* Ensure inputs are on left, outputs on right */
._versioncanvas_ .drawflow-node .inputs {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
}

._versioncanvas_ .drawflow-node .outputs {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
}

/* SVG Connection Container */
._versioncanvas_ .drawflow svg {
  pointer-events: none;
  overflow: visible !important;
}

._versioncanvas_ .drawflow svg path {
  pointer-events: stroke !important;
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */
@media (max-width: 768px) {
  ._versioncanvas_ .canvas-controls {
    top: 10px;
    left: 10px;
    gap: 6px;
    padding: 6px;
  }

  ._versioncanvas_ .control-btn {
    width: 36px;
    height: 36px;
  }

  ._versioncanvas_ .control-btn svg {
    width: 18px;
    height: 18px;
  }

  ._versioncanvas_ .search-container {
    top: 10px;
    right: 10px;
    min-width: 200px;
    max-width: 250px;
  }

  ._versioncanvas_ .legend {
    bottom: 10px;
    right: 10px;
    padding: 12px;
    min-width: 180px;
  }

  ._versioncanvas_ .version-node {
    min-width: 200px;
    max-width: 220px;
  }
}

/* ============================================
   DARK MODE ENHANCEMENTS
   ============================================ */
@media (prefers-color-scheme: dark) {
  ._versioncanvas_ .canvas-controls,
  ._versioncanvas_ .search-wrapper,
  ._versioncanvas_ .search-results,
  ._versioncanvas_ .legend {
    background: rgba(15, 15, 15, 0.98);
  }

  ._versioncanvas_ .drawflow-node {
    background: rgba(25, 25, 25, 0.98);
  }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */
._versioncanvas_ *:focus-visible {
  outline: 2px solid rgba(59, 130, 246, 0.6);
  outline-offset: 2px;
}

._versioncanvas_ .control-btn:focus-visible,
._versioncanvas_ .search-clear:focus-visible,
._versioncanvas_ .version-btn:focus-visible {
  outline: 2px solid rgba(59, 130, 246, 0.8);
}

/* ============================================
   LOADING STATES
   ============================================ */
._versioncanvas_ .control-btn.is-loading {
  pointer-events: none;
  opacity: 0.6;
}

._versioncanvas_ .version-node.is-loading {
  opacity: 0.6;
  pointer-events: none;
}

._versioncanvas_ .version-node.is-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
  ._versioncanvas_ .canvas-controls,
  ._versioncanvas_ .search-container,
  ._versioncanvas_ .legend {
    display: none;
  }
}