/* ========================================================
   Make.com Testing Platform — UI Components
   1. Module Execution Inspector
   2. Collapsible JSON Tree View
   3. Blueprint Validation Panel
   4. Expression Debugger
   5. Execution Timeline
   ======================================================== */

/* ----------------------------------------------------------
   1. MODULE EXECUTION INSPECTOR
   ---------------------------------------------------------- */
.exec-inspector {
  background: var(--panel);
  border: 1px solid #333;
  border-radius: 10px;
  overflow: hidden;
  margin-top: 20px;
}

.exec-inspector-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid #333;
}

.exec-inspector-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}

.exec-inspector-summary {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--muted);
}

.exec-inspector-summary .tag {
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 500;
}

.exec-inspector-summary .tag-ops {
  background: var(--accent)22;
  color: var(--accent);
}

.exec-inspector-summary .tag-status {
  background: var(--success)22;
  color: var(--success);
}

.exec-inspector-summary .tag-status.error {
  background: var(--error)22;
  color: var(--error);
}

.exec-inspector-summary .tag-time {
  background: #4361ee22;
  color: #4361ee;
}

.exec-inspector-body {
  padding: 0;
}

.exec-phase {
  border-bottom: 1px solid #1a1a2e;
}

.exec-phase:last-child {
  border-bottom: none;
}

.exec-phase-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}

.exec-phase-header:hover {
  background: var(--card);
}

.exec-phase-icon {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  flex-shrink: 0;
}

.exec-phase-icon.success {
  background: var(--success)22;
  color: var(--success);
}

.exec-phase-icon.error {
  background: var(--error)22;
  color: var(--error);
}

.exec-phase-icon.pending {
  background: #44444444;
  color: #888;
}

.exec-phase-label {
  font-weight: 500;
  color: var(--text);
}

.exec-phase-detail {
  font-size: 11px;
  color: var(--muted);
  margin-left: auto;
}

.exec-section {
  padding: 0 16px 12px 42px;
}

.exec-section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--muted);
  padding: 8px 0 4px;
  border-top: 1px solid #1a1a2e;
}

.exec-section-title.input-title { color: #4361ee; }
.exec-section-title.output-title { color: var(--success); }
.exec-section-title.credit-title { color: var(--warning); }

.exec-bundle-label {
  font-size: 12px;
  color: var(--text);
  padding: 4px 0;
  font-weight: 500;
}

.exec-credit-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 12px;
}

.exec-credit-row .label { color: var(--muted); }
.exec-credit-row .value { color: var(--warning); font-weight: 600; }

/* ----------------------------------------------------------
   2. COLLAPSIBLE JSON TREE VIEW
   ---------------------------------------------------------- */
.json-tree {
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.6;
  padding: 12px;
  background: #0a0a1a;
  border-radius: 8px;
  overflow: auto;
  max-height: 500px;
}

.json-tree-node {
  padding-left: 20px;
  position: relative;
}

.json-tree-node.root {
  padding-left: 0;
}

.json-tree-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  font-size: 10px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
  transition: transform 0.15s;
  border: none;
  background: none;
  padding: 0;
  vertical-align: middle;
}

.json-tree-toggle.collapsed {
  transform: rotate(-90deg);
}

.json-tree-line {
  display: flex;
  align-items: baseline;
  gap: 0;
  padding: 1px 0;
  cursor: default;
}

.json-tree-line:hover {
  background: #ffffff06;
  border-radius: 3px;
}

.json-tree-key {
  color: #6fb3f2;
  cursor: pointer;
}

.json-tree-key:hover {
  text-decoration: underline;
}

.json-tree-colon {
  color: var(--muted);
  margin: 0 4px;
}

.json-tree-value {
  cursor: pointer;
}

.json-tree-value:hover {
  opacity: 0.8;
}

.json-tree-value.string { color: #98c379; }
.json-tree-value.number { color: #d19a66; }
.json-tree-value.boolean { color: #c678dd; }
.json-tree-value.null { color: #666; font-style: italic; }

.json-tree-bracket {
  color: var(--muted);
}

.json-tree-badge {
  display: inline-block;
  font-size: 10px;
  padding: 0 5px;
  margin-left: 6px;
  border-radius: 3px;
  background: var(--card);
  color: var(--muted);
  font-weight: 500;
  vertical-align: middle;
}

.json-tree-ellipsis {
  color: var(--muted);
  cursor: pointer;
  font-style: italic;
}

.json-tree-ellipsis:hover {
  color: var(--text);
}

.json-tree-string-truncated {
  color: #98c379;
  cursor: pointer;
}

.json-tree-string-truncated:hover::after {
  content: ' (click to expand)';
  font-size: 10px;
  color: var(--muted);
}

.json-tree-comma {
  color: var(--muted);
}

.json-tree-copied {
  position: fixed;
  padding: 4px 12px;
  background: var(--success);
  color: #000;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  pointer-events: none;
  z-index: 9999;
  animation: jsonCopiedFade 1s ease forwards;
}

@keyframes jsonCopiedFade {
  0% { opacity: 1; transform: translateY(0); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-10px); }
}

/* ----------------------------------------------------------
   3. BLUEPRINT VALIDATION PANEL
   ---------------------------------------------------------- */
.validation-panel {
  background: var(--panel);
  border: 1px solid #333;
  border-radius: 10px;
  margin-bottom: 12px;
  overflow: hidden;
}

.validation-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--card);
  border-bottom: 1px solid #333;
  cursor: pointer;
}

.validation-panel-header:hover {
  background: #0f3460cc;
}

.validation-panel-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.validation-panel-counts {
  display: flex;
  gap: 8px;
  font-size: 11px;
}

.validation-count {
  padding: 1px 6px;
  border-radius: 3px;
  font-weight: 600;
}

.validation-count.pass { background: var(--success)22; color: var(--success); }
.validation-count.warn { background: var(--warning)22; color: var(--warning); }
.validation-count.fail { background: var(--error)22; color: var(--error); }

.validation-panel-toggle {
  font-size: 12px;
  color: var(--muted);
  border: none;
  background: none;
  cursor: pointer;
  transition: transform 0.2s;
}

.validation-panel-body {
  padding: 8px 0;
  max-height: 300px;
  overflow-y: auto;
}

.validation-panel-body.collapsed {
  display: none;
}

.validation-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 6px 14px;
  font-size: 12px;
  transition: background 0.1s;
}

.validation-item:hover {
  background: var(--card);
}

.validation-icon {
  flex-shrink: 0;
  width: 18px;
  text-align: center;
  font-size: 13px;
  line-height: 1.4;
}

.validation-message {
  color: var(--text);
  line-height: 1.4;
}

.validation-message .module-ref {
  color: #6fb3f2;
  font-weight: 500;
}

.validation-message .field-ref {
  color: var(--warning);
  font-family: 'Cascadia Code', 'Fira Code', monospace;
  font-size: 11px;
}

/* ----------------------------------------------------------
   4. EXPRESSION DEBUGGER
   ---------------------------------------------------------- */
.expr-debugger {
  background: var(--panel);
  border: 1px solid #333;
  border-radius: 10px;
  overflow: hidden;
  margin-top: 16px;
}

.expr-debugger-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--card);
  border-bottom: 1px solid #333;
}

.expr-debugger-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}

.expr-debugger-body {
  padding: 14px;
}

.expr-input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.expr-input {
  flex: 1;
  background: #0a0a1a;
  color: var(--text);
  border: 1px solid #444;
  border-radius: 6px;
  padding: 10px 14px;
  font-family: 'Cascadia Code', 'Fira Code', monospace;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

.expr-input:focus {
  border-color: var(--accent);
}

.expr-input::placeholder {
  color: #555;
}

.expr-eval-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0 16px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.expr-eval-btn:hover {
  opacity: 0.85;
}

.expr-steps {
  background: #0a0a1a;
  border-radius: 6px;
  padding: 12px;
  min-height: 60px;
}

.expr-step {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  font-size: 12px;
  font-family: 'Cascadia Code', 'Fira Code', monospace;
}

.expr-step-arrow {
  color: var(--muted);
  font-size: 14px;
  flex-shrink: 0;
}

.expr-step-value {
  color: var(--text);
  word-break: break-all;
}

.expr-step-value .resolved {
  color: var(--success);
  background: var(--success)11;
  padding: 1px 4px;
  border-radius: 3px;
}

.expr-step-value .unresolved {
  color: var(--error);
  background: var(--error)11;
  padding: 1px 4px;
  border-radius: 3px;
  text-decoration: wavy underline;
}

.expr-step-value .literal {
  color: #98c379;
}

.expr-step-value .fn {
  color: #c678dd;
}

.expr-step-label {
  font-size: 10px;
  color: var(--muted);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  flex-shrink: 0;
  min-width: 70px;
}

.expr-final {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #333;
  display: flex;
  align-items: center;
  gap: 10px;
}

.expr-final-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--success);
}

.expr-final-value {
  font-family: 'Cascadia Code', 'Fira Code', monospace;
  font-size: 13px;
  color: #fff;
  background: var(--success)15;
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid var(--success)33;
}

.expr-final-value.error {
  color: var(--error);
  background: var(--error)15;
  border-color: var(--error)33;
}

.expr-context-hint {
  font-size: 11px;
  color: var(--muted);
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #1a1a2e;
}

.expr-context-hint code {
  background: var(--card);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
  color: #6fb3f2;
}

/* ----------------------------------------------------------
   5. EXECUTION TIMELINE
   ---------------------------------------------------------- */
.exec-timeline {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 8px 0;
  overflow-x: auto;
}

.exec-timeline-node {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.exec-timeline-module {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.exec-timeline-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  position: relative;
  transition: transform 0.15s, box-shadow 0.15s;
}

.exec-timeline-circle:hover {
  transform: scale(1.12);
}

.exec-timeline-circle.pass {
  border: 2px solid var(--success);
  color: var(--success);
  background: var(--success)11;
}

.exec-timeline-circle.fail {
  border: 2px solid var(--error);
  color: var(--error);
  background: var(--error)11;
  animation: timelinePulse 1.5s ease infinite;
}

.exec-timeline-circle.pending {
  border: 2px solid #444;
  color: #666;
  background: transparent;
}

.exec-timeline-circle.running {
  border: 2px solid var(--warning);
  color: var(--warning);
  background: var(--warning)11;
  animation: timelinePulse 1s ease infinite;
}

@keyframes timelinePulse {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  50% { box-shadow: 0 0 12px 2px var(--warning)44; }
}

.exec-timeline-timing {
  font-size: 10px;
  color: var(--muted);
  text-align: center;
  font-family: 'Cascadia Code', monospace;
}

.exec-timeline-label {
  font-size: 9px;
  color: var(--muted);
  text-align: center;
  max-width: 70px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.exec-timeline-connector {
  display: flex;
  align-items: center;
  flex-direction: column;
  padding: 0 2px;
}

.exec-timeline-line {
  width: 36px;
  height: 2px;
  background: #444;
  position: relative;
}

.exec-timeline-line.pass {
  background: var(--success);
}

.exec-timeline-line::after {
  content: '';
  position: absolute;
  right: -1px;
  top: -3px;
  border: 4px solid transparent;
  border-left: 5px solid #444;
}

.exec-timeline-line.pass::after {
  border-left-color: var(--success);
}

.exec-timeline-delta {
  font-size: 9px;
  color: var(--muted);
  font-family: 'Cascadia Code', monospace;
  margin-top: 2px;
}

.exec-timeline-totals {
  display: flex;
  gap: 20px;
  padding: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid #1a1a2e;
  margin-top: 6px;
}

.exec-timeline-totals .total-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.exec-timeline-totals .total-value {
  font-weight: 600;
  color: var(--text);
  font-family: 'Cascadia Code', monospace;
}

.exec-timeline-totals .total-value.credits {
  color: var(--warning);
}
