:root {
    --bg: #0f1419;
    --bg-card: #1a2332;
    --bg-sidebar: #0a0e14;
    --border: #2d3a4f;
    --text: #e6edf3;
    --text-muted: #8b9cb6;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --success: #22c55e;
    --warning: #eab308;
    --danger: #ef4444;
    --radius: 8px;
    --sidebar-width: 220px;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; min-height: 100vh; }

.app { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-width); background: var(--bg-sidebar); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar-brand { padding: 1.25rem 1rem; font-weight: 700; font-size: 1.1rem; border-bottom: 1px solid var(--border); }
.sidebar-nav { flex: 1; padding: 0.75rem 0; overflow-y: auto; }
.sidebar-nav a { display: block; padding: 0.5rem 1rem; color: var(--text-muted); text-decoration: none; font-size: 0.9rem; }
.sidebar-nav a:hover { color: var(--text); background: rgba(255,255,255,0.05); }
.sidebar-nav a.active { color: var(--accent); background: rgba(59,130,246,0.12); }
.sidebar-footer { padding: 1rem; border-top: 1px solid var(--border); }
.sidebar-footer .logout { color: var(--text-muted); font-size: 0.9rem; }
.sidebar-footer .logout:hover { color: var(--danger); }

.main { flex: 1; padding: 1.5rem; overflow: auto; }

h1, h2, h3 { margin: 0 0 0.75rem; font-weight: 600; }
h1 { font-size: 1.5rem; }
.page-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 1rem; margin-bottom: 1.5rem; }

.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-2 { grid-template-columns: 1fr; } }
@media (max-width: 600px) { .grid-4 { grid-template-columns: 1fr; } }

.stat-card { text-align: center; }
.stat-card .value { font-size: 1.75rem; font-weight: 700; color: var(--accent); }
.stat-card .label { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.25rem; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 0.6rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; }
tr:hover td { background: rgba(255,255,255,0.02); }
.table-wrap { overflow-x: auto; }

label { display: block; margin-bottom: 0.35rem; font-size: 0.9rem; color: var(--text-muted); }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="url"], select, textarea {
    width: 100%; max-width: 400px; padding: 0.5rem 0.75rem; margin-bottom: 1rem; font-size: 0.95rem;
    background: var(--bg); border: 1px solid var(--border); border-radius: 6px; color: var(--text);
}
textarea { min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }

.btn { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.5rem 1rem; font-size: 0.9rem; font-weight: 500; border-radius: 6px; cursor: pointer; border: none; text-decoration: none; background: var(--accent); color: #fff; }
.btn:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #3d4f6b; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.8rem; }

.badge { display: inline-block; padding: 0.2rem 0.5rem; font-size: 0.75rem; border-radius: 4px; }
.badge-success { background: rgba(34,197,94,0.2); color: var(--success); }
.badge-danger { background: rgba(239,68,68,0.2); color: var(--danger); }
.badge-warning { background: rgba(234,179,8,0.2); color: var(--warning); }
.badge-muted { background: rgba(139,156,182,0.2); color: var(--text-muted); }

.tabs { display: flex; gap: 0.25rem; margin-bottom: 1rem; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tabs a, .tabs button.tab { padding: 0.6rem 1rem; color: var(--text-muted); text-decoration: none; font-size: 0.9rem; background: none; border: none; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; font-family: inherit; }
.tabs a:hover, .tabs button.tab:hover { color: var(--text); }
.tabs a.active, .tabs button.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 1rem; }
.modal { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); max-width: 500px; width: 100%; max-height: 90vh; overflow: auto; }
.modal-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); font-weight: 600; }
.modal-body { padding: 1.25rem; }
.modal-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 0.5rem; }

.toast { position: fixed; bottom: 1.5rem; right: 1.5rem; padding: 0.75rem 1.25rem; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 4px 12px rgba(0,0,0,0.3); z-index: 200; animation: fadeIn 0.2s; }
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
.login-box { width: 100%; max-width: 360px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; }
.login-box h1 { margin-bottom: 0.25rem; }
.login-sub { color: var(--text-muted); margin-bottom: 1.5rem; font-size: 0.9rem; }
.login-box .error { color: var(--danger); font-size: 0.9rem; margin-bottom: 1rem; }
.login-box label { margin-top: 1rem; }
.login-box label:first-of-type { margin-top: 0; }
.login-box button { width: 100%; padding: 0.65rem; margin-top: 1rem; font-size: 1rem; cursor: pointer; background: var(--accent); color: #fff; border: none; border-radius: 6px; }
.login-box button:hover { background: var(--accent-hover); }

.form-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.form-row input, .form-row select { max-width: none; }
.flex { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 1rem; }
.mt-1 { margin-top: 1rem; }

pre, code { font-family: ui-monospace, monospace; font-size: 0.85rem; background: rgba(0,0,0,0.3); padding: 0.2rem 0.4rem; border-radius: 4px; }
pre { padding: 1rem; overflow: auto; margin: 0; }

.text-muted { color: var(--text-muted); }
.empty { color: var(--text-muted); padding: 2rem; text-align: center; }

/* Device setup wizard */
.wizard-card { max-width: 560px; }
.wizard-steps { display: flex; gap: 0; margin-bottom: 1.5rem; border-bottom: 1px solid var(--border); padding-bottom: 1rem; }
.wizard-step { display: flex; align-items: center; gap: 0.5rem; flex: 1; font-size: 0.9rem; color: var(--text-muted); }
.wizard-step-num { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 50%; background: var(--border); color: var(--text-muted); font-weight: 600; font-size: 0.85rem; }
.wizard-step.active .wizard-step-num { background: var(--accent); color: #fff; }
.wizard-step.active .wizard-step-label { color: var(--text); }
.wizard-step.done .wizard-step-num { background: var(--success); color: #fff; }
.wizard-step.done .wizard-step-label { color: var(--text-muted); }
.wizard-panel h3 { margin-bottom: 0.5rem; }
.wizard-option-row { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.wizard-option-row input[type="radio"] { width: auto; max-width: none; margin: 0; }
.wizard-option-row label { margin: 0; }
.wizard-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.wizard-qr-section label { margin-top: 0.5rem; }
.wizard-qr-section label:first-child { margin-top: 0; }
.wizard-qr-image-wrap { text-align: center; margin: 1rem 0; padding: 1rem; background: rgba(0,0,0,0.2); border-radius: var(--radius); }
.wizard-qr-img { max-width: 280px; height: auto; display: block; margin: 0 auto; }
.wizard-qr-actions { margin-top: 0.75rem; }
.wizard-enroll-tip ol { padding-left: 1.25rem; }
