:root {
    --bg-color: #0b0f19;
    --panel-bg: rgba(20, 26, 40, 0.6);
    --panel-border: rgba(255, 255, 255, 0.08);
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --accent: #10b981;
    --accent-glow: rgba(16, 185, 129, 0.2);
    --red: #ef4444;
    --blue: #3b82f6;
    --purple: #8b5cf6;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    background-image: 
        radial-gradient(at 0% 0%, rgba(16, 185, 129, 0.08) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(59, 130, 246, 0.08) 0px, transparent 50%);
    background-attachment: fixed;
    color: var(--text-main);
    line-height: 1.5;
    min-height: 100vh;
}

h1, h2, h3 {
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
}

/* Loader */
.loader-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.4s ease;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255,255,255,0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

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

/* App Container */
.app-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* Top Bar */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding: 1rem 1.5rem;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo i { color: var(--accent); }
.logo h1 { font-size: 1.5rem; letter-spacing: -0.5px; }
.badge {
    background: var(--accent-glow);
    color: var(--accent);
    padding: 0.2rem 0.6rem;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.header-stats {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.stat-pill {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
}
.stat-pill i { width: 16px; height: 16px; color: var(--text-muted); }

.last-update {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Update Now Button */
.update-now-btn {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.4rem 0.9rem;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-main);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
    white-space: nowrap;
}
.update-now-btn svg { width: 14px; height: 14px; color: var(--accent); flex-shrink: 0; }
.update-now-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.18);
}
.update-now-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}
.update-now-btn.updating svg {
    animation: spin 0.9s linear infinite;
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    grid-template-areas: 
        "hero log"
        "charts log"
        "gallery gallery";
    gap: 1.5rem;
}

@media (max-width: 1200px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
        grid-template-areas: 
            "hero"
            "charts"
            "log"
            "gallery";
    }
}

/* Panels */
.panel {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    padding: 1.5rem;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.panel-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.panel-header h2 { font-size: 1.25rem; }
.flex-between { justify-content: space-between; }

.status-indicator.live {
    width: 8px; height: 8px;
    background: var(--red);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--red);
    animation: pulse 2s infinite;
}

@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.4; } 100% { opacity: 1; } }

/* Hero Section */
.hero-panel { grid-area: hero; }
.hero-content {
    display: flex;
    gap: 1.5rem;
    align-items: flex-start;
}
@media (max-width: 768px) { .hero-content { flex-direction: column; } }

.main-cam { flex: 0 0 280px; position: relative; }
.side-cam-stats { flex: 1; display: flex; flex-direction: column; gap: 1.5rem; min-width: 0; }
.dash-cam { position: relative; }

.main-cam img, .dash-cam img {
    width: 100%;
    border-radius: 12px;
    object-fit: cover;
    display: block;
    background: #000;
}
.main-cam img { aspect-ratio: 9/16; max-height: 500px; object-fit: cover; }
.dash-cam img { aspect-ratio: 16/9; }

.cam-label {
    position: absolute;
    bottom: 12px; left: 12px;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    padding: 0.25rem 0.75rem;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 500;
}

.current-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    flex-grow: 1;
}

.stat-card {
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.stat-card i { margin-bottom: 0.5rem; }
.icon-red { color: var(--red); }
.icon-blue { color: var(--blue); }
.icon-green { color: var(--accent); }
.icon-purple { color: var(--purple); }

.stat-val { font-size: 1.5rem; font-weight: 700; font-family: 'Outfit'; }
.stat-name { font-size: 0.8rem; color: var(--text-muted); }

/* Charts */
.charts-panel { grid-area: charts; }
.chart-container {
    position: relative;
    height: 250px;
    width: 100%;
}
.mt-4 { margin-top: 1.5rem; }

/* Log Panel */
.log-panel { 
    grid-area: log; 
    display: flex; flex-direction: column;
    max-height: 800px;
}
.log-feed {
    flex: 1;
    overflow-y: auto;
    padding-right: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.log-feed::-webkit-scrollbar { width: 6px; }
.log-feed::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }

.log-item {
    background: rgba(0,0,0,0.2);
    border-left: 3px solid var(--accent);
    padding: 1rem;
    border-radius: 0 8px 8px 0;
}
.log-time { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 0.25rem; }
.log-reason { font-size: 0.9rem; margin-bottom: 0.75rem; }
.log-actions {
    display: flex; flex-wrap: wrap; gap: 0.5rem;
}
.action-tag {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    font-size: 0.75rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}
.action-tag i { width: 12px; height: 12px; }

/* Gallery */
.gallery-panel { grid-area: gallery; }
.tabs { display: flex; gap: 0.5rem; background: rgba(0,0,0,0.3); padding: 0.25rem; border-radius: 8px;}
.tab {
    background: transparent; border: none; color: var(--text-muted);
    padding: 0.4rem 1rem; border-radius: 6px; cursor: pointer;
    font-family: inherit; font-size: 0.85rem; font-weight: 500;
    transition: all 0.2s;
}
.tab.active { background: var(--panel-border); color: #fff; }

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
}
.gallery-grid.landscape {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.gallery-item {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    aspect-ratio: 9/16;
    background: #000;
    cursor: pointer;
}
.gallery-grid.landscape .gallery-item {
    aspect-ratio: 16/9;
}
.gallery-item img {
    width: 100%; height: 100%; object-fit: cover;
    transition: transform 0.3s ease;
}
.gallery-item:hover img { transform: scale(1.05); }
.gallery-meta {
    position: absolute; bottom: 0; left: 0; right: 0;
    background: linear-gradient(transparent, rgba(0,0,0,0.8));
    padding: 1rem 0.5rem 0.5rem;
    font-size: 0.7rem;
    pointer-events: none;
}

/* Delete button on gallery cards */
.delete-btn {
    position: absolute;
    top: 6px; right: 6px;
    width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    background: rgba(239, 68, 68, 0.85);
    border: none; border-radius: 6px;
    color: #fff;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s;
    z-index: 2;
}
.delete-btn i { width: 14px; height: 14px; }
.gallery-item:hover .delete-btn { opacity: 1; }
.delete-btn:hover { background: rgba(239, 68, 68, 1); }
.delete-btn:disabled { background: rgba(100,100,100,0.7); cursor: not-allowed; }
.delete-btn:disabled i { animation: spin 1s linear infinite; }

.gallery-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.25rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.gallery-pagination button {
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--panel-border);
    color: var(--text-main);
    padding: 0.4rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
    transition: all 0.2s;
}
.gallery-pagination button:hover:not(:disabled) { background: rgba(255,255,255,0.12); }
.gallery-pagination button:disabled { opacity: 0.3; cursor: not-allowed; }

/* Auth Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(11, 15, 25, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 1rem;
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-card {
    background: var(--bg-color);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    padding: 1.75rem;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.modal-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.modal-icon {
    color: var(--accent);
    width: 22px;
    height: 22px;
}

.modal-card h3 {
    font-size: 1.15rem;
    color: var(--text-main);
}

.modal-desc {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 1.25rem;
}

.modal-input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    color: #fff;
    font-family: inherit;
    font-size: 0.95rem;
    margin-bottom: 0.75rem;
    outline: none;
    transition: border-color 0.2s;
}

.modal-input:focus {
    border-color: var(--accent);
}

.auth-error-msg {
    color: var(--red);
    font-size: 0.8rem;
    margin-bottom: 0.75rem;
    min-height: 1.2rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

.modal-btn {
    padding: 0.6rem 1.1rem;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.cancel-btn {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-muted);
}

.cancel-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: var(--text-main);
}

.submit-btn {
    background: var(--red);
    color: #fff;
}

.submit-btn:hover {
    background: #dc2626;
    box-shadow: 0 0 12px rgba(239, 68, 68, 0.4);
}


