:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: #1e293b;
    --bg-input: #2d3748;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-green: #10b981;
    --accent-red: #ef4444;
    --accent-yellow: #f59e0b;
    --accent-orange: #f97316;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border: #334155;
    --sidebar-width: 260px;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg-primary); color: var(--text-primary); }

/* ── Layout ── */
.app-layout { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-width); background: var(--bg-secondary); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: fixed; height: 100vh; overflow-y: auto; z-index: 100; }
.main-content { margin-left: var(--sidebar-width); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }
.topnav { background: var(--bg-secondary); border-bottom: 1px solid var(--border); padding: 0 24px; height: 64px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 50; }
.page-body { padding: 24px; flex: 1; }

/* ── Sidebar ── */
.sidebar-logo { padding: 20px 24px; font-size: 1.2rem; font-weight: 700; color: var(--accent); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.sidebar-logo svg { width: 28px; height: 28px; }
.sidebar-nav { padding: 16px 0; flex: 1; }
.nav-section { padding: 0 16px 8px; font-size: 0.7rem; font-weight: 600; letter-spacing: 0.08em; color: var(--text-muted); text-transform: uppercase; margin-top: 16px; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 10px 20px; color: var(--text-secondary); text-decoration: none; font-size: 0.875rem; transition: all 0.15s; border-left: 3px solid transparent; }
.nav-item:hover { color: var(--text-primary); background: rgba(59, 130, 246, 0.08); }
.nav-item.active { color: var(--accent); background: rgba(59, 130, 246, 0.12); border-left-color: var(--accent); }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

/* ── Cards ── */
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 24px; }
.card-sm { padding: 16px; }
.stat-card { display: flex; align-items: flex-start; gap: 16px; }
.stat-icon { width: 48px; height: 48px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.stat-icon svg { width: 24px; height: 24px; }
.stat-value { font-size: 1.875rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: 0.8rem; color: var(--text-secondary); margin-top: 4px; }

/* ── Badges ── */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 0.72rem; font-weight: 600; }
.badge-online { background: rgba(16,185,129,0.15); color: var(--accent-green); }
.badge-offline { background: rgba(100,116,139,0.15); color: var(--text-muted); }
.badge-pending { background: rgba(245,158,11,0.15); color: var(--accent-yellow); }
.badge-banned { background: rgba(239,68,68,0.15); color: var(--accent-red); }
.badge-installed { background: rgba(16,185,129,0.15); color: var(--accent-green); }
.badge-failed { background: rgba(239,68,68,0.15); color: var(--accent-red); }
.badge-dispatched { background: rgba(59,130,246,0.15); color: var(--accent); }
.badge-executing { background: rgba(249,115,22,0.15); color: var(--accent-orange); }
.badge-active { background: rgba(59,130,246,0.15); color: var(--accent); }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 8px 16px; border-radius: 8px; font-size: 0.875rem; font-weight: 500; border: none; cursor: pointer; transition: all 0.15s; text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: rgba(239,68,68,0.15); color: var(--accent-red); border: 1px solid rgba(239,68,68,0.3); }
.btn-danger:hover { background: rgba(239,68,68,0.25); }
.btn-success { background: rgba(16,185,129,0.15); color: var(--accent-green); border: 1px solid rgba(16,185,129,0.3); }
.btn-success:hover { background: rgba(16,185,129,0.25); }
.btn-ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text-primary); background: rgba(255,255,255,0.05); }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }
.btn-icon { padding: 6px; border-radius: 6px; }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
th { padding: 10px 16px; text-align: left; font-size: 0.75rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; border-bottom: 1px solid var(--border); }
td { padding: 12px 16px; border-bottom: 1px solid rgba(51,65,85,0.5); vertical-align: middle; }
tr:hover td { background: rgba(255,255,255,0.02); }
.device-id { font-family: monospace; font-size: 0.8rem; color: var(--text-secondary); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
/* Device codes that link to the device page: larger, bold, neutral colour so they don't read as hyperlinks. */
a.device-code-link, a.device-id { font-family: monospace; font-size: 1rem; font-weight: 600; letter-spacing: 0.03em; color: var(--text-primary); text-decoration: none; }
a.device-code-link code { font-size: inherit; color: inherit; background: none; padding: 0; }
a.device-code-link:hover, a.device-id:hover { color: var(--text-primary); background: rgba(148,163,184,0.15); border-radius: 4px; }

/* ── Forms ── */
input, select, textarea { background: var(--bg-input); border: 1px solid var(--border); color: var(--text-primary); border-radius: 8px; padding: 8px 12px; font-size: 0.875rem; width: 100%; outline: none; transition: border-color 0.15s; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
label { display: block; font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 6px; font-weight: 500; }
.form-group { margin-bottom: 16px; }

/* ── Modals ── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 200; display: none; align-items: center; justify-content: center; }
.modal-backdrop.open { display: flex; }
.modal { background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px; padding: 28px; width: 520px; max-width: 95vw; }
.modal-title { font-size: 1.1rem; font-weight: 600; margin-bottom: 20px; }

/* ── Upload zone ── */
.upload-zone { border: 2px dashed var(--border); border-radius: 12px; padding: 48px; text-align: center; cursor: pointer; transition: all 0.2s; }
.upload-zone:hover, .upload-zone.drag-over { border-color: var(--accent); background: rgba(59,130,246,0.05); }
.upload-zone p { color: var(--text-secondary); margin: 8px 0 0; font-size: 0.875rem; }

/* ── Console ── */
.console-output { background: #0a0f1a; border: 1px solid var(--border); border-radius: 8px; padding: 16px; font-family: monospace; font-size: 0.8rem; max-height: 400px; overflow-y: auto; white-space: pre-wrap; word-break: break-all; }
.console-output .log-error { color: var(--accent-red); }
.console-output .log-info { color: var(--text-secondary); }

/* ── Charts ── */
.chart-container { position: relative; }

/* ── Grid ── */
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-6 { grid-template-columns: repeat(6, 1fr); }
@media (max-width: 1200px) { .grid-6 { grid-template-columns: repeat(3, 1fr); } .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 768px) { .grid-2, .grid-3, .grid-4, .grid-6 { grid-template-columns: 1fr; } .sidebar { transform: translateX(-100%); } .main-content { margin-left: 0; } }

/* ── Status dot ── */
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-online { background: var(--accent-green); box-shadow: 0 0 6px var(--accent-green); }
.dot-offline { background: var(--text-muted); }
.dot-pending { background: var(--accent-yellow); }

/* ── Tabs ── */
.tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 24px; gap: 4px; }
.tab { padding: 10px 16px; color: var(--text-secondary); cursor: pointer; font-size: 0.875rem; border-bottom: 2px solid transparent; transition: all 0.15s; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Page header ── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.page-title { font-size: 1.25rem; font-weight: 600; }
.page-subtitle { font-size: 0.875rem; color: var(--text-secondary); margin-top: 2px; }

/* ── SignalR connection indicator ── */
.connection-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 0.75rem; padding: 4px 10px; border-radius: 999px; background: rgba(16,185,129,0.1); color: var(--accent-green); }
.connection-badge.disconnected { background: rgba(239,68,68,0.1); color: var(--accent-red); }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Toast animation ── */
@keyframes slideInRight {
    from { opacity: 0; transform: translateX(40px); }
    to   { opacity: 1; transform: translateX(0); }
}

