/* Constructor de páginas (pagebuilder.js) — the AI chat on Reportes that builds a page.
 *
 * Reference (CollectUI, 26 oct 2026): "AI chat interaction for a workflow builder" by
 * @timothymaarv — a canvas that fills while the agent works, the conversation as a narrow
 * rail with live step rows, the composer docked at the bottom. Only the frame lives here: the
 * blocks are catalog defaults (`tb-sec-head`, `pm-strip`, `ev-table`, `tb-empty`) and the
 * analyst's own cards (`bb-viz`, agent.css). Everything rides --bb-* tokens. */

/* While a page is open the bundle list steps aside — one surface at a time. */
#pageReportes.pb-on #reportesRoot { display: none; }

.pb-root { position: relative; }

/* ------------------------------------------------------------------- the dock */
.pb-dock {
  position: sticky; bottom: 16px; z-index: 20;
  display: flex; align-items: flex-end; gap: 8px;
  /* Narrower than the column by the help FAB's width on each side, so its send button never
     sits under "Ayuda" (support.js, fixed bottom-right) — measured at an 800px pane. */
  width: min(760px, calc(100% - 180px)); margin: 22px auto 0; padding: 8px 8px 8px 16px;
  background: var(--bb-surface); border-radius: 14px;
  box-shadow: 0 0 0 1px var(--bb-line), var(--bb-sh-raised, 0 10px 30px rgba(13, 42, 94, .14));
}
.pb-input {
  flex: 1; min-width: 0; resize: none; border: 0; outline: 0; background: transparent;
  font: 400 15px/1.45 'Outfit', system-ui, sans-serif; color: var(--bb-ink);
  padding: 8px 0; max-height: 160px;
}
.pb-input::placeholder { color: var(--bb-ink-3, #8a8a8a); }
.pb-input:disabled { opacity: .55; }
.pb-send { flex: none; height: 36px; min-width: 36px; padding: 0 10px; border-radius: 10px; }
.pb-send svg { width: 18px; height: 18px; }
.pb-send.is-stop { padding: 0 14px; }

/* -------------------------------------------------------------------- the top */
.pb-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 2px 0 14px; }
.pb-crumb { display: flex; align-items: center; gap: 8px; min-width: 0; font: 500 14px/1.3 'Outfit', system-ui, sans-serif; color: var(--bb-ink-2, #555); }
.pb-crumb b { color: var(--bb-ink); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
button.pb-back {
  background: none; color: var(--bb-ink-2, #555); border: 0; padding: 0; font: inherit; cursor: pointer;
}
button.pb-back:hover { color: var(--bb-accent, #0D2A5E); }
.pb-acts { display: flex; gap: 8px; flex: none; }
/* The page's own link: host/r/ + the name, one pill. */
.pb-link {
  display: flex; align-items: center; gap: 6px; margin: 0;
  height: 32px; padding: 0 4px 0 10px; border-radius: 8px;
  background: var(--bb-surface); box-shadow: 0 0 0 1px var(--bb-line);
  font: 500 13px/1 var(--bb-mono); color: var(--bb-ink-3, #8a8a8a);
}
.pb-link:focus-within { box-shadow: 0 0 0 1px var(--bb-accent, #0D2A5E); }
.pb-slug {
  width: 150px; min-width: 0; border: 0; outline: 0; background: transparent; padding: 0;
  font: 600 13px/1 var(--bb-mono); color: var(--bb-ink);
}
.pb-slug::placeholder { color: var(--bb-ink-3, #8a8a8a); font-weight: 500; }

/* ------------------------------------------------------------ canvas + rail */
.pb-work { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; align-items: start; }
.pb-work.has-rail { grid-template-columns: minmax(0, 1fr) 320px; }
.pb-canvas { min-width: 0; display: flex; flex-direction: column; gap: 18px; }
.pb-title { margin: 0; }

.pb-block {
  background: var(--bb-surface); border-radius: var(--bb-r-card, 10px);
  box-shadow: var(--bb-sh-card); padding: 14px 16px 16px; min-width: 0;
  animation: pb-in .32s var(--bb-ease-out, ease-out) both;
}
@keyframes pb-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.pb-bhead { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pb-bacts { display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.pb-block:hover .pb-bacts, .pb-bacts:focus-within { opacity: 1; }
button.pb-icon {
  width: 26px; height: 26px; padding: 0; border-radius: 7px; justify-content: center;
  background: var(--bb-field); color: var(--bb-ink-2, #555); border: 0; font: 600 14px/1 'Outfit', system-ui, sans-serif; cursor: pointer;
}
button.pb-icon:hover { background: var(--bb-line); color: var(--bb-ink); }
.pb-bbody { min-width: 0; }
.pb-bbody .bb-agent-vizwrap { margin: 0; }
.pb-bbody .bb-agent-vizwrap + .bb-agent-vizwrap { margin-top: 14px; }
.pb-kpis { margin: 0; }
.pb-num { font-family: var(--bb-mono); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

.pb-skel {
  height: 120px; border-radius: 8px;
  background: linear-gradient(90deg, var(--bb-field) 0%, var(--bb-line) 50%, var(--bb-field) 100%);
  background-size: 200% 100%; animation: pb-shim 1.2s linear infinite;
}
.pb-skel-s { height: 44px; margin-top: 10px; width: 60%; }
.pb-skel-l { height: 260px; }
@keyframes pb-shim { to { background-position: -200% 0; } }

.pb-rail {
  position: sticky; top: 72px; min-width: 0;
  background: var(--bb-surface); border-radius: var(--bb-r-card, 10px); box-shadow: var(--bb-sh-card);
}
.pb-log {
  display: flex; flex-direction: column; gap: 8px; padding: 14px;
  max-height: calc(100vh - 200px); overflow-y: auto;
}
.pb-msg { font: 400 14px/1.45 'Outfit', system-ui, sans-serif; color: var(--bb-ink); overflow-wrap: anywhere; }
.pb-user { align-self: flex-end; max-width: 92%; background: var(--bb-field); padding: 8px 12px; border-radius: 12px 12px 4px 12px; }
.pb-reply { padding: 2px 0; }
.pb-err { color: var(--bb-neg, #B42318); }
.pb-step {
  display: flex; align-items: center; gap: 8px;
  font: 500 12px/1.35 var(--bb-mono); text-transform: uppercase; letter-spacing: .02em; color: var(--bb-ink-2, #555);
}
.pb-dot {
  flex: none; width: 16px; height: 16px; border-radius: 50%; display: grid; place-items: center;
  background: var(--bb-field); color: var(--bb-pos, #1E7A46);
}
.pb-dot svg { width: 11px; height: 11px; }
.pb-step.is-live { color: var(--bb-ink); }
.pb-step.is-live .pb-dot {
  background: transparent; border: 2px solid var(--bb-line); border-top-color: var(--bb-accent, #0D2A5E);
  animation: pb-spin .8s linear infinite;
}
@keyframes pb-spin { to { transform: rotate(360deg); } }

@media (max-width: 1100px) {
  .pb-work.has-rail { grid-template-columns: minmax(0, 1fr); }
  .pb-rail { position: static; order: -1; }
  .pb-log { max-height: 220px; }
}
@media (max-width: 600px) {
  .pb-top { flex-wrap: wrap; }
  .pb-acts { flex-wrap: wrap; }
  .pb-slug { width: 110px; }
  .pb-dock { bottom: 74px; width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .pb-block, .pb-skel, .pb-step.is-live .pb-dot { animation: none; }
}
