:root {
  --bg: #0d0f12;
  --bg-2: #14171c;
  --bg-3: #1b1f26;
  --line: #262b33;
  --line-2: #323843;
  --text: #e8eaed;
  --muted: #8a929e;
  --muted-2: #5b626d;
  --accent: #6ea8fe;
  --accent-dim: #2a3f63;
  --user: #2a3140;
  --green: #4ade80;
  --amber: #fbbf24;
  --red: #f87171;
  --violet: #a78bfa;
  --radius: 12px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--red); font-size: 13px; min-height: 18px; margin: 4px 0 0; }
button { font-family: inherit; cursor: pointer; }

/* ---------- Login ---------- */
.login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 50% -10%, #1a2030 0%, var(--bg) 60%);
}
.login-card {
  width: 320px; padding: 28px;
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 16px; display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.login-card .brand { font-size: 20px; }
.login-card input, .login-card button {
  height: 42px; border-radius: 10px; border: 1px solid var(--line-2);
  background: var(--bg-3); color: var(--text); padding: 0 14px; font-size: 14px;
}
.login-card button {
  background: var(--accent); color: #0b1220; border: none; font-weight: 600;
}
.login-card button:hover { filter: brightness(1.08); }

/* ---------- Brand ---------- */
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; letter-spacing: .2px; }
.brand-mark {
  width: 12px; height: 12px; border-radius: 4px;
  background: linear-gradient(135deg, var(--accent), var(--violet));
  box-shadow: 0 0 14px rgba(110,168,254,.5);
}

/* ---------- App layout ---------- */
.app { display: flex; flex-direction: column; height: 100vh; min-height: 0; }

/* ---------- Top bar ---------- */
.topbar {
  height: 58px; flex: none; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; padding: 0 14px 0 16px;
  background: var(--bg); z-index: 10;
}
.topbar-brand { font-size: 16px; }
.topbar-spacer { flex: 1; min-width: 0; }
.topbar-info { min-width: 0; max-width: 46%; }
.chat-title { font-weight: 600; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-meta { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.cost-chip { font-family: var(--mono); font-size: 11.5px; color: var(--muted); background: var(--bg-3); border: 1px solid var(--line); padding: 4px 9px; border-radius: 7px; }

.icon-btn {
  background: transparent; border: 1px solid var(--line-2); color: var(--muted);
  width: 32px; height: 32px; border-radius: 8px; display: inline-flex;
  align-items: center; justify-content: center; flex: none;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }

.back-btn {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  background: var(--bg-3); border: 1px solid var(--line-2); color: var(--text);
  height: 32px; padding: 0 12px 0 9px; border-radius: 8px; font-size: 13px; font-weight: 550;
}
.back-btn:hover { border-color: var(--accent); color: var(--accent); }

/* providers pills (now live in the topbar) */
.providers { display: flex; flex-wrap: nowrap; gap: 6px; }
.prov-pill { font-size: 10.5px; padding: 3px 8px; border-radius: 20px; border: 1px solid var(--line-2); color: var(--muted); display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.prov-pill .pd { width: 6px; height: 6px; border-radius: 50%; background: var(--muted-2); }
.prov-pill.on { color: var(--text); border-color: var(--accent-dim); }
.prov-pill.on .pd { background: var(--green); }

/* ===================================================================
   MAP VIEW — the spatial deck
   =================================================================== */
.map-view { position: relative; flex: 1; min-height: 0; overflow: hidden; background: var(--bg); }

.canvas-viewport {
  position: absolute; inset: 0; overflow: hidden;
  cursor: grab; touch-action: none;
}
.canvas-viewport.panning { cursor: grabbing; }

/* dotted grid that pans with the canvas (background-position is driven by JS) */
.canvas-grid {
  position: absolute; inset: -2000px;
  background-image:
    radial-gradient(circle at 1px 1px, rgba(255,255,255,.05) 1px, transparent 0);
  background-size: 26px 26px;
  pointer-events: none;
}
.map-view::after {
  /* subtle vignette so cards near edges feel grounded */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(120% 90% at 50% 0%, transparent 55%, rgba(0,0,0,.35) 100%);
}

/* the layer that actually gets transformed (translate + scale) */
.canvas-layer {
  position: absolute; top: 0; left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

/* ---------- Unit cards ---------- */
.unit {
  position: absolute; top: 0; left: 0;
  width: 232px; padding: 13px 14px 12px;
  background: linear-gradient(180deg, var(--bg-2), var(--bg-3));
  border: 1px solid var(--line-2); border-radius: 14px;
  box-shadow: 0 8px 26px rgba(0,0,0,.45);
  cursor: pointer; user-select: none;
  transition: border-color .15s, box-shadow .15s, transform .06s;
  will-change: transform;
}
.unit:hover { border-color: var(--accent); box-shadow: 0 10px 32px rgba(0,0,0,.55), 0 0 0 1px var(--accent-dim); }
.unit.dragging { cursor: grabbing; box-shadow: 0 16px 40px rgba(0,0,0,.6); z-index: 5; }
.unit.active { border-color: var(--accent); }

.unit-head { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; }
.unit-status {
  width: 11px; height: 11px; border-radius: 50%; flex: none; position: relative;
  background: var(--muted-2);
}
.unit-title { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.unit-tag { display: inline-block; font-size: 9.5px; padding: 2px 6px; border-radius: 5px; background: var(--accent-dim); color: var(--accent); text-transform: uppercase; letter-spacing: .5px; font-weight: 600; flex: none; }

.unit-sub { font-size: 11.5px; color: var(--muted); line-height: 1.45; max-height: 33px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.unit-sub.needs { color: var(--green); font-weight: 550; }

.unit-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.unit-state-label { font-size: 10.5px; color: var(--muted-2); text-transform: uppercase; letter-spacing: .4px; }
.unit-cost { font-family: var(--mono); font-size: 11px; color: var(--muted); }

/* status indicator colours + glow (mirrors the old .dot semantics) */
.unit-status.idle { background: var(--muted-2); }
.unit-status.thinking { background: var(--amber); box-shadow: 0 0 10px 1px rgba(251,191,36,.55); animation: u-pulse 1.1s infinite; }
.unit-status.streaming { background: var(--accent); box-shadow: 0 0 10px 1px rgba(110,168,254,.6); animation: u-pulse 1.1s infinite; }
.unit-status.tool { background: var(--violet); box-shadow: 0 0 10px 1px rgba(167,139,250,.6); animation: u-pulse 1.1s infinite; }
.unit-status.error { background: var(--red); box-shadow: 0 0 9px 1px rgba(248,113,113,.5); }
.unit-status.needs-input { background: var(--green); animation: u-ring 1.4s infinite; }

/* whole-card green ring when an agent needs you */
.unit.needs-input { border-color: rgba(74,222,128,.55); box-shadow: 0 10px 32px rgba(0,0,0,.5), 0 0 0 1px rgba(74,222,128,.4); animation: card-ring 1.8s infinite; }

@keyframes u-pulse { 0%,100%{opacity:1} 50%{opacity:.4} }
@keyframes u-ring {
  0%{box-shadow:0 0 0 0 rgba(74,222,128,.55)}
  70%{box-shadow:0 0 0 8px rgba(74,222,128,0)}
  100%{box-shadow:0 0 0 0 rgba(74,222,128,0)}
}
@keyframes card-ring {
  0%,100%{box-shadow:0 10px 32px rgba(0,0,0,.5), 0 0 0 1px rgba(74,222,128,.35)}
  50%{box-shadow:0 10px 32px rgba(0,0,0,.5), 0 0 0 3px rgba(74,222,128,.25)}
}

/* ---------- Canvas controls ---------- */
.canvas-controls {
  position: absolute; right: 16px; bottom: 16px; z-index: 6;
  display: flex; flex-direction: column; align-items: stretch; gap: 6px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
.map-ctrl {
  width: 36px; height: 32px; border-radius: 8px; border: 1px solid transparent;
  background: transparent; color: var(--muted); display: flex; align-items: center; justify-content: center;
}
.map-ctrl:hover { color: var(--text); background: var(--bg-3); border-color: var(--line-2); }
.zoom-label { text-align: center; font-family: var(--mono); font-size: 10.5px; color: var(--muted-2); user-select: none; }

.map-hint {
  position: absolute; left: 16px; bottom: 18px; z-index: 6;
  font-size: 11px; color: var(--muted-2); background: rgba(13,15,18,.6);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; pointer-events: none;
  backdrop-filter: blur(4px);
}

.canvas-empty {
  position: absolute; inset: 0; z-index: 4; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--muted-2); gap: 14px;
}
.canvas-empty .empty-icon { color: var(--line-2); }
.ghost-btn { pointer-events: auto; background: var(--bg-3); border: 1px solid var(--line-2); color: var(--text); height: 38px; padding: 0 18px; border-radius: 10px; font-weight: 600; }
.ghost-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Main / chat view ---------- */
.main { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; }

.messages { flex: 1; overflow-y: auto; padding: 22px clamp(16px, 6vw, 90px); min-height: 0; }
.empty-state { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted-2); gap: 12px; }
.empty-icon { color: var(--line-2); }

.msg { max-width: 760px; margin: 0 auto 18px; display: flex; gap: 12px; }
.msg .avatar { width: 26px; height: 26px; border-radius: 7px; flex: none; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; }
.msg.user .avatar { background: var(--user); color: var(--text); }
.msg.assistant .avatar { background: linear-gradient(135deg, var(--accent), var(--violet)); color: #0b1220; }
.msg .bubble { flex: 1; min-width: 0; }
.msg .role { font-size: 11px; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .5px; }
.msg .content { white-space: pre-wrap; word-wrap: break-word; line-height: 1.6; }
.msg.user .content { color: var(--text); }
.msg.assistant .content { color: #d7dbe2; }
.cursor-blink::after { content: "▋"; color: var(--accent); animation: blink 1s steps(2) infinite; margin-left: 1px; }
@keyframes blink { 0%,50%{opacity:1} 51%,100%{opacity:0} }

.tool-line { font-family: var(--mono); font-size: 12px; color: var(--violet); background: var(--bg-2); border: 1px solid var(--line); border-left: 2px solid var(--violet); border-radius: 6px; padding: 6px 10px; margin: 6px 0; white-space: pre-wrap; }
.msg-foot { font-size: 11px; color: var(--muted-2); margin-top: 6px; font-family: var(--mono); }
.msg-error { color: var(--red); font-size: 12.5px; margin-top: 6px; white-space: pre-wrap; }
.needs-input-banner { max-width: 760px; margin: 0 auto 18px; background: rgba(74,222,128,.08); border: 1px solid rgba(74,222,128,.35); color: var(--green); border-radius: 10px; padding: 10px 14px; font-size: 13px; }

/* ---------- Composer ---------- */
.composer { border-top: 1px solid var(--line); padding: 12px clamp(12px, 5vw, 70px); display: flex; gap: 10px; align-items: flex-end; background: var(--bg); }
.composer textarea {
  flex: 1; resize: none; max-height: 200px; background: var(--bg-3); color: var(--text);
  border: 1px solid var(--line-2); border-radius: 12px; padding: 12px 14px; font-family: inherit;
  font-size: 14.5px; line-height: 1.5; outline: none;
}
.composer textarea:focus { border-color: var(--accent); }
.send-btn, .stop-btn { width: 44px; height: 44px; border-radius: 12px; border: none; display: flex; align-items: center; justify-content: center; flex: none; }
.send-btn { background: var(--accent); color: #0b1220; }
.send-btn:disabled { opacity: .4; cursor: not-allowed; }
.stop-btn { background: var(--bg-3); color: var(--red); border: 1px solid var(--line-2); }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal-card { width: 440px; max-width: 100%; background: var(--bg-2); border: 1px solid var(--line); border-radius: 16px; padding: 22px; box-shadow: 0 24px 70px rgba(0,0,0,.6); }
.modal-card h3 { margin: 0 0 16px; }
.modal-card label { display: block; font-size: 12px; color: var(--muted); margin: 14px 0 6px; }
.modal-card input[type=text], .modal-card select { width: 100%; height: 40px; background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 9px; color: var(--text); padding: 0 12px; font-size: 13.5px; font-family: inherit; }
.row { display: flex; gap: 12px; }
.col { flex: 1; }
.provider-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.prov-card { border: 1px solid var(--line-2); border-radius: 10px; padding: 10px 12px; cursor: pointer; display: flex; align-items: center; gap: 9px; }
.prov-card.sel { border-color: var(--accent); background: var(--accent-dim); }
.prov-card.off { opacity: .45; cursor: not-allowed; }
.prov-card .pd { width: 7px; height: 7px; border-radius: 50%; background: var(--muted-2); }
.prov-card.on .pd { background: var(--green); }
.prov-card .pname { font-size: 13px; font-weight: 550; }
.prov-card .pstate { font-size: 10.5px; color: var(--muted); margin-left: auto; }

/* worktree checkbox */
.check-row { display: flex !important; align-items: flex-start; gap: 10px; margin: 18px 0 0 !important; cursor: pointer; }
.check-row input[type=checkbox] { width: 17px; height: 17px; margin-top: 1px; accent-color: var(--accent); flex: none; cursor: pointer; }
.check-body { display: flex; flex-direction: column; gap: 2px; }
.check-title { font-size: 13px; color: var(--text); font-weight: 550; }
.check-hint { font-size: 11.5px; color: var(--muted); line-height: 1.4; }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.modal-actions button { height: 40px; padding: 0 18px; border-radius: 9px; border: none; background: var(--accent); color: #0b1220; font-weight: 600; }
.modal-actions .ghost { background: transparent; border: 1px solid var(--line-2); color: var(--text); }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  .topbar { gap: 8px; padding: 0 10px; }
  .topbar-brand { display: none; }
  .providers { display: none; }
  .topbar-info { max-width: none; }
  .unit { width: 200px; }
  .map-hint { display: none; }
  .canvas-controls { right: 10px; bottom: 10px; }
  .msg, .needs-input-banner { max-width: 100%; }
  .pipelines-view { grid-template-columns: 1fr; }
  .pl-rail { display: none; }
  .stage-drawer { width: 100%; }
  .view-switch { padding: 2px; }
  .vs-btn { padding: 5px 9px; font-size: 12px; }
  .stats-wrap { padding: 18px 14px 48px; }
  .stats-cards { grid-template-columns: repeat(2, 1fr); }
  .stat-value { font-size: 22px; }
  .stats-table { font-size: 12px; }
  .stats-table th, .stats-table td { padding: 6px 7px; }
}

/* ===================================================================
   VIEW SWITCH
   =================================================================== */
.view-switch { display: inline-flex; background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 9px; padding: 2px; gap: 2px; }
.vs-btn { background: transparent; border: none; color: var(--muted); font-size: 12.5px; font-weight: 550; padding: 5px 12px; border-radius: 7px; }
.vs-btn:hover { color: var(--text); }
.vs-btn.active { background: var(--accent); color: #0b1220; }

/* ===================================================================
   PIPELINES VIEW
   =================================================================== */
.pipelines-view { position: relative; flex: 1; min-height: 0; display: grid; grid-template-columns: 230px 1fr; }
.pl-rail { border-right: 1px solid var(--line); background: var(--bg-2); display: flex; flex-direction: column; min-height: 0; }
.pl-rail-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 10px; border-bottom: 1px solid var(--line); font-weight: 600; font-size: 13px; }
.pl-list { flex: 1; overflow-y: auto; padding: 8px; }
.pl-item { padding: 10px 11px; border-radius: 9px; cursor: pointer; margin-bottom: 4px; border: 1px solid transparent; }
.pl-item:hover { background: var(--bg-3); }
.pl-item.active { background: var(--bg-3); border-color: var(--line-2); }
.pl-item-name { font-size: 13px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-item-sub { font-size: 11px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-item-sub .run-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }

.pl-main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.pl-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: var(--muted-2); text-align: center; }
.pl-empty p { color: var(--muted); line-height: 1.6; }
.ghost-btn { background: var(--bg-3); border: 1px solid var(--line-2); color: var(--text); height: 36px; padding: 0 16px; border-radius: 9px; font-size: 13px; font-weight: 550; }
.ghost-btn:hover { border-color: var(--accent); color: var(--accent); }

.pl-board { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.pl-board-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.pl-name-input { background: transparent; border: 1px solid transparent; color: var(--text); font-size: 16px; font-weight: 650; padding: 5px 8px; border-radius: 8px; min-width: 0; }
.pl-name-input:hover { border-color: var(--line-2); }
.pl-name-input:focus { border-color: var(--accent); outline: none; background: var(--bg-3); }
.pl-cwd { font-family: var(--mono); font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-spacer { flex: 1; }
/* per-run cost budget input in the board header */
.pl-budget { display: inline-flex; align-items: center; gap: 7px; font-size: 11px; color: var(--muted); white-space: nowrap; }
.pl-budget-label { text-transform: uppercase; letter-spacing: .4px; }
.pl-budget-input { width: 64px; background: var(--bg-3); border: 1px solid var(--line-2); color: var(--text); border-radius: 7px; padding: 4px 8px; font-family: var(--mono); font-size: 11.5px; text-align: right; }
.pl-budget-input:focus { border-color: var(--accent); outline: none; }
.pl-note { margin: 10px 18px 0; padding: 8px 12px; border-radius: 8px; background: rgba(251,191,36,.08); border: 1px solid rgba(251,191,36,.3); color: var(--amber); font-size: 12px; }
.pl-note.ok { background: rgba(74,222,128,.08); border-color: rgba(74,222,128,.35); color: var(--green); }

/* apply / discard worktree buttons */
.pl-apply { color: var(--green); border-color: rgba(74,222,128,.4); }
.pl-apply:hover { border-color: var(--green); color: var(--green); background: rgba(74,222,128,.1); }
.pl-discard { color: var(--red); border-color: rgba(248,113,113,.4); }
.pl-discard:hover { border-color: var(--red); color: var(--red); background: rgba(248,113,113,.1); }
.pl-apply:disabled, .pl-discard:disabled { opacity: .4; cursor: not-allowed; }

/* stage chain */
.pl-stages { flex: 1; min-height: 0; overflow: auto; padding: 26px 18px; display: flex; align-items: flex-start; gap: 0; }
.stage-card {
  position: relative; flex: none; width: 256px; display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--bg-2), var(--bg-3));
  border: 1px solid var(--line-2); border-radius: 14px; padding: 14px 15px;
  cursor: pointer; transition: border-color .15s, box-shadow .15s;
}
.stage-card:hover { border-color: var(--accent); }
.stage-arrow { flex: none; align-self: center; width: 38px; text-align: center; color: var(--muted-2); font-size: 18px; user-select: none; }
.stage-top { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; }
.stage-cap { font-size: 9.5px; text-transform: uppercase; letter-spacing: .5px; font-weight: 700; padding: 2px 7px; border-radius: 5px; background: var(--accent-dim); color: var(--accent); }
.stage-cap.cmd { background: rgba(167,139,250,.18); color: var(--violet); }
.stage-dot { width: 9px; height: 9px; border-radius: 50%; margin-left: auto; background: var(--muted-2); }
.stage-dot.running { background: var(--accent); box-shadow: 0 0 9px 1px rgba(110,168,254,.6); animation: u-pulse 1.1s infinite; }
.stage-dot.done { background: var(--green); }
.stage-dot.error { background: var(--red); }
.stage-name { font-size: 14px; font-weight: 600; }
.stage-agent { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.stage-agent .ag { color: var(--text); font-weight: 550; }
.stage-agent .badge { font-size: 9.5px; padding: 1px 5px; border-radius: 4px; margin-left: 5px; background: var(--bg); border: 1px solid var(--line-2); color: var(--muted); }
.stage-agent .badge.write { color: var(--amber); border-color: rgba(251,191,36,.4); }
.stage-agent .badge.fallback { color: var(--violet); border-color: rgba(167,139,250,.4); }
.stage-agent.stage-cmd { font-family: var(--mono); font-size: 11px; color: var(--violet); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stage-loop { margin-top: 6px; font-size: 10.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 3px; padding: 2px 7px; border-radius: 5px; background: var(--bg); border: 1px solid var(--line-2); align-self: flex-start; }
/* live tail while a stage runs — clean sans-serif, faded at the bottom (no raw mono dump) */
.stage-stream {
  font-size: 11.5px; color: var(--muted); margin-top: 11px; max-height: 86px; overflow: hidden;
  white-space: pre-wrap; line-height: 1.5; word-break: break-word;
  -webkit-mask-image: linear-gradient(180deg, #000 58%, transparent); mask-image: linear-gradient(180deg, #000 58%, transparent);
}
.stage-stream:empty { display: none; }

/* finished stage output — rendered markdown, clamped with a soft fade; "ver todo" for the rest */
.stage-result {
  margin-top: 11px; max-height: 188px; overflow: hidden; position: relative;
  font-size: 12px; line-height: 1.55; color: #c9cfda;
  -webkit-mask-image: linear-gradient(180deg, #000 72%, transparent); mask-image: linear-gradient(180deg, #000 72%, transparent);
}
.stage-result > :first-child { margin-top: 0; }
.stage-result .md-p { margin: 0 0 7px; }
.stage-result .md-h { margin: 9px 0 5px; }
.stage-result .md-h1 { font-size: 14px; }
.stage-result .md-h2 { font-size: 13.5px; }
.stage-result .md-h3, .stage-result .md-h4, .stage-result .md-h5, .stage-result .md-h6 { font-size: 12.5px; }
.stage-result .md-list { margin: 0 0 7px; padding-left: 18px; }
.stage-result .md-list li { margin: 2px 0; }
.stage-result .md-pre { margin: 0 0 8px; padding: 9px 11px; font-size: 11px; }
.stage-result .md-table-wrap { margin: 0 0 8px; }
.stage-result .md-table { font-size: 11px; }
.stage-result .md-table th, .stage-result .md-table td { padding: 5px 8px; }
.stage-result code { font-size: 11px; color: #e6c07b; background: var(--bg-3); border: 1px solid var(--line); border-radius: 4px; padding: 1px 4px; }
.stage-result strong { color: var(--text); font-weight: 650; }
.stage-result a { color: var(--accent); text-decoration: none; }
.stage-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; }
.stage-foot-left { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.stage-state-label { font-size: 10px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted-2); }
.stage-iter { font-size: 10px; font-weight: 650; color: var(--accent); background: var(--accent-dim); padding: 1px 6px; border-radius: 5px; white-space: nowrap; }
.stage-cost { font-family: var(--mono); font-size: 10.5px; color: var(--muted); }
.stage-card.running { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent-dim), 0 10px 30px rgba(0,0,0,.4); }
.stage-card.done { border-color: rgba(74,222,128,.4); }
.stage-card.error { border-color: rgba(248,113,113,.5); }
.stage-arrow.flow { color: var(--accent); }

/* "Pensando" (razonamiento) — atenuado y separado de lo que el agente DICE */
.stage-thinking {
  margin-top: 10px; font-size: 11px; color: var(--muted-2); line-height: 1.5;
  border-left: 2px solid var(--violet); padding: 1px 0 1px 9px; max-height: 72px; overflow: hidden;
  -webkit-mask-image: linear-gradient(180deg, #000 55%, transparent); mask-image: linear-gradient(180deg, #000 55%, transparent);
}
.think-label {
  display: inline-block; font-size: 9px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--violet); font-weight: 700; margin-right: 7px;
}
.stage-thinking .think-txt { font-style: italic; white-space: pre-wrap; word-break: break-word; }

/* chat (orquestador): bloque "pensando" dentro de la burbuja de la etapa */
.orch-think {
  margin: 4px 0 8px; font-size: 12.5px; color: var(--muted); line-height: 1.55;
  border-left: 2px solid var(--violet); background: rgba(167,139,250,.06);
  border-radius: 0 8px 8px 0; padding: 7px 12px; max-height: 180px; overflow: auto;
}
.orch-think .think-txt { font-style: italic; white-space: pre-wrap; word-break: break-word; }

/* transcripción ("ver todo"): sección de razonamiento + etiqueta de respuesta */
.rt-think { margin: 4px 0 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg-2); overflow: hidden; }
.rt-think > summary { cursor: pointer; padding: 8px 12px; font-size: 12px; color: var(--violet); font-weight: 600; }
.rt-think-pre { color: var(--muted); font-style: italic; margin: 0; border: none; background: transparent; }
.rt-out-label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 6px 0 5px; font-weight: 600; }

/* parallel (fan-out) stage card */
.stage-cap.par { background: rgba(74,222,128,.16); color: var(--green); }
.stage-card.stage-parallel { width: 264px; }
.stage-branches-board { display: flex; flex-direction: column; gap: 6px; margin-top: 9px; }
.branch-mini { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.branch-mini-head { display: flex; align-items: center; gap: 6px; }
.branch-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--muted-2); }
.branch-dot.running { background: var(--accent); box-shadow: 0 0 7px 1px rgba(110,168,254,.6); animation: u-pulse 1.1s infinite; }
.branch-dot.done { background: var(--green); }
.branch-dot.error { background: var(--red); }
.branch-name { font-size: 11.5px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.branch-ag { font-size: 10.5px; color: var(--muted); margin-left: auto; white-space: nowrap; }
.branch-cost { font-family: var(--mono); font-size: 9.5px; color: var(--muted-2); flex: none; }
.branch-stream { font-family: var(--mono); font-size: 10px; color: var(--muted); margin-top: 4px; max-height: 40px; overflow: hidden; white-space: pre-wrap; line-height: 1.4; opacity: .9; }
.branch-stream:empty { display: none; }
.stage-merge { margin-top: 9px; font-size: 11px; color: var(--muted); padding: 4px 8px; border-radius: 6px; background: var(--bg); border: 1px solid var(--line-2); border-left: 2px solid var(--green); align-self: flex-start; }
.stage-merge .ag { color: var(--text); font-weight: 550; }

/* compete (best-of-N) stage card: amber/violet tag, rival implementer rows, judge footer + winner highlight */
.stage-cap.compete { background: rgba(251,191,36,.16); color: var(--amber); }
.stage-merge.judge { border-left-color: var(--amber); }
.branch-mini.compete-mini.winner { border-color: var(--green); box-shadow: 0 0 0 1px rgba(74,222,128,.45); background: rgba(74,222,128,.06); }
.branch-winner { font-size: 9px; font-weight: 700; letter-spacing: .4px; color: var(--green); background: rgba(74,222,128,.14); border: 1px solid rgba(74,222,128,.4); padding: 1px 5px; border-radius: 5px; flex: none; white-space: nowrap; }

/* branch editor in the drawer */
.branch-row { border: 1px solid var(--line-2); border-radius: 10px; padding: 10px; margin-bottom: 8px; background: var(--bg-3); display: flex; flex-direction: column; gap: 8px; }
.branch-row-head { display: flex; align-items: center; gap: 8px; }
.branch-row-head .br-name { flex: 1; }
.branch-row .br-del { flex: none; }
.branch-row .br-del:hover { color: var(--red); border-color: var(--red); }
.branch-add { width: 100%; background: transparent; border: 1px dashed var(--line-2); color: var(--text); height: 36px; border-radius: 9px; font-weight: 550; }
.branch-add:hover { border-color: var(--accent); color: var(--accent); }
#stage-parallel-group .muted.small { font-size: 11.5px; line-height: 1.5; margin: 0 0 10px; }

/* loop-back return chips beneath the chain */
.pl-loops { flex: none; padding: 0 18px 14px; display: flex; flex-wrap: wrap; gap: 8px; }
.loop-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; color: var(--muted);
  background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 8px;
  padding: 6px 11px; transition: border-color .15s, color .15s, background .15s;
}
.loop-chip b { color: var(--text); font-weight: 600; }
.loop-chip .loop-glyph { color: var(--muted-2); font-size: 14px; }
.loop-chip .loop-arrow { color: var(--muted-2); }
.loop-chip .loop-max { color: var(--muted-2); font-family: var(--mono); font-size: 10.5px; }
.loop-chip.active {
  border-color: var(--accent); color: var(--text);
  background: var(--accent-dim);
}
.loop-chip.active .loop-glyph, .loop-chip.active .loop-arrow { color: var(--accent); }
.loop-chip.flash { animation: loop-flash 1s ease-out; }
@keyframes loop-flash {
  0% { box-shadow: 0 0 0 0 rgba(110,168,254,.55); }
  60% { box-shadow: 0 0 0 6px rgba(110,168,254,0); }
  100% { box-shadow: 0 0 0 0 rgba(110,168,254,0); }
}

.pl-runbar-wrap { border-top: 1px solid var(--line); background: var(--bg); padding: 12px 18px 10px; }
.pl-runbar { display: flex; gap: 10px; align-items: flex-end; }
.pl-runbar-hint { margin-top: 7px; font-size: 11px; color: var(--muted-2); line-height: 1.4; }
.pl-runbar textarea { flex: 1; resize: none; max-height: 120px; background: var(--bg-3); color: var(--text); border: 1px solid var(--line-2); border-radius: 11px; padding: 11px 13px; font-family: inherit; font-size: 14px; line-height: 1.5; outline: none; }
.pl-runbar textarea:focus { border-color: var(--accent); }
.run-btn { background: var(--accent); color: #0b1220; border: none; height: 44px; padding: 0 22px; border-radius: 11px; font-weight: 650; font-size: 14px; flex: none; }
.run-btn:hover { filter: brightness(1.08); }
.run-btn:disabled { opacity: .4; cursor: not-allowed; }
.pl-runbar .stop-btn { width: 44px; height: 44px; }

/* stage config drawer */
.stage-drawer { position: absolute; top: 0; right: 0; bottom: 0; width: 360px; background: var(--bg-2); border-left: 1px solid var(--line); padding: 16px 18px; overflow-y: auto; box-shadow: -16px 0 40px rgba(0,0,0,.4); z-index: 15; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; font-weight: 650; }
.drawer-move { display: flex; gap: 6px; }
.drawer-move .icon-btn { font-size: 16px; }
.stage-drawer label { display: block; font-size: 12px; color: var(--muted); margin: 13px 0 6px; }
.drawer-section { margin: 20px 0 6px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 12.5px; font-weight: 650; color: var(--text); }
#stage-loop-group { margin-top: 4px; }
#stage-command-group textarea { font-family: var(--mono); font-size: 12.5px; }
.stage-drawer input, .stage-drawer select, .stage-drawer textarea { width: 100%; background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 9px; color: var(--text); padding: 9px 11px; font-size: 13.5px; font-family: inherit; }
.stage-drawer textarea { resize: vertical; line-height: 1.5; }
.route-row { display: flex; gap: 8px; }
.route-row select { flex: 1; }
.drawer-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 20px; }
.drawer-actions button { height: 38px; padding: 0 16px; border-radius: 9px; border: none; background: var(--accent); color: #0b1220; font-weight: 600; }
.drawer-actions .ghost { background: transparent; border: 1px solid var(--line-2); color: var(--red); }
.check-row { display: flex; align-items: flex-start; gap: 10px; }
.check-row input { width: auto; margin-top: 3px; }
.check-body { display: flex; flex-direction: column; }
.check-title { font-size: 13px; }
.check-hint { font-size: 11px; color: var(--muted); }
.modal-card .small { font-size: 11.5px; line-height: 1.5; margin: 10px 0 0; }

/* ===================================================================
   RUN PROGRESS — "Etapa 2/4" + thin fill bar + helper note
   =================================================================== */
.pl-progress { display: flex; align-items: center; gap: 12px; padding: 10px 18px 0; flex-wrap: wrap; }
.pl-progress-label { font-size: 11.5px; font-weight: 650; color: var(--text); white-space: nowrap; font-family: var(--mono); }
.pl-progress-track { flex: 1; min-width: 120px; height: 4px; background: var(--bg-3); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.pl-progress-fill { height: 100%; width: 0%; background: var(--accent); border-radius: 999px; transition: width .35s ease; }
.pl-progress-fill.done { background: var(--green); }
.pl-progress-fill.error { background: var(--red); }

/* ===================================================================
   LIVE LOG — chronological run log (collapsible)
   =================================================================== */
.pl-log-panel { flex: none; border-top: 1px solid var(--line); background: var(--bg-2); }
.pl-log-toggle { display: flex; align-items: center; gap: 8px; width: 100%; background: transparent; border: none; color: var(--muted); font-size: 12px; font-weight: 600; padding: 8px 18px; text-align: left; }
.pl-log-toggle:hover { color: var(--text); }
.pl-log-caret { font-size: 10px; color: var(--muted-2); width: 12px; }
.pl-log-count { margin-left: auto; font-family: var(--mono); font-size: 10.5px; color: var(--muted-2); }
.run-log { max-height: 190px; overflow-y: auto; padding: 4px 18px 10px; font-family: var(--mono); font-size: 11px; line-height: 1.6; }
.pl-log-panel.collapsed .run-log { display: none; }
.log-line { display: flex; align-items: baseline; gap: 8px; padding: 1px 0; }
.log-time { color: var(--muted-2); flex: none; }
.log-glyph { flex: none; width: 12px; text-align: center; color: var(--muted); }
.log-text { color: var(--muted); word-break: break-word; min-width: 0; }
.log-start .log-glyph, .log-branch .log-glyph { color: var(--accent); }
.log-start .log-text, .log-branch .log-text { color: var(--text); }
.log-end .log-glyph, .log-complete .log-glyph { color: var(--green); }
.log-tool .log-glyph { color: var(--violet); }
.log-delta .log-glyph, .log-delta .log-text { color: var(--muted-2); }
.log-winner .log-glyph, .log-winner .log-text { color: var(--green); font-weight: 650; }
.log-loop .log-glyph, .log-loop .log-text { color: var(--accent); }
.log-error .log-glyph, .log-error .log-text { color: var(--red); }

/* small "ver" transcript trigger in stage card footers */
.stage-foot-right { display: inline-flex; align-items: center; gap: 8px; flex: none; }
.stage-transcript-btn { background: var(--bg); border: 1px solid var(--line-2); color: var(--muted); font-size: 9.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .4px; padding: 2px 7px; border-radius: 5px; line-height: 1.5; }
.stage-transcript-btn:hover { border-color: var(--accent); color: var(--accent); }
.stage-config-btn { background: var(--bg); border: 1px solid var(--line-2); color: var(--muted); font-size: 11px; padding: 1px 6px; border-radius: 5px; line-height: 1.5; }
.stage-config-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Agent characters (Ralph-style "they're building it") ---------- */
.agent-avatar { position: relative; display: inline-flex; flex: none; line-height: 0; }
.agent-avatar svg { overflow: visible; }
.agent-avatar .av-body { fill: var(--bg-3); stroke: var(--muted-2); stroke-width: 2; }
.agent-avatar .av-belly { fill: var(--bg); opacity: .45; }
.agent-avatar .av-eye { fill: var(--muted); }
.agent-avatar .av-glint { fill: #fff; opacity: .9; }
.agent-avatar .av-foot, .agent-avatar .av-arm rect, .agent-avatar .av-arm-l { fill: var(--muted-2); }
.agent-avatar .av-hammer rect { fill: var(--muted); }
.agent-avatar .av-hat { opacity: 0; transform: translateY(2px); transition: opacity .2s, transform .2s; }
.agent-avatar .av-hat-dome, .agent-avatar .av-hat-brim { fill: var(--amber); }
.av-spark { position: absolute; top: 3px; right: 1px; width: 7px; height: 7px; border-radius: 50%; background: var(--amber); opacity: 0; }
/* provider colors — tint the body outline + eyes */
.av-claude .av-body { stroke: var(--accent); }
.av-claude .av-eye { fill: var(--accent); }
.av-codex .av-body { stroke: var(--green); }
.av-codex .av-eye { fill: var(--green); }
.av-gemini .av-body { stroke: var(--violet); }
.av-gemini .av-eye { fill: var(--violet); }
/* states */
.agent-avatar.is-idle { opacity: .5; }
.agent-avatar.is-done .av-body { stroke: var(--green); }
.agent-avatar.is-done .av-eye { fill: var(--green); }
.agent-avatar.is-error .av-body { stroke: var(--red); }
.agent-avatar.is-error .av-eye { fill: var(--red); }
.agent-avatar.is-working { animation: av-bob .8s ease-in-out infinite; }
.agent-avatar.is-working .av-hat { opacity: 1; transform: translateY(0); }
.agent-avatar.is-working .av-arm { animation: av-hammer .5s ease-in-out infinite; transform-origin: 39px 27px; }
.agent-avatar.is-working .av-spark { animation: av-spark .5s ease-in-out infinite; }
.agent-avatar.is-working .av-eye { animation: av-blink 2.8s step-end infinite; }
@keyframes av-bob { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-2.5px)} }
@keyframes av-hammer { 0%,100%{transform:rotate(8deg)} 45%{transform:rotate(-42deg)} }
@keyframes av-spark { 0%,55%{opacity:0;transform:scale(.4)} 68%{opacity:1;transform:scale(1)} 100%{opacity:0;transform:scale(1.5)} }
@keyframes av-blink { 0%,92%,100%{opacity:1} 95%{opacity:.15} }

/* ---------- Brain (unified knowledge) view ---------- */
.brain-view { display: flex; flex: 1; min-width: 0; min-height: 0; }
.brain-rail { flex: none; width: 270px; display: flex; flex-direction: column; gap: 10px; padding: 14px; border-right: 1px solid var(--line); background: var(--bg-2); min-height: 0; overflow-y: auto; }
.brain-title { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 650; color: var(--text); }
.brain-title svg { color: var(--accent); }
.brain-stats { font-size: 11px; color: var(--muted); margin-top: 4px; }
.brain-search { height: 36px; background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 9px; color: var(--text); padding: 0 12px; font-size: 13px; outline: none; font-family: inherit; }
.brain-search:focus { border-color: var(--accent); }
.brain-cats-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted-2); margin-top: 4px; }
.brain-projects { display: flex; flex-direction: column; gap: 2px; }
.brain-proj { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.brain-proj:hover { background: var(--bg-3); }
.brain-proj.active { background: var(--accent-dim); border-color: var(--accent-dim); }
.brain-proj.active .brain-proj-name { color: var(--accent); }
.brain-proj-name { font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brain-proj-count { font-size: 11px; color: var(--muted); background: var(--bg-3); border-radius: 20px; padding: 1px 7px; flex: none; }
.brain-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.brain-tag { font-size: 11px; padding: 3px 9px; border-radius: 20px; border: 1px solid var(--line-2); background: var(--bg-3); color: var(--muted); cursor: pointer; }
.brain-tag:hover { border-color: var(--accent); color: var(--text); }
.brain-tag.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.brain-tag .bt-n { opacity: .55; }
.brain-main { flex: 1; min-width: 0; min-height: 0; overflow-y: auto; padding: 22px clamp(16px, 4vw, 44px); }
.brain-project { margin-bottom: 28px; }
.brain-project-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; padding-bottom: 9px; border-bottom: 1px solid var(--line); }
.brain-project-head h3 { margin: 0; font-size: 17px; }
.brain-project-path { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
.bp-spacer { flex: 1; }
.brain-code-btn { font-size: 11.5px; padding: 4px 11px; }
.brain-group { margin-bottom: 14px; }
.brain-group-label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin-bottom: 8px; }
.brain-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.brain-card { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; background: linear-gradient(180deg, var(--bg-2), var(--bg-3)); border: 1px solid var(--line-2); border-radius: 12px; cursor: pointer; transition: border-color .15s, transform .1s; }
.brain-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.brain-card .bc-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; flex: none; }
.brain-card.conv .bc-dot { background: var(--accent); }
.brain-card.pipe .bc-dot { background: var(--violet); }
.brain-card .bc-body { min-width: 0; }
.brain-card .bc-title { font-size: 13.5px; font-weight: 550; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brain-card .bc-meta { font-size: 11px; color: var(--muted); margin-top: 3px; }
.brain-code { margin-top: 10px; padding: 12px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; }
.brain-files { display: flex; flex-wrap: wrap; gap: 5px; }
.brain-file { font-family: var(--mono); font-size: 11.5px; color: var(--muted); background: var(--bg-3); border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; }
.brain-file.dir { color: var(--accent); }
.brain-code-err { color: var(--red); font-size: 12px; }
.brain-search-head { font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.brain-card .bc-snip { font-size: 11.5px; color: var(--muted-2); margin-top: 5px; font-style: italic; line-height: 1.4; white-space: normal; }
@media (max-width: 760px) { .brain-rail { display: none; } }

/* ===================================================================
   TRANSCRIPT DRAWER — full per-stage output
   =================================================================== */
.run-transcript { width: 480px; display: flex; flex-direction: column; }
.rt-meta { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; margin: 4px 0 12px; }
.rt-meta > span { font-size: 10.5px; padding: 2px 8px; border-radius: 6px; background: var(--bg-3); border: 1px solid var(--line-2); color: var(--muted); }
.rt-status { text-transform: uppercase; letter-spacing: .4px; }
.rt-status.running { color: var(--accent); border-color: var(--accent-dim); }
.rt-status.done { color: var(--green); border-color: rgba(74,222,128,.4); }
.rt-status.error { color: var(--red); border-color: rgba(248,113,113,.4); }
.rt-agent { color: var(--text); font-weight: 550; }
.rt-cost { font-family: var(--mono); }
.rt-iter { color: var(--accent); }
.rt-body { flex: 1; min-height: 0; overflow-y: auto; }
.rt-prompt { margin: 0 0 12px; border: 1px solid var(--line-2); border-radius: 9px; background: var(--bg-3); overflow: hidden; }
.rt-prompt summary { cursor: pointer; padding: 8px 11px; font-size: 12px; font-weight: 600; color: var(--accent); list-style: none; user-select: none; }
.rt-prompt summary::-webkit-details-marker { display: none; }
.rt-prompt summary::before { content: "▸ "; color: var(--muted-2); }
.rt-prompt[open] summary::before { content: "▾ "; }
.rt-prompt .rt-pre { margin: 0; border: none; border-top: 1px solid var(--line-2); border-radius: 0; background: var(--bg); max-height: 260px; overflow-y: auto; }
.rt-pre { font-family: var(--mono); font-size: 11.5px; line-height: 1.55; color: #d7dbe2; white-space: pre-wrap; word-break: break-word; background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 11px 13px; margin: 0; }
.rt-out:empty::after { content: "— sin salida todavía —"; color: var(--muted-2); }
/* finished answer rendered as markdown (clean, not raw monospace) */
.rt-out.md { white-space: normal; color: #d7dbe2; font-size: 13px; line-height: 1.6; }
.rt-out.md > :first-child { margin-top: 0; }
.rt-out.md > :last-child { margin-bottom: 0; }
.rt-out.md code { font-family: var(--mono); font-size: 12px; background: var(--bg-3); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; color: #e6c07b; }
.rt-out.md strong { color: var(--text); font-weight: 650; }
.rt-out.md a { color: var(--accent); text-decoration: none; }
.rt-out.md .md-pre { background: var(--bg); border: 1px solid var(--line); font-size: 12px; }
.rt-out.md .md-table th, .rt-out.md .md-table td { padding: 6px 9px; }
/* the "✅ RESUMEN:" lead line — make it pop */
.rt-out.md .md-p:first-child { font-size: 14px; color: var(--text); background: var(--bg-2); border-left: 3px solid var(--accent); border-radius: 0 8px 8px 0; padding: 9px 13px; margin-bottom: 12px; }
.rt-error { margin-top: 10px; color: var(--red); font-size: 12.5px; white-space: pre-wrap; }
/* per-stage diff (change safety: ver y deshacer cambios) */
.rt-diff { margin: 12px 0 0; border: 1px solid var(--line); border-radius: 9px; background: var(--bg-2); overflow: hidden; }
.rt-diff > summary { cursor: pointer; padding: 8px 12px; font-size: 12px; color: var(--amber); font-weight: 600; }
.rt-diff-body { max-height: 320px; overflow: auto; font-family: var(--mono); font-size: 11.5px; line-height: 1.5; padding: 6px 0; border-top: 1px solid var(--line); }
.rt-diff-body > div { padding: 0 12px; white-space: pre-wrap; word-break: break-word; }
.rt-diff-body .d-add { background: rgba(74,222,128,.10); color: #b7f7cf; }
.rt-diff-body .d-del { background: rgba(248,113,113,.10); color: #f7bcbc; }
.rt-diff-body .d-hunk { color: var(--accent); }
.rt-diff-body .d-file { color: var(--muted); font-weight: 600; }
.rt-diff-body .d-ctx { color: var(--muted); }
.rt-undo { margin: 8px 12px 10px; background: var(--bg-3); border: 1px solid rgba(248,113,113,.4); color: var(--red); font-size: 12px; font-weight: 600; padding: 5px 12px; border-radius: 8px; }
.rt-undo:hover { background: rgba(248,113,113,.12); }
/* human-in-the-loop pause */
.pl-pause { display: flex; align-items: center; gap: 14px; margin: 0 18px 12px; padding: 10px 16px; background: rgba(251,191,36,.10); border: 1px solid rgba(251,191,36,.4); border-radius: 10px; }
.pl-pause-msg { flex: 1; color: var(--amber); font-size: 13px; font-weight: 550; }
.pl-pause-actions { display: flex; gap: 8px; flex: none; }
#pl-pause-continue { border-color: rgba(74,222,128,.5) !important; color: var(--green) !important; }
#pl-pause-stop { border-color: rgba(248,113,113,.5) !important; color: var(--red) !important; }
#pl-pause-toggle.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
/* Flota (runs activos) + programados */
.pl-runs, .pl-schedules { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; }
.pl-runs-label { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted-2); font-weight: 600; margin-bottom: 2px; }
.pl-run { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-2); cursor: pointer; font-size: 12px; }
.pl-run:hover { border-color: var(--accent-dim); }
.pl-run-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted-2); flex: none; }
.pl-run-dot.running { background: var(--green); box-shadow: 0 0 8px 1px rgba(74,222,128,.5); animation: u-pulse 1.2s infinite; }
.pl-run-dot.paused { background: var(--amber); }
.pl-run-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.pl-run-meta { font-family: var(--mono); font-size: 10.5px; color: var(--muted); flex: none; }
.pl-sched { display: flex; align-items: center; gap: 7px; padding: 6px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-2); font-size: 12px; }
.pl-sched.off { opacity: .55; }
.pl-sched-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); cursor: pointer; }
.pl-sched-every { font-family: var(--mono); font-size: 10px; color: var(--accent); background: var(--accent-dim); padding: 2px 6px; border-radius: 5px; flex: none; cursor: pointer; }
.pl-sched-toggle, .pl-sched-del { background: transparent; border: none; color: var(--muted-2); cursor: pointer; font-size: 12px; padding: 2px 4px; line-height: 1; }
.pl-sched-toggle:hover { color: var(--accent); }
.pl-sched-del:hover { color: var(--red); }
/* ===== Stats / usage dashboard ===== */
.stats-view { flex: 1; overflow-y: auto; }
.stats-wrap { max-width: 860px; margin: 0 auto; padding: 26px 24px 60px; }
.stats-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.stats-head h2 { font-size: 20px; margin: 0; color: var(--text); }
.stats-empty { color: var(--muted); font-size: 13px; padding: 44px 0; text-align: center; }
.stats-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stat-card { background: linear-gradient(180deg, var(--bg-2), var(--bg-3)); border: 1px solid var(--line-2); border-radius: 14px; padding: 16px 18px; }
.stat-value { font-size: 26px; font-weight: 650; color: var(--text); font-family: var(--mono); }
.stat-label { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.stat-card.tone-good .stat-value { color: var(--green); }
.stat-card.tone-warn .stat-value { color: var(--amber); }
.stat-card.tone-bad .stat-value { color: var(--red); }
.stats-section-title { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted-2); font-weight: 600; margin: 24px 0 10px; }
.stat-bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--bg-3); border: 1px solid var(--line); }
.sb-seg { min-width: 0; }
.sb-seg.done { background: var(--green); }
.sb-seg.error { background: var(--red); }
.sb-seg.stopped { background: var(--muted-2); }
.stat-legend { display: flex; gap: 16px; margin-top: 8px; font-size: 11.5px; color: var(--muted); }
.stat-legend i.lg { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.stat-legend i.lg.done { background: var(--green); }
.stat-legend i.lg.error { background: var(--red); }
.stat-legend i.lg.stopped { background: var(--muted-2); }
.stats-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.stats-table th { text-align: left; color: var(--muted-2); font-weight: 600; font-size: 10.5px; text-transform: uppercase; letter-spacing: .4px; padding: 6px 10px; border-bottom: 1px solid var(--line); }
.stats-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); color: var(--text); }
.stats-table td:not(:first-child) { font-family: var(--mono); color: var(--muted); }
.stat-recent { display: flex; flex-direction: column; gap: 4px; }
.stat-recent-row { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-2); font-size: 12.5px; }
.srr-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted-2); flex: none; }
.srr-dot.done { background: var(--green); }
.srr-dot.error { background: var(--red); }
.srr-dot.stopped, .srr-dot.paused { background: var(--amber); }
.srr-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.srr-cost, .srr-dur { font-family: var(--mono); font-size: 11px; color: var(--muted); flex: none; }
.rt-branch, .rt-judge { margin-bottom: 16px; }
.rt-branch-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12.5px; margin-bottom: 7px; }
.rt-branch-head b { color: var(--text); }
.rt-winner { font-size: 9px; font-weight: 700; letter-spacing: .4px; color: var(--green); background: rgba(74,222,128,.14); border: 1px solid rgba(74,222,128,.4); padding: 1px 5px; border-radius: 5px; }
.rt-judge { padding-top: 12px; border-top: 1px solid var(--line); }

/* ===================================================================
   PROJECT-MEMORY DRAWER
   =================================================================== */
.pl-memory-drawer { width: 420px; display: flex; flex-direction: column; }
.pl-memory-drawer textarea { flex: 1; min-height: 200px; resize: vertical; font-family: var(--mono); font-size: 12.5px; line-height: 1.55; }
.pl-memory-drawer .drawer-actions { align-items: center; }
#pl-memory-status { flex: 1; }
#pl-memory-save { background: var(--accent); color: #0b1220; }

@keyframes u-pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

/* ===================================================================
   COST AFFORDANCE — "uso estimado $X" with a "?" info chip.
   The "$" is API-equivalent usage Claude reports, NOT a card charge.
   =================================================================== */
.cost-info {
  display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px; margin-left: 4px; vertical-align: baseline;
  border-radius: 50%; border: 1px solid var(--line-2);
  font-size: 9px; font-weight: 700; line-height: 1; color: var(--muted-2);
  font-family: var(--sans); cursor: help; user-select: none;
}
.cost-info:hover { color: var(--text); border-color: var(--accent); }
/* keep the total-cost chip from wrapping awkwardly with the new longer label */
#pl-total-cost { white-space: nowrap; }

/* ===================================================================
   CHAT (ORCHESTRATOR) VIEW — the conversational, chat-first surface
   =================================================================== */
.orch-view { display: flex; flex-direction: row; flex: 1; min-width: 0; min-height: 0; }
.orch-main { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; }

/* ---------- Conversation sidebar (saved sessions) ---------- */
.orch-rail {
  flex: none; width: 256px; display: flex; flex-direction: column;
  border-right: 1px solid var(--line); background: var(--bg-2); min-height: 0;
}
.orch-rail-head {
  flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
  font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted);
}
.orch-rail-list { flex: 1; overflow-y: auto; padding: 8px; min-height: 0; }
.orch-rail-empty { color: var(--muted-2); font-size: 12.5px; line-height: 1.6; padding: 16px 10px; text-align: center; }
.orch-rail-item {
  display: flex; align-items: center; gap: 6px; padding: 9px 10px; margin-bottom: 3px;
  border: 1px solid transparent; border-radius: 9px; cursor: pointer;
}
.orch-rail-item:hover { background: var(--bg-3); }
.orch-rail-item.active { background: var(--accent-dim); border-color: var(--accent-dim); }
.orch-rail-item.active .orch-rail-title { color: var(--accent); }
.orch-rail-item-main { flex: 1; min-width: 0; }
.orch-rail-title { font-size: 13px; color: var(--text); font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.orch-rail-sub { font-size: 11px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.orch-rail-del {
  flex: none; width: 26px; height: 26px; border-radius: 7px; border: none; background: transparent;
  color: var(--muted-2); display: flex; align-items: center; justify-content: center; opacity: 0;
}
.orch-rail-item:hover .orch-rail-del { opacity: 1; }
.orch-rail-del:hover { background: rgba(248,113,113,.12); color: var(--red); }

.orch-topbar {
  flex: none; display: flex; align-items: center; gap: 10px;
  padding: 10px clamp(16px, 6vw, 90px); border-bottom: 1px solid var(--line); background: var(--bg);
}
.orch-cwd-field {
  display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; max-width: 640px;
  background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 10px; padding: 0 12px; height: 38px;
  color: var(--muted);
}
.orch-cwd-field:focus-within { border-color: var(--accent); color: var(--text); }
.orch-cwd-field svg { flex: none; }
.orch-cwd-field input {
  flex: 1; min-width: 0; background: transparent; border: none; outline: none;
  color: var(--text); font-family: var(--mono); font-size: 12.5px;
}
.orch-cwd-field input::placeholder { color: var(--muted-2); font-family: var(--sans); }
.orch-top-spacer { flex: 1; }
.orch-new-btn { flex: none; height: 38px; }
.orch-browse-btn { flex: none; height: 38px; display: inline-flex; align-items: center; gap: 6px; }
.orch-browse-btn svg { flex: none; }

/* ---------- In-page folder browser ---------- */
.folder-card { width: 560px; max-width: 100%; display: flex; flex-direction: column; }
.folder-path { font-family: var(--mono); font-size: 12px; color: var(--muted); background: var(--bg-3); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 6px 0 10px; word-break: break-all; }
.folder-drives { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.folder-drive { font-family: var(--mono); font-size: 12px; padding: 4px 10px; border-radius: 7px; border: 1px solid var(--line-2); background: var(--bg-3); color: var(--text); }
.folder-drive:hover { border-color: var(--accent); color: var(--accent); }
.folder-list { height: 300px; overflow-y: auto; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); padding: 4px; }
.folder-row { display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: 13.5px; color: var(--text); }
.folder-row:hover { background: var(--bg-3); }
.folder-row svg { flex: none; color: var(--accent); }
.folder-row span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.folder-err { color: var(--red); font-size: 12.5px; padding: 10px; }
.folder-empty { color: var(--muted-2); font-size: 12.5px; padding: 10px; }
.folder-actions { justify-content: space-between; }
.folder-actions .ghost { background: transparent; border: 1px solid var(--line-2); color: var(--text); }

.orch-messages { flex: 1; overflow-y: auto; padding: 22px clamp(16px, 6vw, 90px); min-height: 0; }

/* status/info lines inside the transcript (run start, loop, complete) */
.orch-line {
  max-width: 760px; margin: 0 auto 14px; padding: 9px 13px;
  font-size: 12.5px; color: var(--muted); line-height: 1.5;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.orch-run-line { color: var(--text); border-color: var(--accent-dim); }
.orch-loop-line { color: var(--accent); border-color: var(--accent-dim); background: var(--accent-dim); }
.orch-complete-line { color: var(--green); border-color: rgba(74,222,128,.3); background: rgba(74,222,128,.06); }
.orch-error-line { color: var(--red); border-color: rgba(248,113,113,.35); background: rgba(248,113,113,.06); }

/* "ver en detalle (Avanzado)" jump link */
.orch-detail-link {
  margin-left: auto; background: var(--bg-3); border: 1px solid var(--line-2); color: var(--text);
  font-size: 11.5px; font-weight: 600; padding: 4px 11px; border-radius: 7px;
}
.orch-detail-link:hover { border-color: var(--accent); color: var(--accent); }

/* stage bubbles reuse .msg.assistant; the role line carries the "▸ Stage · provider" title */
.orch-stage-msg .role { color: var(--accent); text-transform: none; letter-spacing: 0; font-weight: 600; font-size: 12px; }

/* "El orquestador está pensando…" indicator */
.orch-thinking {
  flex: none; max-width: 760px; margin: 0 auto; width: 100%;
  padding: 4px clamp(16px, 6vw, 90px) 10px;
  display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 12.5px;
}
.orch-think-dots { display: inline-flex; gap: 4px; }
.orch-think-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); opacity: .5; animation: orch-bounce 1.2s infinite; }
.orch-think-dots span:nth-child(2) { animation-delay: .15s; }
.orch-think-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes orch-bounce { 0%,60%,100%{transform:translateY(0);opacity:.4} 30%{transform:translateY(-4px);opacity:1} }

/* ---------- Mic (dictation) button ---------- */
.mic-btn {
  width: 44px; height: 44px; border-radius: 12px; flex: none;
  background: var(--bg-3); color: var(--muted); border: 1px solid var(--line-2);
  display: flex; align-items: center; justify-content: center;
  transition: color .15s, border-color .15s, background .15s;
}
.mic-btn:hover { color: var(--text); border-color: var(--accent); }
.mic-btn.recording {
  color: var(--red); border-color: var(--red); background: rgba(248,113,113,.1);
  animation: mic-pulse 1.2s infinite;
}
.mic-btn.disabled, .mic-btn:disabled { opacity: .4; cursor: not-allowed; }
@keyframes mic-pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(248,113,113,.5); }
  60% { box-shadow: 0 0 0 7px rgba(248,113,113,0); }
}

/* ---------- Rendered markdown (assistant replies + stage output) ---------- */
.content.md { white-space: normal; }
.content.md > :first-child { margin-top: 0; }
.content.md > :last-child { margin-bottom: 0; }
.md-p { margin: 0 0 10px; line-height: 1.6; }
.md-h { margin: 16px 0 8px; line-height: 1.3; font-weight: 650; color: var(--text); }
.md-h1 { font-size: 19px; }
.md-h2 { font-size: 16.5px; }
.md-h3 { font-size: 14.5px; }
.md-h4, .md-h5, .md-h6 { font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.md-list { margin: 0 0 10px; padding-left: 22px; line-height: 1.6; }
.md-list li { margin: 3px 0; }
.content.md strong { color: var(--text); font-weight: 650; }
.content.md code {
  font-family: var(--mono); font-size: 12.5px; background: var(--bg-3);
  border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; color: #e6c07b;
}
.md-pre {
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 9px;
  padding: 12px 14px; overflow-x: auto; margin: 0 0 12px;
}
.md-pre code { background: none; border: none; padding: 0; color: #d7dbe2; font-size: 12.5px; }
.content.md a { color: var(--accent); text-decoration: none; }
.content.md a:hover { text-decoration: underline; }
.md-quote {
  margin: 0 0 12px; padding: 6px 14px; color: var(--muted);
  border-left: 3px solid var(--line-2); background: var(--bg-2); border-radius: 0 8px 8px 0;
}
.md-hr { border: none; border-top: 1px solid var(--line); margin: 14px 0; }

/* tables — the big readability win (the review output the user couldn't read) */
.md-table-wrap { overflow-x: auto; margin: 0 0 12px; border: 1px solid var(--line); border-radius: 10px; }
.md-table { border-collapse: collapse; width: 100%; font-size: 12.8px; }
.md-table th, .md-table td { text-align: left; padding: 8px 11px; border-bottom: 1px solid var(--line); vertical-align: top; }
.md-table th { background: var(--bg-3); color: var(--text); font-weight: 600; white-space: nowrap; }
.md-table tr:last-child td { border-bottom: none; }
.md-table tbody tr:hover { background: var(--bg-2); }

/* ---------- Cost/usage hidden by request (subscription, no per-use charge) ---------- */
.cost-chip, .msg-foot, .stage-cost, .cost-info, .pl-budget { display: none !important; }

@media (max-width: 760px) {
  .orch-line, .orch-thinking { max-width: 100%; }
  .orch-topbar { padding: 10px; }
  .orch-rail { display: none; } /* chat stays full-width on phones; list is desktop-first */
}
