/**
 * Flow Components CSS
 * 
 * Consolidated CSS for all React Flow components including:
 * - CustomAgentNode
 * - CustomEdge
 * - TraceView/TraceGroup components
 */

/* ======= AGENT NODE STYLES ======= */
.custom-agent-node {
  min-width: 220px;
  max-width: 360px;
  border-radius: 6px;
  background: white;
  box-shadow: 0 3px 7px rgba(0, 0, 0, 0.12);
  border: 3px solid #2196F3;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  overflow: hidden;
  transition: all 0.2s ease;
  position: relative;
}

.custom-agent-node.selected {
  box-shadow: 0 0 0 3px #2196F3, 0 4px 8px rgba(0, 0, 0, 0.25);
  z-index: 10;
}

.custom-agent-header {
  background-color: #2196F3;
  color: white;
  padding: 10px 14px;
  font-weight: 500;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.custom-agent-header:hover {
  filter: brightness(1.1);
}

.agent-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.agent-status {
  margin-left: 8px;
  font-size: 12px;
  text-align: center;
  min-width: 16px;
  height: 16px;
  line-height: 16px;
  animation: blink 1s infinite;
}

/* Agent node is now header-only */
.custom-agent-node {
  cursor: pointer;  /* Make entire node clickable */
}

/* ======= CUSTOM EDGE STYLES ======= */
.react-flow__edge-path.active {
  animation: edge-glow-animation 2s infinite linear;
  stroke: #2196F3;
  stroke-width: 2px;
  stroke-dasharray: 5, 3;
  stroke-linecap: round;
  filter: drop-shadow(0 0 3px rgba(33, 150, 243, 0.8));
}

/* Solid blue style for edges after activity timeout */
.react-flow__edge-path.solid-blue {
  stroke: #2196F3;
  stroke-width: 3px;
  stroke-linecap: round;
  filter: drop-shadow(0 0 2px rgba(33, 150, 243, 0.5));
  transition: all 0.3s ease;
}

@keyframes edge-glow-animation {
  0% {
    stroke-dashoffset: 24;
    opacity: 0.6;
  }
  50% {
    opacity: 1;
    filter: drop-shadow(0 0 5px rgba(33, 150, 243, 1.0));
  }
  100% {
    stroke-dashoffset: 0;
    opacity: 0.6;
  }
}

/* ======= TRACE VIEW STYLES ======= */
.trace-view {
  width: 100%;
  max-height: 300px;
  overflow-y: auto;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 12px;
  line-height: 1.4;
  padding: 8px;
  background-color: #f8f9fa;
  border-radius: 4px;
}

.trace-view.compact {
  max-height: 250px;
}

.trace-view-empty {
  padding: 12px;
  color: #666;
  text-align: center;
  font-style: italic;
}

.trace-group-header {
  font-weight: bold;
  padding: 10px;
  border-radius: 4px 4px 0 0;
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #2196F3; /* Default - will be overridden by inline style */
  color: white;
  transition: all 0.2s ease;
}

.trace-group-header:hover {
  filter: brightness(1.1);
}

.trace-time-badge {
  background-color: rgba(255, 255, 255, 0.25);
  color: white;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: normal;
  margin-right: 8px;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.trace-completion-badge {
  background-color: #28a745;
  color: white;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 10px;
  font-weight: normal;
}

.trace-group {
  margin-bottom: 12px;
  border-radius: 6px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  transition: all 0.2s ease;
}

.trace-group.expanded {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.trace-group-content {
  padding: 8px;
  background-color: #f9f9f9;
  border-top: none;
}

.trace-tasks {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.trace-task {
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  background-color: white;
  transition: box-shadow 0.2s, border-color 0.2s;
  cursor: pointer;
  overflow: hidden;
}

.trace-task:hover {
  border-color: #bbb;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.trace-task.expanded {
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  border-color: #aaa;
}

.trace-task-header {
  padding: 6px 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #f5f5f5;
}

.trace-task-title {
  font-weight: 500;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trace-task-expand {
  width: 16px;
  height: 16px;
  font-weight: bold;
  text-align: center;
  line-height: 16px;
  color: #666;
}

.trace-task-content {
  padding: 8px;
  background-color: #fff;
  border-top: 1px solid #eee;
  overflow: auto;
  max-height: 200px;
}

.trace-task-content pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.trace-empty-state {
  padding: 12px;
  color: #666;
  text-align: center;
  font-style: italic;
}

.trace-see-more {
  text-align: center;
  padding: 4px;
  color: #666;
  font-style: italic;
  border-top: 1px solid #eee;
  margin-top: 4px;
}

/* Style for CustomAgentNode with trace content */
.custom-agent-node .trace-content {
  padding: 0;
}

.custom-agent-node .trace-view {
  border-radius: 0;
  border-top: 1px solid #ddd;
  background-color: #f8f9fa;
}

/* ======= SHARED ANIMATIONS ======= */

/* Blinking animation for status indicators */
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Edge pulse animation */
@keyframes edge-pulse {
  0% {
    filter: drop-shadow(0 0 1px rgba(33, 150, 243, 0.6)) 
           drop-shadow(0 0 1px rgba(33, 150, 243, 0.6));
    opacity: 0.9;
  }
  50% {
    filter: drop-shadow(0 0 3px rgba(33, 150, 243, 0.8)) 
           drop-shadow(0 0 3px rgba(33, 150, 243, 0.8));
    opacity: 1;
  }
  100% {
    filter: drop-shadow(0 0 1px rgba(33, 150, 243, 0.6)) 
           drop-shadow(0 0 1px rgba(33, 150, 243, 0.6));
    opacity: 0.9;
  }
}

/* Node pulse animation */
@keyframes node-pulse {
  0% { box-shadow: 0 0 0 0 rgba(33, 150, 243, 0.5); }
  70% { box-shadow: 0 0 0 12px rgba(33, 150, 243, 0); }
  100% { box-shadow: 0 0 0 0 rgba(33, 150, 243, 0); }
}

/* Node states */
.node-processing,
.react-flow__node.node-processing,
.react-flow__node-customAgent.node-processing,
.custom-agent-node.node-processing {
  animation: node-pulse 1.5s infinite !important;
  border-width: 3px !important;
  box-shadow: 0 0 10px rgba(33, 150, 243, 0.7) !important;
  z-index: 10 !important;
}

/* Frozen processing state - keeps the glow but stops the animation */
.node-frozen-processing,
.react-flow__node.node-frozen-processing,
.react-flow__node-customAgent.node-frozen-processing,
.custom-agent-node.node-frozen-processing {
  animation: none !important; /* No animation */
  border-width: 3px !important;
  box-shadow: 0 0 10px rgba(33, 150, 243, 0.7) !important; /* Same glow as processing */
  z-index: 10 !important;
}

.node-complete,
.react-flow__node.node-complete,
.react-flow__node-customAgent.node-complete,
.custom-agent-node.node-complete {
  box-shadow: 0 0 10px rgba(76, 175, 80, 0.7) !important;
  border-width: 3px !important;
  z-index: 5 !important;
}

/* ======= TRACE MODAL STYLES ======= */
/* Style for Raw Data tab in TraceModal */
.trace-raw-data {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: break-word;
  max-height: 500px;
  overflow-y: auto;
  padding: 8px;
  background-color: #f8f9fa;
  border-radius: 4px;
  font-size: 12px;
  line-height: 1.5;
  font-family: monospace;
}

/* Styles for JSON and text content in trace steps */
.trace-json-content, .trace-text-content {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: break-word;
  font-size: 12px;
  line-height: 1.5;
  font-family: monospace;
  max-width: 100%;
  overflow-x: auto;
}

/* Modal content wrapper */
.trace-modal-content {
  max-width: 100%;
  overflow-x: hidden;
}

/* ======= TRACE SUBTASK STYLES ======= */
.trace-subtasks {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.trace-subtask {
  border-radius: 3px;
  background-color: #fafafa;
  overflow: hidden;
  transition: box-shadow 0.2s, border-color 0.2s;
}

.trace-subtask.expanded {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.trace-subtask-header {
  padding: 6px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  border-radius: 3px;
}

.trace-subtask-header:hover {
  background-color: rgba(0, 0, 0, 0.02);
}

.trace-subtask-title {
  font-size: 0.9em;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trace-subtask-expand {
  width: 14px;
  height: 14px;
  font-weight: bold;
  text-align: center;
  line-height: 14px;
  color: #666;
  font-size: 0.9em;
}

.trace-subtask-content {
  padding: 8px 10px;
  border-top: 1px solid #f0f0f0;
}

.trace-subtask-content pre {
  margin: 0;
  font-size: 0.9em;
  white-space: pre-wrap;
  word-break: break-word;
}

/* For nested trace content - make it more compact */
.trace-subtask .trace-content-json,
.trace-subtask .trace-content-text {
  font-size: 11px;
  line-height: 1.4;
  max-height: 180px;
  overflow-y: auto;
}

/* Styles for paired subtasks (input/output) */
.trace-subtask-pair {
  border-left: 2px solid #f0f0f0;
  margin-left: 5px;
  padding-left: 5px;
  margin-bottom: 10px;
}

.trace-subtask-pair .trace-subtask:first-child {
  border-bottom: 1px dashed #eee;
}

.trace-subtask-pair .trace-subtask:last-child {
  margin-top: 0;
}

.trace-subtask-pair .trace-subtask-header .trace-subtask-title {
  position: relative;
}

/* Special input/output indicators */
.trace-subtask-pair .trace-subtask:first-child .trace-subtask-title::before {
  content: "📤";
  margin-right: 5px;
  font-size: 12px;
  opacity: 0.7;
}

.trace-subtask-pair .trace-subtask:last-child .trace-subtask-title::before {
  content: "📥";
  margin-right: 5px;
  font-size: 12px;
  opacity: 0.7;
}

/* Browser node message styles */
.user-message {
  border-left: 4px solid #42a5f5 !important; /* Blue for user messages */
  margin-bottom: 10px !important;
}

.system-message {
  border-left: 4px solid #66bb6a !important; /* Green for system messages */
  margin-bottom: 10px !important;
}

.message-direction-indicator {
  font-weight: bold;
  margin-right: 5px;
}
