/* App tab: preview toolbar, device frames, select / edit / annotate / X-ray overlays, console */

.pv { display: flex; flex-direction: column; height: 100%; min-height: 560px; min-width: 0; background: var(--bg); container-type: inline-size; container-name: pv; }
.pv--empty { align-items: center; justify-content: center; padding: 40px 16px; background-color: var(--bg-sunken); }

/* Toolbar */
.pv-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--surface); position: relative; z-index: 3; }
.pv-bar__group { display: flex; align-items: center; gap: 4px; min-width: 0; }
.pv-bar__spacer { flex: 1; }
.pv-route { max-width: 220px; min-width: 120px; }
.pv-env { display: inline-flex; }
.pv-actas { white-space: nowrap; }
.pv-spin svg { animation: spin 0.5s linear; }
/* The toolbar sizes to the preview pane (not the window): stay on one row as the chat panel grows.
   The workspace header already shows Draft/Live + sample data, so the badge goes first. */
@container pv (max-width: 1080px) { .pv-env { display: none; } }
@container pv (max-width: 900px) { .pv-tools .segmented__opt span { display: none; } }
@container pv (max-width: 720px) { .pv-actas span { display: none; } .pv-route { max-width: 170px; } }
@media (max-width: 640px) {
  .pv-bar { padding: 8px; gap: 6px; }
  .pv-bar__spacer { display: none; }
  .pv-route { max-width: 150px; }
  .pv-actas span { display: none; }
}

/* Canvas */
.pv-canvas { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column;
  background-color: var(--bg-sunken);
  background-image: linear-gradient(var(--grid-line) 1px, transparent 1px), linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 24px 24px; background-position: -1px -1px; }
.pv-canvas__row { flex: 1; min-height: 0; display: flex; position: relative; }
.pv-stage { position: relative; flex: 1; min-width: 0; min-height: 440px; overflow: auto; display: flex; padding: 28px; }
.pv-fit { position: relative; margin: 0 auto; flex-shrink: 0; }

/* Device frames */
.pv-device { position: absolute; top: 0; left: 0; transform-origin: 0 0; display: flex; flex-direction: column; }
.pv-device--desktop { border: 1px solid var(--border-strong); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow-lg); overflow: hidden; }
.pv-device--tablet { padding: 14px; border-radius: 30px; background: #16171b; box-shadow: var(--shadow-lg), inset 0 0 0 1px rgba(255,255,255,0.08); }
.pv-device--mobile { padding: 12px; border-radius: 52px; background: #16171b; box-shadow: var(--shadow-lg), inset 0 0 0 1px rgba(255,255,255,0.1); }
.pv-glass { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; background: var(--surface); }
.pv-device--tablet .pv-glass { border-radius: 18px; }
.pv-device--mobile .pv-glass { border-radius: 40px; }
.pv-screen { position: relative; flex: 1; min-height: 0; overflow: hidden; }
.pv-chrome { display: flex; align-items: center; gap: 12px; height: 40px; flex-shrink: 0; padding: 0 12px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.pv-dots { display: inline-flex; gap: 6px; }
.pv-dots i { width: 11px; height: 11px; border-radius: 50%; background: var(--border-strong); }
.pv-dots i:nth-child(1) { background: #ED6A5E; } .pv-dots i:nth-child(2) { background: #F4BF4F; } .pv-dots i:nth-child(3) { background: #61C554; }
.pv-url { flex: 1; max-width: 560px; margin: 0 auto; display: flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: var(--radius-full); background: var(--surface); border: 1px solid var(--border); color: var(--text-3); font-size: 12px; font-family: var(--font-mono); min-width: 0; }
.pv-url span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pv-chrome__tag { font-size: 11px; color: var(--text-3); padding: 2px 8px; border-radius: var(--radius-full); background: var(--grey-soft); white-space: nowrap; }
.pv-status { position: relative; height: 34px; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; padding: 0 28px 0 32px; font-size: 13px; font-weight: 600; color: var(--text); background: var(--surface); }
.pv-notch { position: absolute; left: 50%; top: 8px; width: 110px; height: 28px; margin-left: -55px; border-radius: 16px; background: #16171b; }
.pv-status__r { display: inline-flex; align-items: flex-end; gap: 2px; }
.pv-status__r i { width: 3px; background: var(--text); border-radius: 1px; }
.pv-status__r i:nth-child(1) { height: 5px; } .pv-status__r i:nth-child(2) { height: 7px; } .pv-status__r i:nth-child(3) { height: 9px; }
.pv-status__r b { width: 20px; height: 10px; margin-left: 6px; border: 1.5px solid var(--text); border-radius: 3px; box-shadow: inset 12px 0 0 -1px var(--text); }
.pv-home { position: absolute; left: 50%; bottom: 8px; width: 130px; height: 5px; margin-left: -65px; border-radius: 3px; background: var(--text); opacity: 0.35; pointer-events: none; z-index: 2; }
.pv-reloading { position: absolute; inset: 0; display: grid; place-items: center; background: color-mix(in srgb, var(--surface) 70%, transparent); z-index: 5; animation: fade-in var(--dur-fast) var(--ease); }
.pv-spinner { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--border-strong); border-top-color: var(--blueprint); animation: spin 0.8s linear infinite; }

/* Build banner + mode hint */
.pv-build { display: flex; align-items: center; gap: 8px; margin: 10px 12px 0; padding: 7px 12px; border-radius: var(--radius); background: var(--amber-soft); border: 1px solid var(--amber-line); color: var(--amber-ink); font-size: var(--fs-sm); min-width: 0; }
.pv-build.is-paused { background: var(--grey-soft); border-color: var(--border); color: var(--grey-ink); }
.pv-build__pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); flex-shrink: 0; animation: pulse-dot 1.2s ease-in-out infinite; }
.is-paused .pv-build__pulse { background: var(--text-4); animation: none; }
.pv-build__step { opacity: 0.8; white-space: nowrap; }
.pv-build__step::before, .pv-build__label::before { content: '·'; margin-right: 8px; opacity: 0.6; }
.pv-build__label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pv-build__bar { width: 120px; height: 4px; border-radius: 2px; background: color-mix(in srgb, var(--amber) 20%, transparent); overflow: hidden; flex-shrink: 0; }
.pv-build__bar i { display: block; height: 100%; background: var(--amber); border-radius: inherit; transition: width var(--dur-slow) var(--ease); }
.pv-hint { display: flex; align-items: center; gap: 8px; margin: 10px 12px 0; padding: 6px 8px 6px 12px; border-radius: var(--radius); font-size: var(--fs-sm); background: var(--blueprint-soft); color: var(--blueprint-ink); border: 1px solid var(--blueprint-line); animation: rise-in var(--dur) var(--ease); }
.pv-hint span { flex: 1; min-width: 0; }
.pv-hint--annotate, .pv-hint--xray { background: var(--violet-soft); color: var(--violet-ink); border-color: var(--violet-line); }
.pv-hint--edit { background: var(--green-soft); color: var(--green-ink); border-color: var(--green-line); }
.pv-hint__done { display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px; border-radius: var(--radius-sm); border: 0; background: transparent; color: inherit; font: inherit; font-weight: 500; cursor: pointer; }
.pv-hint__done:hover { background: color-mix(in srgb, currentColor 10%, transparent); }
.pv-hint__done kbd { font-family: var(--font-mono); font-size: 10px; padding: 0 5px; border-radius: 4px; border: 1px solid currentColor; opacity: 0.7; }
@media (max-width: 640px) { .pv-build__bar, .pv-build__step { display: none; } }

/* Select action bar */
.pv-selbar { position: absolute; z-index: 20; display: flex; align-items: center; gap: 2px; padding: 4px; border-radius: 10px; background: var(--ink-btn); color: var(--ink-btn-text); box-shadow: var(--shadow-lg); animation: pop-in var(--dur-fast) var(--ease); white-space: nowrap; }
.pv-selbar__label { display: inline-flex; align-items: center; gap: 5px; max-width: 150px; padding: 0 8px 0 6px; font-size: 12px; opacity: 0.7; overflow: hidden; text-overflow: ellipsis; border-right: 1px solid color-mix(in srgb, currentColor 22%, transparent); }
.pv-selbar__btn, .pv-selbar__x { display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 9px; border: 0; border-radius: 7px; background: transparent; color: inherit; font: inherit; font-size: 12.5px; font-weight: 500; cursor: pointer; }
.pv-selbar__btn:hover, .pv-selbar__x:hover { background: color-mix(in srgb, currentColor 14%, transparent); }
.pv-selbar__btn.is-ai svg { color: var(--violet); }
.pv-selbar__x { padding: 0 7px; opacity: 0.75; }
.pv-selbar__form { display: flex; align-items: center; gap: 4px; }
.pv-selbar__input { width: 210px; height: 28px; padding: 0 10px; border-radius: 7px; border: 0; outline: 0; background: color-mix(in srgb, currentColor 12%, transparent); color: inherit; font: inherit; font-size: 12.5px; }
.pv-selbar__input::placeholder { color: inherit; opacity: 0.55; }
@media (max-width: 640px) { .pv-selbar__label { display: none; } .pv-selbar__btn { padding: 0 7px; } .pv-selbar__input { width: 140px; } }

/* Annotate notes panel */
.pv-notes { width: 292px; flex-shrink: 0; display: flex; flex-direction: column; min-height: 0; margin: 12px 12px 12px 0; border-radius: var(--radius-lg); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-md); animation: slide-in-right var(--dur) var(--ease); }
.pv-notes__head { display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 14px; border-bottom: 1px solid var(--border); color: var(--violet-ink); }
.pv-notes__head strong { color: var(--text); font-size: var(--fs-sm); }
.pv-notes__count { font-size: 11px; padding: 0 7px; border-radius: var(--radius-full); background: var(--violet-soft); color: var(--violet-ink); }
.pv-notes__list { flex: 1; min-height: 60px; overflow: auto; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.pv-notes__empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 22px 12px; text-align: center; color: var(--text-3); font-size: var(--fs-sm); line-height: 1.5; }
.pv-note { display: flex; gap: 8px; padding: 8px; border-radius: var(--radius); border: 1px solid transparent; }
.pv-note.is-active { border-color: var(--violet-line); background: var(--violet-soft); }
.pv-note__n { width: 22px; height: 22px; flex-shrink: 0; display: grid; place-items: center; border-radius: 50%; background: var(--violet); color: #fff; font-size: 11px; font-weight: 700; }
.pv-note__main { flex: 1; min-width: 0; }
.pv-note__where { font-size: 11.5px; color: var(--text-3); margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pv-note__input { width: 100%; resize: vertical; min-height: 44px; padding: 6px 8px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: var(--fs-sm); }
.pv-note__input:focus { outline: 0; border-color: var(--violet); box-shadow: 0 0 0 3px var(--violet-soft); }
.pv-note__x { align-self: flex-start; width: 22px; height: 22px; display: grid; place-items: center; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-4); cursor: pointer; }
.pv-note__x:hover { background: var(--surface-hover); color: var(--text); }
.pv-notes__foot { padding: 10px; border-top: 1px solid var(--border); }
.pv-notes__fine { margin-top: 6px; text-align: center; font-size: 11.5px; color: var(--text-3); }
@media (max-width: 760px) {
  .pv-notes { position: absolute; left: 8px; right: 8px; bottom: 8px; width: auto; max-height: 48%; margin: 0; z-index: 25; animation-name: rise-in; }
}

/* Console */
.pv-console { height: 240px; flex-shrink: 0; display: flex; flex-direction: column; border-top: 1px solid var(--border); background: var(--surface); animation: rise-in var(--dur) var(--ease); }
.pv-console__head { display: flex; align-items: center; gap: 6px; padding: 4px 8px; border-bottom: 1px solid var(--border); }
.pv-console__tabs { display: flex; gap: 2px; }
.pv-ctab { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-3); font: inherit; font-size: var(--fs-sm); font-weight: 500; cursor: pointer; }
.pv-ctab:hover { color: var(--text); background: var(--surface-hover); }
.pv-ctab.is-active { color: var(--text); background: var(--surface-active); }
.pv-ccount { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; display: inline-grid; place-items: center; background: var(--red); color: #fff; font-size: 10.5px; font-weight: 700; }
.pv-console__body { flex: 1; min-height: 0; overflow: auto; }
.pv-console__empty { display: flex; align-items: center; justify-content: center; gap: 8px; height: 100%; min-height: 80px; color: var(--text-3); font-size: var(--fs-sm); }
.pv-console__empty svg { color: var(--green); }
.pv-log { padding: 6px 0; font-family: var(--font-mono); font-size: 12px; line-height: 1.6; }
.pv-log__line { display: flex; gap: 10px; padding: 0 12px; }
.pv-log__line:hover { background: var(--surface-hover); }
.pv-log__t { color: var(--text-4); flex-shrink: 0; }
.pv-log__lv { width: 42px; flex-shrink: 0; color: var(--blueprint-ink); }
.pv-log__txt { color: var(--text-2); min-width: 0; overflow-wrap: anywhere; }
.pv-log__line.is-debug .pv-log__lv { color: var(--text-4); }
.pv-log__line.is-warn { background: var(--amber-soft); } .pv-log__line.is-warn .pv-log__lv { color: var(--amber-ink); }
.pv-log__line.is-error { background: var(--red-soft); } .pv-log__line.is-error .pv-log__lv, .pv-log__line.is-error .pv-log__txt { color: var(--red-ink); }
.pv-problems { padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.pv-problem { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--red-line); background: var(--red-soft); }
.pv-problem__icon { color: var(--red); flex-shrink: 0; display: inline-flex; }
.pv-problem__body { flex: 1; min-width: 0; }
.pv-problem__title { font-size: var(--fs-sm); font-weight: 600; color: var(--text); }
.pv-problem__meta { font-size: 12px; color: var(--text-3); margin-top: 2px; }
@media (max-width: 640px) { .pv-console { height: 50vh; } .pv-problem { flex-wrap: wrap; } }

/* QR modal */
.pv-qr { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.pv-qr__frame { padding: 14px; border-radius: var(--radius-lg); border: 1px solid var(--border); background: var(--surface); }
.pv-qr__code { display: block; fill: var(--text); }
.pv-qr__bg { fill: var(--surface); }
.pv-qr__note { max-width: 320px; margin: 0; }
.pv-qr__link { display: flex; align-items: center; gap: 6px; width: 100%; padding: 4px 4px 4px 12px; border-radius: var(--radius); background: var(--bg-sunken); border: 1px solid var(--border); }
.pv-qr__link code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-mono); font-size: 12px; color: var(--text-2); text-align: left; }

/* Live app page (/a/:slug) */
.pv-live { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); }
.pv-live--center { align-items: center; justify-content: center; gap: 12px; padding: 24px 16px; }
.pv-live__app { flex: 1; min-height: 0; position: relative; }
.pv-live__banner { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 8px 16px; background: var(--amber-soft); color: var(--amber-ink); border-bottom: 1px solid var(--amber-line); font-size: var(--fs-sm); }
.pv-live__sub { opacity: 0.85; flex: 1; min-width: 0; }
.pv-live__back { color: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.pv-built { position: fixed; right: 14px; bottom: 14px; z-index: 50; display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px 6px 12px; border-radius: var(--radius-full); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-md); color: var(--text-2); font-size: 12px; text-decoration: none; transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease); }
.pv-built:hover { transform: translateY(-1px); box-shadow: var(--shadow-lg); color: var(--text); }
.pv-built .logo { font-size: 12.5px; gap: 5px; }
.pv-built__txt { color: var(--text-3); }
.pv-404 { max-width: 440px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; animation: rise-in var(--dur-slow) var(--ease); }
.pv-404__mark { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 14px; background: var(--blueprint-soft); color: var(--blueprint); }
.pv-404__code { font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.12em; color: var(--text-4); }
.pv-404__title { margin: 0; font-family: var(--font-display); font-size: var(--fs-2xl); color: var(--text); }
.pv-404__body { margin: 0; color: var(--text-3); line-height: 1.55; }
.pv-404__body code { font-family: var(--font-mono); font-size: 0.92em; padding: 1px 6px; border-radius: 4px; background: var(--bg-sunken); color: var(--text-2); }
.pv-404__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 8px; }
