/* ==========================================================================
   New template gallery (Canva-style) — additive stylesheet.
   Deliberately separate from builder-style.css (compiled from SCSS by Prepros
   on Vince's machine); fold into the SCSS pipeline later if preferred.

   Palette follows the dashboard's own tokens: base #1b1d21
   (--buiilderBaseColor), content tiles rgb(57 80 97 / 40%) with 0.75rem radius
   and white type (same treatment as [data-report]/[data-template] cards),
   white-on-dark pills, AI purple #7E57C2 for the generate cards.
   ========================================================================== */

[data-template-gallery] {
    /* A dashboard-wide rule forces sections to display:flex row — win that
       fight, and keep full-width children as a fallback. */
    display: block !important;
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
    padding-bottom: 4rem;
    color: #fff;
}
[data-template-gallery] > * { width: 100%; flex: 1 1 100%; min-width: 0; }

/* ---- toolbar: search + category pills ---- */
[data-template-gallery] [data-gallery-toolbar] {
    /* position: sticky; */
    top: 0;
    z-index: 30;
    background: rgba(27, 29, 33, 0.82);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    padding: 0.75rem 0rem;
    margin-bottom: 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

[data-template-gallery] [data-gallery-search] {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(57, 80, 97, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 999px;
    padding: 0.4rem 1rem;
    max-width: 34rem;
    margin: 0 auto 0.75rem;
}
[data-template-gallery] [data-gallery-search] .material-symbols-outlined {
    font-size: 1.25rem;
    color: rgba(255, 255, 255, 0.55);
}
[data-template-gallery] [data-gallery-search] input {
    flex: 1;
    border: none;
    outline: none;
    background: none;
    font-size: 0.95rem;
    color: #fff;
}
[data-template-gallery] [data-gallery-search] input::placeholder { color: rgba(255, 255, 255, 0.45); }

[data-template-gallery] [data-gallery-pills] {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.4rem;
    /* max-width: 45rem; */
    margin: 0 auto;
}
[data-template-gallery] [data-pill] {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 1rem;
    border-radius: 999px;
    background: rgba(var(--buiilderFrontRGB));
    font-size: 0.85rem;
    font-weight: 700 !important;
    color: rgba(255, 255, 255, 1);
    text-decoration: none;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    height: 2.25rem;
    flex-grow: 1;
    justify-content: center;
}
[data-template-gallery] [data-pill] .material-symbols-outlined { 
    font-size: 1.2rem !important; 
    font-weight: 600 !important;
    color: rgb(197, 223, 255) !important;
}
[data-template-gallery] [data-pill]:hover { background: #3B98E5 !important; }
[data-template-gallery] [data-pill].active {
    background: #286ea6;
    border-color: #286ea6;
    color: #fff;
}

/* ---- shelves ---- */
[data-template-gallery] [data-gallery-shelf] { margin-bottom: 2rem; }
[data-template-gallery] [data-shelf-head] {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 0.6rem;
}
[data-template-gallery] [data-shelf-head] h3 {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 1.05rem;
    font-weight: 800;
    color: #fff;
    margin: 0;
}
[data-template-gallery] [data-shelf-head] h3 .material-symbols-outlined {
    font-size: 1.2rem;
    color: rgba(255, 255, 255, 0.55);
}
[data-template-gallery] [data-shelf-head] a {
    font-size: 0.82rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.6);
    text-decoration: none;
}
[data-template-gallery] [data-shelf-head] a:hover { color: #fff; text-decoration: underline; }

/* ---- shelf carousel (arrows either side of the scrolling row) ---- */
[data-template-gallery] [data-shelf-carousel] {
    display: flex;
    align-items: stretch;
    gap: 1rem;
}
[data-template-gallery] [data-shelf-nav] {
        height: 17rem;
        flex: none;
    align-self: center;
    color: rgba(255, 255, 255, 0.75);
}
[data-template-gallery] [data-shelf-nav]:disabled {
    opacity: 0.25;
    /* Keep the row from reflowing as arrows enable/disable. */
    pointer-events: none;
}

[data-template-gallery] [data-shelf-row] {
    display: grid;
    grid-auto-flow: column;
    /* Fixed track width: a shelf with 2 cards must not stretch them. */
    grid-auto-columns: 25rem;
    gap: 0.9rem;
    overflow-x: auto;
    padding-bottom: 0rem;
    scroll-snap-type: x proximity;
    /* Carousel viewport: the arrows scroll it, so it must be able to shrink
       inside the flex row rather than push the next arrow off screen. */
    flex: 1;
    min-width: 0;
    cursor: grab;
    /* Vertical panning still belongs to the page. */
    touch-action: pan-y;
    user-select: none;
    -webkit-user-select: none;
    scrollbar-width: none;
}
[data-template-gallery] [data-shelf-row]::-webkit-scrollbar { display: none; }
[data-template-gallery] [data-shelf-row]:active { cursor: grabbing; }
[data-template-gallery] [data-shelf-row] > * { scroll-snap-align: start; }
/* A dragged card must not start a native image/link drag. */
[data-template-gallery] [data-shelf-row] a { -webkit-user-drag: none; }

/* ---- grid (category / search views) ---- */
[data-template-gallery] [data-gallery-grid] {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
    gap: 1rem;
}
[data-template-gallery] [data-gallery-empty] {
    grid-column: 1 / -1;
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.9rem;
    padding: 2rem 0;
    text-align: center;
}
[data-template-gallery] [data-gallery-loading] {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: center;
    color: rgba(255, 255, 255, 0.6);
    padding: 3rem 0;
}

/* ---- cards — same tile treatment as the reports/templates lists ---- */
[data-template-gallery] [data-g-card] {
    position: relative;
    border-radius: 0.75rem;
    overflow: hidden;
    background: rgba(57, 80, 97, 0.4);
    padding: 0.5rem;
    transition: background 0.18s ease, transform 0.18s ease;
}
[data-template-gallery] [data-g-card]:hover {
    background: rgba(57, 80, 97, 0.62);
    transform: translateY(-2px);
}
[data-template-gallery] [data-g-card] a { text-decoration: none; display: block; }
[data-template-gallery] [data-g-cover] {
    aspect-ratio: 16 / 9.5;
    border-radius: 0.5rem;
    background: #1c1c1c no-repeat center center / cover;
    background-size: cover;
    background-position: center;
    position: relative;
    overflow: hidden;
}

/* ---- layered cover stack ----
   The card shows several of a template's designs at once as an overlapping
   cascade rather than cycling them on hover. Layers are emitted back-to-front
   (gallery_cover_stack reverses), so DOM order is paint order and no z-index
   bookkeeping is needed. Sized below 100% and offset diagonally so the whole
   stack stays inside the card; the container keeps overflow:hidden so a layer
   can never bleed over the title or the next card. */
[data-template-gallery] [data-g-cover][data-layers] { background: #14171c; }
[data-template-gallery] [data-g-layer] {
    position: absolute;
    inset: 0;
    background: #1c1c1c no-repeat center center / cover;
    border-radius: 0.3rem;
    box-shadow: 0 0.35rem 0.9rem rgba(0, 0, 0, 0.5);
    transition: transform 0.28s ease;
}
/* One cover: fill the card, no cascade to imply. */
[data-template-gallery] [data-g-cover][data-layers="1"] [data-g-layer] {
    border-radius: 0.5rem;
    box-shadow: none;
}
/* Two and three covers step down-right, front layer last. */
[data-template-gallery] [data-g-cover][data-layers="2"] [data-g-layer] { transform: translate(-5%, -5%) scale(0.88); }
[data-template-gallery] [data-g-cover][data-layers="2"] [data-g-layer]:nth-child(2) { transform: translate(5%, 5%) scale(0.88); }
[data-template-gallery] [data-g-cover][data-layers="3"] [data-g-layer] { transform: translate(-8%, -8%) scale(0.8); }
[data-template-gallery] [data-g-cover][data-layers="3"] [data-g-layer]:nth-child(2) { transform: translate(0, 0) scale(0.8); }
[data-template-gallery] [data-g-cover][data-layers="3"] [data-g-layer]:nth-child(3) { transform: translate(8%, 8%) scale(0.8); }
/* Hover fans the stack apart a little — the only motion, and it's a hint that
   there is more than one design in here. */
[data-template-gallery] [data-g-card]:hover [data-g-cover][data-layers="2"] [data-g-layer] { transform: translate(-8%, -8%) scale(0.86); }
[data-template-gallery] [data-g-card]:hover [data-g-cover][data-layers="2"] [data-g-layer]:nth-child(2) { transform: translate(8%, 8%) scale(0.86); }
[data-template-gallery] [data-g-card]:hover [data-g-cover][data-layers="3"] [data-g-layer] { transform: translate(-12%, -11%) scale(0.78); }
[data-template-gallery] [data-g-card]:hover [data-g-cover][data-layers="3"] [data-g-layer]:nth-child(3) { transform: translate(12%, 11%) scale(0.78); }
/* Badges and locks sit above the stack. */
[data-template-gallery] [data-g-badge],
[data-template-gallery] [data-g-lock] { z-index: 5; }
[data-template-gallery] [data-g-title] {
    font-size: 0.9rem;
    font-weight: 700;
    color: #fff;
    padding: 0.5rem 0.25rem 0.15rem;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
[data-template-gallery] [data-g-badge] {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    background: rgba(27, 29, 33, 0.82);
    color: #fff;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    padding: 0.18rem 0.5rem;
    border-radius: 999px;
}
[data-template-gallery] [data-g-badge] .material-symbols-outlined { font-size: 0.85rem; }
[data-template-gallery] [data-g-lock] {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    display: inline-flex;
    background: rgba(255, 255, 255, 0.92);
    color: #1b1d21;
    border-radius: 999px;
    padding: 0.22rem;
}
[data-template-gallery] [data-g-lock] .material-symbols-outlined { font-size: 1rem; }
[data-template-gallery] [data-g-delete] {
    position: absolute;
    top: 0.65rem;
    right: 0.65rem;
    opacity: 0;
    color: #fff;
    transition: opacity 0.15s ease;
}
[data-template-gallery] [data-g-card]:hover [data-g-delete] { opacity: 1; }

/* "Generate one for me" card — AI purple, translucent on the dark base */
[data-template-gallery] [data-g-generate] { cursor: pointer; background: rgba(126, 87, 194, 0.16); }
[data-template-gallery] [data-g-generate]:hover { background: rgba(126, 87, 194, 0.3); }
[data-template-gallery] [data-g-generate] [data-g-cover] {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    background: rgba(126, 87, 194, 0.14);
    border: 1px dashed rgba(126, 87, 194, 0.55);
    color: #c9b6f2;
    text-align: center;
}
[data-template-gallery] [data-g-generate] [data-g-cover] .material-symbols-outlined { font-size: 2rem; }
[data-template-gallery] [data-g-generate] [data-g-cover] p { font-size: 0.85rem; font-weight: 700; margin: 0; line-height: 1.25; }

/* ---- detail modal — dark panel matching the app chrome ---- */
[data-template-gallery] [data-g-detail] {
    position: fixed;
    inset: 0;
    z-index: 90;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}
[data-template-gallery] [data-g-detail-card] {
    display: flex;
    width: 100%;
    height: 100%;
    background: #232328;
    color: #fff;
    border-radius: 0.5rem;
    overflow: hidden;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
}
[data-template-gallery] [data-g-detail-preview] {
    flex: 1.6;
    background: #1b1d21;
    position: relative;
    min-width: 0;
}
[data-template-gallery] [data-g-detail-preview] iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: #fff;
}
[data-template-gallery] [data-g-detail-covers] {
    height: 100%;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.5rem;
}
[data-template-gallery] [data-g-detail-covers] > div {
    aspect-ratio: 16 / 9;
    border-radius: 0.4rem;
    background: #1c1c1c no-repeat center center / cover;
    background-size: cover;
    background-position: center;
    flex-shrink: 0;
}
[data-template-gallery] [data-g-detail-loading] {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: rgba(255, 255, 255, 0.6);
}
[data-template-gallery] [data-g-detail-info] {
    flex: 1;
    max-width: 24rem;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    position: relative;
    overflow-y: auto;
}
[data-template-gallery] [data-g-detail-close] { position: absolute; top: 0.6rem; right: 0.6rem; color: #fff; }
[data-template-gallery] [data-g-detail-info] h2 {
    font-size: 1.35rem;
    font-weight: 800;
    color: #fff;
    margin: 0.5rem 2rem 0 0;
    line-height: 1.2;
}
[data-template-gallery] [data-g-detail-meta] {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.6);
    margin: 0;
    text-transform: capitalize;
}
[data-template-gallery] [data-g-detail-ctas] {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
[data-template-gallery] [data-g-detail-ctas] .btn {
    justify-content: center;
    gap: 0.4rem;
    border-radius: 0.55rem;
    text-transform: none;
}
/* Explicit CTA hierarchy — the app's blue for the primary action (same
   #3b98e3 the rest of the product uses), translucent outline secondary. */
[data-template-gallery] [data-g-detail-ctas] .btn-primary {
    background: #3b98e3 !important;
    border-color: #3b98e3 !important;
    color: #fff !important;
}
[data-template-gallery] [data-g-detail-ctas] .btn-primary:hover {
    background: #2f86cd !important;
    border-color: #2f86cd !important;
}
[data-template-gallery] [data-g-detail-ctas] .btn:not(.btn-primary):not(.btn-ghost) {
    background: rgba(255, 255, 255, 0.08) !important;
    border: 1px solid rgba(255, 255, 255, 0.25) !important;
    color: #fff !important;
}
[data-template-gallery] [data-g-detail-ctas] .btn:not(.btn-primary):not(.btn-ghost):hover {
    background: rgba(255, 255, 255, 0.16) !important;
}
[data-template-gallery] [data-g-detail-ctas] .btn-ghost {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    color: rgba(255, 255, 255, 0.6) !important;
}
[data-template-gallery] [data-g-detail-note] { font-size: 0.85rem; color: rgba(255, 255, 255, 0.6); }
[data-template-gallery] [data-g-detail-credits] {
    margin-top: auto;
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.45);
    line-height: 1.5;
}
[data-template-gallery] [data-g-detail-credits] a { color: rgba(255, 255, 255, 0.65); text-decoration: underline; }

/* ---- staff curation ---- */
[data-template-gallery] [data-gallery-curation] {
    margin-top: 3rem;
    padding-top: 1.5rem;
    border-top: 1px dashed rgba(255, 255, 255, 0.18);
}
[data-template-gallery] [data-curation-count] { opacity: 0.55; font-weight: 600; }
[data-template-gallery] [data-curation-actions] {
    display: flex;
    gap: 0.3rem;
    justify-content: center;
    padding: 0.4rem 0.25rem 0.1rem;
}
[data-template-gallery] [data-curation-actions] .btn { text-transform: none; }
[data-template-gallery] [data-g-card][data-curation-status="published"],
[data-template-gallery] [data-g-card][data-curation-status="rejected"],
[data-template-gallery] [data-g-card][data-curation-status="failed"] { opacity: 0.45; }
[data-template-gallery] [data-curation-form] aside input,
[data-template-gallery] [data-curation-form] aside select {
    width: 100%;
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
    color: #fff;
}

@media (max-width: 760px) {
    [data-template-gallery] [data-g-detail] { padding: 0; }
    [data-template-gallery] [data-g-detail-card] { flex-direction: column; height: 100%; border-radius: 0; }
    [data-template-gallery] [data-g-detail-preview] { flex: 1; }
    [data-template-gallery] [data-g-detail-info] { max-width: none; flex: none; max-height: 45%; }
}

/* ---- brand controls (detail modal) ---- */
[data-template-gallery] [data-g-detail-brand] {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    margin: 0.35rem 0 0.9rem;
}
[data-template-gallery] [data-g-detail-tint] {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.72);
    cursor: pointer;
    user-select: none;
}
[data-template-gallery] [data-g-detail-tint] .material-symbols-outlined {
    font-size: 1.05rem;
    color: rgba(255, 255, 255, 0.55);
}
[data-template-gallery] [data-g-detail-tint]:hover { color: #fff; }
[data-template-gallery] [data-shelf-count] {
    font-size: 0.82rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.45);
}

/* ---- preview cross-fade ----
   Two stacked iframes; only the active one is visible and interactive. The
   incoming version paints in the hidden buffer first (see
   gallery_preview_refresh), so this fade never reveals a blank frame. */
[data-template-gallery] [data-g-detail-preview] { position: relative; }
[data-template-gallery] iframe[data-g-preview-frame] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.32s ease;
}
[data-template-gallery] iframe[data-g-preview-frame].active {
    opacity: 1;
    pointer-events: auto;
    /* the visible frame sits on top so it can't be occluded mid-fade */
    z-index: 2;
}
@media (prefers-reduced-motion: reduce) {
    [data-template-gallery] iframe[data-g-preview-frame] { transition: none; }
}
