:root {
    --bg-dark: #121212;
    --bg-panel: #1e1e1e;
    --accent: #007bff;
    --text: #e0e0e0;
}
body {
    margin: 0;
    font-family: 'Segoe UI', sans-serif;
    /* Deep charcoal background */
    background-color: #0a0a0b; 
    /* CSS-generated grid pattern */
    background-image: 
        linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
    background-size: 50px 50px; /* Size of the grid squares */
    color: var(--text);
    overflow: hidden;
}

body::after {
    content: "";
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    /* Dark vignette overlay */
    background: radial-gradient(circle, transparent 40%, rgba(0,0,0,0.8) 100%);
    pointer-events: none; /* Allows clicks to pass through to cameras */
    z-index: 2; /* Sits behind the expanded view but over the grid */
}
.app-container { display: flex; height: 100vh; }

/* SIDEBAR */
.sidebar { width: 240px; background: #000; display: flex; flex-direction: column; border-right: 1px solid #333; }
.brand { padding: 20px; font-size: 1.2rem; font-weight: bold; color: var(--accent); border-bottom: 1px solid #333; text-transform: uppercase; letter-spacing: 1px;}
.nav-btn { background: none; border: none; color: #888; padding: 15px 20px; text-align: left; cursor: pointer; width: 100%; font-size: 0.95rem; transition: 0.2s; border-left: 3px solid transparent;}
.nav-btn:hover { background: #111; color: #fff; }
.nav-btn.active { background: #1a1a1a; color: #fff; border-left: 3px solid var(--accent); }
.status-panel { margin-top: auto; padding: 20px; font-size: 0.8rem; color: #666; border-top: 1px solid #333; }

/* MAIN CONTENT */
.main-view { flex: 1; display: flex; flex-direction: column; background: var(--bg-dark); }
.top-bar { height: 60px; display: flex; justify-content: space-between; align-items: center; padding: 0 25px; background: var(--bg-panel); border-bottom: 1px solid #333; }
.top-bar h2 { margin: 0; font-size: 1.2rem; font-weight: 500; }
#clock { font-family: monospace; font-size: 1.1rem; color: var(--accent); }

/* VIDEO GRID */
.video-grid { 
    flex: 1; 
    padding: 15px; 
    overflow-y: auto; 
    display: grid; 
    /* Responsive Grid: Cards are min 350px wide */
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr)); 
    gap: 15px; 
    align-content: start;
}

/* CAMERA CARD */
.cam-card { 
    position: relative; 
    background: #000; 
    aspect-ratio: 16/9; 
    border-radius: 8px; 
    overflow: hidden; 
    border: 1px solid #333; 
    cursor: pointer;
    /* Smooth transition for the pop effect */
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    z-index: 1; /* Default layer */
}

/* THE POP EFFECT */
.cam-card:hover { 
    transform: scale(1.05) translateY(-5px); /* Grow and lift */
    border-color: var(--accent); 
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.5); /* Deep shadow */
    z-index: 10; /* Bring to very front so it overlaps neighbors */
}

.cam-card video { width: 100%; height: 100%; object-fit: cover; pointer-events: none; }

/* THE INSTANT ZOOM CLASS */
.cam-card.expanded {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 99999 !important; /* On top of everything */
    border-radius: 0;
    border: none;
    transform: none !important; /* Disable the hover pop effect */
    background: #000;
    padding: 0;
    margin: 0;
}

/* Make video fit nicely in fullscreen */
.cam-card.expanded video {
    object-fit: contain; /* Show the whole image (adds black bars if needed) */
    /* Use 'cover' if you want it to fill the screen (might crop edges) */
}

/* Hide the hover overlay when expanded */
.cam-card.expanded .cam-overlay {
    display: none;
}

/* Show the Close Button only when expanded */
.close-zoom-btn {
    display: none;
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(200, 0, 0, 0.8);
    color: white;
    border: none;
    padding: 10px 20px;
    font-size: 1rem;
    font-weight: bold;
    border-radius: 4px;
    cursor: pointer;
    z-index: 100000;
}
.close-zoom-btn:hover { background: red; }

.cam-card.expanded .close-zoom-btn {
    display: block; /* Show it! */
}

/* UPDATED CAMERA LABEL: CENTER TOP */
.cam-label { 
    position: absolute; 
    top: 10px; /* Distance from top */
    left: 50%;
    transform: translateX(-50%); /* Perfectly center horizontally */
    
    /* Modern Pill Design */
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px); /* Blur the video slightly behind the text */
    color: #ffffff;
    padding: 4px 15px; 
    border-radius: 20px;
    font-size: 0.85rem; 
    font-weight: 600;
    white-space: nowrap; /* Keep name on one line */
    letter-spacing: 0.5px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
    pointer-events: none;
    z-index: 20; /* Keep it on top */
}

/* Adjust label size when zoomed in */
.cam-card.expanded .cam-label {
    font-size: 1.2rem;
    top: 20px;
    padding: 8px 25px;
    background: rgba(0, 0, 0, 0.8);
}

.loading-indicator { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: #666; font-size: 0.8rem; }

/* HOVER OVERLAY ICON */
.cam-overlay { 
    position: absolute; top: 0; left: 0; width: 100%; height: 100%; 
    background: rgba(0,0,0,0.2); /* Lighter tint */
    display: flex; justify-content: center; align-items: center; 
    opacity: 0; transition: opacity 0.2s; 
    font-size: 2.5rem; 
    color: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(1px); /* Optional: adds a slight blur to video behind icon */
}
.cam-card:hover .cam-overlay { opacity: 1; }

/* FULLSCREEN MODAL */
.fs-modal {
    display: none; /* Hidden by default */
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.95);
    z-index: 1000;
    flex-direction: column;
    justify-content: center; align-items: center;
}
.video-wrapper { width: 90%; height: 80%; display: flex; justify-content: center; }
.fs-modal video { width: 100%; height: 100%; object-fit: contain; box-shadow: 0 0 30px rgba(0,0,0,0.5); }
.close-btn { 
    position: absolute; top: 20px; right: 20px; 
    background: #d32f2f; color: white; border: none; 
    padding: 10px 20px; border-radius: 4px; cursor: pointer; font-weight: bold; 
    z-index: 1001;
}
.close-btn:hover { background: #b71c1c; }
.fs-title { color: white; margin-top: 15px; font-size: 1.2rem; }

/* Connection Error Overlay */
.connection-error {
    display: none; /* Hidden by default */
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(20, 20, 20, 0.9);
    z-index: 5;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #ff4444;
    font-weight: bold;
}

.cam-card.stalled .connection-error {
    display: flex;
}

.spinner-ring {
    width: 40px; height: 40px;
    border: 4px solid rgba(255, 68, 68, 0.1);
    border-top: 4px solid #ff4444;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 10px;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* --- MOBILE LANDSCAPE ZOOM --- */

@media (max-width: 900px) and (orientation: portrait) {
    .cam-card.expanded {
        width: 100vh;
        height: 100vw;
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%) rotate(90deg) !important;
    }

    /* Keep the label centered on the "new" top */
    .cam-card.expanded .cam-label {
        top: 15px;
        left: 50%;
        transform: translateX(-50%); /* Still centered */
    }
}

/* If the user actually rotates their phone to landscape, reset the rotation */
@media (orientation: landscape) {
    .cam-card.expanded {
        transform: none !important;
        width: 100vw;
        height: 100vh;
        top: 0;
        left: 0;
    }
}