/* ============================================================
   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) ───────────────── */
/* Palette source: "Botica Flow Builder" design mockup (2026-07-07 reskin) */
.studio-screen {
  --fb-canvas-bg:  #F4F6FA;
  --fb-canvas-dot: rgba(14, 21, 37, 0.10);
  --fb-node-bg:    #FFFFFF;
  --fb-node-border: #E2E8F0;
  --fb-node-sel:   rgba(37, 99, 235, 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.28);
  --fb-sb-bg:      #FFFFFF;
  --fb-tb-bg:      rgba(255, 255, 255, 0.98);
  --fb-st-bg:      #F5F7FB;
  --fb-inp-bg:     rgba(14, 21, 37, 0.045);
  --fb-blue:       #2563EB;
  --fb-blue-hover: #1D4ED8;
  --fb-blue-bg:    #E8EEFC;
  --fb-purple:     #7C3AED;
  --fb-purple-bg:  #EEE7FB;
  --fb-green:      #22C55E;
  --fb-t1: #1A1D21;
  --fb-t2: #3D4351;
  --fb-t3: #6B7280;
  --fb-tFaint: #9BA3BB;

  /* Node type accents (mockup: trigger/input/search/ai/skill/data/action/decision) */
  --fb-c-trigger: #16A34A;
  --fb-c-input:   #0891B2;
  --fb-c-skill:   #DB2777;
  --fb-c-output:  #2563EB;
  --fb-c-search:  #D97706;
  --fb-c-logic:   #EA580C;
  --fb-c-ai:      #7C3AED;
  --fb-c-save:    #0284C7;

  /* 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.16);
  --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 8px rgba(40,30,20,0.07);
  --fb-shadow-node-hover:  0 4px 14px rgba(40,30,20,0.10);
  --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:  #B9CBF0;

  font-family: 'Heebo', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ── 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(37, 99, 235, 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-blue:       #3B82F6;
  --fb-blue-hover: #60A5FA;
  --fb-blue-bg:    rgba(59, 130, 246, 0.16);
  --fb-purple:     #A78BFA;
  --fb-purple-bg:  rgba(167, 139, 250, 0.16);
  --fb-green:      #34D399;
  --fb-t1: #E4E9F7;
  --fb-t2: #7B8BAD;
  --fb-t3: #3A4862;
  --fb-tFaint: #5A6B8C;

  /* Node type accents keep the same hues, brightened slightly for dark bg */
  --fb-c-trigger: #22C773;
  --fb-c-input:   #22B8D6;
  --fb-c-skill:   #F472B6;
  --fb-c-output:  #3B82F6;
  --fb-c-search:  #F59E0B;
  --fb-c-logic:   #FB923C;
  --fb-c-ai:      #A78BFA;
  --fb-c-save:    #38BDF8;

  --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);
}

/* ── Material Symbols (scoped copy — kms.css's is `.kms-root .ms` only) ── */
.studio-screen .ms {
  font-family: 'Material Symbols Rounded';
  font-weight: normal;
  font-style: normal;
  line-height: 1;
  direction: ltr;
  -webkit-font-feature-settings: 'liga';
  font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ── 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: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 11.5px;
  color: var(--fb-t2);
  border: 1px solid transparent;
  transition: all 0.12s;
  position: relative;
}
.studio-screen .studio-palette__item:hover {
  background: var(--fb-surface-hover);
  color: var(--fb-t1);
  border-color: var(--fb-border-soft);
}
.studio-screen .studio-palette__item-icon {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 14px;
  background: var(--fb-surface-chip);
  color: var(--fb-t2);
}
.studio-screen .studio-palette__item-icon .ms { font-size: 15px; }
.studio-screen .studio-palette__item-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.studio-screen .studio-palette__item-drag {
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.12s;
  color: var(--fb-tFaint);
  flex-shrink: 0;
}
.studio-screen .studio-palette__item:hover .studio-palette__item-drag { opacity: 1; }

/* ── Node card ─────────────────────────────────────────── */
.studio-screen .studio-node {
  background: var(--fb-node-bg);
  border: 1.5px solid var(--fb-node-border);
  border-radius: 13px;
  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;
}
/* Implicit {{nodes.id.port}} data reference — no real graph Edge exists,
   dashed + non-interactive so it never competes with click-to-select edges */
.studio-screen .studio-varref-edge {
  stroke: var(--fb-purple, #7C3AED);
  stroke-width: 1.4;
  stroke-dasharray: 3 4;
  fill: none;
  opacity: 0.55;
  pointer-events: none;
  marker-end: none;
}

/* 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: 52px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
}
.studio-screen .studio-topbar-wrap .studio-topbar__btn {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 34px;
  padding: 0 11px;
  border-radius: 8px;
  border: 1px solid var(--fb-border-medium);
  background: var(--fb-node-bg);
  color: var(--fb-t2);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.12s;
}
.studio-screen .studio-topbar-wrap .studio-topbar__btn .ms { font-size: 15px; }
.studio-screen .studio-topbar-wrap .studio-topbar__btn:hover {
  background: var(--fb-surface-hover);
  color: var(--fb-t1);
  border-color: var(--fb-border-strong);
}
.studio-screen .studio-topbar-wrap .studio-topbar__btn--primary {
  height: 34px;
  padding: 0 16px;
  background: var(--fb-blue);
  color: #fff;
  border: 1px solid var(--fb-blue);
  font-weight: 600;
  font-size: 13px;
  box-shadow: 0 2px 10px rgba(37, 99, 235, 0.28);
}
.studio-screen .studio-topbar-wrap .studio-topbar__btn--primary:hover {
  background: var(--fb-blue-hover);
  border-color: var(--fb-blue-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}
.studio-screen .studio-topbar-wrap .studio-topbar__btn--secondary {
  border-color: rgba(34, 197, 94, 0.35);
  color: #16A34A;
}
body.dark .studio-screen .studio-topbar-wrap .studio-topbar__btn--secondary { color: var(--fb-green); }
.studio-screen .studio-topbar-wrap .studio-topbar__btn--ghost { background: transparent; }
/* AI assistant button — purple accent to stand out from other ghost buttons */
.studio-screen .studio-topbar-wrap .studio-topbar__btn--assist { border-color: rgba(124, 58, 237, 0.35); color: #7C3AED; }
.studio-screen .studio-topbar-wrap .studio-topbar__btn--assist .ms { color: #7C3AED; }
body.dark .studio-screen .studio-topbar-wrap .studio-topbar__btn--assist { color: #A78BFA; }
body.dark .studio-screen .studio-topbar-wrap .studio-topbar__btn--assist .ms { color: #A78BFA; }
.studio-screen .studio-topbar-wrap .studio-topbar__icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--fb-t2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.12s;
}
.studio-screen .studio-topbar-wrap .studio-topbar__icon-btn:hover:not(:disabled) {
  background: var(--fb-surface-hover);
  color: var(--fb-t1);
}
.studio-screen .studio-topbar-wrap .studio-topbar__icon-btn:disabled {
  opacity: 0.35;
  cursor: default;
}
.studio-screen .studio-topbar__left,
.studio-screen .studio-topbar__center,
.studio-screen .studio-topbar__right {
  display: flex;
  align-items: center;
  gap: 6px;
}
.studio-screen .studio-topbar__left  { flex: 1; min-width: 0; }
.studio-screen .studio-topbar__right { flex-wrap: wrap; justify-content: flex-end; }
.studio-screen .studio-topbar__name {
  border: none;
  background: transparent;
  color: var(--fb-t1);
  font-size: 13px;
  font-weight: 600;
  outline: none;
  min-width: 60px;
  max-width: 220px;
}
.studio-screen .studio-topbar__name::placeholder { color: var(--fb-tFaint); font-weight: 400; }
.studio-screen .studio-topbar__zoom-label {
  font-size: 11px;
  color: var(--fb-t3);
  min-width: 34px;
  text-align: center;
}
.studio-screen .studio-topbar__status {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 26px;
  padding: 0 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.studio-screen .studio-topbar__status .ms { font-size: 13px; }
.studio-screen .studio-topbar__status--draft   { background: rgba(245, 158, 11, 0.12); color: #D97706; }
.studio-screen .studio-topbar__status--saved   { background: rgba(34, 197, 94, 0.12);  color: #16A34A; }
body.dark .studio-screen .studio-topbar__status--saved { background: rgba(52, 211, 153, 0.14); color: var(--fb-green); }
.studio-screen .studio-topbar__status--running { background: rgba(37, 99, 235, 0.12);  color: var(--fb-blue); }
.studio-screen .studio-topbar__status--error   { background: rgba(239, 68, 68, 0.12);  color: #DC2626; }
.studio-screen .studio-topbar__status--success { background: rgba(34, 197, 94, 0.12);  color: #16A34A; }

/* Saved / status chip */
.studio-screen .studio-toolbar__saved-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 28px;
  padding: 0 10px;
  border-radius: 20px;
  background: rgba(34, 197, 94, 0.12);
  color: #16A34A;
  font-size: 11.5px;
  font-weight: 600;
}
body.dark .studio-screen .studio-toolbar__saved-chip {
  background: rgba(52, 211, 153, 0.14);
  color: var(--fb-green);
}
.studio-screen .studio-toolbar__saved-chip .ms { font-size: 14px; }

/* Flow-name block: purple icon chip + name input */
.studio-screen .studio-toolbar__name-block {
  display: flex;
  align-items: center;
  gap: 7px;
}
.studio-screen .studio-toolbar__name-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--fb-purple-bg);
  color: var(--fb-purple);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.studio-screen .studio-toolbar__name-icon .ms { font-size: 16px; }

/* Bordered zoom group */
.studio-screen .studio-topbar__zoom-group {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 34px;
  padding: 0 4px;
  border-radius: 8px;
  border: 1px solid var(--fb-border-medium);
  background: var(--fb-node-bg);
}

/* ── 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;
}

/* ── Shared list item / lozenge components (Templates, Flows, Monitor) ──── */
.studio-screen .litem {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid var(--fb-border-soft);
  background: var(--fb-node-bg);
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s;
}
.studio-screen .litem:hover {
  transform: translateY(-1px);
  box-shadow: var(--fb-shadow-node-hover);
  border-color: var(--fb-node-hover-border);
}
.studio-screen .litem-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--fb-blue-bg);
  color: var(--fb-blue);
}
.studio-screen .litem-icon .ms { font-size: 16px; }
.studio-screen .litem-body { flex: 1; min-width: 0; }
.studio-screen .litem-title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--fb-t1);
  display: flex;
  align-items: center;
  gap: 6px;
}
.studio-screen .litem-desc {
  font-size: 11px;
  color: var(--fb-t3);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.studio-screen .litem-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.studio-screen .loz {
  font-size: 9.5px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 10px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.studio-screen .loz.loz-active  { background: #DDF1E4; color: #0B5A36; }
.studio-screen .loz.loz-example { background: var(--fb-surface-chip); color: var(--fb-t3); }
.studio-screen .loz.loz-neutral { background: var(--fb-inp-bg); color: var(--fb-t3); }
body.dark .studio-screen .loz.loz-active { background: rgba(52, 211, 153, 0.16); color: #34D399; }

/* Search box used across panel lists */
.studio-screen .panel-search {
  margin: 6px 8px 4px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 9px;
  border-radius: 8px;
  border: 1px solid var(--fb-border-soft);
  background: var(--fb-inp-bg);
}
.studio-screen .panel-search .ms { font-size: 15px; color: var(--fb-tFaint); }
.studio-screen .panel-search input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 11.5px;
  color: var(--fb-t1);
  font-family: inherit;
}
.studio-screen .panel-search input::placeholder { color: var(--fb-tFaint); }

/* ── Canvas empty state ───────────────────────────────────────────────────── */
.studio-screen .studio-canvas-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  pointer-events: none;
  text-align: center;
  padding: 0 30px;
}
.studio-screen .studio-canvas-empty__icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--fb-blue-bg);
  color: var(--fb-blue);
}
.studio-screen .studio-canvas-empty__icon .ms { font-size: 28px; }
.studio-screen .studio-canvas-empty__title {
  font-size: 14px;
  font-weight: 700;
  color: var(--fb-t2);
}
.studio-screen .studio-canvas-empty__hint {
  font-size: 11.5px;
  color: var(--fb-tFaint);
  max-width: 260px;
  line-height: 1.5;
}

/* ── 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 6px;
  text-align: center;
  border: 1px solid var(--fb-border-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: default;
}
.studio-monitor__card.litem:hover { transform: none; box-shadow: none; }
.studio-monitor__card-icon {
  width: 22px;
  height: 22px;
  border-radius: 7px;
}
.studio-monitor__card-icon .ms { font-size: 13px; }
.studio-monitor__card-body { display:flex; flex-direction:column; align-items:center; }
.studio-monitor__card.warn .studio-monitor__card-val { color: #d97706; }
.studio-monitor__card.warn .studio-monitor__card-icon { background: rgba(217,119,6,.14); color: #d97706; }
.studio-monitor__card.ok .studio-monitor__card-icon { background: rgba(22,163,74,.14); color: #16a34a; }
.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); box-shadow:none; }
.studio-monitor__flow-top.litem { border-radius: 0; box-shadow: none; }
.studio-monitor__arrow { font-size:13px; color:var(--fb-t3); margin-top:1px; flex-shrink:0; }
.studio-monitor__run-errmsg .ms { font-size: 12px; vertical-align: -2px; color: #dc2626; }
.studio-monitor__sum-status.loz { display:inline-flex; align-items:center; gap:3px; }
.studio-monitor__sum-status.loz .ms { font-size: 13px; }
.studio-monitor__step-arrow.ms { font-size: 13px; display:flex; justify-content:center; color: var(--fb-t3); }
.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); }

/* ============================================================
   FLOW ARCHITECT — conversational Agent Builder panel
   (Botica Flow Builder handoff; all colors via --fb-* tokens)
   ============================================================ */
.architect-titlebar {
  display: flex; align-items: center; gap: 9px;
  padding: 11px 12px; flex-shrink: 0;
  border-bottom: 1px solid var(--fb-border-soft);
}
.architect-avatar {
  width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #7C3AED, #2563EB);
  color: #fff; box-shadow: 0 2px 8px rgba(124,58,237,.35);
}
.architect-avatar .ms { font-size: 17px; }
.architect-title-col { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.architect-title-text { font-weight: 700; font-size: 13px; color: var(--fb-t1); }
.architect-status {
  font-size: 10.5px; color: #16A34A; display: flex; align-items: center; gap: 4px;
}
body.dark .architect-status { color: var(--fb-green); }
.architect-status::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0;
}

.architect-chips { display: flex; flex-wrap: wrap; gap: 5px; padding: 8px 10px 4px; flex-shrink: 0; }
.architect-chip {
  background: var(--fb-blue-bg); color: var(--fb-blue);
  border: 1px solid rgba(37,99,235,.25); border-radius: 20px;
  padding: 4px 10px; font-size: 11px; cursor: pointer; white-space: nowrap;
  transition: background .15s;
}
.architect-chip:hover { background: rgba(37,99,235,.22); }

.architect-msgs {
  flex: 1; overflow-y: auto; padding: 10px 10px 6px;
  display: flex; flex-direction: column; gap: 10px;
}
.architect-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 8px; color: var(--fb-t3);
  font-size: 12px; text-align: center; padding: 20px;
}

.architect-bubble {
  max-width: 88%; border-radius: 12px; padding: 8px 11px;
  font-size: 12.5px; line-height: 1.55; word-break: break-word;
  border: 1px solid transparent;
}
.architect-bubble.is-user {
  background: var(--fb-blue); color: #fff;
  border-bottom-right-radius: 4px; white-space: pre-wrap;
  align-self: flex-end;
}
.architect-bubble.is-error {
  background: rgba(239,68,68,.12); color: #dc2626; border-bottom-left-radius: 4px; white-space: pre-wrap;
  border-color: rgba(239,68,68,.25);
}
.architect-bubble.is-ai {
  background: var(--fb-node-bg); color: var(--fb-t1); border-bottom-left-radius: 4px;
  border-color: var(--fb-border-soft);
}

/* Inline markdown code — default (dark chat contexts, e.g. Orchestrator panel) */
.md-pre {
  background: rgba(0,0,0,.35); border-radius: 6px; padding: 8px 10px;
  font-family: monospace; font-size: 11.5px; margin: 4px 0;
  overflow-x: auto; color: #9ecbff; white-space: pre;
}
.md-code {
  background: rgba(0,0,0,.3); padding: 1px 5px; border-radius: 4px;
  font-family: monospace; font-size: 11.5px; color: #9ecbff;
}
/* Light chat bubbles (Flow Architect panel) need light-theme code colors */
.architect-bubble.is-ai .md-pre,
.architect-bubble.is-ai .md-code {
  background: var(--fb-blue-bg);
  color: var(--fb-blue);
}
.architect-bubble.is-typing {
  background: var(--fb-node-bg); color: var(--fb-t3);
  border-radius: 12px; border-bottom-left-radius: 4px;
  border-color: var(--fb-border-soft);
  padding: 10px 13px;
  display: flex; align-items: center; gap: 4px;
}
.architect-typing-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--fb-tFaint);
  animation: architect-blink 1.2s infinite ease-in-out;
}
.architect-typing-dot:nth-child(2) { animation-delay: .18s; }
.architect-typing-dot:nth-child(3) { animation-delay: .36s; }
@keyframes architect-blink {
  0%, 80%, 100% { opacity: .25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

.architect-inputbar {
  flex-shrink: 0; padding: 8px 10px 10px;
  border-top: 1px solid var(--fb-border-soft);
  display: flex; gap: 6px; align-items: flex-end;
}
.architect-input {
  flex: 1; resize: none; border-radius: 10px; padding: 8px 10px;
  font-size: 12.5px; line-height: 1.5; outline: none; font-family: inherit;
  border: 1px solid var(--fb-border-soft);
  background: var(--fb-node-bg); color: var(--fb-t1);
  transition: border-color .12s, box-shadow .12s;
}
.architect-input:focus {
  border-color: var(--fb-blue);
  box-shadow: 0 0 0 3px var(--fb-blue-bg);
}
.architect-send {
  background: var(--fb-blue); color: #fff; border: none; border-radius: 9px;
  width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; cursor: pointer; flex-shrink: 0;
  transition: background .12s;
}
.architect-send:hover { background: var(--fb-blue-hover); }

/* ── Proposal card ─────────────────────────────────────── */
.architect-proposal {
  border: 1px solid var(--fb-node-border); border-radius: 12px;
  background: var(--fb-node-bg); padding: 12px; margin: 2px 0 4px;
  box-shadow: 0 2px 8px rgba(14,21,37,.06);
}
.ap-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.ap-head--advisory {
  margin: -12px -12px 10px; padding: 12px;
  background: linear-gradient(120deg, #1B2230, var(--fb-blue));
  border-radius: 12px 12px 0 0;
}
.ap-head--advisory .ap-name, .ap-head--advisory .ap-model { color: #fff; }
.ap-name { font-weight: 700; font-size: 13.5px; color: var(--fb-t1); }
.ap-model { font-size: 10px; color: var(--fb-t3); white-space: nowrap; }
.ap-desc { font-size: 12px; color: var(--fb-t2); margin-top: 4px; line-height: 1.5; }

.ap-preview { margin: 10px 0; }
.ap-preview-label { font-size: 10.5px; color: var(--fb-t3); margin-bottom: 4px; }
.ap-preview-stage {
  background: var(--fb-canvas-bg); border: 1px dashed var(--fb-node-border);
  border-radius: 8px; padding: 8px; overflow-x: auto; min-height: 60px;
}

.ap-tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin: 8px 0; }
.ap-tiles--3 { grid-template-columns: repeat(3, 1fr); }
.ap-tile {
  background: var(--fb-st-bg); border-radius: 8px; padding: 8px 6px; text-align: center;
}
.ap-tile-icon { color: var(--fb-blue); margin-bottom: 3px; font-size: 16px; }
.ap-tile-val { font-size: 12.5px; font-weight: 700; color: var(--fb-t1); white-space: nowrap; }
.ap-tile-lbl { font-size: 9.5px; color: var(--fb-t3); margin-top: 2px; }

/* Risk list with severity-colored warning icons */
.ap-risk-list { display: flex; flex-direction: column; gap: 5px; }
.ap-risk {
  display: flex; align-items: flex-start; gap: 6px;
  font-size: 11.5px; line-height: 1.5; color: var(--fb-t2);
  padding: 5px 7px; border-radius: 7px; background: var(--fb-st-bg);
}
.ap-risk-icon { font-size: 14px; flex-shrink: 0; margin-top: 1px; }
.ap-risk--high .ap-risk-icon,
.ap-risk--critical .ap-risk-icon { color: #DC2626; }
.ap-risk--medium .ap-risk-icon { color: #D97706; }
.ap-risk--low .ap-risk-icon { color: var(--fb-t3); }
.ap-risk-text { flex: 1; min-width: 0; }

.ap-section { margin-top: 8px; }
.ap-section-h { font-size: 11.5px; font-weight: 600; color: var(--fb-t2); margin-bottom: 3px; }
.ap-section-list { margin: 0; padding-inline-start: 16px; }
.ap-section-list li { font-size: 11.5px; color: var(--fb-t2); line-height: 1.5; margin: 2px 0; }
.ap-disclaimer { font-size: 10px; color: var(--fb-t3); margin-top: 8px; font-style: italic; }

.ap-actions { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.ap-btn { border: none; border-radius: 8px; padding: 7px 12px; font-size: 12px; font-weight: 600; cursor: pointer; }
.ap-build   { background: var(--fb-green); color: #fff; }
.ap-refine  { background: rgba(53,88,240,.12); color: var(--fb-blue); border: 1px solid rgba(53,88,240,.25); }
.ap-dismiss { background: transparent; color: var(--fb-t3); }

/* ── Expanded working width while a proposal is open ────── */
.studio-flows-panel.studio-flows-panel--architect {
  width: min(560px, 46vw) !important;
  transition: width .18s ease;
}
