:root {
    --primary: #0d6efd;
    --primary-dark: #0a58ca;
    --sidebar-width: 240px;
    --navbar-height: 56px;
    --bg-dark: #1a1d29;
    --bg-card: #ffffff;
    --text-primary: #212529;
    --text-muted: #6c757d;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f0f2f5;
    color: var(--text-primary);
    overflow-x: hidden;
}

/* Login */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a1d29 0%, #2d3349 100%);
}
.login-card {
    background: white;
    padding: 2.5rem;
    border-radius: 16px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: var(--navbar-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-dark);
    padding: 1rem 0;
    overflow-y: auto;
    z-index: 100;
}
.sidebar-menu { display: flex; flex-direction: column; gap: 2px; }
.sidebar-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: #adb5bd;
    text-decoration: none;
    transition: all 0.2s;
    border-left: 3px solid transparent;
    font-size: 14px;
}
.sidebar-item:hover { background: rgba(255,255,255,0.05); color: white; }
.sidebar-item.active {
    background: rgba(13,110,253,0.15);
    color: var(--primary);
    border-left-color: var(--primary);
}
.sidebar-item i { font-size: 1.2rem; width: 24px; text-align: center; }

/* Main Content */
.main-content {
    margin-left: var(--sidebar-width);
    margin-top: var(--navbar-height);
    padding: 1.5rem;
    min-height: calc(100vh - var(--navbar-height));
}

/* Stats Cards */
.stat-card {
    background: white;
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    transition: transform 0.2s;
}
.stat-card:hover { transform: translateY(-2px); }
.stat-card .stat-icon { font-size: 2rem; }
.stat-card .stat-value { font-size: 1.8rem; font-weight: 700; }
.stat-card .stat-label { color: var(--text-muted); font-size: 0.85rem; }

/* Live View */
.live-view-container {
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: 1.5rem;
}
.camera-feed {
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    aspect-ratio: 16/9;
    position: relative;
}
.camera-feed img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}
.live-events {
    background: white;
    border-radius: 12px;
    padding: 1rem;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
}
.live-event {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-bottom: 1px solid #eee;
    animation: slideIn 0.3s ease;
}
.live-event:last-child { border-bottom: none; }
.live-event .event-avatar {
    width: 44px; height: 44px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 1.1rem;
    flex-shrink: 0;
}
.live-event.clock_in { border-left: 3px solid #198754; }
.live-event.clock_out { border-left: 3px solid #6c757d; }
.live-event .event-info { flex: 1; min-width: 0; }
.live-event .event-name { font-weight: 600; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.live-event .event-meta { color: var(--text-muted); font-size: 0.8rem; }
.live-event .event-badge {
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 20px;
    font-weight: 600;
}
.event-badge.clock_in { background: #d1e7dd; color: #0f5132; }
.event-badge.clock_out { background: #e2e3e5; color: #41464b; }

@keyframes slideIn {
    from { opacity: 0; transform: translateX(-20px); }
    to { opacity: 1; transform: translateX(0); }
}

/* Tables */
.data-table { font-size: 0.9rem; }
.data-table th { background: #f8f9fa; font-weight: 600; position: sticky; top: 0; }
.data-table td { vertical-align: middle; }

/* Cards */
.card-dashboard {
    background: white;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    border: none;
}
.card-dashboard .card-header {
    background: transparent;
    border-bottom: 1px solid #eee;
    padding: 1rem 1.25rem;
    font-weight: 600;
}

/* Worker thumbnails */
.worker-thumb {
    width: 36px; height: 36px;
    border-radius: 50%;
    object-fit: cover;
    background: #e9ecef;
}

/* Unknown faces grid */
.unknown-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}
.unknown-card {
    background: white;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.unknown-card img { width: 100%; aspect-ratio: 1; object-fit: cover; }
.unknown-card .unknown-info { padding: 0.75rem; }
.unknown-card .unknown-actions { padding: 0.75rem; border-top: 1px solid #eee; display: flex; gap: 0.5rem; }

/* Alert notifications */
.alert-toast {
    position: fixed;
    top: 70px;
    right: 20px;
    z-index: 9999;
    min-width: 320px;
    max-width: 450px;
}

/* Mining mode headcount */
.headcount-display {
    font-size: 3rem;
    font-weight: 800;
    text-align: center;
    padding: 1.5rem;
}
.headcount-display .label { font-size: 1rem; font-weight: 400; color: var(--text-muted); }

/* Responsive */
@media (max-width: 768px) {
    .sidebar { width: 60px; }
    .sidebar-item span { display: none; }
    .sidebar-item { justify-content: center; padding: 12px; }
    .main-content { margin-left: 60px; }
    .live-view-container { grid-template-columns: 1fr; }
}

/* Underground headcount table */
.underground-table td:first-child { font-weight: 600; }

/* Filter bar */
.filter-bar {
    background: white;
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 1rem;
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    align-items: center;
}
.filter-bar .form-control,
.filter-bar .form-select { width: auto; min-width: 150px; }

/* Spinner */
.loading-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem;
}

/* License footer */
.footer-license {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
    padding: 6px;
    font-size: 11px;
    color: #888;
    background: #f8f9fa;
    border-top: 1px solid #dee2e6;
    z-index: 999;
}
