:root {
  --bg:       #0f0f13;
  --surface:  #1a1a24;
  --border:   #2a2a38;
  --accent:   #7c6bff;
  --accent2:  #4fc3f7;
  --text:     #e8e8f0;
  --muted:    #888899;
  --danger:   #ff5252;
  --success:  #4caf50;
  --warn:     #ffb74d;
  --radius:   8px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Topbar ── */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-logo {
  font-weight: 700;
  font-size: 16px;
  color: var(--accent);
  margin-right: auto;
}
.topbar a { color: var(--muted); font-size: 13px; }
.topbar a:hover { color: var(--text); text-decoration: none; }
.topbar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}
.badge-admin {
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 600;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: opacity .15s;
}
.btn:hover { opacity: .85; }
.btn-primary  { background: var(--accent);  color: #fff; }
.btn-outline  { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--accent); }
.btn-danger   { background: var(--danger);  color: #fff; }
.btn-success  { background: var(--success); color: #fff; }
.btn-sm       { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .4; cursor: default; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

/* ── Form ── */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; margin-bottom: 4px; font-size: 12px; color: var(--muted); }
.form-control {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 12px;
  font-size: 14px;
}
.form-control:focus { outline: none; border-color: var(--accent); }
select.form-control { cursor: pointer; }

/* ── Status dot ── */
.dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-green  { background: var(--success); box-shadow: 0 0 5px var(--success); }
.dot-red    { background: var(--danger); }
.dot-yellow { background: var(--warn); }

/* ── Login page ── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-box {
  width: 340px;
}
.login-box h1 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--accent);
}
.login-box p { color: var(--muted); margin-bottom: 24px; font-size: 13px; }
.login-error {
  background: rgba(255,82,82,.12);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  color: var(--danger);
  padding: 8px 12px;
  margin-bottom: 16px;
  font-size: 13px;
}

/* ── Device grid (index) ── */
.page-wrap { max-width: 1200px; margin: 0 auto; padding: 24px 20px; }
.section-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
}
.devices-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.device-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: border-color .15s, transform .1s;
  text-decoration: none;
  color: var(--text);
  display: block;
}
.device-card:hover { border-color: var(--accent); transform: translateY(-1px); text-decoration: none; }
.device-card-header { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.device-name { font-weight: 600; font-size: 15px; }
.device-model { font-size: 12px; color: var(--muted); margin-top: 2px; }
.device-meta { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.device-meta span { display: flex; align-items: center; gap: 4px; }

/* ── Device detail layout ── */
.detail-layout {
  display: flex;
  height: calc(100vh - 52px);
}
.sidebar {
  width: 210px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.sidebar-header {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
}
.sidebar-device-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-model { font-size: 11px; color: var(--muted); margin-top: 2px; }
.sidebar-status { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.sidebar-nav { padding: 8px 0; flex: 1; }
.nav-section { padding: 6px 14px 2px; font-size: 10px; font-weight: 600; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  border-left: 2px solid transparent;
  transition: color .1s, border-color .1s;
}
.nav-item:hover  { color: var(--text); }
.nav-item.active { color: var(--text); border-left-color: var(--accent); background: rgba(124,107,255,.08); }
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }

.content-area {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.content-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.content-header h2 { font-size: 15px; font-weight: 600; flex: 1; }
.content-body { flex: 1; overflow-y: auto; padding: 16px 20px; }

/* ── Date filter bar ── */
.date-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 8px;
}
.date-bar span { font-size: 12px; min-width: 80px; text-align: center; }
.date-nav { background: none; border: none; color: var(--muted); cursor: pointer; padding: 2px 4px; font-size: 16px; line-height: 1; }
.date-nav:hover { color: var(--text); }

/* ── Tables / lists ── */
.data-list { display: flex; flex-direction: column; gap: 6px; }
.data-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
}
.data-item-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.data-item-title { font-size: 13px; font-weight: 500; }
.data-item-time { font-size: 11px; color: var(--muted); flex-shrink: 0; }
.data-item-body { font-size: 12px; color: var(--muted); margin-top: 4px; word-break: break-word; }
.data-item-meta { font-size: 11px; color: var(--muted); margin-top: 4px; display: flex; gap: 12px; }

/* ── Live stream ── */
.stream-container {
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  position: relative;
}
.stream-container img,
.stream-container canvas {
  max-width: 100%;
  max-height: 60vh;
  object-fit: contain;
  display: block;
}
.stream-placeholder {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 40px;
}

/* ── Status grid ── */
.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}
.stat-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.stat-label { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.stat-value { font-size: 18px; font-weight: 600; }
.stat-sub   { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ── Permissions ── */
.perm-list { display: flex; flex-direction: column; gap: 6px; }
.perm-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.perm-name { font-size: 13px; }
.perm-status { font-size: 11px; font-weight: 600; }
.perm-ok     { color: var(--success); }
.perm-fail   { color: var(--danger); }
.perm-warn   { color: var(--warn); }

/* ── Admin page ── */
.admin-wrap { max-width: 800px; margin: 0 auto; padding: 24px 20px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
td { font-size: 13px; }
tr:hover td { background: rgba(255,255,255,.02); }

/* ── Misc ── */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
  font-size: 13px;
}
.empty-state svg { width: 48px; height: 48px; opacity: .2; margin-bottom: 12px; }
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
}
.tag-in  { background: rgba(76,175,80,.15);  color: var(--success); }
.tag-out { background: rgba(79,195,247,.15); color: var(--accent2); }
.tag-mis { background: rgba(255,82,82,.15);  color: var(--danger); }
.gap-8  { gap: 8px; }
.flex   { display: flex; }
.flex-1 { flex: 1; }
.mt-12  { margin-top: 12px; }
.mt-16  { margin-top: 16px; }
.loader { color: var(--muted); font-size: 13px; padding: 20px; text-align: center; }

/* ── Commands panel ── */
.cmd-grid { display: flex; flex-wrap: wrap; gap: 8px; }
