:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1b1f27;
  --muted: #6b7280;
  --line: #e4e7ec;
  --accent: #1e6feb;
  --accent-soft: #e8f0fe;
  --danger: #d92d20;
  --ok: #12805c;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --radius: 12px;
  --card: 230px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel: #171a21;
    --text: #e7e9ee;
    --muted: #9aa1ad;
    --line: #2a2f3a;
    --accent: #5b9bff;
    --accent-soft: #1c2740;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
img { display: block; }
button, input, select { font: inherit; color: inherit; }
code { background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  row-gap: 8px;
  gap: 10px;
  padding: 10px 18px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 9px; margin-right: 4px; }
.logo {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, #1e6feb, #4aa3ff);
  color: #fff; display: grid; place-items: center; font-size: 13px;
}
.brand b { display: block; font-size: 15px; letter-spacing: .2px; }
.brand .sub { color: var(--muted); font-size: 11px; }

.summary { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.summary .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px rgba(18,128,92,.15); }

.spacer { flex: 1; }

.search input {
  width: 250px; padding: 7px 12px; border: 1px solid var(--line);
  border-radius: 9px; background: var(--panel); outline: none;
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.seg { display: flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--panel); }
.seg button {
  border: 0; background: transparent; padding: 7px 13px; cursor: pointer; color: var(--muted);
}
.seg button.on { background: var(--accent); color: #fff; }

select {
  padding: 7px 8px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--panel); cursor: pointer; max-width: 130px;
}

.zoom { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.zoom input { width: 84px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--panel); cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); width: 100%; justify-content: center; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }

/* ---------- 选择条 ---------- */
.selbar {
  position: sticky; top: var(--topbar-h, 58px); z-index: 18;
  display: flex; align-items: center; gap: 10px;
  margin: 10px 18px 0; padding: 9px 14px;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  border-radius: var(--radius);
}
.selbar #selCount { font-weight: 600; margin-right: 4px; }

/* ---------- 瀑布流 ---------- */
.feed { padding: 18px; display: flex; flex-direction: column; gap: 22px; }

.day-head {
  display: flex; align-items: baseline; gap: 10px;
  margin: 0 2px 10px; color: var(--muted);
}
.day-head h3 { margin: 0; font-size: 14.5px; color: var(--text); font-weight: 600; }
.day-head span { font-size: 12px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--card), 1fr));
  gap: 12px;
}

.card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: zoom-in;
  transition: transform .16s ease, box-shadow .16s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 4px 10px rgba(16,24,40,.12), 0 16px 32px rgba(16,24,40,.10); }
.card.selected { outline: 2px solid var(--accent); outline-offset: -2px; }

.thumb {
  position: relative;
  aspect-ratio: 4 / 3;
  background: repeating-linear-gradient(45deg, #eceef2, #eceef2 8px, #f4f5f7 8px, #f4f5f7 16px);
  display: grid; place-items: center;
  overflow: hidden;
}
@media (prefers-color-scheme: dark) {
  .thumb { background: repeating-linear-gradient(45deg, #1b1f27, #1b1f27 8px, #141720 8px, #141720 16px); }
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .ph { color: var(--muted); font-size: 26px; opacity: .55; }

.badge {
  position: absolute; right: 7px; bottom: 7px;
  background: rgba(0,0,0,.62); color: #fff;
  font-size: 11px; padding: 2px 6px; border-radius: 5px;
  font-variant-numeric: tabular-nums;
}
.kindtag {
  position: absolute; left: 7px; top: 7px;
  background: rgba(30,111,235,.9); color: #fff;
  font-size: 10.5px; padding: 2px 6px; border-radius: 5px;
}
.kindtag.video { background: rgba(214,80,20,.92); }

.pick {
  position: absolute; left: 7px; bottom: 7px;
  width: 20px; height: 20px; border-radius: 6px;
  background: rgba(255,255,255,.85); border: 1.5px solid rgba(0,0,0,.25);
  display: grid; place-items: center; opacity: 0; transition: opacity .12s;
  cursor: pointer;
}
.card:hover .pick, .card.selected .pick { opacity: 1; }
.card.selected .pick { background: var(--accent); border-color: var(--accent); color: #fff; }
.pick::after { content: "✓"; font-size: 12px; font-weight: 700; color: transparent; }
.card.selected .pick::after { color: #fff; }

.star {
  position: absolute; right: 5px; top: 4px;
  border: 0; background: transparent; color: rgba(255,255,255,.9);
  font-size: 16px; cursor: pointer; opacity: 0; transition: opacity .12s;
  text-shadow: 0 1px 3px rgba(0,0,0,.5);
}
.card:hover .star, .star.on { opacity: 1; }
.star.on { color: #ffb400; }

.meta {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px 9px;
}
.meta .nm {
  font-size: 12px; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.meta .sz { font-size: 11px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

.sentinel { height: 60px; }
.loading { text-align: center; color: var(--muted); padding: 10px 0 40px; font-size: 12.5px; }
.empty { text-align: center; padding: 110px 20px; color: var(--text); }
.empty .muted { color: var(--muted); font-size: 13px; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 20px 0 40px; }

/* ---------- 大图 modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(8,10,14,.92);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(6px);
}
.modal[hidden] { display: none; }

.lb-stage { flex: 1; height: 100%; display: grid; place-items: center; padding: 48px 72px; }
.lb-stage img, .lb-stage video { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; box-shadow: 0 20px 60px rgba(0,0,0,.5); background: #000; }

.lb-side {
  width: 320px; flex: 0 0 320px; height: 100%; overflow: auto;
  background: #14171d; color: #dfe3ea;
  padding: 26px 22px; border-left: 1px solid rgba(255,255,255,.08);
  display: flex; flex-direction: column; gap: 14px;
}
.lb-side h2 { font-size: 14px; margin: 0 0 4px; font-weight: 600; word-break: break-all; line-height: 1.35; }
.lb-side dl { display: grid; grid-template-columns: 68px 1fr; gap: 6px 10px; margin: 0; font-size: 12.5px; }
.lb-side dt { color: #8b93a1; }
.lb-side dd { margin: 0; word-break: break-all; }
.lb-side .acts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.lb-side .acts a, .lb-side .acts button {
  padding: 7px 11px; border-radius: 8px; border: 1px solid rgba(255,255,255,.16);
  background: rgba(255,255,255,.06); color: #e8eaef; cursor: pointer; font-size: 12.5px;
}
.lb-side .acts button.danger { color: #ff8f85; border-color: rgba(255,90,80,.3); }
.tagrow { display: flex; gap: 6px; }
.tagrow input {
  flex: 1; padding: 6px 9px; background: rgba(255,255,255,.06); color: #fff;
  border: 1px solid rgba(255,255,255,.14); border-radius: 7px; outline: none;
}
.tagrow button { padding: 6px 10px; border-radius: 7px; border: 1px solid rgba(255,255,255,.16); background: rgba(255,255,255,.06); color: #fff; cursor: pointer; }
.lb-side .hintline { font-size: 11.5px; color: #7d8694; margin-top: auto; }

.lb-close {
  position: absolute; top: 14px; right: 16px;
  width: 34px; height: 34px; border-radius: 50%; border: 0;
  background: rgba(255,255,255,.12); color: #fff; font-size: 20px; cursor: pointer;
  line-height: 1;
}
.lb-close.static { position: static; background: rgba(0,0,0,.06); color: var(--text); }
.lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 42px; height: 72px; border: 0; border-radius: 10px;
  background: rgba(255,255,255,.1); color: #fff; font-size: 26px; cursor: pointer;
}
.lb-nav.prev { left: 14px; }
.lb-nav.next { left: calc(320px + 14px); }
@media (max-width: 700px) {
  .lb-side { display: none; }
  .lb-nav.next { left: auto; right: 14px; }
}

/* ---------- 统计 ---------- */
#stats .stats-panel {
  width: min(1080px, 94vw); max-height: 90vh; overflow: auto;
  background: var(--panel); color: var(--text);
  border-radius: 16px; box-shadow: 0 30px 80px rgba(0,0,0,.5);
}
.stats-panel header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--line); position: sticky; top: 0;
  background: var(--panel); border-radius: 16px 16px 0 0; z-index: 2;
}
.stats-panel header h2 { margin: 0; font-size: 17px; }
.stats-body { padding: 20px 22px 28px; display: grid; gap: 22px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.kpi .v { font-size: 22px; font-weight: 650; letter-spacing: -.4px; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 12px; margin-top: 3px; }

.chart-title { font-size: 13.5px; font-weight: 600; margin: 0 0 12px; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 8px; }
.bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; min-width: 0; }
.bar > i {
  display: block; width: 100%; max-width: 46px; border-radius: 5px 5px 2px 2px;
  background: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 55%, transparent));
  min-height: 3px;
}
.bar > span { font-size: 10.5px; color: var(--muted); white-space: nowrap; transform: rotate(-28deg); }
.bar > em { font-size: 10px; color: var(--muted); font-style: normal; }

.split { display: grid; gap: 10px; }
.split-row { display: grid; grid-template-columns: 64px 1fr 130px; gap: 10px; align-items: center; font-size: 12.5px; }
.track { height: 9px; border-radius: 5px; background: var(--bg); overflow: hidden; }
.track > i { display: block; height: 100%; background: var(--accent); border-radius: 5px; }
.track.video > i { background: #e2683a; }

table.simple { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.simple th, table.simple td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
table.simple th { color: var(--muted); font-weight: 500; }
table.simple td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- 登录 / 自检 ---------- */
.login-body, .doctor-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card, .doctor-card {
  width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 30px 26px; box-shadow: var(--shadow); display: grid; gap: 12px;
}
.doctor-card { width: min(760px, 100%); }
.login-logo {
  width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #1e6feb, #4aa3ff); font-size: 19px;
  justify-self: center;
}
.login-card h1 { font-size: 20px; margin: 0; text-align: center; line-height: 1.45; }
.login-card .muted, .doctor-card .muted { color: var(--muted); font-size: 13px; line-height: 1.6; margin: 0; }
.login-card input {
  padding: 10px 13px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); outline: none;
}
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-card .err { color: var(--danger); font-size: 12.5px; }
.login-card .hint, .doctor-card .hint { color: var(--muted); font-size: 11.5px; line-height: 1.6; margin: 0; }
.doctor-card h1 { font-size: 20px; margin: 0 0 2px; }
.doctor-card table { width: 100%; border-collapse: collapse; font-size: 13px; }
.doctor-card th { text-align: left; color: var(--muted); font-weight: 500; width: 42%; padding: 9px 0; border-bottom: 1px solid var(--line); }
.doctor-card td { padding: 9px 0; border-bottom: 1px solid var(--line); word-break: break-all; }
.doctor-card td.ok { color: var(--ok); }
.doctor-card td.bad { color: var(--danger); }

/* ---------- 设备与资产 ---------- */
.chip {
  display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 2px;
  border-radius: 999px; background: var(--accent); color: #fff;
  font-size: 10.5px; line-height: 17px; text-align: center; font-variant-numeric: tabular-nums;
}

#devPanel .dev-panel {
  width: min(1180px, 95vw); max-height: 92vh; overflow: auto;
  background: var(--panel); color: var(--text);
  border-radius: 16px; box-shadow: 0 30px 80px rgba(0,0,0,.5);
  display: flex; flex-direction: column;
}
.dev-head {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 22px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--panel); z-index: 2;
  border-radius: 16px 16px 0 0;
}
.dev-head h2 { margin: 0; font-size: 17px; }
.dev-sum { color: var(--muted); font-size: 12.5px; flex: 1; }
.dev-grid {
  padding: 18px 22px; display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
}
.dev-foot { margin: 0; padding: 0 22px 20px; color: var(--muted); font-size: 11.5px; line-height: 1.7; }

.devcard {
  border: 1px solid var(--line); border-radius: 14px; background: var(--bg);
  overflow: hidden; display: flex; flex-direction: column;
}
.devcard.offline { opacity: .82; }
.dc-top {
  display: flex; align-items: center; gap: 8px; padding: 12px 14px 10px;
}
.dc-dot { width: 9px; height: 9px; border-radius: 50%; background: #9aa1ad; flex: 0 0 auto; }
.dc-dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(18,128,92,.16); }
.dc-dot.idle { background: #d9a400; box-shadow: 0 0 0 3px rgba(217,164,0,.15); }
.dc-name { font-weight: 650; font-size: 14px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dc-sub { color: var(--muted); font-size: 11px; padding: 0 14px 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dc-tools { display: flex; gap: 6px; }
.dc-tools button {
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  border-radius: 7px; padding: 3px 8px; font-size: 11.5px; cursor: pointer;
}
.dc-tools button:hover { color: var(--accent); border-color: var(--accent); }

.dc-map { position: relative; height: 132px; background: #dfe6ea; overflow: hidden; border-block: 1px solid var(--line); }
.dc-map .mm-canvas { position: absolute; top: 0; left: 0; width: 512px; height: 512px; }
.dc-map .mm-canvas img { position: absolute; width: 256px; height: 256px; display: block; }
.dc-map .mm-pin {
  position: absolute; left: 50%; top: 50%; width: 12px; height: 12px; margin: -6px 0 0 -6px;
  border-radius: 50%; background: var(--accent); border: 2px solid #fff;
  box-shadow: 0 0 0 3px rgba(30,111,235,.35);
}
.dc-map .mm-attr { position: absolute; right: 4px; bottom: 2px; font-size: 9.5px; color: #38424d; background: rgba(255,255,255,.7); padding: 0 3px; border-radius: 3px; }
.dc-map .mm-empty {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  color: #5b6673; font-size: 11.5px; line-height: 1.6; padding: 0 14px; background: #e9edf1;
}
.devcard.cold .dc-map { height: 96px; }

.dc-rows { padding: 10px 14px 4px; display: grid; gap: 5px; font-size: 12px; }
.dc-row { display: grid; grid-template-columns: 62px 1fr; gap: 8px; align-items: baseline; }
.dc-row .k { color: var(--muted); }
.dc-row .v { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dc-row .v b { font-weight: 600; }
.dc-bat { display: inline-flex; align-items: center; gap: 6px; }
.dc-bat .bar { width: 42px; height: 7px; border-radius: 4px; background: var(--line); overflow: hidden; }
.dc-bat .bar > i { display: block; height: 100%; background: var(--ok); }
.dc-bat.low .bar > i { background: var(--danger); }
.dc-bat.charging .bar > i { background: var(--accent); }

.dc-acts { display: flex; flex-wrap: wrap; gap: 7px; padding: 10px 14px 13px; }
.dc-acts button, .dc-acts a {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px;
  padding: 5px 10px; font-size: 12px; cursor: pointer; color: var(--text); text-decoration: none;
}
.dc-acts button:hover, .dc-acts a:hover { border-color: var(--accent); color: var(--accent); }
.dc-acts .primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.dc-acts .primary:hover { color: #fff; filter: brightness(1.06); }
.dc-empty { padding: 40px 10px; text-align: center; color: var(--muted); font-size: 13px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%);
  background: #1b1f27; color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 13px; z-index: 80; box-shadow: 0 12px 30px rgba(0,0,0,.35);
  max-width: 80vw;
}
.toast.err { background: var(--danger); }
.toast[hidden] { display: none; }
