:root {
    --bg-color: #0f172a;
    --text-color: #f8fafc;
    --text-muted: #94a3b8;
    --card-bg: rgba(30, 41, 59, 0.7);
    --sidebar-bg: rgba(15, 23, 42, 0.8);
    --border-color: rgba(255, 255, 255, 0.1);
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #10b981;
    --danger: #ef4444;
    --glass-bg: rgba(15, 23, 42, 0.6);
    --glass-border: rgba(255, 255, 255, 0.08);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.5;
    height: 100vh;
    overflow: hidden;
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(59, 130, 246, 0.15), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(16, 185, 129, 0.1), transparent 25%);
}

.layout-wrapper {
    display: flex;
    height: 100vh;
    width: 100vw;
}

.glass-panel {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(12px);
}

/* Dashboard Workspace */
.dashboard-workspace {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    height: calc(100vh - 80px); /* Adjust based on topbar height */
}

.dashboard-workspace::-webkit-scrollbar {
    width: 8px;
}
.dashboard-workspace::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

.sidebar-loading {
    padding: 4rem;
    text-align: center;
    color: var(--text-muted);
}

.truck-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 2rem;
    padding-bottom: 2rem;
}

.truck-card {
    border-radius: 1rem;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.truck-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 15px 35px -5px rgba(0, 0, 0, 0.4);
    border-color: rgba(255, 255, 255, 0.15);
}

.truck-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.2);
}

.truck-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.truck-cameras {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1px; /* border hack */
    background: var(--border-color);
}

.camera-thumb {
    background: var(--bg-color);
    position: relative;
    cursor: pointer;
    display: flex;
    flex-direction: column;
}

.camera-thumb:hover .play-overlay {
    opacity: 1;
}

.thumb-header {
    padding: 0.5rem 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    background: rgba(30, 41, 59, 0.9);
}

.cam-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    color: var(--text-color);
}

.cam-serial {
    color: var(--text-muted);
    font-family: monospace;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}
.status-dot.online { background-color: var(--success); }
.status-dot.offline { background-color: var(--danger); }

.img-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 16/9;
    background: #000;
    overflow: hidden;
}

.img-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: opacity 0.3s ease;
}

.img-wrapper img.fallback {
    opacity: 0.3;
    object-fit: contain;
    padding: 1rem;
}

.play-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.camera-thumb[data-online="false"] .play-overlay {
    display: none;
}

.play-overlay svg {
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.5));
    transform: scale(0.9);
    transition: transform 0.2s ease;
}

.camera-thumb:hover .play-overlay svg {
    transform: scale(1.1);
}


/* Modal Styles */
.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    width: 100%;
    max-width: 1000px;
    border-radius: 1rem;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    z-index: 51;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: rgba(15, 23, 42, 0.95);
    border-radius: 1rem 1rem 0 0;
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    transition: color 0.2s;
}

.btn-close:hover {
    color: #fff;
}

.video-container {
    position: relative;
    width: 100%;
    aspect-ratio: 16/9;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0 0 1rem 1rem;
}

.stream-loading {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: var(--text-muted);
    text-align: center;
    padding: 1rem;
}

.stream-loading p {
    margin: 0;
    font-size: 0.95rem;
}

.key-input-form {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.8rem;
    width: 100%;
    max-width: 340px;
}

.key-input-form input {
    width: 100%;
    padding: 0.6rem 1rem;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    color: var(--text-primary);
    font-size: 0.95rem;
    text-align: center;
    letter-spacing: 0.05em;
    outline: none;
    transition: border-color 0.2s;
}

.key-input-form input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 179, 237, 0.15);
}

.key-input-form .btn {
    width: 100%;
}

#video-stream {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.6rem 1rem;
    border-radius: 0.5rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-primary:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
}

/* Ensure topbar is still flexed correctly */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 40;
}

.hero-content h1 {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(to right, #60a5fa, #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.hero-content p {
    font-size: 0.9rem;
    color: var(--text-muted);
}


.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.08);
    border-radius: 50%;
    border-top-color: var(--primary);
    border-right-color: rgba(99, 179, 237, 0.4);
    animation: spin 0.9s cubic-bezier(0.5, 0, 0.5, 1) infinite;
    margin: 0 auto 1.2rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.hidden {
    display: none !important;
}

/* Header Actions & Stat Badge */
.header-actions {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.refresh-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.camera-thumb {
    cursor: pointer;
    border-radius: 0.5rem;
    overflow: hidden;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    transition: border-color 0.3s;
}

.camera-thumb[data-online="false"] {
    cursor: default;
}

.camera-thumb:hover {
    border-color: rgba(255, 255, 255, 0.2);
}

.camera-thumb[data-online="false"]:hover .img-wrapper img {
    transform: none;
}

.glass-select {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 0.25rem 0.5rem;
    border-radius: 0.35rem;
    outline: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
    transition: border-color 0.2s;
}

.glass-select:focus, .glass-select:hover {
    border-color: rgba(255, 255, 255, 0.25);
}

.glass-select:focus, .glass-select:focus {
    border-color: rgba(255, 255, 255, 0.3);
}

.glass-input {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.3s;
    width: 250px;
}

.glass-input:focus {
    border-color: rgba(255, 255, 255, 0.3);
}

.search-bar {
    display: flex;
    align-items: center;
}

.glass-select option {
    background: var(--bg-color);
    color: var(--text-color);
}

.stat-badge {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    padding: 0.4rem 0.75rem;
    border-radius: 2rem;
    font-size: 0.85rem;
    font-weight: 500;
}

.pulse-indicator {
    width: 8px;
    height: 8px;
    background-color: var(--success);
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.filter-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    cursor: pointer;
}

.filter-toggle input {
    cursor: pointer;
    accent-color: var(--primary);
}

.truck-grid.show-online-only .truck-card.offline {
    display: none;
}

