/* Grid Layout System for Video Player */

.video-grid {
    display: grid;
    gap: var(--video-gap, 1rem);
    padding: 1rem 2rem;
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    /* Fill remaining height in flex container */
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* 1 video: Full width */
.video-grid.grid-1x1 {
    grid-template-columns: 1fr;
}

/* 2 videos: Horizontal 2×1 */
.video-grid.grid-2x1 {
    grid-template-columns: repeat(2, 1fr);
}

/* 3 videos: Horizontal 3×1 */
.video-grid.grid-3x1 {
    grid-template-columns: repeat(3, 1fr);
}

/* 4 videos: 2×2 grid */
.video-grid.grid-2x2 {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
}

/* 4 videos: Horizontal 4×1 */
.video-grid.grid-4x1 {
    grid-template-columns: repeat(4, 1fr);
}

/* 4 videos: Vertical 1×4 */
.video-grid.grid-1x4 {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(4, 1fr);
}

/* 5 videos: Auto layout */
.video-grid.grid-5-auto {
    grid-template-columns: repeat(3, 1fr);
    grid-auto-rows: 1fr;
}

/* 6 videos: 3×2 grid */
.video-grid.grid-3x2 {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 1fr);
}

/* 6 videos: 2×3 grid */
.video-grid.grid-2x3 {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(3, 1fr);
}

/* 7 videos: Auto layout (3+4) */
.video-grid.grid-7-auto {
    grid-template-columns: repeat(4, 1fr);
    grid-auto-rows: 1fr;
}

/* 8 videos: 4×2 grid */
.video-grid.grid-4x2 {
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(2, 1fr);
}

/* 9 videos: 3×3 grid */
.video-grid.grid-3x3 {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
}

/* Video Player Container — flex column card */
.video-player {
    display: flex;
    flex-direction: column;
    position: relative;
    background-color: var(--bg-secondary);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transition: box-shadow 0.2s;
}

.video-player:hover {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

/* Platform-colored top accent line */
.video-player[data-platform="youtube"] { border-top: 2px solid rgba(255, 0, 0, 0.65); }
.video-player[data-platform="twitch"]  { border-top: 2px solid rgba(145, 71, 255, 0.7); }
.video-player[data-platform="kick"]    { border-top: 2px solid rgba(83, 252, 31, 0.6); }

/* Persistent header bar */
.vp-header {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0 0.5rem;
    height: 30px;
    min-height: 30px;
    flex-shrink: 0;
    background: rgba(0, 0, 0, 0.55);
    font-size: 0.72rem;
    overflow: hidden;
    cursor: grab;
    user-select: none;
}

.vp-header:active { cursor: grabbing; }

.vp-title {
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.78);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
    cursor: text;
}

.vp-remove-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.4);
    cursor: pointer;
    font-size: 17px;
    line-height: 1;
    padding: 0 2px;
    flex-shrink: 0;
    transition: color 0.15s;
}

.vp-remove-btn:hover { color: rgba(220, 38, 38, 0.95); }

/* Persistent footer bar */
.vp-footer {
    display: flex;
    align-items: center;
    padding: 0 0.5rem;
    height: 22px;
    min-height: 22px;
    flex-shrink: 0;
    background: rgba(0, 0, 0, 0.4);
    overflow: hidden;
}

.vp-footer-text {
    font-size: 0.68rem;
    color: rgba(255, 255, 255, 0.35);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Drag Bar - Full width at top of video */
.drag-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 28px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0 0.5rem;
    cursor: grab;
    user-select: none;
    z-index: 10;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    font-size: 0.72rem;
    opacity: 0;
    transition: opacity 0.2s;
    overflow: hidden;
}

.video-player:hover .drag-bar {
    opacity: 1;
}

.drag-bar:active {
    cursor: grabbing;
}

.drag-icon {
    font-size: 14px;
    color: rgba(255,255,255,0.5);
    flex-shrink: 0;
    letter-spacing: -1px;
}

/* Platform badge inside drag bar */
.drag-platform-badge {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 1px 5px;
    border-radius: 3px;
    flex-shrink: 0;
    text-transform: uppercase;
}

.drag-badge-youtube {
    background: rgba(255, 0, 0, 0.25);
    color: #ff6666;
    border: 1px solid rgba(255, 0, 0, 0.35);
}

.drag-badge-twitch {
    background: rgba(145, 71, 255, 0.25);
    color: #b688ff;
    border: 1px solid rgba(145, 71, 255, 0.4);
}

.drag-badge-kick {
    background: rgba(83, 252, 31, 0.15);
    color: #53fc1f;
    border: 1px solid rgba(83, 252, 31, 0.3);
}

.drag-label {
    font-size: 0.72rem;
    color: rgba(255,255,255,0.7);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

/* Sticky board: always show drag bar, with platform-colored accent */
.video-grid.sticky-board-mode .video-player .drag-bar {
    opacity: 1;
    background: rgba(0, 0, 0, 0.75);
    border-top: 2px solid rgba(255, 255, 255, 0.08);
}

.video-grid.sticky-board-mode .video-player[data-platform="twitch"] .drag-bar {
    border-top-color: rgba(145, 71, 255, 0.6);
}

.video-grid.sticky-board-mode .video-player[data-platform="kick"] .drag-bar {
    border-top-color: rgba(83, 252, 31, 0.5);
}

.video-grid.sticky-board-mode .video-player[data-platform="youtube"] .drag-bar {
    border-top-color: rgba(255, 0, 0, 0.5);
}

/* Drop Target Visual Feedback */
.video-player.drop-target {
    border: 3px solid #1976d2;
    transform: scale(1.02);
    box-shadow: 0 0 20px rgba(25, 118, 210, 0.6);
    z-index: 20;
}

/* Free Layout Mode */
.video-grid.free-layout {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 1rem;
}

.video-grid.free-layout .video-player {
    flex: 0 0 auto;
    width: 400px;
    height: auto;
}

/* Sticky Board Mode */
.video-grid.sticky-board-mode {
    position: relative;
    z-index: 0; /* Creates a stacking context that traps video players + iframes below control-panel's z-index: 100 */
    display: block;
    background-image:
        linear-gradient(rgba(128, 128, 128, 0.1) 1px, transparent 1px),
        linear-gradient(90deg, rgba(128, 128, 128, 0.1) 1px, transparent 1px);
    background-size: 50px 50px;
    overflow: hidden;
}

.video-grid.sticky-board-mode .video-player {
    position: absolute;
    width: 400px;
    cursor: move;
}

.video-grid.sticky-board-mode .video-player .drag-bar {
    opacity: 1;
    background: rgba(0, 0, 0, 0.78);
}

.video-grid.sticky-board-mode .video-player .drag-bar:hover {
    background: rgba(0, 0, 0, 0.88);
}

/* Resize Handle */
.resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 24px;
    height: 24px;
    background-color: rgba(25, 118, 210, 0.8);
    color: white;
    cursor: nwse-resize;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    border-top-left-radius: 4px;
    z-index: 15;
    user-select: none;
}

.video-grid.sticky-board-mode .resize-handle {
    display: flex;
}

.resize-handle:hover {
    background-color: rgba(25, 118, 210, 1);
}

/* Player wrapper — fills space between vp-header and vp-footer */
.player-wrapper {
    flex: 1;
    position: relative;
    min-height: 0;
    overflow: hidden;
    background-color: #000;
}

.player-wrapper .youtube-iframe,
.player-wrapper iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

/* In grid mode, video player fills its grid cell completely */
.video-grid:not(.sticky-board-mode) .video-player {
    height: 100%;
}

/* In sticky board mode, maintain 16:9 aspect ratio based on card width */
.video-grid.sticky-board-mode .player-wrapper {
    flex: initial;
    aspect-ratio: 16 / 9;
    width: 100%;
}

/* Video Fade-In Animation */
@keyframes videoFadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.video-player {
    animation: videoFadeIn 0.3s ease;
}

/* Playback State Badge */
.playback-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    z-index: 15;
    pointer-events: none;
    transition: background-color 0.3s;
}

.playback-badge.badge-playing {
    background-color: #4caf50;
    box-shadow: 0 0 6px rgba(76, 175, 80, 0.8);
}

.playback-badge.badge-buffering {
    background-color: #ff9800;
    animation: pulseBadge 1s infinite;
}

@keyframes pulseBadge {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.playback-badge.badge-paused {
    background-color: #9e9e9e;
}

.playback-badge.badge-idle {
    display: none;
}

/* Video Error Overlay */
.video-error-overlay {
    position: absolute;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 5;
    gap: 0.5rem;
    padding: 1rem;
}

.video-error-icon {
    font-size: 2rem;
}

.video-error-text {
    color: #ef5350;
    font-size: 0.875rem;
    font-weight: 600;
    text-align: center;
}

/* Video Info Overlay (title/label) */
.video-info-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.5rem 0.75rem;
    background: linear-gradient(to top, rgba(0,0,0,0.75), transparent);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 12;
    pointer-events: none;
}

.video-info-overlay--empty {
    background: transparent;
    justify-content: flex-end;
    pointer-events: none;
}

.video-player:hover .video-info-overlay {
    opacity: 1;
    pointer-events: auto;
}

.video-info-text {
    color: white;
    font-size: 0.8rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

.label-edit-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    border-radius: 4px;
    padding: 2px 5px;
    cursor: pointer;
    font-size: 0.75rem;
    color: white;
    flex-shrink: 0;
    transition: background 0.2s;
}

.label-edit-btn:hover {
    background: rgba(255,255,255,0.4);
}

.label-input {
    flex: 1;
    background: rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.4);
    border-radius: 4px;
    color: white;
    font-size: 0.8rem;
    padding: 2px 6px;
    outline: none;
}

.label-input:focus {
    border-color: rgba(25, 118, 210, 0.8);
}

/* Video Controls */
.video-controls {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 10;
}

.video-controls .remove-button {
    background-color: rgba(220, 38, 38, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.video-controls .remove-button:hover {
    background-color: rgba(220, 38, 38, 1);
    transform: scale(1.1);
}

/* Empty State */
.empty-state {
    padding: 4rem 2rem;
    text-align: center;
}

.empty-state-content {
    max-width: 400px;
    margin: 0 auto;
}

.empty-state svg {
    color: var(--text-secondary);
    opacity: 0.5;
    margin-bottom: 1rem;
}

.empty-state h2 {
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.empty-state p {
    color: var(--text-secondary);
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.example-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    margin: 1rem 0;
}

.example-pill {
    padding: 0.4rem 0.9rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 500;
    border: 1.5px solid;
    cursor: pointer;
    background: transparent;
    transition: background 0.2s, transform 0.1s;
}

.example-pill:hover {
    transform: translateY(-1px);
}

.example-pill.example-yt {
    color: #ff6666;
    border-color: rgba(255, 0, 0, 0.35);
}

.example-pill.example-yt:hover {
    background: rgba(255, 0, 0, 0.1);
}

.example-pill.example-tw {
    color: #b688ff;
    border-color: rgba(145, 71, 255, 0.4);
}

.example-pill.example-tw:hover {
    background: rgba(145, 71, 255, 0.1);
}

.example-pill.example-kk {
    color: #53fc1f;
    border-color: rgba(83, 252, 31, 0.3);
}

.example-pill.example-kk:hover {
    background: rgba(83, 252, 31, 0.08);
}

.empty-tip {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

/* Responsive: Stack on mobile */
@media (max-width: 768px) {
    .video-grid.grid-2x1,
    .video-grid.grid-3x1,
    .video-grid.grid-2x2,
    .video-grid.grid-4x1,
    .video-grid.grid-5-auto,
    .video-grid.grid-3x2,
    .video-grid.grid-2x3,
    .video-grid.grid-7-auto,
    .video-grid.grid-4x2,
    .video-grid.grid-3x3 {
        grid-template-columns: 1fr !important;
        grid-template-rows: auto !important;
    }

    .video-grid {
        padding: 0.5rem;
        gap: 0.5rem;
    }
}

@media (max-width: 480px) {
    .video-grid {
        padding: 0.25rem;
        gap: 0.25rem;
    }
}
