:root { --bg: #0f172a; --panel: rgba(255,255,255,0.85); --text: #0f172a; --muted: #6b7280; --surface: #ffffff; --primary: #2563eb; --gradient: linear-gradient(135deg, #111827 0%, #1f2937 50%, #0f172a 100%); }
.theme-dark { --bg: #0b1020; --panel: rgba(17,24,39,0.75); --text: #e5e7eb; --muted: #9ca3af; --surface: #111827; --primary: #60a5fa; --gradient: linear-gradient(135deg, #0b1020 0%, #111827 50%, #0f172a 100%); }

* { box-sizing: border-box; font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif; }
/* Disable text selection to make dragging smoother */
body, #viewport, #nodes, .node, .port { -webkit-user-select: none; -moz-user-select: none; user-select: none; }
body { margin: 0; color: var(--text); background: var(--bg); background-image: radial-gradient(ellipse at top left, rgba(59,130,246,0.15), transparent 40%), radial-gradient(ellipse at bottom right, rgba(16,185,129,0.12), transparent 40%); }
/* Force lighter base theme */
:root { --bg: #f7f9fc; --text: #0f172a; }
header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid #e5e7eb; background: white; }
h1 { margin: 0; font-size: 18px; }

#auth-forms { display: flex; gap: 8px; }
.auth-card { display: grid; gap: 8px; padding: 10px; border: 1px solid #e5e7eb; border-radius: 12px; background: #ffffff; box-shadow: 0 10px 25px rgba(2,6,23,0.08); }
.auth-card h3 { margin: 0 0 2px 0; }
.auth-card input { padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 10px; }
.auth-card button { padding: 10px 12px; border: 1px solid #1d4ed8; background: #2563eb; color: white; border-radius: 10px; box-shadow: 0 1px 2px rgba(2,6,23,0.06); }
.hidden { display: none !important; }

main { display: grid; grid-template-columns: var(--panel-width, 320px) minmax(0, 1fr); gap: 0; height: calc(100vh - 56px); transition: grid-template-columns .2s ease; min-height: 0; }
body.panel-collapsed main { grid-template-columns: 0 minmax(0, 1fr); }
body.panel-collapsed #actor-setup { display: none !important; }
.panel-collapsed main { grid-template-columns: 0 minmax(0, 1fr); }
.panel { padding: 12px; overflow: auto; background: var(--panel); backdrop-filter: blur(6px); border-left: 1px solid #e5e7eb; }
.panel#flow-builder { display: flex; flex-direction: column; min-height: 0; }
.panel#actor-setup { grid-column: 1; }
.panel#flow-builder { grid-column: 2; }

/* Visual separation: keep left column light and add divider */
main { background: linear-gradient(90deg, rgba(255,255,255,0.85) 0 360px, transparent 360px); }
#flow-builder { border-left: 1px solid #e5e7eb; display: flex; flex-direction: column; }
.panel#actor-setup h2 { margin: 2px 0 6px 0; }
.panel#actor-setup input, .panel#actor-setup select { padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 10px; background: #fff; }
.panel#actor-setup .config { display: grid; gap: 8px; padding: 10px; border: 1px solid #e5e7eb; border-radius: 12px; background: rgba(255,255,255,0.9); box-shadow: 0 6px 20px rgba(2,6,23,0.06); }
.panel#actor-setup #create-actor-btn { justify-self: start; }
.collapse-handle { position: absolute; left: -10px; top: 64px; width: 20px; height: 60px; border-radius: 10px; border: 1px solid #e5e7eb; background: #fff; box-shadow: 0 4px 10px rgba(2,6,23,0.08); cursor: pointer; }
/* New circular hide button at top-right of panel */
.panel-hide-circle { position: sticky; float: right; top: 6px; right: 6px; width: 28px; height: 28px; border-radius: 9999px; border: 1px solid #e5e7eb; background: #fff; box-shadow: 0 4px 10px rgba(2,6,23,0.08); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }

/* Canvas + viewport */
#canvas-container { position: relative; width: 100%; flex: 1 1 auto; min-height: calc(100vh - 120px); border-top: 1px solid #e5e7eb; background: #f8fafc; overflow: hidden; border-radius: 14px; }
#viewport { position: absolute; inset: 0; background-size: 16px 16px, 24px 24px; background-image: linear-gradient(to right, rgba(148,163,184,0.12) 1px, transparent 1px), linear-gradient(135deg, rgba(148,163,184,0.06) 12px, rgba(0,0,0,0) 12px); transform-origin: 0 0; }
/* Hide hero section */
.hero { display: none; }
#edges { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; }
#nodes { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
/* Keep transform origin consistent */
#nodes, #edges { transform-origin: 0 0; }

/* Node styling, n8n-like */
.node { position: absolute; width: 240px; min-height: 80px; background: white; border: 1px solid #e2e8f0; border-radius: 16px; box-shadow: 0 10px 30px rgba(2,6,23,0.10); padding: 12px 14px; cursor: grab; pointer-events: auto; }
.node .edit-btn { position: absolute; top: 8px; right: 8px; width: 24px; height: 24px; border-radius: 6px; border: 1px solid #e5e7eb; background: #fff; color: #334155; display: none; align-items: center; justify-content: center; font-size: 12px; cursor: pointer; }
.node:hover .edit-btn { display: inline-flex; }
.node[data-variant="task"] { border-left: 4px solid #2563eb; }
.node[data-variant="agent"] { border-left: 4px solid #16a34a; }
.node[data-variant="parser"] { border-left: 4px solid #a855f7; }
.node.selected { box-shadow: 0 0 0 3px rgba(37,99,235,0.25), 0 10px 30px rgba(2,6,23,0.10); }
.node.running { animation: pulse 0.6s ease-in-out 2; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(34,197,94,0.0); } 50% { box-shadow: 0 0 0 6px rgba(34,197,94,0.25); } 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0.0);} }
.node:active { cursor: grabbing; }
.node .title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; color: #0f172a; margin-bottom: 6px; }
.node .subtitle { font-size: 12px; color: #64748b; }
.node .note-body { font-size: 13px; color: #78350f; background: #fff9cc; padding: 4px 6px; border-radius: 6px; }
.port { position: absolute; top: 50%; transform: translateY(-50%) rotate(45deg); width: 18px; height: 18px; border: 2px solid #94a3b8; background: #ffffff; border-radius: 4px; box-shadow: 0 1px 2px rgba(2,6,23,0.08); touch-action: none; }
.port.in { left: -8px; }
.port.out { right: -8px; }
.port:hover { border-color: #2563eb; }
.connecting .port.in { border-color: #2563eb; background: #dbeafe; }
.port.hover { transform: translateY(-50%) rotate(45deg) scale(1.2); border-color: #2563eb; }

/* Edges */
.edge-path { stroke: #64748b; stroke-width: 2; fill: none; pointer-events: stroke; }
.edge-path.dashed { stroke-dasharray: 6 6; }
#edges .edge-path.selected { stroke: #2563eb; stroke-width: 3; }
#viewport.grid-hidden { background-image: none; }
.edge-label { font-size: 11px; fill: #475569; user-select: none; pointer-events: none; }
/* Endpoint handles for rewiring */
.edge-handle { fill: #2563eb; stroke: #fff; stroke-width: 1; r: 4; cursor: pointer; }

/* Multi-select rectangle */
.lasso { position: absolute; border: 1px dashed #60a5fa; background: rgba(96,165,250,0.12); pointer-events: none; z-index: 30; }

/* Minimap viewport */
.minimap-viewport { fill: rgba(59,130,246,0.15); stroke: #60a5fa; stroke-width: 1; pointer-events: none; }

/* Alignment guides */
.guide { position: absolute; background: #60a5fa; opacity: 0.6; pointer-events: none; z-index: 20; }
.guide.v { width: 1px; }
.guide.h { height: 1px; }
.snap-on .guide { opacity: 0.9; background: #3b82f6; }

/* Context menu */
.menu { z-index: 200; }
.menu.hidden { display: none; }
.menu button { width: 100%; text-align: left; padding: 8px 10px; border: 0; background: transparent; border-radius: 8px; }
.menu button:hover { background: #f3f4f6; }
.menu { background: #ffffff; border: 1px solid #e5e7eb; border-radius: 8px; box-shadow: 0 10px 30px rgba(2,6,23,0.12); padding: 6px; }
.menu .row { display:flex; gap:6px; padding:4px 2px; align-items:center; }
.menu .row input[type="color"] { width: 28px; height: 24px; padding: 0; border: none; background: transparent; }

/* Canvas controls */
.canvas-controls { position: absolute; bottom: 12px; left: 12px; display: flex; gap: 6px; background: rgba(255,255,255,0.8); border: 1px solid #e5e7eb; border-radius: 10px; padding: 4px; backdrop-filter: blur(8px); }
.canvas-controls button { border: 1px solid #e5e7eb; background: white; border-radius: 8px; padding: 6px 8px; }
.canvas-controls .btn { padding: 6px 8px; }

#toolbar { margin-bottom: 8px; display: flex; gap: 8px; }
#toolbar .btn { padding: 8px 12px; border-radius: 10px; }
#toolbar .legend { margin-left: auto; font-size: 12px; color: #6b7280; display: flex; align-items: center; }

/* Ribbon UI */
.ribbon { display: flex; align-items: center; flex-wrap: nowrap; gap: 2px; padding: 2px 4px; background: linear-gradient(180deg, #ffffff 0%, #eef2f7 100%); border-bottom: 1px solid #e5e7eb; box-shadow: 0 2px 6px rgba(2,6,23,0.03); position: sticky; top: 0; z-index: 40; }
.ribbon.collapsed .ribbon-group:not(.qat) { display: none; }
.ribbon.collapsed { padding: 4px 8px; }
.ribbon .btn.icon { width: 32px; height: 32px; display: inline-grid; place-items: center; padding: 0; }
.ribbon .qat { display: inline-flex; gap: 6px; border-right: 1px solid #e5e7eb; padding-right: 8px; margin-right: 8px; }
.ribbon.compact .ribbon-group { min-width: auto; }
.ribbon-group { display: grid; grid-template-rows: auto 1fr; min-width: 200px; padding: 4px 6px; border: 1px solid #e5e7eb; border-radius: 8px; background: rgba(255,255,255,0.8); }
.ribbon-title { font-size: 12px; font-weight: 600; color: #6b7280; padding: 0 4px 6px; }
.ribbon-buttons { display: flex; flex-wrap: nowrap; gap: 10px; align-items: center; }
.ribbon-gallery { display: grid; grid-auto-flow: column; grid-auto-columns: max-content; gap: 6px; padding-left: 6px; border-left: 1px solid #e5e7eb; }
.ribbon-gallery .palette-item { padding: 6px 10px; border: 1px solid #e5e7eb; border-radius: 8px; background: #f8fafc; box-shadow: none; }
.ribbon .btn { background: #ffffff; border-radius: 8px; }
.ribbon .btn:hover { background: #f3f4f6; }
.ribbon .btn.large { display: grid; grid-template-columns: 24px 1fr; align-items: center; gap: 6px; padding: 8px 10px; min-width: 110px; }
.ribbon .btn.large .icon { width: 24px; height: 24px; display: inline-grid; place-items: center; background: #f1f5f9; border: 1px solid #e5e7eb; border-radius: 6px; }
.ribbon .ctl { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: #374151; padding: 4px 6px; background: #fff; border: 1px solid #e5e7eb; border-radius: 8px; }
.ribbon .ctl input, .ribbon .ctl select { height: 28px; }

/* Ribbon table layout */
.toolbar-table { border-collapse: collapse; width: 100%; table-layout: fixed; }
.toolbar-table thead { display: none; }
.toolbar-table { display: none; }
#top-toolbar .toolbar-grid { display: grid; grid-template-rows: repeat(2, 24px); grid-auto-flow: column; grid-auto-columns: minmax(64px, max-content); gap: 4px; align-items: center; padding: 2px 4px; }
.cell-buttons { display: contents; }
.cell-buttons .btn { height: 24px; width: auto; justify-self: start; font-size: 12px; padding: 2px 6px; border-radius: 4px; }
.cell-buttons .btn { width: 100%; }
.btn.sm { padding: 6px 8px; border-radius: 8px; }
.popover { position: absolute; top: 48px; left: 110px; background: #fff; border: 1px solid #e5e7eb; border-radius: 10px; box-shadow: 0 10px 30px rgba(2,6,23,0.12); padding: 8px; z-index: 50; }
.popover-grid { display: grid; grid-template-columns: repeat(4, max-content); gap: 6px; }
.popover .palette-item { padding: 6px 10px; border: 1px solid #e5e7eb; border-radius: 8px; background: #f8fafc; }

/* Dropdown styling */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu { position: absolute; top: 38px; left: 0; display: grid; grid-auto-rows: 36px; gap: 6px; background: #ffffff; border: 1px solid #e5e7eb; border-radius: 8px; padding: 8px; box-shadow: 0 10px 20px rgba(2,6,23,0.12); z-index: 60; }

/* Note and arrow annotations (scoped to canvas nodes only) */
#nodes .note { position: absolute; background: #fef9c3; border: 1px solid #facc15; color: #78350f; padding: 8px; border-radius: 8px; box-shadow: 0 4px 20px rgba(2,6,23,0.08); min-width: 140px; max-width: 240px; }
#nodes .note .title { font-weight: 700; margin-bottom: 4px; cursor: move; }
#nodes .note .note-body { outline: none; }
.annotation-arrow { stroke: #111827; stroke-width: 2; marker-end: url(#arrow); }
#actors-list { margin-top: 10px; font-size: 14px; color: #374151; }

#palette { display: flex; gap: 8px; margin: 6px 0 8px 0; flex-wrap: wrap; }
.palette-item { padding: 6px 10px; border: 1px dashed #9ca3af; background: #f8fafc; border-radius: 8px; cursor: grab; box-shadow: inset 0 0 0 1px rgba(148,163,184,.2); }
.palette-item.pill { border-radius: 9999px; }
.palette-item.rounded { border-style: solid; }
.palette-item.dashed { border-style: dashed; }

.embed-actions button { margin-left: 8px; padding: 2px 6px; font-size: 12px; }
.embed-snippet { background: #0b1020; color: #d1fae5; padding: 8px; border-radius: 6px; margin-top: 6px; overflow: auto; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12px; }

/* Buttons */
.btn { border: 1px solid #d1d5db; background: linear-gradient(180deg,#ffffff 0%,#f3f4f6 100%); color: #111827; padding: 8px 10px; border-radius: 8px; box-shadow: 0 1px 2px rgba(2,6,23,0.05); transition: background .12s ease, transform .05s ease; cursor: pointer; }
.btn:hover { background: #f3f4f6; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--primary); border-color: #1d4ed8; color: white; }
.btn-primary:hover { background: #1d4ed8; }
.btn.icon { width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; padding: 0; }
.btn.sm { height: 34px; display: inline-flex; align-items: center; justify-content: center; font-size: 14px; }

/* Shape buttons visual previews */
.shape-btn.box { border-radius: 6px; }
.shape-btn.rounded { border-radius: 9999px; }
.shape-btn.decision { clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%); padding: 12px 28px; }
.shape-btn.note { background: #fff7cc; border-color: #facc15; }
.shape-btn.arrow { position: relative; padding-right: 28px; }
.shape-btn.arrow::after { content: ''; position: absolute; right: 8px; width: 0; height: 0; border-left: 10px solid #111827; border-top: 6px solid transparent; border-bottom: 6px solid transparent; }

/* Modal */
.modal.hidden { display: none; }
.modal { position: fixed; inset: 0; display: grid; place-items: center; z-index: 100; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(2,6,23,0.5); }
.modal-card { position: relative; width: 720px; max-width: calc(100vw - 40px); background: white; border: 1px solid #e5e7eb; border-radius: 14px; box-shadow: 0 25px 50px rgba(2,6,23,0.25); overflow: hidden; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid #e5e7eb; background: #f8fafc; }
.modal-title { font-weight: 700; color: #0f172a; }
.modal-body { padding: 16px; display: grid; gap: 12px; }
.modal-footer { padding: 12px 16px; border-top: 1px solid #e5e7eb; display: flex; justify-content: flex-end; gap: 8px; background: #f8fafc; }
.field { display: grid; gap: 6px; }
.field span { font-size: 12px; color: #6b7280; }
.field input, .field textarea { padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 10px; }

/* Rules editor */
.rules { display: grid; gap: 8px; }
.rule-row { display: grid; grid-template-columns: 1.2fr 0.9fr 1fr 1fr auto; gap: 6px; align-items: center; }
.rule-row input, .rule-row select { padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 8px; }

/* Command palette */
.cmdk.hidden { display: none; }
.cmdk { position: fixed; inset: 0; display: grid; place-items: start center; padding-top: 10vh; z-index: 70; background: rgba(2,6,23,0.35); }
.cmdk-card { width: 640px; max-width: calc(100vw - 40px); background: white; border: 1px solid #e5e7eb; border-radius: 12px; box-shadow: 0 25px 60px rgba(2,6,23,0.35); padding: 8px; }
.cmdk-card input { width: 100%; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 8px; margin-bottom: 8px; }
.cmdk-card #cmdk-list { max-height: 300px; overflow: auto; display: grid; gap: 4px; }
.cmdk-card #cmdk-list .item { padding: 8px 10px; border-radius: 8px; }
.cmdk-card #cmdk-list .item:hover { background: #f3f4f6; cursor: pointer; }
/* Validation badge */
.node .badge { position: absolute; right: 6px; top: 6px; background: #ef4444; color: white; font-size: 10px; padding: 2px 6px; border-radius: 9999px; }


