:root {
    --bg-sidebar: #0f172a;
    --bg-sidebar-hover: #1e293b;
    --bg-sidebar-active: #1e293b;
    --bg-main: #f1f5f9;
    --bg-card: #ffffff;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --text-light: #cbd5e1;
    --text-muted: #64748b;
    --text-dark: #1e293b;
    --border: #e2e8f0;
    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-main);
    color: var(--text-dark);
    line-height: 1.5;
}

/* Sidebar */
.sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: 240px;
    background: var(--bg-sidebar);
    color: var(--text-light);
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-header h1 {
    font-size: 20px;
    font-weight: 700;
    color: white;
    letter-spacing: -0.5px;
}

.sidebar-header span {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-radius: 8px;
    color: var(--text-light);
    text-decoration: none;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: 2px;
}

.nav-item:hover {
    background: var(--bg-sidebar-hover);
    color: white;
}

.nav-item.active {
    background: var(--accent);
    color: white;
    font-weight: 500;
}

.nav-item .icon {
    font-size: 18px;
    width: 20px;
    text-align: center;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.06);
    font-size: 13px;
}

.sidebar-footer .user { color: white; font-weight: 500; }
.sidebar-footer .logout {
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
}
.sidebar-footer .logout:hover { color: var(--error); }

/* Main content */
.main {
    margin-left: 240px;
    min-height: 100vh;
    padding: 24px 32px;
}

.page-header {
    margin-bottom: 24px;
}

.page-header h2 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-dark);
}

.page-header p {
    color: var(--text-muted);
    font-size: 14px;
    margin-top: 4px;
}

/* Cards */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 16px;
}

.card-header {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 16px;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    padding: 10px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border);
}

td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

tr:hover td { background: #f8fafc; }
tr.clickable { cursor: pointer; }

/* Badges */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-incoming { background: #dbeafe; color: #1d4ed8; }
.badge-outgoing { background: #d1fae5; color: #059669; }
.badge-missed { background: #fee2e2; color: #dc2626; }
.badge-manual { background: #e0e7ff; color: #4338ca; }
.badge-bluetooth { background: #dbeafe; color: #2563eb; }
.badge-geofence { background: #d1fae5; color: #059669; }
.badge-activity { background: #fef3c7; color: #d97706; }
.badge-flagged { background: #fee2e2; color: #dc2626; }
.badge-admin { background: #fef3c7; color: #d97706; }

/* Buttons */
.btn {
    padding: 8px 16px;
    border-radius: 8px;
    border: none;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

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

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dark);
}
.btn-outline:hover { background: #f8fafc; }

.btn-sm { padding: 4px 10px; font-size: 12px; }

/* Forms */
input[type="text"], input[type="password"], input[type="number"], textarea, select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s;
}

input:focus, textarea:focus, select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.form-group { margin-bottom: 16px; }

/* Map */
.map-container {
    height: 500px;
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 16px;
}

.map-container-full {
    height: calc(100vh - 120px);
    border-radius: var(--radius);
    overflow: hidden;
}

/* Audio */
audio {
    height: 32px;
    border-radius: 16px;
}

/* Pagination */
.pagination {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-top: 16px;
}

/* Status dot */
.status-dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    margin-right: 6px;
}
.status-dot.green { background: var(--success); }
.status-dot.yellow { background: var(--warning); }
.status-dot.red { background: var(--error); }

/* Login page */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 10vh;
    background: var(--bg-sidebar);
}

.login-card {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-card h1 {
    font-size: 28px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 8px;
    color: var(--accent);
}

.login-card .subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 32px;
    font-size: 14px;
}

.login-card .error {
    background: #fee2e2;
    color: #dc2626;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 16px;
    display: none;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar { width: 60px; }
    .sidebar-header h1, .sidebar-header span, .nav-item span, .sidebar-footer { display: none; }
    .nav-item { justify-content: center; padding: 12px; }
    .main { margin-left: 60px; padding: 16px; }
}

/* Loading */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

/* Info grid */
.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.info-item label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
.info-item .value { font-size: 16px; font-weight: 600; }

/* Admin tabs */
.admin-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--border);
    padding-bottom: 0;
}

.admin-tab {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border: none;
    background: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.15s;
}

.admin-tab:hover {
    color: var(--text-dark);
    background: #f8fafc;
}

.admin-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: 600;
}

.admin-tab-content {
    display: none;
}

.admin-tab-content.active {
    display: block;
}

/* Expandable raw data */
.raw-detail {
    background: #0f172a;
    color: #e2e8f0;
    padding: 16px;
    border-radius: 8px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 12px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 500px;
    overflow-y: auto;
    margin: 8px 0;
}

tr.expandable { cursor: pointer; }
tr.expandable:hover td { background: #eef2ff; }
