/* Design Tokens & Variables */
:root {
    /* Colors - Light Theme (Default) */
    --bg-base: #f0f2f5;
    --bg-surface: #ffffff;
    --bg-surface-hover: #f8fafc;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-light: #eff6ff;
    
    --danger: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;
    
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.5);
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    
    /* Typography */
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    
    /* Transitions */
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Layout */
    --sidebar-width: 320px;
}

/* Dark Theme Variables */
[data-theme="dark"] {
    --bg-base: #0f172a;
    --bg-surface: #1e293b;
    --bg-surface-hover: #334155;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: #334155;
    
    --primary: #60a5fa;
    --primary-hover: #3b82f6;
    --primary-light: rgba(59, 130, 246, 0.1);
    
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.05);
}

/* Base Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-base);
    color: var(--text-main);
    line-height: 1.5;
    overflow: hidden; /* App-like feel, no global scroll */
    transition: background-color var(--transition), color var(--transition);
}

/* Layout Container */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* === Sidebar === */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 10;
    transition: transform var(--transition);
    box-shadow: var(--shadow-md);
}

.sidebar-header {
    padding: 24px 20px 16px;
    border-bottom: 1px solid var(--border-color);
}

.brand-logo {
    height: 32px;
    margin-bottom: 16px;
}

.sidebar-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    margin-bottom: 4px;
}

.sidebar-header p {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 20px;
}

/* Search Box */
.search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.search-box i {
    position: absolute;
    left: 12px;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.search-box input {
    width: 100%;
    padding: 10px 10px 10px 36px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--bg-base);
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.875rem;
    transition: var(--transition);
    outline: none;
}

.search-box input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* Camera List */
.camera-list-container {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

/* Custom Scrollbar */
.camera-list-container::-webkit-scrollbar {
    width: 6px;
}
.camera-list-container::-webkit-scrollbar-track {
    background: transparent;
}
.camera-list-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}
.camera-list-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.camera-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.camera-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-radius: 10px;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
}

.camera-item:hover {
    background-color: var(--bg-surface-hover);
    border-color: var(--border-color);
}

.camera-item.active {
    background-color: var(--primary-light);
    border-color: var(--primary);
}

.cam-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background-color: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    flex-shrink: 0;
    font-size: 1.125rem;
    transition: var(--transition);
}

.camera-item.active .cam-icon {
    background-color: var(--primary);
    color: white;
}

.cam-info {
    flex: 1;
    overflow: hidden;
}

.cam-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.cam-loc {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cam-status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-left: 8px;
}

.status-online { background-color: var(--success); }
.status-maintenance { background-color: var(--warning); }
.status-offline { background-color: var(--danger); }

/* === Main Content === */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0; /* Important for flex-child truncation */
    position: relative;
    background: radial-gradient(circle at top right, var(--bg-surface), var(--bg-base));
}

/* Top Navigation */
.top-nav {
    height: 72px;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--glass-border);
    z-index: 5;
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 1.25rem;
    cursor: pointer;
    margin-right: 16px;
}

.current-playing-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    overflow: hidden;
}

.live-badge {
    background-color: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
    border: 1px solid rgba(239, 68, 68, 0.2);
    /* Initially hidden until video plays */
    opacity: 0;
    transition: opacity 0.3s;
}

.pulse {
    width: 6px;
    height: 6px;
    background-color: var(--danger);
    border-radius: 50%;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
    70% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

#currentCameraTitle {
    font-size: 1.125rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.icon-btn, .yt-link {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    font-size: 1.125rem;
}

.icon-btn:hover, .yt-link:hover {
    background-color: var(--bg-surface-hover);
    color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.yt-link:hover {
    color: #ff0000;
    border-color: #ff0000;
}

/* Player Container */
.player-container {
    flex: 1;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    overflow-y: auto;
}

.video-wrapper {
    width: 100%;
    aspect-ratio: 16/9;
    background-color: #000;
    border-radius: 16px;
    overflow: hidden;
    position: relative;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
}

#cctvPlayer {
    width: 100%;
    height: 100%;
    object-fit: contain; /* Prevent cropping */
    background: #000;
    display: none;
}

/* States Overlays */
.placeholder-content, .loading-overlay, .error-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: linear-gradient(135deg, #1e293b, #0f172a);
    z-index: 2;
    text-align: center;
    padding: 20px;
}

.loading-overlay, .error-overlay {
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(8px);
    display: none;
}

.placeholder-content i {
    font-size: 3rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.placeholder-content p {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.placeholder-content span {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255,255,255,0.1);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 1s ease-in-out infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.error-overlay i {
    font-size: 3rem;
    color: var(--danger);
    margin-bottom: 16px;
}

.btn-primary {
    margin-top: 16px;
    padding: 10px 24px;
    background-color: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
}

/* Active States */
.video-wrapper.is-playing #cctvPlayer { display: block; }
.video-wrapper.is-playing .placeholder-content { display: none; }
.video-wrapper.is-loading .loading-overlay { display: flex; }
.video-wrapper.is-error .error-overlay { display: flex; }

/* Camera Details Widget */
.camera-details {
    background-color: var(--bg-surface);
    border-radius: 16px;
    border: 1px solid var(--border-color);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
}

.camera-details.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.detail-header {
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.detail-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.detail-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.detail-item i {
    color: var(--primary);
    background-color: var(--primary-light);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.detail-item div {
    display: flex;
    flex-direction: column;
}

.detail-item span {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.detail-item strong {
    font-size: 0.875rem;
    color: var(--text-main);
    font-weight: 600;
}

.status-badge {
    display: inline-flex;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem !important;
    font-weight: 600;
    background-color: var(--success);
    color: white !important;
    width: fit-content;
}

/* View Options for Multiple Streams - Tabbed Replica */
.view-options-container {
    background-color: var(--bg-surface);
    border-radius: 16px;
    border: 1px solid var(--border-color);
    padding: 0 24px; /* remove top/bottom padding to let tabs sit flush if needed, or keep minimal */
    padding-top: 16px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 8px;
}

.view-options-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0; /* remove gap to make tabs contiguous */
    border-bottom: 1px solid var(--border-color); /* The line under all tabs */
    margin-bottom: 16px; /* Space before content below, if any */
}

.btn-view-option {
    display: inline-block;
    padding: 8px 16px;
    background-color: transparent;
    color: #6c757d; /* Bootstrap gray color for inactive tabs */
    border: 1px solid transparent;
    border-bottom: none;
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
    font-size: 0.875rem;
    font-weight: 400;
    cursor: pointer;
    margin-bottom: -1px; /* To pull active tab over the bottom border */
    transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out;
}

.btn-view-option:hover {
    color: #125AA8;
    border-color: #e9ecef #e9ecef var(--border-color);
}

.btn-view-option.active {
    background-color: #fff;
    color: #125AA8; /* Same blue text as official site */
    border-color: var(--border-color) var(--border-color) #fff;
}

[data-theme="dark"] .btn-view-option {
    color: var(--text-muted);
}

[data-theme="dark"] .btn-view-option:hover {
    color: #60a5fa; /* light blue for dark mode */
}

[data-theme="dark"] .btn-view-option.active {
    background-color: var(--bg-surface);
    color: #60a5fa;
    border-color: var(--border-color) var(--border-color) var(--bg-surface);
}

.btn-view-option i {
    font-size: 1rem;
}

/* ===== CLOCK CHIP (Viewer Top Nav) ===== */
.clock-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--primary-light);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--primary);
    white-space: nowrap;
}

.clock-chip i {
    font-size: 0.8rem;
}

/* ===== SIDEBAR FOOTER ===== */
.sidebar-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border-color);
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

.sidebar-footer strong {
    color: var(--primary);
    font-weight: 700;
}

/* ===== CAMERA STATUS TEXT (Inline in List) ===== */
.cam-status-text {
    font-size: 0.7rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 3px;
}

.cam-status-text i {
    font-size: 0.65rem;
}

.cam-status-text.is-online {
    color: var(--success);
}

.cam-status-text.is-offline {
    color: var(--danger);
}

.cam-loc i {
    font-size: 0.65rem;
    margin-right: 2px;
}

/* ===== Responsive Design ===== */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        width: 85%;
        max-width: 320px;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .mobile-menu-btn {
        display: block;
    }
    
    .player-container {
        padding: 16px;
    }
    
    .video-wrapper {
        border-radius: 12px;
    }

    /* Improved mobile camera list items */
    .camera-item {
        padding: 14px 16px;
        border: 1px solid var(--border-color);
        border-radius: 12px;
        background: var(--bg-surface);
        margin-bottom: 2px;
    }

    .camera-item:hover {
        background-color: var(--bg-surface-hover);
    }

    .cam-icon {
        width: 44px;
        height: 44px;
        font-size: 1.2rem;
    }

    .cam-title {
        font-size: 0.9rem;
    }

    .cam-loc {
        font-size: 0.78rem;
    }

    .cam-status-text {
        font-size: 0.72rem;
    }

    /* Hide clock chip text on very small screens */
    .clock-chip span {
        display: none;
    }
    .clock-chip {
        padding: 6px 8px;
    }

    .top-nav {
        height: 60px;
        padding: 0 12px;
    }

    #currentCameraTitle {
        font-size: 0.95rem;
    }

    .detail-grid {
        grid-template-columns: 1fr;
        gap: 14px;
    }
}

@media (max-width: 480px) {
    .camera-item {
        padding: 12px 14px;
    }
    .cam-icon {
        width: 38px;
        height: 38px;
        font-size: 1rem;
        margin-right: 10px;
    }
}
