/* ============================================================
   V2 "Studio" editor shell — dark top bar, structure rail,
   inspector slot, floating page sheet, device preview overlay.
   Scoped under .bb-studio (root frame) so the preview screen and
   any non-studio render stay untouched. Owner-approved direction
   2026-07-15 (drafts/editor-redesign-v2.html).
   ============================================================ */

.bb-studio {
    --bbs-primary: #DB3A57;
    --bbs-primary-hover: #C22F4A;
    --bbs-primary-soft: #FFF1F5;
    --bbs-ink: #232025;
    --bbs-ink-2: #3A363F;
    --bbs-text: #2B2622;
    --bbs-text-2: #6E6660;
    --bbs-text-3: #A39B93;
    --bbs-border: #EAE4DC;
    --bbs-border-strong: #D9D2C8;
    --bbs-success: #2FBF71;
    --bbs-amber: #EDA100;
    --bbs-topbar-h: 52px;
    --bbs-rail-w: 248px;
    --bbs-rail-collapsed-w: 44px;
    --bbs-insp-w: 344px;
    --bbs-font: 'Inter', system-ui, -apple-system, sans-serif;
    background: #EFECE7;
}

/* the root frame keeps its own scrolling; make room for the chrome.
   The inspector column is ALWAYS reserved (draft V2: docked inspector
   with an empty state) — the sheet scale-to-fit absorbs the width. */
.bb-v2-builder-page.bb-studio {
    padding-top: var(--bbs-topbar-h);
    padding-left: var(--bbs-rail-w);
    padding-right: var(--bbs-insp-w);
}

.bb-v2-builder-page.bb-studio.bb-studio--rail-collapsed {
    padding-left: var(--bbs-rail-collapsed-w);
}

/* the old pages bar pushed the whole fixed frame down 44px — neutralize;
   the studio top bar lives INSIDE the frame's padding instead */
.bb-v2-builder-page.bb-studio.has-pages-bar {
    padding-top: var(--bbs-topbar-h);
    top: 0;
}

/* …and the classic editor also pushes the SITE's fixed nav down 44px
   (below its pages bar). Studio has no pages bar inside the sheet — the
   offset painted a strip of hero above the header. */
.bb-v2-builder-page.bb-studio.has-pages-bar #site-navigation {
    top: 0 !important;
}

/* ---------------- top bar ---------------- */
.bb-studio-topbar {
    align-items: center;
    background: var(--bbs-ink);
    color: #fff;
    display: flex;
    font-family: var(--bbs-font);
    gap: 10px;
    height: var(--bbs-topbar-h);
    left: 0;
    padding: 0 14px;
    position: fixed;
    right: 0;
    top: 0;
    z-index: 2147483200; /* above the side panel (2147483000) */
}

.bb-studio-exit {
    border-radius: 8px;
    color: #B9B2AB;
    font-size: 13px;
    font-weight: 600;
    padding: 6px 10px;
    text-decoration: none;
    white-space: nowrap;
}

.bb-studio-exit:hover {
    background: var(--bbs-ink-2);
    color: #fff;
    text-decoration: none;
}

.bb-studio-pages {
    align-items: center;
    display: flex;
    gap: 4px;
    max-width: 40vw;
    overflow-x: auto;
    scrollbar-width: none;
}

.bb-studio-pages::-webkit-scrollbar { display: none; }

.bb-studio-pages__label {
    color: #8F8880;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    margin-right: 4px;
    text-transform: uppercase;
}

.bb-studio-page-chip {
    border-radius: 999px;
    color: #C9C2BC;
    font-size: 12.5px;
    font-weight: 600;
    padding: 5px 12px;
    text-decoration: none;
    white-space: nowrap;
}

.bb-studio-page-chip:hover {
    background: var(--bbs-ink-2);
    color: #fff;
    text-decoration: none;
}

.bb-studio-page-chip.is-active {
    background: #fff;
    color: var(--bbs-ink);
}

.bb-studio-topbar__mid {
    display: flex;
    flex: 1;
    justify-content: center;
}

.bb-studio-devices {
    background: var(--bbs-ink-2);
    border-radius: 10px;
    display: flex;
    gap: 2px;
    padding: 3px;
}

.bb-studio-devices button {
    align-items: center;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: #B9B2AB;
    cursor: pointer;
    display: flex;
    height: 30px;
    justify-content: center;
    width: 38px;
}

.bb-studio-devices button svg {
    height: 16px;
    width: 16px;
}

.bb-studio-devices button.is-active {
    background: #fff;
    color: var(--bbs-ink);
}

.bb-studio-topbar__right {
    align-items: center;
    display: flex;
    gap: 8px;
}

.bb-studio-save {
    align-items: center;
    color: #B9B2AB;
    display: flex;
    font-size: 12px;
    gap: 7px;
    padding: 0 8px;
    white-space: nowrap;
}

.bb-studio-save__pulse {
    background: var(--bbs-success);
    border-radius: 50%;
    height: 8px;
    width: 8px;
}

.bb-studio-save.is-saving .bb-studio-save__pulse {
    animation: bbs-pulse 1s infinite;
    background: var(--bbs-amber);
}

.bb-studio-save.is-error {
    color: #FF9CB0;
}

.bb-studio-save.is-error .bb-studio-save__pulse {
    background: #FF5D7E;
}

@keyframes bbs-pulse {
    50% { opacity: 0.35; }
}

.bb-studio-btn {
    background: transparent;
    border: 1px solid #4A4550;
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    font-family: var(--bbs-font);
    font-size: 13px;
    font-weight: 600;
    padding: 7px 14px;
    text-decoration: none;
    white-space: nowrap;
}

.bb-studio-btn:hover {
    background: var(--bbs-ink-2);
    color: #fff;
    text-decoration: none;
}

.bb-studio-btn--primary {
    background: var(--bbs-primary);
    border-color: var(--bbs-primary);
}

.bb-studio-btn--primary:hover {
    background: var(--bbs-primary-hover);
}

/* ---------------- structure rail ---------------- */
.bb-studio-rail {
    background: #FBFAF8;
    border-right: 1px solid var(--bbs-border);
    bottom: 0;
    display: flex;
    flex-direction: column;
    font-family: var(--bbs-font);
    left: 0;
    position: fixed;
    top: var(--bbs-topbar-h);
    width: var(--bbs-rail-w);
    z-index: 2147483100;
    transition: width 0.2s ease;
}

.bb-studio-rail__head {
    align-items: center;
    color: var(--bbs-text-3);
    display: flex;
    font-size: 11.5px;
    font-weight: 700;
    justify-content: space-between;
    letter-spacing: 0.08em;
    min-height: 54px;
    padding: 10px 10px 8px 16px;
    text-transform: uppercase;
}

.bb-studio-rail__collapse {
    align-items: center;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--bbs-text-3);
    cursor: pointer;
    display: flex;
    flex: none;
    height: 32px;
    justify-content: center;
    padding: 0;
    transition: background-color 0.16s ease, color 0.16s ease, transform 0.2s ease;
    width: 32px;
}

.bb-studio-rail__collapse:hover,
.bb-studio-rail__collapse:focus-visible {
    background: var(--bbs-primary-soft);
    color: var(--bbs-primary);
    outline: none;
}

.bb-studio-rail__collapse svg {
    height: 17px;
    width: 17px;
}

.bb-studio.bb-studio--rail-collapsed .bb-studio-rail {
    width: var(--bbs-rail-collapsed-w);
}

.bb-studio.bb-studio--rail-collapsed .bb-studio-rail__head {
    justify-content: center;
    padding: 10px 6px 8px;
}

.bb-studio.bb-studio--rail-collapsed .bb-studio-rail__title,
.bb-studio.bb-studio--rail-collapsed .bb-studio-rail__list,
.bb-studio.bb-studio--rail-collapsed .bb-studio-rail__foot {
    display: none;
}

.bb-studio.bb-studio--rail-collapsed .bb-studio-rail__collapse {
    transform: rotate(180deg);
}

.bb-studio-rail__list {
    flex: 1;
    overflow-y: auto;
    padding: 0 10px 10px;
}

.bb-studio-rail-item {
    align-items: center;
    border: 1px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    gap: 9px;
    margin-bottom: 2px;
    padding: 8px 8px 8px 6px;
    position: relative;
    user-select: none;
}

.bb-studio-rail-item:hover {
    background: #F2EFE9;
}

.bb-studio-rail-item.is-active {
    background: #fff;
    border-color: var(--bbs-border);
    box-shadow: 0 2px 10px rgba(43, 38, 34, 0.08);
}

.bb-studio-rail-item__grip {
    align-items: center;
    color: var(--bbs-text-3);
    cursor: grab;
    display: flex;
    flex: none;
    justify-content: center;
    opacity: 0;
    width: 16px;
}

.bb-studio-rail-item:hover .bb-studio-rail-item__grip,
.bb-studio-rail-item.is-active .bb-studio-rail-item__grip {
    opacity: 1;
}

.bb-studio-rail-item__grip svg {
    height: 13px;
    width: 13px;
}

.bb-studio-rail-item__icon {
    align-items: center;
    background: var(--bbs-primary-soft);
    border-radius: 8px;
    color: var(--bbs-primary);
    display: flex;
    flex: none;
    height: 28px;
    justify-content: center;
    width: 28px;
}

.bb-studio-rail-item__icon svg {
    height: 14px;
    width: 14px;
}

.bb-studio-rail-item__name {
    color: var(--bbs-text);
    flex: 1;
    font-size: 13px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bb-studio-rail-item.drop-above::before,
.bb-studio-rail-item.drop-below::after {
    background: var(--bbs-primary);
    border-radius: 2px;
    content: "";
    height: 2.5px;
    left: 6px;
    position: absolute;
    right: 6px;
}

.bb-studio-rail-item.drop-above::before { top: -2px; }
.bb-studio-rail-item.drop-below::after { bottom: -2px; }

.bb-studio-rail.is-busy .bb-studio-rail__list {
    opacity: 0.5;
    pointer-events: none;
}

.bb-studio-rail__foot {
    border-top: 1px solid var(--bbs-border);
    padding: 12px;
}

.bb-studio-rail__add {
    background: transparent;
    border: 1.5px dashed var(--bbs-border-strong);
    border-radius: 10px;
    color: var(--bbs-text-2);
    cursor: pointer;
    font-family: var(--bbs-font);
    font-size: 13px;
    font-weight: 600;
    padding: 11px;
    width: 100%;
}

.bb-studio-rail__add:hover {
    background: var(--bbs-primary-soft);
    border-color: var(--bbs-primary);
    color: var(--bbs-primary);
}

/* ---------------- inspector slot ---------------- */
.bb-studio-insp-slot {
    background: #fff;
    border-left: 1px solid var(--bbs-border);
    bottom: 0;
    font-family: var(--bbs-font);
    position: fixed;
    right: 0;
    top: var(--bbs-topbar-h);
    width: var(--bbs-insp-w);
    z-index: 2147482900; /* just under the side panel */
}

.bb-studio-insp-empty {
    align-items: center;
    color: var(--bbs-text-3);
    display: flex;
    flex-direction: column;
    gap: 12px;
    height: 100%;
    justify-content: center;
    padding: 30px;
    text-align: center;
}

.bb-studio-insp-empty__icon {
    align-items: center;
    background: #F6F6F6;
    border-radius: 16px;
    display: flex;
    height: 52px;
    justify-content: center;
    width: 52px;
}

.bb-studio-insp-empty__icon svg {
    height: 22px;
    width: 22px;
}

.bb-studio-insp-empty p {
    font-size: 13px;
    line-height: 1.55;
    margin: 0;
    max-width: 220px;
}

.bb-studio-insp-empty b {
    color: var(--bbs-text-2);
}

/* dock the existing side panel into the slot */
.bb-studio #form-container.builder-side-panel {
    height: calc(100vh - var(--bbs-topbar-h));
    top: var(--bbs-topbar-h);
    width: var(--bbs-insp-w);
}

/* expanded mode still allowed to grow over the sheet */
.bb-studio #form-container.builder-side-panel.is-expanded {
    width: min(72rem, calc(100vw - var(--bbs-rail-w)));
}

/* ---------------- page sheet: natural width, scaled to fit ----------------
   Legacy pages are built full-bleed with fixed-width containers (~1250px)
   and position:fixed site chrome. The sheet renders them at natural width
   and is scaled down by JS (--bbs-scale) — nothing clips, and the transform
   makes fixed descendants (site nav) position against the SHEET, not the
   viewport. */
.bb-studio-canvas {
    overflow: hidden;
    padding: 0;
    position: relative;
}

.bb-studio-sheet {
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 10px 40px rgba(43, 38, 34, 0.16);
    margin-top: 26px;
    overflow: hidden;
    transform-origin: top left;
    width: 1300px;
}

/* ---------------- device preview overlay ---------------- */
.bb-studio-device-overlay {
    align-items: stretch;
    background: #EFECE7;
    bottom: 0;
    display: flex;
    justify-content: center;
    left: var(--bbs-rail-w);
    padding: 26px 0 0;
    position: fixed;
    right: var(--bbs-insp-w);
    top: var(--bbs-topbar-h);
    z-index: 2147483050;
}

.bb-studio.bb-studio--rail-collapsed .bb-studio-device-overlay {
    left: var(--bbs-rail-collapsed-w);
}

.bb-studio-device-overlay[hidden] {
    display: none;
}

.bb-studio-device-frame-wrap {
    background: #fff;
    border-radius: 14px 14px 0 0;
    box-shadow: 0 10px 40px rgba(43, 38, 34, 0.2);
    overflow: hidden;
    transition: width 0.3s ease;
    width: 768px;
}

.bb-studio-device-frame-wrap[data-bb-studio-device-size="mobile"] {
    width: 392px;
}

.bb-studio-device-frame-wrap iframe {
    border: none;
    display: block;
    height: 100%;
    width: 100%;
}

/* rail-driven block highlight */
[data-bb-v2-block-shell].bb-studio-flash {
    animation: bbs-flash 1.4s ease;
}

@keyframes bbs-flash {
    0%, 60% { box-shadow: inset 0 0 0 2px var(--bbs-primary, #DB3A57); }
    100% { box-shadow: none; }
}

body.bb-studio-dragging {
    cursor: grabbing;
    user-select: none;
}

/* ---------------- narrow screens: collapse the studio chrome ---------------- */
@media (max-width: 1100px) {
    .bb-v2-builder-page.bb-studio {
        padding-left: 0;
        padding-right: 0;
    }

    .bb-studio-rail,
    .bb-studio-insp-slot {
        display: none;
    }

    .bb-studio-sheet {
        border-radius: 0;
        margin: 0;
        max-width: none;
        width: 100%;
    }

    .bb-studio-device-overlay {
        left: 0;
        right: 0;
    }

    .bb-studio #form-container.builder-side-panel {
        width: min(400px, 100vw);
    }
}
