:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --line: #d9dee7;
  --text: #17202c;
  --muted: #667085;
  --primary: #14746f;
  --primary-dark: #0f5f5b;
  --primary-soft: #e8f3f1;
  --blue: #1d4ed8;
  --danger: #b42318;
  --warn: #b54708;
  --ok: #067647;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  font-size: 14px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  padding: 0 14px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
}

button:hover {
  background: var(--primary-dark);
}

button.secondary {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

button.secondary:hover {
  background: #eef2f5;
}

button.danger {
  background: var(--danger);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

input,
select,
textarea {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
  color: var(--text);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.hidden {
  display: none !important;
}

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

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 18px;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.login-panel h1 {
  margin: 0 0 6px;
  font-size: 22px;
}

.login-panel p {
  margin: 0;
  color: var(--muted);
}

.form-error {
  min-height: 20px;
  color: var(--danger);
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px;
  border-right: 1px solid var(--line);
  background: #ffffff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.brand img {
  width: 38px;
  height: 38px;
  border-radius: 8px;
}

.brand div {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.brand strong {
  font-size: 18px;
}

.brand span {
  color: var(--muted);
}

.mobile-menu-button {
  display: none;
}

nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  justify-content: flex-start;
  width: 100%;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.nav-item.active,
.nav-item:hover {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.main {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
}

.topbar p {
  margin: 5px 0 0;
  color: var(--muted);
}

#view {
  min-width: 0;
  padding: 24px;
}

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

.stat-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.stat-card {
  padding: 18px;
}

.stat-card span {
  color: var(--muted);
}

.stat-card strong {
  display: block;
  margin-top: 10px;
  font-size: 30px;
}

.panel {
  margin-bottom: 18px;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-header h2 {
  margin: 0;
  font-size: 16px;
}

.panel-kicker {
  color: var(--muted);
  font-size: 13px;
}

.panel-body {
  padding: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.form-grid .span-2 {
  grid-column: span 2;
}

.form-grid .span-3 {
  grid-column: span 3;
}

.form-grid .span-4 {
  grid-column: span 4;
}

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

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

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  background: #f9fafb;
  color: var(--muted);
  font-weight: 600;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.admin-table input,
.admin-table select {
  min-width: 128px;
}

.admin-table input[name="password"] {
  min-width: 150px;
}

.admin-status-line {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.form-actions {
  margin-top: 14px;
}

.check-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 16px;
  max-height: 280px;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.check-list.compact {
  max-height: 150px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  color: var(--text);
}

.check-row input {
  width: 16px;
  min-height: 16px;
}

.scan-box {
  display: grid;
  gap: 14px;
}

.scan-video {
  width: 100%;
  max-height: 420px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111827;
}

.scan-note {
  color: var(--muted);
  line-height: 1.7;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  background: #edf2f7;
  color: var(--muted);
}

.badge.ok {
  background: #dcfae6;
  color: var(--ok);
}

.badge.warn {
  background: #fef0c7;
  color: var(--warn);
}

.badge.bad {
  background: #fee4e2;
  color: var(--danger);
}

.badge.blue {
  background: #dbeafe;
  color: var(--blue);
}

.muted {
  color: var(--muted);
}

.message {
  margin-top: 10px;
  color: var(--muted);
}

.dashboard-panel {
  margin-top: 18px;
}

.device-card-grid-wrap {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.device-card {
  width: 100%;
  min-height: 210px;
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--muted);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  text-align: left;
  box-shadow: 0 10px 24px rgb(15 23 42 / 6%);
}

.device-card:hover {
  background: #fbfdff;
  border-color: #b8c4d6;
}

.device-card.online {
  border-left-color: var(--ok);
}

.device-card.playing {
  border-left-color: var(--blue);
}

.device-card-head {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.device-card-head strong {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--muted);
}

.device-card.online .status-dot {
  background: var(--ok);
}

.device-card-meta {
  min-height: 20px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-card-task {
  display: grid;
  gap: 5px;
  padding: 12px;
  border: 1px solid #e6edf5;
  border-radius: 8px;
  background: #f8fbff;
}

.device-card-task span,
.device-card-grid span,
.detail-card span,
.progress-label {
  color: var(--muted);
  font-size: 12px;
}

.device-card-task b {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-card-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
}

.device-card-grid b {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-line {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7edf5;
}

.progress-line span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #14746f, #1d4ed8);
}

.progress-label {
  display: inline-block;
  margin-top: 4px;
}

.empty-state {
  min-height: 120px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fbfcfd;
}

.check-list.compact {
  max-height: 180px;
}

.link-button {
  min-height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--blue);
  font-weight: 700;
}

.link-button:hover {
  background: transparent;
  text-decoration: underline;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgb(15 23 42 / 38%);
}

.modal-panel {
  position: fixed;
  inset: 28px;
  z-index: 41;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 70px rgb(15 23 42 / 25%);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
}

.modal-header p {
  margin: 5px 0 0;
  color: var(--muted);
}

.modal-body {
  min-height: 0;
  overflow: auto;
  padding: 18px 22px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.detail-grid > div {
  display: grid;
  gap: 8px;
  min-height: 76px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.detail-grid span {
  color: var(--muted);
}

.detail-card {
  display: grid;
  gap: 8px;
  min-height: 82px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.detail-card strong {
  font-size: 18px;
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    gap: 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand {
    padding-bottom: 8px;
  }

  .mobile-menu-button {
    display: block;
    width: 100%;
  }

  .sidebar.mobile-collapsed nav,
  .sidebar.mobile-collapsed #logout-button {
    display: none;
  }

  nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .stats-grid,
  .detail-grid,
  .form-grid,
  .check-list {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 640px) {
  #view,
  .topbar,
  .sidebar {
    padding: 14px;
  }

  nav,
  .stats-grid,
  .detail-grid,
  .form-grid,
  .check-list {
    grid-template-columns: 1fr;
  }

  .modal-panel {
    inset: 10px;
  }

  .form-grid .span-2 {
    grid-column: span 1;
  }

  .form-grid .span-3,
  .form-grid .span-4 {
    grid-column: span 1;
  }
}
