:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel2: #1d242e;
  --line: #2a323d;
  --fg: #e8edf3;
  --dim: #8b97a6;
  --accent: #2f81f7;
  --ok: #2ea043;
  --warn: #d29922;
  --err: #f85149;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 16px;
  overscroll-behavior: none;
}

body { padding-bottom: 76px; }

/* ---------- 顶栏 ---------- */
header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: rgba(14, 17, 22, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
header h1 { font-size: 18px; margin: 0; font-weight: 600; letter-spacing: .3px; }
header .spacer { flex: 1; }
header .stat { font-size: 12px; color: var(--dim); }

/* ---------- 底部导航 ---------- */
nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  background: rgba(22, 27, 34, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
nav button {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--dim);
  font-size: 12px;
  padding: 10px 4px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  font-family: inherit;
}
nav button .ico { font-size: 20px; line-height: 1; }
nav button.active { color: var(--accent); }

/* ---------- 通用 ---------- */
main { padding: 14px; }
.view { display: none; }
.view.active { display: block; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; color: var(--fg); }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 600; color: var(--dim); }

.row { display: flex; align-items: center; gap: 10px; }
.row + .row { margin-top: 10px; }
.grow { flex: 1; min-width: 0; }

button.btn {
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--fg);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 15px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
button.btn:active { transform: scale(.97); }
button.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.btn.danger { color: var(--err); border-color: rgba(248,81,73,.4); }
button.btn:disabled { opacity: .5; cursor: not-allowed; }

input[type=text], input[type=password], input[type=number], select {
  width: 100%;
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--fg);
  padding: 11px 12px;
  border-radius: 10px;
  font-size: 16px;
  font-family: inherit;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
label.field { display: block; margin-bottom: 12px; }
label.field span { display: block; font-size: 12px; color: var(--dim); margin-bottom: 6px; }

/* ---------- 设备卡片 ---------- */
.grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 720px) { .grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1100px) { .grid { grid-template-columns: 1fr 1fr 1fr; } }

.cam {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
}
.cam .thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000 center/cover no-repeat;
  display: block;
}
.cam .meta {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
}
.cam .name { font-size: 16px; font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #555; flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 8px rgba(46,160,67,.8); }
.dot.rec { background: var(--err); box-shadow: 0 0 8px rgba(248,81,73,.8); animation: blink 1.6s infinite; }
.dot.motion { background: var(--warn); box-shadow: 0 0 8px rgba(210,153,34,.9); }
@keyframes blink { 50% { opacity: .25; } }

.badge {
  position: absolute;
  top: 8px; left: 8px;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 20px;
  background: rgba(0,0,0,.6);
  color: #fff;
  backdrop-filter: blur(4px);
}

/* ---------- 播放器 ---------- */
#player {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #000;
  display: none;
  flex-direction: column;
}
#player.open { display: flex; }
#player .stage {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
#player video { width: 100%; height: 100%; object-fit: contain; background: #000; }
#player .topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: linear-gradient(to bottom, rgba(0,0,0,.75), transparent);
  z-index: 2;
}
#player .topbar .title { font-weight: 600; font-size: 16px; flex: 1; }
#player .status {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  color: var(--dim);
  font-size: 14px;
  text-align: center;
  z-index: 1;
  padding: 0 24px;
}
#player .controls {
  padding: 12px 14px calc(14px + env(safe-area-inset-bottom));
  background: rgba(0,0,0,.55);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#player .controls.hidden { display: none; }

/* PTZ 摇杆 */
.ptz { display: grid; grid-template-columns: repeat(3, 64px); grid-template-rows: repeat(3, 54px); gap: 8px; justify-content: center; }
.ptz button {
  border: 1px solid var(--line);
  background: rgba(255,255,255,.08);
  color: #fff;
  border-radius: 10px;
  font-size: 20px;
  cursor: pointer;
  user-select: none;
}
.ptz button:active { background: var(--accent); }
.ptz .mid { background: rgba(255,255,255,.04); }

/* ---------- 回放 ---------- */
.days { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 12px; }
.days button {
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--dim);
  padding: 8px 14px;
  border-radius: 20px;
  white-space: nowrap;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
}
.days button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.clips { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.clip {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
}
.clip img { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; background: #000; }
.clip .t { padding: 6px 8px; font-size: 13px; display: flex; justify-content: space-between; color: var(--dim); }
.clip .t b { color: var(--fg); font-weight: 600; }

.empty { text-align: center; color: var(--dim); padding: 40px 20px; font-size: 14px; }

/* ---------- 设置 ---------- */
.dev-item { border-bottom: 1px solid var(--line); padding: 12px 0; }
.dev-item:last-child { border-bottom: 0; }
.dev-item .head { display: flex; align-items: center; gap: 10px; }
.dev-item .head .name { font-weight: 600; flex: 1; }
.dev-item .sub { font-size: 12px; color: var(--dim); margin-top: 4px; word-break: break-all; }
.actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

.switch { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }

.toast {
  position: fixed;
  left: 50%; bottom: 96px;
  transform: translateX(-50%) translateY(20px);
  background: #222b36;
  color: #fff;
  padding: 12px 20px;
  border-radius: 24px;
  font-size: 14px;
  opacity: 0;
  transition: .25s;
  z-index: 200;
  pointer-events: none;
  max-width: 86vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.hint { font-size: 12px; color: var(--dim); line-height: 1.6; margin-top: 8px; }
code { background: var(--panel2); padding: 2px 6px; border-radius: 4px; font-size: 12px; }
