/* ── Fonts ─────────────────────────────────────── */
:root {
  --font-ui:   'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;
}

/* ── Dark theme ────────────────────────────────── */
html[data-theme="dark"] {
  --bg:      #1a1a1a;
  --panel:   #202020;
  --node:    #353535;
  --lift:    #2a2a2a;
  --hover:   #2e2e2e;
  --menu-active: #36363d;
  --menu-hover: #323238;
  --line:    #2a2a2a;
  --line2:   #383838;
  --tx1:     #ffffff;
  --tx2:     #fdfdfd;
  --tx3:     #b3b3b3;
  --accent:  #9899a8;
  --learned: #a78bfa;
  --save-pending: #75623c;
  --ok:      #22c55e;
  --warn:    #facc15;
  --err:     #ef4444;
  --rf-bg:   #1a1a1a;
  --rf-dot:  #3a3a3a;
  --rf-edge: #383838;
  --rf-ctrl: #202020;
}

/* ── Light theme ───────────────────────────────── */
html[data-theme="light"] {
  --bg:      #ecedf5;
  --panel:   #ffffff;
  --node:    #ffffff;
  --lift:    #f5f5fb;
  --hover:   #ededf6;
  --menu-active: #e3e5f3;
  --menu-hover: #e8e9f4;
  --line:    #dcdde9;
  --line2:   #bbbcce;
  --tx1:     #11121e;
  --tx2:     #3a3c60;
  --tx3:     #8082a8;
  --accent:  #6b7280;
  --learned: #8b5cf6;
  --save-pending: #8a7248;
  --ok:      #16a34a;
  --warn:    #ca8a04;
  --err:     #dc2626;
  --rf-bg:   #ecedf5;
  --rf-dot:  #d0d1e0;
  --rf-edge: #bbbcce;
  --rf-ctrl: #ffffff;
}

/* ── Reset ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--tx1);
  font-family: var(--font-ui);
  font-size: 14px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── ReactFlow overrides ───────────────────────── */
.react-flow__controls {
  background: var(--rf-ctrl) !important;
  border: 1px solid var(--line2) !important;
  border-radius: 8px !important;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0,0,0,.15) !important;
}
.react-flow__controls button {
  background: transparent !important;
  border: none !important;
  border-bottom: 1px solid var(--line) !important;
  color: var(--tx1) !important;
  fill: var(--tx1) !important;
  width: 28px !important;
  height: 28px !important;
}
.react-flow__controls button svg { fill: var(--tx1) !important; color: var(--tx1) !important; }
.react-flow__controls button:last-child { border-bottom: none !important; }
.react-flow__controls button:hover { background: var(--hover) !important; }

.react-flow__minimap {
  background: var(--rf-ctrl) !important;
  border: 1px solid var(--line2) !important;
  border-radius: 8px !important;
}

.react-flow__edge.selected .react-flow__edge-path { filter: brightness(1.5); stroke-width: 2.5px; }
.react-flow__edge:hover .react-flow__edge-path { filter: brightness(1.3); }

.react-flow__handle { border-radius: 3px !important; }

/* NodeResizer */
.react-flow__resize-control.line { border-color: var(--accent) !important; opacity: 0.5; }
.react-flow__resize-control.handle { background: var(--accent) !important; border-color: var(--accent) !important; }

/* menus */
.bn-menu-item:hover:not(:disabled) {
  background: var(--menu-hover) !important;
  color: var(--tx1) !important;
}

.bn-menu-item:disabled {
  opacity: 0.55;
}

.bn-top-button {
  background: transparent;
  border: 1px solid var(--line2);
  border-radius: 6px;
  color: var(--tx2);
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 12px;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, transform 70ms ease;
}

.bn-top-button:hover {
  background: var(--hover);
  border-color: var(--accent);
  color: var(--tx1);
}

.bn-top-button:active {
  background: var(--menu-active);
  border-color: var(--accent);
  transform: translateY(1px);
}

.bn-top-select {
  background: var(--panel);
  border: 1px solid var(--line2);
  border-radius: 6px;
  color: var(--tx2);
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  min-width: 122px;
  padding: 5px 10px;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.bn-top-select:hover:not(:disabled) {
  background: var(--hover);
  border-color: var(--accent);
  color: var(--tx1);
}

.bn-top-select:disabled {
  cursor: default;
  opacity: .55;
}

.bn-top-run-button {
  background: var(--ok);
  border-color: var(--ok);
  color: #fff;
  font-weight: 700;
  min-width: 64px;
}

.bn-top-run-button:hover:not(:disabled) {
  background: color-mix(in srgb, var(--ok) 86%, #000);
  border-color: var(--ok);
  color: #fff;
}

.bn-top-run-button:disabled {
  cursor: default;
  opacity: .55;
}

.bn-workflow-row:hover {
  background: var(--hover) !important;
  border-color: var(--accent) !important;
}

.bn-node-palette-item.bn-learned-node-pulse {
  animation: bn-learned-pulse 2.1s ease-out;
}

/* Trigger/"hook" node: a live entry point a driver listens on. */
.bn-hook-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  flex-shrink: 0;
  animation: bn-hook-pulse 1.6s ease-out infinite;
}

@keyframes bn-hook-pulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent); }
  70%  { box-shadow: 0 0 0 6px color-mix(in srgb, var(--ok) 0%, transparent); }
  100% { box-shadow: 0 0 0 0 transparent; }
}

@keyframes bn-learned-pulse {
  0% {
    color: var(--tx1);
    box-shadow: inset 2px 0 0 var(--learned), 0 0 0 0 color-mix(in srgb, var(--learned) 42%, transparent);
  }
  35% {
    color: var(--tx1);
    box-shadow: inset 2px 0 0 var(--learned), 0 0 0 5px color-mix(in srgb, var(--learned) 22%, transparent);
  }
  100% {
    box-shadow: inset 2px 0 0 var(--learned), 0 0 0 0 transparent;
  }
}

.bn-learned-panel {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.bn-learned-toolbar {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
}

.bn-learned-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.bn-learned-empty,
.bn-learned-error {
  padding: 14px 12px;
  color: var(--tx3);
  font-size: 12px;
  line-height: 1.45;
}

.bn-learned-error {
  color: var(--err);
  border-bottom: 1px solid var(--line);
  font-family: var(--font-mono);
  overflow-wrap: anywhere;
}

.bn-learned-row {
  padding: 10px 12px 11px;
  border-bottom: 1px solid var(--line);
}

.bn-learned-row:hover {
  background: var(--hover);
}

.bn-learned-row-head {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.bn-learned-name {
  min-width: 0;
  flex: 1;
  color: var(--tx1);
  font-size: 12px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bn-learned-perm {
  flex: 0 0 auto;
  border: 1px solid var(--line2);
  border-radius: 4px;
  color: var(--tx3);
  font-family: var(--font-mono);
  font-size: 9px;
  padding: 2px 5px;
}

.bn-learned-perm.is-network {
  color: var(--learned);
  border-color: var(--learned);
}

.bn-learned-desc {
  margin-top: 5px;
  color: var(--tx2);
  font-size: 11px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.bn-learned-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 7px;
  color: var(--tx3);
  font-family: var(--font-mono);
  font-size: 9px;
}

.bn-learned-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

.bn-learned-modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.42);
}

.bn-learned-source {
  width: min(760px, calc(100vw - 36px));
  max-height: min(680px, calc(100vh - 42px));
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line2);
  border-radius: 8px;
  box-shadow: 0 18px 48px rgba(0,0,0,.35);
}

.bn-learned-source-head {
  min-height: 42px;
  padding: 8px 10px 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  color: var(--tx1);
  font-size: 13px;
  font-weight: 700;
}

.bn-learned-source pre {
  margin: 0;
  padding: 12px;
  overflow: auto;
  color: var(--tx2);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.55;
  white-space: pre;
}

/* run history */
.bn-runs-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.bn-runs-toolbar {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.bn-runs-title {
  color: var(--tx1);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.2;
}

.bn-runs-subtitle {
  margin-top: 2px;
  color: var(--tx3);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.3;
}

.bn-runs-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.bn-runs-actions button:disabled,
.bn-runs-filter:disabled {
  cursor: default !important;
  opacity: .45;
}

.bn-run-detail-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.bn-runs-analytics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
  border-bottom: 1px solid var(--line);
}

.bn-runs-metric {
  min-width: 0;
  padding: 8px 7px;
  background: var(--panel);
}

.bn-runs-metric span,
.bn-runs-metric small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bn-runs-metric span {
  color: var(--tx1);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
}

.bn-runs-metric small {
  margin-top: 2px;
  color: var(--tx3);
  font-size: 9px;
  text-transform: uppercase;
}

.bn-runs-metric.is-muted span {
  color: var(--tx3);
}

.bn-runs-filters {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
  border-bottom: 1px solid var(--line);
}

.bn-runs-filter {
  min-width: 0;
  height: 34px;
  background: var(--panel);
  border: 0;
  color: var(--tx3);
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 10px;
  line-height: 1.1;
}

.bn-runs-filter span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bn-runs-filter span + span {
  margin-top: 2px;
  color: var(--tx2);
  font-family: var(--font-mono);
  font-weight: 700;
}

.bn-runs-filter:hover:not(:disabled),
.bn-runs-filter.is-active {
  background: var(--menu-active);
  color: var(--tx1);
}

.bn-runs-error {
  padding: 8px 12px;
  color: var(--err);
  border-bottom: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.bn-runs-error.is-inline {
  padding: 0;
  border-bottom: 0;
}

.bn-runs-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.bn-runs-empty {
  padding: 16px;
  color: var(--tx3);
  font-size: 12px;
  line-height: 1.5;
}

.bn-run-row {
  --run-status: var(--tx3);
  border-bottom: 1px solid var(--line);
  background: transparent;
}

.bn-run-row.is-expanded {
  background: color-mix(in srgb, var(--menu-active) 36%, transparent);
}

.bn-run-summary {
  width: 100%;
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) auto;
  align-items: stretch;
  gap: 8px;
  padding: 9px 10px 9px 6px;
  background: transparent;
  border: 0;
  color: var(--tx2);
  cursor: pointer;
  font-family: var(--font-ui);
  text-align: left;
}

.bn-run-summary:hover {
  background: var(--hover);
}

.bn-run-timeline-mark {
  position: relative;
  display: flex;
  justify-content: center;
  min-height: 58px;
}

.bn-run-timeline-mark::before {
  content: '';
  width: 1px;
  background: var(--line2);
  position: absolute;
  top: -9px;
  bottom: -9px;
}

.bn-run-timeline-mark span {
  position: relative;
  z-index: 1;
  width: 9px;
  height: 9px;
  margin-top: 7px;
  border-radius: 50%;
  background: var(--run-status);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--run-status) 18%, transparent);
}

.bn-run-main {
  min-width: 0;
}

.bn-run-line {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.bn-run-index {
  color: var(--tx3);
  font-family: var(--font-mono);
  font-size: 9px;
  flex: 0 0 auto;
}

.bn-run-title {
  min-width: 0;
  color: var(--tx1);
  font-size: 12px;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bn-run-age {
  margin-left: auto;
  color: var(--tx3);
  font-family: var(--font-mono);
  font-size: 10px;
  flex: 0 0 auto;
}

.bn-run-node {
  margin-top: 2px;
  color: var(--tx3);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bn-run-node span {
  color: color-mix(in srgb, var(--tx3) 76%, transparent);
}

.bn-run-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.bn-run-badges span {
  max-width: 100%;
  padding: 2px 5px;
  color: var(--tx3);
  background: var(--lift);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 9px;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bn-run-error-line {
  margin-top: 6px;
  color: var(--err);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bn-run-status {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  color: var(--tx3);
  font-family: var(--font-mono);
  font-size: 10px;
  white-space: nowrap;
}

.bn-run-status-pill {
  min-width: 34px;
  padding: 2px 5px;
  color: var(--run-status);
  border: 1px solid var(--run-status);
  border-radius: 4px;
  font-size: 9px;
  font-weight: 800;
  text-align: center;
}

.bn-run-detail {
  padding: 11px 12px 13px 22px;
  background: var(--bg);
  border-top: 1px solid var(--line);
}

.bn-run-detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.bn-run-detail-title {
  color: var(--tx1);
  font-size: 12px;
  font-weight: 650;
}

.bn-run-id,
.bn-run-loading {
  color: var(--tx3);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.45;
}

.bn-run-id {
  max-width: 100%;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bn-run-facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 10px;
}

.bn-run-fact {
  min-width: 0;
  padding: 6px 7px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 5px;
}

.bn-run-fact span,
.bn-run-fact strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bn-run-fact span {
  color: var(--tx3);
  font-size: 9px;
  text-transform: uppercase;
}

.bn-run-fact strong {
  margin-top: 2px;
  color: var(--tx2);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
}

.bn-run-event-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: 10px 0 8px;
}

.bn-run-event-stats span {
  padding: 2px 6px;
  color: var(--tx3);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 9px;
}

.bn-replay-panel {
  margin: 10px 0;
  padding: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.bn-replay-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.bn-replay-title {
  color: var(--tx1);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
}

.bn-replay-subtitle,
.bn-replay-count {
  color: var(--tx3);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bn-replay-subtitle {
  max-width: 210px;
  margin-top: 2px;
}

.bn-replay-count {
  color: var(--accent);
  flex: 0 0 auto;
}

.bn-replay-scrub {
  margin: 8px 0 7px;
}

.bn-replay-scrub input {
  width: 100%;
  accent-color: var(--accent);
}

.bn-replay-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.bn-replay-actions button,
.bn-replay-actions select {
  min-height: 24px;
  background: transparent;
  border: 1px solid var(--line2);
  border-radius: 4px;
  color: var(--tx2);
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 10px;
  padding: 3px 7px;
}

.bn-replay-actions select {
  background: var(--panel);
  max-width: 86px;
}

.bn-replay-actions button:hover:not(:disabled),
.bn-replay-actions select:hover {
  background: var(--hover);
  border-color: var(--accent);
  color: var(--tx1);
}

.bn-replay-actions button:disabled {
  cursor: default;
  opacity: .45;
}

.bn-event-timeline {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.bn-event-row {
  --event-color: var(--tx3);
  display: grid;
  grid-template-columns: 43px 13px minmax(0, 1fr);
  gap: 6px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  text-align: left;
  outline: none;
}

.bn-event-row:hover {
  background: var(--hover);
}

.bn-event-row.is-active {
  background: color-mix(in srgb, var(--event-color) 11%, transparent);
  box-shadow: inset 2px 0 0 var(--event-color);
}

.bn-event-row:focus-visible {
  box-shadow: inset 0 0 0 1px var(--accent);
}

.bn-event-time {
  padding-top: 4px;
  color: var(--tx3);
  font-family: var(--font-mono);
  font-size: 9px;
  line-height: 1.2;
  text-align: right;
}

.bn-event-time span,
.bn-event-time small {
  display: block;
}

.bn-event-time small {
  margin-top: 2px;
  color: color-mix(in srgb, var(--tx3) 68%, transparent);
}

.bn-event-dot {
  position: relative;
  min-height: 34px;
}

.bn-event-dot::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 6px;
  width: 1px;
  background: var(--line2);
}

.bn-event-dot::after {
  content: '';
  position: absolute;
  top: 6px;
  left: 3px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--event-color);
}

.bn-event-body {
  min-width: 0;
  padding: 3px 0 8px;
}

.bn-event-head {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}

.bn-event-label {
  color: var(--event-color);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  flex: 0 0 auto;
}

.bn-event-node {
  min-width: 0;
  color: var(--tx2);
  font-family: var(--font-mono);
  font-size: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bn-event-detail {
  margin-top: 2px;
  color: var(--tx3);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bn-payload {
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel);
  overflow: hidden;
}

.bn-payload-error {
  border-color: color-mix(in srgb, var(--err) 42%, var(--line));
  background: color-mix(in srgb, var(--err) 8%, var(--panel));
}

.bn-payload-value {
  border-color: color-mix(in srgb, var(--ok) 28%, var(--line));
}

.bn-payload-event {
  margin-top: 5px;
  background: var(--bg);
}

.bn-payload summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  padding: 5px 7px;
  color: var(--tx2);
  cursor: pointer;
  font-size: 10px;
  font-weight: 650;
  list-style-position: inside;
}

.bn-payload summary small {
  color: var(--tx3);
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 400;
  white-space: nowrap;
}

.bn-payload pre {
  max-height: 220px;
  padding: 7px;
  overflow: auto;
  border-top: 1px solid var(--line);
  color: var(--tx2);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.bn-payload-error pre {
  color: var(--err);
}

/* scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--tx3); }
