:root {
  --bg: #f7f4f0;
  --panel: #ffffff;
  --sidebar: #2b2622;
  --sidebar-text: #d8cfc6;
  --accent: #f47c75;
  --text: #312a27;
  --muted: #8a7c74;
  --border: #e5ddd4;
  --ok: #3b9a5c;
  --fail: #d64541;
}

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

html, body {
  height: 100%;
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  color: var(--text);
  background: var(--bg);
}

body { display: flex; min-height: 100vh; }

#sidebar {
  width: 200px;
  flex: none;
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
}

.brand {
  padding: 20px 16px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.brand-title { font-size: 18px; font-weight: 700; color: #fff; }
.brand-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

#nav { flex: 1; overflow-y: auto; padding: 8px 0; }
#nav { scrollbar-width: none; }
#nav::-webkit-scrollbar { display: none; width: 0; height: 0; }

.nav-group {
  font-size: 12px;
  color: var(--muted);
  padding: 10px 16px 4px;
}

.nav-actions {
  display: flex;
  gap: 6px;
  padding: 2px 10px 8px;
}

.nav-stat {
  font-size: 11px;
  color: var(--muted);
  padding: 2px 14px 8px;
}

.nav-action {
  flex: 1;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--sidebar-text);
  font-size: 12px;
  padding: 5px 4px;
  cursor: pointer;
}

.nav-action:hover { background: rgba(255, 255, 255, 0.14); }

.nav-device {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-device .nd-main {
  font-size: 12px;
  word-break: break-all;
  line-height: 1.3;
}

.nav-device .nd-tags { display: flex; gap: 4px; }
.nav-device .nd-tag {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--muted);
}

.nav-device .nd-online.on {
  background: rgba(59, 154, 92, 0.35);
  color: #bde8cb;
}

.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--sidebar-text);
  font-size: 14px;
  padding: 8px 16px;
  cursor: pointer;
}

.nav-item:hover { background: rgba(255,255,255,0.06); }
.nav-item:active { background: rgba(255,255,255,0.16); }
.nav-item.active { background: var(--accent); color: #fff; }

#device-state {
  padding: 10px 16px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid rgba(255,255,255,0.08);
}

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

#page-root {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  background: var(--bg);
}

#page-root h2 { font-size: 22px; margin-bottom: 10px; }
#page-root .desc { color: var(--muted); margin-bottom: 14px; }
#page-root h3 { font-size: 16px; margin: 18px 0 10px; }

.page-back { display: flex; margin-bottom: 10px; }
.page-back button { padding: 6px 12px; font-size: 13px; }

#page-root .note {
  color: var(--muted);
  background: #f0e9e1;
  border-left: 3px solid var(--accent);
  padding: 10px 12px;
  border-radius: 4px;
  margin-bottom: 16px;
}

/* 登录 / 注册 */
body.auth-mode #sidebar { display: none; }

body.auth-mode #page-root {
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(1000px 420px at 12% -8%, rgba(244, 124, 117, 0.10), transparent 60%),
    radial-gradient(900px 420px at 95% 110%, rgba(59, 154, 92, 0.08), transparent 60%),
    var(--bg);
}

.auth-box {
  width: 100%;
  max-width: 400px;
  margin: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 18px 48px rgba(49, 42, 39, 0.12);
  padding: 34px 38px 28px;
  box-sizing: border-box;
}

.auth-brand { margin-bottom: 24px; }
.auth-brand .ab-title {
  font-size: 21px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.5px;
}
.auth-brand .ab-sub {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
}

.auth-form { display: flex; flex-direction: column; gap: 14px; }

.auth-field label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--text);
  font-weight: 600;
}

.auth-field input {
  width: 100%;
  box-sizing: border-box;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.auth-field input::placeholder { color: #b8aca2; }

.auth-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(244, 124, 117, 0.18);
}

.auth-field .code-row {
  display: flex;
  gap: 8px;
  width: 100%;
}

.auth-field .code-row input { flex: 1; min-width: 0; }
.auth-field .code-row button { flex: none; }
button:disabled { opacity: 0.55; cursor: default; }

#page-root select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: var(--panel);
  color: var(--text);
  max-width: 100%;
}

#page-root .field {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
}

#page-root .field label {
  color: var(--muted);
  font-size: 13px;
  flex: none;
}

#page-root button.link {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  font-size: inherit;
}

tr[data-license] { cursor: pointer; }
tr[data-license]:hover td { background: rgba(244, 124, 117, 0.06); }
tr[data-license].active-row td {
  background: rgba(244, 124, 117, 0.14);
}
tr[data-license].active-row td:first-child {
  box-shadow: inset 3px 0 0 var(--accent);
}

.auth-msg {
  min-height: 16px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
}

.auth-submit {
  width: 100%;
  padding: 11px 12px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 2px;
  border-radius: 9px;
  margin-top: 2px;
}

.auth-switch {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

.auth-switch button.link {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.auth-switch button.link:hover { filter: brightness(0.9); }

/* Web 演示版：模拟实时画面占位 */
.stream-box .stream-player.mock-stream {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #14100e;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mock-live {
  color: #b9aea4;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.live-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #d64541;
  animation: live-blink 1.2s infinite;
}

@keyframes live-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

/* Web 演示版：整页内容在窗口内布局 */
html, body { height: 100%; }
#page-root { overflow-y: auto; }

.actions { display: flex; gap: 10px; margin: 14px 0; flex-wrap: wrap; }
.actions .batch-hint {
  font-size: 12px;
  color: var(--muted);
  align-self: center;
}

button {
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  transition: background-color 0.12s ease, transform 0.06s ease,
    box-shadow 0.12s ease, filter 0.12s ease;
}

button.secondary { background: #d9cfc4; color: var(--text); }
button.plain {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

button:hover { filter: brightness(0.94); }
button:active {
  transform: translateY(1px) scale(0.97);
  filter: brightness(0.86);
}
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  button { transition: none; }
}

.result-box {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.progress {
  height: 10px;
  background: var(--border);
  border-radius: 5px;
  overflow: hidden;
  margin: 14px 0 8px;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  transition: width 0.25s;
}

form .field {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

form .field label { width: 110px; color: var(--muted); flex: none; }

form input {
  flex: 1;
  max-width: 320px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}

form .value { color: var(--text); }

#log-view {
  width: 100%;
  height: 380px;
  font-family: Consolas, monospace;
  font-size: 12px;
  background: #1f1b18;
  color: #d8cfc6;
  border: none;
  border-radius: 6px;
  padding: 10px;
  white-space: pre;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border-radius: 8px;
  overflow: hidden;
}

th, td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

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

.state-passed { color: var(--ok); font-weight: 600; }
.state-failed { color: var(--fail); font-weight: 600; }
.state-running { color: var(--accent); font-weight: 600; }
.state-untested { color: var(--muted); font-weight: 600; }
.state-skipped { color: var(--muted); font-weight: 600; }

.test-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.test-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
}

.test-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.test-card .t-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.test-card .t-actions button {
  padding: 6px 12px;
  font-size: 13px;
}

.test-card .t-name { font-weight: 700; font-size: 15px; }
.test-card .t-state { font-size: 13px; }
.test-card .t-detail {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  min-height: 2.9em;
}


#statusbar {
  height: 32px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  font-size: 12px;
  color: var(--muted);
}

/* 项圈产测页：读数卡片与表单 */
.readout-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.readout {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.readout .k { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.readout .v { font-size: 16px; font-weight: 600; }
.readout .v.weak { color: var(--muted); font-weight: 400; }

/* 摄像机测试总览：实时画面播放器 */
.stream-box {
  background: #1f1b18;
  border-radius: 8px;
  overflow: hidden;
  margin: 0 0 16px;
}

/* 播放器区域固定 16:9 横屏，不受设备流原始宽高比影响 */
.stream-box .stream-player {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
}

.stream-box video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* 竖屏流旋转 90° 后以横屏 16:9 铺满播放器（宽高比例与 16:9 容器互换） */
.stream-box video.rotate90 {
  inset: auto;
  left: 50%;
  top: 50%;
  width: 56.25%;
  height: 177.78%;
  transform: translate(-50%, -50%) rotate(90deg);
}

/* 播放器底部横向控制栏：不随画面旋转 */
.stream-box .player-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.65));
}

.stream-box .player-bar button {
  background: rgba(31, 27, 24, 0.72);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 12px;
}

.stream-status {
  padding: 8px 12px;
  font-size: 12px;
  color: #d8cfc6;
  background: #1f1b18;
}

/* 测试总览：当前设备与切换入口 */
.overview-device {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--muted);
}

.overview-device b { color: var(--text); }
.overview-device button { padding: 4px 10px; font-size: 12px; }

/* 设备清单 */
.device-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.device-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
}

.device-row.active { border-color: var(--accent); }

.device-row .d-main { flex: 1; min-width: 220px; }
.device-row .d-license {
  font-weight: 700;
  font-size: 14px;
  word-break: break-all;
}
.device-row .d-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
  word-break: break-all;
}

.device-row .d-tags { display: flex; gap: 6px; }
.device-row .d-tag {
  font-size: 12px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--muted);
  background: #f3ede5;
}

.device-row .d-actions { display: flex; gap: 8px; }
