/* FLUXBOT chat app: Live code preview (E3). The ▶ Preview button on code blocks and the preview panel (preview.js),
   also used full window by /preview-tab.html (body.pv-standalone). Dark + light themes through the style.css tokens;
   prefers-reduced-motion and body.fx-off switch the motion off; body.no-preview hides it all for members.
   Layouts: aside.pv.pv-split (≥ 1100 px, beside the chat), .pv-overlay (768–1099 px, over the chat area), .pv-phone
   (< 768 px, full screen), .pv-full (the ⤢ button on the first two). */

/* ---------- the ▶ Preview button in a code block's header ---------- */
.code-head .pv-btn { margin-left: auto; margin-right: 2px; color: var(--accent); font-weight: 600; }
.code-head .pv-btn:hover { color: var(--text); }
.code-head .pv-btn svg { width: 11px; height: 11px; }
[data-theme="light"] .code-head .pv-btn { color: #0a52c4; }
body.no-preview .pv-btn, body.no-preview aside.pv { display: none !important; }

/* ---------- panel ---------- */
aside.pv {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 30; width: var(--pvw, 46vw); min-width: 0;
  display: flex; flex-direction: column; color: var(--text); background: var(--bg);
  border-left: 1px solid var(--border-strong); box-shadow: -18px 0 44px -26px rgba(0, 3, 12, 0.8);
}
aside.pv[hidden] { display: none; }
body.pv-open.pv-split .app { margin-right: var(--pvw, 46vw); }
aside.pv.pv-overlay, aside.pv.pv-full { left: var(--pv-left, 0px); width: auto; z-index: 45; }
aside.pv.pv-phone {
  inset: 0; width: auto; z-index: 58; border-left: 0; box-shadow: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
aside.pv.pv-standalone { inset: 0; width: auto; border-left: 0; box-shadow: none; z-index: 2; }
body:not(.fx-off) aside.pv::before {
  content: ''; position: absolute; left: 0; right: 0; top: 0; height: 1px; pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--flux-cyan), var(--flux-blue), transparent); opacity: .55;
}

/* resize handle (split view only) */
.pv-resize { display: none; position: absolute; left: -5px; top: 0; bottom: 0; width: 10px; z-index: 3; cursor: col-resize; touch-action: none; }
aside.pv.pv-split:not(.pv-full) .pv-resize { display: block; }
.pv-resize::after { content: ''; position: absolute; left: 4px; top: 0; bottom: 0; width: 2px; background: transparent; transition: background .15s; }
.pv-resize:hover::after, .pv-resize:focus-visible::after, aside.pv.pv-dragging .pv-resize::after { background: var(--accent); }
.pv-resize:focus-visible { outline: none; }
aside.pv.pv-dragging .pv-frame { pointer-events: none; }
body.pv-open:has(aside.pv.pv-dragging) { user-select: none; cursor: col-resize; }

/* top bar: tabs · name + status · actions */
.pv-bar { display: flex; align-items: center; gap: 8px; min-height: 52px; padding: 7px 8px 6px 12px; flex-wrap: wrap; }
.pv-tabs { display: inline-flex; flex: none; padding: 3px; gap: 2px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); }
.pv-tab { height: 30px; padding: 0 12px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.pv-tab:hover { color: var(--text); }
.pv-tab[aria-selected="true"] { color: var(--text); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.pv-title { flex: 1 1 120px; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.pv-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pv-status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); min-height: 16px; }
.pv-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: currentColor; }
.pv-s-idle .pv-dot { display: none; }
.pv-s-starting, .pv-s-loading { color: var(--accent); }
.pv-s-running { color: var(--ok); }
.pv-s-error, .pv-s-nostart { color: var(--danger); }
.pv-s-stuck { color: #f59e0b; }
.pv-s-stopped { color: var(--dim); }
[data-theme="light"] .pv-s-stuck { color: #b45309; }
.pv-s-running .pv-dot, .pv-s-starting .pv-dot, .pv-s-loading .pv-dot { animation: pvPulse 1.6s ease-in-out infinite; }
@keyframes pvPulse { 50% { opacity: .35; } }
.pv-acts { display: flex; align-items: center; gap: 2px; flex: none; margin-left: auto; }
.pv-ib { width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; color: var(--muted); flex: none; }
.pv-ib:hover { background: var(--hover); color: var(--text); }
.pv-ib:disabled { opacity: .4; cursor: default; background: none; }
.pv-ib svg { width: 18px; height: 18px; }
.pv-ib[aria-pressed="true"] { color: var(--accent); }
.pv-note { padding: 0 12px 7px; font-size: 11.5px; line-height: 1.4; color: var(--dim); border-bottom: 1px solid var(--border); }
/* /preview-tab.html: an always-visible strip outside the frame (the preview fills the window under the FLUXBOT address) */
.pv-note.pv-note-warn { padding: 8px 12px; font-size: 13px; font-weight: 600; color: var(--text); background: var(--danger-soft); border-bottom: 1px solid var(--danger); }
.pv-note.pv-note-warn::before { content: "\26A0\FE0E\00A0"; color: var(--danger); }

/* preview and code */
.pv-body { position: relative; flex: 1 1 auto; min-height: 140px; }
.pv-pane { position: absolute; inset: 0; }
.pv-stage { position: absolute; inset: 0; background: #fff; }
.pv-frame { display: block; width: 100%; height: 100%; border: 0; background: #fff; color-scheme: light; }
.pv-over { position: absolute; inset: 0; z-index: 1; display: grid; place-items: center; padding: 16px; background: var(--overlay); }
.pv-over[hidden] { display: none; }
.pv-over-card {
  width: 100%; max-width: 380px; padding: 18px; border-radius: 14px; text-align: center;
  background: var(--surface); border: 1px solid var(--border-strong); box-shadow: var(--shadow);
}
.pv-over-title { font-size: 15px; font-weight: 600; margin-bottom: 12px; }
.pv-over-btn svg { width: 12px; height: 12px; }
.pv-over-small { margin-top: 12px; font-size: 12px; line-height: 1.45; color: var(--muted); }
.pv-pane-code { z-index: 2; overflow: auto; padding: 10px; background: var(--code-bg); }
.pv-pane-code[hidden] { display: none; }
.pv-code { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--code-bg); }
.pv-code + .pv-code { margin-top: 10px; }
.pv-code-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; height: 34px; padding: 0 6px 0 12px; background: var(--code-head); font-size: 12px; color: var(--muted); }
.pv-code-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.pv-pre { margin: 0; padding: 12px 14px; overflow-x: auto; }
.pv-pre code { font-family: 'JetBrains Mono', ui-monospace, Consolas, monospace; font-size: 12.5px; line-height: 1.6; font-variant-ligatures: none; white-space: pre; }

/* console drawer */
.pv-con { flex: none; display: flex; flex-direction: column; border-top: 1px solid var(--border-strong); background: var(--code-bg); }
.pv-con.pv-con-open { height: 32%; min-height: 120px; }
.pv-con-bar { display: flex; align-items: center; gap: 4px; min-height: 40px; padding: 2px 6px; }
.pv-con-toggle { display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 8px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.pv-con-toggle:hover { color: var(--text); background: var(--hover); }
.pv-con-toggle svg { width: 16px; height: 16px; flex: none; }
.pv-chev svg { width: 14px; height: 14px; transition: transform .15s; transform: rotate(180deg); display: block; }
.pv-con-open .pv-chev svg { transform: none; }
.pv-badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; display: inline-grid; place-items: center; font-size: 11px; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.pv-badge[hidden] { display: none; }
.pv-badge.pv-badge-err { background: var(--danger); color: #fff; }
.pv-spacer { flex: 1; }
.pv-cbtn { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px; border-radius: 8px; font-size: 12.5px; color: var(--muted); }
.pv-cbtn:hover { color: var(--text); background: var(--hover); }
.pv-cbtn svg { width: 14px; height: 14px; }
.pv-fix { color: var(--accent); font-weight: 600; }
[data-theme="light"] .pv-fix { color: #0a52c4; }
.pv-lines { flex: 1; min-height: 0; overflow: auto; list-style: none; margin: 0; padding: 2px 0 6px; font-family: 'JetBrains Mono', ui-monospace, Consolas, monospace; font-size: 12px; line-height: 1.5; }
.pv-con:not(.pv-con-open) .pv-lines { display: none; }
.pv-line { display: grid; grid-template-columns: auto 14px minmax(0, 1fr); gap: 8px; padding: 3px 12px; border-bottom: 1px solid var(--border); user-select: text; }
.pv-time { color: var(--dim); font-size: 11px; }
.pv-lico { text-align: center; color: var(--dim); }
.pv-ltext { white-space: pre-wrap; overflow-wrap: anywhere; }
.pv-l-error { background: var(--danger-soft); }
.pv-l-error .pv-ltext, .pv-l-error .pv-lico { color: var(--danger); }
.pv-l-warn .pv-ltext, .pv-l-warn .pv-lico { color: #fbbf24; }
.pv-l-blocked .pv-ltext, .pv-l-blocked .pv-lico { color: var(--flux-ice); }
.pv-l-loop .pv-ltext, .pv-l-loop .pv-lico { color: var(--accent); font-weight: 600; }
.pv-l-debug .pv-ltext { color: var(--muted); }
[data-theme="light"] .pv-l-warn .pv-ltext, [data-theme="light"] .pv-l-warn .pv-lico { color: #92400e; }
[data-theme="light"] .pv-l-blocked .pv-ltext, [data-theme="light"] .pv-l-blocked .pv-lico { color: #075985; }
[data-theme="light"] .pv-l-loop .pv-ltext, [data-theme="light"] .pv-l-loop .pv-lico { color: #0a52c4; }
.pv-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* phones: full screen, bigger targets, the name + status on their own line, the console collapsed by default */
aside.pv.pv-phone .pv-bar { padding: 6px 6px 4px 8px; }
aside.pv.pv-phone .pv-title { order: 3; flex-basis: 100%; flex-direction: row; align-items: center; gap: 10px; padding: 0 2px; }
aside.pv.pv-phone .pv-tab { height: 36px; }
aside.pv.pv-phone .pv-ib { width: 40px; height: 40px; }
aside.pv.pv-phone .pv-fullbtn, aside.pv.pv-standalone .pv-fullbtn { display: none; }
aside.pv.pv-phone .pv-con.pv-con-open { height: 40%; }
aside.pv.pv-phone .pv-cbtn { height: 36px; }
@media (max-width: 400px) {
  .pv-fix span { display: none; }
  aside.pv.pv-phone .pv-tab { padding: 0 10px; }
  aside.pv.pv-phone .pv-ib { width: 36px; } /* tabs + five icons on one row at 360 px (still 40 px tall) */
  aside.pv.pv-phone .pv-bar { gap: 4px; }
}

/* /preview-tab.html */
body.pv-standalone { overflow: hidden; }
.pv-empty { position: fixed; inset: 0; display: grid; place-content: center; gap: 6px; padding: 24px; text-align: center; }
.pv-empty-title { font-size: 17px; font-weight: 600; }
.pv-empty-sub { font-size: 14px; color: var(--muted); }

/* motion */
aside.pv.pv-anim.pv-split, aside.pv.pv-anim.pv-overlay { animation: pvIn .2s ease-out; }
aside.pv.pv-anim.pv-phone { animation: pvUp .2s ease-out; }
@keyframes pvIn { from { opacity: 0; transform: translateX(24px); } }
@keyframes pvUp { from { opacity: 0; transform: translateY(16px); } }
body.fx-off aside.pv, body.fx-off aside.pv * { animation: none !important; }
@media (prefers-reduced-motion: reduce) {
  aside.pv, aside.pv * { animation: none !important; transition: none !important; }
}
