/* BWA Plyr Media Player Module */

/* Brand wiring. Each role resolves into a distinct local var (--ply-*) so
   there is NO self-reference cycle — note the corpus emits --bwa-plyr-* at
   :root, so we must NEVER name a local var --bwa-plyr-*. Resolution order:
   1. recolor token (--bg/--text/--accent/...) injected by the stan AI Assist
      agent on this root class — wins when an editor recolors.
   2. inherited --bwa-plyr-* emitted at :root by BrandCorpusController from this
      plugin's manifest brandInheritance (folder slug = "plyr").
   3. the literal fallback — the player's original default.
   For this media player the brand color is the ACCENT (active playlist item +
   Plyr's own --plyr-color-main control highlight). Player chrome / playlist
   surfaces stay light and the video stage is black for legibility. */
/* ========== Player Wrapper ========== */
.bwa-plyr {
    --ply-bg:         var(--bg,         var(--bwa-plyr-bg, #ffffff));
    --ply-text:       var(--text,       var(--bwa-plyr-text, #1e293b));
    --ply-accent:     var(--accent,     var(--bwa-plyr-accent, #00b3ff));
    --ply-link:       var(--link,       var(--bwa-plyr-link, var(--ply-accent)));
    --ply-link-hover: var(--link-hover, var(--bwa-plyr-link-hover, color-mix(in srgb, var(--ply-accent) 82%, #000)));
    --ply-accent-ink: #ffffff;
    --ply-accent-faint: color-mix(in srgb, var(--ply-accent) 12%, var(--ply-bg));
    --ply-muted:      color-mix(in srgb, var(--ply-text) 62%, transparent);
    --ply-faint:      color-mix(in srgb, var(--ply-text) 45%, transparent);
    --ply-border:     color-mix(in srgb, var(--ply-text) 14%, transparent);
    --ply-surface-2:  color-mix(in srgb, var(--ply-text) 6%, var(--ply-bg));

    max-width: 1200px;
    margin: 0 auto;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.5;
    color: var(--ply-text);
}

.bwa-plyr--single {
    max-width: 800px;
}

/* (No --deferred class needed — overlay flows naturally inside .bwa-plyr's
   default 800/1200 cap, snippet self-sizes within that.) */

.bwa-plyr__empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--ply-muted);
    font-size: 14px;
}

/* ========== Player Area ========== */
.bwa-plyr__player-area {
    background: #000;
    border-radius: 8px 8px 0 0;
    overflow: hidden;
}

.bwa-plyr--single .bwa-plyr__player-area {
    border-radius: var(--bwa-radius-md, 8px);
}

.bwa-plyr__media-container {
    position: relative;
    width: 100%;
}

.bwa-plyr__media-container video,
.bwa-plyr__media-container audio {
    width: 100%;
    display: block;
}

/* ========== Playlist Layout: Right ========== */
.bwa-plyr--playlist.bwa-plyr--playlist-right {
    display: flex;
    flex-direction: row;
    border: var(--bwa-border-width, 1px) solid var(--ply-border);
    border-radius: var(--bwa-radius-md, 8px);
    overflow: hidden;
}

.bwa-plyr--playlist.bwa-plyr--playlist-right .bwa-plyr__player-area {
    flex: 1;
    min-width: 0;
    border-radius: 0;
}

.bwa-plyr--playlist.bwa-plyr--playlist-right .bwa-plyr__playlist {
    width: 340px;
    flex-shrink: 0;
    border-left: var(--bwa-border-width, 1px) solid var(--ply-border);
}

/* ========== Playlist Layout: Bottom ========== */
.bwa-plyr--playlist.bwa-plyr--playlist-bottom {
    display: flex;
    flex-direction: column;
    border: var(--bwa-border-width, 1px) solid var(--ply-border);
    border-radius: var(--bwa-radius-md, 8px);
    overflow: hidden;
}

.bwa-plyr--playlist.bwa-plyr--playlist-bottom .bwa-plyr__player-area {
    border-radius: 0;
}

.bwa-plyr--playlist.bwa-plyr--playlist-bottom .bwa-plyr__playlist {
    border-top: var(--bwa-border-width, 1px) solid var(--ply-border);
}

/* ========== Playlist Container ========== */
.bwa-plyr__playlist {
    background: var(--ply-bg);
    display: flex;
    flex-direction: column;
    max-height: 500px;
}

.bwa-plyr__playlist-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: var(--bwa-border-width, 1px) solid var(--ply-border);
    background: var(--ply-surface-2);
    flex-shrink: 0;
}

.bwa-plyr__playlist-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--ply-text);
}

.bwa-plyr__playlist-count {
    font-size: 12px;
    color: var(--ply-muted);
}

.bwa-plyr__playlist-items {
    overflow-y: auto;
    flex: 1;
}

/* ========== Playlist Item ========== */
.bwa-plyr__playlist-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    cursor: pointer;
    border-bottom: var(--bwa-border-width, 1px) solid var(--ply-border);
    transition: background-color 0.15s ease;
}

.bwa-plyr__playlist-item:last-child {
    border-bottom: none;
}

.bwa-plyr__playlist-item:hover {
    background: var(--ply-surface-2);
}

.bwa-plyr__playlist-item:focus {
    outline: 2px solid var(--ply-accent);
    outline-offset: -2px;
}

.bwa-plyr__playlist-item--active {
    background: var(--ply-accent-faint);
    border-left: var(--bwa-border-width-thick, 3px) solid var(--ply-accent);
    padding-left: 13px;
}

.bwa-plyr__playlist-item--active:hover {
    background: var(--ply-accent-faint);
}

.bwa-plyr__playlist-item-num {
    font-size: 12px;
    color: var(--ply-muted);
    min-width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.bwa-plyr__playlist-item--active .bwa-plyr__playlist-item-num {
    color: var(--ply-accent);
    font-weight: 600;
}

.bwa-plyr__playlist-item-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.bwa-plyr__playlist-item-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--ply-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bwa-plyr__playlist-item--active .bwa-plyr__playlist-item-title {
    color: var(--ply-accent);
}

.bwa-plyr__playlist-item-meta {
    display: flex;
    align-items: center;
    gap: var(--bwa-space-2, 8px);
}

/* ========== Source Type Icons ========== */
.bwa-plyr__playlist-item-type {
    font-size: 10px;
    font-weight: var(--bwa-label-weight, 600);
    text-transform: var(--bwa-label-transform, uppercase);
    letter-spacing: var(--bwa-label-tracking, 0.05em);
    padding: 1px 6px;
    border-radius: var(--bwa-radius-sm, 3px);
    background: #f1f5f9;
    color: #64748b;
    flex-shrink: 0;
}

.bwa-plyr__playlist-item-type--video {
    background: #dbeafe;
    color: #2563eb;
}

.bwa-plyr__playlist-item-type--audio {
    background: #fce7f3;
    color: #db2777;
}

.bwa-plyr__playlist-item-type--youtube {
    background: #fee2e2;
    color: #dc2626;
}

.bwa-plyr__playlist-item-type--vimeo {
    background: #e0e7ff;
    color: #4f46e5;
}

.bwa-plyr__playlist-item-duration {
    font-size: 11px;
    color: var(--ply-muted);
    flex-shrink: 0;
}

/* ========== Theme Color Override ========== */
/* Feed the brand accent into Plyr's own control-highlight variable so the
   play button, progress fill, and volume track pick up the brand color. */
.bwa-plyr .plyr {
    --plyr-color-main: var(--ply-accent);
}

/* ========== Focus States ========== */
.bwa-plyr__playlist-item:focus-visible {
    outline: 2px solid var(--ply-accent);
    outline-offset: -2px;
}

/* ========== Responsive: Tablet ========== */
@media (max-width: 768px) {
    .bwa-plyr--playlist.bwa-plyr--playlist-right {
        flex-direction: column;
    }

    .bwa-plyr--playlist.bwa-plyr--playlist-right .bwa-plyr__playlist {
        width: 100%;
        border-left: none;
        border-top: var(--bwa-border-width, 1px) solid var(--ply-border);
        max-height: 300px;
    }

    .bwa-plyr__playlist {
        max-height: 300px;
    }
}

/* ========== Responsive: Mobile ========== */
@media (max-width: 480px) {
    .bwa-plyr__playlist-header {
        padding: 10px 12px;
    }

    .bwa-plyr__playlist-item {
        padding: 8px 12px;
        gap: var(--bwa-space-2, 8px);
    }

    .bwa-plyr__playlist-item-title {
        font-size: 12px;
    }

    .bwa-plyr__playlist-item-type {
        font-size: 9px;
        padding: 1px 4px;
    }

    .bwa-plyr__playlist {
        max-height: 250px;
    }
}

/* ========== Audio-specific Styling ========== */
.bwa-plyr__media-container audio {
    background: #1e293b;
}

/* ========== Scrollbar Styling ========== */
.bwa-plyr__playlist-items::-webkit-scrollbar {
    width: 6px;
}

.bwa-plyr__playlist-items::-webkit-scrollbar-track {
    background: var(--ply-surface-2);
}

.bwa-plyr__playlist-items::-webkit-scrollbar-thumb {
    background: var(--ply-border);
    border-radius: var(--bwa-radius-sm, 3px);
}

.bwa-plyr__playlist-items::-webkit-scrollbar-thumb:hover {
    background: var(--ply-faint);
}

/* ========== Pre-Play Overlay ==========
   When the editor provides a pre-play snippet, the snippet self-styles
   (its own width, aspect-ratio, border-radius, layout, etc). Our wrappers
   (.bwa-plyr__player-area, .bwa-plyr__media-container, .bwa-plyr__overlay)
   would otherwise box the snippet inside a black rounded frame and
   constrain its width to 800/1200. We use `display: contents` so those
   wrappers become layout-transparent — the snippet renders as if it's
   a direct child of .bwa-plyr (and therefore of the page container that
   wraps .bwa-plyr).

   .bwa-plyr itself: drop the 800/1200 max-width so the parent page-
   container's content-cap (typically 1600px from the page builder's
   INNER CAP setting) governs — the snippet then respects the page
   container's cap rather than fighting it. */
/* These two rules neutralised the player frame so an in-flow snippet could
   escape it. The overlay now LAYERS over the player instead of replacing it
   (see .bwa-plyr__overlay below), so the frame must stay intact and must keep
   clipping — letting the overlay overflow is what allowed a snippet to spill
   across the page. Only the background is still dropped, so a poster shows
   through a transparent overlay rather than sitting on black. */
.bwa-plyr__media-container:has(.bwa-plyr__overlay--visible) {
    background: transparent;
}
.bwa-plyr__player-area:has(.bwa-plyr__overlay--visible) {
    background: transparent;
}

/* Layered over the player, matching the CarJiffy homepage hero
   (CJPublic/Modules/Banner/Banner.ascx): the video carries the layout and the
   overlay is absolutely positioned on top of it inside the position:relative
   .bwa-plyr__media-container, above Plyr's own chrome. Previously this was an
   in-flow block that REPLACED the player area, which is why it never sat over
   the video. */
.bwa-plyr__overlay {
    cursor: pointer;
    display: none;
    position: absolute;
    inset: 0;
    z-index: 2;
    overflow: hidden;
}

.bwa-plyr__overlay--visible {
    display: block;
}

.bwa-plyr__overlay--hiding {
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

/* Hide Plyr's stock big-play button while the overlay is up so the
   editor's custom CTA inside the overlay is the only visible play affordance. */
.bwa-plyr__media-container:has(.bwa-plyr__overlay--visible:not(.bwa-plyr__overlay--hiding)) .plyr__control--overlaid {
    display: none !important;            /* bwa-allow-important: overlay takes precedence over stock Plyr big-play */
}

/* An inline (fragment) overlay sets the frame's height until play. The snippet
   carries its own proportions - the CarJiffy homepage one is a 3:1 card - and
   sizing the frame from the 16:9 video left a black band under it. While the
   overlay is up it sits in flow and the player is laid behind it at the same
   size; once bwa-plyr.js dismisses and removes it, the player is back in flow at
   its own aspect. A framed (full-document) overlay is an iframe with no
   intrinsic height, so it keeps the video-carries-the-layout model above. */
.bwa-plyr__overlay--visible:not(.bwa-plyr__overlay--framed) {
    position: relative;
}

.bwa-plyr__media-container:has(> .bwa-plyr__overlay--visible:not(.bwa-plyr__overlay--framed)) > .plyr,
.bwa-plyr__media-container:has(> .bwa-plyr__overlay--visible:not(.bwa-plyr__overlay--framed)) > video {
    position: absolute;
    inset: 0;
    height: 100%;
}

/* Full-document overlay (an AI Block / Claude Design bundle inserted into
   Overlay Content). Such a document carries page-global rules — `* {}`,
   `body {}`, fixed full-screen layers — so it is rendered inside a sandboxed
   iframe rather than injected inline, and cannot reach the host page. The
   frame is visual only: clicks inside an iframe never bubble out, so a
   transparent hit layer above it preserves the click-anywhere-to-play
   contract that bwa-plyr.js wires on .bwa-plyr__overlay. */
.bwa-plyr__overlay--framed {
    /* Positioning comes from .bwa-plyr__overlay (absolute, inset 0) so the
       frame fills the player box. Do NOT re-declare position here — setting
       position:relative would take the overlay back out of the layer and put
       it in flow underneath the video. */
    width: auto;
}

.bwa-plyr__overlay-frame {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
}

.bwa-plyr__overlay-hit {
    position: absolute;
    inset: 0;
    cursor: pointer;
}
