/* BUILDER — danh sách kịch bản + trình xây dựng kéo-thả + khung chạy thử */
.fb-tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.fb-tpl { display: grid; gap: 10px; align-content: start; } .fb-tpl p { min-height: 60px; }
.fb-tpl-i { width: 32px; height: 32px; border-radius: 9px; background: var(--brand-50); color: var(--brand); display: grid; place-items: center; flex: none; }

/* khung trình xây dựng */
.fb-wrap { position: relative; display: flex; flex-direction: column; background: #fff; border: 1px solid var(--line); border-radius: 16px; overflow: hidden; height: max(660px, calc(100vh - 150px)); box-shadow: var(--shadow); }
.fb-bar { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; background: #fff; }
.fb-name { width: min(280px, 100%); min-height: 36px !important; padding: 6px 10px !important; font-weight: 700; } .fb-sp { flex: 1; }
.fb-only-m { display: none; }
.fb-panes { position: relative; flex: 1; display: grid; grid-template-columns: 212px minmax(0, 1fr) 292px; min-height: 0; }
.fb-left, .fb-right { overflow: auto; padding: 12px; background: #fff; min-height: 0; } .fb-left { border-right: 1px solid var(--line); } .fb-right { border-left: 1px solid var(--line); display: grid; align-content: start; gap: 14px; }
.fb-lhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; } .fb-right .fb-lhead { margin: 0; }
.fb-scrim { display: none; }
.fb-pg { margin-bottom: 12px; } .fb-pg h5 { margin: 0 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #94a3b8; }
.fb-pal { display: flex; gap: 10px; align-items: center; width: 100%; padding: 8px 10px; margin-bottom: 6px; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: grab; text-align: left; transition: border-color .12s, box-shadow .12s; }
.fb-pal:hover { border-color: var(--c); box-shadow: 0 2px 8px rgba(16,24,40,.08); } .fb-pal:active { cursor: grabbing; }
.fb-pt { display: grid; min-width: 0; } .fb-pt b { font-size: 13.5px; } .fb-pt small { font-size: 11.5px; color: var(--muted); line-height: 1.3; }
.fb-ni { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; flex: none; background: color-mix(in srgb, var(--c) 14%, #fff); color: var(--c); } .fb-ni .ic { width: 18px; height: 18px; }
.fb-ghost { position: fixed; z-index: 300; pointer-events: none; display: flex; gap: 8px; align-items: center; background: #fff; border: 1.5px solid var(--c); border-radius: 10px; padding: 6px 12px 6px 6px; box-shadow: var(--shadow-lg); font-size: 13.5px; }

/* canvas */
.fb-canvas { position: relative; overflow: hidden; background-color: #f7f9fc; background-image: radial-gradient(#cbd5e1 1.2px, transparent 1.2px); background-size: 24px 24px; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; min-width: 0; }
.fb-canvas:active { cursor: grabbing; } .fb-canvas.drop { outline: 3px dashed rgba(0,104,255,.4); outline-offset: -6px; }
.fb-world { position: absolute; left: 0; top: 0; width: 0; height: 0; transform-origin: 0 0; }
.fb-edges { position: absolute; left: 0; top: 0; width: 1px; height: 1px; overflow: visible; pointer-events: none; }
.fb-eh { fill: none; stroke: transparent; stroke-width: 18; pointer-events: stroke; cursor: pointer; } .fb-ep { fill: none; stroke: #94a3b8; stroke-width: 2; }
.fb-edge:hover .fb-ep { stroke: #64748b; } .fb-edge.sel .fb-ep { stroke: var(--brand); stroke-width: 2.6; }
.fb-tmp { fill: none; stroke: var(--brand); stroke-width: 2; stroke-dasharray: 6 5; }
.fb-edel { cursor: pointer; pointer-events: all; } .fb-edel circle { fill: #fff; stroke: var(--err); stroke-width: 1.6; } .fb-edel path { stroke: var(--err); stroke-width: 2; fill: none; stroke-linecap: round; }
.fb-node { position: absolute; width: 220px; background: #fff; border-radius: 12px; box-shadow: 0 0 0 1.5px var(--line), 0 4px 12px rgba(16,24,40,.07); cursor: move; }
.fb-node.sel { box-shadow: 0 0 0 2px var(--brand), 0 6px 18px rgba(0,104,255,.18); } .fb-node.conn { box-shadow: 0 0 0 2px var(--accent), 0 6px 18px rgba(124,58,237,.2); } .fb-node.drop { box-shadow: 0 0 0 2.5px var(--ok), 0 6px 18px rgba(22,163,74,.22); }
.fb-nh { height: 56px; display: flex; gap: 10px; align-items: center; padding: 0 12px 0 10px; border-radius: 12px; box-sizing: border-box; border-left: 4px solid var(--c); }
.fb-nt { display: grid; min-width: 0; line-height: 1.25; } .fb-nt b { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .fb-nt small { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fb-node .fb-ni { width: 30px; height: 30px; }
.fb-in, .fb-out { position: absolute; width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 2.5px solid #94a3b8; z-index: 2; cursor: crosshair; box-sizing: border-box; }
.fb-in { left: -7px; top: 21px; cursor: default; } .fb-out.single { right: -7px; top: 21px; }
.fb-in::after, .fb-out::after { content: ""; position: absolute; inset: -10px; border-radius: 50%; }
.fb-out.on { background: var(--brand); border-color: var(--brand); } .fb-out:hover, .fb-out.act { border-color: var(--accent); background: var(--accent); transform: scale(1.2); }
.fb-orow { height: 26px; position: relative; display: flex; justify-content: flex-end; align-items: center; padding: 0 14px; font-size: 12px; font-weight: 600; color: #475569; border-top: 1px dashed #e8edf4; box-sizing: border-box; }
.fb-orow:last-child { border-radius: 0 0 12px 12px; } .fb-orow .fb-out { right: -7px; top: 6px; }
.fb-hint { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); background: #172554; color: #fff; font-size: 13px; padding: 7px 14px; border-radius: 999px; z-index: 5; box-shadow: var(--shadow-lg); max-width: calc(100% - 24px); text-align: center; }
.fb-ctl { position: absolute; left: 12px; bottom: 12px; display: flex; gap: 4px; align-items: center; padding: 4px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); z-index: 5; }
.fb-zoomv { min-width: 44px; text-align: center; font-size: 12.5px; font-weight: 700; color: #475569; }
.fb-mini { position: absolute; right: 12px; bottom: 12px; width: 168px; height: 112px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); z-index: 5; overflow: hidden; cursor: pointer; } .fb-mini svg { width: 100%; height: 100%; display: block; }

/* thanh phải */
.fb-cfg-head { display: flex; gap: 10px; align-items: center; padding: 10px; border-radius: 12px; background: color-mix(in srgb, var(--c) 8%, #fff); border: 1px solid color-mix(in srgb, var(--c) 25%, #fff); }
#fb-cfg { display: grid; gap: 14px; }
.fb-sec { display: grid; gap: 10px; padding-top: 4px; } .fb-sec h4 { font-size: 13.5px; display: flex; gap: 8px; align-items: center; }
.fb-outcfg { display: grid; gap: 6px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: #fafbfd; }
.fb-issues { display: grid; gap: 6px; } .fb-issue { display: flex; gap: 8px; align-items: flex-start; text-align: left; padding: 8px 10px; border-radius: 9px; border: 0; font: inherit; font-size: 12.5px; line-height: 1.4; } .fb-issue .ic { margin-top: 1px; }
.fb-issue.err { background: var(--err-50); color: #9b1c1c; } .fb-issue.warn { background: var(--warn-50); color: #7a5200; } .fb-issue.ok { background: var(--ok-50); color: #12603a; } button.fb-issue:not(:disabled) { cursor: pointer; } button.fb-issue:not(:disabled):hover { filter: brightness(.97); }
.fb-tips { margin: 0; padding-left: 18px; font-size: 12.5px; color: var(--muted); display: grid; gap: 4px; }

/* chạy thử */
.fb-simset { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; font-size: 13px; } .fb-simset label { display: flex; gap: 6px; align-items: center; } .fb-simset .select { width: auto; min-height: 34px; padding: 4px 8px; }
.fb-simlog { height: 300px; overflow: auto; background: #eef3fb; border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.fb-b { max-width: 82%; padding: 8px 12px; border-radius: 14px; font-size: 14px; line-height: 1.45; word-break: break-word; }
.fb-b.cust { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 4px; } .fb-b.bot { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.fb-b.sys { align-self: center; max-width: 94%; background: transparent; color: #64748b; font-size: 12px; text-align: center; font-style: italic; }
.fb-simchips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; } .fb-simchips:empty { display: none; }
.fb-chip { border: 1px solid var(--brand); background: var(--brand-50); color: var(--brand-d); border-radius: 999px; padding: 6px 14px; font-weight: 600; font-size: 13px; cursor: pointer; } .fb-chip.br { border-color: var(--accent); background: var(--accent-50); color: var(--accent); }
.fb-simform { display: flex; gap: 8px; margin-top: 10px; }

/* responsive: panel thành ngăn kéo */
@media (max-width: 960px) {
  .fb-only-m { display: inline-flex; }
  .fb-panes { grid-template-columns: minmax(0, 1fr); }
  .fb-left, .fb-right { position: absolute; top: 0; bottom: 0; z-index: 12; width: min(320px, 88%); box-shadow: var(--shadow-lg); transition: transform .2s; }
  .fb-left { left: 0; transform: translateX(-105%); } .fb-right { right: 0; transform: translateX(105%); }
  .fb-wrap[data-pane="left"] .fb-left, .fb-wrap[data-pane="right"] .fb-right { transform: none; }
  .fb-wrap[data-pane="left"] .fb-scrim, .fb-wrap[data-pane="right"] .fb-scrim { display: block; position: absolute; inset: 0; background: rgba(15,23,42,.35); z-index: 11; }
  .fb-wrap { height: max(620px, calc(100vh - 120px)); }
}
@media (max-width: 640px) {
  .fb-name { flex: 1 1 110px; width: auto; min-width: 0; } .fb-sp { flex-basis: 100%; height: 0; }
  .fb-bar { gap: 6px; padding: 8px; } .fb-bar .btn.sm { padding: 0 10px; } .fb-bar .fb-lbl { display: none; }
  .fb-mini { width: 118px; height: 78px; right: 8px; bottom: 8px; } .fb-ctl { left: 8px; bottom: 8px; } .fb-ctl .btn { display: none; }
  .fb-simlog { height: 240px; } .fb-pal { padding: 10px; }
}
