/* streaming.css - Specijalizovani CSS za streaming stranice (TV, Cameras) */
/* Ove stilove se učitavaju samo na Media/Tv i Media/Cameras stranicama    */

/* ========== VIDEO ELEMENT OPTIMIZACIJA ========== */

/* Osnovna video konfiguracija sa maksimalnom performansom */

:root {
    --bg: #08111f;
    --card: linear-gradient(135deg, rgba(56, 189, 248, 0.05), rgba(34, 197, 94, 0.03));
    --card-gradient: linear-gradient(135deg, rgba(56, 189, 248, 0.08), rgba(34, 197, 94, 0.08));
    --border: rgba(255, 255, 255, 0.08);
    --text: #e5eefc;
    --muted: #94a3b8;
    --accent: #38bdf8;
    --accent2: #22c55e;
    --badge-success: rgba(34, 197, 94, 0.18); /* zelena */
    --badge-danger: rgba(239, 68, 68, 0.2) !important; /* crvena   --badge-danger: rgba(239, 68, 68, 0.2) !important; */
    --badge-warning: #f59e0b; /* narandžasta/žuta */
    --badge-info: #3b82f6; /* plava */
    --glass: background: linear-gradient(135deg, #08111f 0%, #132033 100%), backdrop-filter: blur(15px);
    --text-danger-emphasis: #dc3545; /* Ili boja po tvom izboru */
    --text-success-emphasis: #198754; /* Za 'GO' badge */
}

video {
    display: block;                          /* Uklanja inline spacing (4-8px) */
    width: 100%;                             /* Responsive */
    height: auto;                            /* Preserve aspect ratio */
    background: #000;                        /* Crna pozadina dok se učitava */
    border-radius: 0.5rem;                   /* Mala zaobljenja */
    backface-visibility: hidden;             /* GPU acceleration - sprečava flickering */
    perspective: 1000;                       /* 3D rendering mode */
    will-change: transform;                  /* Hint za browser da preparation */
    -webkit-user-select: none;               /* Sprečava text selection */
    user-select: none;
}

/* Video sa aspect ratio - sprečava CLS (Cumulative Layout Shift) */
video[data-stream-kind] {
    aspect-ratio: 16 / 9;                    /* Rezerviši prostor pre nego što se video učita */
    object-fit: cover;                       /* Ispuni container bez distorzije */
}

/* ========== TV PLAYER KOMPONENTA ========== */

/* Sticky TV player header - fiksna pozicija sa min-height */
.tv-player-container {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: linear-gradient(180deg, rgba(8, 17, 31, 0.95), rgba(8, 17, 31, 0.85));
    padding: 0.75rem;
    border-bottom: 1px solid rgba(56, 189, 248, 0.2);
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* HLS player placeholder - smooth fade sa GPU acceleration */
.tv-player-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    visibility: visible;                     /* CLS FIX: Koristi visibility umesto opacity */
    transition: visibility 0.3s ease;
    will-change: visibility;
    contain: layout style;                   /* Sprečava reflow */
}

/* CLS FIX: d-none koristi visibility, ne display */
.tv-player-placeholder.d-none {
    visibility: hidden;
    pointer-events: none;                    /* Sprečava interakciju */
    transition: visibility 0.3s ease;
}

.tv-player-placeholder i {
    font-size: 3rem;
    margin-bottom: 1rem;
    color: #38bdf8;
    animation: spin-placeholder 2s linear infinite;
}

@keyframes spin-placeholder {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* CLS FIX: Aspect ratio container sa fixed dimensions */
.video-container {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%;                  /* 16:9 aspect ratio */
    height: 0;
    overflow: hidden;
    background: #000;
    border-radius: 0.5rem;
    contain: layout style;
}

.video-container video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
    background: #000;
    border-radius: 0.5rem;
    backface-visibility: hidden;
    perspective: 1000;
    will-change: transform;
    -webkit-user-select: none;
    user-select: none;
}

/* CLS FIX: Player shell sa aspect ratio */
.tv-player-shell {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;                   /* CLS FIX: Reserve space za video */
    background: #000;
    border-radius: 0.5rem;
    overflow: hidden;
    margin-bottom: 1rem;
    /* FULLSCREEN FIX: Uklonjeno 'contain: layout style' jer blokira fullscreen API */
}

/* TV Player Card - izbegava inline style */
.tv-player-card {
    position: sticky;
    top: 1rem;
    z-index: 999;
}

/* Status badge animacija sa batching */
.tv-player-status {
    display: inline-block;
    min-width: 80px;                        /* CLS FIX: Reserved space */
    min-height: 24px;                       /* CLS FIX: Reserved space */
    padding: 0.375rem 0.75rem;
    border-radius: 0.25rem;
    font-weight: 600;
    font-size: 0.875rem;
    animation: status-pulse 2s ease-in-out infinite;
    will-change: opacity;                    /* GPU batching hint */
    contain: layout style;                   /* Sprečava reflow external */
    line-height: 1;                         /* CLS FIX: Normalize line height */
}

@keyframes status-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.tv-player-status.badge-success {
    background-color: #22c55e;
    color: white;
    animation: none;                         /* Bez pulsiranja kada je OK */
}

.tv-player-status.badge-danger {
    background-color: #ef4444;
    color: white;
    animation: status-pulse 1s ease-in-out infinite;
}

/* Quality selector */
[data-tv-quality-select] {
    min-width: 120px;
    font-size: 0.875rem;
}

/* Channel list kontejner - lazy scroll sa performance */
.tv-channel-list-container {
    max-height: 400px;
    overflow-y: auto;
    scroll-behavior: smooth;                 /* Native smooth scroll */
    -webkit-overflow-scrolling: touch;       /* iOS momentum scroll */
    contain: layout style paint;             /* Sprečava reflow celog DOM-a */
}

/* Channel item buttons - svezan grid layout sa GPU optimizacijom */
.tv-channel-item {
    min-height: 44px;                        /* Apple HCI guideline - touch-friendly */
    transition: all 0.2s ease;
    border: 1px solid rgba(56, 189, 248, 0.1);
    margin-bottom: 0.5rem;
    border-radius: 0.375rem;
    will-change: background-color, border-color;
    contain: layout style;
}

.tv-channel-item:hover {
    border-color: rgba(56, 189, 248, 0.5);
    background-color: rgba(56, 189, 248, 0.05);
}

.tv-channel-item.active {
    background-color: rgba(56, 189, 248, 0.2);
    border-color: #38bdf8;
    box-shadow: inset 0 0 8px rgba(56, 189, 248, 0.1);
}

/* TV grupa (accordion) - smooth expand/collapse */
.tv-group-button {
    width: 100%;
    padding: 0.75rem;
    text-align: left;
    background: linear-gradient(90deg, rgba(56, 189, 248, 0.05), transparent);
    border: 1px solid rgba(56, 189, 248, 0.1);
    border-radius: 0.375rem;
    color: #e5eefc;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.tv-group-button:hover {
    background: linear-gradient(90deg, rgba(56, 189, 248, 0.1), transparent);
    border-color: rgba(56, 189, 248, 0.3);
}

.tv-group-button.active {
    background: linear-gradient(90deg, rgba(56, 189, 248, 0.2), rgba(56, 189, 248, 0.05));
    border-color: #38bdf8;
}

.tv-group-button::after {
    content: '▼';
    float: right;
    font-size: 0.75rem;
    transition: transform 0.2s ease;
}

.tv-group-button.active::after {
    transform: rotate(180deg);
}

.tv-group-panel {
    padding: 1rem 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.5rem;
}

/* ========== CAMERA STREAM KOMPONENTA ========== */

.camera-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.camera-card {
    background: rgba(19, 32, 51, 0.8);
    border: 1px solid rgba(56, 189, 248, 0.1);
    border-radius: 0.5rem;
    overflow: hidden;
    transition: all 0.3s ease;
    will-change: border-color, box-shadow;
}

.camera-card:hover {
    border-color: rgba(56, 189, 248, 0.3);
    box-shadow: 0 8px 24px rgba(56, 189, 248, 0.1);
}

.camera-card video {
    width: 100%;
    display: block;
    background: #000;
    aspect-ratio: 16 / 9;                   /* Sprečava CLS */
    object-fit: cover;
}

/* ========== VIDEO CARD - Kamera grid komponenta ========== */

/* Generic video-card - koristi se za kamere u grid-u */
.video-card {
    background: rgba(19, 32, 51, 0.8);
    border: 1px solid rgba(56, 189, 248, 0.1);
    border-radius: 0.5rem;
    overflow: hidden;
    transition: all 0.3s ease;
    will-change: border-color, box-shadow;
    display: flex;
    flex-direction: column;
    position: relative;
    /* FULLSCREEN FIX: Uklonjeno 'contain: layout style' jer blokira fullscreen */
}

.video-card:hover {
    border-color: rgba(56, 189, 248, 0.3);
    box-shadow: 0 8px 24px rgba(56, 189, 248, 0.1);
}

/* Video element u card-u - CRITICAL: Must allow fullscreen */
.video-card video {
    width: 100%;
    height: auto;
    display: block;
    background: #000;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    will-change: transform;
}

/* Fullscreen video iz card-a - omogući puni ekran */
.video-card video:fullscreen,
.video-card video:-webkit-full-screen,
.video-card video:-moz-full-screen,
.video-card video:-ms-fullscreen {
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw;
    max-height: 100vh;
    object-fit: contain;
    border-radius: 0;
}

.camera-card-footer {
    padding: 0.75rem;
    background: rgba(8, 17, 31, 0.9);
    border-top: 1px solid rgba(56, 189, 248, 0.1);
}

.camera-status {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    margin-right: 0.5rem;
    will-change: background-color;
}

.camera-status.online {
    background-color: #22c55e;
    color: white;
}

.camera-status.offline {
    background-color: #ef4444;
    color: white;
}

.camera-status.loading {
    background-color: #f59e0b;
    color: white;
    animation: pulse-animation 2s ease-in-out infinite;
}

@keyframes pulse-animation {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.camera-retry-button {
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    border-radius: 0.25rem;
    background: transparent;
    border: 1px solid rgba(56, 189, 248, 0.5);
    color: #38bdf8;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.camera-retry-button:hover:not(:disabled) {
    background: rgba(56, 189, 248, 0.1);
    border-color: #38bdf8;
}

.camera-retry-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ========== RESPONSIVE OPTIMIZACIJA ========== */

/* Grid sa kamerama - responsive layout */
.grid[data-camera-max-retries] {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    margin-top: 1rem;
}

@media (max-width: 768px) {
    .grid[data-camera-max-retries] {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 0.75rem;
    }

    .tv-player-container {
        position: relative;
        top: auto;
        padding: 0.5rem;
    }

    .tv-group-panel {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 0.25rem;
    }

    .camera-grid {
        grid-template-columns: 1fr;
    }

    .tv-channel-item {
        min-height: 40px;
        font-size: 0.875rem;
    }

    /* Disable sticky positioning na mobile za manju potrošnju memorije */
    .tv-player-container {
        position: relative;
    }
}

@media (max-width: 480px) {
    .grid[data-camera-max-retries] {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    video {
        border-radius: 0.25rem;
    }

    .tv-player-placeholder {
        padding: 1rem;
    }

    .tv-player-placeholder i {
        font-size: 2rem;
    }
}

/* ========== PERFORMANSA OPTIMIZACIJA ========== */

/* Sprečava reflow/repaint pri vidljivosti promena */
.d-none {
    display: none !important;
}

/* Smooth scroll ponašanje za kanalnu listu */
.tv-channel-list-container {
    contain: layout style paint;
}

/* Hardware-accelerated transformacije */
video {
    backface-visibility: hidden;
    perspective: 1000;
}

/* Minimal repaints za status badge */
.tv-player-status {
    will-change: opacity;
    contain: layout style;
}

/* Optimizacija za light-dom-only browsers */
@supports (backface-visibility: hidden) {
    .tv-player-container {
        contain: layout style;
    }
}

/* ========== FULLSCREEN VIDEO PODRŠKA ========== */

/* Dokumenta u fullscreen modu */
:-webkit-full-screen {
    width: 100% !important;
    height: 100% !important;
}

:fullscreen {
    width: 100% !important;
    height: 100% !important;
}

/* Standard fullscreen API */
video:fullscreen {
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw;
    max-height: 100vh;
    object-fit: contain;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 99999;
}

/* Webkit fullscreen (Safari/Chrome legacy) */
video:-webkit-full-screen {
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw;
    max-height: 100vh;
    object-fit: contain;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 99999;
}

/* Mozilla fullscreen */
video:-moz-full-screen {
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw;
    max-height: 100vh;
    object-fit: contain;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 99999;
}

/* MS Edge fullscreen */
video:-ms-fullscreen {
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw;
    max-height: 100vh;
    object-fit: contain;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 99999;
}

/* Sprečava scroll kada je video u fullscreen */
body:has(video:fullscreen),
body:has(video:-webkit-full-screen),
body:has(video:-moz-full-screen),
body:has(video:-ms-fullscreen) {
    overflow: hidden !important;
    height: 100vh;
    position: fixed;
    width: 100vw;
    top: 0;
    left: 0;
}

/* Osiguraj da grid kontejner ne blokira fullscreen */
.grid:has(video:fullscreen),
.grid:has(video:-webkit-full-screen),
.grid:has(video:-moz-full-screen),
.grid:has(video:-ms-fullscreen) {
    overflow: visible !important;
}

/* Osiguraj da video-card ne blokira fullscreen */
.video-card:has(video:fullscreen),
.video-card:has(video:-webkit-full-screen),
.video-card:has(video:-moz-full-screen),
.video-card:has(video:-ms-fullscreen) {
    overflow: visible !important;
}

/* ========== FULLSCREEN FALLBACK ZA STARIJE BROWSER-E ========== */

/* Ako je video::backdrop dostupan */
video::backdrop {
    background-color: rgba(0, 0, 0, 1);
}

video:-webkit-full-screen::backdrop {
    background-color: rgba(0, 0, 0, 1);
}

/* Alternativni fullscreen selector */
video[allowfullscreen]:fullscreen {
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw;
    max-height: 100vh;
    object-fit: contain;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 99999;
    background: black;
}

/* Safari fullscreen specifičan selector */
@-webkit-keyframes webkit-full-screen {
    0% { width: 100vw; height: 100vh; }
}

/* ========== CAMERA PAGE STYLING ========== */

/* Camera header sa descriptorom */
.camera-header {
}

.camera-card-wrapper {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 1rem;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    height: 100%;
    position: relative;
    isolation: isolate;
}

.camera-card-wrapper > * {
    position: relative;
    z-index: 1;
}

.camera-card-wrapper:hover,
.camera-card-wrapper:focus-within {
    transform: translateY(-3px);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.25);
}

.camera-card-wrapper:hover .camera-video,
.camera-card-wrapper:focus-within .camera-video {
    filter: saturate(1.05) contrast(1.04);
}

/* Camera card header - title i status */
.camera-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.9rem 1rem;
    min-height: 74px;
}

.camera-card-title {
    flex: 1;
}

.camera-card-title h3 {
    font-size: 1.02rem;
    font-weight: 700;
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
    letter-spacing: 0.01em;
}

/* Status badge - mini indikator */
.camera-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.65rem;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 700;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.camera-status-badge.live {
    animation: pulse-live 2s ease-in-out infinite;
}

@keyframes pulse-live {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Video element u card-u */
.camera-video {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    background: #000;
    display: block;
    flex: 1;
    outline: none;
    transition: filter 0.25s ease;
}

/* Placeholder spinner - prikazuje se dok se video učitava */
.camera-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    background: rgba(0, 0, 0, 0.82);
    border-radius: 0.5rem;
    z-index: 5;
    visibility: visible;
    transition: visibility 0.3s ease;
}

.camera-placeholder.d-none {
    visibility: hidden;
    pointer-events: none;
}

.camera-placeholder .spinner-border {
    width: 2.5rem;
    height: 2.5rem;
    border-width: 0.25em;
}

/* Camera card footer - status i retry dugme */
.camera-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    min-height: 2.9rem;
}

.camera-status-text {
    font-size: 0.813rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.38rem;
    flex-shrink: 0;
}

/* Retry dugme - male varijacije */
.camera-card-footer .btn {
    padding: 0.375rem 0.75rem;
    font-size: 0.813rem;
    border-radius: 0.5rem;
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.camera-card-footer .btn:hover:not(.d-none) {
    transform: translateY(-1px);
}

/* Responsive grid - kamere stranica */
@media (max-width: 640px) {
    .camera-card-wrapper {
        border-radius: 0.5rem;
    }

    .camera-card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .camera-status-badge {
        align-self: flex-start;
    }

    .camera-card-title h3 {
        font-size: 0.95rem;
    }
}

/* Mobile fullscreen optimizacija */
@media (max-height: 600px) and (orientation: landscape) {
    .camera-card-header,
    .camera-card-footer {
        padding: 0.5rem;
        font-size: 0.75rem;
    }
}

/* Tablet view - 2 kolone */
@media (min-width: 768px) and (max-width: 1024px) {
    .grid[data-camera-max-retries] {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Desktop view - 3 kolone */
@media (min-width: 1200px) {
    .grid[data-camera-max-retries] {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Large desktop - 4 kolone */
@media (min-width: 1600px) {
    .grid[data-camera-max-retries] {
        grid-template-columns: repeat(4, 1fr);
    }
}

