:root {
  --bg: #0b1220; --panel: #111a2e; --panel2: #16223b; --line: #25324f; --text: #e8eefc; --muted: #93a4c7;
  --accent: #5eead4; --warn: #fbbf24; --bad: #fb7185; --ok: #4ade80; --run: #60a5fa;
  --control: #eab308; --intake: #3b82f6; --ai: #a855f7; --publish: #22c55e; --whatsapp: #10b981;
  --fs: 1;
}
* { box-sizing: border-box; }
html { font-size: calc(16px * var(--fs)); }
body { margin: 0; background: var(--bg); color: var(--text); font-family: "Segoe UI", "Heebo", Arial, Tahoma, sans-serif; line-height: 1.55; padding-bottom: 92px; }
button, select, input { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.grow { flex: 1; }
code, .mono { font-family: Consolas, "Cascadia Mono", monospace; direction: ltr; unicode-bidi: isolate; }
p code, li code { background: #0a1426; padding: 0 .3em; border-radius: 4px; color: #bfe8ff; }

#bar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; padding: .55rem 1rem; background: rgba(11, 18, 32, .94); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: .6rem; }
.brand .logo { font-size: 1.7rem; }
.brand b { display: block; font-size: 1.15rem; }
.brand small { color: var(--muted); }
.runpick { color: var(--muted); display: flex; gap: .4rem; align-items: center; }
select { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: .3rem .5rem; }
.ctl { display: inline-flex; gap: .4rem; }
.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: .4rem .8rem; cursor: pointer; transition: .15s; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: #0f766e; border-color: #14b8a6; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.small, .mini { padding: .1rem .5rem; font-size: .8rem; }
.mini { background: transparent; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); cursor: pointer; margin-inline-start: auto; }
.chip { padding: .15rem .7rem; border-radius: 99px; background: var(--panel2); border: 1px solid var(--line); font-size: .9rem; }
.chip.running { color: var(--run); border-color: var(--run); } .chip.finished { color: var(--ok); border-color: var(--ok); }
.chip.error, .chip.abandoned { color: var(--bad); border-color: var(--bad); }
.watching .ctl, .watching #dock .btn, .watching #btnStart { display: none; }
.banner { margin: .6rem 1rem 0; padding: .6rem 1rem; border-radius: 10px; background: #3b2f08; border: 1px solid #a16207; color: #fde68a; }
.banner.info { background: #0c2a3b; border-color: #0e7490; color: #bae6fd; }

main { padding: .8rem 1rem; display: grid; grid-template-columns: minmax(0, 1fr); gap: .9rem; }
#strip > *, #stage > *, #mapWrap { min-width: 0; }

/* previous / current / next */
#strip { display: grid; grid-template-columns: 1fr 1.35fr 1fr; gap: .8rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: .75rem 1rem; min-height: 112px; position: relative; cursor: default; }
.card .lbl { font-size: .8rem; color: var(--muted); letter-spacing: .02em; margin-bottom: .2rem; }
.card h4 { margin: 0 0 .3rem; font-size: 1.12rem; }
.card .sub { font-size: .88rem; color: var(--muted); }
.card.clickable { cursor: pointer; } .card.clickable:hover { border-color: var(--accent); }
.card.cur { background: var(--panel2); border-width: 2px; box-shadow: 0 0 0 4px rgba(94, 234, 212, .08); }
.card.cur.running { border-color: var(--run); animation: pulse 1.4s infinite; }
.card.cur.waiting { border-color: var(--warn); }
.card.cur.done { border-color: var(--ok); }
.card.empty { opacity: .55; display: grid; place-items: center; text-align: center; }
.card .pill { display: inline-block; font-size: .78rem; padding: 0 .55rem; border-radius: 99px; margin-inline-end: .4rem; border: 1px solid currentColor; }
.pill.done { color: var(--ok); } .pill.running { color: var(--run); } .pill.waiting { color: var(--warn); } .pill.error { color: var(--bad); }
.card .opts { margin: .1rem 0 0; padding: 0; list-style: none; font-size: .92rem; }
.card .opts li::before { content: "←"; margin-inline-end: .4rem; color: var(--muted); }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(96, 165, 250, .16); } }
.dot { display: inline-block; width: .7rem; height: .7rem; border-radius: 50%; margin-inline-end: .4rem; background: var(--muted); }
.ph-control .dot, .ph-control .pdot { background: var(--control); } .ph-intake .dot { background: var(--intake); } .ph-ai .dot { background: var(--ai); }
.ph-publish .dot { background: var(--publish); } .ph-whatsapp .dot { background: var(--whatsapp); }

/* map */
#mapWrap { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: .5rem .8rem .8rem; }
.maphead { display: flex; gap: .8rem; align-items: center; margin-bottom: .3rem; }
.maphead .btn { margin-inline-start: auto; }
.map { overflow-x: auto; direction: ltr; }
.map svg { display: block; direction: ltr; }
.lane-bg { fill: rgba(255, 255, 255, .02); stroke: var(--line); stroke-width: 1; }
.lane-label { fill: var(--muted); font-size: 13px; }
.edge { fill: none; stroke: #3a4c73; stroke-width: 1.6; } .edge.used { stroke: var(--ok); stroke-width: 2.4; } .edge.lbl { stroke-dasharray: 4 3; }
.edge-t { fill: #7e92b8; font-size: 11px; }
.node rect { fill: #14203a; stroke: #33466f; stroke-width: 1.4; rx: 9; }
.node text { fill: #cfe0ff; font-size: 12.5px; pointer-events: none; }
.node { cursor: pointer; } .node:hover rect { stroke: var(--accent); }
.node.done rect { stroke: var(--ok); fill: #10261f; } .node.running rect { stroke: var(--run); fill: #10213f; animation: pulse 1.4s infinite; }
.node.waiting rect { stroke: var(--warn); fill: #2d2610; } .node.error rect { stroke: var(--bad); fill: #35141b; }
.node.view rect { stroke-width: 3.2; stroke: var(--accent); }
.node.never rect { opacity: .8; }
.node .bar { stroke-width: 5; }
.node.k-trigger rect { rx: 20; } .node.k-if rect { stroke-dasharray: 5 3; }

/* phase banner */
.phasebar { border-radius: 12px; padding: .6rem 1rem; border: 1px solid var(--line); background: var(--panel); }
.phasebar b { margin-inline-end: .5rem; } .phasebar span { color: var(--muted); white-space: pre-line; }

/* the three columns: input | function | output (RTL: input on the right) */
#stage { display: grid; grid-template-columns: 1fr 1.25fr 1fr; gap: .8rem; align-items: start; }
.col { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; min-width: 0; }
.col > h3 { margin: 0; padding: .55rem .9rem; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: .6rem; font-size: 1rem; }
.col > h3 em { color: var(--muted); font-style: normal; font-size: .85rem; }
.jview { padding: .6rem .8rem; max-height: 62vh; overflow: auto; font-size: .88rem; direction: ltr; text-align: left; }
.jview .none { direction: rtl; text-align: center; color: var(--muted); padding: 1.6rem .5rem; }
.jview details { margin-inline-start: .9rem; } .jview > details, .jview > .jl { margin-inline-start: 0; }
.jview summary { cursor: pointer; list-style: none; } .jview summary::-webkit-details-marker { display: none; }
.jview summary::before { content: "▸"; display: inline-block; width: 1em; color: var(--muted); } .jview details[open] > summary::before { content: "▾"; }
.jl { margin-inline-start: 1.3rem; word-break: break-word; }
.jk { color: #7dd3fc; } .js { color: #fde68a; unicode-bidi: plaintext; white-space: pre-wrap; } .jn { color: #86efac; } .jb { color: #f9a8d4; } .jz { color: #94a3b8; }
.jp { color: #7c8db3; margin-inline-start: .5rem; font-size: .82rem; unicode-bidi: plaintext; }
.more { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0 .3rem; }
.fnview { padding: .4rem .9rem .9rem; max-height: 56vh; overflow: auto; }
.stepTitle { padding: .7rem .9rem 0; font-size: 1.2rem; font-weight: 700; }
.stepTitle small { display: block; color: var(--muted); font-weight: 400; font-size: .85rem; }
.tabs { display: flex; flex-wrap: wrap; gap: .3rem; padding: .5rem .9rem 0; }
.tab { background: transparent; border: 1px solid var(--line); border-radius: 99px; padding: .15rem .8rem; cursor: pointer; color: var(--muted); }
.tab.on { background: var(--accent); color: #042f2e; border-color: var(--accent); font-weight: 600; }
.fnview p { margin: .5rem 0; } .fnview pre { margin: .5rem 0; padding: .7rem; background: #08101f; border: 1px solid var(--line); border-radius: 10px; overflow: auto; direction: ltr; text-align: left; font-size: .84rem; max-height: 38vh; }
.fnview .src { color: var(--muted); font-size: .82rem; direction: ltr; text-align: left; }
.tk { color: #c4b5fd; } .tc { color: #64748b; } .ts { color: #fde68a; } .tn { color: #86efac; }
.watch { margin: 0 .9rem .9rem; padding: .5rem .8rem; border-radius: 10px; background: #1a2a1f; border: 1px solid #1f6f43; color: #bbf7d0; }
.running-box { text-align: center; padding: 2rem .5rem; direction: rtl; color: var(--run); }
.spin { width: 1.6rem; height: 1.6rem; border: 3px solid var(--line); border-top-color: var(--run); border-radius: 50%; display: inline-block; animation: sp 1s linear infinite; vertical-align: middle; margin-inline-end: .5rem; }
@keyframes sp { to { transform: rotate(360deg); } }
.taskbtn { margin: .6rem .8rem; }
.taskbtn button { margin: .15rem; }

/* dock */
#dock { position: fixed; inset-inline: 0; bottom: 0; z-index: 30; display: flex; align-items: center; justify-content: center; gap: 1rem; padding: .7rem 1rem; background: rgba(11, 18, 32, .96); border-top: 1px solid var(--line); }
.btn.big { padding: .7rem 1.4rem; font-size: 1.15rem; }
.btn.next { background: #0f766e; border-color: #2dd4bf; min-width: 250px; font-weight: 700; }
.btn.next.waiting { background: #b45309; border-color: #fbbf24; } .btn.next.go { background: #0f766e; }
.progress { min-width: 260px; } .progress .bar { height: 7px; border-radius: 99px; background: var(--panel2); overflow: hidden; margin: .2rem 0; } .progress .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
#progText { font-size: .95rem; }

/* drawer + dialog */
.drawer { position: fixed; inset-block: 0; inset-inline-start: 0; width: min(760px, 96vw); z-index: 40; background: var(--panel); border-inline-end: 1px solid var(--line); display: flex; flex-direction: column; box-shadow: 8px 0 40px rgba(0, 0, 0, .5); }
.drawer[hidden] { display: none; }
.drawer > header { display: flex; justify-content: space-between; align-items: center; padding: .7rem 1rem; border-bottom: 1px solid var(--line); }
.drawerBody { overflow: auto; padding: .8rem 1rem 2rem; }
.drawerBody h3 { margin: 1.1rem 0 .3rem; } .drawerBody table { border-collapse: collapse; width: 100%; font-size: .9rem; }
.drawerBody th, .drawerBody td { border-bottom: 1px solid var(--line); padding: .35rem .5rem; text-align: start; vertical-align: top; }
.drawerBody tr.pick { cursor: pointer; } .drawerBody tr.pick:hover { background: var(--panel2); } .drawerBody tr.sel { background: #12304a; }
.drawerBody pre { background: #08101f; border: 1px solid var(--line); border-radius: 10px; padding: .7rem; overflow: auto; direction: ltr; text-align: left; font-size: .8rem; max-height: 340px; white-space: pre-wrap; word-break: break-all; }
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 16px; padding: 1.2rem 1.5rem; max-width: 460px; }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog label { display: block; margin: .8rem 0; } dialog input[type=number] { width: 4.5rem; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: .2rem .4rem; }
dialog menu { display: flex; gap: .6rem; justify-content: flex-start; padding: 0; margin: 1rem 0 0; }

@media (max-width: 1100px) { #strip, #stage { grid-template-columns: 1fr; } body { padding-bottom: 130px; } #dock { flex-wrap: wrap; } }
