:root {
  --bg: #0a0812;
  --panel: #16131f;
  --panel-2: #1c1828;
  --panel-3: #221d30;
  --border: #292236;
  --text: #e9e7f2;
  --muted: #8b86a3;
  --accent: #8b5cf6;
  --accent-2: #a78bfa;
  --live: #ef4444;
  --ok: #22c55e;
  --warn: #f59e0b;
  --radius: 14px;
  --radius-sm: 9px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.muted { color: var(--muted); }
code { font-family: "JetBrains Mono", ui-monospace, "SF Mono", Consolas, monospace; font-size: .9em; }
a { color: var(--accent-2); }

/* ---------- login ---------- */

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }

.login-card {
  width: 100%; max-width: 380px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 32px;
  display: flex; flex-direction: column; gap: 14px;
}
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.login-card h1 { font-size: 20px; font-weight: 600; }
.login-card input {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 11px 13px; color: var(--text); font-size: 14px; font-family: inherit;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-error {
  background: rgba(239, 68, 68, .12); border: 1px solid rgba(239, 68, 68, .35);
  color: #fca5a5; border-radius: var(--radius-sm); padding: 9px 12px; font-size: 13px;
}
.login-hint { font-size: 12px; color: var(--muted); }

/* ---------- shell ---------- */

.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 18px; padding: 20px 14px;
  position: sticky; top: 0; height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 8px; }
.logo-mark {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  background: linear-gradient(140deg, var(--accent-2), var(--accent));
  position: relative;
}
.logo-mark::after {
  content: ""; position: absolute; inset: 9px;
  background: #fff; border-radius: 50%;
}
.logo-text { font-weight: 700; letter-spacing: .4px; font-size: 16px; }

.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px; border-radius: var(--radius-sm);
  color: var(--muted); text-decoration: none; font-size: 13.5px;
}
.nav a:hover { background: var(--panel-2); color: var(--text); }
.nav a.active { background: var(--accent); color: #fff; font-weight: 500; }
.nav a .ico { width: 17px; text-align: center; opacity: .85; flex: none; }
.nav .tag {
  margin-left: auto; font-size: 10px; letter-spacing: .3px;
  padding: 2px 6px; border-radius: 5px;
  background: var(--panel-3); color: var(--muted);
}
.nav a.active .tag { background: rgba(255,255,255,.22); color: #fff; }

.sidebar-foot { display: flex; flex-direction: column; gap: 12px; }
.storage-mini { background: var(--panel-2); border-radius: var(--radius-sm); padding: 11px 12px; font-size: 12px; }
.storage-mini-head { display: flex; justify-content: space-between; margin-bottom: 7px; }
.bar { height: 5px; background: var(--bg); border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .4s; }

/* ---------- topbar ---------- */

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 20px 26px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: rgba(10, 8, 18, .88);
  backdrop-filter: blur(8px); z-index: 5;
}
.topbar h1 { font-size: 19px; font-weight: 600; }
.topbar-title p { font-size: 12.5px; margin-top: 2px; }
.topbar-right { display: flex; align-items: center; gap: 14px; font-size: 12.5px; }

.conn { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.conn .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.conn.stale .dot { background: var(--warn); }
.conn.down .dot { background: var(--live); }

.content { padding: 22px 26px 40px; display: flex; flex-direction: column; gap: 18px; }

/* ---------- primitives ---------- */

.grid { display: grid; gap: 16px; }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); }

.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 17px 18px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 14px;
}
.card-head h2 { font-size: 14.5px; font-weight: 600; }
.card-head .sub { font-size: 12px; color: var(--muted); }

.stat .stat-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.stat .label { font-size: 12.5px; color: var(--muted); }
.stat .value { font-size: 27px; font-weight: 650; margin-top: 9px; letter-spacing: -.5px; }
.stat .delta { font-size: 12px; margin-top: 5px; }
.stat .chip {
  font-size: 10.5px; padding: 3px 8px; border-radius: 6px;
  background: var(--panel-3); color: var(--muted); white-space: nowrap;
}
.chip.rec { background: rgba(239, 68, 68, .16); color: #fca5a5; }
.chip.ok { background: rgba(34, 197, 94, .15); color: #86efac; }
.chip.warn { background: rgba(245, 158, 11, .15); color: #fcd34d; }

.btn {
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  padding: 9px 14px; border-radius: var(--radius-sm); font: inherit; font-size: 13px;
  cursor: pointer; display: inline-flex; align-items: center; gap: 7px; justify-content: center;
}
.btn:hover { background: var(--panel-3); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-danger { background: rgba(239,68,68,.14); border-color: rgba(239,68,68,.4); color: #fca5a5; }
.btn-danger:hover { background: rgba(239,68,68,.24); }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.list { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 2px; border-bottom: 1px solid var(--border);
}
.row:last-child { border-bottom: none; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-size: 13.5px; font-weight: 500; }
.row .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  background: linear-gradient(140deg, var(--accent-2), var(--accent));
  display: grid; place-items: center; font-size: 13px; font-weight: 600; color: #fff;
}
.state-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--muted); }
.state-dot.live { background: var(--live); box-shadow: 0 0 0 3px rgba(239,68,68,.18); }
.state-dot.rec { background: var(--live); }
.state-dot.ok { background: var(--ok); }
.state-dot.err { background: var(--warn); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 9px 16px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { text-align: right; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; font-weight: 500; color: var(--muted); font-size: 12px;
  padding: 0 10px 9px 0; border-bottom: 1px solid var(--border);
}
td { padding: 10px 10px 10px 0; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; padding-right: 0; }

.empty { padding: 28px 8px; text-align: center; color: var(--muted); font-size: 13px; }

/* Marks data the backend genuinely cannot supply yet, so an empty panel is never
   mistaken for "no activity". */
.pending {
  border-style: dashed; background: transparent;
}
.pending .card-head h2 { color: var(--muted); }
.pending-body { display: flex; flex-direction: column; gap: 9px; align-items: flex-start; }
.pending-badge {
  font-size: 10.5px; letter-spacing: .3px; text-transform: uppercase;
  padding: 3px 8px; border-radius: 6px;
  background: rgba(139, 92, 246, .14); color: var(--accent-2);
}
.pending p { font-size: 12.5px; color: var(--muted); max-width: 52ch; }

.banner {
  display: flex; gap: 11px; align-items: flex-start;
  border-radius: var(--radius); padding: 13px 15px; font-size: 13px;
  background: rgba(245, 158, 11, .1); border: 1px solid rgba(245, 158, 11, .3); color: #fcd34d;
}
.banner.err { background: rgba(239,68,68,.1); border-color: rgba(239,68,68,.32); color: #fca5a5; }

video { width: 100%; border-radius: var(--radius-sm); background: #000; display: block; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; color: var(--muted); }
.field input {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 12px; color: var(--text); font: inherit; font-size: 13px;
}
.field input:focus { outline: none; border-color: var(--accent); }
.inline-form { display: flex; gap: 9px; align-items: flex-end; flex-wrap: wrap; }

pre {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; overflow-x: auto; font-size: 12.5px; line-height: 1.65;
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav .tag { display: none; }
}
