/* ── TemplatePreviewModal — fullscreen preview on top of TemplateGallery ── */

.tpm-overlay {
    position: fixed;
    inset: 0;
    z-index: 200; /* TemplateGallery is z-index: 100 */
    display: flex;
    align-items: stretch;
    justify-content: center;
    background: oklch(0.16 0.02 250 / 0.72);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    animation: tpm-fade-in 0.22s var(--ease-silk, ease-out) both;
}

@keyframes tpm-fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.tpm-panel {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--editor-bg, oklch(0.97 0.01 250));
    animation: tpm-rise 0.26s var(--ease-snappy, cubic-bezier(0.22, 1, 0.36, 1)) both;
}

@keyframes tpm-rise {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── Header (sticky control bar) ── */
.tpm-header {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 16px;
    padding: 14px 22px;
    background: var(--editor-surface-raised, oklch(1 0 0));
    border-bottom: 1px solid var(--editor-border, oklch(0.92 0.01 250));
    box-shadow: 0 1px 0 oklch(0.20 0.02 250 / 0.04);
    z-index: 2;
}

.tpm-header__left {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tpm-title {
    margin: 0;
    font-family: 'Outfit', sans-serif;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--editor-text, oklch(0.22 0.02 250));
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tpm-subtitle {
    margin: 0;
    font-family: 'Outfit', sans-serif;
    font-size: 0.78rem;
    color: var(--editor-text-muted, oklch(0.50 0.02 250));
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Device switcher (segmented control) ── */
.tpm-header__center {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    background: oklch(0.95 0.005 250);
    border-radius: 999px;
    border: 1px solid var(--editor-border, oklch(0.92 0.01 250));
}

.tpm-device {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border: none;
    background: transparent;
    color: var(--editor-text-muted, oklch(0.45 0.02 250));
    font-family: 'Outfit', sans-serif;
    font-size: 0.78rem;
    font-weight: 500;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.18s var(--ease-snappy, ease-out),
        color 0.18s var(--ease-snappy, ease-out);
}

.tpm-device:hover:not(.tpm-device--active) {
    background: oklch(1 0 0 / 0.6);
    color: var(--editor-text, oklch(0.22 0.02 250));
}

.tpm-device--active {
    background: var(--editor-surface-raised, oklch(1 0 0));
    color: var(--editor-accent, oklch(0.55 0.18 240));
    box-shadow: 0 1px 2px oklch(0.20 0.02 250 / 0.10);
}

.tpm-device__label {
    line-height: 1;
}

/* ── Right side: Use + Close ── */
.tpm-header__right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}

.tpm-use {
    padding: 9px 18px;
    font-family: 'Outfit', sans-serif;
    font-size: 0.82rem;
    font-weight: 600;
    color: oklch(1 0 0);
    background: var(--editor-accent, oklch(0.55 0.18 240));
    border: none;
    border-radius: var(--radius-md, 8px);
    cursor: pointer;
    transition: background 0.18s var(--ease-snappy, ease-out),
        transform 0.15s var(--ease-snappy, ease-out);
}

.tpm-use:hover:not(:disabled) {
    background: var(--editor-accent-hover, oklch(0.50 0.18 240));
    transform: translateY(-1px);
}

.tpm-use:disabled,
.tpm-use--active {
    background: oklch(0.55 0.18 145);
    cursor: default;
    transform: none;
}

.tpm-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md, 8px);
    border: 1px solid var(--editor-border, oklch(0.92 0.01 250));
    background: var(--editor-surface-raised, oklch(1 0 0));
    color: var(--editor-text-muted, oklch(0.45 0.02 250));
    cursor: pointer;
    transition: background 0.18s var(--ease-snappy, ease-out),
        color 0.18s var(--ease-snappy, ease-out);
}

.tpm-close:hover {
    background: oklch(0.96 0.005 250);
    color: var(--editor-text, oklch(0.22 0.02 250));
}

.tpm-close:focus-visible {
    outline: 2px solid var(--editor-accent, oklch(0.55 0.18 240));
    outline-offset: 2px;
}

/* ── Viewport ── */
.tpm-viewport {
    flex: 1 1 auto;
    overflow: auto;
    background:
        radial-gradient(circle at 50% 0%, oklch(0.94 0.01 250) 0%, transparent 60%),
        var(--editor-bg, oklch(0.97 0.01 250));
    padding: 28px 24px 48px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

/* ── Frame (the device-sized container holding the demo) ── */
.tpm-frame {
    position: relative;
    background: var(--editor-surface-raised, oklch(1 0 0));
    box-shadow:
        0 1px 1px oklch(0.20 0.02 250 / 0.06),
        0 8px 24px oklch(0.20 0.02 250 / 0.10),
        0 24px 64px oklch(0.20 0.02 250 / 0.06);
    border-radius: 12px;
    overflow: hidden;
    max-width: 100%;
    transition: width 0.28s var(--ease-snappy, cubic-bezier(0.22, 1, 0.36, 1));
    isolation: isolate;
}

.tpm-frame--mobile,
.tpm-frame--tablet {
    border-radius: 22px;
    border: 1px solid var(--editor-border, oklch(0.92 0.01 250));
}

.tpm-guard {
    width: 100%;
    min-height: 100%;
    /* The .tpv-scope inside also applies inline color/font-family from
       previewStyleFromAppearance, so the demo content picks up its theme
       from the scope wrapper, not from this guard. */
}

/* Suppress all animations inside the demo (same trade-off used by the
   miniature live preview): keeps perf predictable while switching devices. */
.tpm-guard,
.tpm-guard * {
    animation-duration: 0s !important;
    animation-delay: 0s !important;
    transition-duration: 0s !important;
    transition-delay: 0s !important;
}

/* Keep anchor styling natural (cursor: pointer) so hover feedback works, but
   visually hint that activation is disabled inside the modal. */
.tpm-guard a,
.tpm-guard button {
    cursor: default !important;
}

/* ── Empty / error state ── */
.tpm-error {
    padding: 48px 24px;
    text-align: center;
    font-family: 'Outfit', sans-serif;
    font-size: 0.92rem;
    color: var(--editor-text-muted, oklch(0.50 0.02 250));
}

/* ── Responsive: small viewports ── */
@media (max-width: 960px) {
    .tpm-header {
        grid-template-columns: 1fr auto;
        grid-template-rows: auto auto;
        gap: 10px 16px;
        padding: 12px 16px;
    }
    .tpm-header__left {
        grid-column: 1;
        grid-row: 1;
    }
    .tpm-header__right {
        grid-column: 2;
        grid-row: 1;
    }
    .tpm-header__center {
        grid-column: 1 / -1;
        grid-row: 2;
        justify-self: center;
    }
    .tpm-subtitle {
        display: none;
    }
    .tpm-viewport {
        padding: 16px 12px 32px;
    }
}

@media (max-width: 520px) {
    .tpm-device__label {
        display: none;
    }
    .tpm-device {
        padding: 7px 10px;
    }
    .tpm-use {
        padding: 9px 12px;
        font-size: 0.78rem;
    }
}

/* Full-width service compositions keep their content inside narrow previews. */
:is(.cv-section-flow,.cv-section-free) .catsec__services:is(.catsec__services--accordion-rich,.catsec__services--process-flow,.catsec__services--tabs-horizontal,.catsec__services--bento-icons,.catsec__services--icon-grid) :is(.catsec__services-grid,.catsec__service-card,.catsec__service-body) {
  min-width: 0;
  max-width: 100%;
}
:is(.cv-section-flow,.cv-section-free) .catsec__services--accordion-rich .catsec__services-grid {
  max-width: none;
}
:is(.cv-section-flow,.cv-section-free) .catsec__services--accordion-rich .catsec__service-card {
  grid-template-columns: minmax(0,2fr) minmax(0,3fr);
}
:is(.cv-section-flow,.cv-section-free) .catsec__services--accordion-rich .catsec__service-footer {
  grid-column: 2;
}
:is(.cv-section-flow,.cv-section-free) .catsec__services--process-flow .catsec__services-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit,minmax(min(100%,240px),1fr));
  overflow: visible;
}
:is(.cv-section-flow,.cv-section-free) .catsec__services--tabs-horizontal .catsec__service-card {
  flex: 1 1 240px;
  border-bottom-color: var(--primary);
}
:is(.cv-section-flow,.cv-section-free) .catsec__services--icon-grid .catsec__services-grid {
  grid-template-columns: repeat(auto-fit,minmax(min(100%,180px),1fr)) !important;
}
:is(.cv-section-flow,.cv-section-free) .catsec__services:is(.catsec__services--accordion-rich,.catsec__services--process-flow,.catsec__services--tabs-horizontal,.catsec__services--bento-icons,.catsec__services--icon-grid) :is(.catsec__service-name,.catsec__service-desc) {
  overflow-wrap: anywhere;
}
:is(.cv-section-flow,.cv-section-free) .catsec__services:is(.catsec__services--accordion-rich,.catsec__services--process-flow,.catsec__services--tabs-horizontal,.catsec__services--bento-icons,.catsec__services--icon-grid) .catsec__service-img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  aspect-ratio: 8 / 5;
  object-fit: cover;
}
@container catalog-section (max-width: 540px) {
  :is(.cv-section-flow,.cv-section-free) .catsec__services--accordion-rich .catsec__service-card {
    grid-template-columns: minmax(0,1fr);
  }
  :is(.cv-section-flow,.cv-section-free) .catsec__services--accordion-rich .catsec__service-footer {
    grid-column: auto;
  }
}

/* Use the hero's own contrast tokens instead of compounding muted opacity.
   Inline colors from edited objects still take precedence over these rules. */
.cv-section-flow .catsec__hero .catsec__hero-desc {
  color: var(--hero-title-color, var(--text-primary, #111));
  opacity: 1;
}
.cv-section-flow .catsec__hero--editorial-split {
  background: var(--hero-surface, var(--surface, #fff)) !important;
}
