/* ═══════════════════════════════════════════════════════════════════════════
   USER PREFERRED SYSTEM DESIGN
   Every node declares its PRIMITIVE type first, then the name wraps it.
   db = database call · fx = function · svc = service · obj = object · ui · actor
   Colour follows the kind, not the position. Ports are calm at rest and only
   light up as the Run pulse — the electric flow — travels through them.
   ═══════════════════════════════════════════════════════════════════════════ */

.ud {
  --blue: #2f6fe4;
  --violet: #7c5bd1;
  --green: #299764;
  --slate: #64748b;

  --hairline: #e7eaf0;
  --port: #cbd5e1;
  --paper: #ffffff;
  --ink: #0f172a;
  --dim: #64748b;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --sans: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Inter', 'Segoe UI', system-ui, sans-serif;
  --mono: 'SF Mono', ui-monospace, 'JetBrains Mono', Menlo, monospace;

  height: 100%;
  overflow: auto;
  background: #eff3fa;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-family: var(--sans);
  position: relative;
}

/* every label is upright — never the default italic <em> */
.ud em { font-style: normal; }

/* clickable tiles + selection ring */
.ud-tile[role="button"] { cursor: pointer; }
.ud-tile[role="button"]:hover { transform: translateY(-2px); }
.ud-tile.is-sel { box-shadow: 0 0 0 2px var(--kc, var(--blue)), 0 4px 12px -3px rgba(15, 23, 42, 0.25); }

@keyframes ud-rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

@keyframes ud-pulse {
  0% { box-shadow: 0 0 0 0 var(--kc-glow); }
  70%, 100% { box-shadow: 0 0 0 9px transparent; }
}

/* ── top bar — the simulation control ── */
.ud-bar {
  flex: none;
  margin-top: 16px;
  animation: ud-rise 0.35s var(--ease) both;
}

.ud-run {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border: none;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.01em;
  color: #fff;
  background: var(--ink);
  cursor: pointer;
  box-shadow: 0 2px 8px -2px rgba(15, 23, 42, 0.4);
  transition: transform 0.15s var(--ease), background 0.15s var(--ease);
}

.ud-run:hover:not(:disabled) { transform: translateY(-1px); background: #1e293b; }
.ud-run.busy { background: var(--violet); cursor: default; }
.ud-run svg { animation: none; }
.ud-run.busy svg { animation: ud-spin 1s linear infinite; }
@keyframes ud-spin { to { transform: rotate(360deg); } }

.ud-canvas {
  position: relative;
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 40px;
  padding: 40px 48px;
  animation: ud-rise 0.4s var(--ease) both;
}

.ud-row { display: flex; align-items: center; }

/* ── db-call connections — phases continue down into the data stores ── */
.ud-conns {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
  z-index: 1;
}

.ud-conns path {
  fill: none;
  stroke-width: 1.5;
}

.ud-conns path.k-db { stroke: #7fccaa; }
.ud-conns path.k-ui { stroke: #a9c4f5; }
.ud-conns path.is-lit { stroke: var(--green); stroke-width: 2; }
.ud-conns path.k-ui.is-lit { stroke: var(--blue); }

/* ── render surfaces — where the output guard sends the answer ── */
.ud-render {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-left: 22px;
  align-self: center;
}

.ud-render .ud-node.is-lit .ud-tile { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(47, 111, 228, 0.18); }

/* ── DATA STORES — the real db boxes, outside the runtime ── */
.ud-data-layer { display: flex; gap: 20px; align-items: flex-start; }

.ud-store {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 14px 12px;
  border-radius: 16px;
  background: #f2fbf6;
  border: 1.5px solid #c9ecda;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 22px -14px rgba(41, 151, 100, 0.3);
}

.ud-store-hd { display: flex; align-items: center; gap: 8px; }
.ud-store-hd b { font-size: 11px; font-weight: 700; color: var(--green); letter-spacing: -0.01em; }
.ud-store-tag { font-size: 7px; color: var(--dim); font-family: var(--mono); margin-left: 2px; }

.ud-tables { display: flex; flex-wrap: wrap; gap: 5px; max-width: 230px; }

.ud-table {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 7px;
  border-radius: 7px;
  background: #fff;
  border: 1px solid #d6efe1;
  color: var(--green);
}

.ud-table em {
  font-style: normal;
  font-family: var(--mono);
  font-size: 7px;
  font-weight: 600;
  color: #2f6b52;
}

/* ── the node — tile (type glyph + type badge) then name ── */
.ud-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.ud-node em {
  font-style: normal;
  font-size: 8.5px;
  font-weight: 650;
  letter-spacing: 0.01em;
  color: var(--dim);
  white-space: nowrap;
}

.ud-tile {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--paper);
  border: 1px solid var(--hairline);
  box-shadow:
    0 1px 2px rgba(15, 23, 42, 0.05),
    0 5px 12px -5px var(--kc-glow, rgba(15, 23, 42, 0.08));
  cursor: default;
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.ud-tile:hover {
  transform: translateY(-2px);
  box-shadow:
    0 2px 4px rgba(15, 23, 42, 0.06),
    0 9px 18px -6px var(--kc-glow, rgba(15, 23, 42, 0.18));
}

/* the type badge — the primitive, stated plainly, corner of the tile */
.ud-type {
  position: absolute;
  right: -5px;
  bottom: -5px;
  font-family: var(--mono);
  font-style: normal;
  font-size: 6.5px;
  font-weight: 700;
  line-height: 1;
  color: #fff;
  padding: 2px 3.5px;
  border-radius: 5px;
  border: 1.5px solid var(--paper);
}

/* ── kind palette — glyph, badge, and lit-ring share one hue ── */
.k-db    { color: var(--green);  --kc: var(--green);  --kc-glow: rgba(41, 151, 100, 0.35); }
.k-fx    { color: var(--violet); --kc: var(--violet); --kc-glow: rgba(124, 91, 209, 0.35); }
.k-svc   { color: var(--blue);   --kc: var(--blue);   --kc-glow: rgba(47, 111, 228, 0.35); }
.k-ui    { color: var(--blue);   --kc: var(--blue);   --kc-glow: rgba(47, 111, 228, 0.35); }
.k-obj   { color: #b45309;       --kc: #b45309;       --kc-glow: rgba(180, 83, 9, 0.35); }
.k-actor { color: var(--slate);  --kc: var(--slate);  --kc-glow: rgba(100, 116, 139, 0.3); }
.k-job   { color: var(--slate);  --kc: var(--slate);  --kc-glow: rgba(100, 116, 139, 0.3); }

/* pastel gradient cards: airy top, clearly the kind's colour at the bottom,
   tone-line border — the icon carries the saturation, the card frames it */
.ud-tile.k-db    { background: linear-gradient(180deg, #f8fdfa, #d9f1e5); border-color: #7fccaa; }
.ud-tile.k-fx    { background: linear-gradient(180deg, #faf8fe, #e8e0f8); border-color: #c9b8ef; }
.ud-tile.k-svc,
.ud-tile.k-ui    { background: linear-gradient(180deg, #f7faff, #dde9fc); border-color: #a9c4f5; }
.ud-tile.k-obj   { background: linear-gradient(180deg, #fefbf4, #f8ead2); border-color: #f0cf94; }
.ud-tile.k-actor { background: linear-gradient(180deg, #f9fafc, #e7ecf2); border-color: #cbd5e1; }
.ud-tile.k-job   { background: linear-gradient(180deg, #f9fafc, #e7ecf2); border-color: #cbd5e1; border-style: dashed; }

.ud-type.k-db    { background: var(--green); }
.ud-type.k-fx    { background: var(--violet); }
.ud-type.k-svc,
.ud-type.k-ui    { background: var(--blue); }
.ud-type.k-obj   { background: #b45309; }
.ud-type.k-actor,
.ud-type.k-job   { background: var(--slate); }

/* Chat — the one lit surface */
.ud-node.hot .ud-tile { background: var(--blue); border-color: var(--blue); color: #fff; box-shadow: 0 3px 10px rgba(47, 111, 228, 0.3); }

/* ── flow: lit as the pulse passes, glowing while it's the live step ── */
.ud-node.is-lit .ud-tile { border-color: var(--kc); box-shadow: 0 0 0 2px var(--kc-glow); }
.ud-node.is-now .ud-tile { animation: ud-pulse 1.1s var(--ease) infinite; }

/* ── user surface — vertical chain, the way in ── */
.ud-chain {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: 20px;
  padding: 16px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px -12px rgba(47, 111, 228, 0.15);
}

.ud-vlink {
  width: 1.5px;
  height: 16px;
  background: var(--hairline);
  transition: background 0.25s var(--ease);
}

.ud-vlink.is-lit { background: var(--blue); }

/* ── the other three loops — small, same scale as the top chain, each just
   flowing on to Supabase (no separate outer scope, no gates) ── */
.loops-row { gap: 34px; flex-wrap: wrap; justify-content: center; margin-top: -8px; }
.ud-mini {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  padding: 8px 12px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.ud-mini b { display: flex; flex-direction: column; gap: 2px; font-size: 9px; font-weight: 700; color: var(--dim); text-transform: uppercase; letter-spacing: .06em; margin-right: 6px; }
.ud-mini b small { font-size: 7px; font-weight: 500; text-transform: none; letter-spacing: 0; color: #94a3b8; white-space: nowrap; }
.ud-mini .ud-node { flex-direction: column; }
.ud-mini .ud-tile { width: 30px; height: 30px; border-radius: 9px; }
.ud-mini .ud-node em { font-size: 8px; margin-top: 2px; white-space: nowrap; }
.ud-mini-link { width: 14px; height: 1.5px; background: var(--hairline); flex: none; transition: background 0.25s var(--ease); }
.ud-mini-link.is-lit { background: var(--green); }
.ud-mini.is-lit { border-color: var(--green); }

/* the wires between loops — named by the table that carries the packet */
.ud-conns text.ud-conn-lbl { font-size: 7.5px; font-weight: 650; fill: #94a3b8; font-family: var(--mono); paint-order: stroke; stroke: var(--paper); stroke-width: 3px; }
.ud-conns text.ud-conn-lbl.is-lit { fill: var(--green); }

/* ── the wire between surfaces — calm at rest, colours on flow ── */
.ud-wire {
  width: 60px;
  height: 1.5px;
  background: var(--hairline);
  flex: none;
  transition: background 0.25s var(--ease);
}

.ud-wire.short { width: 34px; }

.ud-wire.is-lit { background: linear-gradient(to right, var(--blue), var(--violet)); }

/* ── SCOPE — a nested box; the turn runs inside these ── */
.ud-scope {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-radius: 18px;
  transition: border-color 0.25s var(--ease), box-shadow 0.25s var(--ease);
}

/* the session — the outer scope (blue) */
.ud-scope.session {
  padding: 12px 16px 16px;
  background: #f6f9ff;
  border: 1.5px solid #d4e2fb;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 10px 28px -14px rgba(47, 111, 228, 0.25);
}

.ud-scope.session.is-lit {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(47, 111, 228, 0.18), 0 10px 28px -12px rgba(47, 111, 228, 0.3);
}

/* the runner — the agent scope, inside the session (purple) */
.ud-scope.runner {
  position: relative;
  padding: 10px 30px 14px;
  background: #faf8fe;
  border: 1.5px solid #e2d8f7;
}

.ud-scope.runner.is-lit { border-color: var(--violet); box-shadow: 0 0 0 2px rgba(124, 91, 209, 0.16); }

/* ── GATES — checkpoints on the runtime wall (enter left, leave right) ── */
.ud-gate {
  position: absolute;
  top: 50%;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.ud-gate.in { left: 0; transform: translate(-50%, -50%); }
.ud-gate.out { right: 0; transform: translate(50%, -50%); }

/* a runner sitting beside its siblings (not at the row's edge) takes its
   gate-in from the top, centred — the Cloud Run wire lands here */
.ud-scope.runner .ud-gate.in.top { left: 50%; top: 0; transform: translate(-50%, -50%); }

.ud-gate .ud-tile {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: #fff;
  border: 1.5px solid var(--violet);
  color: var(--violet);
  box-shadow: 0 0 0 4px #faf8fe, 0 2px 6px -1px rgba(124, 91, 209, 0.25);
}

.ud-gate em {
  font-size: 6.5px;
  font-weight: 650;
  line-height: 1.15;
  text-align: center;
  color: var(--violet);
  white-space: nowrap;
}

/* lit as the pulse enters / leaves the runtime */
.ud-gate.is-lit .ud-tile,
.ud-gate.is-now .ud-tile { background: var(--violet); color: #fff; }
.ud-gate.is-now .ud-tile { animation: ud-pulse 1.1s var(--ease) infinite; --kc-glow: rgba(124, 91, 209, 0.45); }

/* scope header — the box's own icon + name (+ its own resource) */
.ud-scope-hd { display: flex; align-items: center; gap: 8px; }

.ud-scope-hd b { font-size: 11px; font-weight: 700; color: var(--blue); letter-spacing: -0.01em; }
.ud-scope-hd b.v { color: var(--violet); }

/* a scope's own db, shown as a clean chip (no stray connector) */
.ud-scope-db {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  padding: 3px 9px 3px 4px;
  border-radius: 999px;
  background: #f2fbf6;
  border: 1px solid #d6efe1;
}

.ud-scope-db .ud-tile { width: 20px; height: 20px; border-radius: 6px; box-shadow: none; }
.ud-scope-db em { font-size: 7.5px; font-weight: 600; color: #2f6b52; }

.ud-tile.ud-mid { width: 32px; height: 32px; border-radius: 10px; }

/* ── the journey — phases run in a curved path inside the runner ── */
.ud-journey { display: flex; align-items: flex-start; gap: 0; padding: 2px 4px 0; }

.ud-phase { display: flex; flex-direction: column; align-items: center; }
.ud-tile.ud-box { width: 42px; height: 42px; border-radius: 13px; }

/* the curved hop between phases — the step line, lit as the journey moves */
.ud-hop { flex: none; align-self: flex-start; overflow: visible; }
.ud-hop path {
  fill: none;
  stroke: #d9cef0;
  stroke-width: 1.5;
  transition: stroke 0.25s var(--ease);
}
.ud-hop.is-lit path { stroke: var(--violet); }

/* ── RESOURCE — a db/fx call reached on its OWN coloured line ── */
.ud-res { display: flex; align-items: center; }
.ud-res.down { flex-direction: column; }
.ud-res.right { flex-direction: row; margin-left: auto; }

.ud-res .ud-node { flex-direction: column; gap: 3px; }
.ud-res .ud-tile { width: 22px; height: 22px; border-radius: 7px; }
.ud-res em { font-size: 7px; color: var(--dim); }

/* the coloured connector — green = db, violet = fx (distinct from step lines) */
.ud-line { flex: none; border-radius: 2px; }
.ud-res.down .ud-line { width: 1.5px; height: 15px; margin: 4px 0; }
.ud-res.right .ud-line { height: 1.5px; width: 16px; margin: 0 5px; }

.ud-line.k-db { background: #7fccaa; }
.ud-line.k-fx { background: #c9b8ef; }

/* ── agent brain — the orbit ── */
.ud-brain {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.ud-orbit {
  position: relative;
  width: 260px;
  height: 260px;
}

.ud-orbit::before {
  content: '';
  position: absolute;
  inset: 34px;
  border: 1.5px dashed #e2d8f7;
  border-radius: 50%;
}

.ud-hero {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 60px;
  height: 60px;
  border-radius: 19px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(150deg, #9d7fe0, var(--violet) 65%, #5f3fb8);
  box-shadow:
    0 6px 20px rgba(124, 91, 209, 0.35),
    0 0 0 9px rgba(124, 91, 209, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
  cursor: default;
  --kc-glow: rgba(124, 91, 209, 0.45);
  transition: transform 0.25s var(--ease);
}

.ud-hero:hover { transform: translate(-50%, -50%) scale(1.05); }
.ud-hero.is-now { animation: ud-pulse 1.1s var(--ease) infinite; }

.ud-hero .ud-type { right: -6px; bottom: -6px; }
.ud-hero .ud-type.on-hero { background: var(--blue); }

.ud-hero em {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  font-style: normal;
  font-size: 9px;
  font-weight: 700;
  color: var(--violet);
  white-space: nowrap;
}

/* satellites — a node placed on the ring */
.ud-sat {
  position: absolute;
  transform: translate(-50%, -50%);
  gap: 3px;
}

.ud-sat .ud-tile { width: 34px; height: 34px; border-radius: 11px; }
.ud-sat em { font-size: 8px; }

.ud-sat.p-top    { top: 34px; left: 50%; }
.ud-sat.p-right  { top: 50%; left: calc(100% - 34px); }
.ud-sat.p-bottom { top: calc(100% - 30px); left: 50%; }
.ud-sat.p-left   { top: 50%; left: 34px; }
.ud-sat.p-tl     { top: 26%; left: 24%; }
.ud-sat.p-bl     { top: 74%; left: 24%; }

/* ── phases — six silent circles, with Memory hanging off Observe ── */
.ud-phases {
  position: relative;
  display: flex;
  gap: 12px;
}

.ud-ph {
  position: relative;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--violet);
  background: var(--paper);
  border: 1.5px solid #e2d8f7;
  cursor: default;
  --kc-glow: rgba(124, 91, 209, 0.35);
  transition: all 0.2s var(--ease);
}

.ud-ph:hover { color: #fff; background: var(--violet); border-color: var(--violet); transform: translateY(-2px); }
.ud-ph.is-lit { color: #fff; background: var(--violet); border-color: var(--violet); }
.ud-ph.is-now { animation: ud-pulse 1.1s var(--ease) infinite; }

.ud-ph em {
  position: absolute;
  top: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  font-style: normal;
  font-size: 8px;
  font-weight: 650;
  color: var(--dim);
  white-space: nowrap;
}

/* the memory db call — perpendicular, inside Observe (the first phase) */
.ud-memcall {
  position: absolute;
  top: 100%;
  left: 13.5px;
  transform: translateX(-50%);
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.ud-perp {
  width: 1.5px;
  height: 18px;
  background: var(--hairline);
  transition: background 0.25s var(--ease);
}

.ud-memcall.is-lit .ud-perp { background: var(--green); }

/* ── the data world — Warehouse (read) + app_state (write) ── */
.ud-data {
  align-self: center;
  margin-left: 40px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

/* subtle reaches from the brain out to the data world */
.ud-reach {
  position: absolute;
  right: 96px;
  width: 82px;
  height: 1.5px;
  pointer-events: none;
  transition: opacity 0.25s var(--ease);
}

.ud-reach.read {
  top: calc(50% - 40px);
  background: repeating-linear-gradient(to right, var(--port) 0 5px, transparent 5px 10px);
  opacity: 0.7;
}

.ud-reach.write {
  top: calc(50% + 40px);
  background: repeating-linear-gradient(to right, var(--port) 0 5px, transparent 5px 10px);
  opacity: 0.7;
}

.ud-reach.is-lit { opacity: 1; }
.ud-reach.read.is-lit { background: repeating-linear-gradient(to right, #7fccaa 0 5px, transparent 5px 10px); }
.ud-reach.write.is-lit { background: var(--green); }

/* ═══ DEVELOPER DRAWER — a continuous stepper of the whole turn ═══ */
.ud-drawer {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: 320px;
  background: var(--paper);
  border-left: 1px solid var(--hairline);
  box-shadow: -8px 0 30px -18px rgba(15, 23, 42, 0.4);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s var(--ease);
  z-index: 30;
}

.ud-drawer.open { transform: none; }

.ud-drawer-hd {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--hairline);
}

.ud-drawer-hd b { font-size: 12px; font-weight: 700; color: var(--ink); }

.ud-drawer-x {
  border: none;
  background: none;
  color: var(--faint, #94a3b8);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}
.ud-drawer-x:hover { background: var(--canvas, #eff3fa); color: var(--ink); }

.ud-drawer-feed {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* each card = one node, same icon/type language as the canvas */
.ud-card {
  border: 1px solid var(--hairline);
  border-radius: 12px;
  padding: 10px 11px;
  background: var(--paper);
  cursor: pointer;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.ud-card:hover { border-color: #d8dee8; }

.ud-card.is-sel {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(47, 111, 228, 0.16);
}

.ud-card-hd { display: flex; align-items: center; gap: 8px; }
.ud-card-hd .ud-tile { width: 26px; height: 26px; border-radius: 8px; box-shadow: none; }
.ud-card-hd b { font-size: 11px; font-weight: 700; color: var(--ink); }

.ud-card-kind {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 7px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 5px;
  color: #fff;
}
.ud-card-kind.k-db { background: var(--green); }
.ud-card-kind.k-fx { background: var(--violet); }
.ud-card-kind.k-svc, .ud-card-kind.k-ui { background: var(--blue); }
.ud-card-kind.k-actor, .ud-card-kind.k-job { background: var(--slate); }

.ud-card-role { margin: 7px 0 0; font-size: 9px; line-height: 1.45; color: var(--body, #3f4a5f); }

.ud-card-row {
  display: flex;
  align-items: baseline;
  gap: 7px;
  margin-top: 6px;
  font-size: 8px;
}
.ud-card-row em { font-style: normal; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--faint, #94a3b8); min-width: 34px; }
.ud-card-row code { font-family: var(--mono); font-size: 8px; color: var(--ink); overflow-wrap: anywhere; }

.ud-rw {
  font-family: var(--mono);
  font-size: 7.5px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 5px;
}
.ud-rw.read { color: var(--blue-ink, #1d4ed8); background: #eef4ff; }
.ud-rw.write { color: #b45309; background: #fdf6ec; }
.ud-rw.readwrite { color: var(--green-ink, #047857); background: #eefaf4; }

.ud-card-objs { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 7px; }
.ud-obj {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-family: var(--mono);
  font-size: 7px;
  font-weight: 600;
  color: #2f6b52;
  background: #f2fbf6;
  border: 1px solid #d6efe1;
  border-radius: 6px;
  padding: 2px 6px;
}
.ud-obj svg { color: var(--green); }

/* ═══ FUNCTIONS — action tag (read/query/write/api) + tool marker ═══ */
.ud-act {
  font-family: var(--mono);
  font-size: 6.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 1px 5px;
  border-radius: 4px;
  margin-top: 1px;
}
.a-read  { color: #1d4ed8; background: #eef4ff; }
.a-gate  { color: #be123c; background: #fff1f2; }
.a-write { color: #b45309; background: #fdf6ec; }
.a-api   { color: #6d28d9; background: #f6f3fd; }

/* the tool marker — the agent invoked this function through a tool */
.ud-tool {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--violet);
  color: #fff;
  font-size: 6px;
  font-weight: 800;
  font-style: normal;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--paper);
}

/* Toolbox — the legend of agent-callable functions (violet, no wires) */
.ud-store.tools {
  background: #f8f6fe;
  border-color: #e2d8f7;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 22px -14px rgba(124, 91, 209, 0.3);
}
.ud-store.tools .ud-store-hd b { color: var(--violet); }
.ud-table.tool { border-color: #e6ddf8; gap: 5px; }
.ud-table.tool svg { color: var(--violet); }
.ud-table.tool em { color: #6d28d9; }
.ud-table.tool .ud-act { margin-top: 0; }

/* drawer: tool tag in the call row */
.ud-rw.tool { color: #6d28d9; background: #f6f3fd; }
.ud-card-row .ud-act { margin-top: 0; }

/* ═══════════════════════════════════════════════════════════════════════════
   v2 — fill the page (no scroll), reached tiles darken, compact footer flow
   ═══════════════════════════════════════════════════════════════════════════ */

/* the fx glyph — functions read "fx", never a lightning bolt */
.ud-fx { font-family: var(--mono); font-weight: 800; letter-spacing: -0.04em; line-height: 1; }

/* function/object tags under the tile — tool marker + action/rw */
.ud-res .ud-tags { display: flex; align-items: center; gap: 3px; flex-wrap: wrap; justify-content: center; }
.ud-tag.tool {
  font-family: var(--mono); font-size: 6.5px; font-weight: 700; letter-spacing: 0.02em;
  padding: 1px 5px; border-radius: 4px; color: #6d28d9; background: #f1ecfb;
}
.ud-res .ud-act { margin-top: 0; }

/* ── page fills the viewport; nothing scrolls except the footer strip ── */
/* .ud fills its flex parent exactly — the bar is subtracted, nothing overflows */
.ud { overflow: hidden; max-width: 100%; flex: 1 1 auto; min-height: 0; height: auto; }
.ud-product, .ud-pleft, .ud-pcanvas, .ud-psession, .ud-psession-body, .ud-pchat-log { min-width: 0; }
.ud-bar { margin-top: 12px; }
.ud-canvas {
  flex: 1;
  min-height: 0;
  width: 100%;
  box-sizing: border-box;
  margin: 0;
  justify-content: center;
  gap: 34px;
  padding: 20px 40px;
  overflow: auto;
}

/* a bit bigger, spread to occupy the page */
.ud-tile { width: 46px; height: 46px; }
.ud-tile.ud-box { width: 48px; height: 48px; border-radius: 14px; }
.ud-tile.ud-mid { width: 34px; height: 34px; }
.ud-sat .ud-tile { width: 37px; height: 37px; }
.ud-res .ud-tile { width: 25px; height: 25px; }
.ud-node em { font-size: 9px; }
.ud-scope-hd b { font-size: 12px; }
.ud-wire { width: 70px; }
.ud-render { margin-left: 30px; }
.ud-data-layer { gap: 26px; }
.ud-journey { gap: 4px; }

/* ── REACHED — once the pulse has passed, the tile fills and the icon darkens ── */
.ud-node.is-lit .ud-tile,
.ud-phase.is-lit .ud-tile.ud-box,
.ud-gate.is-lit .ud-tile {
  background: var(--kc);
  border-color: var(--kc);
  color: #fff;
}
.ud-node.is-lit .ud-tile .ud-fx,
.ud-phase.is-lit .ud-tile.ud-box .ud-fx,
.ud-gate.is-lit .ud-tile .ud-fx { color: #fff; }
/* the live step still pulses on top */
.ud-node.is-now .ud-tile,
.ud-phase.is-now .ud-tile.ud-box { animation: ud-pulse 1.1s var(--ease) infinite; }

/* ═══ FOOTER — small, fixed, our standard tiles ═══ */
.ud-footer {
  position: relative;
  flex: none;
  width: 100%;
  box-sizing: border-box;
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--hairline);
  box-shadow: 0 -6px 24px -18px rgba(15, 23, 42, 0.35);
  z-index: 25;
}

.ud-footer-strip {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  padding: 8px 14px;
}

.ud-footer-lbl {
  flex: none;
  font-size: 8px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: #94a3b8;
  margin-right: 4px;
}

/* each step = a compact chip in our tile language */
.ud-chip {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 4px 3px 3px;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.15s var(--ease);
}
.ud-chip:hover { background: #f4f6f9; }
.ud-chip .ud-tile { width: 26px; height: 26px; border-radius: 8px; }
.ud-chip em { font-size: 7px; font-weight: 600; color: var(--dim); max-width: 54px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ud-chip.is-lit .ud-tile { background: var(--kc); border-color: var(--kc); color: #fff; }
.ud-chip.is-lit .ud-tile .ud-fx { color: #fff; }
.ud-chip.is-now .ud-tile { animation: ud-pulse 1.1s var(--ease) infinite; }
.ud-chip.is-sel { background: #eef4ff; }
.ud-chip.is-sel .ud-tile { box-shadow: 0 0 0 2px var(--kc); }

/* ── detail popover — opens above the footer on click ── */
.ud-pop {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 16px;
  width: 300px;
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 16px 40px -14px rgba(15, 23, 42, 0.34);
  padding: 11px 12px;
  animation: ud-rise 0.2s var(--ease) both;
}
.ud-pop-hd { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.ud-pop-hd .ud-tile { width: 24px; height: 24px; border-radius: 7px; box-shadow: none; }
.ud-pop-hd b { font-size: 11px; font-weight: 700; color: var(--ink); }
.ud-pop-hd .ud-drawer-x { margin-left: auto; }
.ud-pop-role { margin: 8px 0 0; font-size: 9px; line-height: 1.45; color: var(--body, #3f4a5f); }

/* ── inline chat — opens inside the Chat node ── */
.ud-node.hot { position: relative; }
.ud-chatbox {
  position: absolute;
  left: calc(100% + 16px);
  top: -8px;
  width: 216px;
  z-index: 40;
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 12px 32px -12px rgba(15, 23, 42, 0.28);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: ud-rise 0.2s var(--ease) both;
}
.ud-chat-log { height: 148px; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.ud-chat-empty { margin: auto; font-size: 9px; color: #94a3b8; text-align: center; }
.ud-chat-msg { max-width: 88%; padding: 5px 9px; border-radius: 10px; font-size: 9px; line-height: 1.4; overflow-wrap: anywhere; }
.ud-chat-msg.user { align-self: flex-end; background: var(--blue); color: #fff; border-bottom-right-radius: 3px; }
.ud-chat-msg.agent { align-self: flex-start; background: #f4f6f9; color: var(--ink); border-bottom-left-radius: 3px; }
.ud-chat-msg.typing { color: var(--violet); background: #f6f3fd; font-style: italic; }
.ud-chat-input { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--hairline); }
.ud-chat-input input {
  flex: 1; min-width: 0; border: 1px solid var(--hairline); border-radius: 999px;
  padding: 6px 11px; font: 9.5px var(--sans); color: var(--ink); outline: none; background: #f8f9fb;
}
.ud-chat-input input:focus { border-color: var(--blue); background: #fff; box-shadow: 0 0 0 3px rgba(47, 111, 228, 0.1); }
.ud-chat-input button {
  flex: none; display: grid; place-items: center; width: 28px; height: 28px;
  border: none; border-radius: 50%; background: var(--ink); color: #fff; cursor: pointer;
}
.ud-chat-input button:disabled { opacity: 0.4; cursor: default; }

/* ── PACKET — a variable cube gliding through each step ── */
.ud-packet {
  position: absolute;
  z-index: 22;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  pointer-events: none;
  opacity: 0;
  transition: left 0.34s var(--ease), top 0.34s var(--ease), opacity 0.2s var(--ease);
}
.ud-packet.on { opacity: 1; }
.ud-packet i {
  width: 13px;
  height: 13px;
  border-radius: 3px;
  background: linear-gradient(150deg, #fff6d6, #ffd84d 60%, #f0a800);
  box-shadow: 0 0 0 3px rgba(240, 168, 0, 0.18), 0 2px 6px rgba(240, 168, 0, 0.5);
  transform: rotate(45deg);
}
.ud-packet em {
  font-family: var(--mono);
  font-size: 6.5px;
  font-weight: 700;
  color: #a86a00;
  background: #fff8e6;
  border: 1px solid #f3d998;
  border-radius: 4px;
  padding: 0 4px;
}

/* ── CHAT — fixed side panels, independent of the flowing canvas ── */
.ud-chatpanel {
  position: absolute;
  top: 84px;
  width: 232px;
  max-height: 260px;
  z-index: 45;
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: 16px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 16px 40px -14px rgba(15, 23, 42, 0.3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: ud-rise 0.2s var(--ease) both;
}
.ud-chatpanel.left { left: 22px; }
.ud-chatpanel.right { right: 22px; }

.ud-chatpanel-hd {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 11px;
  border-bottom: 1px solid var(--hairline);
  color: var(--blue);
}
.ud-chatpanel-hd b { font-size: 9.5px; font-weight: 700; color: var(--ink); }
.ud-chatpanel-hd .ud-drawer-x { margin-left: auto; }

.ud-chat-log { flex: 1; min-height: 90px; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.ud-chat-empty { margin: auto; font-size: 9px; color: #94a3b8; text-align: center; }
.ud-chat-msg { max-width: 88%; padding: 5px 9px; border-radius: 10px; font-size: 9.5px; line-height: 1.4; overflow-wrap: anywhere; }
.ud-chat-msg.user { align-self: flex-end; background: var(--blue); color: #fff; border-bottom-right-radius: 3px; }
.ud-chat-msg.agent { align-self: flex-start; background: #f4f6f9; color: var(--ink); border-bottom-left-radius: 3px; }
.ud-chat-msg.typing { color: var(--violet); background: #f6f3fd; font-style: italic; }

.ud-chat-input { flex: none; display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--hairline); }
.ud-chat-input input {
  flex: 1; min-width: 0; border: 1px solid var(--hairline); border-radius: 999px;
  padding: 7px 12px; font: 10px var(--sans); color: var(--ink); outline: none; background: #f8f9fb;
}
.ud-chat-input input:focus { border-color: var(--blue); background: #fff; box-shadow: 0 0 0 3px rgba(47, 111, 228, 0.1); }
.ud-chat-input button {
  flex: none; display: grid; place-items: center; width: 30px; height: 30px;
  border: none; border-radius: 50%; background: var(--ink); color: #fff; cursor: pointer;
}
.ud-chat-input button:disabled { opacity: 0.4; cursor: default; }

/* ── SKILL node in the runner header — the editable control surface ── */
.ud-scope-db.skill { cursor: pointer; background: #eefaf4; border-color: #c9ecda; transition: box-shadow 0.15s var(--ease); }
.ud-scope-db.skill:hover { box-shadow: 0 0 0 2px rgba(41, 151, 100, 0.2); }

/* ── SKILL PANEL — a real file editor for every agent file ── */
.ud-skillpanel {
  position: absolute;
  top: 66px;
  left: 50%;
  transform: translateX(-50%);
  width: 640px;
  max-width: calc(100% - 40px);
  height: calc(100% - 130px);
  z-index: 46;
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: 16px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 20px 50px -16px rgba(15, 23, 42, 0.34);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: ud-rise 0.2s var(--ease) both;
}

.ud-skill-count { font-size: 8px; color: #94a3b8; font-family: var(--mono); }
.ud-chatpanel-hd .ud-skill-count { margin-left: 6px; }

.ud-skill-2 { flex: 1; min-height: 0; display: flex; }

/* left — the file browser, grouped by what it controls */
.ud-skill-list {
  flex: none;
  width: 186px;
  overflow-y: auto;
  border-right: 1px solid var(--hairline);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ud-skill-group { display: flex; flex-direction: column; gap: 2px; }
.ud-skill-group > b { font-size: 7px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: #94a3b8; padding: 2px 4px; }
.ud-skill-item {
  text-align: left;
  border: none;
  background: none;
  border-radius: 6px;
  padding: 4px 8px;
  font-family: var(--mono);
  font-size: 9px;
  color: var(--body, #3f4a5f);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ud-skill-item:hover { background: #f4f6f9; }
.ud-skill-item.on { background: #eefaf4; color: var(--green-ink, #047857); font-weight: 700; }

/* right — the editor */
.ud-skill-edit { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 10px 12px; gap: 8px; }
.ud-skill-path code { font-family: var(--mono); font-size: 8.5px; color: var(--dim); overflow-wrap: anywhere; }
.ud-skill-empty { margin: auto; text-align: center; font-size: 10px; color: #94a3b8; max-width: 240px; }
.ud-skill-err { margin: 0; font-size: 8.5px; color: #b45309; background: #fdf6ec; border: 1px solid #f3ddb9; border-radius: 8px; padding: 6px 8px; }

.ud-skill-ta {
  flex: 1;
  min-height: 0;
  resize: none;
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 10px 12px;
  font: 11px/1.55 var(--mono);
  color: var(--ink);
  outline: none;
  background: #f8f9fb;
  white-space: pre;
  overflow: auto;
}
.ud-skill-ta:focus { border-color: var(--green); background: #fff; box-shadow: 0 0 0 3px rgba(41, 151, 100, 0.1); }

.ud-skill-actions { flex: none; display: flex; align-items: center; gap: 10px; }
.ud-skill-save {
  border: none; border-radius: 999px; padding: 7px 18px; font-size: 10px; font-weight: 650;
  color: #fff; background: var(--green); cursor: pointer;
}
.ud-skill-save:disabled { opacity: 0.4; cursor: default; }
.ud-skill-msg { font-size: 8.5px; color: var(--dim); overflow-wrap: anywhere; }

