/* CSS Pattern Backgrounds - preview + code left, controls right */

.cpb-app {
    position: relative;
    display: flex;
    height: 100%;
    overflow: hidden;
}

/* Stage (left): the live preview on top, the generated code below it */
.cpb-stage {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Fills the studio frame, so the pattern follows the letterboxing when an
   aspect ratio is picked. The frame behind it carries the checkerboard in
   transparent mode (.gn-studio-transparent in common.css). */
.cpb-preview {
    width: 100%;
    height: 100%;
}

/* The shared background picker sits in the right-hand slot of its colour
   row, so the row already supplies the vertical rhythm */
.cpb-color-row .gn-bg-options {
    padding: 0;
}

/* Code panel: a fixed share of the stage rather than a height that follows
   the code, so the preview never jumps when you switch pattern or format.
   The minimum keeps the toolbar plus a couple of code lines visible on
   short viewports. */
.cpb-code {
    flex: 0 0 32%;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    border-top: 1px solid var(--gn-card-border);
    background-color: var(--gn-card-bg);
}

.cpb-code-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--gn-card-border);
}

.cpb-code-text {
    flex: 1 1 auto;
    min-height: 0;
    margin: 0;
    padding: 0.75rem;
    overflow: auto;
    font-size: 0.8rem;
    line-height: 1.5;
    white-space: pre;
    color: var(--gn-body-color);
}

/* Controls panel (right); header/body/footer layout comes from the shared
   .app-side-* classes in css/common.css */
.cpb-panel {
    flex: 0 0 300px;
    border-left: 1px solid var(--gn-card-border);
}

.cpb-label {
    font-size: 0.8rem;
    color: var(--gn-muted);
    margin-bottom: 0;
    margin-top: 0.5rem;
    display: block;
}

/* Tuck the slider closer to its label + value row */
.cpb-app .form-range {
    margin-top: -2px;
}

/* Previous/next pattern buttons share the select's border colour */
.cpb-nav {
    border: 1px solid var(--bs-border-color);
    color: var(--gn-muted);
    background: none;
}

.cpb-nav:hover {
    border-color: var(--bs-border-color);
    background-color: var(--gn-sidebar-hover-bg);
    color: var(--gn-accent);
}

.cpb-val {
    float: right;
    color: var(--gn-accent);
    font-size: 0.75rem;
}

.cpb-sep {
    margin: 0.75rem 0;
    border-color: var(--gn-card-border);
    opacity: 1;
}

.cpb-color-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.25rem 0;
}

/* The dialog paints the backdrop itself. Bootstrap's own goes on <body>,
   which is outside the app panel and so is not rendered while the panel is
   the fullscreen element - the dialog would float over the pattern with
   nothing behind it. */
.cpb-browser.modal {
    background-color: rgba(0, 0, 0, 0.5);
}

/* A little taller than the default inset allows: this is a grid to browse,
   and the height is what decides how many rows are in view. Through the
   variable rather than the margin, because modal-dialog-scrollable works its
   own height out from it - set the two apart and the dialog is pushed off
   the top of a short screen. */
.cpb-browser.modal {
    --bs-modal-margin: 1rem;
}

.cpb-browser-search {
    max-width: 260px;
}

.cpb-browser-grid {
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 8px;
    padding: 1rem;
}

.cpb-browser-group {
    width: 100%;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gn-accent);
    border-bottom: 1px solid var(--gn-card-border);
    padding-bottom: 4px;
    margin-top: 8px;
}

.cpb-browser-empty {
    width: 100%;
    padding: 2rem 0;
    text-align: center;
    color: var(--gn-muted);
}

.cpb-pattern-card {
    width: 132px;
    padding: 8px;
    text-align: center;
    background: none;
    border: 2px solid transparent;
    border-radius: 0.5rem;
    color: var(--gn-body-color);
    transition: border-color 0.15s, background-color 0.15s;
}

.cpb-pattern-card:hover,
.cpb-pattern-card.active {
    border-color: var(--gn-accent);
    background-color: var(--gn-sidebar-hover-bg);
}

/* The swatch is a real element carrying the pattern's own CSS */
.cpb-swatch {
    display: block;
    width: 112px;
    height: 76px;
    margin: 0 auto 4px;
    border-radius: 0.375rem;
    border: 1px solid var(--gn-card-border);
}

.cpb-pattern-card span:last-child {
    display: block;
    font-size: 0.7rem;
    color: var(--gn-muted);
    line-height: 1.15;
}

/* Small screens: stack, with the preview pinned at the top so the pattern
   stays visible while dragging sliders in the controls below */
@media (max-width: 767px) {
    .cpb-app {
        flex-direction: column;
        overflow-y: auto;
    }

    .cpb-stage {
        position: sticky;
        top: 0;
        z-index: 4;
        flex: 0 0 auto;
        height: 46vh;
    }

    .cpb-panel {
        flex: 0 0 auto;
        border-left: 0;
        border-top: 1px solid var(--gn-card-border);
    }

    /* The whole app container scrolls instead of the panel body; the
       pattern header sticks right below the preview and the action
       footer sticks to the bottom edge */
    .cpb-panel .app-side-body {
        overflow-y: visible;
    }

    .cpb-panel .app-side-header {
        position: sticky;
        top: 46vh;
        z-index: 3;
        background-color: var(--gn-card-bg);
    }

    .cpb-panel .app-side-footer {
        position: sticky;
        bottom: 0;
        z-index: 3;
        background-color: var(--gn-card-bg);
    }
}
