:root {
  color-scheme: dark;
  --bg: #161c24;
  --panel: #202832;
  --ink: #f3f7fb;
  --muted: #a9b7c8;
  --line: #3a4656;
  --green: #35c971;
  --amber: #ffac35;
  --red: #ff5f68;
  --blue: #62a5ff;
  --teal: #2dd4bf;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  display: grid;
  grid-template-columns: 260px 1fr;
  transition: grid-template-columns 180ms ease;
}

body.sidebar-collapsed {
  grid-template-columns: 78px 1fr;
}

button,
input,
select,
textarea {
  font: inherit;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
}

.check-row input {
  width: 18px;
  min-height: 18px;
}

button {
  border: 1px solid #1f2937;
  background: #1f2937;
  color: white;
  min-height: 40px;
  border-radius: 6px;
  padding: 0 14px;
  cursor: pointer;
}

button:hover {
  background: #111827;
}

.sidebar {
  min-height: 100vh;
  padding: 22px 16px;
  background: #101820;
  color: white;
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
  position: relative;
}

.brand-copy {
  min-width: 150px;
}

.sidebar-toggle {
  position: absolute;
  right: -8px;
  width: 30px;
  min-height: 30px;
  padding: 0;
  border-color: #435467;
  background: #243241;
  font-size: 24px;
  line-height: 1;
}

body.sidebar-collapsed .brand-copy,
body.sidebar-collapsed .nav-item,
body.sidebar-collapsed .nav-group-label {
  display: none;
}

body.sidebar-collapsed .sidebar-toggle {
  right: 8px;
  top: 56px;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: #2dd4bf;
  color: #062620;
  font-size: 10px;
  font-weight: 800;
}

.brand small {
  display: block;
  color: #b9c4ce;
  margin-top: 4px;
}

nav {
  display: grid;
  gap: 18px;
}

.nav-group {
  display: grid;
  gap: 6px;
}

.nav-group-label {
  color: #7f91a5;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .08em;
  padding: 0 12px 3px;
  text-transform: uppercase;
}

.nav-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border-color: transparent;
  color: #d6dee6;
}

.nav-item:hover,
.nav-item.active {
  background: #243241;
  color: white;
}

.shell {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 22px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.2;
}

h2 {
  font-size: 18px;
}

.topbar p {
  color: var(--muted);
  margin-top: 6px;
}

.icon-btn {
  width: 44px;
  padding: 0;
  font-size: 22px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric {
  padding: 18px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 10px;
}

.metric strong {
  font-size: 34px;
  line-height: 1;
}

.metric.ok strong {
  color: var(--green);
}

.metric.warn strong {
  color: var(--amber);
}

.metric.off strong {
  color: var(--red);
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 18px;
  margin-bottom: 18px;
}

.mode-bar {
  display: inline-flex;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 6px;
  margin-bottom: 14px;
}

.mode-btn {
  background: transparent;
  color: var(--ink);
  border-color: transparent;
}

.mode-btn.active {
  background: #1f2937;
  color: white;
}

.panel {
  padding: 18px;
  min-width: 0;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
}

.panel-head span {
  color: var(--muted);
  font-size: 13px;
}

.device-health,
.list {
  display: grid;
  gap: 10px;
}

.health-row,
.list-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #252e39;
}

.health-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 76px;
  height: 28px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.status.online {
  color: #14532d;
  background: #dcfce7;
}

.status.warning {
  color: #7c2d12;
  background: #ffedd5;
}

.status.offline {
  color: #7f1d1d;
  background: #fee2e2;
}

.status.queued {
  color: #854d0e;
  background: #fef3c7;
}

.status.sent {
  color: #1d4ed8;
  background: #dbeafe;
}

.status.done {
  color: #166534;
  background: #dcfce7;
}

.status.failed {
  color: #b91c1c;
  background: #fee2e2;
}

.command-history-table {
  min-width: 760px;
}

.command-history-table td {
  vertical-align: middle;
}

.command-history-table .status {
  min-width: 70px;
}

.empty-history {
  color: var(--muted);
  text-align: center;
  padding: 28px;
}

.history-filters {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
}

.history-search {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 360px;
  min-width: 220px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: #1a212a;
}

.history-search input,
.history-filters select {
  height: 38px;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  font: inherit;
}

.history-search input {
  width: 100%;
}

.history-filters select {
  width: 160px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #1a212a;
}

.form-grid {
  display: grid;
  gap: 10px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #1a212a;
  color: var(--ink);
  min-height: 40px;
  padding: 9px 10px;
}

textarea {
  resize: vertical;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

th,
td {
  text-align: left;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.enroll-layout {
  display: grid;
  grid-template-columns: 420px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.enroll-qr img {
  display: block;
  width: 100%;
  max-width: 340px;
  margin: 8px auto 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.qr-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.qr-actions select {
  min-width: 150px;
}

.qr-dialog {
  position: relative;
  width: min(90vw, 760px);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--ink);
}

.qr-dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.qr-dialog img {
  display: block;
  width: min(100%, 680px);
  margin: 0 auto;
  border-radius: 8px;
  image-rendering: pixelated;
}

.qr-dialog p {
  margin-top: 16px;
  color: var(--muted);
  text-align: center;
}

.qr-dialog-close {
  position: absolute;
  top: 8px;
  right: 8px;
  min-height: 34px;
  width: 34px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.diagnostics {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.diag {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  font-size: 13px;
  background: #252e39;
}

.diag.ok {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: #166534;
}

.diag.bad {
  border-color: #fecaca;
  background: #fef2f2;
  color: #991b1b;
}

pre {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  background: #101820;
  color: #d8fff7;
  border-radius: 8px;
  padding: 14px;
  max-height: 640px;
  overflow: auto;
  font-size: 13px;
}

#wifi-chip {
  border: 1px solid #a7f3d0;
  background: #ecfdf5;
  color: #065f46;
  border-radius: 999px;
  padding: 5px 10px;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-item {
  display: grid;
  gap: 6px;
}

.list-item strong {
  font-size: 15px;
}

.meta {
  color: var(--muted);
  font-size: 13px;
}

.inline-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.apk-deploy-panel {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.apk-deploy-panel h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

.apk-deploy-panel select[multiple] {
  min-height: 180px;
}

.deploy-all-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.danger-action {
  color: #fff;
  border-color: #ad3841;
  background: #8f2931;
}

.default-app-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

.default-app-toggle:has(input:checked) {
  border-color: #28a76b;
  color: #d7ffe8;
  background: rgba(40, 167, 107, 0.18);
}

.device-console {
  background: #071326;
  color: #edf7ff;
  border: 1px solid #17345d;
  border-radius: 8px;
  overflow: hidden;
}

.device-console-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid #183a66;
  background: #091b35;
}

.device-console-head h2 {
  color: white;
}

.device-console-head span,
.device-meta {
  color: #9fb6d4;
  font-size: 13px;
}

.device-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.device-filters {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid #183a66;
  background: #08182f;
}

.device-search {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 320px;
  min-width: 220px;
  padding: 0 10px;
  border: 1px solid #31537d;
  border-radius: 6px;
  color: #9fb6d4;
  background: #061226;
}

.device-search input,
.device-filters select {
  height: 34px;
  border: 0;
  outline: 0;
  color: #edf7ff;
  background: transparent;
  font: inherit;
}

.device-search input {
  width: 100%;
}

.device-filters select {
  min-width: 220px;
  padding: 0 8px;
  border: 1px solid #31537d;
  border-radius: 6px;
  background: #061226;
}

.filter-clear {
  min-height: 34px;
  padding: 0 10px;
  color: #b9cbe2;
  border-color: #31537d;
  background: transparent;
}

.device-actions button,
.mini-btn {
  min-height: 30px;
  border-color: #25f4e8;
  background: rgba(37, 244, 232, 0.12);
  color: #68fff7;
  padding: 0 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
}

.device-actions .danger-action {
  border-color: #ff5d72;
  background: rgba(255, 93, 114, 0.12);
  color: #ff9aa8;
}

.device-list-head,
.device-row {
  display: grid;
  grid-template-columns: 32px 82px minmax(250px, 1.5fr) 130px 100px 120px 125px 150px;
  align-items: center;
  gap: 10px;
}

.device-list-head {
  padding: 8px 16px;
  color: #7fa2cc;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid #15365f;
}

.sort-head {
  position: relative;
  min-height: 24px;
  padding: 0 15px 0 0;
  border: 0;
  border-radius: 0;
  color: inherit;
  background: transparent;
  font: inherit;
  font-weight: 700;
  letter-spacing: inherit;
  text-align: left;
  text-transform: inherit;
}

.sort-head::after {
  position: absolute;
  right: 1px;
  color: #4a6f9d;
  content: "↕";
}

.sort-head.active {
  color: #68fff7;
}

.sort-head.active[data-direction="asc"]::after {
  color: #68fff7;
  content: "↑";
}

.sort-head.active[data-direction="desc"]::after {
  color: #68fff7;
  content: "↓";
}

.device-row {
  min-height: 78px;
  padding: 9px 16px;
  border-bottom: 1px solid #17345d;
  background: linear-gradient(90deg, rgba(21, 44, 84, 0.46), rgba(10, 24, 48, 0.2));
}

.device-row:nth-child(even) {
  background: linear-gradient(90deg, rgba(28, 55, 100, 0.62), rgba(10, 24, 48, 0.32));
}

.row-check {
  width: 20px;
  height: 20px;
  min-height: 20px;
  accent-color: #25f4e8;
}

.device-main {
  min-width: 0;
}

.device-id-cell {
  color: #68fff7;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.device-title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: white;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.15;
}

.edit-mark {
  width: 30px;
  height: 30px;
  min-height: 30px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(232, 238, 255, 0.28);
  background: rgba(255, 255, 255, 0.08);
  color: #e8eeff;
  font-size: 18px;
  border-radius: 8px;
  cursor: pointer;
}

.edit-mark:hover {
  border-color: #2dd4bf;
  color: white;
  background: rgba(45, 212, 191, 0.14);
}

.tag {
  display: inline-flex;
  width: fit-content;
  border: 1px solid #2e7be8;
  color: #b9dcff;
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 700;
  margin-top: 4px;
}

.model-tag {
  display: inline-block;
  margin: 4px 0 0 6px;
  padding: 3px 8px;
  border-radius: 999px;
  color: #071326;
  background: #68fff7;
  font-size: 12px;
  font-weight: 800;
}

.status-stack {
  display: grid;
  gap: 8px;
  font-weight: 700;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  display: inline-block;
  margin-right: 8px;
}

.dot.online {
  background: #25f4e8;
  box-shadow: 0 0 12px #25f4e8;
}

.dot.warning,
.dot.offline {
  background: #ffdc4a;
  box-shadow: 0 0 12px #ffdc4a;
}

.app-count {
  color: white;
  font-size: 22px;
  font-weight: 900;
}

.control-icons {
  display: flex;
  gap: 10px;
}

.control-icon {
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid #ff5ed7;
  color: #ffd0f3;
  border-radius: 9px;
  background: rgba(255, 66, 188, 0.16);
}

.danger-icon {
  border-color: #ff6b8a;
  color: #ffd6de;
  background: rgba(255, 64, 100, 0.16);
}

.battery-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  color: white;
  font-weight: 800;
}

.battery {
  width: 42px;
  height: 20px;
  border: 3px solid #25f4e8;
  border-radius: 5px;
  padding: 2px;
  position: relative;
}

.battery::after {
  content: "";
  position: absolute;
  right: -8px;
  top: 5px;
  width: 4px;
  height: 8px;
  border-radius: 0 3px 3px 0;
  background: currentColor;
}

.battery-fill {
  height: 100%;
  border-radius: 2px;
  background: #25f4e8;
}

.battery.low {
  border-color: #ff6b8a;
  color: #ff6b8a;
}

.battery.low .battery-fill {
  background: #ff6b8a;
}

.battery.mid {
  border-color: #ffd94a;
  color: #ffd94a;
}

.battery.mid .battery-fill {
  background: #ffd94a;
}

.uptime-pill {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  gap: 7px;
  border: 1px solid #26e9ff;
  background: rgba(38, 233, 255, 0.15);
  color: #8dfff8;
  border-radius: 8px;
  padding: 6px 12px;
  font-weight: 900;
}

.ready-cell {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #d9ecff;
  font-weight: 800;
}

.toggle {
  width: 54px;
  height: 28px;
  border-radius: 999px;
  background: #102744;
  border: 1px solid #244a77;
  padding: 3px;
}

.toggle::before {
  content: "";
  display: block;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: #9beeff;
  box-shadow: 0 0 12px rgba(155, 238, 255, 0.8);
}

@media (max-width: 1180px) {
  .device-console {
    overflow-x: auto;
  }

  .device-list-head,
  .device-row {
    min-width: 1020px;
  }
}

@media (max-width: 980px) {
  body {
    grid-template-columns: 1fr;
  }

  body.sidebar-collapsed {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
  }

  nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .metrics,
  .split,
  .enroll-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .history-filters {
    align-items: stretch;
    flex-direction: column;
  }

  .history-filters select {
    width: 100%;
  }

  .device-filters {
    align-items: stretch;
    flex-direction: column;
  }

  .device-filters select {
    min-width: 0;
  }

  .shell {
    padding: 18px;
  }

  nav {
    grid-template-columns: 1fr 1fr;
  }

  .topbar {
    align-items: flex-start;
  }
}
