/* Components on top of tokens.css. Sidebar/shell here; later tasks append
   graph, cube, drawer, badge sections. */
* { box-sizing: border-box; }
/* The user-agent's `[hidden] { display: none }` has UA priority, so ANY author rule
   that sets `display` on the same element silently defeats it — `.wf-nav{display:flex}`
   did exactly that, leaving the tree's disclosure control visibly dead. Restating it
   at author level with !important closes the whole class of bug, not one instance. */
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, system-ui, "Segoe UI", sans-serif;
  color: var(--ink);
  /* barely-there gradient mesh so glass reads as glass */
  background:
    radial-gradient(1100px 700px at 12% -8%, var(--glow) 0%, rgba(255,255,255,0) 60%),
    radial-gradient(900px 600px at 108% 18%, var(--accent-weak) 0%, rgba(255,255,255,0) 55%),
    var(--bg);
  line-height: 1.5;
}
.glass {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-md);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
}

/* shell: sidebar | center | drawer */
/* The sidebar and drawer are fixed glass OVERLAYS; the canvas spans full width
   and passes UNDER them (blurred through the glass) — neither clips it. */
.shell { display: block; min-height: 100vh; }
/* Inset convention: the LAYOUT CONTAINER owns the padding that keeps content off
   its edges (never rely on a child's ad-hoc margin for that). So #center always
   insets its children (header, graph) — text can't hug the column wall. */
/* Full-bleed canvas: #center is the whole viewport; the graph fills it edge-to-edge
   and all chrome (header, sidebar, drawer) floats over it as glass overlays — so
   nothing constrains the canvas top or bottom. */
#center { position: relative; min-width: 0; height: 100vh; }

/* sidebar — fixed full-height glass overlay on the left (mirrors #drawer on the
   right); the canvas passes under it, blurred through the glass. */
#sidebar { position: fixed; top: var(--space-3); left: var(--space-3); bottom: var(--space-3);
  width: var(--sidebar-w); border-radius: var(--radius-lg); padding: var(--space-4);
  overflow-y: auto; z-index: 20; }
.brand { font-weight: 700; font-size: var(--text-md); letter-spacing: -.01em;
  display: block; margin-bottom: var(--space-3); color: var(--ink); text-decoration: none; }
.wf-nav { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column;
  gap: var(--space-1); }
.wf-nav a { display: block; padding: var(--space-2) var(--space-3); border-radius: var(--radius-md);
  text-decoration: none; color: var(--gray-700); font-size: var(--text-sm); cursor: pointer; }
.wf-nav a:hover { background: var(--gray-100); color: var(--ink); }
.wf-nav a.active { background: var(--accent-weak); color: var(--accent-ink); font-weight: 600; }
/* ---- catalog tree ----
   A row is [twisty][link]; nesting is expressed by inline padding on the row, so the
   hover/active background still spans the full sidebar width at every depth. */
/* min-height, not padding: a two-line nested row is already tall enough, a
   one-line root row is not — and both must be comfortably tappable. */
.wf-row { display: flex; align-items: center; gap: 2px; min-height: 40px; }
.wf-row .wf-link { flex: 1; min-width: 0; padding: 6px var(--space-2); }
/* 28px, not the 16px glyph box: this is the primary control of the tree and the
   product is used from a phone. Still below the 44px ideal, but the row itself is
   44px tall, so the miss lands on the link rather than on nothing. */
.twisty { flex: 0 0 28px; width: 28px; height: 28px; padding: 0; border: 0;
  background: none; border-radius: var(--radius-sm);
  color: var(--gray-600); font-size: 13px; line-height: 1; cursor: pointer;
  display: grid; place-items: center;
  transition: transform .15s var(--ease), background .15s var(--ease); }
.twisty:hover { color: var(--ink); background: var(--gray-100); }
.twisty[aria-expanded="true"] { transform: rotate(90deg); }
.twisty-gap { flex: 0 0 28px; }
/* The step id leads; the workflow it refers to is secondary — the step belongs to the
   parent, the workflow is shared between call sites. */
.wf-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wf-ref { display: block; font-size: 12px; color: var(--gray-500);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* A guide line makes depth readable at a glance; without it a tree with small
   indents is just a list with ragged left edges. Sits under the twisty column. */
.wf-children { margin: 0; padding: 0; position: relative; }
.wf-children::before { content: ""; position: absolute; top: 2px; bottom: 2px;
  left: 13px; width: 1px; background: var(--gray-200); }
.wf-children .wf-children::before { left: 29px; }
.wf-children .wf-children .wf-children::before { left: 45px; }

/* The section icon in a drawer heading sits with the label, not as an emoji blob. */
.kv-head-icon { margin-right: 6px; color: var(--gray-500); }

/* ---- focus, once, for everything interactive ----
   Keyboard users get the same affordances as mouse users. :focus-visible keeps the
   ring off mouse clicks, so it costs the pointer experience nothing. */
a:focus-visible, button:focus-visible, input:focus-visible,
textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-sm);
}

/* center placeholder */
.center-empty { display: grid; place-items: center; height: 60vh; color: var(--gray-500); }

/* drawer host (off by default; sizing in Task 3) */
#drawer:empty { display: none; }

/* ---- block graph ---- */
/* Floating glass chip (title + Setup) over the canvas: content-width (NOT full
   width), clears the sidebar on the left; the canvas passes under it, blurred. */
.wf-header { position: absolute; z-index: 30; top: var(--space-3);
  left: calc(var(--sidebar-w) + var(--space-3) * 2); width: max-content; margin: 0;
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-4); border-radius: var(--radius-lg); }
.wf-header h1 { font-size: var(--text-lg); font-weight: 700; letter-spacing: -.02em; margin: 0; }
.hdr-run { padding: var(--space-1) var(--space-3); border: 0; border-radius: var(--radius-md);
  background: var(--accent); color: var(--on-accent); font-size: var(--text-sm); font-weight: 700;
  cursor: pointer; white-space: nowrap; transition: filter .15s var(--ease); }
.hdr-run:hover { filter: brightness(1.06); }
/* Breadcrumb trail of a drilled-in call. Sits before the title in the same glass
   chip; the header is a flex row, so it reads as one line. */
.crumbs { display: flex; align-items: center; gap: 6px; font-size: var(--text-sm);
  color: var(--gray-500); white-space: nowrap; max-width: 42vw; overflow: hidden; }
.crumbs a { color: var(--gray-700); text-decoration: none; }
.crumbs a:hover { color: var(--accent); text-decoration: underline; }
.crumb-current { color: var(--ink); font-weight: 600; }
.crumb-sep { color: var(--gray-300); }
/* "Используется в: …" — the reverse index, in the header of a library workflow. */
.used-by { font-size: var(--text-sm); color: var(--gray-500); white-space: nowrap; }
.used-by a { color: var(--accent); text-decoration: none; }
.used-by a:hover { text-decoration: underline; }
.used-by-step { color: var(--gray-500); margin-left: 4px; }
/* Pannable canvas (Google-Maps style): the viewport clips, .graph-canvas is
   dragged via CSS transform by ui.js — no scrollbars. */
.graph { padding: 0; position: absolute; inset: 0; z-index: 0;
  overflow: hidden; cursor: grab; touch-action: none; }
.graph.panning { cursor: grabbing; user-select: none; }
.graph-canvas { position: absolute; top: 0; left: 0;
  /* top padding clears the floating header, left padding clears the sidebar — so
     nodes are visible by default; panning slides content under them (blurred). */
  padding: 60px var(--space-4) var(--space-4) calc(var(--sidebar-w) + var(--space-4) * 2);
  transform-origin: 0 0; will-change: transform; }
/* Fixed-size cards on one horizontal track; connectors are drawn as an SVG
   overlay by ui.js (graphConnectors) — no CSS pseudo-arrows. align-items:center
   keeps cards their natural height (no vertical stretch) and aligns their centres
   so connector lines stay horizontal. */
.chain { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: nowrap;
  align-items: center; gap: var(--space-4) 60px; position: relative; z-index: 1; }
.cube { position: relative; display: flex; flex-direction: column; gap: var(--space-1);
  width: 150px; min-height: 74px; box-sizing: border-box; flex: 0 0 auto;
  padding: var(--space-3); border-radius: var(--radius-md);
  background: var(--glass-bg); border: 1px solid var(--gray-200); box-shadow: var(--shadow-sm);
  cursor: pointer; transition: transform .18s var(--ease), box-shadow .18s var(--ease),
    border-color .18s var(--ease); }
.cube:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.cube.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
/* A `use:` step (a whole sub-workflow used as one block): dashed "nested" outline
   + a corner drill-in link to open the sub-workflow's own graph. */
.cube-workflow { border-style: dashed; border-color: var(--accent); }
.cube-workflow .cube-icon { color: var(--accent); }
.drill-link { position: absolute; top: 6px; right: 8px; font-size: 15px; line-height: 1;
  text-decoration: none; color: var(--gray-500); border-radius: var(--radius-sm);
  /* A control, so a real target: 20x17 was a glyph you had to aim at. */
  min-width: 26px; min-height: 26px; display: grid; place-items: center;
  transition: color .15s var(--ease), background .15s var(--ease); }
.drill-link:hover { color: var(--accent); background: var(--accent-weak); }
/* SVG connector overlay (drawn by ui.js) sits behind the cards. */
.graph-connectors { position: absolute; top: 0; left: 0; pointer-events: none;
  z-index: 0; overflow: visible; }
.graph-connectors path { fill: none; stroke: var(--gray-300); stroke-width: 1.5; }
.cube-icon { font-size: 1.15rem; color: var(--gray-700); }
.cube-id { font-size: var(--text-sm); font-weight: 600; min-width: 0;
  overflow-wrap: anywhere; }  /* long ids (write_telegram_post) wrap inside the card */
.cube-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gray-300); }
.cube-done   { border-color: var(--ok); }
.cube-done   .cube-dot { background: var(--ok); }
.cube-failed { border-color: var(--err); }
.cube-failed .cube-dot { background: var(--err); }
.cube-running .cube-dot { background: var(--accent); }

/* ---- secret badge (key on blocks that reference {secret.NAME}) ---- */
.secret-badge { position: absolute; top: -7px; right: -7px; width: 20px; height: 20px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; line-height: 1; border-radius: 50%;
  border: 1px solid var(--gray-200); box-shadow: var(--shadow-sm); }
.secret-missing { background: var(--warn-weak); border-color: var(--err);
  color: var(--err-ink); }
.secret-set { background: var(--gray-100); border-color: var(--gray-300);
  color: var(--gray-500); }
.secret-section-head { margin-top: var(--space-3); }
.secret-msg { margin: var(--space-1) 0; padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm); font-size: var(--text-sm); }
.secret-msg-ok { background: rgba(22,163,74,.12); color: var(--ok); }
.secret-msg-err { background: rgba(220,38,38,.10); color: var(--err); }
.secret-msg-info { background: var(--gray-100); color: var(--gray-700); }
/* ---- popup modal (long drawer elements open here) ---- */
#modal:empty { display: none; }
.modal-backdrop { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  background: rgba(15,18,25,.38); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  padding: var(--space-4); }
.modal-panel { width: min(760px, 96vw); max-height: 88vh; display: flex; flex-direction: column;
  border-radius: var(--radius-lg); padding: var(--space-4); overflow: hidden; }
.modal-head { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-3); }
.modal-title { font-size: var(--text-md); font-weight: 700; overflow-wrap: anywhere; }
.modal-body { overflow: auto; }
/* buttons that open a popup for a long element */
.chip-open { display: inline-flex; align-items: center; gap: var(--space-1); margin: var(--space-1) 0;
  padding: var(--space-2) var(--space-3); border: 1px solid var(--gray-300); border-radius: var(--radius-md);
  background: var(--surface-chip); color: var(--gray-800); font-size: var(--text-sm); font-weight: 600;
  cursor: pointer; }
.chip-open:hover { border-color: var(--accent); color: var(--accent-ink); }
.drill-chip { text-decoration: none; border-color: var(--accent); color: var(--accent-ink); }
.chip-preview { display: block; color: var(--gray-500); font-size: var(--text-sm); margin: var(--space-1) 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* ---- editable prompt (AI block) ---- */
.prompt-hint { font-weight: 400; font-size: var(--text-sm); color: var(--gray-500); }
.prompt-edit { width: 100%; padding: var(--space-2); border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm); background: rgba(255,255,255,.7); font-size: 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; line-height: 1.5;
  resize: vertical; margin-bottom: var(--space-2); }
.prompt-edit:focus { outline: 2px solid var(--accent-weak); border-color: var(--accent); }

/* ---- drawer ---- */
#drawer { position: fixed; top: var(--space-3); right: var(--space-3); bottom: var(--space-3);
  width: min(380px, 90vw); border-radius: var(--radius-lg); padding: var(--space-4);
  overflow: auto; z-index: 20; transition: transform .26s var(--ease), opacity .26s var(--ease); }
.drawer-head { display: flex; align-items: center; gap: var(--space-2);
  margin-bottom: var(--space-3); }
.drawer-head .cube-icon { font-size: 1.3rem; }
.drawer-title { font-size: var(--text-md); font-weight: 700; }
.drawer-close { margin-left: auto; border: 0; background: var(--gray-100); cursor: pointer;
  width: 28px; height: 28px; border-radius: 50%; color: var(--gray-700); font-size: 1rem; }
.kv { margin: var(--space-2) 0; }
.kv-key { font-size: var(--text-sm); color: var(--gray-500); }
.kv-val { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: var(--text-sm);
  white-space: pre-wrap; word-break: break-word; }
.kv-head { font-size: var(--text-sm); font-weight: 600; color: var(--gray-700);
  margin: var(--space-3) 0 var(--space-1); }
.kv-sub { display: flex; gap: var(--space-3);
  margin: var(--space-1) 0 var(--space-1) var(--space-3); }
.kv-sub .kv-key { min-width: 76px; flex: none; }
.kv-text { margin-top: var(--space-1); }
/* Inter-step dependency chips in a block's drawer ("Зависит от"). */
.dep-list { display: flex; flex-wrap: wrap; gap: var(--space-1); margin-bottom: var(--space-2); }
.dep-chip { font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .78rem; color: var(--accent-ink); background: var(--accent-weak);
  border-radius: 999px; padding: 2px var(--space-2); white-space: nowrap; }
.field { display: block; margin: var(--space-3) 0; }
.field span { display: block; font-size: var(--text-sm); color: var(--gray-700);
  margin-bottom: var(--space-1); }
.field input { width: 100%; padding: var(--space-2); border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm); background: var(--glass-bg); font-size: var(--text-md); }
.field input:focus { outline: 2px solid var(--accent-weak); border-color: var(--accent); }
.btn-run { margin-top: var(--space-3); width: 100%; padding: var(--space-2) var(--space-3);
  border: 0; border-radius: var(--radius-md); background: var(--accent); color: #fff;
  font-size: var(--text-md); font-weight: 600; cursor: pointer; }
.btn-run:hover { filter: brightness(1.05); }
.drawer-state { font-size: var(--text-sm); color: var(--gray-500); }
.drawer-error { margin: var(--space-2) 0; padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm); background: rgba(220,38,38,.10); color: var(--err);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: var(--text-sm);
  white-space: pre-wrap; word-break: break-word; }
.err { color: var(--err); }

/* ---- run status badge + running pulse ---- */
#run-status:empty { display: none; }  /* no run yet → no gap in the header */
.badge { display: inline-block; margin: 0; padding: var(--space-1) var(--space-3);
  border-radius: 999px; font-size: var(--text-sm); font-weight: 600; background: var(--gray-100);
  color: var(--gray-700); }
.badge-running { background: var(--accent-weak); color: var(--accent-ink); }
.badge-completed { background: rgba(22,163,74,.14); color: var(--ok-ink); }
.badge-failed { background: rgba(220,38,38,.12); color: var(--err-ink); }
.status-completed { color: var(--ok); } .status-failed { color: var(--err); }
.status-running { color: var(--accent); } .status-pending { color: var(--gray-500); }
@keyframes cube-pulse {
  0%,100% { box-shadow: 0 0 0 0 var(--accent-weak); }
  50%     { box-shadow: 0 0 0 6px var(--accent-weak); }
}
.cube-running { border-color: var(--accent); animation: cube-pulse 1.4s var(--ease) infinite; }
@media (prefers-reduced-motion: reduce) { .cube-running { animation: none; } }
.cube-waiting_manual { border-color: var(--warn); }
.cube-waiting_manual .cube-dot { background: var(--warn); }
.badge-waiting_manual { background: var(--warn-weak); color: var(--warn-ink); }

/* ---- glass fallback ---- */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass, .cube { background: var(--surface-solid); }
}
/* ---- mobile menu button (hidden on desktop) ---- */
.menu-btn { display: none; }
/* ---- mobile ---- */
@media (max-width: 720px) {
  /* sidebar collapses to a slide-in overlay toggled by the ☰ button */
  #sidebar { z-index: 30; transform: translateX(-120%);
    transition: transform .26s var(--ease); }
  #sidebar.open { transform: none; box-shadow: var(--shadow-md); }
  .menu-btn { display: inline-flex; position: fixed; top: var(--space-3); left: var(--space-3);
    z-index: 31; width: 40px; height: 40px; border-radius: 50%; border: 0; cursor: pointer;
    align-items: center; justify-content: center; font-size: 1.1rem; }
  /* NO phantom sidebar gutter — the sidebar is a hidden overlay, so the canvas is
     full-bleed and pannable/pinch-zoomable by touch. */
  .graph-canvas { padding: 56px var(--space-4) var(--space-4) var(--space-4); }
  /* header clears the ☰ button on the left instead of the (hidden) sidebar */
  .wf-header { left: calc(40px + var(--space-3) * 2); right: var(--space-3);
    width: auto; }
  .wf-header h1 { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  /* The header is crowded on a phone: the trail truncates from the LEFT (the tail
     is where you are), and "Используется в" drops out entirely — it is context,
     not a control. */
  .crumbs { max-width: 40vw; direction: rtl; text-align: left; }
  .crumbs > * { direction: ltr; }
  .used-by { display: none; }
  /* opened block drawer covers the whole width — above the header + ☰ */
  #drawer { left: var(--space-3); width: auto; z-index: 40; }
  .drawer-close { width: 36px; height: 36px; font-size: 1.15rem; } /* finger-sized close */
}
.md-body { font-size: var(--text-md); line-height: 1.55; color: var(--gray-800);
  max-height: 46vh; overflow-y: auto; padding-right: var(--space-2); }
.md-body h1 { font-size: 1.3rem; margin: var(--space-3) 0 var(--space-2); }
.md-body h2 { font-size: 1.1rem; margin: var(--space-3) 0 var(--space-1); }
.md-body p, .md-body ul, .md-body ol { margin: var(--space-2) 0; }
.md-body li { margin-left: var(--space-3); }
.review-actions { display: flex; gap: var(--space-2); margin-top: var(--space-2); }
textarea[name="feedback"] { width: 100%; padding: var(--space-2);
  border: 1px solid var(--gray-300); border-radius: var(--radius-sm);
  background: var(--glass-bg); font: inherit; font-size: var(--text-md); resize: vertical; }

/* ---- loop container ---- */
/* The loop must occupy EXACTLY its inner content (cube/sub-chain) width in layout
   flow so cubes line up by their actual cubes across fan-out branches — NOT by the
   loop's padding/border. So the box itself is flow-transparent (no padding, border
   or background); the dashed rounded box is painted by ::before as an overlay that
   expands outward without affecting layout, and the header floats above the cubes. */
.loop { position: relative; padding: 0; border: none; background: none;
  cursor: pointer; }
.loop::before { content: ""; position: absolute; inset: -30px -10px -10px -10px;
  border: 2px dashed var(--gray-300); border-radius: var(--radius-md);
  background: var(--glass-bg); pointer-events: none; z-index: -1;
  transition: border-color .18s var(--ease); }
.loop:hover::before { border-color: var(--accent); }
.loop.active::before { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.loop-done::before   { border-color: var(--ok);  border-style: solid; }
.loop-failed::before { border-color: var(--err); border-style: solid; }
.loop-running::before { border-color: var(--accent); border-style: solid;
  animation: cube-pulse 1.4s var(--ease) infinite; }
/* Header floats absolutely just above the cubes so it adds no horizontal flow width
   (loop flow width == cube width) and stays inside the overlay's top band. */
.loop-header { position: absolute; bottom: 100%; left: 0; margin: 0 0 4px 0;
  display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm);
  white-space: nowrap; line-height: 1; pointer-events: none; }
.loop-icon { font-size: 1rem; color: var(--accent); }
.loop-id { font-weight: 700; color: var(--ink); }
.loop-condition { color: var(--gray-600); flex: 1; }
.loop-counter { color: var(--accent); font-weight: 600; white-space: nowrap; }
.chain-nested { margin-left: var(--space-3); }

/* ---- fan_out container: stacked parallel branches (one track per row) ---- */
.fan-out { border: 1px dashed var(--gray-300); border-radius: var(--radius-md);
  padding: var(--space-4); background: rgba(120,130,150,.04); flex: 0 0 auto; }
.fan-out-header { display: flex; gap: var(--space-2); align-items: center;
  cursor: pointer; font-weight: 700; color: var(--ink); margin-bottom: var(--space-3); }
.fan-out-icon { color: var(--accent); }
/* Extra inter-branch gap (--space-4, not --space-3) gives a loop's floating header
   room to sit above its cubes without colliding with the branch row above it. */
.fan-branches { display: flex; flex-direction: column; gap: var(--space-4); }
.fan-branch { display: flex; flex-direction: row; align-items: center; gap: var(--space-3); }
/* No text-transform: a branch name is the author's own value from the YAML
   ("publish", "social"). Upper-casing it shows something the file does not say. */
.fan-branch-name { min-width: 68px; font-size: 11px;
  letter-spacing: .02em; color: var(--gray-600); font-weight: 600; }
.fan-branch .chain-nested { margin-left: 0; }
.fan-out.fan-out-running { border-color: var(--accent); }

/* ---- cycle badge on plain cubes ---- */
.cycle-badge { display: inline-block; font-size: .72rem; font-weight: 600;
  color: var(--accent); background: var(--accent-weak);
  border-radius: 999px; padding: 0 var(--space-1); margin-left: var(--space-1);
  vertical-align: middle; }
