:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #202941;
  --muted: #7c879b;
  --line: #e8edf5;
  --accent: #5969e8;
  --soft: #eef0ff;
  --shadow: 0 10px 30px #23335a0a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111521;
    --panel: #191f2e;
    --text: #e8ecf6;
    --muted: #929db2;
    --line: #292f40;
    --accent: #8992ff;
    --soft: #252b48;
    --shadow: 0 10px 30px #0001;
  }
  .online { background: #1d3a32; color: #7fe0b3; }
  .offline { background: #292f3d; color: #a5afc1; }
  .warning { background: #403621; color: #efc36b; }
  .samsung { background: #2a3156; color: #aab2ff; }
  .redmi { background: #403023; color: #f5b27b; }
  .infinix { background: #1e3c36; color: #7fe0b3; }
  .demo { background: #302948; color: #c2b0ff; }
  .green-bg { background: #1e3c36; }
  .blue-bg { background: #2a3156; }
  .amber-bg { background: #403522; }
  .secondary { border-color: #3b4164; }
}

body.light-mode {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #202941;
  --muted: #7c879b;
  --line: #e8edf5;
  --accent: #5969e8;
  --soft: #eef0ff;
  --shadow: 0 10px 30px #23335a0a;
}

body.dark-mode {
  --bg: #111521;
  --panel: #191f2e;
  --text: #e8ecf6;
  --muted: #929db2;
  --line: #292f40;
  --accent: #8992ff;
  --soft: #252b48;
  --shadow: 0 10px 30px #0001;
}

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

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.sidebar {
  width: 240px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 22px 16px;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 22px;
}

.logo {
  width: 32px;
  height: 32px;
  background: var(--accent);
  color: #fff;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-weight: 800;
  box-shadow: 0 5px 15px #5969e83d;
}

.brand b {
  display: block;
  font-size: 13px;
  letter-spacing: -0.2px;
  color: var(--text);
}

.brand small {
  font-size: 9px;
  color: var(--muted);
}

.label {
  font-size: 8px;
  letter-spacing: 1px;
  color: #909bb0;
  font-weight: 800;
  margin: 16px 0 6px 10px;
}

nav a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 9px;
  color: var(--muted);
  text-decoration: none;
  font-size: 11px;
  font-weight: 650;
  margin-bottom: 3px;
  transition: 0.15s;
}

nav a:hover, nav a.active {
  background: var(--soft);
  color: var(--accent);
}

nav a i, nav a .badge-count {
  margin-left: auto;
  font-style: normal;
  background: var(--line);
  color: var(--text);
  font-size: 8px;
  padding: 2px 6px;
  border-radius: 10px;
}

.profile {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.avatar {
  width: 29px;
  height: 29px;
  border-radius: 50%;
  background: var(--soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 11px;
}

.profile b {
  display: block;
  font-size: 10px;
  color: var(--text);
}

.profile small {
  font-size: 8px;
  color: var(--muted);
}

main {
  flex: 1;
  margin-left: 240px;
  padding: 0 32px 30px;
  max-width: 1380px;
  width: calc(100% - 240px);
}

header {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.crumb {
  font-size: 11px;
  color: var(--muted);
}

.crumb span {
  margin: 0 4px;
  color: var(--text);
}

.top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.top input {
  width: 190px;
  height: 37px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  background: var(--panel);
  color: var(--text);
  font-size: 11px;
  transition: 0.2s;
}

.top input:focus {
  width: 240px;
  border-color: var(--accent);
  outline: 0;
}

.icon {
  width: 37px;
  height: 37px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--muted);
  font-size: 17px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: 0.15s;
}

.icon:hover {
  background: var(--soft);
  color: var(--accent);
}

.mobile {
  display: none;
}

.heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 31px 0 24px;
  gap: 18px;
}

.eyebrow {
  font-size: 10px;
  letter-spacing: 1.5px;
  color: #939eb2;
  font-weight: 800;
}

.heading h1 {
  font-size: clamp(25px, 3vw, 34px);
  letter-spacing: -1.2px;
  margin: 10px 0;
  color: var(--text);
}

.heading h1 em {
  font-style: normal;
  color: #717ded;
}

.heading p, .panel-head p {
  font-size: 11px;
  color: var(--muted);
  margin: 0;
}

.primary, .secondary {
  border: 0;
  border-radius: 10px;
  padding: 12px 15px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 750;
  cursor: pointer;
  box-shadow: 0 7px 17px #5969e82b;
  transition: 0.2s;
}

.primary:hover, .secondary:hover {
  transform: translateY(-2px);
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 15px;
}

.stats article {
  position: relative;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 18px;
  box-shadow: var(--shadow);
  animation: rise 0.5s both;
}

.stats article:nth-child(2) { animation-delay: 0.06s; }
.stats article:nth-child(3) { animation-delay: 0.12s; }
.stats article:nth-child(4) { animation-delay: 0.18s; }

.stats small {
  font-size: 11px;
  color: var(--muted);
  font-weight: 650;
}

.stats strong {
  display: block;
  font-size: 30px;
  letter-spacing: -1px;
  margin: 12px 0 3px;
  color: var(--text);
}

.stats p {
  font-size: 10px;
  color: var(--muted);
}

.green { color: #24a477 !important; }
.amber { color: #d79b32 !important; }

.chart {
  position: absolute;
  right: 18px;
  bottom: 18px;
  width: 66px;
  height: 28px;
  opacity: 0.45;
  background: repeating-linear-gradient(90deg, #8795f5 0 5px, transparent 5px 10px);
  clip-path: polygon(0 80%, 15% 50%, 28% 67%, 42% 15%, 57% 55%, 72% 0, 86% 37%, 100% 10%, 100% 100%, 0 100%);
}

.green-chart { filter: hue-rotate(80deg); }
.orange { filter: hue-rotate(240deg); }
.purple { filter: hue-rotate(35deg); }

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(270px, 1fr);
  gap: 15px;
  margin-top: 17px;
}

.panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 15px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 20px 15px;
  gap: 10px;
}

.panel-head h2 {
  font-size: 14px;
  margin: 0 0 5px;
  letter-spacing: -0.3px;
  color: var(--text);
}

.link {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 10px;
  font-weight: 750;
  cursor: pointer;
}

.tablewrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
}

th {
  font-size: 9px;
  letter-spacing: 0.7px;
  color: #9aa4b6;
  text-align: left;
  background: var(--bg);
  padding: 12px 13px;
}

td {
  font-size: 10px;
  padding: 14px 13px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}

td:first-child, th:first-child { padding-left: 20px; }
tbody tr:hover { background: var(--soft); }
tbody tr:last-child td { border-bottom: 0; }

.device {
  display: flex;
  align-items: center;
  gap: 9px;
}

.device b, .device small { display: block; }
.device b { font-size: 10px; color: var(--text); }
.device small { font-size: 9px; margin-top: 4px; }

.phone {
  width: 32px;
  height: 38px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-weight: 800;
}

.samsung { background: #edf0ff; color: #5969e8; }
.redmi { background: #fff0e4; color: #df8c40; }
.infinix { background: #e3f7ed; color: #22a477; }

.status {
  padding: 6px 7px;
  border-radius: 7px;
  font-size: 9px;
  font-weight: 750;
}

.online { background: #e5f8ee; color: #219765; }
.offline { background: #f0f2f6; color: #778197; }
.warning { background: #fff3df; color: #c88b1d; }

.battery {
  display: inline-block;
  width: 35px;
  height: 5px;
  border-radius: 5px;
  background: #e8edf4;
  vertical-align: middle;
  margin-right: 5px;
  overflow: hidden;
}

.battery i {
  display: block;
  height: 100%;
  background: #38b985;
  border-radius: 5px;
}

.more {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 17px;
  cursor: pointer;
}

.foot {
  display: flex;
  justify-content: space-between;
  padding: 13px 20px;
  border-top: 1px solid var(--line);
  font-size: 10px;
  color: var(--muted);
}

.foot span { color: var(--accent); }

.demo {
  font-size: 8px;
  font-weight: 800;
  color: #7e68d2;
  background: #f0edff;
  padding: 6px 8px;
  border-radius: 7px;
}

.health {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 6px 20px 20px;
}

.ring {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(closest-side, var(--panel) 82%, transparent 84%), conic-gradient(#717df0 94%, #edf0f6 0);
  font-size: 21px;
  font-weight: 800;
  color: var(--text);
}

.health > div:last-child b { font-size: 11px; color: var(--text); }
.health p, .note { font-size: 9px; color: var(--muted); line-height: 1.6; }

.health-row {
  display: flex;
  align-items: center;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding: 12px 20px;
  font-size: 10px;
  color: var(--muted);
}

.health-row > span { color: #32b987; }
.health-row b { margin-left: auto; color: var(--text); font-size: 10px; }
.health-row .warn { color: #dfa83b; }

.note {
  padding: 10px 20px;
  background: var(--bg);
  margin: 0;
}

.lower { grid-template-columns: minmax(0, 1.55fr) minmax(270px, 1fr); }

.activity {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 20px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}

.activity:last-child { border: 0; }

.event {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  font-weight: 800;
}

.green-bg { background: #e5f8ee; color: #24a477; }
.blue-bg { background: #edf0ff; color: #5969e8; }
.amber-bg { background: #fff3df; color: #d79b32; }

.activity div { flex: 1; }
.activity b, .activity small { display: block; }
.activity b { font-size: 10px; color: var(--text); }
.activity small { font-size: 9px; color: var(--muted); margin-top: 4px; }
.activity time { font-size: 9px; color: var(--muted); white-space: nowrap; }

.privacy-icon { font-size: 22px; color: var(--accent); }

.privacy-box {
  background: var(--soft);
  border-radius: 11px;
  margin: 0 19px 12px;
  padding: 13px;
  font-size: 10px;
  color: var(--text);
}

.privacy-box p { font-size: 9px; line-height: 1.6; color: var(--muted); margin: 6px 0 0; }

.perm {
  display: flex;
  justify-content: space-between;
  padding: 11px 20px;
  border-bottom: 1px solid var(--line);
  font-size: 10px;
  color: var(--text);
}

.perm b { font-size: 9px; color: var(--muted); }

.secondary {
  margin: 15px 19px 18px;
  width: calc(100% - 38px);
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--accent);
  box-shadow: none;
}

footer {
  display: flex;
  justify-content: space-between;
  padding: 24px 2px 4px;
  font-size: 9px;
  color: #9aa4b6;
}

/* Modals & Views */
.view-content {
  display: none;
}

.view-content.active {
  display: block;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 1;
  transition: opacity 0.2s ease;
}

.modal-overlay.hidden {
  display: none;
  opacity: 0;
  pointer-events: none;
}

.auth-card, .modal-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
  width: 90%;
  max-width: 440px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.auth-header {
  text-align: center;
  margin-bottom: 22px;
}

.logo-badge {
  width: 42px;
  height: 42px;
  background: var(--accent);
  color: #fff;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 20px;
  font-weight: 800;
  margin: 0 auto 12px;
  box-shadow: 0 6px 18px #5969e83d;
}

.auth-header h2 {
  font-size: 18px;
  margin-bottom: 4px;
  color: var(--text);
}

.auth-header p {
  font-size: 11px;
  color: var(--muted);
}

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

.form-group label {
  display: block;
  font-size: 10px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 11px;
}

.form-group input:focus {
  border-color: var(--accent);
  outline: 0;
}

.auth-hint {
  margin-top: 14px;
  color: var(--muted);
  font-size: 10px;
  text-align: center;
}

/* Pairing Code */
.pairing-code-display {
  font-size: 32px;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 800;
  letter-spacing: 6px;
  color: var(--accent);
  background: var(--soft);
  border: 1px dashed var(--accent);
  padding: 16px;
  border-radius: 12px;
  margin: 12px auto;
  max-width: 300px;
  text-align: center;
}

/* Tabs Bar */
.tabs-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 12px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.tab-btn {
  padding: 8px 14px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
  transition: 0.15s;
}

.tab-btn:hover, .tab-btn.active {
  background: var(--soft);
  color: var(--accent);
  border-color: var(--accent);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* Drawer */
.drawer-overlay {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 380px;
  max-width: 100%;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -10px 0 30px rgba(0, 0, 0, 0.15);
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: 900;
}

.drawer-overlay.open {
  transform: translateX(0);
}

/* Pulse Dot */
.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #24a477;
  display: inline-block;
  box-shadow: 0 0 8px #24a477;
  animation: liveDot 1.6s infinite ease-in-out;
}

@keyframes liveDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

/* Toast */
#toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  background: #20283a;
  color: white;
  border-radius: 10px;
  padding: 12px 15px;
  font-size: 12px;
  opacity: 0;
  transform: translateY(8px);
  transition: 0.2s;
  pointer-events: none;
  z-index: 1500;
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 1100px) {
  main { padding: 0 20px; width: calc(100% - 215px); }
  .sidebar { width: 215px; }
  main { margin-left: 215px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 700px) {
  .sidebar {
    transform: translateX(-105%);
    transition: transform 0.25s;
    width: 255px;
    box-shadow: 10px 0 35px #0002;
  }
  .sidebar.open { transform: translateX(0); }
  main { margin-left: 0; padding: 0 13px 18px; width: 100%; }
  header { height: 61px; }
  .mobile { display: block; }
  .top { gap: 6px; }
  .top input { width: 35px; padding: 0 8px; }
  .top input:focus { width: 145px; }
  .heading { align-items: flex-start; flex-direction: column; padding: 24px 0 19px; }
  .heading h1 { font-size: 27px; }
  .stats { gap: 9px; }
  .stats article { padding: 14px; }
  .stats strong { font-size: 27px; }
  .chart { display: none; }
  .grid { gap: 11px; margin-top: 12px; }
  .panel-head { padding: 16px 14px 12px; }
  .tablewrap { overflow-x: auto; }
  .tablewrap table { min-width: 600px; }
  td:first-child, th:first-child { padding-left: 14px; }
  .health { padding: 5px 14px 17px; }
  .health-row { padding: 11px 14px; }
  .note { padding: 10px 14px; }
  .activity { margin: 0 14px; }
  .privacy-box { margin: 0 14px 10px; }
  .perm { padding: 11px 14px; }
  .secondary { margin: 14px; width: calc(100% - 28px); }
  footer { gap: 10px; line-height: 1.5; }
}
