/* ============================================================
   BOTICA STUDIO v2 — Flow Builder visual upgrade
   Layered on top of screens.css studio rules; matches the
   "Botica Flow Builder" design handoff.
   ============================================================ */

/* ── Theme tokens — light mode (default) ───────────────── */
.studio-screen {
  --fb-canvas-bg:  #F0F3FA;
  --fb-canvas-dot: rgba(14, 21, 37, 0.07);
  --fb-node-bg:    #FFFFFF;
  --fb-node-border: #E2E6F0;
  --fb-node-sel:   rgba(53, 88, 240, 0.5);
  --fb-node-run:   rgba(217, 119, 6, 0.7);
  --fb-node-done:  rgba(22, 163, 74, 0.6);
  --fb-conn-idle:  rgba(100, 116, 139, 0.22);
  --fb-sb-bg:      #FFFFFF;
  --fb-tb-bg:      rgba(240, 243, 250, 0.96);
  --fb-st-bg:      #E8ECF5;
  --fb-inp-bg:     rgba(14, 21, 37, 0.05);
  --fb-blue:       #3558F0;
  --fb-green:      #22C773;
  --fb-t1: #0E1525;
  --fb-t2: #5B6685;
  --fb-t3: #9BA3BB;

  /* Node type accents */
  --fb-c-trigger: #22C773;
  --fb-c-input:   #3558F0;
  --fb-c-skill:   #EC4899;
  --fb-c-output:  #0EA5E9;
  --fb-c-search:  #06B6D4;
  --fb-c-logic:   #F59E0B;
  --fb-c-ai:      #8B5CF6;
  --fb-c-save:    #7C3AED;

  /* Surface / border tokens that flip between modes */
  --fb-border-soft:        rgba(14, 21, 37, 0.08);
  --fb-border-medium:      rgba(14, 21, 37, 0.10);
  --fb-border-strong:      rgba(14, 21, 37, 0.14);
  --fb-surface-hover:      rgba(14, 21, 37, 0.05);
  --fb-surface-subtle:     rgba(14, 21, 37, 0.04);
  --fb-surface-chip:       rgba(14, 21, 37, 0.07);
  --fb-shadow-node:        0 2px 10px rgba(14,21,37,0.10), 0 1px 3px rgba(14,21,37,0.07);
  --fb-shadow-node-hover:  0 4px 18px rgba(14,21,37,0.14);
  --fb-edge-hover:         rgba(14, 21, 37, 0.35);
  --fb-textarea-bg:        rgba(14, 21, 37, 0.04);
  --fb-textarea-color:     var(--fb-t2);
  --fb-node-hover-border:  rgba(14, 21, 37, 0.20);
}

/* ── Theme tokens — dark mode ──────────────────────────── */
body.dark .studio-screen {
  --fb-canvas-bg:  #0B1020;
  --fb-canvas-dot: rgba(148, 163, 184, 0.07);
  --fb-node-bg:    #141C30;
  --fb-node-border: rgba(255, 255, 255, 0.08);
  --fb-node-sel:   rgba(53, 88, 240, 0.7);
  --fb-node-run:   rgba(245, 158, 11, 0.7);
  --fb-node-done:  rgba(34, 199, 115, 0.6);
  --fb-conn-idle:  rgba(148, 163, 184, 0.22);
  --fb-sb-bg:      #0E1525;
  --fb-tb-bg:      rgba(10, 15, 28, 0.96);
  --fb-st-bg:      #070D1C;
  --fb-inp-bg:     rgba(255, 255, 255, 0.05);
  --fb-t1: #E4E9F7;
  --fb-t2: #7B8BAD;
  --fb-t3: #3A4862;

  --fb-border-soft:        rgba(255, 255, 255, 0.06);
  --fb-border-medium:      rgba(255, 255, 255, 0.08);
  --fb-border-strong:      rgba(255, 255, 255, 0.14);
  --fb-surface-hover:      rgba(255, 255, 255, 0.05);
  --fb-surface-subtle:     rgba(255, 255, 255, 0.04);
  --fb-surface-chip:       rgba(255, 255, 255, 0.07);
  --fb-shadow-node:        0 4px 18px rgba(0, 0, 0, 0.4), 0 1px 4px rgba(0, 0, 0, 0.3);
  --fb-shadow-node-hover:  0 8px 28px rgba(0, 0, 0, 0.5);
  --fb-edge-hover:         rgba(255, 255, 255, 0.4);
  --fb-textarea-bg:        rgba(0, 0, 0, 0.3);
  --fb-textarea-color:     #7B9BB8;
  --fb-node-hover-border:  rgba(255, 255, 255, 0.15);
}

/* ── Canvas grid background ────────────────────────────── */
.studio-screen .studio-canvas-container,
.studio-screen .ci {
  background-color: var(--fb-canvas-bg);
  background-image: radial-gradient(circle, var(--fb-canvas-dot) 1px, transparent 1px);
  background-size: 24px 24px;
}

/* ── Sidebar / palette ─────────────────────────────────── */
.studio-screen .studio-palette {
  background: var(--fb-sb-bg);
  border-right: 1px solid var(--fb-border-soft);
}
.studio-screen .studio-palette__group-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fb-t3);
  padding: 8px 6px 4px;
}
.studio-screen .studio-palette__item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 8px;
  border-radius: 7px;
  font-size: 11.5px;
  color: var(--fb-t2);
  border: 1px solid transparent;
  transition: all 0.12s;
}
.studio-screen .studio-palette__item:hover {
  background: var(--fb-surface-hover);
  color: var(--fb-t1);
  border-color: var(--fb-border-soft);
}

/* ── Node card ─────────────────────────────────────────── */
.studio-screen .studio-node {
  background: var(--fb-node-bg);
  border: 1px solid var(--fb-node-border);
  border-radius: 11px;
  overflow: hidden;
  box-shadow: var(--fb-shadow-node);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.12s;
}
.studio-screen .studio-node:hover {
  border-color: var(--fb-node-hover-border);
  transform: translateY(-1px);
  box-shadow: var(--fb-shadow-node-hover);
}
.studio-screen .studio-node--selected {
  border-color: var(--fb-node-sel);
  box-shadow: 0 0 0 1px rgba(53, 88, 240, 0.25), var(--fb-shadow-node-hover);
}
/* Multi-select: lighter blue ring — distinct from primary selection */
.studio-screen .studio-node--multi-sel {
  border-color: rgba(99, 179, 237, 0.55);
  box-shadow: 0 0 0 2px rgba(99, 179, 237, 0.18);
}
/* Search highlight: amber ring */
.studio-screen .studio-node--search-highlight {
  border-color: rgba(246, 173, 85, 0.8) !important;
  box-shadow: 0 0 0 2px rgba(246, 173, 85, 0.2) !important;
  animation: studio-search-pulse 1.2s ease-in-out infinite;
}
@keyframes studio-search-pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(246,173,85,.2); }
  50%       { box-shadow: 0 0 0 5px rgba(246,173,85,.08); }
}
/* Floating node-search bar */
.studio-node-search {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 8px;
  background: #1a2540;
  border: 1px solid rgba(99, 179, 237, 0.45);
  border-radius: 8px;
  padding: 6px 14px;
  box-shadow: 0 4px 20px rgba(0,0,0,.45);
}
.studio-node-search input {
  background: transparent;
  border: none;
  outline: none;
  color: #e2e8f0;
  font-size: 13px;
  width: 200px;
  direction: rtl;
}
.studio-node-search input::placeholder { color: rgba(255,255,255,.3); }
.studio-node-search__count {
  font-size: 11px;
  color: rgba(255,255,255,.4);
  white-space: nowrap;
}
.studio-screen .studio-node.running {
  border-color: var(--fb-node-run);
}
.studio-screen .studio-node.done {
  border-color: var(--fb-node-done);
}

/* Per-type header colors. Node classes are `studio-node--<type>` where type
   is one of trigger_manual, input_text, search_hybrid, ai_prompt, etc. We
   match by prefix so all variants of a category share the same accent. */
.studio-screen .studio-node .sn-header {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px 7px 8px;
  position: relative;
}
.studio-screen .studio-node .sn-label {
  flex: 1;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  line-height: 1;
  letter-spacing: -0.01em;
}
.studio-screen .studio-node .sn-icon {
  width: 20px;
  height: 20px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 13px;
}
.studio-screen .studio-node .sn-delete {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.45);
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s;
}
.studio-screen .studio-node .sn-delete:hover {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

/* Help button */
.studio-screen .studio-node .sn-help-btn {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: transparent;
  color: rgba(255, 255, 255, 0.55);
  cursor: pointer;
  font-size: 9px;
  font-weight: 700;
  font-family: sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.12s;
  line-height: 1;
  padding: 0;
}
.studio-screen .studio-node .sn-help-btn:hover,
.studio-screen .studio-node .sn-help-btn.sn-help-btn--active {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.65);
}

/* Help popup panel — appended to <body> with fixed positioning so the canvas
   container's overflow:hidden can never clip it (see _toggleHelp in canvas.js) */
.sn-help-popup {
  position: fixed;
  z-index: 10000;
  background: #1a2336;
  border: 1px solid rgba(99, 179, 237, 0.35);
  border-radius: 8px;
  padding: 10px 12px 13px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.55);
  pointer-events: auto;
}
.sn-help-popup__title {
  font-size: 11.5px;
  font-weight: 700;
  color: #63b3ed;
  margin-bottom: 7px;
  direction: ltr;
  letter-spacing: 0.01em;
}
.sn-help-popup__text {
  font-size: 11.5px;
  color: rgba(220, 230, 245, 0.88);
  line-height: 1.65;
  direction: rtl;
  white-space: pre-line;
}

/* Multi-select (checkbox list) field — used by the AI Agent node toolset pickers */
.studio-screen .studio-node .sn-multiselect {
  max-height: 96px;
  overflow-y: auto;
  border: 1px solid var(--fb-node-border, rgba(255,255,255,0.12));
  border-radius: 7px;
  padding: 4px 6px;
  background: rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.studio-screen .studio-node .sn-ms-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
}
.studio-screen .studio-node .sn-ms-item input[type="checkbox"] {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  cursor: pointer;
}
.studio-screen .studio-node .sn-ms-empty {
  font-size: 11px;
  opacity: 0.6;
  padding: 2px 0;
}

/* Type accents */
.studio-screen [class*="studio-node--trigger"]      .sn-header { background: var(--fb-c-trigger); }
.studio-screen [class*="studio-node--input"]        .sn-header { background: var(--fb-c-input); }
.studio-screen [class*="studio-node--skill"]        .sn-header,
.studio-screen .studio-node--skill_run              .sn-header { background: var(--fb-c-skill); }
.studio-screen [class*="studio-node--mcp"]          .sn-header { background: var(--fb-c-skill); }
.studio-screen [class*="studio-node--search"]       .sn-header { background: var(--fb-c-search); }
.studio-screen [class*="studio-node--ai"]           .sn-header { background: var(--fb-c-ai); }
.studio-screen [class*="studio-node--output"]       .sn-header { background: var(--fb-c-output); }
.studio-screen [class*="studio-node--condition"]    .sn-header,
.studio-screen [class*="studio-node--transform"]    .sn-header,
.studio-screen [class*="studio-node--logic"]        .sn-header { background: var(--fb-c-logic); }
.studio-screen .studio-node--output_save            .sn-header { background: var(--fb-c-save); }
/* New node types added post-launch */
.studio-screen .studio-node--http_request           .sn-header { background: var(--fb-c-search); }
.studio-screen .studio-node--switch                 .sn-header { background: var(--fb-c-logic); }
.studio-screen .studio-node--loop_foreach           .sn-header { background: var(--fb-c-input); }
.studio-screen .studio-node--set_variable           .sn-header { background: var(--fb-c-input); }
.studio-screen .studio-node--run_flow               .sn-header { background: var(--fb-c-ai); }

/* Node body (fields) */
.studio-screen .studio-node .sn-body {
  padding: 8px 10px 9px;
}
.studio-screen .studio-node .sn-field { margin-bottom: 7px; }
.studio-screen .studio-node .sn-field:last-child { margin-bottom: 0; }
.studio-screen .studio-node .sn-field-label {
  font-size: 9px;
  color: var(--fb-t3);
  margin-bottom: 3px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.studio-screen .studio-node .sn-field-input {
  padding: 4px 7px;
  border-radius: 5px;
  background: var(--fb-inp-bg);
  border: 1px solid var(--fb-border-soft);
  color: var(--fb-t1);
  font-size: 11px;
}
.studio-screen .studio-node textarea.sn-field-input {
  background: var(--fb-textarea-bg);
  border: 1px solid var(--fb-border-soft);
  color: var(--fb-textarea-color);
  font-family: 'JetBrains Mono', 'Consolas', monospace;
  font-size: 10px;
  line-height: 1.55;
  resize: vertical;
  min-height: 54px;
}

/* ── Connections (SVG paths) ──────────────────────────── */
.studio-screen .studio-edge,
.studio-screen .studio-edge-path {
  stroke: var(--fb-conn-idle);
  stroke-width: 1.8;
  fill: none;
  transition: stroke 0.2s, stroke-width 0.15s;
}
.studio-screen .studio-edge:hover,
.studio-screen .studio-edge-path:hover {
  stroke: var(--fb-edge-hover);
  stroke-width: 2.4;
}
.studio-screen .studio-edge.running,
.studio-screen .studio-edge-path.running {
  stroke: rgba(53, 88, 240, 0.9);
  stroke-dasharray: 10 6;
  stroke-width: 2;
  animation: fbFlow 0.5s linear infinite;
}
.studio-screen .studio-edge.done,
.studio-screen .studio-edge-path.done {
  stroke: var(--fb-green);
}
@keyframes fbFlow { to { stroke-dashoffset: -16; } }

/* Edge hit area — wide transparent stroke for easy clicking */
.studio-screen .studio-edge-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 14;
  pointer-events: stroke;
  cursor: pointer;
}
/* Edge hover — amber tint signals "selectable" */
.studio-screen .studio-edge--hovered {
  stroke: #f59e0bcc;
  stroke-width: 2.4;
}
/* Edge selected — blue highlight, stays until deselected */
.studio-screen .studio-edge--selected {
  stroke: #3b82f6;
  stroke-width: 3;
}
/* Delete edge toolbar button */
.studio-screen .studio-topbar__btn--delete-edge {
  border-color: rgba(239,68,68,0.45);
  color: #f87171;
}
.studio-screen .studio-topbar__btn--delete-edge:hover {
  border-color: #ef4444;
  color: #ef4444;
  background: rgba(239,68,68,0.1);
}

/* ── Toolbar ──────────────────────────────────────────── */
.studio-screen .studio-topbar-wrap {
  background: var(--fb-tb-bg);
  border-bottom: 1px solid var(--fb-border-medium);
  height: 46px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 12px;
}
.studio-screen .studio-topbar-wrap .studio-toolbar__btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  border-radius: 7px;
  border: 1px solid var(--fb-border-medium);
  background: var(--fb-surface-subtle);
  color: var(--fb-t2);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.12s;
}
.studio-screen .studio-topbar-wrap .studio-toolbar__btn:hover {
  background: var(--fb-surface-hover);
  color: var(--fb-t1);
  border-color: var(--fb-border-strong);
}
.studio-screen .studio-topbar-wrap .studio-toolbar__btn--run {
  padding: 6px 15px;
  background: var(--fb-blue);
  color: #fff;
  border: none;
  font-weight: 600;
  font-size: 13px;
  box-shadow: 0 2px 12px rgba(53, 88, 240, 0.45);
}
.studio-screen .studio-topbar-wrap .studio-toolbar__btn--run:hover {
  background: #2545D9;
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(53, 88, 240, 0.5);
}

/* ── Status bar ───────────────────────────────────────── */
.studio-screen .studio-statusbar {
  height: 25px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  background: var(--fb-st-bg);
  border-top: 1px solid var(--fb-border-soft);
  font-size: 10.5px;
  color: var(--fb-t3);
  direction: rtl;
}
.studio-screen .studio-statusbar::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--fb-green);
  display: inline-block;
}
.studio-screen .studio-statusbar.running::before { background: #F59E0B; }
.studio-screen .studio-statusbar.error::before   { background: #F87171; }

/* ── Flows panel (right side) ─────────────────────────── */
.studio-screen .studio-flows-panel {
  width: 210px;
  flex-shrink: 0;
  background: var(--fb-sb-bg);
  border-left: 1px solid var(--fb-border-soft);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  direction: rtl;
  position: relative;
  min-width: 180px;
  max-width: 520px;
}

/* Drag-to-resize handle — sits on the LEFT edge (adjacent to canvas in RTL layout) */
.studio-panel-resizer {
  position: absolute;
  left: -3px;
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: col-resize;
  z-index: 20;
  transition: background .12s;
  border-radius: 4px;
}
.studio-panel-resizer::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 28px;
  background: rgba(255,255,255,.08);
  border-radius: 1px;
  transition: background .12s;
}
.studio-panel-resizer:hover::after,
.studio-panel-resizer.dragging::after {
  background: rgba(99,179,237,.55);
}
.studio-panel-resizer:hover,
.studio-panel-resizer.dragging {
  background: rgba(99,179,237,.08);
}

/* Prevent text selection + force cursor while dragging */
body.studio-panel-resizing {
  cursor: col-resize !important;
  user-select: none !important;
}
body.studio-panel-resizing * {
  cursor: col-resize !important;
}

/* ── Saved Flows list section inside flows panel ────── */
.studio-screen .studio-flows-section {
  padding: 0 6px 8px;
  flex: 1;
}
.studio-screen .studio-flows-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 4px 6px;
}
.studio-screen .studio-flows-lbl {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fb-t3);
}
.studio-screen .studio-flows-count {
  font-size: 9px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--fb-surface-chip);
  color: var(--fb-t2);
}
.studio-screen .studio-flows-add {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: none;
  background: var(--fb-surface-chip);
  color: var(--fb-t2);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
}
.studio-screen .studio-flows-add:hover {
  background: rgba(53, 88, 240, 0.2);
  color: #7EA8FF;
}
.studio-screen .studio-flows-search {
  position: relative;
  margin-bottom: 6px;
}
.studio-screen .studio-flows-search input {
  width: 100%;
  padding: 5px 8px;
  background: var(--fb-surface-subtle);
  border: 1px solid var(--fb-border-soft);
  border-radius: 6px;
  color: var(--fb-t1);
  font-size: 10.5px;
  outline: none;
  direction: rtl;
}
.studio-screen .studio-flows-search input:focus {
  border-color: rgba(53, 88, 240, 0.35);
}
.studio-screen .studio-flow-item {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  padding: 7px 8px 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.12s;
}
.studio-screen .studio-flow-item:hover {
  background: var(--fb-surface-hover);
  border-color: var(--fb-border-soft);
}
.studio-screen .studio-flow-item.current {
  background: rgba(53, 88, 240, 0.12);
  border-color: rgba(53, 88, 240, 0.25);
}
.studio-screen .studio-flow-item-icon {
  width: 28px; height: 28px;
  border-radius: 7px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--fb-surface-chip);
  color: var(--fb-t2);
  font-size: 14px;
}
.studio-screen .studio-flow-item.current .studio-flow-item-icon {
  background: rgba(53, 88, 240, 0.2);
  color: #7EA8FF;
}
.studio-screen .studio-flow-item-main { flex: 1; min-width: 0; }
.studio-screen .studio-flow-item-name {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--fb-t2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}
.studio-screen .studio-flow-item:hover .studio-flow-item-name,
.studio-screen .studio-flow-item.current .studio-flow-item-name { color: var(--fb-t1); }
.studio-screen .studio-flow-item-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 3px;
}
.studio-screen .studio-flow-item-status {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 9.5px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 3px;
}
.studio-screen .studio-flow-item-status.st-active  { background: rgba(34, 199, 115, 0.12); color: #22C773; }
.studio-screen .studio-flow-item-status.st-paused  { background: rgba(148, 163, 184, 0.1);  color: var(--fb-t3); }
.studio-screen .studio-flow-item-status.st-error   { background: rgba(239, 68, 68, 0.12);   color: #F87171; }
.studio-screen .studio-flow-item-status.st-draft   { background: rgba(245, 158, 11, 0.1);   color: #FBBF24; }
.studio-screen .studio-flow-item-status.st-shared  { background: rgba(99, 179, 237, 0.12);  color: #63B3ED; }
.studio-screen .studio-flow-item-nodes {
  font-size: 9.5px;
  color: var(--fb-t3);
}
.studio-screen .studio-flow-item-time {
  font-size: 9.5px;
  color: var(--fb-t3);
  margin-right: auto;
}

/* ── Run history section in flows panel ─────────────────────────────── */
.studio-screen .studio-run-history-sec {
  border-top: 1px solid var(--fb-border-soft);
  margin-top: 4px;
}
.studio-screen .studio-run-history-list {
  padding: 2px 0 6px;
}
.studio-screen .studio-run-history-item {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 5px 10px;
  cursor: default;
  transition: background .12s;
}
.studio-screen .studio-run-history-item:hover {
  background: rgba(255,255,255,.04);
}
.studio-screen .studio-run-history-when {
  font-size: 10px;
  color: var(--fb-t2);
  display: flex;
  gap: 4px;
  align-items: center;
}
.studio-screen .studio-run-history-input {
  font-size: 10px;
  color: var(--fb-t3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 170px;
}

/* ── Tutorial ──────────────────────────────────────────────── */

.tutorial-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  z-index: 3000;
  animation: tut-fade-in .2s ease;
}

@keyframes tut-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.tutorial-card {
  position: fixed;
  z-index: 3001;
  background: #1A2540;
  border: 1px solid rgba(99, 179, 237, 0.35);
  border-radius: 14px;
  padding: 18px 20px 16px;
  width: 310px;
  box-shadow: 0 8px 32px rgba(0,0,0,.45);
  direction: rtl;
  font-family: inherit;
  animation: tut-slide-in .2s ease;
}

@keyframes tut-slide-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.tutorial-card--modal {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.tutorial-card--floating {
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
}

.tutorial-card__close {
  position: absolute;
  top: 10px;
  left: 12px;
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,.4);
  font-size: 14px;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 4px;
  transition: color .15s, background .15s;
}
.tutorial-card__close:hover {
  color: #fff;
  background: rgba(255,255,255,.1);
}

.tutorial-card__title {
  font-size: 14px;
  font-weight: 700;
  color: #63b3ed;
  margin-bottom: 8px;
  padding-left: 20px;
}

.tutorial-card__body {
  font-size: 12.5px;
  color: rgba(255,255,255,.82);
  line-height: 1.6;
  white-space: pre-line;
  margin-bottom: 12px;
}

.tutorial-card__progress {
  height: 3px;
  background: rgba(255,255,255,.12);
  border-radius: 2px;
  margin-bottom: 12px;
  overflow: hidden;
}

.tutorial-card__progress-fill {
  height: 100%;
  background: #63b3ed;
  border-radius: 2px;
  transition: width .3s ease;
}

.tutorial-card__footer {
  display: flex;
  justify-content: flex-start;
  gap: 8px;
  align-items: center;
}

.tutorial-card__skip {
  background: none;
  border: 1px solid rgba(255,255,255,.2);
  color: rgba(255,255,255,.55);
  font-size: 11px;
  padding: 5px 12px;
  border-radius: 7px;
  cursor: pointer;
  transition: all .15s;
}
.tutorial-card__skip:hover {
  border-color: rgba(255,255,255,.4);
  color: rgba(255,255,255,.85);
}

.tutorial-card__next {
  background: #3558F0;
  border: none;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s;
}
.tutorial-card__next:hover {
  background: #4a6bf5;
}

/* Glow highlight on targeted elements */
.tutorial-highlight {
  outline: 2px solid #63b3ed !important;
  outline-offset: 3px !important;
  border-radius: 6px;
  box-shadow: 0 0 0 4px rgba(99, 179, 237, 0.25) !important;
  animation: tut-glow-pulse 1.4s ease-in-out infinite;
  position: relative;
  z-index: 2500 !important;
}

@keyframes tut-glow-pulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(99, 179, 237, 0.25) !important; }
  50%       { box-shadow: 0 0 0 8px rgba(99, 179, 237, 0.12) !important; }
}

/* ── Monitoring — token cards + run detail (theme-aware) ──────────────────── */
.studio-monitor__cards--tokens .studio-monitor__card-val { font-size:13px; }
.studio-monitor__card.tok  .studio-monitor__card-val { color:#7c3aed; }
.studio-monitor__card.dim  .studio-monitor__card-val { color:var(--fb-t3); font-size:12px; }
.studio-monitor__card.ok   .studio-monitor__card-val { color:#16a34a; }
.studio-monitor__card.warn .studio-monitor__card-val { color:#d97706; }

/* Run detail summary */
.studio-monitor__detail { display:flex; flex-direction:column; gap:8px; padding:6px 0; }
.studio-monitor__detail-loading { padding:8px; font-size:11px; color:var(--fb-t3); }
.studio-monitor__detail-summary {
  background: var(--fb-inp-bg); border-radius:6px;
  padding:7px 10px; display:flex; flex-direction:column; gap:4px;
}
.studio-monitor__sum-line { display:flex; align-items:baseline; gap:6px; font-size:11px; }
.studio-monitor__sum-status { font-weight:600; }
.studio-monitor__sum-status.ok  { color:#16a34a; }
.studio-monitor__sum-status.err { color:#ef4444; }
.studio-monitor__sum-lbl { color:var(--fb-t3); flex-shrink:0; }
.studio-monitor__sum-val { color:var(--fb-t1); }
.studio-monitor__tok-in  { color:#2563eb; }
.studio-monitor__tok-out { color:#7c3aed; }
.studio-monitor__tok-model { color:var(--fb-t3); font-size:10px; }
.studio-monitor__sum-output { display:flex; gap:6px; font-size:11px; align-items:flex-start; }
.studio-monitor__sum-out-txt { color:var(--fb-t2); font-style:italic; line-height:1.4; }

/* ── Execution graph ──────────────────────────────────────────────────────── */
.studio-monitor__graph-hd {
  font-size: 10px;
  font-weight: 600;
  color: var(--fb-t3);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 4px;
}
.studio-monitor__graph {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.studio-monitor__step {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.studio-monitor__step-box {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-size: 11px;
  font-weight: 600;
  transition: filter .1s;
}
/* Node type colors */
.studio-monitor__step-box.trigger  { background:rgba(99,179,237,.12); border-color:rgba(99,179,237,.25); color:#90cdf4; }
.studio-monitor__step-box.input    { background:rgba(154,230,180,.1);  border-color:rgba(154,230,180,.2); color:#9ae6b4; }
.studio-monitor__step-box.search   { background:rgba(246,173,85,.1);   border-color:rgba(246,173,85,.2);  color:#f6ad55; }
.studio-monitor__step-box.ai       { background:rgba(183,148,244,.12); border-color:rgba(183,148,244,.25);color:#b794f4; }
.studio-monitor__step-box.skill    { background:rgba(183,148,244,.1);  border-color:rgba(183,148,244,.2); color:#d6bcfa; }
.studio-monitor__step-box.mcp      { background:rgba(246,173,85,.08);  border-color:rgba(246,173,85,.18); color:#fbd38d; }
.studio-monitor__step-box.cond     { background:rgba(237,137,54,.1);   border-color:rgba(237,137,54,.2);  color:#f6ad55; }
.studio-monitor__step-box.tf       { background:rgba(160,174,192,.08); border-color:rgba(160,174,192,.15);color:#a0aec0; }
.studio-monitor__step-box.output   { background:rgba(72,187,120,.1);   border-color:rgba(72,187,120,.2);  color:#68d391; }
.studio-monitor__step-box.other    { background:var(--fb-inp-bg); border-color:var(--fb-border-soft); color:var(--fb-t2); }
.studio-monitor__step-box.err      { background:rgba(239,68,68,.1) !important; border-color:rgba(239,68,68,.3) !important; color:#ef4444 !important; }
.studio-monitor__step-lbl  { flex:1; }
.studio-monitor__step-tok  { font-size:9px; font-weight:400; opacity:.75; white-space:nowrap; }

/* Duration bar */
.studio-monitor__step-bar-wrap {
  height: 3px;
  background: var(--fb-border-soft);
  border-radius: 2px;
  overflow: hidden;
}
.studio-monitor__step-bar { height:100%; border-radius:2px; min-width:4px; }
.studio-monitor__step-bar.trigger  { background:#90cdf4; }
.studio-monitor__step-bar.input    { background:#9ae6b4; }
.studio-monitor__step-bar.search   { background:#f6ad55; }
.studio-monitor__step-bar.ai       { background:#b794f4; }
.studio-monitor__step-bar.skill    { background:#d6bcfa; }
.studio-monitor__step-bar.mcp      { background:#fbd38d; }
.studio-monitor__step-bar.cond     { background:#f6ad55; }
.studio-monitor__step-bar.tf       { background:#a0aec0; }
.studio-monitor__step-bar.output   { background:#68d391; }
.studio-monitor__step-bar.other    { background:#e2e8f0; }
.studio-monitor__step-bar.err      { background:#fc8181; }

.studio-monitor__step-ms {
  font-size: 10px;
  color: var(--fb-t3);
  padding-right: 2px;
}
.studio-monitor__step-err {
  font-size: 10px;
  color: #ef4444;
  padding: 2px 4px;
  background: rgba(239,68,68,.08);
  border-radius: 4px;
}
.studio-monitor__step-arrow {
  text-align: center;
  font-size: 10px;
  color: var(--fb-t3);
  line-height: 1;
  padding: 1px 0;
}

/* Input/output snippets */
.studio-monitor__step-snippets {
  background: rgba(0,0,0,.2);
  border-radius: 4px;
  padding: 5px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.studio-monitor__snippet { display:flex; flex-direction:column; gap:2px; }
.studio-monitor__snip-lbl { font-size:9px; color:rgba(255,255,255,.3); text-transform:uppercase; letter-spacing:.3px; }
.studio-monitor__snip-txt {
  font-size: 10px;
  color: rgba(255,255,255,.6);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.4;
}

/* ── Template cards ──────────────────────────────────────────────────────── */
.studio-template-card {
  margin: 4px 6px;
  padding: 9px 10px;
  background: var(--fb-inp-bg);
  border: 1px solid var(--fb-border-soft);
  border-radius: 8px;
  cursor: default;
  transition: border-color .12s, background .12s;
}
.studio-template-card:hover {
  border-color: rgba(53,88,240,.25);
  background: rgba(53,88,240,.04);
}
/* Template badge on flow item */
.studio-flow-item-tpl {
  font-size: 11px;
}

/* ── Flow category filter pills ──────────────────────────────────────────── */
.studio-flows-cats {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px 6px 6px;
}
.studio-flows-cat-pill {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 10px;
  border: 1px solid var(--fb-border-soft);
  background: transparent;
  color: var(--fb-t2);
  cursor: pointer;
  transition: all .12s;
  white-space: nowrap;
}
.studio-flows-cat-pill:hover      { background: var(--fb-inp-bg); }
.studio-flows-cat-pill.active     { background: rgba(53,88,240,.1); border-color: rgba(53,88,240,.3); color: #3558F0; font-weight: 600; }

/* Category badge on flow items */
.studio-flow-item-cat {
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 8px;
  background: rgba(53,88,240,.08);
  color: #3558F0;
  border: 1px solid rgba(53,88,240,.2);
  white-space: nowrap;
}
/* Tag badge on flow items */
.studio-flow-item-tag {
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 8px;
  background: var(--fb-inp-bg);
  color: var(--fb-t3);
  border: 1px solid var(--fb-border-soft);
  white-space: nowrap;
}

/* ── Panel tabs (Flows / Monitoring) ──────────────────────────────────────── */
.studio-panel-tabs {
  display: flex;
  gap: 2px;
  padding: 6px 8px 0;
  border-bottom: 1px solid var(--fb-border-soft);
  flex-shrink: 0;
}
.studio-panel-tab {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--fb-t3);
  font-size: 11px;
  font-weight: 500;
  padding: 5px 4px 6px;
  cursor: pointer;
  border-radius: 4px 4px 0 0;
  transition: color .15s, border-color .15s;
  white-space: nowrap;
}
.studio-panel-tab:hover { color: var(--fb-t2); }
.studio-panel-tab--active {
  color: var(--fb-blue, #3558F0);
  border-bottom-color: var(--fb-blue, #3558F0);
}

/* The scrollable content below the tabs */
.studio-panel-content {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

/* ── Monitoring panel ─────────────────────────────────────────────────────── */
/* ── Monitoring panel — theme-aware (works in both light and dark) ─────────── */
.studio-monitor {
  padding: 10px 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.studio-monitor__loading,
.studio-monitor__empty {
  padding: 24px 8px;
  text-align: center;
  color: var(--fb-t3);
  font-size: 12px;
  white-space: pre-line;
  line-height: 1.7;
}

/* Summary cards */
.studio-monitor__cards { display:flex; gap:6px; }
.studio-monitor__card {
  flex: 1;
  background: var(--fb-inp-bg);
  border-radius: 8px;
  padding: 8px 4px;
  text-align: center;
  border: 1px solid var(--fb-border-soft);
}
.studio-monitor__card.warn .studio-monitor__card-val { color: #d97706; }
.studio-monitor__card-val {
  font-size: 15px;
  font-weight: 700;
  color: var(--fb-t1);
  line-height: 1.2;
}
.studio-monitor__card-lbl {
  font-size: 9px;
  color: var(--fb-t3);
  margin-top: 2px;
  letter-spacing: .3px;
}

/* Section */
.studio-monitor__section { display:flex; flex-direction:column; gap:6px; }
.studio-monitor__sec-hd {
  font-size: 10px;
  font-weight: 600;
  color: var(--fb-t3);
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* Daily chart */
.studio-monitor__chart {
  display: flex; align-items:flex-end; gap:2px; height:52px;
}
.studio-monitor__bar-col {
  flex:1; display:flex; flex-direction:column; align-items:center;
  gap:2px; height:100%; cursor:default;
}
.studio-monitor__bar-wrap {
  flex:1; display:flex; align-items:flex-end; width:100%;
}
.studio-monitor__bar {
  width:100%; min-height:2px; background:#3558F0;
  border-radius:2px 2px 0 0; opacity:.75; transition:opacity .1s;
}
.studio-monitor__bar:hover      { opacity:1; }
.studio-monitor__bar.has-errors { background:#ef4444; }
.studio-monitor__bar-lbl {
  font-size:8px; color:var(--fb-t3); white-space:nowrap;
}

/* Flow rows */
.studio-monitor__flow-row {
  border-radius: 6px; overflow:hidden;
  background: var(--fb-inp-bg);
  border: 1px solid var(--fb-border-soft);
}
.studio-monitor__flow-row.open { border-color: rgba(53,88,240,.25); }
.studio-monitor__flow-top {
  display:flex; align-items:flex-start; gap:5px;
  padding:7px 8px; cursor:pointer; flex-wrap:wrap;
}
.studio-monitor__flow-top:hover { background: var(--fb-inp-bg); filter:brightness(.97); }
.studio-monitor__arrow { font-size:9px; color:var(--fb-t3); margin-top:2px; flex-shrink:0; }
.studio-monitor__flow-name {
  font-size:12px; color:var(--fb-t1); flex:1;
  min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
}
.studio-monitor__flow-meta { display:flex; gap:3px; flex-shrink:0; align-items:center; }
.studio-monitor__chip {
  font-size:9px; padding:1px 5px; border-radius:10px;
  background:var(--fb-border-soft); color:var(--fb-t2); white-space:nowrap;
}
.studio-monitor__chip.ok  { background:rgba(22,163,74,.12); color:#16a34a; }
.studio-monitor__chip.err { background:rgba(239,68,68,.12);  color:#ef4444; }
.studio-monitor__chip.dim { color:var(--fb-t3); }

/* Runs list */
.studio-monitor__runs { border-top:1px solid var(--fb-border-soft); padding:4px 0; }
.studio-monitor__run-empty { padding:8px 12px; font-size:11px; color:var(--fb-t3); }
.studio-monitor__run { padding:5px 10px; cursor:pointer; }
.studio-monitor__run:hover { background:var(--fb-inp-bg); }
.studio-monitor__run-top { display:flex; align-items:center; gap:5px; }
.studio-monitor__run-dot { width:7px; height:7px; border-radius:50%; flex-shrink:0; }
.studio-monitor__run-dot.ok  { background:#16a34a; }
.studio-monitor__run-dot.err { background:#ef4444; }
.studio-monitor__run-time { font-size:11px; color:var(--fb-t2); flex:1; }
.studio-monitor__run-dur  { font-size:10px; color:var(--fb-t3); }
.studio-monitor__run-node {
  font-size:9px; color:#ef4444;
  background:rgba(239,68,68,.1); padding:1px 4px; border-radius:3px;
}
.studio-monitor__run-errmsg {
  font-size:10px; color:#ef4444; margin-top:2px;
  padding-right:12px; line-height:1.4; opacity:.85;
}

/* Node trace */
.studio-monitor__trace {
  margin:4px 0 2px 12px;
  border-right:2px solid var(--fb-border-soft);
  padding-right:6px;
}
.studio-monitor__node {
  display:flex; align-items:center; gap:4px; padding:2px 0; font-size:10px;
}
.studio-monitor__node-dot { width:5px; height:5px; border-radius:50%; flex-shrink:0; }
.studio-monitor__node.ok  .studio-monitor__node-dot { background:#16a34a; }
.studio-monitor__node.err .studio-monitor__node-dot { background:#ef4444; }
.studio-monitor__node-type { flex:1; color:var(--fb-t2); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.studio-monitor__node-ms  { color:var(--fb-t3); flex-shrink:0; }
.studio-monitor__node-err { font-size:9px; color:#ef4444; width:100%; margin-top:1px; opacity:.85; }

/* ── Flow right-click context menu ─────────────────────────
   Appended to <body>, OUTSIDE .studio-screen, so it can't use the
   scoped --fb-* vars. Styled at body level with explicit theme colors
   + a shadow so it reads as a floating window (support ticket #37). */
.studio-flow-ctx-menu {
  position: fixed;
  z-index: 9999;
  background: #FFFFFF;
  color: #0E1525;
  border: 1px solid rgba(14, 21, 37, 0.12);
  border-radius: 8px;
  padding: 4px;
  min-width: 150px;
  font-size: 12px;
  direction: rtl;
  box-shadow: 0 8px 28px rgba(14, 21, 37, 0.18), 0 2px 8px rgba(14, 21, 37, 0.10);
}
body.dark .studio-flow-ctx-menu {
  background: #0E1525;
  color: #E4E9F7;
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.4);
}
.studio-flow-ctx-menu__item {
  display: block;
  width: 100%;
  padding: 6px 10px;
  border: none;
  background: transparent;
  color: inherit;
  text-align: right;
  cursor: pointer;
  border-radius: 5px;
  font-size: 12px;
}
.studio-flow-ctx-menu__item:hover { background: rgba(14, 21, 37, 0.06); }
body.dark .studio-flow-ctx-menu__item:hover { background: rgba(255, 255, 255, 0.08); }
