/* 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: 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: 1px solid var(--ply-border);
    border-radius: 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: 1px solid var(--ply-border);
}

/* ========== Playlist Layout: Bottom ========== */
.bwa-plyr--playlist.bwa-plyr--playlist-bottom {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--ply-border);
    border-radius: 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: 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: 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: 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: 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: 8px;
}

/* ========== Source Type Icons ========== */
.bwa-plyr__playlist-item-type {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 1px 6px;
    border-radius: 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: 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: 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: 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. */
/* When the snippet is rendering, neutralize the chrome wrappers so the
   snippet renders without the black rounded video frame around it. We
   keep .bwa-plyr's own max-width (800/1200) so the snippet is sized
   reasonably; if you need a wider snippet, set max-width on .bwa-plyr
   per-instance or wrap the page section with a wider page-builder cap. */
.bwa-plyr__media-container:has(.bwa-plyr__overlay--visible) {
    background: transparent;
    overflow: visible;
    border-radius: 0;
}
.bwa-plyr__player-area:has(.bwa-plyr__overlay--visible) {
    background: transparent;
    overflow: visible;
    border-radius: 0;
}

.bwa-plyr__overlay {
    cursor: pointer;
    display: none;
}

.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 */
}
