/* ── CVH — Frontend v3.2 ── */

.cvh-hero-section {
    box-sizing: border-box;
    contain: layout style paint;
}
.cvh-hero-section > div,
.cvh-hero-section > picture,
.cvh-hero-section > video,
.cvh-hero-section > img,
.cvh-hero-section > button,
.cvh-hero-section .cvh-layer,
.cvh-hero-section .cvh-layer > div,
.cvh-hero-section .cvh-layer img,
.cvh-hero-section .cvh-layer picture,
.cvh-hero-section .cvh-layer a {
    box-sizing: border-box;
}

/*
 * isolation:isolate on #cvh-outer-X creates a stacking context without
 * assigning a z-index, so the hero group stays below themed nav (z:100+).
 *
 * Theme compatibility: the hero's stacking context (isolation:isolate)
 * ensures all hero z-indices are scoped. If your theme's header appears
 * behind the hero, add z-index:100 to your header element in your theme CSS.
 * CVH no longer forces z-index on theme selectors to avoid side effects.
 */

/* Full-width breakout */
.cvh-full-width {
    width: 100vw !important;
    max-width: 100vw !important;
}

[id$="-outer"]:has(.cvh-full-width) {
    width: 100vw !important;
    max-width: 100vw !important;
    position: relative !important;
    left: 50% !important;
    margin-left: -50vw !important;
    margin-right: -50vw !important;
}

/* Background media — never interactive */
.cvh-placeholder,
.cvh-video {
    pointer-events: none !important;
    -webkit-user-select: none;
    user-select: none;
}

/* Layers */
.cvh-layer {
    pointer-events: none;
}
.cvh-layer a,
.cvh-layer button,
.cvh-layer input,
.cvh-layer select,
.cvh-layer textarea,
.cvh-layer [role="button"],
.cvh-layer [tabindex] {
    pointer-events: auto;
}

/* Tint: uses rgba() background — no CSS opacity needed */
.cvh-tint {
    pointer-events: none !important;
    -webkit-user-select: none;
    user-select: none;
}

/* CDN image layers */
.cvh-layer img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* ── Play button overlay ── */
.cvh-play-btn {
    /* Reset browser button styles */
    background: rgba(0, 0, 0, 0.45);
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
    /* Visual */
    width: 64px;
    height: 64px;
    border-radius: 50%;
    color: #fff;          /* SVG polygon uses currentColor */
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.15s ease;
    pointer-events: auto;
}
/* SVG inside play button: inherits color, no-shrink */
.cvh-play-btn svg {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    margin-left: 3px; /* optical centering for play triangle */
}

.cvh-play-btn:hover,
.cvh-play-btn:focus-visible {
    background: rgba(0, 0, 0, 0.65);
    transform: scale(1.1);
    outline: 2px solid rgba(255,255,255,0.6);
    outline-offset: 3px;
}

.cvh-play-btn:active {
    transform: scale(0.95);
}

/* When section has play mode, cursor is pointer */
.cvh-has-playbtn {
    cursor: pointer;
}

/* Responsive — smaller button on mobile */
@media (max-width: 480px) {
    .cvh-play-btn {
        width: 48px;
        height: 48px;
    }
    .cvh-play-btn svg {
        width: 22px;
        height: 22px;
    }
}

/* ── Blur overlay (z:6) ── */
/*
 * State-driven: the section gets data-playing="0" | "1" from JS.
 * Everything visual is CSS — JS only flips the attribute.
 *
 * The blur amount comes from a CSS custom property `--cvh-blur-px` set
 * inline on the section per-hero. Browsers without backdrop-filter
 * (Firefox < 103, old Android Chrome) get a darkened rgba fallback
 * via @supports — no JS feature detection needed.
 */
.cvh-blur-overlay {
    transition: opacity 0.35s ease;
    opacity: 1;                       /* starts visible — section is data-playing="0" and not yet played */
    will-change: opacity;
    pointer-events: none !important;
    -webkit-user-select: none;
    user-select: none;
    /* Read the per-hero blur amount from the section's CSS variable. */
    -webkit-backdrop-filter: blur(var(--cvh-blur-px, 0px));
            backdrop-filter: blur(var(--cvh-blur-px, 0px));
}

/* While the video is playing → hide the blur overlay. */
.cvh-hero-section[data-playing="1"] .cvh-blur-overlay {
    opacity: 0;
}

/* After the video has played at least once AND blur-restore is NOT enabled:
   keep the blur hidden even on pause. This matches the typical ambient-hero
   behavior where users don't want the blur to flash back when the video loops
   or pauses briefly. When data-blur-restore="1" is set on the section, this
   rule does not match, so blur naturally returns on pause via data-playing="0". */
.cvh-hero-section[data-played-once="1"]:not([data-blur-restore="1"]) .cvh-blur-overlay {
    opacity: 0;
}

/* Fallback for browsers without backdrop-filter — replaced rgba background.
   The fallback intensity is computed from --cvh-blur-px so heroes with
   stronger blur get a darker overlay. Min 0, max ~0.55. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .cvh-blur-overlay {
        background: rgba(0, 0, 0, calc(min(0.55, var(--cvh-blur-px, 0) / 36)));
    }
}

/* ─────────────────────────────────────────────────────
   Responsive play button tweaks
   On very small viewports, keep the button accessible
───────────────────────────────────────────────────── */
@media (max-width: 360px) {
    .cvh-play-btn {
        width: 44px;
        height: 44px;
    }
    .cvh-play-btn svg {
        width: 18px;
        height: 18px;
    }
}

/* ── Poster placeholder fade on play (z:1) ── */
/*
 * When the video starts playing, the placeholder fades out and disappears.
 * Once the video has played at least once, the placeholder stays hidden —
 * matches the previous JS behavior of `display:none` on first `playing`.
 *
 * Using visibility:hidden (not display:none) preserves the element so JS in
 * play-mode heroes can still restore it imperatively when the user pauses
 * and the play button needs the placeholder visible again.
 */
.cvh-placeholder {
    transition: opacity 0.4s ease, visibility 0s linear 0.4s;
    opacity: 1;
    visibility: visible;
}
/* While playing → fade out. */
.cvh-hero-section[data-playing="1"] .cvh-placeholder {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s ease, visibility 0s linear 0.4s;
}
/* After first play, for autoplay heroes (no play button) → stay hidden.
   Play-mode heroes (.cvh-has-playbtn) get imperative restoration via JS
   so we exclude them — they need the placeholder visible when paused. */
.cvh-hero-section[data-played-once="1"]:not(.cvh-has-playbtn) .cvh-placeholder {
    opacity: 0;
    visibility: hidden;
}

/* ── Poster blur (loading state) ── */
/*
 * Applied via class when "Blur Placeholder" is enabled. The blur amount comes
 * from --cvh-poster-blur-px on the placeholder element (set inline per-hero).
 * Pure CSS — no inline filter/transform, no JS reset.
 */
.cvh-poster-blur {
    filter: blur(var(--cvh-poster-blur-px, 0px));
    transform: scale(1.04);
    transition: filter 0.4s ease, transform 0.4s ease, opacity 0.4s ease, visibility 0s linear 0.4s;
}
.cvh-hero-section[data-playing="1"] .cvh-poster-blur {
    filter: none;
    transform: none;
}

/* ── CVH Layer Button ── */
.cvh-layer-btn {
    /* hover handled via opacity + slight lift */
}
.cvh-layer-btn:hover,
.cvh-layer-btn:focus-visible {
    opacity: .85;
    transform: translateY(-2px);
    outline: 3px solid rgba(255,255,255,.5);
    outline-offset: 2px;
}
.cvh-layer-btn:active {
    transform: translateY(0);
    opacity: .7;
}

/* Dark + outline_dark buttons: dark outline on hover */
.cvh-layer-btn-dark:hover,
.cvh-layer-btn-dark:focus-visible,
.cvh-layer-btn-outline_dark:hover,
.cvh-layer-btn-outline_dark:focus-visible {
    outline-color: rgba(0,0,0,.3);
}

/* Glass button: brighter on hover */
.cvh-layer-btn-glass:hover,
.cvh-layer-btn-glass:focus-visible {
    background: rgba(255,255,255,.22) !important;
    outline-color: rgba(255,255,255,.4);
}

/* Gradient button: slight glow */
.cvh-layer-btn-gradient:hover,
.cvh-layer-btn-gradient:focus-visible {
    box-shadow: 0 4px 20px rgba(102,126,234,.4);
    outline-color: rgba(255,255,255,.4);
}

/* ═══════════════════════════════════════════════════════════
   DEBUG OVERLAY  (z:999 — always on top within the hero)
   Only rendered for logged-in admin users or when
   localStorage.cvhDebug='1'. Never visible to front-end
   visitors unless they explicitly activate it.
═══════════════════════════════════════════════════════════ */

/* Toggle button — floating in top-right of the hero */
.cvh-debug-btn {
    position: absolute;
    top: 10px; right: 10px;
    z-index: 999;
    padding: 4px 10px;
    background: rgba(0,0,0,0.65);
    color: #7affb2;
    border: 1px solid rgba(122,255,178,0.4);
    border-radius: 4px;
    font: 600 11px/1 monospace;
    cursor: pointer;
    pointer-events: auto;
    transition: background 0.15s;
    letter-spacing: .04em;
}
.cvh-debug-btn:hover,
.cvh-debug-btn.active {
    background: rgba(20,20,20,0.9);
    border-color: #7affb2;
}

/* Full-hero debug panel */
.cvh-debug-panel {
    position: absolute;
    inset: 0;
    z-index: 999;
    background: rgba(0, 0, 0, 0.88);
    color: #e8e8e8;
    overflow-y: auto;
    padding: 0 0 12px;
    pointer-events: auto;
    font: 12px/1.5 monospace;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* Header bar */
.cvh-dbg-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: rgba(122,255,178,0.12);
    border-bottom: 1px solid rgba(122,255,178,0.25);
    position: sticky;
    top: 0;
    z-index: 1;
}
.cvh-dbg-title {
    color: #7affb2;
    font-weight: 700;
    font-size: 12px;
    letter-spacing: .03em;
}
.cvh-dbg-close {
    background: none;
    border: none;
    color: #aaa;
    font-size: 16px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}
.cvh-dbg-close:hover { color: #fff; }

/* Data table */
.cvh-dbg-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
    table-layout: fixed;
}
.cvh-dbg-table th {
    text-align: left;
    padding: 8px 14px 4px;
    color: #7affb2;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .06em;
    border-top: 1px solid rgba(255,255,255,0.08);
}
.cvh-dbg-table td {
    padding: 3px 14px;
    vertical-align: top;
    word-break: break-all;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}
.cvh-dbg-table td:first-child {
    color: #aaa;
    width: 120px;
    white-space: nowrap;
    word-break: normal;
}
.cvh-dbg-table a {
    color: #6bbdff;
    text-decoration: none;
}
.cvh-dbg-table a:hover { text-decoration: underline; }

/* Active breakpoint highlight */
.cvh-dbg-active-bp td { background: rgba(122,255,178,0.08); }
.cvh-dbg-active-bp td:first-child { color: #7affb2; font-weight: 700; }

/* Source labels */
.cvh-dbg-local { color: #7affb2; font-size: 10px; font-weight: 700; }
.cvh-dbg-cld   { color: #f5a623; font-size: 10px; }

/* ── Accessibility: prefers-reduced-motion ────────────────
   Autoplay ambient videos are paused, transitions shortened.
   Users who requested reduced motion shouldn't see auto-
   playing background videos. JS checks this at runtime too,
   but the CSS rule acts as an instant guard before JS loads. */
@media (prefers-reduced-motion: reduce) {
    .cvh-video[autoplay] {
        /* Pause via animation-play-state — actual pause happens in JS */
        animation-play-state: paused;
    }
    .cvh-placeholder,
    .cvh-blur-overlay,
    .cvh-play-btn,
    .cvh-layer {
        transition: none !important;
        animation: none !important;
    }
}

/* ── Print: show poster, hide video ──────────────────────── */
@media print {
    .cvh-video { display: none !important; }
    .cvh-placeholder { position: static !important; width: 100% !important; height: auto !important; }
    .cvh-hero-section { min-height: unset !important; }
}
